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

Loading...
Searching...
No Matches
ComponentFMU3CS.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_CS_H_
37#define _OMS_COMPONENT_FMU_3_CS_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#include <map>
48#include <pugixml.hpp>
49#include <string>
50#include <unordered_map>
51#include <vector>
52#include <cmath>
53
54 namespace oms
55{
56 class System;
57
58 class ComponentFMU3CS : public Component
59 {
60 public:
61 ~ComponentFMU3CS();
62
63 static Component* NewComponent(const ComRef& cref, System* parentSystem, const std::string& fmuPath, std::string replaceComponent = "");
64 static Component* NewComponent(const pugi::xml_node& node, System* parentSystem, const std::string& sspVersion, const Snapshot& snapshot, std::string variantName);
65 const FMUInfo* getFMUInfo() const {return &(this->fmuInfo);}
66
67 oms_status_enu_t exportToSSD(pugi::xml_node& node, Snapshot& snapshot, std::string variantName) const;
68 oms_status_enu_t exportToSSV(pugi::xml_node& ssvNode);
69 void getFilteredUnitDefinitionsToSSD(std::map<std::string, std::map<std::string, std::string>>& unitDefinitions);
70 void getFilteredEnumerationDefinitionsToSSD(std::map<std::string, std::map<std::string, std::string>>& enumerationDefinitions);
71 oms_status_enu_t exportToSSVTemplate(pugi::xml_node& ssvNode, Snapshot& snapshot);
72 oms_status_enu_t exportToSSMTemplate(pugi::xml_node& ssmNode);
73 oms_status_enu_t instantiate();
74 oms_status_enu_t initialize();
75 oms_status_enu_t terminate();
76 oms_status_enu_t reset();
77
78 oms_status_enu_t stepUntil(double stopTime);
79
80 oms_status_enu_t initializeDependencyGraph_initialUnknowns();
81 oms_status_enu_t initializeDependencyGraph_outputs();
82
83 Variable* getVariable(const ComRef& cref);
84
85 Values& getValues() { return values; }
86 oms_status_enu_t setValuesResources(Values& values);
87
88 oms_status_enu_t getBoolean(const ComRef& cref, bool& value);
89 oms_status_enu_t getBoolean(const fmi3ValueReference& vr, bool& value);
90 oms_status_enu_t getInteger(const ComRef& cref, int& value);
91 oms_status_enu_t getInteger(const fmi3ValueReference& vr, int& value, oms_signal_numeric_type_enu_t numericType);
92 oms_status_enu_t getReal(const ComRef& cref, double& value);
93 oms_status_enu_t getReal(const fmi3ValueReference& vr, double& value, oms_signal_numeric_type_enu_t numericType);
94 oms_status_enu_t getString(const ComRef& cref, std::string& value);
95 oms_status_enu_t getString(const fmi3ValueReference& vr, std::string& value);
96 oms_status_enu_t setBoolean(const ComRef& cref, bool value);
97 oms_status_enu_t setInteger(const ComRef& cref, int value);
98 oms_status_enu_t setReal(const ComRef& cref, double value);
99 oms_status_enu_t setString(const ComRef& cref, const std::string& value);
100 oms_status_enu_t setUnit(const ComRef& cref, const std::string& value);
101
102 oms_status_enu_t getDirectionalDerivative(const ComRef& unknownCref, const ComRef& knownCref, double& value);
103 oms_status_enu_t getDirectionalDerivativeHeper(const int unknownIndex, const int knownindex, const std::vector<int>& dependencyList, double& value);
104
105 oms_status_enu_t deleteStartValue(const ComRef& cref);
106 oms_status_enu_t updateOrDeleteStartValueInReplacedComponent(std::vector<std::string>& warningList);
107
108 oms_status_enu_t setFmuTime(double time) {this->time = time; return oms_status_ok;}
109 fmiHandle* getFMU() {return fmu;}
110 std::vector<Variable> getAllVariables() {return allVariables;}
111
112 oms_status_enu_t getRealOutputDerivative(const ComRef& cref, SignalDerivative& der);
113 oms_status_enu_t setRealInputDerivative(const ComRef& cref, const SignalDerivative& der);
114
115 oms_status_enu_t registerSignalsForResultFile(ResultWriter& resultFile);
116 oms_status_enu_t updateSignals(ResultWriter& resultWriter);
117 oms_status_enu_t addSignalsToResults(const char* regex);
118 oms_status_enu_t removeSignalsFromResults(const char* regex);
119
120 bool getCanGetAndSetState() {return getFMUInfo()->getCanGetAndSetFMUstate();}
121 oms_status_enu_t saveState();
122 oms_status_enu_t freeState();
123 oms_status_enu_t restoreState();
124
125 void getFilteredSignals(std::vector<Connector>& filteredSignals) const;
126
127 oms_status_enu_t newResources(const std::string& ssvFilename, const std::string& ssmFilename, bool externalResources);
128 oms_status_enu_t setResourcesHelper1(Values value);
129 oms_status_enu_t setResourcesHelper2(Values value);
130 oms_status_enu_t setExportName(const std::string & exportName);
131 std::string getExportName() const { return this->exportName; }
132 oms_status_enu_t deleteReferencesInSSD(const std::string& filename);
133 oms_status_enu_t deleteResourcesInSSP(const std::string& filename);
134 void copyModelDescriptionUnit(Values& value);
135
136 protected:
137 ComponentFMU3CS(const ComRef& cref, System* parentSystem, const std::string& fmuPath);
138
139 // stop the compiler generating methods copying the object
140 ComponentFMU3CS(ComponentFMU3CS const& copy);
141 ComponentFMU3CS& operator=(ComponentFMU3CS const& copy);
142
143 oms_status_enu_t renameValues(const ComRef& oldCref, const ComRef& newCref);
144
145 void dumpInitialUnknowns();
146
147 private:
148 fmi3LogMessageCallback omsfmi3logger;
149 fmiHandle *fmu = NULL;
150 FMUInfo fmuInfo;
151
152 std::vector<Variable> allVariables;
153 std::vector<unsigned int> calculatedParameters;
154 std::vector<unsigned int> derivatives;
155 std::vector<unsigned int> inputs;
156 std::vector<unsigned int> outputs;
157 std::vector<unsigned int> parameters;
158 std::vector<bool> exportVariables;
159 std::string exportName;
160
161 Values values;
162
163 std::unordered_map<unsigned int /*result file var ID*/, unsigned int /*allVariables ID*/> resultFileMapping;
164
165 double time;
166 fmi3FMUState fmuState = NULL;
167 double fmuStateTime;
168
169 oms::ComRef getValidCref(ComRef cref);
170 };
171}
172
173#endif
ComRef.h
Component.h
ResultWriter.h
Snapshot.h
Values.h
Variable.h
oms::ComRef
ComRef - component reference.
Definition ComRef.h:51
oms::ComponentFMU3CS
Definition ComponentFMU3CS.h:59
oms::ComponentFMU3CS::~ComponentFMU3CS
~ComponentFMU3CS()
Definition ComponentFMU3CS.cpp:59
oms::ComponentFMU3CS::getFMU
fmiHandle * getFMU()
Definition ComponentFMU3CS.h:109
oms::ComponentFMU3CS::getDirectionalDerivative
oms_status_enu_t getDirectionalDerivative(const ComRef &unknownCref, const ComRef &knownCref, double &value)
Definition ComponentFMU3CS.cpp:1391
oms::ComponentFMU3CS::getValues
Values & getValues()
Definition ComponentFMU3CS.h:85
oms::ComponentFMU3CS::setString
oms_status_enu_t setString(const ComRef &cref, const std::string &value)
Definition ComponentFMU3CS.cpp:1793
oms::ComponentFMU3CS::newResources
oms_status_enu_t newResources(const std::string &ssvFilename, const std::string &ssmFilename, bool externalResources)
Definition ComponentFMU3CS.cpp:791
oms::ComponentFMU3CS::fmuState
fmi3FMUState fmuState
Definition ComponentFMU3CS.h:166
oms::ComponentFMU3CS::fmuStateTime
double fmuStateTime
Definition ComponentFMU3CS.h:167
oms::ComponentFMU3CS::getInteger
oms_status_enu_t getInteger(const ComRef &cref, int &value)
Definition ComponentFMU3CS.cpp:1094
oms::ComponentFMU3CS::getAllVariables
std::vector< Variable > getAllVariables()
Definition ComponentFMU3CS.h:110
oms::ComponentFMU3CS::setExportName
oms_status_enu_t setExportName(const std::string &exportName)
Definition ComponentFMU3CS.cpp:630
oms::ComponentFMU3CS::initializeDependencyGraph_initialUnknowns
oms_status_enu_t initializeDependencyGraph_initialUnknowns()
Definition ComponentFMU3CS.cpp:477
oms::ComponentFMU3CS::exportVariables
std::vector< bool > exportVariables
Definition ComponentFMU3CS.h:158
oms::ComponentFMU3CS::inputs
std::vector< unsigned int > inputs
Definition ComponentFMU3CS.h:155
oms::ComponentFMU3CS::allVariables
std::vector< Variable > allVariables
Definition ComponentFMU3CS.h:152
oms::ComponentFMU3CS::exportToSSMTemplate
oms_status_enu_t exportToSSMTemplate(pugi::xml_node &ssmNode)
Definition ComponentFMU3CS.cpp:454
oms::ComponentFMU3CS::getFilteredUnitDefinitionsToSSD
void getFilteredUnitDefinitionsToSSD(std::map< std::string, std::map< std::string, std::string > > &unitDefinitions)
Definition ComponentFMU3CS.cpp:415
oms::ComponentFMU3CS::fmu
fmiHandle * fmu
Definition ComponentFMU3CS.h:149
oms::ComponentFMU3CS::setUnit
oms_status_enu_t setUnit(const ComRef &cref, const std::string &value)
Definition ComponentFMU3CS.cpp:1848
oms::ComponentFMU3CS::omsfmi3logger
fmi3LogMessageCallback omsfmi3logger
Definition ComponentFMU3CS.h:148
oms::ComponentFMU3CS::dumpInitialUnknowns
void dumpInitialUnknowns()
Definition ComponentFMU3CS.cpp:460
oms::ComponentFMU3CS::updateOrDeleteStartValueInReplacedComponent
oms_status_enu_t updateOrDeleteStartValueInReplacedComponent(std::vector< std::string > &warningList)
Definition ComponentFMU3CS.cpp:1927
oms::ComponentFMU3CS::getBoolean
oms_status_enu_t getBoolean(const ComRef &cref, bool &value)
Definition ComponentFMU3CS.cpp:932
oms::ComponentFMU3CS::registerSignalsForResultFile
oms_status_enu_t registerSignalsForResultFile(ResultWriter &resultFile)
Definition ComponentFMU3CS.cpp:1953
oms::ComponentFMU3CS::setReal
oms_status_enu_t setReal(const ComRef &cref, double value)
Definition ComponentFMU3CS.cpp:1719
oms::ComponentFMU3CS::reset
oms_status_enu_t reset()
Definition ComponentFMU3CS.cpp:876
oms::ComponentFMU3CS::getString
oms_status_enu_t getString(const ComRef &cref, std::string &value)
Definition ComponentFMU3CS.cpp:1311
oms::ComponentFMU3CS::getValidCref
oms::ComRef getValidCref(ComRef cref)
Definition ComponentFMU3CS.cpp:781
oms::ComponentFMU3CS::operator=
ComponentFMU3CS & operator=(ComponentFMU3CS const &copy)
not implemented
oms::ComponentFMU3CS::copyModelDescriptionUnit
void copyModelDescriptionUnit(Values &value)
oms::ComponentFMU3CS::getDirectionalDerivativeHeper
oms_status_enu_t getDirectionalDerivativeHeper(const int unknownIndex, const int knownindex, const std::vector< int > &dependencyList, double &value)
Definition ComponentFMU3CS.cpp:1480
oms::ComponentFMU3CS::deleteReferencesInSSD
oms_status_enu_t deleteReferencesInSSD(const std::string &filename)
Definition ComponentFMU3CS.cpp:833
oms::ComponentFMU3CS::freeState
oms_status_enu_t freeState()
Definition ComponentFMU3CS.cpp:2128
oms::ComponentFMU3CS::setFmuTime
oms_status_enu_t setFmuTime(double time)
Definition ComponentFMU3CS.h:108
oms::ComponentFMU3CS::getFMUInfo
const FMUInfo * getFMUInfo() const
Definition ComponentFMU3CS.h:65
oms::ComponentFMU3CS::exportToSSV
oms_status_enu_t exportToSSV(pugi::xml_node &ssvNode)
Definition ComponentFMU3CS.cpp:442
oms::ComponentFMU3CS::exportName
std::string exportName
export name for the component, used in the result file
Definition ComponentFMU3CS.h:159
oms::ComponentFMU3CS::instantiate
oms_status_enu_t instantiate()
Definition ComponentFMU3CS.cpp:643
oms::ComponentFMU3CS::initializeDependencyGraph_outputs
oms_status_enu_t initializeDependencyGraph_outputs()
Definition ComponentFMU3CS.cpp:580
oms::ComponentFMU3CS::terminate
oms_status_enu_t terminate()
Definition ComponentFMU3CS.cpp:864
oms::ComponentFMU3CS::exportToSSD
oms_status_enu_t exportToSSD(pugi::xml_node &node, Snapshot &snapshot, std::string variantName) const
Definition ComponentFMU3CS.cpp:391
oms::ComponentFMU3CS::setResourcesHelper1
oms_status_enu_t setResourcesHelper1(Values value)
Definition ComponentFMU3CS.cpp:700
oms::ComponentFMU3CS::ComponentFMU3CS
ComponentFMU3CS(ComponentFMU3CS const &copy)
not implemented
oms::ComponentFMU3CS::getReal
oms_status_enu_t getReal(const ComRef &cref, double &value)
Definition ComponentFMU3CS.cpp:1218
oms::ComponentFMU3CS::setResourcesHelper2
oms_status_enu_t setResourcesHelper2(Values value)
Definition ComponentFMU3CS.cpp:724
oms::ComponentFMU3CS::stepUntil
oms_status_enu_t stepUntil(double stopTime)
Definition ComponentFMU3CS.cpp:893
oms::ComponentFMU3CS::outputs
std::vector< unsigned int > outputs
Definition ComponentFMU3CS.h:156
oms::ComponentFMU3CS::saveState
oms_status_enu_t saveState()
Definition ComponentFMU3CS.cpp:2119
oms::ComponentFMU3CS::restoreState
oms_status_enu_t restoreState()
Definition ComponentFMU3CS.cpp:2140
oms::ComponentFMU3CS::updateSignals
oms_status_enu_t updateSignals(ResultWriter &resultWriter)
Definition ComponentFMU3CS.cpp:2025
oms::ComponentFMU3CS::getFilteredSignals
void getFilteredSignals(std::vector< Connector > &filteredSignals) const
Definition ComponentFMU3CS.cpp:2149
oms::ComponentFMU3CS::fmuInfo
FMUInfo fmuInfo
Definition ComponentFMU3CS.h:150
oms::ComponentFMU3CS::calculatedParameters
std::vector< unsigned int > calculatedParameters
Definition ComponentFMU3CS.h:153
oms::ComponentFMU3CS::parameters
std::vector< unsigned int > parameters
Definition ComponentFMU3CS.h:157
oms::ComponentFMU3CS::getVariable
Variable * getVariable(const ComRef &cref)
Definition ComponentFMU3CS.cpp:1174
oms::ComponentFMU3CS::setInteger
oms_status_enu_t setInteger(const ComRef &cref, int value)
Definition ComponentFMU3CS.cpp:1609
oms::ComponentFMU3CS::getExportName
std::string getExportName() const
Definition ComponentFMU3CS.h:131
oms::ComponentFMU3CS::removeSignalsFromResults
oms_status_enu_t removeSignalsFromResults(const char *regex)
Definition ComponentFMU3CS.cpp:2092
oms::ComponentFMU3CS::time
double time
Definition ComponentFMU3CS.h:165
oms::ComponentFMU3CS::initialize
oms_status_enu_t initialize()
Definition ComponentFMU3CS.cpp:849
oms::ComponentFMU3CS::deleteStartValue
oms_status_enu_t deleteStartValue(const ComRef &cref)
Definition ComponentFMU3CS.cpp:1889
oms::ComponentFMU3CS::getRealOutputDerivative
oms_status_enu_t getRealOutputDerivative(const ComRef &cref, SignalDerivative &der)
Definition ComponentFMU3CS.cpp:1508
oms::ComponentFMU3CS::setBoolean
oms_status_enu_t setBoolean(const ComRef &cref, bool value)
Definition ComponentFMU3CS.cpp:1558
oms::ComponentFMU3CS::exportToSSVTemplate
oms_status_enu_t exportToSSVTemplate(pugi::xml_node &ssvNode, Snapshot &snapshot)
Definition ComponentFMU3CS.cpp:447
oms::ComponentFMU3CS::setRealInputDerivative
oms_status_enu_t setRealInputDerivative(const ComRef &cref, const SignalDerivative &der)
Definition ComponentFMU3CS.cpp:1529
oms::ComponentFMU3CS::values
Values values
start values defined before instantiating the FMU and external inputs defined after initialization
Definition ComponentFMU3CS.h:161
oms::ComponentFMU3CS::getCanGetAndSetState
bool getCanGetAndSetState()
Definition ComponentFMU3CS.h:120
oms::ComponentFMU3CS::NewComponent
static Component * NewComponent(const ComRef &cref, System *parentSystem, const std::string &fmuPath, std::string replaceComponent="")
Definition ComponentFMU3CS.cpp:67
oms::ComponentFMU3CS::deleteResourcesInSSP
oms_status_enu_t deleteResourcesInSSP(const std::string &filename)
Definition ComponentFMU3CS.cpp:841
oms::ComponentFMU3CS::addSignalsToResults
oms_status_enu_t addSignalsToResults(const char *regex)
Definition ComponentFMU3CS.cpp:2065
oms::ComponentFMU3CS::setValuesResources
oms_status_enu_t setValuesResources(Values &values)
Definition ComponentFMU3CS.cpp:1914
oms::ComponentFMU3CS::derivatives
std::vector< unsigned int > derivatives
Definition ComponentFMU3CS.h:154
oms::ComponentFMU3CS::renameValues
oms_status_enu_t renameValues(const ComRef &oldCref, const ComRef &newCref)
Definition ComponentFMU3CS.cpp:2158
oms::ComponentFMU3CS::getFilteredEnumerationDefinitionsToSSD
void getFilteredEnumerationDefinitionsToSSD(std::map< std::string, std::map< std::string, std::string > > &enumerationDefinitions)
Definition ComponentFMU3CS.cpp:437
oms::ComponentFMU3CS::resultFileMapping
std::unordered_map< unsigned int, unsigned int > resultFileMapping
Definition ComponentFMU3CS.h:163
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::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
Definition AlgLoop.h:52