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.
52  const boost::filesystem::path&);
53  FMU1(
55  const boost::filesystem::path& fmuDir);
56 
57 public:
58  // Disable copy and move
59  FMU1(const FMU1&) = delete;
60  FMU1& operator=(const FMU1&) = delete;
61  FMU1(FMU1&&) = delete;
62  FMU1& operator=(FMU1&&) = delete;
63 
64  ~FMU1();
65 
66  // coral::fmi::FMU methods
67  coral::fmi::FMIVersion FMIVersion() const override;
68  const coral::model::SlaveTypeDescription& Description() const override;
71 
79 
81  const boost::filesystem::path& Directory() const;
82 
93  fmi1_value_reference_t FMIValueReference(coral::model::VariableID variable)
94  const;
95 
97  fmi1_import_t* FmilibHandle() const;
98 
99 private:
101  boost::filesystem::path m_dir;
102 
103  fmi1_import_t* m_handle;
105  std::vector<fmi1_value_reference_t> m_valueReferences;
107 
108 #ifdef _WIN32
109  // Workaround for VIPROMA-67 (FMU DLL search paths on Windows).
110  std::unique_ptr<AdditionalPath> m_additionalDllSearchPath;
111 #endif
112 };
113 
114 
117 {
118 private:
119  // Only FMU1 is allowed to instantiate this class.
122 
123 public:
124  // Disable copy and move.
125  SlaveInstance1(const SlaveInstance1&) = delete;
126  SlaveInstance1& operator=(const SlaveInstance1&) = delete;
127  SlaveInstance1(SlaveInstance1&&) = delete;
128  SlaveInstance1& operator=(SlaveInstance1&&) = delete;
129 
130  ~SlaveInstance1() CORAL_NOEXCEPT;
131 
132  // coral::slave::Instance methods
133  coral::model::SlaveTypeDescription TypeDescription() const override;
134 
135  void Setup(
136  const std::string& slaveName,
137  const std::string& executionName,
138  coral::model::TimePoint startTime,
139  coral::model::TimePoint stopTime,
140  bool adaptiveStepSize,
141  double relativeTolerance) override;
142 
143  void StartSimulation() override;
144  void EndSimulation() override;
145 
146  bool DoStep(coral::model::TimePoint currentT, coral::model::TimeDuration deltaT) override;
147 
148  double GetRealVariable(coral::model::VariableID variable) const override;
149  int GetIntegerVariable(coral::model::VariableID variable) const override;
150  bool GetBooleanVariable(coral::model::VariableID variable) const override;
151  std::string GetStringVariable(coral::model::VariableID variable) const override;
152 
153  bool SetRealVariable(coral::model::VariableID variable, double value) override;
154  bool SetIntegerVariable(coral::model::VariableID variable, int value) override;
155  bool SetBooleanVariable(coral::model::VariableID variable, bool value) override;
156  bool SetStringVariable(coral::model::VariableID variable, const std::string& value) override;
157 
158  // coral::fmi::SlaveInstance methods
159  std::shared_ptr<coral::fmi::FMU> FMU() const override;
160 
163 
165  fmi1_import_t* FmilibHandle() const;
166 
167 private:
169  fmi1_import_t* m_handle;
170 
171  bool m_setupComplete = false;
172  bool m_simStarted = false;
173 
174  std::string m_instanceName;
175  coral::model::TimePoint m_startTime = 0.0;
177 };
178 
179 
180 }} // namespace
181 #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:116
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
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.