|
8 | 8 |
|
9 | 9 | import numpy as np |
10 | 10 | import pytest |
11 | | -from power_grid_model import ComponentType, TapChangingStrategy, initialize_array |
| 11 | +from power_grid_model import ComponentType, MeasuredTerminalType, TapChangingStrategy, initialize_array |
12 | 12 |
|
13 | 13 | from power_grid_model_ds._core.data_source.generator.grid_generators import RadialGridGenerator |
14 | 14 | from power_grid_model_ds._core.model.grids.base import Grid |
@@ -114,6 +114,39 @@ def test_grid_with_automatic_tap_regulator(self, grid_with_tap_regulator: Grid): |
114 | 114 | assert output["transformer_tap_regulator"]["tap_pos"][0] > 0 |
115 | 115 |
|
116 | 116 |
|
| 117 | +class TestCalculateStateEstimation: |
| 118 | + def test_simple_grid_with_sensors(self, simple_loadflow_grid: Grid): |
| 119 | + core_interface = PowerGridModelInterface(grid=simple_loadflow_grid) |
| 120 | + input_data = core_interface.create_input_from_grid() |
| 121 | + |
| 122 | + voltage_sensors = initialize_array("input", "sym_voltage_sensor", 2) |
| 123 | + voltage_sensors["id"] = [10, 11] |
| 124 | + voltage_sensors["measured_object"] = [0, 1] |
| 125 | + voltage_sensors["u_sigma"] = [1.0, 1.0] |
| 126 | + voltage_sensors["u_measured"] = [10_500.0, 10_497.5] |
| 127 | + voltage_sensors["u_angle_measured"] = [0.0, -0.0002] |
| 128 | + |
| 129 | + power_sensors = initialize_array("input", "sym_power_sensor", 2) |
| 130 | + power_sensors["id"] = [12, 13] |
| 131 | + power_sensors["measured_object"] = [3, 4] |
| 132 | + power_sensors["measured_terminal_type"] = [MeasuredTerminalType.source, MeasuredTerminalType.load] |
| 133 | + power_sensors["power_sigma"] = [100.0, 100.0] |
| 134 | + power_sensors["p_measured"] = [-250_000.0, 250_000.0] |
| 135 | + power_sensors["q_measured"] = [-50_000.0, 50_000.0] |
| 136 | + power_sensors["p_sigma"] = [100.0, 100.0] |
| 137 | + power_sensors["q_sigma"] = [100.0, 100.0] |
| 138 | + |
| 139 | + input_data["sym_voltage_sensor"] = voltage_sensors |
| 140 | + input_data["sym_power_sensor"] = power_sensors |
| 141 | + |
| 142 | + output = core_interface.calculate_state_estimation() |
| 143 | + |
| 144 | + assert output is core_interface.output_data |
| 145 | + assert output["node"]["u"][0] == pytest.approx(10_498.75, 0.1) |
| 146 | + assert output["node"]["u"][1] == pytest.approx(10_498.75, 0.1) |
| 147 | + assert all(output["line"]["i_from"] > 0) |
| 148 | + |
| 149 | + |
117 | 150 | @pytest.fixture |
118 | 151 | def base_grid() -> Grid: |
119 | 152 | grid_generator = RadialGridGenerator(grid_class=Grid, nr_nodes=5, nr_sources=1, nr_nops=0) |
|
0 commit comments