Hdf5DataWriter Class Reference

#include <Hdf5DataWriter.hpp>

Collaboration diagram for Hdf5DataWriter:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Hdf5DataWriter (DistributedVectorFactory &rVectorFactory, const std::string &rDirectory, const std::string &rBaseName, bool cleanDirectory=true, bool extendData=false)
virtual ~Hdf5DataWriter ()
void DefineFixedDimension (long dimensionSize)
void DefineFixedDimension (const std::vector< unsigned > &rNodesToOuput, long vecSize)
void DefineUnlimitedDimension (const std::string &rVariableName, const std::string &rVariableUnits)
void AdvanceAlongUnlimitedDimension ()
int DefineVariable (const std::string &rVariableName, const std::string &rVariableUnits)
virtual void EndDefineMode ()
void PossiblyExtend ()
void PutVector (int variableID, Vec petscVector)
void PutStripedVector (int firstVariableID, int secondVariableID, Vec petscVector)
void PutUnlimitedVariable (double value)
void Close ()
int GetVariableByName (const std::string &rVariableName)

Private Member Functions

void CheckVariableName (const std::string &rName)
void CheckUnitsName (const std::string &rName)
void ComputeIncompleteOffset ()

Private Attributes

DistributedVectorFactorymrVectorFactory
std::string mDirectory
std::string mBaseName
bool mCleanDirectory
bool mIsInDefineMode
bool mIsFixedDimensionSet
bool mIsUnlimitedDimensionSet
std::string mUnlimitedDimensionName
std::string mUnlimitedDimensionUnit
unsigned mFileFixedDimensionSize
unsigned mDataFixedDimensionSize
unsigned mLo
unsigned mHi
unsigned mNumberOwned
unsigned mOffset
bool mIsDataComplete
bool mNeedExtend
std::vector< unsignedmIncompleteNodeIndices
std::vector< DataWriterVariablemVariables
hid_t mFileId
hid_t mDatasetId
hid_t mTimeDatasetId
long mCurrentTimeStep
hsize_t mDatasetDims [DATASET_DIMS]

Static Private Attributes

static const unsigned DATASET_DIMS = 3

Detailed Description

A concrete HDF5 data writer class.

Definition at line 43 of file Hdf5DataWriter.hpp.


Constructor & Destructor Documentation

Hdf5DataWriter::Hdf5DataWriter ( DistributedVectorFactory rVectorFactory,
const std::string &  rDirectory,
const std::string &  rBaseName,
bool  cleanDirectory = true,
bool  extendData = false 
)

Constructor.

Parameters:
rVectorFactory the factory to use in creating PETSc Vec and DistributedVector objects.
rDirectory the directory in which to write the data to file
rBaseName the name of the file in which to write the data
cleanDirectory whether to clean the directory (defaults to true)
extendData whether to try opening an existing file and appending to it.

The extendData parameter allows us to add to an existing dataset. It only really makes sense if the existing file has an unlimited dimension which we can extend. It also only makes sense if cleanDirectory is false, otherwise there won't be a file there to read...

Todo:
1300 We can't set mDataFixedDimensionSize, because the information isn't in the input file. This means that checking the size of input vectors in PutVector and PutStripedVector is impossible.

Definition at line 40 of file Hdf5DataWriter.cpp.

References AdvanceAlongUnlimitedDimension(), ComputeIncompleteOffset(), DATASET_DIMS, DistributedVectorFactory::GetLocalOwnership(), OutputFileHandler::GetOutputDirectoryFullPath(), mBaseName, mCurrentTimeStep, mDataFixedDimensionSize, mDatasetDims, mDatasetId, mDirectory, mFileFixedDimensionSize, mFileId, mIncompleteNodeIndices, mIsDataComplete, mIsFixedDimensionSet, mIsInDefineMode, mIsUnlimitedDimensionSet, mLo, mNumberOwned, mOffset, mrVectorFactory, mTimeDatasetId, mUnlimitedDimensionName, mUnlimitedDimensionUnit, DataWriterVariable::mVariableName, mVariables, and DataWriterVariable::mVariableUnits.

Hdf5DataWriter::~Hdf5DataWriter (  )  [virtual]

Destructor.

Definition at line 215 of file Hdf5DataWriter.cpp.

References Close().


Member Function Documentation

void Hdf5DataWriter::AdvanceAlongUnlimitedDimension (  ) 

Advance along the unlimited dimension. Normally this will be called when all variables in a row have been input.

Definition at line 738 of file Hdf5DataWriter.cpp.

References mCurrentTimeStep, mDatasetDims, mIsUnlimitedDimensionSet, and mNeedExtend.

Referenced by Hdf5DataWriter(), CardiacElectroMechanicsProblem< DIM >::Solve(), and AbstractCardiacProblem< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::Solve().

void Hdf5DataWriter::CheckUnitsName ( const std::string &  rName  )  [private]

Check name of unit is allowed, i.e. contains only alphanumeric & _, and isn't blank.

Parameters:
rName unit name

Definition at line 331 of file Hdf5DataWriter.cpp.

Referenced by CheckVariableName(), and DefineVariable().

void Hdf5DataWriter::CheckVariableName ( const std::string &  rName  )  [private]

Check name of variable is allowed, i.e. contains only alphanumeric & _, and isn't blank.

Parameters:
rName variable name

Definition at line 322 of file Hdf5DataWriter.cpp.

References CheckUnitsName().

Referenced by DefineVariable().

void Hdf5DataWriter::Close (  ) 
void Hdf5DataWriter::ComputeIncompleteOffset (  )  [private]

Compute mOffset and mNumberOwned from mIncompleteNodeIndices when we have incomplete data.

Definition at line 270 of file Hdf5DataWriter.cpp.

References mHi, mIncompleteNodeIndices, mLo, mNumberOwned, and mOffset.

Referenced by DefineFixedDimension(), and Hdf5DataWriter().

void Hdf5DataWriter::DefineFixedDimension ( const std::vector< unsigned > &  rNodesToOuput,
long  vecSize 
)

Define the fixed dimension, assuming incomplete data output (subset of the nodes).

Parameters:
rNodesToOuput Node indexes to be output (precondition: to be monotonic increasing)
vecSize 

Definition at line 245 of file Hdf5DataWriter.cpp.

References ComputeIncompleteOffset(), DefineFixedDimension(), mFileFixedDimensionSize, mIncompleteNodeIndices, and mIsDataComplete.

void Hdf5DataWriter::DefineFixedDimension ( long  dimensionSize  ) 
void Hdf5DataWriter::DefineUnlimitedDimension ( const std::string &  rVariableName,
const std::string &  rVariableUnits 
)

Define a variable.

Parameters:
rVariableName The name of the dimension
rVariableUnits The physical units of the dimension

Definition at line 720 of file Hdf5DataWriter.cpp.

References mIsInDefineMode, mIsUnlimitedDimensionSet, mUnlimitedDimensionName, and mUnlimitedDimensionUnit.

Referenced by AbstractCardiacProblem< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::DefineWriterColumns().

int Hdf5DataWriter::DefineVariable ( const std::string &  rVariableName,
const std::string &  rVariableUnits 
)
void Hdf5DataWriter::EndDefineMode (  )  [virtual]
int Hdf5DataWriter::GetVariableByName ( const std::string &  rVariableName  ) 

Get the id of the given variable, the variable must already exist or an exception will be thrown.

Parameters:
rVariableName variable name to look up
Returns:
HDF5 id for the given variable.

Definition at line 762 of file Hdf5DataWriter.cpp.

References mVariables.

Referenced by AbstractCardiacProblem< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::DefineExtraVariablesWriterColumns(), BidomainProblem< DIM >::DefineWriterColumns(), and AbstractCardiacProblem< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::DefineWriterColumns().

void Hdf5DataWriter::PossiblyExtend (  ) 

Extend the dataset to the correct to the correct dimensions if needed.

Definition at line 752 of file Hdf5DataWriter.cpp.

References mDatasetDims, mDatasetId, mNeedExtend, and mTimeDatasetId.

Referenced by PutStripedVector(), PutUnlimitedVariable(), and PutVector().

void Hdf5DataWriter::PutStripedVector ( int  firstVariableID,
int  secondVariableID,
Vec  petscVector 
)

Write data for two variables from a Petsc vector to the dataset.

Parameters:
firstVariableID the first variable
secondVariableID the first variable
petscVector the data

Todo:
Use distributed vector functionality here?

Definition at line 588 of file Hdf5DataWriter.cpp.

References DATASET_DIMS, mCurrentTimeStep, mDataFixedDimensionSize, mDatasetId, mIncompleteNodeIndices, mIsDataComplete, mIsInDefineMode, mLo, mNumberOwned, mOffset, and PossiblyExtend().

Referenced by BidomainProblem< DIM >::WriteOneStep().

void Hdf5DataWriter::PutUnlimitedVariable ( double  value  ) 

Write a single value for the unlimited variable (e.g. time) to the dataset.

Parameters:
value the data

Definition at line 666 of file Hdf5DataWriter.cpp.

References PetscTools::AmMaster(), mCurrentTimeStep, mIsInDefineMode, mIsUnlimitedDimensionSet, mTimeDatasetId, and PossiblyExtend().

Referenced by MonodomainProblem< ELEMENT_DIM, SPACE_DIM >::WriteOneStep(), and BidomainProblem< DIM >::WriteOneStep().

void Hdf5DataWriter::PutVector ( int  variableID,
Vec  petscVector 
)

Write data for a given variable from a Petsc vector to the dataset.

Parameters:
variableID the variable
petscVector the data

Definition at line 523 of file Hdf5DataWriter.cpp.

References DATASET_DIMS, mCurrentTimeStep, mDataFixedDimensionSize, mDatasetId, mIncompleteNodeIndices, mIsDataComplete, mIsInDefineMode, mLo, mNumberOwned, mOffset, and PossiblyExtend().

Referenced by AbstractCardiacProblem< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::WriteExtraVariablesOneStep(), and MonodomainProblem< ELEMENT_DIM, SPACE_DIM >::WriteOneStep().


Member Data Documentation

const unsigned Hdf5DataWriter::DATASET_DIMS = 3 [static, private]

Defined in HDF5 reader too.

Todo:
: define it once

Definition at line 88 of file Hdf5DataWriter.hpp.

Referenced by EndDefineMode(), Hdf5DataWriter(), PutStripedVector(), and PutVector().

std::string Hdf5DataWriter::mBaseName [private]

The base name for the output data files.

Definition at line 49 of file Hdf5DataWriter.hpp.

Referenced by EndDefineMode(), and Hdf5DataWriter().

Whether to wipe the output directory

Definition at line 50 of file Hdf5DataWriter.hpp.

Referenced by EndDefineMode().

The current time step.

Definition at line 86 of file Hdf5DataWriter.hpp.

Referenced by AdvanceAlongUnlimitedDimension(), Hdf5DataWriter(), PutStripedVector(), PutUnlimitedVariable(), and PutVector().

The size of the fixed dimension (size of the vector of nodes)

Definition at line 57 of file Hdf5DataWriter.hpp.

Referenced by DefineFixedDimension(), Hdf5DataWriter(), PutStripedVector(), and PutVector().

The sizes of each variable data set.

Definition at line 89 of file Hdf5DataWriter.hpp.

Referenced by AdvanceAlongUnlimitedDimension(), EndDefineMode(), Hdf5DataWriter(), and PossiblyExtend().

hid_t Hdf5DataWriter::mDatasetId [private]

The variables data set ID.

Definition at line 83 of file Hdf5DataWriter.hpp.

Referenced by Close(), EndDefineMode(), Hdf5DataWriter(), PossiblyExtend(), PutStripedVector(), and PutVector().

std::string Hdf5DataWriter::mDirectory [private]

Directory output files will be stored in.

Definition at line 48 of file Hdf5DataWriter.hpp.

Referenced by EndDefineMode(), and Hdf5DataWriter().

The size of the fixed dimension (number of rows)

Definition at line 56 of file Hdf5DataWriter.hpp.

Referenced by DefineFixedDimension(), EndDefineMode(), and Hdf5DataWriter().

hid_t Hdf5DataWriter::mFileId [private]

The data file ID.

Definition at line 82 of file Hdf5DataWriter.hpp.

Referenced by Close(), EndDefineMode(), and Hdf5DataWriter().

Local ownership of a PETSc vector of size mFileFixedDimensionSize

Definition at line 59 of file Hdf5DataWriter.hpp.

Referenced by ComputeIncompleteOffset(), and DefineFixedDimension().

Vector of node indices for which the data file does contain data.

Definition at line 64 of file Hdf5DataWriter.hpp.

Referenced by ComputeIncompleteOffset(), DefineFixedDimension(), EndDefineMode(), Hdf5DataWriter(), PutStripedVector(), and PutVector().

Whether the data file is complete.

Definition at line 62 of file Hdf5DataWriter.hpp.

Referenced by DefineFixedDimension(), EndDefineMode(), Hdf5DataWriter(), PutStripedVector(), and PutVector().

Is the fixed dimension set

Definition at line 52 of file Hdf5DataWriter.hpp.

Referenced by DefineFixedDimension(), EndDefineMode(), and Hdf5DataWriter().

Is the unlimited dimension set

Definition at line 53 of file Hdf5DataWriter.hpp.

Referenced by AdvanceAlongUnlimitedDimension(), Close(), DefineUnlimitedDimension(), EndDefineMode(), Hdf5DataWriter(), and PutUnlimitedVariable().

Local ownership of a PETSc vector of size mFileFixedDimensionSize

Definition at line 58 of file Hdf5DataWriter.hpp.

Referenced by ComputeIncompleteOffset(), DefineFixedDimension(), Hdf5DataWriter(), PutStripedVector(), and PutVector().

Used so that the data set is only extended when data is written

Definition at line 63 of file Hdf5DataWriter.hpp.

Referenced by AdvanceAlongUnlimitedDimension(), and PossiblyExtend().

mNumberOwned=mHi-mLo; except with incomplete data

Definition at line 60 of file Hdf5DataWriter.hpp.

Referenced by ComputeIncompleteOffset(), DefineFixedDimension(), Hdf5DataWriter(), PutStripedVector(), and PutVector().

mOffset=mLo; except with incomplete data

Definition at line 61 of file Hdf5DataWriter.hpp.

Referenced by ComputeIncompleteOffset(), DefineFixedDimension(), Hdf5DataWriter(), PutStripedVector(), and PutVector().

The factory to use in creating PETSc Vec and DistributedVector objects.

Definition at line 47 of file Hdf5DataWriter.hpp.

Referenced by DefineFixedDimension(), and Hdf5DataWriter().

The time data set ID.

Definition at line 84 of file Hdf5DataWriter.hpp.

Referenced by Close(), EndDefineMode(), Hdf5DataWriter(), PossiblyExtend(), and PutUnlimitedVariable().

The name of the unlimited dimension.

Definition at line 54 of file Hdf5DataWriter.hpp.

Referenced by DefineUnlimitedDimension(), EndDefineMode(), and Hdf5DataWriter().

The physical units of the unlimited dimension.

Definition at line 55 of file Hdf5DataWriter.hpp.

Referenced by DefineUnlimitedDimension(), EndDefineMode(), and Hdf5DataWriter().

The data variables

Definition at line 66 of file Hdf5DataWriter.hpp.

Referenced by DefineVariable(), EndDefineMode(), GetVariableByName(), and Hdf5DataWriter().


The documentation for this class was generated from the following files:

Generated by  doxygen 1.6.2