diff --git a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/tripping/AbstractInjectionTripping.java b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/tripping/AbstractInjectionTripping.java index d717d489c32..71d78f5861d 100644 --- a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/tripping/AbstractInjectionTripping.java +++ b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/tripping/AbstractInjectionTripping.java @@ -26,10 +26,10 @@ protected AbstractInjectionTripping(String id) { } @Override - public void traverse(Network network, Set switchesToOpen, Set terminalsToDisconnect) { + public void traverse(Network network, Set switchesToOpen, Set terminalsToDisconnect, Set traversedTerminals) { Objects.requireNonNull(network); - TrippingTopologyTraverser.traverse(getInjection(network).getTerminal(), switchesToOpen, terminalsToDisconnect); + TrippingTopologyTraverser.traverse(getInjection(network).getTerminal(), switchesToOpen, terminalsToDisconnect, traversedTerminals); } protected abstract Injection getInjection(Network network); diff --git a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/tripping/BranchTripping.java b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/tripping/BranchTripping.java index 90bd0e83d91..d8a1782e899 100644 --- a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/tripping/BranchTripping.java +++ b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/tripping/BranchTripping.java @@ -50,7 +50,7 @@ protected String getVoltageLevelId() { } @Override - public void traverse(Network network, Set switchesToOpen, Set terminalsToDisconnect) { + public void traverse(Network network, Set switchesToOpen, Set terminalsToDisconnect, Set traversedTerminals) { Objects.requireNonNull(network); Branch branch = supplier.apply(network, branchId); @@ -59,15 +59,15 @@ public void traverse(Network network, Set switchesToOpen, Set } if (voltageLevelId != null) { if (voltageLevelId.equals(branch.getTerminal1().getVoltageLevel().getId())) { - TrippingTopologyTraverser.traverse(branch.getTerminal1(), switchesToOpen, terminalsToDisconnect); + TrippingTopologyTraverser.traverse(branch.getTerminal1(), switchesToOpen, terminalsToDisconnect, traversedTerminals); } else if (voltageLevelId.equals(branch.getTerminal2().getVoltageLevel().getId())) { - TrippingTopologyTraverser.traverse(branch.getTerminal2(), switchesToOpen, terminalsToDisconnect); + TrippingTopologyTraverser.traverse(branch.getTerminal2(), switchesToOpen, terminalsToDisconnect, traversedTerminals); } else { throw createNotConnectedException(); } } else { - TrippingTopologyTraverser.traverse(branch.getTerminal1(), switchesToOpen, terminalsToDisconnect); - TrippingTopologyTraverser.traverse(branch.getTerminal2(), switchesToOpen, terminalsToDisconnect); + TrippingTopologyTraverser.traverse(branch.getTerminal1(), switchesToOpen, terminalsToDisconnect, traversedTerminals); + TrippingTopologyTraverser.traverse(branch.getTerminal2(), switchesToOpen, terminalsToDisconnect, traversedTerminals); } } diff --git a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/tripping/BusbarSectionTripping.java b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/tripping/BusbarSectionTripping.java index 98be79fcdf3..95f0860eca8 100644 --- a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/tripping/BusbarSectionTripping.java +++ b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/tripping/BusbarSectionTripping.java @@ -27,7 +27,7 @@ public BusbarSectionTripping(String busbarSectionId) { } @Override - public void traverse(Network network, Set switchesToOpen, Set terminalsToDisconnect) { + public void traverse(Network network, Set switchesToOpen, Set terminalsToDisconnect, Set traversedTerminals) { Objects.requireNonNull(network); BusbarSection busbarSection = network.getBusbarSection(busbarSectionId); @@ -35,6 +35,6 @@ public void traverse(Network network, Set switchesToOpen, Set throw new PowsyblException("Busbar section '" + busbarSectionId + "' not found"); } - TrippingTopologyTraverser.traverse(busbarSection.getTerminal(), switchesToOpen, terminalsToDisconnect); + TrippingTopologyTraverser.traverse(busbarSection.getTerminal(), switchesToOpen, terminalsToDisconnect, traversedTerminals); } } diff --git a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/tripping/HvdcLineTripping.java b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/tripping/HvdcLineTripping.java index 6edf6b66130..7e5f27a90ce 100644 --- a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/tripping/HvdcLineTripping.java +++ b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/tripping/HvdcLineTripping.java @@ -34,7 +34,7 @@ public HvdcLineTripping(String hvdcLineId, String voltageLevelId) { } @Override - public void traverse(Network network, Set switchesToOpen, Set terminalsToDisconnect) { + public void traverse(Network network, Set switchesToOpen, Set terminalsToDisconnect, Set traversedTerminals) { Objects.requireNonNull(network); HvdcLine hvdcLine = network.getHvdcLine(hvdcLineId); @@ -47,15 +47,15 @@ public void traverse(Network network, Set switchesToOpen, Set if (voltageLevelId != null) { if (voltageLevelId.equals(terminal1.getVoltageLevel().getId())) { - TrippingTopologyTraverser.traverse(terminal1, switchesToOpen, terminalsToDisconnect); + TrippingTopologyTraverser.traverse(terminal1, switchesToOpen, terminalsToDisconnect, traversedTerminals); } else if (voltageLevelId.equals(terminal2.getVoltageLevel().getId())) { - TrippingTopologyTraverser.traverse(terminal2, switchesToOpen, terminalsToDisconnect); + TrippingTopologyTraverser.traverse(terminal2, switchesToOpen, terminalsToDisconnect, traversedTerminals); } else { throw new PowsyblException("VoltageLevel '" + voltageLevelId + "' not connected to HVDC line '" + hvdcLineId + "'"); } } else { - TrippingTopologyTraverser.traverse(terminal1, switchesToOpen, terminalsToDisconnect); - TrippingTopologyTraverser.traverse(terminal2, switchesToOpen, terminalsToDisconnect); + TrippingTopologyTraverser.traverse(terminal1, switchesToOpen, terminalsToDisconnect, traversedTerminals); + TrippingTopologyTraverser.traverse(terminal2, switchesToOpen, terminalsToDisconnect, traversedTerminals); } } } diff --git a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/tripping/ThreeWindingsTransformerTripping.java b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/tripping/ThreeWindingsTransformerTripping.java index 72b97ed177a..41a2c67f1c6 100644 --- a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/tripping/ThreeWindingsTransformerTripping.java +++ b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/tripping/ThreeWindingsTransformerTripping.java @@ -27,16 +27,16 @@ public ThreeWindingsTransformerTripping(String id) { } @Override - public void traverse(Network network, Set switchesToOpen, Set terminalsToDisconnect) { + public void traverse(Network network, Set switchesToOpen, Set terminalsToDisconnect, Set traversedTerminals) { Objects.requireNonNull(network); ThreeWindingsTransformer twt3 = network.getThreeWindingsTransformer(id); if (twt3 == null) { throw createNotFoundException(); } - TrippingTopologyTraverser.traverse(twt3.getLeg1().getTerminal(), switchesToOpen, terminalsToDisconnect); - TrippingTopologyTraverser.traverse(twt3.getLeg2().getTerminal(), switchesToOpen, terminalsToDisconnect); - TrippingTopologyTraverser.traverse(twt3.getLeg3().getTerminal(), switchesToOpen, terminalsToDisconnect); + TrippingTopologyTraverser.traverse(twt3.getLeg1().getTerminal(), switchesToOpen, terminalsToDisconnect, traversedTerminals); + TrippingTopologyTraverser.traverse(twt3.getLeg2().getTerminal(), switchesToOpen, terminalsToDisconnect, traversedTerminals); + TrippingTopologyTraverser.traverse(twt3.getLeg3().getTerminal(), switchesToOpen, terminalsToDisconnect, traversedTerminals); } protected PowsyblException createNotFoundException() { diff --git a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/tripping/Tripping.java b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/tripping/Tripping.java index 7d5899039fd..a9b497969b3 100644 --- a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/tripping/Tripping.java +++ b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/tripping/Tripping.java @@ -18,5 +18,9 @@ */ public interface Tripping extends NetworkModification { - void traverse(Network network, Set switchesToOpen, Set terminalsToDisconnect); + void traverse(Network network, Set switchesToOpen, Set terminalsToDisconnect, Set traversedTerminals); + + default void traverse(Network network, Set switchesToOpen, Set terminalsToDisconnect) { + traverse(network, switchesToOpen, terminalsToDisconnect, null); + } } diff --git a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/tripping/TrippingTopologyTraverser.java b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/tripping/TrippingTopologyTraverser.java index 92b2ec738a0..11b926c6b76 100644 --- a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/tripping/TrippingTopologyTraverser.java +++ b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/tripping/TrippingTopologyTraverser.java @@ -26,7 +26,7 @@ private static boolean isOpenable(Switch aSwitch) { aSwitch.getKind() == SwitchKind.BREAKER; } - static void traverse(Terminal terminal, Set switchesToOpen, Set terminalsToDisconnect) { + static void traverse(Terminal terminal, Set switchesToOpen, Set terminalsToDisconnect, Set traversedTerminals) { Objects.requireNonNull(terminal); Objects.requireNonNull(switchesToOpen); Objects.requireNonNull(terminalsToDisconnect); @@ -39,8 +39,13 @@ public TraverseResult traverse(Terminal terminal, boolean connected) { // so to keep things simple we do not propagate the fault if (connected) { terminalsToDisconnect.add(terminal); + if (traversedTerminals != null) { + traversedTerminals.add(terminal); + } } return TraverseResult.TERMINATE_PATH; + } else if (traversedTerminals != null) { + traversedTerminals.add(terminal); } // in node/breaker topology propagation is decided only based on switch position return TraverseResult.CONTINUE; diff --git a/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/tripping/BranchTrippingTest.java b/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/tripping/BranchTrippingTest.java index 6482fa896fb..6c8589f88f4 100644 --- a/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/tripping/BranchTrippingTest.java +++ b/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/tripping/BranchTrippingTest.java @@ -126,8 +126,11 @@ public void fictitiousSwitchTest() { Set switchesToOpen = new HashSet<>(); Set terminalsToDisconnect = new HashSet<>(); - tripping.traverse(network, switchesToOpen, terminalsToDisconnect); + Set affectedTerminals = new HashSet<>(); + tripping.traverse(network, switchesToOpen, terminalsToDisconnect, affectedTerminals); assertEquals(switchIds, switchesToOpen.stream().map(Switch::getId).collect(Collectors.toSet())); + assertEquals(affectedTerminals.stream().map(Terminal::getConnectable).map(Connectable::getId).collect(Collectors.toSet()), + Set.of("CI", "D", "CJ")); assertEquals(Collections.emptySet(), terminalsToDisconnect); tripping.apply(network); diff --git a/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/tripping/TrippingTopologyTraverserTest.java b/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/tripping/TrippingTopologyTraverserTest.java index 7ac5f4735be..187189ff7f8 100644 --- a/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/tripping/TrippingTopologyTraverserTest.java +++ b/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/tripping/TrippingTopologyTraverserTest.java @@ -60,7 +60,7 @@ public void test() { Set switchesToOpen = new HashSet<>(); Set terminalsToDisconnect = new HashSet<>(); - TrippingTopologyTraverser.traverse(l1.getTerminal1(), switchesToOpen, terminalsToDisconnect); + TrippingTopologyTraverser.traverse(l1.getTerminal1(), switchesToOpen, terminalsToDisconnect, null); assertTrue(switchesToOpen.isEmpty()); assertEquals(1, terminalsToDisconnect.size()); assertEquals("BusTerminal[b1]", terminalsToDisconnect.iterator().next().toString()); @@ -70,13 +70,13 @@ public void test() { switchesToOpen.clear(); terminalsToDisconnect.clear(); - TrippingTopologyTraverser.traverse(l1.getTerminal1(), switchesToOpen, terminalsToDisconnect); + TrippingTopologyTraverser.traverse(l1.getTerminal1(), switchesToOpen, terminalsToDisconnect, null); assertTrue(switchesToOpen.isEmpty()); assertTrue(terminalsToDisconnect.isEmpty()); switchesToOpen.clear(); terminalsToDisconnect.clear(); - TrippingTopologyTraverser.traverse(l1.getTerminal2(), switchesToOpen, terminalsToDisconnect); + TrippingTopologyTraverser.traverse(l1.getTerminal2(), switchesToOpen, terminalsToDisconnect, null); assertTrue(switchesToOpen.isEmpty()); assertEquals(1, terminalsToDisconnect.size()); assertEquals("BusTerminal[b2]", terminalsToDisconnect.iterator().next().toString());