-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmodel.cpp
98 lines (80 loc) · 3.71 KB
/
model.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// FMU4cpp Hello World example
//
#include <fmu4cpp/fmu_base.hpp>
#include <utility>
using namespace fmu4cpp;
class Model : public fmu_base {
public:
Model(const std::string &instanceName, const std::filesystem::path &resources)
: fmu_base(instanceName, resources) {
register_variable(integer(
"integerIn", &integer_)
.setCausality(causality_t::INPUT)
.setVariability(variability_t::DISCRETE)
.setInitial(initial_t::EXACT));
register_variable(
real(
"realIn", &real_)
.setCausality(causality_t::INPUT)
.setVariability(variability_t::DISCRETE)
.setInitial(initial_t::EXACT));
register_variable(boolean(
"booleanIn", &boolean_)
.setCausality(causality_t::INPUT)
.setVariability(variability_t::DISCRETE)
.setInitial(initial_t::EXACT));
register_variable(string(
"stringIn", &string_)
.setCausality(causality_t::INPUT)
.setVariability(variability_t::DISCRETE)
.setInitial(initial_t::EXACT));
register_variable(integer("integerOut", &integer_)
.setCausality(causality_t::OUTPUT)
.setVariability(variability_t::DISCRETE)
.setInitial(initial_t::CALCULATED)
.setDependencies({get_int_variable("integerIn")->index()}));
register_variable(real("realOut", &real_)
.setCausality(causality_t::OUTPUT)
.setVariability(variability_t::DISCRETE)
.setInitial(initial_t::CALCULATED)
.setDependencies({get_real_variable("realIn")->index()}));
register_variable(boolean("booleanOut", &boolean_)
.setCausality(causality_t::OUTPUT)
.setVariability(variability_t::DISCRETE)
.setInitial(initial_t::CALCULATED)
.setDependencies({get_bool_variable("booleanIn")->index()}));
register_variable(string("stringOut", &string_)
.setCausality(causality_t::OUTPUT)
.setVariability(variability_t::DISCRETE)
.setInitial(initial_t::CALCULATED)
.setDependencies({get_string_variable("stringIn")->index()}));
Model::reset();
}
bool do_step(double currentTime, double dt) override {
log(fmi2OK, "hello@ " + std::to_string(currentTime));
return true;
}
void reset() override {
integer_ = 0;
real_ = 0;
boolean_ = false;
string_ = "empty";
}
private:
int integer_;
double real_;
bool boolean_;
std::string string_;
};
model_info fmu4cpp::get_model_info() {
model_info info;
info.modelName = "Identity";
info.description = "A simple feed-trough model";
info.modelIdentifier = FMU4CPP_MODEL_IDENTIFIER;
return info;
}
std::unique_ptr<fmu_base> fmu4cpp::createInstance(const std::string &instanceName,
const std::filesystem::path &fmuResourceLocation) {
return std::make_unique<Model>(instanceName, fmuResourceLocation);
}