OMSimulatorLib
The OMSimulator project is a FMI-based co-simulation environment that supports ordinary (i.e., non-delayed) and TLM connections.
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 "Types.h"
40 #include "Snapshot.h"
41 #include "Values.h"
42 #include <assert.h>
43 #include <pugixml.hpp>
44 
45 #if (BOOST_VERSION >= 105300)
46 #include <ctpl.h>
47 #else // use the standard queue
48 #include <ctpl_stl.h>
49 #endif
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);
79  oms_status_enu_t addResources(const ComRef& cref, const std::string& path);
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;
93  oms_status_enu_t importSnapshot(const char* snapshot, char** newCref);
94  oms_status_enu_t importSignalFilter(const std::string& filename, const Snapshot& snapshot);
95  oms_status_enu_t exportToFile(const std::string& filename) const;
96  oms_system_enu_t getSystemType(const pugi::xml_node& node, const std::string& sspVersion);
97  oms_system_enu_t getSystemTypeHelper(const pugi::xml_node& node, const std::string& sspVersion);
98  oms_status_enu_t updateParameterBindingsToSSD(pugi::xml_node& node, bool isTopSystemOrModel) const;
99  void copyResources(bool copy_resources) {this->copy_resources = copy_resources;}
100  bool copyResources() {return copy_resources;}
101 
103  void writeAllResourcesToFilesystem(std::vector<std::string>& resources, Snapshot& snapshot) const;
104 
112 
114 
115  oms_status_enu_t setStartTime(double value);
116  double getStartTime() const {return startTime;}
117  oms_status_enu_t setStopTime(double value);
118  double getStopTime() const {return stopTime;}
119  double getTime() const;
120 
122  double getLoggingInterval() const {return loggingInterval;}
123  oms_status_enu_t setResultFile(const std::string& filename, int bufferSize);
124  oms_status_enu_t getResultFile(char** filename, int* bufferSize);
125  oms_status_enu_t emit(double time, bool force=false, bool* emitted=NULL);
126  oms_status_enu_t addSignalsToResults(const char* regex);
127  oms_status_enu_t removeSignalsFromResults(const char* regex);
128 
129  bool validState(int validStates) const {return (modelState & validStates);}
130 
131  bool isIsolatedFMUModel() const {return isolatedFMU;}
133 
134  bool useThreadPool() {return (pool != nullptr);}
135  ctpl::thread_pool& getThreadPool() {assert(pool); return *pool;}
136 
137  oms_status_enu_t loadSnapshot(const pugi::xml_node& node);
138 
139  std::vector<std::string> importedResources;
140 
141  std::map<ComRef, char*> ssdVariants;
142 
143  std::string getVariantName() {return variantName;}
144 
145  private: // methods
146  Model(const ComRef& cref, const std::string& tempDir);
147 
148  // stop the compiler generating methods copying the object
149  Model(Model const& copy);
150  Model& operator=(Model const& copy);
151 
153 
154  private: // attributes
156  System* system = NULL;
157  std::string tempDir;
158 
159  std::vector<oms::Element*> elements;
160  bool copy_resources = true;
161 
163 
164  // ssd:DefaultExperiment
165  double startTime = 0.0;
166  double stopTime = 1.0;
167 
169  double lastEmit;
170  double loggingInterval = 0.0;
171  int bufferSize = 10;
173 
175 
176  std::string resultFilename;
177  std::string signalFilterFilename = "resources/signalFilter.xml";
178 
179  std::string variantName = "SystemStructure.ssd";
180 
181  std::vector<std::string> externalResources;
182 
183  bool isolatedFMU = false;
184 
185  ctpl::thread_pool* pool = nullptr;
186 
188  };
189 }
190 
191 #endif
oms_status_enu_t setResultFile(const std::string &filename, int bufferSize)
Definition: Model.cpp:1394
oms_status_enu_t list(const ComRef &cref, char **contents)
Definition: Model.cpp:407
oms_status_enu_t removeSignalsFromResults(const char *regex)
Definition: Model.cpp:1453
oms_status_enu_t emit(double time, bool force=false, bool *emitted=NULL)
Definition: Model.cpp:1367
System * getTopLevelSystem() const
Definition: Model.h:71
oms_status_enu_t initialize()
Definition: Model.cpp:1159
Definition: ResultWriter.h:68
Definition: Model.h:56
Definition: Clock.h:38
Model & operator=(Model const &copy)
not implemented
oms_status_enu_t setLoggingInterval(double loggingInterval)
Definition: Model.cpp:1348
double getLoggingInterval() const
Definition: Model.h:122
Model(const ComRef &cref, const std::string &tempDir)
Definition: Model.cpp:47
oms_status_enu_t activateVariant(const ComRef &crefA, const ComRef &crefB)
Definition: Model.cpp:229
oms_modelState_enu_t modelState
Definition: Model.h:162
oms_status_enu_t updateParameterBindingsToSSD(pugi::xml_node &node, bool isTopSystemOrModel) const
Definition: Model.cpp:597
oms_status_enu_t setStopTime(double value)
Definition: Model.cpp:1119
ComRef cref
Definition: Model.h:155
bool validState(int validStates) const
Definition: Model.h:129
oms_status_enu_t reduceSSV(const std::string &ssvfile, const std::string &ssmfile, const std::string &filepath)
Definition: Model.cpp:698
std::map< ComRef, char * > ssdVariants
list of all variants copied when user create a new variant using oms_duplicateVariant() ...
Definition: Model.h:141
oms_status_enu_t referenceResources(const ComRef &cref, const std::string &ssmFile)
Definition: Model.cpp:668
~Model()
Definition: Model.cpp:57
std::string getTempDirectory() const
Definition: Model.h:72
std::string tempDir
Definition: Model.h:157
ComRef new_root_cref
Definition: Model.h:187
int bufferSize
Definition: Model.h:171
oms_status_enu_t newResources(const ComRef &cref)
Definition: Model.cpp:619
oms_status_enu_t
Definition: Types.h:43
oms_status_enu_t addSignalsToResults(const char *regex)
Definition: Model.cpp:1445
System * system
Definition: Model.h:156
oms_status_enu_t doStep()
Definition: Model.cpp:1253
void exportSignalFilter(Snapshot &snapshot) const
Definition: Model.cpp:1461
Values values
Definition: Model.h:174
oms_modelState_enu_t getModelState() const
Definition: Model.h:113
std::vector< std::string > importedResources
list of imported resources from ssp
Definition: Model.h:139
ctpl::thread_pool * pool
Definition: Model.h:185
oms_modelState_enu_t
Definition: Types.h:52
System * getSystem(const ComRef &cref)
Definition: Model.cpp:358
oms_status_enu_t terminate()
Definition: Model.cpp:1297
double stopTime
Definition: Model.h:166
oms_status_enu_t simulate()
Definition: Model.cpp:1232
Definition: Snapshot.h:46
void setIsolatedFMUModel()
Definition: Model.h:132
oms_status_enu_t exportSnapshot(const ComRef &cref, char **contents)
Definition: Model.cpp:474
void writeAllResourcesToFilesystem(std::vector< std::string > &resources, Snapshot &snapshot) const
Definition: Model.cpp:1058
double getStartTime() const
Definition: Model.h:116
oms_system_enu_t getSystemType(const pugi::xml_node &node, const std::string &sspVersion)
Definition: Model.cpp:930
oms_status_enu_t setStartTime(double value)
Definition: Model.cpp:1110
void exportUnitDefinitionsToSSD(pugi::xml_node &node) const
Definition: Model.cpp:1480
oms_status_enu_t importFromSnapshot(const Snapshot &snapshot)
Definition: Model.cpp:844
oms_status_enu_t addSystem(const ComRef &cref, oms_system_enu_t type)
Definition: Model.cpp:780
double startTime
Definition: Model.h:165
ComRef - component reference.
Definition: ComRef.h:46
oms_system_enu_t
Definition: Types.h:121
Definition: Component.h:60
oms_status_enu_t deleteReferencesInSSD(const ComRef &cref)
Definition: Model.cpp:741
double loggingInterval
Definition: Model.h:170
oms_status_enu_t stepUntil(double stopTime)
Definition: Model.cpp:1273
Component * getComponent(const ComRef &cref)
Definition: Model.cpp:375
oms_status_enu_t rename(const ComRef &cref)
Definition: Model.cpp:116
oms_status_enu_t exportSSMTemplate(const ComRef &cref, const std::string &filename)
Definition: Model.cpp:550
oms_status_enu_t loadSnapshot(const pugi::xml_node &node)
Definition: Model.cpp:155
Definition: Values.h:45
std::vector< std::string > externalResources
list of external ssv or ssm resources from filesystem
Definition: Model.h:181
bool isolatedFMU
Definition: Model.h:183
bool useThreadPool()
Definition: Model.h:134
Clock clock
Definition: Model.h:172
std::string resultFilename
default <name>_res.mat
Definition: Model.h:176
bool copy_resources
Definition: Model.h:160
oms_status_enu_t registerSignalsForResultFile()
Definition: Model.cpp:1356
double getStopTime() const
Definition: Model.h:118
Definition: AlgLoop.h:44
std::vector< oms::Element * > elements
Definition: Model.h:159
ctpl::thread_pool & getThreadPool()
Definition: Model.h:135
std::string getVariantName()
Definition: Model.h:143
oms_status_enu_t exportSSVTemplate(const ComRef &cref, const std::string &filename)
Definition: Model.cpp:490
oms_status_enu_t importSnapshot(const char *snapshot, char **newCref)
Definition: Model.cpp:292
void copyResources(bool copy_resources)
Definition: Model.h:99
oms_status_enu_t reset()
Definition: Model.cpp:1327
std::string variantName
default name
Definition: Model.h:179
oms_system_enu_t getSystemTypeHelper(const pugi::xml_node &node, const std::string &sspVersion)
Definition: Model.cpp:981
oms_status_enu_t deleteResourcesInSSP(const std::string &filename)
Definition: Model.cpp:762
bool isIsolatedFMUModel() const
Definition: Model.h:131
Element.
Definition: Element.h:49
oms_status_enu_t getResultFile(char **filename, int *bufferSize)
Definition: Model.cpp:1437
static Model * NewModel(const ComRef &cref)
Definition: Model.cpp:82
Definition: Types.h:53
const ComRef & getCref() const
Definition: Model.h:67
ResultWriter * resultFile
Definition: Model.h:168
oms_status_enu_t duplicateVariant(const ComRef &crefA, const ComRef &crefB)
Definition: Model.cpp:190
std::string signalFilterFilename
Definition: Model.h:177
oms_status_enu_t exportToSSD(Snapshot &snapshot) const
Definition: Model.cpp:806
Definition: System.h:69
oms_status_enu_t instantiate()
Definition: Model.cpp:1132
oms::Element ** getElements()
Definition: Model.h:102
oms_status_enu_t delete_(const ComRef &cref)
Definition: Model.cpp:389
bool copyResources()
Definition: Model.h:100
oms_status_enu_t importSignalFilter(const std::string &filename, const Snapshot &snapshot)
Definition: Model.cpp:1511
oms_status_enu_t addResources(const ComRef &cref, const std::string &path)
Definition: Model.cpp:640
oms_status_enu_t listVariants(const ComRef &cref, char **contents)
Definition: Model.cpp:263
oms_status_enu_t exportToFile(const std::string &filename) const
Definition: Model.cpp:1004
double lastEmit
Definition: Model.h:169
double getTime() const
Definition: Model.cpp:1125