Skip to content

Commit

Permalink
XNode sensitivity unit test (#237)
Browse files Browse the repository at this point in the history
Signed-off-by: Geoffroy Jamgotchian <[email protected]>
  • Loading branch information
geofjamg authored Oct 4, 2021
1 parent 0abb659 commit 678dd6a
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 13 deletions.
46 changes: 46 additions & 0 deletions data/simple-eu-xnode.uct
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
##C 2007.05.01
Generated by powsybl, 2021-06-05T22:56:17.145+02:00
Case date: 2014-01-16T08:30:00.000+01:00
##N
##ZBE
BBE1AA1 0 2 400.00 3000.00 0.00000 -1500.0 0.00000 0.00000 -4999.0 4999.00 -9000.0 F
BBE2AA1 0 2 400.00 1000.00 0.00000 -3000.0 0.00000 0.00000 -4999.0 4999.00 -9000.0 F
BBE3AA1 0 2 400.00 1500.00 0.00000 -2500.0 0.00000 0.00000 -4999.0 4999.00 -9000.0 F
##ZDE
DDE1AA1 0 2 400.00 3500.00 0.00000 -2500.0 0.00000 0.00000 -4999.0 4999.00 -9000.0 F
DDE2AA1 0 2 400.00 3000.00 0.00000 -2000.0 0.00000 0.00000 -4999.0 4999.00 -9000.0 F
DDE3AA1 0 2 400.00 2000.00 0.00000 -1500.0 0.00000 0.00000 -4999.0 4999.00 -9000.0 F
##ZFR
FFR1AA1 0 2 400.00 1000.00 0.00000 -2000.0 0.00000 0.00000 -4999.0 4999.00 -9000.0 F
FFR2AA1 0 2 400.00 3500.00 0.00000 -2000.0 0.00000 0.00000 -4999.0 4999.00 -9000.0 F
FFR3AA1 0 2 400.00 1500.00 0.00000 -3000.0 0.00000 0.00000 -4999.0 4999.00 -9000.0 F
##ZNL
NNL1AA1 0 2 400.00 1000.00 0.00000 -1500.0 0.00000 0.00000 -4999.0 4999.00 -9000.0 F
NNL2AA1 0 2 400.00 1000.00 0.00000 -500.00 0.00000 0.00000 -4999.0 4999.00 -9000.0 F
NNL3AA1 0 2 400.00 2500.00 0.00000 -2500.0 0.00000 0.00000 -4999.0 4999.00 -9000.0 F
##ZXX
XXXXXX11 1 0 0.00000 0.00000 0.00000 0.00000
##L
BBE1AA1 BBE2AA1 1 0 0.0000 10.000 0.000000 5000
BBE1AA1 BBE3AA1 1 0 0.0000 10.000 0.000000 5000
BBE2AA1 BBE3AA1 1 0 0.0000 10.000 0.000000 5000
BBE2AA1 FFR3AA1 1 0 0.0000 10.000 0.000000 5000
DDE1AA1 DDE2AA1 1 0 0.0000 10.000 0.000000 5000
DDE1AA1 DDE3AA1 1 0 0.0000 10.000 0.000000 5000
DDE2AA1 DDE3AA1 1 0 0.0000 10.000 0.000000 5000
DDE2AA1 NNL3AA1 1 0 0.0000 10.000 0.000000 5000
FFR1AA1 FFR2AA1 1 0 0.0000 10.000 0.000000 5000
FFR1AA1 FFR3AA1 1 0 0.0000 10.000 0.000000 5000
FFR2AA1 DDE3AA1 1 0 0.0000 10.000 0.000000 5000
FFR2AA1 FFR3AA1 1 0 0.0000 10.000 0.000000 5000
NNL1AA1 NNL2AA1 1 0 0.0000 10.000 0.000000 5000
NNL1AA1 NNL3AA1 1 0 0.0000 10.000 0.000000 5000
NNL2AA1 BBE3AA1 1 0 0.0000 10.000 0.000000 5000
NNL2AA1 NNL3AA1 1 0 0.0000 10.000 0.000000 5000
NNL2AA1 XXXXXX11 1 0 0.0000 10.000 0.000000 5000
##T
BBE1AA1 BBE3AA1 2 0 400.0 400.0 0.2080 25.500 -2.16250 1.0625 1227
FFR1AA1 FFR2AA1 2 0 400.0 400.0 0.0867 13.988 -2.32750 1.2216 2329
##R
BBE1AA1 BBE3AA1 2 1.626 90.00 33 5 SYMM
FFR1AA1 FFR2AA1 2 2.568 90.00 17 -5 SYMM
6 changes: 1 addition & 5 deletions docs/user_guide/loadflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ The most important part before running a load flow is, after importing a network
.. doctest::

>>> network = pp.network.create_eurostag_tutorial_example1_network()
>>> import pypowsybl.loadflow
>>> pp.loadflow.Parameters()
LoadFlowParameters(voltage_init_mode=UNIFORM_VALUES, transformer_voltage_control_on=False, no_generator_reactive_limits=False, phase_shifter_regulation_on=False, twt_split_shunt_admittance=False, simul_shunt=False, read_slack_bus=False, write_slack_bus=False, distributed_slack=True, balance_type=PROPORTIONAL_TO_GENERATION_P_MAX, dc_use_transformer_ratio=True, countries_to_balance=[], connected_component_mode=<ConnectedComponentMode.MAIN: 0>)

Expand All @@ -40,7 +39,6 @@ AC Load Flow
.. doctest::

>>> network = pp.network.create_eurostag_tutorial_example1_network()
>>> import pypowsybl.loadflow
>>> parameters = pp.loadflow.Parameters(distributed_slack=False)
>>> results = pp.loadflow.run_ac(network, parameters)
>>> results
Expand All @@ -51,7 +49,6 @@ AC Load Flow
.. doctest::

>>> network = pp.network.create_four_substations_node_breaker_network()
>>> import pypowsybl.loadflow
>>> parameters = pp.loadflow.Parameters(balance_type=pp.loadflow.BalanceType.PROPORTIONAL_TO_GENERATION_P_MAX, distributed_slack=True)
>>> results = pp.loadflow.run_ac(network, parameters)
>>> network.get_buses().v_mag
Expand All @@ -65,7 +62,7 @@ AC Load Flow

If you want more logs:

.. doctest::
.. code-block:: python
>>> pp.set_debug_mode(True)
Expand All @@ -76,7 +73,6 @@ DC Load Flow
.. doctest::

>>> network = pp.network.create_eurostag_tutorial_example1_network()
>>> import pypowsybl.loadflow
>>> parameters = pp.loadflow.Parameters(dc_use_transformer_ratio=False, distributed_slack=True, balance_type=pp.loadflow.BalanceType.PROPORTIONAL_TO_GENERATION_P_MAX)
>>> results = pp.loadflow.run_dc(network, parameters)
>>> network.get_lines().p1
Expand Down
27 changes: 27 additions & 0 deletions docs/user_guide/sensitivity.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,33 @@ Let's obtain that directly. In the following example, we create four zones based
DE -> FR 0.256641 -0.743359
NL -0.225206 -0.225206
Sensitivity to a X-Node
^^^^^^^^^^^^^^^^^^^^^^^^
X-Nodes when imported from a UCTE or CGMES file are represented by a so called "dangling line" in the PowSyBl network model.
The dangling line ID is taken from the line ID connecting the X-Node. So to calculate a X-Node sensitivity, we just have to
use the dangling line ID as the injection in the zone definition.

.. code-block:: python
>>> n = pp.network.load('simple-eu-xnode.uct')
>>> n.get_dangling_lines()
name r x g b p0 q0 p q i voltage_level_id bus_id connected ucte-x-node-code isCoupler status_XNode geographicalName
id
NNL2AA1 XXXXXX11 1 0.0 10.0 0.0 0.0 0.0 0.0 NaN NaN NaN NNL2AA1 NNL2AA1_0 True XXXXXX11 false EQUIVALENT >>> zone_x = pp.sensitivity.create_empty_zone("X")
We can see that the dangling line 'NNL2AA1 XXXXXX11 1' correspond to the X-Node XXXXXX11 (see column ucte-x-node-code of dangling line data frame).
To calculate to sensitivity of X-Node XXXXXX11 on tie line 'BBE2AA1 FFR3AA1 1':

.. code-block:: python
>>> zone_x.add_injection('NNL2AA1 XXXXXX11 1')
>>> sa = pp.sensitivity.create_dc_analysis()
>>> sa.set_zones([zone_x])
>>> sa.set_branch_flow_factor_matrix(['BBE2AA1 FFR3AA1 1'], ['X'])
>>> result = sa.run(n)
>>> result.get_branch_flows_sensitivity_matrix()
BBE2AA1 FFR3AA1 1
X 0.176618
Shift keys modification
^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ static NetworkDataframeMapper danglingLines() {
.strings("voltage_level_id", getVoltageLevelId())
.strings("bus_id", dl -> getBusId(dl.getTerminal()))
.booleans("connected", dl -> dl.getTerminal().isConnected(), connectInjection())
.strings("ucte-x-node-code", dl -> Objects.toString(dl.getUcteXnodeCode(), ""))
.addProperties()
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void danglingLines() {

assertThat(series)
.extracting(Series::getName)
.containsExactly("id", "name", "r", "x", "g", "b", "p0", "q0", "p", "q", "i", "voltage_level_id", "bus_id", "connected");
.containsExactly("id", "name", "r", "x", "g", "b", "p0", "q0", "p", "q", "i", "voltage_level_id", "bus_id", "connected", "ucte-x-node-code");
}

@Test
Expand Down
14 changes: 7 additions & 7 deletions tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,17 +443,17 @@ def test_dangling_lines(self):
n = self.create_dangling_lines_network()
expected = pd.DataFrame(index=pd.Series(name='id', data=['DL']),
columns=['name', 'r', 'x', 'g', 'b', 'p0', 'q0', 'p', 'q', 'i', 'voltage_level_id', 'bus_id',
'connected'],
data=[['', 10.0, 1.0, 0.0001, 0.00001, 50.0, 30.0, NaN, NaN, NaN, 'VL', 'VL_0', True]])
'connected', 'ucte-x-node-code'],
data=[['', 10.0, 1.0, 0.0001, 0.00001, 50.0, 30.0, NaN, NaN, NaN, 'VL', 'VL_0', True, '']])
pd.testing.assert_frame_equal(expected, n.get_dangling_lines(), check_dtype=False)
n.update_dangling_lines(
pd.DataFrame(index=['DL'], columns=['r', 'x', 'g', 'b', 'p0', 'q0', 'connected'],
data=[[11.0, 1.1, 0.0002, 0.00002, 40.0, 40.0, False]]))
udpdated = pd.DataFrame(index=pd.Series(name='id', data=['DL']),
columns=['name', 'r', 'x', 'g', 'b', 'p0', 'q0', 'p', 'q', 'i', 'voltage_level_id', 'bus_id',
'connected'],
data=[['', 11.0, 1.1, 0.0002, 0.00002, 40.0, 40.0, NaN, NaN, NaN, 'VL', '', False]])
pd.testing.assert_frame_equal(udpdated, n.get_dangling_lines(), check_dtype=False)
updated = pd.DataFrame(index=pd.Series(name='id', data=['DL']),
columns=['name', 'r', 'x', 'g', 'b', 'p0', 'q0', 'p', 'q', 'i', 'voltage_level_id', 'bus_id',
'connected', 'ucte-x-node-code'],
data=[['', 11.0, 1.1, 0.0002, 0.00002, 40.0, 40.0, NaN, NaN, NaN, 'VL', '', False, '']])
pd.testing.assert_frame_equal(updated, n.get_dangling_lines(), check_dtype=False)

def test_batteries(self):
n = self.create_battery_network()
Expand Down
17 changes: 17 additions & 0 deletions tests/test_sensitivity_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,23 @@ def test_sensi_power_transfer(self):
self.assertAlmostEqual(0.256641, s['BBE2AA1 FFR3AA1 1']['DE -> FR'], places=6)
self.assertAlmostEqual(0.103426, s['BBE2AA1 FFR3AA1 1']['NL'], places=6)

def test_xnode_sensi(self):
n = pp.network.load(str(DATA_DIR.joinpath('simple-eu-xnode.uct')))
# assert there is one dangling line (corresponding to the UCTE xnode)
dangling_lines = n.get_dangling_lines()
self.assertEqual(1, len(dangling_lines))
# create a new zone with only one xnode, this is the dangling line id that has to be configured (corresponding
# to the line connecting the xnode in the UCTE file)
zone_x = pp.sensitivity.create_empty_zone("X")
zone_x.add_injection('NNL2AA1 XXXXXX11 1')
sa = pp.sensitivity.create_dc_analysis()
sa.set_zones([zone_x])
sa.set_branch_flow_factor_matrix(['BBE2AA1 FFR3AA1 1'], ['X'])
result = sa.run(n)
s = result.get_branch_flows_sensitivity_matrix()
self.assertEqual((1, 1), s.shape)
self.assertAlmostEqual(0.176618, s['BBE2AA1 FFR3AA1 1']['X'], places=6)


if __name__ == '__main__':
unittest.main()

0 comments on commit 678dd6a

Please sign in to comment.