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 #ifdef _WIN32
36 class AdditionalPath;
37 #endif
38 class SlaveInstance1;
39 
40 
48 {
49 private:
50  // Only Importer is allowed to instantiate this class.
51  friend class Importer;
52  FMU1(
54  const boost::filesystem::path& fmuDir);
55 
56 public:
57  // Disable copy and move
58  FMU1(const FMU1&) = delete;
59  FMU1& operator=(const FMU1&) = delete;
60  FMU1(FMU1&&) = delete;
61  FMU1& operator=(FMU1&&) = delete;
62 
63  ~FMU1();
64 
65  // coral::fmi::FMU methods
66  coral::fmi::FMIVersion FMIVersion() const override;
67  const coral::model::SlaveTypeDescription& Description() const override;
70 
78 
80  const boost::filesystem::path& Directory() const;
81 
92  fmi1_value_reference_t FMIValueReference(coral::model::VariableID variable)
93  const;
94 
96  fmi1_import_t* FmilibHandle() const;
97 
98 private:
100  boost::filesystem::path m_dir;
101 
102  fmi1_import_t* m_handle;
104  std::vector<fmi1_value_reference_t> m_valueReferences;
106 
107 #ifdef _WIN32
108  // Workaround for VIPROMA-67 (FMU DLL search paths on Windows).
109  std::unique_ptr<AdditionalPath> m_additionalDllSearchPath;
110 #endif
111 };
112 
113 
116 {
117 private:
118  // Only FMU1 is allowed to instantiate this class.
121 
122 public:
123  // Disable copy and move.
124  SlaveInstance1(const SlaveInstance1&) = delete;
125  SlaveInstance1& operator=(const SlaveInstance1&) = delete;
126  SlaveInstance1(SlaveInstance1&&) = delete;
127  SlaveInstance1& operator=(SlaveInstance1&&) = delete;
128 
129  ~SlaveInstance1() CORAL_NOEXCEPT;
130 
131  // coral::slave::Instance methods
132  coral::model::SlaveTypeDescription TypeDescription() const override;
133 
134  void Setup(
135  const std::string& slaveName,
136  const std::string& executionName,
137  coral::model::TimePoint startTime,
138  coral::model::TimePoint stopTime,
139  bool adaptiveStepSize,
140  double relativeTolerance) override;
141 
142  void StartSimulation() override;
143  void EndSimulation() override;
144 
145  bool DoStep(coral::model::TimePoint currentT, coral::model::TimeDuration deltaT) override;
146 
147  double GetRealVariable(coral::model::VariableID variable) const override;
148  int GetIntegerVariable(coral::model::VariableID variable) const override;
149  bool GetBooleanVariable(coral::model::VariableID variable) const override;
150  std::string GetStringVariable(coral::model::VariableID variable) const override;
151 
152  bool SetRealVariable(coral::model::VariableID variable, double value) override;
153  bool SetIntegerVariable(coral::model::VariableID variable, int value) override;
154  bool SetBooleanVariable(coral::model::VariableID variable, bool value) override;
155  bool SetStringVariable(coral::model::VariableID variable, const std::string& value) override;
156 
157  // coral::fmi::SlaveInstance methods
158  std::shared_ptr<coral::fmi::FMU> FMU() const override;
159 
162 
164  fmi1_import_t* FmilibHandle() const;
165 
166 private:
168  fmi1_import_t* m_handle;
169 
170  bool m_setupComplete = false;
171  bool m_simStarted = false;
172 
173  std::string m_instanceName;
174  coral::model::TimePoint m_startTime = 0.0;
176 };
177 
178 
179 }} // namespace
180 #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:115
Imports and caches FMUs.
Definition: importer.hpp:56
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:47
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
const coral::model::SlaveTypeDescription & Description() const override
A description of this FMU.