From 7c776990a5eeadfe8224932eca72e2854c919d1d Mon Sep 17 00:00:00 2001 From: Hugo SCHINDLER Date: Mon, 29 Jan 2024 13:39:04 +0100 Subject: [PATCH] Refactor test Signed-off-by: Hugo SCHINDLER --- .../flow_decomposition/NetPositionTest.java | 56 ++++++++++++++++--- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/flow-decomposition/src/test/java/com/powsybl/flow_decomposition/NetPositionTest.java b/flow-decomposition/src/test/java/com/powsybl/flow_decomposition/NetPositionTest.java index 0c829f5f..a4dbfe23 100644 --- a/flow-decomposition/src/test/java/com/powsybl/flow_decomposition/NetPositionTest.java +++ b/flow-decomposition/src/test/java/com/powsybl/flow_decomposition/NetPositionTest.java @@ -26,6 +26,7 @@ class NetPositionTest { @Test void testLines() { Network network = Network.read("testCase.xiidm", getClass().getResourceAsStream("testCase.xiidm")); + LoadFlow.run(network, new LoadFlowParameters().setDc(true)); Map netPositions = NetPositionComputer.computeNetPositions(network); assertEquals(1000.0, netPositions.get(Country.FR), DOUBLE_TOLERANCE); assertEquals(1500.0, netPositions.get(Country.BE), DOUBLE_TOLERANCE); @@ -36,9 +37,24 @@ void testLines() { } @Test - void testDanglingLines() { + void testLinesDisconnected() { + Network network = Network.read("testCase.xiidm", getClass().getResourceAsStream("testCase.xiidm")); + network.getBranch("BBE1AA1 BBE2AA1 1").getTerminal1().disconnect(); + network.getBranch("BBE1AA1 BBE2AA1 1").getTerminal2().disconnect(); + LoadFlow.run(network, new LoadFlowParameters().setDc(true)); + Map netPositions = NetPositionComputer.computeNetPositions(network); + assertEquals(1000.0, netPositions.get(Country.FR), DOUBLE_TOLERANCE); + assertEquals(1500.0, netPositions.get(Country.BE), DOUBLE_TOLERANCE); + assertEquals(0.0, netPositions.get(Country.NL), DOUBLE_TOLERANCE); + assertEquals(-2500.0, netPositions.get(Country.DE), DOUBLE_TOLERANCE); + double sumAllNetPositions = netPositions.values().stream().mapToDouble(Double::doubleValue).sum(); + assertEquals(0.0, sumAllNetPositions, DOUBLE_TOLERANCE); + } + + @Test + void testDanglingLinesBalanced() { Network network = Network.read("TestCaseDangling.xiidm", getClass().getResourceAsStream("TestCaseDangling.xiidm")); - LoadFlow.run(network); + LoadFlow.run(network, new LoadFlowParameters().setDc(true)); Map netPositions = NetPositionComputer.computeNetPositions(network); assertEquals(1000.0, netPositions.get(Country.FR), DOUBLE_TOLERANCE); assertEquals(2300.0, netPositions.get(Country.BE), DOUBLE_TOLERANCE); @@ -49,17 +65,21 @@ void testDanglingLines() { } @Test - void testHvdcLines() { - Network network = Network.read("TestCaseHvdc.xiidm", getClass().getResourceAsStream("TestCaseHvdc.xiidm")); + void testDanglingLinesDisconnected() { + Network network = Network.read("TestCaseDangling.xiidm", getClass().getResourceAsStream("TestCaseDangling.xiidm")); + network.getDanglingLine("BBE2AA1 X_BEFR1 1").getTerminal().disconnect(); + LoadFlow.run(network, new LoadFlowParameters().setDc(true)); Map netPositions = NetPositionComputer.computeNetPositions(network); - assertEquals(272.0, netPositions.get(Country.FR), DOUBLE_TOLERANCE); - assertEquals(-272.0, netPositions.get(Country.DE), DOUBLE_TOLERANCE); + assertEquals(1000.0, netPositions.get(Country.FR), DOUBLE_TOLERANCE); + assertEquals(2300.0, netPositions.get(Country.BE), DOUBLE_TOLERANCE); + assertEquals(-500.0, netPositions.get(Country.NL), DOUBLE_TOLERANCE); + assertEquals(-2800.0, netPositions.get(Country.DE), DOUBLE_TOLERANCE); double sumAllNetPositions = netPositions.values().stream().mapToDouble(Double::doubleValue).sum(); assertEquals(0.0, sumAllNetPositions, DOUBLE_TOLERANCE); } @Test - void testUnboundedXnode() { + void testDanglingLinesUnbalanced() { Network network = Network.read("NETWORK_SINGLE_LOAD_TWO_GENERATORS_WITH_UNBOUNDED_XNODE.uct", getClass().getResourceAsStream("NETWORK_SINGLE_LOAD_TWO_GENERATORS_WITH_UNBOUNDED_XNODE.uct")); LoadFlow.run(network, new LoadFlowParameters().setDc(true)); Map netPositions = NetPositionComputer.computeNetPositions(network); @@ -68,4 +88,26 @@ void testUnboundedXnode() { double sumAllNetPositions = netPositions.values().stream().mapToDouble(Double::doubleValue).sum(); assertEquals(100, sumAllNetPositions, DOUBLE_TOLERANCE); } + + @Test + void testHvdcLines() { + Network network = Network.read("TestCaseHvdc.xiidm", getClass().getResourceAsStream("TestCaseHvdc.xiidm")); + Map netPositions = NetPositionComputer.computeNetPositions(network); + assertEquals(272.0, netPositions.get(Country.FR), DOUBLE_TOLERANCE); + assertEquals(-272.0, netPositions.get(Country.DE), DOUBLE_TOLERANCE); + double sumAllNetPositions = netPositions.values().stream().mapToDouble(Double::doubleValue).sum(); + assertEquals(0.0, sumAllNetPositions, DOUBLE_TOLERANCE); + } + + @Test + void testHvdcLinesDisconnected() { + Network network = Network.read("TestCaseHvdc.xiidm", getClass().getResourceAsStream("TestCaseHvdc.xiidm")); + network.getHvdcLine("hvdc_line_FR_1_DE").getConverterStation1().getTerminal().disconnect(); + network.getHvdcLine("hvdc_line_FR_1_DE").getConverterStation2().getTerminal().disconnect(); + Map netPositions = NetPositionComputer.computeNetPositions(network); + assertEquals(200.0, netPositions.get(Country.FR), DOUBLE_TOLERANCE); + assertEquals(-200.0, netPositions.get(Country.DE), DOUBLE_TOLERANCE); + double sumAllNetPositions = netPositions.values().stream().mapToDouble(Double::doubleValue).sum(); + assertEquals(0.0, sumAllNetPositions, DOUBLE_TOLERANCE); + } }