GemaCoreLib
The GeMA Core library
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
GmHdf5 Class Reference

A support class for saving data to a HDF5 file. Hdf5 files are self-describing but do not have a fixed semantic, so this file is usally accompanied by another file that describes the semantic of the tables exported in the HDF5 file. More...

#include <gmHdf5.h>

Collaboration diagram for GmHdf5:
Collaboration graph
[legend]

Public Member Functions

 GmHdf5 (const GmLogCategory &logger)
 Constructor.
 
 ~GmHdf5 ()
 Destructor.
 
bool create (QString fileName, const GmFileFormat *fileFormat, const GmSimulationData *simData, bool singlePrecision, int sequenceNumber)
 Creates a new HDF5 file. If it already exists, it will be replaced. The file is initialized with some metadata attributes and the simulation description from simData. The given file format object is used to define which types of cells can be exported and also their node orderings. More...
 
bool createGroups (const QStringList &groups)
 Adds the given groups to the file. The group list should be ordered in a way that when creating a group in a hierarchy, all its fathers are already created.
 
bool createGroup (QString group, double time, QString timeUnit)
 Adds the given group to the file, with added time attributes.
 
bool adjustTimeInfo (int sequenceNum, bool multiTime, double startTime, double endTime, QString timeUnit)
 Saves to the root metadata the time step information. If sequenceNum is 0, saves the global simulation time info. Otherwise, saves the sequence file time info.
 
bool saveMeshNodeCoord (QString dsName, const GmMesh *mesh, const GmFileFilter *filter, GmValueAccessor *nodeAc, const double *scaleFactor, const double *offset)
 Saves mesh geometry (node coordinates) to a new HDF5 data set. Some basic mesh metadata is also saved in the form of attributes. More...
 
bool saveMeshGaussNodeCoord (QString dsName, const GmElementMesh *mesh, const GmFileFilter *filter, int ruleIndex, GmValueAccessor *nodeAc, const double *scaleFactor, const double *offset)
 Saves the coordinates of the mesh Gauss points, as if they where mesh nodes, to a new HDF5 data set. Some basic mesh metadata is also saved in the form of attributes. More...
 
bool saveMeshTopology (QString dsName, const GmCellMesh *mesh, const GmFileFilter *filter)
 Saves mesh topology (cell node incidence list) to a new HDF5 data set. Some basic mesh metadata are also saved in the form of attributes. More...
 
bool saveMeshPointCloudTopology (QString dsName, const GmMesh *mesh, const GmFileFilter *filter, int ruleIndex=-1)
 Saves a simple vector with size equal to the number of mesh nodes / number of gauss points (if ruleIndex != -1), where each value is equal to its vector index position.
 
bool saveMeshNodeData (QString dsName, const GmMesh *mesh, const GmFileFilter *filter, GmValueAccessor *dataAc, int dimFilter)
 Saves mesh node data to a new HDF5 data set. Some basic mesh metadata is also saved in the form of attributes. The filter defining which mesh nodes should be saved MUST be equal to the one given in the call to saveMeshNodeCoord(). More...
 
bool saveMeshNodeIdColumn (QString dsName, const GmMesh *mesh, const GmFileFilter *filter)
 Saves mesh node ids to a new HDF5 data set. Some basic mesh metadata is also saved in the form of attributes. The filter defining which mesh nodes should be saved MUST be equal to the one given in the call to saveMeshNodeCoord(). More...
 
bool saveMeshCellData (QString dsName, const GmCellMesh *mesh, const GmFileFilter *filter, GmCellAccessor *dataAc, int dimFilter)
 Saves mesh cell data to a new HDF5 data set. Some basic mesh metadata is also saved in the form of attributes. The filter defining which mesh cells should be saved MUST be equal to the one given in the call to saveMeshTopology(). More...
 
bool saveMeshGaussData (QString dsName, const GmElementMesh *mesh, const GmFileFilter *filter, int ruleIndex, GmGaussAccessor *dataAc, int dimFilter)
 Saves mesh Gauss data to a new HDF5 data set. Some basic mesh metadata is also saved in the form of attributes. The filter defining which mesh cells should be saved MUST be equal to the one given in the call to saveMeshGaussNodeCoord(). More...
 
bool saveDiscontinuitySetData (QString coordDsName, QString cellDsName, const GmDiscontinuitySet *discSet, bool original, const UnitConverter *conv, const double *scaleFactor, const double *offset, int *numNodes, int *numSegments, int *dataSize)
 Saves discontinuity set geometry data to a pair of new HDF5 data sets (one for node coordinates. More...
 
bool saveMeshCellExtraColumn (QString dsName, const GmCellMesh *mesh, const GmFileFilter *filter, GmFileIO::ExtraColumns column, int propertySet)
 Saves mesh cell extra column (cell id, type, active or material) data to a new HDF5 data set. Some basic mesh metadata is also saved in the form of attributes. The filter defining which mesh cells should be saved MUST be equal to the one given in the call to saveMeshTopology(). More...
 
bool saveMeshGaussIdColumn (QString dsName, const GmElementMesh *mesh, const GmFileFilter *filter, int ruleIndex)
 Saves mesh Gauss point ID data to a new HDF5 data set. Some basic mesh metadata is also saved in the form of attributes. The filter defining which mesh cells should be saved MUST be equal to the one given in the call to saveMeshGaussNodeCoord(). More...
 

Static Public Member Functions

static bool addSequenceInfo (QString fileName, int numSequenceFiles, double startTime, double endTime, QString timeUnit, const GmLogCategory &logger)
 Adds to the given existing (and closed) HDF5 file a set of attributes with the total number of sequence files used and the global time info.
 

Private Member Functions

bool saveNodeData (QString dsName, const GmMesh *mesh, const GmFileFilter *filter, GmValueAccessor *dataAc, int dimFilter, std::function< void(const double *, int, double *)> transformFunc)
 Work horse for both saveMeshNodeCoord() and saveMeshNodeData(). See those method descriptions for an explanation of the parameters. The transformFunc parameter is an optional transformation function that, when given, is applied over each node value. It receives as parameters a vector with the original set of values, the vector size and an output buffer with the same size as the input one, where the calculated values should be placed. Keep in mind that the input and output buffers can be the same. If dimFilter is active (different from -1), the transformation function's input buffer will be the scalar value selected by the dimension filter.
 
template<class T >
bool fillDiscontinuityPolylineData (const GmDiscontinuitySet *discSet, bool original, const UnitConverter *conv, const double *scaleFactor, const double *offset, QVector< T > &nodes, QVector< int > &topology, int *nsegments) const
 Helper function used by saveDiscontinuitySetData() to fill the nodes and topology vectors with the polyline discontinuity geometric data that will be saved. See the caller function for a description of the input parameters. Returns true on success, false on out of memory error. More...
 
const char * dataBuffer (GmValueAccessor *ac, const GmValueInfo *info) const
 If the given accessor is a tracked accessor with an underlying data buffer and the accessor does NOT accept functions, the data is not stored in a sparse format and there is no unit or data type conversion, returns the buffer. Otherwise, returns NULL.
 
const H5::PredType & hdf5Type (GmStorageType type) const
 Returns the compatible HDF5 type for the given GmStorageType, obeying the _singlePrecision flag.
 
void addTableAttributes (H5::H5Object *obj, const GmMesh *mesh, const char *type, const GmDiscontinuitySet *discSet=NULL)
 Add metadata attributes common to all tables.
 
void addNodeAttributes (H5::H5Object *obj, const GmMesh *mesh, const GmFileFilter *filter)
 Add metadata attributes to obj describing the set of saved nodes.
 
void addCellAttributes (H5::H5Object *obj, const GmCellMesh *mesh, const GmFileFilter *filter, int ruleIndex=-1)
 Add metadata attributes to obj describing the set of saved cells.
 
void addAcAttributes (H5::H5Object *obj, const GmValueInfo *info, QString unit, int dimFilter, const double *scaleFactor=NULL, const double *offset=NULL)
 Add metadata attributes to obj describing the saved data.
 
void addPropertySetAttributes (H5::H5Object *obj, const GmCellMesh *mesh, int propertySet)
 Add metadata attributes describing the property set.
 
void addDiscSetNodeAttributes (H5::H5Object *obj, const GmDiscontinuitySet *discSet, bool original, const UnitConverter *conv, const double *scaleFactor, const double *offset)
 Add metadata attributes describing the discontinuity set nodes.
 
void addDiscSetTopologyAttributes (H5::H5Object *obj, const GmDiscontinuitySet *discSet, bool original)
 Add metadata attributes describing the discontinuity set topology.
 

Static Private Member Functions

static void addAttribute (H5::H5Object *obj, QString name, int value)
 Adds an int attribute to the given object.
 
static void addAttribute (H5::H5Object *obj, QString name, unsigned value)
 Adds an unsigned int attribute to the given object.
 
static void addAttribute (H5::H5Object *obj, QString name, double value)
 Adds a double attribute to the given object.
 
static void addAttribute (H5::H5Object *obj, QString name, bool value)
 Adds a boolean attribute to the given object.
 
static void addAttribute (H5::H5Object *obj, QString name, const char *value)
 Adds a string attribute to the given object.
 
static void addAttribute (H5::H5Object *obj, QString name, QString value)
 Adds a string attribute to the given object.
 
static void addAttribute (H5::H5Object *obj, QString name, const QStringList &value)
 Adds the given string list as a vector attribute.
 
static void addAttribute (H5::H5Object *obj, QString name, unsigned n, const int *values)
 Adds an int vector attribute to the given object.
 
static void addAttribute (H5::H5Object *obj, QString name, unsigned n, const unsigned *values)
 Adds an unsigned vector attribute to the given object.
 
static void addAttribute (H5::H5Object *obj, QString name, unsigned n, const double *values)
 Adds a double vector attribute to the given object.
 
template<class T >
static void addScalarAttribute (H5::H5Object *obj, QString name, const H5::PredType &type, T value)
 Writes a "generic" attribute to the given object. Template type T must be compatible with the given HDF5 type.
 
template<class T >
static void addVectorAttribute (H5::H5Object *obj, QString name, const H5::PredType &type, unsigned n, const T *values)
 Writes a "generic" vector attribute to the given object. Template type T must be compatible with the given HDF5 type.
 

Private Attributes

const GmLogCategory_logger
 The logger used to report errors.
 
QString _fileName
 The hdf5 file name.
 
H5::H5File * _fileh
 The hdf5 file handle.
 
const GmFileFormat_fileFormat
 The file format object specifying the desired topology order.
 
bool _singlePrecision
 Should we force real data to be saved in single precision (floats instead of doubles)?
 

Detailed Description

A support class for saving data to a HDF5 file. Hdf5 files are self-describing but do not have a fixed semantic, so this file is usally accompanied by another file that describes the semantic of the tables exported in the HDF5 file.

This class can export node geometry, cell topology, node data, cell data and Gauss data. Each data set is exported as a single table. A file format object is used, when exporting cell topology, to define which types of cells can be exported and also their node orderings. This is used to comply with reader requirements (Paraview, for example).

Member Function Documentation

◆ create()

bool GmHdf5::create ( QString  fileName,
const GmFileFormat fileFormat,
const GmSimulationData simData,
bool  singlePrecision,
int  sequenceNumber 
)

Creates a new HDF5 file. If it already exists, it will be replaced. The file is initialized with some metadata attributes and the simulation description from simData. The given file format object is used to define which types of cells can be exported and also their node orderings.

When sequence number is different from 0, assumes that the caller is splitting the data in multiple HDF5 files. This has the effect of adding a sequence number attribute to the created file. A call to the static addNumSequences() method, after the end of the save operation, can be used to add the number of sequences to the "main" file.

◆ fillDiscontinuityPolylineData()

template<class T >
bool GmHdf5::fillDiscontinuityPolylineData ( const GmDiscontinuitySet discSet,
bool  original,
const UnitConverter conv,
const double *  scaleFactor,
const double *  offset,
QVector< T > &  nodes,
QVector< int > &  topology,
int *  nsegments 
) const
private

Helper function used by saveDiscontinuitySetData() to fill the nodes and topology vectors with the polyline discontinuity geometric data that will be saved. See the caller function for a description of the input parameters. Returns true on success, false on out of memory error.

When preparing the topology vector, original data will be prepared as one polyline per discontinuity while for intersection data a bar will be saved for each one.

The template parameter should be double or float if _singlePrecision is true.

◆ saveDiscontinuitySetData()

bool GmHdf5::saveDiscontinuitySetData ( QString  coordDsName,
QString  cellDsName,
const GmDiscontinuitySet discSet,
bool  original,
const UnitConverter conv,
const double *  scaleFactor,
const double *  offset,
int *  numNodes,
int *  numSegments,
int *  dataSize 
)

Saves discontinuity set geometry data to a pair of new HDF5 data sets (one for node coordinates.

  • one for cell topology). Some basic mesh metadata is also saved in the form of attributes.

IMPORTANT: The current implementation only accepts GM_DISC_POLYLINE set types.

Parameters
coordDsNameThe new data set name where coordinates will be stored
cellDsNameThe new data set name where cell topology will be stored
discSetThe discontinuity set object.
originalShould we save the original discontinuity data or the intersection information?
convIf not NULL, a unit converter that should be used to convert coordinate units
scaleFactor,offsetAn optional pair of vectors defining an affine transformation that will be applied to each node coordinate (after unit conversion). If different from NULL, both vectors should be given and their sizes should be equal to the coordinate dimension. When given, the resulting coordinates will be equal to newx[i] = conv(x[i]) * scaleFactor[i] + offset[i]
numNodes,numSegments,dataSizeOutput parameters filled with the number of node coordinates and topology "segments" that where saved. If dataSize is not NULL, it is filled with the topology table size.
Returns
Returns true on success, false on errors (and logs message with the given logger)

◆ saveMeshCellData()

bool GmHdf5::saveMeshCellData ( QString  dsName,
const GmCellMesh mesh,
const GmFileFilter filter,
GmCellAccessor dataAc,
int  dimFilter 
)

Saves mesh cell data to a new HDF5 data set. Some basic mesh metadata is also saved in the form of attributes. The filter defining which mesh cells should be saved MUST be equal to the one given in the call to saveMeshTopology().

Parameters
dsNameThe new data set name
meshThe mesh that contains the cell data to be saved
filterThe filter object specifying which mesh cells should be saved according to the configured filters.
dataAcThe accessor providing cell data.
dimFilterA filter that can specify that only a single dimension of a vector (or matrix) data should be exported. Use -1 to specify that all dimensions should be saved.
Returns
Returns true on success, false on errors (and logs message with the given logger)

◆ saveMeshCellExtraColumn()

bool GmHdf5::saveMeshCellExtraColumn ( QString  dsName,
const GmCellMesh mesh,
const GmFileFilter filter,
GmFileIO::ExtraColumns  column,
int  propertySet 
)

Saves mesh cell extra column (cell id, type, active or material) data to a new HDF5 data set. Some basic mesh metadata is also saved in the form of attributes. The filter defining which mesh cells should be saved MUST be equal to the one given in the call to saveMeshTopology().

Parameters
dsNameThe new data set name
meshThe mesh that contains the cell property index (material) data to be saved
filterThe filter object specifying which mesh cells should be saved according to the configured filters.
columnThe column to be saved
propertySetThe property set index (remember that a mesh can be tied to several property sets) if column is CELL_MATERIAL_COLUMN.
Returns
Returns true on success, false on errors (and logs message with the given logger)

◆ saveMeshGaussData()

bool GmHdf5::saveMeshGaussData ( QString  dsName,
const GmElementMesh mesh,
const GmFileFilter filter,
int  ruleIndex,
GmGaussAccessor dataAc,
int  dimFilter 
)

Saves mesh Gauss data to a new HDF5 data set. Some basic mesh metadata is also saved in the form of attributes. The filter defining which mesh cells should be saved MUST be equal to the one given in the call to saveMeshGaussNodeCoord().

Parameters
dsNameThe new data set name
meshThe mesh that contains the Gauss data to be saved
filterThe filter object specifying which mesh cells should be saved according to the configured filters and the used integration rule set.
ruleIndexThe index in filter of the integration rule in use
dataAcThe accessor providing Gauss data.
dimFilterA filter that can specify that only a single dimension of a vector (or matrix) data should be exported. Use -1 to specify that all dimensions should be saved.
Returns
Returns true on success, false on errors (and logs message with the given logger)

◆ saveMeshGaussIdColumn()

bool GmHdf5::saveMeshGaussIdColumn ( QString  dsName,
const GmElementMesh mesh,
const GmFileFilter filter,
int  ruleIndex 
)

Saves mesh Gauss point ID data to a new HDF5 data set. Some basic mesh metadata is also saved in the form of attributes. The filter defining which mesh cells should be saved MUST be equal to the one given in the call to saveMeshGaussNodeCoord().

Parameters
dsNameThe new data set name
meshThe mesh that contains the Gauss data to be saved
filterThe filter object specifying which mesh cells should be saved according to the configured filters and the used integration rule set.
ruleIndexThe index in filter of the integration rule in use
Returns
Returns true on success, false on errors (and logs message with the given logger)

◆ saveMeshGaussNodeCoord()

bool GmHdf5::saveMeshGaussNodeCoord ( QString  dsName,
const GmElementMesh mesh,
const GmFileFilter filter,
int  ruleIndex,
GmValueAccessor nodeAc,
const double *  scaleFactor,
const double *  offset 
)

Saves the coordinates of the mesh Gauss points, as if they where mesh nodes, to a new HDF5 data set. Some basic mesh metadata is also saved in the form of attributes.

The saved cells whose integration points will be saved follow the set of exported cells defined by the given filter, which also defines the used rule set.

Parameters
dsNameThe new data set name
meshThe mesh to be saved
filterThe filter object specifying which mesh cells should be saved according to the configured filters.
ruleIndexThe index in filter of the integration rule in use
nodeAcThe accessor providing node coordinates. Usually this is the standard mesh node coordinate accessor but it can be an alternate value accessor. Used to get cell node coordinates that in turn are used to get integration point coordinates.
scaleFactor,offsetAn optional pair of vectors defining an affine transformation that will be applied to each node coordinate. If different from NULL, both vectors should be given and their sizes should be equal to the coordinate dimension. When given, the resulting coordinates will be equal to x[i] = nodeAc->value(node)[i] * scaleFactor[i] + offset[i]
Returns
Returns true on success, false on errors (and logs message with the given logger)

◆ saveMeshNodeCoord()

bool GmHdf5::saveMeshNodeCoord ( QString  dsName,
const GmMesh mesh,
const GmFileFilter filter,
GmValueAccessor nodeAc,
const double *  scaleFactor,
const double *  offset 
)

Saves mesh geometry (node coordinates) to a new HDF5 data set. Some basic mesh metadata is also saved in the form of attributes.

If exporting mesh cells require additional nodes for adapting cell geometry, the needed nodes will be given by an extraNodes object provided by filter. Those nodes will be added just after the (filtered) regular set of mesh nodes, with their values calculated as a mean of the vertex values from the edges where the extra nodes where inserted.

Parameters
dsNameThe new data set name
meshThe mesh to be saved
filterThe filter object specifying which mesh nodes should be saved according to the configured filters, including eventual extra nodes due to cell type transformations required by the current file format.
nodeAcThe accessor providing node coordinates. Usually this is the standard mesh node coordinate accessor but it can be an alternate value accessor.
scaleFactor,offsetAn optional pair of vectors defining an affine transformation that will be applied to each node value. If different from NULL, both vectors should be given and their sizes should be equal to the coordinate dimension. When given, the resulting coordinates will be equal to x[i] = nodeAc->value(node)[i] * scaleFactor[i] + offset[i]
Returns
Returns true on success, false on errors (and logs message with the given logger)

◆ saveMeshNodeData()

bool GmHdf5::saveMeshNodeData ( QString  dsName,
const GmMesh mesh,
const GmFileFilter filter,
GmValueAccessor dataAc,
int  dimFilter 
)

Saves mesh node data to a new HDF5 data set. Some basic mesh metadata is also saved in the form of attributes. The filter defining which mesh nodes should be saved MUST be equal to the one given in the call to saveMeshNodeCoord().

Parameters
dsNameThe new data set name
meshThe mesh that contains the node data to be saved
filterThe filter object specifying which mesh nodes should be saved according to the configured filters, including eventual extra nodes due to cell type transformations required by the current file format.
dataAcThe accessor providing node data.
dimFilterA filter that can specify that only a single dimension of a vector (or matrix) data should be exported. Use -1 to specify that all dimensions should be saved.
Returns
Returns true on success, false on errors (and logs message with the given logger)

◆ saveMeshNodeIdColumn()

bool GmHdf5::saveMeshNodeIdColumn ( QString  dsName,
const GmMesh mesh,
const GmFileFilter filter 
)

Saves mesh node ids to a new HDF5 data set. Some basic mesh metadata is also saved in the form of attributes. The filter defining which mesh nodes should be saved MUST be equal to the one given in the call to saveMeshNodeCoord().

Parameters
dsNameThe new data set name
meshThe mesh that contains the node data to be saved
filterThe filter object specifying which mesh nodes should be saved according to the configured filters, including eventual extra nodes due to cell type transformations required by the current file format.
Returns
Returns true on success, false on errors (and logs message with the given logger)

◆ saveMeshTopology()

bool GmHdf5::saveMeshTopology ( QString  dsName,
const GmCellMesh mesh,
const GmFileFilter filter 
)

Saves mesh topology (cell node incidence list) to a new HDF5 data set. Some basic mesh metadata are also saved in the form of attributes.

If the mesh is homogeneous, the saved data will be a 2 dimensional table with the number of lines equal to the number of exported cells and the number of columns equal to the number of cell nodes. Otherwise, it will be a single "vector" with consecutive cell data, where each cell data contains a cell type followed by its incidence list.

For each cell, the exported cell type and node ordering can be different from the natural GeMA cell type and node ordering as defined by the _fileFormat object.

If extra nodes are needed for exporting some cell types, they should be provided by the extraNodes object (from the filter object). This function expects extra nodes NOT to be shared between neighbor elements and to have been emmited in the mesh cell list order and, for each cell, in the same order that they appear in the node ordering vector returned by file format.

When traversing the cell list, finding an unsuported cell type causes the function to silently ignore it. Keep in mind that this will change the cell ordering in the saved file with respect to the original GeMA ordering (as will all other cell filters).

If the original mesh node numbers where renumbered (usualy when removing nodes used only by inactive cells), the given nodeMap (from the filter object) will be used to adjust the saved node numbers.

NOTE: Ghost nodes are NEVER added to the topology. Even if we wanted to do that, we lack information for defining a correct topology with the added ghost nodes.

Parameters
dsNameThe new data set name
meshThe mesh to be saved
filterThe filter object specifying which mesh cells should be saved according to the configured filters, also providing eventual extra nodes due to cell type transformations required by the current file format.
Returns
Returns true on succes, false on errors (and logs message with the given logger)

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