From 770757dd136057e1907ecb652f5d7c820aa9e0e0 Mon Sep 17 00:00:00 2001 From: Hadrien Date: Fri, 27 May 2022 14:55:14 +0200 Subject: [PATCH] Fix isElementConnectedToComponent removing disabled lines from component even if both ends are still connected. Signed-off-by: Hadrien --- .../sensi/AbstractSensitivityAnalysis.java | 2 +- .../sensi/AcSensitivityAnalysis.java | 27 +++++++++---------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/powsybl/openloadflow/sensi/AbstractSensitivityAnalysis.java b/src/main/java/com/powsybl/openloadflow/sensi/AbstractSensitivityAnalysis.java index 7f4f315143..4b652a5f61 100644 --- a/src/main/java/com/powsybl/openloadflow/sensi/AbstractSensitivityAnalysis.java +++ b/src/main/java/com/powsybl/openloadflow/sensi/AbstractSensitivityAnalysis.java @@ -298,7 +298,7 @@ protected boolean isElementConnectedToComponent(LfElement element, Set co if (element instanceof LfBus) { return component.contains(element); } else if (element instanceof LfBranch) { - return component.contains(((LfBranch) element).getBus1()) && component.contains(((LfBranch) element).getBus2()); + return component.contains(((LfBranch) element).getBus1()) && component.contains(((LfBranch) element).getBus2()) && !element.isDisabled(); } throw new PowsyblException("Cannot compute connectivity for variable element of class: " + element.getClass().getSimpleName()); } diff --git a/src/main/java/com/powsybl/openloadflow/sensi/AcSensitivityAnalysis.java b/src/main/java/com/powsybl/openloadflow/sensi/AcSensitivityAnalysis.java index 4e95df134e..11110aa22b 100644 --- a/src/main/java/com/powsybl/openloadflow/sensi/AcSensitivityAnalysis.java +++ b/src/main/java/com/powsybl/openloadflow/sensi/AcSensitivityAnalysis.java @@ -289,24 +289,23 @@ public void analyse(Network network, List contingencies, Map postContingencySlackParticipationByBus; - // Sensitivity values 0 and function reference NaN in case of a sensitivity on a disabled branch - contingencyFactors.stream() - .filter(lfFactor -> lfFactor.getFunctionElement() instanceof LfBranch) - .filter(lfFactor -> lfContingency.getDisabledBranches().contains(lfFactor.getFunctionElement())) - .forEach(lfFactor -> { - lfFactor.setSensitivityValuePredefinedResult(0d); - lfFactor.setFunctionPredefinedResult(Double.NaN); - }); - // Sensitivity values 0 in case of a sensitivity from the transformer phase of a disabled transformer - contingencyFactors.stream() - .filter(lfFactor -> lfFactor.getVariableType().equals(SensitivityVariableType.TRANSFORMER_PHASE)) - .filter(lfFactor -> lfContingency.getDisabledBranches().contains(lfNetwork.getBranchById(lfFactor.getVariableId()))) - .forEach(lfFactor -> lfFactor.setSensitivityValuePredefinedResult(0d)); - if (lfContingency.getDisabledBuses().isEmpty()) { // contingency not breaking connectivity LOGGER.info("Contingency {} without loss of connectivity", lfContingency.getId()); postContingencySlackParticipationByBus = slackParticipationByBus; + // Sensitivity values 0 and function reference NaN in case of a sensitivity on a disabled branch + contingencyFactors.stream() + .filter(lfFactor -> lfFactor.getFunctionElement() instanceof LfBranch) + .filter(lfFactor -> lfContingency.getDisabledBranches().contains(lfFactor.getFunctionElement())) + .forEach(lfFactor -> { + lfFactor.setSensitivityValuePredefinedResult(0d); + lfFactor.setFunctionPredefinedResult(Double.NaN); + }); + // Sensitivity values 0 in case of a sensitivity from the transformer phase of a disabled transformer + contingencyFactors.stream() + .filter(lfFactor -> lfFactor.getVariableType().equals(SensitivityVariableType.TRANSFORMER_PHASE)) + .filter(lfFactor -> lfContingency.getDisabledBranches().contains(lfNetwork.getBranchById(lfFactor.getVariableId()))) + .forEach(lfFactor -> lfFactor.setSensitivityValuePredefinedResult(0d)); } else { // contingency breaking connectivity LOGGER.info("Contingency {} with loss of connectivity", lfContingency.getId());