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 "Option.h"
38 #include "ResultWriter.h"
39 #include "Variable.h"
40 #include <fmilib.h>
41 #include <map>
42 #include <pugixml.hpp>
43 #include <string>
44 #include <unordered_map>
45 #include <vector>
46 
47 namespace oms
48 {
49  class ComponentFMUME : public Component
50  {
51  public:
53 
54  static Component* NewComponent(const oms::ComRef& cref, System* parentSystem, const std::string& fmuPath);
55  static Component* NewComponent(const pugi::xml_node& node, System* parentSystem);
56  const FMUInfo* getFMUInfo() const {return &(this->fmuInfo);}
57 
58  oms_status_enu_t exportToSSD(pugi::xml_node& node) const;
63 
66 
67  oms_status_enu_t getBoolean(const ComRef& cref, bool& value);
68  oms_status_enu_t getBoolean(const fmi2_value_reference_t& vr, bool& value);
69  oms_status_enu_t getInteger(const ComRef& cref, int& value);
70  oms_status_enu_t getInteger(const fmi2_value_reference_t& vr, int& value);
71  oms_status_enu_t getReal(const ComRef& cref, double& value);
72  oms_status_enu_t getReal(const fmi2_value_reference_t& vr, double& value);
73  oms_status_enu_t setBoolean(const ComRef& cref, bool value);
74  oms_status_enu_t setInteger(const ComRef& cref, int value);
75  oms_status_enu_t setReal(const ComRef& cref, double value);
76 
79  oms_status_enu_t addSignalsToResults(const char* regex);
80  oms_status_enu_t removeSignalsFromResults(const char* regex);
81 
83 
86  oms_status_enu_t getContinuousStates(double* states);
87  oms_status_enu_t setContinuousStates(double* states);
88  oms_status_enu_t getDerivatives(double* derivatives);
90  oms_status_enu_t getEventindicators(double* eventindicators);
91 
92  fmi2_import_t* getFMU() {return fmu;}
93  fmi2_event_info_t* getEventInfo() {return &eventInfo;}
94 
95  protected:
96  ComponentFMUME(const ComRef& cref, System* parentSystem, const std::string& fmuPath);
97 
98  // stop the compiler generating methods copying the object
99  ComponentFMUME(ComponentFMUME const& copy);
100  ComponentFMUME& operator=(ComponentFMUME const& copy);
101 
102  private:
103  jm_callbacks callbacks;
104  fmi2_callback_functions_t callbackFunctions;
105  fmi_import_context_t* context = NULL;
106  fmi2_import_t* fmu = NULL;
107  std::string tempDir;
108 
109  fmi2_event_info_t eventInfo;
112 
114 
115  std::vector<Variable> allVariables;
116  std::vector<Variable> inputs;
117  std::vector<Variable> outputs;
118  std::vector<Variable> parameters;
119  std::vector<bool> exportVariables;
120 
121  std::map<ComRef, double> realStartValues;
122  std::map<ComRef, int> integerStartValues;
123  std::map<ComRef, bool> booleanStartValues;
124 
125  std::unordered_map<unsigned int /*result file var ID*/, unsigned int /*allVariables ID*/> resultFileMapping;
126  };
127 }
128 
129 #endif
ComponentFMUME(const ComRef &cref, System *parentSystem, const std::string &fmuPath)
Definition: ComponentFMUME.cpp:45
FMU info.
Definition: FMUInfo.h:45
fmi2_event_info_t eventInfo
Definition: ComponentFMUME.h:109
fmi2_event_info_t * getEventInfo()
Definition: ComponentFMUME.h:93
oms_status_enu_t initializeDependencyGraph_outputs()
Definition: ComponentFMUME.cpp:386
Definition: ResultWriter.h:67
size_t getNumberOfEventIndicators() const
Definition: ComponentFMUME.h:85
System * parentSystem
Definition: Component.h:126
oms_status_enu_t instantiate()
Definition: ComponentFMUME.cpp:430
size_t getNumberOfContinuousStates() const
Definition: ComponentFMUME.h:84
oms_status_enu_t initializeDependencyGraph_initialUnknowns()
Definition: ComponentFMUME.cpp:329
std::vector< Variable > allVariables
Definition: ComponentFMUME.h:115
size_t nEventIndicators
Definition: ComponentFMUME.h:111
std::vector< bool > exportVariables
Definition: ComponentFMUME.h:119
oms_status_enu_t getInteger(const ComRef &cref, int &value)
Definition: ComponentFMUME.cpp:598
oms_status_enu_t setContinuousStates(double *states)
Definition: ComponentFMUME.cpp:854
FMUInfo fmuInfo
Definition: ComponentFMUME.h:113
std::vector< Variable > outputs
Definition: ComponentFMUME.h:117
oms_status_enu_t
Definition: Types.h:43
fmi2_import_t * getFMU()
Definition: ComponentFMUME.h:92
oms_status_enu_t getBoolean(const ComRef &cref, bool &value)
Definition: ComponentFMUME.cpp:568
size_t nContinuousStates
Definition: ComponentFMUME.h:110
ComponentFMUME & operator=(ComponentFMUME const &copy)
not implemented
std::string tempDir
Definition: ComponentFMUME.h:107
~ComponentFMUME()
Definition: ComponentFMUME.cpp:50
oms_status_enu_t getEventindicators(double *eventindicators)
Definition: ComponentFMUME.cpp:881
fmi2_callback_functions_t callbackFunctions
Definition: ComponentFMUME.h:104
oms_status_enu_t getNominalsOfContinuousStates(double *nominals)
Definition: ComponentFMUME.cpp:872
std::vector< Variable > inputs
Definition: ComponentFMUME.h:116
oms_status_enu_t getDerivatives(double *derivatives)
Definition: ComponentFMUME.cpp:863
ComRef - component reference.
Definition: ComRef.h:43
Definition: Component.h:54
oms_status_enu_t getReal(const ComRef &cref, double &value)
Definition: ComponentFMUME.cpp:633
fmi2_import_t * fmu
Definition: ComponentFMUME.h:106
oms_status_enu_t setReal(const ComRef &cref, double value)
Definition: ComponentFMUME.cpp:710
jm_callbacks callbacks
Definition: ComponentFMUME.h:103
oms_status_enu_t terminate()
Definition: ComponentFMUME.cpp:519
oms_status_enu_t getContinuousStates(double *states)
Definition: ComponentFMUME.cpp:845
std::unordered_map< unsigned int, unsigned int > resultFileMapping
Definition: ComponentFMUME.h:125
std::map< ComRef, int > integerStartValues
parameters and start values defined before instantiating the FMU
Definition: ComponentFMUME.h:122
Definition: ComponentFMUME.h:49
Definition: BusConnector.h:15
std::vector< Variable > parameters
Definition: ComponentFMUME.h:118
oms_status_enu_t initialize()
Definition: ComponentFMUME.cpp:498
std::map< ComRef, bool > booleanStartValues
parameters and start values defined before instantiating the FMU
Definition: ComponentFMUME.h:123
oms_status_enu_t doEventIteration()
Definition: ComponentFMUME.cpp:484
ComRef cref
Definition: Component.h:127
oms_status_enu_t setBoolean(const ComRef &cref, bool value)
Definition: ComponentFMUME.cpp:653
oms_status_enu_t updateSignals(ResultWriter &resultWriter)
Definition: ComponentFMUME.cpp:805
oms_status_enu_t setInteger(const ComRef &cref, int value)
Definition: ComponentFMUME.cpp:682
oms_status_enu_t exportToSSD(pugi::xml_node &node) const
Definition: ComponentFMUME.cpp:300
oms_status_enu_t reset()
Definition: ComponentFMUME.cpp:530
oms_status_enu_t addSignalsToResults(const char *regex)
Definition: ComponentFMUME.cpp:890
static Component * NewComponent(const oms::ComRef &cref, System *parentSystem, const std::string &fmuPath)
Definition: ComponentFMUME.cpp:64
oms_status_enu_t removeSignalsFromResults(const char *regex)
Definition: ComponentFMUME.cpp:909
oms_status_enu_t registerSignalsForResultFile(ResultWriter &resultFile)
Definition: ComponentFMUME.cpp:742
Definition: System.h:58
const FMUInfo * getFMUInfo() const
Definition: ComponentFMUME.h:56
fmi_import_context_t * context
Definition: ComponentFMUME.h:105
std::map< ComRef, double > realStartValues
parameters and start values defined before instantiating the FMU
Definition: ComponentFMUME.h:121