OMSimulatorLib
The OMSimulator project is a FMI-based co-simulation environment that supports ordinary (i.e., non-delayed) and TLM connections.
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 "Values.h"
38 #include "ResultWriter.h"
39 #include "Variable.h"
40 
41 #include <fmilib.h>
42 #include <map>
43 #include <pugixml.hpp>
44 #include <string>
45 #include <unordered_map>
46 #include <vector>
47 
48 namespace oms
49 {
50  class ComponentFMUME : public Component
51  {
52  public:
54 
55  static Component* NewComponent(const oms::ComRef& cref, System* parentSystem, const std::string& fmuPath);
56  static Component* NewComponent(const pugi::xml_node& node, System* parentSystem, const std::string& sspVersion);
57  const FMUInfo* getFMUInfo() const {return &(this->fmuInfo);}
58 
59  oms_status_enu_t exportToSSD(pugi::xml_node& node, pugi::xml_node& ssvNode) const;
60  oms_status_enu_t exportToSSVTemplate(pugi::xml_node& ssvNode);
61  oms_status_enu_t exportToSSMTemplate(pugi::xml_node& ssmNode);
66 
69 
70  Variable* getVariable(const ComRef& cref);
71 
72  oms_status_enu_t getBoolean(const ComRef& cref, bool& value);
73  oms_status_enu_t getBoolean(const fmi2_value_reference_t& vr, bool& value);
74  oms_status_enu_t getInteger(const ComRef& cref, int& value);
75  oms_status_enu_t getInteger(const fmi2_value_reference_t& vr, int& value);
76  oms_status_enu_t getReal(const ComRef& cref, double& value);
77  oms_status_enu_t getReal(const fmi2_value_reference_t& vr, double& value);
78  oms_status_enu_t setBoolean(const ComRef& cref, bool value);
79  oms_status_enu_t setInteger(const ComRef& cref, int value);
80  oms_status_enu_t setReal(const ComRef& cref, double value);
81 
83 
86  oms_status_enu_t addSignalsToResults(const char* regex);
87  oms_status_enu_t removeSignalsFromResults(const char* regex);
88 
90 
93  oms_status_enu_t getContinuousStates(double* states);
94  oms_status_enu_t setContinuousStates(double* states);
95  oms_status_enu_t getDerivatives(double* derivatives);
97  oms_status_enu_t getEventindicators(double* eventindicators);
98 
99  fmi2_import_t* getFMU() {return fmu;}
100  fmi2_event_info_t* getEventInfo() {return &eventInfo;}
101 
103 
104  oms_status_enu_t setFaultInjection(const ComRef& signal, oms_fault_type_enu_t faultType, double faultValue);
105 
106  protected:
107  ComponentFMUME(const ComRef& cref, System* parentSystem, const std::string& fmuPath);
108 
109  // stop the compiler generating methods copying the object
110  ComponentFMUME(ComponentFMUME const& copy);
111  ComponentFMUME& operator=(ComponentFMUME const& copy);
112 
113  private:
114  jm_callbacks callbacks;
115  fmi2_callback_functions_t callbackFunctions;
116  fmi_import_context_t* context = NULL;
117  fmi2_import_t* fmu = NULL;
118 
119  fmi2_event_info_t eventInfo;
122 
124 
125  std::vector<Variable> allVariables;
126  std::vector<Variable> inputs;
127  std::vector<Variable> outputs;
128  std::vector<Variable> parameters;
129  std::vector<Variable> calculatedParameters;
130  std::vector<bool> exportVariables;
131 
133 
134  std::unordered_map<unsigned int /*result file var ID*/, unsigned int /*allVariables ID*/> resultFileMapping;
135 
136  std::map<fmi2_value_reference_t, oms_fault_type_t> fib;
138  };
139 }
140 
141 #endif
ComponentFMUME(const ComRef &cref, System *parentSystem, const std::string &fmuPath)
Definition: ComponentFMUME.cpp:46
FMU info.
Definition: FMUInfo.h:45
fmi2_event_info_t eventInfo
Definition: ComponentFMUME.h:119
fmi2_event_info_t * getEventInfo()
Definition: ComponentFMUME.h:100
oms_status_enu_t initializeDependencyGraph_outputs()
Definition: ComponentFMUME.cpp:462
Definition: ResultWriter.h:68
size_t getNumberOfEventIndicators() const
Definition: ComponentFMUME.h:92
System * parentSystem
Definition: Component.h:143
oms_status_enu_t instantiate()
Definition: ComponentFMUME.cpp:511
size_t getNumberOfContinuousStates() const
Definition: ComponentFMUME.h:91
oms_status_enu_t initializeDependencyGraph_initialUnknowns()
Definition: ComponentFMUME.cpp:370
Definition: Variable.h:44
std::vector< Variable > allVariables
Definition: ComponentFMUME.h:125
size_t nEventIndicators
Definition: ComponentFMUME.h:121
std::vector< bool > exportVariables
Definition: ComponentFMUME.h:130
oms_status_enu_t getInteger(const ComRef &cref, int &value)
Definition: ComponentFMUME.cpp:724
oms_status_enu_t exportToSSVTemplate(pugi::xml_node &ssvNode)
Definition: ComponentFMUME.cpp:358
oms_status_enu_t setContinuousStates(double *states)
Definition: ComponentFMUME.cpp:1095
FMUInfo fmuInfo
Definition: ComponentFMUME.h:123
std::vector< Variable > outputs
Definition: ComponentFMUME.h:127
oms_status_enu_t
Definition: Types.h:43
fmi2_import_t * getFMU()
Definition: ComponentFMUME.h:99
oms_status_enu_t getBoolean(const ComRef &cref, bool &value)
Definition: ComponentFMUME.cpp:671
size_t nContinuousStates
Definition: ComponentFMUME.h:120
ComponentFMUME & operator=(ComponentFMUME const &copy)
not implemented
~ComponentFMUME()
Definition: ComponentFMUME.cpp:51
oms_status_enu_t getEventindicators(double *eventindicators)
Definition: ComponentFMUME.cpp:1122
Variable * getVariable(const ComRef &cref)
Definition: ComponentFMUME.cpp:767
fmi2_callback_functions_t callbackFunctions
Definition: ComponentFMUME.h:115
oms_status_enu_t getNominalsOfContinuousStates(double *nominals)
Definition: ComponentFMUME.cpp:1113
std::vector< Variable > inputs
Definition: ComponentFMUME.h:126
oms_status_enu_t exportToSSD(pugi::xml_node &node, pugi::xml_node &ssvNode) const
Definition: ComponentFMUME.cpp:318
oms_status_enu_t setFaultInjection(const ComRef &signal, oms_fault_type_enu_t faultType, double faultValue)
Definition: ComponentFMUME.cpp:1169
oms_status_enu_t getDerivatives(double *derivatives)
Definition: ComponentFMUME.cpp:1104
ComRef - component reference.
Definition: ComRef.h:43
std::map< fmi2_value_reference_t, oms_fault_type_t > fib
fault injection blocks
Definition: ComponentFMUME.h:136
Definition: Component.h:56
oms_status_enu_t getReal(const ComRef &cref, double &value)
Definition: ComponentFMUME.cpp:816
fmi2_import_t * fmu
Definition: ComponentFMUME.h:117
oms_status_enu_t setReal(const ComRef &cref, double value)
Definition: ComponentFMUME.cpp:941
jm_callbacks callbacks
Definition: ComponentFMUME.h:114
oms_status_enu_t terminate()
Definition: ComponentFMUME.cpp:622
Definition: Values.h:42
oms_status_enu_t getContinuousStates(double *states)
Definition: ComponentFMUME.cpp:1086
std::unordered_map< unsigned int, unsigned int > resultFileMapping
Definition: ComponentFMUME.h:134
Definition: ComponentFMUME.h:50
Definition: AlgLoop.h:44
std::vector< Variable > parameters
Definition: ComponentFMUME.h:128
std::vector< Variable > calculatedParameters
Definition: ComponentFMUME.h:129
oms_fault_type_enu_t
Definition: Types.h:76
oms_status_enu_t deleteStartValue(const ComRef &cref)
Definition: ComponentFMUME.cpp:936
oms_status_enu_t initialize()
Definition: ComponentFMUME.cpp:601
Values values
start values defined before instantiating the FMU and external inputs defined after initialization ...
Definition: ComponentFMUME.h:132
oms_status_enu_t doEventIteration()
Definition: ComponentFMUME.cpp:581
ComRef cref
Definition: Component.h:144
const char * signal
Definition: Tags.cpp:38
oms_status_enu_t setBoolean(const ComRef &cref, bool value)
Definition: ComponentFMUME.cpp:859
oms_status_enu_t exportToSSMTemplate(pugi::xml_node &ssmNode)
Definition: ComponentFMUME.cpp:364
oms_status_enu_t updateSignals(ResultWriter &resultWriter)
Definition: ComponentFMUME.cpp:1046
oms_status_enu_t setInteger(const ComRef &cref, int value)
Definition: ComponentFMUME.cpp:898
oms_status_enu_t reset()
Definition: ComponentFMUME.cpp:633
oms_status_enu_t addSignalsToResults(const char *regex)
Definition: ComponentFMUME.cpp:1131
bool getCanGetAndSetFMUstate() const
Definition: FMUInfo.h:58
bool getCanGetAndSetState()
Definition: ComponentFMUME.h:102
oms::ComRef getValidCref(ComRef cref)
Definition: ComponentFMUME.cpp:571
static Component * NewComponent(const oms::ComRef &cref, System *parentSystem, const std::string &fmuPath)
Definition: ComponentFMUME.cpp:59
oms_status_enu_t removeSignalsFromResults(const char *regex)
Definition: ComponentFMUME.cpp:1150
oms_status_enu_t registerSignalsForResultFile(ResultWriter &resultFile)
Definition: ComponentFMUME.cpp:983
Definition: System.h:67
const FMUInfo * getFMUInfo() const
Definition: ComponentFMUME.h:57
fmi_import_context_t * context
Definition: ComponentFMUME.h:116