Hdf5DataWriter.hpp

00001 /*
00002 
00003 Copyright (c) 2005-2015, University of Oxford.
00004 All rights reserved.
00005 
00006 University of Oxford means the Chancellor, Masters and Scholars of the
00007 University of Oxford, having an administrative office at Wellington
00008 Square, Oxford OX1 2JD, UK.
00009 
00010 This file is part of Chaste.
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016  * Redistributions in binary form must reproduce the above copyright notice,
00017    this list of conditions and the following disclaimer in the documentation
00018    and/or other materials provided with the distribution.
00019  * Neither the name of the University of Oxford nor the names of its
00020    contributors may be used to endorse or promote products derived from this
00021    software without specific prior written permission.
00022 
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 
00034 */
00035 
00036 #ifndef HDF5DATAWRITER_HPP_
00037 #define HDF5DATAWRITER_HPP_
00038 
00039 
00040 // Not sure why this seems to need to be included here as well as in AbstractHdf5Access.hpp,
00041 // but it does on some of the build machines.
00042 #ifndef H5_USE_16_API
00043 #define H5_USE_16_API 1
00044 #endif
00045 
00046 #include <vector>
00047 
00048 #include "AbstractHdf5Access.hpp"
00049 #include "DataWriterVariable.hpp"
00050 #include "DistributedVectorFactory.hpp"
00051 
00055 class Hdf5DataWriter : public AbstractHdf5Access //: public AbstractDataWriter
00056 {
00057 private:
00058 
00060     DistributedVectorFactory& mrVectorFactory;
00061 
00062     bool mCleanDirectory;                           
00063     bool mUseExistingFile;                          
00064     bool mIsInDefineMode;                           
00065     bool mIsFixedDimensionSet;                      
00067     unsigned mEstimatedUnlimitedLength;             
00068     unsigned mFileFixedDimensionSize;               
00069     unsigned mDataFixedDimensionSize;               
00070     unsigned mLo;                                   
00071     unsigned mHi;                                   
00072     unsigned mNumberOwned;                          
00073     unsigned mOffset;                               
00075     bool mNeedExtend;                               
00076     bool mUseMatrixForIncompleteData;               
00078     std::vector<DataWriterVariable> mVariables;     
00080     long unsigned mCurrentTimeStep;                 
00082     Mat mSinglePermutation;                         
00083     Mat mDoublePermutation;                         
00085     Mat mSingleIncompleteOutputMatrix;              
00086     Mat mDoubleIncompleteOutputMatrix;              
00088     bool mUseOptimalChunkSizeAlgorithm;             
00089     hsize_t mChunkSize[DATASET_DIMS];               
00090     hsize_t mNumberOfChunks;                  
00091     hsize_t mFixedChunkSize[DATASET_DIMS];          
00099     void CheckVariableName(const std::string& rName);
00100 
00106     void CheckUnitsName(const std::string& rName);
00107 
00111     void ComputeIncompleteOffset();
00112 
00118     void OpenFile();
00119 
00124     hsize_t CalculateNumberOfChunks();
00125 
00134     void CalculateChunkDims( unsigned targetSize, unsigned* pChunkSizeInBytes, bool* pAllOneChunk );
00135 
00142     void SetChunkSize();
00143 
00144 public:
00145 
00160     Hdf5DataWriter(DistributedVectorFactory& rVectorFactory,
00161                    const std::string& rDirectory,
00162                    const std::string& rBaseName,
00163                    bool cleanDirectory=true,
00164                    bool extendData=false,
00165                    std::string datasetName="Data");
00166 
00170     virtual ~Hdf5DataWriter();
00171 
00177     void DefineFixedDimension(long dimensionSize);
00178 
00185     void DefineFixedDimension(const std::vector<unsigned>& rNodesToOuput, long vecSize);
00186 
00195     void DefineUnlimitedDimension(const std::string& rVariableName, const std::string& rVariableUnits, unsigned estimatedLength = 1);
00196 
00201     void AdvanceAlongUnlimitedDimension();
00202 
00211     int DefineVariable(const std::string& rVariableName, const std::string& rVariableUnits);
00212 
00216     virtual void EndDefineMode();
00217 
00221     void PossiblyExtend();
00222 
00229     void PutVector(int variableID, Vec petscVector);
00230 
00237     void PutStripedVector(std::vector<int> variableIDs, Vec petscVector);
00238 
00244     void PutUnlimitedVariable(double value);
00245 
00249     void Close();
00250 
00258     int GetVariableByName(const std::string& rVariableName);
00259 
00260 
00269     bool ApplyPermutation(const std::vector<unsigned>& rPermutation, bool unsafeExtendingMode=false);
00270 
00278     void DefineFixedDimensionUsingMatrix(const std::vector<unsigned>& rNodesToOuput, long vecSize);
00279 
00294     void SetFixedChunkSize(const unsigned& rTimestepsPerChunk,
00295                            const unsigned& rNodesPerChunk,
00296                            const unsigned& rVariablesPerChunk);
00297 
00298 };
00299 
00300 #endif /*HDF5DATAWRITER_HPP_*/

Generated by  doxygen 1.6.2