Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "No such edge in graph" exception #534

Merged
merged 12 commits into from
May 18, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,8 @@ private static void createTransformersVoltageControls(LfNetwork lfNetwork, boole
}
}

private static void createSwitches(List<Switch> switches, LfNetwork lfNetwork, List<LfNetworkLoaderPostProcessor> postProcessors) {
private static void createSwitches(List<Switch> switches, LfNetwork lfNetwork, List<LfNetworkLoaderPostProcessor> postProcessors,
LfNetworkLoadingReport report) {
if (switches != null) {
for (Switch sw : switches) {
VoltageLevel vl = sw.getVoltageLevel();
Expand All @@ -422,7 +423,7 @@ private static void createSwitches(List<Switch> switches, LfNetwork lfNetwork, L
LfBus lfBus1 = lfNetwork.getBusById(bus1.getId());
LfBus lfBus2 = lfNetwork.getBusById(bus2.getId());
LfSwitch lfSwitch = new LfSwitch(lfNetwork, lfBus1, lfBus2, sw);
lfNetwork.addBranch(lfSwitch);
addBranch(lfNetwork, lfSwitch, report);
postProcessors.forEach(pp -> pp.onBranchAdded(sw, lfSwitch));
}
}
Expand Down Expand Up @@ -721,7 +722,7 @@ private static LfNetwork create(int numCC, int numSC, List<Bus> buses, List<Swit
}

if (parameters.isBreakers()) {
createSwitches(switches, lfNetwork, postProcessors);
createSwitches(switches, lfNetwork, postProcessors, report);
}

if (!parameters.isDc()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
import com.powsybl.iidm.network.TopologyKind;
import com.powsybl.iidm.network.VoltageLevel;

public class NodeBreakerNetworkFactory extends AbstractLoadFlowNetworkFactory {
public final class NodeBreakerNetworkFactory {

private NodeBreakerNetworkFactory() {
}

/**
* <pre>
* G
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/**
* Copyright (c) 2022, 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/.
*/
package com.powsybl.openloadflow.network;

import com.powsybl.iidm.network.*;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public final class SwitchLoopIssueNetworkFactory {

private SwitchLoopIssueNetworkFactory() {
}

/**
* LD(1)
* |
* ----------------------- BBS1(0) VL1
* | |(2)
* BR5 BR2
* | |
* | (3) |
* | L1 |
* | (2) |
* | | L2
* ------------ |
* | | |
* D2 | |
* |(3) | |(1) VL2
* BR1 | BR3
* | | |
* BBS2(0)---------------BR4-------- BBS3(5)
* |
* G(4)
*/
public static Network create() {
Network network = Network.create("test", "test");
Substation s = network.newSubstation()
.setId("S")
.add();
VoltageLevel vl1 = s.newVoltageLevel()
.setId("VL1")
.setNominalV(400)
.setTopologyKind(TopologyKind.NODE_BREAKER)
.add();
VoltageLevel vl2 = s.newVoltageLevel()
.setId("VL2")
.setNominalV(400)
.setTopologyKind(TopologyKind.NODE_BREAKER)
.add();
vl1.getNodeBreakerView().newBusbarSection()
.setId("BBS1")
.setNode(0)
.add();
vl2.getNodeBreakerView().newBusbarSection()
.setId("BBS2")
.setNode(0)
.add();
vl2.getNodeBreakerView().newBusbarSection()
.setId("BBS3")
.setNode(5)
.add();
vl1.newLoad()
.setId("LD")
.setNode(1)
.setP0(600.0)
.setQ0(200.0)
.add();
vl2.newGenerator()
.setId("G")
.setNode(4)
.setMinP(-999.99)
.setMaxP(999.99)
.setVoltageRegulatorOn(true)
.setTargetV(398)
.setTargetP(600)
.setTargetQ(300)
.add();
vl2.getNodeBreakerView().newInternalConnection()
.setNode1(4)
.setNode2(5)
.add();
vl2.getNodeBreakerView().newInternalConnection()
.setNode1(0)
.setNode2(2)
.add();
vl2.getNodeBreakerView().newBreaker()
.setId("BR1")
.setNode1(0)
.setNode2(3)
.setRetained(true)
.add();
vl2.getNodeBreakerView().newDisconnector()
.setId("D2")
.setNode1(3)
.setNode2(2)
.setRetained(false)
.add();
vl2.getNodeBreakerView().newBreaker()
.setId("BR3")
.setNode1(5)
.setNode2(1)
.setRetained(true)
.add();
vl2.getNodeBreakerView().newBreaker()
.setId("BR4")
.setNode1(0)
.setNode2(5)
.setRetained(true)
.add();
vl1.getNodeBreakerView().newBreaker()
.setId("BR5")
.setNode1(0)
.setNode2(3)
.setRetained(true)
.add();
vl1.getNodeBreakerView().newInternalConnection()
.setNode1(0)
.setNode2(1)
.add();
vl1.getNodeBreakerView().newBreaker()
.setId("BR2")
.setNode1(0)
.setNode2(2)
.setRetained(false)
.add();
network.newLine()
.setId("L1")
.setVoltageLevel1("VL1")
.setNode1(3)
.setVoltageLevel2("VL2")
.setNode2(2)
.setR(3.0)
.setX(33.0)
.setG1(0.0)
.setB1(386E-6 / 2)
.setG2(0.0)
.setB2(386E-6 / 2)
.add();
network.newLine()
.setId("L2")
.setVoltageLevel1("VL1")
.setNode1(2)
.setVoltageLevel2("VL2")
.setNode2(1)
.setR(3.0)
.setX(33.0)
.setG1(0.0)
.setB1(386E-6 / 2)
.setG2(0.0)
.setB2(386E-6 / 2)
.add();
return network;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1378,4 +1378,23 @@ void testSwitchContingencyNotFound() {
assertTrue(e.getCause() instanceof PowsyblException);
assertEquals("Switch 'X' not found in the network", e.getCause().getMessage());
}

@Test
void testSwitchLoopIssue() {
Network network = SwitchLoopIssueNetworkFactory.create();

List<Contingency> contingencies = List.of(Contingency.line("L1"));

List<StateMonitor> monitors = createAllBranchesMonitors(network);

var result = runSecurityAnalysis(network, contingencies, monitors);

PreContingencyResult preContingencyResult = result.getPreContingencyResult();
assertEquals(-299.977, preContingencyResult.getPreContingencyBranchResult("L2").getP1(), LoadFlowAssert.DELTA_POWER);
assertEquals(301.862, preContingencyResult.getPreContingencyBranchResult("L2").getP2(), LoadFlowAssert.DELTA_POWER);

PostContingencyResult postContingencyResult = getPostContingencyResult(result, "L1");
assertEquals(-599.882, postContingencyResult.getBranchResult("L2").getP1(), LoadFlowAssert.DELTA_POWER);
assertEquals(608.214, postContingencyResult.getBranchResult("L2").getP2(), LoadFlowAssert.DELTA_POWER);
}
}