Skip to content

Commit

Permalink
app: shows which part fail after simulation error
Browse files Browse the repository at this point in the history
  • Loading branch information
quesnel committed Oct 23, 2024
1 parent 16942c2 commit f08c2ff
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 46 deletions.
102 changes: 81 additions & 21 deletions app/gui/simulation-component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@

namespace irt {

static constexpr std::string_view simulation_part_names[] = {
"messages", "nodes", "dated_messages", "models",
"hsms", "observers", "scheduler", "external_sources"
};

static status simulation_init_observation(application& app) noexcept
{
for (auto& grid_obs : app.pj.grid_observers)
Expand Down Expand Up @@ -143,37 +148,92 @@ static void simulation_init(application& app) noexcept
});
}

static status debug_run(simulation_editor& sim_ed) noexcept
static bool debug_run(simulation_editor& sim_ed) noexcept
{
auto& app = container_of(&sim_ed, &application::simulation_ed);
auto success = true;

if (auto ret = run(sim_ed.tl, app.sim, app.sim.t); !ret) {
app.notifications.try_insert(log_level::error,
[&](auto& t, auto&) noexcept {
t = "Simulation debug task run error";
});
attempt_all(
[&] {
auto& app = container_of(&sim_ed, &application::simulation_ed);
return run(sim_ed.tl, app.sim, app.sim.t);
},

sim_ed.simulation_state = simulation_status::finish_requiring;
return ret.error();
}
[&](simulation::part type, simulation::model_error* ptr) noexcept {
auto& app = container_of(&sim_ed, &application::simulation_ed);
sim_ed.simulation_state = simulation_status::finish_requiring;
success = false;

app.notifications.try_insert(
log_level::error, [&](auto& t, auto& msg) noexcept {
t = "Simulation debug task run error";

if (ptr)
format(msg,
"Model error in part {}",
simulation_part_names[ordinal(type)]);
else
format(msg,
"Error in part {}",
simulation_part_names[ordinal(type)]);
});
},

return success();
[&] {
auto& app = container_of(&sim_ed, &application::simulation_ed);
sim_ed.simulation_state = simulation_status::finish_requiring;
success = false;

app.notifications.try_insert(
log_level::error, [&](auto& t, auto& /*msg*/) noexcept {
t = "Simulation debug task run error";
});
});

return success;
}

static status run(simulation_editor& sim_ed) noexcept
static bool run(simulation_editor& sim_ed) noexcept
{
auto& app = container_of(&sim_ed, &application::simulation_ed);
auto success = true;

if (auto ret = app.sim.run(); !ret) {
app.notifications.try_insert(
log_level::error,
[&](auto& t, auto&) noexcept { t = "Simulation task run error"; });
attempt_all(
[&] {
auto& app = container_of(&sim_ed, &application::simulation_ed);
return app.sim.run();
},

sim_ed.simulation_state = simulation_status::finish_requiring;
return ret.error();
}
[&](simulation::part type, simulation::model_error* ptr) noexcept {
auto& app = container_of(&sim_ed, &application::simulation_ed);
sim_ed.simulation_state = simulation_status::finish_requiring;
success = false;

app.notifications.try_insert(
log_level::error, [&](auto& t, auto& msg) noexcept {
t = "Simulation task run error";

if (ptr)
format(msg,
"Model error in part {}",
simulation_part_names[ordinal(type)]);
else
format(msg,
"Error in part {}",
simulation_part_names[ordinal(type)]);
});
},

return success();
[&] {
auto& app = container_of(&sim_ed, &application::simulation_ed);
sim_ed.simulation_state = simulation_status::finish_requiring;
success = false;

app.notifications.try_insert(log_level::error,
[&](auto& t, auto& /*msg*/) noexcept {
t = "Simulation task run error";
});
});

return success;
}

void simulation_editor::start_simulation_static_run() noexcept
Expand Down
50 changes: 25 additions & 25 deletions lib/include/irritator/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6195,38 +6195,38 @@ inline status hsm_wrapper::transition(simulation& sim,
hierarchical_state_machine::event_type::internal, exec));
}

auto old_state = exec.current_state;
while (old_state != exec.current_state) {
if (exec.messages > 0) {
sigma = time_domain<time>::zero;
return success();
}
// for (;;) {
if (exec.messages > 0) {
sigma = time_domain<time>::zero;
return success();
}

if (exec.current_state ==
hierarchical_state_machine::invalid_state_id or
machine->states[exec.current_state].is_terminal())
return success();
sigma = time_domain<time>::infinity;
if (exec.current_state == hierarchical_state_machine::invalid_state_id or
machine->states[exec.current_state].is_terminal())
return success();

switch (machine->states[exec.current_state].condition.type) {
case hierarchical_state_machine::condition_type::sigma:
sigma = exec.timer;
return success();
switch (machine->states[exec.current_state].condition.type) {
case hierarchical_state_machine::condition_type::sigma:
sigma = exec.timer;
return success();

case irt::hierarchical_state_machine::condition_type::port:
sigma = time_domain<time>::infinity;
return success();
case irt::hierarchical_state_machine::condition_type::port:
sigma = time_domain<time>::infinity;
return success();

default:
irt_check(machine->dispatch(
hierarchical_state_machine::event_type::internal, exec));
break;
}
default: {
const auto old = exec.current_state;
irt_check(machine->dispatch(
hierarchical_state_machine::event_type::internal, exec));

old_state = exec.current_state;
if (old == exec.current_state)
return new_error(simulation::part::hsms, simulation::model_error{});
} break;
}
// }

sigma = time_domain<time>::infinity;
return new_error(simulation::part::hsms, simulation::model_error{});
return success();
}

inline status hsm_wrapper::lambda(simulation& sim) noexcept
Expand Down

0 comments on commit f08c2ff

Please sign in to comment.