Hdf5DataWriter.hpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef HDF5DATAWRITER_HPP_
00037 #define HDF5DATAWRITER_HPP_
00038
00039
00040
00041
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
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