From 5f48516124777b64fc32ba035636525a054fa934 Mon Sep 17 00:00:00 2001 From: Anne Tilloy Date: Fri, 23 Sep 2022 10:42:05 +0200 Subject: [PATCH 1/2] Add TU to show the bug. Signed-off-by: Anne Tilloy --- .../DcSensitivityAnalysisContingenciesTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/test/java/com/powsybl/openloadflow/sensi/dc/DcSensitivityAnalysisContingenciesTest.java b/src/test/java/com/powsybl/openloadflow/sensi/dc/DcSensitivityAnalysisContingenciesTest.java index fd7cdcb4fd..f76787025f 100644 --- a/src/test/java/com/powsybl/openloadflow/sensi/dc/DcSensitivityAnalysisContingenciesTest.java +++ b/src/test/java/com/powsybl/openloadflow/sensi/dc/DcSensitivityAnalysisContingenciesTest.java @@ -2122,4 +2122,21 @@ void testSwitchContingency() { assertEquals(300.0, result.getBranchFlow1FunctionReferenceValue("L1"), LoadFlowAssert.DELTA_POWER); assertEquals(-3.770, result.getBranchFlow1FunctionReferenceValue("C", "L1"), LoadFlowAssert.DELTA_POWER); } + + @Test + void testFunctionDisconnectedBranchBothSidesWithContingency() { + Network network = ConnectedComponentNetworkFactory.createTwoCcLinkedByTwoLines(); + Line l45 = network.getLine("l45"); + l45.getTerminal1().disconnect(); + l45.getTerminal2().disconnect(); + runDcLf(network); + + SensitivityAnalysisParameters sensiParameters = createParameters(true, "b1_vl_0", true); + sensiParameters.getLoadFlowParameters().setBalanceType(LoadFlowParameters.BalanceType.PROPORTIONAL_TO_LOAD); + + List factors = List.of(createBranchFlowPerInjectionIncrease("l45", "g2")); + List contingencies = List.of(new Contingency("C", List.of(new BranchContingency("l24"), new BranchContingency("l35")))); + + SensitivityAnalysisResult result = sensiRunner.run(network, factors, contingencies, Collections.emptyList(), sensiParameters); + } } From dc71a97d071abfa714920fe3ee368a803173bf51 Mon Sep 17 00:00:00 2001 From: Anne Tilloy Date: Fri, 23 Sep 2022 10:54:30 +0200 Subject: [PATCH 2/2] Fix proposal. Signed-off-by: Anne Tilloy --- .../openloadflow/sensi/DcSensitivityAnalysis.java | 9 +++++++-- .../sensi/dc/DcSensitivityAnalysisContingenciesTest.java | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/powsybl/openloadflow/sensi/DcSensitivityAnalysis.java b/src/main/java/com/powsybl/openloadflow/sensi/DcSensitivityAnalysis.java index a8bf8e09b8..b258bef45a 100644 --- a/src/main/java/com/powsybl/openloadflow/sensi/DcSensitivityAnalysis.java +++ b/src/main/java/com/powsybl/openloadflow/sensi/DcSensitivityAnalysis.java @@ -571,7 +571,7 @@ private static Set getGroupOfElementsBreakingConnect private static List computeConnectivityData(LfNetwork lfNetwork, SensitivityFactorHolder factorHolder, Map, List> contingenciesByGroupOfElementsBreakingConnectivity, - List nonLosingConnectivityContingencies) { + List nonLosingConnectivityContingencies, SensitivityResultWriter resultWriter) { if (contingenciesByGroupOfElementsBreakingConnectivity.isEmpty()) { return Collections.emptyList(); } @@ -606,6 +606,11 @@ private static List computeConnectivityData(LfNetwor List> lfFactors = factorHolder.getFactorsForContingencies(contingenciesIds); if (!lfFactors.isEmpty()) { connectivityAnalysisResults.computeIfAbsent(breakingConnectivityElements, branches -> new ConnectivityAnalysisResult(lfFactors, branches, connectivity, lfNetwork)).getContingencies().addAll(contingencyList); + } else { + // write contingency status + for (PropagatedContingency propagatedContingency : contingencyList) { + resultWriter.writeContingencyStatus(propagatedContingency.getIndex(), SensitivityAnalysisResult.Status.SUCCESS); + } } } connectivity.undoTemporaryChanges(); @@ -931,7 +936,7 @@ public void analyse(Network network, List contingencies, // this second method process all contingencies that potentially break connectivity and using graph algorithms // find remaining contingencies that do not break connectivity List connectivityAnalysisResults - = computeConnectivityData(lfNetwork, validFactorHolder, contingenciesByGroupOfElementsPotentiallyBreakingConnectivity, nonBreakingConnectivityContingencies); + = computeConnectivityData(lfNetwork, validFactorHolder, contingenciesByGroupOfElementsPotentiallyBreakingConnectivity, nonBreakingConnectivityContingencies, resultWriter); LOGGER.info("After graph based connectivity analysis, {} contingencies do not break connectivity, {} contingencies break connectivity", nonBreakingConnectivityContingencies.size(), connectivityAnalysisResults.stream().mapToInt(results -> results.getContingencies().size()).count()); diff --git a/src/test/java/com/powsybl/openloadflow/sensi/dc/DcSensitivityAnalysisContingenciesTest.java b/src/test/java/com/powsybl/openloadflow/sensi/dc/DcSensitivityAnalysisContingenciesTest.java index f76787025f..d8b9b8ad02 100644 --- a/src/test/java/com/powsybl/openloadflow/sensi/dc/DcSensitivityAnalysisContingenciesTest.java +++ b/src/test/java/com/powsybl/openloadflow/sensi/dc/DcSensitivityAnalysisContingenciesTest.java @@ -2138,5 +2138,6 @@ void testFunctionDisconnectedBranchBothSidesWithContingency() { List contingencies = List.of(new Contingency("C", List.of(new BranchContingency("l24"), new BranchContingency("l35")))); SensitivityAnalysisResult result = sensiRunner.run(network, factors, contingencies, Collections.emptyList(), sensiParameters); + assertEquals(SensitivityAnalysisResult.Status.SUCCESS, result.getContingencyStatus("C")); } }