Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connectivity data in DC sensitivity analysis #1035

Merged
merged 3 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}