Skip to content

Commit

Permalink
Bump powsybl-core to 6.1.0-alpha-1
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Dupuy <[email protected]>
  • Loading branch information
flo-dup committed Nov 22, 2023
1 parent 1911606 commit 1240c76
Show file tree
Hide file tree
Showing 66 changed files with 408 additions and 384 deletions.
2 changes: 1 addition & 1 deletion commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-iidm-xml-converter</artifactId>
<artifactId>powsybl-iidm-serde</artifactId>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
package com.powsybl.dynawo.commons;

import com.powsybl.iidm.xml.IidmXmlVersion;
import com.powsybl.iidm.serde.IidmVersion;

import java.util.List;

Expand All @@ -22,7 +22,7 @@ private DynawoConstants() {
/**
* write the network to XIIDM v1.4 because currently Dynawo does not support versions above
*/
public static final String IIDM_VERSION = IidmXmlVersion.V_1_4.toString(".");
public static final String IIDM_VERSION = IidmVersion.V_1_4.toString(".");

public static final String DYNAWO_CMD_NAME = "dynawo";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.powsybl.commons.PowsyblException;
import com.powsybl.computation.*;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.xml.XMLExporter;
import com.powsybl.iidm.serde.XMLExporter;

import java.io.IOException;
import java.io.InputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ public static void update(Network targetNetwork, Network sourceNetwork, boolean

private static void updateHvdcLines(Network targetNetwork, Iterable<HvdcLine> hvdcLines) {
for (HvdcLine sourceHvdcLine : hvdcLines) {
Terminal targetTerminal1 = targetNetwork.getHvdcLine(sourceHvdcLine.getId()).getConverterStation(HvdcLine.Side.ONE).getTerminal();
Terminal targetTerminal2 = targetNetwork.getHvdcLine(sourceHvdcLine.getId()).getConverterStation(HvdcLine.Side.TWO).getTerminal();
Terminal sourceTerminal1 = sourceHvdcLine.getConverterStation(HvdcLine.Side.ONE).getTerminal();
Terminal sourceTerminal2 = sourceHvdcLine.getConverterStation(HvdcLine.Side.TWO).getTerminal();
Terminal targetTerminal1 = targetNetwork.getHvdcLine(sourceHvdcLine.getId()).getConverterStation(TwoSides.ONE).getTerminal();
Terminal targetTerminal2 = targetNetwork.getHvdcLine(sourceHvdcLine.getId()).getConverterStation(TwoSides.TWO).getTerminal();
Terminal sourceTerminal1 = sourceHvdcLine.getConverterStation(TwoSides.ONE).getTerminal();
Terminal sourceTerminal2 = sourceHvdcLine.getConverterStation(TwoSides.TWO).getTerminal();
update(targetTerminal1, sourceTerminal1);
update(targetTerminal2, sourceTerminal2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.powsybl.iidm.network.Load;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.VoltageLevel;
import com.powsybl.iidm.xml.NetworkXml;
import com.powsybl.iidm.serde.NetworkSerDe;

import java.util.EnumMap;
import java.util.List;
Expand All @@ -33,7 +33,7 @@ private LoadsMerger() {
}

public static Network mergeLoads(Network network) throws PowsyblException {
Network mergedLoadsNetwork = NetworkXml.copy(network);
Network mergedLoadsNetwork = NetworkSerDe.copy(network);
mergedLoadsNetwork.getVoltageLevelStream().forEach(LoadsMerger::mergeLoadsInVoltageLevel);
return mergedLoadsNetwork;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,18 @@ private static List<TimelineEntry> read(XMLStreamReader xmlReader) throws XMLStr
while (state == XMLStreamConstants.COMMENT) {
state = xmlReader.next();
}
XmlUtil.readUntilEndElement("timeline", xmlReader, () -> {
if (xmlReader.getLocalName().equals("event")) {
String time = xmlReader.getAttributeValue(null, TIME);
String modelName = xmlReader.getAttributeValue(null, MODEL_NAME);
String message = xmlReader.getAttributeValue(null, MESSAGE);
TimeLineUtil.createEvent(time, modelName, message)
.ifPresent(timeline::add);
XmlUtil.readSubElements(xmlReader, elementName -> {
try {
if (elementName.equals("event")) {
String time = xmlReader.getAttributeValue(null, TIME);
String modelName = xmlReader.getAttributeValue(null, MODEL_NAME);
String message = xmlReader.getAttributeValue(null, MESSAGE);
XmlUtil.readEndElementOrThrow(xmlReader);
TimeLineUtil.createEvent(time, modelName, message)
.ifPresent(timeline::add);
}
} catch (XMLStreamException e) {
throw new UncheckedXmlStreamException(e);
}
});
return timeline;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,35 @@
*/
package com.powsybl.dynawo.commons;

import com.powsybl.commons.test.AbstractConverterTest;
import com.powsybl.commons.test.AbstractSerDeTest;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.xml.NetworkXml;
import com.powsybl.iidm.serde.NetworkSerDe;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Objects;

import static com.powsybl.commons.test.ComparisonUtils.compareTxt;
import static com.powsybl.commons.test.ComparisonUtils.compareXml;

/**
* @author Florian Dupuy {@literal <florian.dupuy at rte-france.com>}
*/
abstract class AbstractDynawoCommonsTest extends AbstractConverterTest {
abstract class AbstractDynawoCommonsTest extends AbstractSerDeTest {

protected void compare(String expectedIidmResource, Network actual) throws IOException {
InputStream expected = Objects.requireNonNull(getClass().getResourceAsStream(expectedIidmResource));
compareTxt(expected, getInputStream(actual, tmpDir.resolve("actual.xiidm")));
compareXml(expected, getInputStream(actual, tmpDir.resolve("actual.xiidm")));
}

protected void compare(Network expected, Network actual) throws IOException {
compareTxt(getInputStream(expected, tmpDir.resolve("expected.xiidm")),
compareXml(getInputStream(expected, tmpDir.resolve("expected.xiidm")),
getInputStream(actual, tmpDir.resolve("actual.xiidm")));
}

private InputStream getInputStream(Network n, Path path) throws IOException {
NetworkXml.write(n, path);
NetworkSerDe.write(n, path);
return Files.newInputStream(path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
package com.powsybl.dynawo.commons;

import com.powsybl.commons.PowsyblException;
import com.powsybl.commons.test.AbstractConverterTest;
import org.junit.jupiter.api.Test;

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

/**
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
*/
class DynawoVersionTest extends AbstractConverterTest {
class DynawoVersionTest {

private static final DynawoVersion DV_MIN = new DynawoVersion(1, 3, 0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import com.powsybl.dynawo.commons.loadmerge.LoadsMerger;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.test.FourSubstationsNodeBreakerFactory;
import com.powsybl.iidm.xml.ExportOptions;
import com.powsybl.iidm.xml.NetworkXml;
import com.powsybl.iidm.serde.ExportOptions;
import com.powsybl.iidm.serde.NetworkSerDe;
import org.junit.jupiter.api.Test;

import java.io.IOException;
Expand All @@ -24,7 +24,7 @@ class NetworkResultsUpdaterTest extends AbstractDynawoCommonsTest {
@Test
void testUpdateWithoutMergeLoads() throws IOException {
Network expected = TestNetworkFactory.createMultiBusesVoltageLevelNetwork();
Network actual = NetworkXml.copy(expected);
Network actual = NetworkSerDe.copy(expected);
reset(actual);
NetworkResultsUpdater.update(actual, expected, false);
compare(expected, actual);
Expand All @@ -33,15 +33,15 @@ void testUpdateWithoutMergeLoads() throws IOException {
@Test
void testUpdateWithMergeLoads() throws IOException {
Network expected = TestNetworkFactory.createMultiBusesVoltageLevelNetwork();
Network actual = NetworkXml.copy(expected);
Network actual = NetworkSerDe.copy(expected);
NetworkResultsUpdater.update(actual, LoadsMerger.mergeLoads(expected), true);
compare(expected, actual);
}

@Test
void testUpdateNetworkPassingThroughBusBreaker() throws IOException {
Network expected = TestNetworkFactory.createMultiBusesVoltageLevelNetwork();
Network actual = NetworkXml.copy(expected);
Network actual = NetworkSerDe.copy(expected);
reset(actual);

// We assume that the original network will be updated by some analysis tool
Expand All @@ -50,8 +50,8 @@ void testUpdateNetworkPassingThroughBusBreaker() throws IOException {
// is properly updated from the Bus/Breaker "solution" exchanged
// with the external analysis tool
Path pexpectedAsBusBreaker = tmpDir.resolve("expected-as-busbreaker.xiidm");
NetworkXml.write(expected, new ExportOptions().setTopologyLevel(TopologyLevel.BUS_BREAKER), pexpectedAsBusBreaker);
Network expectedBusBreaker = NetworkXml.read(pexpectedAsBusBreaker);
NetworkSerDe.write(expected, new ExportOptions().setTopologyLevel(TopologyLevel.BUS_BREAKER), pexpectedAsBusBreaker);
Network expectedBusBreaker = NetworkSerDe.read(pexpectedAsBusBreaker);
NetworkResultsUpdater.update(actual, expectedBusBreaker, false);

compare(expected, actual);
Expand All @@ -60,7 +60,7 @@ void testUpdateNetworkPassingThroughBusBreaker() throws IOException {
@Test
void testUpdateWithDisconnects() throws IOException {
Network expected = FourSubstationsNodeBreakerFactory.create();
Network actual = NetworkXml.copy(expected);
Network actual = NetworkSerDe.copy(expected);
reset(actual);

// Test with some elements disconnected in the network
Expand Down Expand Up @@ -89,8 +89,8 @@ private static void reset(Network targetNetwork) {
reset(targetDangling.getTerminal());
}
for (HvdcLine targetHvdcLine : targetNetwork.getHvdcLines()) {
reset(targetHvdcLine.getConverterStation(HvdcLine.Side.ONE).getTerminal());
reset(targetHvdcLine.getConverterStation(HvdcLine.Side.TWO).getTerminal());
reset(targetHvdcLine.getConverterStation(TwoSides.ONE).getTerminal());
reset(targetHvdcLine.getConverterStation(TwoSides.TWO).getTerminal());
}
for (TwoWindingsTransformer targetTwoWindingsTransformer : targetNetwork.getTwoWindingsTransformers()) {
reset(targetTwoWindingsTransformer.getTerminal1());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
package com.powsybl.dynawo.commons;

import com.powsybl.iidm.network.*;
import org.joda.time.DateTime;

import java.time.ZonedDateTime;
import java.util.List;

/**
Expand All @@ -22,7 +22,7 @@ private TestNetworkFactory() {

static Network createMultiBusesVoltageLevelNetwork() {
Network network = Network.create("multiBusesVl", "test")
.setCaseDate(DateTime.parse("2023-02-17T05:41:11.194+01:00"));
.setCaseDate(ZonedDateTime.parse("2023-02-17T05:41:11.194+01:00"));
Substation s = network.newSubstation().setId("substation").add();

VoltageLevel vl1 = s.newVoltageLevel().setId("vl1").setNominalV(250).setTopologyKind(TopologyKind.NODE_BREAKER).add();
Expand Down Expand Up @@ -70,7 +70,7 @@ static Network createMultiBusesVoltageLevelNetwork() {
*/
static Network createMultiLoadsBusesNetwork(List<LoadState> loadStates) {
Network network = Network.create("multiLoads", "test")
.setCaseDate(DateTime.parse("2023-02-17T05:41:11.194+01:00"));
.setCaseDate(ZonedDateTime.parse("2023-02-17T05:41:11.194+01:00"));
Substation s = network.newSubstation().setId("substation").add();

// First node breaker voltage level
Expand Down
2 changes: 1 addition & 1 deletion dynaflow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-iidm-xml-converter</artifactId>
<artifactId>powsybl-iidm-serde</artifactId>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.powsybl.dynawo.commons.timeline.TimelineEntry;
import com.powsybl.dynawo.commons.timeline.XmlTimeLineParser;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.xml.NetworkXml;
import com.powsybl.iidm.serde.NetworkSerDe;
import com.powsybl.loadflow.LoadFlowParameters;
import com.powsybl.loadflow.LoadFlowProvider;
import com.powsybl.loadflow.LoadFlowResult;
Expand Down Expand Up @@ -187,7 +187,7 @@ public LoadFlowResult after(Path workingDir, ExecutionReport report) {
boolean status = true;
Path outputNetworkFile = workingDir.resolve("outputs").resolve("finalState").resolve(OUTPUT_IIDM_FILENAME);
if (Files.exists(outputNetworkFile)) {
NetworkResultsUpdater.update(network, NetworkXml.read(outputNetworkFile), dynaFlowParameters.isMergeLoads());
NetworkResultsUpdater.update(network, NetworkSerDe.read(outputNetworkFile), dynaFlowParameters.isMergeLoads());
} else {
status = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,49 @@ public static List<LimitViolation> read(Network network, InputStream is) {
state = reader.next();
}

XmlUtil.readUntilEndElement(CONSTRAINTS_ELEMENT_NAME, reader, () -> {
if (!reader.getLocalName().equals(CONSTRAINT_ELEMENT_NAME)) {
throw new AssertionError();
XmlUtil.readSubElements(reader, elementName -> {
try {
if (!elementName.equals(CONSTRAINT_ELEMENT_NAME)) {
throw new PowsyblException("Unknown element name '" + elementName + "' in constraints file");
}
String name = reader.getAttributeValue(null, MODEL_NAME);
reader.getAttributeValue(null, DESCRIPTION); // description: unused
reader.getAttributeValue(null, TYPE); // type: unused
String kind = reader.getAttributeValue(null, KIND);
double limit = readDouble(reader, LIMIT);
double value = readDouble(reader, VALUE);
Integer side = readInteger(reader, SIDE);
Integer acceptableDuration = readInteger(reader, ACCEPTABLE_DURATION, Integer.MAX_VALUE);
XmlUtil.readEndElementOrThrow(reader);

getLimitViolation(network, name, kind, limit, 1f, value, side, acceptableDuration)
.ifPresent(lvRead -> addOrDismiss(lvRead, limitViolations));

} catch (XMLStreamException e) {
throw new UncheckedXmlStreamException(e);
}
String name = reader.getAttributeValue(null, MODEL_NAME);
reader.getAttributeValue(null, DESCRIPTION); // description: unused
reader.getAttributeValue(null, TYPE); // type: unused
String kind = reader.getAttributeValue(null, KIND);
double limit = XmlUtil.readOptionalDoubleAttribute(reader, LIMIT);
double value = XmlUtil.readOptionalDoubleAttribute(reader, VALUE);
Integer side = XmlUtil.readOptionalIntegerAttribute(reader, SIDE);
Integer acceptableDuration = XmlUtil.readOptionalIntegerAttribute(reader, ACCEPTABLE_DURATION, Integer.MAX_VALUE);

getLimitViolation(network, name, kind, limit, 1f, value, side, acceptableDuration)
.ifPresent(lvRead -> addOrDismiss(lvRead, limitViolations));
});
return limitViolations;
} catch (XMLStreamException e) {
throw new UncheckedXmlStreamException(e);
}
}

private static double readDouble(XMLStreamReader reader, String name) {
String doubleStr = reader.getAttributeValue(null, name);
return doubleStr != null ? Double.parseDouble(doubleStr) : Double.NaN;
}

private static Integer readInteger(XMLStreamReader reader, String name) {
String intStr = reader.getAttributeValue(null, name);
return intStr != null ? Integer.valueOf(intStr) : null;
}

private static int readInteger(XMLStreamReader reader, String name, int defaultValue) {
String intStr = reader.getAttributeValue(null, name);
return intStr != null ? Integer.parseInt(intStr) : defaultValue;
}

private static void addOrDismiss(LimitViolation lvRead, List<LimitViolation> limitViolations) {
LimitViolationComparator comparator = new LimitViolationComparator();
limitViolations.stream().filter(lv -> comparator.compare(lvRead, lv) == 0).findFirst()
Expand All @@ -117,7 +138,7 @@ private static Optional<LimitViolation> getLimitViolation(Network network, Strin
.map(identifiable -> new LimitViolation(
identifiable.getId(), identifiable.getOptionalName().orElse(null),
toLimitViolationType(kind), kind, acceptableDuration,
limit, limitReduction, value, toBranchSide(side)));
limit, limitReduction, value, toThreeSides(side)));
}

private static Optional<Identifiable<?>> getLimitViolationIdentifiable(Network network, String name) {
Expand All @@ -142,16 +163,16 @@ private static Optional<Identifiable<?>> getLimitViolationIdentifiable(Network n
}
}

private static Branch.Side toBranchSide(Integer side) {
private static ThreeSides toThreeSides(Integer side) {
if (side == null) {
return null;
} else if (side == 1) {
return Branch.Side.ONE;
} else if (side == 2) {
return Branch.Side.TWO;
} else {
return null;
}
return switch (side) {
case 1 -> ThreeSides.ONE;
case 2 -> ThreeSides.TWO;
case 3 -> ThreeSides.THREE;
default -> null;
};
}

private static LimitViolationType toLimitViolationType(String kind) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.google.common.jimfs.Jimfs;
import com.powsybl.commons.config.InMemoryPlatformConfig;
import com.powsybl.commons.config.MapModuleConfig;
import com.powsybl.commons.test.AbstractConverterTest;
import com.powsybl.commons.test.AbstractSerDeTest;
import com.powsybl.dynaflow.DynaFlowConstants.ActivePowerCompensation;
import com.powsybl.dynaflow.DynaFlowConstants.OutputTypes;
import com.powsybl.dynaflow.DynaFlowConstants.StartingPointMode;
Expand All @@ -34,7 +34,7 @@
*
* @author Guillaume Pernin {@literal <guillaume.pernin at rte-france.com>}
*/
class DynaFlowParametersTest extends AbstractConverterTest {
class DynaFlowParametersTest extends AbstractSerDeTest {

private InMemoryPlatformConfig platformConfig;

Expand Down
Loading

0 comments on commit 1240c76

Please sign in to comment.