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

Loading...
Searching...
No Matches
Component.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_COMPONENT_H_
37#define _OMS_COMPONENT_H_
38
39#include "Clock.h"
40#include "ComRef.h"
41#include "Connector.h"
42#include "DirectedGraph.h"
43#include "Element.h"
44#include "FMUInfo.h"
45#include "Logging.h"
46#include "ResultWriter.h"
47#include "SignalDerivative.h"
48#include "Snapshot.h"
49#include "Variable.h"
50#include "OMSimulator/Types.h"
51#include "Values.h"
52
53#include <fmi4c.h>
54#include <pugixml.hpp>
55
56 namespace oms
57{
58 class System;
59 class Model;
60 class Variable;
61
62 void fmi2logger(fmi2ComponentEnvironment env, fmi2String instanceName, fmi2Status status, fmi2String category, fmi2String message, ...);
63 void fmi3logger(fmi3InstanceEnvironment env, fmi3Status status, fmi3String category, fmi3String message);
64 class Component
65 {
66 public:
67 virtual ~Component();
68
69 virtual oms_status_enu_t addSignalsToResults(const char* regex) = 0;
70 virtual oms_status_enu_t exportToSSD(pugi::xml_node& node, Snapshot& snapshot, std::string variantName) const = 0;
71 virtual oms_status_enu_t exportToSSV(pugi::xml_node& ssvNode) { return logError_NotImplemented; }
72 virtual void getFilteredUnitDefinitionsToSSD(std::map<std::string, std::map<std::string, std::string>>& unitDefinitions) { return ; }
73 virtual void getFilteredEnumerationDefinitionsToSSD(std::map<std::string, std::map<std::string, std::string>>& enumerationDefinitions) { return ; }
74
75 virtual oms_status_enu_t initialize() = 0;
76 virtual oms_status_enu_t instantiate() = 0;
77 virtual oms_status_enu_t registerSignalsForResultFile(ResultWriter& resultFile) = 0;
78 virtual oms_status_enu_t removeSignalsFromResults(const char* regex) = 0;
79 virtual oms_status_enu_t reset() = 0;
80 virtual oms_status_enu_t terminate() = 0;
81 virtual oms_status_enu_t updateSignals(ResultWriter& resultWriter) = 0;
82 virtual Variable* getVariable(const ComRef& cref) = 0;
83 virtual oms_status_enu_t getVariableType(const ComRef& cref, oms_signal_type_enu_t& type)
84 {
85 Variable* var = getVariable(cref);
86 if (!var)
87 return oms_status_error;
88 type = var->getType();
89 return oms_status_ok;
90 }
91
92 virtual bool getCanGetAndSetState() { return false; }
93 virtual const FMUInfo* getFMUInfo() const { return nullptr; }
94 virtual oms_status_enu_t deleteStartValue(const ComRef& cref) { return oms_status_ok; }
95 virtual std::vector<Values> getValuesResources() { return{}; }
96 virtual Values& getValues() {return values;}
97 virtual oms_status_enu_t setValuesResources(Values& values) { return oms_status_ok; }
98 virtual oms_status_enu_t updateOrDeleteStartValueInReplacedComponent(std::vector<std::string> &warningList) { return oms_status_ok; }
99 virtual oms_status_enu_t exportToSSMTemplate(pugi::xml_node& ssmNode) { return logError_NotImplemented; }
100 virtual oms_status_enu_t exportToSSVTemplate(pugi::xml_node& ssvNode, Snapshot& snapshot) { return logError_NotImplemented; }
101 virtual oms_status_enu_t freeState() { return logError_NotImplemented; }
102 virtual oms_status_enu_t getBoolean(const ComRef& cref, bool& value) { return logError_NotImplemented; }
103 virtual oms_status_enu_t getInteger(const ComRef& cref, int& value) { return logError_NotImplemented; }
104 virtual oms_status_enu_t getReal(const ComRef& cref, double& value) { return logError_NotImplemented; }
105 virtual oms_status_enu_t getString(const ComRef& cref, std::string& value) { return logError_NotImplemented; }
106 virtual oms_status_enu_t getRealOutputDerivative(const ComRef& cref, SignalDerivative& der) { return logError_NotImplemented; }
107 virtual oms_status_enu_t getDirectionalDerivative(const ComRef& unknownCref, const ComRef& knownCref, double& value) { return logError_NotImplemented; }
108 virtual oms_status_enu_t restoreState() { return logError_NotImplemented; }
109 virtual oms_status_enu_t saveState() { return logError_NotImplemented; }
110 virtual oms_status_enu_t setBoolean(const ComRef& cref, bool value) { return logError_NotImplemented; }
111 virtual oms_status_enu_t setInteger(const ComRef& cref, int value) { return logError_NotImplemented; }
112 virtual oms_status_enu_t setReal(const ComRef& cref, double value) { return logError_NotImplemented; }
113 virtual oms_status_enu_t setString(const ComRef& cref, const std::string& value) { return logError_NotImplemented; }
114 virtual oms_status_enu_t setUnit(const ComRef& cref, const std::string& value) { return logError_NotImplemented; }
115 virtual oms_status_enu_t setRealInputDerivative(const ComRef& cref, const SignalDerivative& der) { return logError_NotImplemented; }
116 virtual oms_status_enu_t stepUntil(double stopTime) { return logError_NotImplemented; }
117 virtual oms_status_enu_t setTime(double time) { return logError_NotImplemented; }
118 virtual oms_status_enu_t setExportName(const std::string & exportName) { return oms_status_ok; }
119 virtual oms_status_enu_t newResources(const std::string& ssvFileName, const std::string& ssmFileName, bool externalResources) { return logError_NotImplemented; }
120 virtual oms_status_enu_t addResources(std::string& filename) { return logError_NotImplemented; }
121 virtual oms_status_enu_t deleteReferencesInSSD(const std::string& filename) {return logError_NotImplemented;}
122 virtual oms_status_enu_t deleteResourcesInSSP(const std::string& filename) {return logError_NotImplemented;}
123 // common virtual functions for ME for fmi2 and fmi3
124 virtual size_t getNumberOfContinuousStates() const {return logError_NotImplemented;}
125 virtual size_t getNumberOfEventIndicators() const {return logError_NotImplemented;}
126 virtual oms_status_enu_t getContinuousStates(double* states) {return logError_NotImplemented;}
127 virtual oms_status_enu_t setContinuousStates(double* states) {return logError_NotImplemented;}
128 virtual oms_status_enu_t getDerivatives(double* derivatives) {return logError_NotImplemented;}
129 virtual oms_status_enu_t getNominalsOfContinuousStates(double* nominals) {return logError_NotImplemented;}
130 virtual oms_status_enu_t getEventindicators(double* eventindicators) {return logError_NotImplemented;}
131 virtual oms_status_enu_t getEventindicators(double* eventindicators, size_t size) {return logError_NotImplemented;}
132
133 virtual fmiHandle* getFMU() {return nullptr; }
134 virtual fmi2EventInfo* getEventInfo() {return nullptr;}
135 virtual oms_status_enu_t doEventIteration() {return logError_NotImplemented;}
136 virtual oms_status_enu_t completedIntegratorStep(bool noSetFMUStatePriorToCurrentPoint, bool& enterEventMode, bool& terminateSimulation) {return logError_NotImplemented;}
137 virtual oms_status_enu_t enterEventMode() {return logError_NotImplemented;}
138 virtual oms_status_enu_t enterContinuousTimeMode() {return logError_NotImplemented;}
139
140 virtual bool getNewDiscreteStatesNeeded() {return logError_NotImplemented; }
141 virtual bool getTerminateSimulation() {return logError_NotImplemented; }
142 virtual bool getNominalsOfContinuousStatesChanged() {return logError_NotImplemented; }
143 virtual bool getValuesOfContinuousStatesChanged() {return logError_NotImplemented; }
144 virtual bool getNextEventTimeDefined() {return logError_NotImplemented; }
145 virtual double getNextEventTime() { return logError_NotImplemented; }
146
147 const ComRef& getCref() const { return cref; }
148 ComRef getFullCref() const;
149 Element* getElement() { return &element; }
150 Connector* getConnector(const ComRef& cref);
151 Connector** getConnectors() { return &connectors[0]; }
152 oms_status_enu_t deleteConnector(const ComRef& cref);
153 void getAllResources(std::vector<std::string>& resources) const { resources.push_back(path); }
154 const std::string& getPath() const { return path; }
155 const std::string& getTempDir() const { return tempDir; }
156 void setPath(const std::string& newPath) { this->path = newPath; }
157 void setTempDir(const std::string& tempDir) { this->tempDir = tempDir; }
158 oms_component_enu_t getType() const { return type; }
159 System* getParentSystem() const { return parentSystem; }
160 Model& getModel() const;
161 void setGeometry(const ssd::ElementGeometry& geometry) { element.setGeometry(&geometry); }
162
163 const DirectedGraph& getInitialUnknownsGraph() { return initialUnknownsGraph; }
164 const DirectedGraph& getOutputsGraph() { return outputsGraph; }
165
166 oms_status_enu_t rename(const ComRef& newCref);
167
168 virtual void getFilteredSignals(std::vector<Connector>& filteredSignals) const = 0;
169
170 protected:
171 Component(const ComRef& cref, oms_component_enu_t type, System* parentSystem, const std::string& path);
172
173 // stop the compiler generating methods copying the object
174 Component(Component const&);
175 Component& operator=(Component const&);
176
177 virtual oms_status_enu_t renameValues(const ComRef& oldCref, const ComRef& newCref) { return oms_status_ok; }
178
179 protected:
180 DirectedGraph initialUnknownsGraph;
181 DirectedGraph outputsGraph;
182 Element element;
183 std::vector<Connector*> connectors;
184
185 Clock clock;
186 unsigned int clock_id;
187
188 private:
189 System* parentSystem;
190 ComRef cref;
191 oms_component_enu_t type;
192 std::string path;
193 std::string tempDir;
194 Values values;
195 };
196}
197
198#endif
Clock.h
ComRef.h
Connector.h
DirectedGraph.h
Element.h
FMUInfo.h
Logging.h
logError_NotImplemented
#define logError_NotImplemented
Definition Logging.h:111
ResultWriter.h
SignalDerivative.h
Snapshot.h
Values.h
Variable.h
Clock
Definition Clock.h:43
oms::ComRef
ComRef - component reference.
Definition ComRef.h:51
oms::Component
Definition Component.h:65
oms::Component::deleteConnector
oms_status_enu_t deleteConnector(const ComRef &cref)
Definition Component.cpp:162
oms::Component::tempDir
std::string tempDir
unzipped fmu
Definition Component.h:193
oms::Component::setReal
virtual oms_status_enu_t setReal(const ComRef &cref, double value)
Definition Component.h:112
oms::Component::getCref
const ComRef & getCref() const
Definition Component.h:147
oms::Component::setExportName
virtual oms_status_enu_t setExportName(const std::string &exportName)
Definition Component.h:118
oms::Component::element
Element element
Definition Component.h:182
oms::Component::freeState
virtual oms_status_enu_t freeState()
Definition Component.h:101
oms::Component::restoreState
virtual oms_status_enu_t restoreState()
Definition Component.h:108
oms::Component::enterContinuousTimeMode
virtual oms_status_enu_t enterContinuousTimeMode()
Definition Component.h:138
oms::Component::setString
virtual oms_status_enu_t setString(const ComRef &cref, const std::string &value)
Definition Component.h:113
oms::Component::setValuesResources
virtual oms_status_enu_t setValuesResources(Values &values)
Definition Component.h:97
oms::Component::path
std::string path
resource file (fmu, mat)
Definition Component.h:192
oms::Component::getValuesResources
virtual std::vector< Values > getValuesResources()
Definition Component.h:95
oms::Component::getCanGetAndSetState
virtual bool getCanGetAndSetState()
Definition Component.h:92
oms::Component::deleteStartValue
virtual oms_status_enu_t deleteStartValue(const ComRef &cref)
Definition Component.h:94
oms::Component::connectors
std::vector< Connector * > connectors
Definition Component.h:183
oms::Component::getValues
virtual Values & getValues()
Definition Component.h:96
oms::Component::cref
ComRef cref
Definition Component.h:190
oms::Component::deleteResourcesInSSP
virtual oms_status_enu_t deleteResourcesInSSP(const std::string &filename)
Definition Component.h:122
oms::Component::getNominalsOfContinuousStatesChanged
virtual bool getNominalsOfContinuousStatesChanged()
Definition Component.h:142
oms::Component::getTerminateSimulation
virtual bool getTerminateSimulation()
Definition Component.h:141
oms::Component::getDirectionalDerivative
virtual oms_status_enu_t getDirectionalDerivative(const ComRef &unknownCref, const ComRef &knownCref, double &value)
Definition Component.h:107
oms::Component::getFilteredUnitDefinitionsToSSD
virtual void getFilteredUnitDefinitionsToSSD(std::map< std::string, std::map< std::string, std::string > > &unitDefinitions)
Definition Component.h:72
oms::Component::getInteger
virtual oms_status_enu_t getInteger(const ComRef &cref, int &value)
Definition Component.h:103
oms::Component::setTempDir
void setTempDir(const std::string &tempDir)
Definition Component.h:157
oms::Component::setTime
virtual oms_status_enu_t setTime(double time)
Definition Component.h:117
oms::Component::getDerivatives
virtual oms_status_enu_t getDerivatives(double *derivatives)
Definition Component.h:128
oms::Component::getVariable
virtual Variable * getVariable(const ComRef &cref)=0
oms::Component::setPath
void setPath(const std::string &newPath)
Definition Component.h:156
oms::Component::addResources
virtual oms_status_enu_t addResources(std::string &filename)
Definition Component.h:120
oms::Component::getVariableType
virtual oms_status_enu_t getVariableType(const ComRef &cref, oms_signal_type_enu_t &type)
Definition Component.h:83
oms::Component::getEventindicators
virtual oms_status_enu_t getEventindicators(double *eventindicators)
Definition Component.h:130
oms::Component::getBoolean
virtual oms_status_enu_t getBoolean(const ComRef &cref, bool &value)
Definition Component.h:102
oms::Component::removeSignalsFromResults
virtual oms_status_enu_t removeSignalsFromResults(const char *regex)=0
oms::Component::getString
virtual oms_status_enu_t getString(const ComRef &cref, std::string &value)
Definition Component.h:105
oms::Component::clock_id
unsigned int clock_id
Definition Component.h:186
oms::Component::setInteger
virtual oms_status_enu_t setInteger(const ComRef &cref, int value)
Definition Component.h:111
oms::Component::clock
Clock clock
Definition Component.h:185
oms::Component::initialize
virtual oms_status_enu_t initialize()=0
oms::Component::getType
oms_component_enu_t getType() const
Definition Component.h:158
oms::Component::newResources
virtual oms_status_enu_t newResources(const std::string &ssvFileName, const std::string &ssmFileName, bool externalResources)
Definition Component.h:119
oms::Component::getNumberOfContinuousStates
virtual size_t getNumberOfContinuousStates() const
Definition Component.h:124
oms::Component::getElement
Element * getElement()
Definition Component.h:149
oms::Component::getOutputsGraph
const DirectedGraph & getOutputsGraph()
Definition Component.h:164
oms::Component::setUnit
virtual oms_status_enu_t setUnit(const ComRef &cref, const std::string &value)
Definition Component.h:114
oms::Component::saveState
virtual oms_status_enu_t saveState()
Definition Component.h:109
oms::Component::exportToSSVTemplate
virtual oms_status_enu_t exportToSSVTemplate(pugi::xml_node &ssvNode, Snapshot &snapshot)
Definition Component.h:100
oms::Component::getInitialUnknownsGraph
const DirectedGraph & getInitialUnknownsGraph()
Definition Component.h:163
oms::Component::getConnector
Connector * getConnector(const ComRef &cref)
Definition Component.cpp:153
oms::Component::terminate
virtual oms_status_enu_t terminate()=0
oms::Component::parentSystem
System * parentSystem
Definition Component.h:189
oms::Component::getFMU
virtual fmiHandle * getFMU()
Definition Component.h:133
oms::Component::exportToSSMTemplate
virtual oms_status_enu_t exportToSSMTemplate(pugi::xml_node &ssmNode)
Definition Component.h:99
oms::Component::operator=
Component & operator=(Component const &)
not implemented
oms::Component::values
Values values
Definition Component.h:194
oms::Component::stepUntil
virtual oms_status_enu_t stepUntil(double stopTime)
Definition Component.h:116
oms::Component::addSignalsToResults
virtual oms_status_enu_t addSignalsToResults(const char *regex)=0
oms::Component::getNextEventTimeDefined
virtual bool getNextEventTimeDefined()
Definition Component.h:144
oms::Component::deleteReferencesInSSD
virtual oms_status_enu_t deleteReferencesInSSD(const std::string &filename)
Definition Component.h:121
oms::Component::registerSignalsForResultFile
virtual oms_status_enu_t registerSignalsForResultFile(ResultWriter &resultFile)=0
oms::Component::getFullCref
ComRef getFullCref() const
Definition Component.cpp:143
oms::Component::getEventindicators
virtual oms_status_enu_t getEventindicators(double *eventindicators, size_t size)
Definition Component.h:131
oms::Component::setRealInputDerivative
virtual oms_status_enu_t setRealInputDerivative(const ComRef &cref, const SignalDerivative &der)
Definition Component.h:115
oms::Component::renameValues
virtual oms_status_enu_t renameValues(const ComRef &oldCref, const ComRef &newCref)
Definition Component.h:177
oms::Component::initialUnknownsGraph
DirectedGraph initialUnknownsGraph
Definition Component.h:180
oms::Component::getParentSystem
System * getParentSystem() const
Definition Component.h:159
oms::Component::getFilteredEnumerationDefinitionsToSSD
virtual void getFilteredEnumerationDefinitionsToSSD(std::map< std::string, std::map< std::string, std::string > > &enumerationDefinitions)
Definition Component.h:73
oms::Component::exportToSSD
virtual oms_status_enu_t exportToSSD(pugi::xml_node &node, Snapshot &snapshot, std::string variantName) const =0
oms::Component::getReal
virtual oms_status_enu_t getReal(const ComRef &cref, double &value)
Definition Component.h:104
oms::Component::getNewDiscreteStatesNeeded
virtual bool getNewDiscreteStatesNeeded()
Definition Component.h:140
oms::Component::getFilteredSignals
virtual void getFilteredSignals(std::vector< Connector > &filteredSignals) const =0
oms::Component::reset
virtual oms_status_enu_t reset()=0
oms::Component::getNextEventTime
virtual double getNextEventTime()
Definition Component.h:145
oms::Component::outputsGraph
DirectedGraph outputsGraph
Definition Component.h:181
oms::Component::enterEventMode
virtual oms_status_enu_t enterEventMode()
Definition Component.h:137
oms::Component::setContinuousStates
virtual oms_status_enu_t setContinuousStates(double *states)
Definition Component.h:127
oms::Component::rename
oms_status_enu_t rename(const ComRef &newCref)
rename submodules, e.g., fmu:s
Definition Component.cpp:183
oms::Component::getRealOutputDerivative
virtual oms_status_enu_t getRealOutputDerivative(const ComRef &cref, SignalDerivative &der)
Definition Component.h:106
oms::Component::setBoolean
virtual oms_status_enu_t setBoolean(const ComRef &cref, bool value)
Definition Component.h:110
oms::Component::instantiate
virtual oms_status_enu_t instantiate()=0
oms::Component::getValuesOfContinuousStatesChanged
virtual bool getValuesOfContinuousStatesChanged()
Definition Component.h:143
oms::Component::updateOrDeleteStartValueInReplacedComponent
virtual oms_status_enu_t updateOrDeleteStartValueInReplacedComponent(std::vector< std::string > &warningList)
Definition Component.h:98
oms::Component::getAllResources
void getAllResources(std::vector< std::string > &resources) const
Definition Component.h:153
oms::Component::Component
Component(Component const &)
not implemented
oms::Component::getModel
Model & getModel() const
Definition Component.cpp:148
oms::Component::type
oms_component_enu_t type
Definition Component.h:191
oms::Component::completedIntegratorStep
virtual oms_status_enu_t completedIntegratorStep(bool noSetFMUStatePriorToCurrentPoint, bool &enterEventMode, bool &terminateSimulation)
Definition Component.h:136
oms::Component::getFMUInfo
virtual const FMUInfo * getFMUInfo() const
Definition Component.h:93
oms::Component::getConnectors
Connector ** getConnectors()
Definition Component.h:151
oms::Component::getPath
const std::string & getPath() const
Definition Component.h:154
oms::Component::getEventInfo
virtual fmi2EventInfo * getEventInfo()
Definition Component.h:134
oms::Component::setGeometry
void setGeometry(const ssd::ElementGeometry &geometry)
Definition Component.h:161
oms::Component::getNumberOfEventIndicators
virtual size_t getNumberOfEventIndicators() const
Definition Component.h:125
oms::Component::exportToSSV
virtual oms_status_enu_t exportToSSV(pugi::xml_node &ssvNode)
Definition Component.h:71
oms::Component::doEventIteration
virtual oms_status_enu_t doEventIteration()
Definition Component.h:135
oms::Component::getTempDir
const std::string & getTempDir() const
Definition Component.h:155
oms::Component::updateSignals
virtual oms_status_enu_t updateSignals(ResultWriter &resultWriter)=0
oms::Component::~Component
virtual ~Component()
Definition Component.cpp:136
oms::Component::getContinuousStates
virtual oms_status_enu_t getContinuousStates(double *states)
Definition Component.h:126
oms::Component::getNominalsOfContinuousStates
virtual oms_status_enu_t getNominalsOfContinuousStates(double *nominals)
Definition Component.h:129
oms::Connector
Connector.
Definition Connector.h:54
oms::DirectedGraph
Definition DirectedGraph.h:71
oms::Element
Element.
Definition Element.h:51
oms::Element::setGeometry
void setGeometry(const oms::ssd::ElementGeometry *newGeometry)
Definition Element.cpp:70
oms::FMUInfo
FMU info.
Definition FMUInfo.h:49
oms::Model
Definition Model.h:57
oms::ResultWriter
Definition ResultWriter.h:73
oms::SignalDerivative
Definition SignalDerivative.h:46
oms::Snapshot
Definition Snapshot.h:51
oms::System
Definition System.h:66
oms::Values
Definition Values.h:50
oms::Variable
Definition Variable.h:50
oms::Variable::getType
oms_signal_type_enu_t getType() const
Definition Variable.h:94
oms::ssd::ElementGeometry
Definition ElementGeometry.h:50
oms
Definition AlgLoop.h:52
oms::fmi3logger
void fmi3logger(fmi3InstanceEnvironment env, fmi3Status status, fmi3String category, fmi3String message)
Definition Component.cpp:96
oms::fmi2logger
void fmi2logger(fmi2ComponentEnvironment env, fmi2String instanceName, fmi2Status status, fmi2String category, fmi2String message,...)
Definition Component.cpp:46