Skip to content

Commit

Permalink
Connectivity data in DC sensitivity analysis (#1035)
Browse files Browse the repository at this point in the history
Signed-off-by: Anne Tilloy <anne.tilloy@rte-france.com>
  • Loading branch information
annetill authored May 24, 2024
1 parent 3a60d46 commit ea70178
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ private static void setLocalIndexes(Collection<ComputedContingencyElement> eleme
}
}

static void applyToConnectivity(LfNetwork lfNetwork, GraphConnectivity<LfBus, LfBranch> connectivity, Collection<ComputedContingencyElement> breakingConnectivityElements) {
breakingConnectivityElements.stream()
.map(ComputedContingencyElement::getElement)
.map(ContingencyElement::getId)
.distinct()
.map(lfNetwork::getBranchById)
.filter(b -> b.getBus1() != null && b.getBus2() != null)
.forEach(connectivity::removeEdge);
}
}

private static final class PhaseTapChangerContingenciesIndexing {
Expand Down Expand Up @@ -569,19 +578,19 @@ private static List<ConnectivityAnalysisResult> computeConnectivityData(LfNetwor
for (Map.Entry<Set<ComputedContingencyElement>, List<PropagatedContingency>> e : contingenciesByGroupOfElementsBreakingConnectivity.entrySet()) {
Set<ComputedContingencyElement> breakingConnectivityCandidates = e.getKey();
List<PropagatedContingency> contingencyList = e.getValue();

Set<ComputedContingencyElement> breakingConnectivityElements;
connectivity.startTemporaryChanges();
breakingConnectivityCandidates.stream()
.map(ComputedContingencyElement::getElement)
.map(ContingencyElement::getId)
.distinct()
.map(lfNetwork::getBranchById)
.filter(b -> b.getBus1() != null && b.getBus2() != null)
.forEach(connectivity::removeEdge);
try {
ComputedContingencyElement.applyToConnectivity(lfNetwork, connectivity, breakingConnectivityCandidates);
// filter the branches that really impacts connectivity
breakingConnectivityElements = breakingConnectivityCandidates.stream()
.filter(element -> isBreakingConnectivity(connectivity, element))
.collect(Collectors.toCollection(LinkedHashSet::new));
} finally {
connectivity.undoTemporaryChanges();
}

// filter the branches that really impacts connectivity
Set<ComputedContingencyElement> breakingConnectivityElements = breakingConnectivityCandidates.stream()
.filter(element -> isBreakingConnectivity(connectivity, element))
.collect(Collectors.toCollection(LinkedHashSet::new));
if (breakingConnectivityElements.isEmpty()) {
// we did not break any connectivity
nonLosingConnectivityContingencies.addAll(contingencyList);
Expand All @@ -591,19 +600,24 @@ private static List<ConnectivityAnalysisResult> computeConnectivityData(LfNetwor

List<LfSensitivityFactor<DcVariableType, DcEquationType>> lfFactors = factorHolder.getFactorsForContingencies(contingenciesIds);
if (!lfFactors.isEmpty()) {
ConnectivityAnalysisResult connectivityAnalysisResult = connectivityAnalysisResults.computeIfAbsent(breakingConnectivityElements, k -> {
Set<String> elementsToReconnect = computeElementsToReconnect(connectivity, breakingConnectivityElements);
return new ConnectivityAnalysisResult(elementsToReconnect, connectivity, lfNetwork);
});
connectivityAnalysisResult.getContingencies().addAll(contingencyList);
connectivity.startTemporaryChanges();
try {
ComputedContingencyElement.applyToConnectivity(lfNetwork, connectivity, breakingConnectivityElements);
ConnectivityAnalysisResult connectivityAnalysisResult = connectivityAnalysisResults.computeIfAbsent(breakingConnectivityElements, k -> {
Set<String> elementsToReconnect = computeElementsToReconnect(connectivity, breakingConnectivityElements);
return new ConnectivityAnalysisResult(elementsToReconnect, connectivity, lfNetwork);
});
connectivityAnalysisResult.getContingencies().addAll(contingencyList);
} finally {
connectivity.undoTemporaryChanges();
}
} else {
// write contingency status
for (PropagatedContingency propagatedContingency : contingencyList) {
resultWriter.writeContingencyStatus(propagatedContingency.getIndex(), SensitivityAnalysisResult.Status.SUCCESS);
}
}
}
connectivity.undoTemporaryChanges();
}
return new ArrayList<>(connectivityAnalysisResults.values());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2471,4 +2471,22 @@ void testVSCLoss() {
assertEquals(0.0, result.getBranchFlow1FunctionReferenceValue("contingency", "l34"), LoadFlowAssert.DELTA_POWER);
assertEquals(0.0, result.getBranchFlow1FunctionReferenceValue("bus", "l34"), LoadFlowAssert.DELTA_POWER);
}

@Test
void testContingenciesWithConnectivityBreak() {
Network network = ConnectedComponentNetworkFactory.createHighlyConnectedNetwork();

SensitivityAnalysisParameters sensiParameters = createParameters(true, "b3_vl_0", true);
sensiParameters.getLoadFlowParameters().setBalanceType(LoadFlowParameters.BalanceType.PROPORTIONAL_TO_LOAD);

List<SensitivityFactor> factors = network.getBranchStream().map(branch -> createBranchFlowPerInjectionIncrease(branch.getId(), "d5")).collect(Collectors.toList());

List<Contingency> contingencies = List.of(
new Contingency("l67+l57+l56", new BranchContingency("l67"), new BranchContingency("l57"), new BranchContingency("l56")),
new Contingency("l67+l57", new BranchContingency("l67"), new BranchContingency("l57")));

SensitivityAnalysisResult result = sensiRunner.run(network, factors, contingencies, Collections.emptyList(), sensiParameters);
assertEquals(Double.NaN, result.getBranchFlow1FunctionReferenceValue("l67+l57+l56", "l56"));
assertEquals(-0.296, result.getBranchFlow1FunctionReferenceValue("l67+l57", "l56"), LoadFlowAssert.DELTA_POWER);
}
}

0 comments on commit ea70178

Please sign in to comment.