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-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_CS_H_
33#define _OMS_COMPONENT_FMU_CS_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#include <map>
44#include <pugixml.hpp>
45#include <string>
46#include <unordered_map>
47#include <vector>
48#include <cmath>
49
50 namespace oms
51{
52 class System;
53
54 class ComponentFMUCS : public Component
55 {
56 public:
57 ~ComponentFMUCS();
58
59 static Component* NewComponent(const ComRef& cref, System* parentSystem, const std::string& fmuPath, std::string replaceComponent = "");
60 static Component* NewComponent(const pugi::xml_node& node, System* parentSystem, const std::string& sspVersion, const Snapshot& snapshot, std::string variantName);
61 const FMUInfo* getFMUInfo() const {return &(this->fmuInfo);}
62
63 oms_status_enu_t exportToSSD(pugi::xml_node& node, Snapshot& snapshot, std::string variantName) const;
64 oms_status_enu_t exportToSSV(pugi::xml_node& ssvNode);
65 void getFilteredUnitDefinitionsToSSD(std::map<std::string, std::map<std::string, std::string>>& unitDefinitions);
66 void getFilteredEnumerationDefinitionsToSSD(std::map<std::string, std::map<std::string, std::string>>& enumerationDefinitions);
67 oms_status_enu_t exportToSSVTemplate(pugi::xml_node& ssvNode, Snapshot& snapshot);
68 oms_status_enu_t exportToSSMTemplate(pugi::xml_node& ssmNode);
69 oms_status_enu_t instantiate();
70 oms_status_enu_t initialize();
71 oms_status_enu_t terminate();
72 oms_status_enu_t reset();
73
74 oms_status_enu_t stepUntil(double stopTime);
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
98 oms_status_enu_t getDirectionalDerivative(const ComRef& unknownCref, const ComRef& knownCref, double& value);
99 oms_status_enu_t getDirectionalDerivativeHeper(const int unknownIndex, const int knownindex, const std::vector<int>& dependencyList, double& value);
100
101 oms_status_enu_t deleteStartValue(const ComRef& cref);
102 oms_status_enu_t updateOrDeleteStartValueInReplacedComponent(std::vector<std::string>& warningList);
103
104 oms_status_enu_t setFmuTime(double time) {this->time = time; return oms_status_ok;}
105 fmiHandle* getFMU() {return fmu;}
106 std::vector<Variable> getAllVariables() {return allVariables;}
107
108 oms_status_enu_t getRealOutputDerivative(const ComRef& cref, SignalDerivative& der);
109 oms_status_enu_t setRealInputDerivative(const ComRef& cref, const SignalDerivative& der);
110 oms_status_enu_t setExportName(const std::string & exportName);
111 std::string getExportName() const { return this->exportName; }
112 oms_status_enu_t registerSignalsForResultFile(ResultWriter& resultFile);
113 oms_status_enu_t updateSignals(ResultWriter& resultWriter);
114 oms_status_enu_t addSignalsToResults(const char* regex);
115 oms_status_enu_t removeSignalsFromResults(const char* regex);
116
117 bool getCanGetAndSetState() {return getFMUInfo()->getCanGetAndSetFMUstate();}
118 oms_status_enu_t saveState();
119 oms_status_enu_t freeState();
120 oms_status_enu_t restoreState();
121
122 void getFilteredSignals(std::vector<Connector>& filteredSignals) const;
123
124 oms_status_enu_t newResources(const std::string& ssvFilename, const std::string& ssmFilename, bool externalResources);
125 oms_status_enu_t setResourcesHelper1(Values value);
126 oms_status_enu_t setResourcesHelper2(Values value);
127
128 oms_status_enu_t deleteReferencesInSSD(const std::string& filename);
129 oms_status_enu_t deleteResourcesInSSP(const std::string& filename);
130 void copyModelDescriptionUnit(Values& value);
131
132 protected:
133 ComponentFMUCS(const ComRef& cref, System* parentSystem, const std::string& fmuPath);
134
135 // stop the compiler generating methods copying the object
136 ComponentFMUCS(ComponentFMUCS const& copy);
137 ComponentFMUCS& operator=(ComponentFMUCS const& copy);
138
139 oms_status_enu_t renameValues(const ComRef& oldCref, const ComRef& newCref);
140
141 void dumpInitialUnknowns();
142
143 private:
144 fmi2CallbackLogger omsfmi2logger;
145 fmiHandle *fmu = NULL;
146 FMUInfo fmuInfo;
147
148 std::vector<Variable> allVariables;
149 std::vector<unsigned int> calculatedParameters;
150 std::vector<unsigned int> derivatives;
151 std::vector<unsigned int> inputs;
152 std::vector<unsigned int> outputs;
153 std::vector<unsigned int> parameters;
154 std::vector<bool> exportVariables;
155 std::string exportName;
156 Values values;
157
158 std::unordered_map<unsigned int /*result file var ID*/, unsigned int /*allVariables ID*/> resultFileMapping;
159
160 double time;
161
162 fmi2FMUstate fmuState = NULL;
163 double fmuStateTime;
164
165 oms::ComRef getValidCref(ComRef cref);
166 };
167}
168
169#endif
ComRef.h
Component.h
ResultWriter.h
Snapshot.h
Values.h
Variable.h
oms::ComRef
ComRef - component reference.
Definition ComRef.h:47
oms::ComponentFMUCS
Definition ComponentFMUCS.h:55
oms::ComponentFMUCS::updateOrDeleteStartValueInReplacedComponent
oms_status_enu_t updateOrDeleteStartValueInReplacedComponent(std::vector< std::string > &warningList)
Definition ComponentFMUCS.cpp:1744
oms::ComponentFMUCS::exportVariables
std::vector< bool > exportVariables
Definition ComponentFMUCS.h:154
oms::ComponentFMUCS::calculatedParameters
std::vector< unsigned int > calculatedParameters
Definition ComponentFMUCS.h:149
oms::ComponentFMUCS::updateSignals
oms_status_enu_t updateSignals(ResultWriter &resultWriter)
Definition ComponentFMUCS.cpp:1838
oms::ComponentFMUCS::getInteger
oms_status_enu_t getInteger(const ComRef &cref, int &value)
Definition ComponentFMUCS.cpp:1004
oms::ComponentFMUCS::fmuInfo
FMUInfo fmuInfo
Definition ComponentFMUCS.h:146
oms::ComponentFMUCS::exportToSSD
oms_status_enu_t exportToSSD(pugi::xml_node &node, Snapshot &snapshot, std::string variantName) const
Definition ComponentFMUCS.cpp:373
oms::ComponentFMUCS::registerSignalsForResultFile
oms_status_enu_t registerSignalsForResultFile(ResultWriter &resultFile)
Definition ComponentFMUCS.cpp:1770
oms::ComponentFMUCS::derivatives
std::vector< unsigned int > derivatives
Definition ComponentFMUCS.h:150
oms::ComponentFMUCS::getCanGetAndSetState
bool getCanGetAndSetState()
Definition ComponentFMUCS.h:117
oms::ComponentFMUCS::exportToSSVTemplate
oms_status_enu_t exportToSSVTemplate(pugi::xml_node &ssvNode, Snapshot &snapshot)
Definition ComponentFMUCS.cpp:442
oms::ComponentFMUCS::saveState
oms_status_enu_t saveState()
Definition ComponentFMUCS.cpp:1932
oms::ComponentFMUCS::setFmuTime
oms_status_enu_t setFmuTime(double time)
Definition ComponentFMUCS.h:104
oms::ComponentFMUCS::allVariables
std::vector< Variable > allVariables
Definition ComponentFMUCS.h:148
oms::ComponentFMUCS::getBoolean
oms_status_enu_t getBoolean(const ComRef &cref, bool &value)
Definition ComponentFMUCS.cpp:914
oms::ComponentFMUCS::setInteger
oms_status_enu_t setInteger(const ComRef &cref, int value)
Definition ComponentFMUCS.cpp:1501
oms::ComponentFMUCS::getFilteredSignals
void getFilteredSignals(std::vector< Connector > &filteredSignals) const
Definition ComponentFMUCS.cpp:1962
oms::ComponentFMUCS::getFMU
fmiHandle * getFMU()
Definition ComponentFMUCS.h:105
oms::ComponentFMUCS::removeSignalsFromResults
oms_status_enu_t removeSignalsFromResults(const char *regex)
Definition ComponentFMUCS.cpp:1905
oms::ComponentFMUCS::getAllVariables
std::vector< Variable > getAllVariables()
Definition ComponentFMUCS.h:106
oms::ComponentFMUCS::getReal
oms_status_enu_t getReal(const ComRef &cref, double &value)
Definition ComponentFMUCS.cpp:1110
oms::ComponentFMUCS::fmuState
fmi2FMUstate fmuState
Definition ComponentFMUCS.h:162
oms::ComponentFMUCS::renameValues
oms_status_enu_t renameValues(const ComRef &oldCref, const ComRef &newCref)
Definition ComponentFMUCS.cpp:1971
oms::ComponentFMUCS::getVariable
Variable * getVariable(const ComRef &cref)
Definition ComponentFMUCS.cpp:1084
oms::ComponentFMUCS::addSignalsToResults
oms_status_enu_t addSignalsToResults(const char *regex)
Definition ComponentFMUCS.cpp:1878
oms::ComponentFMUCS::operator=
ComponentFMUCS & operator=(ComponentFMUCS const &copy)
not implemented
oms::ComponentFMUCS::deleteStartValue
oms_status_enu_t deleteStartValue(const ComRef &cref)
Definition ComponentFMUCS.cpp:1706
oms::ComponentFMUCS::omsfmi2logger
fmi2CallbackLogger omsfmi2logger
Definition ComponentFMUCS.h:144
oms::ComponentFMUCS::setReal
oms_status_enu_t setReal(const ComRef &cref, double value)
Definition ComponentFMUCS.cpp:1552
oms::ComponentFMUCS::copyModelDescriptionUnit
void copyModelDescriptionUnit(Values &value)
oms::ComponentFMUCS::time
double time
Definition ComponentFMUCS.h:160
oms::ComponentFMUCS::setResourcesHelper2
oms_status_enu_t setResourcesHelper2(Values value)
Definition ComponentFMUCS.cpp:708
oms::ComponentFMUCS::initialize
oms_status_enu_t initialize()
Definition ComponentFMUCS.cpp:833
oms::ComponentFMUCS::exportToSSMTemplate
oms_status_enu_t exportToSSMTemplate(pugi::xml_node &ssmNode)
Definition ComponentFMUCS.cpp:449
oms::ComponentFMUCS::setExportName
oms_status_enu_t setExportName(const std::string &exportName)
Definition ComponentFMUCS.cpp:397
oms::ComponentFMUCS::parameters
std::vector< unsigned int > parameters
Definition ComponentFMUCS.h:153
oms::ComponentFMUCS::getFilteredUnitDefinitionsToSSD
void getFilteredUnitDefinitionsToSSD(std::map< std::string, std::map< std::string, std::string > > &unitDefinitions)
Definition ComponentFMUCS.cpp:410
oms::ComponentFMUCS::getFMUInfo
const FMUInfo * getFMUInfo() const
Definition ComponentFMUCS.h:61
oms::ComponentFMUCS::setString
oms_status_enu_t setString(const ComRef &cref, const std::string &value)
Definition ComponentFMUCS.cpp:1610
oms::ComponentFMUCS::setRealInputDerivative
oms_status_enu_t setRealInputDerivative(const ComRef &cref, const SignalDerivative &der)
Definition ComponentFMUCS.cpp:1421
oms::ComponentFMUCS::values
Values values
start values defined before instantiating the FMU and external inputs defined after initialization
Definition ComponentFMUCS.h:156
oms::ComponentFMUCS::restoreState
oms_status_enu_t restoreState()
Definition ComponentFMUCS.cpp:1953
oms::ComponentFMUCS::getExportName
std::string getExportName() const
Definition ComponentFMUCS.h:111
oms::ComponentFMUCS::getDirectionalDerivativeHeper
oms_status_enu_t getDirectionalDerivativeHeper(const int unknownIndex, const int knownindex, const std::vector< int > &dependencyList, double &value)
Definition ComponentFMUCS.cpp:1372
oms::ComponentFMUCS::outputs
std::vector< unsigned int > outputs
Definition ComponentFMUCS.h:152
oms::ComponentFMUCS::newResources
oms_status_enu_t newResources(const std::string &ssvFilename, const std::string &ssmFilename, bool externalResources)
Definition ComponentFMUCS.cpp:775
oms::ComponentFMUCS::setValuesResources
oms_status_enu_t setValuesResources(Values &values)
Definition ComponentFMUCS.cpp:1731
oms::ComponentFMUCS::~ComponentFMUCS
~ComponentFMUCS()
Definition ComponentFMUCS.cpp:55
oms::ComponentFMUCS::reset
oms_status_enu_t reset()
Definition ComponentFMUCS.cpp:858
oms::ComponentFMUCS::ComponentFMUCS
ComponentFMUCS(ComponentFMUCS const &copy)
not implemented
oms::ComponentFMUCS::terminate
oms_status_enu_t terminate()
Definition ComponentFMUCS.cpp:846
oms::ComponentFMUCS::exportName
std::string exportName
export name for the component, used in the result file
Definition ComponentFMUCS.h:155
oms::ComponentFMUCS::getValidCref
oms::ComRef getValidCref(ComRef cref)
Definition ComponentFMUCS.cpp:765
oms::ComponentFMUCS::setUnit
oms_status_enu_t setUnit(const ComRef &cref, const std::string &value)
Definition ComponentFMUCS.cpp:1665
oms::ComponentFMUCS::getFilteredEnumerationDefinitionsToSSD
void getFilteredEnumerationDefinitionsToSSD(std::map< std::string, std::map< std::string, std::string > > &enumerationDefinitions)
Definition ComponentFMUCS.cpp:432
oms::ComponentFMUCS::deleteResourcesInSSP
oms_status_enu_t deleteResourcesInSSP(const std::string &filename)
Definition ComponentFMUCS.cpp:825
oms::ComponentFMUCS::getDirectionalDerivative
oms_status_enu_t getDirectionalDerivative(const ComRef &unknownCref, const ComRef &knownCref, double &value)
Definition ComponentFMUCS.cpp:1283
oms::ComponentFMUCS::fmu
fmiHandle * fmu
Definition ComponentFMUCS.h:145
oms::ComponentFMUCS::getString
oms_status_enu_t getString(const ComRef &cref, std::string &value)
Definition ComponentFMUCS.cpp:1203
oms::ComponentFMUCS::exportToSSV
oms_status_enu_t exportToSSV(pugi::xml_node &ssvNode)
Definition ComponentFMUCS.cpp:437
oms::ComponentFMUCS::initializeDependencyGraph_initialUnknowns
oms_status_enu_t initializeDependencyGraph_initialUnknowns()
Definition ComponentFMUCS.cpp:472
oms::ComponentFMUCS::NewComponent
static Component * NewComponent(const ComRef &cref, System *parentSystem, const std::string &fmuPath, std::string replaceComponent="")
Definition ComponentFMUCS.cpp:63
oms::ComponentFMUCS::deleteReferencesInSSD
oms_status_enu_t deleteReferencesInSSD(const std::string &filename)
Definition ComponentFMUCS.cpp:817
oms::ComponentFMUCS::getValues
Values & getValues()
Definition ComponentFMUCS.h:81
oms::ComponentFMUCS::initializeDependencyGraph_outputs
oms_status_enu_t initializeDependencyGraph_outputs()
Definition ComponentFMUCS.cpp:575
oms::ComponentFMUCS::inputs
std::vector< unsigned int > inputs
Definition ComponentFMUCS.h:151
oms::ComponentFMUCS::dumpInitialUnknowns
void dumpInitialUnknowns()
Definition ComponentFMUCS.cpp:455
oms::ComponentFMUCS::instantiate
oms_status_enu_t instantiate()
Definition ComponentFMUCS.cpp:625
oms::ComponentFMUCS::getRealOutputDerivative
oms_status_enu_t getRealOutputDerivative(const ComRef &cref, SignalDerivative &der)
Definition ComponentFMUCS.cpp:1400
oms::ComponentFMUCS::fmuStateTime
double fmuStateTime
Definition ComponentFMUCS.h:163
oms::ComponentFMUCS::resultFileMapping
std::unordered_map< unsigned int, unsigned int > resultFileMapping
Definition ComponentFMUCS.h:158
oms::ComponentFMUCS::setResourcesHelper1
oms_status_enu_t setResourcesHelper1(Values value)
Definition ComponentFMUCS.cpp:684
oms::ComponentFMUCS::setBoolean
oms_status_enu_t setBoolean(const ComRef &cref, bool value)
Definition ComponentFMUCS.cpp:1450
oms::ComponentFMUCS::freeState
oms_status_enu_t freeState()
Definition ComponentFMUCS.cpp:1941
oms::ComponentFMUCS::stepUntil
oms_status_enu_t stepUntil(double stopTime)
Definition ComponentFMUCS.cpp:877
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::SignalDerivative
Definition SignalDerivative.h:42
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