GemaCoreLib
The GeMA Core library
gmStateDump.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_STATE_DUMP_H_
25 #define _GEMA_STATE_DUMP_H_
26 
27 #include "gmMemoryDump.h"
28 
29 #include "gmVector.h"
30 #include "gmMatrix.h"
31 
32 class LuaTable;
33 struct lua_State;
34 
35 class GmSimulationData;
36 class GmValueAccessor;
37 class GmCellAccessor;
38 class GmGaussAccessor;
40 class GmAccessorProxy;
41 class GmMesh;
44 
46 class GmGroupDumpItem;
47 
48 
53 {
54 public:
55  GmStateDump(const GmSimulationData* simulation);
56  virtual ~GmStateDump();
57 
59  void setMode(GmMemoryDumpMode mode) { assert(!_md); _mode = mode; }
60 
62  void setSaveAndRestoreSupport(bool mode) { assert(!_md); _saveAndRestoreSupport = mode; }
63 
64  void setDumpFile(QString file);
65 
69  void setCompression(int level, int minSize) { assert(!_md); _compression = level; _compressionMinSize = minSize; }
70 
74  void setGrowFactors(double a, int b) { assert(!_md); _growAFactor = a; _growBFactor = b; }
75 
77  void setPrintStructure(bool mode) { assert(!_md); _printStructure = mode; }
78 
79  bool loadUserDefinitions(LuaTable& table, QString& err);
80 
81  int addStateItem(GmValueAccessor* ac, const GmMesh* mesh, bool fixedHint, bool ownership = false, int groupId = -1, QString prefix = "");
82  int addStateItem(GmCellAccessor* ac, const GmMesh* mesh, bool fixedHint, bool ownership = false, int groupId = -1, QString prefix = "");
83  int addStateItem(GmGaussAccessor* ac, const GmMesh* mesh, bool fixedHint, bool ownership = false, int groupId = -1, QString prefix = "");
84  int addStateItem(GmBoundaryConditionAccessor* ac, const GmBoundaryCondition* bc, bool fixedHint, bool ownership = false, int groupId = -1, QString prefix = "");
85  int addStateItem(GmVector* data, bool fixedHint, int groupId = -1, QString prefix = "");
86  int addStateItem(GmMatrix* data, bool fixedHint, int groupId = -1, QString prefix = "");
87  int addStateItem(QVariantMap* data, bool fixedHint, int groupId = -1, QString prefix = "");
88  int addStateItem(char** data, int* size, int sizeMultiplier, bool fixedHint, int groupId = -1, QString prefix = "");
89  int addStateItem(lua_State* L, const QStringList& globals, const QStringList& locals, QString localTabName, int groupId = -1, QString prefix = "");
90  int addStateItem(FILE* fhandle, QString fileName, QString tempName, int groupId = -1, QString prefix = "");
91  int addStateItem(GmStateDumpBaseDataItem* item, int groupId = -1);
92 
93  int addGroupItem(GmGroupDumpItem* obj, int groupId = -1);
94  int addGroupItem(GmBoundaryCondition* bc, int groupId = -1);
95  int addGroupItem(GmContactBoundaryCondition* cbc, int groupId = -1);
96 
98  GmStateDumpBaseDataItem* stateItem(int itemId) const { assert(_md); return (GmStateDumpBaseDataItem*)_md->item(itemId); }
99 
101  int stateItemGroup(int itemId) const { assert(_md); return _md->itemGroup(itemId); }
102 
104  int numStateItems() const { assert(_md); return _md->numItems(); }
105 
109  int findStateItem(QString name, int typeMask = 0, int typeValue = 0, int groupId = -1, int start = 0)
110  {
111  assert(_md);
112  return _md->findItem(name, typeMask, typeValue, groupId, start);
113  }
114 
115  void setGroupActive(int groupId, bool active);
116 
117  bool init();
118 
119  bool save();
120  bool load();
121 
122  bool saveItem(int itemId, qint64 size = 0, qint64 offset = 0);
123  bool loadItem(int itemId, qint64 size = 0, qint64 offset = 0);
124 
125  bool saveActiveGroups();
126  bool loadActiveGroups();
127 
129  void flush() { assert(_md && _init); _md->flush(); }
130 
132  void clear() { assert(_md && _init); _md->clear(); }
133 
135  const GmLogCategory& logger() const { return _logger; }
136 
137  int nextIdInGroup(int groupId);
138 
139 private:
140  Q_DISABLE_COPY(GmStateDump)
141 
142  int addAcStateItem(GmValueAccessor* ac, const GmMesh* mesh, QString mapId, bool fixedHint,
143  bool ownership, int groupId, QString prefix, bool* added);
144 
145  void newmd();
146  bool notifyGroupObjects(bool load, bool done, bool activeOnly);
147 
153  double _growAFactor;
156 
160  bool _init;
167 
170 };
171 
172 #endif
QVector< GmGroupDumpItem * > _ownedGroupItems
A set of group items owned by the state dump object.
Definition: gmStateDump.h:166
A class used to represent a set of contact boundary conditions of the same type, tied to the same mes...
Definition: gmContactBoundaryCondition.h:32
QVector< int > _funcItems
The set of function dump item ids.
Definition: gmStateDump.h:162
void flush()
Ensure that the dump file (if any) is flushed. Meaningfull after individual saves.
Definition: gmStateDump.h:129
void setGrowFactors(double a, int b)
Updates the grow factors applied for dump items expected to grow. Must be called before the first cal...
Definition: gmStateDump.h:74
The GmStateDump class presents a higher level of abstraction over GmMemoryDump, storing accessor data...
Definition: gmStateDump.h:52
Declaration of the GmMemoryDump and GmMemoryDumpItem classes.
The GmGaussAccessor class is a proxy object to a value accesor implementing a more convenient interfa...
Definition: gmGaussAccessor.h:38
A class used to represent a set of boundary conditions of the same type, tied to the same mesh.
Definition: gmBoundaryCondition.h:262
bool _init
Has this object been initialized (init() was called?)
Definition: gmStateDump.h:160
Declaration of the GmMatrix class.
int numStateItems() const
Returns the number of dump items added (can be greater than the number of addStateItem() calls)
Definition: gmStateDump.h:104
void setMode(GmMemoryDumpMode mode)
Updates the dump mode. Must be called before the first call to addStateItem().
Definition: gmStateDump.h:59
Interface class for accessing and setting values from an "indexable" collection of values.
Definition: gmValueAccessor.h:59
Auxiliar class used to store the complete set of simulation data.
Definition: gmSimulationData.h:51
int findStateItem(QString name, int typeMask=0, int typeValue=0, int groupId=-1, int start=0)
Finds the index of a state item identified by its name. See the GmMemoryDump::findItem() method docum...
Definition: gmStateDump.h:109
GmMemoryDumpMode _mode
The dump mode.
Definition: gmStateDump.h:148
GmLogCategory _logger
Basic logger object for state dump messages.
Definition: gmStateDump.h:158
bool _saveAndRestoreSupport
Does the state needs to support a saving and later restore pattern?
Definition: gmStateDump.h:149
bool _printStructure
Should the dump items structure be printed on init()?
Definition: gmStateDump.h:155
The GmBoundaryConditionAccessor class is a proxy object to a value accesor implementing a more conven...
Definition: gmBoundaryConditionAccessor.h:73
QMap< int, QPair< GmGroupDumpItem *, bool > > _groupItems
A map, indexed by group index storing the associated group dump item and a flag stating if this group...
Definition: gmStateDump.h:169
QVector< GmValueAccessor * > _ownedValueAccessors
A set of value accessors owned by the state dump object.
Definition: gmStateDump.h:164
The GmCellAccessor class is a proxy object to a value accesor implementing a more convenient interfac...
Definition: gmCellAccessor.h:66
QMap< QString, int > _acMap
Map keeping track of the already added accessors to the state dump.
Definition: gmStateDump.h:163
GmMemoryDumpMode
Supported memory dump modes.
Definition: gmMemoryDump.h:37
QMap< int, int > _currIdInGroup
Map storing, per group id, the index of its last added item.
Definition: gmStateDump.h:161
QString _dumpFile
The dump file.
Definition: gmStateDump.h:150
void setCompression(int level, int minSize)
Updates the compression level and the minimum size for which compression is desirable....
Definition: gmStateDump.h:69
Declaration of the GmVector class.
#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
int _growBFactor
'b' grow factor in ax + b
Definition: gmStateDump.h:154
const GmLogCategory & logger() const
Returns the logger used by the state dump object.
Definition: gmStateDump.h:135
QVector< GmAccessorProxy * > _ownedProxyAccessors
A set of cell, Gauss and BC accessors owned by the state dump object.
Definition: gmStateDump.h:165
void setPrintStructure(bool mode)
Updates the print structure mode. Must be called before the first call to addStateItem().
Definition: gmStateDump.h:77
Class representing a category with multiple logging levels.
Definition: gmLog.h:58
void setSaveAndRestoreSupport(bool mode)
Updates whether save and restore support is enabled or not. Must be called before the first call to a...
Definition: gmStateDump.h:62
Ensure that all dump items stored by GmStateDump have an id() and a logger.
Definition: gmStateDumpItem.h:131
GmMemoryDump * _md
The memory dump object responsible for the actual dumping.
Definition: gmStateDump.h:159
GmStateDumpBaseDataItem * stateItem(int itemId) const
Returns the state dump item associated with the given index.
Definition: gmStateDump.h:98
void clear()
Releases dump memory when dumping to memory.
Definition: gmStateDump.h:132
arma::vec GmVector
The basic type for a GeMA vector object. Currently based on an Armadillo vector.
Definition: gmVector.h:34
A basic interface used for creating dump items for objects that can be dumped by a composition of mul...
Definition: gmStateDumpItem.h:52
Base interface class for Mesh type plugins.
Definition: gmMesh.h:44
int _compression
The desired compression level (0 = no, 9 = maz, -1 = zlib default)
Definition: gmStateDump.h:151
int _compressionMinSize
The minimum size for which compression makes sense (must be > 0)
Definition: gmStateDump.h:152
arma::mat GmMatrix
The basic type for a GeMA matrix object. Currently based on an Armadillo matrix.
Definition: gmMatrix.h:38
const GmSimulationData * _simulation
The simulation object.
Definition: gmStateDump.h:157
Helper class with common code for several classes that wrap a value accessor, provinding a slitly dif...
Definition: gmAccessorProxy.h:38
int stateItemGroup(int itemId) const
Returns the group id of the given item.
Definition: gmStateDump.h:101
double _growAFactor
'a' grow factor in ax + b
Definition: gmStateDump.h:153
Class storing a memory dump containing several dump items.
Definition: gmMemoryDump.h:221