From 0e471694278fa5c87c02ca76dad4d08f6222a219 Mon Sep 17 00:00:00 2001 From: BOUTIER Charly Date: Tue, 1 Aug 2023 10:21:52 +0200 Subject: [PATCH 1/9] Adds equipment information on problematic VSC and Busbar index in error messages Signed-off-by: BOUTIER Charly --- .../iidm/impl/BusbarSectionPositionImpl.java | 14 +++--- .../extensions/StandbyAutomatonAdderImpl.java | 2 +- .../impl/extensions/StandbyAutomatonImpl.java | 43 ++++++++----------- 3 files changed, 27 insertions(+), 32 deletions(-) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusbarSectionPositionImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusbarSectionPositionImpl.java index 7878b3885..e1f5152a4 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusbarSectionPositionImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusbarSectionPositionImpl.java @@ -8,6 +8,8 @@ import com.powsybl.commons.extensions.AbstractExtension; import com.powsybl.iidm.network.BusbarSection; +import com.powsybl.iidm.network.Validable; +import com.powsybl.iidm.network.ValidationException; import com.powsybl.iidm.network.extensions.BusbarSectionPosition; import com.powsybl.network.store.model.BusbarSectionAttributes; import com.powsybl.network.store.model.BusbarSectionPositionAttributes; @@ -20,13 +22,13 @@ public class BusbarSectionPositionImpl extends AbstractExtension public BusbarSectionPositionImpl(BusbarSectionImpl busbarSectionImpl) { super(busbarSectionImpl); - checkIndex(getBusbarIndex()); - checkIndex(getSectionIndex()); + checkIndex(busbarSectionImpl, getBusbarIndex()); + checkIndex(busbarSectionImpl, getSectionIndex()); } - private static int checkIndex(int index) { + private static int checkIndex(Validable validable, int index) { if (index < 0) { - throw new IllegalArgumentException("Busbar index has to be greater or equals to zero"); + throw new ValidationException(validable, "Busbar index has to be greater or equals to zero"); } return index; } @@ -50,7 +52,7 @@ private BusbarSectionPositionAttributes getPositionAttributes(Resource getPositionAttributes(res).setBusbarIndex(checkIndex(busbarIndex))); + getBusbarSection().updateResource(res -> getPositionAttributes(res).setBusbarIndex(checkIndex(getBusbarSection(), busbarIndex))); return this; } @@ -61,7 +63,7 @@ public int getSectionIndex() { @Override public BusbarSectionPosition setSectionIndex(int sectionIndex) { - getBusbarSection().updateResource(res -> getPositionAttributes(res).setSectionIndex(checkIndex(sectionIndex))); + getBusbarSection().updateResource(res -> getPositionAttributes(res).setSectionIndex(checkIndex(getBusbarSection(), sectionIndex))); return this; } } diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/StandbyAutomatonAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/StandbyAutomatonAdderImpl.java index 695856ac9..e86664b36 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/StandbyAutomatonAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/StandbyAutomatonAdderImpl.java @@ -36,7 +36,7 @@ public StandbyAutomatonAdderImpl(StaticVarCompensator svc) { @Override protected StandbyAutomaton createExtension(StaticVarCompensator svc) { - var attributes = StandbyAutomatonImpl.createAttributes(b0, standby, + var attributes = StandbyAutomatonImpl.createAttributes((StaticVarCompensatorImpl) svc, b0, standby, lowVoltageSetpoint, highVoltageSetpoint, lowVoltageThreshold, highVoltageThreshold); ((StaticVarCompensatorImpl) svc).updateResource(res -> res.getAttributes().setStandbyAutomaton(attributes)); return new StandbyAutomatonImpl(svc); diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/StandbyAutomatonImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/StandbyAutomatonImpl.java index 84c6581f3..9b0c07c1a 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/StandbyAutomatonImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/extensions/StandbyAutomatonImpl.java @@ -8,6 +8,8 @@ import com.powsybl.commons.extensions.AbstractExtension; import com.powsybl.iidm.network.StaticVarCompensator; +import com.powsybl.iidm.network.Validable; +import com.powsybl.iidm.network.ValidationException; import com.powsybl.iidm.network.extensions.StandbyAutomaton; import com.powsybl.network.store.iidm.impl.StaticVarCompensatorImpl; import com.powsybl.network.store.model.Resource; @@ -23,29 +25,29 @@ public class StandbyAutomatonImpl extends AbstractExtension= highVoltageThreshold) { - throw new IllegalArgumentException("Inconsistent low (" + lowVoltageThreshold + ") and high (" + highVoltageThreshold + ") voltage thresholds"); + throw new ValidationException(validable, "Inconsistent low (" + lowVoltageThreshold + ") and high (" + highVoltageThreshold + ") voltage thresholds"); } if (lowVoltageSetpoint < lowVoltageThreshold) { LOGGER.warn("Invalid low voltage setpoint {} < threshold {}", lowVoltageSetpoint, lowVoltageThreshold); @@ -55,19 +57,10 @@ private static void checkVoltageConfig(double lowVoltageSetpoint, double highVol } } - public static StandbyAutomatonAttributes createAttributes(StandbyAutomaton standbyAutomaton) { - return createAttributes(standbyAutomaton.getB0(), - standbyAutomaton.isStandby(), - standbyAutomaton.getLowVoltageSetpoint(), - standbyAutomaton.getHighVoltageSetpoint(), - standbyAutomaton.getLowVoltageThreshold(), - standbyAutomaton.getHighVoltageThreshold()); - } - - public static StandbyAutomatonAttributes createAttributes(double b0, boolean standby, double lowVoltageSetpoint, double highVoltageSetpoint, + public static StandbyAutomatonAttributes createAttributes(Validable validable, double b0, boolean standby, double lowVoltageSetpoint, double highVoltageSetpoint, double lowVoltageThreshold, double highVoltageThreshold) { - checkVoltageConfig(lowVoltageSetpoint, highVoltageSetpoint, lowVoltageThreshold, highVoltageThreshold); - checkB0(b0); + checkVoltageConfig(validable, lowVoltageSetpoint, highVoltageSetpoint, lowVoltageThreshold, highVoltageThreshold); + checkB0(validable, b0); return StandbyAutomatonAttributes.builder() .b0(b0) .standby(standby) @@ -112,7 +105,7 @@ public double getB0() { @Override public StandbyAutomatonImpl setB0(double b0) { - getSvc().updateResource(res -> getAttributes(res).setB0(checkB0(b0))); + getSvc().updateResource(res -> getAttributes(res).setB0(checkB0(getSvc(), b0))); return this; } @@ -123,7 +116,7 @@ public double getHighVoltageSetpoint() { @Override public StandbyAutomatonImpl setHighVoltageSetpoint(double highVoltageSetpoint) { - checkVoltageConfig(getLowVoltageSetpoint(), highVoltageSetpoint, getLowVoltageThreshold(), getHighVoltageThreshold()); + checkVoltageConfig(getSvc(), getLowVoltageSetpoint(), highVoltageSetpoint, getLowVoltageThreshold(), getHighVoltageThreshold()); getSvc().updateResource(res -> getAttributes(res).setHighVoltageSetpoint(highVoltageSetpoint)); return this; } @@ -135,7 +128,7 @@ public double getHighVoltageThreshold() { @Override public StandbyAutomatonImpl setHighVoltageThreshold(double highVoltageThreshold) { - checkVoltageConfig(getLowVoltageSetpoint(), getHighVoltageSetpoint(), getLowVoltageThreshold(), highVoltageThreshold); + checkVoltageConfig(getSvc(), getLowVoltageSetpoint(), getHighVoltageSetpoint(), getLowVoltageThreshold(), highVoltageThreshold); getSvc().updateResource(res -> getAttributes(res).setHighVoltageThreshold(highVoltageThreshold)); return this; } @@ -147,7 +140,7 @@ public double getLowVoltageSetpoint() { @Override public StandbyAutomatonImpl setLowVoltageSetpoint(double lowVoltageSetpoint) { - checkVoltageConfig(lowVoltageSetpoint, getHighVoltageSetpoint(), getLowVoltageThreshold(), getHighVoltageThreshold()); + checkVoltageConfig(getSvc(), lowVoltageSetpoint, getHighVoltageSetpoint(), getLowVoltageThreshold(), getHighVoltageThreshold()); getSvc().updateResource(res -> getAttributes(res).setLowVoltageSetpoint(lowVoltageSetpoint)); return this; } @@ -159,7 +152,7 @@ public double getLowVoltageThreshold() { @Override public StandbyAutomatonImpl setLowVoltageThreshold(double lowVoltageThreshold) { - checkVoltageConfig(getLowVoltageSetpoint(), getHighVoltageSetpoint(), lowVoltageThreshold, getHighVoltageThreshold()); + checkVoltageConfig(getSvc(), getLowVoltageSetpoint(), getHighVoltageSetpoint(), lowVoltageThreshold, getHighVoltageThreshold()); getSvc().updateResource(res -> getAttributes(res).setLowVoltageThreshold(lowVoltageThreshold)); return this; } From 9ade47a46079d88071fca2524298c4f12b5f940f Mon Sep 17 00:00:00 2001 From: BOUTIER Charly Date: Tue, 1 Aug 2023 12:23:20 +0200 Subject: [PATCH 2/9] Fixes unit tests Signed-off-by: BOUTIER Charly --- .../store/iidm/impl/VoltageLevelTest.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/VoltageLevelTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/VoltageLevelTest.java index 32124045b..2496bec2d 100644 --- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/VoltageLevelTest.java +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/VoltageLevelTest.java @@ -61,27 +61,27 @@ public void testBusbarSectionPositions() { assertNotNull(network.getVoltageLevel("VL").getNodeBreakerView().getBusbarSection("idBBS")); BusbarSectionPositionAdder busbarSectionPositionAdder = bbs.newExtension(BusbarSectionPositionAdder.class); - assertEquals("Busbar index has to be greater or equals to zero", - assertThrows(IllegalArgumentException.class, busbarSectionPositionAdder::add).getMessage()); + assertEquals("Busbar section 'idBBS': Busbar index has to be greater or equals to zero", + assertThrows(ValidationException.class, busbarSectionPositionAdder::add).getMessage()); busbarSectionPositionAdder = bbs.newExtension(BusbarSectionPositionAdder.class).withBusbarIndex(0); - assertEquals("Busbar index has to be greater or equals to zero", - assertThrows(IllegalArgumentException.class, busbarSectionPositionAdder::add).getMessage()); + assertEquals("Busbar section 'idBBS': Busbar index has to be greater or equals to zero", + assertThrows(ValidationException.class, busbarSectionPositionAdder::add).getMessage()); busbarSectionPositionAdder = bbs.newExtension(BusbarSectionPositionAdder.class).withSectionIndex(0); - assertEquals("Busbar index has to be greater or equals to zero", - assertThrows(IllegalArgumentException.class, busbarSectionPositionAdder::add).getMessage()); + assertEquals("Busbar section 'idBBS': Busbar index has to be greater or equals to zero", + assertThrows(ValidationException.class, busbarSectionPositionAdder::add).getMessage()); busbarSectionPositionAdder = bbs.newExtension(BusbarSectionPositionAdder.class).withBusbarIndex(-1).withSectionIndex(0); - assertEquals("Busbar index has to be greater or equals to zero", - assertThrows(IllegalArgumentException.class, busbarSectionPositionAdder::add).getMessage()); + assertEquals("Busbar section 'idBBS': Busbar index has to be greater or equals to zero", + assertThrows(ValidationException.class, busbarSectionPositionAdder::add).getMessage()); busbarSectionPositionAdder = bbs.newExtension(BusbarSectionPositionAdder.class).withBusbarIndex(0).withSectionIndex(-1); - assertEquals("Busbar index has to be greater or equals to zero", - assertThrows(IllegalArgumentException.class, busbarSectionPositionAdder::add).getMessage()); + assertEquals("Busbar section 'idBBS': Busbar index has to be greater or equals to zero", + assertThrows(ValidationException.class, busbarSectionPositionAdder::add).getMessage()); busbarSectionPositionAdder = bbs.newExtension(BusbarSectionPositionAdder.class).withBusbarIndex(-1).withSectionIndex(-1); - assertEquals("Busbar index has to be greater or equals to zero", - assertThrows(IllegalArgumentException.class, busbarSectionPositionAdder::add).getMessage()); + assertEquals("Busbar section 'idBBS': Busbar index has to be greater or equals to zero", + assertThrows(ValidationException.class, busbarSectionPositionAdder::add).getMessage()); } } From 05074ac8037d2074cb7bcdbb10dba7692b0fcef7 Mon Sep 17 00:00:00 2001 From: BOUTIER Charly Date: Tue, 1 Aug 2023 17:06:09 +0200 Subject: [PATCH 3/9] Fixes coverage Signed-off-by: BOUTIER Charly --- .../tck/extensions/StandbyAutomatonTest.java | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/extensions/StandbyAutomatonTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/extensions/StandbyAutomatonTest.java index b8d32096c..1abbf0d51 100644 --- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/extensions/StandbyAutomatonTest.java +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/extensions/StandbyAutomatonTest.java @@ -6,7 +6,12 @@ */ package com.powsybl.network.store.iidm.impl.tck.extensions; +import com.powsybl.iidm.network.*; +import com.powsybl.iidm.network.extensions.StandbyAutomatonAdder; import com.powsybl.iidm.network.tck.extensions.AbstractStandbyAutomatonTest; +import org.junit.Test; + +import static org.junit.Assert.*; /** * @author Geoffroy Jamgotchian @@ -16,4 +21,83 @@ public class StandbyAutomatonTest extends AbstractStandbyAutomatonTest { public void variantsCloneTest() { // FIXME } + + @Test + public void testStandbyAutomatonCheckVoltageConfig() { + Network network = Network.create("test", "test"); + Substation s = network.newSubstation() + .setId("S") + .setCountry(Country.FR) + .add(); + VoltageLevel vl = s.newVoltageLevel() + .setId("VL") + .setNominalV(400.0) + .setTopologyKind(TopologyKind.BUS_BREAKER) + .add(); + vl.getBusBreakerView().newBus() + .setId("BUS") + .add(); + StaticVarCompensator svc = vl.newStaticVarCompensator() + .setId("SVC") + .setConnectableBus("BUS") + .setBmin(12.2) + .setBmax(32.2) + .setRegulationMode(StaticVarCompensator.RegulationMode.VOLTAGE) + .setVoltageSetpoint(23.8) + .add(); + + StandbyAutomatonAdder standbyAutomatonAdder = svc.newExtension(StandbyAutomatonAdder.class) + .withHighVoltageSetpoint(21.3) + .withLowVoltageSetpoint(1.7) + .withHighVoltageThreshold(0.0) + .withLowVoltageThreshold(0.0); + assertEquals("Static var compensator 'SVC': Inconsistent low (0.0) and high (0.0) voltage thresholds", assertThrows(ValidationException.class, standbyAutomatonAdder::add).getMessage()); + + standbyAutomatonAdder = svc.newExtension(StandbyAutomatonAdder.class).withLowVoltageSetpoint(Double.NaN); + assertEquals("Static var compensator 'SVC': lowVoltageSetpoint is invalid", assertThrows(ValidationException.class, standbyAutomatonAdder::add).getMessage()); + + standbyAutomatonAdder = svc.newExtension(StandbyAutomatonAdder.class).withHighVoltageSetpoint(Double.NaN); + assertEquals("Static var compensator 'SVC': highVoltageSetpoint is invalid", assertThrows(ValidationException.class, standbyAutomatonAdder::add).getMessage()); + + standbyAutomatonAdder = svc.newExtension(StandbyAutomatonAdder.class).withHighVoltageThreshold(Double.NaN); + assertEquals("Static var compensator 'SVC': highVoltageThreshold is invalid", assertThrows(ValidationException.class, standbyAutomatonAdder::add).getMessage()); + + standbyAutomatonAdder = svc.newExtension(StandbyAutomatonAdder.class).withLowVoltageThreshold(Double.NaN); + assertEquals("Static var compensator 'SVC': lowVoltageThreshold is invalid", assertThrows(ValidationException.class, standbyAutomatonAdder::add).getMessage()); + } + + @Test + public void testStandbyAutomatonCheckB0() { + + Network network = Network.create("test", "test"); + Substation s = network.newSubstation() + .setId("S") + .setCountry(Country.FR) + .add(); + VoltageLevel vl = s.newVoltageLevel() + .setId("VL") + .setNominalV(400.0) + .setTopologyKind(TopologyKind.BUS_BREAKER) + .add(); + vl.getBusBreakerView().newBus() + .setId("BUS") + .add(); + StaticVarCompensator svc = vl.newStaticVarCompensator() + .setId("SVC") + .setConnectableBus("BUS") + .setBmin(12.2) + .setBmax(32.2) + .setRegulationMode(StaticVarCompensator.RegulationMode.VOLTAGE) + .setVoltageSetpoint(23.8) + .add(); + + StandbyAutomatonAdder standbyAutomatonAdder = svc.newExtension(StandbyAutomatonAdder.class) + .withHighVoltageSetpoint(21.3) + .withLowVoltageSetpoint(1.7) + .withHighVoltageThreshold(10.0) + .withLowVoltageThreshold(3.0) + .withB0(Double.NaN); + + assertEquals("Static var compensator 'SVC': b0 is invalid", assertThrows(ValidationException.class, standbyAutomatonAdder::add).getMessage()); + } } From c060ade9b44c423db86c8b56330ee33b34b2bc25 Mon Sep 17 00:00:00 2001 From: BOUTIER Charly Date: Tue, 1 Aug 2023 17:38:00 +0200 Subject: [PATCH 4/9] PR Review Signed-off-by: BOUTIER Charly --- .../tck/extensions/StandbyAutomatonTest.java | 30 ++----------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/extensions/StandbyAutomatonTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/extensions/StandbyAutomatonTest.java index 1abbf0d51..aeb0bf9c7 100644 --- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/extensions/StandbyAutomatonTest.java +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/extensions/StandbyAutomatonTest.java @@ -23,7 +23,7 @@ public void variantsCloneTest() { } @Test - public void testStandbyAutomatonCheckVoltageConfig() { + public void testStandbyAutomatonChecks() { Network network = Network.create("test", "test"); Substation s = network.newSubstation() .setId("S") @@ -64,34 +64,8 @@ public void testStandbyAutomatonCheckVoltageConfig() { standbyAutomatonAdder = svc.newExtension(StandbyAutomatonAdder.class).withLowVoltageThreshold(Double.NaN); assertEquals("Static var compensator 'SVC': lowVoltageThreshold is invalid", assertThrows(ValidationException.class, standbyAutomatonAdder::add).getMessage()); - } - - @Test - public void testStandbyAutomatonCheckB0() { - - Network network = Network.create("test", "test"); - Substation s = network.newSubstation() - .setId("S") - .setCountry(Country.FR) - .add(); - VoltageLevel vl = s.newVoltageLevel() - .setId("VL") - .setNominalV(400.0) - .setTopologyKind(TopologyKind.BUS_BREAKER) - .add(); - vl.getBusBreakerView().newBus() - .setId("BUS") - .add(); - StaticVarCompensator svc = vl.newStaticVarCompensator() - .setId("SVC") - .setConnectableBus("BUS") - .setBmin(12.2) - .setBmax(32.2) - .setRegulationMode(StaticVarCompensator.RegulationMode.VOLTAGE) - .setVoltageSetpoint(23.8) - .add(); - StandbyAutomatonAdder standbyAutomatonAdder = svc.newExtension(StandbyAutomatonAdder.class) + standbyAutomatonAdder = svc.newExtension(StandbyAutomatonAdder.class) .withHighVoltageSetpoint(21.3) .withLowVoltageSetpoint(1.7) .withHighVoltageThreshold(10.0) From 0c576a1150c2729a5cda2c1249a3c282309a8be4 Mon Sep 17 00:00:00 2001 From: BOUTIER Charly Date: Wed, 16 Aug 2023 11:54:46 +0200 Subject: [PATCH 5/9] PR Review Signed-off-by: BOUTIER Charly --- .../iidm/impl/BusbarSectionPositionImpl.java | 29 +++++++++++++++---- .../store/iidm/impl/VoltageLevelTest.java | 4 +-- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusbarSectionPositionImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusbarSectionPositionImpl.java index e1f5152a4..9daae29ef 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusbarSectionPositionImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusbarSectionPositionImpl.java @@ -15,20 +15,37 @@ import com.powsybl.network.store.model.BusbarSectionPositionAttributes; import com.powsybl.network.store.model.Resource; +import java.util.Objects; + /** * @author Jon Harper */ public class BusbarSectionPositionImpl extends AbstractExtension implements BusbarSectionPosition { + private enum BusbarSectionType { + BUSBAR("Busbar"), + SECTION("Section"); + + final String description; + + BusbarSectionType(String description) { + this.description = Objects.requireNonNull(description); + } + + String getDescription() { + return description; + } + } + public BusbarSectionPositionImpl(BusbarSectionImpl busbarSectionImpl) { super(busbarSectionImpl); - checkIndex(busbarSectionImpl, getBusbarIndex()); - checkIndex(busbarSectionImpl, getSectionIndex()); + checkIndex(busbarSectionImpl, getBusbarIndex(), BusbarSectionType.BUSBAR); + checkIndex(busbarSectionImpl, getSectionIndex(), BusbarSectionType.SECTION); } - private static int checkIndex(Validable validable, int index) { + private static int checkIndex(Validable validable, int index, BusbarSectionType type) { if (index < 0) { - throw new ValidationException(validable, "Busbar index has to be greater or equals to zero"); + throw new ValidationException(validable, type.getDescription() + " index has to be greater or equals to zero"); } return index; } @@ -52,7 +69,7 @@ private BusbarSectionPositionAttributes getPositionAttributes(Resource getPositionAttributes(res).setBusbarIndex(checkIndex(getBusbarSection(), busbarIndex))); + getBusbarSection().updateResource(res -> getPositionAttributes(res).setBusbarIndex(checkIndex(getBusbarSection(), busbarIndex, BusbarSectionType.BUSBAR))); return this; } @@ -63,7 +80,7 @@ public int getSectionIndex() { @Override public BusbarSectionPosition setSectionIndex(int sectionIndex) { - getBusbarSection().updateResource(res -> getPositionAttributes(res).setSectionIndex(checkIndex(getBusbarSection(), sectionIndex))); + getBusbarSection().updateResource(res -> getPositionAttributes(res).setSectionIndex(checkIndex(getBusbarSection(), sectionIndex, BusbarSectionType.SECTION))); return this; } } diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/VoltageLevelTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/VoltageLevelTest.java index 2496bec2d..1ffe9b351 100644 --- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/VoltageLevelTest.java +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/VoltageLevelTest.java @@ -65,7 +65,7 @@ public void testBusbarSectionPositions() { assertThrows(ValidationException.class, busbarSectionPositionAdder::add).getMessage()); busbarSectionPositionAdder = bbs.newExtension(BusbarSectionPositionAdder.class).withBusbarIndex(0); - assertEquals("Busbar section 'idBBS': Busbar index has to be greater or equals to zero", + assertEquals("Busbar section 'idBBS': Section index has to be greater or equals to zero", assertThrows(ValidationException.class, busbarSectionPositionAdder::add).getMessage()); busbarSectionPositionAdder = bbs.newExtension(BusbarSectionPositionAdder.class).withSectionIndex(0); @@ -77,7 +77,7 @@ public void testBusbarSectionPositions() { assertThrows(ValidationException.class, busbarSectionPositionAdder::add).getMessage()); busbarSectionPositionAdder = bbs.newExtension(BusbarSectionPositionAdder.class).withBusbarIndex(0).withSectionIndex(-1); - assertEquals("Busbar section 'idBBS': Busbar index has to be greater or equals to zero", + assertEquals("Busbar section 'idBBS': Section index has to be greater or equals to zero", assertThrows(ValidationException.class, busbarSectionPositionAdder::add).getMessage()); busbarSectionPositionAdder = bbs.newExtension(BusbarSectionPositionAdder.class).withBusbarIndex(-1).withSectionIndex(-1); From cd63fa60a3488746aa9b793928f989ed4fd556aa Mon Sep 17 00:00:00 2001 From: BOUTIER Charly Date: Fri, 18 Aug 2023 13:57:21 +0200 Subject: [PATCH 6/9] PR Review Signed-off-by: BOUTIER Charly --- .../iidm/impl/BusbarSectionPositionImpl.java | 29 ++++--------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusbarSectionPositionImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusbarSectionPositionImpl.java index 9daae29ef..f6aea7f33 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusbarSectionPositionImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BusbarSectionPositionImpl.java @@ -15,37 +15,20 @@ import com.powsybl.network.store.model.BusbarSectionPositionAttributes; import com.powsybl.network.store.model.Resource; -import java.util.Objects; - /** * @author Jon Harper */ public class BusbarSectionPositionImpl extends AbstractExtension implements BusbarSectionPosition { - private enum BusbarSectionType { - BUSBAR("Busbar"), - SECTION("Section"); - - final String description; - - BusbarSectionType(String description) { - this.description = Objects.requireNonNull(description); - } - - String getDescription() { - return description; - } - } - public BusbarSectionPositionImpl(BusbarSectionImpl busbarSectionImpl) { super(busbarSectionImpl); - checkIndex(busbarSectionImpl, getBusbarIndex(), BusbarSectionType.BUSBAR); - checkIndex(busbarSectionImpl, getSectionIndex(), BusbarSectionType.SECTION); + checkIndex(busbarSectionImpl, getBusbarIndex(), "Busbar"); + checkIndex(busbarSectionImpl, getSectionIndex(), "Section"); } - private static int checkIndex(Validable validable, int index, BusbarSectionType type) { + private static int checkIndex(Validable validable, int index, String equipmentTypeLabel) { if (index < 0) { - throw new ValidationException(validable, type.getDescription() + " index has to be greater or equals to zero"); + throw new ValidationException(validable, equipmentTypeLabel + " index has to be greater or equals to zero"); } return index; } @@ -69,7 +52,7 @@ private BusbarSectionPositionAttributes getPositionAttributes(Resource getPositionAttributes(res).setBusbarIndex(checkIndex(getBusbarSection(), busbarIndex, BusbarSectionType.BUSBAR))); + getBusbarSection().updateResource(res -> getPositionAttributes(res).setBusbarIndex(checkIndex(getBusbarSection(), busbarIndex, "Busbar"))); return this; } @@ -80,7 +63,7 @@ public int getSectionIndex() { @Override public BusbarSectionPosition setSectionIndex(int sectionIndex) { - getBusbarSection().updateResource(res -> getPositionAttributes(res).setSectionIndex(checkIndex(getBusbarSection(), sectionIndex, BusbarSectionType.SECTION))); + getBusbarSection().updateResource(res -> getPositionAttributes(res).setSectionIndex(checkIndex(getBusbarSection(), sectionIndex, "Section"))); return this; } } From d711d335d1e9c33e94201cba00902474c4009bbf Mon Sep 17 00:00:00 2001 From: Jon Harper Date: Thu, 31 Aug 2023 14:18:53 +0200 Subject: [PATCH 7/9] Powsybl6 deprecations (#346) * Remove deprecated checkActivePowerLimits call (fixup from powsybl 4.7 migration) * StaticVarCompensatorAdder use setpoint instead of deprecated setPoint * remove deprecated Identifiable getName Signed-off-by: HARPER Jon --- .../com/powsybl/network/store/iidm/impl/BatteryImpl.java | 2 +- .../com/powsybl/network/store/iidm/impl/CalculatedBus.java | 5 ----- .../store/iidm/impl/StaticVarCompensatorAdderImpl.java | 4 ++-- .../powsybl/network/store/iidm/impl/CreateNetworksUtil.java | 4 ++-- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BatteryImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BatteryImpl.java index 2bcff7bc4..6a18e939e 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BatteryImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BatteryImpl.java @@ -95,7 +95,7 @@ public double getMaxP() { @Override public Battery setMaxP(double maxP) { ValidationUtil.checkMaxP(this, maxP); - ValidationUtil.checkActivePowerLimits(this, getMinP(), maxP, getTargetP()); + ValidationUtil.checkActivePowerLimits(this, getMinP(), maxP); double oldValue = getResource().getAttributes().getMaxP(); if (maxP != oldValue) { updateResource(res -> res.getAttributes().setMaxP(maxP)); diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CalculatedBus.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CalculatedBus.java index 1db1bce63..b9f199936 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CalculatedBus.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CalculatedBus.java @@ -73,11 +73,6 @@ public String getId() { return id; } - @Override - public String getName() { - return getNameOrId(); - } - @Override public String getNameOrId() { return name != null ? name : id; diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/StaticVarCompensatorAdderImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/StaticVarCompensatorAdderImpl.java index b72f4c878..667947847 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/StaticVarCompensatorAdderImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/StaticVarCompensatorAdderImpl.java @@ -43,13 +43,13 @@ public StaticVarCompensatorAdder setBmax(double bMax) { } @Override - public StaticVarCompensatorAdder setVoltageSetPoint(double voltageSetPoint) { + public StaticVarCompensatorAdder setVoltageSetpoint(double voltageSetPoint) { this.voltageSetPoint = voltageSetPoint; return this; } @Override - public StaticVarCompensatorAdder setReactivePowerSetPoint(double reactivePowerSetPoint) { + public StaticVarCompensatorAdder setReactivePowerSetpoint(double reactivePowerSetPoint) { this.reactivePowerSetPoint = reactivePowerSetPoint; return this; } diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/CreateNetworksUtil.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/CreateNetworksUtil.java index b3d103a94..a401dbe9e 100644 --- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/CreateNetworksUtil.java +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/CreateNetworksUtil.java @@ -249,9 +249,9 @@ private static Network createNetwokWithMultipleEquipments(TopologyKind topologyK .setId("SVC2") .setBmin(0.0002) .setBmax(0.0008) - .setReactivePowerSetPoint(200) + .setReactivePowerSetpoint(200) .setRegulationMode(StaticVarCompensator.RegulationMode.VOLTAGE) - .setVoltageSetPoint(390) + .setVoltageSetpoint(390) .add(); svc.getTerminal().setP(435); svc.getTerminal().setQ(315); From afb3f3ba999ffa099843e012c81ad96f14162dcd Mon Sep 17 00:00:00 2001 From: Geoffroy Jamgotchian Date: Mon, 25 Sep 2023 11:56:42 +0200 Subject: [PATCH 8/9] GetConnectables performance optimization Signed-off-by: Geoffroy Jamgotchian --- .../network/store/iidm/impl/NetworkImpl.java | 53 ++++++++++++++++++- .../store/iidm/impl/GetConnectablesTest.java | 39 ++++++++++++++ 2 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/GetConnectablesTest.java diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkImpl.java index 235841f43..d20799f8c 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkImpl.java @@ -771,7 +771,58 @@ public Iterable getConnectables(Class clazz) { @Override public Stream getConnectableStream(Class clazz) { - return index.getIdentifiables().stream().filter(clazz::isInstance).map(clazz::cast); + Objects.requireNonNull(clazz); + if (clazz == BusbarSection.class) { + return getBusbarSectionStream().map(c -> (C) c); + } else if (clazz == Generator.class) { + return getGeneratorStream().map(c -> (C) c); + } else if (clazz == Line.class) { + return getLineStream().map(c -> (C) c); + } else if (clazz == TwoWindingsTransformer.class) { + return getTwoWindingsTransformerStream().map(c -> (C) c); + } else if (clazz == ThreeWindingsTransformer.class) { + return getThreeWindingsTransformerStream().map(c -> (C) c); + } else if (clazz == Battery.class) { + return getBatteryStream().map(c -> (C) c); + } else if (clazz == DanglingLine.class) { + return getDanglingLineStream().map(c -> (C) c); + } else if (clazz == LccConverterStation.class) { + return getLccConverterStationStream().map(c -> (C) c); + } else if (clazz == VscConverterStation.class) { + return getVscConverterStationStream().map(c -> (C) c); + } else if (clazz == Load.class) { + return getLoadStream().map(c -> (C) c); + } else if (clazz == ShuntCompensator.class) { + return getShuntCompensatorStream().map(c -> (C) c); + } else if (clazz == StaticVarCompensator.class) { + return getStaticVarCompensatorStream().map(c -> (C) c); + } else { + Stream s = null; + for (Class connectableClass : List.of(BusbarSection.class, + Generator.class, + Line.class, + TwoWindingsTransformer.class, + ThreeWindingsTransformer.class, + Battery.class, + DanglingLine.class, + LccConverterStation.class, + VscConverterStation.class, + Load.class, + ShuntCompensator.class, + StaticVarCompensator.class)) { + if (clazz.isAssignableFrom(connectableClass)) { + if (s == null) { + s = getConnectableStream((Class) connectableClass); + } else { + s = Stream.concat(s, getConnectableStream((Class) connectableClass)); + } + } + } + if (s == null) { + s = Stream.empty(); + } + return s; + } } @Override diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/GetConnectablesTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/GetConnectablesTest.java new file mode 100644 index 000000000..1d2c9669b --- /dev/null +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/GetConnectablesTest.java @@ -0,0 +1,39 @@ +/** + * Copyright (c) 2023, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package com.powsybl.network.store.iidm.impl; + +import com.powsybl.iidm.network.*; +import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * @author Geoffroy Jamgotchian + */ +public class GetConnectablesTest { + + @Test + public void test() { + Network network = EurostagTutorialExample1Factory.create(); + List generators = network.getConnectableStream(Generator.class).toList(); + assertEquals(1, generators.size()); + List lines = network.getConnectableStream(Line.class).toList(); + assertEquals(2, lines.size()); + List transformers = network.getConnectableStream(TwoWindingsTransformer.class).toList(); + assertEquals(2, transformers.size()); + List loads = network.getConnectableStream(Load.class).toList(); + assertEquals(1, loads.size()); + List injections = network.getConnectableStream(Injection.class).toList(); + assertEquals(2, injections.size()); + List converterStations = network.getConnectableStream(HvdcConverterStation.class).toList(); + assertTrue(converterStations.isEmpty()); + } +} From 10d9e33926332d79dbc2cf555997fc0db58ef0f1 Mon Sep 17 00:00:00 2001 From: Geoffroy Jamgotchian Date: Tue, 26 Sep 2023 10:37:38 +0200 Subject: [PATCH 9/9] Clean Signed-off-by: Geoffroy Jamgotchian --- .../powsybl/network/store/iidm/impl/NetworkImpl.java | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkImpl.java index d20799f8c..8ef9fa068 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkImpl.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/NetworkImpl.java @@ -797,7 +797,7 @@ public Stream getConnectableStream(Class clazz) { } else if (clazz == StaticVarCompensator.class) { return getStaticVarCompensatorStream().map(c -> (C) c); } else { - Stream s = null; + Stream s = Stream.empty(); for (Class connectableClass : List.of(BusbarSection.class, Generator.class, Line.class, @@ -811,16 +811,9 @@ public Stream getConnectableStream(Class clazz) { ShuntCompensator.class, StaticVarCompensator.class)) { if (clazz.isAssignableFrom(connectableClass)) { - if (s == null) { - s = getConnectableStream((Class) connectableClass); - } else { - s = Stream.concat(s, getConnectableStream((Class) connectableClass)); - } + s = Stream.concat(s, getConnectableStream((Class) connectableClass)); } } - if (s == null) { - s = Stream.empty(); - } return s; } }