Chaste  Release::3.4
Hdf5DataWriter.hpp
1 /*
2 
3 Copyright (c) 2005-2016, University of Oxford.
4 All rights reserved.
5 
6 University of Oxford means the Chancellor, Masters and Scholars of the
7 University of Oxford, having an administrative office at Wellington
8 Square, Oxford OX1 2JD, UK.
9 
10 This file is part of Chaste.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
14  * Redistributions of source code must retain the above copyright notice,
15  this list of conditions and the following disclaimer.
16  * Redistributions in binary form must reproduce the above copyright notice,
17  this list of conditions and the following disclaimer in the documentation
18  and/or other materials provided with the distribution.
19  * Neither the name of the University of Oxford nor the names of its
20  contributors may be used to endorse or promote products derived from this
21  software without specific prior written permission.
22 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34 */
35 
36 #ifndef HDF5DATAWRITER_HPP_
37 #define HDF5DATAWRITER_HPP_
38 
39 
40 // Not sure why this seems to need to be included here as well as in AbstractHdf5Access.hpp,
41 // but it does on some of the build machines.
42 #ifndef H5_USE_16_API
43 #define H5_USE_16_API 1
44 #endif
45 
46 #include <vector>
47 
48 #include "AbstractHdf5Access.hpp"
49 #include "DataWriterVariable.hpp"
50 #include "DistributedVectorFactory.hpp"
51 
55 class Hdf5DataWriter : public AbstractHdf5Access //: public AbstractDataWriter
56 {
57 private:
58 
61 
70  unsigned mLo;
71  unsigned mHi;
72  unsigned mNumberOwned;
73  unsigned mOffset;
75  bool mNeedExtend;
78  std::vector<DataWriterVariable> mVariables;
80  long unsigned mCurrentTimeStep;
90  hsize_t mNumberOfChunks;
99  void CheckVariableName(const std::string& rName);
100 
106  void CheckUnitsName(const std::string& rName);
107 
112 
118  void OpenFile();
119 
124  hsize_t CalculateNumberOfChunks();
125 
134  void CalculateChunkDims( unsigned targetSize, unsigned* pChunkSizeInBytes, bool* pAllOneChunk );
135 
142  void SetChunkSize();
143 
144 public:
145 
161  const std::string& rDirectory,
162  const std::string& rBaseName,
163  bool cleanDirectory=true,
164  bool extendData=false,
165  std::string datasetName="Data");
166 
170  virtual ~Hdf5DataWriter();
171 
177  void DefineFixedDimension(long dimensionSize);
178 
185  void DefineFixedDimension(const std::vector<unsigned>& rNodesToOuput, long vecSize);
186 
195  void DefineUnlimitedDimension(const std::string& rVariableName, const std::string& rVariableUnits, unsigned estimatedLength = 1);
196 
202 
211  int DefineVariable(const std::string& rVariableName, const std::string& rVariableUnits);
212 
222  bool IsInDefineMode();
223 
227  virtual void EndDefineMode();
228 
232  void PossiblyExtend();
233 
240  void EmptyDataset();
241 
248  void PutVector(int variableID, Vec petscVector);
249 
256  void PutStripedVector(std::vector<int> variableIDs, Vec petscVector);
257 
263  void PutUnlimitedVariable(double value);
264 
268  void Close();
269 
277  int GetVariableByName(const std::string& rVariableName);
278 
279 
288  bool ApplyPermutation(const std::vector<unsigned>& rPermutation, bool unsafeExtendingMode=false);
289 
297  void DefineFixedDimensionUsingMatrix(const std::vector<unsigned>& rNodesToOuput, long vecSize);
298 
313  void SetFixedChunkSize(const unsigned& rTimestepsPerChunk,
314  const unsigned& rNodesPerChunk,
315  const unsigned& rVariablesPerChunk);
316 
317 };
318 
319 #endif /*HDF5DATAWRITER_HPP_*/
void ComputeIncompleteOffset()
hsize_t CalculateNumberOfChunks()
bool ApplyPermutation(const std::vector< unsigned > &rPermutation, bool unsafeExtendingMode=false)
Hdf5DataWriter(DistributedVectorFactory &rVectorFactory, const std::string &rDirectory, const std::string &rBaseName, bool cleanDirectory=true, bool extendData=false, std::string datasetName="Data")
bool mUseOptimalChunkSizeAlgorithm
void CheckVariableName(const std::string &rName)
int GetVariableByName(const std::string &rVariableName)
void CalculateChunkDims(unsigned targetSize, unsigned *pChunkSizeInBytes, bool *pAllOneChunk)
void DefineFixedDimensionUsingMatrix(const std::vector< unsigned > &rNodesToOuput, long vecSize)
bool mUseMatrixForIncompleteData
void SetFixedChunkSize(const unsigned &rTimestepsPerChunk, const unsigned &rNodesPerChunk, const unsigned &rVariablesPerChunk)
unsigned mEstimatedUnlimitedLength
void AdvanceAlongUnlimitedDimension()
DistributedVectorFactory & mrVectorFactory
hsize_t mFixedChunkSize[DATASET_DIMS]
int DefineVariable(const std::string &rVariableName, const std::string &rVariableUnits)
Mat mDoubleIncompleteOutputMatrix
void PutVector(int variableID, Vec petscVector)
unsigned mNumberOwned
void DefineFixedDimension(long dimensionSize)
virtual ~Hdf5DataWriter()
Mat mSingleIncompleteOutputMatrix
void CheckUnitsName(const std::string &rName)
void PutStripedVector(std::vector< int > variableIDs, Vec petscVector)
std::vector< DataWriterVariable > mVariables
void PutUnlimitedVariable(double value)
static const unsigned DATASET_DIMS
hsize_t mNumberOfChunks
unsigned mDataFixedDimensionSize
long unsigned mCurrentTimeStep
hsize_t mChunkSize[DATASET_DIMS]
unsigned mFileFixedDimensionSize
virtual void EndDefineMode()
void DefineUnlimitedDimension(const std::string &rVariableName, const std::string &rVariableUnits, unsigned estimatedLength=1)