Skip to content

Commit

Permalink
Fix RemoveFeederBay
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Dupuy <[email protected]>
  • Loading branch information
flo-dup committed Jan 21, 2025
1 parent 1461740 commit 04a8448
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions iidm/iidm-modification/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
</build>

<dependencies>
<dependency>
<groupId>org.jgrapht</groupId>
<artifactId>jgrapht-io</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-iidm-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
import org.jgrapht.Graph;
import org.jgrapht.alg.util.Pair;
import org.jgrapht.graph.Pseudograph;
import org.jgrapht.nio.dot.DOTExporter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.*;

import static com.powsybl.iidm.modification.util.ModificationReports.*;
Expand Down Expand Up @@ -93,6 +95,7 @@ private Graph<Integer, Object> createGraphFromTerminal(Terminal terminal) {
graph.addEdge(node1, node2, sw != null ? sw : Pair.of(node1, node2));
return result;
});
new DOTExporter<Integer, Object>(i -> i.toString()).exportGraph(graph, new File("/tmp/graph.dot"));
return graph;
}

Expand Down Expand Up @@ -200,6 +203,11 @@ private void searchConnectables(VoltageLevel.NodeBreakerView nbv, Graph<Integer,
*/
private void removeAllSwitchesAndInternalConnections(VoltageLevel.NodeBreakerView nbv, Graph<Integer, Object> graph,
int originNode, Object edge, ReportNode reportNode) {
// in case of loops inside the traversed bay, the edge might have been already removed
if (!graph.containsEdge(edge)) {
return;
}

Integer oppositeNode = getOppositeNode(graph, originNode, edge);
removeSwitchOrInternalConnection(nbv, graph, edge, reportNode);
if (!isBusbarSection(nbv, oppositeNode)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.Set;

Expand Down Expand Up @@ -52,6 +53,14 @@ public void afterRemoval(String id) {
});
}

@Test
void testBug() throws IOException {
Network network = Network.read("/home/dupuyflo/Data/test-iidm.xiidm");
String voltageLevelId = ".A.ZA 6";
network.getVoltageLevel(voltageLevelId).exportTopology(Path.of("/tmp/x.dot"));
new RemoveVoltageLevelBuilder().withVoltageLevelId(voltageLevelId).build().apply(network);
}

@Test
void testLoops() {
Network network = Network.create("test", "test");
Expand Down Expand Up @@ -85,7 +94,7 @@ void testLoops() {

new RemoveVoltageLevelBuilder().withVoltageLevelId(vl1.getId()).build().apply(network);

assertEquals(Set.of("bbs1", "bbs2", "Coupler", "d_l2_bbs2", "vl1", "d_l2_bbs1", "d_l1_bbs2", "line2", "line1", "d_l1_bbs1"), removedObjects);
assertEquals(Set.of("bbs1", "bbs2", "Coupler", "b_l2_bbs2_B", "b_l2_bbs2_A", "d_l2_bbs2", "vl1", "d_l2_bbs1", "d_l1_bbs2", "line2", "line1", "d_l1_bbs1"), removedObjects);
assertNull(network.getVoltageLevel("vl1"));
}

Expand Down

0 comments on commit 04a8448

Please sign in to comment.