![]() |
GemaCoreLib
The GeMA Core library
|
A file serializer for saving data in the "Xdmf (Hdf5)" file format. More...
#include <gmXdmfFileWriter.h>
Public Member Functions | |
GmXdmfFileWriter (const GmLogCategory &logger) | |
Default constructor. | |
virtual | ~GmXdmfFileWriter () |
Destructor. | |
virtual bool | createFiles (QString fileName, const GmSimulationData *simData, const GmFileFilter *filter, const QVariantMap &options, bool multipleResults, bool gaussValues, bool discValues, GmFileIO::DumpMode dumpMode, QString timeUnit) |
virtual bool | setCurrentTime (int iter, double time) |
Sets the current time step, valid for the next calls to saveGeometry() and/or saveData(). This function IS CALLED even for single time step files in order to allow them to register the information. The first call is done with iter equal to 1, unless this is a single time step file, when iter will have a value of 0. Can return false on errors. | |
virtual bool | saveGeometry (GmValueAccessor *nodeAc, const double *scaleFactor, const double *offset) |
Save mesh node coordinates, cell geometry and gauss rule set coordinates (if needed) to the file, as defined by the filter object received on createFiles(). Returns false on errors. Node coordinates should be multiplied by the scale factor and sum the provided offset if the pointers are not NULL (they are either both NULL or both valid). When working with multiple time steps, this function is called at the first time step and then when the mesh changed (and the file format supports mesh changes) | |
virtual bool | saveDiscontinuities (const QVector< GmDiscontinuitySet * > &sets, GmFileIO::DiscontinuityDataMode mode, const UnitConverter *conv, const double *scaleFactor, const double *offset) |
Save discontinuity geometry data to the file. THe mode parameter defines which data should be saved. Returns false on errors. Node coordinates should be converted with the supplied converter (if not NULL) and also multiplied by the scale factor and sum the provided offset if the pointers are not NULL (they are either both NULL or both valid). When working with multiple time steps, this function is called at the first time step and then when the discontinuities changed (and the file format supports mesh changes) | |
virtual bool | saveData (const QVector< GmResultNodeDataSrc * > &nodeData, const QVector< GmResultCellDataSrc * > &cellData, const QVector< GmResultGaussDataSrc * > &gaussData, int extraColumns, const QVector< int > &propertySets) |
Saves the current result set to the file for the node, cells and Gauss points as defined by the filter object received on createFiles(). Will be called multiple times if multipleResults was true on the call to createFiles(). This function is always called, even if the data lists are empty, since special values defined by save options might need to be handled. The extra columns value is an or of the set of GmFilIO::ExtraColumns that should also be saved. If CELL_MATERIAL_COLUMN is in that set, the propertySets list informs for which property sets the material index should be saved. | |
virtual bool | closeFiles (bool deleteFiles=false) |
Closes the set of files opened by a call to createFiles(). Will be called automatically by the destructor (so may be called with a closed file). On errors, closeFiles is called with deleteFiles == true and should remove the created files. | |
virtual void | flushFiles () |
Flush opened files. | |
virtual GmFileFormat * | fileFormat () |
Returns the file format of the serializer. | |
virtual bool | dumpSupport () const |
This function should return true if this serializer supports saving dump files. | |
virtual bool | addSavedItemsToMap (QVariantMap &map) |
This function should add to map any internal serializer state that must be saved on a dump operation, returning false on errors. More... | |
virtual bool | loadSavedItemsFromMap (QVariantMap &map) |
This function should retrieve from the given map any internal writer state that was saved on a dump operation and now restored, returning false on errors. It should also be used to make any adjustments needed on the save files when restoring a state. | |
![]() | |
GmFileWriter (const GmLogCategory &logger) | |
Constructor. Receives as parameter the logger used to report errors. | |
virtual | ~GmFileWriter () |
Destructor. Should call closeFiles() on derived classes. | |
virtual bool | createFiles (QString fileName, const GmSimulationData *simData, const GmMesh *mesh, const QVariantMap &options, int numNodeValues, int numElemValues, int intRuleSet, bool multipleResults) |
virtual bool | saveNodeCoordinates (const GmMesh *mesh, GmValueAccessor *nodeAcc, QList< double > &scaleFactor, QList< double > &offset) |
Save mesh node coordinates to the file. Returns false on errors. Node coordinates should be multiplied by the scale factor and sum the provided offset. | |
virtual bool | saveCellGeometry (const GmCellMesh *mesh) |
Saves cell geometry to the file. Returns false on errors. | |
virtual bool | saveNodeData (const GmMesh *mesh, const QList< GmValueAccessor * > &accList, int iter, double currentTime, bool split) |
Saves node data to the file. The accList parameter contains accessors for the values to be saved. Returns false on errors. Will be called multiple times if the parameter multipleResults was true on the call to createFiles(). | |
virtual bool | saveElementData (const GmCellMesh *mesh, const QList< GmCellAccessor * > &elemAccList, const QList< GmGaussAccessor * > &gaussAccList, int iter, double currentTime, bool split) |
Saves element data to the file. The accessor lists parameters contains accessors for the values to be saved. Returns false on errors. Will be called multiple times if the parameter multipleResults was true on the call to createFiles(). | |
virtual QString | tempFile () |
Returns, if any, the name of the temp file used for the operation started with createFiles() | |
![]() | |
virtual const char * | formatName () const |
Returns the file format name. | |
virtual bool | supportsMultipleIterations () const |
Returns true if this file type supports multiple iterations (result sets) | |
virtual bool | acceptsNodeDimension (int ndim) const |
Returns true if this file format accepts meshes with nodes of the given dimension. | |
virtual int | acceptsCellType (GmCellType type) const |
Does the file format accepts this cell type? Returns 0 if the cell type is not accepted, 1 if it is natively accepted or 2 if it is accepted requiring standard Gema transformations for adjusting interface elements that need extra interpolated nodes to be exported. | |
virtual const QVector< int > & | cellNumbering (GmCellType type) const |
Returns the node cell type numbering order in the file format view or an empty vector for unsupported types. More... | |
virtual int | fileCellType (GmCellType type) const |
Returns the cell type code as seen by the file format. Currently used only by HDF5 based formats. | |
virtual const char * | fileCellTypeName (GmCellType type) const |
Returns the cell type name as seen by the exported file format. | |
virtual bool | acceptsDataType (const GmValueInfo *info, int nodeDim, int dimFilter=-1) const |
Returns true if this file format can save node/element data with the specified type (especially its dimension and value set kind). The nodeDim parameter provides the mesh node dimension since some file formats only accept vectors and matrices with the same size as the mesh dimension. The dimFilter parameter specifies if a dimension filter will be applied to the data or not (dimFilter == -1) | |
virtual bool | acceptsMultipleGaussProfiles () const |
Does the file supports multiple Gauss points per element type? | |
virtual bool | acceptsGaussRuleForElement (GmCellType type, const GmIntegrationRule *ir) const |
Does the file support exporting data at Gauss points for an element of type type with the supplied integration rule? | |
virtual bool | acceptsDiscontinuitySet (GmDiscontinuitySet::DiscontinuityType type) const |
virtual bool | supportsSplitVectors () const |
Returns true if this writer prefers to split vector values into scalar values by itself. | |
virtual bool | supportsMeshChanges () const |
Returns true if this writer can cope with mesh changes during the simulation. | |
Private Member Functions | |
const char * | tab () const |
Helper function returning the current identation as space string. | |
QString | meshPath (int rule=-1) const |
Returns the root mesh path. The mesh name is the mesh id with an added suffix if rule >= 0. | |
QString | discontinuityPath (QString dsName, bool original) const |
Returns the root discontinuity set path. | |
QString | path (const char *baseName, int rule, int iter) const |
Returns tha group path for the given base name. The name is composed by the mesh name, the base name and the iteration number, if iter > 0. The mesh name is the mesh id with an added suffix if rule >= 0. | |
QString | geometryPath (int iter=0) const |
Returns the HDF5 geometry path for the given iteration group or for the single iteration group if iter is 0. | |
QString | discontinuityGeometryPath (QString dsName, bool original, int iter=0) const |
Returns the HDF5 geometry path for the given discontinuity set for the iteration group or for the single iteration group if iter is 0. | |
QString | nodeDataPath (int iter=0) const |
Returns the HDF5 node data path for the given iteration group or for the single iteration group if iter is 0. | |
QString | cellDataPath (int iter=0) const |
Returns the HDF5 cell data path for the given iteration group or for the single iteration group if iter is 0. | |
QString | gaussGeometryPath (int rule, int iter=0) const |
Returns the HDF5 gauss geometry path for the given integration rule and iteration group or for the single iteration group if iter is 0. | |
QString | gaussDataPath (int rule, int iter=0) const |
Returns the HDF5 gauss data path for the given integration rule and iteration group or for the single iteration group if iter is 0. | |
QString | adjustSequenceInName (QString path, int seq) const |
Replaces in path the placeholder for the file sequence number. If seq != -1, that value is used instead of _currSequence. | |
QString | hdf5Name (int seq=-1) const |
Returns the Hdf5 file name, with sequence mask replaced, if any. If seq != -1, that value is used instead of _currSequence. | |
QString | hdf5Prefix (int seq=-1) const |
Returns the Hdf5 file name without path, with sequence mask replaced, if any. If seq != -1, that value is used instead of _currSequence. | |
bool | createCurrentHdf5File () |
Create the current HDF5 file. When saving in multiple sequence files, expects that _currSequence is already updated with the number of the created file. | |
void | closeCurrentHdf5File (bool onError=false) |
Closes the current HDF5 file. | |
void | partialFileNames (QString &writingName, QString &partialName) const |
Fills writingName and partialName with the apropriate file names depending on the _lastPartialSuffix value. | |
bool | savePartialFile () |
Saves a "partial" xdmf control file by duplicating the contents of the main xdmf file and closing it with the missing XML sections needed to create a valid file that can be viewed. More... | |
bool | removeOldFiles (bool partialOnly) |
Removes old hdf5 files and partial xdmf files, returning true if they do not exist or where successfully removed. Returns false if they exist an could not be removed. More... | |
void | addMeshGeometryEntries (QString basePath, bool pointCloud, int ruleIndex=-1) |
Add to the output XDMF file the required geometry and topology entries whose data is stored at the given geometry group. | |
void | addMainSection (bool start, const GmSimulationData *simData) |
Add to the output Xdmf file the file header / trailler. simData is needed only when start is true. | |
void | addTimeCollectionSection (bool start) |
Add to the output Xdmf file the Grid colletion for a temporal analysis. | |
void | addSpatialCollectionSection (bool start) |
Add to the output Xdmf file a spatial colletion for grouping several meshes. | |
void | addGridCollectionSection (bool start) |
Add to the output Xdmf file a grid section named after the current mesh. If the saved data includes Gauss data and several time steps, a top level Spatial collection grid is also generated. | |
void | addGridGaussSection (bool start, int rule=-1) |
Add to the output Xdmf file a grid section named after the current mesh and rule set (if different from -1). | |
void | addGridDiscontinuitySection (bool start, QString dsName, bool original) |
Add to the output Xdmf file a grid section named after the current mesh and the given discontinuity set name. | |
void | addGeometryEntry (QString tableName, int nlin, int ncol, QString unit, GmStorageType storage, bool forDiscontinuity=false) |
Add to the output Xdmf file a geometry entry. | |
void | addTopologyEntry (QString tableName, int cellType, int numElem, int dataSize, bool forDiscontinuity=false) |
Add to the output Xdmf file a topology entry. If cellType is -1, a mixed topology is generated and dataSize should be equal to the size exported for the table. Otherwise, data size is ignored (the data is multidimensional and the number of columns equal to the number of nodes per cell) | |
void | addNodeTopologyEntry (QString tableName, int numNodes) |
Add to the output Xdmf file a topology entry for a mesh that has no cells. If tableName is empty, no data item will be added and the resulting mesh will have no cells. | |
void | addDataAttributeEntry (QString tableName, QString name, QString unit, bool node, int nlin, int ncol1, int ncol2, GmStorageType storage) |
Add to the output Xdmf file an attribute data entry. The node attribute defines if the attribute is tied to a node or a cell. ncol1 and ncol2 are the attributes dimension. They should be BOTH 1 for scalar values and ncol2 should be 1 for vector values. | |
void | addDataItemEntry (QString tableName, int d1, int d2, int d3, GmStorageType storage, int seq) |
Add to the output Xdmf file a data item entry. | |
Private Attributes | |
const GmSimulationData * | _simData |
The simulation data object. | |
const GmFileFilter * | _filter |
The filter object specifying which nodes and elements should be saved. | |
QString | _fileName |
The Xdmf file name. | |
FILE * | _xdmfh |
The handle for the xdmf control file. | |
QString | _hdf5Name |
The Hdf5 file name, possibly including a "%1" mask to be replaced by the file sequence number if _splitHDF5Files > 0. | |
QString | _hdf5Prefix |
The Hdf5 file name without path (mask included, if any), as used on the xml file to reference an hdf5 table. | |
GmHdf5 * | _hdf5 |
The hdf5 helper object. | |
GmFileIO::DumpMode | _dumpMode |
The dump mode with wich the file was created. | |
QByteArray | _ident |
The "current identation level" in calls to addXxxxSection() | |
bool | _openGrid |
Is there an open grid section in the XDMF file? | |
bool | _multiTime |
Will this file be used for saving multiple time steps? | |
bool | _multiGrid |
Do we need to save multiple grids (per time step)? True when allso saving Gauss data or discontinuity set data. | |
bool | _gaussMultiGrid |
Set to true if we need to save Gauss data (as a point cloud) | |
bool | _dsMultiGrid |
Set to true if we need to save Discontinuity set data. | |
int | _splitHDF5Files |
0 for a single file. Otherwise, splits the file every _splitHDF5Files iterations | |
int | _savePartialXdmfFile |
0 if no partial files are created. When > 0, must be a multiple of _splitHDF5Files | |
bool | _saveCloudPointTopology |
Should we save a "cell topology" vector for point clouds? | |
double | _startTime |
The simulation start time or the only time if the simulation has a single time step. | |
double | _currTime |
The current simulation time or the only time if the simulation has a single time step. | |
int | _currIter |
The current save iteration number (0 if the simulation has a single time step) | |
QString | _timeUnit |
The unit in which time values are expressed. | |
int | _currSequence |
The current HDF5 file sequence if _splitHDF5Files > 0. Starts with 1. Set to 0 otherwise. | |
double | _sequenceStartTime |
The simulation time at the moment that the current sequence was opened. | |
bool | _newHDF5File |
A flag set to true whenever a new HDF5 is created and reset after node, cell and gauss data groups where added to the file. | |
int | _lastGeometryIter |
The last iteration number where the mesh geometry was saved. -1 if not saved yet. 0 for single time step. | |
int | _lastGeometrySequence |
The last sequence file where the mesh geometry was saved. -1 if not saved yet. 0 for single sequence. | |
int | _lastDiscontinuityIter |
The last iteration number where discontinuity data was saved. -1 if not saved yet. 0 for single time step. | |
int | _lastDiscontinuitySequence |
The last sequence file where discontinuity data was saved. -1 if not saved yet. 0 for single sequence. | |
int | _lastPartialXdmfOffset |
The offset of the last "regular" byte from the main xdmf file that was saved to the partial file. | |
int | _lastPartialSuffix |
The last suffix number applied to the partial xdmf file name. If 0, no suffix was applied. | |
int | _geometryDim |
The geometry node dimension. | |
GmStorageType | _geometryStorage |
The storage type for node coordinates. | |
QString | _geometryUnit |
The unit for node coordinates. | |
bool | _singlePrecision |
Should we force real data to be saved in single precision (floats instead of doubles)? | |
QStringList | _dsNames |
The names of the discontinuity sets. | |
GmFileIO::DiscontinuityDataMode | _dsMode |
The saving mode for the discontinuity sets. | |
QVector< int > | _dsSizes |
The last number of nodes/cells for the original / intersection data when the discontinuity data was last saved, for EACH entry in _dsNames. The first 5 entries (original num_nodes, num_elem, data_size + intersection num_nodes, num_elem) correspond to _dsNames[0], the next five to _dsNames[1] and so on. | |
Additional Inherited Members | |
![]() | |
static void | registerSupportedCellType (GmCellType type, SupportedTypesT &&cellData) |
Registers the information needed about each element type to save it on the Xdmf file. An entry for each supported cell type should be registered before any attempt to save a file. More... | |
![]() | |
const GmLogCategory & | _logger |
The logger used to report errors. | |
A file serializer for saving data in the "Xdmf (Hdf5)" file format.
|
virtual |
This function should add to map any internal serializer state that must be saved on a dump operation, returning false on errors.
To avoid naming conflicts, each added key should have a prefix unique to this writer.
Reimplemented from GmFileWriter.
|
private |
Removes old hdf5 files and partial xdmf files, returning true if they do not exist or where successfully removed. Returns false if they exist an could not be removed.
The flag controls if we are deleting hdf5 and xdmf files or xdmf only.
|
private |
Saves a "partial" xdmf control file by duplicating the contents of the main xdmf file and closing it with the missing XML sections needed to create a valid file that can be viewed.
Saving the partial file is always done to a temporary "writing" file that is later renamed to a "partial" file when the saving is finished. This prevents any readers to see unfinished files. When saving a partial file a second (or later) time, we try to rename the last partial file to the "writing" name and update it. if that is not possible due to the file being in use, we create another partial file adding a numeric suffix to it.
For this routine to work, it expects that: