-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor DC Sensitivity Analysis with Woodbury engine (#1001)
Signed-off-by: parvy <[email protected]> Co-authored-by: Hadrien <[email protected]>
- Loading branch information
1 parent
3c92bd6
commit 9a1830e
Showing
8 changed files
with
1,014 additions
and
784 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/main/java/com/powsybl/openloadflow/dc/AbstractWoodburyEngineInputReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Copyright (c) 2020, RTE (http://www.rte-france.com) | ||
* 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; | ||
|
||
import com.powsybl.loadflow.LoadFlowParameters; | ||
import com.powsybl.openloadflow.network.LfBus; | ||
import com.powsybl.openloadflow.network.LfHvdc; | ||
import com.powsybl.openloadflow.network.impl.Networks; | ||
import com.powsybl.openloadflow.network.util.ParticipatingElement; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
/** | ||
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>} | ||
* @author Gaël Macherel {@literal <[email protected]>} | ||
*/ | ||
public abstract class AbstractWoodburyEngineInputReader implements WoodburyEngineInputReader { | ||
|
||
/** | ||
* @return True if the disabled buses change the slack distribution. | ||
*/ | ||
protected boolean hasRhsChangedDueToDisabledSlackBus(LoadFlowParameters lfParameters, Set<LfBus> disabledBuses, List<ParticipatingElement> participatingElements) { | ||
return lfParameters.isDistributedSlack() && participatingElements.stream().anyMatch(element -> disabledBuses.contains(element.getLfBus())); | ||
} | ||
|
||
protected void processHvdcLinesWithDisconnection(DcLoadFlowContext loadFlowContext, Set<LfBus> disabledBuses, ConnectivityBreakAnalysis.ConnectivityAnalysisResult connectivityAnalysisResult) { | ||
for (LfHvdc hvdc : loadFlowContext.getNetwork().getHvdcs()) { | ||
if (Networks.isIsolatedBusForHvdc(hvdc.getBus1(), disabledBuses) ^ Networks.isIsolatedBusForHvdc(hvdc.getBus2(), disabledBuses)) { | ||
connectivityAnalysisResult.getContingencies().forEach(contingency -> { | ||
contingency.getGeneratorIdsToLose().add(hvdc.getConverterStation1().getId()); | ||
contingency.getGeneratorIdsToLose().add(hvdc.getConverterStation2().getId()); | ||
}); | ||
} | ||
} | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
src/main/java/com/powsybl/openloadflow/dc/ComputedContingencyElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/** | ||
* Copyright (c) 2020, RTE (http://www.rte-france.com) | ||
* 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; | ||
|
||
import com.powsybl.contingency.ContingencyElement; | ||
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; | ||
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 <[email protected]>} | ||
*/ | ||
public final class ComputedContingencyElement { | ||
|
||
private int contingencyIndex = -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 alphaForPostContingencyState = Double.NaN; | ||
private final ContingencyElement element; | ||
private final LfBranch lfBranch; | ||
private final ClosedBranchSide1DcFlowEquationTerm branchEquation; | ||
|
||
public ComputedContingencyElement(final ContingencyElement element, LfNetwork lfNetwork, EquationSystem<DcVariableType, DcEquationType> equationSystem) { | ||
this.element = element; | ||
lfBranch = lfNetwork.getBranchById(element.getId()); | ||
branchEquation = equationSystem.getEquationTerm(ElementType.BRANCH, lfBranch.getNum(), ClosedBranchSide1DcFlowEquationTerm.class); | ||
} | ||
|
||
public int getContingencyIndex() { | ||
return contingencyIndex; | ||
} | ||
|
||
public void setContingencyIndex(final int index) { | ||
this.contingencyIndex = index; | ||
} | ||
|
||
public int getLocalIndex() { | ||
return localIndex; | ||
} | ||
|
||
public void setLocalIndex(final int index) { | ||
this.localIndex = index; | ||
} | ||
|
||
public double getAlphaForPostContingencyState() { | ||
return alphaForPostContingencyState; | ||
} | ||
|
||
public void setAlphaForPostContingencyState(final double alpha) { | ||
this.alphaForPostContingencyState = alpha; | ||
} | ||
|
||
public ContingencyElement getElement() { | ||
return element; | ||
} | ||
|
||
public LfBranch getLfBranch() { | ||
return lfBranch; | ||
} | ||
|
||
public ClosedBranchSide1DcFlowEquationTerm getLfBranchEquation() { | ||
return branchEquation; | ||
} | ||
|
||
public static void setContingencyIndexes(Collection<ComputedContingencyElement> elements) { | ||
int index = 0; | ||
for (ComputedContingencyElement element : elements) { | ||
element.setContingencyIndex(index++); | ||
} | ||
} | ||
|
||
public static void setLocalIndexes(Collection<ComputedContingencyElement> elements) { | ||
int index = 0; | ||
for (ComputedContingencyElement element : elements) { | ||
element.setLocalIndex(index++); | ||
} | ||
} | ||
|
||
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); | ||
} | ||
} |
Oops, something went wrong.