GemaCoreLib
The GeMA Core library
gmFileIO.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_FILE_IO_H_
25 #define _GEMA_FILE_IO_H_
26 
27 #include "gmCoreConfig.h"
28 
29 #include "gmStateDumpItem.h"
31 
32 #include <QStringList>
33 #include <QVariantMap>
34 
35 class GmFileReader;
36 class GmFileWriter;
37 class GmFileFormat;
38 class GmFileFilter;
39 
40 class GmLogCategory;
41 class GmSimulationData;
42 class GmMesh;
43 class GmCellMesh;
44 class GmElementMesh;
45 class GmCellGroupSet;
47 class GmDiscontinuitySet;
48 
52 
53 class GmValueInfo;
54 class GmValueSetData;
55 class GmValueAccessor;
56 class GmSpatialIndex;
57 class GmNumSolver;
58 
59 class UnitConverter;
60 
65 {
66 public:
68  enum DumpMode
69  {
71  DUMP,
73  };
74 
77  {
82  };
83 
85  enum ExtraColumns {
86  NODE_ID_COLUMN = 0x01,
87  CELL_ID_COLUMN = 0x02,
88  CELL_TYPE_COLUMN = 0x04,
89  CELL_ACTIVE_COLUMN = 0x08,
90  CELL_MATERIAL_COLUMN = 0x10,
91  GAUSS_ID_COLUMN = 0x20,
92  NODE_BC_COLUMN = 0x40,
93  // --- Combined options ---
94  NODE_COLUMNS = NODE_ID_COLUMN,
95  CELL_COLUMNS = CELL_ID_COLUMN | CELL_TYPE_COLUMN | CELL_ACTIVE_COLUMN | CELL_MATERIAL_COLUMN,
96  GAUSS_COLUMNS = GAUSS_ID_COLUMN,
97  };
98 
99  ~GmFileIO();
100 
101  static GmFileIO* createInstance(QString fileType, bool writeMode, const GmLogCategory& logger);
102 
103  bool setNodeData (LuaTable& tab, GmMesh* mesh, bool split);
104  bool setCellData (LuaTable& tab, GmCellMesh* mesh, bool split);
105  bool setGaussData(LuaTable& tab, GmElementMesh* mesh, bool split);
106 
107  bool saveData(QString fileName, const GmSimulationData* simData, GmMesh* mesh, const GmCellGroupSet* group, const QVariantMap& options);
108 
109  bool prepareForSaving(QString fileName, const GmSimulationData* simData, GmMesh* mesh, const GmCellGroupSet* group, const QVariantMap& options);
110 
111  bool saveCurrentResult(double currentTime, bool meshChanged = false, bool discChanged = false);
112  bool closeFile();
113 
114  QString tempFile();
115 
116  virtual bool addStateItemsToGroup(GmStateDump* state, int groupId);
117  virtual bool stateAboutToBeSaved (GmStateDump* state);
118  virtual bool stateLoaded (GmStateDump* state);
119 
120  static QString extraColumnName(ExtraColumns col, const GmCellMesh* mesh = NULL, int psIndex = -1);
121 
122 private:
123  GmFileIO(GmFileReader* reader, GmFileWriter* writer, const GmLogCategory& logger);
124 
125  Q_DISABLE_COPY(GmFileIO);
126 
127  template <class T, class Mesh, class DsF>
128  bool setData(LuaTable& tab, Mesh* mesh, const DsF& dsF, QVector<T*>& dataList, const char* entity, bool split);
129 
130  bool parseAndCheckDumpMode (bool multipleTimeSteps);
131  bool parseAndCheckStates (bool multipleTimeSteps, int* state, bool* allStates, QVector<double>& timeList);
132  bool parseAndCheckGaussRules(QVector<int>& rules);
133  bool parseAndCheckGaussInterpolationOptions(const GmSimulationData* simData);
134  bool parseAndCheckCoordAccessor();
135  bool parseAndCheckDiscontinuityOptions(const GmSimulationData* simData);
136  bool parseAndCheckExtraColumnOptions(const GmSimulationData* simData);
137  bool checkDataForSaving(bool multipleTimeSteps);
138  bool adjustAcStates (int state);
139  bool adjustAndCheckIds ();
140 
141  bool prepareNodeInterpolatedValues();
142  bool prepareNodeBcValues();
143 
144  bool savePrepare(QString fileName, const GmSimulationData* simData, GmMesh* mesh, const GmCellGroupSet* group,
145  const QVariantMap& options, bool multipleTimeSteps, QVector<double>& timeList);
146 
147  bool doSaveGeometry();
148  bool doSaveDiscontinuities();
149  bool doSaveData();
150 
151  bool cleanup(bool deleteFiles = false);
152 
159 
164 
167  double _coordScaleFactor[3];
168  double _coordOffset[3];
169 
170  bool _openFiles;
171  int _saveIter;
172  QVariantMap _options;
175 
179  struct InternalVsData {
183 
184  InternalVsData(GmValueInfo* info, GmValueSetData* vs, GmResultNodeDataSrc* ds) : _info(info), _vs(vs), _ds(ds) {}
185  ~InternalVsData();
186  private:
187  Q_DISABLE_COPY(InternalVsData);
188  };
189 
192 
195  {
200  };
201 
203  struct InterpData {
211  double _searchDomain;
216 
217  InterpData();
218  ~InterpData();
219  private:
220  Q_DISABLE_COPY(InterpData);
221  };
222 
224 
228 
229  QVariantMap _stateMap;
230 };
231 
232 #endif
233 
Auxiliar class used to store the definition of a value. It can be used to store informations about st...
Definition: gmValueInfo.h:126
bool _coordTransf
A boolean defining if the coordinate transformation vectors are filled or not.
Definition: gmFileIO.h:166
GmFileReader * _reader
The object used for reading data when instanced in write mode. Null otherwise.
Definition: gmFileIO.h:155
Interface for helping managing mesh cell groups and returning the elements in their union.
Definition: gmCellGroupSet.h:34
ExtraColumns
The set of extra columns that should be saved on file.
Definition: gmFileIO.h:85
InternalVsData * _nodeBcVsData
The set of mesh boundary conditions, WITH TAGS, that should be saved when _extraColumns includes NODE...
Definition: gmFileIO.h:191
A GmResultDataSrc class holding a cell value accessor.
Definition: gmResultDataSrc.h:323
GmValueInfo * _info
An info object with most of its data copied from the "parent" Gauss value set or representing the Bc ...
Definition: gmFileIO.h:180
The file will be involved as part of an initial restore operation (maybe followed by other dump opera...
Definition: gmFileIO.h:72
A GmResultDataSrc class holding a node value accessor.
Definition: gmResultDataSrc.h:303
Only the intersection data will be saved.
Definition: gmFileIO.h:80
Basic interface for file deserializers.
Definition: gmFileReader.h:40
GmValueSetData * _vs
The value set storing the new (interpolated/Bc tag) data buffer.
Definition: gmFileIO.h:181
QVariant _interpParam
Optional interpolation parameters.
Definition: gmFileIO.h:207
The GmStateDump class presents a higher level of abstraction over GmMemoryDump, storing accessor data...
Definition: gmStateDump.h:52
InterpDataMode
The value set used to saved Bc tag data when _extraColumns includes NODE_BC_COLUMN.
Definition: gmFileIO.h:194
QVariantMap _stateMap
Variant map used for state dumping.
Definition: gmFileIO.h:229
Declaration of usefull configuration definitions for the Core library.
A helper structure to store data for the value sets created to enable Gauss to node interpolations & ...
Definition: gmFileIO.h:179
bool _searchModeRadius
Is the search mode radius (true) or closest (false) for SPLINE or CLOUD based interpolations.
Definition: gmFileIO.h:210
EB_G2N interpolation.
Definition: gmFileIO.h:196
A class used to represent a set of boundary conditions of the same type, tied to the same mesh.
Definition: gmBoundaryCondition.h:262
GmMesh * _mesh
The mesh for load / save operations.
Definition: gmFileIO.h:160
A GmResultDataSrc class holding a Gauss value accessor.
Definition: gmResultDataSrc.h:343
NB_GN2N interpolation.
Definition: gmFileIO.h:197
Declaration of the GmStateDumpBaseDataItem and basic derived classes.
virtual bool addStateItemsToGroup(GmStateDump *state, int groupId)=0
Initialization method, called once, allowing the object to add its state items to the given group of ...
double _searchDomain
The search radius or number of closets points for SPLINE or CLOUD based interpolations.
Definition: gmFileIO.h:211
The file will take part in state dumping.
Definition: gmFileIO.h:71
Interface class for accessing and setting values from an "indexable" collection of values.
Definition: gmValueAccessor.h:59
virtual bool stateLoaded(GmStateDump *state)
Virtual method called just after succesfully completing a load operation on the given state....
Definition: gmStateDumpItem.h:85
Auxiliar class used to store the complete set of simulation data.
Definition: gmSimulationData.h:51
No data will be saved.
Definition: gmFileIO.h:78
GmInterpolatorAveraging
Averaging options for calculating nodal values from multiple element contributions.
Definition: gmGaussToElementNodeInterpolator.h:69
bool _openFiles
States if we have an open file or not.
Definition: gmFileIO.h:170
QString _fileName
The base file name.
Definition: gmFileIO.h:157
GmFileFilter * _filter
The configured filter for saving operations.
Definition: gmFileIO.h:156
No save & restore operations in use.
Definition: gmFileIO.h:70
Both the original and the intersection data will be saved.
Definition: gmFileIO.h:81
GmInterpolatorType
Available interpolation methods. Not every method is suitable for every kind of interpolator class....
Definition: gmInterpolator.h:62
Declaration of the GmGaussToElementNodeInterpolator class.
Base interface class for CellMesh type plugins.
Definition: gmCellMesh.h:39
Base interface class for Spatial Index type plugins.
Definition: gmSpatialIndex.h:37
QVariantMap _options
Keeps track of save options in a statefull operation.
Definition: gmFileIO.h:172
GmCellGroupSet * _meshGroup
A group set for the entire mesh. Used by the interpolation routines.
Definition: gmFileIO.h:214
Base interface class for NumSolver type plugins.
Definition: gmNumSolver.h:34
GmFileWriter * _writer
The object used for writing data when instanced in write mode. Null otherwise.
Definition: gmFileIO.h:154
const GmSpatialIndex * _gaussIndex
The spatial index object used for SPLINE or CLOUD based interpolations.
Definition: gmFileIO.h:212
#define GMC_API_EXPORT
Macro for controling if the class is being exported (GEMA_CORE_LIB defined) or imported (GEMA_CORE_LI...
Definition: gmCoreConfig.h:35
Basic interface for file serializers.
Definition: gmFileWriter.h:36
GmInterpolatorAveraging _elemAvgMode
The averaging mode for ELEMENT based interpolations.
Definition: gmFileIO.h:208
A helper structure to collect all the needed interpolation configuration options.
Definition: gmFileIO.h:203
The generic interface implemented by every GmValueSetData object. Its purpose is to provide a base cl...
Definition: gmValueSetData.h:65
Only the original, user given, discontinuity data will be saved.
Definition: gmFileIO.h:79
const GmNumSolver * _splineNumSolver
The numeric solver object used for SPLINE based interpolations.
Definition: gmFileIO.h:213
QVector< GmResultGaussDataSrc * > _gaussData
Data accessors & save definitions for Gauss results that will be saved / loaded.
Definition: gmFileIO.h:163
Class representing a category with multiple logging levels.
Definition: gmLog.h:58
GmInterpolatorType _interpType
The interpolator used when mode is different from SPLINE.
Definition: gmFileIO.h:206
SPLINE_G2N interpolation.
Definition: gmFileIO.h:198
DiscontinuityDataMode
The selected mode when saving discontinuity data.
Definition: gmFileIO.h:76
Base interface for FEM (finite element) meshes.
Definition: gmElementMesh.h:40
Base interface for providing discontinuity geometry information for spatial indices.
Definition: gmDiscontinuitySet.h:48
GmValueAccessor * _nodeAc
The accessor used for retrieving node coordinates. Can be different from the mesh coordinate accessor...
Definition: gmFileIO.h:165
QVector< GmResultCellDataSrc * > _cellData
Data accessors & save definitions for cell results that will be saved / loaded.
Definition: gmFileIO.h:162
DumpMode
The dump mode when creating the file.
Definition: gmFileIO.h:68
DumpMode _dumpMode
Will this file take part on a dump / restore operation?
Definition: gmFileIO.h:158
int _saveIter
Keeps track of the number of times that saveCurrentResult was called.
Definition: gmFileIO.h:171
bool _nodeClosest
The "closest" mode for NODE based interpolations.
Definition: gmFileIO.h:209
DiscontinuityDataMode _dsMode
The selected mode defining which kind of discontinuity data should be saved.
Definition: gmFileIO.h:226
An object for conducting high level aspects of writing results to export files and / or reading mesh ...
Definition: gmFileIO.h:64
const GmLogCategory & _logger
The logger object used to report errors.
Definition: gmFileIO.h:153
MESH_G2N interpolation.
Definition: gmFileIO.h:199
Basic interface for describing high level file format capabilities.
Definition: gmFileFormat.h:34
GmResultNodeDataSrc * _ds
The associated data src stored and owned by _nodeData.
Definition: gmFileIO.h:182
QVector< InternalVsData * > _nodeVsData
Stores for each entry in _gaussData the associated node interpolated values.
Definition: gmFileIO.h:215
A basic interface used for creating dump items for objects that can be dumped by a composition of mul...
Definition: gmStateDumpItem.h:52
bool _alsoSaveAtGauss
When interpolating Gauss to nodes, should we also save the original Gauss data?
Definition: gmFileIO.h:205
int _extraColumns
The set of extra columns that should be saved. An or of GmFileWriter::ExtraColumns values.
Definition: gmFileIO.h:173
Base interface class for Mesh type plugins.
Definition: gmMesh.h:44
virtual bool stateAboutToBeSaved(GmStateDump *state)
Virtual method called just before starting a save operation on the given state. Returning false abort...
Definition: gmStateDumpItem.h:70
QVector< GmDiscontinuitySet * > _dsList
The list with saved discontinuity sets.
Definition: gmFileIO.h:225
QVector< GmResultNodeDataSrc * > _nodeData
Data accessors & save definitions for node results that will be saved / loaded. May include srcs from...
Definition: gmFileIO.h:161
UnitConverter * _dsConv
The unit converter needed to convert from the mesh unit to the _nodeAc unit. NULL if not needed.
Definition: gmFileIO.h:227
QVector< int > _propertySets
The list of property sets whose material indices should be saved when _extraColumns includes CELL_MAT...
Definition: gmFileIO.h:174
InterpData * _interpData
The set of interpolation options and data when Gauss to node interpolation is configured.
Definition: gmFileIO.h:223
InterpDataMode _mode
The interpolation mode.
Definition: gmFileIO.h:204
A generic auxilliary class for managing the various options that can be used to define the set of nod...
Definition: gmFileFilter.h:45