Merge links into nodes: link registration dual code path - #1550
Merge links into nodes: link registration dual code path#1550Jerry-Jinfeng-Guo wants to merge 19 commits into
Conversation
Bumps the all-dependencies group with 1 update: [astral-sh/setup-uv](https://github.com/astral-sh/setup-uv). Updates `astral-sh/setup-uv` from 9.0.0 to 10.0.1 - [Release notes](https://github.com/astral-sh/setup-uv/releases) - [Commits](astral-sh/setup-uv@c771a70...20cfd1b) --- updated-dependencies: - dependency-name: astral-sh/setup-uv dependency-version: 10.0.1 dependency-type: direct:production update-type: version-update:semver-major dependency-group: all-dependencies ... Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Jerry Jinfeng Guo <jerry.jinfeng.guo@alliander.com>
|
This PR is blocked by #1545 due to the link output being necessary in |
@Jerry-Jinfeng-Guo #1545 is now in merge queue. That should get you unblocked. |
Signed-off-by: Jerry Guo <guojinfeng8621@gmail.com>
…iling Signed-off-by: Jerry Guo <guojinfeng8621@gmail.com>
Signed-off-by: Jerry Guo <6221579+Jerry-Jinfeng-Guo@users.noreply.github.com>
Signed-off-by: Jerry Guo <guojinfeng8621@gmail.com>
Signed-off-by: Santiago Figueroa Manrique <santiago.figueroa.manrique@alliander.com>
Signed-off-by: Santiago Figueroa Manrique <santiago.figueroa.manrique@alliander.com>
Signed-off-by: Nitish Bharambe <nitish.bharambe@alliander.com>
Signed-off-by: Santiago Figueroa Manrique <santiago.figueroa.manrique@alliander.com>
| @@ -154,9 +158,14 @@ inline TopologicalNodesAndCoupling create_topological_nodes(ComponentTopology co | |||
| return Idx2D{.group = disconnected, .pos = disconnected}; | |||
| } | |||
|
|
|||
| // early out if either is disconnected since the link solver doesn't consume semi-disconnected links | |||
| if (from_conn == disconnected || to_conn == disconnected) { | |||
| return Idx2D{.group = topo_node, .pos = disconnected}; | |||
| } | |||
|
|
|||
There was a problem hiding this comment.
Two bugs are in here. This is consumed by the link solver algorithm, but it doesn't understand disconnected sides of a link, and that breaks its premise. In addition, the "enumeration" that was coming from the user nodes (i.e. links per supernode being numbered [{{0, 1},{2, 3}}, {4, 5}] instead of [{{0, 1},{2, 3}}, {0, 1}]), was not suitable either.
This is a bit of a hacky fix, as now user_links doesn't really contain the user links indexed by the user nodes, but rather it's own indexing per super node. That said, I added it here to attempt the fix. Since this works, it's probably a better idea to put it where the link solver algorithm consumes user links or elsewhere; this only works because currently user_links isn't consumed elsewhere besides for the link solver algorithm (we can probably delete it in the final clean up for v2).
| @@ -165,7 +165,7 @@ TEST_CASE("Test Supernodes") { | |||
| CHECK(std::ranges::equal( | |||
| topo_nodes.topo_nodes | | |||
| std::views::transform([](TopologicalNode const& node) -> auto& { return node.user_links; }), | |||
| std::vector<std::vector<BranchIdx>>{{{0, disconnected}}, {{disconnected, 1}}, {{2, 4}}, {}, {}})); | |||
| std::vector<std::vector<BranchIdx>>{{{0, disconnected}}, {{disconnected, 0}}, {{0, 1}}, {}, {}})); | |||
There was a problem hiding this comment.
These result from https://github.com/PowerGridModel/power-grid-model/pull/1550/changes#r3921543997, hence you can see here it's hacky.
| auto const user_node_idx = state.components.template get_seq<Node>(fault.get_fault_object()); | ||
| auto const topo_node_idx = | ||
| state.reduced_topology->topo_node_coup.coupling.user_nodes_to_topo_nodes[user_node_idx].group; | ||
| auto const topo_bus_idx = state.topo_comp_coup->node[topo_node_idx]; |
There was a problem hiding this comment.
This is the SC bug. Wrong mapping was used.
| @@ -146,9 +146,9 @@ constexpr auto output_result(Component const& link, MainModelState<ComponentCont | |||
| } | |||
| template <std::same_as<Link> Component, class ComponentContainer, short_circuit_solver_output_type SolverOutputType> | |||
| requires model_component_state_c<MainModelState, ComponentContainer, Component> | |||
| inline auto output_result(Component const& link, MainModelState<ComponentContainer> const& /* state */, | |||
| inline auto output_result(Component const& link, MainModelState<ComponentContainer> const& state, | |||
| MathOutput<std::vector<SolverOutputType>> const& math_output, Idx2D const& topo_id) { | |||
| if (topo_id.group == disconnected) { | |||
| if (topo_id.group == disconnected || state.topo_comp_coup->node[topo_id.group].group == disconnected) { | |||
There was a problem hiding this comment.
This was another bug. The output didn't understand that a link was not energized if it's statuses where on but it wasn't connected to a source.
| template <std::same_as<Link> Component, class ComponentContainer> | ||
| requires model_component_state_c<MainModelState, ComponentContainer, Component> | ||
| constexpr auto comp_base_sequence_cbegin(MainModelState<ComponentContainer> const& state) { | ||
| auto const& link_topo_ids = state.reduced_topology->topo_node_coup.coupling.user_links_to_topo_nodes; | ||
|
|
||
| if (std::ranges::ssize(link_topo_ids) == get_component_size<Link>(state.components)) { | ||
| // new path: links are not branches | ||
| return link_topo_ids.cbegin(); | ||
| } else { | ||
| // legacy path: links are branches | ||
| return state.topo_comp_coup->branch.cbegin() + get_component_sequence_offset<Edge, Link>(state.components); | ||
| } |
There was a problem hiding this comment.
The rest of the issues so far, were related to the "two-path dispatch", similar to this. Where in the old path Branches included links, so the offset was different to the new path (or the container to use was different), where branches and links are separated.
I think it's good that we spam TODOs in every such two-code-path place introduced here, so we can easily pinpoint for the cleanup after v2.
Signed-off-by: Jerry Jinfeng Guo <jerry.jinfeng.guo@alliander.com>
Signed-off-by: Jerry Jinfeng Guo <jerry.jinfeng.guo@alliander.com>
Signed-off-by: Jerry Jinfeng Guo <jerry.jinfeng.guo@alliander.com>
Signed-off-by: Jerry Jinfeng Guo <jerry.jinfeng.guo@alliander.com>
…e-after-merging Merge links into nodes: update pf and sc tests
Signed-off-by: Jerry Jinfeng Guo <jerry.jinfeng.guo@alliander.com>
Signed-off-by: Jerry Jinfeng Guo <jerry.jinfeng.guo@alliander.com>
Based on the presence of node injection sensors, this PR adds two Link registration path:
Whether this will go forward depends on the outcome of offline discussion.