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

Loading...
Searching...
No Matches
ComponentFMUCS.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_CS_H_
37#define _OMS_COMPONENT_FMU_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 ComponentFMUCS : public Component
59 {
60 public:
61 ~ComponentFMUCS();
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 fmi2ValueReference& vr, bool& value);
90 oms_status_enu_t getInteger(const ComRef& cref, int& value);
91 oms_status_enu_t getInteger(const fmi2ValueReference& vr, int& value);
92 oms_status_enu_t getReal(const ComRef& cref, double& value);
93 oms_status_enu_t getReal(const fmi2ValueReference& vr, double& value);
94 oms_status_enu_t getString(const ComRef& cref, std::string& value);
95 oms_status_enu_t getString(const fmi2ValueReference& 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 oms_status_enu_t setExportName(const std::string & exportName);
115 std::string getExportName() const { return this->exportName; }
116 oms_status_enu_t registerSignalsForResultFile(ResultWriter& resultFile);
117 oms_status_enu_t updateSignals(ResultWriter& resultWriter);
118 oms_status_enu_t addSignalsToResults(const char* regex);
119 oms_status_enu_t removeSignalsFromResults(const char* regex);
120
121 bool getCanGetAndSetState() {return getFMUInfo()->getCanGetAndSetFMUstate();}
122 oms_status_enu_t saveState();
123 oms_status_enu_t freeState();
124 oms_status_enu_t restoreState();
125
126 void getFilteredSignals(std::vector<Connector>& filteredSignals) const;
127
128 oms_status_enu_t newResources(const std::string& ssvFilename, const std::string& ssmFilename, bool externalResources);
129 oms_status_enu_t setResourcesHelper1(Values value);
130 oms_status_enu_t setResourcesHelper2(Values value);
131
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 ComponentFMUCS(const ComRef& cref, System* parentSystem, const std::string& fmuPath);
138
139 // stop the compiler generating methods copying the object
140 ComponentFMUCS(ComponentFMUCS const& copy);
141 ComponentFMUCS& operator=(ComponentFMUCS const& copy);
142
143 oms_status_enu_t renameValues(const ComRef& oldCref, const ComRef& newCref);
144
145 void dumpInitialUnknowns();
146
147 private:
148 fmi2CallbackLogger omsfmi2logger;
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 Values values;
161
162 std::unordered_map<unsigned int /*result file var ID*/, unsigned int /*allVariables ID*/> resultFileMapping;
163
164 double time;
165
166 fmi2FMUstate 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::ComponentFMUCS
Definition ComponentFMUCS.h:59
oms::ComponentFMUCS::updateOrDeleteStartValueInReplacedComponent
oms_status_enu_t updateOrDeleteStartValueInReplacedComponent(std::vector< std::string > &warningList)
Definition ComponentFMUCS.cpp:1748
oms::ComponentFMUCS::exportVariables
std::vector< bool > exportVariables
Definition ComponentFMUCS.h:158
oms::ComponentFMUCS::calculatedParameters
std::vector< unsigned int > calculatedParameters
Definition ComponentFMUCS.h:153
oms::ComponentFMUCS::updateSignals
oms_status_enu_t updateSignals(ResultWriter &resultWriter)
Definition ComponentFMUCS.cpp:1846
oms::ComponentFMUCS::getInteger
oms_status_enu_t getInteger(const ComRef &cref, int &value)
Definition ComponentFMUCS.cpp:1008
oms::ComponentFMUCS::fmuInfo
FMUInfo fmuInfo
Definition ComponentFMUCS.h:150
oms::ComponentFMUCS::exportToSSD
oms_status_enu_t exportToSSD(pugi::xml_node &node, Snapshot &snapshot, std::string variantName) const
Definition ComponentFMUCS.cpp:377
oms::ComponentFMUCS::registerSignalsForResultFile
oms_status_enu_t registerSignalsForResultFile(ResultWriter &resultFile)
Definition ComponentFMUCS.cpp:1774
oms::ComponentFMUCS::derivatives
std::vector< unsigned int > derivatives
Definition ComponentFMUCS.h:154
oms::ComponentFMUCS::getCanGetAndSetState
bool getCanGetAndSetState()
Definition ComponentFMUCS.h:121
oms::ComponentFMUCS::exportToSSVTemplate
oms_status_enu_t exportToSSVTemplate(pugi::xml_node &ssvNode, Snapshot &snapshot)
Definition ComponentFMUCS.cpp:446
oms::ComponentFMUCS::saveState
oms_status_enu_t saveState()
Definition ComponentFMUCS.cpp:1940
oms::ComponentFMUCS::setFmuTime
oms_status_enu_t setFmuTime(double time)
Definition ComponentFMUCS.h:108
oms::ComponentFMUCS::allVariables
std::vector< Variable > allVariables
Definition ComponentFMUCS.h:152
oms::ComponentFMUCS::getBoolean
oms_status_enu_t getBoolean(const ComRef &cref, bool &value)
Definition ComponentFMUCS.cpp:918
oms::ComponentFMUCS::setInteger
oms_status_enu_t setInteger(const ComRef &cref, int value)
Definition ComponentFMUCS.cpp:1505
oms::ComponentFMUCS::getFilteredSignals
void getFilteredSignals(std::vector< Connector > &filteredSignals) const
Definition ComponentFMUCS.cpp:1970
oms::ComponentFMUCS::getFMU
fmiHandle * getFMU()
Definition ComponentFMUCS.h:109
oms::ComponentFMUCS::removeSignalsFromResults
oms_status_enu_t removeSignalsFromResults(const char *regex)
Definition ComponentFMUCS.cpp:1913
oms::ComponentFMUCS::getAllVariables
std::vector< Variable > getAllVariables()
Definition ComponentFMUCS.h:110
oms::ComponentFMUCS::getReal
oms_status_enu_t getReal(const ComRef &cref, double &value)
Definition ComponentFMUCS.cpp:1114
oms::ComponentFMUCS::fmuState
fmi2FMUstate fmuState
Definition ComponentFMUCS.h:166
oms::ComponentFMUCS::renameValues
oms_status_enu_t renameValues(const ComRef &oldCref, const ComRef &newCref)
Definition ComponentFMUCS.cpp:1979
oms::ComponentFMUCS::getVariable
Variable * getVariable(const ComRef &cref)
Definition ComponentFMUCS.cpp:1088
oms::ComponentFMUCS::addSignalsToResults
oms_status_enu_t addSignalsToResults(const char *regex)
Definition ComponentFMUCS.cpp:1886
oms::ComponentFMUCS::operator=
ComponentFMUCS & operator=(ComponentFMUCS const &copy)
not implemented
oms::ComponentFMUCS::deleteStartValue
oms_status_enu_t deleteStartValue(const ComRef &cref)
Definition ComponentFMUCS.cpp:1710
oms::ComponentFMUCS::omsfmi2logger
fmi2CallbackLogger omsfmi2logger
Definition ComponentFMUCS.h:148
oms::ComponentFMUCS::setReal
oms_status_enu_t setReal(const ComRef &cref, double value)
Definition ComponentFMUCS.cpp:1556
oms::ComponentFMUCS::copyModelDescriptionUnit
void copyModelDescriptionUnit(Values &value)
oms::ComponentFMUCS::time
double time
Definition ComponentFMUCS.h:164
oms::ComponentFMUCS::setResourcesHelper2
oms_status_enu_t setResourcesHelper2(Values value)
Definition ComponentFMUCS.cpp:712
oms::ComponentFMUCS::initialize
oms_status_enu_t initialize()
Definition ComponentFMUCS.cpp:837
oms::ComponentFMUCS::exportToSSMTemplate
oms_status_enu_t exportToSSMTemplate(pugi::xml_node &ssmNode)
Definition ComponentFMUCS.cpp:453
oms::ComponentFMUCS::setExportName
oms_status_enu_t setExportName(const std::string &exportName)
Definition ComponentFMUCS.cpp:401
oms::ComponentFMUCS::parameters
std::vector< unsigned int > parameters
Definition ComponentFMUCS.h:157
oms::ComponentFMUCS::getFilteredUnitDefinitionsToSSD
void getFilteredUnitDefinitionsToSSD(std::map< std::string, std::map< std::string, std::string > > &unitDefinitions)
Definition ComponentFMUCS.cpp:414
oms::ComponentFMUCS::getFMUInfo
const FMUInfo * getFMUInfo() const
Definition ComponentFMUCS.h:65
oms::ComponentFMUCS::setString
oms_status_enu_t setString(const ComRef &cref, const std::string &value)
Definition ComponentFMUCS.cpp:1614
oms::ComponentFMUCS::setRealInputDerivative
oms_status_enu_t setRealInputDerivative(const ComRef &cref, const SignalDerivative &der)
Definition ComponentFMUCS.cpp:1425
oms::ComponentFMUCS::values
Values values
start values defined before instantiating the FMU and external inputs defined after initialization
Definition ComponentFMUCS.h:160
oms::ComponentFMUCS::restoreState
oms_status_enu_t restoreState()
Definition ComponentFMUCS.cpp:1961
oms::ComponentFMUCS::getExportName
std::string getExportName() const
Definition ComponentFMUCS.h:115
oms::ComponentFMUCS::getDirectionalDerivativeHeper
oms_status_enu_t getDirectionalDerivativeHeper(const int unknownIndex, const int knownindex, const std::vector< int > &dependencyList, double &value)
Definition ComponentFMUCS.cpp:1376
oms::ComponentFMUCS::outputs
std::vector< unsigned int > outputs
Definition ComponentFMUCS.h:156
oms::ComponentFMUCS::newResources
oms_status_enu_t newResources(const std::string &ssvFilename, const std::string &ssmFilename, bool externalResources)
Definition ComponentFMUCS.cpp:779
oms::ComponentFMUCS::setValuesResources
oms_status_enu_t setValuesResources(Values &values)
Definition ComponentFMUCS.cpp:1735
oms::ComponentFMUCS::~ComponentFMUCS
~ComponentFMUCS()
Definition ComponentFMUCS.cpp:59
oms::ComponentFMUCS::reset
oms_status_enu_t reset()
Definition ComponentFMUCS.cpp:862
oms::ComponentFMUCS::ComponentFMUCS
ComponentFMUCS(ComponentFMUCS const &copy)
not implemented
oms::ComponentFMUCS::terminate
oms_status_enu_t terminate()
Definition ComponentFMUCS.cpp:850
oms::ComponentFMUCS::exportName
std::string exportName
export name for the component, used in the result file
Definition ComponentFMUCS.h:159
oms::ComponentFMUCS::getValidCref
oms::ComRef getValidCref(ComRef cref)
Definition ComponentFMUCS.cpp:769
oms::ComponentFMUCS::setUnit
oms_status_enu_t setUnit(const ComRef &cref, const std::string &value)
Definition ComponentFMUCS.cpp:1669
oms::ComponentFMUCS::getFilteredEnumerationDefinitionsToSSD
void getFilteredEnumerationDefinitionsToSSD(std::map< std::string, std::map< std::string, std::string > > &enumerationDefinitions)
Definition ComponentFMUCS.cpp:436
oms::ComponentFMUCS::deleteResourcesInSSP
oms_status_enu_t deleteResourcesInSSP(const std::string &filename)
Definition ComponentFMUCS.cpp:829
oms::ComponentFMUCS::getDirectionalDerivative
oms_status_enu_t getDirectionalDerivative(const ComRef &unknownCref, const ComRef &knownCref, double &value)
Definition ComponentFMUCS.cpp:1287
oms::ComponentFMUCS::fmu
fmiHandle * fmu
Definition ComponentFMUCS.h:149
oms::ComponentFMUCS::getString
oms_status_enu_t getString(const ComRef &cref, std::string &value)
Definition ComponentFMUCS.cpp:1207
oms::ComponentFMUCS::exportToSSV
oms_status_enu_t exportToSSV(pugi::xml_node &ssvNode)
Definition ComponentFMUCS.cpp:441
oms::ComponentFMUCS::initializeDependencyGraph_initialUnknowns
oms_status_enu_t initializeDependencyGraph_initialUnknowns()
Definition ComponentFMUCS.cpp:476
oms::ComponentFMUCS::NewComponent
static Component * NewComponent(const ComRef &cref, System *parentSystem, const std::string &fmuPath, std::string replaceComponent="")
Definition ComponentFMUCS.cpp:67
oms::ComponentFMUCS::deleteReferencesInSSD
oms_status_enu_t deleteReferencesInSSD(const std::string &filename)
Definition ComponentFMUCS.cpp:821
oms::ComponentFMUCS::getValues
Values & getValues()
Definition ComponentFMUCS.h:85
oms::ComponentFMUCS::initializeDependencyGraph_outputs
oms_status_enu_t initializeDependencyGraph_outputs()
Definition ComponentFMUCS.cpp:579
oms::ComponentFMUCS::inputs
std::vector< unsigned int > inputs
Definition ComponentFMUCS.h:155
oms::ComponentFMUCS::dumpInitialUnknowns
void dumpInitialUnknowns()
Definition ComponentFMUCS.cpp:459
oms::ComponentFMUCS::instantiate
oms_status_enu_t instantiate()
Definition ComponentFMUCS.cpp:629
oms::ComponentFMUCS::getRealOutputDerivative
oms_status_enu_t getRealOutputDerivative(const ComRef &cref, SignalDerivative &der)
Definition ComponentFMUCS.cpp:1404
oms::ComponentFMUCS::fmuStateTime
double fmuStateTime
Definition ComponentFMUCS.h:167
oms::ComponentFMUCS::resultFileMapping
std::unordered_map< unsigned int, unsigned int > resultFileMapping
Definition ComponentFMUCS.h:162
oms::ComponentFMUCS::setResourcesHelper1
oms_status_enu_t setResourcesHelper1(Values value)
Definition ComponentFMUCS.cpp:688
oms::ComponentFMUCS::setBoolean
oms_status_enu_t setBoolean(const ComRef &cref, bool value)
Definition ComponentFMUCS.cpp:1454
oms::ComponentFMUCS::freeState
oms_status_enu_t freeState()
Definition ComponentFMUCS.cpp:1949
oms::ComponentFMUCS::stepUntil
oms_status_enu_t stepUntil(double stopTime)
Definition ComponentFMUCS.cpp:881
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