|
| 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