Skip to content

Commit

Permalink
Refactor DC Sensitivity Analysis with Woodbury engine (#1001)
Browse files Browse the repository at this point in the history
Signed-off-by: parvy <[email protected]>
Co-authored-by: Hadrien <[email protected]>
  • Loading branch information
p-arvy and Hadrien-Godard authored Jul 3, 2024
1 parent 3c92bd6 commit 9a1830e
Show file tree
Hide file tree
Showing 8 changed files with 1,014 additions and 784 deletions.
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());
});
}
}
}
}
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);
}
}
Loading

0 comments on commit 9a1830e

Please sign in to comment.