Skip to content

Commit a59a0ec

Browse files
Merge branch 'main' into unsupported-limit-reduction
2 parents 4d64937 + 0513d2f commit a59a0ec

File tree

51 files changed

+1635
-752
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1635
-752
lines changed

src/main/java/com/powsybl/openloadflow/AcLoadFlowFromCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private List<AcLoadFlowContext> initContexts(NetworkCache.Entry entry) {
9595

9696
// Because of caching, we only need to switch back to working variant but not to remove the variant, thus
9797
// WorkingVariantReverter is used instead of DefaultVariantCleaner
98-
try (LfNetworkList lfNetworkList = Networks.load(network, acParameters.getNetworkParameters(), topoConfig,
98+
try (LfNetworkList lfNetworkList = Networks.loadWithReconnectableElements(network, topoConfig, acParameters.getNetworkParameters(),
9999
LfNetworkList.WorkingVariantReverter::new, reportNode)) {
100100
contexts = lfNetworkList.getList()
101101
.stream()

src/main/java/com/powsybl/openloadflow/OpenLoadFlowProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private LoadFlowResult runAc(Network network, LoadFlowParameters parameters, Ope
139139
results = new AcLoadFlowFromCache(network, parameters, parametersExt, acParameters, reportNode)
140140
.run();
141141
} else {
142-
try (LfNetworkList lfNetworkList = Networks.load(network, acParameters.getNetworkParameters(), new LfTopoConfig(), reportNode)) {
142+
try (LfNetworkList lfNetworkList = Networks.loadWithReconnectableElements(network, new LfTopoConfig(), acParameters.getNetworkParameters(), reportNode)) {
143143
results = AcloadFlowEngine.run(lfNetworkList.getList(), acParameters);
144144
}
145145
}

src/main/java/com/powsybl/openloadflow/dc/equations/AbstractClosedBranchDcFlowEquationTerm.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public double calculateSensi(DenseMatrix dx, int column) {
9797
double dph1 = dx.get(ph1Var.getRow(), column);
9898
double dph2 = dx.get(ph2Var.getRow(), column);
9999
double da1 = a1Var != null ? dx.get(a1Var.getRow(), column) : 0;
100-
// - eval(0,0,0) to have an exact epression and remove the constant term of the affine function (wich is 0 in practe because A2 = 0)
100+
// - eval(0,0,0) to have an exact expression and remove the constant term of the affine function (which is 0 in practice because A2 = 0)
101101
return eval(dph1, dph2, da1) - eval(0, 0, 0);
102102
}
103103

src/main/java/com/powsybl/openloadflow/dc/fastdc/AbstractComputedElement.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import com.powsybl.openloadflow.dc.equations.ClosedBranchSide1DcFlowEquationTerm;
1111
import com.powsybl.openloadflow.network.LfBranch;
1212

13+
import java.util.Objects;
14+
1315
/**
1416
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
1517
* @author Gaël Macherel {@literal <gael.macherel@artelys.com>}
@@ -22,8 +24,8 @@ abstract class AbstractComputedElement {
2224
private final ClosedBranchSide1DcFlowEquationTerm branchEquation;
2325

2426
protected AbstractComputedElement(LfBranch lfBranch, ClosedBranchSide1DcFlowEquationTerm branchEquation) {
25-
this.lfBranch = lfBranch;
26-
this.branchEquation = branchEquation;
27+
this.lfBranch = Objects.requireNonNull(lfBranch);
28+
this.branchEquation = Objects.requireNonNull(branchEquation);
2729
}
2830

2931
public int getComputedElementIndex() {

src/main/java/com/powsybl/openloadflow/dc/fastdc/ComputedElement.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
*/
88
package com.powsybl.openloadflow.dc.fastdc;
99

10+
import com.powsybl.action.PhaseTapChangerTapPositionAction;
11+
import com.powsybl.action.SwitchAction;
12+
import com.powsybl.action.TerminalsConnectionAction;
1013
import com.powsybl.commons.PowsyblException;
1114
import com.powsybl.math.matrix.DenseMatrix;
1215
import com.powsybl.math.matrix.Matrix;
@@ -19,19 +22,29 @@
1922
import com.powsybl.openloadflow.graph.GraphConnectivity;
2023
import com.powsybl.openloadflow.network.LfBranch;
2124
import com.powsybl.openloadflow.network.LfBus;
25+
import com.powsybl.openloadflow.network.action.AbstractLfBranchAction;
26+
import com.powsybl.openloadflow.network.action.AbstractLfTapChangerAction;
27+
import com.powsybl.openloadflow.network.action.LfAction;
28+
import org.slf4j.Logger;
29+
import org.slf4j.LoggerFactory;
2230

2331
import java.util.Collection;
2432
import java.util.HashMap;
33+
import java.util.LinkedHashMap;
2534
import java.util.Map;
2635
import java.util.Objects;
2736
import java.util.concurrent.atomic.AtomicInteger;
37+
import java.util.stream.Collectors;
38+
import java.util.stream.Stream;
2839

2940
/**
3041
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
3142
* @author Gaël Macherel {@literal <gael.macherel@artelys.com>}
3243
*/
3344
public interface ComputedElement {
3445

46+
Logger LOGGER = LoggerFactory.getLogger(ComputedElement.class);
47+
3548
int getComputedElementIndex();
3649

3750
void setComputedElementIndex(final int index);
@@ -119,4 +132,38 @@ static DenseMatrix calculateElementsStates(DcLoadFlowContext loadFlowContext, Co
119132
loadFlowContext.getJacobianMatrix().solveTransposed(elementsStates);
120133
return elementsStates;
121134
}
135+
136+
static Map<LfAction, ComputedElement> createActionElementsIndexByLfAction(Map<String, LfAction> lfActionById, EquationSystem<DcVariableType, DcEquationType> equationSystem) {
137+
Map<LfAction, ComputedElement> computedElements = lfActionById.values().stream()
138+
.flatMap(lfAction -> {
139+
ComputedElement element = switch (lfAction.getType()) {
140+
case SwitchAction.NAME, TerminalsConnectionAction.NAME -> {
141+
AbstractLfBranchAction<?> lfBranchAction = (AbstractLfBranchAction<?>) lfAction;
142+
if (lfBranchAction.getEnabledBranch() != null) {
143+
yield ComputedSwitchBranchElement.create(lfBranchAction.getEnabledBranch(), true, equationSystem);
144+
} else if (lfBranchAction.getDisabledBranch() != null) {
145+
yield ComputedSwitchBranchElement.create(lfBranchAction.getDisabledBranch(), false, equationSystem);
146+
}
147+
yield null;
148+
}
149+
case PhaseTapChangerTapPositionAction.NAME ->
150+
new ComputedTapPositionChangeElement(((AbstractLfTapChangerAction<?>) lfAction).getChange(), equationSystem);
151+
default -> throw new IllegalStateException("Only tap position change and branch enabling/disabling are supported in WoodburyDcSecurityAnalysis");
152+
};
153+
if (element == null) {
154+
return Stream.empty();
155+
}
156+
return Stream.of(Map.entry(lfAction, element));
157+
})
158+
.filter(e -> e.getValue().getLfBranchEquation() != null)
159+
.collect(Collectors.toMap(
160+
Map.Entry::getKey,
161+
Map.Entry::getValue,
162+
(existing, replacement) -> existing,
163+
LinkedHashMap::new
164+
));
165+
ComputedElement.setComputedElementIndexes(computedElements.values());
166+
return computedElements;
167+
}
168+
122169
}

src/main/java/com/powsybl/openloadflow/dc/fastdc/ComputedSwitchBranchElement.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,24 @@
1616
import com.powsybl.openloadflow.network.LfBranch;
1717
import com.powsybl.openloadflow.network.LfBus;
1818

19+
import java.util.Objects;
20+
1921
/**
2022
* @author Pierre Arvy {@literal <pierre.arvy@artelys.com>}
2123
*/
2224
public final class ComputedSwitchBranchElement extends AbstractComputedElement implements ComputedElement {
2325

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

26-
public ComputedSwitchBranchElement(LfBranch lfBranch, boolean enabled, EquationSystem<DcVariableType, DcEquationType> equationSystem) {
27-
super(lfBranch, equationSystem.getEquationTerm(ElementType.BRANCH, lfBranch.getNum(), ClosedBranchSide1DcFlowEquationTerm.class));
28+
public static ComputedSwitchBranchElement create(LfBranch lfBranch, boolean enabled, EquationSystem<DcVariableType, DcEquationType> equationSystem) {
29+
Objects.requireNonNull(lfBranch);
30+
Objects.requireNonNull(equationSystem);
31+
ClosedBranchSide1DcFlowEquationTerm branchEquation = equationSystem.getEquationTerm(ElementType.BRANCH, lfBranch.getNum(), ClosedBranchSide1DcFlowEquationTerm.class);
32+
return new ComputedSwitchBranchElement(lfBranch, enabled, branchEquation);
33+
}
34+
35+
private ComputedSwitchBranchElement(LfBranch lfBranch, boolean enabled, ClosedBranchSide1DcFlowEquationTerm branchEquation) {
36+
super(lfBranch, branchEquation);
2837
this.enabled = enabled;
2938
}
3039

0 commit comments

Comments
 (0)