Skip to content

Commit

Permalink
Fix exception for connectable not found in Network Modification conne…
Browse files Browse the repository at this point in the history
…ction and disconnection (#3069)

Signed-off-by: Nicolas Rol <nicolas.rol@rte-france.com>
  • Loading branch information
rolnico authored and geofjamg committed Sep 18, 2024
1 parent f79a54d commit d15f6c4
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
package com.powsybl.action;

import com.powsybl.commons.PowsyblException;
import com.powsybl.commons.report.ReportNode;
import com.powsybl.computation.ComputationManager;
import com.powsybl.computation.local.LocalComputationManager;
import com.powsybl.iidm.modification.NetworkModification;
import com.powsybl.iidm.modification.topology.DefaultNamingStrategy;
import com.powsybl.iidm.modification.topology.NamingStrategy;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.extensions.HvdcAngleDroopActivePowerControl;
import com.powsybl.iidm.network.extensions.HvdcAngleDroopActivePowerControlAdder;
Expand Down Expand Up @@ -58,6 +63,28 @@ void terminalConnectionAction() {
assertFalse(branch.getTerminal(TwoSides.ONE).isConnected());
}

/**
* This action fails on tie-lines since they are not a connectable
*/
@Test
void terminalConnectionActionOnTieLineException() {
Network network = EurostagTutorialExample1Factory.createWithTieLine();

// Disconnection
TerminalsConnectionAction disconnectionAction = new TerminalsConnectionAction("id", "NHV1_NHV2_1", true);
NetworkModification disconnection = disconnectionAction.toModification();
NamingStrategy namingStrategy = new DefaultNamingStrategy();
ComputationManager computationManager = LocalComputationManager.getDefault();
PowsyblException disconnectionException = assertThrows(PowsyblException.class, () -> disconnection.apply(network, namingStrategy, true, computationManager, ReportNode.NO_OP));
assertEquals("Connectable 'NHV1_NHV2_1' not found", disconnectionException.getMessage());

// Connection
TerminalsConnectionAction connectionAction = new TerminalsConnectionAction("id", "NHV1_NHV2_1", false);
NetworkModification connection = connectionAction.toModification();
PowsyblException connectionException = assertThrows(PowsyblException.class, () -> connection.apply(network, namingStrategy, true, computationManager, ReportNode.NO_OP));
assertEquals("Connectable 'NHV1_NHV2_1' not found", connectionException.getMessage());
}

@Test
void dangingLineAction() {
Network network = EurostagTutorialExample1Factory.createWithTieLine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ public abstract class AbstractDisconnection extends AbstractNetworkModification
this.side = side;
}

public void applyModification(Network network, boolean isPlanned, ReportNode reportNode) {
public void applyModification(Network network, boolean isPlanned, boolean throwException, ReportNode reportNode) {
// Add the reportNode to the network reportNode context
network.getReportNodeContext().pushReportNode(reportNode);

// Get the connectable
Connectable<?> connectable = network.getConnectable(connectableId);
if (connectable == null) {
logOrThrow(throwException, "Connectable '" + connectableId + "' not found");
return;
}

// Disconnect the connectable
boolean hasBeenDisconnected;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public class ConnectableConnection extends AbstractNetworkModification {
public void apply(Network network, NamingStrategy namingStrategy, boolean throwException, ComputationManager computationManager, ReportNode reportNode) {
// Get the connectable
Connectable<?> connectable = network.getConnectable(connectableId);
if (connectable == null) {
logOrThrow(throwException, "Connectable '" + connectableId + "' not found");
return;
}

// Add the reportNode to the network reportNode context
network.getReportNodeContext().pushReportNode(reportNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public class PlannedDisconnection extends AbstractDisconnection {
@Override
public void apply(Network network, NamingStrategy namingStrategy, boolean throwException,
ComputationManager computationManager, ReportNode reportNode) {
applyModification(network, true, reportNode);
applyModification(network, true, throwException, reportNode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public class UnplannedDisconnection extends AbstractDisconnection {
@Override
public void apply(Network network, NamingStrategy namingStrategy, boolean throwException,
ComputationManager computationManager, ReportNode reportNode) {
applyModification(network, false, reportNode);
applyModification(network, false, throwException, reportNode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@
*/
package com.powsybl.iidm.modification;

import com.powsybl.commons.PowsyblException;
import com.powsybl.commons.report.ReportNode;
import com.powsybl.computation.ComputationManager;
import com.powsybl.computation.local.LocalComputationManager;
import com.powsybl.iidm.modification.topology.AbstractModificationTest;
import com.powsybl.iidm.modification.topology.DefaultNamingStrategy;
import com.powsybl.iidm.modification.topology.NamingStrategy;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.extensions.BusbarSectionPositionAdder;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.time.ZonedDateTime;

import static org.junit.jupiter.api.Assertions.*;

/**
* @author Nicolas Rol {@literal <nicolas.rol at rte-france.com>}
*/
Expand Down Expand Up @@ -404,4 +411,73 @@ void testConnectionNoConnection() throws IOException {
writeXmlTest(network, "/network-unplanned-disconnection-not-disconnected.xiidm");
testReportNode(reportNode, "/reportNode/connectable-not-connected.txt");
}


/**
* This network modification fails on tie-lines since they are not a connectable
*/
@Test
void testExceptions() {
Network network = createNetwork();

// Add tie line
DanglingLine nhv1xnode1 = network.getVoltageLevel("VL2").newDanglingLine()
.setId("NHV1_XNODE1")
.setP0(0.0)
.setQ0(0.0)
.setR(1.5)
.setX(20.0)
.setG(1E-6)
.setB(386E-6 / 2)
.setBus("bus2A")
.setPairingKey("XNODE1")
.add();
DanglingLine xnode1nhv2 = network.getVoltageLevel("VL3").newDanglingLine()
.setId("XNODE1_NHV2")
.setP0(0.0)
.setQ0(0.0)
.setR(1.5)
.setX(13.0)
.setG(2E-6)
.setB(386E-6 / 2)
.setBus("bus3A")
.setPairingKey("XNODE1")
.add();
TieLine tieLine = network.newTieLine()
.setId("NHV1_NHV2_1")
.setDanglingLine1(nhv1xnode1.getId())
.setDanglingLine2(xnode1nhv2.getId())
.add();

// Disconnection
assertTrue(tieLine.getDanglingLine1().getTerminal().isConnected());
assertTrue(tieLine.getDanglingLine2().getTerminal().isConnected());
UnplannedDisconnection disconnection = new UnplannedDisconnectionBuilder()
.withConnectableId("NHV1_NHV2_1")
.withFictitiousSwitchesOperable(false)
.build();
NamingStrategy namingStrategy = new DefaultNamingStrategy();
ComputationManager computationManager = LocalComputationManager.getDefault();
PowsyblException disconnectionException = assertThrows(PowsyblException.class, () -> disconnection.apply(network, namingStrategy, true, computationManager, ReportNode.NO_OP));
assertEquals("Connectable 'NHV1_NHV2_1' not found", disconnectionException.getMessage());
disconnection.apply(network);
assertTrue(tieLine.getDanglingLine1().getTerminal().isConnected());
assertTrue(tieLine.getDanglingLine2().getTerminal().isConnected());

// Connection
tieLine.getDanglingLine1().disconnect();
tieLine.getDanglingLine2().disconnect();
assertFalse(tieLine.getDanglingLine1().getTerminal().isConnected());
assertFalse(tieLine.getDanglingLine2().getTerminal().isConnected());
ConnectableConnection connection = new ConnectableConnectionBuilder()
.withConnectableId("NHV1_NHV2_1")
.withFictitiousSwitchesOperable(false)
.withOnlyBreakersOperable(true)
.build();
PowsyblException connectionException = assertThrows(PowsyblException.class, () -> connection.apply(network, namingStrategy, true, computationManager, ReportNode.NO_OP));
assertEquals("Connectable 'NHV1_NHV2_1' not found", connectionException.getMessage());
connection.apply(network);
assertFalse(tieLine.getDanglingLine1().getTerminal().isConnected());
assertFalse(tieLine.getDanglingLine2().getTerminal().isConnected());
}
}

0 comments on commit d15f6c4

Please sign in to comment.