diff --git a/flow-decomposition/src/main/java/com/powsybl/flow_decomposition/NetPositionComputer.java b/flow-decomposition/src/main/java/com/powsybl/flow_decomposition/NetPositionComputer.java index 47c1a89d..3fe22400 100644 --- a/flow-decomposition/src/main/java/com/powsybl/flow_decomposition/NetPositionComputer.java +++ b/flow-decomposition/src/main/java/com/powsybl/flow_decomposition/NetPositionComputer.java @@ -66,7 +66,7 @@ private static void addLeavingFlow(Map netPositions, HvdcLine h } private static void addLeavingFlow(Map netPositions, DanglingLine danglingLine, Country country) { - Double previousValue = getPreviousValue(netPositions, country); + double previousValue = getPreviousValue(netPositions, country); netPositions.put(country, previousValue + getLeavingFlow(danglingLine)); } 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 a4dbfe23..20b896bd 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 @@ -19,49 +19,59 @@ /** * @author Sebastien Murgey {@literal } * @author Peter Mitri {@literal } + * @author Hugo Schindler{@literal } */ class NetPositionTest { private static final double DOUBLE_TOLERANCE = 1e-3; - @Test - void testLines() { - Network network = Network.read("testCase.xiidm", getClass().getResourceAsStream("testCase.xiidm")); - LoadFlow.run(network, new LoadFlowParameters().setDc(true)); + private static void assertNetPosition(Network network, double netPositionBe, double netPositionNl, double netPositionDe) { 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); + assertEquals(netPositionBe, netPositions.get(Country.BE), DOUBLE_TOLERANCE); + assertEquals(netPositionNl, netPositions.get(Country.NL), DOUBLE_TOLERANCE); + assertEquals(netPositionDe, netPositions.get(Country.DE), DOUBLE_TOLERANCE); + double sumAllNetPositions = netPositions.values().stream().mapToDouble(Double::doubleValue).sum(); + assertEquals(0.0, sumAllNetPositions, DOUBLE_TOLERANCE); + } + + private static void assertNetPositionForHvdc(Network network, double countryNetPosition) { + Map netPositions = NetPositionComputer.computeNetPositions(network); + assertEquals(countryNetPosition, netPositions.get(Country.FR), DOUBLE_TOLERANCE); + assertEquals(-countryNetPosition, netPositions.get(Country.DE), DOUBLE_TOLERANCE); double sumAllNetPositions = netPositions.values().stream().mapToDouble(Double::doubleValue).sum(); assertEquals(0.0, sumAllNetPositions, DOUBLE_TOLERANCE); } + @Test + void testLines() { + Network network = Network.read("testCase.xiidm", getClass().getResourceAsStream("testCase.xiidm")); + LoadFlow.run(network, new LoadFlowParameters().setDc(true)); + assertNetPosition(network, 1500.0, 0.0, -2500.0); + } + @Test 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(); + network.getBranch("NNL2AA1 BBE3AA1 1").getTerminal1().disconnect(); + network.getBranch("NNL2AA1 BBE3AA1 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); + assertNetPosition(network, 1500.0, 0.0, -2500.0); + } + + @Test + void testLinesNaN() { + Network network = Network.read("testCase.xiidm", getClass().getResourceAsStream("testCase.xiidm")); + LoadFlow.run(network, new LoadFlowParameters().setDc(true)); + network.getBranch("NNL2AA1 BBE3AA1 1").getTerminal1().setP(Double.NaN); + network.getBranch("NNL2AA1 BBE3AA1 1").getTerminal2().setP(Double.NaN); + assertNetPosition(network, 324.666, 1175.334, -2500.0); } @Test void testDanglingLinesBalanced() { Network network = Network.read("TestCaseDangling.xiidm", getClass().getResourceAsStream("TestCaseDangling.xiidm")); 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); - 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); + assertNetPosition(network, 2300.0, -500.0, -2800.0); } @Test @@ -69,13 +79,15 @@ 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(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); + assertNetPosition(network, 2300.0, -500.0, -2800.0); + } + + @Test + void testDanglingLinesNaN() { + Network network = Network.read("TestCaseDangling.xiidm", getClass().getResourceAsStream("TestCaseDangling.xiidm")); + LoadFlow.run(network, new LoadFlowParameters().setDc(true)); + network.getDanglingLine("BBE2AA1 X_BEFR1 1").getTerminal().setP(Double.NaN); + assertNetPosition(network, 2300.0, -500.0, -2800.0); } @Test @@ -92,11 +104,7 @@ void testDanglingLinesUnbalanced() { @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); + assertNetPositionForHvdc(network, 272.0); } @Test @@ -104,10 +112,14 @@ 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); + assertNetPositionForHvdc(network, 200.0); + } + + @Test + void testHvdcLinesNaN() { + Network network = Network.read("TestCaseHvdc.xiidm", getClass().getResourceAsStream("TestCaseHvdc.xiidm")); + network.getHvdcLine("hvdc_line_FR_1_DE").getConverterStation1().getTerminal().setP(Double.NaN); + network.getHvdcLine("hvdc_line_FR_1_DE").getConverterStation2().getTerminal().setP(Double.NaN); + assertNetPositionForHvdc(network, 200.0); } }