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

Loading...
Searching...
No Matches
ComponentFMUME.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_FMU_ME_H_
37#define _OMS_COMPONENT_FMU_ME_H_
38
39#include "Component.h"
40#include "ComRef.h"
41#include "ResultWriter.h"
42#include "Snapshot.h"
43#include "Values.h"
44#include "Variable.h"
45
46#include <fmi4c.h>
47
48#include <map>
49#include <pugixml.hpp>
50#include <string>
51#include <unordered_map>
52#include <vector>
53
54 namespace oms
55{
56 class ComponentFMUME : public Component
57 {
58 public:
59 ~ComponentFMUME();
60
61 static Component* NewComponent(const oms::ComRef& cref, System* parentSystem, const std::string& fmuPath, std::string replaceComponent = "");
62 static Component* NewComponent(const pugi::xml_node& node, System* parentSystem, const std::string& sspVersion, const Snapshot& snapshot, std::string variantName);
63 const FMUInfo* getFMUInfo() const {return &(this->fmuInfo);}
64
65 oms_status_enu_t exportToSSD(pugi::xml_node& node, Snapshot& snapshot, std::string variantName) const;
66 oms_status_enu_t exportToSSV(pugi::xml_node& ssvNode);
67 void getFilteredUnitDefinitionsToSSD(std::map<std::string, std::map<std::string, std::string>>& unitDefinitions);
68 void getFilteredEnumerationDefinitionsToSSD(std::map<std::string, std::map<std::string, std::string>>& enumerationDefinitions);
69 oms_status_enu_t exportToSSVTemplate(pugi::xml_node& ssvNode, Snapshot& snapshot);
70 oms_status_enu_t exportToSSMTemplate(pugi::xml_node& ssmNode);
71 oms_status_enu_t instantiate();
72 oms_status_enu_t initialize();
73 oms_status_enu_t terminate();
74 oms_status_enu_t reset();
75
76 oms_status_enu_t initializeDependencyGraph_initialUnknowns();
77 oms_status_enu_t initializeDependencyGraph_outputs();
78
79 Variable* getVariable(const ComRef& cref);
80
81 Values& getValues() { return values; }
82 oms_status_enu_t setValuesResources(Values& values);
83
84 oms_status_enu_t getBoolean(const ComRef& cref, bool& value);
85 oms_status_enu_t getBoolean(const fmi2ValueReference& vr, bool& value);
86 oms_status_enu_t getInteger(const ComRef& cref, int& value);
87 oms_status_enu_t getInteger(const fmi2ValueReference& vr, int& value);
88 oms_status_enu_t getReal(const ComRef& cref, double& value);
89 oms_status_enu_t getReal(const fmi2ValueReference& vr, double& value);
90 oms_status_enu_t getString(const ComRef& cref, std::string& value);
91 oms_status_enu_t getString(const fmi2ValueReference& vr, std::string& value);
92 oms_status_enu_t setBoolean(const ComRef& cref, bool value);
93 oms_status_enu_t setInteger(const ComRef& cref, int value);
94 oms_status_enu_t setReal(const ComRef& cref, double value);
95 oms_status_enu_t setString(const ComRef& cref, const std::string& value);
96 oms_status_enu_t setUnit(const ComRef& cref, const std::string& value);
97 oms_status_enu_t setTime(double time);
98
99 oms_status_enu_t getDirectionalDerivative(const ComRef& unknownCref, const ComRef& knownCref, double& value);
100 oms_status_enu_t getDirectionalDerivativeHeper(const int unknownIndex, const int knownIndex, const std::vector<int>& dependencyList, double& value);
101
102 oms_status_enu_t deleteStartValue(const ComRef& cref);
103 oms_status_enu_t updateOrDeleteStartValueInReplacedComponent(std::vector<std::string>& warningList);
104
105 oms_status_enu_t registerSignalsForResultFile(ResultWriter& resultFile);
106 oms_status_enu_t updateSignals(ResultWriter& resultWriter);
107 oms_status_enu_t addSignalsToResults(const char* regex);
108 oms_status_enu_t removeSignalsFromResults(const char* regex);
109
110 oms_status_enu_t doEventIteration();
111
112 size_t getNumberOfContinuousStates() const {return derivatives.size();}
113 size_t getNumberOfEventIndicators() const {return nEventIndicators;}
114 oms_status_enu_t getContinuousStates(double* states);
115 oms_status_enu_t setContinuousStates(double* states);
116 oms_status_enu_t getDerivatives(double* derivatives);
117 oms_status_enu_t getNominalsOfContinuousStates(double* nominals);
118 oms_status_enu_t getEventindicators(double* eventindicators);
119 oms_status_enu_t getEventindicators(double* eventindicators, size_t size);
120 oms_status_enu_t completedIntegratorStep(bool noSetFMUStatePriorToCurrentPoint, bool& enterEventMode, bool& terminateSimulation);
121 oms_status_enu_t enterEventMode();
122 oms_status_enu_t enterContinuousTimeMode();
123
124 fmiHandle* getFMU() {return fmu;}
125 fmi2EventInfo* getEventInfo() {return &eventInfo;}
126
127 bool getCanGetAndSetState() {return getFMUInfo()->getCanGetAndSetFMUstate();}
128
129 void getFilteredSignals(std::vector<Connector>& filteredSignals) const;
130
131 oms_status_enu_t newResources(const std::string& ssvFilename, const std::string& ssmFilename, bool externalResources);
132 oms_status_enu_t setResourcesHelper1(Values value);
133 oms_status_enu_t setResourcesHelper2(Values value);
134 oms_status_enu_t setExportName(const std::string & exportName);
135 std::string getExportName() const { return this->exportName; }
136 oms_status_enu_t deleteReferencesInSSD(const std::string& filename);
137 oms_status_enu_t deleteResourcesInSSP(const std::string& filename);
138
139 bool getNewDiscreteStatesNeeded() {return eventInfo.newDiscreteStatesNeeded == fmi2True; }
140 bool getTerminateSimulation() {return eventInfo.terminateSimulation == fmi2True; }
141 bool getNominalsOfContinuousStatesChanged() {return eventInfo.nominalsOfContinuousStatesChanged == fmi2True; }
142 bool getValuesOfContinuousStatesChanged() {return eventInfo.valuesOfContinuousStatesChanged == fmi2True; }
143 bool getNextEventTimeDefined() {return eventInfo.nextEventTimeDefined == fmi2True; }
144 double getNextEventTime() { return eventInfo.nextEventTime; }
145
146 protected:
147 ComponentFMUME(const ComRef& cref, System* parentSystem, const std::string& fmuPath);
148
149 // stop the compiler generating methods copying the object
150 ComponentFMUME(ComponentFMUME const& copy);
151 ComponentFMUME& operator=(ComponentFMUME const& copy);
152
153 oms_status_enu_t renameValues(const ComRef& oldCref, const ComRef& newCref);
154
155 void dumpInitialUnknowns();
156
157 private:
158 fmi2CallbackLogger omsfmi2logger;
159 fmiHandle *fmu = NULL;
160
161 fmi2EventInfo eventInfo;
162 size_t nEventIndicators;
163
164 FMUInfo fmuInfo;
165
166 std::vector<Variable> allVariables;
167 std::vector<unsigned int> calculatedParameters;
168 std::vector<unsigned int> derivatives;
169 std::vector<unsigned int> inputs;
170 std::vector<unsigned int> outputs;
171 std::vector<unsigned int> parameters;
172 std::vector<bool> exportVariables;
173 std::string exportName;
174
175 Values values;
176
177 std::unordered_map<unsigned int /*result file var ID*/, unsigned int /*allVariables ID*/> resultFileMapping;
178
179 oms::ComRef getValidCref(ComRef cref);
180 };
181}
182
183#endif
ComRef.h
Component.h
ResultWriter.h
Snapshot.h
Values.h
Variable.h
oms::ComRef
ComRef - component reference.
Definition ComRef.h:51
oms::ComponentFMUME
Definition ComponentFMUME.h:57
oms::ComponentFMUME::registerSignalsForResultFile
oms_status_enu_t registerSignalsForResultFile(ResultWriter &resultFile)
Definition ComponentFMUME.cpp:1770
oms::ComponentFMUME::deleteStartValue
oms_status_enu_t deleteStartValue(const ComRef &cref)
Definition ComponentFMUME.cpp:1551
oms::ComponentFMUME::getNextEventTime
double getNextEventTime()
Definition ComponentFMUME.h:144
oms::ComponentFMUME::~ComponentFMUME
~ComponentFMUME()
Definition ComponentFMUME.cpp:57
oms::ComponentFMUME::getEventInfo
fmi2EventInfo * getEventInfo()
Definition ComponentFMUME.h:125
oms::ComponentFMUME::deleteReferencesInSSD
oms_status_enu_t deleteReferencesInSSD(const std::string &filename)
Definition ComponentFMUME.cpp:876
oms::ComponentFMUME::enterContinuousTimeMode
oms_status_enu_t enterContinuousTimeMode()
Definition ComponentFMUME.cpp:1967
oms::ComponentFMUME::getValidCref
oms::ComRef getValidCref(ComRef cref)
Definition ComponentFMUME.cpp:806
oms::ComponentFMUME::getDirectionalDerivativeHeper
oms_status_enu_t getDirectionalDerivativeHeper(const int unknownIndex, const int knownIndex, const std::vector< int > &dependencyList, double &value)
Definition ComponentFMUME.cpp:1420
oms::ComponentFMUME::operator=
ComponentFMUME & operator=(ComponentFMUME const &copy)
not implemented
oms::ComponentFMUME::getReal
oms_status_enu_t getReal(const ComRef &cref, double &value)
Definition ComponentFMUME.cpp:1166
oms::ComponentFMUME::renameValues
oms_status_enu_t renameValues(const ComRef &oldCref, const ComRef &newCref)
Definition ComponentFMUME.cpp:2039
oms::ComponentFMUME::reset
oms_status_enu_t reset()
Definition ComponentFMUME.cpp:924
oms::ComponentFMUME::derivatives
std::vector< unsigned int > derivatives
Definition ComponentFMUME.h:168
oms::ComponentFMUME::setTime
oms_status_enu_t setTime(double time)
Definition ComponentFMUME.cpp:1052
oms::ComponentFMUME::parameters
std::vector< unsigned int > parameters
Definition ComponentFMUME.h:171
oms::ComponentFMUME::setExportName
oms_status_enu_t setExportName(const std::string &exportName)
Definition ComponentFMUME.cpp:401
oms::ComponentFMUME::getVariable
Variable * getVariable(const ComRef &cref)
Definition ComponentFMUME.cpp:1140
oms::ComponentFMUME::setBoolean
oms_status_enu_t setBoolean(const ComRef &cref, bool value)
Definition ComponentFMUME.cpp:1448
oms::ComponentFMUME::resultFileMapping
std::unordered_map< unsigned int, unsigned int > resultFileMapping
Definition ComponentFMUME.h:177
oms::ComponentFMUME::getContinuousStates
oms_status_enu_t getContinuousStates(double *states)
Definition ComponentFMUME.cpp:1883
oms::ComponentFMUME::setContinuousStates
oms_status_enu_t setContinuousStates(double *states)
Definition ComponentFMUME.cpp:1892
oms::ComponentFMUME::inputs
std::vector< unsigned int > inputs
Definition ComponentFMUME.h:169
oms::ComponentFMUME::getFilteredSignals
void getFilteredSignals(std::vector< Connector > &filteredSignals) const
Definition ComponentFMUME.cpp:2030
oms::ComponentFMUME::getValues
Values & getValues()
Definition ComponentFMUME.h:81
oms::ComponentFMUME::fmuInfo
FMUInfo fmuInfo
Definition ComponentFMUME.h:164
oms::ComponentFMUME::calculatedParameters
std::vector< unsigned int > calculatedParameters
Definition ComponentFMUME.h:167
oms::ComponentFMUME::getFMU
fmiHandle * getFMU()
Definition ComponentFMUME.h:124
oms::ComponentFMUME::getNominalsOfContinuousStatesChanged
bool getNominalsOfContinuousStatesChanged()
Definition ComponentFMUME.h:141
oms::ComponentFMUME::terminate
oms_status_enu_t terminate()
Definition ComponentFMUME.cpp:913
oms::ComponentFMUME::getNextEventTimeDefined
bool getNextEventTimeDefined()
Definition ComponentFMUME.h:143
oms::ComponentFMUME::addSignalsToResults
oms_status_enu_t addSignalsToResults(const char *regex)
Definition ComponentFMUME.cpp:1976
oms::ComponentFMUME::setInteger
oms_status_enu_t setInteger(const ComRef &cref, int value)
Definition ComponentFMUME.cpp:1500
oms::ComponentFMUME::values
Values values
start values defined before instantiating the FMU and external inputs defined after initialization
Definition ComponentFMUME.h:175
oms::ComponentFMUME::NewComponent
static Component * NewComponent(const oms::ComRef &cref, System *parentSystem, const std::string &fmuPath, std::string replaceComponent="")
Definition ComponentFMUME.cpp:65
oms::ComponentFMUME::getString
oms_status_enu_t getString(const ComRef &cref, std::string &value)
Definition ComponentFMUME.cpp:1258
oms::ComponentFMUME::removeSignalsFromResults
oms_status_enu_t removeSignalsFromResults(const char *regex)
Definition ComponentFMUME.cpp:2003
oms::ComponentFMUME::getFMUInfo
const FMUInfo * getFMUInfo() const
Definition ComponentFMUME.h:63
oms::ComponentFMUME::allVariables
std::vector< Variable > allVariables
Definition ComponentFMUME.h:166
oms::ComponentFMUME::getFilteredUnitDefinitionsToSSD
void getFilteredUnitDefinitionsToSSD(std::map< std::string, std::map< std::string, std::string > > &unitDefinitions)
Definition ComponentFMUME.cpp:414
oms::ComponentFMUME::fmu
fmiHandle * fmu
Definition ComponentFMUME.h:159
oms::ComponentFMUME::initialize
oms_status_enu_t initialize()
Definition ComponentFMUME.cpp:892
oms::ComponentFMUME::exportToSSMTemplate
oms_status_enu_t exportToSSMTemplate(pugi::xml_node &ssmNode)
Definition ComponentFMUME.cpp:453
oms::ComponentFMUME::initializeDependencyGraph_outputs
oms_status_enu_t initializeDependencyGraph_outputs()
Definition ComponentFMUME.cpp:579
oms::ComponentFMUME::deleteResourcesInSSP
oms_status_enu_t deleteResourcesInSSP(const std::string &filename)
Definition ComponentFMUME.cpp:884
oms::ComponentFMUME::initializeDependencyGraph_initialUnknowns
oms_status_enu_t initializeDependencyGraph_initialUnknowns()
Definition ComponentFMUME.cpp:476
oms::ComponentFMUME::getBoolean
oms_status_enu_t getBoolean(const ComRef &cref, bool &value)
Definition ComponentFMUME.cpp:962
oms::ComponentFMUME::getNumberOfContinuousStates
size_t getNumberOfContinuousStates() const
Definition ComponentFMUME.h:112
oms::ComponentFMUME::exportToSSVTemplate
oms_status_enu_t exportToSSVTemplate(pugi::xml_node &ssvNode, Snapshot &snapshot)
Definition ComponentFMUME.cpp:446
oms::ComponentFMUME::setResourcesHelper1
oms_status_enu_t setResourcesHelper1(Values value)
Definition ComponentFMUME.cpp:725
oms::ComponentFMUME::eventInfo
fmi2EventInfo eventInfo
Definition ComponentFMUME.h:161
oms::ComponentFMUME::nEventIndicators
size_t nEventIndicators
Definition ComponentFMUME.h:162
oms::ComponentFMUME::exportToSSD
oms_status_enu_t exportToSSD(pugi::xml_node &node, Snapshot &snapshot, std::string variantName) const
Definition ComponentFMUME.cpp:377
oms::ComponentFMUME::enterEventMode
oms_status_enu_t enterEventMode()
Definition ComponentFMUME.cpp:1958
oms::ComponentFMUME::getValuesOfContinuousStatesChanged
bool getValuesOfContinuousStatesChanged()
Definition ComponentFMUME.h:142
oms::ComponentFMUME::completedIntegratorStep
oms_status_enu_t completedIntegratorStep(bool noSetFMUStatePriorToCurrentPoint, bool &enterEventMode, bool &terminateSimulation)
Definition ComponentFMUME.cpp:1937
oms::ComponentFMUME::exportVariables
std::vector< bool > exportVariables
Definition ComponentFMUME.h:172
oms::ComponentFMUME::getTerminateSimulation
bool getTerminateSimulation()
Definition ComponentFMUME.h:140
oms::ComponentFMUME::getInteger
oms_status_enu_t getInteger(const ComRef &cref, int &value)
Definition ComponentFMUME.cpp:1060
oms::ComponentFMUME::getFilteredEnumerationDefinitionsToSSD
void getFilteredEnumerationDefinitionsToSSD(std::map< std::string, std::map< std::string, std::string > > &enumerationDefinitions)
Definition ComponentFMUME.cpp:436
oms::ComponentFMUME::doEventIteration
oms_status_enu_t doEventIteration()
Definition ComponentFMUME.cpp:816
oms::ComponentFMUME::getNumberOfEventIndicators
size_t getNumberOfEventIndicators() const
Definition ComponentFMUME.h:113
oms::ComponentFMUME::exportName
std::string exportName
export name of the FMU, used for the result file
Definition ComponentFMUME.h:173
oms::ComponentFMUME::setValuesResources
oms_status_enu_t setValuesResources(Values &values)
Definition ComponentFMUME.cpp:1576
oms::ComponentFMUME::ComponentFMUME
ComponentFMUME(ComponentFMUME const &copy)
not implemented
oms::ComponentFMUME::instantiate
oms_status_enu_t instantiate()
Definition ComponentFMUME.cpp:659
oms::ComponentFMUME::getExportName
std::string getExportName() const
Definition ComponentFMUME.h:135
oms::ComponentFMUME::updateOrDeleteStartValueInReplacedComponent
oms_status_enu_t updateOrDeleteStartValueInReplacedComponent(std::vector< std::string > &warningList)
Definition ComponentFMUME.cpp:1589
oms::ComponentFMUME::exportToSSV
oms_status_enu_t exportToSSV(pugi::xml_node &ssvNode)
Definition ComponentFMUME.cpp:441
oms::ComponentFMUME::getCanGetAndSetState
bool getCanGetAndSetState()
Definition ComponentFMUME.h:127
oms::ComponentFMUME::omsfmi2logger
fmi2CallbackLogger omsfmi2logger
Definition ComponentFMUME.h:158
oms::ComponentFMUME::updateSignals
oms_status_enu_t updateSignals(ResultWriter &resultWriter)
Definition ComponentFMUME.cpp:1843
oms::ComponentFMUME::getNewDiscreteStatesNeeded
bool getNewDiscreteStatesNeeded()
Definition ComponentFMUME.h:139
oms::ComponentFMUME::getNominalsOfContinuousStates
oms_status_enu_t getNominalsOfContinuousStates(double *nominals)
Definition ComponentFMUME.cpp:1910
oms::ComponentFMUME::getEventindicators
oms_status_enu_t getEventindicators(double *eventindicators)
Definition ComponentFMUME.cpp:1919
oms::ComponentFMUME::setReal
oms_status_enu_t setReal(const ComRef &cref, double value)
Definition ComponentFMUME.cpp:1615
oms::ComponentFMUME::dumpInitialUnknowns
void dumpInitialUnknowns()
Definition ComponentFMUME.cpp:459
oms::ComponentFMUME::newResources
oms_status_enu_t newResources(const std::string &ssvFilename, const std::string &ssmFilename, bool externalResources)
Definition ComponentFMUME.cpp:836
oms::ComponentFMUME::setString
oms_status_enu_t setString(const ComRef &cref, const std::string &value)
Definition ComponentFMUME.cpp:1673
oms::ComponentFMUME::getDirectionalDerivative
oms_status_enu_t getDirectionalDerivative(const ComRef &unknownCref, const ComRef &knownCref, double &value)
Definition ComponentFMUME.cpp:1338
oms::ComponentFMUME::setUnit
oms_status_enu_t setUnit(const ComRef &cref, const std::string &value)
Definition ComponentFMUME.cpp:1729
oms::ComponentFMUME::setResourcesHelper2
oms_status_enu_t setResourcesHelper2(Values value)
Definition ComponentFMUME.cpp:749
oms::ComponentFMUME::outputs
std::vector< unsigned int > outputs
Definition ComponentFMUME.h:170
oms::ComponentFMUME::getDerivatives
oms_status_enu_t getDerivatives(double *derivatives)
Definition ComponentFMUME.cpp:1901
oms::Component
Definition Component.h:65
oms::Component::cref
ComRef cref
Definition Component.h:190
oms::Component::parentSystem
System * parentSystem
Definition Component.h:189
oms::FMUInfo
FMU info.
Definition FMUInfo.h:49
oms::FMUInfo::getCanGetAndSetFMUstate
bool getCanGetAndSetFMUstate() const
Definition FMUInfo.h:60
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::Variable
Definition Variable.h:50
oms
Definition AlgLoop.h:52