Skip to content
Closed
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
98d2a6e
get all voltage level connections
EtienneLt Aug 21, 2025
397e97c
Merge branch 'main' into get-all-voltage-levels-connections
EtienneLt Aug 21, 2025
884a664
fix
EtienneLt Aug 21, 2025
732185b
refactor
EtienneLt Aug 22, 2025
46700f8
refactor everything
EtienneLt Aug 22, 2025
6b9b5a4
fix
EtienneLt Aug 22, 2025
6d0e15e
fix
EtienneLt Aug 22, 2025
01cbb74
fix
EtienneLt Aug 27, 2025
80a13c0
Merge branch 'main' into get-all-voltage-levels-connections
EtienneLt Aug 27, 2025
7774634
fix
EtienneLt Aug 27, 2025
0305db9
remove error from merge
EtienneLt Aug 27, 2025
84cff31
checkstyle
EtienneLt Aug 27, 2025
a971d0c
Merge branch 'main' into get-all-voltage-levels-connections
EtienneLt Sep 3, 2025
1e5770b
add tests
EtienneLt Sep 3, 2025
f63c963
add side for branches
EtienneLt Sep 5, 2025
7e6fd6b
add side
ghazwarhili Sep 5, 2025
c966b59
rename side to connectionSide
ghazwarhili Sep 7, 2025
c2a535e
fix naming
ghazwarhili Sep 7, 2025
12d9d9f
renaming
ghazwarhili Sep 8, 2025
fed0ec8
fix for BusbarSectionFinderTraverser
ghazwarhili Sep 14, 2025
c112b6a
enhance BusbarSectionFinderTraverser to handle all cases
ghazwarhili Sep 15, 2025
34b31cc
code review remarks part 1
ghazwarhili Sep 19, 2025
5a615ba
code review remarks part 2
ghazwarhili Sep 19, 2025
8163bb1
resolving conflicts
ghazwarhili Sep 21, 2025
8bcf99a
Merge branch 'fix-busbar-section-finder-traverser' into get-all-volta…
ghazwarhili Sep 22, 2025
fff52f6
Etienne H Request to use FeederSide
ghazwarhili Sep 24, 2025
c40fe02
resolving conflicts and revert BusbarSectionFinderTraverser
ghazwarhili Sep 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,82 @@

import com.powsybl.iidm.network.IdentifiableType;
import com.powsybl.iidm.network.Switch;
import com.powsybl.iidm.network.SwitchKind;
import com.powsybl.iidm.network.Terminal;
import com.powsybl.math.graph.TraverseResult;
import lombok.Getter;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* @author Slimane Amar <slimane.amar at rte-france.com>
*/
public class BusbarSectionFinderTraverser implements Terminal.TopologyTraverser {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move those changes in another PR. So the review can be done with #288. And the changes in the tests will be reviewed with it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's back lol


private final boolean onlyConnectedBbs;

private String firstTraversedBbsId;

public BusbarSectionFinderTraverser(boolean onlyConnectedBbs) {
this.onlyConnectedBbs = onlyConnectedBbs;
}
private final List<BusbarCandidate> busbarCandidates = new ArrayList<>();
private final Set<String> visitedTerminals = new HashSet<>();
private static final int MAX_VISITED = 50;

@Override
public TraverseResult traverse(Terminal terminal, boolean connected) {
if (terminal.getConnectable().getType() == IdentifiableType.BUSBAR_SECTION) {
firstTraversedBbsId = terminal.getConnectable().getId();
String terminalId = terminal.getConnectable().getId();
if (visitedTerminals.contains(terminalId)) {
return TraverseResult.TERMINATE_PATH;
}
visitedTerminals.add(terminalId);
if (visitedTerminals.size() > MAX_VISITED) {
return TraverseResult.TERMINATE_TRAVERSER;
}

// If a busbar section is found, add it as a candidate
if (terminal.getConnectable().getType() == IdentifiableType.BUSBAR_SECTION) {
busbarCandidates.add(new BusbarCandidate(terminalId, connected));
// CONTINUE to explore other paths to other busbars
return TraverseResult.CONTINUE;
}
return TraverseResult.CONTINUE;
}

@Override
public TraverseResult traverse(Switch aSwitch) {
if (onlyConnectedBbs && aSwitch.isOpen()) {
return TraverseResult.TERMINATE_PATH;
if (visitedTerminals.size() > MAX_VISITED) {
return TraverseResult.TERMINATE_TRAVERSER;
}

// KEY: Open disconnectors end this path but not the overall traversal
// They block access to this busbar but not to the others
if (aSwitch.isOpen() && aSwitch.getKind() == SwitchKind.DISCONNECTOR) {
return TraverseResult.TERMINATE_PATH; // Ends this path, not the whole traversal
}
return TraverseResult.CONTINUE;
}

public String getFirstTraversedBbsId() {
return firstTraversedBbsId;
public String getBusbarWithClosedDisconnector() {
// Search for a connected busbar (disconnector closed)
for (BusbarCandidate candidate : busbarCandidates) {
if (candidate.isConnected()) {
return candidate.getId();
}
}

// If none is connected, return the first one found (fallback)
if (!busbarCandidates.isEmpty()) {
return busbarCandidates.getFirst().getId();
}
return null;
}

@Getter
private static class BusbarCandidate {
private final String id;
private final boolean connected;

public BusbarCandidate(String id, boolean connected) {
this.id = id;
this.connected = connected;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.gridsuite.network.map.dto.definition.extension;

import com.fasterxml.jackson.annotation.JsonInclude;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Copyright (c) 2025, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.gridsuite.network.map.dto.definition.voltagelevel;

import com.powsybl.iidm.network.TwoSides;
import org.gridsuite.network.map.dto.definition.extension.ConnectablePositionInfos;

/**
* @author Etienne Lesot <etienne.lesot at rte-france.com>
*/
public record FeederBayInfos(String busbarSectionId, ConnectablePositionInfos connectablePositionInfos, TwoSides connectionSide) { }
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,7 @@ public class VoltageLevelFormInfos extends ElementInfosWithProperties {

@JsonInclude(JsonInclude.Include.NON_NULL)
private Map<String, List<String>> busBarSectionInfos;

@JsonInclude(JsonInclude.Include.NON_NULL)
private Map<String, List<FeederBayInfos>> feederBaysInfos;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.gridsuite.network.map.dto.ElementInfos;
import org.gridsuite.network.map.dto.InfoTypeParameters;
import org.gridsuite.network.map.dto.definition.busbarsection.BusBarSectionFormInfos;
import org.gridsuite.network.map.dto.definition.voltagelevel.FeederBayInfos;
import org.gridsuite.network.map.dto.definition.voltagelevel.VoltageLevelFormInfos;
import org.gridsuite.network.map.dto.definition.voltagelevel.VoltageLevelMapInfos;
import org.gridsuite.network.map.dto.definition.voltagelevel.VoltageLevelTabInfos;
Expand All @@ -23,6 +24,7 @@
import java.util.*;
import java.util.stream.Collectors;

import static com.powsybl.iidm.network.Terminal.getConnectableSide;
import static org.gridsuite.network.map.dto.utils.ElementUtils.*;

/**
Expand Down Expand Up @@ -106,14 +108,37 @@ static VoltageLevelFormInfos toFormInfos(Identifiable<?> identifiable) {
builder.isRetrievedBusbarSections(vlTopologyInfos.isRetrievedBusbarSections());
builder.isBusbarSectionPositionFound(vlTopologyInfos.isBusbarSectionPositionFound());
builder.busBarSectionInfos(vlTopologyInfos.getBusBarSectionInfosGrouped());
builder.feederBaysInfos(getFeederBaysInfos(voltageLevel));
}

builder.identifiableShortCircuit(ExtensionUtils.toIdentifiableShortCircuit(voltageLevel));

return builder.build();
}

static VoltageLevelMapInfos toMapInfos(Identifiable<?> identifiable) {
private static Map<String, List<FeederBayInfos>> getFeederBaysInfos(VoltageLevel voltageLevel) {
Map<String, List<FeederBayInfos>> feederBayInfos = new HashMap<>();
String currentVoltageLevelId = voltageLevel.getId();
voltageLevel.getConnectableStream()
.filter(connectable -> !(connectable instanceof BusbarSection))
.forEach(connectable -> {
List<FeederBayInfos> connections = new ArrayList<>();
for (Object obj : connectable.getTerminals()) {
Terminal terminal = (Terminal) obj;
if (terminal.getVoltageLevel().getId().equals(currentVoltageLevelId)) {
connections.add(new FeederBayInfos(
getBusOrBusbarSection(terminal),
getConnectablePosition(connectable, FeederSide.from(getConnectableSide(terminal))),
Objects.requireNonNull(getConnectableSide(terminal).orElse(null)).toTwoSides()
));
}
}
feederBayInfos.put(connectable.getId(), connections);
});
return feederBayInfos;
}

protected static VoltageLevelMapInfos toMapInfos(Identifiable<?> identifiable) {
VoltageLevel voltageLevel = (VoltageLevel) identifiable;
return VoltageLevelMapInfos.builder()
.id(voltageLevel.getId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
package org.gridsuite.network.map.dto.utils;

import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.extensions.ConnectablePosition;
import com.powsybl.math.graph.TraversalType;
import lombok.NonNull;
import org.gridsuite.network.map.dto.common.ReactiveCapabilityCurveMapData;
import org.gridsuite.network.map.dto.common.TapChangerData;
import org.gridsuite.network.map.dto.common.TapChangerStepData;
import org.gridsuite.network.map.dto.definition.extension.BusbarSectionFinderTraverser;
import org.springframework.lang.NonNull;
import org.gridsuite.network.map.dto.definition.extension.ConnectablePositionInfos;

import java.util.Collection;
import java.util.List;
Expand All @@ -39,6 +41,53 @@ public static void setIfNotNan(@NonNull final DoubleConsumer setter, final doubl
}
}

public enum FeederSide {
INJECTION_SINGLE_SIDE,
BRANCH_SIDE_ONE,
BRANCH_SIDE_TWO;

public static FeederSide from(Optional<ThreeSides> connectableSide) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public static FeederSide from(Optional<ThreeSides> connectableSide) {
            if (connectableSide.isEmpty()) {
                return INJECTION_SINGLE_SIDE;
            }
            return connectableSide.get() == ThreeSides.ONE ? BRANCH_SIDE_ONE : BRANCH_SIDE_TWO;
}

ThreeSides threeSides = connectableSide.orElse(null);
if (threeSides == null) {
return INJECTION_SINGLE_SIDE;
}
return threeSides == ThreeSides.ONE ? BRANCH_SIDE_ONE : BRANCH_SIDE_TWO;
}
}

private static ConnectablePosition.Feeder getFeederInfos(Identifiable<?> identifiable, FeederSide side) {
var connectablePosition = identifiable.getExtension(ConnectablePosition.class);
if (connectablePosition == null) {
return null;
}

switch (side) {
case INJECTION_SINGLE_SIDE:
return connectablePosition.getFeeder();
case BRANCH_SIDE_ONE:
return connectablePosition.getFeeder1();
case BRANCH_SIDE_TWO:
return connectablePosition.getFeeder2();
default:
throw new IllegalArgumentException("Invalid feeder side: " + side);
}
}

public static ConnectablePositionInfos getConnectablePosition(Identifiable<?> identifiable, FeederSide side) {
ConnectablePosition.Feeder feeder = getFeederInfos(identifiable, side);
return buildConnectablePositionInfos(feeder);
}

public static ConnectablePositionInfos buildConnectablePositionInfos(ConnectablePosition.Feeder feeder) {
ConnectablePositionInfos.ConnectablePositionInfosBuilder builder = ConnectablePositionInfos.builder();
if (feeder != null) {
builder.connectionDirection(feeder.getDirection() == null ? null : feeder.getDirection())
.connectionPosition(feeder.getOrder().orElse(null))
.connectionName(feeder.getName().orElse(null));
}
return builder.build();
}

public static String getBusOrBusbarSection(Terminal terminal) {
if (terminal.getVoltageLevel().getTopologyKind().equals(TopologyKind.BUS_BREAKER)) {
if (terminal.isConnected()) {
Expand All @@ -47,9 +96,10 @@ public static String getBusOrBusbarSection(Terminal terminal) {
return terminal.getBusBreakerView().getConnectableBus().getId();
}
} else {
final BusbarSectionFinderTraverser connectedBusbarSectionFinder = new BusbarSectionFinderTraverser(terminal.isConnected());
terminal.traverse(connectedBusbarSectionFinder, TraversalType.BREADTH_FIRST);
return connectedBusbarSectionFinder.getFirstTraversedBbsId();
// NODE_BREAKER: explore all paths and choose the busbar with the closed disconnector
BusbarSectionFinderTraverser finder = new BusbarSectionFinderTraverser();
terminal.traverse(finder, TraversalType.BREADTH_FIRST);
return finder.getBusbarWithClosedDisconnector();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static ConnectablePositionInfos toMapConnectablePosition(@NonNull final I
case 0 -> connectablePosition.getFeeder();
case 1 -> connectablePosition.getFeeder1();
case 2 -> connectablePosition.getFeeder2();
case 3 -> connectablePosition.getFeeder3();
default -> throw new IllegalArgumentException("Invalid feeder index: " + index);
})
.ifPresent(feeder -> builder
Expand Down
Loading