OMSimulatorLib
The OMSimulator project is a FMI-based co-simulation environment that supports ordinary (i.e., non-delayed) and TLM connections.
System.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_SYSTEM_H_
33 #define _OMS_SYSTEM_H_
34 
35 #include "BusConnector.h"
36 #include "Clock.h"
37 #include "ComRef.h"
38 #include "Connection.h"
39 #include "DirectedGraph.h"
40 #include "Element.h"
41 #include "ExternalModel.h"
42 #include "ResultWriter.h"
43 #include "ssd/ConnectorGeometry.h"
44 #if !defined(NO_TLM)
45 #include "TLMBusConnector.h"
46 #endif
47 #include "Types.h"
48 #include <map>
49 #include <pugixml.hpp>
50 #include <unordered_map>
51 
52 namespace oms
53 {
54  class Component;
55  class Model;
56  class Variable;
57 
58  class System
59  {
60  public:
61  virtual ~System();
62 
64  System* getSystem(const ComRef& cref);
65  Component* getComponent(const ComRef& cref);
66  System* getSubSystem(const ComRef& cref);
67  const ComRef& getCref() const {return cref;}
68  ComRef getFullCref() const;
69  Element* getElement() {return &element;}
70  oms_status_enu_t listUnconnectedConnectors(char** contents) const;
71  oms_system_enu_t getType() const {return type;}
73  oms_status_enu_t addSubModel(const ComRef& cref, const std::string& fmuPath);
74  bool validCref(const ComRef& cref);
75  oms_status_enu_t exportToSSD(pugi::xml_node& node) const;
76  oms_status_enu_t importFromSSD(const pugi::xml_node& node);
77  virtual oms_status_enu_t exportToSSD_SimulationInformation(pugi::xml_node& node) const = 0;
78  virtual oms_status_enu_t importFromSSD_SimulationInformation(const pugi::xml_node& node) = 0;
79  void setGeometry(const ssd::ElementGeometry& geometry) {element.setGeometry(&geometry);}
81  Connector* getConnector(const ComRef& cref);
83  BusConnector* getBusConnector(const ComRef& cref);
84  oms_status_enu_t addTLMConnection(const ComRef& crefA, const ComRef& crefB, double delay, double alpha, double linearimpedance, double angularimpedance);
85  oms_status_enu_t setTLMConnectionParameters(const ComRef &crefA, const ComRef &crefB, const oms_tlm_connection_parameters_t* parameters);
86  oms_status_enu_t addTLMBus(const ComRef& cref, oms_tlm_domain_t domain, const int dimensions, const oms_tlm_interpolation_t interpolation);
87  oms_status_enu_t addConnectorToTLMBus(const ComRef& busCref, const ComRef& connectorCref, const std::string type);
88  oms_status_enu_t deleteConnectorFromTLMBus(const ComRef& busCref, const ComRef& connectorCref);
90 #if !defined(NO_TLM)
93 #endif
94  Connection* getConnection(const ComRef& crefA, const ComRef& crefB);
95  Connection** getConnections(const ComRef &cref);
96  oms_status_enu_t addConnection(const ComRef& crefA, const ComRef& crefB);
97  oms_status_enu_t deleteConnection(const ComRef& crefA, const ComRef& crefB);
99  oms_status_enu_t setConnectionGeometry(const ComRef &crefA, const ComRef &crefB, const oms::ssd::ConnectionGeometry* geometry);
100  oms_status_enu_t addBus(const ComRef& cref);
101  oms_status_enu_t addConnectorToBus(const ComRef& busCref, const ComRef& connectorCref);
102  oms_status_enu_t deleteConnectorFromBus(const ComRef& busCref, const ComRef& connectorCref);
104  oms_status_enu_t addExternalModel(const ComRef &cref, std::string path, std::string startscript);
105  oms_status_enu_t delete_(const ComRef& cref);
107  bool isConnected(const ComRef& cref) const;
108  Model* getModel();
110  bool copyResources();
111  oms_status_enu_t getAllResources(std::vector<std::string>& resources);
112  const std::map<ComRef, System*>& getSubSystems() {return subsystems;}
113  const std::map<ComRef, Component*>& getComponents() {return components;}
117  oms_status_enu_t exportDependencyGraphs(const std::string& pathInitialization, const std::string& pathSimulation);
118 
119  virtual oms_status_enu_t instantiate() = 0;
120  virtual oms_status_enu_t initialize() = 0;
121  virtual oms_status_enu_t terminate() = 0;
122  virtual oms_status_enu_t reset() = 0;
123  virtual oms_status_enu_t stepUntil(double stopTime, void (*cb)(const char* ident, double time, oms_status_enu_t status)) = 0;
124 
125  oms_status_enu_t getBoolean(const ComRef& cref, bool& value);
126  oms_status_enu_t getInteger(const ComRef& cref, int& value);
127  oms_status_enu_t getReal(const ComRef& cref, double& value);
128  oms_status_enu_t setBoolean(const ComRef& cref, bool value);
129  oms_status_enu_t setInteger(const ComRef& cref, int value);
130  oms_status_enu_t setReal(const ComRef& cref, double value);
131 
132  oms_status_enu_t getReals(const std::vector<ComRef> &crefs, std::vector<double> &values);
133  oms_status_enu_t setReals(const std::vector<ComRef> &crefs, std::vector<double> values);
134  oms_status_enu_t setRealInputDerivatives(const ComRef &cref, int order, double value);
135 
136  bool isTopLevelSystem() const {return (parentSystem == NULL);}
137 
139  virtual oms_status_enu_t updateSignals(ResultWriter& resultFile);
140  oms_status_enu_t addSignalsToResults(const char* regex);
141  oms_status_enu_t removeSignalsFromResults(const char* regex);
142 
144 
145  void getTolerance(double* absoluteTolerance, double* relativeTolerance) const {if (absoluteTolerance) *absoluteTolerance=this->absoluteTolerance; if (relativeTolerance) *relativeTolerance=this->relativeTolerance;}
146  void getStepSize(double* initialStepSize, double* minimumStepSize, double* maximumStepSize) const {if (initialStepSize) *initialStepSize=this->initialStepSize; if (minimumStepSize) *minimumStepSize=this->minimumStepSize; if (maximumStepSize) *maximumStepSize=this->maximumStepSize;}
147  oms_status_enu_t setTolerance(double absoluteTolerance, double relativeTolerance) {this->absoluteTolerance=absoluteTolerance; this->relativeTolerance=relativeTolerance; return oms_status_ok;}
148  oms_status_enu_t setFixedStepSize(double stepSize) {this->minimumStepSize=this->maximumStepSize=this->initialStepSize=stepSize; return oms_status_ok;}
149  oms_status_enu_t setVariableStepSize(double initialStepSize, double minimumStepSize, double maximumStepSize) {this->minimumStepSize=minimumStepSize; this->maximumStepSize=maximumStepSize; this->initialStepSize=initialStepSize; return oms_status_ok;}
152 
153  protected:
154  System(const ComRef& cref, oms_system_enu_t type, Model* parentModel, System* parentSystem, oms_solver_enu_t solverMethod);
155 
156  // stop the compiler generating methods copying the object
157  System(System const& copy);
158  System& operator=(System const& copy);
159 
162 
164  unsigned int clock_id;
165 
167 
168  double absoluteTolerance = 1e-4;
169  double relativeTolerance = 1e-4;
170  double minimumStepSize = 1e-4;
171  double maximumStepSize = 1e-1;
172  double initialStepSize = 1e-4;
173  private:
178  std::map<ComRef, System*> subsystems;
179  std::map<ComRef, Component*> components;
180 
181  std::map<ComRef, double> realValues;
182  std::map<ComRef, int> integerValues;
183  std::map<ComRef, bool> booleanValues;
184 
186  std::vector<Connector*> connectors;
187  std::vector<oms_element_t*> subelements;
188  std::vector<BusConnector*> busconnectors;
189 #if !defined(NO_TLM)
190  std::vector<TLMBusConnector*> tlmbusconnectors;
191 #endif
192  std::vector<Connection*> connections;
193 
194  std::unordered_map<unsigned int /*result file var ID*/, unsigned int /*allVariables ID*/> resultFileMapping;
195  std::unordered_map<ComRef, bool> exportConnectors;
196 
197  oms_status_enu_t importFromSSD_ConnectionGeometry(const pugi::xml_node& node, const ComRef& crefA, const ComRef& crefB);
198  };
199 }
200 
201 #endif
TLMBusConnector * getTLMBusConnector(const ComRef &cref)
Definition: System.cpp:775
oms_status_enu_t addSignalsToResults(const char *regex)
Definition: System.cpp:1805
Definition: Types.h:85
virtual oms_status_enu_t initialize()=0
std::map< ComRef, bool > booleanValues
values of the boolean connectors
Definition: System.h:183
ComRef getFullCref() const
Definition: System.cpp:157
oms_solver_enu_t
Definition: Types.h:84
Definition: Types.h:44
oms_solver_enu_t solverMethod
Definition: System.h:166
Definition: ResultWriter.h:67
Definition: Model.h:48
Definition: ElementGeometry.h:45
std::vector< oms_element_t * > subelements
last element is always NULL; don&#39;t free it
Definition: System.h:187
oms_status_enu_t setTLMBusGeometry(const ComRef &cref, const oms::ssd::ConnectorGeometry *geometry)
Definition: System.cpp:1310
Definition: Clock.h:38
oms_status_enu_t setConnectionGeometry(const ComRef &crefA, const ComRef &crefB, const oms::ssd::ConnectionGeometry *geometry)
Definition: System.cpp:1236
Element element
Definition: System.h:185
oms_system_enu_t type
Definition: System.h:175
void setGeometry(const oms::ssd::ElementGeometry *newGeometry)
Definition: Element.cpp:84
Clock clock
Definition: System.h:163
oms_status_enu_t addBus(const ComRef &cref)
Definition: System.cpp:1003
oms_status_enu_t removeSignalsFromResults(const char *regex)
Definition: System.cpp:1838
double initialStepSize
Definition: System.h:172
oms_status_enu_t importFromSSD(const pugi::xml_node &node)
Definition: System.cpp:447
System & operator=(System const &copy)
not implemented
oms_status_enu_t deleteAllConectionsTo(const ComRef &cref)
Definition: System.cpp:1346
std::unordered_map< unsigned int, unsigned int > resultFileMapping
Definition: System.h:194
virtual oms_status_enu_t updateSignals(ResultWriter &resultFile)
Definition: System.cpp:1763
virtual ~System()
Definition: System.cpp:69
DirectedGraph initialUnknownsGraph
Definition: System.h:160
oms_causality_enu_t
Definition: Types.h:61
oms_tlm_interpolation_t
Definition: Types.h:69
oms_status_enu_t getBoolean(const ComRef &cref, bool &value)
Definition: System.cpp:1500
oms_status_enu_t setBoolean(const ComRef &cref, bool value)
Definition: System.cpp:1596
oms_status_enu_t getReals(const std::vector< ComRef > &crefs, std::vector< double > &values)
Definition: System.cpp:1674
TLMBusConnector ** getTLMBusConnectors()
Definition: System.h:92
std::unordered_map< ComRef, bool > exportConnectors
Definition: System.h:195
oms_status_enu_t
Definition: Types.h:43
void getTolerance(double *absoluteTolerance, double *relativeTolerance) const
Definition: System.h:145
TLMBusConnector.
Definition: TLMBusConnector.h:96
bool isTopLevelSystem() const
Definition: System.h:136
virtual oms_status_enu_t exportToSSD_SimulationInformation(pugi::xml_node &node) const =0
ComRef cref
Definition: System.h:174
oms_status_enu_t addTLMConnection(const ComRef &crefA, const ComRef &crefB, double delay, double alpha, double linearimpedance, double angularimpedance)
Definition: System.cpp:947
oms_solver_enu_t getSolver()
Definition: System.h:151
System(const ComRef &cref, oms_system_enu_t type, Model *parentModel, System *parentSystem, oms_solver_enu_t solverMethod)
Definition: System.cpp:49
oms_status_enu_t setFixedStepSize(double stepSize)
Definition: System.h:148
oms_status_enu_t deleteConnection(const ComRef &crefA, const ComRef &crefB)
Definition: System.cpp:914
oms_status_enu_t getReal(const ComRef &cref, double &value)
Definition: System.cpp:1564
oms_status_enu_t setInteger(const ComRef &cref, int value)
Definition: System.cpp:1622
Connector * getConnector(const ComRef &cref)
Definition: System.cpp:733
virtual oms_status_enu_t stepUntil(double stopTime, void(*cb)(const char *ident, double time, oms_status_enu_t status))=0
oms_status_enu_t updateDependencyGraphs()
Definition: System.cpp:1452
static System * NewSystem(const ComRef &cref, oms_system_enu_t type, Model *parentModel, System *parentSystem)
Definition: System.cpp:96
virtual oms_status_enu_t importFromSSD_SimulationInformation(const pugi::xml_node &node)=0
BusConnector * getBusConnector(const ComRef &cref)
Definition: System.cpp:753
System * getSubSystem(const ComRef &cref)
Definition: System.cpp:201
Definition: Types.h:47
void setGeometry(const ssd::ElementGeometry &geometry)
Definition: System.h:79
oms_status_enu_t getInteger(const ComRef &cref, int &value)
Definition: System.cpp:1532
oms_status_enu_t listUnconnectedConnectors(char **contents) const
Definition: System.cpp:312
Model * getModel()
Definition: System.cpp:1339
const std::map< ComRef, Component * > & getComponents()
Definition: System.h:113
std::map< ComRef, double > realValues
values of the real connectors
Definition: System.h:181
std::vector< TLMBusConnector * > tlmbusconnectors
Definition: System.h:190
oms_status_enu_t addConnector(const ComRef &cref, oms_causality_enu_t causality, oms_signal_type_enu_t type)
Definition: System.cpp:710
ComRef - component reference.
Definition: ComRef.h:43
void getStepSize(double *initialStepSize, double *minimumStepSize, double *maximumStepSize) const
Definition: System.h:146
unsigned int clock_id
Definition: System.h:164
oms_status_enu_t setBusGeometry(const ComRef &cref, const oms::ssd::ConnectorGeometry *geometry)
Definition: System.cpp:1293
oms_system_enu_t
Definition: Types.h:101
Definition: Component.h:54
std::vector< BusConnector * > busconnectors
Definition: System.h:188
oms_status_enu_t setReals(const std::vector< ComRef > &crefs, std::vector< double > values)
Definition: System.cpp:1685
Connection * getConnection(const ComRef &crefA, const ComRef &crefB)
Definition: System.cpp:1331
std::map< ComRef, int > integerValues
values of the integer connectors
Definition: System.h:182
oms_status_enu_t setVariableStepSize(double initialStepSize, double minimumStepSize, double maximumStepSize)
Definition: System.h:149
Connector.
Definition: Connector.h:48
double relativeTolerance
Definition: System.h:169
oms_status_enu_t deleteConnectorFromBus(const ComRef &busCref, const ComRef &connectorCref)
Definition: System.cpp:1087
oms_status_enu_t deleteConnectorFromTLMBus(const ComRef &busCref, const ComRef &connectorCref)
Definition: System.cpp:1150
BusConnector.
Definition: BusConnector.h:20
virtual oms_status_enu_t setSolver(oms_solver_enu_t solver)
Definition: System.h:143
oms_status_enu_t setTLMConnectionParameters(const ComRef &crefA, const ComRef &crefB, const oms_tlm_connection_parameters_t *parameters)
Definition: System.cpp:1263
oms_status_enu_t addConnectorToBus(const ComRef &busCref, const ComRef &connectorCref)
Definition: System.cpp:1063
oms_signal_type_enu_t
Definition: Types.h:115
std::vector< Connector * > connectors
last element is always NULL
Definition: System.h:186
oms_status_enu_t addConnectorToTLMBus(const ComRef &busCref, const ComRef &connectorCref, const std::string type)
Definition: System.cpp:1111
oms_status_enu_t importFromSSD_ConnectionGeometry(const pugi::xml_node &node, const ComRef &crefA, const ComRef &crefB)
Definition: System.cpp:1701
Definition: BusConnector.h:15
oms_system_enu_t getType() const
Definition: System.h:71
DirectedGraph outputsGraph
Definition: System.h:161
oms_status_enu_t delete_(const ComRef &cref)
Definition: System.cpp:1372
double absoluteTolerance
Definition: System.h:168
virtual oms_status_enu_t instantiate()=0
oms_status_enu_t getAllResources(std::vector< std::string > &resources)
Definition: System.cpp:1429
oms_status_enu_t setTolerance(double absoluteTolerance, double relativeTolerance)
Definition: System.h:147
Parameters for TLM connection.
Definition: Types.h:340
bool isConnected(const ComRef &cref) const
Definition: System.cpp:1363
const std::map< ComRef, System * > & getSubSystems()
Definition: System.h:112
const ComRef & getCref() const
Definition: System.h:67
Element * getElement()
Definition: System.h:69
oms_tlm_domain_t
Definition: Types.h:75
bool copyResources()
Definition: System.cpp:1422
virtual oms_status_enu_t reset()=0
oms_status_enu_t addSubSystem(const ComRef &cref, oms_system_enu_t type)
Definition: System.cpp:235
oms_status_enu_t setReal(const ComRef &cref, double value)
Definition: System.cpp:1648
double minimumStepSize
Definition: System.h:170
Model * parentModel
Definition: System.h:176
Element.
Definition: Element.h:52
Definition: ConnectionGeometry.h:45
**
Definition: Connection.h:46
const DirectedGraph & getOutputsGraph()
Definition: System.h:116
std::map< ComRef, Component * > components
Definition: System.h:179
System * getParentSystem() const
Definition: System.h:109
double maximumStepSize
Definition: System.h:171
oms_status_enu_t exportDependencyGraphs(const std::string &pathInitialization, const std::string &pathSimulation)
Definition: System.cpp:1442
oms_status_enu_t addSubModel(const ComRef &cref, const std::string &fmuPath)
Definition: System.cpp:267
oms_status_enu_t addTLMBus(const ComRef &cref, oms_tlm_domain_t domain, const int dimensions, const oms_tlm_interpolation_t interpolation)
Definition: System.cpp:1030
Definition: ConnectorGeometry.h:45
oms_status_enu_t setRealInputDerivatives(const ComRef &cref, int order, double value)
Definition: System.cpp:1696
const DirectedGraph & getInitialUnknownsGraph()
Definition: System.h:115
oms_status_enu_t addConnection(const ComRef &crefA, const ComRef &crefB)
Definition: System.cpp:814
Component * getComponent(const ComRef &cref)
Definition: System.cpp:183
bool validCref(const ComRef &cref)
Definition: System.cpp:210
Connection ** getConnections(const ComRef &cref)
Definition: System.cpp:800
oms_status_enu_t setConnectorGeometry(const ComRef &cref, const oms::ssd::ConnectorGeometry *geometry)
Definition: System.cpp:1205
Definition: System.h:58
System * parentSystem
Definition: System.h:177
Connector ** getConnectors()
Definition: System.h:82
Definition: DirectedGraph.h:48
oms_status_enu_t addExternalModel(const ComRef &cref, std::string path, std::string startscript)
Definition: System.cpp:1181
System * getSystem(const ComRef &cref)
Definition: System.cpp:168
std::map< ComRef, System * > subsystems
Definition: System.h:178
virtual oms_status_enu_t terminate()=0
double getMaximumStepSize()
Definition: System.h:150
virtual oms_status_enu_t registerSignalsForResultFile(ResultWriter &resultFile)
Definition: System.cpp:1721
oms_status_enu_t exportToSSD(pugi::xml_node &node) const
Definition: System.cpp:379
std::vector< Connection * > connections
last element is always NULL
Definition: System.h:192