Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLD : add LCC_CONVERTER_STATION component type #537

Merged
merged 7 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
45 changes: 45 additions & 0 deletions diagram-test/src/main/java/com/powsybl/diagram/test/Networks.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public final class Networks {
private static final String CONVERTER_1_ID = "Converter1";

private static final String CONVERTER_2_ID = "Converter2";

private static final String CONVERTER_3_ID = "Converter3";

private static final String CONVERTER_4_ID = "Converter4";
private static final String LOAD_3_ID = "load3";
private static final String LOAD_1_ID = "load1";
private static final String LOAD_2_ID = "load2";
Expand Down Expand Up @@ -420,6 +424,7 @@ public static Network createNetworkWithHvdcLine() {
voltageLevel1.getBusBreakerView().newBus()
.setId("Bus1")
.add();
// VSC 1
voltageLevel1.newVscConverterStation()
.setId(CONVERTER_1_ID)
.setConnectableBus("Bus1")
Expand All @@ -440,6 +445,7 @@ public static Network createNetworkWithHvdcLine() {
voltageLevel2.getBusBreakerView().newBus()
.setId("Bus2")
.add();
// VSC 2
voltageLevel2.newVscConverterStation()
.setId(CONVERTER_2_ID)
.setConnectableBus("Bus2")
Expand All @@ -461,6 +467,45 @@ public static Network createNetworkWithHvdcLine() {
return network;
}

public static Network createNetworkWithHvdcLines() {
Network network = Networks.createNetworkWithHvdcLine();
VoltageLevel voltageLevel1 = network.getVoltageLevel(VOLTAGELEVEL_1_ID);
VoltageLevel voltageLevel2 = network.getVoltageLevel(VOLTAGELEVEL_2_ID);
voltageLevel1.getBusBreakerView().newBus()
.setId("Bus3")
.add();
// LCC 1
voltageLevel1.newLccConverterStation()
.setId(CONVERTER_3_ID)
.setConnectableBus("Bus3")
.setBus("Bus3")
.setLossFactor(0.011f)
.setPowerFactor(0.5f)
.add();
voltageLevel2.getBusBreakerView().newBus()
.setId("Bus4")
.add();
// LCC 2
voltageLevel2.newLccConverterStation()
.setId(CONVERTER_4_ID)
.setConnectableBus("Bus4")
.setBus("Bus4")
.setLossFactor(0.011f)
.setPowerFactor(-0.5f)
.add();
network.newHvdcLine()
.setId("HvdcLine2")
.setConverterStationId1(CONVERTER_3_ID)
.setConverterStationId2(CONVERTER_4_ID)
.setR(1)
.setNominalV(400)
.setConvertersMode(HvdcLine.ConvertersMode.SIDE_1_INVERTER_SIDE_2_RECTIFIER)
.setMaxP(300.0)
.setActivePowerSetpoint(280)
.add();
return network;
}

public static Network createNetworkWithBusbarAndSwitch() {
Network network = Network.create(NETWORK_ID, "test");
network.setCaseDate(DateTime.parse(CASE_DATE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,19 @@ public static LineDiagramData<DanglingLine> getOrCreateDiagramData(DanglingLine
return danglingLineData;
}

public static LineDiagramData<VscConverterStation> getOrCreateDiagramData(VscConverterStation vcs) {
LineDiagramData<VscConverterStation> vcsLineData = vcs.getExtension(LineDiagramData.class);
if (vcsLineData == null) {
vcsLineData = new LineDiagramData<>(vcs);
public static LineDiagramData<VscConverterStation> getOrCreateDiagramData(VscConverterStation vsc) {
LineDiagramData<VscConverterStation> vscLineData = vsc.getExtension(LineDiagramData.class);
if (vscLineData == null) {
vscLineData = new LineDiagramData<>(vsc);
}
return vcsLineData;
return vscLineData;
}

public static LineDiagramData<LccConverterStation> getOrCreateDiagramData(LccConverterStation lcc) {
LineDiagramData<LccConverterStation> lccLineData = lcc.getExtension(LineDiagramData.class);
if (lccLineData == null) {
lccLineData = new LineDiagramData<>(lcc);
}
return lccLineData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
package com.powsybl.sld.cgmes.dl.iidm.extensions;

import com.powsybl.iidm.network.HvdcLine;
import com.powsybl.iidm.network.LccConverterStation;
import com.powsybl.iidm.network.Network;
import com.powsybl.diagram.test.Networks;
import com.powsybl.iidm.network.VscConverterStation;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;

/**
*
Expand Down Expand Up @@ -55,4 +58,44 @@ void testMultipleDiagrams() {
checkDiagramData(hvdcLineDiagramData2, DIAGRAM_NAME);
checkDiagramData(hvdcLineDiagramData2, DIAGRAM2_NAME);
}

@Test
void testVsc() {
Network network = Networks.createNetworkWithHvdcLine();
VscConverterStation vsc = network.getVscConverterStation("Converter1");

LineDiagramData<VscConverterStation> vscDiagramData = LineDiagramData.getOrCreateDiagramData(vsc);
vscDiagramData.addPoint(DIAGRAM_NAME, new DiagramPoint(10, 0, 2));
vscDiagramData.addPoint(DIAGRAM_NAME, new DiagramPoint(0, 10, 1));
vsc.addExtension(LineDiagramData.class, vscDiagramData);

VscConverterStation vsc2 = network.getVscConverterStation("Converter1");
LineDiagramData<VscConverterStation> vscDiagramData2 = vsc2.getExtension(LineDiagramData.class);

assertEquals(1, vscDiagramData2.getDiagramsNames().size());
checkDiagramData(vscDiagramData2, DIAGRAM_NAME);

LineDiagramData<VscConverterStation> vscDiagramData3 = LineDiagramData.getOrCreateDiagramData(vsc);
assertSame(vscDiagramData, vscDiagramData3);
}

@Test
void testLcc() {
Network network = Networks.createNetworkWithHvdcLines();
LccConverterStation lcc = network.getLccConverterStation("Converter3");

LineDiagramData<LccConverterStation> lccDiagramData = LineDiagramData.getOrCreateDiagramData(lcc);
lccDiagramData.addPoint(DIAGRAM_NAME, new DiagramPoint(10, 0, 2));
lccDiagramData.addPoint(DIAGRAM_NAME, new DiagramPoint(0, 10, 1));
lcc.addExtension(LineDiagramData.class, lccDiagramData);

LccConverterStation lcc2 = network.getLccConverterStation("Converter3");
LineDiagramData<LccConverterStation> lccDiagramData2 = lcc2.getExtension(LineDiagramData.class);

assertEquals(1, lccDiagramData2.getDiagramsNames().size());
checkDiagramData(lccDiagramData2, DIAGRAM_NAME);

LineDiagramData<LccConverterStation> lccDiagramData3 = LineDiagramData.getOrCreateDiagramData(lcc);
assertSame(lccDiagramData, lccDiagramData3);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected void setNodeCoordinates(VoltageLevel vl, VoltageLevelGraph graph, Stri
}

protected boolean isLineNode(Node node) {
return Arrays.asList(LINE, DANGLING_LINE, VSC_CONVERTER_STATION).contains(node.getComponentType());
return Arrays.asList(LINE, DANGLING_LINE, VSC_CONVERTER_STATION, LCC_CONVERTER_STATION).contains(node.getComponentType());
}

protected void setNodeCoordinates(VoltageLevel vl, Node node, String diagramName, boolean useNames) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ private LayoutInfo applyLayout(Network network, String substationId, double xoff

vlGraph.getNodes().stream().filter(node -> Objects.equals(node.getComponentType(), VSC_CONVERTER_STATION)).forEach(node -> applyLayoutOnVscConverterStation(node, voltageLevel, diagramName, offsetPoint));

vlGraph.getNodes().stream().filter(node -> Objects.equals(node.getComponentType(), LCC_CONVERTER_STATION)).forEach(node -> applyLayoutOnLccConverterStation(node, voltageLevel, diagramName, offsetPoint));

if (TopologyKind.BUS_BREAKER.equals(voltageLevel.getTopologyKind())) {
voltageLevel.getBusBreakerView().getBusStream().forEach(bus ->
vlGraph.getNodeBuses().stream().filter(busNode -> busNode.getId().equals(bus.getId())).findFirst().ifPresent(busNode -> {
Expand Down Expand Up @@ -239,16 +241,30 @@ private void applyLayoutOnDanglingLines(Node node, VoltageLevel voltageLevel, St
}

private void applyLayoutOnVscConverterStation(Node node, VoltageLevel voltageLevel, String diagramName, OffsetPoint offsetPoint) {
FeederNode vcsNode = (FeederNode) node;
VscConverterStation vscConverterStation = voltageLevel.getConnectable(vcsNode.getId(), VscConverterStation.class);
FeederNode vscNode = (FeederNode) node;
VscConverterStation vscConverterStation = voltageLevel.getConnectable(vscNode.getId(), VscConverterStation.class);
if (vscConverterStation != null) {
LineDiagramData<VscConverterStation> vcsDiagramData = LineDiagramData.getOrCreateDiagramData(vscConverterStation);
int danglingLineSeq = getMaxSeq(vcsDiagramData.getPoints(diagramName)) + 1;
DiagramPoint vcsPoint = offsetPoint.newDiagramPoint(vcsNode.getX(), vcsNode.getY(), danglingLineSeq);
vcsDiagramData.addPoint(diagramName, vcsPoint);
LineDiagramData<VscConverterStation> vscDiagramData = LineDiagramData.getOrCreateDiagramData(vscConverterStation);
int danglingLineSeq = getMaxSeq(vscDiagramData.getPoints(diagramName)) + 1;
DiagramPoint vscPoint = offsetPoint.newDiagramPoint(vscNode.getX(), vscNode.getY(), danglingLineSeq);
vscDiagramData.addPoint(diagramName, vscPoint);

LOG.debug("setting CGMES DL IIDM extensions for Vsc Converter Station {} ({}), point {}", vscConverterStation.getId(), vscConverterStation.getNameOrId(), vscPoint);
vscConverterStation.addExtension(LineDiagramData.class, vscDiagramData);
}
}

LOG.debug("setting CGMES DL IIDM extensions for Vsc Converter Station {} ({}), point {}", vscConverterStation.getId(), vscConverterStation.getNameOrId(), vcsPoint);
vscConverterStation.addExtension(LineDiagramData.class, vcsDiagramData);
private void applyLayoutOnLccConverterStation(Node node, VoltageLevel voltageLevel, String diagramName, OffsetPoint offsetPoint) {
FeederNode lccNode = (FeederNode) node;
LccConverterStation lccConverterStation = voltageLevel.getConnectable(lccNode.getId(), LccConverterStation.class);
if (lccConverterStation != null) {
LineDiagramData<LccConverterStation> lccDiagramData = LineDiagramData.getOrCreateDiagramData(lccConverterStation);
int danglingLineSeq = getMaxSeq(lccDiagramData.getPoints(diagramName)) + 1;
DiagramPoint lccPoint = offsetPoint.newDiagramPoint(lccNode.getX(), lccNode.getY(), danglingLineSeq);
lccDiagramData.addPoint(diagramName, lccPoint);

LOG.debug("setting CGMES DL IIDM extensions for Lcc Converter Station {} ({}), point {}", lccConverterStation.getId(), lccConverterStation.getNameOrId(), lccPoint);
lccConverterStation.addExtension(LineDiagramData.class, lccDiagramData);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
import com.powsybl.diagram.test.Networks;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.mockito.stubbing.Answer;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.*;

Expand All @@ -23,7 +26,7 @@
*/
class LayoutToCgmesExtensionsTest {

private List<Network> networks = new ArrayList<>();
private final List<Network> networks = new ArrayList<>();

@BeforeEach
public void setUp() {
Expand All @@ -44,7 +47,7 @@ private void createNetworks() {
networks.add(Networks.createNetworkWithThreeWindingsTransformer());
networks.add(Networks.createNetworkWithBusbarAndSwitch());
networks.add(Networks.createNetworkWithPhaseShiftTransformer());
networks.add(Networks.createNetworkWithHvdcLine());
networks.add(Networks.createNetworkWithHvdcLines());
}

private void checkExtensionsSet(Network network) {
Expand Down Expand Up @@ -161,12 +164,12 @@ public void visitHvdcConverterStation(HvdcConverterStation<?> converterStation)

@Test
void testCgmesDlExtensionsEmpty() {
networks.stream().forEach(this::checkExtensionsUnset);
networks.forEach(this::checkExtensionsUnset);
}

@Test
void testCgmesDlExtensionsSet() {
networks.stream().forEach(network -> {
networks.forEach(network -> {
LayoutToCgmesExtensionsConverter lconv = new LayoutToCgmesExtensionsConverter();
lconv.convertLayout(network, "new-diagram");
checkExtensionsSet(network);
Expand All @@ -175,7 +178,7 @@ void testCgmesDlExtensionsSet() {

@Test
void testCgmesDlExtensionsSetNoname() {
networks.stream().forEach(network -> {
networks.forEach(network -> {
LayoutToCgmesExtensionsConverter lconv = new LayoutToCgmesExtensionsConverter();
lconv.convertLayout(network);
checkExtensionsSet(network);
Expand Down Expand Up @@ -211,4 +214,29 @@ void testCgmesDlExtensionsBridgePatternNetwork() {

assertEquals(2, VoltageLevelDiagramData.getInternalNodeDiagramPoints(vl1, vl1.getSubstation().map(Substation::getId).orElse(null)).length);
}

@Test
void testCoverage() {
// Spying Network
Network network = Mockito.spy(Networks.createNetworkWithHvdcLines());
// Spying Substation1
Substation substation = Mockito.spy(network.getSubstation("Substation1"));
// Spying VoltageLevel
VoltageLevel vl1 = Mockito.spy(network.getVoltageLevel("VoltageLevel1"));
// Using Substation1 only
Mockito.doReturn(substation).when(network).getSubstation(Mockito.anyString());
// Using VoltageLevel1 only
Answer<Stream<VoltageLevel>> answer = invocation -> Stream.of(vl1);
Mockito.doAnswer(answer).when(substation).getVoltageLevelStream();
// Faking Converter1 to null
Mockito.doReturn(null).when(vl1).getConnectable("Converter1", VscConverterStation.class);
// Faking Converter3 to null
Mockito.doReturn(null).when(vl1).getConnectable("Converter3", LccConverterStation.class);

LayoutToCgmesExtensionsConverter lconv = new LayoutToCgmesExtensionsConverter();
lconv.convertLayout(network, "new-diagram");

network.getVscConverterStationStream().forEach(vsc -> assertNull(vsc.getExtension(LineDiagramData.class)));
network.getLccConverterStationStream().forEach(lcc -> assertNull(lcc.getExtension(LineDiagramData.class)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,16 @@ private FeederNode createFeederVscNode(VoltageLevelGraph graph, HvdcConverterSta
.orElseGet(() -> NodeFactory.createVscConverterStationInjection(graph, hvdcStation.getId(), hvdcStation.getNameOrId()));
}

private FeederNode createFeederLccNode(VoltageLevelGraph graph, HvdcConverterStation<?> hvdcStation) {
// An injection node is created if only one side of the station in the network
return hvdcStation.getOtherConverterStation()
.map(otherStation -> otherStation.getTerminal().getVoltageLevel())
.map(otherVl -> new VoltageLevelInfos(otherVl.getId(), otherVl.getNameOrId(), otherVl.getNominalV()))
.map(otherVlInfo -> NodeFactory.createLccConverterStation(graph, hvdcStation.getId(), hvdcStation.getNameOrId(), hvdcStation.getHvdcLine().getId(),
hvdcStation.getHvdcLine().getConverterStation1() == hvdcStation ? NodeSide.ONE : NodeSide.TWO, otherVlInfo))
.orElseGet(() -> NodeFactory.createLccConverterStationInjection(graph, hvdcStation.getId(), hvdcStation.getNameOrId()));
}

private Node createInternal2wtSideNode(VoltageLevelGraph graph, TwoWindingsTransformer branch, Branch.Side side) {
return NodeFactory.createConnectivityNode(graph, branch.getId() + "_" + side.name(), NODE);
}
Expand Down Expand Up @@ -384,7 +394,13 @@ private void visitTieLine(TieLine tieLine, DanglingLine dl, Graph graph) {

@Override
public void visitHvdcConverterStation(HvdcConverterStation<?> converterStation) {
addTerminalNode(createFeederVscNode(graph, converterStation), converterStation.getTerminal());
FeederNode node;
switch (converterStation.getHvdcType()) {
case LCC: node = createFeederLccNode(graph, converterStation); break;
case VSC: node = createFeederVscNode(graph, converterStation); break;
default: throw new AssertionError();
}
addTerminalNode(node, converterStation.getTerminal());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public final class ComponentTypeName {
public static final String THREE_WINDINGS_TRANSFORMER = "THREE_WINDINGS_TRANSFORMER";
public static final String THREE_WINDINGS_TRANSFORMER_LEG = "THREE_WINDINGS_TRANSFORMER_LEG";
public static final String VSC_CONVERTER_STATION = "VSC_CONVERTER_STATION";
public static final String LCC_CONVERTER_STATION = "LCC_CONVERTER_STATION";
public static final String DANGLING_LINE = "DANGLING_LINE";
public static final String TIE_LINE = "TIE_LINE";
public static final String PHASE_SHIFT_TRANSFORMER = "PHASE_SHIFT_TRANSFORMER";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ public static FeederNode createVscConverterStationInjection(VoltageLevelGraph gr
return createFeederInjectionNode(graph, id, name, VSC_CONVERTER_STATION);
}

public static FeederNode createLccConverterStation(VoltageLevelGraph graph, String id, String name, String equipmentId, NodeSide side, VoltageLevelInfos otherSideVoltageLevelInfos) {
FeederWithSides feeder = new FeederWithSides(FeederType.HVDC, side, graph.getVoltageLevelInfos(), otherSideVoltageLevelInfos);
return createFeederNode(graph, id, name, equipmentId, ComponentTypeName.LCC_CONVERTER_STATION, feeder);
}

public static FeederNode createLccConverterStationInjection(VoltageLevelGraph graph, String id, String name) {
return createFeederInjectionNode(graph, id, name, LCC_CONVERTER_STATION);
}

public static FeederNode createFeederBranchNode(VoltageLevelGraph graph, String id, String name, String equipmentId, String componentType, NodeSide side, VoltageLevelInfos otherSideVoltageLevelInfos) {
return createFeederNode(graph, id, name, equipmentId, componentType, new FeederWithSides(FeederType.BRANCH, side, graph.getVoltageLevelInfos(), otherSideVoltageLevelInfos));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
.sld-pst-arrow {stroke: black; fill: none}
.sld-svc {stroke: var(--sld-vl-color, blue); fill: none}
.sld-vsc {stroke: var(--sld-vl-color, blue); font-size: 7.43px; fill: none}
.sld-lcc {stroke: var(--sld-vl-color, blue); font-size: 7.43px; fill: none}
/* Stroke none & fill: --sld-vl-color */
.sld-node-infos {stroke: none; fill: var(--sld-vl-color, black)}
/* Stroke none & fill: black */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,27 @@
"fileName" : "vsc.svg"
} ],
"styleClass" : "sld-vsc"
}, {
"type" : "LCC_CONVERTER_STATION",
"anchorPoints" : [ {
"x" : 0.0,
"y" : -6.0,
"orientation" : "VERTICAL"
}, {
"x" : 0.0,
"y" : 6.0,
"orientation" : "VERTICAL"
} ],
"size" : {
"width" : 16.0,
"height" : 8.0
},
"transformations" : { "LEFT":"ROTATION", "RIGHT":"ROTATION" },
"subComponents" : [ {
"name" : "LCC_CONVERTER_STATION",
"fileName" : "lcc.svg"
} ],
"styleClass" : "sld-lcc"
}, {
"type" : "BUSBAR_SECTION",
"styleClass" : "sld-busbar-section"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading