Commit 0904763c authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

core: add component data into none model

parent c61e82af
Pipeline #34873 passed with stage
in 1 minute and 22 seconds
...@@ -261,8 +261,8 @@ editor::group(const ImVector<int>& nodes) noexcept ...@@ -261,8 +261,8 @@ editor::group(const ImVector<int>& nodes) noexcept
*model, *model,
[this, &new_cluster]<typename Dynamics>(Dynamics& dyn) { [this, &new_cluster]<typename Dynamics>(Dynamics& dyn) {
if constexpr (is_detected_v<has_input_port_t, Dynamics>) { if constexpr (is_detected_v<has_input_port_t, Dynamics>) {
for (sz i = 0u, e = std::size(dyn.x); i != e; ++i) { for (auto& elem : dyn.x) {
for (const auto& elem : dyn.x[i].connections) { for (const auto& elem : elem.connections) {
auto* src = sim.models.try_to_get(elem.model); auto* src = sim.models.try_to_get(elem.model);
if (src && if (src &&
is_in_hierarchy(new_cluster, is_in_hierarchy(new_cluster,
...@@ -276,8 +276,8 @@ editor::group(const ImVector<int>& nodes) noexcept ...@@ -276,8 +276,8 @@ editor::group(const ImVector<int>& nodes) noexcept
if constexpr (is_detected_v<has_output_port_t, if constexpr (is_detected_v<has_output_port_t,
Dynamics>) { Dynamics>) {
for (sz i = 0u, e = std::size(dyn.y); i != e; ++i) { for (auto& y_ : dyn.y) {
for (const auto& elem : dyn.y[i].connections) { for (const auto& elem : y_.connections) {
auto* src = sim.models.try_to_get(elem.model); auto* src = sim.models.try_to_get(elem.model);
if (src && if (src &&
is_in_hierarchy(new_cluster, is_in_hierarchy(new_cluster,
...@@ -304,8 +304,7 @@ editor::group(const ImVector<int>& nodes) noexcept ...@@ -304,8 +304,7 @@ editor::group(const ImVector<int>& nodes) noexcept
Dynamics& dyn) { Dynamics& dyn) {
if constexpr (is_detected_v<has_input_port_t, if constexpr (is_detected_v<has_input_port_t,
Dynamics>) { Dynamics>) {
for (sz i = 0u, e = std::size(dyn.x); i != e; for (auto& x_ : dyn.x) {
++i) {
for (const auto& elem : for (const auto& elem :
dyn.x[model_port.port_index] dyn.x[model_port.port_index]
.connections) { .connections) {
...@@ -337,8 +336,7 @@ editor::group(const ImVector<int>& nodes) noexcept ...@@ -337,8 +336,7 @@ editor::group(const ImVector<int>& nodes) noexcept
Dynamics& dyn) { Dynamics& dyn) {
if constexpr (is_detected_v<has_output_port_t, if constexpr (is_detected_v<has_output_port_t,
Dynamics>) { Dynamics>) {
for (sz i = 0u, e = std::size(dyn.y); i != e; for (auto& _y : dyn.y) {
++i) {
for (const auto& elem : for (const auto& elem :
dyn.y[model_port.port_index] dyn.y[model_port.port_index]
.connections) { .connections) {
...@@ -624,17 +622,25 @@ struct copier ...@@ -624,17 +622,25 @@ struct copier
auto& new_dyn = sim.alloc<Dynamics>(); auto& new_dyn = sim.alloc<Dynamics>();
*mdl_id_dst = sim.get_id(new_dyn); *mdl_id_dst = sim.get_id(new_dyn);
if constexpr (is_detected_v<has_input_port_t, Dynamics>) if constexpr (is_detected_v<has_input_port_t, Dynamics>) {
for (sz j = 0u, ej = std::size(new_dyn.x); j != ej; ++j) int j = 0;
for (auto& elem : new_dyn.x) {
this->c_input_ports.emplace_back( this->c_input_ports.emplace_back(
make_input_node_id(sim.models.get_id(mdl), (int)j), make_input_node_id(sim.models.get_id(mdl), j),
make_input_node_id(*mdl_id_dst, (int)j)); make_input_node_id(*mdl_id_dst, j));
++j;
}
}
if constexpr (is_detected_v<has_output_port_t, Dynamics>) if constexpr (is_detected_v<has_output_port_t, Dynamics>) {
for (sz j = 0, ej = std::size(new_dyn.y); j != ej; ++j) int j = 0;
for (auto& elem : new_dyn.y) {
this->c_output_ports.emplace_back( this->c_output_ports.emplace_back(
make_output_node_id(sim.models.get_id(mdl), (int)j), make_output_node_id(sim.models.get_id(mdl), j),
make_input_node_id(*mdl_id_dst, (int)j)); make_input_node_id(*mdl_id_dst, j));
++j;
}
}
return status::success; return status::success;
}); });
...@@ -784,8 +790,8 @@ compute_connection_distance(const model& mdl, editor& ed, const float k) ...@@ -784,8 +790,8 @@ compute_connection_distance(const model& mdl, editor& ed, const float k)
ed.sim.dispatch( ed.sim.dispatch(
mdl, [&mdl, &ed, k]<typename Dynamics>(Dynamics& dyn) -> void { mdl, [&mdl, &ed, k]<typename Dynamics>(Dynamics& dyn) -> void {
if constexpr (is_detected_v<has_output_port_t, Dynamics>) { if constexpr (is_detected_v<has_output_port_t, Dynamics>) {
for (sz i = 0, e = std::size(dyn.y); i != e; ++i) for (auto& elem : dyn.y)
for (auto& dst : dyn.y[i].connections) for (auto& dst : elem.connections)
compute_connection_distance( compute_connection_distance(
ed.sim.get_id(mdl), dst.model, ed, k); ed.sim.get_id(mdl), dst.model, ed, k);
} }
...@@ -1275,8 +1281,10 @@ show_connection(editor& ed, const model& mdl, int connection_id) ...@@ -1275,8 +1281,10 @@ show_connection(editor& ed, const model& mdl, int connection_id)
mdl, mdl,
[&ed, &mdl, &connection_id]<typename Dynamics>(Dynamics& dyn) -> void { [&ed, &mdl, &connection_id]<typename Dynamics>(Dynamics& dyn) -> void {
if constexpr (is_detected_v<has_output_port_t, Dynamics>) { if constexpr (is_detected_v<has_output_port_t, Dynamics>) {
for (sz i = 0, e = std::size(dyn.y); i != e; ++i) { int i = 0;
int out = make_output_node_id(ed.sim.get_id(dyn), (int)i);
for (auto& elem : dyn.y) {
int out = make_output_node_id(ed.sim.get_id(dyn), i);
for (const auto& c : dyn.y[i].connections) { for (const auto& c : dyn.y[i].connections) {
if (auto* mdl_dst = ed.sim.models.try_to_get(c.model); if (auto* mdl_dst = ed.sim.models.try_to_get(c.model);
...@@ -1285,6 +1293,8 @@ show_connection(editor& ed, const model& mdl, int connection_id) ...@@ -1285,6 +1293,8 @@ show_connection(editor& ed, const model& mdl, int connection_id)
ImNodes::Link(connection_id++, out, in); ImNodes::Link(connection_id++, out, in);
} }
} }
++i;
} }
} }
}); });
...@@ -1367,7 +1377,8 @@ add_input_attribute(editor& ed, const Dynamics& dyn) noexcept ...@@ -1367,7 +1377,8 @@ add_input_attribute(editor& ed, const Dynamics& dyn) noexcept
if constexpr (is_detected_v<has_input_port_t, Dynamics>) { if constexpr (is_detected_v<has_input_port_t, Dynamics>) {
const auto** names = get_input_port_names<Dynamics>(); const auto** names = get_input_port_names<Dynamics>();
for (size_t i = 0, e = std::size(dyn.x); i != e; ++i) { sz i = 0;
for (auto& elem : dyn.x) {
irt_assert(i < 8u); irt_assert(i < 8u);
const auto& mdl = get_model(dyn); const auto& mdl = get_model(dyn);
const auto mdl_id = ed.sim.models.get_id(mdl); const auto mdl_id = ed.sim.models.get_id(mdl);
...@@ -1378,6 +1389,7 @@ add_input_attribute(editor& ed, const Dynamics& dyn) noexcept ...@@ -1378,6 +1389,7 @@ add_input_attribute(editor& ed, const Dynamics& dyn) noexcept
ImNodesPinShape_TriangleFilled); ImNodesPinShape_TriangleFilled);
ImGui::TextUnformatted(names[i]); ImGui::TextUnformatted(names[i]);
ImNodes::EndInputAttribute(); ImNodes::EndInputAttribute();
++i;
} }
} }
} }
...@@ -1389,9 +1401,9 @@ add_output_attribute(editor& ed, const Dynamics& dyn) noexcept ...@@ -1389,9 +1401,9 @@ add_output_attribute(editor& ed, const Dynamics& dyn) noexcept
if constexpr (is_detected_v<has_output_port_t, Dynamics>) { if constexpr (is_detected_v<has_output_port_t, Dynamics>) {
const auto** names = get_output_port_names<Dynamics>(); const auto** names = get_output_port_names<Dynamics>();
for (size_t i = 0, e = std::size(dyn.y); i != e; ++i) { sz i = 0;
for (auto& elem : dyn.y) {
irt_assert(i < 8u); irt_assert(i < 8u);
const auto& mdl = get_model(dyn); const auto& mdl = get_model(dyn);
const auto mdl_id = ed.sim.models.get_id(mdl); const auto mdl_id = ed.sim.models.get_id(mdl);
...@@ -1401,6 +1413,7 @@ add_output_attribute(editor& ed, const Dynamics& dyn) noexcept ...@@ -1401,6 +1413,7 @@ add_output_attribute(editor& ed, const Dynamics& dyn) noexcept
ImNodesPinShape_TriangleFilled); ImNodesPinShape_TriangleFilled);
ImGui::TextUnformatted(names[i]); ImGui::TextUnformatted(names[i]);
ImNodes::EndOutputAttribute(); ImNodes::EndOutputAttribute();
++i;
} }
} }
} }
...@@ -2362,8 +2375,9 @@ static status ...@@ -2362,8 +2375,9 @@ static status
make_input_tooltip(Dynamics& dyn, std::string& out) make_input_tooltip(Dynamics& dyn, std::string& out)
{ {
if constexpr (is_detected_v<has_input_port_t, Dynamics>) { if constexpr (is_detected_v<has_input_port_t, Dynamics>) {
for (size_t i = 0, e = std::size(dyn.x); i != e; ++i) { sz i = 0;
if (dyn.x[i].messages.empty()) for (auto& elem : dyn.x) {
if (elem.messages.empty())
continue; continue;
fmt::format_to(std::back_inserter(out), "x[{}]: ", i); fmt::format_to(std::back_inserter(out), "x[{}]: ", i);
...@@ -2391,6 +2405,8 @@ make_input_tooltip(Dynamics& dyn, std::string& out) ...@@ -2391,6 +2405,8 @@ make_input_tooltip(Dynamics& dyn, std::string& out)
break; break;
} }
} }
++i;
} }
} }
...@@ -2786,8 +2802,8 @@ editor::show_editor() noexcept ...@@ -2786,8 +2802,8 @@ editor::show_editor() noexcept
&link_id_to_delete]<typename Dynamics>(Dynamics& dyn) { &link_id_to_delete]<typename Dynamics>(Dynamics& dyn) {
if constexpr (is_detected_v<has_output_port_t, if constexpr (is_detected_v<has_output_port_t,
Dynamics>) { Dynamics>) {
for (sz j = 0, e = std::size(dyn.y); j != e; int j = 0;
++j) { for (auto& elem : dyn.y) {
for (const auto& elem : for (const auto& elem :
dyn.y[j].connections) { dyn.y[j].connections) {
if (current_link_id == if (current_link_id ==
...@@ -2809,6 +2825,8 @@ editor::show_editor() noexcept ...@@ -2809,6 +2825,8 @@ editor::show_editor() noexcept
++current_link_id; ++current_link_id;
} }
++j;
} }
} }
}); });
......
...@@ -3372,24 +3372,34 @@ struct port ...@@ -3372,24 +3372,34 @@ struct port
{ {
shared_flat_list<node> connections; shared_flat_list<node> connections;
flat_list<message> messages; flat_list<message> messages;
// message* output = nullptr;
// port& operator=(const double v) noexcept
// {
// output[0] = v;
// return *this;
// }
// port& operator=(const std::initializer_list<double>& v) noexcept
// {
// std::copy_n(std::data(v), std::size(v), &output->real[0]);
// return *this;
// }
}; };
struct component_port
{
shared_flat_list<node> connections;
flat_list<message> messages;
};
/**
* @brief Useless for user
*
* @c none model does not have dynamics. It is use internally to develop the
* component part of the irritator gui. @c none is a component. A component
* stores children as a list of @c model_id, parameters and observable as a list
* of @c model_id and two @c component_port for the input and output port (the
* part of the public interface).
*/
struct none struct none
{ {
time sigma = time_domain<time>::infinity; time sigma = time_domain<time>::infinity;
shared_flat_list<model_id> children;
shared_flat_list<model_id> parameters;
shared_flat_list<model_id> observables;
shared_flat_list<port> x;
shared_flat_list<port> y;
shared_flat_list<node> internal_x;
shared_flat_list<node> internal_y;
}; };
struct integrator struct integrator
...@@ -6819,13 +6829,13 @@ public: ...@@ -6819,13 +6829,13 @@ public:
*mdl, *mdl,
[]<typename Dynamics>([[maybe_unused]] Dynamics& dyn) -> void { []<typename Dynamics>([[maybe_unused]] Dynamics& dyn) -> void {
if constexpr (is_detected_v<has_input_port_t, Dynamics>) { if constexpr (is_detected_v<has_input_port_t, Dynamics>) {
for (sz i = 0; i < std::size(dyn.x); ++i) for (auto& elem : dyn.x)
dyn.x[i].messages.clear(); elem.messages.clear();
} }
if constexpr (is_detected_v<has_output_port_t, Dynamics>) { if constexpr (is_detected_v<has_output_port_t, Dynamics>) {
for (sz i = 0; i < std::size(dyn.y); ++i) for (auto& elem : dyn.y)
dyn.y[i].messages.clear(); elem.messages.clear();
} }
}); });
} }
...@@ -6876,15 +6886,13 @@ public: ...@@ -6876,15 +6886,13 @@ public:
dyn.archive.set_allocator(&flat_double_list_shared_allocator); dyn.archive.set_allocator(&flat_double_list_shared_allocator);
if constexpr (is_detected_v<has_input_port_t, Dynamics>) { if constexpr (is_detected_v<has_input_port_t, Dynamics>) {
for (size_t i = 0, e = std::size(dyn.x); i != e; ++i) { for (auto& elem : dyn.x)
dyn.x[i].messages.set_allocator(&message_list_allocator); elem.messages.set_allocator(&message_list_allocator);
}
} }
if constexpr (is_detected_v<has_output_port_t, Dynamics>) { if constexpr (is_detected_v<has_output_port_t, Dynamics>) {
for (size_t i = 0, e = std::size(dyn.y); i != e; ++i) { for (auto& elem : dyn.y)
dyn.y[i].messages.set_allocator(&message_list_allocator); elem.messages.set_allocator(&message_list_allocator);
}
} }
return dyn; return dyn;
...@@ -6911,14 +6919,13 @@ public: ...@@ -6911,14 +6919,13 @@ public:
dyn.archive.set_allocator(&flat_double_list_shared_allocator); dyn.archive.set_allocator(&flat_double_list_shared_allocator);
if constexpr (is_detected_v<has_input_port_t, Dynamics>) { if constexpr (is_detected_v<has_input_port_t, Dynamics>) {
for (size_t i = 0, e = std::size(dyn.x); i != e; ++i) { for (auto& elem : dyn.x)
dyn.x[i].messages.set_allocator(&message_list_allocator); elem.messages.set_allocator(&message_list_allocator);
}
} }
if constexpr (is_detected_v<has_output_port_t, Dynamics>) { if constexpr (is_detected_v<has_output_port_t, Dynamics>) {
for (size_t i = 0, e = std::size(dyn.y); i != e; ++i) { for (auto& elem : dyn.y) {
dyn.y[i].messages.set_allocator(&message_list_allocator); elem.messages.set_allocator(&message_list_allocator);
} }
} }
}); });
...@@ -6959,40 +6966,44 @@ public: ...@@ -6959,40 +6966,44 @@ public:
if constexpr (is_detected_v<has_output_port_t, Dynamics>) { if constexpr (is_detected_v<has_output_port_t, Dynamics>) {
auto& mdl_src = get_model(dyn); auto& mdl_src = get_model(dyn);
for (int i = 0, e = (int)std::size(dyn.y); i != e; ++i) { int i = 0;
while (!dyn.y[i].connections.empty()) { for (auto& elem : dyn.y) {
while (!elem.connections.empty()) {
auto* mdl_dst = auto* mdl_dst =
models.try_to_get(dyn.y[i].connections.front().model); models.try_to_get(elem.connections.front().model);
if (mdl_dst) { if (mdl_dst) {
disconnect(mdl_src, disconnect(mdl_src,
i, i,
*mdl_dst, *mdl_dst,
dyn.y[i].connections.front().port_index); elem.connections.front().port_index);
} }
} }
dyn.y[i].connections.clear(node_list_allocator); elem.connections.clear(node_list_allocator);
dyn.y[i].messages.clear(); elem.messages.clear();
++i;
} }
} }
if constexpr (is_detected_v<has_input_port_t, Dynamics>) { if constexpr (is_detected_v<has_input_port_t, Dynamics>) {
auto& mdl_dst = get_model(dyn); auto& mdl_dst = get_model(dyn);
for (int i = 0, e = (int)std::size(dyn.x); i != e; ++i) { int i = 0;
while (!dyn.x[i].connections.empty()) { for (auto& elem : dyn.x) {
while (!elem.connections.empty()) {
auto* mdl_src = auto* mdl_src =
models.try_to_get(dyn.x[i].connections.front().model); models.try_to_get(elem.connections.front().model);
if (mdl_src) { if (mdl_src) {
disconnect(*mdl_src, disconnect(*mdl_src,
dyn.x[i].connections.front().port_index, elem.connections.front().port_index,
mdl_dst, mdl_dst,
i); i);
} }
} }
dyn.x[i].connections.clear(node_list_allocator); elem.connections.clear(node_list_allocator);
dyn.x[i].messages.clear(); elem.messages.clear();
++i;
} }
} }
...@@ -7090,9 +7101,20 @@ public: ...@@ -7090,9 +7101,20 @@ public:
return dispatch( return dispatch(
src, [port_src, &p]<typename Dynamics>(Dynamics& dyn) -> status { src, [port_src, &p]<typename Dynamics>(Dynamics& dyn) -> status {
if constexpr (is_detected_v<has_input_port_t, Dynamics>) { if constexpr (is_detected_v<has_input_port_t, Dynamics>) {
if (port_src >= 0 && port_src < (int)std::size(dyn.x)) { if constexpr (std::is_same_v<none, Dynamics>) {
p = &dyn.x[port_src]; auto it = dyn.x.begin();
return status::success; for (int i = 0; i < port_src && it != dyn.x.end(); ++i)
++it;
if (it != dyn.x.end()) {
p = &(*it);
return status::success;
}
} else {
if (port_src >= 0 && port_src < length(dyn.x)) {
p = &dyn.x[port_src];
return status::success;
}
} }
} }
...@@ -7105,9 +7127,20 @@ public: ...@@ -7105,9 +7127,20 @@ public:
return dispatch( return dispatch(
dst, [port_dst, &p]<typename Dynamics>(Dynamics& dyn) -> status { dst, [port_dst, &p]<typename Dynamics>(Dynamics& dyn) -> status {
if constexpr (is_detected_v<has_output_port_t, Dynamics>) { if constexpr (is_detected_v<has_output_port_t, Dynamics>) {
if (port_dst >= 0 && port_dst < (int)std::size(dyn.y)) { if constexpr (std::is_same_v<none, Dynamics>) {
p = &dyn.y[port_dst]; auto it = dyn.y.begin();
return status::success; for (int i = 0; i < port_dst && it != dyn.y.end(); ++i)
++it;
if (it != dyn.y.end()) {
p = &(*it);
return status::success;
}
} else {
if (port_dst >= 0 && port_dst < length(dyn.y)) {
p = &dyn.y[port_dst];
return status::success;
}
} }
} }
...@@ -7359,8 +7392,8 @@ public: ...@@ -7359,8 +7392,8 @@ public:
irt_return_if_bad(dyn.transition(t, t - mdl.tl, mdl.tn - t)); irt_return_if_bad(dyn.transition(t, t - mdl.tl, mdl.tn - t));
if constexpr (is_detected_v<has_input_port_t, Dynamics>) if constexpr (is_detected_v<has_input_port_t, Dynamics>)
for (size_t i = 0, e = std::size(dyn.x); i != e; ++i) for (auto& elem : dyn.x)
dyn.x[i].messages.clear(); elem.messages.clear();
irt_assert(mdl.tn >= t); irt_assert(mdl.tn >= t);
......
...@@ -507,8 +507,8 @@ private: ...@@ -507,8 +507,8 @@ private:
position() noexcept = default; position() noexcept = default;
position(const float x_, const float y_) noexcept position(const float x_, const float y_) noexcept
: x(x_) : x(x_)
, y(y_) , y(y_)
{} {}
float x, y; float x, y;
...@@ -550,9 +550,8 @@ public: ...@@ -550,9 +550,8 @@ public:
position get_position(const sz index) const noexcept position get_position(const sz index) const noexcept
{ {
return index < positions.size() ? return index < positions.size() ? positions[index]
positions[index] : : position{ 0.f, 0.f };
position{ 0.f, 0.f };
} }
status operator()(simulation& sim, external_source& srcs) noexcept status operator()(simulation& sim, external_source& srcs) noexcept
...@@ -1599,16 +1598,17 @@ struct writer ...@@ -1599,16 +1598,17 @@ struct writer
sim.dispatch( sim.dispatch(
*mdl, [this, &sim, &mdl]<typename Dynamics>(Dynamics& dyn) { *mdl, [this, &sim, &mdl]<typename Dynamics>(Dynamics& dyn) {
if constexpr (is_detected_v<has_output_port_t, Dynamics>) { if constexpr (is_detected_v<has_output_port_t, Dynamics>) {
for (size_t i = 0, e = std::size(dyn.y); i != e; ++i) { int i = 0;
for (const auto& elem : dyn.y[i].connections) { for (auto& elem : dyn.y) {
auto* dst = sim.models.try_to_get(elem.model); for (const auto& cnt : elem.connections) {
auto* dst = sim.models.try_to_get(