From 6b260af2062f0fe0ef31a4a92babf10513b7c31a Mon Sep 17 00:00:00 2001 From: Anne Tilloy Date: Tue, 13 Sep 2022 17:17:24 +0200 Subject: [PATCH 1/4] Add a test. Signed-off-by: Anne Tilloy --- .../sa/OpenSecurityAnalysisTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java b/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java index 81c5e3e668..f1349d4b8b 100644 --- a/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java +++ b/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java @@ -2126,4 +2126,22 @@ void testWithControlledBranchContingency() { assertEquals(100.369, result.getPostContingencyResults().get(0).getNetworkResult().getBranchResult("PS1").getP1(), LoadFlowAssert.DELTA_POWER); assertEquals(100.184, result.getPostContingencyResults().get(0).getNetworkResult().getBranchResult("L2").getP1(), LoadFlowAssert.DELTA_POWER); } + + @Test + void testContingencyPropagation() { + var network = NodeBreakerNetworkFactory.create3barsAndJustOneVoltageLevel(); + for (Bus bus : network.getBusBreakerView().getBuses()) { + System.out.println("bus: " + bus.getId()); + } + List contingencies = List.of(new Contingency("G1", new GeneratorContingency("G1"))); + List monitors = createNetworkMonitors(network); + SecurityAnalysisParameters securityAnalysisParameters = new SecurityAnalysisParameters(); + OpenLoadFlowParameters openLoadFlowParameters = new OpenLoadFlowParameters(); + openLoadFlowParameters.setSlackBusSelectionMode(SlackBusSelectionMode.NAME).setSlackBusId("VL1_1"); + securityAnalysisParameters.getLoadFlowParameters().addExtension(OpenLoadFlowParameters.class, openLoadFlowParameters); + SecurityAnalysisResult result = runSecurityAnalysis(network, contingencies, monitors, securityAnalysisParameters, Reporter.NO_OP); + for (BusResult busResult : result.getPreContingencyResult().getNetworkResult().getBusResults()) { + System.out.println("busResult: " + busResult.getBusId()); + } + } } From 8d99e39fc9cc60c2760505477da1048ace03259a Mon Sep 17 00:00:00 2001 From: Anne Tilloy Date: Wed, 19 Jul 2023 17:06:33 +0200 Subject: [PATCH 2/4] With bbs ids. Signed-off-by: Anne Tilloy --- .../openloadflow/network/impl/LfBusImpl.java | 16 +++++++++++----- .../sa/OpenSecurityAnalysisTest.java | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/powsybl/openloadflow/network/impl/LfBusImpl.java b/src/main/java/com/powsybl/openloadflow/network/impl/LfBusImpl.java index f4c972c173..1804c65a05 100644 --- a/src/main/java/com/powsybl/openloadflow/network/impl/LfBusImpl.java +++ b/src/main/java/com/powsybl/openloadflow/network/impl/LfBusImpl.java @@ -6,10 +6,7 @@ */ package com.powsybl.openloadflow.network.impl; -import com.powsybl.iidm.network.Bus; -import com.powsybl.iidm.network.Country; -import com.powsybl.iidm.network.Load; -import com.powsybl.iidm.network.Substation; +import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.extensions.LoadAsymmetrical; import com.powsybl.iidm.network.extensions.SlackTerminal; import com.powsybl.openloadflow.network.LfNetwork; @@ -43,6 +40,8 @@ public class LfBusImpl extends AbstractLfBus { private final Country country; + private List bbsIds = null; + protected LfBusImpl(Bus bus, LfNetwork network, double v, double angle, LfNetworkParameters parameters, boolean participating) { super(network, v, angle, parameters.isDistributedOnConformLoad()); @@ -53,6 +52,13 @@ protected LfBusImpl(Bus bus, LfNetwork network, double v, double angle, LfNetwor this.participating = participating; this.breakers = parameters.isBreakers(); country = bus.getVoltageLevel().getSubstation().flatMap(Substation::getCountry).orElse(null); + if (bus.getVoltageLevel().getTopologyKind() == TopologyKind.NODE_BREAKER) { + List foundBbsIds = bus.getConnectedTerminalStream().map(Terminal::getConnectable) + .filter(c -> c instanceof BusbarSection).map(Connectable::getId).collect(Collectors.toList()); + if (foundBbsIds.size() > 0) { + bbsIds = foundBbsIds; + } + } } private static void createAsym(Bus bus, LfBusImpl lfBus) { @@ -142,7 +148,7 @@ public boolean isParticipating() { public List createBusResults() { var bus = getBus(); if (breakers) { - return List.of(new BusResult(getVoltageLevelId(), bus.getId(), v, Math.toDegrees(angle))); + return List.of(new BusResult(getVoltageLevelId(), bbsIds != null ? bbsIds.toString() : bus.getId(), v, Math.toDegrees(angle))); } else { return bus.getVoltageLevel().getBusBreakerView().getBusesFromBusViewBusId(bus.getId()) .stream().map(b -> new BusResult(getVoltageLevelId(), b.getId(), v, Math.toDegrees(angle))).collect(Collectors.toList()); diff --git a/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java b/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java index f1349d4b8b..0dc16d89be 100644 --- a/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java +++ b/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java @@ -93,7 +93,7 @@ void testCurrentLimitViolations() { assertSame(PostContingencyComputationStatus.CONVERGED, result.getPostContingencyResults().get(1).getStatus()); assertEquals(2, result.getPostContingencyResults().get(1).getLimitViolationsResult().getLimitViolations().size()); PostContingencyResult postContingencyResult = getPostContingencyResult(result, "LD"); - assertEquals(398.0, postContingencyResult.getNetworkResult().getBusResult("VL1_0").getV(), LoadFlowAssert.DELTA_V); + assertEquals(398.0, postContingencyResult.getNetworkResult().getBusResult("[BBS2]").getV(), LoadFlowAssert.DELTA_V); } @Test From 364541ae9664ae5f25192f42ff9ced125b0a08ef Mon Sep 17 00:00:00 2001 From: Bertrand Rix Date: Mon, 4 Sep 2023 11:01:43 +0200 Subject: [PATCH 3/4] Clean and output one bus result per bbs. Signed-off-by: Bertrand Rix --- .../openloadflow/network/impl/LfBusImpl.java | 18 ++++++++++++------ .../sa/OpenSecurityAnalysisTest.java | 12 +++++------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/powsybl/openloadflow/network/impl/LfBusImpl.java b/src/main/java/com/powsybl/openloadflow/network/impl/LfBusImpl.java index 1804c65a05..cf18fb0a6b 100644 --- a/src/main/java/com/powsybl/openloadflow/network/impl/LfBusImpl.java +++ b/src/main/java/com/powsybl/openloadflow/network/impl/LfBusImpl.java @@ -53,11 +53,11 @@ protected LfBusImpl(Bus bus, LfNetwork network, double v, double angle, LfNetwor this.breakers = parameters.isBreakers(); country = bus.getVoltageLevel().getSubstation().flatMap(Substation::getCountry).orElse(null); if (bus.getVoltageLevel().getTopologyKind() == TopologyKind.NODE_BREAKER) { - List foundBbsIds = bus.getConnectedTerminalStream().map(Terminal::getConnectable) - .filter(c -> c instanceof BusbarSection).map(Connectable::getId).collect(Collectors.toList()); - if (foundBbsIds.size() > 0) { - bbsIds = foundBbsIds; - } + bbsIds = bus.getConnectedTerminalStream() + .map(Terminal::getConnectable) + .filter(BusbarSection.class::isInstance) + .map(Connectable::getId) + .collect(Collectors.toList()); } } @@ -148,7 +148,13 @@ public boolean isParticipating() { public List createBusResults() { var bus = getBus(); if (breakers) { - return List.of(new BusResult(getVoltageLevelId(), bbsIds != null ? bbsIds.toString() : bus.getId(), v, Math.toDegrees(angle))); + if (bbsIds.isEmpty()) { + return List.of(new BusResult(getVoltageLevelId(), bus.getId(), v, Math.toDegrees(angle))); + } else { + return bbsIds.stream() + .map(bbsId -> new BusResult(getVoltageLevelId(), bbsId, v, Math.toDegrees(angle))) + .collect(Collectors.toList()); + } } else { return bus.getVoltageLevel().getBusBreakerView().getBusesFromBusViewBusId(bus.getId()) .stream().map(b -> new BusResult(getVoltageLevelId(), b.getId(), v, Math.toDegrees(angle))).collect(Collectors.toList()); diff --git a/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java b/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java index 0dc16d89be..4cb7b4834d 100644 --- a/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java +++ b/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java @@ -93,7 +93,7 @@ void testCurrentLimitViolations() { assertSame(PostContingencyComputationStatus.CONVERGED, result.getPostContingencyResults().get(1).getStatus()); assertEquals(2, result.getPostContingencyResults().get(1).getLimitViolationsResult().getLimitViolations().size()); PostContingencyResult postContingencyResult = getPostContingencyResult(result, "LD"); - assertEquals(398.0, postContingencyResult.getNetworkResult().getBusResult("[BBS2]").getV(), LoadFlowAssert.DELTA_V); + assertEquals(398.0, postContingencyResult.getNetworkResult().getBusResult("BBS2").getV(), LoadFlowAssert.DELTA_V); } @Test @@ -2130,9 +2130,6 @@ void testWithControlledBranchContingency() { @Test void testContingencyPropagation() { var network = NodeBreakerNetworkFactory.create3barsAndJustOneVoltageLevel(); - for (Bus bus : network.getBusBreakerView().getBuses()) { - System.out.println("bus: " + bus.getId()); - } List contingencies = List.of(new Contingency("G1", new GeneratorContingency("G1"))); List monitors = createNetworkMonitors(network); SecurityAnalysisParameters securityAnalysisParameters = new SecurityAnalysisParameters(); @@ -2140,8 +2137,9 @@ void testContingencyPropagation() { openLoadFlowParameters.setSlackBusSelectionMode(SlackBusSelectionMode.NAME).setSlackBusId("VL1_1"); securityAnalysisParameters.getLoadFlowParameters().addExtension(OpenLoadFlowParameters.class, openLoadFlowParameters); SecurityAnalysisResult result = runSecurityAnalysis(network, contingencies, monitors, securityAnalysisParameters, Reporter.NO_OP); - for (BusResult busResult : result.getPreContingencyResult().getNetworkResult().getBusResults()) { - System.out.println("busResult: " + busResult.getBusId()); - } + assertEquals(3, result.getPreContingencyResult().getNetworkResult().getBusResults().size()); + assertEquals("BBS1", result.getPreContingencyResult().getNetworkResult().getBusResults().get(0).getBusId()); + assertEquals("BBS2", result.getPreContingencyResult().getNetworkResult().getBusResults().get(1).getBusId()); + assertEquals("BBS3", result.getPreContingencyResult().getNetworkResult().getBusResults().get(2).getBusId()); } } From 794a86f0ab540d14b7899bbf206e716b1207f55e Mon Sep 17 00:00:00 2001 From: Anne Tilloy Date: Tue, 5 Sep 2023 13:18:26 +0200 Subject: [PATCH 4/4] Improve test. Signed-off-by: Anne Tilloy --- .../sa/OpenSecurityAnalysisTest.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java b/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java index 4cb7b4834d..0fa376516a 100644 --- a/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java +++ b/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java @@ -2130,7 +2130,8 @@ void testWithControlledBranchContingency() { @Test void testContingencyPropagation() { var network = NodeBreakerNetworkFactory.create3barsAndJustOneVoltageLevel(); - List contingencies = List.of(new Contingency("G1", new GeneratorContingency("G1"))); + List contingencies = List.of(new Contingency("C1", new SwitchContingency("C1")), + new Contingency("C2", new SwitchContingency("C2"))); List monitors = createNetworkMonitors(network); SecurityAnalysisParameters securityAnalysisParameters = new SecurityAnalysisParameters(); OpenLoadFlowParameters openLoadFlowParameters = new OpenLoadFlowParameters(); @@ -2138,8 +2139,16 @@ void testContingencyPropagation() { securityAnalysisParameters.getLoadFlowParameters().addExtension(OpenLoadFlowParameters.class, openLoadFlowParameters); SecurityAnalysisResult result = runSecurityAnalysis(network, contingencies, monitors, securityAnalysisParameters, Reporter.NO_OP); assertEquals(3, result.getPreContingencyResult().getNetworkResult().getBusResults().size()); - assertEquals("BBS1", result.getPreContingencyResult().getNetworkResult().getBusResults().get(0).getBusId()); - assertEquals("BBS2", result.getPreContingencyResult().getNetworkResult().getBusResults().get(1).getBusId()); - assertEquals("BBS3", result.getPreContingencyResult().getNetworkResult().getBusResults().get(2).getBusId()); + PreContingencyResult preContingencyResult = result.getPreContingencyResult(); + assertEquals("BBS1", preContingencyResult.getNetworkResult().getBusResults().get(0).getBusId()); + assertEquals(400.0, preContingencyResult.getNetworkResult().getBusResult("BBS1").getV(), LoadFlowAssert.DELTA_V); + assertEquals("BBS2", preContingencyResult.getNetworkResult().getBusResults().get(1).getBusId()); + assertEquals(400.0, preContingencyResult.getNetworkResult().getBusResult("BBS2").getV(), LoadFlowAssert.DELTA_V); + assertEquals("BBS3", preContingencyResult.getNetworkResult().getBusResults().get(2).getBusId()); + assertEquals(400.0, preContingencyResult.getNetworkResult().getBusResult("BBS3").getV(), LoadFlowAssert.DELTA_V); + PostContingencyResult postContingencyResult = getPostContingencyResult(result, "C1"); + assertNull(postContingencyResult.getNetworkResult().getBusResult("BBS1")); + assertEquals(400.0, postContingencyResult.getNetworkResult().getBusResult("BBS2").getV(), LoadFlowAssert.DELTA_V); + assertEquals(400.0, postContingencyResult.getNetworkResult().getBusResult("BBS3").getV(), LoadFlowAssert.DELTA_V); } }