Skip to content

Commit

Permalink
Move cleanContingencies from DC sensitivity analysis to PropagatedCon…
Browse files Browse the repository at this point in the history
…tingency utility method (#1081)

Signed-off-by: p-arvy <[email protected]>
Co-authored-by: Anne Tilloy <[email protected]>
  • Loading branch information
p-arvy and annetill authored Aug 29, 2024
1 parent b4266bb commit 8fd8cc4
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -540,4 +540,58 @@ public Optional<LfContingency> toLfContingency(LfNetwork network) {
new DisabledNetwork(busesToLost, branchesToOpen, lostHvdcs), shunts, loads, generators,
connectivityLossImpact.hvdcsWithoutPower()));
}

/**
* In general, a {@link PropagatedContingency} is translated to a {@link LfContingency}. During the translation,
* cleans are performed to deal with branches connected at one side and slack bus loss. But in some fast DC computations,
* we don't want to use {@link LfContingency} object, so a dedicated clean method directly available on a {@link PropagatedContingency}
* is needed. It contains:
* - Removing branches out of this synchronous component from branches to open.
* - Removing branches connected at one side from branches to open.
* - Removing slack bus from buses lost (not supported yet).
* - Adding branches connected to buses lost in branches to open.
*/
public static void cleanContingencies(LfNetwork lfNetwork, List<PropagatedContingency> contingencies) {
for (PropagatedContingency contingency : contingencies) {
// Elements have already been checked and found in PropagatedContingency, so there is no need to
// check them again
Set<String> branchesToRemove = new HashSet<>(); // branches connected to one side, or switches
for (String branchId : contingency.getBranchIdsToOpen().keySet()) {
LfBranch lfBranch = lfNetwork.getBranchById(branchId);
if (lfBranch == null) {
branchesToRemove.add(branchId); // disconnected branch
continue;
}
if (!lfBranch.isConnectedAtBothSides()) {
branchesToRemove.add(branchId); // branch connected only on one side
}
}
branchesToRemove.forEach(branchToRemove -> contingency.getBranchIdsToOpen().remove(branchToRemove));

// update branches to open connected with buses in contingency. This is an approximation:
// these branches are indeed just open at one side.
String slackBusId = null;
for (String busId : contingency.getBusIdsToLose()) {
LfBus bus = lfNetwork.getBusById(busId);
if (bus != null) {
if (bus.isSlack()) {
// slack bus disabling is not supported in DC because the relocation is done from propagated contingency
// to LfContingency
// we keep the slack bus enabled and the connected branches
LOGGER.error("Contingency '{}' leads to the loss of a slack bus: slack bus kept", contingency.getContingency().getId());
slackBusId = busId;
} else {
bus.getBranches().forEach(branch -> contingency.getBranchIdsToOpen().put(branch.getId(), DisabledBranchStatus.BOTH_SIDES));
}
}
}
if (slackBusId != null) {
contingency.getBusIdsToLose().remove(slackBusId);
}

if (contingency.hasNoImpact()) {
LOGGER.warn("Contingency '{}' has no impact", contingency.getContingency().getId());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.stream.Collectors;

import static com.powsybl.openloadflow.dc.DcLoadFlowEngine.run;
import static com.powsybl.openloadflow.network.impl.PropagatedContingency.cleanContingencies;
import static com.powsybl.openloadflow.network.util.ParticipatingElement.normalizeParticipationFactors;

/**
Expand Down Expand Up @@ -338,50 +339,6 @@ private void processContingenciesBreakingConnectivity(ConnectivityBreakAnalysis.
connectivityAnalysisResult.getElementsToReconnect(), resultWriter, reportNode, partialDisabledBranches, rhsChanged);
}

protected void cleanContingencies(LfNetwork lfNetwork, List<PropagatedContingency> contingencies) {
for (PropagatedContingency contingency : contingencies) {
// Elements have already been checked and found in PropagatedContingency, so there is no need to
// check them again
Set<String> branchesToRemove = new HashSet<>(); // branches connected to one side, or switches
for (String branchId : contingency.getBranchIdsToOpen().keySet()) {
LfBranch lfBranch = lfNetwork.getBranchById(branchId);
if (lfBranch == null) {
branchesToRemove.add(branchId); // disconnected branch
continue;
}
if (!lfBranch.isConnectedAtBothSides()) {
branchesToRemove.add(branchId); // branch connected only on one side
}
}
branchesToRemove.forEach(branchToRemove -> contingency.getBranchIdsToOpen().remove(branchToRemove));

// update branches to open connected with buses in contingency. This is an approximation:
// these branches are indeed just open at one side.
String slackBusId = null;
for (String busId : contingency.getBusIdsToLose()) {
LfBus bus = lfNetwork.getBusById(busId);
if (bus != null) {
if (bus.isSlack()) {
// slack bus disabling is not supported in DC because the relocation is done from propagated contingency
// to LfContingency
// we keep the slack bus enabled and the connected branches
LOGGER.error("Contingency '{}' leads to the loss of a slack bus: slack bus kept", contingency.getContingency().getId());
slackBusId = busId;
} else {
bus.getBranches().forEach(branch -> contingency.getBranchIdsToOpen().put(branch.getId(), DisabledBranchStatus.BOTH_SIDES));
}
}
}
if (slackBusId != null) {
contingency.getBusIdsToLose().remove(slackBusId);
}

if (contingency.hasNoImpact()) {
LOGGER.warn("Contingency '{}' has no impact", contingency.getContingency().getId());
}
}
}

@Override
public void analyse(Network network, List<PropagatedContingency> contingencies, List<SensitivityVariableSet> variableSets,
SensitivityFactorReader factorReader, SensitivityResultWriter resultWriter, ReportNode reportNode,
Expand Down

0 comments on commit 8fd8cc4

Please sign in to comment.