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-CurrentYear, 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 GPL VERSION 3 LICENSE OR
11 * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
12 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
13 * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
14 * ACCORDING TO RECIPIENTS CHOICE.
15 *
16 * The OpenModelica software and the Open Source Modelica
17 * Consortium (OSMC) Public License (OSMC-PL) are obtained
18 * from OSMC, either from the above address,
19 * from the URLs: http://www.ida.liu.se/projects/OpenModelica or
20 * http://www.openmodelica.org, and in the OpenModelica distribution.
21 * GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
22 *
23 * This program is distributed WITHOUT ANY WARRANTY; without
24 * even the implied warranty of MERCHANTABILITY or FITNESS
25 * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
26 * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
27 *
28 * See the full OSMC Public License conditions for more details.
29 *
30 */
31
32#ifndef _OMS_COMPONENT_FMU_ME_H_
33#define _OMS_COMPONENT_FMU_ME_H_
34
35#include "Component.h"
36#include "ComRef.h"
37#include "ResultWriter.h"
38#include "Snapshot.h"
39#include "Values.h"
40#include "Variable.h"
41
42#include <fmi4c.h>
43
44#include <map>
45#include <pugixml.hpp>
46#include <string>
47#include <unordered_map>
48#include <vector>
49
50 namespace oms
51{
52 class ComponentFMUME : public Component
53 {
54 public:
55 ~ComponentFMUME();
56
57 static Component* NewComponent(const oms::ComRef& cref, System* parentSystem, const std::string& fmuPath, std::string replaceComponent = "");
58 static Component* NewComponent(const pugi::xml_node& node, System* parentSystem, const std::string& sspVersion, const Snapshot& snapshot, std::string variantName);
59 const FMUInfo* getFMUInfo() const {return &(this->fmuInfo);}
60
61 oms_status_enu_t exportToSSD(pugi::xml_node& node, Snapshot& snapshot, std::string variantName) const;
62 oms_status_enu_t exportToSSV(pugi::xml_node& ssvNode);
63 void getFilteredUnitDefinitionsToSSD(std::map<std::string, std::map<std::string, std::string>>& unitDefinitions);
64 void getFilteredEnumerationDefinitionsToSSD(std::map<std::string, std::map<std::string, std::string>>& enumerationDefinitions);
65 oms_status_enu_t exportToSSVTemplate(pugi::xml_node& ssvNode, Snapshot& snapshot);
66 oms_status_enu_t exportToSSMTemplate(pugi::xml_node& ssmNode);
67 oms_status_enu_t instantiate();
68 oms_status_enu_t initialize();
69 oms_status_enu_t terminate();
70 oms_status_enu_t reset();
71
72 oms_status_enu_t initializeDependencyGraph_initialUnknowns();
73 oms_status_enu_t initializeDependencyGraph_outputs();
74
75 Variable* getVariable(const ComRef& cref);
76
77 Values& getValues() { return values; }
78 oms_status_enu_t setValuesResources(Values& values);
79
80 oms_status_enu_t getBoolean(const ComRef& cref, bool& value);
81 oms_status_enu_t getBoolean(const fmi2ValueReference& vr, bool& value);
82 oms_status_enu_t getInteger(const ComRef& cref, int& value);
83 oms_status_enu_t getInteger(const fmi2ValueReference& vr, int& value);
84 oms_status_enu_t getReal(const ComRef& cref, double& value);
85 oms_status_enu_t getReal(const fmi2ValueReference& vr, double& value);
86 oms_status_enu_t getString(const ComRef& cref, std::string& value);
87 oms_status_enu_t getString(const fmi2ValueReference& vr, std::string& value);
88 oms_status_enu_t setBoolean(const ComRef& cref, bool value);
89 oms_status_enu_t setInteger(const ComRef& cref, int value);
90 oms_status_enu_t setReal(const ComRef& cref, double value);
91 oms_status_enu_t setString(const ComRef& cref, const std::string& value);
92 oms_status_enu_t setUnit(const ComRef& cref, const std::string& value);
93 oms_status_enu_t setTime(double time);
94
95 oms_status_enu_t getDirectionalDerivative(const ComRef& unknownCref, const ComRef& knownCref, double& value);
96 oms_status_enu_t getDirectionalDerivativeHeper(const int unknownIndex, const int knownIndex, const std::vector<int>& dependencyList, double& value);
97
98 oms_status_enu_t deleteStartValue(const ComRef& cref);
99 oms_status_enu_t updateOrDeleteStartValueInReplacedComponent(std::vector<std::string>& warningList);
100
101 oms_status_enu_t registerSignalsForResultFile(ResultWriter& resultFile);
102 oms_status_enu_t updateSignals(ResultWriter& resultWriter);
103 oms_status_enu_t addSignalsToResults(const char* regex);
104 oms_status_enu_t removeSignalsFromResults(const char* regex);
105
106 oms_status_enu_t doEventIteration();
107
108 size_t getNumberOfContinuousStates() const {return derivatives.size();}
109 size_t getNumberOfEventIndicators() const {return nEventIndicators;}
110 oms_status_enu_t getContinuousStates(double* states);
111 oms_status_enu_t setContinuousStates(double* states);
112 oms_status_enu_t getDerivatives(double* derivatives);
113 oms_status_enu_t getNominalsOfContinuousStates(double* nominals);
114 oms_status_enu_t getEventindicators(double* eventindicators);
115
116 fmiHandle* getFMU() {return fmu;}
117 fmi2EventInfo* getEventInfo() {return &eventInfo;}
118
119 bool getCanGetAndSetState() {return getFMUInfo()->getCanGetAndSetFMUstate();}
120
121 void getFilteredSignals(std::vector<Connector>& filteredSignals) const;
122
123 oms_status_enu_t newResources(const std::string& ssvFilename, const std::string& ssmFilename, bool externalResources);
124 oms_status_enu_t setResourcesHelper1(Values value);
125 oms_status_enu_t setResourcesHelper2(Values value);
126 oms_status_enu_t setExportName(const std::string & exportName);
127 std::string getExportName() const { return this->exportName; }
128 oms_status_enu_t deleteReferencesInSSD(const std::string& filename);
129 oms_status_enu_t deleteResourcesInSSP(const std::string& filename);
130
131 protected:
132 ComponentFMUME(const ComRef& cref, System* parentSystem, const std::string& fmuPath);
133
134 // stop the compiler generating methods copying the object
135 ComponentFMUME(ComponentFMUME const& copy);
136 ComponentFMUME& operator=(ComponentFMUME const& copy);
137
138 oms_status_enu_t renameValues(const ComRef& oldCref, const ComRef& newCref);
139
140 void dumpInitialUnknowns();
141
142 private:
143 fmi2CallbackLogger omsfmi2logger;
144 fmiHandle *fmu = NULL;
145
146 fmi2EventInfo eventInfo;
147 size_t nEventIndicators;
148
149 FMUInfo fmuInfo;
150
151 std::vector<Variable> allVariables;
152 std::vector<unsigned int> calculatedParameters;
153 std::vector<unsigned int> derivatives;
154 std::vector<unsigned int> inputs;
155 std::vector<unsigned int> outputs;
156 std::vector<unsigned int> parameters;
157 std::vector<bool> exportVariables;
158 std::string exportName;
159
160 Values values;
161
162 std::unordered_map<unsigned int /*result file var ID*/, unsigned int /*allVariables ID*/> resultFileMapping;
163
164 oms::ComRef getValidCref(ComRef cref);
165 };
166}
167
168#endif
ComRef.h
Component.h
ResultWriter.h
Snapshot.h
Values.h
Variable.h
oms::ComRef
ComRef - component reference.
Definition ComRef.h:47
oms::ComponentFMUME
Definition ComponentFMUME.h:53
oms::ComponentFMUME::registerSignalsForResultFile
oms_status_enu_t registerSignalsForResultFile(ResultWriter &resultFile)
Definition ComponentFMUME.cpp:1765
oms::ComponentFMUME::deleteStartValue
oms_status_enu_t deleteStartValue(const ComRef &cref)
Definition ComponentFMUME.cpp:1546
oms::ComponentFMUME::~ComponentFMUME
~ComponentFMUME()
Definition ComponentFMUME.cpp:53
oms::ComponentFMUME::getEventInfo
fmi2EventInfo * getEventInfo()
Definition ComponentFMUME.h:117
oms::ComponentFMUME::deleteReferencesInSSD
oms_status_enu_t deleteReferencesInSSD(const std::string &filename)
Definition ComponentFMUME.cpp:871
oms::ComponentFMUME::getValidCref
oms::ComRef getValidCref(ComRef cref)
Definition ComponentFMUME.cpp:801
oms::ComponentFMUME::getDirectionalDerivativeHeper
oms_status_enu_t getDirectionalDerivativeHeper(const int unknownIndex, const int knownIndex, const std::vector< int > &dependencyList, double &value)
Definition ComponentFMUME.cpp:1415
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:1161
oms::ComponentFMUME::renameValues
oms_status_enu_t renameValues(const ComRef &oldCref, const ComRef &newCref)
Definition ComponentFMUME.cpp:1982
oms::ComponentFMUME::reset
oms_status_enu_t reset()
Definition ComponentFMUME.cpp:919
oms::ComponentFMUME::derivatives
std::vector< unsigned int > derivatives
Definition ComponentFMUME.h:153
oms::ComponentFMUME::setTime
oms_status_enu_t setTime(double time)
Definition ComponentFMUME.cpp:1047
oms::ComponentFMUME::parameters
std::vector< unsigned int > parameters
Definition ComponentFMUME.h:156
oms::ComponentFMUME::setExportName
oms_status_enu_t setExportName(const std::string &exportName)
Definition ComponentFMUME.cpp:397
oms::ComponentFMUME::getVariable
Variable * getVariable(const ComRef &cref)
Definition ComponentFMUME.cpp:1135
oms::ComponentFMUME::setBoolean
oms_status_enu_t setBoolean(const ComRef &cref, bool value)
Definition ComponentFMUME.cpp:1443
oms::ComponentFMUME::resultFileMapping
std::unordered_map< unsigned int, unsigned int > resultFileMapping
Definition ComponentFMUME.h:162
oms::ComponentFMUME::getContinuousStates
oms_status_enu_t getContinuousStates(double *states)
Definition ComponentFMUME.cpp:1874
oms::ComponentFMUME::setContinuousStates
oms_status_enu_t setContinuousStates(double *states)
Definition ComponentFMUME.cpp:1883
oms::ComponentFMUME::inputs
std::vector< unsigned int > inputs
Definition ComponentFMUME.h:154
oms::ComponentFMUME::getFilteredSignals
void getFilteredSignals(std::vector< Connector > &filteredSignals) const
Definition ComponentFMUME.cpp:1973
oms::ComponentFMUME::getValues
Values & getValues()
Definition ComponentFMUME.h:77
oms::ComponentFMUME::fmuInfo
FMUInfo fmuInfo
Definition ComponentFMUME.h:149
oms::ComponentFMUME::calculatedParameters
std::vector< unsigned int > calculatedParameters
Definition ComponentFMUME.h:152
oms::ComponentFMUME::getFMU
fmiHandle * getFMU()
Definition ComponentFMUME.h:116
oms::ComponentFMUME::terminate
oms_status_enu_t terminate()
Definition ComponentFMUME.cpp:908
oms::ComponentFMUME::addSignalsToResults
oms_status_enu_t addSignalsToResults(const char *regex)
Definition ComponentFMUME.cpp:1919
oms::ComponentFMUME::setInteger
oms_status_enu_t setInteger(const ComRef &cref, int value)
Definition ComponentFMUME.cpp:1495
oms::ComponentFMUME::values
Values values
start values defined before instantiating the FMU and external inputs defined after initialization
Definition ComponentFMUME.h:160
oms::ComponentFMUME::NewComponent
static Component * NewComponent(const oms::ComRef &cref, System *parentSystem, const std::string &fmuPath, std::string replaceComponent="")
Definition ComponentFMUME.cpp:61
oms::ComponentFMUME::getString
oms_status_enu_t getString(const ComRef &cref, std::string &value)
Definition ComponentFMUME.cpp:1253
oms::ComponentFMUME::removeSignalsFromResults
oms_status_enu_t removeSignalsFromResults(const char *regex)
Definition ComponentFMUME.cpp:1946
oms::ComponentFMUME::getFMUInfo
const FMUInfo * getFMUInfo() const
Definition ComponentFMUME.h:59
oms::ComponentFMUME::allVariables
std::vector< Variable > allVariables
Definition ComponentFMUME.h:151
oms::ComponentFMUME::getFilteredUnitDefinitionsToSSD
void getFilteredUnitDefinitionsToSSD(std::map< std::string, std::map< std::string, std::string > > &unitDefinitions)
Definition ComponentFMUME.cpp:410
oms::ComponentFMUME::fmu
fmiHandle * fmu
Definition ComponentFMUME.h:144
oms::ComponentFMUME::initialize
oms_status_enu_t initialize()
Definition ComponentFMUME.cpp:887
oms::ComponentFMUME::exportToSSMTemplate
oms_status_enu_t exportToSSMTemplate(pugi::xml_node &ssmNode)
Definition ComponentFMUME.cpp:449
oms::ComponentFMUME::initializeDependencyGraph_outputs
oms_status_enu_t initializeDependencyGraph_outputs()
Definition ComponentFMUME.cpp:575
oms::ComponentFMUME::deleteResourcesInSSP
oms_status_enu_t deleteResourcesInSSP(const std::string &filename)
Definition ComponentFMUME.cpp:879
oms::ComponentFMUME::initializeDependencyGraph_initialUnknowns
oms_status_enu_t initializeDependencyGraph_initialUnknowns()
Definition ComponentFMUME.cpp:472
oms::ComponentFMUME::getBoolean
oms_status_enu_t getBoolean(const ComRef &cref, bool &value)
Definition ComponentFMUME.cpp:957
oms::ComponentFMUME::getNumberOfContinuousStates
size_t getNumberOfContinuousStates() const
Definition ComponentFMUME.h:108
oms::ComponentFMUME::exportToSSVTemplate
oms_status_enu_t exportToSSVTemplate(pugi::xml_node &ssvNode, Snapshot &snapshot)
Definition ComponentFMUME.cpp:442
oms::ComponentFMUME::setResourcesHelper1
oms_status_enu_t setResourcesHelper1(Values value)
Definition ComponentFMUME.cpp:720
oms::ComponentFMUME::eventInfo
fmi2EventInfo eventInfo
Definition ComponentFMUME.h:146
oms::ComponentFMUME::nEventIndicators
size_t nEventIndicators
Definition ComponentFMUME.h:147
oms::ComponentFMUME::exportToSSD
oms_status_enu_t exportToSSD(pugi::xml_node &node, Snapshot &snapshot, std::string variantName) const
Definition ComponentFMUME.cpp:373
oms::ComponentFMUME::exportVariables
std::vector< bool > exportVariables
Definition ComponentFMUME.h:157
oms::ComponentFMUME::getInteger
oms_status_enu_t getInteger(const ComRef &cref, int &value)
Definition ComponentFMUME.cpp:1055
oms::ComponentFMUME::getFilteredEnumerationDefinitionsToSSD
void getFilteredEnumerationDefinitionsToSSD(std::map< std::string, std::map< std::string, std::string > > &enumerationDefinitions)
Definition ComponentFMUME.cpp:432
oms::ComponentFMUME::doEventIteration
oms_status_enu_t doEventIteration()
Definition ComponentFMUME.cpp:811
oms::ComponentFMUME::getNumberOfEventIndicators
size_t getNumberOfEventIndicators() const
Definition ComponentFMUME.h:109
oms::ComponentFMUME::exportName
std::string exportName
export name of the FMU, used for the result file
Definition ComponentFMUME.h:158
oms::ComponentFMUME::setValuesResources
oms_status_enu_t setValuesResources(Values &values)
Definition ComponentFMUME.cpp:1571
oms::ComponentFMUME::ComponentFMUME
ComponentFMUME(ComponentFMUME const &copy)
not implemented
oms::ComponentFMUME::instantiate
oms_status_enu_t instantiate()
Definition ComponentFMUME.cpp:655
oms::ComponentFMUME::getExportName
std::string getExportName() const
Definition ComponentFMUME.h:127
oms::ComponentFMUME::updateOrDeleteStartValueInReplacedComponent
oms_status_enu_t updateOrDeleteStartValueInReplacedComponent(std::vector< std::string > &warningList)
Definition ComponentFMUME.cpp:1584
oms::ComponentFMUME::exportToSSV
oms_status_enu_t exportToSSV(pugi::xml_node &ssvNode)
Definition ComponentFMUME.cpp:437
oms::ComponentFMUME::getCanGetAndSetState
bool getCanGetAndSetState()
Definition ComponentFMUME.h:119
oms::ComponentFMUME::omsfmi2logger
fmi2CallbackLogger omsfmi2logger
Definition ComponentFMUME.h:143
oms::ComponentFMUME::updateSignals
oms_status_enu_t updateSignals(ResultWriter &resultWriter)
Definition ComponentFMUME.cpp:1834
oms::ComponentFMUME::getNominalsOfContinuousStates
oms_status_enu_t getNominalsOfContinuousStates(double *nominals)
Definition ComponentFMUME.cpp:1901
oms::ComponentFMUME::getEventindicators
oms_status_enu_t getEventindicators(double *eventindicators)
Definition ComponentFMUME.cpp:1910
oms::ComponentFMUME::setReal
oms_status_enu_t setReal(const ComRef &cref, double value)
Definition ComponentFMUME.cpp:1610
oms::ComponentFMUME::dumpInitialUnknowns
void dumpInitialUnknowns()
Definition ComponentFMUME.cpp:455
oms::ComponentFMUME::newResources
oms_status_enu_t newResources(const std::string &ssvFilename, const std::string &ssmFilename, bool externalResources)
Definition ComponentFMUME.cpp:831
oms::ComponentFMUME::setString
oms_status_enu_t setString(const ComRef &cref, const std::string &value)
Definition ComponentFMUME.cpp:1668
oms::ComponentFMUME::getDirectionalDerivative
oms_status_enu_t getDirectionalDerivative(const ComRef &unknownCref, const ComRef &knownCref, double &value)
Definition ComponentFMUME.cpp:1333
oms::ComponentFMUME::setUnit
oms_status_enu_t setUnit(const ComRef &cref, const std::string &value)
Definition ComponentFMUME.cpp:1724
oms::ComponentFMUME::setResourcesHelper2
oms_status_enu_t setResourcesHelper2(Values value)
Definition ComponentFMUME.cpp:744
oms::ComponentFMUME::outputs
std::vector< unsigned int > outputs
Definition ComponentFMUME.h:155
oms::ComponentFMUME::getDerivatives
oms_status_enu_t getDerivatives(double *derivatives)
Definition ComponentFMUME.cpp:1892
oms::Component
Definition Component.h:60
oms::Component::cref
ComRef cref
Definition Component.h:154
oms::Component::parentSystem
System * parentSystem
Definition Component.h:153
oms::FMUInfo
FMU info.
Definition FMUInfo.h:45
oms::FMUInfo::getCanGetAndSetFMUstate
bool getCanGetAndSetFMUstate() const
Definition FMUInfo.h:56
oms::ResultWriter
Definition ResultWriter.h:69
oms::Snapshot
Definition Snapshot.h:47
oms::System
Definition System.h:62
oms::Values
Definition Values.h:46
oms::Variable
Definition Variable.h:46
oms
Definition AlgLoop.h:45