From 11b9ea13036eeae81fcd0127768202f2e2661cbf Mon Sep 17 00:00:00 2001 From: Geoffroy Jamgotchian Date: Wed, 4 Dec 2024 09:38:57 +0100 Subject: [PATCH] Refactoring Signed-off-by: Geoffroy Jamgotchian --- .../iidm/network/impl/VoltageLevelImpl.java | 16 +++++++++------- .../network/tck/AbstractConvertTopologyTest.java | 15 +++++++++++---- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/VoltageLevelImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/VoltageLevelImpl.java index 86d3b062cfe..88e2c5b3936 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/VoltageLevelImpl.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/VoltageLevelImpl.java @@ -622,6 +622,11 @@ public void allocateVariantArrayElement(int[] indexes, int sourceIndex) { private void convertToBusBreakerModel() { BusBreakerTopologyModel newTopologyModel = new BusBreakerTopologyModel(this); + // remove busbar sections because not needed in a bus/breaker topology + for (BusbarSection bbs : topologyModel.getNodeBreakerView().getBusbarSections()) { + bbs.remove(); + } + for (Bus bus : topologyModel.getBusBreakerView().getBuses()) { // no notification, this is just a mutation of a calculation bus to a configured bus ConfiguredBusImpl configuredBus = new ConfiguredBusImpl(bus.getId(), bus.getOptionalName().orElse(null), bus.isFictitious(), this); @@ -664,13 +669,10 @@ record TopologyModelInfos(TerminalExt terminal, String connectableBusId, boolean AbstractConnectable connectable = oldTerminalExt.getConnectable(); // create the new terminal with new type - TerminalExt newTerminalExt = null; - if (oldTerminalExt.getConnectable().getType() != IdentifiableType.BUSBAR_SECTION) { - newTerminalExt = new TerminalBuilder(networkRef, this, oldTerminalExt.getSide()) - .setBus(infos.connected ? infos.connectableBusId() : null) - .setConnectableBus(infos.connectableBusId()) - .build(); - } + TerminalExt newTerminalExt = new TerminalBuilder(networkRef, this, oldTerminalExt.getSide()) + .setBus(infos.connected ? infos.connectableBusId() : null) + .setConnectableBus(infos.connectableBusId()) + .build(); connectable.replaceTerminal(oldTerminalExt, newTopologyModel, newTerminalExt, false); } diff --git a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractConvertTopologyTest.java b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractConvertTopologyTest.java index 6389ff23ff2..03ec6becfdf 100644 --- a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractConvertTopologyTest.java +++ b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractConvertTopologyTest.java @@ -17,8 +17,7 @@ import java.util.Collections; import java.util.List; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.*; /** * @author Geoffroy Jamgotchian {@literal } @@ -59,7 +58,11 @@ void testNodeBreakerToBusBreaker() { assertEquals(List.of("VSC1", "LD2", "LD3", "LD4", "LCC1"), busesBbModel.get(1).getConnectedTerminalStream().map(t -> t.getConnectable().getId()).toList()); // only retained switches have been kept assertEquals(List.of("S1VL2_COUPLER"), vl.getBusBreakerView().getSwitchStream().map(Identifiable::getId).toList()); - assertEquals(List.of(new RemovalNetworkEvent("S1VL2_BBS1_TWT_DISCONNECTOR", false), + assertEquals(List.of(new RemovalNetworkEvent("S1VL2_BBS1", false), + new RemovalNetworkEvent("S1VL2_BBS1", true), + new RemovalNetworkEvent("S1VL2_BBS2", false), + new RemovalNetworkEvent("S1VL2_BBS2", true), + new RemovalNetworkEvent("S1VL2_BBS1_TWT_DISCONNECTOR", false), new RemovalNetworkEvent("S1VL2_BBS2_TWT_DISCONNECTOR", false), new RemovalNetworkEvent("S1VL2_TWT_BREAKER", false), new RemovalNetworkEvent("S1VL2_BBS1_VSC1_DISCONNECTOR", false), @@ -128,6 +131,10 @@ void testNodeBreakerToBusBreaker() { // check regulating terminal has been correctly updated assertEquals("S1VL2_0", gh1.getRegulatingTerminal().getBusBreakerView().getBus().getId()); + + // check busbar sections have been removed + assertNull(network.getBusbarSection("S1VL2_BBS1")); + assertNull(network.getBusbarSection("S1VL2_BBS2")); } @Test @@ -143,7 +150,7 @@ void testNodeBreakerToBusBreakerOneElementDisconnected() { assertEquals(List.of("S1VL2_BBS2", "VSC1", "LD2", "LD3", "LD4", "LCC1"), busesNbModel.get(1).getConnectedTerminalStream().map(t -> t.getConnectable().getId()).toList()); assertEquals(List.of("GH2"), busesNbModel.get(2).getConnectedTerminalStream().map(t -> t.getConnectable().getId()).toList()); vl.convertToTopology(TopologyKind.BUS_BREAKER); - assertEquals(65, eventRecorder.getEvents().size()); + assertEquals(69, eventRecorder.getEvents().size()); var busesBbModel = vl.getBusBreakerView().getBusStream().toList(); assertEquals(3, busesBbModel.size());