diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/common/enum.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/common/enum.hpp index e24291164..2be8ac245 100644 --- a/power_grid_model_c/power_grid_model/include/power_grid_model/common/enum.hpp +++ b/power_grid_model_c/power_grid_model/include/power_grid_model/common/enum.hpp @@ -20,6 +20,32 @@ enum class BranchSide : IntS { from = 0, to = 1 }; enum class Branch3Side : IntS { side_1 = 0, side_2 = 1, side_3 = 2 }; +enum class TapSide : IntS { from = 0, to = 1, side_1 = 0, side_2 = 1, side_3 = 2 }; + +inline TapSide branch_side_to_tap_side(BranchSide branch_side) { + switch (branch_side) { + case BranchSide::from: + return TapSide::from; + case BranchSide::to: + return TapSide::to; + default: + throw std::invalid_argument("branch_side_to_tap_side: Invalid BranchSide value"); + } +} + +inline TapSide branch_3_side_to_tap_side(Branch3Side branch3_side) { + switch (branch3_side) { + case Branch3Side::side_1: + return TapSide::side_1; + case Branch3Side::side_2: + return TapSide::side_2; + case Branch3Side::side_3: + return TapSide::side_3; + default: + throw std::invalid_argument("branch_3_side_to_tap_side: Invalid Branch3Side value"); + } +} + enum class ControlSide : IntS { from = 0, to = 1, side_1 = 0, side_2 = 1, side_3 = 2 }; enum class CalculationType : IntS { power_flow = 0, state_estimation = 1, short_circuit = 2 }; diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/optimizer/tap_position_optimizer.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/optimizer/tap_position_optimizer.hpp index 49282bc44..f4b843f7f 100644 --- a/power_grid_model_c/power_grid_model/include/power_grid_model/optimizer/tap_position_optimizer.hpp +++ b/power_grid_model_c/power_grid_model/include/power_grid_model/optimizer/tap_position_optimizer.hpp @@ -51,6 +51,9 @@ struct TrafoGraphEdge { Idx2D regulated_idx{}; EdgeWeight weight{}; + TapSide tap_side{}; + ControlSide control_side{}; + bool operator==(const TrafoGraphEdge& other) const { return regulated_idx == other.regulated_idx && weight == other.weight; } // thanks boost @@ -66,7 +69,7 @@ struct TrafoGraphEdge { } }; -constexpr TrafoGraphEdge unregulated_edge_prop = {unregulated_idx, 0}; +constexpr TrafoGraphEdge unregulated_edge_prop = {unregulated_idx, 0, TapSide::from, ControlSide::from}; using TrafoGraphEdges = std::vector>; using TrafoGraphEdgeProperties = std::vector; @@ -74,14 +77,14 @@ struct RegulatedTrafoProperties { Idx id{}; ControlSide control_side{}; - auto operator<=>(RegulatedTrafoProperties const& other) const = default; + auto operator<=>(RegulatedTrafoProperties const& other) const = default; // NOLINT(modernize-use-nullptr) }; using RegulatedTrafos = std::set; inline std::pair regulated_trafos_contain(RegulatedTrafos const& trafos_set, Idx const& id) { - if (auto it = std::find_if(trafos_set.begin(), trafos_set.end(), - [&](RegulatedTrafoProperties const& trafo) { return trafo.id == id; }); + if (auto it = + std::ranges::find_if(trafos_set, [&](RegulatedTrafoProperties const& trafo) { return trafo.id == id; }); it != trafos_set.end()) { return {true, it->control_side}; } @@ -149,7 +152,9 @@ inline void process_trafo3w_edge(main_core::main_model_state_c auto const& state // add regulated idx only when the first side node is tap side node. // This is done to add only one directional edge with regulated idx. auto const edge_value = - (from_node == tap_side_node) ? unregulated_edge_prop : TrafoGraphEdge{trafo3w_idx, 1}; + (from_node == tap_side_node) + ? unregulated_edge_prop + : TrafoGraphEdge{trafo3w_idx, 1, branch_3_side_to_tap_side(transformer3w.tap_side()), control_side}; // (TODO: jguo) old way, to be removed // add_to_edge(state, edges, edge_props, tap_side_node, non_tap_side_node, edge_value); add_to_edge(state, edges, edge_props, edge_from_node, edge_to_node, edge_value); @@ -201,7 +206,8 @@ constexpr void add_edge(main_core::MainModelState const& sta // (TODO: jguo) old way, to be removed // add_to_edge(state, edges, edge_props, tap_side_node, non_tap_side_node, // {main_core::get_component_idx_by_id(state, transformer.id()), 1}); - add_to_edge(state, edges, edge_props, non_control_side_node, control_side_node, {trafo_idx, 1}); + add_to_edge(state, edges, edge_props, non_control_side_node, control_side_node, + {trafo_idx, 1, branch_side_to_tap_side(transformer.tap_side()), control_side}); } else { add_to_edge(state, edges, edge_props, from_node, to_node, unregulated_edge_prop); add_to_edge(state, edges, edge_props, to_node, from_node, unregulated_edge_prop);