Skip to content

Commit

Permalink
core: adapting cross model for synchronization issues
Browse files Browse the repository at this point in the history
  • Loading branch information
K-H-Ismail committed Apr 5, 2020
1 parent 05fe63a commit 44c776c
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/include/irritator/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2853,6 +2853,7 @@ struct cross
double value = threshold - 1.0;
double if_value = 0.0;
double else_value = 0.0;
double res = 0.0;

enum port_name
{
Expand All @@ -2876,6 +2877,8 @@ struct cross
time /*r*/) noexcept
{
bool have_message = false;
double before_value = value;
double before_if_value = if_value;

if (auto* port = input_ports.try_to_get(x[port_value]); port) {
for (const auto& msg : port->messages) {
Expand Down Expand Up @@ -2919,9 +2922,16 @@ struct cross

else_value = msg.to_real_64(0);
have_message = true;

}
}

if(value != before_value ) {
else_value = value >= threshold ? if_value : else_value;
}
res = else_value;


sigma =
have_message ? time_domain<time>::zero : time_domain<time>::infinity;
return status::success;
Expand All @@ -2930,10 +2940,10 @@ struct cross
status lambda(
data_array<output_port, output_port_id>& output_ports) noexcept
{
double output_value = 0.0;

if (auto* port = output_ports.try_to_get(y[0]); port) {
output_value = value >= threshold ? if_value : else_value;
port->messages.emplace_front(output_value);

port->messages.emplace_front(res);
}
return status::success;
}
Expand Down Expand Up @@ -3024,7 +3034,7 @@ struct integrator
irt_return_if_fail(msg.type == value_type::real_64 &&
msg.size() == 1,
status::model_integrator_bad_external_message);

reset_value = msg.to_real_64(0);
reset = true;
}
Expand Down

0 comments on commit 44c776c

Please sign in to comment.