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