GemaCoreLib
The GeMA Core library
Loading...
Searching...
No Matches
gmSimulationData.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_SIMULATION_DATA_H_
25#define _GEMA_SIMULATION_DATA_H_
26
27#include "gmCoreConfig.h"
28#include "gmThreadManager.h"
29#include "gmResultsData.h"
30#include "gmPluginObject.h"
31
32#include <unit.h>
33
34#include <QString>
35#include <QVariant>
36#include <assert.h>
37
38class GmModelData;
39class GmSolutionData;
41
42class GmPath;
43class GmPluginLoader;
44class GmLogCategory;
45
46class GmTaskManager;
47class GmMpiContext;
48
49struct QtHardwareInfo;
50struct QtGlobalMemUsage;
51
52
55{
56public:
57 GmSimulationData(GmPluginLoader* loader, const GmPath* paths,
58 const QVariantMap& configConstants, const QVariantMap& configOptions);
60
61 void init();
62 void clearData();
63
65 QString name() const { return _name; }
66
68 QString description() const { return _description; }
69
71 const QStringList& loadedFiles() const { return _loadedFiles; }
72
74 void setSimulationGlobalInfo(QString name, QString description,
75 const QVariantMap& constants, const QVariantMap& options)
76 {
77 _name = name;
78 _description = description;
79 _constants = constants;
80 _options = options;
81 setupDisabledWarningsList();
82 }
83
85 void setLoadedFiles(const QStringList& loadedFiles) { _loadedFiles = loadedFiles; }
86
88 void setSharedCode(QString sharedCode) { _sharedCode = sharedCode; }
89
91 GmModelData* modelData() const { return _model; }
92
94 GmSolutionData* solutionData() const { return _solution; }
95
97 GmResultsData* resultsData() const { return _results; }
98
100 GmRunProgressStats* progressStats() const { return _progress; }
101
104
106 QString sharedCode() const { return _sharedCode; }
107
109 GmPluginLoader* loader() const { return _loader; }
110
112 const GmPath* paths() const { return _paths; }
113
114 void printInfo();
115
123 bool cancelRequested() const { assert(_threadManager); return _threadManager->cancelRequested(); }
124
126 GmThreadManager* threadManager() const { return _threadManager; }
127
129 GmTaskManager* taskManager() const { return _taskManager; }
130
132 GmMpiContext* mpiContext() const { return _mpiContext; }
133
135 QtHardwareInfo* hwInfo() const { return _hwInfo; }
136
138 double currentTime() const { return _currentTime; }
139
141 double previousTime() const { return _prevTime; }
142
143 double currentTime (const Unit& desiredUnit) const;
144 double previousTime(const Unit& desiredUnit) const;
145
147 const Unit& timeUnit() const { return _timeUnit; }
148
155 void setCurrentTime(double time, bool updatePrev = true)
156 {
158 if(updatePrev)
159 _prevTime = (time == 0.0 ? 0.0 : _currentTime);
160 _currentTime = time;
161
162 _results->setCurrentTime(_currentTime);
163 }
164
166 void setPreviousTime(double time) { assert(GmThreadManager::inMainThread()); _prevTime = time; }
167
169 void setCurrentTimeUnit(const Unit& unit) { assert(GmThreadManager::inMainThread()); _timeUnit = unit; }
170
172 bool disabledWarning(QString warnName) const { return _disabledWarnings.contains(warnName); }
173
175 void pushDisabledWarning(QString warnName) { _disabledWarnings.append(warnName); }
176
178 void popDisabledWarning() { assert(!_disabledWarnings.isEmpty()); _disabledWarnings.removeLast(); }
179
185 const QVariant& optionValue(const QString& name) const { return mapValue(name, _options, _configOptions); }
186
192 QVariant optionValue(const QString& name, const QVariant& defValue) const { return mapValue(name, _options, _configOptions, defValue); }
193
198 const QVariant& constantValue(const QString& name) const { return mapValue(name, _constants, _configConstants); }
199
204 QVariant constantValue(const QString& name, const QVariant& defValue) const { return mapValue(name, _constants, _configConstants, defValue); }
205
209 const QVariantMap& simulationOptions() const { return _options; }
210
214 const QVariantMap& simulationConstants() const { return _constants; }
215
219 const QVariantMap& configOptions() const { return _configOptions; }
220
224 const QVariantMap& configConstants() const { return _configConstants; }
225
226private:
227 void createStdProgressItems();
228
229 QString variantToString (const QVariant& v);
230 void printMapValues (const GmLogCategory& logger, const QVariantMap& map, const QVariantMap& configMap);
231 void printHardwareInfo(const GmLogCategory& logger);
232
233 const QVariant& mapValue(const QString& name, const QVariantMap& map, const QVariantMap& configMap) const;
234 QVariant mapValue(const QString& name, const QVariantMap& map, const QVariantMap& configMap, const QVariant& defValue) const;
235
237 void setupDisabledWarningsList() { _disabledWarnings = mapValue("disabledWarnings", _options, _configOptions, QStringList()).toStringList(); }
238
242 QVariantMap _constants;
243 QVariantMap _options;
244 const QVariantMap& _configConstants;
245 const QVariantMap& _configOptions;
247
252
254
255 QtHardwareInfo* _hwInfo;
256 QtGlobalMemUsage* _initMemoryInfo;
257
260
261 GmMpiContext* _mpiContext;
262
264 const GmPath* _paths;
265
267 double _prevTime;
269};
270
271#endif
272
Class representing a category with multiple logging levels.
Definition gmLog.h:58
Auxiliar class used to store the complete set of model data for a simulation.
Definition gmModelData.h:53
Class used to store releveant system and project paths, providing functions for path macro translatio...
Definition gmPath.h:38
Class responsible for managing discovery and loading of plugins.
Definition gmPluginLoader.h:43
Base interface class for all object plugins.
Definition gmPluginObject.h:37
GmSimulationData * simulationData() const
Returns a reference to the simulation data object keeping global simulation information.
Definition gmPluginObject.h:88
Auxiliar class used to store the complete set of results data for a simulation.
Definition gmResultsData.h:58
A class used to store time, memory and additional values statistics related to the simulation loading...
Definition gmRunProgressStats.h:42
Auxiliar class used to store the complete set of simulation data.
Definition gmSimulationData.h:55
QString _description
Simulation description.
Definition gmSimulationData.h:240
void setLoadedFiles(const QStringList &loadedFiles)
Updates the list of loaded files for this simulation.
Definition gmSimulationData.h:85
void popDisabledWarning()
Removes the last temporarily disabled warning by a call to pushDisabledWarning()
Definition gmSimulationData.h:178
GmPluginLoader * _loader
The application plugin manager.
Definition gmSimulationData.h:263
GmResultsData * _results
Results configuration data.
Definition gmSimulationData.h:250
QtHardwareInfo * _hwInfo
Some useful information about the execution hardware.
Definition gmSimulationData.h:255
const GmPath * _paths
Object storing the set of important paths for path macro substitution.
Definition gmSimulationData.h:264
QVariantMap _constants
The map with constants defined in the simulation section.
Definition gmSimulationData.h:242
QString _name
Simulation name.
Definition gmSimulationData.h:239
double currentTime() const
Returns the current simulation time in the current time unit.
Definition gmSimulationData.h:138
double _prevTime
The previous simulation time.
Definition gmSimulationData.h:267
GmRunProgressStats * _progress
The object used to track simulation progress statistics.
Definition gmSimulationData.h:251
GmResultsData * resultsData() const
Returns the results configuration associated to this simulation.
Definition gmSimulationData.h:97
GmPluginLoader * loader() const
Returns the plugin loader to allow for plugins to load other plugins.
Definition gmSimulationData.h:109
QString sharedCode() const
Returns the shared code associated to this simulation.
Definition gmSimulationData.h:106
const Unit & timeUnit() const
Returns the unit in which the current time is stored.
Definition gmSimulationData.h:147
GmSolutionData * solutionData() const
Returns the solution definition associated to this simulation.
Definition gmSimulationData.h:94
const QVariantMap & configOptions() const
Returns the map with options read from the config file. Not for general use (used by the loader onl...
Definition gmSimulationData.h:219
QString name() const
Returns the simulation name.
Definition gmSimulationData.h:65
QVariant constantValue(const QString &name, const QVariant &defValue) const
Returns the given constant value. Looks for the given name first in the data set read from the Simula...
Definition gmSimulationData.h:204
const QVariant & optionValue(const QString &name) const
Returns a reference to the given option value. Looks for the given name first in the data set read fr...
Definition gmSimulationData.h:185
double _currentTime
The current simulation time.
Definition gmSimulationData.h:266
const QVariantMap & _configConstants
The map with constants defined in the configuration file.
Definition gmSimulationData.h:244
GmSolutionData * _solution
Solution method data.
Definition gmSimulationData.h:249
void setCurrentTime(double time, bool updatePrev=true)
Updates the current time.
Definition gmSimulationData.h:155
QString _sharedCode
The shared code for setting the Lua environment for worker threads.
Definition gmSimulationData.h:253
QStringList _loadedFiles
The set of Lua files that where loaded for this simulation.
Definition gmSimulationData.h:241
void setPreviousTime(double time)
Updates the previous time.
Definition gmSimulationData.h:166
QtHardwareInfo * hwInfo() const
Returns some useful information about the execution hardware.
Definition gmSimulationData.h:135
bool cancelRequested() const
Do we have a pending request to cancel the simulation? Returns the information stored on the thread...
Definition gmSimulationData.h:123
double previousTime() const
Returns the previous simulation time in the current time unit.
Definition gmSimulationData.h:141
GmModelData * _model
Model data.
Definition gmSimulationData.h:248
const QVariantMap & simulationOptions() const
Returns the map with options read from the simulation. Not for general use (used by the loader only...
Definition gmSimulationData.h:209
QString description() const
Returns the simulation description.
Definition gmSimulationData.h:68
GmThreadManager * _threadManager
The configured thread manager.
Definition gmSimulationData.h:258
QVariantMap _options
The map with options defined in the simulation section.
Definition gmSimulationData.h:243
const QStringList & loadedFiles() const
Returns the list of loaded files for this simulation.
Definition gmSimulationData.h:71
GmModelData * modelData() const
Returns the model data associated to this simulation.
Definition gmSimulationData.h:91
QStringList _disabledWarnings
Disabled warnings list (initialized from _options & _configOptions but editable)
Definition gmSimulationData.h:246
QtGlobalMemUsage * _initMemoryInfo
The global memory usage pattern before loading the simulation data.
Definition gmSimulationData.h:256
GmTaskManager * _taskManager
The configured task manager.
Definition gmSimulationData.h:259
GmMpiContext * _mpiContext
The Mpi context for distributed simulations. NULL otherwise.
Definition gmSimulationData.h:261
const QVariantMap & simulationConstants() const
Returns the map with constants read from the simulation. Not for general use (used by the loader on...
Definition gmSimulationData.h:214
const GmPath * paths() const
Returns the object storing information for path macro substitution.
Definition gmSimulationData.h:112
QVariant optionValue(const QString &name, const QVariant &defValue) const
Returns the given option value. Looks for the given name first in the data set read from the Simulati...
Definition gmSimulationData.h:192
Unit _timeUnit
The current simulation time unit.
Definition gmSimulationData.h:268
GmTaskManager * taskManager() const
Returns a pointer to the configured task manager.
Definition gmSimulationData.h:129
void setSimulationGlobalInfo(QString name, QString description, const QVariantMap &constants, const QVariantMap &options)
Updates the simulation global attributes: name & description.
Definition gmSimulationData.h:74
const QVariantMap & _configOptions
The map with options defined in the configuration file.
Definition gmSimulationData.h:245
static GmRunProgressStats * progressStats(const GmPluginObject *obj)
Returns the run progress monitoring object from the simulation data stored on any plugin object.
Definition gmSimulationData.h:103
GmRunProgressStats * progressStats() const
Returns the run progress monitoring object.
Definition gmSimulationData.h:100
const QVariantMap & configConstants() const
Returns the map with constants read from the config file. Not for general use (used by the loader o...
Definition gmSimulationData.h:224
void setupDisabledWarningsList()
Initializes the disabled warnings list from the options and config options tables.
Definition gmSimulationData.h:237
const QVariant & constantValue(const QString &name) const
Returns a reference to the given constant value. Looks for the given name first in the data set read ...
Definition gmSimulationData.h:198
GmThreadManager * threadManager() const
Returns a pointer to the configured thread manager.
Definition gmSimulationData.h:126
bool disabledWarning(QString warnName) const
Returns true if the given warning is disabled.
Definition gmSimulationData.h:172
void pushDisabledWarning(QString warnName)
Temporarily disables a warning until a call to popDisabledWarning()
Definition gmSimulationData.h:175
void setSharedCode(QString sharedCode)
Updates the shared code.
Definition gmSimulationData.h:88
void setCurrentTimeUnit(const Unit &unit)
Updates the current time unit.
Definition gmSimulationData.h:169
Auxiliar class used to store the complete set of solution methods data for a simulation.
Definition gmSolutionData.h:42
Task manager used for handling parallel executions.
Definition gmTaskManager.h:84
Thread manager used for handling parallel executions.
Definition gmThreadManager.h:100
static bool inMainThread()
Is the current thread the main thread? Equivalent to comparing the currentId() with 0.
Definition gmThreadManager.h:174
Declaration of useful configuration definitions for the Core library.
#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 GmPluginObject base class.
Declaration of the GmResultsData class.
Declaration of the GmThreadManager class.