Skip to content

Commit

Permalink
Filter Update
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhjp01 committed Nov 16, 2024
1 parent 12334a7 commit c1da6f6
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions src/cosim/slave_simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,25 +549,19 @@ class slave_simulator::impl
void initialize_start_values()
{
auto deltaT = duration::zero();
auto filter = [this](const value_reference& vr, const std::variant<double, int, bool, std::string>& vt) {
variable_type type;
std::visit(
visitor(
[&](double) { type = variable_type::real; },
[&](int) { type = variable_type::integer; },
[&](bool) { type = variable_type::boolean; },
[&](const std::string&) { type = variable_type::string; }),
vt);
const auto& vd = this->find_variable_description(vr, type);
/// FMI Specification 2.0.4 - Section 4.2.4
return vd.variability != variable_variability::constant &&
vd.causality != variable_causality::input;
auto filter = [this](const variable_type& vt) {
return [this, &vt](const value_reference& vr, const std::variant<double, int, bool, std::string>&) {
const auto& vd = this->find_variable_description(vr, vt);
/// FMI Specification 2.0.4 - Section 4.2.4
return vd.variability != variable_variability::constant &&
vd.causality != variable_causality::input;
};
};

const auto [realRefs, realValues] = realSetCache_.modify_and_get(deltaT, filter);
const auto [integerRefs, integerValues] = integerSetCache_.modify_and_get(deltaT, filter);
const auto [booleanRefs, booleanValues] = booleanSetCache_.modify_and_get(deltaT, filter);
const auto [stringRefs, stringValues] = stringSetCache_.modify_and_get(deltaT, filter);
const auto [realRefs, realValues] = realSetCache_.modify_and_get(deltaT, filter(variable_type::real));
const auto [integerRefs, integerValues] = integerSetCache_.modify_and_get(deltaT, filter(variable_type::integer));
const auto [booleanRefs, booleanValues] = booleanSetCache_.modify_and_get(deltaT, filter(variable_type::boolean));
const auto [stringRefs, stringValues] = stringSetCache_.modify_and_get(deltaT, filter(variable_type::string));

slave_->set_variables(
gsl::make_span(realRefs),
Expand Down

0 comments on commit c1da6f6

Please sign in to comment.