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-2026, 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 AGPL VERSION 3 LICENSE OR
11 * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8.
12 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
13 * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL
14 * VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
15 *
16 * The OpenModelica software and the OSMC (Open Source Modelica Consortium)
17 * Public License (OSMC-PL) are obtained from OSMC, either from the above
18 * address, from the URLs:
19 * http://www.openmodelica.org or
20 * https://github.com/OpenModelica/ or
21 * http://www.ida.liu.se/projects/OpenModelica,
22 * and in the OpenModelica distribution.
23 *
24 * GNU AGPL version 3 is obtained from:
25 * https://www.gnu.org/licenses/licenses.html#GPL
26 *
27 * This program is distributed WITHOUT ANY WARRANTY; without
28 * even the implied warranty of MERCHANTABILITY or FITNESS
29 * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
30 * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
31 *
32 * See the full OSMC Public License conditions for more details.
33 *
34 */
35
36#ifndef _OMS_MODEL_H_
37#define _OMS_MODEL_H_
38
39#include "Clock.h"
40#include "ComRef.h"
41#include "Element.h"
42#include "ResultWriter.h"
43#include "OMSimulator/Types.h"
44#include "Snapshot.h"
45#include "Values.h"
46#include <assert.h>
47#include <pugixml.hpp>
48
49#include <ctpl_stl.h>
50
51 namespace oms
52{
53 class Component;
54 class System;
55
56 class Model
57 {
58 public: // methods
59 ~Model();
60
65 static Model* NewModel(const ComRef& cref);
66
67 const ComRef& getCref() const {return cref;}
68 System* getSystem(const ComRef& cref);
69 oms_status_enu_t delete_(const ComRef& cref);
70 Component* getComponent(const ComRef& cref);
71 System* getTopLevelSystem() const {return system;}
72 std::string getTempDirectory() const {return tempDir;}
73 oms_status_enu_t rename(const ComRef& cref);
74 oms_status_enu_t rename(const ComRef& cref, const ComRef& newCref);
75 oms_status_enu_t list(const ComRef& cref, char** contents);
76 oms_status_enu_t listVariants(const ComRef& cref, char** contents);
77 oms_status_enu_t addSystem(const ComRef& cref, oms_system_enu_t type);
78 oms_status_enu_t newResources(const ComRef& cref);
79 oms_status_enu_t addResources(const ComRef& cref, const std::string& path);
80 oms_status_enu_t deleteReferencesInSSD(const ComRef& cref);
81 oms_status_enu_t deleteResourcesInSSP(const std::string& filename);
82 oms_status_enu_t duplicateVariant(const ComRef& crefA, const ComRef& crefB);
83 oms_status_enu_t activateVariant(const ComRef& crefA, const ComRef& crefB);
84 oms_status_enu_t referenceResources(const ComRef& cref, const std::string& ssmFile);
85 oms_status_enu_t reduceSSV(const std::string& ssvfile, const std::string& ssmfile, const std::string& filepath);
86 oms_status_enu_t exportToSSD(Snapshot& snapshot) const;
87 oms_status_enu_t exportSnapshot(const ComRef& cref, char** contents);
88 oms_status_enu_t exportSSVTemplate(const ComRef& cref, const std::string& filename);
89 oms_status_enu_t exportSSMTemplate(const ComRef& cref, const std::string& filename);
90 void exportSignalFilter(Snapshot& snapshot) const;
91 void exportUnitDefinitionsToSSD(pugi::xml_node& node) const;
92 void exportEnumerationDefinitionsToSSD(pugi::xml_node& node) const;
93 oms_status_enu_t importFromSnapshot(const Snapshot& snapshot);
94 oms_status_enu_t importSnapshot(const char* snapshot, char** newCref);
95 oms_status_enu_t importSignalFilter(const std::string& filename, const Snapshot& snapshot);
96 oms_status_enu_t exportToFile(const std::string& filename) const;
97 oms_system_enu_t getSystemType(const pugi::xml_node& node, const std::string& sspVersion);
98 oms_system_enu_t getSystemTypeHelper(const pugi::xml_node& node, const std::string& sspVersion);
99 oms_status_enu_t updateParameterBindingsToSSD(pugi::xml_node& node, bool isTopSystemOrModel) const;
100 void copyResources(bool copy_resources) {this->copy_resources = copy_resources;}
101 bool copyResources() {return copy_resources;}
102
103 oms::Element** getElements() {return system ? &elements[0] : nullptr;}
104 void writeAllResourcesToFilesystem(std::vector<std::string>& resources, Snapshot& snapshot) const;
105
106 oms_status_enu_t instantiate();
107 oms_status_enu_t initialize();
108 oms_status_enu_t simulate();
109 oms_status_enu_t doStep();
110 oms_status_enu_t stepUntil(double stopTime);
111 oms_status_enu_t terminate();
112 oms_status_enu_t reset();
113
114 oms_modelState_enu_t getModelState() const {return modelState;}
115
116 oms_status_enu_t setStartTime(double value);
117 double getStartTime() const {return startTime;}
118 oms_status_enu_t setStopTime(double value);
119 double getStopTime() const {return stopTime;}
120 double getTime() const;
121
122 oms_status_enu_t setLoggingInterval(double loggingInterval);
123 double getLoggingInterval() const {return loggingInterval;}
124 oms_status_enu_t setResultFile(const std::string& filename, int bufferSize);
125 oms_status_enu_t getResultFile(char** filename, int* bufferSize);
126 oms_status_enu_t emit(double time, bool force=false, bool* emitted=NULL);
127 oms_status_enu_t addSignalsToResults(const char* regex);
128 oms_status_enu_t removeSignalsFromResults(const char* regex);
129 std::string escapeSpecialCharacters(const std::string& regex);
130
131 bool validState(int validStates) const {return (modelState & validStates);}
132
133 bool isIsolatedFMUModel() const {return isolatedFMU;}
134 void setIsolatedFMUModel() {isolatedFMU = true;}
135
136 bool useThreadPool() {return (pool != nullptr);}
137 ctpl::thread_pool& getThreadPool() {assert(pool); return *pool;}
138
139 oms_status_enu_t loadSnapshot(const pugi::xml_node& node);
140
141 std::vector<std::string> importedResources;
142
143 std::map<ComRef, char*> ssdVariants;
144
145 std::string getVariantName() {return variantName;}
146
147 private: // methods
148 Model(const ComRef& cref, const std::string& tempDir);
149
150 // stop the compiler generating methods copying the object
151 Model(Model const& copy);
152 Model& operator=(Model const& copy);
153
154 oms_status_enu_t registerSignalsForResultFile();
155
156 private: // attributes
157 ComRef cref;
158 System* system = NULL;
159 std::string tempDir;
160
161 std::vector<oms::Element*> elements;
162 bool copy_resources = true;
163
164 oms_modelState_enu_t modelState = oms_modelState_virgin;
165
166 // ssd:DefaultExperiment
167 double startTime = 0.0;
168 double stopTime = 1.0;
169
170 ResultWriter* resultFile = NULL;
171 double lastEmit;
172 double loggingInterval = 0.0;
173 int bufferSize = 10;
174 Clock clock;
175
176 Values values;
177
178 std::string resultFilename;
179 std::string signalFilterFilename = "resources/signalFilter.xml";
180
181 std::string variantName = "SystemStructure.ssd";
182
183 std::vector<std::string> externalResources;
184
185 bool isolatedFMU = false;
186
187 ctpl::thread_pool* pool = nullptr;
188
189 ComRef new_root_cref;
190 };
191}
192
193#endif
Clock.h
ComRef.h
Element.h
ResultWriter.h
Snapshot.h
Values.h
Clock
Definition Clock.h:43
oms::ComRef
ComRef - component reference.
Definition ComRef.h:51
oms::Component
Definition Component.h:65
oms::Element
Element.
Definition Element.h:51
oms::Model
Definition Model.h:57
oms::Model::setStopTime
oms_status_enu_t setStopTime(double value)
Definition Model.cpp:1154
oms::Model::getSystemType
oms_system_enu_t getSystemType(const pugi::xml_node &node, const std::string &sspVersion)
Definition Model.cpp:965
oms::Model::getLoggingInterval
double getLoggingInterval() const
Definition Model.h:123
oms::Model::resultFile
ResultWriter * resultFile
Definition Model.h:170
oms::Model::tempDir
std::string tempDir
Definition Model.h:159
oms::Model::loggingInterval
double loggingInterval
Definition Model.h:172
oms::Model::reduceSSV
oms_status_enu_t reduceSSV(const std::string &ssvfile, const std::string &ssmfile, const std::string &filepath)
Definition Model.cpp:727
oms::Model::externalResources
std::vector< std::string > externalResources
list of external ssv or ssm resources from filesystem
Definition Model.h:183
oms::Model::getStartTime
double getStartTime() const
Definition Model.h:117
oms::Model::addSystem
oms_status_enu_t addSystem(const ComRef &cref, oms_system_enu_t type)
Definition Model.cpp:809
oms::Model::importSignalFilter
oms_status_enu_t importSignalFilter(const std::string &filename, const Snapshot &snapshot)
Definition Model.cpp:1595
oms::Model::importSnapshot
oms_status_enu_t importSnapshot(const char *snapshot, char **newCref)
Definition Model.cpp:309
oms::Model::clock
Clock clock
Definition Model.h:174
oms::Model::useThreadPool
bool useThreadPool()
Definition Model.h:136
oms::Model::importedResources
std::vector< std::string > importedResources
list of imported resources from ssp
Definition Model.h:141
oms::Model::updateParameterBindingsToSSD
oms_status_enu_t updateParameterBindingsToSSD(pugi::xml_node &node, bool isTopSystemOrModel) const
Definition Model.cpp:626
oms::Model::exportSSVTemplate
oms_status_enu_t exportSSVTemplate(const ComRef &cref, const std::string &filename)
Definition Model.cpp:507
oms::Model::simulate
oms_status_enu_t simulate()
Definition Model.cpp:1267
oms::Model::getTime
double getTime() const
Definition Model.cpp:1160
oms::Model::getVariantName
std::string getVariantName()
Definition Model.h:145
oms::Model::getElements
oms::Element ** getElements()
Definition Model.h:103
oms::Model::importFromSnapshot
oms_status_enu_t importFromSnapshot(const Snapshot &snapshot)
Definition Model.cpp:875
oms::Model::doStep
oms_status_enu_t doStep()
Definition Model.cpp:1288
oms::Model::system
System * system
Definition Model.h:158
oms::Model::bufferSize
int bufferSize
Definition Model.h:173
oms::Model::reset
oms_status_enu_t reset()
Definition Model.cpp:1362
oms::Model::getSystem
System * getSystem(const ComRef &cref)
Definition Model.cpp:375
oms::Model::startTime
double startTime
Definition Model.h:167
oms::Model::getModelState
oms_modelState_enu_t getModelState() const
Definition Model.h:114
oms::Model::registerSignalsForResultFile
oms_status_enu_t registerSignalsForResultFile()
Definition Model.cpp:1391
oms::Model::terminate
oms_status_enu_t terminate()
Definition Model.cpp:1332
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:143
oms::Model::getComponent
Component * getComponent(const ComRef &cref)
Definition Model.cpp:392
oms::Model::getTopLevelSystem
System * getTopLevelSystem() const
Definition Model.h:71
oms::Model::~Model
~Model()
Definition Model.cpp:62
oms::Model::instantiate
oms_status_enu_t instantiate()
Definition Model.cpp:1167
oms::Model::resultFilename
std::string resultFilename
default <name>_res.mat
Definition Model.h:178
oms::Model::removeSignalsFromResults
oms_status_enu_t removeSignalsFromResults(const char *regex)
Definition Model.cpp:1488
oms::Model::escapeSpecialCharacters
std::string escapeSpecialCharacters(const std::string &regex)
Definition Model.cpp:1574
oms::Model::exportSignalFilter
void exportSignalFilter(Snapshot &snapshot) const
Definition Model.cpp:1496
oms::Model::exportToFile
oms_status_enu_t exportToFile(const std::string &filename) const
Definition Model.cpp:1039
oms::Model::exportSSMTemplate
oms_status_enu_t exportSSMTemplate(const ComRef &cref, const std::string &filename)
Definition Model.cpp:579
oms::Model::modelState
oms_modelState_enu_t modelState
Definition Model.h:164
oms::Model::exportEnumerationDefinitionsToSSD
void exportEnumerationDefinitionsToSSD(pugi::xml_node &node) const
Definition Model.cpp:1546
oms::Model::elements
std::vector< oms::Element * > elements
Definition Model.h:161
oms::Model::lastEmit
double lastEmit
Definition Model.h:171
oms::Model::NewModel
static Model * NewModel(const ComRef &cref)
Definition Model.cpp:90
oms::Model::values
Values values
Definition Model.h:176
oms::Model::copyResources
bool copyResources()
Definition Model.h:101
oms::Model::addSignalsToResults
oms_status_enu_t addSignalsToResults(const char *regex)
Definition Model.cpp:1480
oms::Model::signalFilterFilename
std::string signalFilterFilename
Definition Model.h:179
oms::Model::getSystemTypeHelper
oms_system_enu_t getSystemTypeHelper(const pugi::xml_node &node, const std::string &sspVersion)
Definition Model.cpp:1016
oms::Model::emit
oms_status_enu_t emit(double time, bool force=false, bool *emitted=NULL)
Definition Model.cpp:1402
oms::Model::pool
ctpl::thread_pool * pool
Definition Model.h:187
oms::Model::writeAllResourcesToFilesystem
void writeAllResourcesToFilesystem(std::vector< std::string > &resources, Snapshot &snapshot) const
Definition Model.cpp:1093
oms::Model::getThreadPool
ctpl::thread_pool & getThreadPool()
Definition Model.h:137
oms::Model::loadSnapshot
oms_status_enu_t loadSnapshot(const pugi::xml_node &node)
Definition Model.cpp:163
oms::Model::setLoggingInterval
oms_status_enu_t setLoggingInterval(double loggingInterval)
Definition Model.cpp:1383
oms::Model::deleteReferencesInSSD
oms_status_enu_t deleteReferencesInSSD(const ComRef &cref)
Definition Model.cpp:770
oms::Model::rename
oms_status_enu_t rename(const ComRef &cref)
Definition Model.cpp:124
oms::Model::referenceResources
oms_status_enu_t referenceResources(const ComRef &cref, const std::string &ssmFile)
Definition Model.cpp:697
oms::Model::stepUntil
oms_status_enu_t stepUntil(double stopTime)
Definition Model.cpp:1308
oms::Model::isolatedFMU
bool isolatedFMU
Definition Model.h:185
oms::Model::copy_resources
bool copy_resources
Definition Model.h:162
oms::Model::addResources
oms_status_enu_t addResources(const ComRef &cref, const std::string &path)
Definition Model.cpp:669
oms::Model::duplicateVariant
oms_status_enu_t duplicateVariant(const ComRef &crefA, const ComRef &crefB)
Definition Model.cpp:198
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:1472
oms::Model::listVariants
oms_status_enu_t listVariants(const ComRef &cref, char **contents)
Definition Model.cpp:279
oms::Model::setStartTime
oms_status_enu_t setStartTime(double value)
Definition Model.cpp:1145
oms::Model::setIsolatedFMUModel
void setIsolatedFMUModel()
Definition Model.h:134
oms::Model::delete_
oms_status_enu_t delete_(const ComRef &cref)
Definition Model.cpp:406
oms::Model::getCref
const ComRef & getCref() const
Definition Model.h:67
oms::Model::exportToSSD
oms_status_enu_t exportToSSD(Snapshot &snapshot) const
Definition Model.cpp:835
oms::Model::getTempDirectory
std::string getTempDirectory() const
Definition Model.h:72
oms::Model::copyResources
void copyResources(bool copy_resources)
Definition Model.h:100
oms::Model::newResources
oms_status_enu_t newResources(const ComRef &cref)
Definition Model.cpp:648
oms::Model::activateVariant
oms_status_enu_t activateVariant(const ComRef &crefA, const ComRef &crefB)
Definition Model.cpp:244
oms::Model::new_root_cref
ComRef new_root_cref
Definition Model.h:189
oms::Model::Model
Model(Model const &copy)
not implemented
oms::Model::getStopTime
double getStopTime() const
Definition Model.h:119
oms::Model::validState
bool validState(int validStates) const
Definition Model.h:131
oms::Model::stopTime
double stopTime
Definition Model.h:168
oms::Model::list
oms_status_enu_t list(const ComRef &cref, char **contents)
Definition Model.cpp:424
oms::Model::cref
ComRef cref
Definition Model.h:157
oms::Model::deleteResourcesInSSP
oms_status_enu_t deleteResourcesInSSP(const std::string &filename)
Definition Model.cpp:791
oms::Model::exportUnitDefinitionsToSSD
void exportUnitDefinitionsToSSD(pugi::xml_node &node) const
Definition Model.cpp:1515
oms::Model::isIsolatedFMUModel
bool isIsolatedFMUModel() const
Definition Model.h:133
oms::Model::initialize
oms_status_enu_t initialize()
Definition Model.cpp:1194
oms::Model::setResultFile
oms_status_enu_t setResultFile(const std::string &filename, int bufferSize)
Definition Model.cpp:1429
oms::Model::variantName
std::string variantName
default name
Definition Model.h:181
oms::Model::exportSnapshot
oms_status_enu_t exportSnapshot(const ComRef &cref, char **contents)
Definition Model.cpp:491
oms::ResultWriter
Definition ResultWriter.h:73
oms::Snapshot
Definition Snapshot.h:51
oms::System
Definition System.h:66
oms::Values
Definition Values.h:50
oms
Definition AlgLoop.h:49