diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/main_core/output.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/main_core/output.hpp index e008e8b733..92e811eb63 100644 --- a/power_grid_model_c/power_grid_model/include/power_grid_model/main_core/output.hpp +++ b/power_grid_model_c/power_grid_model/include/power_grid_model/main_core/output.hpp @@ -60,9 +60,11 @@ constexpr bool measured_terminal_active(MeasuredTerminalType const terminal_type using enum MeasuredTerminalType; case branch_from: - return measured_component_active(state, obj_seq, BranchSide::from); + return measured_component_active(state, obj_seq, + BranchSide::from); // TODO(mgovers): cleanup v2: change back to Branch case branch_to: - return measured_component_active(state, obj_seq, BranchSide::to); + return measured_component_active(state, obj_seq, + BranchSide::to); // TODO(mgovers): cleanup v2: change back to Branch case source: return measured_component_active(state, obj_seq); case shunt: diff --git a/power_grid_model_c/power_grid_model/include/power_grid_model/main_core/topology.hpp b/power_grid_model_c/power_grid_model/include/power_grid_model/main_core/topology.hpp index f2dca1df70..1e9b7bd58e 100644 --- a/power_grid_model_c/power_grid_model/include/power_grid_model/main_core/topology.hpp +++ b/power_grid_model_c/power_grid_model/include/power_grid_model/main_core/topology.hpp @@ -121,7 +121,8 @@ constexpr void register_topology_components(ComponentContainer const& components case branch_from: [[fallthrough]]; case branch_to: - return get_component_sequence_idx(components, measured_object); + return get_component_sequence_idx( + components, measured_object); // TODO(mgovers): cleanup v2: change back to Branch case source: return get_component_sequence_idx(components, measured_object); case shunt: @@ -152,28 +153,29 @@ constexpr void register_topology_components(ComponentContainer const& components template Component, class ComponentContainer> requires common::component_container_c constexpr void register_topology_components(ComponentContainer const& components, ComponentTopology& comp_topo) { - apply_registration(components, comp_topo.current_sensor_object_idx, - [&components](GenericCurrentSensor const& current_sensor) { - using enum MeasuredTerminalType; - - auto const measured_object = current_sensor.measured_object(); - - switch (current_sensor.get_terminal_type()) { - case branch_from: - [[fallthrough]]; - case branch_to: - return get_component_sequence_idx(components, measured_object); - case branch3_1: - [[fallthrough]]; - case branch3_2: - [[fallthrough]]; - case branch3_3: - return get_component_sequence_idx(components, measured_object); - default: - throw MissingCaseForEnumError("Current sensor idx to seq transformation", - current_sensor.get_terminal_type()); - } - }); + apply_registration( + components, comp_topo.current_sensor_object_idx, [&components](GenericCurrentSensor const& current_sensor) { + using enum MeasuredTerminalType; + + auto const measured_object = current_sensor.measured_object(); + + switch (current_sensor.get_terminal_type()) { + case branch_from: + [[fallthrough]]; + case branch_to: + return get_component_sequence_idx( + components, measured_object); // TODO(mgovers): cleanup v2: change back to Branch + case branch3_1: + [[fallthrough]]; + case branch3_2: + [[fallthrough]]; + case branch3_3: + return get_component_sequence_idx(components, measured_object); + default: + throw MissingCaseForEnumError("Current sensor idx to seq transformation", + current_sensor.get_terminal_type()); + } + }); apply_registration( components, comp_topo.current_sensor_terminal_type, @@ -187,7 +189,8 @@ constexpr void register_topology_components(ComponentContainer const& components components, comp_topo.regulated_object_idx, [&components](Regulator const& regulator) { switch (regulator.regulated_object_type()) { case ComponentType::branch: - return get_component_sequence_idx(components, regulator.regulated_object()); + return get_component_sequence_idx( + components, regulator.regulated_object()); // TODO(mgovers): cleanup v2: change back to Branch case ComponentType::branch3: return get_component_sequence_idx(components, regulator.regulated_object()); case ComponentType::generic_load_gen: diff --git a/tests/cpp_unit_tests/main_core/test_main_core_output.cpp b/tests/cpp_unit_tests/main_core/test_main_core_output.cpp index ba01d9a173..e2311edd59 100644 --- a/tests/cpp_unit_tests/main_core/test_main_core_output.cpp +++ b/tests/cpp_unit_tests/main_core/test_main_core_output.cpp @@ -43,7 +43,7 @@ namespace power_grid_model::main_core { namespace { using PowerSensorOutputComponents = - Container, + Container, GenericBranch, ThreeWindingTransformer, Source, Shunt, SymGenerator, SymLoad, SymPowerSensor>; using PowerSensorOutputState = MainModelState; diff --git a/tests/data/state_estimation/link-after-trafo-with-node-injection-sensor/asym_output.json b/tests/data/state_estimation/link-after-trafo-with-node-injection-sensor/asym_output.json new file mode 100644 index 0000000000..4c059c4976 --- /dev/null +++ b/tests/data/state_estimation/link-after-trafo-with-node-injection-sensor/asym_output.json @@ -0,0 +1,29 @@ +{ + "version": "1.0", + "type": "asym_output", + "is_batch": false, + "attributes": {}, + "data": { + "node": [ + {"id": 30, "energized": 1, "u_pu": [1.000000010064068, 1.000000010064068, 1.000000010064068], "u": [230.94011000004724, 230.94011000004724, 230.94011000004724], "p": [0, 0, 0], "q": [0, 0, 0]}, + {"id": 90, "energized": 1, "u_pu": [1.0000101193813746, 1.0000101193813751, 1.0000101193813746], "u": [5773.5611161718643, 5773.5611161718671, 5773.5611161718643], "p": [393.33930563990441, 393.33930564063223, 393.33930563908439], "q": [0.00709388887433921, 0.0070938906288457171, 0.0070938892082683235]}, + {"id": 112, "energized": 1, "u_pu": [1.000000010064068, 1.000000010064068, 1.000000010064068], "u": [230.94011000004724, 230.94011000004724, 230.94011000004724], "p": [0, 0, 0], "q": [0, 0, 0]} + ], + "source": [ + {"id": 207, "energized": 1, "p": [393.33930563990441, 393.33930564063223, 393.33930563908439], "q": [0.00709388887433921, 0.0070938906288457171, 0.0070938892082683235], "i": [0.068127676799353901, 0.068127676799479939, 0.068127676799211861], "s": [393.33930570387372, 393.33930570460149, 393.3393057030537], "pf": [0.99999999983736865, 0.99999999983736876, 0.99999999983736865]} + ], + "transformer": [ + {"id": 208, "energized": 1, "loading": 0.0018730443128754427, "p_from": [393.33930563990441, 393.33930564063223, 393.33930563908439], "q_from": [0.00709388887433921, 0.0070938906288644295, 0.0070938892082577018], "i_from": [0.068127676799353901, 0.068127676799479939, 0.068127676799211875], "s_from": [393.33930570387372, 393.33930570460149, 393.3393057030537], "p_to": [-2.9599540235974926e-10, -1.065247035871966e-09, -2.960409795477462e-10], "q_to": [1.7763675350654815e-09, -6.8662416846613241e-11, 5.1280073347288324e-10], "i_to": [7.797950250597033e-12, 4.6222270443732789e-12, 2.5639502485114186e-12], "s_to": [1.8008594886477745e-09, 1.0674576220727582e-09, 5.9211895242587547e-10]} + ], + "link": [ + {"id": 229, "energized": 1, "loading": 0, "p_from": [0, 0, 0], "q_from": [0, 0, 0], "i_from": [0, 0, 0], "s_from": [0, 0, 0], "p_to": [0, 0, 0], "q_to": [0, 0, 0], "i_to": [0, 0, 0], "s_to": [0, 0, 0]} + ], + "asym_voltage_sensor": [ + {"id": 329, "energized": 1, "u_residual": [0, 0, 0]} + ], + "asym_power_sensor": [ + {"id": 466, "energized": 1, "p_residual": [0, 0, 0], "q_residual": [0, 0, 0]}, + {"id": 467, "energized": 1, "p_residual": [0, 0, 0], "q_residual": [0, 0, 0]} + ] + } +} \ No newline at end of file diff --git a/tests/data/state_estimation/link/asym_output.json.license b/tests/data/state_estimation/link-after-trafo-with-node-injection-sensor/asym_output.json.license similarity index 100% rename from tests/data/state_estimation/link/asym_output.json.license rename to tests/data/state_estimation/link-after-trafo-with-node-injection-sensor/asym_output.json.license diff --git a/tests/data/state_estimation/link-after-trafo-with-node-injection-sensor/input.json b/tests/data/state_estimation/link-after-trafo-with-node-injection-sensor/input.json new file mode 100644 index 0000000000..0dee80cbd5 --- /dev/null +++ b/tests/data/state_estimation/link-after-trafo-with-node-injection-sensor/input.json @@ -0,0 +1,29 @@ +{ + "version": "1.0", + "type": "input", + "is_batch": false, + "attributes": {}, + "data": { + "node": [ + {"id": 30, "u_rated": 400}, + {"id": 90, "u_rated": 10000}, + {"id": 112, "u_rated": 400} + ], + "source": [ + {"id": 207, "node": 90, "status": 1, "u_ref": 1, "u_ref_angle": 0} + ], + "transformer": [ + {"id": 208, "from_node": 90, "to_node": 112, "from_status": 1, "to_status": 1, "u1": 10000, "u2": 400, "sn": 630000, "uk": 0.040000000000000001, "pk": 6800.2200000000003, "i0": 0.0018730158730158729, "p0": 1180, "winding_from": 1, "winding_to": 1, "clock": 0, "tap_side": 1, "tap_pos": 5, "tap_min": 1, "tap_max": 9, "tap_nom": 5, "tap_size": 10, "r_grounding_from": 0, "x_grounding_from": 0, "r_grounding_to": 0, "x_grounding_to": 0} + ], + "link": [ + {"id": 229, "from_node": 30, "to_node": 112, "from_status": 1, "to_status": 1} + ], + "asym_voltage_sensor": [ + {"id": 329, "measured_object": 30, "u_sigma": 2.3094, "u_measured": [230.94011, 230.94011, 230.94011]} + ], + "asym_power_sensor": [ + {"id": 466, "measured_object": 208, "measured_terminal_type": 1, "p_measured": [0, 0, 0], "q_measured": [0, 0, 0], "p_sigma": [1000, 1000, 1000], "q_sigma": [1000, 1000, 1000]}, + {"id": 467, "measured_object": 112, "measured_terminal_type": 9, "p_measured": [0, 0, 0], "q_measured": [0, 0, 0], "p_sigma": [1000, 1000, 1000], "q_sigma": [1000, 1000, 1000]} + ] + } +} \ No newline at end of file diff --git a/tests/data/state_estimation/link/input.json.license b/tests/data/state_estimation/link-after-trafo-with-node-injection-sensor/input.json.license similarity index 100% rename from tests/data/state_estimation/link/input.json.license rename to tests/data/state_estimation/link-after-trafo-with-node-injection-sensor/input.json.license diff --git a/tests/data/state_estimation/link-after-trafo-with-node-injection-sensor/params.json b/tests/data/state_estimation/link-after-trafo-with-node-injection-sensor/params.json new file mode 100644 index 0000000000..1daf7c3915 --- /dev/null +++ b/tests/data/state_estimation/link-after-trafo-with-node-injection-sensor/params.json @@ -0,0 +1,20 @@ +{ + "calculation_method": ["iterative_linear", "newton_raphson"], + "rtol": 1e-8, + "atol": { + "default": 1e-5, + "p": 2e-2, + "q": 2e-2, + "s": 2e-2, + "p_from": 2e-2, + "q_from": 2e-2, + "i_from": 1e-4, + "s_from": 2e-2, + "p_to": 2e-2, + "q_to": 2e-2, + "i_to": 1e-4, + "s_to": 2e-2, + "p_residual": 1e-2, + "q_residual": 2e-2 + } +} diff --git a/tests/data/state_estimation/link/params.json.license b/tests/data/state_estimation/link-after-trafo-with-node-injection-sensor/params.json.license similarity index 100% rename from tests/data/state_estimation/link/params.json.license rename to tests/data/state_estimation/link-after-trafo-with-node-injection-sensor/params.json.license diff --git a/tests/data/state_estimation/link-after-trafo/asym_output.json b/tests/data/state_estimation/link-after-trafo/asym_output.json new file mode 100644 index 0000000000..03bde4755c --- /dev/null +++ b/tests/data/state_estimation/link-after-trafo/asym_output.json @@ -0,0 +1,28 @@ +{ + "version": "1.0", + "type": "asym_output", + "is_batch": false, + "attributes": {}, + "data": { + "node": [ + {"id": 30, "energized": 1, "u_pu": [1.000000010064068, 1.000000010064068, 1.000000010064068], "u": [230.94011000004724, 230.94011000004724, 230.94011000004724], "p": [0, 0, 0], "q": [0, 0, 0]}, + {"id": 90, "energized": 1, "u_pu": [1.0000101193813746, 1.0000101193813751, 1.0000101193813746], "u": [5773.5611161718643, 5773.5611161718671, 5773.5611161718643], "p": [393.33930563990441, 393.33930564063223, 393.33930563908439], "q": [0.00709388887433921, 0.0070938906288457171, 0.0070938892082683235]}, + {"id": 112, "energized": 1, "u_pu": [1.000000010064068, 1.000000010064068, 1.000000010064068], "u": [230.94011000004724, 230.94011000004724, 230.94011000004724], "p": [0, 0, 0], "q": [0, 0, 0]} + ], + "source": [ + {"id": 207, "energized": 1, "p": [393.33930563990441, 393.33930564063223, 393.33930563908439], "q": [0.00709388887433921, 0.0070938906288457171, 0.0070938892082683235], "i": [0.068127676799353901, 0.068127676799479939, 0.068127676799211861], "s": [393.33930570387372, 393.33930570460149, 393.3393057030537], "pf": [0.99999999983736865, 0.99999999983736876, 0.99999999983736865]} + ], + "transformer": [ + {"id": 208, "energized": 1, "loading": 0.0018730443128754427, "p_from": [393.33930563990441, 393.33930564063223, 393.33930563908439], "q_from": [0.00709388887433921, 0.0070938906288644295, 0.0070938892082577018], "i_from": [0.068127676799353901, 0.068127676799479939, 0.068127676799211875], "s_from": [393.33930570387372, 393.33930570460149, 393.3393057030537], "p_to": [-2.9599540235974926e-10, -1.065247035871966e-09, -2.960409795477462e-10], "q_to": [1.7763675350654815e-09, -6.8662416846613241e-11, 5.1280073347288324e-10], "i_to": [7.797950250597033e-12, 4.6222270443732789e-12, 2.5639502485114186e-12], "s_to": [1.8008594886477745e-09, 1.0674576220727582e-09, 5.9211895242587547e-10]} + ], + "link": [ + {"id": 229, "energized": 1, "loading": 0, "p_from": [0, 0, 0], "q_from": [0, 0, 0], "i_from": [0, 0, 0], "s_from": [0, 0, 0], "p_to": [0, 0, 0], "q_to": [0, 0, 0], "i_to": [0, 0, 0], "s_to": [0, 0, 0]} + ], + "asym_voltage_sensor": [ + {"id": 329, "energized": 1, "u_residual": [0, 0, 0]} + ], + "asym_power_sensor": [ + {"id": 466, "energized": 1, "p_residual": [0, 0, 0], "q_residual": [0, 0, 0]} + ] + } +} \ No newline at end of file diff --git a/tests/data/state_estimation/link-after-trafo/asym_output.json.license b/tests/data/state_estimation/link-after-trafo/asym_output.json.license new file mode 100644 index 0000000000..7601059167 --- /dev/null +++ b/tests/data/state_estimation/link-after-trafo/asym_output.json.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: Contributors to the Power Grid Model project + +SPDX-License-Identifier: MPL-2.0 diff --git a/tests/data/state_estimation/link/input.json b/tests/data/state_estimation/link-after-trafo/input.json similarity index 90% rename from tests/data/state_estimation/link/input.json rename to tests/data/state_estimation/link-after-trafo/input.json index e1d79c5b5c..62588da098 100644 --- a/tests/data/state_estimation/link/input.json +++ b/tests/data/state_estimation/link-after-trafo/input.json @@ -19,8 +19,7 @@ {"id": 229, "from_node": 30, "to_node": 112, "from_status": 1, "to_status": 1} ], "asym_voltage_sensor": [ - {"id": 329, "measured_object": 30, "u_sigma": 2.3094000000000001, "u_measured": [230.94011, 230.94011, 230.94011]} - + {"id": 329, "measured_object": 30, "u_sigma": 2.3094, "u_measured": [230.94011, 230.94011, 230.94011]} ], "asym_power_sensor": [ {"id": 466, "measured_object": 208, "measured_terminal_type": 1, "p_measured": [0, 0, 0], "q_measured": [0, 0, 0], "p_sigma": [1000, 1000, 1000], "q_sigma": [1000, 1000, 1000]} diff --git a/tests/data/state_estimation/link-after-trafo/input.json.license b/tests/data/state_estimation/link-after-trafo/input.json.license new file mode 100644 index 0000000000..7601059167 --- /dev/null +++ b/tests/data/state_estimation/link-after-trafo/input.json.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: Contributors to the Power Grid Model project + +SPDX-License-Identifier: MPL-2.0 diff --git a/tests/data/state_estimation/link-after-trafo/params.json b/tests/data/state_estimation/link-after-trafo/params.json new file mode 100644 index 0000000000..1daf7c3915 --- /dev/null +++ b/tests/data/state_estimation/link-after-trafo/params.json @@ -0,0 +1,20 @@ +{ + "calculation_method": ["iterative_linear", "newton_raphson"], + "rtol": 1e-8, + "atol": { + "default": 1e-5, + "p": 2e-2, + "q": 2e-2, + "s": 2e-2, + "p_from": 2e-2, + "q_from": 2e-2, + "i_from": 1e-4, + "s_from": 2e-2, + "p_to": 2e-2, + "q_to": 2e-2, + "i_to": 1e-4, + "s_to": 2e-2, + "p_residual": 1e-2, + "q_residual": 2e-2 + } +} diff --git a/tests/data/state_estimation/link-after-trafo/params.json.license b/tests/data/state_estimation/link-after-trafo/params.json.license new file mode 100644 index 0000000000..7601059167 --- /dev/null +++ b/tests/data/state_estimation/link-after-trafo/params.json.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: Contributors to the Power Grid Model project + +SPDX-License-Identifier: MPL-2.0 diff --git a/tests/data/state_estimation/link/asym_output.json b/tests/data/state_estimation/link/asym_output.json deleted file mode 100644 index f1ef399339..0000000000 --- a/tests/data/state_estimation/link/asym_output.json +++ /dev/null @@ -1,254 +0,0 @@ -{ - "version": "1.0", - "type": "asym_output", - "is_batch": false, - "attributes": {}, - "data": { - "node": [ - { - "id": 30, - "energized": 1, - "u_pu": [ - 1.0000000100640516, - 1.0000000100640518, - 1.0000000100640518 - ], - "u": [ - 230.94011000004346, - 230.94011000004352, - 230.94011000004352 - ], - "u_angle": [ - -3.607050966088345e-05, - -2.0944311729028566, - 2.094359031883535 - ], - "p": [ - 0.0, - -0.0012418410248675865, - 0.009268427792436354 - ], - "q": [ - -0.0, - -0.0021507525858327006, - -0.006119996943348736 - ] - }, - { - "id": 90, - "energized": 1, - "u_pu": [ - 1.0000101195612183, - 1.0000101195612185, - 1.0000101195612183 - ], - "u": [ - 5773.561117210193, - 5773.5611172101935, - 5773.561117210193 - ], - "u_angle": [ - -6.776195005914213e-21, - -2.0943951023931957, - 2.0943951023931957 - ], - "p": [ - 393.3408030101657, - 393.3408030098129, - 393.3408030088496 - ], - "q": [ - 0.007654988835790601, - 0.007654989582357776, - 0.00765498827708678 - ] - }, - { - "id": 112, - "energized": 1, - "u_pu": [ - 1.0000000100640516, - 1.000000010064052, - 1.0000000100640516 - ], - "u": [ - 230.94011000004346, - 230.94011000004355, - 230.94011000004346 - ], - "u_angle": [ - -3.6070509660883455e-05, - -2.0944311729028566, - 2.094359031883535 - ], - "p": [ - 0.0010466757970555023, - 0.006889802345860008, - -0.004495174863230333 - ], - "q": [ - -0.0005375343256626614, - -0.0006991445095695525, - -0.0005247856136144402 - ] - } - ], - "source": [ - { - "id": 207, - "energized": 1, - "p": [ - 393.3408030101657, - 393.3408030098129, - 393.3408030088496 - ], - "q": [ - 0.007654988835790601, - 0.007654989582357776, - 0.00765498827708678 - ], - "i": [ - 0.06812793613843621, - 0.06812793613837509, - 0.06812793613820825 - ], - "s": [ - 393.34080308465434, - 393.34080308430157, - 393.3408030833383 - ], - "pf": [ - 0.9999999998106257, - 0.9999999998106256, - 0.9999999998106256 - ] - } - ], - "transformer": [ - { - "id": 208, - "energized": 1, - "loading": 0.0018730514432576098, - "p_from": [ - 393.3408030101657, - 393.3408030098129, - 393.3408030088496 - ], - "q_from": [ - 0.007654988835790601, - 0.007654989582357776, - 0.00765498827708678 - ], - "i_from": [ - 0.06812793613843621, - 0.06812793613837509, - 0.06812793613820826 - ], - "s_from": [ - 393.34080308465434, - 393.34080308430157, - 393.3408030833383 - ], - "p_to": [ - -0.0014972687986235403, - -0.0014972693598851046, - -0.0014972685747695362 - ], - "q_to": [ - -0.0005609905429188497, - -0.0005609913192535611, - -0.0005609908303419999 - ], - "i_to": [ - 6.9234982935624505e-06, - 6.923501748849574e-06, - 6.923497822536436e-06 - ], - "s_to": [ - 0.0015989134575004255, - 0.0015989142554648143, - 0.0015989133487216264 - ] - } - ], - "link": [ - { - "id": 229, - "energized": 1, - "loading": 0.0, - "p_from": [ - 0.0, - -0.0012418410248675865, - 0.009268427792436354 - ], - "q_from": [ - -0.0, - -0.0021507525858327006, - -0.006119996943348736 - ], - "i_from": [ - 0.0, - 1.0753986783132437e-05, - 4.8093290952436835e-05 - ], - "s_from": [ - 0.0, - 0.002483526890635619, - 0.011106669902819858 - ], - "p_to": [ - 0.0, - 0.001241841024867587, - -0.009268427792436354 - ], - "q_to": [ - -0.0, - 0.0021507525858327006, - 0.006119996943348735 - ], - "i_to": [ - 0.0, - 1.0753986783132437e-05, - 4.8093290952436835e-05 - ], - "s_to": [ - 0.0, - 0.0024835268906356193, - 0.011106669902819858 - ] - } - ], - "asym_voltage_sensor": [ - { - "id": 329, - "energized": 1, - "u_residual": [ - -4.3433317209783434e-11, - -4.348459621475366e-11, - -4.348459621475366e-11 - ], - "u_angle_residual": [ - null, - null, - null - ] - } - ], - "asym_power_sensor": [ - { - "id": 466, - "energized": 1, - "p_residual": [ - 0.0014972687986235403, - 0.0014972693598851046, - 0.0014972685747695362 - ], - "q_residual": [ - 0.0005609905429188497, - 0.0005609913192535611, - 0.0005609908303419999 - ] - } - ] - } -} diff --git a/tests/data/state_estimation/link/params.json b/tests/data/state_estimation/link/params.json deleted file mode 100644 index 11b506051b..0000000000 --- a/tests/data/state_estimation/link/params.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "calculation_method": ["iterative_linear", "newton_raphson"], - "rtol": 1e-3, - "atol": { - "default": 1e-5, - ".+_residual": 0.15 - }, - "xfail": { - "raises": "SparseMatrixError", - "reason": "Bug in https://github.com/PowerGridModel/power-grid-model/issues/1567" - } -}