-
Notifications
You must be signed in to change notification settings - Fork 49
/
System.h
201 lines (178 loc) · 10.2 KB
/
System.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
#ifndef _OMS_SYSTEM_H_
#define _OMS_SYSTEM_H_
#include "BusConnector.h"
#include "Clock.h"
#include "ComRef.h"
#include "Connection.h"
#include "DirectedGraph.h"
#include "Element.h"
#include "ExternalModel.h"
#include "ResultWriter.h"
#include "ssd/ConnectorGeometry.h"
#if !defined(NO_TLM)
#include "TLMBusConnector.h"
#endif
#include "Types.h"
#include <map>
#include <pugixml.hpp>
#include <unordered_map>
namespace oms
{
class Component;
class Model;
class Variable;
class System
{
public:
virtual ~System();
static System* NewSystem(const ComRef& cref, oms_system_enu_t type, Model* parentModel, System* parentSystem);
System* getSystem(const ComRef& cref);
Component* getComponent(const ComRef& cref);
System* getSubSystem(const ComRef& cref);
const ComRef& getCref() const {return cref;}
ComRef getFullCref() const;
Element* getElement() {return &element;}
oms_status_enu_t listUnconnectedConnectors(char** contents) const;
oms_system_enu_t getType() const {return type;}
oms_status_enu_t addSubSystem(const ComRef& cref, oms_system_enu_t type);
oms_status_enu_t addSubModel(const ComRef& cref, const std::string& fmuPath);
bool validCref(const ComRef& cref);
oms_status_enu_t exportToSSD(pugi::xml_node& node) const;
oms_status_enu_t importFromSSD(const pugi::xml_node& node);
virtual oms_status_enu_t exportToSSD_SimulationInformation(pugi::xml_node& node) const = 0;
virtual oms_status_enu_t importFromSSD_SimulationInformation(const pugi::xml_node& node) = 0;
void setGeometry(const ssd::ElementGeometry& geometry) {element.setGeometry(&geometry);}
oms_status_enu_t addConnector(const ComRef& cref, oms_causality_enu_t causality, oms_signal_type_enu_t type);
Connector* getConnector(const ComRef& cref);
Connector** getConnectors() {return &connectors[0];}
BusConnector* getBusConnector(const ComRef& cref);
oms_status_enu_t addTLMConnection(const ComRef& crefA, const ComRef& crefB, double delay, double alpha, double linearimpedance, double angularimpedance);
oms_status_enu_t setTLMConnectionParameters(const ComRef &crefA, const ComRef &crefB, const oms_tlm_connection_parameters_t* parameters);
oms_status_enu_t addTLMBus(const ComRef& cref, oms_tlm_domain_t domain, const int dimensions, const oms_tlm_interpolation_t interpolation);
oms_status_enu_t addConnectorToTLMBus(const ComRef& busCref, const ComRef& connectorCref, const std::string type);
oms_status_enu_t deleteConnectorFromTLMBus(const ComRef& busCref, const ComRef& connectorCref);
oms_status_enu_t setTLMBusGeometry(const ComRef& cref, const oms::ssd::ConnectorGeometry* geometry);
#if !defined(NO_TLM)
TLMBusConnector *getTLMBusConnector(const ComRef& cref);
TLMBusConnector **getTLMBusConnectors() {return &tlmbusconnectors[0];}
#endif
Connection* getConnection(const ComRef& crefA, const ComRef& crefB);
Connection** getConnections(const ComRef &cref);
oms_status_enu_t addConnection(const ComRef& crefA, const ComRef& crefB);
oms_status_enu_t deleteConnection(const ComRef& crefA, const ComRef& crefB);
oms_status_enu_t setConnectorGeometry(const ComRef& cref, const oms::ssd::ConnectorGeometry* geometry);
oms_status_enu_t setConnectionGeometry(const ComRef &crefA, const ComRef &crefB, const oms::ssd::ConnectionGeometry* geometry);
oms_status_enu_t addBus(const ComRef& cref);
oms_status_enu_t addConnectorToBus(const ComRef& busCref, const ComRef& connectorCref);
oms_status_enu_t deleteConnectorFromBus(const ComRef& busCref, const ComRef& connectorCref);
oms_status_enu_t setBusGeometry(const ComRef& cref, const oms::ssd::ConnectorGeometry* geometry);
oms_status_enu_t addExternalModel(const ComRef &cref, std::string path, std::string startscript);
oms_status_enu_t delete_(const ComRef& cref);
oms_status_enu_t deleteAllConectionsTo(const ComRef& cref);
bool isConnected(const ComRef& cref) const;
Model* getModel();
System* getParentSystem() const {return parentSystem;}
bool copyResources();
oms_status_enu_t getAllResources(std::vector<std::string>& resources);
const std::map<ComRef, System*>& getSubSystems() {return subsystems;}
const std::map<ComRef, Component*>& getComponents() {return components;}
oms_status_enu_t updateDependencyGraphs();
const DirectedGraph& getInitialUnknownsGraph() {return initialUnknownsGraph;}
const DirectedGraph& getOutputsGraph() {return outputsGraph;}
oms_status_enu_t exportDependencyGraphs(const std::string& pathInitialization, const std::string& pathSimulation);
virtual oms_status_enu_t instantiate() = 0;
virtual oms_status_enu_t initialize() = 0;
virtual oms_status_enu_t terminate() = 0;
virtual oms_status_enu_t reset() = 0;
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 getBoolean(const ComRef& cref, bool& value);
oms_status_enu_t getInteger(const ComRef& cref, int& value);
oms_status_enu_t getReal(const ComRef& cref, double& value);
oms_status_enu_t setBoolean(const ComRef& cref, bool value);
oms_status_enu_t setInteger(const ComRef& cref, int value);
oms_status_enu_t setReal(const ComRef& cref, double value);
oms_status_enu_t getReals(const std::vector<ComRef> &crefs, std::vector<double> &values);
oms_status_enu_t setReals(const std::vector<ComRef> &crefs, std::vector<double> values);
oms_status_enu_t setRealInputDerivatives(const ComRef &cref, int order, double value);
bool isTopLevelSystem() const {return (parentSystem == NULL);}
virtual oms_status_enu_t registerSignalsForResultFile(ResultWriter& resultFile);
virtual oms_status_enu_t updateSignals(ResultWriter& resultFile);
oms_status_enu_t addSignalsToResults(const char* regex);
oms_status_enu_t removeSignalsFromResults(const char* regex);
virtual oms_status_enu_t setSolver(oms_solver_enu_t solver) {return oms_status_error;}
void getTolerance(double* absoluteTolerance, double* relativeTolerance) const {if (absoluteTolerance) *absoluteTolerance=this->absoluteTolerance; if (relativeTolerance) *relativeTolerance=this->relativeTolerance;}
void getStepSize(double* initialStepSize, double* minimumStepSize, double* maximumStepSize) const {if (initialStepSize) *initialStepSize=this->initialStepSize; if (minimumStepSize) *minimumStepSize=this->minimumStepSize; if (maximumStepSize) *maximumStepSize=this->maximumStepSize;}
oms_status_enu_t setTolerance(double absoluteTolerance, double relativeTolerance) {this->absoluteTolerance=absoluteTolerance; this->relativeTolerance=relativeTolerance; return oms_status_ok;}
oms_status_enu_t setFixedStepSize(double stepSize) {this->minimumStepSize=this->maximumStepSize=this->initialStepSize=stepSize; return oms_status_ok;}
oms_status_enu_t setVariableStepSize(double initialStepSize, double minimumStepSize, double maximumStepSize) {this->minimumStepSize=minimumStepSize; this->maximumStepSize=maximumStepSize; this->initialStepSize=initialStepSize; return oms_status_ok;}
double getMaximumStepSize() {return maximumStepSize;}
oms_solver_enu_t getSolver() {return solverMethod;}
protected:
System(const ComRef& cref, oms_system_enu_t type, Model* parentModel, System* parentSystem, oms_solver_enu_t solverMethod);
// stop the compiler generating methods copying the object
System(System const& copy); ///< not implemented
System& operator=(System const& copy); ///< not implemented
DirectedGraph initialUnknownsGraph;
DirectedGraph outputsGraph;
Clock clock;
unsigned int clock_id;
oms_solver_enu_t solverMethod = oms_solver_none;
double absoluteTolerance = 1e-4;
double relativeTolerance = 1e-4;
double minimumStepSize = 1e-4;
double maximumStepSize = 1e-1;
double initialStepSize = 1e-4;
private:
ComRef cref;
oms_system_enu_t type;
Model* parentModel;
System* parentSystem;
std::map<ComRef, System*> subsystems;
std::map<ComRef, Component*> components;
std::map<ComRef, double> realValues; ///< values of the real connectors
std::map<ComRef, int> integerValues; ///< values of the integer connectors
std::map<ComRef, bool> booleanValues; ///< values of the boolean connectors
Element element;
std::vector<Connector*> connectors; ///< last element is always NULL
std::vector<oms_element_t*> subelements; ///< last element is always NULL; don't free it
std::vector<BusConnector*> busconnectors;
#if !defined(NO_TLM)
std::vector<TLMBusConnector*> tlmbusconnectors;
#endif
std::vector<Connection*> connections; ///< last element is always NULL
std::unordered_map<unsigned int /*result file var ID*/, unsigned int /*allVariables ID*/> resultFileMapping;
std::unordered_map<ComRef, bool> exportConnectors;
oms_status_enu_t importFromSSD_ConnectionGeometry(const pugi::xml_node& node, const ComRef& crefA, const ComRef& crefB);
};
}
#endif