Skip to content

Commit

Permalink
add affected terminals to traverse in TrippingTopologyTraverser to tr…
Browse files Browse the repository at this point in the history
…ace which terminals have been traversed (#2040)

Signed-off-by: jacques borsenberger <jacques.borsenberger@rte-france.com>
  • Loading branch information
JacquesBorsenberger authored Mar 30, 2022
1 parent 5d3a617 commit 409e636
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ protected AbstractInjectionTripping(String id) {
}

@Override
public void traverse(Network network, Set<Switch> switchesToOpen, Set<Terminal> terminalsToDisconnect) {
public void traverse(Network network, Set<Switch> switchesToOpen, Set<Terminal> terminalsToDisconnect, Set<Terminal> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected String getVoltageLevelId() {
}

@Override
public void traverse(Network network, Set<Switch> switchesToOpen, Set<Terminal> terminalsToDisconnect) {
public void traverse(Network network, Set<Switch> switchesToOpen, Set<Terminal> terminalsToDisconnect, Set<Terminal> traversedTerminals) {
Objects.requireNonNull(network);

Branch<?> branch = supplier.apply(network, branchId);
Expand All @@ -59,15 +59,15 @@ public void traverse(Network network, Set<Switch> switchesToOpen, Set<Terminal>
}
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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ public BusbarSectionTripping(String busbarSectionId) {
}

@Override
public void traverse(Network network, Set<Switch> switchesToOpen, Set<Terminal> terminalsToDisconnect) {
public void traverse(Network network, Set<Switch> switchesToOpen, Set<Terminal> terminalsToDisconnect, Set<Terminal> traversedTerminals) {
Objects.requireNonNull(network);

BusbarSection busbarSection = network.getBusbarSection(busbarSectionId);
if (busbarSection == null) {
throw new PowsyblException("Busbar section '" + busbarSectionId + "' not found");
}

TrippingTopologyTraverser.traverse(busbarSection.getTerminal(), switchesToOpen, terminalsToDisconnect);
TrippingTopologyTraverser.traverse(busbarSection.getTerminal(), switchesToOpen, terminalsToDisconnect, traversedTerminals);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public HvdcLineTripping(String hvdcLineId, String voltageLevelId) {
}

@Override
public void traverse(Network network, Set<Switch> switchesToOpen, Set<Terminal> terminalsToDisconnect) {
public void traverse(Network network, Set<Switch> switchesToOpen, Set<Terminal> terminalsToDisconnect, Set<Terminal> traversedTerminals) {
Objects.requireNonNull(network);

HvdcLine hvdcLine = network.getHvdcLine(hvdcLineId);
Expand All @@ -47,15 +47,15 @@ public void traverse(Network network, Set<Switch> switchesToOpen, Set<Terminal>

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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ public ThreeWindingsTransformerTripping(String id) {
}

@Override
public void traverse(Network network, Set<Switch> switchesToOpen, Set<Terminal> terminalsToDisconnect) {
public void traverse(Network network, Set<Switch> switchesToOpen, Set<Terminal> terminalsToDisconnect, Set<Terminal> 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@
*/
public interface Tripping extends NetworkModification {

void traverse(Network network, Set<Switch> switchesToOpen, Set<Terminal> terminalsToDisconnect);
void traverse(Network network, Set<Switch> switchesToOpen, Set<Terminal> terminalsToDisconnect, Set<Terminal> traversedTerminals);

default void traverse(Network network, Set<Switch> switchesToOpen, Set<Terminal> terminalsToDisconnect) {
traverse(network, switchesToOpen, terminalsToDisconnect, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private static boolean isOpenable(Switch aSwitch) {
aSwitch.getKind() == SwitchKind.BREAKER;
}

static void traverse(Terminal terminal, Set<Switch> switchesToOpen, Set<Terminal> terminalsToDisconnect) {
static void traverse(Terminal terminal, Set<Switch> switchesToOpen, Set<Terminal> terminalsToDisconnect, Set<Terminal> traversedTerminals) {
Objects.requireNonNull(terminal);
Objects.requireNonNull(switchesToOpen);
Objects.requireNonNull(terminalsToDisconnect);
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,11 @@ public void fictitiousSwitchTest() {

Set<Switch> switchesToOpen = new HashSet<>();
Set<Terminal> terminalsToDisconnect = new HashSet<>();
tripping.traverse(network, switchesToOpen, terminalsToDisconnect);
Set<Terminal> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void test() {

Set<Switch> switchesToOpen = new HashSet<>();
Set<Terminal> 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());
Expand All @@ -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());
Expand Down

0 comments on commit 409e636

Please sign in to comment.