@@ -42,9 +42,11 @@ public static Optional<Terminal> mapForVoltageControl(String cgmesTerminalId, Co
4242 .or (() -> new EquivalentTerminalFinderVoltageControl (cgmesTerminalId , context ).find ())
4343 // As a last resource, rely on the "find" method of terminal mapping:
4444 // Bus/branch models may define remote voltage controls that point to busbar sections
45- // Busbar sections are not mapped to IIDM
45+ // Since busbar sections are not mapped to IIDM, we look for an equivalent IIDM terminal
46+ // that is connected to the busbar section via switches
4647 .or (() -> Optional .ofNullable (context .terminalMapping ()
47- .findFromTopologicalNode (context .terminalMapping ().getTopologicalNode (cgmesTerminalId ))));
48+ .findFromTopologicalNode (context .terminalMapping ().getTopologicalNode (cgmesTerminalId )))
49+ .or (() -> findEquivalentTerminalForVoltageRegulatingTerminalDefinedAtBusbarSection (cgmesTerminalId , context )));
4850 }
4951
5052 public static Optional <TerminalAndSign > mapForFlowControl (String cgmesTerminalId , Context context ) {
@@ -337,7 +339,7 @@ private Optional<Terminal> findNodeBreaker() {
337339
338340 private Optional <Terminal > findBusBranch () {
339341 Bus end1 = vl .getBusBreakerView ().getBus1 (sw .getId ());
340- List <Terminal > terminals = findTerminalsBusBranch (end1 );
342+ List <Terminal > terminals = findTerminalsBusBranch (vl , end1 );
341343 return best (terminals );
342344 }
343345
@@ -346,7 +348,7 @@ protected List<Terminal> findTerminalsNodeBreaker(int node) {
346348 return allTerminals (vl , nodes , t -> t .getNodeBreakerView ().getNode ());
347349 }
348350
349- private List <Terminal > findTerminalsBusBranch (Bus end ) {
351+ private static List <Terminal > findTerminalsBusBranch (VoltageLevel vl , Bus end ) {
350352 Set <Bus > buses = allBusesReachableBySwitches (vl , end );
351353 return allTerminals (vl , buses , RegulatingTerminalMapper ::getTerminalBus );
352354 }
@@ -399,6 +401,17 @@ private Optional<Terminal> findBusBranch() {
399401 }
400402 }
401403
404+ static Optional <Terminal > findEquivalentTerminalForVoltageRegulatingTerminalDefinedAtBusbarSection (String cgmesTerminalId , Context context ) {
405+ CgmesTerminal busbarSectionCgmesTerminal = context .cgmes ().terminal (cgmesTerminalId );
406+ if (busbarSectionCgmesTerminal == null ) {
407+ return Optional .empty ();
408+ }
409+ Bus busInBusBreakerView = context .network ().getBusBreakerView ().getBus (busbarSectionCgmesTerminal .topologicalNode ());
410+ return busInBusBreakerView != null
411+ ? EquivalentTerminalFinderVoltageControl .best (EquivalentTerminalFinderVoltageControl .findTerminalsBusBranch (busInBusBreakerView .getVoltageLevel (), busInBusBreakerView ))
412+ : Optional .empty ();
413+ }
414+
402415 private static Bus getTerminalBus (Terminal terminal ) {
403416 return terminal .getBusBreakerView ().getBus () != null ? terminal .getBusBreakerView ().getBus ()
404417 : terminal .getBusBreakerView ().getConnectableBus ();
0 commit comments