Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Commit

Permalink
Sort voltage levels input (#89)
Browse files Browse the repository at this point in the history
* Factorize duplicate stream
* Sort filtered voltage levels
* Update unit tests

Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
  • Loading branch information
flo-dup authored Sep 15, 2022
1 parent 8a56054 commit 35f4a8f
Show file tree
Hide file tree
Showing 14 changed files with 9,050 additions and 9,056 deletions.
30 changes: 12 additions & 18 deletions src/main/java/com/powsybl/nad/build/iidm/NetworkGraphBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@

import com.powsybl.commons.PowsyblException;
import com.powsybl.iidm.network.Identifiable;
import com.powsybl.nad.model.ThreeWtNode;
import com.powsybl.iidm.network.*;
import com.powsybl.nad.build.GraphBuilder;
import com.powsybl.nad.model.*;
import com.powsybl.nad.utils.iidm.IidmUtils;

import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
* @author Florian Dupuy <florian.dupuy at rte-france.com>
Expand Down Expand Up @@ -43,24 +45,16 @@ public NetworkGraphBuilder(Network network) {
@Override
public Graph buildGraph() {
Graph graph = new Graph();
addGraphNodes(graph);
addGraphEdges(graph);
return graph;
}

private void addGraphNodes(Graph graph) {
network.getVoltageLevelStream()
List<VoltageLevel> voltageLevels = network.getVoltageLevelStream()
.filter(voltageLevelFilter)
.forEach(vl -> createVoltageLevelNode(vl, graph, true));
}

private void addGraphEdges(Graph graph) {
network.getVoltageLevelStream()
.filter(voltageLevelFilter)
.forEach(vl -> visitEquipments(vl, graph));
.sorted(Comparator.comparing(VoltageLevel::getId))
.collect(Collectors.toList());
voltageLevels.forEach(vl -> addVoltageLevelGraphNode(vl, graph, true));
voltageLevels.forEach(vl -> addGraphEdges(vl, graph));
return graph;
}

private VoltageLevelNode createVoltageLevelNode(VoltageLevel vl, Graph graph, boolean visible) {
private VoltageLevelNode addVoltageLevelGraphNode(VoltageLevel vl, Graph graph, boolean visible) {
VoltageLevelNode vlNode = new VoltageLevelNode(idProvider.createId(vl), vl.getId(), vl.getNameOrId(), vl.isFictitious(), visible);
vl.getBusView().getBusStream()
.map(bus -> new BusNode(idProvider.createId(bus), bus.getId()))
Expand All @@ -72,7 +66,7 @@ private VoltageLevelNode createVoltageLevelNode(VoltageLevel vl, Graph graph, bo
return vlNode;
}

private void visitEquipments(VoltageLevel vl, Graph graph) {
private void addGraphEdges(VoltageLevel vl, Graph graph) {
vl.getLineStream().forEach(l -> visitLine(vl, l, graph));
vl.getTwoWindingsTransformerStream().forEach(twt -> visitTwoWindingsTransformer(vl, twt, graph));
vl.getThreeWindingsTransformerStream().forEach(thwt -> visitThreeWindingsTransformer(vl, thwt, graph));
Expand Down Expand Up @@ -174,7 +168,7 @@ private BusNode getBusNode(Graph graph, Terminal terminal) {

private VoltageLevelNode getOrCreateInvisibleVoltageLevelNode(Graph graph, Terminal terminal) {
VoltageLevel vl = terminal.getVoltageLevel();
return graph.getVoltageLevelNode(vl.getId()).orElseGet(() -> createVoltageLevelNode(vl, graph, false));
return graph.getVoltageLevelNode(vl.getId()).orElseGet(() -> addVoltageLevelGraphNode(vl, graph, false));
}

private ThreeWindingsTransformer.Side[] getSidesArray(ThreeWindingsTransformer.Side sideA) {
Expand Down
36 changes: 18 additions & 18 deletions src/test/resources/3wt.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 27 additions & 27 deletions src/test/resources/3wt_disconnected.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 35f4a8f

Please sign in to comment.