OMSimulatorLib The OMSimulator project is a FMI-based co-simulation environment.

Loading...
Searching...
No Matches
Model.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenModelica.
3 *
4 * Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC),
5 * c/o Linköpings universitet, Department of Computer and Information Science,
6 * SE-58183 Linköping, Sweden.
7 *
8 * All rights reserved.
9 *
10 * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
11 * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
12 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
13 * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
14 * ACCORDING TO RECIPIENTS CHOICE.
15 *
16 * The OpenModelica software and the Open Source Modelica
17 * Consortium (OSMC) Public License (OSMC-PL) are obtained
18 * from OSMC, either from the above address,
19 * from the URLs: http://www.ida.liu.se/projects/OpenModelica or
20 * http://www.openmodelica.org, and in the OpenModelica distribution.
21 * GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
22 *
23 * This program is distributed WITHOUT ANY WARRANTY; without
24 * even the implied warranty of MERCHANTABILITY or FITNESS
25 * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
26 * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
27 *
28 * See the full OSMC Public License conditions for more details.
29 *
30 */
31
32#ifndef _OMS_MODEL_H_
33#define _OMS_MODEL_H_
34
35#include "Clock.h"
36#include "ComRef.h"
37#include "Element.h"
38#include "ResultWriter.h"
39#include "OMSimulator/Types.h"
40#include "Snapshot.h"
41#include "Values.h"
42#include <assert.h>
43#include <pugixml.hpp>
44
45#include <ctpl_stl.h>
46
47 namespace oms
48{
49 class Component;
50 class System;
51
52 class Model
53 {
54 public: // methods
55 ~Model();
56
61 static Model* NewModel(const ComRef& cref);
62
63 const ComRef& getCref() const {return cref;}
64 System* getSystem(const ComRef& cref);
65 oms_status_enu_t delete_(const ComRef& cref);
66 Component* getComponent(const ComRef& cref);
67 System* getTopLevelSystem() const {return system;}
68 std::string getTempDirectory() const {return tempDir;}
69 oms_status_enu_t rename(const ComRef& cref);
70 oms_status_enu_t rename(const ComRef& cref, const ComRef& newCref);
71 oms_status_enu_t list(const ComRef& cref, char** contents);
72 oms_status_enu_t listVariants(const ComRef& cref, char** contents);
73 oms_status_enu_t addSystem(const ComRef& cref, oms_system_enu_t type);
74 oms_status_enu_t newResources(const ComRef& cref);
75 oms_status_enu_t addResources(const ComRef& cref, const std::string& path);
76 oms_status_enu_t deleteReferencesInSSD(const ComRef& cref);
77 oms_status_enu_t deleteResourcesInSSP(const std::string& filename);
78 oms_status_enu_t duplicateVariant(const ComRef& crefA, const ComRef& crefB);
79 oms_status_enu_t activateVariant(const ComRef& crefA, const ComRef& crefB);
80 oms_status_enu_t referenceResources(const ComRef& cref, const std::string& ssmFile);
81 oms_status_enu_t reduceSSV(const std::string& ssvfile, const std::string& ssmfile, const std::string& filepath);
82 oms_status_enu_t exportToSSD(Snapshot& snapshot) const;
83 oms_status_enu_t exportSnapshot(const ComRef& cref, char** contents);
84 oms_status_enu_t exportSSVTemplate(const ComRef& cref, const std::string& filename);
85 oms_status_enu_t exportSSMTemplate(const ComRef& cref, const std::string& filename);
86 void exportSignalFilter(Snapshot& snapshot) const;
87 void exportUnitDefinitionsToSSD(pugi::xml_node& node) const;
88 void exportEnumerationDefinitionsToSSD(pugi::xml_node& node) const;
89 oms_status_enu_t importFromSnapshot(const Snapshot& snapshot);
90 oms_status_enu_t importSnapshot(const char* snapshot, char** newCref);
91 oms_status_enu_t importSignalFilter(const std::string& filename, const Snapshot& snapshot);
92 oms_status_enu_t exportToFile(const std::string& filename) const;
93 oms_system_enu_t getSystemType(const pugi::xml_node& node, const std::string& sspVersion);
94 oms_system_enu_t getSystemTypeHelper(const pugi::xml_node& node, const std::string& sspVersion);
95 oms_status_enu_t updateParameterBindingsToSSD(pugi::xml_node& node, bool isTopSystemOrModel) const;
96 void copyResources(bool copy_resources) {this->copy_resources = copy_resources;}
97 bool copyResources() {return copy_resources;}
98
99 oms::Element** getElements() {return system ? &elements[0] : nullptr;}
100 void writeAllResourcesToFilesystem(std::vector<std::string>& resources, Snapshot& snapshot) const;
101
102 oms_status_enu_t instantiate();
103 oms_status_enu_t initialize();
104 oms_status_enu_t simulate();
105 oms_status_enu_t doStep();
106 oms_status_enu_t stepUntil(double stopTime);
107 oms_status_enu_t terminate();
108 oms_status_enu_t reset();
109
110 oms_modelState_enu_t getModelState() const {return modelState;}
111
112 oms_status_enu_t setStartTime(double value);
113 double getStartTime() const {return startTime;}
114 oms_status_enu_t setStopTime(double value);
115 double getStopTime() const {return stopTime;}
116 double getTime() const;
117
118 oms_status_enu_t setLoggingInterval(double loggingInterval);
119 double getLoggingInterval() const {return loggingInterval;}
120 oms_status_enu_t setResultFile(const std::string& filename, int bufferSize);
121 oms_status_enu_t getResultFile(char** filename, int* bufferSize);
122 oms_status_enu_t emit(double time, bool force=false, bool* emitted=NULL);
123 oms_status_enu_t addSignalsToResults(const char* regex);
124 oms_status_enu_t removeSignalsFromResults(const char* regex);
125 std::string escapeSpecialCharacters(const std::string& regex);
126
127 bool validState(int validStates) const {return (modelState & validStates);}
128
129 bool isIsolatedFMUModel() const {return isolatedFMU;}
130 void setIsolatedFMUModel() {isolatedFMU = true;}
131
132 bool useThreadPool() {return (pool != nullptr);}
133 ctpl::thread_pool& getThreadPool() {assert(pool); return *pool;}
134
135 oms_status_enu_t loadSnapshot(const pugi::xml_node& node);
136
137 std::vector<std::string> importedResources;
138
139 std::map<ComRef, char*> ssdVariants;
140
141 std::string getVariantName() {return variantName;}
142
143 private: // methods
144 Model(const ComRef& cref, const std::string& tempDir);
145
146 // stop the compiler generating methods copying the object
147 Model(Model const& copy);
148 Model& operator=(Model const& copy);
149
150 oms_status_enu_t registerSignalsForResultFile();
151
152 private: // attributes
153 ComRef cref;
154 System* system = NULL;
155 std::string tempDir;
156
157 std::vector<oms::Element*> elements;
158 bool copy_resources = true;
159
160 oms_modelState_enu_t modelState = oms_modelState_virgin;
161
162 // ssd:DefaultExperiment
163 double startTime = 0.0;
164 double stopTime = 1.0;
165
166 ResultWriter* resultFile = NULL;
167 double lastEmit;
168 double loggingInterval = 0.0;
169 int bufferSize = 10;
170 Clock clock;
171
172 Values values;
173
174 std::string resultFilename;
175 std::string signalFilterFilename = "resources/signalFilter.xml";
176
177 std::string variantName = "SystemStructure.ssd";
178
179 std::vector<std::string> externalResources;
180
181 bool isolatedFMU = false;
182
183 ctpl::thread_pool* pool = nullptr;
184
185 ComRef new_root_cref;
186 };
187}
188
189#endif
Clock.h
ComRef.h
Element.h
ResultWriter.h
Snapshot.h
Values.h
Clock
Definition Clock.h:39
oms::ComRef
ComRef - component reference.
Definition ComRef.h:47
oms::Component
Definition Component.h:60
oms::Element
Element.
Definition Element.h:47
oms::Model
Definition Model.h:53
oms::Model::setStopTime
oms_status_enu_t setStopTime(double value)
Definition Model.cpp:1150
oms::Model::getSystemType
oms_system_enu_t getSystemType(const pugi::xml_node &node, const std::string &sspVersion)
Definition Model.cpp:961
oms::Model::getLoggingInterval
double getLoggingInterval() const
Definition Model.h:119
oms::Model::resultFile
ResultWriter * resultFile
Definition Model.h:166
oms::Model::tempDir
std::string tempDir
Definition Model.h:155
oms::Model::loggingInterval
double loggingInterval
Definition Model.h:168
oms::Model::reduceSSV
oms_status_enu_t reduceSSV(const std::string &ssvfile, const std::string &ssmfile, const std::string &filepath)
Definition Model.cpp:723
oms::Model::externalResources
std::vector< std::string > externalResources
list of external ssv or ssm resources from filesystem
Definition Model.h:179
oms::Model::getStartTime
double getStartTime() const
Definition Model.h:113
oms::Model::addSystem
oms_status_enu_t addSystem(const ComRef &cref, oms_system_enu_t type)
Definition Model.cpp:805
oms::Model::importSignalFilter
oms_status_enu_t importSignalFilter(const std::string &filename, const Snapshot &snapshot)
Definition Model.cpp:1591
oms::Model::importSnapshot
oms_status_enu_t importSnapshot(const char *snapshot, char **newCref)
Definition Model.cpp:305
oms::Model::clock
Clock clock
Definition Model.h:170
oms::Model::useThreadPool
bool useThreadPool()
Definition Model.h:132
oms::Model::importedResources
std::vector< std::string > importedResources
list of imported resources from ssp
Definition Model.h:137
oms::Model::updateParameterBindingsToSSD
oms_status_enu_t updateParameterBindingsToSSD(pugi::xml_node &node, bool isTopSystemOrModel) const
Definition Model.cpp:622
oms::Model::exportSSVTemplate
oms_status_enu_t exportSSVTemplate(const ComRef &cref, const std::string &filename)
Definition Model.cpp:503
oms::Model::simulate
oms_status_enu_t simulate()
Definition Model.cpp:1263
oms::Model::getTime
double getTime() const
Definition Model.cpp:1156
oms::Model::getVariantName
std::string getVariantName()
Definition Model.h:141
oms::Model::getElements
oms::Element ** getElements()
Definition Model.h:99
oms::Model::importFromSnapshot
oms_status_enu_t importFromSnapshot(const Snapshot &snapshot)
Definition Model.cpp:871
oms::Model::doStep
oms_status_enu_t doStep()
Definition Model.cpp:1284
oms::Model::system
System * system
Definition Model.h:154
oms::Model::bufferSize
int bufferSize
Definition Model.h:169
oms::Model::reset
oms_status_enu_t reset()
Definition Model.cpp:1358
oms::Model::getSystem
System * getSystem(const ComRef &cref)
Definition Model.cpp:371
oms::Model::startTime
double startTime
Definition Model.h:163
oms::Model::getModelState
oms_modelState_enu_t getModelState() const
Definition Model.h:110
oms::Model::registerSignalsForResultFile
oms_status_enu_t registerSignalsForResultFile()
Definition Model.cpp:1387
oms::Model::terminate
oms_status_enu_t terminate()
Definition Model.cpp:1328
oms::Model::ssdVariants
std::map< ComRef, char * > ssdVariants
list of all variants copied when user create a new variant using oms_duplicateVariant()
Definition Model.h:139
oms::Model::getComponent
Component * getComponent(const ComRef &cref)
Definition Model.cpp:388
oms::Model::getTopLevelSystem
System * getTopLevelSystem() const
Definition Model.h:67
oms::Model::~Model
~Model()
Definition Model.cpp:58
oms::Model::instantiate
oms_status_enu_t instantiate()
Definition Model.cpp:1163
oms::Model::resultFilename
std::string resultFilename
default <name>_res.mat
Definition Model.h:174
oms::Model::removeSignalsFromResults
oms_status_enu_t removeSignalsFromResults(const char *regex)
Definition Model.cpp:1484
oms::Model::escapeSpecialCharacters
std::string escapeSpecialCharacters(const std::string &regex)
Definition Model.cpp:1570
oms::Model::exportSignalFilter
void exportSignalFilter(Snapshot &snapshot) const
Definition Model.cpp:1492
oms::Model::exportToFile
oms_status_enu_t exportToFile(const std::string &filename) const
Definition Model.cpp:1035
oms::Model::exportSSMTemplate
oms_status_enu_t exportSSMTemplate(const ComRef &cref, const std::string &filename)
Definition Model.cpp:575
oms::Model::modelState
oms_modelState_enu_t modelState
Definition Model.h:160
oms::Model::exportEnumerationDefinitionsToSSD
void exportEnumerationDefinitionsToSSD(pugi::xml_node &node) const
Definition Model.cpp:1542
oms::Model::elements
std::vector< oms::Element * > elements
Definition Model.h:157
oms::Model::lastEmit
double lastEmit
Definition Model.h:167
oms::Model::NewModel
static Model * NewModel(const ComRef &cref)
Definition Model.cpp:86
oms::Model::values
Values values
Definition Model.h:172
oms::Model::copyResources
bool copyResources()
Definition Model.h:97
oms::Model::addSignalsToResults
oms_status_enu_t addSignalsToResults(const char *regex)
Definition Model.cpp:1476
oms::Model::signalFilterFilename
std::string signalFilterFilename
Definition Model.h:175
oms::Model::getSystemTypeHelper
oms_system_enu_t getSystemTypeHelper(const pugi::xml_node &node, const std::string &sspVersion)
Definition Model.cpp:1012
oms::Model::emit
oms_status_enu_t emit(double time, bool force=false, bool *emitted=NULL)
Definition Model.cpp:1398
oms::Model::pool
ctpl::thread_pool * pool
Definition Model.h:183
oms::Model::writeAllResourcesToFilesystem
void writeAllResourcesToFilesystem(std::vector< std::string > &resources, Snapshot &snapshot) const
Definition Model.cpp:1089
oms::Model::getThreadPool
ctpl::thread_pool & getThreadPool()
Definition Model.h:133
oms::Model::loadSnapshot
oms_status_enu_t loadSnapshot(const pugi::xml_node &node)
Definition Model.cpp:159
oms::Model::setLoggingInterval
oms_status_enu_t setLoggingInterval(double loggingInterval)
Definition Model.cpp:1379
oms::Model::deleteReferencesInSSD
oms_status_enu_t deleteReferencesInSSD(const ComRef &cref)
Definition Model.cpp:766
oms::Model::rename
oms_status_enu_t rename(const ComRef &cref)
Definition Model.cpp:120
oms::Model::referenceResources
oms_status_enu_t referenceResources(const ComRef &cref, const std::string &ssmFile)
Definition Model.cpp:693
oms::Model::stepUntil
oms_status_enu_t stepUntil(double stopTime)
Definition Model.cpp:1304
oms::Model::isolatedFMU
bool isolatedFMU
Definition Model.h:181
oms::Model::copy_resources
bool copy_resources
Definition Model.h:158
oms::Model::addResources
oms_status_enu_t addResources(const ComRef &cref, const std::string &path)
Definition Model.cpp:665
oms::Model::duplicateVariant
oms_status_enu_t duplicateVariant(const ComRef &crefA, const ComRef &crefB)
Definition Model.cpp:194
oms::Model::operator=
Model & operator=(Model const &copy)
not implemented
oms::Model::getResultFile
oms_status_enu_t getResultFile(char **filename, int *bufferSize)
Definition Model.cpp:1468
oms::Model::listVariants
oms_status_enu_t listVariants(const ComRef &cref, char **contents)
Definition Model.cpp:275
oms::Model::setStartTime
oms_status_enu_t setStartTime(double value)
Definition Model.cpp:1141
oms::Model::setIsolatedFMUModel
void setIsolatedFMUModel()
Definition Model.h:130
oms::Model::delete_
oms_status_enu_t delete_(const ComRef &cref)
Definition Model.cpp:402
oms::Model::getCref
const ComRef & getCref() const
Definition Model.h:63
oms::Model::exportToSSD
oms_status_enu_t exportToSSD(Snapshot &snapshot) const
Definition Model.cpp:831
oms::Model::getTempDirectory
std::string getTempDirectory() const
Definition Model.h:68
oms::Model::copyResources
void copyResources(bool copy_resources)
Definition Model.h:96
oms::Model::newResources
oms_status_enu_t newResources(const ComRef &cref)
Definition Model.cpp:644
oms::Model::activateVariant
oms_status_enu_t activateVariant(const ComRef &crefA, const ComRef &crefB)
Definition Model.cpp:240
oms::Model::new_root_cref
ComRef new_root_cref
Definition Model.h:185
oms::Model::Model
Model(Model const &copy)
not implemented
oms::Model::getStopTime
double getStopTime() const
Definition Model.h:115
oms::Model::validState
bool validState(int validStates) const
Definition Model.h:127
oms::Model::stopTime
double stopTime
Definition Model.h:164
oms::Model::list
oms_status_enu_t list(const ComRef &cref, char **contents)
Definition Model.cpp:420
oms::Model::cref
ComRef cref
Definition Model.h:153
oms::Model::deleteResourcesInSSP
oms_status_enu_t deleteResourcesInSSP(const std::string &filename)
Definition Model.cpp:787
oms::Model::exportUnitDefinitionsToSSD
void exportUnitDefinitionsToSSD(pugi::xml_node &node) const
Definition Model.cpp:1511
oms::Model::isIsolatedFMUModel
bool isIsolatedFMUModel() const
Definition Model.h:129
oms::Model::initialize
oms_status_enu_t initialize()
Definition Model.cpp:1190
oms::Model::setResultFile
oms_status_enu_t setResultFile(const std::string &filename, int bufferSize)
Definition Model.cpp:1425
oms::Model::variantName
std::string variantName
default name
Definition Model.h:177
oms::Model::exportSnapshot
oms_status_enu_t exportSnapshot(const ComRef &cref, char **contents)
Definition Model.cpp:487
oms::ResultWriter
Definition ResultWriter.h:69
oms::Snapshot
Definition Snapshot.h:47
oms::System
Definition System.h:62
oms::Values
Definition Values.h:46
oms
Definition AlgLoop.h:45