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
*model,
[this, &new_cluster]<typename Dynamics>(Dynamics& dyn) {
if constexpr (is_detected_v<has_input_port_t, Dynamics>) {
for (sz i = 0u, e = std::size(dyn.x); i != e; ++i) {
for (const auto& elem : dyn.x[i].connections) {
for (auto& elem : dyn.x) {
for (const auto& elem : elem.connections) {
auto* src = sim.models.try_to_get(elem.model);
if (src &&
is_in_hierarchy(new_cluster,
......@@ -276,8 +276,8 @@ editor::group(const ImVector<int>& nodes) noexcept
if constexpr (is_detected_v<has_output_port_t,
Dynamics>) {
for (sz i = 0u, e = std::size(dyn.y); i != e; ++i) {
for (const auto& elem : dyn.y[i].connections) {
for (auto& y_ : dyn.y) {
for (const auto& elem : y_.connections) {
auto* src = sim.models.try_to_get(elem.model);
if (src &&
is_in_hierarchy(new_cluster,
......@@ -304,8 +304,7 @@ editor::group(const ImVector<int>& nodes) noexcept
Dynamics& dyn) {
if constexpr (is_detected_v<has_input_port_t,
Dynamics>) {
for (sz i = 0u, e = std::size(dyn.x); i != e;
++i) {
for (auto& x_ : dyn.x) {
for (const auto& elem :
dyn.x[model_port.port_index]
.connections) {
......@@ -337,8 +336,7 @@ editor::group(const ImVector<int>& nodes) noexcept
Dynamics& dyn) {
if constexpr (is_detected_v<has_output_port_t,
Dynamics>) {
for (sz i = 0u, e = std::size(dyn.y); i != e;
++i) {
for (auto& _y : dyn.y) {
for (const auto& elem :
dyn.y[model_port.port_index]
.connections) {
......@@ -624,17 +622,25 @@ struct copier
auto& new_dyn = sim.alloc<Dynamics>();
*mdl_id_dst = sim.get_id(new_dyn);
if constexpr (is_detected_v<has_input_port_t, Dynamics>)
for (sz j = 0u, ej = std::size(new_dyn.x); j != ej; ++j)
if constexpr (is_detected_v<has_input_port_t, Dynamics>) {
int j = 0;
for (auto& elem : new_dyn.x) {
this->c_input_ports.emplace_back(
make_input_node_id(sim.models.get_id(mdl), (int)j),
make_input_node_id(*mdl_id_dst, (int)j));
make_input_node_id(sim.models.get_id(mdl), j),
make_input_node_id(*mdl_id_dst, j));
++j;
}
}
if constexpr (is_detected_v<has_output_port_t, Dynamics>)
for (sz j = 0, ej = std::size(new_dyn.y); j != ej; ++j)
if constexpr (is_detected_v<has_output_port_t, Dynamics>) {
int j = 0;
for (auto& elem : new_dyn.y) {
this->c_output_ports.emplace_back(
make_output_node_id(sim.models.get_id(mdl), (int)j),
make_input_node_id(*mdl_id_dst, (int)j));
make_output_node_id(sim.models.get_id(mdl), j),
make_input_node_id(*mdl_id_dst, j));
++j;
}
}
return status::success;
});
......@@ -784,8 +790,8 @@ compute_connection_distance(const model& mdl, editor& ed, const float k)
ed.sim.dispatch(
mdl, [&mdl, &ed, k]<typename Dynamics>(Dynamics& dyn) -> void {
if constexpr (is_detected_v<has_output_port_t, Dynamics>) {
for (sz i = 0, e = std::size(dyn.y); i != e; ++i)
for (auto& dst : dyn.y[i].connections)
for (auto& elem : dyn.y)
for (auto& dst : elem.connections)
compute_connection_distance(
ed.sim.get_id(mdl), dst.model, ed, k);
}
......@@ -1275,8 +1281,10 @@ show_connection(editor& ed, const model& mdl, int connection_id)
mdl,
[&ed, &mdl, &connection_id]<typename Dynamics>(Dynamics& dyn) -> void {
if constexpr (is_detected_v<has_output_port_t, Dynamics>) {
for (sz i = 0, e = std::size(dyn.y); i != e; ++i) {
int out = make_output_node_id(ed.sim.get_id(dyn), (int)i);
int i = 0;
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) {
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)
ImNodes::Link(connection_id++, out, in);
}
}
++i;
}
}
});
......@@ -1367,7 +1377,8 @@ add_input_attribute(editor& ed, const Dynamics& dyn) noexcept
if constexpr (is_detected_v<has_input_port_t, 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);
const auto& mdl = get_model(dyn);
const auto mdl_id = ed.sim.models.get_id(mdl);
......@@ -1378,6 +1389,7 @@ add_input_attribute(editor& ed, const Dynamics& dyn) noexcept
ImNodesPinShape_TriangleFilled);
ImGui::TextUnformatted(names[i]);
ImNodes::EndInputAttribute();
++i;
}
}
}
......@@ -1389,9 +1401,9 @@ add_output_attribute(editor& ed, const Dynamics& dyn) noexcept
if constexpr (is_detected_v<has_output_port_t, 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);
const auto& mdl = get_model(dyn);
const auto mdl_id = ed.sim.models.get_id(mdl);
......@@ -1401,6 +1413,7 @@ add_output_attribute(editor& ed, const Dynamics& dyn) noexcept
ImNodesPinShape_TriangleFilled);
ImGui::TextUnformatted(names[i]);
ImNodes::EndOutputAttribute();
++i;
}
}
}
......@@ -2362,8 +2375,9 @@ static status
make_input_tooltip(Dynamics& dyn, std::string& out)
{
if constexpr (is_detected_v<has_input_port_t, Dynamics>) {
for (size_t i = 0, e = std::size(dyn.x); i != e; ++i) {
if (dyn.x[i].messages.empty())
sz i = 0;
for (auto& elem : dyn.x) {
if (elem.messages.empty())
continue;
fmt::format_to(std::back_inserter(out), "x[{}]: ", i);
......@@ -2391,6 +2405,8 @@ make_input_tooltip(Dynamics& dyn, std::string& out)
break;
}
}
++i;
}
}
......@@ -2786,8 +2802,8 @@ editor::show_editor() noexcept
&link_id_to_delete]<typename Dynamics>(Dynamics& dyn) {
if constexpr (is_detected_v<has_output_port_t,
Dynamics>) {
for (sz j = 0, e = std::size(dyn.y); j != e;
++j) {
int j = 0;
for (auto& elem : dyn.y) {
for (const auto& elem :
dyn.y[j].connections) {
if (current_link_id ==
......@@ -2809,6 +2825,8 @@ editor::show_editor() noexcept
++current_link_id;
}
++j;
}
}
});
......
......@@ -3372,24 +3372,34 @@ struct port
{
shared_flat_list<node> connections;
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
{
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
......@@ -6819,13 +6829,13 @@ public:
*mdl,
[]<typename Dynamics>([[maybe_unused]] Dynamics& dyn) -> void {
if constexpr (is_detected_v<has_input_port_t, Dynamics>) {
for (sz i = 0; i < std::size(dyn.x); ++i)
dyn.x[i].messages.clear();
for (auto& elem : dyn.x)
elem.messages.clear();
}
if constexpr (is_detected_v<has_output_port_t, Dynamics>) {
for (sz i = 0; i < std::size(dyn.y); ++i)
dyn.y[i].messages.clear();
for (auto& elem : dyn.y)
elem.messages.clear();
}
});
}
......@@ -6876,15 +6886,13 @@ public:
dyn.archive.set_allocator(&flat_double_list_shared_allocator);
if constexpr (is_detected_v<has_input_port_t, Dynamics>) {
for (size_t i = 0, e = std::size(dyn.x); i != e; ++i) {
dyn.x[i].messages.set_allocator(&message_list_allocator);
}
for (auto& elem : dyn.x)
elem.messages.set_allocator(&message_list_allocator);
}
if constexpr (is_detected_v<has_output_port_t, Dynamics>) {
for (size_t i = 0, e = std::size(dyn.y); i != e; ++i) {
dyn.y[i].messages.set_allocator(&message_list_allocator);
}
for (auto& elem : dyn.y)
elem.messages.set_allocator(&message_list_allocator);
}
return dyn;
......@@ -6911,14 +6919,13 @@ public:
dyn.archive.set_allocator(&flat_double_list_shared_allocator);
if constexpr (is_detected_v<has_input_port_t, Dynamics>) {
for (size_t i = 0, e = std::size(dyn.x); i != e; ++i) {
dyn.x[i].messages.set_allocator(&message_list_allocator);
}
for (auto& elem : dyn.x)
elem.messages.set_allocator(&message_list_allocator);
}
if constexpr (is_detected_v<has_output_port_t, Dynamics>) {
for (size_t i = 0, e = std::size(dyn.y); i != e; ++i) {
dyn.y[i].messages.set_allocator(&message_list_allocator);
for (auto& elem : dyn.y) {
elem.messages.set_allocator(&message_list_allocator);
}
}
});
......@@ -6959,40 +6966,44 @@ public:
if constexpr (is_detected_v<has_output_port_t, Dynamics>) {
auto& mdl_src = get_model(dyn);
for (int i = 0, e = (int)std::size(dyn.y); i != e; ++i) {
while (!dyn.y[i].connections.empty()) {
int i = 0;
for (auto& elem : dyn.y) {
while (!elem.connections.empty()) {
auto* mdl_dst =
models.try_to_get(dyn.y[i].connections.front().model);
models.try_to_get(elem.connections.front().model);
if (mdl_dst) {
disconnect(mdl_src,
i,
*mdl_dst,
dyn.y[i].connections.front().port_index);
elem.connections.front().port_index);
}
}
dyn.y[i].connections.clear(node_list_allocator);
dyn.y[i].messages.clear();
elem.connections.clear(node_list_allocator);
elem.messages.clear();
++i;
}
}
if constexpr (is_detected_v<has_input_port_t, Dynamics>) {
auto& mdl_dst = get_model(dyn);
for (int i = 0, e = (int)std::size(dyn.x); i != e; ++i) {
while (!dyn.x[i].connections.empty()) {
int i = 0;
for (auto& elem : dyn.x) {
while (!elem.connections.empty()) {
auto* mdl_src =
models.try_to_get(dyn.x[i].connections.front().model);
models.try_to_get(elem.connections.front().model);
if (mdl_src) {
disconnect(*mdl_src,
dyn.x[i].connections.front().port_index,
elem.connections.front().port_index,
mdl_dst,
i);
}
}
dyn.x[i].connections.clear(node_list_allocator);
dyn.x[i].messages.clear();
elem.connections.clear(node_list_allocator);
elem.messages.clear();
++i;
}
}
......@@ -7090,9 +7101,20 @@ public:
return dispatch(
src, [port_src, &p]<typename Dynamics>(Dynamics& dyn) -> status {
if constexpr (is_detected_v<has_input_port_t, Dynamics>) {
if (port_src >= 0 && port_src < (int)std::size(dyn.x)) {
p = &dyn.x[port_src];
return status::success;
if constexpr (std::is_same_v<none, Dynamics>) {
auto it = dyn.x.begin();
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:
return dispatch(
dst, [port_dst, &p]<typename Dynamics>(Dynamics& dyn) -> status {
if constexpr (is_detected_v<has_output_port_t, Dynamics>) {
if (port_dst >= 0 && port_dst < (int)std::size(dyn.y)) {
p = &dyn.y[port_dst];
return status::success;
if constexpr (std::is_same_v<none, Dynamics>) {
auto it = dyn.y.begin();
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:
irt_return_if_bad(dyn.transition(t, t - mdl.tl, mdl.tn - t));
if constexpr (is_detected_v<has_input_port_t, Dynamics>)
for (size_t i = 0, e = std::size(dyn.x); i != e; ++i)
dyn.x[i].messages.clear();
for (auto& elem : dyn.x)
elem.messages.clear();
irt_assert(mdl.tn >= t);
......
......@@ -507,8 +507,8 @@ private:
position() noexcept = default;
position(const float x_, const float y_) noexcept
: x(x_)
, y(y_)
: x(x_)
, y(y_)
{}
float x, y;
......@@ -550,9 +550,8 @@ public:
position get_position(const sz index) const noexcept
{
return index < positions.size() ?
positions[index] :
position{ 0.f, 0.f };
return index < positions.size() ? positions[index]
: position{ 0.f, 0.f };
}
status operator()(simulation& sim, external_source& srcs) noexcept
......@@ -1599,16 +1598,17 @@ struct writer
sim.dispatch(
*mdl, [this, &sim, &mdl]<typename Dynamics>(Dynamics& dyn) {
if constexpr (is_detected_v<has_output_port_t, Dynamics>) {
for (size_t i = 0, e = std::size(dyn.y); i != e; ++i) {
for (const auto& elem : dyn.y[i].connections) {
auto* dst = sim.models.try_to_get(elem.model);
int i = 0;
for (auto& elem : dyn.y) {
for (const auto& cnt : elem.connections) {
auto* dst = sim.models.try_to_get(cnt.model);
if (dst) {
auto it_out =
std::find(map.begin(),
map.end(),
sim.models.get_id(*mdl));
auto it_in = std::find(
map.begin(), map.end(), elem.model);
map.begin(), map.end(), cnt.model);
irt_assert(it_out != map.end());
irt_assert(it_in != map.end());
......@@ -1616,9 +1616,11 @@ struct writer
os << std::distance(map.begin(), it_out)
<< ' ' << i << ' '
<< std::distance(map.begin(), it_in) << ' '
<< elem.port_index << '\n';
<< cnt.port_index << '\n';
}
}
++i;
}
}
});
......@@ -2125,18 +2127,21 @@ public:
sim.dispatch(
*mdl, [this, &sim, &mdl]<typename Dynamics>(Dynamics& dyn) {
if constexpr (is_detected_v<has_output_port_t, Dynamics>) {
for (size_t i = 0, e = std::size(dyn.y); i != e; ++i) {
for (const auto& elem : dyn.y[i].connections) {
auto* dst = sim.models.try_to_get(elem.model);
int i = 0;
for (auto& elem : dyn.y) {
for (const auto& cnt : elem.connections) {
auto* dst = sim.models.try_to_get(cnt.model);
if (dst) {
auto src_id = sim.models.get_id(*mdl);
os << irt::get_key(src_id) << " -> "
<< irt::get_key(elem.model) << " [label=\""
<< i << " - " << elem.port_index
<< irt::get_key(cnt.model) << " [label=\""
<< i << " - " << cnt.port_index
<< "\"];\n";
}
}
++i;
}
}
});
......
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