Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <boost/graph/compressed_sparse_row_graph.hpp>

#include <algorithm>
#include <compare>
#include <functional>
#include <numeric>
#include <optional>
Expand Down Expand Up @@ -62,10 +63,10 @@ struct TrafoGraphEdge {
} // thanks boost

auto constexpr operator<=>(TrafoGraphEdge const& other) const {
if (auto cmp = weight <=> other.weight; cmp != 0) { // NOLINT(modernize-use-nullptr)
if (auto cmp = weight <=> other.weight; std::is_neq(cmp)) {
return cmp;
}
if (auto cmp = regulated_idx.group <=> other.regulated_idx.group; cmp != 0) { // NOLINT(modernize-use-nullptr)
if (auto cmp = regulated_idx.group <=> other.regulated_idx.group; std::is_neq(cmp)) {
return cmp;
}
return regulated_idx.pos <=> other.regulated_idx.pos;
Expand Down Expand Up @@ -804,6 +805,10 @@ class TapPositionOptimizerImpl<std::tuple<TransformerTypes...>, StateCalculator,
return tap_pos;
}

void rewind(IntS tap_pos, IntS tap_min, IntS tap_max) {
reset(tap_pos, tap_min, tap_max, control_at_tap_side_);
}

private:
void reset(IntS tap_pos, IntS tap_min, IntS tap_max, bool control_at_tap_side) {
last_down_ = false;
Expand Down Expand Up @@ -1085,10 +1090,10 @@ class TapPositionOptimizerImpl<std::tuple<TransformerTypes...>, StateCalculator,

auto const cmp = node_state <=> param;
auto new_tap_pos = [&transformer, &cmp, &control_at_tap_side] {
if (cmp > 0) { // NOLINT(modernize-use-nullptr)
if (std::is_gt(cmp)) {
return one_step_control_voltage_down(transformer, control_at_tap_side);
}
if (cmp < 0) { // NOLINT(modernize-use-nullptr)
if (std::is_lt(cmp)) {
return one_step_control_voltage_up(transformer, control_at_tap_side);
}
return transformer.tap_pos();
Expand Down Expand Up @@ -1126,8 +1131,8 @@ class TapPositionOptimizerImpl<std::tuple<TransformerTypes...>, StateCalculator,
auto const cmp = node_state <=> param;
if (auto new_tap_pos =
[&cmp, strategy_max, &current_bs] {
if (cmp != 0) { // NOLINT(modernize-use-nullptr)
current_bs.propose_new_pos(strategy_max, cmp > 0); // NOLINT(modernize-use-nullptr)
if (std::is_neq(cmp)) {
current_bs.propose_new_pos(strategy_max, std::is_gt(cmp));
}
return current_bs.get_current_tap();
}();
Expand All @@ -1138,7 +1143,7 @@ class TapPositionOptimizerImpl<std::tuple<TransformerTypes...>, StateCalculator,
return;
}

if (strategy_ == OptimizerStrategy::fast_any) {
if (strategy_ == OptimizerStrategy::fast_any && std::is_eq(cmp)) {
tap_changed = false;
return;
}
Expand All @@ -1147,6 +1152,16 @@ class TapPositionOptimizerImpl<std::tuple<TransformerTypes...>, StateCalculator,
current_bs.recalibrate(strategy_max);

IntS const tap_pos = current_bs.repropose_tap(strategy_max, previous_down, tap_changed);
// The new same tap pos is only valid in a cmp == equivalent situation
// in other words, a same tap pos in a non equivalent situation means
// the binary search cannot find a valid tap position
// _tap_changed_ is an aggregated flag with _inevitable_run_, so we can not use it here
if (tap_pos == transformer.tap_pos() && cmp != 0 && !current_bs.get_end_of_bs()) {
current_bs.rewind(tap_pos, transformer.tap_min(), transformer.tap_max());
throw MaxIterationReached{std::format(
"TapPositionOptimizer::binary_search: no valid tap position found between tap {} and tap {}",
transformer.tap_min(), transformer.tap_max())};
}
add_tap_pos_update(tap_pos, transformer, update_data);
};
regulator.transformer.apply(adjust_transformer_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"u": 100.0
},
"xfail": {
"raises": "AssertionError",
"raises": "MaxIterationReached",
"reason": "Bug in fast any tap changing strategy in this edge case: https://github.com/PowerGridModel/power-grid-model/issues/1215"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"version": "1.0",
"type": "input",
"is_batch": false,
"attributes": {},
"data": {
"node": [
{"id": 0, "u_rated": 10000},
{"id": 1, "u_rated": 10000},
{"id": 2, "u_rated": 10000},
{"id": 3, "u_rated": 10000},
{"id": 4, "u_rated": 10000},
{"id": 5, "u_rated": 10000},
{"id": 6, "u_rated": 10000},
{"id": 7, "u_rated": 400},
{"id": 8, "u_rated": 400},
{"id": 9, "u_rated": 400},
{"id": 10, "u_rated": 400}
],
"line": [
{"id": 11, "from_node": 0, "to_node": 1, "from_status": 1, "to_status": 1, "r1": 0.005, "x1": 0.5, "c1": 0, "tan1": 0},
{"id": 12, "from_node": 0, "to_node": 2, "from_status": 1, "to_status": 1, "r1": 0.1, "x1": 0.6, "c1": 0, "tan1": 0},
{"id": 13, "from_node": 3, "to_node": 5, "from_status": 1, "to_status": 1, "r1": 0.005, "x1": 0.5, "c1": 0, "tan1": 0},
{"id": 14, "from_node": 4, "to_node": 6, "from_status": 1, "to_status": 1, "r1": 0.003, "x1": 0.3, "c1": 0, "tan1": 0},
{"id": 15, "from_node": 7, "to_node": 9, "from_status": 1, "to_status": 1, "r1": 0.005, "x1": 0.5, "c1": 0, "tan1": 0},
{"id": 16, "from_node": 8, "to_node": 9, "from_status": 1, "to_status": 1, "r1": 0.005, "x1": 0.6, "c1": 0, "tan1": 0}
],
"transformer": [
{"id": 17, "from_node": 1, "to_node": 3, "from_status": 1, "to_status": 1, "u1": 10000, "u2": 10000, "sn": 300000, "uk": 0.0005, "pk": 1000, "i0": 0, "p0": 0, "winding_from": 2, "winding_to": 1, "clock": 5, "tap_side": 0, "tap_pos": 0, "tap_min": -10, "tap_max": 10, "tap_size": 100},
{"id": 18, "from_node": 2, "to_node": 4, "from_status": 1, "to_status": 1, "u1": 10000, "u2": 10000, "sn": 300000, "uk": 0.0005, "pk": 1000, "i0": 0, "p0": 0, "winding_from": 2, "winding_to": 1, "clock": 5, "tap_side": 0, "tap_pos": 0, "tap_min": -10, "tap_max": 10, "tap_size": 100},
{"id": 19, "from_node": 5, "to_node": 7, "from_status": 1, "to_status": 1, "u1": 10000, "u2": 400, "sn": 300000, "uk": 0.0005, "pk": 1000, "i0": 0, "p0": 0, "winding_from": 2, "winding_to": 1, "clock": 5, "tap_side": 0, "tap_pos": 0, "tap_min": -10, "tap_max": 10, "tap_size": 20},
{"id": 20, "from_node": 6, "to_node": 8, "from_status": 1, "to_status": 1, "u1": 10000, "u2": 400, "sn": 300000, "uk": 0.0005, "pk": 1000, "i0": 0, "p0": 0, "winding_from": 2, "winding_to": 1, "clock": 5, "tap_side": 0, "tap_pos": 0, "tap_min": -10, "tap_max": 10, "tap_size": 20},
{"id": 21, "from_node": 9, "to_node": 10, "from_status": 1, "to_status": 1, "u1": 400, "u2": 400, "sn": 300000, "uk": 0.0005, "pk": 1000, "i0": 0, "p0": 0, "winding_from": 2, "winding_to": 1, "clock": 5, "tap_side": 0, "tap_pos": 0, "tap_min": -10, "tap_max": 10, "tap_size": 20}
],
"source": [
{"id": 22, "node": 0, "status": 1, "u_ref": 1}
],
"sym_load": [
{"id": 23, "node": 0, "status": 1, "type": 0, "p_specified": 100000, "q_specified": 10000},
{"id": 24, "node": 1, "status": 1, "type": 0, "p_specified": 100000, "q_specified": 10000},
{"id": 25, "node": 2, "status": 1, "type": 0, "p_specified": 100000, "q_specified": 10000},
{"id": 26, "node": 3, "status": 1, "type": 0, "p_specified": 100000, "q_specified": 10000},
{"id": 27, "node": 4, "status": 1, "type": 0, "p_specified": 100000, "q_specified": 10000},
{"id": 28, "node": 5, "status": 1, "type": 0, "p_specified": 100000, "q_specified": 10000},
{"id": 29, "node": 6, "status": 1, "type": 0, "p_specified": 100000, "q_specified": 10000},
{"id": 30, "node": 7, "status": 1, "type": 0, "p_specified": 100000, "q_specified": 10000},
{"id": 31, "node": 8, "status": 1, "type": 0, "p_specified": 100000, "q_specified": 10000},
{"id": 32, "node": 9, "status": 1, "type": 0, "p_specified": 100000, "q_specified": 10000},
{"id": 33, "node": 10, "status": 1, "type": 0, "p_specified": 100000, "q_specified": 10000}
],
"transformer_tap_regulator": [
{"id": 34, "regulated_object": 17, "status": 1, "control_side": 1, "u_set": 10000, "u_band": 300},
{"id": 35, "regulated_object": 18, "status": 1, "control_side": 1, "u_set": 10000, "u_band": 300},
{"id": 36, "regulated_object": 19, "status": 1, "control_side": 1, "u_set": 400, "u_band": 5},
{"id": 37, "regulated_object": 20, "status": 1, "control_side": 1, "u_set": 400, "u_band": 5},
{"id": 38, "regulated_object": 21, "status": 1, "control_side": 1, "u_set": 400, "u_band": 5}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2023 Contributors to the Power Grid Model project <dynamic.grid.calculation@alliander.com>

SPDX-License-Identifier: MPL-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"calculation_method": "newton_raphson",
"tap_changing_strategy": "fast_any_tap",
"rtol": 1e-05,
"atol": 1e-05,
"raises": {
"raises": "MaxIterationReached",
"reason": "TapPositionOptimizer::iterate"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2023 Contributors to the Power Grid Model project <dynamic.grid.calculation@alliander.com>

SPDX-License-Identifier: MPL-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"version": "1.0",
"type": "sym_output",
"is_batch": false,
"attributes": {},
"data": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2023 Contributors to the Power Grid Model project <dynamic.grid.calculation@alliander.com>

SPDX-License-Identifier: MPL-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"version": "1.0",
"type": "input",
"is_batch": false,
"attributes": {},
"data": {
"node": [
{
"id": 1,
"u_rated": 10000
},
{
"id": 2,
"u_rated": 400
}
],
"source": [
{
"id": 3,
"node": 1,
"status": 1,
"u_ref": 1
}
],
"sym_load": [
{
"id": 4,
"node": 2,
"status": 1,
"type": 0,
"p_specified": 5000,
"q_specified": 1015
}
],
"transformer": [
{
"id": 5,
"from_node": 1,
"to_node": 2,
"from_status": 1,
"to_status": 1,
"u1": 10000,
"u2": 400,
"sn": 100000,
"uk": 0.04,
"pk": 1000,
"i0": 0.01,
"p0": 100,
"winding_from": 2,
"winding_to": 2,
"clock": 0,
"tap_side": 0,
"tap_pos": 2,
"tap_min": 1,
"tap_max": 5,
"tap_nom": 3,
"tap_size": 250
}
],
"transformer_tap_regulator": [
{
"id": 6,
"regulated_object": 5,
"status": 1,
"control_side": 1,
"u_set": 400,
"u_band": 0.00001
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2023 Contributors to the Power Grid Model project <dynamic.grid.calculation@alliander.com>

SPDX-License-Identifier: MPL-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"calculation_method": "newton_raphson",
"tap_changing_strategy": "any_valid_tap",
"rtol": 1e-05,
"atol": 1e-05,
"raises": {
"raises": "MaxIterationReached",
"reason": "TapPositionOptimizer::binary_search"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2023 Contributors to the Power Grid Model project <dynamic.grid.calculation@alliander.com>

SPDX-License-Identifier: MPL-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "1.0",
"type": "sym_output",
"is_batch": false,
"attributes": {},
"data": {
"node": [
{"id": 1, "u_pu": 1, "u": 9999.9},
{"id": 2, "u_pu": 1.02456, "u": 409.8260092982474}
],
"transformer_tap_regulator": [
{"id": 6, "tap_pos": 2}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2023 Contributors to the Power Grid Model project <dynamic.grid.calculation@alliander.com>

SPDX-License-Identifier: MPL-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"version": "1.0",
"type": "input",
"is_batch": false,
"attributes": {},
"data": {
"node": [
{
"id": 1,
"u_rated": 10000
},
{
"id": 2,
"u_rated": 400
}
],
"source": [
{
"id": 3,
"node": 1,
"status": 1,
"u_ref": 1
}
],
"sym_load": [
{
"id": 4,
"node": 2,
"status": 1,
"type": 0,
"p_specified": 5000,
"q_specified": 1015
}
],
"transformer": [
{
"id": 5,
"from_node": 1,
"to_node": 2,
"from_status": 1,
"to_status": 1,
"u1": 10000,
"u2": 400,
"sn": 100000,
"uk": 0.04,
"pk": 1000,
"i0": 0.01,
"p0": 100,
"winding_from": 2,
"winding_to": 2,
"clock": 0,
"tap_side": 0,
"tap_pos": 2,
"tap_min": 1,
"tap_max": 5,
"tap_nom": 3,
"tap_size": 250
}
],
"transformer_tap_regulator": [
{
"id": 6,
"regulated_object": 5,
"status": 1,
"control_side": 1,
"u_set": 400,
"u_band": 0.00001
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2023 Contributors to the Power Grid Model project <dynamic.grid.calculation@alliander.com>

SPDX-License-Identifier: MPL-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"calculation_method": "newton_raphson",
"tap_changing_strategy": "fast_any_tap",
"rtol": 1e-05,
"atol": 1e-05,
"raises": {
"raises": "MaxIterationReached",
"reason": "TapPositionOptimizer::binary_search"
}
}
Loading
Loading