Skip to content

Commit

Permalink
Bump core 610 (#569)
Browse files Browse the repository at this point in the history
* Bump to powsybl-core 6.1.0
* Remove joda-time library
* Change artifact name from xml-converter to serde
* BranchStatus renamed OperatingStatus
* TwoSides and ThreeSides used instead of Branch.Side and ThreeWindingsTransformer.Side
* Remove remaining ThreeWindingsTransformer.Side
* Deal with change of package name xml -> serde
* Replace readUntilEndElement function (that does not exist anymore) by readSubElements (1 test failing)
* Update reading metadata following XmlUtil changes
* Fix unit test
* Rename methods to clarify use
* Fix comparing to have the diff in the logs
* Fix checkstyle
* Following review comments: use ThreeSides functions to refactor code
* Fix code smell regarding lambda / method reference
* Revert "Fix comparing to have the diff in the logs" (This reverts commit 35551ec.)
* Revert "Fix checkstyle" (This reverts commit 67a07d9.)
* Improve getNextSideNum(...) function

---------

Signed-off-by: Sophie Frasnedo <sophie.frasnedo@rte-france.com>
Co-authored-by: Florian Dupuy <florian.dupuy@rte-france.com>
  • Loading branch information
So-Fras and flo-dup authored Dec 12, 2023
1 parent fcf45db commit e8ac836
Show file tree
Hide file tree
Showing 23 changed files with 220 additions and 204 deletions.
56 changes: 28 additions & 28 deletions diagram-test/src/main/java/com/powsybl/diagram/test/Networks.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import com.powsybl.commons.extensions.Extendable;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.extensions.*;
import org.joda.time.DateTime;

import java.time.ZonedDateTime;
import java.util.Optional;

/**
Expand Down Expand Up @@ -65,7 +65,7 @@ private Networks() {

public static Network createNetworkWithBusbar() {
Network network = Network.create(NETWORK_ID, "test");
network.setCaseDate(DateTime.parse(CASE_DATE));
network.setCaseDate(ZonedDateTime.parse(CASE_DATE));
Substation substation = network.newSubstation()
.setId(SUBSTATION_ID)
.setCountry(Country.FR)
Expand All @@ -84,7 +84,7 @@ public static Network createNetworkWithBusbar() {

public static Network createNetworkWithBus() {
Network network = Network.create(NETWORK_ID, "test");
network.setCaseDate(DateTime.parse(CASE_DATE));
network.setCaseDate(ZonedDateTime.parse(CASE_DATE));
Substation substation = network.newSubstation()
.setId(SUBSTATION_ID)
.setCountry(Country.FR)
Expand All @@ -102,7 +102,7 @@ public static Network createNetworkWithBus() {

public static Network createNetworkWithGenerator() {
Network network = Network.create("test", "test");
network.setCaseDate(DateTime.parse(CASE_DATE));
network.setCaseDate(ZonedDateTime.parse(CASE_DATE));
Substation substation = network.newSubstation()
.setId(SUBSTATION_ID)
.setCountry(Country.FR)
Expand Down Expand Up @@ -130,7 +130,7 @@ public static Network createNetworkWithGenerator() {

public static Network createNetworkWithLine() {
Network network = Network.create(NETWORK_ID, "test");
network.setCaseDate(DateTime.parse(CASE_DATE));
network.setCaseDate(ZonedDateTime.parse(CASE_DATE));
Substation substation1 = network.newSubstation()
.setId(SUBSTATION_1_ID)
.setCountry(Country.FR)
Expand Down Expand Up @@ -175,7 +175,7 @@ public static Network createNetworkWithLine() {

public static Network createNetworkWithLoad() {
Network network = Network.create("test", "test");
network.setCaseDate(DateTime.parse(CASE_DATE));
network.setCaseDate(ZonedDateTime.parse(CASE_DATE));
Substation substation = network.newSubstation()
.setId(SUBSTATION_ID)
.setCountry(Country.FR)
Expand All @@ -200,7 +200,7 @@ public static Network createNetworkWithLoad() {

public static Network createNetworkWithShuntCompensator() {
Network network = Network.create("test", "test");
network.setCaseDate(DateTime.parse(CASE_DATE));
network.setCaseDate(ZonedDateTime.parse(CASE_DATE));
Substation substation = network.newSubstation()
.setId(SUBSTATION_ID)
.setCountry(Country.FR)
Expand Down Expand Up @@ -228,7 +228,7 @@ public static Network createNetworkWithShuntCompensator() {

public static Network createNetworkWithStaticVarCompensator() {
Network network = Network.create("test", "test");
network.setCaseDate(DateTime.parse(CASE_DATE));
network.setCaseDate(ZonedDateTime.parse(CASE_DATE));
Substation substation = network.newSubstation()
.setId(SUBSTATION_ID)
.setCountry(Country.FR)
Expand Down Expand Up @@ -256,7 +256,7 @@ public static Network createNetworkWithStaticVarCompensator() {

public static Network createNetworkWithSwitch() {
Network network = Network.create(NETWORK_ID, "test");
network.setCaseDate(DateTime.parse(CASE_DATE));
network.setCaseDate(ZonedDateTime.parse(CASE_DATE));
Substation substation = network.newSubstation()
.setId(SUBSTATION_ID)
.setCountry(Country.FR)
Expand All @@ -283,7 +283,7 @@ public static Network createNetworkWithSwitch() {

public static Network createNetworkWithThreeWindingsTransformer() {
Network network = Network.create(NETWORK_ID, "test");
network.setCaseDate(DateTime.parse(CASE_DATE));
network.setCaseDate(ZonedDateTime.parse(CASE_DATE));
Substation substation = network.newSubstation()
.setId(SUBSTATION_ID)
.setCountry(Country.FR)
Expand Down Expand Up @@ -343,7 +343,7 @@ public static Network createNetworkWithThreeWindingsTransformer() {

public static Network createNetworkWithTwoWindingsTransformer() {
Network network = Network.create(NETWORK_ID, "test");
network.setCaseDate(DateTime.parse(CASE_DATE));
network.setCaseDate(ZonedDateTime.parse(CASE_DATE));
Substation substation = network.newSubstation()
.setId(SUBSTATION_ID)
.setCountry(Country.FR)
Expand Down Expand Up @@ -385,7 +385,7 @@ public static Network createNetworkWithTwoWindingsTransformer() {

public static Network createNetworkWithDanglingLine() {
Network network = Network.create(NETWORK_ID, "test");
network.setCaseDate(DateTime.parse(CASE_DATE));
network.setCaseDate(ZonedDateTime.parse(CASE_DATE));
Substation substation = network.newSubstation()
.setId(SUBSTATION_ID)
.setCountry(Country.FR)
Expand Down Expand Up @@ -417,7 +417,7 @@ public static Network createNetworkWithHvdcLine() {

public static Network createNetworkWithHvdcLine(String vsc1Id, String vsc2Id) {
Network network = Network.create(NETWORK_ID, "test");
network.setCaseDate(DateTime.parse(CASE_DATE));
network.setCaseDate(ZonedDateTime.parse(CASE_DATE));
Substation substation1 = network.newSubstation()
.setId(SUBSTATION_1_ID)
.setCountry(Country.FR)
Expand Down Expand Up @@ -519,7 +519,7 @@ public static Network createNetworkWithHvdcLines() {

public static Network createNetworkWithBusbarAndSwitch() {
Network network = Network.create(NETWORK_ID, "test");
network.setCaseDate(DateTime.parse(CASE_DATE));
network.setCaseDate(ZonedDateTime.parse(CASE_DATE));
Substation s = network.newSubstation()
.setId("S")
.setCountry(Country.FR)
Expand Down Expand Up @@ -647,7 +647,7 @@ public static Network createNetworkWithPhaseShiftTransformer() {

public static Network createNetworkWithBridge() {
Network network = NetworkFactory.findDefault().createNetwork(NETWORK_ID, "test");
network.setCaseDate(DateTime.parse("2020-01-01T00:30:00.000+01:00"));
network.setCaseDate(ZonedDateTime.parse("2020-01-01T00:30:00.000+01:00"));

Substation substation = network.newSubstation()
.setId("S")
Expand Down Expand Up @@ -1197,13 +1197,13 @@ public static Network createBusBreakerNetworkWithBranchStatus(String id, String
}

private static void createStatusExtensions(Network network) {
network.getLine("L11").newExtension(BranchStatusAdder.class).withStatus(BranchStatus.Status.PLANNED_OUTAGE).add();
network.getLine("L12").newExtension(BranchStatusAdder.class).withStatus(BranchStatus.Status.FORCED_OUTAGE).add();
network.getLine("L11").newExtension(OperatingStatusAdder.class).withStatus(OperatingStatus.Status.PLANNED_OUTAGE).add();
network.getLine("L12").newExtension(OperatingStatusAdder.class).withStatus(OperatingStatus.Status.FORCED_OUTAGE).add();

network.getTwoWindingsTransformer("T11").newExtension(BranchStatusAdder.class).withStatus(BranchStatus.Status.PLANNED_OUTAGE).add();
network.getTwoWindingsTransformer("T12").newExtension(BranchStatusAdder.class).withStatus(BranchStatus.Status.FORCED_OUTAGE).add();
network.getTwoWindingsTransformer("T11").newExtension(OperatingStatusAdder.class).withStatus(OperatingStatus.Status.PLANNED_OUTAGE).add();
network.getTwoWindingsTransformer("T12").newExtension(OperatingStatusAdder.class).withStatus(OperatingStatus.Status.FORCED_OUTAGE).add();

network.getThreeWindingsTransformer(THREE_WINDING_TRANSFORMER_12_ID).newExtension(BranchStatusAdder.class).withStatus(BranchStatus.Status.FORCED_OUTAGE).add();
network.getThreeWindingsTransformer(THREE_WINDING_TRANSFORMER_12_ID).newExtension(OperatingStatusAdder.class).withStatus(OperatingStatus.Status.FORCED_OUTAGE).add();
}

public static Network createNodeBreakerNetworkWithInternalBranches(String id, String sourceFormat) {
Expand Down Expand Up @@ -1272,10 +1272,10 @@ public static Network createNodeBreakerNetworkWithInternalBranches(String id, St
"T11", null, ConnectablePosition.Direction.TOP);

TwoWindingsTransformer twoWindingsTransformer = network.getTwoWindingsTransformer("T11");
twoWindingsTransformer.getTerminal(Branch.Side.ONE).setP(375);
twoWindingsTransformer.getTerminal(Branch.Side.TWO).setP(375);
twoWindingsTransformer.getTerminal(Branch.Side.ONE).setQ(48);
twoWindingsTransformer.getTerminal(Branch.Side.TWO).setQ(48);
twoWindingsTransformer.getTerminal(TwoSides.ONE).setP(375);
twoWindingsTransformer.getTerminal(TwoSides.TWO).setP(375);
twoWindingsTransformer.getTerminal(TwoSides.ONE).setQ(48);
twoWindingsTransformer.getTerminal(TwoSides.TWO).setQ(48);

createSwitch(vl1, "D27", "D27", SwitchKind.DISCONNECTOR, false, false, false, 20, 27);
createSwitch(vl1, "BR28", "BR28", SwitchKind.BREAKER, false, false, false, 27, 28);
Expand All @@ -1289,10 +1289,10 @@ public static Network createNodeBreakerNetworkWithInternalBranches(String id, St
"T12", null, ConnectablePosition.Direction.TOP);

twoWindingsTransformer = network.getTwoWindingsTransformer("T12");
twoWindingsTransformer.getTerminal(Branch.Side.ONE).setP(375);
twoWindingsTransformer.getTerminal(Branch.Side.TWO).setP(375);
twoWindingsTransformer.getTerminal(Branch.Side.ONE).setQ(48);
twoWindingsTransformer.getTerminal(Branch.Side.TWO).setQ(48);
twoWindingsTransformer.getTerminal(TwoSides.ONE).setP(375);
twoWindingsTransformer.getTerminal(TwoSides.TWO).setP(375);
twoWindingsTransformer.getTerminal(TwoSides.ONE).setQ(48);
twoWindingsTransformer.getTerminal(TwoSides.TWO).setQ(48);

createSwitch(vl1, "D19", "D19", SwitchKind.DISCONNECTOR, false, false, false, 10, 19);
createSwitch(vl1, "BR20", "BR20", SwitchKind.BREAKER, false, false, false, 19, 190);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.powsybl.nad.model.*;
import com.powsybl.nad.utils.iidm.IidmUtils;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -99,16 +100,12 @@ private void visitThreeWindingsTransformer(VoltageLevel vl, ThreeWindingsTransfo
ThreeWtNode tn = new ThreeWtNode(idProvider.createId(thwt), thwt.getId(), thwt.getNameOrId());
graph.addNode(tn);

ThreeWindingsTransformer.Side side;
if (thwt.getLeg1().getTerminal().getVoltageLevel() == vl) {
side = ThreeWindingsTransformer.Side.ONE;
} else if (thwt.getLeg2().getTerminal().getVoltageLevel() == vl) {
side = ThreeWindingsTransformer.Side.TWO;
} else {
side = ThreeWindingsTransformer.Side.THREE;
}
ThreeSides side = Arrays.stream(ThreeSides.values())
.filter(streamedSide -> thwt.getLeg(streamedSide).getTerminal().getVoltageLevel() == vl)
.findFirst()
.orElseThrow(IllegalStateException::new);

for (ThreeWindingsTransformer.Side s : getSidesArray(side)) {
for (ThreeSides s : getSidesArray(side)) {
addThreeWtEdge(graph, thwt, tn, s);
}
}
Expand Down Expand Up @@ -136,17 +133,17 @@ private void visitHvdcConverterStation(HvdcConverterStation<?> converterStation,
return;
}

HvdcLine.Side otherSide = (hvdcLine.getConverterStation1().getId().equals(converterStation.getId()))
? HvdcLine.Side.TWO : HvdcLine.Side.ONE;
TwoSides otherSide = (hvdcLine.getConverterStation1().getId().equals(converterStation.getId()))
? TwoSides.TWO : TwoSides.ONE;

Terminal terminal = converterStation.getTerminal();
Terminal otherSideTerminal = hvdcLine.getConverterStation(otherSide).getTerminal();

addEdge(graph, terminal, otherSideTerminal, hvdcLine, BranchEdge.HVDC_LINE_EDGE, otherSide == HvdcLine.Side.ONE);
addEdge(graph, terminal, otherSideTerminal, hvdcLine, BranchEdge.HVDC_LINE_EDGE, otherSide == TwoSides.ONE);
}

private void addEdge(Graph graph, Branch<?> branch, VoltageLevel vl, String edgeType) {
Branch.Side side = branch.getTerminal(Branch.Side.ONE).getVoltageLevel() == vl ? Branch.Side.ONE : Branch.Side.TWO;
TwoSides side = branch.getTerminal(TwoSides.ONE).getVoltageLevel() == vl ? TwoSides.ONE : TwoSides.TWO;
// check if the edge was not already added (at the other side of the transformer)
if (graph.containsEdge(branch.getId())) {
return;
Expand All @@ -155,7 +152,7 @@ private void addEdge(Graph graph, Branch<?> branch, VoltageLevel vl, String edge
Terminal terminalA = branch.getTerminal(side);
Terminal terminalB = branch.getTerminal(IidmUtils.getOpposite(side));

addEdge(graph, terminalA, terminalB, branch, edgeType, side == Branch.Side.TWO);
addEdge(graph, terminalA, terminalB, branch, edgeType, side == TwoSides.TWO);
}

private void addEdge(Graph graph, Terminal terminalA, Terminal terminalB, Identifiable<?> identifiable, String edgeType, boolean terminalsInReversedOrder) {
Expand All @@ -173,7 +170,7 @@ private void addEdge(Graph graph, Terminal terminalA, Terminal terminalB, Identi
}
}

private void addThreeWtEdge(Graph graph, ThreeWindingsTransformer twt, ThreeWtNode tn, ThreeWindingsTransformer.Side side) {
private void addThreeWtEdge(Graph graph, ThreeWindingsTransformer twt, ThreeWtNode tn, ThreeSides side) {
Terminal terminal = twt.getTerminal(side);
VoltageLevelNode vlNode = getVoltageLevelNode(graph, terminal);
ThreeWtEdge edge = new ThreeWtEdge(idProvider.createId(IidmUtils.get3wtLeg(twt, side)),
Expand Down Expand Up @@ -203,19 +200,11 @@ private VoltageLevelNode getVoltageLevelNode(Graph graph, Terminal terminal) {
.orElseThrow(() -> new PowsyblException("Cannot add edge, corresponding voltage level is unknown: '" + terminal.getVoltageLevel().getId() + "'"));
}

private ThreeWindingsTransformer.Side[] getSidesArray(ThreeWindingsTransformer.Side sideA) {
ThreeWindingsTransformer.Side sideB;
ThreeWindingsTransformer.Side sideC;
if (sideA == ThreeWindingsTransformer.Side.ONE) {
sideB = ThreeWindingsTransformer.Side.TWO;
sideC = ThreeWindingsTransformer.Side.THREE;
} else if (sideA == ThreeWindingsTransformer.Side.TWO) {
sideB = ThreeWindingsTransformer.Side.ONE;
sideC = ThreeWindingsTransformer.Side.THREE;
} else {
sideB = ThreeWindingsTransformer.Side.ONE;
sideC = ThreeWindingsTransformer.Side.TWO;
}
return new ThreeWindingsTransformer.Side[] {sideA, sideB, sideC};
private ThreeSides[] getSidesArray(ThreeSides sideA) {
return new ThreeSides[] {sideA, ThreeSides.valueOf(getNextSideNum(sideA.getNum(), 1)), ThreeSides.valueOf(getNextSideNum(sideA.getNum(), 2))};
}

private int getNextSideNum(int sideNum, int steps) {
return (sideNum + steps + 2) % 3 + 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,26 +138,26 @@ public VlVisitor(Set<VoltageLevel> nextDepthVoltageLevels, Set<VoltageLevel> vis
}

@Override
public void visitLine(Line line, Branch.Side side) {
public void visitLine(Line line, TwoSides side) {
visitBranch(line, side);
}

@Override
public void visitTwoWindingsTransformer(TwoWindingsTransformer twt, Branch.Side side) {
public void visitTwoWindingsTransformer(TwoWindingsTransformer twt, TwoSides side) {
visitBranch(twt, side);
}

@Override
public void visitThreeWindingsTransformer(ThreeWindingsTransformer twt, ThreeWindingsTransformer.Side side) {
if (side == ThreeWindingsTransformer.Side.ONE) {
visitTerminal(twt.getTerminal(ThreeWindingsTransformer.Side.TWO));
visitTerminal(twt.getTerminal(ThreeWindingsTransformer.Side.THREE));
} else if (side == ThreeWindingsTransformer.Side.TWO) {
visitTerminal(twt.getTerminal(ThreeWindingsTransformer.Side.ONE));
visitTerminal(twt.getTerminal(ThreeWindingsTransformer.Side.THREE));
public void visitThreeWindingsTransformer(ThreeWindingsTransformer twt, ThreeSides side) {
if (side == ThreeSides.ONE) {
visitTerminal(twt.getTerminal(ThreeSides.TWO));
visitTerminal(twt.getTerminal(ThreeSides.THREE));
} else if (side == ThreeSides.TWO) {
visitTerminal(twt.getTerminal(ThreeSides.ONE));
visitTerminal(twt.getTerminal(ThreeSides.THREE));
} else {
visitTerminal(twt.getTerminal(ThreeWindingsTransformer.Side.ONE));
visitTerminal(twt.getTerminal(ThreeWindingsTransformer.Side.TWO));
visitTerminal(twt.getTerminal(ThreeSides.ONE));
visitTerminal(twt.getTerminal(ThreeSides.TWO));
}
}

Expand All @@ -166,7 +166,7 @@ public void visitHvdcConverterStation(HvdcConverterStation<?> converterStation)
converterStation.getOtherConverterStation().ifPresent(c -> visitTerminal(c.getTerminal()));
}

private void visitBranch(Branch<?> branch, Branch.Side side) {
private void visitBranch(Branch<?> branch, TwoSides side) {
visitTerminal(branch.getTerminal(IidmUtils.getOpposite(side)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
* 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/.
*/
import com.powsybl.commons.exceptions.UncheckedXmlStreamException;
import com.powsybl.commons.xml.XmlUtil;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

/**
Expand All @@ -32,7 +36,14 @@ public String getElementName() {
}

public BusNodeMetadata read(XMLStreamReader reader) {
return new BusNodeMetadata(readDiagramId(reader), readEquipmentId(reader));
try {
String diagramId = readDiagramId(reader);
String equipmentId = readEquipmentId(reader);
XmlUtil.readEndElementOrThrow(reader);
return new BusNodeMetadata(diagramId, equipmentId);
} catch (XMLStreamException e) {
throw new UncheckedXmlStreamException(e);
}
}
}
}
Loading

0 comments on commit e8ac836

Please sign in to comment.