diff --git a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/CreateVoltageLevelTopology.java b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/CreateVoltageLevelTopology.java index 2375771503b..611e69b2d03 100644 --- a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/CreateVoltageLevelTopology.java +++ b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/CreateVoltageLevelTopology.java @@ -15,11 +15,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Objects; -import static com.powsybl.iidm.modification.topology.ModificationReports.*; -import static com.powsybl.iidm.modification.topology.TopologyModificationUtils.createNBBreaker; -import static com.powsybl.iidm.modification.topology.TopologyModificationUtils.createNBDisconnector; +import static com.powsybl.iidm.modification.topology.ModificationReports.createdNewSymmetricalTopology; +import static com.powsybl.iidm.modification.topology.ModificationReports.notFoundVoltageLevelReport; +import static com.powsybl.iidm.modification.topology.TopologyModificationUtils.*; /** * Creates symmetrical matrix topology in a given voltage level, @@ -36,27 +39,27 @@ public class CreateVoltageLevelTopology extends AbstractNetworkModification { private final String voltageLevelId; - private final int lowBusbarIndex; - private final int busbarCount; + private final int lowBusOrBusbarIndex; + private final int alignedBusesOrBusbarCount; private final int lowSectionIndex; private final int sectionCount; - private final String busbarSectionPrefixId; + private final String busOrBusbarSectionPrefixId; private final String switchPrefixId; private final List switchKinds; - CreateVoltageLevelTopology(String voltageLevelId, int lowBusbarIndex, Integer busbarCount, + CreateVoltageLevelTopology(String voltageLevelId, int lowBusOrBusbarIndex, Integer alignedBusesOrBusbarCount, int lowSectionIndex, Integer sectionCount, - String busbarSectionPrefixId, String switchPrefixId, List switchKinds) { + String busOrBusbarSectionPrefixId, String switchPrefixId, List switchKinds) { this.voltageLevelId = Objects.requireNonNull(voltageLevelId, "Undefined voltage level ID"); - this.lowBusbarIndex = checkCount(lowBusbarIndex, "low busbar index", 0); - this.busbarCount = checkCount(busbarCount, "busBar count", 1); + this.lowBusOrBusbarIndex = checkCount(lowBusOrBusbarIndex, "low busbar index", 0); + this.alignedBusesOrBusbarCount = checkCount(alignedBusesOrBusbarCount, "busBar count", 1); this.lowSectionIndex = checkCount(lowSectionIndex, "low section index", 0); this.sectionCount = checkCount(sectionCount, "section count", 1); - this.busbarSectionPrefixId = Objects.requireNonNull(busbarSectionPrefixId, "Undefined busbar section prefix ID"); + this.busOrBusbarSectionPrefixId = Objects.requireNonNull(busOrBusbarSectionPrefixId, "Undefined busbar section prefix ID"); this.switchPrefixId = Objects.requireNonNull(switchPrefixId, "Undefined switch prefix ID"); - this.switchKinds = checkSwitchKinds(switchKinds, sectionCount); + this.switchKinds = switchKinds; } private static int checkCount(Integer count, String type, int min) { @@ -85,12 +88,12 @@ public String getVoltageLevelId() { return voltageLevelId; } - public int getLowBusbarIndex() { - return lowBusbarIndex; + public int getLowBusOrBusbarIndex() { + return lowBusOrBusbarIndex; } - public int getBusbarCount() { - return busbarCount; + public int getAlignedBusesOrBusbarCount() { + return alignedBusesOrBusbarCount; } public int getLowSectionIndex() { @@ -117,35 +120,37 @@ public void apply(Network network, boolean throwException, ComputationManager co } return; } - // Check voltage level is NODE_BREAKER TopologyKind topologyKind = voltageLevel.getTopologyKind(); - if (topologyKind != TopologyKind.NODE_BREAKER) { - LOG.error("Voltage Level {} has an unsupported topology {}. Should be {}", voltageLevelId, topologyKind, TopologyKind.NODE_BREAKER); - unsupportedVoltageLevelTopologyKind(reporter, voltageLevelId, TopologyKind.NODE_BREAKER, topologyKind); - if (throwException) { - throw new PowsyblException(String.format("Voltage Level %s has an unsupported topology %s. Should be %s", - voltageLevelId, topologyKind.name(), TopologyKind.NODE_BREAKER.name())); + if (topologyKind == TopologyKind.BUS_BREAKER) { + if (!switchKinds.isEmpty()) { + LOG.warn("Voltage level {} is BUS_BREAKER. Switchkinds is ignored.", voltageLevelId); } - return; + // Create buses + createBuses(voltageLevel); + // Create switches between buses + createBusBreakerSwitches(voltageLevel); + } else { + // Check switch kinds + checkSwitchKinds(switchKinds, sectionCount); + // Create busbar sections + createBusbarSections(voltageLevel); + // Create switches + createSwitches(voltageLevel); } - // Create busbar sections - createBusBarSections(voltageLevel); - // Create switches - createSwitches(voltageLevel); - LOG.info("New symmetrical topology in voltage level {}: creation of {} busbar(s) with {} section(s) each.", voltageLevelId, busbarCount, sectionCount); - createdNewSymmetricalTopology(reporter, voltageLevelId, busbarCount, sectionCount); + LOG.info("New symmetrical topology in voltage level {}: creation of {} bus(es) or busbar(s) with {} section(s) each.", voltageLevelId, alignedBusesOrBusbarCount, sectionCount); + createdNewSymmetricalTopology(reporter, voltageLevelId, alignedBusesOrBusbarCount, sectionCount); } - private void createBusBarSections(VoltageLevel voltageLevel) { + private void createBusbarSections(VoltageLevel voltageLevel) { int node = 0; for (int sectionNum = lowSectionIndex; sectionNum < lowSectionIndex + sectionCount; sectionNum++) { - for (int busBarNum = lowBusbarIndex; busBarNum < lowBusbarIndex + busbarCount; busBarNum++) { + for (int busbarNum = lowBusOrBusbarIndex; busbarNum < lowBusOrBusbarIndex + alignedBusesOrBusbarCount; busbarNum++) { BusbarSection bbs = voltageLevel.getNodeBreakerView().newBusbarSection() - .setId(busbarSectionPrefixId + SEPARATOR + busBarNum + SEPARATOR + sectionNum) + .setId(busOrBusbarSectionPrefixId + SEPARATOR + busbarNum + SEPARATOR + sectionNum) .setNode(node) .add(); bbs.newExtension(BusbarSectionPositionAdder.class) - .withBusbarIndex(busBarNum) + .withBusbarIndex(busbarNum) .withSectionIndex(sectionNum) .add(); node++; @@ -153,21 +158,41 @@ private void createBusBarSections(VoltageLevel voltageLevel) { } } + private void createBuses(VoltageLevel voltageLevel) { + for (int sectionNum = lowSectionIndex; sectionNum < lowSectionIndex + sectionCount; sectionNum++) { + for (int busNum = lowBusOrBusbarIndex; busNum < lowBusOrBusbarIndex + alignedBusesOrBusbarCount; busNum++) { + voltageLevel.getBusBreakerView().newBus() + .setId(busOrBusbarSectionPrefixId + SEPARATOR + busNum + SEPARATOR + sectionNum) + .add(); + } + } + } + + private void createBusBreakerSwitches(VoltageLevel voltageLevel) { + for (int sectionNum = lowSectionIndex; sectionNum < lowSectionIndex + sectionCount - 1; sectionNum++) { + for (int busNum = lowBusOrBusbarIndex; busNum < lowSectionIndex + alignedBusesOrBusbarCount; busNum++) { + String bus1Id = busOrBusbarSectionPrefixId + SEPARATOR + busNum + SEPARATOR + sectionNum; + String bus2Id = busOrBusbarSectionPrefixId + SEPARATOR + busNum + SEPARATOR + (sectionNum + 1); + createBusBreakerSwitch(bus1Id, bus2Id, switchPrefixId + SEPARATOR, SEPARATOR + busNum + SEPARATOR + sectionNum, voltageLevel.getBusBreakerView()); + } + } + } + private void createSwitches(VoltageLevel voltageLevel) { for (int sectionNum = lowSectionIndex; sectionNum < lowSectionIndex + sectionCount - 1; sectionNum++) { SwitchKind switchKind = switchKinds.get(sectionNum - 1); - for (int busBarNum = lowBusbarIndex; busBarNum < lowBusbarIndex + busbarCount; busBarNum++) { + for (int busBarNum = lowBusOrBusbarIndex; busBarNum < lowBusOrBusbarIndex + alignedBusesOrBusbarCount; busBarNum++) { if (switchKind == SwitchKind.BREAKER) { - int node1 = getNode(busBarNum, sectionNum, busbarSectionPrefixId, voltageLevel); + int node1 = getNode(busBarNum, sectionNum, busOrBusbarSectionPrefixId, voltageLevel); int node2 = voltageLevel.getNodeBreakerView().getMaximumNodeIndex() + 1; int node3 = node2 + 1; - int node4 = getNode(busBarNum, sectionNum + 1, busbarSectionPrefixId, voltageLevel); + int node4 = getNode(busBarNum, sectionNum + 1, busOrBusbarSectionPrefixId, voltageLevel); createNBDisconnector(node1, node2, SEPARATOR + busBarNum + SEPARATOR + sectionNum, switchPrefixId, voltageLevel.getNodeBreakerView(), false); createNBBreaker(node2, node3, SEPARATOR + busBarNum + SEPARATOR + sectionNum, switchPrefixId, voltageLevel.getNodeBreakerView(), false); createNBDisconnector(node3, node4, SEPARATOR + busBarNum + SEPARATOR + sectionNum, switchPrefixId, voltageLevel.getNodeBreakerView(), false); } else if (switchKind == SwitchKind.DISCONNECTOR) { - int node1 = getNode(busBarNum, sectionNum, busbarSectionPrefixId, voltageLevel); - int node2 = getNode(busBarNum, sectionNum + 1, busbarSectionPrefixId, voltageLevel); + int node1 = getNode(busBarNum, sectionNum, busOrBusbarSectionPrefixId, voltageLevel); + int node2 = getNode(busBarNum, sectionNum + 1, busOrBusbarSectionPrefixId, voltageLevel); createNBDisconnector(node1, node2, SEPARATOR + busBarNum + SEPARATOR + sectionNum, switchPrefixId, voltageLevel.getNodeBreakerView(), false); } // other cases cannot happen (has been checked in the constructor) } diff --git a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/CreateVoltageLevelTopologyBuilder.java b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/CreateVoltageLevelTopologyBuilder.java index 7582c9e270a..3bafcb02287 100644 --- a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/CreateVoltageLevelTopologyBuilder.java +++ b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/CreateVoltageLevelTopologyBuilder.java @@ -20,12 +20,12 @@ public class CreateVoltageLevelTopologyBuilder { private String voltageLevelId = null; - private int lowBusbarIndex = 1; - private Integer busbarCount = null; + private int lowBusOrBusbarIndex = 1; + private Integer alignedBusesOrBusbarCount = null; private int lowSectionIndex = 1; private Integer sectionCount = null; - private String busbarSectionPrefixId = null; + private String busOrBusbarSectionPrefixId = null; private String switchPrefixId = null; private List switchKinds = Collections.emptyList(); @@ -38,8 +38,8 @@ public class CreateVoltageLevelTopologyBuilder { */ public CreateVoltageLevelTopologyBuilder withVoltageLevelId(String voltageLevelId) { this.voltageLevelId = voltageLevelId; - if (busbarSectionPrefixId == null) { - busbarSectionPrefixId = voltageLevelId; + if (busOrBusbarSectionPrefixId == null) { + busOrBusbarSectionPrefixId = voltageLevelId; } if (switchPrefixId == null) { switchPrefixId = voltageLevelId; @@ -48,22 +48,24 @@ public CreateVoltageLevelTopologyBuilder withVoltageLevelId(String voltageLevelI } /** - * Set the lowest index of busbar index that will be created (1 by default). + * Set the lowest index of bus or busbar index that will be created (1 by default). * - * @param lowBusbarIndex + * @param lowBusOrBusbarIndex */ - public CreateVoltageLevelTopologyBuilder withLowBusbarIndex(int lowBusbarIndex) { - this.lowBusbarIndex = lowBusbarIndex; + public CreateVoltageLevelTopologyBuilder withLowBusOrBusbarIndex(int lowBusOrBusbarIndex) { + this.lowBusOrBusbarIndex = lowBusOrBusbarIndex; return this; } /** - * Set the number of busbar which will be created. + * Set the number of parallel bus lines or busbar which will be created. + * In case of node/breaker topology, it is the number of busbar sections. + * In case of bus/breaker topology, it is the number of lines of aligned buses. * - * @param busbarCount + * @param alignedBusesOrBusbarCount */ - public CreateVoltageLevelTopologyBuilder withBusbarCount(int busbarCount) { - this.busbarCount = busbarCount; + public CreateVoltageLevelTopologyBuilder withAlignedBusesOrBusbarCount(int alignedBusesOrBusbarCount) { + this.alignedBusesOrBusbarCount = alignedBusesOrBusbarCount; return this; } @@ -78,7 +80,7 @@ public CreateVoltageLevelTopologyBuilder withLowSectionIndex(int lowSectionIndex } /** - * Set the number of sections for each created busbar. + * Set the number of sections for each created busbar or the number of switches between the buses in bus/breaker topology. * * @param sectionCount */ @@ -88,12 +90,12 @@ public CreateVoltageLevelTopologyBuilder withSectionCount(int sectionCount) { } /** - * Set the prefix ID for the created busbar sections. By default, it is equals to the voltage level ID. + * Set the prefix ID for the created buses or busbar sections. By default, it is equals to the voltage level ID. * * @param busbarSectionPrefixId */ public CreateVoltageLevelTopologyBuilder withBusbarSectionPrefixId(String busbarSectionPrefixId) { - this.busbarSectionPrefixId = busbarSectionPrefixId; + this.busOrBusbarSectionPrefixId = busbarSectionPrefixId; return this; } @@ -115,6 +117,8 @@ public CreateVoltageLevelTopologyBuilder withSwitchPrefixId(String switchPrefixI * If it is {@link SwitchKind#DISCONNECTOR}, a closed disconnector is created. * If it is null, no switch is created: the sections are disconnected. * + * In bus/breaker topology, all the switching devices are by default breakers. + * * @param switchKinds */ public CreateVoltageLevelTopologyBuilder withSwitchKinds(SwitchKind... switchKinds) { @@ -129,6 +133,8 @@ public CreateVoltageLevelTopologyBuilder withSwitchKinds(SwitchKind... switchKin * If it is {@link SwitchKind#BREAKER}, a closed disconnector, a closed breaker and a closed disconnector are created. * If it is {@link SwitchKind#DISCONNECTOR}, a closed disconnector is created. * + * In bus/breaker topology, all the switching devices are by default breakers. + * * @param switchKinds */ public CreateVoltageLevelTopologyBuilder withSwitchKinds(List switchKinds) { @@ -137,6 +143,6 @@ public CreateVoltageLevelTopologyBuilder withSwitchKinds(List switch } public CreateVoltageLevelTopology build() { - return new CreateVoltageLevelTopology(voltageLevelId, lowBusbarIndex, busbarCount, lowSectionIndex, sectionCount, busbarSectionPrefixId, switchPrefixId, switchKinds); + return new CreateVoltageLevelTopology(voltageLevelId, lowBusOrBusbarIndex, alignedBusesOrBusbarCount, lowSectionIndex, sectionCount, busOrBusbarSectionPrefixId, switchPrefixId, switchKinds); } } diff --git a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/ModificationReports.java b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/ModificationReports.java index 925cda2ae43..bc31c430ef3 100644 --- a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/ModificationReports.java +++ b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/ModificationReports.java @@ -98,7 +98,7 @@ static void newCouplingDeviceAddedReport(Reporter reporter, String voltageLevelI static void createdNewSymmetricalTopology(Reporter reporter, String voltageLevelId, int busbarCount, int sectionCount) { reporter.report(Report.builder() .withKey("SymmetricalTopologyCreated") - .withDefaultMessage("New symmetrical topology in voltage level ${voltageLevelId}: creation of ${busbarCount} busbar(s) with ${sectionCount} section(s) each.") + .withDefaultMessage("New symmetrical topology in voltage level ${voltageLevelId}: creation of ${busbarCount} bus(es) or busbar(s) with ${sectionCount} section(s) each.") .withValue(VOLTAGE_LEVEL_ID, voltageLevelId) .withValue("busbarCount", busbarCount) .withValue("sectionCount", sectionCount) diff --git a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/TopologyModificationUtils.java b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/TopologyModificationUtils.java index 5c7e46fa72f..9cc265c5658 100644 --- a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/TopologyModificationUtils.java +++ b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/TopologyModificationUtils.java @@ -254,18 +254,16 @@ static void createNBDisconnector(int node1, int node2, String suffix, String pre } static void createBusBreakerSwitches(String busId1, String middleBusId, String busId2, String lineId, VoltageLevel.BusBreakerView view) { + createBusBreakerSwitch(busId1, middleBusId, lineId + "_", "_1", view); + createBusBreakerSwitch(middleBusId, busId2, lineId + "_", "_2", view); + } + + static void createBusBreakerSwitch(String busId1, String busId2, String prefix, String suffix, VoltageLevel.BusBreakerView view) { view.newSwitch() - .setId(lineId + "_SW_1") + .setId(prefix + "SW" + suffix) .setEnsureIdUnicity(true) .setOpen(false) .setBus1(busId1) - .setBus2(middleBusId) - .add(); - view.newSwitch() - .setId(lineId + "_SW_2") - .setEnsureIdUnicity(true) - .setOpen(false) - .setBus1(middleBusId) .setBus2(busId2) .add(); } diff --git a/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/CreateVoltageLevelTopologyTest.java b/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/CreateVoltageLevelTopologyTest.java index 3264bafa54a..dd4eba2fc08 100644 --- a/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/CreateVoltageLevelTopologyTest.java +++ b/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/CreateVoltageLevelTopologyTest.java @@ -12,9 +12,11 @@ import com.powsybl.iidm.network.BusbarSection; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.SwitchKind; +import com.powsybl.iidm.network.TopologyKind; import com.powsybl.iidm.network.extensions.BusbarSectionPosition; import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; import com.powsybl.iidm.xml.NetworkXml; +import org.joda.time.DateTime; import org.junit.Test; import java.io.IOException; @@ -33,7 +35,7 @@ public void test() throws IOException { Network network = createNbNetwork(); CreateVoltageLevelTopology modification = new CreateVoltageLevelTopologyBuilder() .withVoltageLevelId(VLTEST) - .withBusbarCount(3) + .withAlignedBusesOrBusbarCount(3) .withSectionCount(4) .withSwitchKinds(SwitchKind.BREAKER, SwitchKind.DISCONNECTOR, SwitchKind.DISCONNECTOR) .build(); @@ -47,7 +49,7 @@ public void testComplete() throws IOException { Network network = createNbNetwork(); CreateVoltageLevelTopology modification = new CreateVoltageLevelTopologyBuilder() .withVoltageLevelId(VLTEST) - .withBusbarCount(3) + .withAlignedBusesOrBusbarCount(3) .withSectionCount(4) .withBusbarSectionPrefixId("BBS_TEST") .withSwitchPrefixId("SW_TEST") @@ -60,23 +62,27 @@ public void testComplete() throws IOException { @Test public void testWithNullSwitchKind() { - CreateVoltageLevelTopologyBuilder builder = new CreateVoltageLevelTopologyBuilder() + Network network = createNbNetwork(); + CreateVoltageLevelTopology modification = new CreateVoltageLevelTopologyBuilder() .withVoltageLevelId(VLTEST) - .withBusbarCount(3) + .withAlignedBusesOrBusbarCount(3) .withSectionCount(4) - .withSwitchKinds(SwitchKind.BREAKER, null, SwitchKind.DISCONNECTOR); - PowsyblException e = assertThrows(PowsyblException.class, builder::build); + .withSwitchKinds(SwitchKind.BREAKER, null, SwitchKind.DISCONNECTOR) + .build(); + PowsyblException e = assertThrows(PowsyblException.class, () -> modification.apply(network)); assertEquals("All switch kinds must be defined", e.getMessage()); } @Test public void testWithUnsupportedSwitchKind() { - CreateVoltageLevelTopologyBuilder builder = new CreateVoltageLevelTopologyBuilder() + Network network = createNbNetwork(); + CreateVoltageLevelTopology modification = new CreateVoltageLevelTopologyBuilder() .withVoltageLevelId(VLTEST) - .withBusbarCount(3) + .withAlignedBusesOrBusbarCount(3) .withSectionCount(4) - .withSwitchKinds(SwitchKind.BREAKER, SwitchKind.LOAD_BREAK_SWITCH, SwitchKind.DISCONNECTOR); - PowsyblException e = assertThrows(PowsyblException.class, builder::build); + .withSwitchKinds(SwitchKind.BREAKER, SwitchKind.LOAD_BREAK_SWITCH, SwitchKind.DISCONNECTOR) + .build(); + PowsyblException e = assertThrows(PowsyblException.class, () -> modification.apply(network)); assertEquals("Switch kinds must be DISCONNECTOR or BREAKER", e.getMessage()); } @@ -84,7 +90,7 @@ public void testWithUnsupportedSwitchKind() { public void testWithNegativeCount() { CreateVoltageLevelTopologyBuilder modification = new CreateVoltageLevelTopologyBuilder() .withVoltageLevelId(VLTEST) - .withBusbarCount(-1) + .withAlignedBusesOrBusbarCount(-1) .withSectionCount(4) .withSwitchKinds(SwitchKind.BREAKER, SwitchKind.DISCONNECTOR, SwitchKind.DISCONNECTOR); PowsyblException e = assertThrows(PowsyblException.class, modification::build); @@ -96,7 +102,7 @@ public void testWithOneSection() { Network network = createNbNetwork(); CreateVoltageLevelTopology modification = new CreateVoltageLevelTopologyBuilder() .withVoltageLevelId(VLTEST) - .withBusbarCount(2) + .withAlignedBusesOrBusbarCount(2) .withSectionCount(1) .build(); modification.apply(network); @@ -120,12 +126,14 @@ public void testWithOneSection() { @Test public void testWithUnexpectedSwitchKindsSize() { - CreateVoltageLevelTopologyBuilder modification = new CreateVoltageLevelTopologyBuilder() + Network network = createNbNetwork(); + CreateVoltageLevelTopology modification = new CreateVoltageLevelTopologyBuilder() .withVoltageLevelId(VLTEST) - .withBusbarCount(3) + .withAlignedBusesOrBusbarCount(3) .withSectionCount(4) - .withSwitchKinds(SwitchKind.BREAKER); - PowsyblException e = assertThrows(PowsyblException.class, modification::build); + .withSwitchKinds(SwitchKind.BREAKER) + .build(); + PowsyblException e = assertThrows(PowsyblException.class, () -> modification.apply(network)); assertEquals("Unexpected switch kinds count (1). Should be 3", e.getMessage()); } @@ -134,7 +142,7 @@ public void testWithNotExistingVoltageLevel() { Network network = createNbNetwork(); CreateVoltageLevelTopology modification = new CreateVoltageLevelTopologyBuilder() .withVoltageLevelId("NOT_EXISTING") - .withBusbarCount(3) + .withAlignedBusesOrBusbarCount(3) .withSectionCount(4) .withSwitchKinds(SwitchKind.BREAKER, SwitchKind.DISCONNECTOR, SwitchKind.DISCONNECTOR) .build(); @@ -143,15 +151,32 @@ public void testWithNotExistingVoltageLevel() { } @Test - public void testWithBusBreakerVoltageLevel() { - Network network = EurostagTutorialExample1Factory.create(); + public void testWithBusBreakerVoltageLevel() throws IOException { + Network network = EurostagTutorialExample1Factory.create().setCaseDate(DateTime.parse("2017-06-25T17:43:00.000+01:00")); + network.newVoltageLevel() + .setId("VLTEST") + .setNominalV(400.0) + .setTopologyKind(TopologyKind.BUS_BREAKER) + .add(); CreateVoltageLevelTopology modification = new CreateVoltageLevelTopologyBuilder() - .withVoltageLevelId("VLHV1") - .withBusbarCount(3) + .withVoltageLevelId("VLTEST") + .withAlignedBusesOrBusbarCount(3) .withSectionCount(4) - .withSwitchKinds(SwitchKind.BREAKER, SwitchKind.DISCONNECTOR, SwitchKind.DISCONNECTOR) .build(); - PowsyblException e = assertThrows(PowsyblException.class, () -> modification.apply(network, true, Reporter.NO_OP)); - assertEquals("Voltage Level VLHV1 has an unsupported topology BUS_BREAKER. Should be NODE_BREAKER", e.getMessage()); + modification.apply(network); + roundTripTest(network, NetworkXml::writeAndValidate, NetworkXml::validateAndRead, + "/eurostag-new-voltage-level.xml"); + } + + @Test + public void testErrorIfNotSwitchKindsDefinedAndNodeBreaker() { + Network network = createNbNetwork(); + CreateVoltageLevelTopology modification = new CreateVoltageLevelTopologyBuilder() + .withVoltageLevelId(VLTEST) + .withAlignedBusesOrBusbarCount(3) + .withSectionCount(4) + .build(); + PowsyblException e = assertThrows(PowsyblException.class, () -> modification.apply(network)); + assertEquals("Unexpected switch kinds count (0). Should be 3", e.getMessage()); } } diff --git a/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/RemoveFeederBayTest.java b/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/RemoveFeederBayTest.java index 02b74d4cf9d..b57af7915bf 100644 --- a/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/RemoveFeederBayTest.java +++ b/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/RemoveFeederBayTest.java @@ -148,7 +148,7 @@ private Network createNetwork2Feeders() { Network network = createNbNetwork(); CreateVoltageLevelTopology createVlTopology = new CreateVoltageLevelTopologyBuilder() .withVoltageLevelId(VLTEST) - .withBusbarCount(3) + .withAlignedBusesOrBusbarCount(3) .withSectionCount(1) .withBusbarSectionPrefixId("BBS_TEST") .withSwitchPrefixId("SW_TEST") diff --git a/iidm/iidm-modification/src/test/resources/eurostag-new-voltage-level.xml b/iidm/iidm-modification/src/test/resources/eurostag-new-voltage-level.xml new file mode 100644 index 00000000000..a3a306d3023 --- /dev/null +++ b/iidm/iidm-modification/src/test/resources/eurostag-new-voltage-level.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +