![]() |
GemaLib
The GeMA library
|
Basic class for defining a GeMA physical Simulation, containing references to the model definition, solution defnition and results configuration definition. More...
#include <gmSimulation.h>
Public Types | |
enum | LogModes { QUIET_LOG_MODE = 0x001, VERBOSE_LOG_MODE = 0x002, NOCONSOLE_LOG_MODE = 0x004, REGRESSION_LOG_MODE = 0x008, MEMORY_LOG_MODE = 0x010, NOMEMORY_LOG_MODE = 0x020, TIME_LOG_MODE = 0x040, NOTIME_LOG_MODE = 0x080, SERVER_LOG_MODE = 0x100, NOSERVER_LOG_MODE = 0x200, PLUGININFO_LOG_MODE = 0x400, TIMESTATS_LOG_MODE = 0x800 } |
Predefined Log modes. Can be ored together. More... | |
enum | ServerMode { CONFIG_SERVER_MODE, ENABLE_SERVER_MODE, DISABLE_SERVER_MODE, LOCAL_SERVER_MODE } |
Server initialization modes. More... | |
Signals | |
void | sectionParsed (QString section, LuaTable &data) |
Signal emmited whenever a model section has been parsed from the Lua file. More... | |
Public Member Functions | |
GmSimulation () | |
Constructor. Simulation initialization should be done by calling init(). | |
~GmSimulation () | |
Destructor. | |
bool | initLibrary (QString configFile, QString logFile, int logMode, QString logPath, QString inputPath, QString outputPath, ServerMode serverMode, unsigned localServerPort, QString serverAddrFile, bool rsrcFiles) |
Initializes the library by reading the provided configuration file. More... | |
bool | initSimulation (QString simulationFile, const QMap< QString, QString > &globalVars, int timeout=-1, lua_State *state=NULL) |
Initializes the simulation by reading the provided model file. More... | |
GmSimulationResult | run () |
Runs the simulation loaded by the call to init() More... | |
void | clear () |
Clears the current simulation environment, preparing the object for a new simulation: new calls to initSimulation() + run(). | |
void | printInfo () |
Prints information about the simulation using the Info logger. | |
const GmLogCategory & | logger () |
Returns the basic logger for the GeMA library. | |
LuaEnv * | env () |
Returns the simulation environment. | |
GmSimulationData * | data () const |
Returns a reference to the simulation data. | |
GmPluginLoader * | pluginLoader () const |
Returns a pointer to the plugin loader. Must be called AFTER a succesfull call to initLibrary(). | |
const GmPath * | paths () const |
Returns the object storing information for path macro susbstitution. | |
![]() | |
virtual const QMetaObject * | metaObject () const const |
virtual void * | qt_metacast (const char *) |
virtual int | qt_metacall (QMetaObject::Call, int, void **) |
QObject (QObject *parent) | |
virtual bool | event (QEvent *e) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
QString | objectName () const const |
void | setObjectName (const QString &name) |
bool | isWidgetType () const const |
bool | isWindowType () const const |
bool | signalsBlocked () const const |
bool | blockSignals (bool block) |
QThread * | thread () const const |
void | moveToThread (QThread *targetThread) |
int | startTimer (int interval, Qt::TimerType timerType) |
int | startTimer (std::chrono::milliseconds time, Qt::TimerType timerType) |
void | killTimer (int id) |
T | findChild (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QRegExp ®Exp, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const |
const QObjectList & | children () const const |
void | setParent (QObject *parent) |
void | installEventFilter (QObject *filterObj) |
void | removeEventFilter (QObject *obj) |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const |
bool | disconnect (const char *signal, const QObject *receiver, const char *method) const const |
bool | disconnect (const QObject *receiver, const char *method) const const |
void | dumpObjectTree () |
void | dumpObjectInfo () |
void | dumpObjectTree () const const |
void | dumpObjectInfo () const const |
bool | setProperty (const char *name, const QVariant &value) |
QVariant | property (const char *name) const const |
QList< QByteArray > | dynamicPropertyNames () const const |
void | destroyed (QObject *obj) |
void | objectNameChanged (const QString &objectName) |
QObject * | parent () const const |
bool | inherits (const char *className) const const |
void | deleteLater () |
Private Slots | |
void | cancelRequested () |
The slot called if the monitor server accepted a cancelation request. More... | |
Private Member Functions | |
bool | setConfigFile (QString configFile, QString logFile, int logMode, ServerMode serverMode, unsigned localServerPort, QString serverAddrFile) |
Loads global configuration options for the library. Those include paths to loaded components, logging options, etc. More... | |
bool | setSimulationFile (QString file, const QMap< QString, QString > &globalVars, lua_State *state) |
Loads data defining the model to be simulated. More... | |
bool | setupLogging (LuaEnv &env, QString logFile, int logMode) |
Setup logging options. More... | |
bool | setupMonitorServer (LuaEnv &env, ServerMode serverMode, unsigned localServerPort, bool logToServer, QString serverAddrFile) |
Initializes the monitor server depending on the configuration from serverMode and from the Lua config file. If the server is initialized, sets _monitorServer. More... | |
bool | setupUnitManager (LuaEnv &env) |
Setup the unit manager. More... | |
bool | loadConfigValueTables (LuaEnv &env) |
Loads from the given Lua environment the contents of the "modelConstants" and "modelOptions" tables, filling the _configConstants and _configOptions maps. More... | |
void | setData (GmSimulationData *data) |
Changes the simulation data for this simulation. More... | |
void | clearDataOnError (bool abort) |
Notifies the monitor server about the error / cancelation and sets the internal data to NULL. Also prints a cancelation message if appropriate. If abort is true, will always notify the server of an abort. | |
void | printPluginVersions (GmLogCategory &logger) |
Print plugin versions to the specified logger. | |
Private Attributes | |
GmSimulationData * | _simulationData |
Object storing the complete Simulation information. | |
GmSimulationLoader * | _simulationLoader |
Simulation loader. | |
GmPath * | _paths |
Object storing the set of important simulation paths for macro translation. | |
QVariantMap | _configConstants |
The set of constants defined on the config file. | |
QVariantMap | _configOptions |
The set of options defined on the config file. | |
bool | _rsrcFiles |
If set to true, the config file and the model file are allowed to be resource files. | |
GmLogCategory | _logger |
Basic logger object for the library. | |
GmCommServer * | _monitorServer |
The monitor server. Will be NULL if monitoring is not enabled. | |
QMutex | _envMutex |
The mutex used to control the possible data race during the creation of the Lua environments and possible concurrent cancelation requests. | |
LuaEnv * | _env |
Lua environment used to read the Simulation. Reused during the execution step as it contains functions used by the orchestration. | |
bool | _externalState |
Are we using an external Lua environment provided in initSimulation() ? | |
bool | _redirectPrint |
Should we redirect Lua print() calls to the logger? | |
bool | _loadCompleted |
A flag set to true when the model loading has finished successfully. Also protected by _envMutex. | |
QList< LuaEnv * > | _workerEnvList |
A list with Lua environments for worker threads. | |
Additional Inherited Members | |
![]() | |
QString | tr (const char *sourceText, const char *disambiguation, int n) |
QString | trUtf8 (const char *sourceText, const char *disambiguation, int n) |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, Functor functor) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type) |
bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method) |
bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method) |
bool | disconnect (const QMetaObject::Connection &connection) |
bool | disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method) |
![]() | |
QObject * | sender () const const |
int | senderSignalIndex () const const |
int | receivers (const char *signal) const const |
bool | isSignalConnected (const QMetaMethod &signal) const const |
virtual void | timerEvent (QTimerEvent *event) |
virtual void | childEvent (QChildEvent *event) |
virtual void | customEvent (QEvent *event) |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
![]() | |
objectName | |
Basic class for defining a GeMA physical Simulation, containing references to the model definition, solution defnition and results configuration definition.
This is the core GeMA class. It should be initialized by successfully calling the initLibrary() and initSimulation() functions, passing as parameters, respectively, a global configuration file, and the simulation file.
After the initialization, the methods run() and saveFinalResults() complete the set of functions that are needed to execute a simulation.
Warnings and errors found by the classes methods are generally logged to the default logger, configured by the configuration file.
Predefined Log modes. Can be ored together.
Enumerator | |
---|---|
QUIET_LOG_MODE | Log only warnings and errors (exclusive with VERBOSE_LOG_MODE) |
VERBOSE_LOG_MODE | Log everything (exclusive with QUIET_LOG_MODE) |
NOCONSOLE_LOG_MODE | Don't log to the console. |
REGRESSION_LOG_MODE | Log will include tags for helping regression tests comparisson. |
MEMORY_LOG_MODE | Log will turn on memory messages (not to be used together with verbose & quiet) |
NOMEMORY_LOG_MODE | Log will turn off memory messages (not to be used together with verbose & quiet) |
TIME_LOG_MODE | Log will turn on time messages (not to be used together with verbose & quiet) |
NOTIME_LOG_MODE | Log will turn off time messages (not to be used together with verbose & quiet) |
SERVER_LOG_MODE | Log messages to the monitor server. |
NOSERVER_LOG_MODE | Don't log messages to the monitor server. |
PLUGININFO_LOG_MODE | Print log version / revision information. |
TIMESTATS_LOG_MODE | Print time statistics generated with GmTimeMsg, grouped by message, at the simulation end. |
Server initialization modes.
|
privateslot |
The slot called if the monitor server accepted a cancelation request.
IMPORTANT: This slot runs from the server thread, and so its execution happends in parallel with the main thread activity.
bool GmSimulation::initLibrary | ( | QString | configFile, |
QString | logFile, | ||
int | logMode, | ||
QString | logPath, | ||
QString | inputPath, | ||
QString | outputPath, | ||
ServerMode | serverMode, | ||
unsigned | localServerPort, | ||
QString | serverAddrFile, | ||
bool | rsrcFiles | ||
) |
Initializes the library by reading the provided configuration file.
configFile | Path for the configuration file containing global configuration options for the library. Those include paths to loaded components, logging options, etc. |
logFile | Path to the desired log file. If empty the value at the configuration file will be used instead. |
logMode | Flags used to override config file options for logging. |
logPath,inputPath | and outputPath: Paths uses by macro translations for, respectiveley, the following macros: $LOG, $INPUT and $OUTPUT. If empty default values will be the application path for $LOG and the simulation dir for the other two. |
serverMode | Flag defining if the monitor server should be started or not |
localServerPort | The port where the server should listen for connections if serverMode equals LOCAL_SERVER_MODE. Can be 0 for any port. Ignored for other values of serverMode. |
serverAddrFile | The name of the file that should be used to publish the monitor server address and port (if the server should be started). If empty, the name in the config file will be used instead. |
rsrcFiles | Flag stating whether the config file and later the model file can refernce a resource file or not (this distintion is made for better error messages only). |
bool GmSimulation::initSimulation | ( | QString | simulationFile, |
const QMap< QString, QString > & | globalVars, | ||
int | timeout = -1 , |
||
lua_State * | state = NULL |
||
) |
Initializes the simulation by reading the provided model file.
modelFile | Path for the simulation definition file |
globalVars | User supplied values for global variables that will be definied on the simulation environment. The map should be keyed by the variable name and its value should be equal the string needed to initialize the variable following the Lua syntax, such as that the statement key = value can be interpreted by Lua. This is used, for example, to fill the userParams global variable. |
timeout | An optional parameter thet when different from -1, asks the main thread to wait until the first client is connected to the monitor server. This can be important if the external monitor process needs to have access to every log message generated by GeMA. This value is the maximum time to wait in mili seconds. A value of zero waits for ever. A value of -1 disables waiting at all. |
state | This optional parameter should be almost always be set to NULL. When filled with a pointer to a Lua state, that state will be used when loading the simulation file and later during simulation execution. This option helps the integration of the GeMA environment inside other environments where the control loop is outside the GeMA library. IMPORTANT: The Lua state MUST have been compiled with LUAI_EXTRASPACE, as explained in luaEnv.h. We also expect the extra area to be filled with 0 when the state is created. |
|
private |
Loads from the given Lua environment the contents of the "modelConstants" and "modelOptions" tables, filling the _configConstants and _configOptions maps.
Lua object references are removed from the map so that its contents remains valid after the disposal of the environment used to load the config file.
GmSimulationResult GmSimulation::run | ( | ) |
Runs the simulation loaded by the call to init()
< The simulation was cancelled by user request
< The simulation was aborted by a run time error
Signal emmited whenever a model section has been parsed from the Lua file.
This signal is emmited while the model file is beeing parsed during the Lua file load.
section | The name of the parsed section ('Simulation', 'Mesh', 'StateVar', ...) |
data | A reference to the table storing the section data |
|
private |
Loads global configuration options for the library. Those include paths to loaded components, logging options, etc.
configFile | Path for the configuration file |
logFile | Path to the desired log file. If empty the value at the configuration file will be used instead. |
logMode | Flags used to override config file options for logging. |
serverMode | Flag defining if the monitor server should be started or not |
localServerPort | The port where the server should listen for connections if serverMode equals LOCAL_SERVER_MODE. Can be 0 for any port. Ignored for other values of serverMode. |
serverAddrFile | The name of the file that should be used to publish the monitor server address and port (if the server should be started). If empty, the name in the config file will be used instead. |
|
private |
Changes the simulation data for this simulation.
WARNING: You probably don't want to call this function. Use it only if really know what you are doing. For the bold only!!!
If called with NULL will clear the simulation data and also the Lua environment. When called with a pointer, replaces the simulation data with the new pointer and also CLEARS the Lua environment.
|
private |
Loads data defining the model to be simulated.
file | Path for the model file |
globalVars | User supplied values for global variables that will be definied on the simulation environment. The map should be keyed by the variable name and its value should be equal the string needed to initialize the variable following the Lua syntax, such as that the statement key = value can be interpreted by Lua. This is used, for example, to fill the userParams global variable. |
state | This optional parameter should be almost always be set to NULL. When filled with a pointer to a Lua state, that state will be used when loading the simulation file and later during simulation execution. This option helps the integration of the GeMA environment inside other environments where the control loop is outside the GeMA library. IMPORTANT: The Lua state MUST have been compiled with LUAI_EXTRASPACE, as explained in luaEnv.h. We also expect the extra area to be filled with 0 when the state is created. |
Setup logging options.
env | Lua environment loaded with configuration options |
logFile | Log file name. If empty, config file value will be used |
logMode | Log options overriding the config file |
|
private |
Initializes the monitor server depending on the configuration from serverMode and from the Lua config file. If the server is initialized, sets _monitorServer.
env | Lua environment loaded with configuration options |
serverMode | Flag defining if the monitor server should be turned on, off or use the Lua configuration settings. |
localServerPort | The port where the server should listen for connections if serverMode equals LOCAL_SERVER_MODE. Can be 0 for any port. Ignored for other values of serverMode. |
logToServer | Is the logger configured to emit signals that cn be connected to the server, so that it can forward log messages? |
serverAddrFile | Optional path to the file where the server should advertise its address. If empty, the value from the Lua config file will be used. |
|
private |
Setup the unit manager.
env | Lua environment loaded with configuration options |