Skip to content

Add switch actions in Fast DC Security Analysis #1153

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

Merged
merged 76 commits into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
72b5783
Add TUs to be verified by future developments
p-arvy Dec 13, 2024
ff34773
Add ComputedSwitchBranchElement and relative calculation in WoodburyE…
p-arvy Dec 13, 2024
534b2d3
Refactor calculation of rhs/matrix values in WoodburyEngine
p-arvy Dec 13, 2024
99ae55f
Add case with transformer lost as an action, and non null alpha on cu…
p-arvy Dec 13, 2024
e36189f
Merge branch 'refs/heads/main' into switching-actions-in-fast-dc-sa
p-arvy Dec 31, 2024
8f52842
Merge branch 'refs/heads/main' into switching-actions-in-fast-dc-sa
p-arvy Feb 17, 2025
096a892
wip
p-arvy Feb 17, 2025
567fd60
Add cases with connectivity break
p-arvy Feb 17, 2025
bf95a91
clean
p-arvy Feb 17, 2025
c04a621
Clean
p-arvy Feb 17, 2025
fc82b3d
Clean
p-arvy Feb 18, 2025
bc9123d
Clean
p-arvy Feb 18, 2025
18ecb1f
Refactor connectivity break analysis to add connectivity loss impact
p-arvy Feb 18, 2025
6ed4611
Clean
p-arvy Feb 18, 2025
07046ea
Add TU
p-arvy Feb 18, 2025
c61317f
Clean
p-arvy Feb 18, 2025
8f3207d
Clean
p-arvy Feb 18, 2025
627b986
Merge branch 'refs/heads/main' into switching-actions-in-fast-dc-sa
p-arvy Feb 18, 2025
b71ba78
Update
p-arvy Feb 18, 2025
a9a5c1f
Clean
p-arvy Feb 18, 2025
15b5bd9
Update TU
p-arvy Feb 25, 2025
a9328cc
Merge branch 'refs/heads/main' into connectivity-loss-in-connectivity…
p-arvy Feb 25, 2025
ac766a8
Merge branch 'refs/heads/main' into connectivity-loss-in-connectivity…
p-arvy Mar 3, 2025
994f6a2
Small clean
p-arvy Mar 3, 2025
6cfcf3f
Update TU
p-arvy Mar 3, 2025
87938b6
Clean
Hadrien-Godard Mar 4, 2025
a5a862a
Refacto
Hadrien-Godard Mar 5, 2025
e4dc7c4
Add NO_DISABLED_ELEMENTS
p-arvy Mar 7, 2025
cad785b
Merge remote-tracking branch 'origin/main' into connectivity-loss-in-…
Hadrien-Godard Mar 10, 2025
31ac8e3
Remove ok field in ContingencyConnectivityLossImpact
Hadrien-Godard Mar 10, 2025
76de054
Proposal to reduce arguments in addPostContingencyAndOperatorStrategy…
Hadrien-Godard Mar 10, 2025
eb720dc
Add test to ensure proper behavior when HVDC (not in AC emulation) ha…
vidaldid-rte Mar 12, 2025
582a4f3
Sonar believes public test is bad. And some people pay attention to t…
vidaldid-rte Mar 12, 2025
32e2b81
fix comment
vidaldid-rte Mar 12, 2025
f87c848
Merge branch 'refs/heads/main' into connectivity-loss-in-connectivity…
p-arvy Mar 17, 2025
bbdf051
Merge remote-tracking branch 'origin/connectivity-loss-in-connectivit…
p-arvy Mar 17, 2025
711c4cf
Refactor records in WoodburyDcSecurityAnalysis
p-arvy Mar 18, 2025
eef4e96
Very small clean
p-arvy Mar 18, 2025
4f92d7c
Merge branch 'refs/heads/main' into connectivity-loss-in-connectivity…
p-arvy Mar 18, 2025
7014908
Merge branch 'main' into connectivity-loss-in-connectivity-break-anal…
Hadrien-Godard Mar 25, 2025
c50c5fb
Merge branch 'refs/heads/main' into connectivity-loss-in-connectivity…
p-arvy Mar 28, 2025
80e18b5
Update TUs to include slow mode
p-arvy Mar 28, 2025
62700ce
Merge branch 'refs/heads/main' into switching-actions-in-fast-dc-sa
p-arvy Apr 2, 2025
7c46bb3
Merge branch 'refs/heads/connectivity-loss-in-connectivity-break-anal…
p-arvy Apr 2, 2025
8542936
wip
p-arvy Apr 2, 2025
5c45b84
wip
p-arvy Apr 2, 2025
9808667
Clean
p-arvy Apr 2, 2025
d9ba68d
Merge branch 'refs/heads/main' into connectivity-loss-in-connectivity…
p-arvy Apr 2, 2025
2d234d5
Merge branch 'refs/heads/main' into connectivity-loss-in-connectivity…
p-arvy Apr 4, 2025
6857279
clean
p-arvy Apr 4, 2025
6ce81ca
clean
p-arvy Apr 4, 2025
2d2a7f0
Merge branch 'refs/heads/connectivity-loss-in-connectivity-break-anal…
p-arvy Apr 4, 2025
f583d0e
Use post contingency and operator strategy connectivity analysis resu…
p-arvy Apr 4, 2025
57a1cd7
wip
p-arvy Apr 4, 2025
f17dd20
wip
p-arvy Apr 4, 2025
bdfbee8
clean
p-arvy Apr 4, 2025
7080594
wip
p-arvy Apr 4, 2025
75a0e25
Update TUs
p-arvy Apr 7, 2025
52b9722
Refactor Woodbury Engine
p-arvy Apr 7, 2025
63c7846
Merge branch 'refs/heads/main' into switching-actions-in-fast-dc-sa
p-arvy Apr 7, 2025
b4a1665
wip
p-arvy Apr 7, 2025
2598ed2
Add comments
p-arvy Apr 7, 2025
2ed6e48
Merge branch 'main' into switching-actions-in-fast-dc-sa
Hadrien-Godard Apr 10, 2025
8caa93f
Minor typos
Hadrien-Godard Apr 10, 2025
04b1f1b
Add comments
p-arvy Apr 11, 2025
1091790
Merge branch 'main' into switching-actions-in-fast-dc-sa
Hadrien-Godard Apr 11, 2025
e5bc7c5
Merge branch 'refs/heads/main' into switching-actions-in-fast-dc-sa
p-arvy Apr 11, 2025
f733a43
Index columns of action states by branches
p-arvy Apr 11, 2025
c2ba64f
Adjust some comments
Hadrien-Godard Apr 15, 2025
cf3f846
Merge branch 'main' into switching-actions-in-fast-dc-sa
Hadrien-Godard Apr 24, 2025
7c8d3cb
Merge remote-tracking branch 'origin/main' into switching-actions-in-…
Hadrien-Godard May 7, 2025
2df9e51
Some improvments thanks to review
Hadrien-Godard May 7, 2025
e9defae
Use computeIfAbsent in setComputedElementIndexes
Hadrien-Godard May 12, 2025
061f9bf
Merge remote-tracking branch 'origin/main' into switching-actions-in-…
Hadrien-Godard May 20, 2025
9e8be38
Merge remote-tracking branch 'origin/main' into switching-actions-in-…
Hadrien-Godard May 20, 2025
c16048e
Refacto
Hadrien-Godard May 20, 2025
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
2 changes: 1 addition & 1 deletion docs/security/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Please note that fast mode has a few limitations:
it is considered completely disabled, and no results are reported for this branch.
- AC emulation of HVDC lines is disabled, as it is not yet supported.
Instead, the [active power setpoint](../loadflow/loadflow.md#computing-hvdc-power-flow) mode is used to control the active power flow through these lines.
- Only PST remedial actions are supported for now.
- Only PST and topological (except for transformer closing) remedial actions are supported for now.
- Slack relocation following the application of a contingency is not supported.
As a result, security analysis is carried out only in slack component, and not necessarily in the largest one.
- Customizing the way contingency imbalances are compensated via `contingencyActivePowerLossDistribution` parameter is not supported.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,24 @@
import com.powsybl.openloadflow.dc.equations.DcVariableType;
import com.powsybl.openloadflow.equations.Equation;
import com.powsybl.openloadflow.equations.EquationSystem;
import com.powsybl.openloadflow.graph.GraphConnectivity;
import com.powsybl.openloadflow.network.LfBranch;
import com.powsybl.openloadflow.network.LfBus;

import java.util.Collection;
import java.util.*;

/**
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
* @author Gaël Macherel {@literal <gael.macherel@artelys.com>}
*/
public class ComputedElement {
public abstract class AbstractComputedElement {
private int computedElementIndex = -1; // index of the element in the rhs for +1-1
private int localIndex = -1; // local index of the element : index of the element in the matrix used in the setAlphas method
private double alphaForWoodburyComputation = Double.NaN;
private final LfBranch lfBranch;
private final ClosedBranchSide1DcFlowEquationTerm branchEquation;

public ComputedElement(LfBranch lfBranch, ClosedBranchSide1DcFlowEquationTerm branchEquation) {
protected AbstractComputedElement(LfBranch lfBranch, ClosedBranchSide1DcFlowEquationTerm branchEquation) {
this.lfBranch = lfBranch;
this.branchEquation = branchEquation;
}
Expand Down Expand Up @@ -69,25 +70,39 @@ public ClosedBranchSide1DcFlowEquationTerm getLfBranchEquation() {
return branchEquation;
}

public static void setComputedElementIndexes(Collection<? extends ComputedElement> elements) {
/**
* Set the indexes of the computed elements in the +1-1 rhs, used in Woodbury calculations.
* The indexes depend on the number of distinct branches affected by the elements.
* Those affecting the same branch share the same +1-1 rhs column.
*/
public static void setComputedElementIndexes(Collection<? extends AbstractComputedElement> elements) {
int index = 0;
for (ComputedElement element : elements) {
element.setComputedElementIndex(index++);
Map<LfBranch, Integer> branchesToRhsIndex = new HashMap<>();
for (AbstractComputedElement element : elements) {
LfBranch elementLfBranch = element.getLfBranch();
Integer elementIndex = branchesToRhsIndex.get(elementLfBranch);

if (elementIndex == null) {
branchesToRhsIndex.put(elementLfBranch, index);
element.setComputedElementIndex(index++);
} else {
element.setComputedElementIndex(elementIndex);
}
}
}

public static void setLocalIndexes(Collection<? extends ComputedElement> elements) {
public static void setLocalIndexes(Collection<? extends AbstractComputedElement> elements) {
int index = 0;
for (ComputedElement element : elements) {
for (AbstractComputedElement element : elements) {
element.setLocalIndex(index++);
}
}

/**
* Fills the right hand side with +1/-1 to model a branch contingency or action.
*/
private static void fillRhs(EquationSystem<DcVariableType, DcEquationType> equationSystem, Collection<? extends ComputedElement> computedElements, Matrix rhs) {
for (ComputedElement element : computedElements) {
private static void fillRhs(EquationSystem<DcVariableType, DcEquationType> equationSystem, Collection<? extends AbstractComputedElement> computedElements, Matrix rhs) {
for (AbstractComputedElement element : computedElements) {
LfBranch lfBranch = element.getLfBranch();
if (lfBranch.getBus1() == null || lfBranch.getBus2() == null) {
continue;
Expand All @@ -109,23 +124,27 @@ private static void fillRhs(EquationSystem<DcVariableType, DcEquationType> equat
}
}

public static DenseMatrix initRhs(EquationSystem<DcVariableType, DcEquationType> equationSystem, Collection<? extends ComputedElement> elements) {
public static DenseMatrix initRhs(EquationSystem<DcVariableType, DcEquationType> equationSystem, Collection<? extends AbstractComputedElement> elements) {
// the number of columns of the rhs equals the number of distinct branches affected by the computed elements
// those affecting the same branch share the same column
int columnCount = (int) elements.stream().map(AbstractComputedElement::getLfBranch).filter(Objects::nonNull).distinct().count();
// otherwise, defining the rhs matrix will result in integer overflow
int equationCount = equationSystem.getIndex().getSortedEquationsToSolve().size();
int maxElements = Integer.MAX_VALUE / (equationCount * Double.BYTES);
if (elements.size() > maxElements) {
throw new PowsyblException("Too many elements " + elements.size()
if (columnCount > maxElements) {
throw new PowsyblException("Too many elements " + columnCount
+ ", maximum is " + maxElements + " for a system with " + equationCount + " equations");
}

DenseMatrix rhs = new DenseMatrix(equationCount, elements.size());
DenseMatrix rhs = new DenseMatrix(equationCount, columnCount);
fillRhs(equationSystem, elements, rhs);
return rhs;
}

public static DenseMatrix calculateElementsStates(DcLoadFlowContext loadFlowContext, Collection<? extends ComputedElement> computedElements) {
public static DenseMatrix calculateElementsStates(DcLoadFlowContext loadFlowContext, Collection<? extends AbstractComputedElement> computedElements) {
DenseMatrix elementsStates = initRhs(loadFlowContext.getEquationSystem(), computedElements); // rhs with +1 -1 on computed elements
loadFlowContext.getJacobianMatrix().solveTransposed(elementsStates);
return elementsStates;
}

public abstract void applyToConnectivity(GraphConnectivity<LfBus, LfBranch> connectivity);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
import com.powsybl.openloadflow.network.LfBus;
import com.powsybl.openloadflow.network.LfNetwork;

import java.util.Collection;

/**
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
* @author Gaël Macherel {@literal <gael.macherel@artelys.com>}
*/
public final class ComputedContingencyElement extends ComputedElement {
public final class ComputedContingencyElement extends AbstractComputedElement {

private final ContingencyElement element;

Expand All @@ -38,13 +36,11 @@ public ContingencyElement getElement() {
return element;
}

public 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);
@Override
public void applyToConnectivity(GraphConnectivity<LfBus, LfBranch> connectivity) {
LfBranch lfBranch = getLfBranch();
if (lfBranch.getBus1() != null && lfBranch.getBus2() != null) {
connectivity.removeEdge(lfBranch);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Copyright (c) 2024, Coreso SA (https://www.coreso.eu/) and TSCNET Services GmbH (https://www.tscnet.eu/)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.openloadflow.dc.fastdc;

import com.powsybl.openloadflow.dc.equations.ClosedBranchSide1DcFlowEquationTerm;
import com.powsybl.openloadflow.dc.equations.DcEquationType;
import com.powsybl.openloadflow.dc.equations.DcVariableType;
import com.powsybl.openloadflow.equations.EquationSystem;
import com.powsybl.openloadflow.graph.GraphConnectivity;
import com.powsybl.openloadflow.network.ElementType;
import com.powsybl.openloadflow.network.LfBranch;
import com.powsybl.openloadflow.network.LfBus;

/**
* @author Pierre Arvy {@literal <pierre.arvy@artelys.com>}
*/
public final class ComputedSwitchBranchElement extends AbstractComputedElement {

private final boolean enabled; // indicates whether the action opens or closes the branch

public ComputedSwitchBranchElement(LfBranch lfBranch, boolean enabled, EquationSystem<DcVariableType, DcEquationType> equationSystem) {
super(lfBranch, equationSystem.getEquationTerm(ElementType.BRANCH, lfBranch.getNum(), ClosedBranchSide1DcFlowEquationTerm.class));
this.enabled = enabled;
}

public boolean isEnabled() {
return enabled;
}

public void applyToConnectivity(GraphConnectivity<LfBus, LfBranch> connectivity) {
LfBranch lfBranch = getLfBranch();
if (lfBranch.getBus1() != null && lfBranch.getBus2() != null) {
if (isEnabled()) {
connectivity.addEdge(lfBranch.getBus1(), lfBranch.getBus2(), lfBranch);
} else {
connectivity.removeEdge(lfBranch);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
import com.powsybl.openloadflow.dc.equations.DcEquationType;
import com.powsybl.openloadflow.dc.equations.DcVariableType;
import com.powsybl.openloadflow.equations.EquationSystem;
import com.powsybl.openloadflow.graph.GraphConnectivity;
import com.powsybl.openloadflow.network.ElementType;
import com.powsybl.openloadflow.network.LfBranch;
import com.powsybl.openloadflow.network.LfBus;
import com.powsybl.openloadflow.network.TapPositionChange;

/**
* @author Pierre Arvy {@literal <pierre.arvy@artelys.com>}
*/
public final class ComputedTapPositionChangeElement extends ComputedElement {
public final class ComputedTapPositionChangeElement extends AbstractComputedElement {

private final TapPositionChange tapPositionChange;

Expand All @@ -29,4 +32,9 @@ public ComputedTapPositionChangeElement(TapPositionChange tapPositionChange, Equ
public TapPositionChange getTapPositionChange() {
return tapPositionChange;
}

@Override
public void applyToConnectivity(GraphConnectivity<LfBus, LfBranch> connectivity) {
// nothing to do
}
}
Loading