Skip to content

Commit

Permalink
Fix AC sensitivity analysis in case of a branch contingency breaking …
Browse files Browse the repository at this point in the history
…connectivity (#541)

Signed-off-by: Hadrien <hadrien.godard@artelys.com>
  • Loading branch information
Hadrien-Godard authored May 30, 2022
1 parent 9b6203b commit 4d3e30e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ protected boolean isElementConnectedToComponent(LfElement element, Set<LfBus> co
if (element instanceof LfBus) {
return component.contains(element);
} else if (element instanceof LfBranch) {
// FIXME: a branch in contingency could have both buses in the component, then the method will return True.
return component.contains(((LfBranch) element).getBus1()) && component.contains(((LfBranch) element).getBus2());
}
throw new PowsyblException("Cannot compute connectivity for variable element of class: " + element.getClass().getSimpleName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,21 +276,22 @@ public void analyse(Network network, List<PropagatedContingency> contingencies,
lfFactor.setFunctionPredefinedResult(null);
});

contingencyFactors.stream()
.filter(lfFactor -> lfFactor.getFunctionElement() instanceof LfBranch)
.filter(lfFactor -> lfContingency.getDisabledBranches().contains(lfFactor.getFunctionElement()))
.forEach(lfFactor -> {
lfFactor.setSensitivityValuePredefinedResult(0d);
lfFactor.setFunctionPredefinedResult(Double.NaN);
});
contingencyFactors.stream()
.filter(lfFactor -> lfFactor.getVariableType().equals(SensitivityVariableType.TRANSFORMER_PHASE))
.filter(lfFactor -> lfContingency.getDisabledBranches().contains(lfNetwork.getBranchById(lfFactor.getVariableId())))
.forEach(lfFactor -> lfFactor.setSensitivityValuePredefinedResult(0d));

Map<LfBus, Double> postContingencySlackParticipationByBus;
if (lfContingency.getDisabledBuses().isEmpty()) {
// contingency not breaking connectivity
postContingencySlackParticipationByBus = slackParticipationByBus;
contingencyFactors.stream()
.filter(lfFactor -> lfFactor.getFunctionElement() instanceof LfBranch)
.filter(lfFactor -> lfContingency.getDisabledBranches().contains(lfFactor.getFunctionElement()))
.forEach(lfFactor -> {
lfFactor.setSensitivityValuePredefinedResult(0d);
lfFactor.setFunctionPredefinedResult(Double.NaN);
});
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
// we check if factors are still in the main component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -771,4 +771,24 @@ void test4busesPhaseShiftIntensityFunctionReference() {
assertEquals(Double.NaN, result.getFunctionReferenceValue("l23", "l23", SensitivityFunctionType.BRANCH_CURRENT_1), LoadFlowAssert.DELTA_POWER);
assertEquals(0.0, result.getBranchCurrent1SensitivityValue("l23", "l23", "l12"), LoadFlowAssert.DELTA_POWER);
}

@Test
void testLosingALineButBothEndsInMainComponent() {
Network network = ConnectedComponentNetworkFactory.createTwoComponentWithGeneratorOnOneSide();

SensitivityAnalysisParameters sensiParameters = createParameters(false, "b3_vl_0", false);

List<Contingency> contingencies = List.of(new Contingency("l34+l12", new BranchContingency("l34"), new BranchContingency("l12")));

List<SensitivityFactor> factors = createFactorMatrix(List.of(network.getGenerator("g3")),
List.of(network.getLine("l12")),
"l34+l12");

SensitivityAnalysisResult result = sensiRunner.run(network, factors, contingencies, Collections.emptyList(), sensiParameters);

assertEquals(1, result.getValues("l34+l12").size());

assertEquals(0.0, result.getBranchFlow1SensitivityValue("l34+l12", "g3", "l12"), LoadFlowAssert.DELTA_POWER);
assertEquals(Double.NaN, result.getBranchFlow1FunctionReferenceValue("l34+l12", "l12"), LoadFlowAssert.DELTA_POWER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2017,4 +2017,24 @@ void testGLSK3() {
assertNotEquals(result2.getBranchFlow1SensitivityValue("glsk", "l34"), result.getBranchFlow1SensitivityValue("d2", "glsk", "l34"), LoadFlowAssert.DELTA_POWER);
assertNotEquals(result2.getBranchFlow1SensitivityValue("glsk", "l13"), result.getBranchFlow1SensitivityValue("d2", "glsk", "l13"), LoadFlowAssert.DELTA_POWER);
}

@Test
void testLosingALineButBothEndsInMainComponent() {
Network network = ConnectedComponentNetworkFactory.createTwoComponentWithGeneratorOnOneSide();

SensitivityAnalysisParameters sensiParameters = createParameters(true, "b3_vl_0", false);

List<Contingency> contingencies = List.of(new Contingency("l34+l12", new BranchContingency("l34"), new BranchContingency("l12")));

List<SensitivityFactor> factors = createFactorMatrix(List.of(network.getGenerator("g3")),
List.of(network.getLine("l12")),
"l34+l12");

SensitivityAnalysisResult result = sensiRunner.run(network, factors, contingencies, Collections.emptyList(), sensiParameters);

assertEquals(1, result.getValues("l34+l12").size());

assertEquals(0.0, result.getBranchFlow1SensitivityValue("l34+l12", "g3", "l12"), LoadFlowAssert.DELTA_POWER);
assertEquals(Double.NaN, result.getBranchFlow1FunctionReferenceValue("l34+l12", "l12"), LoadFlowAssert.DELTA_POWER);
}
}

0 comments on commit 4d3e30e

Please sign in to comment.