GemaCoreLib
The GeMA Core library
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 
31 #include <unit.h>
32 
33 #include <QString>
34 #include <QVariant>
35 #include <assert.h>
36 
37 class GmModelData;
38 class GmSolutionData;
39 
40 class GmPath;
41 class GmPluginLoader;
42 class GmLogCategory;
43 
44 class GmTaskManager;
45 
46 struct QtHardwareInfo;
47 struct QtGlobalMemUsage;
48 
49 
52 {
53 public:
54  GmSimulationData(GmPluginLoader* loader, const GmPath* paths,
55  const QVariantMap& configConstants, const QVariantMap& configOptions);
57 
58  void init();
59  void clearData();
60 
62  QString name() const { return _name; }
63 
65  QString description() const { return _description; }
66 
68  const QStringList& loadedFiles() const { return _loadedFiles; }
69 
71  void setSimulationGlobalInfo(QString name, QString description,
72  QVariantMap& constants, QVariantMap& options)
73  {
74  _name = name;
75  _description = description;
76  _constants = constants;
77  _options = options;
78  }
79 
81  void setLoadedFiles(const QStringList& loadedFiles) { _loadedFiles = loadedFiles; }
82 
84  void setSharedCode(QString sharedCode) { _sharedCode = sharedCode; }
85 
87  GmModelData* modelData() const { return _model; }
88 
90  GmSolutionData* solutionData() const { return _solution; }
91 
93  GmResultsData* resultsData() const { return _results; }
94 
96  QString sharedCode() const { return _sharedCode; }
97 
99  GmPluginLoader* loader() const { return _loader; }
100 
102  const GmPath* paths() const { return _paths; }
103 
104  void printInfo();
105 
113  bool cancelRequested() const { assert(_threadManager); return _threadManager->cancelRequested(); }
114 
116  GmThreadManager* threadManager() const { return _threadManager; }
117 
119  GmTaskManager* taskManager() const { return _taskManager; }
120 
122  QtHardwareInfo* hwInfo() const { return _hwInfo; }
123 
125  double currentTime() const { return _currentTime; }
126 
128  double previousTime() const { return _prevTime; }
129 
130  double currentTime (const Unit& desiredUnit) const;
131  double previousTime(const Unit& desiredUnit) const;
132 
134  const Unit& timeUnit() const { return _timeUnit; }
135 
142  void setCurrentTime(double time, bool updatePrev = true)
143  {
145  if(updatePrev)
146  _prevTime = (time == 0.0 ? 0.0 : _currentTime);
147  _currentTime = time;
148 
149  _results->setCurrentTime(_currentTime);
150  }
151 
153  void setPreviousTime(double time) { assert(GmThreadManager::inMainThread()); _prevTime = time; }
154 
156  void setCurrentTimeUnit(const Unit& unit) { assert(GmThreadManager::inMainThread()); _timeUnit = unit; }
157 
162  const QVariant& optionValue(const QString& name) const { return mapValue(name, _options, _configOptions); }
163 
168  QVariant optionValue(const QString& name, const QVariant& defValue) const { return mapValue(name, _options, _configOptions, defValue); }
169 
174  const QVariant& constantValue(const QString& name) const { return mapValue(name, _constants, _configConstants); }
175 
180  QVariant constantValue(const QString& name, const QVariant& defValue) const { return mapValue(name, _constants, _configConstants, defValue); }
181 
185  const QVariantMap& simulationOptions() const { return _options; }
186 
190  const QVariantMap& simulationConstants() const { return _constants; }
191 
195  const QVariantMap& configOptions() const { return _configOptions; }
196 
200  const QVariantMap& configConstants() const { return _configConstants; }
201 
202 private:
203  QString variantToString(const QVariant& v);
204  void printMapValues (const GmLogCategory& logger, const QVariantMap& map, const QVariantMap& configMap);
205 
206  const QVariant& mapValue(const QString& name, const QVariantMap& map, const QVariantMap& configMap) const;
207  QVariant mapValue(const QString& name, const QVariantMap& map, const QVariantMap& configMap, const QVariant& defValue) const;
208 
212  QVariantMap _constants;
213  QVariantMap _options;
214  const QVariantMap& _configConstants;
215  const QVariantMap& _configOptions;
216 
221 
222  QtHardwareInfo* _hwInfo;
223  QtGlobalMemUsage* _initMemoryInfo;
224 
227 
229  const GmPath* _paths;
230 
231  double _currentTime;
232  double _prevTime;
234 };
235 
236 #endif
237 
Auxiliar class used to store the complete set of solution methods data for a simulation.
Definition: gmSolutionData.h:40
bool cancelRequested() const
Do we have a pending request to cancel the simulation?
Definition: gmSimulationData.h:113
GmThreadManager * threadManager() const
Returns a pointer to the configured thread manager.
Definition: gmSimulationData.h:116
const QVariantMap & simulationOptions() const
Returns the map with options read from the simulation.
Definition: gmSimulationData.h:185
Auxiliar class used to store the complete set of model data for a simulation.
Definition: gmModelData.h:49
const QVariantMap & _configOptions
The map with options defined in the configuration file.
Definition: gmSimulationData.h:215
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:180
GmModelData * modelData() const
Returns the model data associated to this simulation.
Definition: gmSimulationData.h:87
QString description() const
Returns the simulation description.
Definition: gmSimulationData.h:65
Declaration of usefull configuration definitions for the Core library.
QString _sharedCode
The shared code for setting the Lua environment for worker threads.
Definition: gmSimulationData.h:220
const QVariantMap & configConstants() const
Returns the map with constants read from the config file.
Definition: gmSimulationData.h:200
double currentTime() const
Returns the current simulation time in the current time unit.
Definition: gmSimulationData.h:125
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:168
QStringList _loadedFiles
The set of Lua files that where loaded for this simulation.
Definition: gmSimulationData.h:211
GmTaskManager * _taskManager
The configured task manager.
Definition: gmSimulationData.h:226
Auxiliar class used to store the complete set of simulation data.
Definition: gmSimulationData.h:51
Declaration of the GmThreadManager class.
GmPluginLoader * loader() const
Returns the plugin loader to allow for plugins to load other plugins.
Definition: gmSimulationData.h:99
void setCurrentTime(double time, bool updatePrev=true)
Updates the current time.
Definition: gmSimulationData.h:142
QtGlobalMemUsage * _initMemoryInfo
The global memory usage pattern before loading the simulation data.
Definition: gmSimulationData.h:223
Class used to store releveant system and project paths, providing functions for path macro translatio...
Definition: gmPath.h:37
QVariantMap _options
The map with options defined in the simulation section.
Definition: gmSimulationData.h:213
QString _name
Simulation name.
Definition: gmSimulationData.h:209
const GmPath * _paths
Object storing the set of important paths for path macro substitution.
Definition: gmSimulationData.h:229
Class responsible for managing discovery and loading of plugins.
Definition: gmPluginLoader.h:42
QString name() const
Returns the simulation name.
Definition: gmSimulationData.h:62
Declaration of the GmResultsData class.
GmResultsData * resultsData() const
Returns the results configuration associated to this simulation.
Definition: gmSimulationData.h:93
double previousTime() const
Returns the previous simulation time in the current time unit.
Definition: gmSimulationData.h:128
const GmPath * paths() const
Returns the object storing information for path macro susbstitution.
Definition: gmSimulationData.h:102
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:174
QString sharedCode() const
Returns the shared code associated to this simulation.
Definition: gmSimulationData.h:96
void setCurrentTimeUnit(const Unit &unit)
Updates the current time unit.
Definition: gmSimulationData.h:156
QVariantMap _constants
The map with constants defined in the simulation section.
Definition: gmSimulationData.h:212
Auxiliar class used to store the complete set of results data for a simulation.
Definition: gmResultsData.h:51
GmSolutionData * solutionData() const
Returns the solution definition associated to this simulation.
Definition: gmSimulationData.h:90
Unit _timeUnit
The current simulation time unit.
Definition: gmSimulationData.h:233
#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
const QStringList & loadedFiles() const
Returns the list of loaded files for this simulation.
Definition: gmSimulationData.h:68
GmModelData * _model
Model data.
Definition: gmSimulationData.h:217
GmSolutionData * _solution
Solution method data.
Definition: gmSimulationData.h:218
const QVariantMap & simulationConstants() const
Returns the map with constants read from the simulation.
Definition: gmSimulationData.h:190
QString _description
Simulation description.
Definition: gmSimulationData.h:210
GmPluginLoader * _loader
The application plugin manager.
Definition: gmSimulationData.h:228
Class representing a category with multiple logging levels.
Definition: gmLog.h:58
GmResultsData * _results
Results configuration data.
Definition: gmSimulationData.h:219
static bool inMainThread()
Is the current thread the main thread? Equivalent to comparing the currentId() with 0.
Definition: gmThreadManager.h:169
void setLoadedFiles(const QStringList &loadedFiles)
Updates the list of loaded files for this simulation.
Definition: gmSimulationData.h:81
QtHardwareInfo * hwInfo() const
Returns some usefull information about the execution hardware.
Definition: gmSimulationData.h:122
QtHardwareInfo * _hwInfo
Some usefull information about the execution hardware.
Definition: gmSimulationData.h:222
const Unit & timeUnit() const
Returns the unit in which the current time is stored.
Definition: gmSimulationData.h:134
void setSharedCode(QString sharedCode)
Updates the shared code.
Definition: gmSimulationData.h:84
GmThreadManager * _threadManager
The configured thread manager.
Definition: gmSimulationData.h:225
Thread manager used for handling parallel executions.
Definition: gmThreadManager.h:94
void setPreviousTime(double time)
Updates the previous time.
Definition: gmSimulationData.h:153
GmTaskManager * taskManager() const
Returns a pointer to the configured task manager.
Definition: gmSimulationData.h:119
double _currentTime
The current simulation time.
Definition: gmSimulationData.h:231
void setSimulationGlobalInfo(QString name, QString description, QVariantMap &constants, QVariantMap &options)
Updates the simulation global attributes: name & description.
Definition: gmSimulationData.h:71
const QVariantMap & configOptions() const
Returns the map with options read from the config file.
Definition: gmSimulationData.h:195
const QVariantMap & _configConstants
The map with constants defined in the configuration file.
Definition: gmSimulationData.h:214
double _prevTime
The previous simulation time.
Definition: gmSimulationData.h:232
Task manager used for handling parallel executions.
Definition: gmTaskManager.h:76
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:162