From 478fa4e5b821c68b6f9404f28886d0069f7789db Mon Sep 17 00:00:00 2001 From: p-arvy Date: Tue, 21 Jan 2025 18:12:47 +0100 Subject: [PATCH 1/3] Disable AC emulation in WoodburyDcSecurityAnalysis Signed-off-by: p-arvy --- .../sa/WoodburyDcSecurityAnalysis.java | 7 +- .../sa/OpenSecurityAnalysisTest.java | 135 ++++++++++++++++++ 2 files changed, 140 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/powsybl/openloadflow/sa/WoodburyDcSecurityAnalysis.java b/src/main/java/com/powsybl/openloadflow/sa/WoodburyDcSecurityAnalysis.java index 4f812249fb..30527dd612 100644 --- a/src/main/java/com/powsybl/openloadflow/sa/WoodburyDcSecurityAnalysis.java +++ b/src/main/java/com/powsybl/openloadflow/sa/WoodburyDcSecurityAnalysis.java @@ -68,8 +68,11 @@ protected ReportNode createSaRootReportNode() { @Override protected DcLoadFlowParameters createParameters(LoadFlowParameters lfParameters, OpenLoadFlowParameters lfParametersExt, boolean breakers) { DcLoadFlowParameters dcParameters = super.createParameters(lfParameters, lfParametersExt, breakers); - // connectivity break analysis does not handle zero impedance lines - dcParameters.getNetworkParameters().setMinImpedance(true); + dcParameters.getNetworkParameters() + // connectivity break analysis does not handle zero impedance lines + .setMinImpedance(true) + // ac emulation is not yet supported + .setHvdcAcEmulation(false); // needed an equation to force angle to zero when a PST is lost dcParameters.getEquationSystemCreationParameters().setForcePhaseControlOffAndAddAngle1Var(true); return dcParameters; diff --git a/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java b/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java index 07a08ee6b8..f281077230 100644 --- a/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java +++ b/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java @@ -4034,4 +4034,139 @@ void testNoCc0Sc0() { assertEquals(LoadFlowResult.ComponentResult.Status.CONVERGED, saResultAll.getPreContingencyResult().getStatus()); assertEquals(6, saResultAll.getPreContingencyResult().getNetworkResult().getBusResults().size()); // 6 buses in total } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testDcSaWithHvdcLineContingency(boolean dcFastMode) { + Network network = HvdcNetworkFactory.createNetworkWithGenerators(); + + LoadFlowParameters parameters = new LoadFlowParameters(); + parameters.setDc(true).setHvdcAcEmulation(true); + OpenLoadFlowParameters.create(parameters) + .setSlackBusSelectionMode(SlackBusSelectionMode.FIRST); + SecurityAnalysisParameters securityAnalysisParameters = new SecurityAnalysisParameters(); + securityAnalysisParameters.setLoadFlowParameters(parameters); + OpenSecurityAnalysisParameters openSecurityAnalysisParameters = new OpenSecurityAnalysisParameters(); + openSecurityAnalysisParameters.setDcFastMode(dcFastMode); + securityAnalysisParameters.addExtension(OpenSecurityAnalysisParameters.class, openSecurityAnalysisParameters); + + List monitors = createAllBranchesMonitors(network); + List contingencies = List.of(new Contingency("hvdc34+g1", List.of(new HvdcLineContingency("hvdc34"), new GeneratorContingency("g1")))); + SecurityAnalysisResult result = runSecurityAnalysis(network, contingencies, monitors, securityAnalysisParameters); + + // apply contingency by hand + network.getHvdcLine("hvdc34").remove(); + network.getGenerator("g1").disconnect(); + // run load flow to compare results + loadFlowRunner.run(network, parameters); + + // post-contingency tests + PostContingencyResult postContingencyResult = getPostContingencyResult(result, "hvdc34+g1"); + assertEquals(network.getLine("l12").getTerminal1().getP(), postContingencyResult.getNetworkResult().getBranchResult("l12").getP1(), LoadFlowAssert.DELTA_POWER); + assertEquals(network.getLine("l13").getTerminal1().getP(), postContingencyResult.getNetworkResult().getBranchResult("l13").getP1(), LoadFlowAssert.DELTA_POWER); + assertEquals(network.getLine("l23").getTerminal1().getP(), postContingencyResult.getNetworkResult().getBranchResult("l23").getP1(), LoadFlowAssert.DELTA_POWER); + assertEquals(network.getLine("l25").getTerminal1().getP(), postContingencyResult.getNetworkResult().getBranchResult("l25").getP1(), LoadFlowAssert.DELTA_POWER); + assertEquals(network.getLine("l45").getTerminal1().getP(), postContingencyResult.getNetworkResult().getBranchResult("l45").getP1(), LoadFlowAssert.DELTA_POWER); + assertEquals(network.getLine("l46").getTerminal1().getP(), postContingencyResult.getNetworkResult().getBranchResult("l46").getP1(), LoadFlowAssert.DELTA_POWER); + assertEquals(network.getLine("l56").getTerminal1().getP(), postContingencyResult.getNetworkResult().getBranchResult("l56").getP1(), LoadFlowAssert.DELTA_POWER); + } + + @Test + void testDcSaWithHvdcLineContingencyAndConnectivityBreak() { + Network network = HvdcNetworkFactory.createNetworkWithGenerators(); + + LoadFlowParameters parameters = new LoadFlowParameters(); + parameters.setDc(true); + OpenLoadFlowParameters.create(parameters) + .setSlackBusId("b2_vl_0") + .setSlackBusSelectionMode(SlackBusSelectionMode.NAME); + SecurityAnalysisParameters securityAnalysisParameters = new SecurityAnalysisParameters(); + securityAnalysisParameters.setLoadFlowParameters(parameters); + OpenSecurityAnalysisParameters openSecurityAnalysisParameters = new OpenSecurityAnalysisParameters(); + openSecurityAnalysisParameters.setDcFastMode(true); + securityAnalysisParameters.addExtension(OpenSecurityAnalysisParameters.class, openSecurityAnalysisParameters); + + List monitors = createAllBranchesMonitors(network); + List contingencies = List.of(new Contingency("hvdc34+l25", List.of(new HvdcLineContingency("hvdc34"), new LineContingency("l25")))); + SecurityAnalysisResult result = runSecurityAnalysis(network, contingencies, monitors, securityAnalysisParameters); + + // apply contingency by hand + network.getHvdcLine("hvdc34").remove(); + network.getLine("l25").disconnect(); + loadFlowRunner.run(network, parameters); + + // compare results on the lines + PostContingencyResult postContingencyResult = getPostContingencyResult(result, "hvdc34+l25"); + assertEquals(network.getLine("l12").getTerminal1().getP(), postContingencyResult.getNetworkResult().getBranchResult("l12").getP1(), LoadFlowAssert.DELTA_POWER); + assertEquals(network.getLine("l12").getTerminal2().getP(), postContingencyResult.getNetworkResult().getBranchResult("l12").getP2(), LoadFlowAssert.DELTA_POWER); + assertEquals(network.getLine("l13").getTerminal1().getP(), postContingencyResult.getNetworkResult().getBranchResult("l13").getP1(), LoadFlowAssert.DELTA_POWER); + assertEquals(network.getLine("l13").getTerminal2().getP(), postContingencyResult.getNetworkResult().getBranchResult("l13").getP2(), LoadFlowAssert.DELTA_POWER); + assertEquals(network.getLine("l23").getTerminal1().getP(), postContingencyResult.getNetworkResult().getBranchResult("l23").getP1(), LoadFlowAssert.DELTA_POWER); + assertEquals(network.getLine("l23").getTerminal2().getP(), postContingencyResult.getNetworkResult().getBranchResult("l23").getP2(), LoadFlowAssert.DELTA_POWER); + } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testDcSaHvdcLineInAcEmulationContingency(boolean dcFastMode) { + Network network = HvdcNetworkFactory.createHvdcInAcEmulationInSymetricNetwork(); + + LoadFlowParameters parameters = new LoadFlowParameters(); + parameters.setDc(true).setHvdcAcEmulation(true); + OpenLoadFlowParameters.create(parameters) + .setSlackBusSelectionMode(SlackBusSelectionMode.FIRST); + SecurityAnalysisParameters securityAnalysisParameters = new SecurityAnalysisParameters(); + securityAnalysisParameters.setLoadFlowParameters(parameters); + OpenSecurityAnalysisParameters openSecurityAnalysisParameters = new OpenSecurityAnalysisParameters(); + openSecurityAnalysisParameters.setDcFastMode(dcFastMode); + securityAnalysisParameters.addExtension(OpenSecurityAnalysisParameters.class, openSecurityAnalysisParameters); + + List monitors = createAllBranchesMonitors(network); + List contingencies = List.of(Contingency.hvdcLine("hvdc12")); + SecurityAnalysisResult result = runSecurityAnalysis(network, contingencies, monitors, securityAnalysisParameters); + + // apply contingency by hand + network.getHvdcLine("hvdc12").remove(); + // run load flow to compare results + loadFlowRunner.run(network, parameters); + + // post-contingency tests + PostContingencyResult hvdcContingencyResult = getPostContingencyResult(result, "hvdc12"); + assertEquals(network.getLine("l12").getTerminal1().getP(), hvdcContingencyResult.getNetworkResult().getBranchResult("l12").getP1(), LoadFlowAssert.DELTA_POWER); + assertEquals(network.getLine("l12").getTerminal2().getP(), hvdcContingencyResult.getNetworkResult().getBranchResult("l12").getP2(), LoadFlowAssert.DELTA_POWER); + } + + @Test + void testFastDcSaHvdcAcEmulationDisabled() { + Network network = HvdcNetworkFactory.createHvdcInAcEmulationInSymetricNetwork(); + network.newLine() + .setId("l12_2") + .setBus1("b1") + .setConnectableBus1("b1") + .setBus2("b2") + .setConnectableBus2("b2") + .setR(0) + .setX(0.1f) + .add(); + + List monitors = createAllBranchesMonitors(network); + List contingencies = List.of(new Contingency("l12", new BranchContingency("l12"))); + + SecurityAnalysisParameters securityAnalysisParameters = new SecurityAnalysisParameters(); + LoadFlowParameters lfParameters = new LoadFlowParameters().setDc(true).setHvdcAcEmulation(true); + securityAnalysisParameters.setLoadFlowParameters(lfParameters); + OpenSecurityAnalysisParameters openSecurityAnalysisParameters = new OpenSecurityAnalysisParameters(); + openSecurityAnalysisParameters.setDcFastMode(true); + securityAnalysisParameters.addExtension(OpenSecurityAnalysisParameters.class, openSecurityAnalysisParameters); + + SecurityAnalysisResult result = runSecurityAnalysis(network, contingencies, monitors, securityAnalysisParameters); + + network.getLine("l12").disconnect(); + lfParameters.setHvdcAcEmulation(false); + loadFlowRunner.run(network, lfParameters); + + // verify ac emulation is disabled + PostContingencyResult postContingencyResult = getPostContingencyResult(result, "l12"); + assertEquals(network.getLine("l12_2").getTerminal1().getP(), postContingencyResult.getNetworkResult().getBranchResult("l12_2").getP1(), LoadFlowAssert.DELTA_POWER); + assertEquals(network.getLine("l12_2").getTerminal2().getP(), postContingencyResult.getNetworkResult().getBranchResult("l12_2").getP2(), LoadFlowAssert.DELTA_POWER); + } } From 8930cfd8cb517159ed1b74c9f4cc9d08b92fd5ba Mon Sep 17 00:00:00 2001 From: p-arvy Date: Fri, 24 Jan 2025 17:22:58 +0100 Subject: [PATCH 2/3] Clean Signed-off-by: p-arvy --- .../sa/OpenSecurityAnalysisTest.java | 97 +++---------------- 1 file changed, 15 insertions(+), 82 deletions(-) diff --git a/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java b/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java index f281077230..c07d7cf72e 100644 --- a/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java +++ b/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java @@ -4037,15 +4037,11 @@ void testNoCc0Sc0() { @ParameterizedTest @ValueSource(booleans = {false, true}) - void testDcSaWithHvdcLineContingency(boolean dcFastMode) { + void testDcSaHvdcLineContingency(boolean dcFastMode) { Network network = HvdcNetworkFactory.createNetworkWithGenerators(); - LoadFlowParameters parameters = new LoadFlowParameters(); - parameters.setDc(true).setHvdcAcEmulation(true); - OpenLoadFlowParameters.create(parameters) - .setSlackBusSelectionMode(SlackBusSelectionMode.FIRST); SecurityAnalysisParameters securityAnalysisParameters = new SecurityAnalysisParameters(); - securityAnalysisParameters.setLoadFlowParameters(parameters); + securityAnalysisParameters.getLoadFlowParameters().setDc(true).setHvdcAcEmulation(true); OpenSecurityAnalysisParameters openSecurityAnalysisParameters = new OpenSecurityAnalysisParameters(); openSecurityAnalysisParameters.setDcFastMode(dcFastMode); securityAnalysisParameters.addExtension(OpenSecurityAnalysisParameters.class, openSecurityAnalysisParameters); @@ -4058,7 +4054,7 @@ void testDcSaWithHvdcLineContingency(boolean dcFastMode) { network.getHvdcLine("hvdc34").remove(); network.getGenerator("g1").disconnect(); // run load flow to compare results - loadFlowRunner.run(network, parameters); + loadFlowRunner.run(network, securityAnalysisParameters.getLoadFlowParameters()); // post-contingency tests PostContingencyResult postContingencyResult = getPostContingencyResult(result, "hvdc34+g1"); @@ -4071,51 +4067,21 @@ void testDcSaWithHvdcLineContingency(boolean dcFastMode) { assertEquals(network.getLine("l56").getTerminal1().getP(), postContingencyResult.getNetworkResult().getBranchResult("l56").getP1(), LoadFlowAssert.DELTA_POWER); } - @Test - void testDcSaWithHvdcLineContingencyAndConnectivityBreak() { - Network network = HvdcNetworkFactory.createNetworkWithGenerators(); - - LoadFlowParameters parameters = new LoadFlowParameters(); - parameters.setDc(true); - OpenLoadFlowParameters.create(parameters) - .setSlackBusId("b2_vl_0") - .setSlackBusSelectionMode(SlackBusSelectionMode.NAME); - SecurityAnalysisParameters securityAnalysisParameters = new SecurityAnalysisParameters(); - securityAnalysisParameters.setLoadFlowParameters(parameters); - OpenSecurityAnalysisParameters openSecurityAnalysisParameters = new OpenSecurityAnalysisParameters(); - openSecurityAnalysisParameters.setDcFastMode(true); - securityAnalysisParameters.addExtension(OpenSecurityAnalysisParameters.class, openSecurityAnalysisParameters); - - List monitors = createAllBranchesMonitors(network); - List contingencies = List.of(new Contingency("hvdc34+l25", List.of(new HvdcLineContingency("hvdc34"), new LineContingency("l25")))); - SecurityAnalysisResult result = runSecurityAnalysis(network, contingencies, monitors, securityAnalysisParameters); - - // apply contingency by hand - network.getHvdcLine("hvdc34").remove(); - network.getLine("l25").disconnect(); - loadFlowRunner.run(network, parameters); - - // compare results on the lines - PostContingencyResult postContingencyResult = getPostContingencyResult(result, "hvdc34+l25"); - assertEquals(network.getLine("l12").getTerminal1().getP(), postContingencyResult.getNetworkResult().getBranchResult("l12").getP1(), LoadFlowAssert.DELTA_POWER); - assertEquals(network.getLine("l12").getTerminal2().getP(), postContingencyResult.getNetworkResult().getBranchResult("l12").getP2(), LoadFlowAssert.DELTA_POWER); - assertEquals(network.getLine("l13").getTerminal1().getP(), postContingencyResult.getNetworkResult().getBranchResult("l13").getP1(), LoadFlowAssert.DELTA_POWER); - assertEquals(network.getLine("l13").getTerminal2().getP(), postContingencyResult.getNetworkResult().getBranchResult("l13").getP2(), LoadFlowAssert.DELTA_POWER); - assertEquals(network.getLine("l23").getTerminal1().getP(), postContingencyResult.getNetworkResult().getBranchResult("l23").getP1(), LoadFlowAssert.DELTA_POWER); - assertEquals(network.getLine("l23").getTerminal2().getP(), postContingencyResult.getNetworkResult().getBranchResult("l23").getP2(), LoadFlowAssert.DELTA_POWER); - } - @ParameterizedTest @ValueSource(booleans = {false, true}) void testDcSaHvdcLineInAcEmulationContingency(boolean dcFastMode) { Network network = HvdcNetworkFactory.createHvdcInAcEmulationInSymetricNetwork(); + network.newLine() + .setId("l12_2") + .setBus1("b1") + .setConnectableBus1("b1") + .setBus2("b2") + .setConnectableBus2("b2") + .setR(0) + .setX(0.2f) + .add(); - LoadFlowParameters parameters = new LoadFlowParameters(); - parameters.setDc(true).setHvdcAcEmulation(true); - OpenLoadFlowParameters.create(parameters) - .setSlackBusSelectionMode(SlackBusSelectionMode.FIRST); SecurityAnalysisParameters securityAnalysisParameters = new SecurityAnalysisParameters(); - securityAnalysisParameters.setLoadFlowParameters(parameters); OpenSecurityAnalysisParameters openSecurityAnalysisParameters = new OpenSecurityAnalysisParameters(); openSecurityAnalysisParameters.setDcFastMode(dcFastMode); securityAnalysisParameters.addExtension(OpenSecurityAnalysisParameters.class, openSecurityAnalysisParameters); @@ -4127,46 +4093,13 @@ void testDcSaHvdcLineInAcEmulationContingency(boolean dcFastMode) { // apply contingency by hand network.getHvdcLine("hvdc12").remove(); // run load flow to compare results - loadFlowRunner.run(network, parameters); + loadFlowRunner.run(network, securityAnalysisParameters.getLoadFlowParameters()); // post-contingency tests PostContingencyResult hvdcContingencyResult = getPostContingencyResult(result, "hvdc12"); assertEquals(network.getLine("l12").getTerminal1().getP(), hvdcContingencyResult.getNetworkResult().getBranchResult("l12").getP1(), LoadFlowAssert.DELTA_POWER); assertEquals(network.getLine("l12").getTerminal2().getP(), hvdcContingencyResult.getNetworkResult().getBranchResult("l12").getP2(), LoadFlowAssert.DELTA_POWER); - } - - @Test - void testFastDcSaHvdcAcEmulationDisabled() { - Network network = HvdcNetworkFactory.createHvdcInAcEmulationInSymetricNetwork(); - network.newLine() - .setId("l12_2") - .setBus1("b1") - .setConnectableBus1("b1") - .setBus2("b2") - .setConnectableBus2("b2") - .setR(0) - .setX(0.1f) - .add(); - - List monitors = createAllBranchesMonitors(network); - List contingencies = List.of(new Contingency("l12", new BranchContingency("l12"))); - - SecurityAnalysisParameters securityAnalysisParameters = new SecurityAnalysisParameters(); - LoadFlowParameters lfParameters = new LoadFlowParameters().setDc(true).setHvdcAcEmulation(true); - securityAnalysisParameters.setLoadFlowParameters(lfParameters); - OpenSecurityAnalysisParameters openSecurityAnalysisParameters = new OpenSecurityAnalysisParameters(); - openSecurityAnalysisParameters.setDcFastMode(true); - securityAnalysisParameters.addExtension(OpenSecurityAnalysisParameters.class, openSecurityAnalysisParameters); - - SecurityAnalysisResult result = runSecurityAnalysis(network, contingencies, monitors, securityAnalysisParameters); - - network.getLine("l12").disconnect(); - lfParameters.setHvdcAcEmulation(false); - loadFlowRunner.run(network, lfParameters); - - // verify ac emulation is disabled - PostContingencyResult postContingencyResult = getPostContingencyResult(result, "l12"); - assertEquals(network.getLine("l12_2").getTerminal1().getP(), postContingencyResult.getNetworkResult().getBranchResult("l12_2").getP1(), LoadFlowAssert.DELTA_POWER); - assertEquals(network.getLine("l12_2").getTerminal2().getP(), postContingencyResult.getNetworkResult().getBranchResult("l12_2").getP2(), LoadFlowAssert.DELTA_POWER); + assertEquals(network.getLine("l12_2").getTerminal1().getP(), hvdcContingencyResult.getNetworkResult().getBranchResult("l12_2").getP1(), LoadFlowAssert.DELTA_POWER); + assertEquals(network.getLine("l12_2").getTerminal2().getP(), hvdcContingencyResult.getNetworkResult().getBranchResult("l12_2").getP2(), LoadFlowAssert.DELTA_POWER); } } From c2f556acb400cb2c0f4ae0a7df1424ec6e14fa5c Mon Sep 17 00:00:00 2001 From: p-arvy Date: Fri, 24 Jan 2025 17:41:51 +0100 Subject: [PATCH 3/3] Fix Signed-off-by: p-arvy --- .../com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java b/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java index c07d7cf72e..c7ff05beb0 100644 --- a/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java +++ b/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java @@ -4082,6 +4082,7 @@ void testDcSaHvdcLineInAcEmulationContingency(boolean dcFastMode) { .add(); SecurityAnalysisParameters securityAnalysisParameters = new SecurityAnalysisParameters(); + securityAnalysisParameters.getLoadFlowParameters().setDc(true).setHvdcAcEmulation(true); OpenSecurityAnalysisParameters openSecurityAnalysisParameters = new OpenSecurityAnalysisParameters(); openSecurityAnalysisParameters.setDcFastMode(dcFastMode); securityAnalysisParameters.addExtension(OpenSecurityAnalysisParameters.class, openSecurityAnalysisParameters);