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-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_3_CS_H_
33#define _OMS_COMPONENT_FMU_3_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 ComponentFMU3CS : public Component
55 {
56 public:
57 ~ComponentFMU3CS();
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 fmi3ValueReference& vr, bool& value);
86 oms_status_enu_t getInteger(const ComRef& cref, int& value);
87 oms_status_enu_t getInteger(const fmi3ValueReference& 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 fmi3ValueReference& 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 fmi3ValueReference& 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
111 oms_status_enu_t registerSignalsForResultFile(ResultWriter& resultFile);
112 oms_status_enu_t updateSignals(ResultWriter& resultWriter);
113 oms_status_enu_t addSignalsToResults(const char* regex);
114 oms_status_enu_t removeSignalsFromResults(const char* regex);
115
116 bool getCanGetAndSetState() {return getFMUInfo()->getCanGetAndSetFMUstate();}
117 oms_status_enu_t saveState();
118 oms_status_enu_t freeState();
119 oms_status_enu_t restoreState();
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 void copyModelDescriptionUnit(Values& value);
131
132 protected:
133 ComponentFMU3CS(const ComRef& cref, System* parentSystem, const std::string& fmuPath);
134
135 // stop the compiler generating methods copying the object
136 ComponentFMU3CS(ComponentFMU3CS const& copy);
137 ComponentFMU3CS& operator=(ComponentFMU3CS const& copy);
138
139 oms_status_enu_t renameValues(const ComRef& oldCref, const ComRef& newCref);
140
141 void dumpInitialUnknowns();
142
143 private:
144 fmi3LogMessageCallback omsfmi3logger;
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
157 Values values;
158
159 std::unordered_map<unsigned int /*result file var ID*/, unsigned int /*allVariables ID*/> resultFileMapping;
160
161 double time;
162 fmi3FMUState 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::ComponentFMU3CS
Definition ComponentFMU3CS.h:55
oms::ComponentFMU3CS::~ComponentFMU3CS
~ComponentFMU3CS()
Definition ComponentFMU3CS.cpp:55
oms::ComponentFMU3CS::getFMU
fmiHandle * getFMU()
Definition ComponentFMU3CS.h:105
oms::ComponentFMU3CS::getDirectionalDerivative
oms_status_enu_t getDirectionalDerivative(const ComRef &unknownCref, const ComRef &knownCref, double &value)
Definition ComponentFMU3CS.cpp:1372
oms::ComponentFMU3CS::getValues
Values & getValues()
Definition ComponentFMU3CS.h:81
oms::ComponentFMU3CS::setString
oms_status_enu_t setString(const ComRef &cref, const std::string &value)
Definition ComponentFMU3CS.cpp:1782
oms::ComponentFMU3CS::newResources
oms_status_enu_t newResources(const std::string &ssvFilename, const std::string &ssmFilename, bool externalResources)
Definition ComponentFMU3CS.cpp:775
oms::ComponentFMU3CS::fmuState
fmi3FMUState fmuState
Definition ComponentFMU3CS.h:162
oms::ComponentFMU3CS::fmuStateTime
double fmuStateTime
Definition ComponentFMU3CS.h:163
oms::ComponentFMU3CS::getInteger
oms_status_enu_t getInteger(const ComRef &cref, int &value)
Definition ComponentFMU3CS.cpp:1075
oms::ComponentFMU3CS::getAllVariables
std::vector< Variable > getAllVariables()
Definition ComponentFMU3CS.h:106
oms::ComponentFMU3CS::setExportName
oms_status_enu_t setExportName(const std::string &exportName)
Definition ComponentFMU3CS.cpp:614
oms::ComponentFMU3CS::initializeDependencyGraph_initialUnknowns
oms_status_enu_t initializeDependencyGraph_initialUnknowns()
Definition ComponentFMU3CS.cpp:461
oms::ComponentFMU3CS::exportVariables
std::vector< bool > exportVariables
Definition ComponentFMU3CS.h:154
oms::ComponentFMU3CS::inputs
std::vector< unsigned int > inputs
Definition ComponentFMU3CS.h:151
oms::ComponentFMU3CS::allVariables
std::vector< Variable > allVariables
Definition ComponentFMU3CS.h:148
oms::ComponentFMU3CS::exportToSSMTemplate
oms_status_enu_t exportToSSMTemplate(pugi::xml_node &ssmNode)
Definition ComponentFMU3CS.cpp:438
oms::ComponentFMU3CS::getFilteredUnitDefinitionsToSSD
void getFilteredUnitDefinitionsToSSD(std::map< std::string, std::map< std::string, std::string > > &unitDefinitions)
Definition ComponentFMU3CS.cpp:399
oms::ComponentFMU3CS::fmu
fmiHandle * fmu
Definition ComponentFMU3CS.h:145
oms::ComponentFMU3CS::setUnit
oms_status_enu_t setUnit(const ComRef &cref, const std::string &value)
Definition ComponentFMU3CS.cpp:1837
oms::ComponentFMU3CS::omsfmi3logger
fmi3LogMessageCallback omsfmi3logger
Definition ComponentFMU3CS.h:144
oms::ComponentFMU3CS::dumpInitialUnknowns
void dumpInitialUnknowns()
Definition ComponentFMU3CS.cpp:444
oms::ComponentFMU3CS::updateOrDeleteStartValueInReplacedComponent
oms_status_enu_t updateOrDeleteStartValueInReplacedComponent(std::vector< std::string > &warningList)
Definition ComponentFMU3CS.cpp:1916
oms::ComponentFMU3CS::getBoolean
oms_status_enu_t getBoolean(const ComRef &cref, bool &value)
Definition ComponentFMU3CS.cpp:916
oms::ComponentFMU3CS::registerSignalsForResultFile
oms_status_enu_t registerSignalsForResultFile(ResultWriter &resultFile)
Definition ComponentFMU3CS.cpp:1942
oms::ComponentFMU3CS::setReal
oms_status_enu_t setReal(const ComRef &cref, double value)
Definition ComponentFMU3CS.cpp:1708
oms::ComponentFMU3CS::reset
oms_status_enu_t reset()
Definition ComponentFMU3CS.cpp:860
oms::ComponentFMU3CS::getString
oms_status_enu_t getString(const ComRef &cref, std::string &value)
Definition ComponentFMU3CS.cpp:1292
oms::ComponentFMU3CS::getValidCref
oms::ComRef getValidCref(ComRef cref)
Definition ComponentFMU3CS.cpp:765
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:1461
oms::ComponentFMU3CS::deleteReferencesInSSD
oms_status_enu_t deleteReferencesInSSD(const std::string &filename)
Definition ComponentFMU3CS.cpp:817
oms::ComponentFMU3CS::freeState
oms_status_enu_t freeState()
Definition ComponentFMU3CS.cpp:2113
oms::ComponentFMU3CS::setFmuTime
oms_status_enu_t setFmuTime(double time)
Definition ComponentFMU3CS.h:104
oms::ComponentFMU3CS::getFMUInfo
const FMUInfo * getFMUInfo() const
Definition ComponentFMU3CS.h:61
oms::ComponentFMU3CS::exportToSSV
oms_status_enu_t exportToSSV(pugi::xml_node &ssvNode)
Definition ComponentFMU3CS.cpp:426
oms::ComponentFMU3CS::exportName
std::string exportName
export name for the component, used in the result file
Definition ComponentFMU3CS.h:155
oms::ComponentFMU3CS::instantiate
oms_status_enu_t instantiate()
Definition ComponentFMU3CS.cpp:627
oms::ComponentFMU3CS::initializeDependencyGraph_outputs
oms_status_enu_t initializeDependencyGraph_outputs()
Definition ComponentFMU3CS.cpp:564
oms::ComponentFMU3CS::terminate
oms_status_enu_t terminate()
Definition ComponentFMU3CS.cpp:848
oms::ComponentFMU3CS::exportToSSD
oms_status_enu_t exportToSSD(pugi::xml_node &node, Snapshot &snapshot, std::string variantName) const
Definition ComponentFMU3CS.cpp:375
oms::ComponentFMU3CS::setResourcesHelper1
oms_status_enu_t setResourcesHelper1(Values value)
Definition ComponentFMU3CS.cpp:684
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:1199
oms::ComponentFMU3CS::setResourcesHelper2
oms_status_enu_t setResourcesHelper2(Values value)
Definition ComponentFMU3CS.cpp:708
oms::ComponentFMU3CS::stepUntil
oms_status_enu_t stepUntil(double stopTime)
Definition ComponentFMU3CS.cpp:877
oms::ComponentFMU3CS::outputs
std::vector< unsigned int > outputs
Definition ComponentFMU3CS.h:152
oms::ComponentFMU3CS::saveState
oms_status_enu_t saveState()
Definition ComponentFMU3CS.cpp:2104
oms::ComponentFMU3CS::restoreState
oms_status_enu_t restoreState()
Definition ComponentFMU3CS.cpp:2125
oms::ComponentFMU3CS::updateSignals
oms_status_enu_t updateSignals(ResultWriter &resultWriter)
Definition ComponentFMU3CS.cpp:2010
oms::ComponentFMU3CS::getFilteredSignals
void getFilteredSignals(std::vector< Connector > &filteredSignals) const
Definition ComponentFMU3CS.cpp:2134
oms::ComponentFMU3CS::fmuInfo
FMUInfo fmuInfo
Definition ComponentFMU3CS.h:146
oms::ComponentFMU3CS::calculatedParameters
std::vector< unsigned int > calculatedParameters
Definition ComponentFMU3CS.h:149
oms::ComponentFMU3CS::parameters
std::vector< unsigned int > parameters
Definition ComponentFMU3CS.h:153
oms::ComponentFMU3CS::getVariable
Variable * getVariable(const ComRef &cref)
Definition ComponentFMU3CS.cpp:1155
oms::ComponentFMU3CS::setInteger
oms_status_enu_t setInteger(const ComRef &cref, int value)
Definition ComponentFMU3CS.cpp:1590
oms::ComponentFMU3CS::getExportName
std::string getExportName() const
Definition ComponentFMU3CS.h:127
oms::ComponentFMU3CS::removeSignalsFromResults
oms_status_enu_t removeSignalsFromResults(const char *regex)
Definition ComponentFMU3CS.cpp:2077
oms::ComponentFMU3CS::time
double time
Definition ComponentFMU3CS.h:161
oms::ComponentFMU3CS::initialize
oms_status_enu_t initialize()
Definition ComponentFMU3CS.cpp:833
oms::ComponentFMU3CS::deleteStartValue
oms_status_enu_t deleteStartValue(const ComRef &cref)
Definition ComponentFMU3CS.cpp:1878
oms::ComponentFMU3CS::getRealOutputDerivative
oms_status_enu_t getRealOutputDerivative(const ComRef &cref, SignalDerivative &der)
Definition ComponentFMU3CS.cpp:1489
oms::ComponentFMU3CS::setBoolean
oms_status_enu_t setBoolean(const ComRef &cref, bool value)
Definition ComponentFMU3CS.cpp:1539
oms::ComponentFMU3CS::exportToSSVTemplate
oms_status_enu_t exportToSSVTemplate(pugi::xml_node &ssvNode, Snapshot &snapshot)
Definition ComponentFMU3CS.cpp:431
oms::ComponentFMU3CS::setRealInputDerivative
oms_status_enu_t setRealInputDerivative(const ComRef &cref, const SignalDerivative &der)
Definition ComponentFMU3CS.cpp:1510
oms::ComponentFMU3CS::values
Values values
start values defined before instantiating the FMU and external inputs defined after initialization
Definition ComponentFMU3CS.h:157
oms::ComponentFMU3CS::getCanGetAndSetState
bool getCanGetAndSetState()
Definition ComponentFMU3CS.h:116
oms::ComponentFMU3CS::NewComponent
static Component * NewComponent(const ComRef &cref, System *parentSystem, const std::string &fmuPath, std::string replaceComponent="")
Definition ComponentFMU3CS.cpp:63
oms::ComponentFMU3CS::deleteResourcesInSSP
oms_status_enu_t deleteResourcesInSSP(const std::string &filename)
Definition ComponentFMU3CS.cpp:825
oms::ComponentFMU3CS::addSignalsToResults
oms_status_enu_t addSignalsToResults(const char *regex)
Definition ComponentFMU3CS.cpp:2050
oms::ComponentFMU3CS::setValuesResources
oms_status_enu_t setValuesResources(Values &values)
Definition ComponentFMU3CS.cpp:1903
oms::ComponentFMU3CS::derivatives
std::vector< unsigned int > derivatives
Definition ComponentFMU3CS.h:150
oms::ComponentFMU3CS::renameValues
oms_status_enu_t renameValues(const ComRef &oldCref, const ComRef &newCref)
Definition ComponentFMU3CS.cpp:2143
oms::ComponentFMU3CS::getFilteredEnumerationDefinitionsToSSD
void getFilteredEnumerationDefinitionsToSSD(std::map< std::string, std::map< std::string, std::string > > &enumerationDefinitions)
Definition ComponentFMU3CS.cpp:421
oms::ComponentFMU3CS::resultFileMapping
std::unordered_map< unsigned int, unsigned int > resultFileMapping
Definition ComponentFMU3CS.h:159
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