Commit 5ec1ff96 authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

core: add dynamics_type to observer callback

parent 607ef3d2
...@@ -230,6 +230,7 @@ struct plot_output ...@@ -230,6 +230,7 @@ struct plot_output
{} {}
void operator()(const irt::observer& obs, void operator()(const irt::observer& obs,
const irt::dynamics_type /*type*/,
const irt::time t, const irt::time t,
const irt::observer::status s); const irt::observer::status s);
...@@ -252,8 +253,9 @@ struct file_output ...@@ -252,8 +253,9 @@ struct file_output
{} {}
void operator()(const irt::observer& obs, void operator()(const irt::observer& obs,
const irt::time t, const irt::dynamics_type /*type*/,
const irt::observer::status s); const irt::time t,
const irt::observer::status s);
editor* ed = nullptr; editor* ed = nullptr;
std::ofstream ofs; std::ofstream ofs;
......
...@@ -29,6 +29,7 @@ namespace irt { ...@@ -29,6 +29,7 @@ namespace irt {
void void
plot_output::operator()(const irt::observer& obs, plot_output::operator()(const irt::observer& obs,
const irt::dynamics_type /*type*/,
const irt::time t, const irt::time t,
const irt::observer::status s) const irt::observer::status s)
{ {
...@@ -63,6 +64,7 @@ plot_output::operator()(const irt::observer& obs, ...@@ -63,6 +64,7 @@ plot_output::operator()(const irt::observer& obs,
void void
file_output::operator()(const irt::observer& obs, file_output::operator()(const irt::observer& obs,
const irt::dynamics_type /*type*/,
const irt::time t, const irt::time t,
const irt::observer::status s) const irt::observer::status s)
{ {
......
...@@ -34,6 +34,7 @@ struct file_output ...@@ -34,6 +34,7 @@ struct file_output
} }
void operator()(const irt::observer& obs, void operator()(const irt::observer& obs,
const irt::dynamics_type /*type*/,
const irt::time t, const irt::time t,
const irt::observer::status s) noexcept const irt::observer::status s) noexcept
{ {
......
...@@ -34,6 +34,7 @@ struct file_output ...@@ -34,6 +34,7 @@ struct file_output
} }
void operator()(const irt::observer& obs, void operator()(const irt::observer& obs,
const irt::dynamics_type /*type*/,
const irt::time t, const irt::time t,
const irt::observer::status s) const irt::observer::status s)
{ {
......
...@@ -34,6 +34,7 @@ struct file_output ...@@ -34,6 +34,7 @@ struct file_output
} }
void operator()(const irt::observer& obs, void operator()(const irt::observer& obs,
const irt::dynamics_type /*type*/,
const irt::time t, const irt::time t,
const irt::observer::status s) const irt::observer::status s)
{ {
......
...@@ -2477,7 +2477,8 @@ struct observer ...@@ -2477,7 +2477,8 @@ struct observer
}; };
using update_fn = using update_fn =
function_ref<void(const observer&, const time, const observer::status)>; function_ref<void(const observer&, const dynamics_type,
const time, const observer::status)>;
observer(const char* name_, update_fn cb_) noexcept observer(const char* name_, update_fn cb_) noexcept
: cb(cb_) : cb(cb_)
...@@ -6475,9 +6476,11 @@ public: ...@@ -6475,9 +6476,11 @@ public:
irt::observer* obs = nullptr; irt::observer* obs = nullptr;
while (observers.next(obs)) { while (observers.next(obs)) {
obs->tl = t; if (auto* mdl = models.try_to_get(obs->model); mdl) {
if (!obs->cb.empty()) obs->msg.reset();
obs->cb(*obs, t, observer::status::initialize); obs->cb(*obs, mdl->type, t, observer::status::initialize);
obs->tl = t;
}
} }
return status::success; return status::success;
...@@ -6585,7 +6588,7 @@ public: ...@@ -6585,7 +6588,7 @@ public:
if (mdl.obs_id != static_cast<observer_id>(0)) { if (mdl.obs_id != static_cast<observer_id>(0)) {
if (auto* obs = observers.try_to_get(mdl.obs_id); obs) { if (auto* obs = observers.try_to_get(mdl.obs_id); obs) {
obs->msg = dyn.observation(t - mdl.tl); obs->msg = dyn.observation(t - mdl.tl);
obs->cb(*obs, t, observer::status::run); obs->cb(*obs, mdl.type, t, observer::status::run);
obs->tl = t; obs->tl = t;
} else { } else {
mdl.obs_id = static_cast<observer_id>(0); mdl.obs_id = static_cast<observer_id>(0);
...@@ -6625,7 +6628,7 @@ public: ...@@ -6625,7 +6628,7 @@ public:
{ {
if constexpr (is_detected_v<observation_function_t, Dynamics>) { if constexpr (is_detected_v<observation_function_t, Dynamics>) {
obs.msg = dyn.observation(t - mdl.tl); obs.msg = dyn.observation(t - mdl.tl);
obs.cb(obs, t, observer::status::finalize); obs.cb(obs, mdl.type, t, observer::status::finalize);
obs.tl = t; obs.tl = t;
} }
} }
...@@ -6645,8 +6648,7 @@ public: ...@@ -6645,8 +6648,7 @@ public:
model* mdl = nullptr; model* mdl = nullptr;
while (models.next(mdl)) { while (models.next(mdl)) {
if (mdl->obs_id != static_cast<observer_id>(0)) { if (mdl->obs_id != static_cast<observer_id>(0)) {
if (auto* obs = observers.try_to_get(mdl->obs_id); if (auto* obs = observers.try_to_get(mdl->obs_id); obs) {
obs && !obs->cb.empty()) {
dispatch(mdl->type, dispatch(mdl->type,
[this, mdl, obs, t]<typename DynamicsModels>( [this, mdl, obs, t]<typename DynamicsModels>(
DynamicsModels& dyn_models) { DynamicsModels& dyn_models) {
......
...@@ -24,6 +24,7 @@ struct file_output ...@@ -24,6 +24,7 @@ struct file_output
{} {}
void operator()(const irt::observer& obs, void operator()(const irt::observer& obs,
const irt::dynamics_type /*type*/,
const irt::time t, const irt::time t,
const irt::observer::status s) const irt::observer::status s)
{ {
......
...@@ -33,6 +33,7 @@ struct file_output ...@@ -33,6 +33,7 @@ struct file_output
} }
void operator()(const irt::observer& obs, void operator()(const irt::observer& obs,
const irt::dynamics_type /*type*/,
const irt::time t, const irt::time t,
const irt::observer::status s) noexcept const irt::observer::status s) noexcept
{ {
...@@ -46,6 +47,7 @@ struct file_output ...@@ -46,6 +47,7 @@ struct file_output
break; break;
case irt::observer::status::finalize: case irt::observer::status::finalize:
fmt::print(os, "{},{}\n", t, obs.msg.real[0]);
break; break;
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment