From 1240c766ef51778f4dd2e7ed30fff69803959eae Mon Sep 17 00:00:00 2001 From: Florian Dupuy Date: Wed, 22 Nov 2023 16:35:30 +0100 Subject: [PATCH] Bump powsybl-core to 6.1.0-alpha-1 Signed-off-by: Florian Dupuy --- commons/pom.xml | 2 +- .../dynawo/commons/DynawoConstants.java | 4 +- .../powsybl/dynawo/commons/DynawoUtil.java | 2 +- .../dynawo/commons/NetworkResultsUpdater.java | 8 +-- .../dynawo/commons/loadmerge/LoadsMerger.java | 4 +- .../commons/timeline/XmlTimeLineParser.java | 19 ++++-- .../commons/AbstractDynawoCommonsTest.java | 14 ++-- .../dynawo/commons/DynawoVersionTest.java | 3 +- .../commons/NetworkResultsUpdaterTest.java | 20 +++--- .../dynawo/commons/TestNetworkFactory.java | 6 +- dynaflow/pom.xml | 2 +- .../powsybl/dynaflow/DynaFlowProvider.java | 4 +- .../dynaflow/xml/ConstraintsReader.java | 65 ++++++++++++------ .../dynaflow/DynaFlowParametersTest.java | 4 +- .../dynaflow/DynaFlowProviderTest.java | 14 ++-- .../DynaFlowSecurityAnalysisTest.java | 11 +-- .../JsonDynaFlowParametersSerializerTest.java | 4 +- ...urrentLimitAutomatonGroovyExtension.groovy | 10 +-- ...itTwoLevelsAutomatonGroovyExtension.groovy | 14 ++-- .../EventDisconnectionGroovyExtension.groovy | 3 +- .../models/hvdc/AbstractHvdcBuilder.groovy | 11 +-- dynawaltz/pom.xml | 2 +- .../powsybl/dynawaltz/DynaWaltzContext.java | 3 +- .../powsybl/dynawaltz/DynaWaltzProvider.java | 43 +++++------- .../models/AbstractBlackBoxModel.java | 16 ++--- .../com/powsybl/dynawaltz/models/Side.java | 35 ---------- .../automatons/CurrentLimitAutomaton.java | 11 +-- .../CurrentLimitTwoLevelsAutomaton.java | 11 +-- .../models/automatons/QuadripoleModel.java | 4 +- .../DefaultEquipmentConnectionPoint.java | 10 +-- .../buses/EquipmentConnectionPoint.java | 6 +- .../models/events/EventHvdcDisconnection.java | 12 ++-- .../dynawaltz/models/hvdc/AbstractHvdc.java | 15 ++-- .../dynawaltz/models/hvdc/DanglingSide.java | 21 +++--- .../dynawaltz/models/hvdc/DefaultHvdc.java | 6 +- .../dynawaltz/models/hvdc/HvdcModel.java | 4 +- .../powsybl/dynawaltz/models/hvdc/HvdcP.java | 7 +- .../dynawaltz/models/hvdc/HvdcPDangling.java | 9 ++- .../dynawaltz/models/hvdc/HvdcVsc.java | 6 +- .../models/hvdc/HvdcVscDangling.java | 6 +- .../dynawaltz/models/lines/DefaultLine.java | 7 +- .../dynawaltz/models/lines/StandardLine.java | 13 ++-- .../macroconnections/MacroConnector.java | 7 +- .../transformers/DefaultTransformer.java | 7 +- .../transformers/TransformerFixedRatio.java | 16 ++--- .../{SideConverter.java => SideUtils.java} | 21 +++--- ...l.java => AbstractXmlDynawaltzWriter.java} | 35 ++++++---- .../com/powsybl/dynawaltz/xml/CurvesXml.java | 14 ++-- .../com/powsybl/dynawaltz/xml/DydXml.java | 14 ++-- .../com/powsybl/dynawaltz/xml/JobsXml.java | 14 ++-- .../powsybl/dynawaltz/xml/ParametersXml.java | 68 ++++++++++++------- .../dynawaltz/xml/XmlDynawaltzWriter.java | 21 ++++++ .../dynawaltz/DynaWaltzParametersTest.java | 4 +- .../dynawaltz/DynaWaltzProviderTest.java | 20 +++--- .../models/lines/StandardLineTest.java | 3 +- .../xml/AbstractDynamicModelXmlTest.java | 4 +- ...stractParametrizedDynamicModelXmlTest.java | 4 +- .../xml/CurrentLimitModelXmlTest.java | 8 +-- .../CurrentLimitTwoLevelsModelXmlTest.java | 4 +- .../xml/DisconnectHvdcEventXmlTest.java | 6 +- .../xml/DisconnectionExceptionXmlTest.java | 18 ++--- .../dynawaltz/xml/DynaWaltzTestUtil.java | 9 ++- .../powsybl/dynawaltz/xml/HvdcXmlTest.java | 6 +- .../dynawaltz/xml/ParametersXmlTest.java | 3 +- .../com/powsybl/dynawo/it/DynaWaltzTest.java | 13 ++-- pom.xml | 2 +- 66 files changed, 408 insertions(+), 384 deletions(-) delete mode 100644 dynawaltz/src/main/java/com/powsybl/dynawaltz/models/Side.java rename dynawaltz/src/main/java/com/powsybl/dynawaltz/models/utils/{SideConverter.java => SideUtils.java} (54%) rename dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/{XmlUtil.java => AbstractXmlDynawaltzWriter.java} (54%) create mode 100644 dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/XmlDynawaltzWriter.java diff --git a/commons/pom.xml b/commons/pom.xml index eaade231c..68c1efed5 100644 --- a/commons/pom.xml +++ b/commons/pom.xml @@ -51,7 +51,7 @@ com.powsybl - powsybl-iidm-xml-converter + powsybl-iidm-serde com.powsybl diff --git a/commons/src/main/java/com/powsybl/dynawo/commons/DynawoConstants.java b/commons/src/main/java/com/powsybl/dynawo/commons/DynawoConstants.java index 25474862e..9e1eebdd9 100644 --- a/commons/src/main/java/com/powsybl/dynawo/commons/DynawoConstants.java +++ b/commons/src/main/java/com/powsybl/dynawo/commons/DynawoConstants.java @@ -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; @@ -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"; diff --git a/commons/src/main/java/com/powsybl/dynawo/commons/DynawoUtil.java b/commons/src/main/java/com/powsybl/dynawo/commons/DynawoUtil.java index 3cf6da070..681076e6b 100644 --- a/commons/src/main/java/com/powsybl/dynawo/commons/DynawoUtil.java +++ b/commons/src/main/java/com/powsybl/dynawo/commons/DynawoUtil.java @@ -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; diff --git a/commons/src/main/java/com/powsybl/dynawo/commons/NetworkResultsUpdater.java b/commons/src/main/java/com/powsybl/dynawo/commons/NetworkResultsUpdater.java index ec6cca474..520cf1102 100644 --- a/commons/src/main/java/com/powsybl/dynawo/commons/NetworkResultsUpdater.java +++ b/commons/src/main/java/com/powsybl/dynawo/commons/NetworkResultsUpdater.java @@ -78,10 +78,10 @@ public static void update(Network targetNetwork, Network sourceNetwork, boolean private static void updateHvdcLines(Network targetNetwork, Iterable 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); } diff --git a/commons/src/main/java/com/powsybl/dynawo/commons/loadmerge/LoadsMerger.java b/commons/src/main/java/com/powsybl/dynawo/commons/loadmerge/LoadsMerger.java index dfb5de9e3..5b17b9bb1 100644 --- a/commons/src/main/java/com/powsybl/dynawo/commons/loadmerge/LoadsMerger.java +++ b/commons/src/main/java/com/powsybl/dynawo/commons/loadmerge/LoadsMerger.java @@ -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; @@ -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; } diff --git a/commons/src/main/java/com/powsybl/dynawo/commons/timeline/XmlTimeLineParser.java b/commons/src/main/java/com/powsybl/dynawo/commons/timeline/XmlTimeLineParser.java index fe697a08b..33d344983 100644 --- a/commons/src/main/java/com/powsybl/dynawo/commons/timeline/XmlTimeLineParser.java +++ b/commons/src/main/java/com/powsybl/dynawo/commons/timeline/XmlTimeLineParser.java @@ -75,13 +75,18 @@ private static List 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; diff --git a/commons/src/test/java/com/powsybl/dynawo/commons/AbstractDynawoCommonsTest.java b/commons/src/test/java/com/powsybl/dynawo/commons/AbstractDynawoCommonsTest.java index 8ac2f3dda..d284f684d 100644 --- a/commons/src/test/java/com/powsybl/dynawo/commons/AbstractDynawoCommonsTest.java +++ b/commons/src/test/java/com/powsybl/dynawo/commons/AbstractDynawoCommonsTest.java @@ -7,9 +7,9 @@ */ 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; @@ -17,25 +17,25 @@ 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 } */ -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); } } diff --git a/commons/src/test/java/com/powsybl/dynawo/commons/DynawoVersionTest.java b/commons/src/test/java/com/powsybl/dynawo/commons/DynawoVersionTest.java index 7526d49a9..4abbb8fa8 100644 --- a/commons/src/test/java/com/powsybl/dynawo/commons/DynawoVersionTest.java +++ b/commons/src/test/java/com/powsybl/dynawo/commons/DynawoVersionTest.java @@ -8,7 +8,6 @@ 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.*; @@ -16,7 +15,7 @@ /** * @author Laurent Issertial {@literal } */ -class DynawoVersionTest extends AbstractConverterTest { +class DynawoVersionTest { private static final DynawoVersion DV_MIN = new DynawoVersion(1, 3, 0); diff --git a/commons/src/test/java/com/powsybl/dynawo/commons/NetworkResultsUpdaterTest.java b/commons/src/test/java/com/powsybl/dynawo/commons/NetworkResultsUpdaterTest.java index 50a2ec135..2f36f3d50 100644 --- a/commons/src/test/java/com/powsybl/dynawo/commons/NetworkResultsUpdaterTest.java +++ b/commons/src/test/java/com/powsybl/dynawo/commons/NetworkResultsUpdaterTest.java @@ -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; @@ -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); @@ -33,7 +33,7 @@ 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); } @@ -41,7 +41,7 @@ void testUpdateWithMergeLoads() throws IOException { @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 @@ -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); @@ -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 @@ -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()); diff --git a/commons/src/test/java/com/powsybl/dynawo/commons/TestNetworkFactory.java b/commons/src/test/java/com/powsybl/dynawo/commons/TestNetworkFactory.java index b3588c79c..51bf19394 100644 --- a/commons/src/test/java/com/powsybl/dynawo/commons/TestNetworkFactory.java +++ b/commons/src/test/java/com/powsybl/dynawo/commons/TestNetworkFactory.java @@ -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; /** @@ -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(); @@ -70,7 +70,7 @@ static Network createMultiBusesVoltageLevelNetwork() { */ static Network createMultiLoadsBusesNetwork(List 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 diff --git a/dynaflow/pom.xml b/dynaflow/pom.xml index b66ead0ca..791b35d8c 100644 --- a/dynaflow/pom.xml +++ b/dynaflow/pom.xml @@ -28,7 +28,7 @@ com.powsybl - powsybl-iidm-xml-converter + powsybl-iidm-serde com.powsybl diff --git a/dynaflow/src/main/java/com/powsybl/dynaflow/DynaFlowProvider.java b/dynaflow/src/main/java/com/powsybl/dynaflow/DynaFlowProvider.java index a5cfa4986..260795236 100644 --- a/dynaflow/src/main/java/com/powsybl/dynaflow/DynaFlowProvider.java +++ b/dynaflow/src/main/java/com/powsybl/dynaflow/DynaFlowProvider.java @@ -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; @@ -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; } diff --git a/dynaflow/src/main/java/com/powsybl/dynaflow/xml/ConstraintsReader.java b/dynaflow/src/main/java/com/powsybl/dynaflow/xml/ConstraintsReader.java index c46b29f14..8ba676199 100644 --- a/dynaflow/src/main/java/com/powsybl/dynaflow/xml/ConstraintsReader.java +++ b/dynaflow/src/main/java/com/powsybl/dynaflow/xml/ConstraintsReader.java @@ -72,21 +72,27 @@ public static List 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) { @@ -94,6 +100,21 @@ public static List read(Network network, InputStream is) { } } + 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 limitViolations) { LimitViolationComparator comparator = new LimitViolationComparator(); limitViolations.stream().filter(lv -> comparator.compare(lvRead, lv) == 0).findFirst() @@ -117,7 +138,7 @@ private static Optional 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> getLimitViolationIdentifiable(Network network, String name) { @@ -142,16 +163,16 @@ private static Optional> 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) { diff --git a/dynaflow/src/test/java/com/powsybl/dynaflow/DynaFlowParametersTest.java b/dynaflow/src/test/java/com/powsybl/dynaflow/DynaFlowParametersTest.java index 022543290..52347e736 100644 --- a/dynaflow/src/test/java/com/powsybl/dynaflow/DynaFlowParametersTest.java +++ b/dynaflow/src/test/java/com/powsybl/dynaflow/DynaFlowParametersTest.java @@ -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; @@ -34,7 +34,7 @@ * * @author Guillaume Pernin {@literal } */ -class DynaFlowParametersTest extends AbstractConverterTest { +class DynaFlowParametersTest extends AbstractSerDeTest { private InMemoryPlatformConfig platformConfig; diff --git a/dynaflow/src/test/java/com/powsybl/dynaflow/DynaFlowProviderTest.java b/dynaflow/src/test/java/com/powsybl/dynaflow/DynaFlowProviderTest.java index b45e099e1..e04371357 100644 --- a/dynaflow/src/test/java/com/powsybl/dynaflow/DynaFlowProviderTest.java +++ b/dynaflow/src/test/java/com/powsybl/dynaflow/DynaFlowProviderTest.java @@ -7,14 +7,14 @@ package com.powsybl.dynaflow; import com.powsybl.commons.PowsyblException; -import com.powsybl.commons.test.AbstractConverterTest; +import com.powsybl.commons.test.AbstractSerDeTest; import com.powsybl.computation.ComputationManager; import com.powsybl.computation.local.LocalCommandExecutor; import com.powsybl.computation.local.LocalComputationConfig; import com.powsybl.computation.local.LocalComputationManager; import com.powsybl.dynawo.commons.DynawoConstants; import com.powsybl.iidm.network.*; -import com.powsybl.iidm.xml.NetworkXml; +import com.powsybl.iidm.serde.NetworkSerDe; import com.powsybl.loadflow.LoadFlow; import com.powsybl.loadflow.LoadFlowParameters; import com.powsybl.loadflow.LoadFlowResult; @@ -40,7 +40,7 @@ /** * @author Guillaume Pernin {@literal } */ -class DynaFlowProviderTest extends AbstractConverterTest { +class DynaFlowProviderTest extends AbstractSerDeTest { private Path homeDir; private DynaFlowConfig config; @@ -137,7 +137,7 @@ void testWithoutMergeLoads() throws Exception { assertTrue(result.isOk()); InputStream pReferenceOutput = getClass().getResourceAsStream("/output.xiidm"); - Network expectedNetwork = NetworkXml.read(pReferenceOutput); + Network expectedNetwork = NetworkSerDe.read(pReferenceOutput); compare(expectedNetwork, network); } @@ -158,7 +158,7 @@ void testWithMergeLoads() throws Exception { assertTrue(result.isOk()); InputStream pReferenceOutput = getClass().getResourceAsStream("/output.xiidm"); - Network expectedNetwork = NetworkXml.read(pReferenceOutput); + Network expectedNetwork = NetworkSerDe.read(pReferenceOutput); compare(expectedNetwork, network); } @@ -217,9 +217,9 @@ private void compare(Network expected, Network actual) throws IOException { assertNotNull(pexpected); Path pactual = tmpDir.resolve("actual.xiidm"); assertNotNull(pactual); - NetworkXml.write(expected, pexpected); + NetworkSerDe.write(expected, pexpected); actual.setCaseDate(expected.getCaseDate()); - NetworkXml.write(actual, pactual); + NetworkSerDe.write(actual, pactual); compareXml(Files.newInputStream(pexpected), Files.newInputStream(pactual)); } diff --git a/dynaflow/src/test/java/com/powsybl/dynaflow/DynaFlowSecurityAnalysisTest.java b/dynaflow/src/test/java/com/powsybl/dynaflow/DynaFlowSecurityAnalysisTest.java index c20d88729..60d6c4910 100644 --- a/dynaflow/src/test/java/com/powsybl/dynaflow/DynaFlowSecurityAnalysisTest.java +++ b/dynaflow/src/test/java/com/powsybl/dynaflow/DynaFlowSecurityAnalysisTest.java @@ -7,7 +7,7 @@ package com.powsybl.dynaflow; import com.powsybl.commons.PowsyblException; -import com.powsybl.commons.test.AbstractConverterTest; +import com.powsybl.commons.test.AbstractSerDeTest; import com.powsybl.computation.ComputationManager; import com.powsybl.computation.local.LocalCommandExecutor; import com.powsybl.computation.local.LocalComputationConfig; @@ -22,7 +22,6 @@ import com.powsybl.security.SecurityAnalysisReport; import com.powsybl.security.SecurityAnalysisResult; import com.powsybl.security.json.SecurityAnalysisResultSerializer; -import org.joda.time.DateTime; import org.junit.jupiter.api.Test; import java.io.IOException; @@ -31,6 +30,7 @@ import java.io.UncheckedIOException; import java.nio.file.Files; import java.nio.file.Path; +import java.time.ZonedDateTime; import java.util.List; import java.util.Map; import java.util.Objects; @@ -40,12 +40,13 @@ import static com.powsybl.commons.test.ComparisonUtils.compareXml; import static com.powsybl.dynaflow.DynaFlowConstants.DYNAFLOW_NAME; import static com.powsybl.dynaflow.DynaFlowConstants.IIDM_FILENAME; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * @author Marcos de Miguel {@literal } */ -class DynaFlowSecurityAnalysisTest extends AbstractConverterTest { +class DynaFlowSecurityAnalysisTest extends AbstractSerDeTest { private static class LocalCommandExecutorMock extends AbstractLocalCommandExecutor { @@ -142,7 +143,7 @@ void testCallingBadVersionDynawo() throws IOException { private static Network buildNetwork() { Network network = EurostagTutorialExample1Factory.create(); - network.setCaseDate(DateTime.parse("2023-03-23T16:40:48.060+01:00")); + network.setCaseDate(ZonedDateTime.parse("2023-03-23T16:40:48.060+01:00")); // Changing the network for having some pre-contingencies violations network.getBusBreakerView().getBus("NHV1").setV(380.0); diff --git a/dynaflow/src/test/java/com/powsybl/dynaflow/json/JsonDynaFlowParametersSerializerTest.java b/dynaflow/src/test/java/com/powsybl/dynaflow/json/JsonDynaFlowParametersSerializerTest.java index 58dc5f866..fcc5c4982 100644 --- a/dynaflow/src/test/java/com/powsybl/dynaflow/json/JsonDynaFlowParametersSerializerTest.java +++ b/dynaflow/src/test/java/com/powsybl/dynaflow/json/JsonDynaFlowParametersSerializerTest.java @@ -6,8 +6,8 @@ */ package com.powsybl.dynaflow.json; -import com.powsybl.commons.test.AbstractConverterTest; import com.powsybl.commons.config.InMemoryPlatformConfig; +import com.powsybl.commons.test.AbstractSerDeTest; import com.powsybl.dynaflow.DynaFlowConstants; import com.powsybl.dynaflow.DynaFlowParameters; import com.powsybl.loadflow.LoadFlowParameters; @@ -25,7 +25,7 @@ * * @author Guillaume Pernin {@literal } */ -class JsonDynaFlowParametersSerializerTest extends AbstractConverterTest { +class JsonDynaFlowParametersSerializerTest extends AbstractSerDeTest { @Test void testDeserialize() { diff --git a/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/automatons/CurrentLimitAutomatonGroovyExtension.groovy b/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/automatons/CurrentLimitAutomatonGroovyExtension.groovy index a63db5d7d..20da99d6f 100644 --- a/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/automatons/CurrentLimitAutomatonGroovyExtension.groovy +++ b/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/automatons/CurrentLimitAutomatonGroovyExtension.groovy @@ -13,11 +13,11 @@ import com.powsybl.dynamicsimulation.groovy.DynamicModelGroovyExtension import com.powsybl.dynawaltz.dsl.AbstractPureDynamicGroovyExtension import com.powsybl.dynawaltz.dsl.DslEquipment import com.powsybl.dynawaltz.dsl.builders.AbstractPureDynamicModelBuilder -import com.powsybl.dynawaltz.models.Side + import com.powsybl.dynawaltz.models.automatons.CurrentLimitAutomaton -import com.powsybl.dynawaltz.models.utils.SideConverter import com.powsybl.iidm.network.Branch import com.powsybl.iidm.network.Network +import com.powsybl.iidm.network.TwoSides /** * An implementation of {@link DynamicModelGroovyExtension} that adds the
CurrentLimitAutomaton
keyword to the DSL @@ -43,7 +43,7 @@ class CurrentLimitAutomatonGroovyExtension extends AbstractPureDynamicGroovyExte static class CurrentLimitAutomatonBuilder extends AbstractPureDynamicModelBuilder { protected final DslEquipment iMeasurement - protected Side iMeasurementSide + protected TwoSides iMeasurementSide protected final DslEquipment controlledEquipment CurrentLimitAutomatonBuilder(Network network, String lib) { @@ -56,8 +56,8 @@ class CurrentLimitAutomatonGroovyExtension extends AbstractPureDynamicGroovyExte iMeasurement.addEquipment(staticId, network::getBranch) } - void iMeasurementSide(Branch.Side side) { - this.iMeasurementSide = SideConverter.convert(side) + void iMeasurementSide(TwoSides side) { + this.iMeasurementSide = side } void controlledQuadripole(String staticId) { diff --git a/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/automatons/CurrentLimitTwoLevelsAutomatonGroovyExtension.groovy b/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/automatons/CurrentLimitTwoLevelsAutomatonGroovyExtension.groovy index 289abdcf1..381489fcf 100644 --- a/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/automatons/CurrentLimitTwoLevelsAutomatonGroovyExtension.groovy +++ b/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/automatons/CurrentLimitTwoLevelsAutomatonGroovyExtension.groovy @@ -8,16 +8,16 @@ package com.powsybl.dynawaltz.dsl.automatons import com.google.auto.service.AutoService -import com.powsybl.dsl.DslException import com.powsybl.dynamicsimulation.DynamicModel import com.powsybl.dynamicsimulation.groovy.DynamicModelGroovyExtension import com.powsybl.dynawaltz.dsl.AbstractPureDynamicGroovyExtension import com.powsybl.dynawaltz.dsl.DslEquipment -import com.powsybl.dynawaltz.models.Side + import com.powsybl.dynawaltz.models.automatons.CurrentLimitTwoLevelsAutomaton -import com.powsybl.dynawaltz.models.utils.SideConverter +import com.powsybl.dynawaltz.models.utils.SideUtils import com.powsybl.iidm.network.Branch import com.powsybl.iidm.network.Network +import com.powsybl.iidm.network.TwoSides /** * @author Laurent Issertial {@literal } @@ -41,7 +41,7 @@ class CurrentLimitTwoLevelsAutomatonGroovyExtension extends AbstractPureDynamicG static class CurrentLimitAutomatonTwoLevelBuilder extends CurrentLimitAutomatonGroovyExtension.CurrentLimitAutomatonBuilder { protected final DslEquipment iMeasurement2 - protected Side iMeasurement2Side + protected TwoSides iMeasurement2Side CurrentLimitAutomatonTwoLevelBuilder(Network network, String lib) { super(network, lib) @@ -52,7 +52,7 @@ class CurrentLimitTwoLevelsAutomatonGroovyExtension extends AbstractPureDynamicG iMeasurement(staticId) } - void iMeasurement1Side(Branch.Side side) { + void iMeasurement1Side(TwoSides side) { iMeasurementSide(side) } @@ -60,8 +60,8 @@ class CurrentLimitTwoLevelsAutomatonGroovyExtension extends AbstractPureDynamicG iMeasurement2.addEquipment(staticId, network::getBranch) } - void iMeasurement2Side(Branch.Side side) { - this.iMeasurement2Side = SideConverter.convert(side) + void iMeasurement2Side(TwoSides side) { + this.iMeasurement2Side = SideUtils.convert(side) } @Override diff --git a/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/events/EventDisconnectionGroovyExtension.groovy b/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/events/EventDisconnectionGroovyExtension.groovy index 82d165476..b68f65872 100644 --- a/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/events/EventDisconnectionGroovyExtension.groovy +++ b/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/events/EventDisconnectionGroovyExtension.groovy @@ -22,6 +22,7 @@ import com.powsybl.iidm.network.HvdcLine import com.powsybl.iidm.network.Identifiable import com.powsybl.iidm.network.IdentifiableType import com.powsybl.iidm.network.Network +import com.powsybl.iidm.network.TwoSides /** * @author Laurent Issertial {@literal } @@ -58,7 +59,7 @@ class EventDisconnectionGroovyExtension extends AbstractPureDynamicGroovyExtensi super(network, new DslEquipment("Disconnectable equipment"), tag) } - void disconnectOnly(Branch.Side side) { + void disconnectOnly(TwoSides side) { disconnectSide = true switch (side) { case Branch.Side.ONE : diff --git a/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/models/hvdc/AbstractHvdcBuilder.groovy b/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/models/hvdc/AbstractHvdcBuilder.groovy index b166a9df8..69be7f0ab 100644 --- a/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/models/hvdc/AbstractHvdcBuilder.groovy +++ b/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/models/hvdc/AbstractHvdcBuilder.groovy @@ -9,26 +9,27 @@ package com.powsybl.dynawaltz.dsl.models.hvdc import com.powsybl.dynawaltz.dsl.EquipmentConfig import com.powsybl.dynawaltz.dsl.builders.AbstractEquipmentModelBuilder -import com.powsybl.dynawaltz.models.Side -import com.powsybl.dynawaltz.models.utils.SideConverter + +import com.powsybl.dynawaltz.models.utils.SideUtils import com.powsybl.iidm.network.Branch import com.powsybl.iidm.network.HvdcLine import com.powsybl.iidm.network.IdentifiableType import com.powsybl.iidm.network.Network +import com.powsybl.iidm.network.TwoSides /** * @author Laurent Issertial {@literal } */ abstract class AbstractHvdcBuilder extends AbstractEquipmentModelBuilder { - protected Side danglingSide + protected TwoSides danglingSide AbstractHvdcBuilder(Network network, EquipmentConfig equipmentConfig) { super(network, equipmentConfig, IdentifiableType.HVDC_LINE) } - void dangling(Branch.Side danglingSide) { - this.danglingSide = SideConverter.convert(danglingSide) + void dangling(TwoSides danglingSide) { + this.danglingSide = danglingSide } @Override diff --git a/dynawaltz/pom.xml b/dynawaltz/pom.xml index 66da83472..d5e7ea19d 100644 --- a/dynawaltz/pom.xml +++ b/dynawaltz/pom.xml @@ -55,7 +55,7 @@
com.powsybl - powsybl-iidm-xml-converter + powsybl-iidm-serde com.powsybl diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzContext.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzContext.java index 8f214d55d..0b2947820 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzContext.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzContext.java @@ -25,6 +25,7 @@ import com.powsybl.dynawaltz.xml.MacroStaticReference; import com.powsybl.iidm.network.Identifiable; import com.powsybl.iidm.network.Network; +import com.powsybl.iidm.network.TwoSides; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -220,7 +221,7 @@ public String addMacroConnector(String name1, String name2, List return macroConnectorId; } - public String addMacroConnector(String name1, String name2, Side side, List varConnections) { + public String addMacroConnector(String name1, String name2, TwoSides side, List varConnections) { String macroConnectorId = MacroConnector.createMacroConnectorId(name1, name2, side); macroConnectorsMap.computeIfAbsent(macroConnectorId, k -> new MacroConnector(macroConnectorId, varConnections)); return macroConnectorId; diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzProvider.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzProvider.java index 0df2081f7..ea7fabecb 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzProvider.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzProvider.java @@ -8,7 +8,7 @@ import com.google.auto.service.AutoService; import com.powsybl.commons.config.PlatformConfig; -import com.powsybl.commons.exceptions.UncheckedXmlStreamException; +import com.powsybl.commons.reporter.Reporter; import com.powsybl.computation.*; import com.powsybl.dynamicsimulation.*; import com.powsybl.dynawaltz.models.BlackBoxModel; @@ -22,7 +22,7 @@ import com.powsybl.dynawo.commons.PowsyblDynawoVersion; import com.powsybl.dynawo.commons.loadmerge.LoadsMerger; import com.powsybl.iidm.network.Network; -import com.powsybl.iidm.xml.NetworkXml; +import com.powsybl.iidm.serde.NetworkSerDe; import com.powsybl.timeseries.TimeSeries; import com.powsybl.timeseries.TimeSeries.TimeFormat; import com.powsybl.timeseries.TimeSeriesConstants; @@ -30,9 +30,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.xml.stream.XMLStreamException; import java.io.IOException; -import java.io.UncheckedIOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; @@ -103,7 +101,7 @@ public static Command getVersionCommand(DynaWaltzConfig dynaWaltzConfig) { @Override public CompletableFuture run(Network network, DynamicModelsSupplier dynamicModelsSupplier, EventModelsSupplier eventModelsSupplier, CurvesSupplier curvesSupplier, String workingVariantId, - ComputationManager computationManager, DynamicSimulationParameters parameters) { + ComputationManager computationManager, DynamicSimulationParameters parameters, Reporter reporter) { Objects.requireNonNull(dynamicModelsSupplier); Objects.requireNonNull(eventModelsSupplier); Objects.requireNonNull(curvesSupplier); @@ -178,7 +176,7 @@ public DynamicSimulationResult after(Path workingDir, ExecutionReport report) th if (parameters.isWriteFinalState()) { Path outputNetworkFile = workingDir.resolve(OUTPUTS_FOLDER).resolve(FINAL_STATE_FOLDER).resolve(OUTPUT_IIDM_FILENAME); if (Files.exists(outputNetworkFile)) { - NetworkResultsUpdater.update(context.getNetwork(), NetworkXml.read(outputNetworkFile), context.getDynaWaltzParameters().isMergeLoads()); + NetworkResultsUpdater.update(context.getNetwork(), NetworkSerDe.read(outputNetworkFile), context.getDynaWaltzParameters().isMergeLoads()); } else { status = false; } @@ -204,27 +202,20 @@ public DynamicSimulationResult after(Path workingDir, ExecutionReport report) th return new DynamicSimulationResultImpl(status, null, curves, DynamicSimulationResult.emptyTimeLine()); } - private void writeInputFiles(Path workingDir) { - try { - DynawoUtil.writeIidm(dynawoInput, workingDir.resolve(NETWORK_FILENAME)); - JobsXml.write(workingDir, context); - DydXml.write(workingDir, context); - ParametersXml.write(workingDir, context); - if (context.withCurves()) { - CurvesXml.write(workingDir, context); - } - DumpFileParameters dumpFileParameters = context.getDynaWaltzParameters().getDumpFileParameters(); - if (dumpFileParameters.useDumpFile()) { - Path dumpFilePath = dumpFileParameters.getDumpFilePath(); - if (dumpFilePath != null) { - Files.copy(dumpFilePath, workingDir.resolve(dumpFileParameters.dumpFile()), StandardCopyOption.REPLACE_EXISTING); - } + private void writeInputFiles(Path workingDir) throws IOException { + DynawoUtil.writeIidm(dynawoInput, workingDir.resolve(NETWORK_FILENAME)); + JobsXml.write(workingDir, context); + DydXml.write(workingDir, context); + ParametersXml.write(workingDir, context); + if (context.withCurves()) { + CurvesXml.write(workingDir, context); + } + DumpFileParameters dumpFileParameters = context.getDynaWaltzParameters().getDumpFileParameters(); + if (dumpFileParameters.useDumpFile()) { + Path dumpFilePath = dumpFileParameters.getDumpFilePath(); + if (dumpFilePath != null) { + Files.copy(dumpFilePath, workingDir.resolve(dumpFileParameters.dumpFile()), StandardCopyOption.REPLACE_EXISTING); } - - } catch (IOException e) { - throw new UncheckedIOException(e); - } catch (XMLStreamException e) { - throw new UncheckedXmlStreamException(e); } } } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/AbstractBlackBoxModel.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/AbstractBlackBoxModel.java index 2e4079c41..7fb758d9b 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/AbstractBlackBoxModel.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/AbstractBlackBoxModel.java @@ -8,13 +8,11 @@ import com.powsybl.dynawaltz.DynaWaltzContext; import com.powsybl.dynawaltz.DynaWaltzParameters; +import com.powsybl.dynawaltz.models.buses.EquipmentConnectionPoint; import com.powsybl.dynawaltz.models.macroconnections.MacroConnectAttribute; import com.powsybl.dynawaltz.models.macroconnections.MacroConnectionSuffix; -import com.powsybl.dynawaltz.parameters.ParametersSet; -import com.powsybl.iidm.network.Identifiable; -import com.powsybl.dynawaltz.models.buses.EquipmentConnectionPoint; import com.powsybl.dynawaltz.models.utils.BusUtils; -import com.powsybl.dynawaltz.models.utils.SideConverter; +import com.powsybl.dynawaltz.parameters.ParametersSet; import com.powsybl.iidm.network.*; import javax.xml.stream.XMLStreamException; @@ -142,13 +140,13 @@ protected boolean createMacroConnectionsOrSkip(Identifiable /** * Suffixes MacroConnector id with side name */ - protected final void createMacroConnections(String modelStaticId, Class modelClass, BiFunction> varConnectionsSupplier, DynaWaltzContext context, Side side) { + protected final void createMacroConnections(String modelStaticId, Class modelClass, BiFunction> varConnectionsSupplier, DynaWaltzContext context, TwoSides side) { T connectedModel = context.getDynamicModel(modelStaticId, modelClass); String macroConnectorId = context.addMacroConnector(getName(), connectedModel.getName(), side, varConnectionsSupplier.apply(connectedModel, side)); context.addMacroConnect(macroConnectorId, getMacroConnectFromAttributes(), connectedModel.getMacroConnectToAttributes()); } - protected final void createMacroConnections(Identifiable equipment, Class modelClass, BiFunction> varConnectionsSupplier, DynaWaltzContext context, Side side) { + protected final void createMacroConnections(Identifiable equipment, Class modelClass, BiFunction> varConnectionsSupplier, DynaWaltzContext context, TwoSides side) { T connectedModel = context.getDynamicModel(equipment, modelClass); String macroConnectorId = context.addMacroConnector(getName(), connectedModel.getName(), side, varConnectionsSupplier.apply(connectedModel, side)); context.addMacroConnect(macroConnectorId, getMacroConnectFromAttributes(), connectedModel.getMacroConnectToAttributes()); @@ -182,14 +180,14 @@ protected void createTerminalMacroConnections(Injection equipment, Function> varConnectionsSupplier, DynaWaltzContext context, Side side) { + protected final void createTerminalMacroConnections(Terminal terminal, BiFunction> varConnectionsSupplier, DynaWaltzContext context, TwoSides side) { EquipmentConnectionPoint connectedModel = context.getConnectionPointDynamicModel(BusUtils.getConnectableBusStaticId(terminal)); String macroConnectorId = context.addMacroConnector(getName(), connectedModel.getName(), side, varConnectionsSupplier.apply(connectedModel, side)); context.addMacroConnect(macroConnectorId, getMacroConnectFromAttributes(), connectedModel.getMacroConnectToAttributes()); } - protected final void createTerminalMacroConnections(HvdcLine hvdc, BiFunction> varConnectionsSupplier, DynaWaltzContext context, Side side) { - HvdcConverterStation station = hvdc.getConverterStation(SideConverter.convert(side)); + protected final void createTerminalMacroConnections(HvdcLine hvdc, BiFunction> varConnectionsSupplier, DynaWaltzContext context, TwoSides side) { + HvdcConverterStation station = hvdc.getConverterStation(side); createTerminalMacroConnections(station.getTerminal(), varConnectionsSupplier, context, side); } } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/Side.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/Side.java deleted file mode 100644 index 24183d522..000000000 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/Side.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright (c) 2023, 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/. - * SPDX-License-Identifier: MPL-2.0 - */ -package com.powsybl.dynawaltz.models; - -/** - * @author Laurent Issertial {@literal } - */ -public enum Side { - - ONE("Side1"), - TWO("Side2"); - - private final String sideSuffix; - - Side(String sideSuffix) { - this.sideSuffix = sideSuffix; - } - - public String getSideSuffix() { - return sideSuffix; - } - - public int getSideNumber() { - return ordinal() + 1; - } - - public Side getOppositeSide() { - return this == ONE ? TWO : ONE; - } -} diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automatons/CurrentLimitAutomaton.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automatons/CurrentLimitAutomaton.java index d743b08ec..e454863cd 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automatons/CurrentLimitAutomaton.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automatons/CurrentLimitAutomaton.java @@ -8,9 +8,10 @@ import com.powsybl.dynawaltz.DynaWaltzContext; import com.powsybl.dynawaltz.models.AbstractPureDynamicBlackBoxModel; -import com.powsybl.dynawaltz.models.Side; import com.powsybl.dynawaltz.models.VarConnection; +import com.powsybl.dynawaltz.models.utils.SideUtils; import com.powsybl.iidm.network.Branch; +import com.powsybl.iidm.network.TwoSides; import java.util.Arrays; import java.util.List; @@ -26,11 +27,11 @@ public class CurrentLimitAutomaton extends AbstractPureDynamicBlackBoxModel { protected static final String CONTROL_SUFFIX = "Control"; protected final Branch measuredQuadripole; - protected final Side measuredSide; + protected final TwoSides measuredSide; protected final Branch controlledQuadripole; protected final String lib; - public CurrentLimitAutomaton(String dynamicModelId, String parameterSetId, Branch measuredQuadripole, Side measuredSide, Branch controlledQuadripole, String lib) { + public CurrentLimitAutomaton(String dynamicModelId, String parameterSetId, Branch measuredQuadripole, TwoSides measuredSide, Branch controlledQuadripole, String lib) { super(dynamicModelId, parameterSetId); this.measuredQuadripole = Objects.requireNonNull(measuredQuadripole); this.measuredSide = Objects.requireNonNull(measuredSide); @@ -38,7 +39,7 @@ public CurrentLimitAutomaton(String dynamicModelId, String parameterSetId, Branc this.lib = lib; } - public CurrentLimitAutomaton(String dynamicModelId, String parameterSetId, Branch measuredQuadripole, Side measuredSide, String lib) { + public CurrentLimitAutomaton(String dynamicModelId, String parameterSetId, Branch measuredQuadripole, TwoSides measuredSide, String lib) { this(dynamicModelId, parameterSetId, measuredQuadripole, measuredSide, measuredQuadripole, lib); } @@ -49,7 +50,7 @@ public String getLib() { @Override public void createMacroConnections(DynaWaltzContext context) { - createMacroConnections(measuredQuadripole, QuadripoleModel.class, this::getVarConnectionsWithMeasuredQuadripole, context, MEASURE_SUFFIX + measuredSide.getSideSuffix()); + createMacroConnections(measuredQuadripole, QuadripoleModel.class, this::getVarConnectionsWithMeasuredQuadripole, context, MEASURE_SUFFIX + SideUtils.getSideSuffix(measuredSide)); createMacroConnections(controlledQuadripole, QuadripoleModel.class, this::getVarConnectionsWithControlledQuadripole, context, CONTROL_SUFFIX); } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automatons/CurrentLimitTwoLevelsAutomaton.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automatons/CurrentLimitTwoLevelsAutomaton.java index 8aa8bfc49..645480229 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automatons/CurrentLimitTwoLevelsAutomaton.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automatons/CurrentLimitTwoLevelsAutomaton.java @@ -8,9 +8,10 @@ package com.powsybl.dynawaltz.models.automatons; import com.powsybl.dynawaltz.DynaWaltzContext; -import com.powsybl.dynawaltz.models.Side; import com.powsybl.dynawaltz.models.VarConnection; +import com.powsybl.dynawaltz.models.utils.SideUtils; import com.powsybl.iidm.network.Branch; +import com.powsybl.iidm.network.TwoSides; import java.util.Arrays; import java.util.List; @@ -25,9 +26,9 @@ public class CurrentLimitTwoLevelsAutomaton extends CurrentLimitAutomaton { protected static final String SECOND_MEASURE_SUFFIX = MEASURE_SUFFIX + "2"; private final Branch secondMeasuredQuadripole; - private final Side secondMeasuredSide; + private final TwoSides secondMeasuredSide; - public CurrentLimitTwoLevelsAutomaton(String dynamicModelId, String parameterSetId, Branch measuredQuadripole, Side measuredSide, Branch secondMeasuredQuadripole, Side secondMeasuredSide, Branch controlledQuadripole, String lib) { + public CurrentLimitTwoLevelsAutomaton(String dynamicModelId, String parameterSetId, Branch measuredQuadripole, TwoSides measuredSide, Branch secondMeasuredQuadripole, TwoSides secondMeasuredSide, Branch controlledQuadripole, String lib) { super(dynamicModelId, parameterSetId, measuredQuadripole, measuredSide, controlledQuadripole, lib); this.secondMeasuredQuadripole = Objects.requireNonNull(secondMeasuredQuadripole); this.secondMeasuredSide = Objects.requireNonNull(secondMeasuredSide); @@ -35,8 +36,8 @@ public CurrentLimitTwoLevelsAutomaton(String dynamicModelId, String parameterSet @Override public void createMacroConnections(DynaWaltzContext context) { - createMacroConnections(measuredQuadripole, QuadripoleModel.class, this::getVarConnectionsWithMeasuredQuadripole, context, FIRST_MEASURE_SUFFIX + measuredSide.getSideSuffix()); - createMacroConnections(secondMeasuredQuadripole, QuadripoleModel.class, this::getVarConnectionsWithSecondMeasuredQuadripole, context, SECOND_MEASURE_SUFFIX + secondMeasuredSide.getSideSuffix()); + createMacroConnections(measuredQuadripole, QuadripoleModel.class, this::getVarConnectionsWithMeasuredQuadripole, context, FIRST_MEASURE_SUFFIX + SideUtils.getSideSuffix(measuredSide)); + createMacroConnections(secondMeasuredQuadripole, QuadripoleModel.class, this::getVarConnectionsWithSecondMeasuredQuadripole, context, SECOND_MEASURE_SUFFIX + SideUtils.getSideSuffix(secondMeasuredSide)); createMacroConnections(controlledQuadripole, QuadripoleModel.class, this::getVarConnectionsWithControlledQuadripole, context, CONTROL_SUFFIX); } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automatons/QuadripoleModel.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automatons/QuadripoleModel.java index f68af7969..bafd17e32 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automatons/QuadripoleModel.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/automatons/QuadripoleModel.java @@ -8,14 +8,14 @@ package com.powsybl.dynawaltz.models.automatons; import com.powsybl.dynawaltz.models.Model; -import com.powsybl.dynawaltz.models.Side; +import com.powsybl.iidm.network.TwoSides; /** * @author Laurent Issertial {@literal } */ public interface QuadripoleModel extends Model { - String getIVarName(Side side); + String getIVarName(TwoSides side); String getStateVarName(); diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/buses/DefaultEquipmentConnectionPoint.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/buses/DefaultEquipmentConnectionPoint.java index 2e073767e..7d61ec881 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/buses/DefaultEquipmentConnectionPoint.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/buses/DefaultEquipmentConnectionPoint.java @@ -7,9 +7,9 @@ */ package com.powsybl.dynawaltz.models.buses; -import com.powsybl.dynawaltz.models.Side; import com.powsybl.dynawaltz.models.macroconnections.MacroConnectAttribute; import com.powsybl.dynawaltz.xml.DynaWaltzXmlConstants; +import com.powsybl.iidm.network.TwoSides; import java.util.List; import java.util.Optional; @@ -42,8 +42,8 @@ public String getTerminalVarName() { } @Override - public String getTerminalVarName(Side side) { - return "@STATIC_ID@@NODE" + side.getSideNumber() + "@_ACPIN"; + public String getTerminalVarName(TwoSides side) { + return "@STATIC_ID@@NODE" + side.getNum() + "@_ACPIN"; } @Override @@ -52,8 +52,8 @@ public Optional getSwitchOffSignalVarName() { } @Override - public Optional getSwitchOffSignalVarName(Side side) { - return Optional.of("@STATIC_ID@@NODE" + side.getSideNumber() + "@_switchOff"); + public Optional getSwitchOffSignalVarName(TwoSides side) { + return Optional.of("@STATIC_ID@@NODE" + side.getNum() + "@_switchOff"); } @Override diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/buses/EquipmentConnectionPoint.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/buses/EquipmentConnectionPoint.java index 3b48d3509..03f2d30ec 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/buses/EquipmentConnectionPoint.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/buses/EquipmentConnectionPoint.java @@ -8,7 +8,7 @@ package com.powsybl.dynawaltz.models.buses; import com.powsybl.dynawaltz.models.Model; -import com.powsybl.dynawaltz.models.Side; +import com.powsybl.iidm.network.TwoSides; import java.util.Optional; @@ -20,13 +20,13 @@ public interface EquipmentConnectionPoint extends Model { String getTerminalVarName(); - default String getTerminalVarName(Side side) { + default String getTerminalVarName(TwoSides side) { return getTerminalVarName(); } Optional getSwitchOffSignalVarName(); - default Optional getSwitchOffSignalVarName(Side side) { + default Optional getSwitchOffSignalVarName(TwoSides side) { return getSwitchOffSignalVarName(); } } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/events/EventHvdcDisconnection.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/events/EventHvdcDisconnection.java index b9c07cccb..9eb25ca59 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/events/EventHvdcDisconnection.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/events/EventHvdcDisconnection.java @@ -8,10 +8,10 @@ package com.powsybl.dynawaltz.models.events; import com.powsybl.dynawaltz.DynaWaltzContext; -import com.powsybl.dynawaltz.models.Side; import com.powsybl.dynawaltz.models.VarConnection; import com.powsybl.dynawaltz.models.hvdc.HvdcModel; import com.powsybl.iidm.network.HvdcLine; +import com.powsybl.iidm.network.TwoSides; import java.util.List; @@ -34,11 +34,11 @@ public EventHvdcDisconnection(HvdcLine equipment, double startTime) { } private List getVarConnectionsWithHvdcModel(HvdcModel connected) { - return List.of(new VarConnection(DISCONNECTION_VAR_CONNECT, connected.getSwitchOffSignalEventVarName(Side.ONE)), - new VarConnection(DISCONNECTION_VAR_CONNECT, connected.getSwitchOffSignalEventVarName(Side.TWO))); + return List.of(new VarConnection(DISCONNECTION_VAR_CONNECT, connected.getSwitchOffSignalEventVarName(TwoSides.ONE)), + new VarConnection(DISCONNECTION_VAR_CONNECT, connected.getSwitchOffSignalEventVarName(TwoSides.TWO))); } - private List getVarConnectionsWithHvdcModelSide(HvdcModel connected, Side side) { + private List getVarConnectionsWithHvdcModelSide(HvdcModel connected, TwoSides side) { return List.of(new VarConnection(DISCONNECTION_VAR_CONNECT, connected.getSwitchOffSignalEventVarName(side))); } @@ -47,9 +47,9 @@ public void createMacroConnections(DynaWaltzContext context) { if (disconnectOrigin && disconnectExtremity) { createMacroConnections(getEquipment(), HvdcModel.class, this::getVarConnectionsWithHvdcModel, context); } else if (disconnectOrigin) { - createMacroConnections(getEquipment(), HvdcModel.class, this::getVarConnectionsWithHvdcModelSide, context, Side.ONE); + createMacroConnections(getEquipment(), HvdcModel.class, this::getVarConnectionsWithHvdcModelSide, context, TwoSides.ONE); } else if (disconnectExtremity) { - createMacroConnections(getEquipment(), HvdcModel.class, this::getVarConnectionsWithHvdcModelSide, context, Side.TWO); + createMacroConnections(getEquipment(), HvdcModel.class, this::getVarConnectionsWithHvdcModelSide, context, TwoSides.TWO); } } } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/AbstractHvdc.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/AbstractHvdc.java index 2c79c41e6..d442f4d30 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/AbstractHvdc.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/AbstractHvdc.java @@ -9,11 +9,12 @@ import com.powsybl.dynawaltz.DynaWaltzContext; import com.powsybl.dynawaltz.models.AbstractEquipmentBlackBoxModel; -import com.powsybl.dynawaltz.models.Side; import com.powsybl.dynawaltz.models.VarConnection; import com.powsybl.dynawaltz.models.VarMapping; import com.powsybl.dynawaltz.models.buses.EquipmentConnectionPoint; +import com.powsybl.dynawaltz.models.utils.SideUtils; import com.powsybl.iidm.network.HvdcLine; +import com.powsybl.iidm.network.TwoSides; import java.util.ArrayList; import java.util.Arrays; @@ -40,8 +41,8 @@ protected AbstractHvdc(String dynamicModelId, HvdcLine hvdc, String parameterSet @Override public void createMacroConnections(DynaWaltzContext context) { - createTerminalMacroConnections(equipment, this::getVarConnectionsWith, context, Side.ONE); - createTerminalMacroConnections(equipment, this::getVarConnectionsWith, context, Side.TWO); + createTerminalMacroConnections(equipment, this::getVarConnectionsWith, context, TwoSides.ONE); + createTerminalMacroConnections(equipment, this::getVarConnectionsWith, context, TwoSides.TWO); } @Override @@ -49,16 +50,16 @@ public List getVarsMapping() { return VAR_MAPPING; } - protected List getVarConnectionsWith(EquipmentConnectionPoint connected, Side side) { + protected List getVarConnectionsWith(EquipmentConnectionPoint connected, TwoSides side) { List varConnections = new ArrayList<>(2); varConnections.add(getSimpleVarConnectionWithBus(connected, side)); connected.getSwitchOffSignalVarName(side) - .map(switchOff -> new VarConnection("hvdc_switchOffSignal1" + side.getSideSuffix(), switchOff)) + .map(switchOff -> new VarConnection("hvdc_switchOffSignal1" + SideUtils.getSideSuffix(side), switchOff)) .ifPresent(varConnections::add); return varConnections; } - protected final VarConnection getSimpleVarConnectionWithBus(EquipmentConnectionPoint connected, Side side) { - return new VarConnection(TERMINAL_PREFIX + side.getSideNumber(), connected.getTerminalVarName(side)); + protected final VarConnection getSimpleVarConnectionWithBus(EquipmentConnectionPoint connected, TwoSides side) { + return new VarConnection(TERMINAL_PREFIX + side.getNum(), connected.getTerminalVarName(side)); } } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/DanglingSide.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/DanglingSide.java index 86d93f717..c4a7e1e48 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/DanglingSide.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/DanglingSide.java @@ -1,8 +1,9 @@ package com.powsybl.dynawaltz.models.hvdc; -import com.powsybl.dynawaltz.models.Side; import com.powsybl.dynawaltz.models.VarConnection; import com.powsybl.dynawaltz.models.buses.EquipmentConnectionPoint; +import com.powsybl.dynawaltz.models.utils.SideUtils; +import com.powsybl.iidm.network.TwoSides; import java.util.List; import java.util.Objects; @@ -12,28 +13,28 @@ public final class DanglingSide { private final String prefix; - private final Side side; + private final TwoSides side; - public DanglingSide(String prefix, Side side) { + public DanglingSide(String prefix, TwoSides side) { this.prefix = Objects.requireNonNull(prefix); this.side = Objects.requireNonNull(side); } - boolean isDangling(Side side) { + boolean isDangling(TwoSides side) { return this.side == side; } public int getSideNumber() { - return side.getSideNumber(); + return side.getNum(); } - public void createMacroConnections(BiFunction> basicVarConnectionsSupplier, - BiConsumer>, Side> connectionCreator) { + public void createMacroConnections(BiFunction> basicVarConnectionsSupplier, + BiConsumer>, TwoSides> connectionCreator) { connectionCreator.accept(this::getVarConnectionsWith, side); - connectionCreator.accept(basicVarConnectionsSupplier, side.getOppositeSide()); + connectionCreator.accept(basicVarConnectionsSupplier, SideUtils.getOppositeSide(side)); } - private List getVarConnectionsWith(EquipmentConnectionPoint connected, Side side) { - return List.of(new VarConnection(prefix + side.getSideNumber(), connected.getTerminalVarName(side))); + private List getVarConnectionsWith(EquipmentConnectionPoint connected, TwoSides side) { + return List.of(new VarConnection(prefix + side.getNum(), connected.getTerminalVarName(side))); } } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/DefaultHvdc.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/DefaultHvdc.java index 9bc165212..6e2b4a339 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/DefaultHvdc.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/DefaultHvdc.java @@ -8,7 +8,7 @@ package com.powsybl.dynawaltz.models.hvdc; import com.powsybl.dynawaltz.models.defaultmodels.AbstractDefaultModel; -import com.powsybl.dynawaltz.models.Side; +import com.powsybl.iidm.network.TwoSides; /** * @author Laurent Issertial {@literal } @@ -25,7 +25,7 @@ public String getName() { } @Override - public String getSwitchOffSignalEventVarName(Side side) { - return "@NAME@_state" + side.getSideNumber() + "_value"; + public String getSwitchOffSignalEventVarName(TwoSides side) { + return "@NAME@_state" + side.getNum() + "_value"; } } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/HvdcModel.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/HvdcModel.java index 782d1af78..82104b67e 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/HvdcModel.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/HvdcModel.java @@ -8,12 +8,12 @@ package com.powsybl.dynawaltz.models.hvdc; import com.powsybl.dynawaltz.models.Model; -import com.powsybl.dynawaltz.models.Side; +import com.powsybl.iidm.network.TwoSides; /** * @author Laurent Issertial {@literal } */ public interface HvdcModel extends Model { - String getSwitchOffSignalEventVarName(Side side); + String getSwitchOffSignalEventVarName(TwoSides side); } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/HvdcP.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/HvdcP.java index 0baf4ed3d..22733d2a2 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/HvdcP.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/HvdcP.java @@ -7,8 +7,9 @@ */ package com.powsybl.dynawaltz.models.hvdc; -import com.powsybl.dynawaltz.models.Side; +import com.powsybl.dynawaltz.models.utils.SideUtils; import com.powsybl.iidm.network.HvdcLine; +import com.powsybl.iidm.network.TwoSides; /** * @author Laurent Issertial {@literal } @@ -20,7 +21,7 @@ public HvdcP(String dynamicModelId, HvdcLine hvdc, String parameterSetId, String } @Override - public String getSwitchOffSignalEventVarName(Side side) { - return "hvdc_switchOffSignal2" + side.getSideSuffix(); + public String getSwitchOffSignalEventVarName(TwoSides side) { + return "hvdc_switchOffSignal2" + SideUtils.getSideSuffix(side); } } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/HvdcPDangling.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/HvdcPDangling.java index 39dea79a3..8c9042a8d 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/HvdcPDangling.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/HvdcPDangling.java @@ -9,9 +9,8 @@ import com.powsybl.commons.PowsyblException; import com.powsybl.dynawaltz.DynaWaltzContext; -import com.powsybl.dynawaltz.models.Side; -import com.powsybl.dynawaltz.models.utils.SideConverter; import com.powsybl.iidm.network.HvdcLine; +import com.powsybl.iidm.network.TwoSides; /** * @author Laurent Issertial {@literal } @@ -20,7 +19,7 @@ public class HvdcPDangling extends HvdcP { private final DanglingSide danglingSide; - public HvdcPDangling(String dynamicModelId, HvdcLine hvdc, String parameterSetId, String hvdcLib, Side danglingSide) { + public HvdcPDangling(String dynamicModelId, HvdcLine hvdc, String parameterSetId, String hvdcLib, TwoSides danglingSide) { super(dynamicModelId, hvdc, parameterSetId, hvdcLib); this.danglingSide = new DanglingSide(TERMINAL_PREFIX, danglingSide); } @@ -29,12 +28,12 @@ public HvdcPDangling(String dynamicModelId, HvdcLine hvdc, String parameterSetId public void createMacroConnections(DynaWaltzContext context) { danglingSide.createMacroConnections( this::getVarConnectionsWith, - (varCoSupplier, side) -> createTerminalMacroConnections(equipment.getConverterStation(SideConverter.convert(side)).getTerminal(), varCoSupplier, context, side) + (varCoSupplier, side) -> createTerminalMacroConnections(equipment.getConverterStation(side).getTerminal(), varCoSupplier, context, side) ); } @Override - public String getSwitchOffSignalEventVarName(Side side) { + public String getSwitchOffSignalEventVarName(TwoSides side) { if (danglingSide.isDangling(side)) { throw new PowsyblException(String.format("Equipment %s side %s is dangling and can't be disconnected with an event", getLib(), danglingSide.getSideNumber())); } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/HvdcVsc.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/HvdcVsc.java index 3102a17ee..515525cbc 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/HvdcVsc.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/HvdcVsc.java @@ -7,8 +7,8 @@ */ package com.powsybl.dynawaltz.models.hvdc; -import com.powsybl.dynawaltz.models.Side; import com.powsybl.iidm.network.HvdcLine; +import com.powsybl.iidm.network.TwoSides; /** * @author Laurent Issertial {@literal } @@ -20,7 +20,7 @@ public HvdcVsc(String dynamicModelId, HvdcLine hvdc, String parameterSetId, Stri } @Override - public String getSwitchOffSignalEventVarName(Side side) { - return "hvdc_Conv" + side.getSideNumber() + "_switchOffSignal2"; + public String getSwitchOffSignalEventVarName(TwoSides side) { + return "hvdc_Conv" + side.getNum() + "_switchOffSignal2"; } } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/HvdcVscDangling.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/HvdcVscDangling.java index 2eb39236e..f6773b32f 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/HvdcVscDangling.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/hvdc/HvdcVscDangling.java @@ -9,8 +9,8 @@ import com.powsybl.commons.PowsyblException; import com.powsybl.dynawaltz.DynaWaltzContext; -import com.powsybl.dynawaltz.models.Side; import com.powsybl.iidm.network.HvdcLine; +import com.powsybl.iidm.network.TwoSides; /** * @author Laurent Issertial {@literal } @@ -19,7 +19,7 @@ public class HvdcVscDangling extends HvdcVsc { private final DanglingSide danglingSide; - public HvdcVscDangling(String dynamicModelId, HvdcLine hvdc, String parameterSetId, String hvdcLib, Side danglingSide) { + public HvdcVscDangling(String dynamicModelId, HvdcLine hvdc, String parameterSetId, String hvdcLib, TwoSides danglingSide) { super(dynamicModelId, hvdc, parameterSetId, hvdcLib); this.danglingSide = new DanglingSide(TERMINAL_PREFIX, danglingSide); } @@ -33,7 +33,7 @@ public void createMacroConnections(DynaWaltzContext context) { } @Override - public String getSwitchOffSignalEventVarName(Side side) { + public String getSwitchOffSignalEventVarName(TwoSides side) { if (danglingSide.isDangling(side)) { throw new PowsyblException(String.format("Equipment %s side %s is dangling and can't be disconnected with an event", getLib(), danglingSide.getSideNumber())); } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/lines/DefaultLine.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/lines/DefaultLine.java index 4fd1caf6a..bd42d9628 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/lines/DefaultLine.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/lines/DefaultLine.java @@ -7,7 +7,8 @@ package com.powsybl.dynawaltz.models.lines; import com.powsybl.dynawaltz.models.defaultmodels.AbstractDefaultModel; -import com.powsybl.dynawaltz.models.Side; +import com.powsybl.dynawaltz.models.utils.SideUtils; +import com.powsybl.iidm.network.TwoSides; /** * @author Florian Dupuy {@literal } @@ -24,8 +25,8 @@ public String getName() { } @Override - public String getIVarName(Side side) { - return "@NAME@_i" + side.getSideSuffix(); + public String getIVarName(TwoSides side) { + return "@NAME@_i" + SideUtils.getSideSuffix(side); } @Override diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/lines/StandardLine.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/lines/StandardLine.java index 58ffcba6b..7747930f5 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/lines/StandardLine.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/lines/StandardLine.java @@ -9,11 +9,10 @@ import com.powsybl.dynawaltz.DynaWaltzContext; import com.powsybl.dynawaltz.models.AbstractEquipmentBlackBoxModel; -import com.powsybl.dynawaltz.models.Side; import com.powsybl.dynawaltz.models.VarConnection; import com.powsybl.dynawaltz.models.buses.EquipmentConnectionPoint; -import com.powsybl.dynawaltz.models.utils.SideConverter; import com.powsybl.iidm.network.Line; +import com.powsybl.iidm.network.TwoSides; import java.util.List; @@ -26,17 +25,17 @@ public StandardLine(String dynamicModelId, Line line, String parameterSetId) { super(dynamicModelId, parameterSetId, line, "Line"); } - private List getVarConnectionsWith(EquipmentConnectionPoint connected, Side side) { + private List getVarConnectionsWith(EquipmentConnectionPoint connected, TwoSides side) { return List.of(new VarConnection(getTerminalVarName(side), connected.getTerminalVarName())); } - private String getTerminalVarName(Side side) { - return "line_terminal" + side.getSideNumber(); + private String getTerminalVarName(TwoSides side) { + return "line_terminal" + side.getNum(); } @Override public void createMacroConnections(DynaWaltzContext context) { - equipment.getTerminals().forEach(t -> createTerminalMacroConnections(t, this::getVarConnectionsWith, context, SideConverter.convert(equipment.getSide(t)))); + equipment.getTerminals().forEach(t -> createTerminalMacroConnections(t, this::getVarConnectionsWith, context, equipment.getSide(t))); } @Override @@ -55,7 +54,7 @@ public String getStateValueVarName() { } @Override - public String getIVarName(Side side) { + public String getIVarName(TwoSides side) { throw new UnsupportedOperationException("i variable not implemented in StandardLine dynawo's model"); } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/macroconnections/MacroConnector.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/macroconnections/MacroConnector.java index 626549eae..44b7b3255 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/macroconnections/MacroConnector.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/macroconnections/MacroConnector.java @@ -6,8 +6,9 @@ */ package com.powsybl.dynawaltz.models.macroconnections; -import com.powsybl.dynawaltz.models.Side; import com.powsybl.dynawaltz.models.VarConnection; +import com.powsybl.dynawaltz.models.utils.SideUtils; +import com.powsybl.iidm.network.TwoSides; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; @@ -38,8 +39,8 @@ public static String createMacroConnectorId(String name1, String name2) { return MACRO_CONNECTOR_PREFIX + name1 + "-" + name2; } - public static String createMacroConnectorId(String name1, String name2, Side side) { - return MACRO_CONNECTOR_PREFIX + name1 + side.getSideSuffix() + "-" + name2; + public static String createMacroConnectorId(String name1, String name2, TwoSides side) { + return MACRO_CONNECTOR_PREFIX + name1 + SideUtils.getSideSuffix(side) + "-" + name2; } public static String createMacroConnectorId(String name1, String name2, String name1Suffix) { diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/transformers/DefaultTransformer.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/transformers/DefaultTransformer.java index 41a15eef2..d55b89f49 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/transformers/DefaultTransformer.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/transformers/DefaultTransformer.java @@ -8,8 +8,9 @@ package com.powsybl.dynawaltz.models.transformers; import com.powsybl.dynawaltz.models.defaultmodels.AbstractDefaultModel; -import com.powsybl.dynawaltz.models.Side; import com.powsybl.dynawaltz.models.VarConnection; +import com.powsybl.dynawaltz.models.utils.SideUtils; +import com.powsybl.iidm.network.TwoSides; import java.util.List; @@ -60,8 +61,8 @@ public List getTapChangerBlockerVarConnections() { } @Override - public String getIVarName(Side side) { - return "@NAME@_i" + side.getSideSuffix(); + public String getIVarName(TwoSides side) { + return "@NAME@_i" + SideUtils.getSideSuffix(side); } @Override diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/transformers/TransformerFixedRatio.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/transformers/TransformerFixedRatio.java index 7055409ab..679d8a0f1 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/transformers/TransformerFixedRatio.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/transformers/TransformerFixedRatio.java @@ -9,10 +9,10 @@ import com.powsybl.dynawaltz.DynaWaltzContext; import com.powsybl.dynawaltz.models.AbstractEquipmentBlackBoxModel; -import com.powsybl.dynawaltz.models.Side; import com.powsybl.dynawaltz.models.VarConnection; import com.powsybl.dynawaltz.models.buses.EquipmentConnectionPoint; -import com.powsybl.dynawaltz.models.utils.SideConverter; +import com.powsybl.dynawaltz.models.utils.SideUtils; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.iidm.network.TwoWindingsTransformer; import java.util.List; @@ -28,17 +28,17 @@ public TransformerFixedRatio(String dynamicModelId, TwoWindingsTransformer trans super(dynamicModelId, parameterSetId, transformer, lib); } - private List getVarConnectionsWith(EquipmentConnectionPoint connected, Side side) { + private List getVarConnectionsWith(EquipmentConnectionPoint connected, TwoSides side) { return List.of(new VarConnection(getTerminalVarName(side), connected.getTerminalVarName())); } - private String getTerminalVarName(Side side) { - return "transformer_terminal" + side.getSideNumber(); + private String getTerminalVarName(TwoSides side) { + return "transformer_terminal" + side.getNum(); } @Override public void createMacroConnections(DynaWaltzContext context) { - equipment.getTerminals().forEach(t -> createTerminalMacroConnections(t, this::getVarConnectionsWith, context, SideConverter.convert(equipment.getSide(t)))); + equipment.getTerminals().forEach(t -> createTerminalMacroConnections(t, this::getVarConnectionsWith, context, equipment.getSide(t))); } @Override @@ -72,8 +72,8 @@ public List getTapChangerBlockerVarConnections() { } @Override - public String getIVarName(Side side) { - return "transformer_i" + side.getSideSuffix(); + public String getIVarName(TwoSides side) { + return "transformer_i" + SideUtils.getSideSuffix(side); } @Override diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/utils/SideConverter.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/utils/SideUtils.java similarity index 54% rename from dynawaltz/src/main/java/com/powsybl/dynawaltz/models/utils/SideConverter.java rename to dynawaltz/src/main/java/com/powsybl/dynawaltz/models/utils/SideUtils.java index 2c368c76e..671d700b7 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/utils/SideConverter.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/utils/SideUtils.java @@ -7,29 +7,28 @@ */ package com.powsybl.dynawaltz.models.utils; -import com.powsybl.dynawaltz.models.Side; -import com.powsybl.iidm.network.Branch; -import com.powsybl.iidm.network.HvdcLine; +import com.powsybl.iidm.network.TwoSides; /** * @author Laurent Issertial {@literal } */ -public final class SideConverter { +public final class SideUtils { - private SideConverter() { + private SideUtils() { } - public static Side convert(Branch.Side side) { + public static String getSideSuffix(TwoSides side) { return switch (side) { - case ONE -> Side.ONE; - case TWO -> Side.TWO; + case ONE -> "Side1"; + case TWO -> "Side2"; }; } - public static HvdcLine.Side convert(Side side) { + public static TwoSides getOppositeSide(TwoSides side) { return switch (side) { - case ONE -> HvdcLine.Side.ONE; - case TWO -> HvdcLine.Side.TWO; + case ONE -> TwoSides.TWO; + case TWO -> TwoSides.ONE; }; } + } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/XmlUtil.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/AbstractXmlDynawaltzWriter.java similarity index 54% rename from dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/XmlUtil.java rename to dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/AbstractXmlDynawaltzWriter.java index 59f93e77e..281ce2ff4 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/XmlUtil.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/AbstractXmlDynawaltzWriter.java @@ -1,12 +1,13 @@ /** - * Copyright (c) 2020, RTE (http://www.rte-france.com) + * Copyright (c) 2023, 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/. + * SPDX-License-Identifier: MPL-2.0 */ - package com.powsybl.dynawaltz.xml; +import com.powsybl.commons.exceptions.UncheckedXmlStreamException; import com.powsybl.dynawaltz.DynaWaltzContext; import javax.xml.stream.XMLStreamException; @@ -22,39 +23,43 @@ import static com.powsybl.dynawaltz.xml.DynaWaltzXmlConstants.DYN_URI; /** - * @author Mathieu Bague {@literal } + * @author Florian Dupuy {@literal } */ -public final class XmlUtil { +public abstract class AbstractXmlDynawaltzWriter implements XmlDynawaltzWriter { - @FunctionalInterface - public interface XmlDynawaltzWriter { - void write(XMLStreamWriter writer, DynaWaltzContext dynaWaltzContext) throws XMLStreamException; - } + private final String xmlFileName; + private final String xmlRootName; - private XmlUtil() { + protected AbstractXmlDynawaltzWriter(String xmlFileName, String xmlRootName) { + this.xmlFileName = Objects.requireNonNull(xmlFileName); + this.xmlRootName = Objects.requireNonNull(xmlRootName); } - public static void write(Path file, DynaWaltzContext context, String elementName, XmlDynawaltzWriter xmlDynawaltzWriter) throws IOException, XMLStreamException { - Objects.requireNonNull(file); + @Override + public void createXmlFileFromContext(Path workingDir, DynaWaltzContext context) throws IOException { + Objects.requireNonNull(workingDir); Objects.requireNonNull(context); - Objects.requireNonNull(elementName); - Objects.requireNonNull(xmlDynawaltzWriter); + Path file = workingDir.resolve(xmlFileName); try (Writer writer = Files.newBufferedWriter(file, StandardCharsets.UTF_8)) { XMLStreamWriter xmlWriter = XmlStreamWriterFactory.newInstance(writer); try { xmlWriter.writeStartDocument(StandardCharsets.UTF_8.toString(), "1.0"); xmlWriter.setPrefix(DYN_PREFIX, DYN_URI); - xmlWriter.writeStartElement(DYN_URI, elementName); + xmlWriter.writeStartElement(DYN_URI, xmlRootName); xmlWriter.writeNamespace(DYN_PREFIX, DYN_URI); - xmlDynawaltzWriter.write(xmlWriter, context); + write(xmlWriter, context); xmlWriter.writeEndElement(); xmlWriter.writeEndDocument(); } finally { xmlWriter.close(); } + } catch (XMLStreamException e) { + throw new UncheckedXmlStreamException(e); } } + + abstract void write(XMLStreamWriter writer, DynaWaltzContext dynaWaltzContext) throws XMLStreamException; } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/CurvesXml.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/CurvesXml.java index 1de66e92c..3fe6aec83 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/CurvesXml.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/CurvesXml.java @@ -14,7 +14,6 @@ import javax.xml.stream.XMLStreamWriter; import java.io.IOException; import java.nio.file.Path; -import java.util.Objects; import static com.powsybl.dynawaltz.xml.DynaWaltzConstants.CRV_FILENAME; import static com.powsybl.dynawaltz.xml.DynaWaltzXmlConstants.DYN_URI; @@ -22,19 +21,18 @@ /** * @author Marcos de Miguel {@literal } */ -public final class CurvesXml { +public final class CurvesXml extends AbstractXmlDynawaltzWriter { private CurvesXml() { + super(CRV_FILENAME, "curvesInput"); } - public static void write(Path workingDir, DynaWaltzContext context) throws IOException, XMLStreamException { - Objects.requireNonNull(workingDir); - Path file = workingDir.resolve(CRV_FILENAME); - - XmlUtil.write(file, context, "curvesInput", CurvesXml::write); + public static void write(Path workingDir, DynaWaltzContext context) throws IOException { + new CurvesXml().createXmlFileFromContext(workingDir, context); } - private static void write(XMLStreamWriter writer, DynaWaltzContext context) throws XMLStreamException { + @Override + public void write(XMLStreamWriter writer, DynaWaltzContext context) throws XMLStreamException { for (Curve curve : context.getCurves()) { DynaWaltzCurve dynCurve = (DynaWaltzCurve) curve; writer.writeEmptyElement(DYN_URI, "curve"); diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/DydXml.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/DydXml.java index c477e2b7f..6774e22e6 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/DydXml.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/DydXml.java @@ -16,26 +16,24 @@ import javax.xml.stream.XMLStreamWriter; import java.io.IOException; import java.nio.file.Path; -import java.util.Objects; import static com.powsybl.dynawaltz.xml.DynaWaltzConstants.DYD_FILENAME; /** * @author Mathieu Bague {@literal } */ -public final class DydXml { +public final class DydXml extends AbstractXmlDynawaltzWriter { private DydXml() { + super(DYD_FILENAME, "dynamicModelsArchitecture"); } - public static void write(Path workingDir, DynaWaltzContext context) throws IOException, XMLStreamException { - Objects.requireNonNull(workingDir); - Path file = workingDir.resolve(DYD_FILENAME); - - XmlUtil.write(file, context, "dynamicModelsArchitecture", DydXml::write); + public static void write(Path workingDir, DynaWaltzContext context) throws IOException { + new DydXml().createXmlFileFromContext(workingDir, context); } - private static void write(XMLStreamWriter writer, DynaWaltzContext context) throws XMLStreamException { + @Override + public void write(XMLStreamWriter writer, DynaWaltzContext context) throws XMLStreamException { // loop over the values of the map indexed by dynamicIds to write only once objects with the same dynamicId for (BlackBoxModel model : context.getBlackBoxDynamicModels()) { model.write(writer, context); diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/JobsXml.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/JobsXml.java index 329ad79f0..2dcf216b8 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/JobsXml.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/JobsXml.java @@ -15,7 +15,6 @@ import javax.xml.stream.XMLStreamWriter; import java.io.IOException; import java.nio.file.Path; -import java.util.Objects; import static com.powsybl.dynawaltz.xml.DynaWaltzConstants.*; import static com.powsybl.dynawaltz.xml.DynaWaltzXmlConstants.DYN_URI; @@ -23,19 +22,18 @@ /** * @author Marcos de Miguel {@literal } */ -public final class JobsXml { +public final class JobsXml extends AbstractXmlDynawaltzWriter { private JobsXml() { + super(JOBS_FILENAME, "jobs"); } - public static void write(Path workingDir, DynaWaltzContext context) throws IOException, XMLStreamException { - Objects.requireNonNull(workingDir); - Path file = workingDir.resolve(JOBS_FILENAME); - - XmlUtil.write(file, context, "jobs", JobsXml::write); + public static void write(Path workingDir, DynaWaltzContext context) throws IOException { + new JobsXml().createXmlFileFromContext(workingDir, context); } - private static void write(XMLStreamWriter writer, DynaWaltzContext context) throws XMLStreamException { + @Override + public void write(XMLStreamWriter writer, DynaWaltzContext context) throws XMLStreamException { writer.writeStartElement(DYN_URI, "job"); writer.writeAttribute("name", "Job"); writeSolver(writer, context); diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/ParametersXml.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/ParametersXml.java index 2d19b6999..5b0039a06 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/ParametersXml.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/ParametersXml.java @@ -9,6 +9,7 @@ import com.powsybl.commons.PowsyblException; import com.powsybl.commons.exceptions.UncheckedXmlStreamException; +import com.powsybl.commons.xml.XmlUtil; import com.powsybl.dynawaltz.DynaWaltzContext; import com.powsybl.dynawaltz.DynaWaltzParameters; import com.powsybl.dynawaltz.parameters.Parameter; @@ -93,8 +94,8 @@ public static ParametersSet load(Path parametersFile, String parameterSetId) { private static List readAndClose(XMLStreamReader xmlReader) throws XMLStreamException { List parametersSets = new ArrayList<>(); skipComments(xmlReader); - com.powsybl.commons.xml.XmlUtil.readUntilEndElement(PARAMETERS_SET_ELEMENT_NAME, xmlReader, () -> { - if (!xmlReader.getLocalName().equals("set")) { + XmlUtil.readSubElements(xmlReader, elementName -> { + if (!elementName.equals("set")) { closeAndThrowException(xmlReader, xmlReader.getLocalName()); } String parameterSetIdRead = xmlReader.getAttributeValue(null, "id"); @@ -107,40 +108,49 @@ private static List readAndClose(XMLStreamReader xmlReader) throw private static ParametersSet readOneSetAndClose(XMLStreamReader xmlReader, String parameterSetId) throws XMLStreamException { AtomicReference parametersSet = new AtomicReference<>(); skipComments(xmlReader); - com.powsybl.commons.xml.XmlUtil.readUntilEndElement(PARAMETERS_SET_ELEMENT_NAME, xmlReader, () -> { + XmlUtil.readSubElements(xmlReader, elementName -> { if (parametersSet.get() != null) { return; } - if (!xmlReader.getLocalName().equals("set")) { + if (!elementName.equals("set")) { closeAndThrowException(xmlReader, xmlReader.getLocalName()); } - if (xmlReader.getAttributeValue(null, "id").equals(parameterSetId)) { + String idSetRead = xmlReader.getAttributeValue(null, "id"); + if (idSetRead.equals(parameterSetId)) { parametersSet.set(createParametersSet(xmlReader, parameterSetId)); } else { - com.powsybl.commons.xml.XmlUtil.readUntilEndElement("set", xmlReader, () -> { - }); + XmlUtil.readSubElements(xmlReader); } }); xmlReader.close(); return parametersSet.get(); } - private static ParametersSet createParametersSet(XMLStreamReader xmlReader, String parameterSetId) throws XMLStreamException { + private static ParametersSet createParametersSet(XMLStreamReader xmlReader, String parameterSetId) { ParametersSet parametersSet = new ParametersSet(parameterSetId); - com.powsybl.commons.xml.XmlUtil.readUntilEndElement("set", xmlReader, () -> { - String name = xmlReader.getAttributeValue(null, "name"); - ParameterType type = ParameterType.valueOf(xmlReader.getAttributeValue(null, "type")); - if (xmlReader.getLocalName().equals("par")) { - String value = xmlReader.getAttributeValue(null, "value"); - parametersSet.addParameter(name, type, value); - } else if (xmlReader.getLocalName().equals("reference")) { - String origData = xmlReader.getAttributeValue(null, "origData"); - String origName = xmlReader.getAttributeValue(null, "origName"); - String componentId = xmlReader.getAttributeValue(null, "componentId"); - parametersSet.addReference(name, type, origData, origName, componentId); - } else { - closeAndThrowException(xmlReader, xmlReader.getLocalName()); + XmlUtil.readSubElements(xmlReader, elementName -> { + try { + String name = xmlReader.getAttributeValue(null, "name"); + ParameterType type = ParameterType.valueOf(xmlReader.getAttributeValue(null, "type")); + switch (elementName) { + case "par" -> { + String value = xmlReader.getAttributeValue(null, "value"); + XmlUtil.readEndElementOrThrow(xmlReader); + parametersSet.addParameter(name, type, value); + } + case "reference" -> { + String origData = xmlReader.getAttributeValue(null, "origData"); + String origName = xmlReader.getAttributeValue(null, "origName"); + String componentId = xmlReader.getAttributeValue(null, "componentId"); + XmlUtil.readEndElementOrThrow(xmlReader); + parametersSet.addReference(name, type, origData, origName, componentId); + } + default -> closeAndThrowException(xmlReader, xmlReader.getLocalName()); + } + } catch (XMLStreamException e) { + throw new UncheckedXmlStreamException(e); } + }); return parametersSet; } @@ -159,12 +169,16 @@ private static void skipComments(XMLStreamReader xmlReader) throws XMLStreamExce } } - private static void closeAndThrowException(XMLStreamReader xmlReader, String unexpectedElement) throws XMLStreamException { - xmlReader.close(); + private static void closeAndThrowException(XMLStreamReader xmlReader, String unexpectedElement) { + try { + xmlReader.close(); + } catch (XMLStreamException e) { + throw new UncheckedXmlStreamException(e); + } throw new PowsyblException("Unexpected element: " + unexpectedElement); } - public static void write(Path workingDir, DynaWaltzContext context) throws IOException, XMLStreamException { + public static void write(Path workingDir, DynaWaltzContext context) { Objects.requireNonNull(workingDir); write(context.getDynamicModelsParameters(), context.getSimulationParFile(), workingDir, DYN_PREFIX); @@ -174,7 +188,7 @@ public static void write(Path workingDir, DynaWaltzContext context) throws IOExc write(List.of(parameters.getSolverParameters()), DynaWaltzParameters.SOLVER_OUTPUT_PARAMETERS_FILE, workingDir, ""); } - private static void write(Collection parametersSets, String filename, Path workingDir, String dynPrefix) throws IOException, XMLStreamException { + private static void write(Collection parametersSets, String filename, Path workingDir, String dynPrefix) { Path parametersPath = workingDir.resolve(filename); try (Writer writer = Files.newBufferedWriter(parametersPath, StandardCharsets.UTF_8)) { XMLStreamWriter xmlWriter = XmlStreamWriterFactory.newInstance(writer); @@ -191,6 +205,10 @@ private static void write(Collection parametersSets, String filen } finally { xmlWriter.close(); } + } catch (IOException e) { + throw new UncheckedIOException(e); + } catch (XMLStreamException e) { + throw new UncheckedXmlStreamException(e); } } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/XmlDynawaltzWriter.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/XmlDynawaltzWriter.java new file mode 100644 index 000000000..4668e8f06 --- /dev/null +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/XmlDynawaltzWriter.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) 2023, 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/. + * SPDX-License-Identifier: MPL-2.0 + */ +package com.powsybl.dynawaltz.xml; + +import com.powsybl.dynawaltz.DynaWaltzContext; + +import java.io.IOException; +import java.nio.file.Path; + +/** + * @author Florian Dupuy {@literal } + */ +@FunctionalInterface +public interface XmlDynawaltzWriter { + void createXmlFileFromContext(Path workingDir, DynaWaltzContext context) throws IOException; +} diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/DynaWaltzParametersTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/DynaWaltzParametersTest.java index c5c84add3..3a27d257a 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/DynaWaltzParametersTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/DynaWaltzParametersTest.java @@ -9,7 +9,7 @@ import com.powsybl.commons.PowsyblException; 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.dynamicsimulation.DynamicSimulationParameters; import com.powsybl.dynamicsimulation.json.JsonDynamicSimulationParameters; import com.powsybl.dynawaltz.DynaWaltzParameters.SolverType; @@ -31,7 +31,7 @@ /** * @author Marcos de Miguel {@literal } */ -class DynaWaltzParametersTest extends AbstractConverterTest { +class DynaWaltzParametersTest extends AbstractSerDeTest { public static final String USER_HOME = "/home/user/"; diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/DynaWaltzProviderTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/DynaWaltzProviderTest.java index 8324633b4..4f54899cc 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/DynaWaltzProviderTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/DynaWaltzProviderTest.java @@ -7,7 +7,8 @@ package com.powsybl.dynawaltz; import com.powsybl.commons.PowsyblException; -import com.powsybl.commons.test.AbstractConverterTest; +import com.powsybl.commons.reporter.Reporter; +import com.powsybl.commons.test.AbstractSerDeTest; import com.powsybl.computation.ComputationManager; import com.powsybl.computation.local.LocalCommandExecutor; import com.powsybl.computation.local.LocalComputationConfig; @@ -37,7 +38,7 @@ * @author Florian Dupuy {@literal } * @author Marcos de Miguel {@literal } */ -class DynaWaltzProviderTest extends AbstractConverterTest { +class DynaWaltzProviderTest extends AbstractSerDeTest { private static final String OUTPUT_IIDM_FILENAME = "outputIIDM.xml"; private DynaWaltzConfig config; @@ -49,9 +50,8 @@ public void setUp() throws IOException { } public static class CurvesSupplierMock implements CurvesSupplier { - @Override - public List get(Network network) { + public List get(Network network, Reporter reporter) { return Collections.singletonList(new DynaWaltzCurve("bus", "uPu")); } } @@ -86,7 +86,7 @@ void testWithMergeLoads() throws Exception { ComputationManager computationManager = new LocalComputationManager(new LocalComputationConfig(tmpDir, 1), commandExecutor, ForkJoinPool.commonPool()); DynamicSimulation.Runner dynawoSimulation = DynamicSimulation.find(); assertEquals(DynaWaltzProvider.NAME, dynawoSimulation.getName()); - DynamicSimulationResult result = dynawoSimulation.run(network, n -> Collections.emptyList(), EventModelsSupplier.empty(), + DynamicSimulationResult result = dynawoSimulation.run(network, (n, r) -> Collections.emptyList(), EventModelsSupplier.empty(), CurvesSupplier.empty(), network.getVariantManager().getWorkingVariantId(), computationManager, DynamicSimulationParameters.load()); assertNotNull(result); @@ -104,7 +104,7 @@ void testWithoutMergeLoads() throws Exception { dynamicSimulationParameters.addExtension(DynaWaltzParameters.class, dynaWaltzParameters); assertEquals(DynaWaltzProvider.NAME, dynawoSimulation.getName()); - DynamicSimulationResult result = dynawoSimulation.run(network, n -> Collections.emptyList(), EventModelsSupplier.empty(), + DynamicSimulationResult result = dynawoSimulation.run(network, (n, r) -> Collections.emptyList(), EventModelsSupplier.empty(), CurvesSupplier.empty(), network.getVariantManager().getWorkingVariantId(), computationManager, dynamicSimulationParameters); assertNotNull(result); @@ -128,7 +128,7 @@ void testWithDump() throws Exception { dynamicSimulationParameters.addExtension(DynaWaltzParameters.class, dynaWaltzParameters); assertEquals(DynaWaltzProvider.NAME, dynawoSimulation.getName()); - DynamicSimulationResult result = dynawoSimulation.run(network, n -> Collections.emptyList(), EventModelsSupplier.empty(), + DynamicSimulationResult result = dynawoSimulation.run(network, (n, r) -> Collections.emptyList(), EventModelsSupplier.empty(), CurvesSupplier.empty(), network.getVariantManager().getWorkingVariantId(), computationManager, dynamicSimulationParameters); assertNotNull(result); @@ -141,7 +141,7 @@ void testFail() throws Exception { ComputationManager computationManager = new LocalComputationManager(new LocalComputationConfig(tmpDir, 1), commandExecutor, ForkJoinPool.commonPool()); DynamicSimulation.Runner dynawoSimulation = DynamicSimulation.find(); assertEquals(DynaWaltzProvider.NAME, dynawoSimulation.getName()); - DynamicSimulationResult result = dynawoSimulation.run(network, n -> Collections.emptyList(), EventModelsSupplier.empty(), + DynamicSimulationResult result = dynawoSimulation.run(network, (n, r) -> Collections.emptyList(), EventModelsSupplier.empty(), CurvesSupplier.empty(), network.getVariantManager().getWorkingVariantId(), computationManager, DynamicSimulationParameters.load()); assertNotNull(result); @@ -155,7 +155,7 @@ void testWithoutCurves() throws Exception { ComputationManager computationManager = new LocalComputationManager(new LocalComputationConfig(tmpDir, 1), commandExecutor, ForkJoinPool.commonPool()); DynamicSimulation.Runner dynawoSimulation = DynamicSimulation.find(); assertEquals(DynaWaltzProvider.NAME, dynawoSimulation.getName()); - DynamicSimulationResult result = dynawoSimulation.run(network, n -> Collections.emptyList(), EventModelsSupplier.empty(), + DynamicSimulationResult result = dynawoSimulation.run(network, (n, r) -> Collections.emptyList(), EventModelsSupplier.empty(), new CurvesSupplierMock(), network.getVariantManager().getWorkingVariantId(), computationManager, DynamicSimulationParameters.load()); assertNotNull(result); @@ -189,7 +189,7 @@ void testCallingBadVersionDynawo() throws Exception { ComputationManager computationManager = new LocalComputationManager(new LocalComputationConfig(tmpDir, 1), commandExecutor, ForkJoinPool.commonPool()); DynamicSimulation.Runner dynawoSimulation = DynamicSimulation.find(); assertEquals(DynaWaltzProvider.NAME, dynawoSimulation.getName()); - DynamicModelsSupplier dms = n -> Collections.emptyList(); + DynamicModelsSupplier dms = (n, r) -> Collections.emptyList(); EventModelsSupplier ems = EventModelsSupplier.empty(); CurvesSupplier cs = CurvesSupplier.empty(); String wvId = network.getVariantManager().getWorkingVariantId(); diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/models/lines/StandardLineTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/models/lines/StandardLineTest.java index 9ec9353b2..7ba3f1ab7 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/models/lines/StandardLineTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/models/lines/StandardLineTest.java @@ -12,7 +12,6 @@ import com.powsybl.dynawaltz.DynaWaltzContext; import com.powsybl.dynawaltz.DynaWaltzParameters; import com.powsybl.dynawaltz.models.BlackBoxModel; -import com.powsybl.dynawaltz.models.Side; import com.powsybl.dynawaltz.models.automatons.CurrentLimitAutomaton; import com.powsybl.iidm.network.*; import org.junit.jupiter.api.Test; @@ -42,7 +41,7 @@ void connectionToCurrentLimitAutomatonException() { List dynamicModels = new ArrayList<>(); dynamicModels.add(new StandardLine("BBM_l", l, "SL")); - dynamicModels.add(new CurrentLimitAutomaton("BBM_CLA", "CLA", l, Side.ONE, "CurrentLimitAutomaton")); + dynamicModels.add(new CurrentLimitAutomaton("BBM_CLA", "CLA", l, TwoSides.ONE, "CurrentLimitAutomaton")); DynamicSimulationParameters parameters = DynamicSimulationParameters.load(); DynaWaltzParameters dynawoParameters = DynaWaltzParameters.load(); String workingVariantId = network.getVariantManager().getWorkingVariantId(); diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/AbstractDynamicModelXmlTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/AbstractDynamicModelXmlTest.java index f8f909f3d..74a4f73a5 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/AbstractDynamicModelXmlTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/AbstractDynamicModelXmlTest.java @@ -7,7 +7,7 @@ */ package com.powsybl.dynawaltz.xml; -import com.powsybl.commons.test.AbstractConverterTest; +import com.powsybl.commons.test.AbstractSerDeTest; import com.powsybl.dynamicsimulation.Curve; import com.powsybl.dynamicsimulation.DynamicSimulationParameters; import com.powsybl.dynawaltz.DynaWaltzContext; @@ -37,7 +37,7 @@ /** * @author Laurent Issertial {@literal } */ -public abstract class AbstractDynamicModelXmlTest extends AbstractConverterTest { +public abstract class AbstractDynamicModelXmlTest extends AbstractSerDeTest { protected Network network; protected List dynamicModels = new ArrayList<>(); diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/AbstractParametrizedDynamicModelXmlTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/AbstractParametrizedDynamicModelXmlTest.java index 253fd2dc5..c0a138037 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/AbstractParametrizedDynamicModelXmlTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/AbstractParametrizedDynamicModelXmlTest.java @@ -7,7 +7,7 @@ */ package com.powsybl.dynawaltz.xml; -import com.powsybl.commons.test.AbstractConverterTest; +import com.powsybl.commons.test.AbstractSerDeTest; import com.powsybl.dynamicsimulation.Curve; import com.powsybl.dynamicsimulation.DynamicSimulationParameters; import com.powsybl.dynawaltz.DynaWaltzContext; @@ -35,7 +35,7 @@ /** * @author Laurent Issertial {@literal } */ -abstract class AbstractParametrizedDynamicModelXmlTest extends AbstractConverterTest { +abstract class AbstractParametrizedDynamicModelXmlTest extends AbstractSerDeTest { protected Network network; protected List dynamicModels = new ArrayList<>(); diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/CurrentLimitModelXmlTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/CurrentLimitModelXmlTest.java index 3d8970272..041a8c232 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/CurrentLimitModelXmlTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/CurrentLimitModelXmlTest.java @@ -7,9 +7,9 @@ */ package com.powsybl.dynawaltz.xml; -import com.powsybl.dynawaltz.models.Side; import com.powsybl.dynawaltz.models.automatons.CurrentLimitAutomaton; import com.powsybl.dynawaltz.models.transformers.TransformerFixedRatio; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; import org.junit.jupiter.api.Test; import org.xml.sax.SAXException; @@ -29,10 +29,10 @@ protected void setupNetwork() { @Override protected void addDynamicModels() { - dynamicModels.add(new CurrentLimitAutomaton("BBM_CLA_LINE", "cla", network.getLine("NHV1_NHV2_1"), Side.ONE, "CurrentLimitAutomaton")); - dynamicModels.add(new CurrentLimitAutomaton("BBM_CLA_TRANSFORMER", "cla", network.getTwoWindingsTransformer("NGEN_NHV1"), Side.TWO, "CurrentLimitAutomaton")); + dynamicModels.add(new CurrentLimitAutomaton("BBM_CLA_LINE", "cla", network.getLine("NHV1_NHV2_1"), TwoSides.ONE, "CurrentLimitAutomaton")); + dynamicModels.add(new CurrentLimitAutomaton("BBM_CLA_TRANSFORMER", "cla", network.getTwoWindingsTransformer("NGEN_NHV1"), TwoSides.TWO, "CurrentLimitAutomaton")); dynamicModels.add(new TransformerFixedRatio("BBM_TRANSFORMER", network.getTwoWindingsTransformer("NHV2_NLOAD"), "tf", "TransformerFixedRatio")); - dynamicModels.add(new CurrentLimitAutomaton("BBM_CLA_TRANSFORMER2", "cla", network.getTwoWindingsTransformer("NHV2_NLOAD"), Side.TWO, network.getLine("NHV1_NHV2_1"), "CurrentLimitAutomaton")); + dynamicModels.add(new CurrentLimitAutomaton("BBM_CLA_TRANSFORMER2", "cla", network.getTwoWindingsTransformer("NHV2_NLOAD"), TwoSides.TWO, network.getLine("NHV1_NHV2_1"), "CurrentLimitAutomaton")); } @Test diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/CurrentLimitTwoLevelsModelXmlTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/CurrentLimitTwoLevelsModelXmlTest.java index 813835f8b..9afffaa5d 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/CurrentLimitTwoLevelsModelXmlTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/CurrentLimitTwoLevelsModelXmlTest.java @@ -7,8 +7,8 @@ */ package com.powsybl.dynawaltz.xml; -import com.powsybl.dynawaltz.models.Side; import com.powsybl.dynawaltz.models.automatons.CurrentLimitTwoLevelsAutomaton; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; import org.junit.jupiter.api.Test; import org.xml.sax.SAXException; @@ -28,7 +28,7 @@ protected void setupNetwork() { @Override protected void addDynamicModels() { - dynamicModels.add(new CurrentLimitTwoLevelsAutomaton("BBM_CLA_TWO_LEVELS", "cla", network.getLine("NHV1_NHV2_1"), Side.TWO, network.getLine("NHV1_NHV2_2"), Side.ONE, network.getTwoWindingsTransformer("NGEN_NHV1"), "CurrentLimitAutomatonTwoLevels")); + dynamicModels.add(new CurrentLimitTwoLevelsAutomaton("BBM_CLA_TWO_LEVELS", "cla", network.getLine("NHV1_NHV2_1"), TwoSides.TWO, network.getLine("NHV1_NHV2_2"), TwoSides.ONE, network.getTwoWindingsTransformer("NGEN_NHV1"), "CurrentLimitAutomatonTwoLevels")); } @Test diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/DisconnectHvdcEventXmlTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/DisconnectHvdcEventXmlTest.java index c51021bc5..8cd7d3d02 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/DisconnectHvdcEventXmlTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/DisconnectHvdcEventXmlTest.java @@ -8,13 +8,13 @@ package com.powsybl.dynawaltz.xml; import com.powsybl.dynawaltz.models.BlackBoxModel; -import com.powsybl.dynawaltz.models.Side; import com.powsybl.dynawaltz.models.events.EventHvdcDisconnection; import com.powsybl.dynawaltz.models.hvdc.HvdcP; import com.powsybl.dynawaltz.models.hvdc.HvdcPDangling; import com.powsybl.dynawaltz.models.hvdc.HvdcVsc; import com.powsybl.dynawaltz.models.hvdc.HvdcVscDangling; import com.powsybl.iidm.network.Network; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.iidm.network.test.HvdcTestNetwork; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtendWith; @@ -77,10 +77,10 @@ private static Stream provideModels() { (Function) n -> new HvdcVsc(DYN_HVDC_NAME, n.getHvdcLine(HVDC_NAME), "hvdc", "HvdcVsc"), (Function) n -> new EventHvdcDisconnection(n.getHvdcLine(HVDC_NAME), 1, false, true)), Arguments.of("disconnect_hvdc_pv_dangling_dyd.xml", - (Function) n -> new HvdcPDangling(DYN_HVDC_NAME, n.getHvdcLine(HVDC_NAME), "hvdc", "HvdcPVDangling", Side.TWO), + (Function) n -> new HvdcPDangling(DYN_HVDC_NAME, n.getHvdcLine(HVDC_NAME), "hvdc", "HvdcPVDangling", TwoSides.TWO), (Function) n -> new EventHvdcDisconnection(n.getHvdcLine(HVDC_NAME), 1, true, false)), Arguments.of("disconnect_hvdc_vsc_dangling_dyd.xml", - (Function) n -> new HvdcVscDangling(DYN_HVDC_NAME, n.getHvdcLine(HVDC_NAME), "hvdc", "HvdcVSCDanglingUdc", Side.ONE), + (Function) n -> new HvdcVscDangling(DYN_HVDC_NAME, n.getHvdcLine(HVDC_NAME), "hvdc", "HvdcVSCDanglingUdc", TwoSides.ONE), (Function) n -> new EventHvdcDisconnection(n.getHvdcLine(HVDC_NAME), 1, false, true)) ); } diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/DisconnectionExceptionXmlTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/DisconnectionExceptionXmlTest.java index 1e7b3cc0e..d90a149d7 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/DisconnectionExceptionXmlTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/DisconnectionExceptionXmlTest.java @@ -9,11 +9,11 @@ import com.powsybl.commons.PowsyblException; import com.powsybl.dynawaltz.models.BlackBoxModel; -import com.powsybl.dynawaltz.models.Side; import com.powsybl.dynawaltz.models.events.EventHvdcDisconnection; import com.powsybl.dynawaltz.models.hvdc.HvdcPDangling; import com.powsybl.dynawaltz.models.hvdc.HvdcVscDangling; import com.powsybl.iidm.network.HvdcLine; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.iidm.network.test.HvdcTestNetwork; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtendWith; @@ -34,7 +34,7 @@ class DisconnectionExceptionXmlTest extends AbstractParametrizedDynamicModelXmlTest { @BeforeEach - void setup(String exception, Side side, BiFunction constructor) { + void setup(String exception, TwoSides side, BiFunction constructor) { setupNetwork(); addDynamicModels(side, constructor); } @@ -43,16 +43,16 @@ protected void setupNetwork() { network = HvdcTestNetwork.createVsc(); } - protected void addDynamicModels(Side side, BiFunction constructor) { + protected void addDynamicModels(TwoSides side, BiFunction constructor) { HvdcLine hvdc = network.getHvdcLine("L"); dynamicModels.add(constructor.apply(hvdc, side)); - boolean disconnectOrigin = Side.ONE == side; + boolean disconnectOrigin = TwoSides.ONE == side; eventModels.add(new EventHvdcDisconnection(hvdc, 1, disconnectOrigin, !disconnectOrigin)); } @ParameterizedTest(name = "{0}") @MethodSource("provideModels") - void disconnectionOnDanglingSide(String exception, Side side, BiFunction constructor) { + void disconnectionOnDanglingSide(String exception, TwoSides side, BiFunction constructor) { Exception e = assertThrows(PowsyblException.class, this::setupDynawaltzContext); assertEquals(exception, e.getMessage()); } @@ -60,11 +60,11 @@ void disconnectionOnDanglingSide(String exception, Side side, BiFunction provideModels() { return Stream.of( Arguments.of("Equipment HvdcPVDangling side 1 is dangling and can't be disconnected with an event", - Side.ONE, - (BiFunction) (hvdc, side) -> new HvdcPDangling("BBM_L", hvdc, "hvdc", "HvdcPVDangling", side)), + TwoSides.ONE, + (BiFunction) (hvdc, side) -> new HvdcPDangling("BBM_L", hvdc, "hvdc", "HvdcPVDangling", side)), Arguments.of("Equipment HvdcVSCDanglingUdc side 2 is dangling and can't be disconnected with an event", - Side.TWO, - (BiFunction) (hvdc, side) -> new HvdcVscDangling("BBM_L", hvdc, "hvdc", "HvdcVSCDanglingUdc", side)) + TwoSides.TWO, + (BiFunction) (hvdc, side) -> new HvdcVscDangling("BBM_L", hvdc, "hvdc", "HvdcVSCDanglingUdc", side)) ); } } diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/DynaWaltzTestUtil.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/DynaWaltzTestUtil.java index 8dc9a2052..69cebbc11 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/DynaWaltzTestUtil.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/DynaWaltzTestUtil.java @@ -6,17 +6,16 @@ */ package com.powsybl.dynawaltz.xml; -import com.powsybl.commons.test.AbstractConverterTest; +import com.powsybl.commons.test.AbstractSerDeTest; import com.powsybl.dynamicsimulation.Curve; import com.powsybl.dynawaltz.DynaWaltzCurve; import com.powsybl.dynawaltz.models.BlackBoxModel; -import com.powsybl.dynawaltz.models.Side; import com.powsybl.dynawaltz.models.automatons.CurrentLimitAutomaton; import com.powsybl.dynawaltz.models.events.EventInjectionDisconnection; import com.powsybl.dynawaltz.models.events.EventQuadripoleDisconnection; import com.powsybl.dynawaltz.models.generators.GeneratorFictitious; -import com.powsybl.dynawaltz.models.generators.SynchronousGenerator; import com.powsybl.dynawaltz.models.generators.SynchronizedGenerator; +import com.powsybl.dynawaltz.models.generators.SynchronousGenerator; import com.powsybl.dynawaltz.models.lines.StandardLine; import com.powsybl.dynawaltz.models.loads.BaseLoad; import com.powsybl.dynawaltz.models.loads.LoadOneTransformer; @@ -43,7 +42,7 @@ /** * @author Marcos de Miguel {@literal } */ -public class DynaWaltzTestUtil extends AbstractConverterTest { +public class DynaWaltzTestUtil extends AbstractSerDeTest { protected Network network; protected List dynamicModels; @@ -107,7 +106,7 @@ void setup() { // Automatons network.getLineStream().filter(line -> line != standardLine) - .forEach(l -> dynamicModels.add(new CurrentLimitAutomaton("BBM_" + l.getId(), "CLA", l, Side.ONE, "CurrentLimitAutomaton"))); + .forEach(l -> dynamicModels.add(new CurrentLimitAutomaton("BBM_" + l.getId(), "CLA", l, TwoSides.ONE, "CurrentLimitAutomaton"))); } public void validate(String schemaDefinition, String expectedResourceName, Path xmlFile) throws SAXException, IOException { diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/HvdcXmlTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/HvdcXmlTest.java index 1a017930a..8cf9a40c6 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/HvdcXmlTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/HvdcXmlTest.java @@ -8,12 +8,12 @@ package com.powsybl.dynawaltz.xml; import com.powsybl.dynawaltz.models.BlackBoxModel; -import com.powsybl.dynawaltz.models.Side; import com.powsybl.dynawaltz.models.hvdc.HvdcP; import com.powsybl.dynawaltz.models.hvdc.HvdcPDangling; import com.powsybl.dynawaltz.models.hvdc.HvdcVsc; import com.powsybl.dynawaltz.models.hvdc.HvdcVscDangling; import com.powsybl.iidm.network.Network; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.iidm.network.test.HvdcTestNetwork; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtendWith; @@ -62,8 +62,8 @@ private static Stream provideHvdc() { return Stream.of( Arguments.of("hvdc_p_dyd.xml", (Function) n -> new HvdcP(DYN_NAME, n.getHvdcLine(HVDC_NAME), "hv", "HvdcPV")), Arguments.of("hvdc_vsc_dyd.xml", (Function) n -> new HvdcVsc(DYN_NAME, n.getHvdcLine(HVDC_NAME), "hv", "HvdcVSC")), - Arguments.of("hvdc_p_dangling_dyd.xml", (Function) n -> new HvdcPDangling(DYN_NAME, n.getHvdcLine(HVDC_NAME), "hv", "HvdcPVDangling", Side.ONE)), - Arguments.of("hvdc_vsc_dangling_dyd.xml", (Function) n -> new HvdcVscDangling(DYN_NAME, n.getHvdcLine(HVDC_NAME), "hv", "HvdcVSCDanglingP", Side.TWO)) + Arguments.of("hvdc_p_dangling_dyd.xml", (Function) n -> new HvdcPDangling(DYN_NAME, n.getHvdcLine(HVDC_NAME), "hv", "HvdcPVDangling", TwoSides.ONE)), + Arguments.of("hvdc_vsc_dangling_dyd.xml", (Function) n -> new HvdcVscDangling(DYN_NAME, n.getHvdcLine(HVDC_NAME), "hv", "HvdcVSCDanglingP", TwoSides.TWO)) ); } } diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/ParametersXmlTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/ParametersXmlTest.java index 8ee5e79bb..e71d57ba9 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/ParametersXmlTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/ParametersXmlTest.java @@ -13,7 +13,6 @@ import org.junit.jupiter.api.Test; import org.xml.sax.SAXException; -import javax.xml.stream.XMLStreamException; import java.io.IOException; /** @@ -22,7 +21,7 @@ class ParametersXmlTest extends DynaWaltzTestUtil { @Test - void writeOmegaRef() throws SAXException, IOException, XMLStreamException { + void writeOmegaRef() throws SAXException, IOException { DynamicSimulationParameters parameters = DynamicSimulationParameters.load(); DynaWaltzParameters dynawoParameters = DynaWaltzParameters.load(PlatformConfig.defaultConfig(), fileSystem); DynaWaltzContext context = new DynaWaltzContext(network, network.getVariantManager().getWorkingVariantId(), dynamicModels, eventModels, curves, parameters, dynawoParameters); diff --git a/dynawo-integration-tests/src/test/java/com/powsybl/dynawo/it/DynaWaltzTest.java b/dynawo-integration-tests/src/test/java/com/powsybl/dynawo/it/DynaWaltzTest.java index b60287a5c..09fce25bf 100644 --- a/dynawo-integration-tests/src/test/java/com/powsybl/dynawo/it/DynaWaltzTest.java +++ b/dynawo-integration-tests/src/test/java/com/powsybl/dynawo/it/DynaWaltzTest.java @@ -8,6 +8,7 @@ import com.powsybl.commons.datasource.ResourceDataSource; import com.powsybl.commons.datasource.ResourceSet; +import com.powsybl.commons.reporter.Reporter; import com.powsybl.dynamicsimulation.*; import com.powsybl.dynamicsimulation.groovy.*; import com.powsybl.dynawaltz.DumpFileParameters; @@ -81,7 +82,7 @@ void testIeee14() { .setDefaultDumpFileParameters(); DynamicSimulationResult result = provider.run(network, dynamicModelsSupplier, eventModelsSupplier, curvesSupplier, - VariantManagerConstants.INITIAL_VARIANT_ID, computationManager, parameters) + VariantManagerConstants.INITIAL_VARIANT_ID, computationManager, parameters, Reporter.NO_OP) .join(); assertTrue(result.isOk()); @@ -125,7 +126,7 @@ void testIeee14WithDump() throws IOException { .setDumpFileParameters(dumpFileParameters); DynamicSimulationResult result = provider.run(network, dynamicModelsSupplier, eventModelsSupplier, curvesSupplier, - VariantManagerConstants.INITIAL_VARIANT_ID, computationManager, parameters) + VariantManagerConstants.INITIAL_VARIANT_ID, computationManager, parameters, Reporter.NO_OP) .join(); assertTrue(result.isOk()); @@ -140,7 +141,7 @@ void testIeee14WithDump() throws IOException { dynaWaltzParameters.setDumpFileParameters(DumpFileParameters.createImportDumpFileParameters(dumpDir, dumpFile)); result = provider.run(network, dynamicModelsSupplier, eventModelsSupplier, curvesSupplier, - VariantManagerConstants.INITIAL_VARIANT_ID, computationManager, parameters) + VariantManagerConstants.INITIAL_VARIANT_ID, computationManager, parameters, Reporter.NO_OP) .join(); assertTrue(result.isOk()); @@ -165,7 +166,7 @@ void testSvc() { .setDefaultDumpFileParameters(); DynamicSimulationResult result = provider.run(network, dynamicModelsSupplier, EventModelsSupplier.empty(), CurvesSupplier.empty(), - VariantManagerConstants.INITIAL_VARIANT_ID, computationManager, parameters) + VariantManagerConstants.INITIAL_VARIANT_ID, computationManager, parameters, Reporter.NO_OP) .join(); assertTrue(result.isOk()); @@ -193,7 +194,7 @@ void testHvdc() { .setDefaultDumpFileParameters(); DynamicSimulationResult result = provider.run(network, dynamicModelsSupplier, EventModelsSupplier.empty(), CurvesSupplier.empty(), - VariantManagerConstants.INITIAL_VARIANT_ID, computationManager, parameters) + VariantManagerConstants.INITIAL_VARIANT_ID, computationManager, parameters, Reporter.NO_OP) .join(); assertTrue(result.isOk()); @@ -230,7 +231,7 @@ void testSmib() { .setDefaultDumpFileParameters(); DynamicSimulationResult result = provider.run(network, dynamicModelsSupplier, eventModelsSupplier, curvesSupplier, - VariantManagerConstants.INITIAL_VARIANT_ID, computationManager, parameters) + VariantManagerConstants.INITIAL_VARIANT_ID, computationManager, parameters, Reporter.NO_OP) .join(); assertTrue(result.isOk()); diff --git a/pom.xml b/pom.xml index ddfdb8c4c..ec3734768 100644 --- a/pom.xml +++ b/pom.xml @@ -56,7 +56,7 @@ 17 - 6.0.1 + 6.1.0-alpha-1 4.0.14 ../distribution/target/site/jacoco-aggregate/jacoco.xml,