From c068869cbc27c37b50e0a3e07cf37167faf67563 Mon Sep 17 00:00:00 2001 From: Coline PILOQUET Date: Tue, 28 Mar 2023 12:04:30 +0200 Subject: [PATCH 1/4] Bug fix. Signed-off-by: Coline PILOQUET --- .../iidm/modification/topology/RemoveHvdcLine.java | 14 +++++++------- .../modification/topology/RemoveVoltageLevel.java | 5 ++--- .../topology/RemoveVoltageLevelTest.java | 6 +++--- .../resources/eurostag-remove-voltage-level-nb.xml | 13 ++++--------- 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/RemoveHvdcLine.java b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/RemoveHvdcLine.java index f27eb9521d1..14a9dd51686 100644 --- a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/RemoveHvdcLine.java +++ b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/RemoveHvdcLine.java @@ -57,8 +57,8 @@ public void apply(Network network, boolean throwException, ComputationManager co hvdcLine.remove(); removedHvdcLineReport(reporter, hvdcLineId); // Remove the Shunt compensators that represent the filters of the LCC - removeShuntCompensators(hvdcConverterStation1, hvdcConverterStation2, shunts, reporter); - removeConverterStations(hvdcConverterStation1, hvdcConverterStation2, reporter); + removeShuntCompensators(network, hvdcConverterStation1, hvdcConverterStation2, shunts, throwException, computationManager, reporter); + removeConverterStations(network, hvdcConverterStation1, hvdcConverterStation2, throwException, computationManager, reporter); } else { LOGGER.error("Hvdc Line {} not found", hvdcLineId); notFoundHvdcLineReport(reporter, hvdcLineId); @@ -80,7 +80,7 @@ private static ShuntCompensator getShuntCompensator(String id, Network network, return sc; } - private static void removeShuntCompensators(HvdcConverterStation hvdcConverterStation1, HvdcConverterStation hvdcConverterStation2, Set shunts, Reporter reporter) { + private static void removeShuntCompensators(Network network, HvdcConverterStation hvdcConverterStation1, HvdcConverterStation hvdcConverterStation2, Set shunts, boolean throwException, ComputationManager computationManager, Reporter reporter) { if (shunts == null) { return; } @@ -94,7 +94,7 @@ private static void removeShuntCompensators(HvdcConverterStation hvdcConverte VoltageLevel shuntVl = shuntCompensator.getTerminal().getVoltageLevel(); // check whether the shunt compensator is connected to the same voltage level as the lcc if (vl1 == shuntVl || vl2 == shuntVl) { - shuntCompensator.remove(); + new RemoveFeederBay(shuntCompensator.getId()).apply(network, throwException, computationManager, reporter); removedShuntCompensatorReport(reporter, shuntCompensator.getId()); } else { LOGGER.warn("Shunt compensator {} has been ignored because it is not in the same voltage levels as the Lcc ({} or {})", shuntCompensator.getId(), vl1.getId(), vl2.getId()); @@ -103,9 +103,9 @@ private static void removeShuntCompensators(HvdcConverterStation hvdcConverte } } - private static void removeConverterStations(HvdcConverterStation hvdcConverterStation1, HvdcConverterStation hvdcConverterStation2, Reporter reporter) { - hvdcConverterStation1.remove(); - hvdcConverterStation2.remove(); + private static void removeConverterStations(Network network, HvdcConverterStation hvdcConverterStation1, HvdcConverterStation hvdcConverterStation2, boolean throwException, ComputationManager computationManager, Reporter reporter) { + new RemoveFeederBay(hvdcConverterStation1.getId()).apply(network, throwException, computationManager, reporter); + new RemoveFeederBay(hvdcConverterStation2.getId()).apply(network, throwException, computationManager, reporter); reportConverterStationRemoved(reporter, hvdcConverterStation1); reportConverterStationRemoved(reporter, hvdcConverterStation2); } diff --git a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/RemoveVoltageLevel.java b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/RemoveVoltageLevel.java index 84b2dab8132..ebf78e53be3 100644 --- a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/RemoveVoltageLevel.java +++ b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/RemoveVoltageLevel.java @@ -46,12 +46,11 @@ public void apply(Network network, boolean throwException, ComputationManager co voltageLevel.getConnectables(HvdcConverterStation.class).forEach(hcs -> { if (hcs.getHvdcLine() != null) { - hcs.getHvdcLine().remove(); + new RemoveHvdcLineBuilder().withHvdcLineId(hcs.getHvdcLine().getId()).build().apply(network, throwException, computationManager, reporter); } - hcs.remove(); }); - voltageLevel.getConnectables().forEach(Connectable::remove); + voltageLevel.getConnectables().forEach(connectable -> new RemoveFeederBayBuilder().withConnectableId(connectable.getId()).build().apply(network, throwException, computationManager, reporter)); voltageLevel.remove(); removedVoltageLevelReport(reporter, voltageLevelId); diff --git a/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/RemoveVoltageLevelTest.java b/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/RemoveVoltageLevelTest.java index 26a7876365b..131f51f1387 100644 --- a/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/RemoveVoltageLevelTest.java +++ b/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/RemoveVoltageLevelTest.java @@ -59,8 +59,8 @@ void testRemoveVoltageLevel() { addListener(network); new RemoveVoltageLevelBuilder().withVoltageLevelId("S1VL1").build().apply(network); - assertEquals(Set.of("TWT", "S1VL1_BBS", "S1VL1_BBS_TWT_DISCONNECTOR", "S1VL1", "S1VL1_LD1_BREAKER", "LD1", "S1VL1_TWT_BREAKER", "S1VL1_BBS_LD1_DISCONNECTOR"), beforeRemovalObjects); - assertEquals(Set.of("TWT", "S1VL1_BBS", "S1VL1_BBS_TWT_DISCONNECTOR", "S1VL1", "S1VL1_LD1_BREAKER", "LD1", "S1VL1_TWT_BREAKER", "S1VL1_BBS_LD1_DISCONNECTOR"), removedObjects); + assertEquals(Set.of("TWT", "S1VL1_BBS", "S1VL1_BBS_TWT_DISCONNECTOR", "S1VL1", "S1VL1_LD1_BREAKER", "LD1", "S1VL1_TWT_BREAKER", "S1VL1_BBS_LD1_DISCONNECTOR", "S1VL2_BBS1_TWT_DISCONNECTOR", "S1VL2_BBS2_TWT_DISCONNECTOR", "S1VL2_TWT_BREAKER"), beforeRemovalObjects); + assertEquals(Set.of("TWT", "S1VL1_BBS", "S1VL1_BBS_TWT_DISCONNECTOR", "S1VL1", "S1VL1_LD1_BREAKER", "LD1", "S1VL1_TWT_BREAKER", "S1VL1_BBS_LD1_DISCONNECTOR", "S1VL2_BBS1_TWT_DISCONNECTOR", "S1VL2_BBS2_TWT_DISCONNECTOR", "S1VL2_TWT_BREAKER"), removedObjects); assertNull(network.getVoltageLevel("S1VL1")); assertNull(network.getTwoWindingsTransformer("TWT")); @@ -86,7 +86,7 @@ void testRemoveVLRoundTripNB() throws IOException { Network network = createNbNetwork(); NetworkModification modification = new RemoveVoltageLevelBuilder().withVoltageLevelId("C").build(); modification.apply(network); - roundTripXmlTest(network, NetworkXml::writeAndValidate, NetworkXml::validateAndRead, + roundTripTest(network, NetworkXml::writeAndValidate, NetworkXml::validateAndRead, "/eurostag-remove-voltage-level-nb.xml"); } diff --git a/iidm/iidm-modification/src/test/resources/eurostag-remove-voltage-level-nb.xml b/iidm/iidm-modification/src/test/resources/eurostag-remove-voltage-level-nb.xml index c3c6fa4b1f3..059ca1a52c1 100644 --- a/iidm/iidm-modification/src/test/resources/eurostag-remove-voltage-level-nb.xml +++ b/iidm/iidm-modification/src/test/resources/eurostag-remove-voltage-level-nb.xml @@ -1,6 +1,7 @@ + - + @@ -13,7 +14,6 @@ - - \ No newline at end of file + From 959f8512f676b6d5df772b7b345df6a9e13fee1c Mon Sep 17 00:00:00 2001 From: Coline PILOQUET Date: Tue, 28 Mar 2023 13:06:44 +0200 Subject: [PATCH 2/4] Revert changes on testRemoveVLRoundTripNB Signed-off-by: Coline PILOQUET --- .../iidm/modification/topology/RemoveVoltageLevelTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/RemoveVoltageLevelTest.java b/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/RemoveVoltageLevelTest.java index 131f51f1387..4c79287b4ff 100644 --- a/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/RemoveVoltageLevelTest.java +++ b/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/RemoveVoltageLevelTest.java @@ -86,7 +86,7 @@ void testRemoveVLRoundTripNB() throws IOException { Network network = createNbNetwork(); NetworkModification modification = new RemoveVoltageLevelBuilder().withVoltageLevelId("C").build(); modification.apply(network); - roundTripTest(network, NetworkXml::writeAndValidate, NetworkXml::validateAndRead, + roundTripXmlTest(network, NetworkXml::writeAndValidate, NetworkXml::validateAndRead, "/eurostag-remove-voltage-level-nb.xml"); } From e45d988d2d885579a81828a14a3a5bfc6e90fb65 Mon Sep 17 00:00:00 2001 From: Coline PILOQUET Date: Tue, 28 Mar 2023 18:17:01 +0200 Subject: [PATCH 3/4] Review. Signed-off-by: Coline PILOQUET --- .../iidm/modification/topology/RemoveVoltageLevel.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/RemoveVoltageLevel.java b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/RemoveVoltageLevel.java index ebf78e53be3..c523e6a3b18 100644 --- a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/RemoveVoltageLevel.java +++ b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/RemoveVoltageLevel.java @@ -50,7 +50,9 @@ public void apply(Network network, boolean throwException, ComputationManager co } }); - voltageLevel.getConnectables().forEach(connectable -> new RemoveFeederBayBuilder().withConnectableId(connectable.getId()).build().apply(network, throwException, computationManager, reporter)); + voltageLevel.getConnectables(Branch.class).forEach(branch -> new RemoveFeederBayBuilder().withConnectableId(branch.getId()).build().apply(network, throwException, computationManager, reporter)); + voltageLevel.getConnectables(ThreeWindingsTransformer.class).forEach(threewt -> new RemoveFeederBayBuilder().withConnectableId(threewt.getId()).build().apply(network, throwException, computationManager, reporter)); + voltageLevel.getConnectables().forEach(Connectable::remove); voltageLevel.remove(); removedVoltageLevelReport(reporter, voltageLevelId); From 6b4d2805b010f896de66e2c6906dfb96a09d1282 Mon Sep 17 00:00:00 2001 From: Coline PILOQUET Date: Wed, 29 Mar 2023 14:03:53 +0200 Subject: [PATCH 4/4] Review. Signed-off-by: Coline PILOQUET --- .../iidm/modification/topology/RemoveVoltageLevel.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/RemoveVoltageLevel.java b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/RemoveVoltageLevel.java index c523e6a3b18..99f6ed458f7 100644 --- a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/RemoveVoltageLevel.java +++ b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/RemoveVoltageLevel.java @@ -50,9 +50,13 @@ public void apply(Network network, boolean throwException, ComputationManager co } }); - voltageLevel.getConnectables(Branch.class).forEach(branch -> new RemoveFeederBayBuilder().withConnectableId(branch.getId()).build().apply(network, throwException, computationManager, reporter)); - voltageLevel.getConnectables(ThreeWindingsTransformer.class).forEach(threewt -> new RemoveFeederBayBuilder().withConnectableId(threewt.getId()).build().apply(network, throwException, computationManager, reporter)); - voltageLevel.getConnectables().forEach(Connectable::remove); + voltageLevel.getConnectables().forEach(connectable -> { + if (connectable instanceof Injection) { + connectable.remove(); + } else { + new RemoveFeederBayBuilder().withConnectableId(connectable.getId()).build().apply(network, throwException, computationManager, reporter); + } + }); voltageLevel.remove(); removedVoltageLevelReport(reporter, voltageLevelId);