coral
A C++ library for distributed co-simulation
fmu1.hpp
Go to the documentation of this file.
1 
10 #ifndef CORAL_FMI_FMU1_HPP
11 #define CORAL_FMI_FMU1_HPP
12 
13 #include <memory>
14 #include <string>
15 #include <vector>
16 
17 #include "boost/filesystem/path.hpp"
18 
19 #include "coral/config.h"
20 #include "coral/fmi/fmu.hpp"
21 #include "coral/fmi/importer.hpp"
22 #include "coral/model.hpp"
23 
24 
25 // Forward declarations to avoid external dependency on FMI Library
26 struct fmi1_import_t;
27 typedef unsigned int fmi1_value_reference_t;
28 
29 
30 namespace coral
31 {
32 namespace fmi
33 {
34 
35 class SlaveInstance1;
36 
37 
45 {
46 private:
47  // Only Importer is allowed to instantiate this class.
49  const boost::filesystem::path&);
50  FMU1(
52  const boost::filesystem::path& fmuDir);
53 
54 public:
55  // Disable copy and move
56  FMU1(const FMU1&) = delete;
57  FMU1& operator=(const FMU1&) = delete;
58  FMU1(FMU1&&) = delete;
59  FMU1& operator=(FMU1&&) = delete;
60 
61  ~FMU1();
62 
63  // coral::fmi::FMU methods
64  coral::fmi::FMIVersion FMIVersion() const override;
65  const coral::model::SlaveTypeDescription& Description() const override;
68 
76 
78  const boost::filesystem::path& Directory() const;
79 
90  fmi1_value_reference_t FMIValueReference(coral::model::VariableID variable)
91  const;
92 
94  fmi1_import_t* FmilibHandle() const;
95 
96 private:
98  boost::filesystem::path m_dir;
99 
100  fmi1_import_t* m_handle;
102  std::vector<fmi1_value_reference_t> m_valueReferences;
104 
105 #ifdef _WIN32
106  // Workaround for VIPROMA-67 (FMU DLL search paths on Windows).
107  class AdditionalPath;
108  std::unique_ptr<AdditionalPath> m_additionalDllSearchPath;
109 #endif
110 };
111 
112 
115 {
116 private:
117  // Only FMU1 is allowed to instantiate this class.
120 
121 public:
122  // Disable copy and move.
123  SlaveInstance1(const SlaveInstance1&) = delete;
124  SlaveInstance1& operator=(const SlaveInstance1&) = delete;
125  SlaveInstance1(SlaveInstance1&&) = delete;
126  SlaveInstance1& operator=(SlaveInstance1&&) = delete;
127 
128  ~SlaveInstance1() CORAL_NOEXCEPT;
129 
130  // coral::slave::Instance methods
131  coral::model::SlaveTypeDescription TypeDescription() const override;
132 
133  void Setup(
134  const std::string& slaveName,
135  const std::string& executionName,
136  coral::model::TimePoint startTime,
137  coral::model::TimePoint stopTime,
138  bool adaptiveStepSize,
139  double relativeTolerance) override;
140 
141  void StartSimulation() override;
142  void EndSimulation() override;
143 
144  bool DoStep(coral::model::TimePoint currentT, coral::model::TimeDuration deltaT) override;
145 
146  double GetRealVariable(coral::model::VariableID variable) const override;
147  int GetIntegerVariable(coral::model::VariableID variable) const override;
148  bool GetBooleanVariable(coral::model::VariableID variable) const override;
149  std::string GetStringVariable(coral::model::VariableID variable) const override;
150 
151  bool SetRealVariable(coral::model::VariableID variable, double value) override;
152  bool SetIntegerVariable(coral::model::VariableID variable, int value) override;
153  bool SetBooleanVariable(coral::model::VariableID variable, bool value) override;
154  bool SetStringVariable(coral::model::VariableID variable, const std::string& value) override;
155 
156  // coral::fmi::SlaveInstance methods
157  std::shared_ptr<coral::fmi::FMU> FMU() const override;
158 
161 
163  fmi1_import_t* FmilibHandle() const;
164 
165 private:
167  fmi1_import_t* m_handle;
168 
169  bool m_setupComplete = false;
170  bool m_simStarted = false;
171 
172  std::string m_instanceName;
173  coral::model::TimePoint m_startTime = 0.0;
175 };
176 
177 
178 }} // namespace
179 #endif // header guard
FMU import functionality.
Defines a version-independent FMU interface.
An interface for classes that represent imported FMUs.
Definition: fmu.hpp:50
const boost::filesystem::path & Directory() const
Returns the path to the directory in which this FMU was unpacked.
An FMI co-simulation slave instance.
Definition: fmu.hpp:70
fmi1_import_t * FmilibHandle() const
Returns the underlying C API handle (for FMI Library)
STL class.
An FMI 1.0 co-simulation slave instance.
Definition: fmu1.hpp:114
fmi1_value_reference_t FMIValueReference(coral::model::VariableID variable) const
Returns the FMI value reference for the variable with the given ID.
A description of a slave type.
Definition: model.hpp:148
Definition: variable_io.hpp:28
FMIVersion
Constants that refer to FMI version numbers.
Definition: fmu.hpp:27
std::shared_ptr< coral::fmi::Importer > Importer() const override
Returns the coral::fmi::Importer which was used to import this FMU.
double TimeDuration
The type used to specify (simulation) time durations.
Definition: model.hpp:56
const TimePoint ETERNITY
A special TimePoint value that lies infinitely far in the future.
Definition: model.hpp:46
A class which represents an imported FMI 1.0 FMU.
Definition: fmu1.hpp:44
std::shared_ptr< SlaveInstance1 > InstantiateSlave1()
Creates a new co-simulation slave instance.
std::shared_ptr< coral::fmi::SlaveInstance > InstantiateSlave() override
Creates a co-simulation slave instance of this FMU.
Main module header for coral::model.
coral::fmi::FMIVersion FMIVersion() const override
Which FMI standard version is used in this FMU.
double TimePoint
The type used to specify (simulation) time points.
Definition: model.hpp:42
std::shared_ptr< FMU > Import(const boost::filesystem::path &fmuPath)
Imports and loads an FMU.
const coral::model::SlaveTypeDescription & Description() const override
A description of this FMU.