OMSimulatorLib
The OMSimulator project is a FMI-based co-simulation environment.
Loading...
Searching...
No Matches
ComponentFMU3ME.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_3_ME_H_
37#define _OMS_COMPONENT_FMU_3_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
54namespace oms
55{
57 {
58 public:
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
77 oms_status_enu_t initializeDependencyGraph_outputs();
78
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, oms_signal_numeric_type_enu_t numericType);
88 oms_status_enu_t getReal(const ComRef& cref, double& value);
89 oms_status_enu_t getReal(const fmi2ValueReference& vr, double& value, oms_signal_numeric_type_enu_t numericType);
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
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
127
128 void getFilteredSignals(std::vector<Connector>& filteredSignals) const;
129
130 oms_status_enu_t newResources(const std::string& ssvFilename, const std::string& ssmFilename, bool externalResources);
131 oms_status_enu_t setResourcesHelper1(Values value);
132 oms_status_enu_t setResourcesHelper2(Values value);
133 oms_status_enu_t setExportName(const std::string & exportName) { this->exportName = exportName; return oms_status_ok;};
134 std::string getExportName() const { return this->exportName; }
135 oms_status_enu_t deleteReferencesInSSD(const std::string& filename);
136 oms_status_enu_t deleteResourcesInSSP(const std::string& filename);
137
139 bool getTerminateSimulation() {return terminateSimulation == fmi3True; }
142 bool getNextEventTimeDefined() {return nextEventTimeDefined == fmi3True; }
143 double getNextEventTime() { return nextEventTime; }
144
145 protected:
146 ComponentFMU3ME(const ComRef& cref, System* parentSystem, const std::string& fmuPath);
147
148 // stop the compiler generating methods copying the object
151
152 oms_status_enu_t renameValues(const ComRef& oldCref, const ComRef& newCref);
153
154 void dumpInitialUnknowns();
155
156 private:
157 fmi3LogMessageCallback omsfmi3logger;
158 fmiHandle *fmu = NULL;
159
162
168 fmi3Float64 nextEventTime;
170
171 std::vector<Variable> allVariables;
172 std::vector<unsigned int> calculatedParameters;
173 std::vector<unsigned int> derivatives;
174 std::vector<unsigned int> inputs;
175 std::vector<unsigned int> outputs;
176 std::vector<unsigned int> parameters;
177 std::vector<bool> exportVariables;
178 std::string exportName;
179
181
182 std::unordered_map<unsigned int /*result file var ID*/, unsigned int /*allVariables ID*/> resultFileMapping;
183
185 };
186}
187
188#endif
ComRef - component reference.
Definition ComRef.h:51
Definition ComponentFMU3ME.h:57
fmi3Float64 nextEventTime
Definition ComponentFMU3ME.h:168
oms_status_enu_t getReal(const fmi2ValueReference &vr, double &value, oms_signal_numeric_type_enu_t numericType)
oms_status_enu_t getContinuousStates(double *states)
Definition ComponentFMU3ME.cpp:2026
size_t nContinuousStates
Definition ComponentFMU3ME.h:161
oms_status_enu_t exportToSSVTemplate(pugi::xml_node &ssvNode, Snapshot &snapshot)
Definition ComponentFMU3ME.cpp:446
oms_status_enu_t getEventindicators(double *eventindicators)
Definition ComponentFMU3ME.cpp:2062
oms_status_enu_t registerSignalsForResultFile(ResultWriter &resultFile)
Definition ComponentFMU3ME.cpp:1917
std::vector< unsigned int > parameters
Definition ComponentFMU3ME.h:176
oms_status_enu_t getReal(const ComRef &cref, double &value)
Definition ComponentFMU3ME.cpp:1235
std::vector< unsigned int > inputs
Definition ComponentFMU3ME.h:174
oms_status_enu_t terminate()
Definition ComponentFMU3ME.cpp:896
fmi3Boolean terminateSimulation
Definition ComponentFMU3ME.h:164
ComponentFMU3ME & operator=(ComponentFMU3ME const &copy)
not implemented
fmiHandle * getFMU()
Definition ComponentFMU3ME.h:124
oms_status_enu_t getDirectionalDerivativeHeper(const int unknownIndex, const int knownIndex, const std::vector< int > &dependencyList, double &value)
Definition ComponentFMU3ME.cpp:1489
double getNextEventTime()
Definition ComponentFMU3ME.h:143
size_t nEventIndicators
Definition ComponentFMU3ME.h:160
bool getTerminateSimulation()
Definition ComponentFMU3ME.h:139
oms_status_enu_t renameValues(const ComRef &oldCref, const ComRef &newCref)
Definition ComponentFMU3ME.cpp:2181
oms_status_enu_t updateSignals(ResultWriter &resultWriter)
Definition ComponentFMU3ME.cpp:1986
oms_status_enu_t enterEventMode()
Definition ComponentFMU3ME.cpp:2091
oms_status_enu_t initializeDependencyGraph_outputs()
Definition ComponentFMU3ME.cpp:579
oms_status_enu_t setInteger(const ComRef &cref, int value)
Definition ComponentFMU3ME.cpp:1572
oms_status_enu_t getBoolean(const ComRef &cref, bool &value)
Definition ComponentFMU3ME.cpp:941
oms_status_enu_t exportToSSD(pugi::xml_node &node, Snapshot &snapshot, std::string variantName) const
Definition ComponentFMU3ME.cpp:390
void getFilteredSignals(std::vector< Connector > &filteredSignals) const
Definition ComponentFMU3ME.cpp:2172
oms_status_enu_t setValuesResources(Values &values)
Definition ComponentFMU3ME.cpp:1707
oms::ComRef getValidCref(ComRef cref)
Definition ComponentFMU3ME.cpp:775
void getFilteredUnitDefinitionsToSSD(std::map< std::string, std::map< std::string, std::string > > &unitDefinitions)
Definition ComponentFMU3ME.cpp:414
Values values
start values defined before instantiating the FMU and external inputs defined after initialization
Definition ComponentFMU3ME.h:180
oms_status_enu_t setResourcesHelper1(Values value)
Definition ComponentFMU3ME.cpp:694
oms_status_enu_t addSignalsToResults(const char *regex)
Definition ComponentFMU3ME.cpp:2118
size_t getNumberOfEventIndicators() const
Definition ComponentFMU3ME.h:113
fmi3Boolean nextEventTimeDefined
Definition ComponentFMU3ME.h:167
oms_status_enu_t getNominalsOfContinuousStates(double *nominals)
Definition ComponentFMU3ME.cpp:2053
std::vector< Variable > allVariables
Definition ComponentFMU3ME.h:171
oms_status_enu_t deleteReferencesInSSD(const std::string &filename)
Definition ComponentFMU3ME.cpp:851
fmi3Boolean newDiscreteStatesNeeded
Definition ComponentFMU3ME.h:163
std::string exportName
export name of the FMU, used for the result file
Definition ComponentFMU3ME.h:178
oms_status_enu_t getBoolean(const fmi2ValueReference &vr, bool &value)
oms_status_enu_t removeSignalsFromResults(const char *regex)
Definition ComponentFMU3ME.cpp:2145
oms_status_enu_t initializeDependencyGraph_initialUnknowns()
Definition ComponentFMU3ME.cpp:476
oms_status_enu_t setBoolean(const ComRef &cref, bool value)
Definition ComponentFMU3ME.cpp:1521
ComponentFMU3ME(ComponentFMU3ME const &copy)
not implemented
oms_status_enu_t getDerivatives(double *derivatives)
Definition ComponentFMU3ME.cpp:2044
Variable * getVariable(const ComRef &cref)
Definition ComponentFMU3ME.cpp:1191
const FMUInfo * getFMUInfo() const
Definition ComponentFMU3ME.h:63
bool getNominalsOfContinuousStatesChanged()
Definition ComponentFMU3ME.h:140
fmi3LogMessageCallback omsfmi3logger
Definition ComponentFMU3ME.h:157
oms_status_enu_t exportToSSV(pugi::xml_node &ssvNode)
Definition ComponentFMU3ME.cpp:441
oms_status_enu_t setResourcesHelper2(Values value)
Definition ComponentFMU3ME.cpp:718
oms_status_enu_t newResources(const std::string &ssvFilename, const std::string &ssmFilename, bool externalResources)
Definition ComponentFMU3ME.cpp:811
std::string getExportName() const
Definition ComponentFMU3ME.h:134
oms_status_enu_t getString(const fmi2ValueReference &vr, std::string &value)
oms_status_enu_t completedIntegratorStep(bool noSetFMUStatePriorToCurrentPoint, bool &enterEventMode, bool &terminateSimulation)
Definition ComponentFMU3ME.cpp:2071
oms_status_enu_t setTime(double time)
Definition ComponentFMU3ME.cpp:1103
oms_status_enu_t updateOrDeleteStartValueInReplacedComponent(std::vector< std::string > &warningList)
Definition ComponentFMU3ME.cpp:1720
Values & getValues()
Definition ComponentFMU3ME.h:81
oms_status_enu_t reset()
Definition ComponentFMU3ME.cpp:907
fmi3Boolean nominalsOfContinuousStatesChanged
Definition ComponentFMU3ME.h:165
oms_status_enu_t setUnit(const ComRef &cref, const std::string &value)
Definition ComponentFMU3ME.cpp:1876
std::vector< unsigned int > outputs
Definition ComponentFMU3ME.h:175
oms_status_enu_t getDirectionalDerivative(const ComRef &unknownCref, const ComRef &knownCref, double &value)
Definition ComponentFMU3ME.cpp:1407
void dumpInitialUnknowns()
Definition ComponentFMU3ME.cpp:459
oms_status_enu_t enterContinuousTimeMode()
Definition ComponentFMU3ME.cpp:2100
oms_status_enu_t initialize()
Definition ComponentFMU3ME.cpp:867
bool getNewDiscreteStatesNeeded()
Definition ComponentFMU3ME.h:138
oms_status_enu_t getInteger(const fmi2ValueReference &vr, int &value, oms_signal_numeric_type_enu_t numericType)
oms_status_enu_t getInteger(const ComRef &cref, int &value)
Definition ComponentFMU3ME.cpp:1111
std::vector< bool > exportVariables
Definition ComponentFMU3ME.h:177
oms_status_enu_t setReal(const ComRef &cref, double value)
Definition ComponentFMU3ME.cpp:1746
FMUInfo fmuInfo
Definition ComponentFMU3ME.h:169
oms_status_enu_t setString(const ComRef &cref, const std::string &value)
Definition ComponentFMU3ME.cpp:1820
~ComponentFMU3ME()
Definition ComponentFMU3ME.cpp:59
oms_status_enu_t setExportName(const std::string &exportName)
Definition ComponentFMU3ME.h:133
oms_status_enu_t exportToSSMTemplate(pugi::xml_node &ssmNode)
Definition ComponentFMU3ME.cpp:453
bool getNextEventTimeDefined()
Definition ComponentFMU3ME.h:142
static Component * NewComponent(const oms::ComRef &cref, System *parentSystem, const std::string &fmuPath, std::string replaceComponent="")
Definition ComponentFMU3ME.cpp:67
size_t getNumberOfContinuousStates() const
Definition ComponentFMU3ME.h:112
bool getValuesOfContinuousStatesChanged()
Definition ComponentFMU3ME.h:141
fmi3Boolean valuesOfContinuousStatesChanged
Definition ComponentFMU3ME.h:166
std::vector< unsigned int > calculatedParameters
Definition ComponentFMU3ME.h:172
fmiHandle * fmu
Definition ComponentFMU3ME.h:158
oms_status_enu_t getString(const ComRef &cref, std::string &value)
Definition ComponentFMU3ME.cpp:1327
bool getCanGetAndSetState()
Definition ComponentFMU3ME.h:126
std::vector< unsigned int > derivatives
Definition ComponentFMU3ME.h:173
void getFilteredEnumerationDefinitionsToSSD(std::map< std::string, std::map< std::string, std::string > > &enumerationDefinitions)
Definition ComponentFMU3ME.cpp:436
oms_status_enu_t setContinuousStates(double *states)
Definition ComponentFMU3ME.cpp:2035
oms_status_enu_t deleteResourcesInSSP(const std::string &filename)
Definition ComponentFMU3ME.cpp:859
std::unordered_map< unsigned int, unsigned int > resultFileMapping
Definition ComponentFMU3ME.h:182
oms_status_enu_t instantiate()
Definition ComponentFMU3ME.cpp:630
oms_status_enu_t deleteStartValue(const ComRef &cref)
Definition ComponentFMU3ME.cpp:1682
oms_status_enu_t doEventIteration()
Definition ComponentFMU3ME.cpp:785
Definition Component.h:65
ComRef cref
Definition Component.h:190
System * parentSystem
Definition Component.h:189
FMU info.
Definition FMUInfo.h:49
bool getCanGetAndSetFMUstate() const
Definition FMUInfo.h:60
Definition ResultWriter.h:73
Definition Snapshot.h:51
Definition System.h:66
Definition Values.h:50
Definition Variable.h:50
Definition AlgLoop.h:49