GemaCoreLib
The GeMA Core library
Loading...
Searching...
No Matches
gmHdf5ModelWriter.h
Go to the documentation of this file.
1/************************************************************************
2**
3** Copyright (C) 2014 by Carlos Augusto Teixera Mendes
4** All rights reserved.
5**
6** This file is part of the "GeMA" software. It's use should respect
7** the terms in the license agreement that can be found together
8** with this source code.
9** It is provided AS IS, with NO WARRANTY OF ANY KIND,
10** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
11** A PARTICULAR PURPOSE.
12**
13************************************************************************/
14
24#ifndef _GEMA_HDF5_MODEL_WRITER_H_
25#define _GEMA_HDF5_MODEL_WRITER_H_
26
27#include "gmLog.h"
28#include "gmHdf5Model.h"
29#include "gmPODVector.h"
30#include "gmCellType.h"
31#include "gmBoundaryCondition.h"
32#include "gmDiscontinuitySet.h"
33#include "gmNanBoxedValue.h"
34
35#include <QStringList>
36
37class GmModelData;
38class GmMesh;
39class GmCellMesh;
40class GmValueAccessor;
41class GmUserFunction;
42class GmNodeSet;
43class GmCellBoundary;
44
45namespace H5 {
46 class H5File;
47}
48
49
58{
59public:
60
61 GmHdf5ModelWriter(QString fileName, const GmLogCategory& logger);
63
64 void setInitialData(const QStringList& nodeAttributes, const QStringList& cellAttributes,
65 const QStringList& gaussAttributes);
66
67 bool saveFromModel(const GmModelData* data, QString modelName = "", QString meshName = "");
68
69 bool addNewMesh (QString meshName, QString modelName = "");
70 bool addDictionary(DictionaryType type, const QStringList& names);
71
72 bool addGeometryNodeCoordinates (int n, int d, const double* values, int nghost = 0);
73 bool addGeometryCells (int ncells, int size, const int* data);
74 bool addGeometryCellGhostNodes (int ncells, int size, const int* data);
75 bool addGeometryIndexTable (GroupType group, QString tableName, int n, const int* values);
76 bool addGeometryBorderTable (GroupType group, QString tableName, int n, const int* values);
77 bool addInitialData (GroupType group, QString attributeName, int n, int d, const double* values, bool hasFunctions, int history = -1);
78 bool addBoundaryCondition (QString bcName, GmBoundaryCondition::BcType type, int n, const int* data);
79 bool addBoundaryConditionProperty(QString bcName, QString propertyName, int n, int d, const double* values, bool hasFunctions);
80 bool addDiscontinuitySet (QString dsName, GmDiscontinuitySet::DiscontinuityType type, const QStringList& discontinuityNames);
81 bool addDiscontinuityPolyline (QString dsName, int index, int n, int d, const double* coordinates);
82 bool addDiscontinuitySurface (QString dsName, int index, int n, const double* coordinates, int ntri, const int* triangles);
83 bool addDiscontinuityEdgeList (QString dsName, int index, int n, const int* borderData);
84 bool addDiscontinuityFaceList (QString dsName, int index, int n, const int* borderData);
85
86
87 bool cellVectorBuildBegin(int npsets, int expectedSize);
88 bool cellVectorAddCell (GmCellType type, const int* propertyIndices, const int* nodeIndices);
89 const int* cellVectorBuildEnd (int* size);
90
91 bool cellGhostNodesVectorBuildBegin(int expectedSize);
92 bool cellGhostNodesVectorAddCell (int cellId, int numGhostNodes, const int* nodeIndices);
93 const int* cellGhostNodesVectorBuildEnd (int* size);
94
96 double dindexToNan(unsigned index) const
97 {
98 assert(index < (unsigned)_dictionaries[GM_HDF5MODEL_FUNCTIONS].size());
99 return GmNanBoxedIndex(index).toRawDouble();
100 }
101
108 double nanToCanonicNan(double v) const { return GmNanBoxedIndex(v, true).toDouble(); }
109
110private:
111 bool buildAndSaveFunctionsDictionary (const GmModelData* data);
112 bool buildAndSavePropertySetsDictionary(const GmCellMesh* mesh);
113 bool buildAndSaveCellGroupsDictionary (const GmCellMesh* mesh);
114 bool buildAndSaveNodeSetsDictionary (const GmMesh* mesh);
115 bool buildAndSaveCellBordersDictionary (const GmCellMesh* mesh);
116
117 bool saveMeshGeometryNodes (const GmMesh* mesh);
118 bool saveMeshGeometryNodeSets (const GmMesh* mesh);
119 bool saveMeshGeometryCells (const GmCellMesh* mesh);
120 bool saveMeshGeometryBoundaries(const GmCellMesh* mesh);
121 bool saveInitialData (const GmMesh* mesh);
122 bool saveBoundaryConditions (const GmMesh* mesh);
123 bool saveDiscontinuitySets (const GmModelData* data, const GmCellMesh* mesh);
124
125 int* cellVectorAddCell (GmCellType type);
126 int* cellGhostNodesVectorAddCell(int cellId, int numGhostNodes);
127
128 template <class T>
129 bool addDataTable(GroupType group, QString subGroup, QString tableName, int n, int d, const T* values);
130
131 template <class T, class A>
132 bool addDataTableWithAttributes(GroupType group, QString subGroup, QString tableName, int n, int d, const T* values,
133 const QStringList& attrNames, const QVector<A>& attrValues);
134
135
140 QString groupName(GroupType group, QString subGroupName) const { return GmHdf5Model::groupName(_currentMesh, group, subGroupName); }
141
142 bool createGroupIfNecessary(QString groupName);
143
144 void initSavedAttributeLists(const GmMesh* mesh);
145
146 bool initBuffer(const GmModelData* data, const GmMesh* mesh);
147 template<class T> T* getBuffer(int n);
148
149 double* getFilledDataBuffer(GmValueAccessor* ac, const GmMesh* mesh, bool* bufferHasFunctions = NULL);
150
153
158
166
168
169 H5::H5File* _fileh;
172
176
181};
182
183#endif
184
BcType
Boundary condition type defining where a BC is applied (node, edge or face)
Definition gmBoundaryCondition.h:62
This class stores a set of cell edges or cell faces that together form a piece of the boundary of a m...
Definition gmCellBoundary.h:44
Base interface class for CellMesh type plugins.
Definition gmCellMesh.h:40
DiscontinuityType
Discontinuity type (defining how the disc. geometry is defined)
Definition gmDiscontinuitySet.h:63
A helper class with enums and methods common to GmHdf5ModelWriter & GmHdf5ModelReader.
Definition gmHdf5Model.h:36
DictionaryType
Definition gmHdf5Model.h:40
QString groupName(QString meshName, GroupType group, QString subGroupName) const
Returns the group name for the given mesh / group type. If type is GM_HDF5MODEL_BC_GROUP or GM_HDF5MO...
Definition gmHdf5Model.cpp:61
GroupType
Definition gmHdf5Model.h:58
A class used to export parts of a GeMA model to an HDF5 file. Its API includes both GeMA centric func...
Definition gmHdf5ModelWriter.h:58
bool _userDefinedAttributes
Set to true if setInitialData() was called. Defines if the _savedXxxAttribtes vectors where user give...
Definition gmHdf5ModelWriter.h:157
QMap< const GmCellBoundary *, int > _edgeMap
Map for converting boundary edges to their associated dictionary entry.
Definition gmHdf5ModelWriter.h:179
double nanToCanonicNan(double v) const
If v is not a Quiet nan value, returns v. Otherwise, returns the canonical Quiet NA.
Definition gmHdf5ModelWriter.h:108
QString _fileName
The saved file name.
Definition gmHdf5ModelWriter.h:151
QMap< const GmCellBoundary *, int > _faceMap
Map for converting boundary faces to their associated dictionary entry.
Definition gmHdf5ModelWriter.h:180
QString _currentMesh
The name of the current mesh being saved.
Definition gmHdf5ModelWriter.h:170
const GmLogCategory & _logger
The logger used to emmit error messages.
Definition gmHdf5ModelWriter.h:152
QMap< const GmNodeSet *, int > _nodeSetMap
Map for converting node sets to their associated dictionary entry.
Definition gmHdf5ModelWriter.h:178
QVector< QPair< QString, int > > _savedCellAttributes
Like _savedNodeAttributes for cell attributes.
Definition gmHdf5ModelWriter.h:164
GmPODVector< char, size_t, GmPODVectorTightGrow > _saveBuffer
An auxiliar buffer that is used by save routines to build temporary data vectors.
Definition gmHdf5ModelWriter.h:167
QString groupName(GroupType group, QString subGroupName) const
Returns the group name for the given group type.If type is GM_HDF5MODEL_BC_GROUP or GM_HDF5MODEL_DS_G...
Definition gmHdf5ModelWriter.h:140
H5::H5File * _fileh
The hdf5 file handle.
Definition gmHdf5ModelWriter.h:169
QVector< QPair< QString, int > > _savedGaussAttributes
Like _savedNodeAttributes for Gauss attributes.
Definition gmHdf5ModelWriter.h:165
int _npsets
The number of property sets currently stored in the Property set dictionary.
Definition gmHdf5ModelWriter.h:175
QVector< QStringList > _dictionaries
The set of saved dictionaries. Indexed by DictionaryType.
Definition gmHdf5ModelWriter.h:173
double dindexToNan(unsigned index) const
Encodes a dictionary index into a nan entry.
Definition gmHdf5ModelWriter.h:96
QVector< QPair< QString, int > > _savedNodeAttributes
Either the user given or the auto defined set of node attributes & state vars whose values should be ...
Definition gmHdf5ModelWriter.h:163
QMap< QString, int > _userFunctionMap
Map for converting user functions to their associated dictionary entry.
Definition gmHdf5ModelWriter.h:177
QVector< const GmBoundaryCondition * > _currentMeshBcs
The set of boundary conditions associated with the current mesh.
Definition gmHdf5ModelWriter.h:171
QSet< QString > _fileGroups
A set used by ensureGroupExists to control the set of groups already created on the file.
Definition gmHdf5ModelWriter.h:174
Class representing a category with multiple logging levels.
Definition gmLog.h:58
Base interface class for Mesh type plugins.
Definition gmMesh.h:48
Auxiliar class used to store the complete set of model data for a simulation.
Definition gmModelData.h:53
A helper class to store an usigned index as the boxed nan value.
Definition gmNanBoxedValue.h:78
This class stores a set of nodes belonging to a mesh. The nodes can belong to the mesh boundary but t...
Definition gmNodeSet.h:34
A simple vector for Plain Old Data (POD) types with the control size variable type parameterized to a...
Definition gmPODVector.h:88
Class used to store the definition of a user function and its parameters.
Definition gmUserFunction.h:82
Interface class for accessing and setting values from an "indexable" collection of values.
Definition gmValueAccessor.h:60
Declaration of the GmBoundaryCondition class.
Declaration of the GmCellType enum.
GmCellType
Mesh Cell types. Don't change type orders or add types without reading comments below.
Definition gmCellType.h:31
#define GMC_API_EXPORT
Macro for controlling if the class is being exported (GEMA_CORE_LIB defined) or imported (GEMA_CORE_L...
Definition gmCoreConfig.h:35
Implementation of the GmDiscontinuitySet class.
Declaration of the GmHdf5Model class.
Declaration of support functions and macros for information logging.
Declaration of the GmNanBoxedValue class.
Implementation of the GmPODVector template class.