Skip to content

Commit

Permalink
tap side and control side made available to ranking
Browse files Browse the repository at this point in the history
Signed-off-by: Jerry Guo <Jerry.Jinfeng.Guo@alliander.com>
  • Loading branch information
Jerry-Jinfeng-Guo committed Nov 17, 2024
1 parent 3a910f5 commit 04b173c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -66,22 +69,22 @@ 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<std::pair<TrafoGraphIdx, TrafoGraphIdx>>;
using TrafoGraphEdgeProperties = std::vector<TrafoGraphEdge>;

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<RegulatedTrafoProperties>;

inline std::pair<bool, ControlSide> 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};
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -201,7 +206,8 @@ constexpr void add_edge(main_core::MainModelState<ComponentContainer> 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);
Expand Down

0 comments on commit 04b173c

Please sign in to comment.