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

Move cleanContingencies from DC sensitivity analysis to utility method #1081

Merged
merged 5 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -540,4 +540,55 @@ public Optional<LfContingency> toLfContingency(LfNetwork network) {
new DisabledNetwork(busesToLost, branchesToOpen, lostHvdcs), shunts, loads, generators,
connectivityLossImpact.hvdcsWithoutPower()));
}

/**
* Clean the propagated contingencies, by:
* - Removing branches connected to one side or switches from branches to open.
* - Removing slack bus from buses lost by the contingencies.
* - Adding branches connected to buses lost by contingencies in branches to open.
* This clean should be applied before conducting a {@link com.powsybl.openloadflow.sensi.ConnectivityBreakAnalysis}.
*/
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