Skip to content

Commit 9a1830e

Browse files
Refactor DC Sensitivity Analysis with Woodbury engine (#1001)
Signed-off-by: parvy <pierre.arvy@artelys.com> Co-authored-by: Hadrien <hadrien.godard@artelys.com>
1 parent 3c92bd6 commit 9a1830e

8 files changed

+1014
-784
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Copyright (c) 2020, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
* SPDX-License-Identifier: MPL-2.0
7+
*/
8+
package com.powsybl.openloadflow.dc;
9+
10+
import com.powsybl.loadflow.LoadFlowParameters;
11+
import com.powsybl.openloadflow.network.LfBus;
12+
import com.powsybl.openloadflow.network.LfHvdc;
13+
import com.powsybl.openloadflow.network.impl.Networks;
14+
import com.powsybl.openloadflow.network.util.ParticipatingElement;
15+
16+
import java.util.List;
17+
import java.util.Set;
18+
19+
/**
20+
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
21+
* @author Gaël Macherel {@literal <gael.macherel@artelys.com>}
22+
*/
23+
public abstract class AbstractWoodburyEngineInputReader implements WoodburyEngineInputReader {
24+
25+
/**
26+
* @return True if the disabled buses change the slack distribution.
27+
*/
28+
protected boolean hasRhsChangedDueToDisabledSlackBus(LoadFlowParameters lfParameters, Set<LfBus> disabledBuses, List<ParticipatingElement> participatingElements) {
29+
return lfParameters.isDistributedSlack() && participatingElements.stream().anyMatch(element -> disabledBuses.contains(element.getLfBus()));
30+
}
31+
32+
protected void processHvdcLinesWithDisconnection(DcLoadFlowContext loadFlowContext, Set<LfBus> disabledBuses, ConnectivityBreakAnalysis.ConnectivityAnalysisResult connectivityAnalysisResult) {
33+
for (LfHvdc hvdc : loadFlowContext.getNetwork().getHvdcs()) {
34+
if (Networks.isIsolatedBusForHvdc(hvdc.getBus1(), disabledBuses) ^ Networks.isIsolatedBusForHvdc(hvdc.getBus2(), disabledBuses)) {
35+
connectivityAnalysisResult.getContingencies().forEach(contingency -> {
36+
contingency.getGeneratorIdsToLose().add(hvdc.getConverterStation1().getId());
37+
contingency.getGeneratorIdsToLose().add(hvdc.getConverterStation2().getId());
38+
});
39+
}
40+
}
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
* Copyright (c) 2020, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
* SPDX-License-Identifier: MPL-2.0
7+
*/
8+
package com.powsybl.openloadflow.dc;
9+
10+
import com.powsybl.contingency.ContingencyElement;
11+
import com.powsybl.openloadflow.dc.equations.ClosedBranchSide1DcFlowEquationTerm;
12+
import com.powsybl.openloadflow.dc.equations.DcEquationType;
13+
import com.powsybl.openloadflow.dc.equations.DcVariableType;
14+
import com.powsybl.openloadflow.equations.EquationSystem;
15+
import com.powsybl.openloadflow.graph.GraphConnectivity;
16+
import com.powsybl.openloadflow.network.ElementType;
17+
import com.powsybl.openloadflow.network.LfBranch;
18+
import com.powsybl.openloadflow.network.LfBus;
19+
import com.powsybl.openloadflow.network.LfNetwork;
20+
21+
import java.util.Collection;
22+
23+
/**
24+
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
25+
* @author Gaël Macherel {@literal <gael.macherel@artelys.com>}
26+
*/
27+
public final class ComputedContingencyElement {
28+
29+
private int contingencyIndex = -1; // index of the element in the rhs for +1-1
30+
private int localIndex = -1; // local index of the element : index of the element in the matrix used in the setAlphas method
31+
private double alphaForPostContingencyState = Double.NaN;
32+
private final ContingencyElement element;
33+
private final LfBranch lfBranch;
34+
private final ClosedBranchSide1DcFlowEquationTerm branchEquation;
35+
36+
public ComputedContingencyElement(final ContingencyElement element, LfNetwork lfNetwork, EquationSystem<DcVariableType, DcEquationType> equationSystem) {
37+
this.element = element;
38+
lfBranch = lfNetwork.getBranchById(element.getId());
39+
branchEquation = equationSystem.getEquationTerm(ElementType.BRANCH, lfBranch.getNum(), ClosedBranchSide1DcFlowEquationTerm.class);
40+
}
41+
42+
public int getContingencyIndex() {
43+
return contingencyIndex;
44+
}
45+
46+
public void setContingencyIndex(final int index) {
47+
this.contingencyIndex = index;
48+
}
49+
50+
public int getLocalIndex() {
51+
return localIndex;
52+
}
53+
54+
public void setLocalIndex(final int index) {
55+
this.localIndex = index;
56+
}
57+
58+
public double getAlphaForPostContingencyState() {
59+
return alphaForPostContingencyState;
60+
}
61+
62+
public void setAlphaForPostContingencyState(final double alpha) {
63+
this.alphaForPostContingencyState = alpha;
64+
}
65+
66+
public ContingencyElement getElement() {
67+
return element;
68+
}
69+
70+
public LfBranch getLfBranch() {
71+
return lfBranch;
72+
}
73+
74+
public ClosedBranchSide1DcFlowEquationTerm getLfBranchEquation() {
75+
return branchEquation;
76+
}
77+
78+
public static void setContingencyIndexes(Collection<ComputedContingencyElement> elements) {
79+
int index = 0;
80+
for (ComputedContingencyElement element : elements) {
81+
element.setContingencyIndex(index++);
82+
}
83+
}
84+
85+
public static void setLocalIndexes(Collection<ComputedContingencyElement> elements) {
86+
int index = 0;
87+
for (ComputedContingencyElement element : elements) {
88+
element.setLocalIndex(index++);
89+
}
90+
}
91+
92+
static void applyToConnectivity(LfNetwork lfNetwork, GraphConnectivity<LfBus, LfBranch> connectivity, Collection<ComputedContingencyElement> breakingConnectivityElements) {
93+
breakingConnectivityElements.stream()
94+
.map(ComputedContingencyElement::getElement)
95+
.map(ContingencyElement::getId)
96+
.distinct()
97+
.map(lfNetwork::getBranchById)
98+
.filter(b -> b.getBus1() != null && b.getBus2() != null)
99+
.forEach(connectivity::removeEdge);
100+
}
101+
}

0 commit comments

Comments
 (0)