From 6229d231a83bbb97b7b4dac241a1ba3c21ba7f0e Mon Sep 17 00:00:00 2001 From: vmouradian Date: Tue, 17 Dec 2024 17:42:32 +0100 Subject: [PATCH] new tests + refactor tests Signed-off-by: vmouradian --- .../sa/OpenSecurityAnalysisTest.java | 53 +++++++++++++++++++ .../OpenSecurityAnalysisWithActionsTest.java | 14 +++-- 2 files changed, 63 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 07a08ee6b8..e3542ba873 100644 --- a/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java +++ b/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java @@ -41,6 +41,7 @@ import com.powsybl.openloadflow.network.impl.Networks; import com.powsybl.openloadflow.network.impl.OlfBranchResult; import com.powsybl.openloadflow.network.impl.OlfThreeWindingsTransformerResult; +import com.powsybl.openloadflow.sa.extensions.ContingencyLoadFlowParameters; import com.powsybl.openloadflow.util.LoadFlowAssert; import com.powsybl.security.*; import com.powsybl.security.condition.TrueCondition; @@ -4034,4 +4035,56 @@ void testNoCc0Sc0() { assertEquals(LoadFlowResult.ComponentResult.Status.CONVERGED, saResultAll.getPreContingencyResult().getStatus()); assertEquals(6, saResultAll.getPreContingencyResult().getNetworkResult().getBusResults().size()); // 6 buses in total } + + @ParameterizedTest(name = "DC = {0}") + @ValueSource(booleans = {false, true}) + void testContingencyParameters(boolean isDc) { + Network network = MultiAreaNetworkFactory.createTwoAreasWithTieLine(); + + // Create 3 times the same contingency + Contingency cont1 = new Contingency("load3_aic_load", new LoadContingency("load3")); + Contingency cont2 = new Contingency("load3_no_ext", new LoadContingency("load3")); + Contingency cont3 = new Contingency("load3_slack_gen_p", new LoadContingency("load3")); + List contingencies = List.of(cont1, cont2, cont3); + + // Default LF parameters + LoadFlowParameters parameters = new LoadFlowParameters() + .setDc(isDc) + .setDistributedSlack(true) + .setBalanceType(LoadFlowParameters.BalanceType.PROPORTIONAL_TO_GENERATION_P_MAX); + + // Add contingency LF parameters to contingencies 1 and 3 + ContingencyLoadFlowParameters contLfParams1 = new ContingencyLoadFlowParameters(false, true, LoadFlowParameters.BalanceType.PROPORTIONAL_TO_LOAD); + cont1.addExtension(ContingencyLoadFlowParameters.class, contLfParams1); + ContingencyLoadFlowParameters contLfParams3 = new ContingencyLoadFlowParameters(true, false, LoadFlowParameters.BalanceType.PROPORTIONAL_TO_GENERATION_P); + cont3.addExtension(ContingencyLoadFlowParameters.class, contLfParams3); + + // Run security analysis + List monitors = createAllBranchesMonitors(network); + SecurityAnalysisParameters securityAnalysisParameters = new SecurityAnalysisParameters(); + securityAnalysisParameters.setLoadFlowParameters(parameters); + SecurityAnalysisResult resultAc = runSecurityAnalysis(network, contingencies, monitors, securityAnalysisParameters); + + // Pre-contingency results -> distributed slack on gens, proportional to Pmax + PreContingencyResult preContingencyResult = resultAc.getPreContingencyResult(); + assertEquals(25, preContingencyResult.getNetworkResult().getBranchResult("tl1").getP1(), LoadFlowAssert.DELTA_POWER); + assertEquals(30, preContingencyResult.getNetworkResult().getBranchResult("l34").getP1(), LoadFlowAssert.DELTA_POWER); + + // Post-contingency results + // Contingency 1: AIC, proportional to load + PostContingencyResult postContingencyResult1 = getPostContingencyResult(resultAc, "load3_aic_load"); + assertEquals(50, postContingencyResult1.getNetworkResult().getBranchResult("tl1").getP1(), LoadFlowAssert.DELTA_POWER); + assertEquals(75, postContingencyResult1.getNetworkResult().getBranchResult("l34").getP1(), LoadFlowAssert.DELTA_POWER); + + // Contingency 2: no extension, distributed slack proportional to gen Pmax + PostContingencyResult postContingencyResult2 = getPostContingencyResult(resultAc, "load3_no_ext"); + assertEquals(15, postContingencyResult2.getNetworkResult().getBranchResult("tl1").getP1(), LoadFlowAssert.DELTA_POWER); + assertEquals(30, postContingencyResult2.getNetworkResult().getBranchResult("l34").getP1(), LoadFlowAssert.DELTA_POWER); + + // Contingency 3: distributed slack, proportional to gen P + PostContingencyResult postContingencyResult3 = getPostContingencyResult(resultAc, "load3_slack_gen_p"); + assertEquals(9.545, postContingencyResult3.getNetworkResult().getBranchResult("tl1").getP1(), LoadFlowAssert.DELTA_POWER); + assertEquals(30, postContingencyResult3.getNetworkResult().getBranchResult("l34").getP1(), LoadFlowAssert.DELTA_POWER); + + } } diff --git a/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisWithActionsTest.java b/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisWithActionsTest.java index 8b408c015e..9ec37b0e90 100644 --- a/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisWithActionsTest.java +++ b/src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisWithActionsTest.java @@ -1673,9 +1673,12 @@ void testOperatorStrategyNoMoreBusVoltageControlled() throws IOException { assertReportEquals("/saReportOperatorStrategyNoVoltageControl.txt", reportNode); } - @Test - void testContingencyParameters() { + @ParameterizedTest(name = "DC = {0}") + @ValueSource(booleans = {false, true}) + void testContingencyParameters(boolean isDc) { Network network = MultiAreaNetworkFactory.createTwoAreasWithTieLine(); + + // create a contingency with ContingencyLoadFlowParameters extension Contingency contingency1 = new Contingency("load3", new LoadContingency("load3")); ContingencyLoadFlowParameters contingencyParameters1 = new ContingencyLoadFlowParameters(false, true, LoadFlowParameters.BalanceType.PROPORTIONAL_TO_LOAD); contingency1.addExtension(ContingencyLoadFlowParameters.class, contingencyParameters1); @@ -1688,22 +1691,25 @@ void testContingencyParameters() { List actions = List.of(action1); List operatorStrategies = List.of(operatorStrategy1); - LoadFlowParameters parameters = new LoadFlowParameters(); - parameters.setDistributedSlack(true); + // run the security analysis + LoadFlowParameters parameters = new LoadFlowParameters().setDc(isDc); parameters.setConnectedComponentMode(LoadFlowParameters.ConnectedComponentMode.ALL); SecurityAnalysisParameters securityAnalysisParameters = new SecurityAnalysisParameters(); securityAnalysisParameters.setLoadFlowParameters(parameters); SecurityAnalysisResult resultAc = runSecurityAnalysis(network, contingencies, monitors, securityAnalysisParameters, operatorStrategies, actions, ReportNode.NO_OP); + // Pre-contingency results PreContingencyResult preContingencyResult = resultAc.getPreContingencyResult(); assertEquals(25, preContingencyResult.getNetworkResult().getBranchResult("tl1").getP1(), LoadFlowAssert.DELTA_POWER); assertEquals(30, preContingencyResult.getNetworkResult().getBranchResult("l34").getP1(), LoadFlowAssert.DELTA_POWER); + // Post-contingency results : AIC on loads PostContingencyResult postContingencyResult = getPostContingencyResult(resultAc, "load3"); assertEquals(50, postContingencyResult.getNetworkResult().getBranchResult("tl1").getP1(), LoadFlowAssert.DELTA_POWER); assertEquals(75, postContingencyResult.getNetworkResult().getBranchResult("l34").getP1(), LoadFlowAssert.DELTA_POWER); + // Operator strategy results : AIC on loads OperatorStrategyResult acStrategyResult = getOperatorStrategyResult(resultAc, "strategy1"); assertEquals(50, acStrategyResult.getNetworkResult().getBranchResult("tl1").getP1(), LoadFlowAssert.DELTA_POWER); assertEquals(95, acStrategyResult.getNetworkResult().getBranchResult("l34").getP1(), LoadFlowAssert.DELTA_POWER);