GemaCoreLib
The GeMA Core library
Loading...
Searching...
No Matches
GmNfFileWriter Class Reference

A file serializer for saving data in the "Neutral File" file format. More...

#include <gmNfFileWriter.h>

Inheritance diagram for GmNfFileWriter:
Collaboration diagram for GmNfFileWriter:

Classes

struct  CellOrder
 

Public Member Functions

 GmNfFileWriter (const GmLogCategory &logger)
 Default constructor.
 
virtual ~GmNfFileWriter ()
 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< GmNodeAcResultsDataSrc * > &nodeData, const QVector< GmCellAcResultsDataSrc * > &cellData, const QVector< GmGaussAcResultsDataSrc * > &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 endWrite ()
 
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 QString tempFile ()
 Returns, if any, the name of the temp file used for the operation started with createFiles()
 
virtual void flushFiles ()
 Flush opened files.
 
virtual GmFileFormatfileFormat ()
 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.
 
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.
 
- Public Member Functions inherited from GmFileWriter
 GmFileWriter (const GmLogCategory &logger)
 Constructor. Receives as parameter the logger used to report errors.
 
virtual ~GmFileWriter ()
 Destructor. Should call closeFiles() on derived classes.
 
- Public Member Functions inherited from GmNfFileFormat
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 supportsSplitVectors () const
 Returns true if this writer prefers to split vector values into scalar values by itself.
 
virtual bool acceptsNodeDimension (int ndim) const
 Returns true if this file format accepts meshes with nodes of the given dimension.
 
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 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.
 
virtual const QVector< int > & gaussNumbering (GmCellType type, int numIp) const
 Returns the Gauss point numbering order for a given cell type and number of integration points. Returns an empty vector for unsupported types.
 
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 supportsMeshChanges () const
 Returns true if this writer can cope with mesh changes during the simulation.
 
- Public Member Functions inherited from GmFileFormat

Private Types

using wNFunc = std::function<int(char*, int)>
 
using wCFunc = std::function<int(char*, CellOrder, const GmCell*)>
 
using wGFunc = std::function<int(char*, CellOrder, int, const GmCell*, const GmIntegrationRule*)>
 
using GetCoord = std::function<const GmVector* (const GmCell*, GmVector*)>
 

Private Member Functions

bool copyResultData (FILE *srcFile, FILE *dstFile, qint64 size=0)
 Appends size bytes from srcFile to dstFile.
 
void writeHeader ()
 
void saveNodeCoordinates (GmValueAccessor *nodeAcc, const QVector< int > &indexer, const double *scaleFactor, const double *offset)
 
void saveMeshTopology (const GmCellMesh *mesh)
 
int fillExtraNodesIndex (const GmMesh *mesh, const GmValueAccessor *nodeAc)
 
void writeResultsHeader ()
 
void findMaterialGroup (const GmMesh *mesh, const QVariantMap &options)
 Set _materialGroup with the property set index that will be used to exposrt material inidces.
 
void saveMaterialGroup (const GmCellMesh *mesh)
 Save material information.
 
void saveIntegrationRules (const GmElementMesh *mesh)
 Save integration rule information and fills _elementRule with the mapping between types and integration ids in the file.
 
bool saveNodeData (const QVector< GmNodeAcResultsDataSrc * > &nodeData, int extraCol)
 
void saveDisplacement (GmValueAccessor *ac, const QVector< int > &indexer)
 
bool saveCellGaussData (const QVector< GmCellAcResultsDataSrc * > &cellData, const QVector< GmGaussAcResultsDataSrc * > &gaussData, int extraCol)
 
void fillNodeCoordBuffer (const GmValueAccessor *cac, int start, int count, const double *scale, const double *offset, const QVector< int > &indexer, GmFileIOUtils::GmWBuffer &buf)
 
void fillCellTopoBuffer (const GmCellMesh *mesh, int start, int count, int nnodes, const char *afterMaterial, const char *afterNode, const QVector< int > &nodeNumbering, const QVector< CellOrder > &indexer, GmFileIOUtils::GmWBuffer &buf)
 
int fillCellIndexerPerType (QVector< CellOrder > order[GM_NUM_CELL_TYPES], bool checkIr=false)
 
int buildNodeFunctions (const QVector< GmNodeAcResultsDataSrc * > &prop, const QVector< int > &indexer, int extraCol, QVector< wNFunc > &func, GmValueAccessor **dispAc, QString &header)
 
int buildCellFunctions (const QVector< GmCellAcResultsDataSrc * > &prop, int extraCol, const GetCoord &getCoord, QVector< wCFunc > &func, QString &header)
 
int buildGaussFunctions (const QVector< GmGaussAcResultsDataSrc * > &prop, int extraCol, QVector< wGFunc > &func, QString &header)
 

Private Attributes

const int maxNodeIdChars = 10
 
QString _nfFileName
 The neutral file file name.
 
FILE * _nfFile
 The neutral file file handle.
 
FILE * _tempFile
 The temporary file file handler (used for multiple result sets)
 
QTemporaryFile_tempFileObj
 The Qt object used to safelly create the temp object in a "sane" place.
 
int _materialGroup
 The material group used to identify cell materials.
 
int _intRuleSet
 The mesh integration rule set that will be used to export values.
 
int _elementRule [GM_NUM_CELL_TYPES]
 The integration rule bound to each element type.
 
int _elementNip [GM_NUM_CELL_TYPES]
 
int _nresults
 The number of added result cases.
 
bool _saveDisplacements
 Save displacement data?
 
bool _useModelOrder
 Should we keep the internal node/cell order while saving or should we translate them to the original model numbering?
 
QVector< double > _extraNodes
 
const GmFileFilter_filter
 The file filter that was used to create the file.
 
const GmSimulationData_simData
 The simulation data that was used to create the file.
 
GmTaskManager_tm
 
bool _saveGaussData
 Should we save gauss point data?
 
bool _multipleResults
 Are we saving multiple result sets?
 
int _dumpMode
 

Additional Inherited Members

- Static Public Member Functions inherited from GmNfFileFormat
static void registerSupportedCellType (GmCellType type, SupportedTypesT &cellData)
 Registers the information needed about each element type to save it on the NF file. An entry for each supported cell type should be registered before any attempt to save a file.
 
- Protected Member Functions inherited from GmNfFileFormat
unsigned int offset (unsigned int n)
 
- Static Protected Member Functions inherited from GmNfFileFormat
static SupportedTypesTsupportedTypesList ()
 Returns the vector with the definition of the GeMA supported types and their mapping to xdmf types. The vector has GM_NUM_CELL_TYPES entries.
 
- Protected Attributes inherited from GmFileWriter
const GmLogCategory_logger
 The logger used to report errors.
 
- Static Protected Attributes inherited from GmNfFileFormat
static const nfrType nfrTypeTable []
 
static const nfrElement nfrElementTable []
 

Detailed Description

A file serializer for saving data in the "Neutral File" file format.

Member Function Documentation

◆ addSavedItemsToMap()

bool GmNfFileWriter::addSavedItemsToMap ( QVariantMap & map)
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.

◆ closeFiles()

bool GmNfFileWriter::closeFiles ( bool deleteFiles = false)
virtual

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.

Implements GmFileWriter.

◆ copyResultData()

bool GmNfFileWriter::copyResultData ( FILE * srcFile,
FILE * dstFile,
qint64 size = 0 )
private

Appends size bytes from srcFile to dstFile.

If size is 0, the whole contents will be appended. Assumes that the file pointer for dstFile is in the correct place. The src file is rewinded and ends in the end of the file or in position size.

On error, prints message and returns false

◆ createFiles()

bool GmNfFileWriter::createFiles ( QString fileName,
const GmSimulationData * simData,
const GmFileFilter * filter,
const QVariantMap & options,
bool multipleResults,
bool gaussValues,
bool discValues,
GmFileIO::DumpMode dumpMode,
QString timeUnit )
virtual

Implements GmFileWriter.

◆ dumpSupport()

bool GmNfFileWriter::dumpSupport ( ) const
virtual

This function should return true if this serializer supports saving dump files.

Reimplemented from GmFileWriter.

◆ endWrite()

bool GmNfFileWriter::endWrite ( )
virtual

Implements GmFileWriter.

◆ fileFormat()

virtual GmFileFormat * GmNfFileWriter::fileFormat ( )
inlinevirtual

Returns the file format of the serializer.

Implements GmFileWriter.

◆ flushFiles()

void GmNfFileWriter::flushFiles ( )
virtual

Flush opened files.

Implements GmFileWriter.

◆ loadSavedItemsFromMap()

bool GmNfFileWriter::loadSavedItemsFromMap ( QVariantMap & map)
virtual

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.

Reimplemented from GmFileWriter.

◆ saveData()

bool GmNfFileWriter::saveData ( const QVector< GmNodeAcResultsDataSrc * > & nodeData,
const QVector< GmCellAcResultsDataSrc * > & cellData,
const QVector< GmGaussAcResultsDataSrc * > & gaussData,
int extraColumns,
const QVector< int > & propertySets )
virtual

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.

Implements GmFileWriter.

◆ saveDiscontinuities()

virtual bool GmNfFileWriter::saveDiscontinuities ( const QVector< GmDiscontinuitySet * > & sets,
GmFileIO::DiscontinuityDataMode mode,
const UnitConverter * conv,
const double * scaleFactor,
const double * offset )
inlinevirtual

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)

Implements GmFileWriter.

◆ saveGeometry()

bool GmNfFileWriter::saveGeometry ( GmValueAccessor * nodeAc,
const double * scaleFactor,
const double * offset )
virtual

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)

Implements GmFileWriter.

◆ setCurrentTime()

bool GmNfFileWriter::setCurrentTime ( int iter,
double time )
virtual

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.

Implements GmFileWriter.

◆ tempFile()

QString GmNfFileWriter::tempFile ( )
virtual

Returns, if any, the name of the temp file used for the operation started with createFiles()

Reimplemented from GmFileWriter.


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