From 873dcb048a25ced37ac85b9c87829d7aa228c467 Mon Sep 17 00:00:00 2001 From: Peter Mitri Date: Wed, 26 Jun 2024 16:51:31 +0200 Subject: [PATCH 1/8] Fix cucumber tests steps (#1064) --- .../powsybl/openrao/tests/steps/AngleMonitoringSteps.java | 2 ++ .../powsybl/openrao/tests/steps/SearchTreeRaoSteps.java | 7 ++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/src/test/java/com/powsybl/openrao/tests/steps/AngleMonitoringSteps.java b/tests/src/test/java/com/powsybl/openrao/tests/steps/AngleMonitoringSteps.java index 42e0c79ff9..ea9ca2b56e 100644 --- a/tests/src/test/java/com/powsybl/openrao/tests/steps/AngleMonitoringSteps.java +++ b/tests/src/test/java/com/powsybl/openrao/tests/steps/AngleMonitoringSteps.java @@ -9,6 +9,7 @@ import com.powsybl.glsk.cim.CimGlskDocument; import com.powsybl.iidm.network.Network; import com.powsybl.loadflow.LoadFlowParameters; +import com.powsybl.openrao.commons.PhysicalParameter; import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.Instant; @@ -76,6 +77,7 @@ private AngleMonitoringResult roundTripOnAngleMonitoringResult(AngleMonitoringRe @Then("the angle monitoring result is {string}") public void statusCheck(String expectedStatus) { assertEquals(CommonTestData.getAngleMonitoringResult().getStatus().toString(), expectedStatus); + assertEquals(expectedStatus.equalsIgnoreCase("secure"), CommonTestData.getRaoResult().isSecure(PhysicalParameter.ANGLE)); } @Then("the applied remedial actions should be:") diff --git a/tests/src/test/java/com/powsybl/openrao/tests/steps/SearchTreeRaoSteps.java b/tests/src/test/java/com/powsybl/openrao/tests/steps/SearchTreeRaoSteps.java index d662265e6b..2426713350 100644 --- a/tests/src/test/java/com/powsybl/openrao/tests/steps/SearchTreeRaoSteps.java +++ b/tests/src/test/java/com/powsybl/openrao/tests/steps/SearchTreeRaoSteps.java @@ -9,6 +9,7 @@ import com.powsybl.glsk.commons.ZonalData; import com.powsybl.iidm.network.Network; import com.powsybl.openrao.commons.OpenRaoException; +import com.powsybl.openrao.commons.PhysicalParameter; import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.Instant; @@ -143,11 +144,7 @@ public void theCalculationFails() { @Then("its security status should be {string}") public void statusShouldBe(String status) { - if (status.equalsIgnoreCase("secured")) { - assertTrue(raoResult.isSecure()); - } else { - assertFalse(raoResult.isSecure()); - } + assertEquals(status.equalsIgnoreCase("secured"), raoResult.isSecure(PhysicalParameter.FLOW)); } @Then("the value of the objective function initially should be {double}") From 16556cb426296ca72fc20043f603d7cc21c9786b Mon Sep 17 00:00:00 2001 From: Thomas Bouquet <63302082+bqth29@users.noreply.github.com> Date: Wed, 26 Jun 2024 17:01:57 +0200 Subject: [PATCH 2/8] Harmonize I/O APIs for Json CRAC and Json RaoResult with PowSyBl's Network (#1040) --- .../crac-creator-csa-profiles/pom.xml | 5 - data/crac-io/crac-io-api/pom.xml | 46 -- .../openrao/data/cracioapi/CracExporter.java | 28 - .../openrao/data/cracioapi/CracExporters.java | 75 --- .../openrao/data/cracioapi/CracImporter.java | 30 - .../openrao/data/cracioapi/CracImporters.java | 79 --- .../data/cracioapi/CracExporterMock.java | 29 - .../cracioapi/CracExportersImportersTest.java | 48 -- .../data/cracioapi/CracImporterMock.java | 39 -- .../crac-io-api/src/test/resources/empty.txt | 0 .../src/test/resources/logback-test.xml | 11 - data/crac-io/crac-io-json/pom.xml | 5 - .../openrao/data/craciojson/JsonExport.java | 16 +- .../openrao/data/craciojson/JsonImport.java | 52 +- .../deserializers/CracDeserializer.java | 38 +- .../data/craciojson/CracImportExportTest.java | 66 +- .../JsonRetrocompatibilityTest.java | 40 +- .../data/craciojson/RoundTripUtil.java | 16 +- .../src/test/resources/cracHeader.json | 4 + .../src/test/resources/invalidCrac.json | 3 + .../src/test/resources/invalidCrac.txt | 1 + data/crac-io/pom.xml | 1 - .../powsybl/openrao/data/cracapi/Crac.java | 93 ++- .../openrao/data/cracapi/io/Exporter.java | 22 + .../openrao/data/cracapi/io/Importer.java | 37 + .../openrao/data/cracapi/CracExportTest.java | 43 ++ .../openrao/data/cracapi/CracImportTest.java | 25 + .../openrao/data/cracapi/MockCrac.java | 473 +++++++++++++ .../data/cracapi/MockCracExporter.java | 31 + .../data/cracapi/MockCracImporter.java | 36 + .../crac/crac-api/src/test/resources/crac.txt | 1 + ...LoopFlowThresholdImplImportExportTest.java | 6 +- data/crac/crac-util/pom.xml | 6 - .../data/cracutil/CracAliasesCreatorTest.java | 18 +- .../src/test/resources/crac-for-aliases.json | 264 -------- .../deprecated-crac-for-aliases-1.json | 30 +- .../deprecated-crac-for-aliases-2.json | 22 +- .../deprecated-crac-for-aliases-3.json | 24 +- .../deprecated-crac-for-aliases-4.json | 24 +- .../openrao/data/raoresultapi/RaoResult.java | 70 +- .../data/raoresultapi/io/Exporter.java | 27 + .../data/raoresultapi/io/Importer.java | 34 + .../data/raoresultapi/MockRaoResult.java | 182 +++++ .../raoresultapi/MockRaoResultExporter.java | 34 + .../raoresultapi/MockRaoResultImporter.java | 35 + .../raoresultapi/RaoResultExportTest.java | 45 ++ .../raoresultapi/RaoResultImportTest.java | 25 + .../src/test/resources/raoResult.txt | 1 + ...porter.java => RaoResultJsonExporter.java} | 12 +- ...porter.java => RaoResultJsonImporter.java} | 29 +- .../deserializers/RaoResultDeserializer.java | 56 +- .../ImporterRetrocompatibilityTest.java | 63 +- .../raoresultjson/RaoResultRoundTripTest.java | 636 ++++++++++-------- .../SweCneDivergentAngleMonitoringTest.java | 5 +- .../data/swecneexporter/SweCneTest.java | 7 +- distribution/pom.xml | 5 - docs/input-data/crac/import.md | 14 +- docs/output-data/rao-result.md | 4 +- .../flowbased-computation-api/pom.xml | 5 - .../impl/ExampleGenerator.java | 6 +- .../impl/FlowbasedComputationImplTest.java | 9 +- .../RaoResultWithAngleMonitoringTest.java | 9 +- .../RaoResultWithVoltageMonitoringTest.java | 9 +- ra-optimisation/rao-api/pom.xml | 5 - .../algorithm/CastorFullOptimizationTest.java | 72 +- .../fillers/AbstractFillerTest.java | 6 +- .../ContinuousRangeActionGroupFillerTest.java | 3 +- .../fillers/CoreProblemFillerTest.java | 3 +- .../fillers/DiscretePstGroupFillerTest.java | 3 +- .../fillers/DiscretePstTapFillerTest.java | 3 +- .../fillers/MaxLoopFlowFillerTest.java | 3 +- .../fillers/MaxMinMarginFillerTest.java | 3 +- .../MaxMinRelativeMarginFillerTest.java | 3 +- .../algorithms/fillers/MnecFillerTest.java | 3 +- .../fillers/RaUsageLimitsFillerTest.java | 3 +- ...mizedCnecFillerMarginDecreaseRuleTest.java | 3 +- .../parameters/SearchTreeParametersTest.java | 8 +- tests/pom.xml | 6 - .../powsybl/openrao/tests/utils/Helpers.java | 20 +- .../powsybl/openrao/tests/utils/RaoUtils.java | 13 +- 80 files changed, 1992 insertions(+), 1277 deletions(-) delete mode 100644 data/crac-io/crac-io-api/pom.xml delete mode 100644 data/crac-io/crac-io-api/src/main/java/com/powsybl/openrao/data/cracioapi/CracExporter.java delete mode 100644 data/crac-io/crac-io-api/src/main/java/com/powsybl/openrao/data/cracioapi/CracExporters.java delete mode 100644 data/crac-io/crac-io-api/src/main/java/com/powsybl/openrao/data/cracioapi/CracImporter.java delete mode 100644 data/crac-io/crac-io-api/src/main/java/com/powsybl/openrao/data/cracioapi/CracImporters.java delete mode 100644 data/crac-io/crac-io-api/src/test/java/com/powsybl/openrao/data/cracioapi/CracExporterMock.java delete mode 100644 data/crac-io/crac-io-api/src/test/java/com/powsybl/openrao/data/cracioapi/CracExportersImportersTest.java delete mode 100644 data/crac-io/crac-io-api/src/test/java/com/powsybl/openrao/data/cracioapi/CracImporterMock.java delete mode 100644 data/crac-io/crac-io-api/src/test/resources/empty.txt delete mode 100644 data/crac-io/crac-io-api/src/test/resources/logback-test.xml create mode 100644 data/crac-io/crac-io-json/src/test/resources/cracHeader.json create mode 100644 data/crac-io/crac-io-json/src/test/resources/invalidCrac.json create mode 100644 data/crac-io/crac-io-json/src/test/resources/invalidCrac.txt create mode 100644 data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/io/Exporter.java create mode 100644 data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/io/Importer.java create mode 100644 data/crac/crac-api/src/test/java/com/powsybl/openrao/data/cracapi/CracExportTest.java create mode 100644 data/crac/crac-api/src/test/java/com/powsybl/openrao/data/cracapi/CracImportTest.java create mode 100644 data/crac/crac-api/src/test/java/com/powsybl/openrao/data/cracapi/MockCrac.java create mode 100644 data/crac/crac-api/src/test/java/com/powsybl/openrao/data/cracapi/MockCracExporter.java create mode 100644 data/crac/crac-api/src/test/java/com/powsybl/openrao/data/cracapi/MockCracImporter.java create mode 100644 data/crac/crac-api/src/test/resources/crac.txt delete mode 100644 data/crac/crac-util/src/test/resources/crac-for-aliases.json create mode 100644 data/rao-result/rao-result-api/src/main/java/com/powsybl/openrao/data/raoresultapi/io/Exporter.java create mode 100644 data/rao-result/rao-result-api/src/main/java/com/powsybl/openrao/data/raoresultapi/io/Importer.java create mode 100644 data/rao-result/rao-result-api/src/test/java/com/powsybl/openrao/data/raoresultapi/MockRaoResult.java create mode 100644 data/rao-result/rao-result-api/src/test/java/com/powsybl/openrao/data/raoresultapi/MockRaoResultExporter.java create mode 100644 data/rao-result/rao-result-api/src/test/java/com/powsybl/openrao/data/raoresultapi/MockRaoResultImporter.java create mode 100644 data/rao-result/rao-result-api/src/test/java/com/powsybl/openrao/data/raoresultapi/RaoResultExportTest.java create mode 100644 data/rao-result/rao-result-api/src/test/java/com/powsybl/openrao/data/raoresultapi/RaoResultImportTest.java create mode 100644 data/rao-result/rao-result-api/src/test/resources/raoResult.txt rename data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/{RaoResultExporter.java => RaoResultJsonExporter.java} (83%) rename data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/{RaoResultImporter.java => RaoResultJsonImporter.java} (56%) diff --git a/data/crac-creation/crac-creator-csa-profiles/pom.xml b/data/crac-creation/crac-creator-csa-profiles/pom.xml index cc83ba4347..3c2c23db9e 100644 --- a/data/crac-creation/crac-creator-csa-profiles/pom.xml +++ b/data/crac-creation/crac-creator-csa-profiles/pom.xml @@ -53,11 +53,6 @@ open-rao-crac-creation-util ${project.version} - - ${project.groupId} - open-rao-crac-io-api - ${project.version} - ${project.groupId} open-rao-crac-util diff --git a/data/crac-io/crac-io-api/pom.xml b/data/crac-io/crac-io-api/pom.xml deleted file mode 100644 index 32367849d6..0000000000 --- a/data/crac-io/crac-io-api/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - open-rao-crac-io - com.powsybl - 5.6.0-SNAPSHOT - - 4.0.0 - - open-rao-crac-io-api - jar - CRAC import/export management - API for CRAC import and export management - - - - ${project.groupId} - open-rao-commons - ${project.version} - - - ${project.groupId} - open-rao-crac-api - ${project.version} - - - - ch.qos.logback - logback-classic - test - - - org.junit.jupiter - junit-jupiter - test - - - org.mockito - mockito-inline - test - - - - \ No newline at end of file diff --git a/data/crac-io/crac-io-api/src/main/java/com/powsybl/openrao/data/cracioapi/CracExporter.java b/data/crac-io/crac-io-api/src/main/java/com/powsybl/openrao/data/cracioapi/CracExporter.java deleted file mode 100644 index 40560fdf61..0000000000 --- a/data/crac-io/crac-io-api/src/main/java/com/powsybl/openrao/data/cracioapi/CracExporter.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2019, 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/. - */ - -package com.powsybl.openrao.data.cracioapi; - -import com.powsybl.openrao.data.cracapi.Crac; -import com.powsybl.iidm.network.Network; - -import java.io.OutputStream; - -/** - * Interface for CRAC object export - * - * @author Joris Mancini {@literal } - */ - -public interface CracExporter { - - String getFormat(); - - void exportCrac(Crac crac, OutputStream outputStream); - - void exportCrac(Crac crac, Network network, OutputStream outputStream); -} diff --git a/data/crac-io/crac-io-api/src/main/java/com/powsybl/openrao/data/cracioapi/CracExporters.java b/data/crac-io/crac-io-api/src/main/java/com/powsybl/openrao/data/cracioapi/CracExporters.java deleted file mode 100644 index 53ea4b9b00..0000000000 --- a/data/crac-io/crac-io-api/src/main/java/com/powsybl/openrao/data/cracioapi/CracExporters.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2019, 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/. - */ - -package com.powsybl.openrao.data.cracioapi; - -import com.powsybl.openrao.commons.OpenRaoException; -import com.powsybl.openrao.data.cracapi.Crac; - -import java.io.*; -import java.nio.file.Path; -import java.util.function.Supplier; -import com.google.common.base.Suppliers; -import com.powsybl.commons.util.ServiceLoaderCache; -import com.powsybl.iidm.network.Network; - -import java.util.List; -import java.util.Objects; - -/** - * @author Viktor Terrier {@literal } - */ -public final class CracExporters { - - private static final Supplier> CRAC_EXPORTERS - = Suppliers.memoize(() -> new ServiceLoaderCache<>(CracExporter.class).getServices())::get; - - private CracExporters() { - } - - public static void exportCrac(Crac crac, String format, Path cracPath) { - try (OutputStream os = new FileOutputStream(cracPath.toFile())) { - exportCrac(crac, format, os); - } catch (FileNotFoundException e) { - throw new OpenRaoException("File not found."); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - } - - public static void exportCrac(Crac crac, String format, OutputStream outputStream) { - CracExporter exporter = findCracExporter(format, CRAC_EXPORTERS.get()); - exporter.exportCrac(crac, outputStream); - } - - public static void exportCrac(Crac crac, Network network, String format, OutputStream outputStream) { - CracExporter exporter = findCracExporter(format, CRAC_EXPORTERS.get()); - exporter.exportCrac(crac, network, outputStream); - } - - static CracExporter findCracExporter(String name, List cracExporters) { - Objects.requireNonNull(cracExporters); - - if (cracExporters.size() == 1 && name == null) { - // no information to select the implementation but only one crac exporter, so we can use it by default - // (that is be the most common use case) - return cracExporters.get(0); - } else { - if (cracExporters.size() > 1 && name == null) { - // several crac exporters and no information to select which one to choose, we can only throw - // an exception - List exportersNames = cracExporters.stream().map(CracExporter::getFormat).toList(); - throw new OpenRaoException("Several crac exporters implementations found (" + exportersNames - + "), you must specify an explicit exporter name"); - } - return cracExporters.stream() - .filter(ns -> ns.getFormat().equals(name)) - .findFirst() - .orElseThrow(() -> new OpenRaoException("Crac exporter '" + name + "' not found")); - } - } -} diff --git a/data/crac-io/crac-io-api/src/main/java/com/powsybl/openrao/data/cracioapi/CracImporter.java b/data/crac-io/crac-io-api/src/main/java/com/powsybl/openrao/data/cracioapi/CracImporter.java deleted file mode 100644 index d9a56aad5b..0000000000 --- a/data/crac-io/crac-io-api/src/main/java/com/powsybl/openrao/data/cracioapi/CracImporter.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2019, 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/. - */ - -package com.powsybl.openrao.data.cracioapi; - -import com.powsybl.iidm.network.Network; -import com.powsybl.openrao.data.cracapi.Crac; -import com.powsybl.openrao.data.cracapi.CracFactory; - -import javax.annotation.Nonnull; -import java.io.InputStream; - -/** - * Interface for CRAC object import - * - * @author Joris Mancini {@literal } - */ - -public interface CracImporter { - - Crac importCrac(InputStream inputStream, @Nonnull CracFactory cracFactory, Network network); - - Crac importCrac(InputStream inputStream, Network network); - - boolean exists(String fileName, InputStream inputStream); -} diff --git a/data/crac-io/crac-io-api/src/main/java/com/powsybl/openrao/data/cracioapi/CracImporters.java b/data/crac-io/crac-io-api/src/main/java/com/powsybl/openrao/data/cracioapi/CracImporters.java deleted file mode 100644 index 6196bd2847..0000000000 --- a/data/crac-io/crac-io-api/src/main/java/com/powsybl/openrao/data/cracioapi/CracImporters.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2019, 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/. - */ - -package com.powsybl.openrao.data.cracioapi; - -import com.powsybl.iidm.network.Network; -import com.powsybl.openrao.commons.OpenRaoException; -import com.powsybl.openrao.data.cracapi.Crac; -import com.google.common.base.Suppliers; -import com.powsybl.commons.util.ServiceLoaderCache; - -import java.io.*; -import java.nio.file.Path; -import java.util.List; -import java.util.function.Supplier; - -/** - * @author Viktor Terrier {@literal } - */ -public final class CracImporters { - - private static final Supplier> CRAC_IMPORTERS - = Suppliers.memoize(() -> new ServiceLoaderCache<>(CracImporter.class).getServices())::get; - - private CracImporters() { - } - - public static Crac importCrac(Path cracPath, Network network) { - try (InputStream is = new FileInputStream(cracPath.toFile())) { - return importCrac(cracPath.getFileName().toString(), is, network); - } catch (FileNotFoundException e) { - throw new OpenRaoException("File not found."); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - } - - private static byte[] getBytesFromInputStream(InputStream inputStream) throws IOException { - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - org.apache.commons.io.IOUtils.copy(inputStream, baos); - return baos.toByteArray(); - } - - public static Crac importCrac(String fileName, InputStream inputStream, Network network) { - try { - byte[] bytes = getBytesFromInputStream(inputStream); - - CracImporter importer = findImporter(fileName, new ByteArrayInputStream(bytes)); - if (importer == null) { - throw new OpenRaoException("No importer found for this file"); - } - return importer.importCrac(new ByteArrayInputStream(bytes), network); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - } - - public static CracImporter findImporter(String fileName, InputStream inputStream) { - try { - byte[] bytes = getBytesFromInputStream(inputStream); - - for (CracImporter importer : CRAC_IMPORTERS.get()) { - ByteArrayInputStream bais = new ByteArrayInputStream(bytes); - if (importer.exists(fileName, bais)) { - return importer; - } - } - return null; - - } catch (IOException e) { - throw new UncheckedIOException(e); - } - } -} diff --git a/data/crac-io/crac-io-api/src/test/java/com/powsybl/openrao/data/cracioapi/CracExporterMock.java b/data/crac-io/crac-io-api/src/test/java/com/powsybl/openrao/data/cracioapi/CracExporterMock.java deleted file mode 100644 index b18397bdf4..0000000000 --- a/data/crac-io/crac-io-api/src/test/java/com/powsybl/openrao/data/cracioapi/CracExporterMock.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.powsybl.openrao.data.cracioapi; - -import com.powsybl.openrao.data.cracapi.Crac; -import com.google.auto.service.AutoService; -import com.powsybl.iidm.network.Network; -import org.apache.commons.lang3.NotImplementedException; - -import java.io.OutputStream; - -/** - * @author Viktor Terrier {@literal } - */ -@AutoService(CracExporter.class) -public class CracExporterMock implements CracExporter { - - public String getFormat() { - return "Mock"; - } - - @Override - public void exportCrac(Crac crac, OutputStream outputStream) { - throw new NotImplementedException("not implemented"); - } - - @Override - public void exportCrac(Crac crac, Network network, OutputStream outputStream) { - throw new NotImplementedException("not implemented"); - } -} diff --git a/data/crac-io/crac-io-api/src/test/java/com/powsybl/openrao/data/cracioapi/CracExportersImportersTest.java b/data/crac-io/crac-io-api/src/test/java/com/powsybl/openrao/data/cracioapi/CracExportersImportersTest.java deleted file mode 100644 index 124d827706..0000000000 --- a/data/crac-io/crac-io-api/src/test/java/com/powsybl/openrao/data/cracioapi/CracExportersImportersTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2019, 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/. - */ - -package com.powsybl.openrao.data.cracioapi; - -import com.powsybl.iidm.network.Network; -import com.powsybl.openrao.data.cracapi.Crac; -import org.apache.commons.lang3.NotImplementedException; -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; - -import java.io.File; -import java.nio.file.Path; -import java.nio.file.Paths; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; - -/** - * @author Viktor Terrier {@literal } - */ -class CracExportersImportersTest { - - private String cracFile = "/empty.txt"; - - @Test - void testExport() { - Crac crac = Mockito.mock(Crac.class); - Path path = Paths.get(new File(getClass().getResource(cracFile).getFile()).getAbsolutePath()); - assertThrows(NotImplementedException.class, () -> CracExporters.exportCrac(crac, "Mock", path)); - } - - @Test - void testImport() { - Crac crac = CracImporters.importCrac(Paths.get(new File(getClass().getResource(cracFile).getFile()).getAbsolutePath()), Mockito.mock(Network.class)); - assertNotNull(crac); - } - - @Test - void testImportWithInstant() { - Crac crac = CracImporters.importCrac(Paths.get(new File(getClass().getResource(cracFile).getFile()).getAbsolutePath()), Mockito.mock(Network.class)); - assertNotNull(crac); - } -} diff --git a/data/crac-io/crac-io-api/src/test/java/com/powsybl/openrao/data/cracioapi/CracImporterMock.java b/data/crac-io/crac-io-api/src/test/java/com/powsybl/openrao/data/cracioapi/CracImporterMock.java deleted file mode 100644 index f8f529b59b..0000000000 --- a/data/crac-io/crac-io-api/src/test/java/com/powsybl/openrao/data/cracioapi/CracImporterMock.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2019, 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/. - */ - -package com.powsybl.openrao.data.cracioapi; - -import com.powsybl.iidm.network.Network; -import com.powsybl.openrao.data.cracapi.Crac; -import com.powsybl.openrao.data.cracapi.CracFactory; -import com.google.auto.service.AutoService; -import org.mockito.Mockito; - -import javax.annotation.Nonnull; -import java.io.InputStream; - -/** - * @author Viktor Terrier {@literal } - */ -@AutoService(CracImporter.class) -public class CracImporterMock implements CracImporter { - - @Override - public Crac importCrac(InputStream inputStream, @Nonnull CracFactory cracFactory, Network network) { - return Mockito.mock(Crac.class); - } - - @Override - public Crac importCrac(InputStream inputStream, Network network) { - return Mockito.mock(Crac.class); - } - - @Override - public boolean exists(String fileName, InputStream inputStream) { - return true; - } -} diff --git a/data/crac-io/crac-io-api/src/test/resources/empty.txt b/data/crac-io/crac-io-api/src/test/resources/empty.txt deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/data/crac-io/crac-io-api/src/test/resources/logback-test.xml b/data/crac-io/crac-io-api/src/test/resources/logback-test.xml deleted file mode 100644 index 841f9c96b6..0000000000 --- a/data/crac-io/crac-io-api/src/test/resources/logback-test.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - diff --git a/data/crac-io/crac-io-json/pom.xml b/data/crac-io/crac-io-json/pom.xml index 6e9804113b..1ab9b79bc4 100644 --- a/data/crac-io/crac-io-json/pom.xml +++ b/data/crac-io/crac-io-json/pom.xml @@ -20,11 +20,6 @@ open-rao-crac-api ${project.version} - - ${project.groupId} - open-rao-crac-io-api - ${project.version} - diff --git a/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/JsonExport.java b/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/JsonExport.java index d2a572db7a..7bd3c5d355 100644 --- a/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/JsonExport.java +++ b/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/JsonExport.java @@ -8,14 +8,13 @@ package com.powsybl.openrao.data.craciojson; import com.powsybl.openrao.data.cracapi.Crac; -import com.powsybl.openrao.data.cracioapi.CracExporter; +import com.powsybl.openrao.data.cracapi.io.Exporter; import com.powsybl.openrao.data.craciojson.serializers.CracJsonSerializerModule; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; import com.fasterxml.jackson.databind.module.SimpleModule; import com.google.auto.service.AutoService; -import com.powsybl.iidm.network.Network; import java.io.IOException; import java.io.OutputStream; @@ -28,10 +27,10 @@ * * @author Viktor Terrier {@literal } */ -@AutoService(CracExporter.class) -public class JsonExport implements CracExporter { +@AutoService(Exporter.class) +public class JsonExport implements Exporter { - private static final String JSON_FORMAT = "Json"; + private static final String JSON_FORMAT = "JSON"; @Override public String getFormat() { @@ -39,7 +38,7 @@ public String getFormat() { } @Override - public void exportCrac(Crac crac, OutputStream outputStream) { + public void exportData(Crac crac, OutputStream outputStream) { try { ObjectMapper objectMapper = createObjectMapper(); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); @@ -51,9 +50,4 @@ public void exportCrac(Crac crac, OutputStream outputStream) { throw new UncheckedIOException(e); } } - - @Override - public void exportCrac(Crac crac, Network network, OutputStream outputStream) { - exportCrac(crac, outputStream); - } } diff --git a/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/JsonImport.java b/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/JsonImport.java index 0de5b0e8fe..7943b0ca50 100644 --- a/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/JsonImport.java +++ b/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/JsonImport.java @@ -11,14 +11,12 @@ import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.CracFactory; -import com.powsybl.openrao.data.cracioapi.CracImporter; +import com.powsybl.openrao.data.cracapi.io.Importer; import com.powsybl.openrao.data.craciojson.deserializers.CracDeserializer; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.module.SimpleModule; import com.google.auto.service.AutoService; -import org.apache.commons.io.FilenameUtils; -import javax.annotation.Nonnull; import java.io.IOException; import java.io.InputStream; import java.io.UncheckedIOException; @@ -29,41 +27,41 @@ * @author Viktor Terrier {@literal } * @author Peter Mitri {@literal } */ -@AutoService(CracImporter.class) -public class JsonImport implements CracImporter { - private static final String JSON_EXTENSION = "json"; +@AutoService(Importer.class) +public class JsonImport implements Importer { + @Override + public String getFormat() { + return "JSON"; + } - private Crac importCrac(InputStream inputStream, CracDeserializer cracDeserializer) { + @Override + public boolean exists(InputStream inputStream) { try { ObjectMapper objectMapper = createObjectMapper(); SimpleModule module = new SimpleModule(); - module.addDeserializer(Crac.class, cracDeserializer); + module.addDeserializer(Crac.class, new CracDeserializer(true)); objectMapper.registerModule(module); - return objectMapper.readValue(inputStream, Crac.class); - } catch (IOException e) { - throw new UncheckedIOException(e); + // TODO: replace this by a call to CracDeserializer.isValid + objectMapper.readValue(inputStream, Crac.class); + return true; + } catch (OpenRaoException | IOException e) { + return false; } } @Override - public Crac importCrac(InputStream inputStream, @Nonnull CracFactory cracFactory, Network network) { + public Crac importData(InputStream inputStream, CracFactory cracFactory, Network network) { if (network == null) { throw new OpenRaoException("Network object is null but it is needed to map contingency's elements"); } - return importCrac(inputStream, new CracDeserializer(cracFactory, network)); - } - - @Override - public Crac importCrac(InputStream inputStream, Network network) { - return importCrac(inputStream, CracFactory.findDefault(), network); - } - - @Override - public boolean exists(String fileName, InputStream inputStream) { - return validCracFile(fileName); - } - - private boolean validCracFile(String fileName) { - return FilenameUtils.getExtension(fileName).equals(JSON_EXTENSION); + try { + ObjectMapper objectMapper = createObjectMapper(); + SimpleModule module = new SimpleModule(); + module.addDeserializer(Crac.class, new CracDeserializer(cracFactory, network)); + objectMapper.registerModule(module); + return objectMapper.readValue(inputStream, Crac.class); + } catch (IOException e) { + throw new UncheckedIOException(e); + } } } diff --git a/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/deserializers/CracDeserializer.java b/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/deserializers/CracDeserializer.java index a0ac537cb1..63e2e88509 100644 --- a/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/deserializers/CracDeserializer.java +++ b/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/deserializers/CracDeserializer.java @@ -41,30 +41,26 @@ public class CracDeserializer extends JsonDeserializer { private Network network; - private CracDeserializer() { + private final boolean headerCheckOnly; + + public CracDeserializer(boolean headerCheckOnly) { + this.headerCheckOnly = headerCheckOnly; } public CracDeserializer(CracFactory cracFactory, Network network) { this.cracFactory = cracFactory; this.network = network; + this.headerCheckOnly = false; } @Override public Crac deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { // check header - if (!jsonParser.nextFieldName().equals(TYPE)) { - throw new OpenRaoException(String.format("json CRAC must start with field %s", TYPE)); + String version = isValid(jsonParser); + if (headerCheckOnly) { + return null; } - if (!jsonParser.nextTextValue().equals(CRAC_TYPE)) { - throw new OpenRaoException(String.format("type of document must be %s", CRAC_TYPE)); - } - if (!jsonParser.nextFieldName().equals(VERSION)) { - throw new OpenRaoException(String.format("%s must contain a %s in its second field", CRAC_TYPE, VERSION)); - } - String version = jsonParser.nextTextValue(); - checkVersion(version); - jsonParser.nextToken(); // get id and name scrollJsonUntilField(jsonParser, ID); @@ -159,6 +155,22 @@ public Crac deserialize(JsonParser jsonParser, DeserializationContext deserializ return crac; } + public static String isValid(JsonParser jsonParser) throws IOException { + if (!jsonParser.nextFieldName().equals(TYPE)) { + throw new OpenRaoException(String.format("json CRAC must start with field %s", TYPE)); + } + if (!jsonParser.nextTextValue().equals(CRAC_TYPE)) { + throw new OpenRaoException(String.format("type of document must be %s", CRAC_TYPE)); + } + if (!jsonParser.nextFieldName().equals(VERSION)) { + throw new OpenRaoException(String.format("%s must contain a %s in its second field", CRAC_TYPE, VERSION)); + } + String version = jsonParser.nextTextValue(); + checkVersion(version); + jsonParser.nextToken(); + return version; + } + private void scrollJsonUntilField(JsonParser jsonParser, String field) throws IOException { while (!jsonParser.getCurrentName().equals(field)) { if (jsonParser.nextToken() == JsonToken.END_OBJECT) { @@ -168,7 +180,7 @@ private void scrollJsonUntilField(JsonParser jsonParser, String field) throws IO } } - private void checkVersion(String cracVersion) { + private static void checkVersion(String cracVersion) { if (getPrimaryVersionNumber(CRAC_IO_VERSION) > getPrimaryVersionNumber(cracVersion)) { LOGGER.warn("CRAC importer {} might not be longer compatible with json CRAC version {}, consider updating your json CRAC file", CRAC_IO_VERSION, cracVersion); diff --git a/data/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/craciojson/CracImportExportTest.java b/data/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/craciojson/CracImportExportTest.java index 166ab338f4..6294465f46 100644 --- a/data/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/craciojson/CracImportExportTest.java +++ b/data/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/craciojson/CracImportExportTest.java @@ -44,23 +44,40 @@ class CracImportExportTest { @Test - void roundTripTest() { + void testExists() { + assertTrue(new JsonImport().exists(getClass().getResourceAsStream("/cracHeader.json"))); + assertFalse(new JsonImport().exists(getClass().getResourceAsStream("/invalidCrac.json"))); + assertFalse(new JsonImport().exists(getClass().getResourceAsStream("/invalidCrac.txt"))); + } + + @Test + void explicitJsonRoundTripTest() { + Crac crac = ExhaustiveCracCreation.create(); + Crac importedCrac = RoundTripUtil.explicitJsonRoundTrip(crac, ExhaustiveCracCreation.createAssociatedNetwork()); + checkContent(importedCrac); + } + + @Test + void implicitJsonRoundTripTest() { Crac crac = ExhaustiveCracCreation.create(); + Crac importedCrac = RoundTripUtil.implicitJsonRoundTrip(crac, ExhaustiveCracCreation.createAssociatedNetwork()); + checkContent(importedCrac); + } + + private void checkContent(Crac crac) { Instant preventiveInstant = crac.getInstant("preventive"); Instant autoInstant = crac.getInstant("auto"); Instant curativeInstant = crac.getInstant("curative"); - Crac importedCrac = RoundTripUtil.roundTrip(crac, ExhaustiveCracCreation.createAssociatedNetwork()); - // check overall content - assertNotNull(importedCrac); - assertEquals(5, importedCrac.getStates().size()); - assertEquals(2, importedCrac.getContingencies().size()); - assertEquals(7, importedCrac.getFlowCnecs().size()); - assertEquals(1, importedCrac.getAngleCnecs().size()); - assertEquals(1, importedCrac.getVoltageCnecs().size()); - assertEquals(9, importedCrac.getRangeActions().size()); - assertEquals(4, importedCrac.getNetworkActions().size()); + assertNotNull(crac); + assertEquals(5, crac.getStates().size()); + assertEquals(2, crac.getContingencies().size()); + assertEquals(7, crac.getFlowCnecs().size()); + assertEquals(1, crac.getAngleCnecs().size()); + assertEquals(1, crac.getVoltageCnecs().size()); + assertEquals(9, crac.getRangeActions().size()); + assertEquals(4, crac.getNetworkActions().size()); // -------------------------- // --- test Ra Usage Limits --- @@ -207,9 +224,9 @@ void roundTripTest() { // check onContingencyState usage Rule (curative) OnContingencyState onContingencyState = crac.getNetworkAction("pstSetpointRaId").getUsageRules().stream() - .filter(ur -> ur instanceof OnContingencyState) - .map(ur -> (OnContingencyState) ur) - .findAny().orElse(null); + .filter(ur -> ur instanceof OnContingencyState) + .map(ur -> (OnContingencyState) ur) + .findAny().orElse(null); assertNotNull(onContingencyState); assertEquals("contingency1Id", onContingencyState.getContingency().getId()); assertEquals(curativeInstant, onContingencyState.getInstant()); @@ -273,11 +290,11 @@ void roundTripTest() { assertEquals(2, crac.getPstRangeAction("pstRange1Id").getRanges().size()); TapRange absRange = crac.getPstRangeAction("pstRange1Id").getRanges().stream() - .filter(tapRange -> tapRange.getRangeType().equals(RangeType.ABSOLUTE)) - .findAny().orElse(null); + .filter(tapRange -> tapRange.getRangeType().equals(RangeType.ABSOLUTE)) + .findAny().orElse(null); TapRange relRange = crac.getPstRangeAction("pstRange1Id").getRanges().stream() - .filter(tapRange -> tapRange.getRangeType().equals(RangeType.RELATIVE_TO_INITIAL_NETWORK)) - .findAny().orElse(null); + .filter(tapRange -> tapRange.getRangeType().equals(RangeType.RELATIVE_TO_INITIAL_NETWORK)) + .findAny().orElse(null); assertNotNull(absRange); assertEquals(1, absRange.getMinTap()); @@ -302,14 +319,14 @@ void roundTripTest() { assertEquals(3, crac.getPstRangeAction("pstRange2Id").getRanges().size()); absRange = crac.getPstRangeAction("pstRange2Id").getRanges().stream() - .filter(tapRange -> tapRange.getRangeType().equals(RangeType.ABSOLUTE)) - .findAny().orElse(null); + .filter(tapRange -> tapRange.getRangeType().equals(RangeType.ABSOLUTE)) + .findAny().orElse(null); relRange = crac.getPstRangeAction("pstRange2Id").getRanges().stream() - .filter(tapRange -> tapRange.getRangeType().equals(RangeType.RELATIVE_TO_INITIAL_NETWORK)) - .findAny().orElse(null); + .filter(tapRange -> tapRange.getRangeType().equals(RangeType.RELATIVE_TO_INITIAL_NETWORK)) + .findAny().orElse(null); TapRange relTimestampRange = crac.getPstRangeAction("pstRange2Id").getRanges().stream() - .filter(tapRange -> tapRange.getRangeType().equals(RangeType.RELATIVE_TO_PREVIOUS_TIME_STEP)) - .findAny().orElse(null); + .filter(tapRange -> tapRange.getRangeType().equals(RangeType.RELATIVE_TO_PREVIOUS_TIME_STEP)) + .findAny().orElse(null); assertNotNull(absRange); assertEquals(-4, absRange.getMinTap()); @@ -442,6 +459,5 @@ void roundTripTest() { assertEquals(curativeInstant, ur.getInstant()); assertEquals(Country.ES, ur.getCountry()); assertEquals(AVAILABLE, ur.getUsageMethod()); - } } diff --git a/data/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/craciojson/JsonRetrocompatibilityTest.java b/data/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/craciojson/JsonRetrocompatibilityTest.java index cd1c602ca7..7c77278506 100644 --- a/data/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/craciojson/JsonRetrocompatibilityTest.java +++ b/data/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/craciojson/JsonRetrocompatibilityTest.java @@ -7,6 +7,7 @@ package com.powsybl.openrao.data.craciojson; import com.powsybl.iidm.network.Network; +import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.*; import com.powsybl.openrao.data.cracapi.cnec.AngleCnec; @@ -66,13 +67,24 @@ public void setUp() { network = NetworkImportsUtil.createNetworkWithLines("ne1Id", "ne2Id", "ne3Id"); } + @Test + void testFormat() { + assertEquals("JSON", new JsonImport().getFormat()); + } + + @Test + void testNoNetworkProvided() { + OpenRaoException exception = assertThrows(OpenRaoException.class, () -> new JsonImport().importData(getClass().getResourceAsStream("/retrocompatibility/v2/crac-v2.4.json"), CracFactory.findDefault(), null)); + assertEquals("Network object is null but it is needed to map contingency's elements", exception.getMessage()); + } + @Test void importV1Point0Test() { // JSON file of open-rao v3.4.3 InputStream cracFile = getClass().getResourceAsStream("/retrocompatibility/v1/crac-v1.0.json"); - Crac crac = new JsonImport().importCrac(cracFile, network); + Crac crac = new JsonImport().importData(cracFile, CracFactory.findDefault(), network); assertEquals(2, crac.getContingencies().size()); assertEquals(7, crac.getFlowCnecs().size()); @@ -89,7 +101,7 @@ void importV1Point1Test() { // addition of switch pairs InputStream cracFile = getClass().getResourceAsStream("/retrocompatibility/v1/crac-v1.1.json"); - Crac crac = new JsonImport().importCrac(cracFile, network); + Crac crac = new JsonImport().importData(cracFile, CracFactory.findDefault(), network); assertEquals(2, crac.getContingencies().size()); assertEquals(7, crac.getFlowCnecs().size()); @@ -106,7 +118,7 @@ void importV1Point2Test() { // addition of injection range action InputStream cracFile = getClass().getResourceAsStream("/retrocompatibility/v1/crac-v1.2.json"); - Crac crac = new JsonImport().importCrac(cracFile, network); + Crac crac = new JsonImport().importData(cracFile, CracFactory.findDefault(), network); assertEquals(2, crac.getContingencies().size()); assertEquals(7, crac.getFlowCnecs().size()); @@ -124,7 +136,7 @@ void importV1Point3Test() { // addition of initial setpoints for InjectionRangeActions and HvdcRangeActions InputStream cracFile = getClass().getResourceAsStream("/retrocompatibility/v1/crac-v1.3.json"); - Crac crac = new JsonImport().importCrac(cracFile, network); + Crac crac = new JsonImport().importData(cracFile, CracFactory.findDefault(), network); assertEquals(2, crac.getContingencies().size()); assertEquals(7, crac.getFlowCnecs().size()); @@ -142,7 +154,7 @@ void importV1Point4Test() { // addition of angle cnecs InputStream cracFile = getClass().getResourceAsStream("/retrocompatibility/v1/crac-v1.4.json"); - Crac crac = new JsonImport().importCrac(cracFile, network); + Crac crac = new JsonImport().importData(cracFile, CracFactory.findDefault(), network); assertEquals(2, crac.getContingencies().size()); assertEquals(7, crac.getFlowCnecs().size()); @@ -161,7 +173,7 @@ void importV1Point5Test() { // addition of voltage cnecs InputStream cracFile = getClass().getResourceAsStream("/retrocompatibility/v1/crac-v1.5.json"); - Crac crac = new JsonImport().importCrac(cracFile, network); + Crac crac = new JsonImport().importData(cracFile, CracFactory.findDefault(), network); assertEquals(2, crac.getContingencies().size()); assertEquals(7, crac.getFlowCnecs().size()); @@ -182,7 +194,7 @@ void importV1Point6Test() { InputStream cracFile = getClass().getResourceAsStream("/retrocompatibility/v1/crac-v1.6.json"); - Crac crac = new JsonImport().importCrac(cracFile, network); + Crac crac = new JsonImport().importData(cracFile, CracFactory.findDefault(), network); assertEquals(2, crac.getContingencies().size()); assertEquals(7, crac.getFlowCnecs().size()); @@ -203,7 +215,7 @@ void importV1Point7Test() { InputStream cracFile = getClass().getResourceAsStream("/retrocompatibility/v1/crac-v1.7.json"); - Crac crac = new JsonImport().importCrac(cracFile, network); + Crac crac = new JsonImport().importData(cracFile, CracFactory.findDefault(), network); assertEquals(2, crac.getContingencies().size()); assertEquals(7, crac.getFlowCnecs().size()); @@ -224,7 +236,7 @@ void importV1Point8Test() { InputStream cracFile = getClass().getResourceAsStream("/retrocompatibility/v1/crac-v1.8.json"); - Crac crac = new JsonImport().importCrac(cracFile, network); + Crac crac = new JsonImport().importData(cracFile, CracFactory.findDefault(), network); assertEquals(2, crac.getContingencies().size()); assertEquals(7, crac.getFlowCnecs().size()); @@ -242,7 +254,7 @@ void importV1Point9Test() { // Add support for CounterTrade remedial actions InputStream cracFile = getClass().getResourceAsStream("/retrocompatibility/v1/crac-v1.9.json"); - Crac crac = new JsonImport().importCrac(cracFile, network); + Crac crac = new JsonImport().importData(cracFile, CracFactory.findDefault(), network); assertEquals(2, crac.getContingencies().size()); assertEquals(7, crac.getFlowCnecs().size()); @@ -261,7 +273,7 @@ void importV2Point0Test() { // Add support for user-defined Instants InputStream cracFile = getClass().getResourceAsStream("/retrocompatibility/v2/crac-v2.0.json"); - Crac crac = new JsonImport().importCrac(cracFile, network); + Crac crac = new JsonImport().importData(cracFile, CracFactory.findDefault(), network); assertEquals(4, crac.getNetworkActions().size()); testContentOfV2Point0Crac(crac); } @@ -271,7 +283,7 @@ void importV2Point2Test() { // Add support for CNECs' borders and relative-to-previous-time-step ranges for PSTs InputStream cracFile = getClass().getResourceAsStream("/retrocompatibility/v2/crac-v2.2.json"); - Crac crac = new JsonImport().importCrac(cracFile, network); + Crac crac = new JsonImport().importData(cracFile, CracFactory.findDefault(), network); assertEquals(6, crac.getNetworkActions().size()); testContentOfV2Point2Crac(crac); } @@ -281,7 +293,7 @@ void importV2Point3Test() { // Add support for unified onConstraint usage rules InputStream cracFile = getClass().getResourceAsStream("/retrocompatibility/v2/crac-v2.3.json"); - Crac crac = new JsonImport().importCrac(cracFile, network); + Crac crac = new JsonImport().importData(cracFile, CracFactory.findDefault(), network); assertEquals(6, crac.getNetworkActions().size()); testContentOfV2Point3Crac(crac); } @@ -291,7 +303,7 @@ void importV2Point4Test() { // Add support for contingency in OnFlowConstraintInCountry InputStream cracFile = getClass().getResourceAsStream("/retrocompatibility/v2/crac-v2.4.json"); - Crac crac = new JsonImport().importCrac(cracFile, network); + Crac crac = new JsonImport().importData(cracFile, CracFactory.findDefault(), network); assertEquals(6, crac.getNetworkActions().size()); testContentOfV2Point4Crac(crac); } diff --git a/data/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/craciojson/RoundTripUtil.java b/data/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/craciojson/RoundTripUtil.java index 97972be49c..66ccb2b29e 100644 --- a/data/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/craciojson/RoundTripUtil.java +++ b/data/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/craciojson/RoundTripUtil.java @@ -8,6 +8,7 @@ import com.powsybl.iidm.network.Network; import com.powsybl.openrao.data.cracapi.Crac; +import com.powsybl.openrao.data.cracapi.CracFactory; import com.powsybl.openrao.data.craciojson.serializers.CracJsonSerializerModule; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.ObjectMapper; @@ -37,7 +38,18 @@ private RoundTripUtil() { * @param object: object to export/import * @return the object exported and re-imported */ - static Crac roundTrip(Crac object, Network network) { + static Crac implicitJsonRoundTrip(Crac object, Network network) { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + object.write("JSON", outputStream); + + try (ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray())) { + return Crac.read(inputStream, network); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + static Crac explicitJsonRoundTrip(Crac object, Network network) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { ObjectMapper objectMapper = createObjectMapper(); @@ -51,7 +63,7 @@ static Crac roundTrip(Crac object, Network network) { } try (ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray())) { - return (new JsonImport()).importCrac(inputStream, network); + return new JsonImport().importData(inputStream, CracFactory.findDefault(), network); } catch (IOException e) { throw new UncheckedIOException(e); } diff --git a/data/crac-io/crac-io-json/src/test/resources/cracHeader.json b/data/crac-io/crac-io-json/src/test/resources/cracHeader.json new file mode 100644 index 0000000000..dc9baa00b3 --- /dev/null +++ b/data/crac-io/crac-io-json/src/test/resources/cracHeader.json @@ -0,0 +1,4 @@ +{ + "type": "CRAC", + "version": "2.5" +} \ No newline at end of file diff --git a/data/crac-io/crac-io-json/src/test/resources/invalidCrac.json b/data/crac-io/crac-io-json/src/test/resources/invalidCrac.json new file mode 100644 index 0000000000..f7c4ec3339 --- /dev/null +++ b/data/crac-io/crac-io-json/src/test/resources/invalidCrac.json @@ -0,0 +1,3 @@ +{ + "field": "Hello world!" +} \ No newline at end of file diff --git a/data/crac-io/crac-io-json/src/test/resources/invalidCrac.txt b/data/crac-io/crac-io-json/src/test/resources/invalidCrac.txt new file mode 100644 index 0000000000..4d36853aa8 --- /dev/null +++ b/data/crac-io/crac-io-json/src/test/resources/invalidCrac.txt @@ -0,0 +1 @@ +CRAC \ No newline at end of file diff --git a/data/crac-io/pom.xml b/data/crac-io/pom.xml index 177745b0d7..276737bac4 100644 --- a/data/crac-io/pom.xml +++ b/data/crac-io/pom.xml @@ -17,7 +17,6 @@ Module that gathers all the CRAC importers and exporters modules - crac-io-api crac-io-json diff --git a/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/Crac.java b/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/Crac.java index ada85debb2..0c3fc267e1 100644 --- a/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/Crac.java +++ b/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/Crac.java @@ -6,14 +6,23 @@ */ package com.powsybl.openrao.data.cracapi; +import com.powsybl.commons.util.ServiceLoaderCache; import com.powsybl.contingency.Contingency; +import com.powsybl.iidm.network.Network; import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.data.cracapi.cnec.*; +import com.powsybl.openrao.data.cracapi.io.Exporter; +import com.powsybl.openrao.data.cracapi.io.Importer; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.networkaction.NetworkActionAdder; import com.powsybl.openrao.data.cracapi.rangeaction.*; import com.powsybl.openrao.data.cracapi.usagerule.UsageMethod; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.util.*; import static java.lang.String.format; @@ -21,7 +30,7 @@ /** * Interface to manage CRAC. * CRAC stands for Contingency list, Remedial Actions and additional Constraints - * + *

* It involves: *

    *
  • {@link Instant} objects
  • @@ -162,7 +171,7 @@ public interface Crac extends Identifiable { * Can return null if no matching state or contingency are found. * * @param contingency: The contingency after which we want to select the state. - * @param instant: The instant at which we want to select the state. + * @param instant: The instant at which we want to select the state. * @return State after a contingency and at a specific instant. */ State getState(Contingency contingency, Instant instant); @@ -200,7 +209,7 @@ default SortedSet getStatesFromContingency(String id) { * Select a unique state after a contingency and at a specific instant, specified by their ids. * * @param contingencyId: The contingency id after which we want to select the state. - * @param instant: The instant at which we want to select the state. + * @param instant: The instant at which we want to select the state. * @return State after a contingency and at a specific instant. Can return null if no matching * state or contingency are found. */ @@ -254,7 +263,7 @@ default State getState(String contingencyId, Instant instant) { * @deprecated consider using getCnecs() or getFlowCnecs() instead */ // keep the method (might be useful when we will have other BranchCnec than FlowCnec) - @Deprecated (since = "3.0.0") + @Deprecated(since = "3.0.0") Set getBranchCnecs(); /** @@ -264,7 +273,7 @@ default State getState(String contingencyId, Instant instant) { * @deprecated consider using getCnecs() or getFlowCnecs() instead */ // keep the method (might be useful when we will have other BranchCnec than FlowCnec) - @Deprecated (since = "3.0.0") + @Deprecated(since = "3.0.0") Set getBranchCnecs(State state); /** @@ -273,7 +282,7 @@ default State getState(String contingencyId, Instant instant) { * @deprecated consider using getCnec() or getFlowCnec() instead */ // keep the method (might be usefuls when we will have other BranchCnec than FlowCnec) - @Deprecated (since = "3.0.0") + @Deprecated(since = "3.0.0") BranchCnec getBranchCnec(String branchCnecId); /** @@ -531,4 +540,76 @@ default State getState(String contingencyId, Instant instant) { * Get a {@link RaUsageLimitsAdder}, to add a {@link RaUsageLimits} to the crac */ RaUsageLimitsAdder newRaUsageLimits(String instantName); + + /** + * Import CRAC from a file + * + * @param importers candidates CRAC importers to process the data + * @param inputStream CRAC data + * @param cracFactory CRAC factory + * @param network the network on which the CRAC data is based + * @return CRAC object + */ + private static Crac read(List importers, InputStream inputStream, CracFactory cracFactory, Network network) throws IOException { + byte[] bytes = getBytesFromInputStream(inputStream); + return importers.stream() + .filter(importer -> importer.exists(new ByteArrayInputStream(bytes))) + .findAny() + .orElseThrow(() -> new OpenRaoException("No suitable CRAC importer found.")) + .importData(new ByteArrayInputStream(bytes), cracFactory, network); + } + + /** + * Import CRAC from a file + * + * @param inputStream CRAC data + * @param cracFactory CRAC factory + * @param network the network on which the CRAC data is based + * @return CRAC object + */ + static Crac read(InputStream inputStream, CracFactory cracFactory, Network network) throws IOException { + return read(new ServiceLoaderCache<>(Importer.class).getServices(), inputStream, cracFactory, network); + } + + /** + * Import CRAC from a file + * + * @param inputStream CRAC data + * @param network the network on which the CRAC data is based + * @return CRAC object + */ + static Crac read(InputStream inputStream, Network network) throws IOException { + return read(inputStream, CracFactory.findDefault(), network); + } + + private static byte[] getBytesFromInputStream(InputStream inputStream) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + org.apache.commons.io.IOUtils.copy(inputStream, baos); + return baos.toByteArray(); + } + + /** + * Write CRAC data into a file + * + * @param exporters candidate CRAC exporters + * @param format desired output CRAC data type + * @param outputStream file where to write the CRAC data + */ + private void write(List exporters, String format, OutputStream outputStream) { + exporters.stream() + .filter(ex -> format.equals(ex.getFormat())) + .findAny() + .orElseThrow(() -> new OpenRaoException("Export format " + format + " not supported")) + .exportData(this, outputStream); + } + + /** + * Write CRAC data into a file + * + * @param format desired output CRAC data type + * @param outputStream file where to write the CRAC data + */ + default void write(String format, OutputStream outputStream) { + write(new ServiceLoaderCache<>(Exporter.class).getServices(), format, outputStream); + } } diff --git a/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/io/Exporter.java b/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/io/Exporter.java new file mode 100644 index 0000000000..acfef8d457 --- /dev/null +++ b/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/io/Exporter.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024, 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/. + */ + +package com.powsybl.openrao.data.cracapi.io; + +import com.powsybl.openrao.data.cracapi.Crac; + +import java.io.OutputStream; + +/** + * @author Thomas Bouquet {@literal } + */ +public interface Exporter { + + String getFormat(); + + void exportData(Crac crac, OutputStream outputStream); +} diff --git a/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/io/Importer.java b/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/io/Importer.java new file mode 100644 index 0000000000..e8b091575f --- /dev/null +++ b/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/io/Importer.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024, 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/. + */ + +package com.powsybl.openrao.data.cracapi.io; + +import com.powsybl.iidm.network.Network; +import com.powsybl.openrao.data.cracapi.Crac; +import com.powsybl.openrao.data.cracapi.CracFactory; + +import java.io.InputStream; + +/** + * @author Thomas Bouquet {@literal } + */ +public interface Importer { + + /** + * Get a unique identifier of the format. + */ + String getFormat(); + + boolean exists(InputStream inputStream); + + /** + * Create a model. + * + * @param inputStream data input stream + * @param cracFactory CRAC factory + * @param network network upon which the CRAC is based + * @return the model + */ + Crac importData(InputStream inputStream, CracFactory cracFactory, Network network); +} diff --git a/data/crac/crac-api/src/test/java/com/powsybl/openrao/data/cracapi/CracExportTest.java b/data/crac/crac-api/src/test/java/com/powsybl/openrao/data/cracapi/CracExportTest.java new file mode 100644 index 0000000000..628b2604e4 --- /dev/null +++ b/data/crac/crac-api/src/test/java/com/powsybl/openrao/data/cracapi/CracExportTest.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024, 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/. + */ + +package com.powsybl.openrao.data.cracapi; + +import com.powsybl.openrao.commons.OpenRaoException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * @author Thomas Bouquet {@literal } + */ +class CracExportTest { + + private MockCrac crac; + + @BeforeEach + void setUp() { + crac = new MockCrac("crac"); + } + + @Test + void testExportWithUnknownExporter() { + OpenRaoException exception = assertThrows(OpenRaoException.class, () -> crac.write("unknownFormat", null)); + assertEquals("Export format unknownFormat not supported", exception.getMessage()); + assertFalse(crac.wasExportSuccessful()); + } + + @Test + void testExportCracWithValidExporter() { + crac.write("Mock", null); + assertTrue(crac.wasExportSuccessful()); + } +} diff --git a/data/crac/crac-api/src/test/java/com/powsybl/openrao/data/cracapi/CracImportTest.java b/data/crac/crac-api/src/test/java/com/powsybl/openrao/data/cracapi/CracImportTest.java new file mode 100644 index 0000000000..fece514ddf --- /dev/null +++ b/data/crac/crac-api/src/test/java/com/powsybl/openrao/data/cracapi/CracImportTest.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024, 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/. + */ + +package com.powsybl.openrao.data.cracapi; + +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * @author Thomas Bouquet {@literal } + */ +class CracImportTest { + + @Test + void testImportFromInputStream() throws IOException { + assertEquals("crac", Crac.read(getClass().getResourceAsStream("/crac.txt"), null).getId()); + } +} diff --git a/data/crac/crac-api/src/test/java/com/powsybl/openrao/data/cracapi/MockCrac.java b/data/crac/crac-api/src/test/java/com/powsybl/openrao/data/cracapi/MockCrac.java new file mode 100644 index 0000000000..3703db2557 --- /dev/null +++ b/data/crac/crac-api/src/test/java/com/powsybl/openrao/data/cracapi/MockCrac.java @@ -0,0 +1,473 @@ +/* + * Copyright (c) 2024, 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/. + */ + +package com.powsybl.openrao.data.cracapi; + +import com.powsybl.commons.extensions.Extension; +import com.powsybl.contingency.Contingency; +import com.powsybl.openrao.data.cracapi.cnec.AngleCnec; +import com.powsybl.openrao.data.cracapi.cnec.AngleCnecAdder; +import com.powsybl.openrao.data.cracapi.cnec.BranchCnec; +import com.powsybl.openrao.data.cracapi.cnec.Cnec; +import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; +import com.powsybl.openrao.data.cracapi.cnec.FlowCnecAdder; +import com.powsybl.openrao.data.cracapi.cnec.VoltageCnec; +import com.powsybl.openrao.data.cracapi.cnec.VoltageCnecAdder; +import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; +import com.powsybl.openrao.data.cracapi.networkaction.NetworkActionAdder; +import com.powsybl.openrao.data.cracapi.rangeaction.CounterTradeRangeAction; +import com.powsybl.openrao.data.cracapi.rangeaction.CounterTradeRangeActionAdder; +import com.powsybl.openrao.data.cracapi.rangeaction.HvdcRangeAction; +import com.powsybl.openrao.data.cracapi.rangeaction.HvdcRangeActionAdder; +import com.powsybl.openrao.data.cracapi.rangeaction.InjectionRangeAction; +import com.powsybl.openrao.data.cracapi.rangeaction.InjectionRangeActionAdder; +import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; +import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeActionAdder; +import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; +import com.powsybl.openrao.data.cracapi.usagerule.UsageMethod; + +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; + +/** + * @author Thomas Bouquet {@literal } + */ +public final class MockCrac implements Crac { + private final String id; + private boolean wasExportSuccessful; + + public MockCrac(String id) { + this.id = id; + this.wasExportSuccessful = false; + } + + public void setExportSuccessful() { + wasExportSuccessful = true; + } + + public boolean wasExportSuccessful() { + return wasExportSuccessful; + } + + @Override + public ContingencyAdder newContingency() { + return null; + } + + @Override + public Set getContingencies() { + return null; + } + + @Override + public Contingency getContingency(String id) { + return null; + } + + @Override + public void removeContingency(String id) { + + } + + @Override + public Crac newInstant(String instantId, InstantKind instantKind) { + return null; + } + + @Override + public Instant getInstant(String instantId) { + return null; + } + + @Override + public List getSortedInstants() { + return null; + } + + @Override + public Instant getInstant(InstantKind instantKind) { + return null; + } + + @Override + public SortedSet getInstants(InstantKind instantKind) { + return null; + } + + @Override + public Instant getInstantBefore(Instant providedInstant) { + return null; + } + + @Override + public Instant getPreventiveInstant() { + return null; + } + + @Override + public Instant getOutageInstant() { + return null; + } + + @Override + public Instant getLastInstant() { + return null; + } + + @Override + public boolean hasAutoInstant() { + return false; + } + + @Override + public Set getStates() { + return null; + } + + @Override + public State getPreventiveState() { + return null; + } + + @Override + public Set getCurativeStates() { + return null; + } + + @Override + public SortedSet getStates(Contingency contingency) { + return null; + } + + @Override + public Set getStates(Instant instant) { + return null; + } + + @Override + public State getState(Contingency contingency, Instant instant) { + return null; + } + + @Override + public FlowCnecAdder newFlowCnec() { + return null; + } + + @Override + public AngleCnecAdder newAngleCnec() { + return null; + } + + @Override + public VoltageCnecAdder newVoltageCnec() { + return null; + } + + @Override + public Set getCnecs() { + return null; + } + + @Override + public Set getCnecs(State state) { + return null; + } + + @Override + public Cnec getCnec(String cnecId) { + return null; + } + + @Override + public Set getBranchCnecs() { + return null; + } + + @Override + public Set getBranchCnecs(State state) { + return null; + } + + @Override + public BranchCnec getBranchCnec(String branchCnecId) { + return null; + } + + @Override + public Set getFlowCnecs() { + return null; + } + + @Override + public Set getFlowCnecs(State state) { + return null; + } + + @Override + public FlowCnec getFlowCnec(String flowCnecId) { + return null; + } + + @Override + public Set getAngleCnecs() { + return null; + } + + @Override + public Set getAngleCnecs(State state) { + return null; + } + + @Override + public AngleCnec getAngleCnec(String angleCnecId) { + return null; + } + + @Override + public Set getVoltageCnecs() { + return null; + } + + @Override + public Set getVoltageCnecs(State state) { + return null; + } + + @Override + public VoltageCnec getVoltageCnec(String voltageCnecId) { + return null; + } + + @Override + public void removeCnec(String cnecId) { + + } + + @Override + public void removeFlowCnec(String flowCnecId) { + + } + + @Override + public void removeFlowCnecs(Set flowCnecsIds) { + + } + + @Override + public void removeAngleCnec(String angleCnecId) { + + } + + @Override + public void removeAngleCnecs(Set angleCnecsIds) { + + } + + @Override + public void removeVoltageCnec(String voltageCnecId) { + + } + + @Override + public void removeVoltageCnecs(Set voltageCnecsIds) { + + } + + @Override + public Set> getRemedialActions() { + return null; + } + + @Override + public RemedialAction getRemedialAction(String remedialActionId) { + return null; + } + + @Override + public void removeRemedialAction(String id) { + + } + + @Override + public PstRangeActionAdder newPstRangeAction() { + return null; + } + + @Override + public HvdcRangeActionAdder newHvdcRangeAction() { + return null; + } + + @Override + public InjectionRangeActionAdder newInjectionRangeAction() { + return null; + } + + @Override + public CounterTradeRangeActionAdder newCounterTradeRangeAction() { + return null; + } + + @Override + public Set> getRangeActions() { + return null; + } + + @Override + public Set> getRangeActions(State state, UsageMethod... usageMethod) { + return null; + } + + @Override + public Set> getPotentiallyAvailableRangeActions(State state) { + return null; + } + + @Override + public RangeAction getRangeAction(String id) { + return null; + } + + @Override + public Set getPstRangeActions() { + return null; + } + + @Override + public Set getHvdcRangeActions() { + return null; + } + + @Override + public Set getInjectionRangeActions() { + return null; + } + + @Override + public Set getCounterTradeRangeActions() { + return null; + } + + @Override + public PstRangeAction getPstRangeAction(String pstRangeActionId) { + return null; + } + + @Override + public HvdcRangeAction getHvdcRangeAction(String hvdcRangeActionId) { + return null; + } + + @Override + public InjectionRangeAction getInjectionRangeAction(String injectionRangeActionId) { + return null; + } + + @Override + public CounterTradeRangeAction getCounterTradeRangeAction(String counterTradeRangeActionId) { + return null; + } + + @Override + public void removePstRangeAction(String id) { + + } + + @Override + public void removeHvdcRangeAction(String id) { + + } + + @Override + public void removeInjectionRangeAction(String id) { + + } + + @Override + public NetworkActionAdder newNetworkAction() { + return null; + } + + @Override + public Set getNetworkActions() { + return null; + } + + @Override + public Set getNetworkActions(State state, UsageMethod... usageMethod) { + return null; + } + + @Override + public Set getPotentiallyAvailableNetworkActions(State state) { + return null; + } + + @Override + public NetworkAction getNetworkAction(String id) { + return null; + } + + @Override + public void removeNetworkAction(String id) { + + } + + @Override + public Map getRaUsageLimitsPerInstant() { + return null; + } + + @Override + public RaUsageLimits getRaUsageLimits(Instant instant) { + return null; + } + + @Override + public RaUsageLimitsAdder newRaUsageLimits(String instantName) { + return null; + } + + @Override + public String getId() { + return id; + } + + @Override + public String getName() { + return null; + } + + @Override + public > void addExtension(Class aClass, E e) { + + } + + @Override + public > E getExtension(Class aClass) { + return null; + } + + @Override + public > E getExtensionByName(String s) { + return null; + } + + @Override + public > boolean removeExtension(Class aClass) { + return false; + } + + @Override + public > Collection getExtensions() { + return null; + } +} diff --git a/data/crac/crac-api/src/test/java/com/powsybl/openrao/data/cracapi/MockCracExporter.java b/data/crac/crac-api/src/test/java/com/powsybl/openrao/data/cracapi/MockCracExporter.java new file mode 100644 index 0000000000..d146214af8 --- /dev/null +++ b/data/crac/crac-api/src/test/java/com/powsybl/openrao/data/cracapi/MockCracExporter.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024, 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/. + */ + +package com.powsybl.openrao.data.cracapi; + +import com.google.auto.service.AutoService; +import com.powsybl.openrao.data.cracapi.io.Exporter; + +import java.io.OutputStream; + +/** + * @author Thomas Bouquet {@literal } + */ +@AutoService(Exporter.class) +public class MockCracExporter implements Exporter { + @Override + public String getFormat() { + return "Mock"; + } + + @Override + public void exportData(Crac crac, OutputStream outputStream) { + if (crac instanceof MockCrac mockCrac) { + mockCrac.setExportSuccessful(); + } + } +} diff --git a/data/crac/crac-api/src/test/java/com/powsybl/openrao/data/cracapi/MockCracImporter.java b/data/crac/crac-api/src/test/java/com/powsybl/openrao/data/cracapi/MockCracImporter.java new file mode 100644 index 0000000000..1afd4b56c6 --- /dev/null +++ b/data/crac/crac-api/src/test/java/com/powsybl/openrao/data/cracapi/MockCracImporter.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024, 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/. + */ + +package com.powsybl.openrao.data.cracapi; + +import com.google.auto.service.AutoService; +import com.powsybl.iidm.network.Network; +import com.powsybl.openrao.data.cracapi.io.Importer; + +import java.io.InputStream; + +/** + * @author Thomas Bouquet {@literal } + */ +@AutoService(Importer.class) +public class MockCracImporter implements Importer { + + @Override + public String getFormat() { + return "Mock"; + } + + @Override + public boolean exists(InputStream inputStream) { + return true; + } + + @Override + public Crac importData(InputStream inputStream, CracFactory cracFactory, Network network) { + return new MockCrac("crac"); + } +} diff --git a/data/crac/crac-api/src/test/resources/crac.txt b/data/crac/crac-api/src/test/resources/crac.txt new file mode 100644 index 0000000000..9a4324ab0a --- /dev/null +++ b/data/crac/crac-api/src/test/resources/crac.txt @@ -0,0 +1 @@ +Example CRAC file \ No newline at end of file diff --git a/data/crac/crac-loopflow-extension/src/test/java/com/powsybl/openrao/data/cracloopflowextension/JsonLoopFlowThresholdImplImportExportTest.java b/data/crac/crac-loopflow-extension/src/test/java/com/powsybl/openrao/data/cracloopflowextension/JsonLoopFlowThresholdImplImportExportTest.java index f1a121cf93..3da33064c3 100644 --- a/data/crac/crac-loopflow-extension/src/test/java/com/powsybl/openrao/data/cracloopflowextension/JsonLoopFlowThresholdImplImportExportTest.java +++ b/data/crac/crac-loopflow-extension/src/test/java/com/powsybl/openrao/data/cracloopflowextension/JsonLoopFlowThresholdImplImportExportTest.java @@ -13,8 +13,6 @@ import com.powsybl.openrao.data.cracapi.InstantKind; import com.powsybl.openrao.data.cracapi.cnec.Side; import com.powsybl.openrao.data.cracimpl.CracImplFactory; -import com.powsybl.openrao.data.cracioapi.CracExporters; -import com.powsybl.openrao.data.cracioapi.CracImporters; import org.junit.jupiter.api.Test; import java.io.ByteArrayInputStream; @@ -63,12 +61,12 @@ void roundTripTest() { // export Crac ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - CracExporters.exportCrac(crac, "Json", outputStream); + crac.write("JSON", outputStream); // import Crac Crac importedCrac; try (ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray())) { - importedCrac = CracImporters.importCrac("whatever.json", inputStream, Network.create("test", "test")); + importedCrac = Crac.read(inputStream, Network.create("test", "test")); } catch (IOException e) { throw new UncheckedIOException(e); } diff --git a/data/crac/crac-util/pom.xml b/data/crac/crac-util/pom.xml index 165dae31c9..6c4884b860 100644 --- a/data/crac/crac-util/pom.xml +++ b/data/crac/crac-util/pom.xml @@ -34,12 +34,6 @@ ${project.version} test - - ${project.groupId} - open-rao-crac-io-api - ${project.version} - test - ${project.groupId} open-rao-crac-io-json diff --git a/data/crac/crac-util/src/test/java/com/powsybl/openrao/data/cracutil/CracAliasesCreatorTest.java b/data/crac/crac-util/src/test/java/com/powsybl/openrao/data/cracutil/CracAliasesCreatorTest.java index e9833b8e8a..abbc7c2950 100644 --- a/data/crac/crac-util/src/test/java/com/powsybl/openrao/data/cracutil/CracAliasesCreatorTest.java +++ b/data/crac/crac-util/src/test/java/com/powsybl/openrao/data/cracutil/CracAliasesCreatorTest.java @@ -7,12 +7,14 @@ package com.powsybl.openrao.data.cracutil; +import com.powsybl.iidm.network.Network; import com.powsybl.openrao.commons.OpenRaoException; -import com.powsybl.openrao.data.cracioapi.CracImporters; +import com.powsybl.openrao.data.cracapi.Crac; import org.junit.jupiter.api.Test; import java.io.InputStream; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; /** @@ -21,31 +23,37 @@ class CracAliasesCreatorTest { + private final Network network = Network.read("case-for-aliases.uct", getClass().getResourceAsStream("/case-for-aliases.uct")); + @Test void testDeprecatedCracExtensions1() { // Extensions have been deprecated InputStream inputStream = getClass().getResourceAsStream("/deprecated-crac-for-aliases-1.json"); - assertThrows(OpenRaoException.class, () -> CracImporters.importCrac("deprecated-crac-for-aliases-1.json", inputStream, null)); + OpenRaoException exception = assertThrows(OpenRaoException.class, () -> Crac.read(inputStream, network)); + assertEquals("Extensions are deprecated since CRAC version 1.7", exception.getMessage()); } @Test void testDeprecatedCracExtensions2() { // Extensions have been deprecated InputStream inputStream = getClass().getResourceAsStream("/deprecated-crac-for-aliases-2.json"); - assertThrows(OpenRaoException.class, () -> CracImporters.importCrac("deprecated-crac-for-aliases-2.json", inputStream, null)); + OpenRaoException exception = assertThrows(OpenRaoException.class, () -> Crac.read(inputStream, network)); + assertEquals("Extensions are deprecated since CRAC version 1.7", exception.getMessage()); } @Test void testDeprecatedCracExtensions3() { // Extensions have been deprecated InputStream inputStream = getClass().getResourceAsStream("/deprecated-crac-for-aliases-3.json"); - assertThrows(OpenRaoException.class, () -> CracImporters.importCrac("deprecated-crac-for-aliases-3.json", inputStream, null)); + OpenRaoException exception = assertThrows(OpenRaoException.class, () -> Crac.read(inputStream, network)); + assertEquals("Extensions are deprecated since CRAC version 1.7", exception.getMessage()); } @Test void testDeprecatedCracExtensions4() { // Extensions have been deprecated InputStream inputStream = getClass().getResourceAsStream("/deprecated-crac-for-aliases-4.json"); - assertThrows(OpenRaoException.class, () -> CracImporters.importCrac("deprecated-crac-for-aliases-4.json", inputStream, null)); + OpenRaoException exception = assertThrows(OpenRaoException.class, () -> Crac.read(inputStream, network)); + assertEquals("Extensions are deprecated since CRAC version 1.7", exception.getMessage()); } } diff --git a/data/crac/crac-util/src/test/resources/crac-for-aliases.json b/data/crac/crac-util/src/test/resources/crac-for-aliases.json deleted file mode 100644 index 8c02077a86..0000000000 --- a/data/crac/crac-util/src/test/resources/crac-for-aliases.json +++ /dev/null @@ -1,264 +0,0 @@ -{ - "type" : "CRAC", - "version" : "1.0", - "id" : "LS_parade_pst_direct", - "name" : "LS_parade_pst_direct", - "networkElementsNamePerId": { }, - "contingencies" : [ { - "id" : "Contingency BE2 FR3", - "networkElementsIds" : [ "BBE2AA1B FFR3AA1I 1" ] - }, { - "id" : "Contingency Interco", - "networkElementsIds" : [ "BBE2AA1B BBE3AA1C 1" ] - }], - "flowCnecs" : [ { - "id" : "FFR2AA1 DDE3AA1 1 - Curatif - Contingency BE2 FR3", - "name" : "Tie-line FR DE", - "networkElementId" : "FFR2AA1 DDE3AA1 1", - "contingencyId" : "Contingency BE2 FR3", - "instant": "curative", - "frm" : 0.0, - "nominalV" : [ 380.0 ], - "thresholds" : [ { - "unit" : "ampere", - "rule" : "onLeftSide", - "max" : 1500.0 - } ], - "extensions" : { - "CnecResultExtension" : { - "resultsPerVariant" : { - "preOptimisationResults-3788be4e-3998-4fe8-8d7d-e5088ab87edf" : { - "type" : "cnec-result", - "flowInMW" : 1451.9127197265625, - "flowInA" : 2097.820556640625, - "minThresholdInMW" : -Infinity, - "maxThresholdInMW" : 1039.2304845413264, - "minThresholdInA" : -Infinity, - "maxThresholdInA" : 1500.0 - }, - "postOptimisationResults-5541441d-b49f-4670-bb70-d30e60c8ccaa" : { - "type" : "cnec-result", - "flowInMW" : 1286.8662109375, - "flowInA" : 1858.9375, - "minThresholdInMW" : -Infinity, - "maxThresholdInMW" : 1039.2304845413264, - "minThresholdInA" : -Infinity, - "maxThresholdInA" : 1500.0 - } - } - } - } - }, { - "id" : "DDE1AA1 DDE2AA1 1 - Défaut - Contingency BE2 FR3", - "name" : "Line DE1 DE2", - "networkElementId" : "DDE1AA1 DDE2AA1 1", - "contingencyId" : "Contingency BE2 FR3", - "instant": "outage", - "frm" : -1.0, - "nominalV" : [ 380.0 ], - "thresholds" : [ { - "unit" : "ampere", - "rule" : "onLeftSide", - "min" : -1500.0, - "max" : 1500.0 - } ], - "extensions" : { - "CnecResultExtension" : { - "resultsPerVariant" : { - "preOptimisationResults-3788be4e-3998-4fe8-8d7d-e5088ab87edf" : { - "type" : "cnec-result", - "flowInMW" : -349.3979797363281, - "flowInA" : -504.3426208496094, - "minThresholdInMW" : -1039.2304845413264, - "maxThresholdInMW" : 1039.2304845413264, - "minThresholdInA" : -1500.0, - "maxThresholdInA" : 1500.0 - }, - "postOptimisationResults-5541441d-b49f-4670-bb70-d30e60c8ccaa" : { - "type" : "cnec-result", - "flowInMW" : -404.3988952636719, - "flowInA" : -583.7461547851562, - "minThresholdInMW" : -1039.2304845413264, - "maxThresholdInMW" : 1039.2304845413264, - "minThresholdInA" : -1500.0, - "maxThresholdInA" : 1500.0 - } - } - } - } - }, { - "id" : "DDE1AA1 DDE2AA1 1 - Curatif - Contingency BE2 FR3", - "name" : "Line DE1 DE2", - "networkElementId" : "DDE1AA1 DDE2AA1 1", - "contingencyId" : "Contingency BE2 FR3", - "instant": "curative", - "frm" : 2.0, - "nominalV" : [ 380.0 ], - "thresholds" : [ { - "unit" : "ampere", - "rule" : "onLeftSide", - "min" : -1500.0, - "max" : 1500.0 - } ], - "extensions" : { - "CnecResultExtension" : { - "resultsPerVariant" : { - "preOptimisationResults-3788be4e-3998-4fe8-8d7d-e5088ab87edf" : { - "type" : "cnec-result", - "flowInMW" : -349.3979797363281, - "flowInA" : -504.3426208496094, - "minThresholdInMW" : -1039.2304845413264, - "maxThresholdInMW" : 1039.2304845413264, - "minThresholdInA" : -1500.0, - "maxThresholdInA" : 1500.0 - }, - "postOptimisationResults-5541441d-b49f-4670-bb70-d30e60c8ccaa" : { - "type" : "cnec-result", - "flowInMW" : -404.3988952636719, - "flowInA" : -583.7461547851562, - "minThresholdInMW" : -1039.2304845413264, - "maxThresholdInMW" : 1039.2304845413264, - "minThresholdInA" : -1500.0, - "maxThresholdInA" : 1500.0 - } - } - } - } - }, { - "id" : "DDE1AA1 DDE2AA1 1 - N - preventive", - "name" : "Line DE1 DE2", - "networkElementId" : "DDE1AA1 DDE2AA1 1", - "instant" : "preventive", - "frm" : 3.0, - "nominalV" : [ 380.0 ], - "thresholds" : [ { - "unit" : "ampere", - "rule" : "onLeftSide", - "min" : -1500.0, - "max" : 1500.0 - } ], - "extensions" : { - "CnecResultExtension" : { - "resultsPerVariant" : { - "preOptimisationResults-3788be4e-3998-4fe8-8d7d-e5088ab87edf" : { - "type" : "cnec-result", - "flowInMW" : -333.455078125, - "flowInA" : -481.3270568847656, - "minThresholdInMW" : -1039.2304845413264, - "maxThresholdInMW" : 1039.2304845413264, - "minThresholdInA" : -1500.0, - "maxThresholdInA" : 1500.0 - }, - "postOptimisationResults-5541441d-b49f-4670-bb70-d30e60c8ccaa" : { - "type" : "cnec-result", - "flowInMW" : -391.2393493652344, - "flowInA" : -564.74755859375, - "minThresholdInMW" : -1039.2304845413264, - "maxThresholdInMW" : 1039.2304845413264, - "minThresholdInA" : -1500.0, - "maxThresholdInA" : 1500.0 - } - } - } - } - }, { - "id" : "FFR2AA1 DDE3AA1 1 - Défaut - Contingency BE2 FR3", - "name" : "Tie-line FR DE", - "networkElementId" : "FFR2AA1 DDE3AA1 1", - "contingencyId" : "Contingency BE2 FR3", - "instant": "outage", - "frm" : 4.0, - "nominalV" : [ 380.0 ], - "thresholds" : [ { - "unit" : "ampere", - "rule" : "onLeftSide", - "max" : 1500.0 - } ], - "extensions" : { - "CnecResultExtension" : { - "resultsPerVariant" : { - "preOptimisationResults-3788be4e-3998-4fe8-8d7d-e5088ab87edf" : { - "type" : "cnec-result", - "flowInMW" : 1451.9127197265625, - "flowInA" : 2097.820556640625, - "minThresholdInMW" : -Infinity, - "maxThresholdInMW" : 1039.2304845413264, - "minThresholdInA" : -Infinity, - "maxThresholdInA" : 1500.0 - }, - "postOptimisationResults-5541441d-b49f-4670-bb70-d30e60c8ccaa" : { - "type" : "cnec-result", - "flowInMW" : 1286.8662109375, - "flowInA" : 1858.9375, - "minThresholdInMW" : -Infinity, - "maxThresholdInMW" : 1039.2304845413264, - "minThresholdInA" : -Infinity, - "maxThresholdInA" : 1500.0 - } - } - } - } - }, { - "id" : "FFR2AA1 DDE3AA1 1 - N - preventive", - "name" : "Tie-line FR DE", - "networkElementId" : "FFR2AA1 DDE3AA1 1", - "instant" : "preventive", - "frm" : 5.0, - "nominalV" : [ 380.0 ], - "thresholds" : [ { - "unit" : "ampere", - "rule" : "onLeftSide", - "max" : 1500.0 - } ], - "extensions" : { - "CnecResultExtension" : { - "resultsPerVariant" : { - "preOptimisationResults-3788be4e-3998-4fe8-8d7d-e5088ab87edf" : { - "type" : "cnec-result", - "flowInMW" : 1499.7794189453125, - "flowInA" : 2167.1318359375, - "minThresholdInMW" : -Infinity, - "maxThresholdInMW" : 1039.2304845413264, - "minThresholdInA" : -Infinity, - "maxThresholdInA" : 1500.0 - }, - "postOptimisationResults-5541441d-b49f-4670-bb70-d30e60c8ccaa" : { - "type" : "cnec-result", - "flowInMW" : 1326.383056640625, - "flowInA" : 1916.11865234375, - "minThresholdInMW" : -Infinity, - "maxThresholdInMW" : 1039.2304845413264, - "minThresholdInA" : -Infinity, - "maxThresholdInA" : 1500.0 - } - } - } - } - } ], - "pstRangeActions" : [ { - "id" : "PST1", - "name" : "PST1", - "operator" : "FR", - "initialTap": 0, - "tapToAngleConversionMap" : { - "-3" : 0.0, - "-2" : 0.5, - "-1" : 1.0, - "0" : 1.5, - "1" : 2.0, - "2" : 2.5, - "3" : 3.0 - }, - "freeToUseUsageRules" : [ { - "usageMethod" : "available", - "instant" : "preventive" - } ], - "networkElementId" : "BBE2AA1 BBE3AA1 1", - "ranges" : [ { - "min" : 1.0, - "max" : 33.0, - "rangeType" : "absolute" - } ] - } ], - "networkActions" : [ ] -} \ No newline at end of file diff --git a/data/crac/crac-util/src/test/resources/deprecated-crac-for-aliases-1.json b/data/crac/crac-util/src/test/resources/deprecated-crac-for-aliases-1.json index 6e71ade22d..50f74b83e5 100644 --- a/data/crac/crac-util/src/test/resources/deprecated-crac-for-aliases-1.json +++ b/data/crac/crac-util/src/test/resources/deprecated-crac-for-aliases-1.json @@ -5,17 +5,17 @@ "name" : "LS_parade_pst_direct", "networkElementsNamePerId": { }, "contingencies" : [ { - "id" : "Contingency FR1 FR3", - "networkElementsIds" : [ "FFR3AA1 FFR1AA1 1" ] + "id" : "Contingency 1", + "networkElementsIds" : [ "FFR1AA1G FFR2AA1H 1" ] }, { "id" : "Contingency Interco", - "networkElementsIds" : [ "DDE3AA1 FFR2AA1 HFSK JDV" ] + "networkElementsIds" : [ "FFR2AA1H DDE3AA1F 1" ] }], "flowCnecs" : [ { - "id" : "FFR2AA1 DDE3AA1 1 - Curatif - Contingency FR1 FR3", + "id" : "FFR2AA1 DDE3AA1 1 - Curatif - Contingency 1", "name" : "Tie-line FR DE", "networkElementId" : "FFR2AA1 DDE3AA1 1", - "contingencyId" : "Contingency FR1 FR3", + "contingencyId" : "Contingency 1", "instant": "curative", "frm" : 0.0, "nominalV" : [ 380.0 ], @@ -49,10 +49,10 @@ } } }, { - "id" : "DDE1AA1 DDE2AA1 1 - Défaut - Contingency FR1 FR3", + "id" : "DDE1AA1 DDE2AA1 1 - Défaut - Contingency 1", "name" : "Line DE1 DE2", "networkElementId" : "DDE1AA1 DDE2AA1 1", - "contingencyId" : "Contingency FR1 FR3", + "contingencyId" : "Contingency 1", "instant": "outage", "frm" : -1.0, "nominalV" : [ 380.0 ], @@ -87,10 +87,10 @@ } } }, { - "id" : "DDE1AA1 DDE2AA1 1 - Curatif - Contingency FR1 FR3", + "id" : "DDE1AA1 DDE2AA1 1 - Curatif - Contingency 1", "name" : "Line DE1 DE2", "networkElementId" : "DDE1AA1 DDE2AA1 1", - "contingencyId" : "Contingency FR1 FR3", + "contingencyId" : "Contingency 1", "instant": "curative", "frm" : 2.0, "nominalV" : [ 380.0 ], @@ -162,10 +162,10 @@ } } }, { - "id" : "FFR2AA1 DDE3AA1 1 - Défaut - Contingency FR1 FR3", + "id" : "FFR2AA1 DDE3AA1 1 - Défaut - Contingency 1", "name" : "Tie-line FR DE", "networkElementId" : "FFR2AA1 DDE3AA1 1", - "contingencyId" : "Contingency FR1 FR3", + "contingencyId" : "Contingency 1", "instant": "outage", "frm" : 4.0, "nominalV" : [ 380.0 ], @@ -268,8 +268,8 @@ "preventive" : 0 }, "setPointPerStates" : { - "Contingency FR1 FR3-outage" : NaN, - "Contingency FR1 FR3-curative" : NaN, + "Contingency 1-outage" : NaN, + "Contingency 1-curative" : NaN, "preventive" : 0.0 } }, @@ -279,8 +279,8 @@ "preventive" : -16 }, "setPointPerStates" : { - "Contingency FR1 FR3-outage" : NaN, - "Contingency FR1 FR3-curative" : NaN, + "Contingency 1-outage" : NaN, + "Contingency 1-curative" : NaN, "preventive" : -6.22764253616333 } } diff --git a/data/crac/crac-util/src/test/resources/deprecated-crac-for-aliases-2.json b/data/crac/crac-util/src/test/resources/deprecated-crac-for-aliases-2.json index 80370e994e..32a490b364 100644 --- a/data/crac/crac-util/src/test/resources/deprecated-crac-for-aliases-2.json +++ b/data/crac/crac-util/src/test/resources/deprecated-crac-for-aliases-2.json @@ -5,17 +5,17 @@ "name" : "LS_parade_pst_direct", "networkElementsNamePerId": { }, "contingencies" : [ { - "id" : "Contingency FR1 FR3", - "networkElementsIds" : [ "FFR3AA1 FFR1AA1 1" ] + "id" : "Contingency 1", + "networkElementsIds" : [ "FFR1AA1G FFR2AA1H 1" ] }, { "id" : "Contingency Interco", - "networkElementsIds" : [ "DDE3AA1 FFR2AA1 HFSK JDV" ] + "networkElementsIds" : [ "FFR2AA1H DDE3AA1F 1" ] }], "flowCnecs" : [ { - "id" : "FFR2AA1 DDE3AA1 1 - Curatif - Contingency FR1 FR3", + "id" : "FFR2AA1 DDE3AA1 1 - Curatif - Contingency 1", "name" : "Tie-line FR DE", "networkElementId" : "FFR2AA1 DDE3AA1 1", - "contingencyId" : "Contingency FR1 FR3", + "contingencyId" : "Contingency 1", "instant": "curative", "frm" : 0.0, "nominalV" : [ 380.0 ], @@ -49,10 +49,10 @@ } } }, { - "id" : "DDE1AA1 DDE2AA1 1 - Défaut - Contingency FR1 FR3", + "id" : "DDE1AA1 DDE2AA1 1 - Défaut - Contingency 1", "name" : "Line DE1 DE2", "networkElementId" : "DDE1AA1 DDE2AA1 1", - "contingencyId" : "Contingency FR1 FR3", + "contingencyId" : "Contingency 1", "instant": "outage", "frm" : -1.0, "nominalV" : [ 380.0 ], @@ -87,10 +87,10 @@ } } }, { - "id" : "DDE1AA1 DDE2AA1 1 - Curatif - Contingency FR1 FR3", + "id" : "DDE1AA1 DDE2AA1 1 - Curatif - Contingency 1", "name" : "Line DE1 DE2", "networkElementId" : "DDE1AA1 DDE2AA1 1", - "contingencyId" : "Contingency FR1 FR3", + "contingencyId" : "Contingency 1", "instant": "curative", "frm" : 2.0, "nominalV" : [ 380.0 ], @@ -162,10 +162,10 @@ } } }, { - "id" : "FFR2AA1 DDE3AA1 1 - Défaut - Contingency FR1 FR3", + "id" : "FFR2AA1 DDE3AA1 1 - Défaut - Contingency 1", "name" : "Tie-line FR DE", "networkElementId" : "FFR2AA1 DDE3AA1 1", - "contingencyId" : "Contingency FR1 FR3", + "contingencyId" : "Contingency 1", "instant": "outage", "frm" : 4.0, "nominalV" : [ 380.0 ], diff --git a/data/crac/crac-util/src/test/resources/deprecated-crac-for-aliases-3.json b/data/crac/crac-util/src/test/resources/deprecated-crac-for-aliases-3.json index c65f29d982..0482d9de8d 100644 --- a/data/crac/crac-util/src/test/resources/deprecated-crac-for-aliases-3.json +++ b/data/crac/crac-util/src/test/resources/deprecated-crac-for-aliases-3.json @@ -5,17 +5,17 @@ "name" : "LS_parade_pst_direct", "networkElementsNamePerId": { }, "contingencies" : [ { - "id" : "Contingency FR1 FR3", - "networkElementsIds" : [ "FFR3AA1 FFR1AA1 1" ] + "id" : "Contingency 1", + "networkElementsIds" : [ "FFR1AA1G FFR2AA1H 1" ] }, { "id" : "Contingency Interco", - "networkElementsIds" : [ "DDE3AA1 FFR2AA1 HFSK JDV" ] + "networkElementsIds" : [ "FFR2AA1H DDE3AA1F 1" ] }], "flowCnecs" : [ { - "id" : "FFR2AA1 DDE3AA1 1 - Curatif - Contingency FR1 FR3", + "id" : "FFR2AA1 DDE3AA1 1 - Curatif - Contingency 1", "name" : "Tie-line FR DE", "networkElementId" : "FFR2AA1 DDE3AA1 1", - "contingencyId" : "Contingency FR1 FR3", + "contingencyId" : "Contingency 1", "instant": "curative", "frm" : 0.0, "nominalV" : [ 380.0 ], @@ -49,10 +49,10 @@ } } }, { - "id" : "DDE1AA1 DDE2AA1 1 - Défaut - Contingency FR1 FR3", + "id" : "DDE1AA1 DDE2AA1 1 - Défaut - Contingency 1", "name" : "Line DE1 DE2", "networkElementId" : "DDE1AA1 DDE2AA1 1", - "contingencyId" : "Contingency FR1 FR3", + "contingencyId" : "Contingency 1", "instant": "outage", "frm" : -1.0, "nominalV" : [ 380.0 ], @@ -87,10 +87,10 @@ } } }, { - "id" : "DDE1AA1 DDE2AA1 1 - Curatif - Contingency FR1 FR3", + "id" : "DDE1AA1 DDE2AA1 1 - Curatif - Contingency 1", "name" : "Line DE1 DE2", "networkElementId" : "DDE1AA1 DDE2AA1 1", - "contingencyId" : "Contingency FR1 FR3", + "contingencyId" : "Contingency 1", "instant": "curative", "frm" : 2.0, "nominalV" : [ 380.0 ], @@ -162,10 +162,10 @@ } } }, { - "id" : "FFR2AA1 DDE3AA1 1 - Défaut - Contingency FR1 FR3", + "id" : "FFR2AA1 DDE3AA1 1 - Défaut - Contingency 1", "name" : "Tie-line FR DE", "networkElementId" : "FFR2AA1 DDE3AA1 1", - "contingencyId" : "Contingency FR1 FR3", + "contingencyId" : "Contingency 1", "instant": "outage", "frm" : 4.0, "nominalV" : [ 380.0 ], @@ -279,7 +279,7 @@ "operator" : "RTE", "onFlowConstraintUsageRules" : [ { "instant" : "preventive", - "flowCnecId" : "cnec3curId" + "flowCnecId" : "FFR2AA1 DDE3AA1 1 - Curatif - Contingency 1" } ], "networkElementId" : "hvdc2", "groupId" : "group-1-hvdc", diff --git a/data/crac/crac-util/src/test/resources/deprecated-crac-for-aliases-4.json b/data/crac/crac-util/src/test/resources/deprecated-crac-for-aliases-4.json index e6a7dc8e44..185db8875d 100644 --- a/data/crac/crac-util/src/test/resources/deprecated-crac-for-aliases-4.json +++ b/data/crac/crac-util/src/test/resources/deprecated-crac-for-aliases-4.json @@ -5,17 +5,17 @@ "name" : "LS_parade_pst_direct", "networkElementsNamePerId": { }, "contingencies" : [ { - "id" : "Contingency FR1 FR3", - "networkElementsIds" : [ "FFR3AA1 FFR1AA1 1" ] + "id" : "Contingency 1", + "networkElementsIds" : [ "FFR1AA1G FFR2AA1H 1" ] }, { "id" : "Contingency Interco", - "networkElementsIds" : [ "DDE3AA1 FFR2AA1 HFSK JDV" ] + "networkElementsIds" : [ "FFR2AA1H DDE3AA1F 1" ] }], "flowCnecs" : [ { - "id" : "FFR2AA1 DDE3AA1 1 - Curatif - Contingency FR1 FR3", + "id" : "FFR2AA1 DDE3AA1 1 - Curatif - Contingency 1", "name" : "Tie-line FR DE", "networkElementId" : "FFR2AA1 DDE3AA1 1", - "contingencyId" : "Contingency FR1 FR3", + "contingencyId" : "Contingency 1", "instant": "curative", "frm" : 0.0, "nominalV" : [ 380.0 ], @@ -49,10 +49,10 @@ } } }, { - "id" : "DDE1AA1 DDE2AA1 1 - Défaut - Contingency FR1 FR3", + "id" : "DDE1AA1 DDE2AA1 1 - Défaut - Contingency 1", "name" : "Line DE1 DE2", "networkElementId" : "DDE1AA1 DDE2AA1 1", - "contingencyId" : "Contingency FR1 FR3", + "contingencyId" : "Contingency 1", "instant": "outage", "frm" : -1.0, "nominalV" : [ 380.0 ], @@ -87,10 +87,10 @@ } } }, { - "id" : "DDE1AA1 DDE2AA1 1 - Curatif - Contingency FR1 FR3", + "id" : "DDE1AA1 DDE2AA1 1 - Curatif - Contingency 1", "name" : "Line DE1 DE2", "networkElementId" : "DDE1AA1 DDE2AA1 1", - "contingencyId" : "Contingency FR1 FR3", + "contingencyId" : "Contingency 1", "instant": "curative", "frm" : 2.0, "nominalV" : [ 380.0 ], @@ -162,10 +162,10 @@ } } }, { - "id" : "FFR2AA1 DDE3AA1 1 - Défaut - Contingency FR1 FR3", + "id" : "FFR2AA1 DDE3AA1 1 - Défaut - Contingency 1", "name" : "Tie-line FR DE", "networkElementId" : "FFR2AA1 DDE3AA1 1", - "contingencyId" : "Contingency FR1 FR3", + "contingencyId" : "Contingency 1", "instant": "outage", "frm" : 4.0, "nominalV" : [ 380.0 ], @@ -266,7 +266,7 @@ "operator" : null, "onStateUsageRules" : [ { "instant" : "curative", - "contingencyId" : "contingency1Id", + "contingencyId" : "Contingency 1", "usageMethod" : "available" } ], "networkElementIdsAndKeys" : { diff --git a/data/rao-result/rao-result-api/src/main/java/com/powsybl/openrao/data/raoresultapi/RaoResult.java b/data/rao-result/rao-result-api/src/main/java/com/powsybl/openrao/data/raoresultapi/RaoResult.java index ace16b11c6..cdd0995cfe 100644 --- a/data/rao-result/rao-result-api/src/main/java/com/powsybl/openrao/data/raoresultapi/RaoResult.java +++ b/data/rao-result/rao-result-api/src/main/java/com/powsybl/openrao/data/raoresultapi/RaoResult.java @@ -7,6 +7,7 @@ package com.powsybl.openrao.data.raoresultapi; +import com.powsybl.commons.util.ServiceLoaderCache; import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.commons.PhysicalParameter; import com.powsybl.openrao.commons.Unit; @@ -21,7 +22,15 @@ import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; - +import com.powsybl.openrao.data.raoresultapi.io.Exporter; +import com.powsybl.openrao.data.raoresultapi.io.Importer; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.List; import java.util.Map; import java.util.Set; @@ -438,4 +447,63 @@ default boolean isActivated(State state, NetworkAction networkAction) { default boolean isSecure() { return isSecure(PhysicalParameter.FLOW, PhysicalParameter.ANGLE, PhysicalParameter.VOLTAGE); } + + /** + * Import RaoResult from a file + * + * @param importers candidates RaoResult importers to process the data + * @param inputStream RaoResult data + * @param crac the crac on which the RaoResult data is based + * @return RaoResult object + */ + private static RaoResult read(List importers, InputStream inputStream, Crac crac) throws IOException { + byte[] bytes = getBytesFromInputStream(inputStream); + return importers.stream() + .filter(importer -> importer.exists(new ByteArrayInputStream(bytes))) + .findAny() + .orElseThrow(() -> new OpenRaoException("No suitable RaoResult importer found.")) + .importData(new ByteArrayInputStream(bytes), crac); + } + + /** + * Import RaoResult from a file + * + * @param inputStream RaoResult data + * @param crac the crac on which the RaoResult data is based + * @return RaoResult object + */ + static RaoResult read(InputStream inputStream, Crac crac) throws IOException { + return read(new ServiceLoaderCache<>(Importer.class).getServices(), inputStream, crac); + } + + private static byte[] getBytesFromInputStream(InputStream inputStream) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + org.apache.commons.io.IOUtils.copy(inputStream, baos); + return baos.toByteArray(); + } + + /** + * Write CRAC data into a file + * + * @param exporters candidate CRAC exporters + * @param format desired output CRAC data type + * @param outputStream file where to write the CRAC data + */ + private void write(List exporters, String format, Crac crac, Set flowUnits, OutputStream outputStream) { + exporters.stream() + .filter(ex -> format.equals(ex.getFormat())) + .findAny() + .orElseThrow(() -> new OpenRaoException("Export format " + format + " not supported")) + .exportData(this, crac, flowUnits, outputStream); + } + + /** + * Write CRAC data into a file + * + * @param format desired output CRAC data type + * @param outputStream file where to write the CRAC data + */ + default void write(String format, Crac crac, Set flowUnits, OutputStream outputStream) { + write(new ServiceLoaderCache<>(Exporter.class).getServices(), format, crac, flowUnits, outputStream); + } } diff --git a/data/rao-result/rao-result-api/src/main/java/com/powsybl/openrao/data/raoresultapi/io/Exporter.java b/data/rao-result/rao-result-api/src/main/java/com/powsybl/openrao/data/raoresultapi/io/Exporter.java new file mode 100644 index 0000000000..a2134eff47 --- /dev/null +++ b/data/rao-result/rao-result-api/src/main/java/com/powsybl/openrao/data/raoresultapi/io/Exporter.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024, 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/. + */ + +package com.powsybl.openrao.data.raoresultapi.io; + +import com.powsybl.openrao.commons.Unit; +import com.powsybl.openrao.data.cracapi.Crac; +import com.powsybl.openrao.data.raoresultapi.RaoResult; + +import java.io.OutputStream; +import java.util.Set; + +/** + * @author Thomas Bouquet {@literal } + */ +public interface Exporter { + /** + * Get a unique identifier of the format. + */ + String getFormat(); + + void exportData(RaoResult raoResult, Crac crac, Set flowUnits, OutputStream outputStream); +} diff --git a/data/rao-result/rao-result-api/src/main/java/com/powsybl/openrao/data/raoresultapi/io/Importer.java b/data/rao-result/rao-result-api/src/main/java/com/powsybl/openrao/data/raoresultapi/io/Importer.java new file mode 100644 index 0000000000..ac49c93045 --- /dev/null +++ b/data/rao-result/rao-result-api/src/main/java/com/powsybl/openrao/data/raoresultapi/io/Importer.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024, 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/. + */ + +package com.powsybl.openrao.data.raoresultapi.io; + +import com.powsybl.openrao.data.cracapi.Crac; +import com.powsybl.openrao.data.raoresultapi.RaoResult; + +import java.io.InputStream; + +/** + * @author Thomas Bouquet {@literal } + */ +public interface Importer { + /** + * Get a unique identifier of the format. + */ + String getFormat(); + + boolean exists(InputStream inputStream); + + /** + * Create a RaoResult. + * + * @param inputStream RaoResult data + * @param crac the crac on which the RaoResult data is based + * @return the model + */ + RaoResult importData(InputStream inputStream, Crac crac); +} diff --git a/data/rao-result/rao-result-api/src/test/java/com/powsybl/openrao/data/raoresultapi/MockRaoResult.java b/data/rao-result/rao-result-api/src/test/java/com/powsybl/openrao/data/raoresultapi/MockRaoResult.java new file mode 100644 index 0000000000..a1f5c4b414 --- /dev/null +++ b/data/rao-result/rao-result-api/src/test/java/com/powsybl/openrao/data/raoresultapi/MockRaoResult.java @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2024, 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/. + */ + +package com.powsybl.openrao.data.raoresultapi; + +import com.powsybl.openrao.commons.PhysicalParameter; +import com.powsybl.openrao.commons.Unit; +import com.powsybl.openrao.data.cracapi.Instant; +import com.powsybl.openrao.data.cracapi.RemedialAction; +import com.powsybl.openrao.data.cracapi.State; +import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; +import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; +import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; +import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; + +import java.util.Map; +import java.util.Set; + +/** + * @author Thomas Bouquet {@literal } + */ +public class MockRaoResult implements RaoResult { + + private boolean wasExportSuccessful; + + public MockRaoResult() { + this.wasExportSuccessful = false; + } + + public void setExportSuccessful() { + wasExportSuccessful = true; + } + + public boolean wasExportSuccessful() { + return wasExportSuccessful; + } + + @Override + public ComputationStatus getComputationStatus() { + return null; + } + + @Override + public ComputationStatus getComputationStatus(State state) { + return null; + } + + @Override + public double getFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit) { + return 0; + } + + @Override + public double getMargin(Instant optimizedInstant, FlowCnec flowCnec, Unit unit) { + return 0; + } + + @Override + public double getRelativeMargin(Instant optimizedInstant, FlowCnec flowCnec, Unit unit) { + return 0; + } + + @Override + public double getCommercialFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit) { + return 0; + } + + @Override + public double getLoopFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit) { + return 0; + } + + @Override + public double getPtdfZonalSum(Instant optimizedInstant, FlowCnec flowCnec, Side side) { + return 0; + } + + @Override + public double getFunctionalCost(Instant optimizedInstant) { + return 0; + } + + @Override + public double getVirtualCost(Instant optimizedInstant) { + return 0; + } + + @Override + public Set getVirtualCostNames() { + return null; + } + + @Override + public double getVirtualCost(Instant optimizedInstant, String virtualCostName) { + return 0; + } + + @Override + public boolean isActivatedDuringState(State state, RemedialAction remedialAction) { + return false; + } + + @Override + public boolean wasActivatedBeforeState(State state, NetworkAction networkAction) { + return false; + } + + @Override + public boolean isActivatedDuringState(State state, NetworkAction networkAction) { + return false; + } + + @Override + public Set getActivatedNetworkActionsDuringState(State state) { + return null; + } + + @Override + public boolean isActivatedDuringState(State state, RangeAction rangeAction) { + return false; + } + + @Override + public int getPreOptimizationTapOnState(State state, PstRangeAction pstRangeAction) { + return 0; + } + + @Override + public int getOptimizedTapOnState(State state, PstRangeAction pstRangeAction) { + return 0; + } + + @Override + public double getPreOptimizationSetPointOnState(State state, RangeAction rangeAction) { + return 0; + } + + @Override + public double getOptimizedSetPointOnState(State state, RangeAction rangeAction) { + return 0; + } + + @Override + public Set> getActivatedRangeActionsDuringState(State state) { + return null; + } + + @Override + public Map getOptimizedTapsOnState(State state) { + return null; + } + + @Override + public Map, Double> getOptimizedSetPointsOnState(State state) { + return null; + } + + @Override + public OptimizationStepsExecuted getOptimizationStepsExecuted() { + return null; + } + + @Override + public void setOptimizationStepsExecuted(OptimizationStepsExecuted optimizationStepsExecuted) { + + } + + @Override + public boolean isSecure(Instant optimizedInstant, PhysicalParameter... u) { + return false; + } + + @Override + public boolean isSecure(PhysicalParameter... u) { + return false; + } +} diff --git a/data/rao-result/rao-result-api/src/test/java/com/powsybl/openrao/data/raoresultapi/MockRaoResultExporter.java b/data/rao-result/rao-result-api/src/test/java/com/powsybl/openrao/data/raoresultapi/MockRaoResultExporter.java new file mode 100644 index 0000000000..b77719a1ca --- /dev/null +++ b/data/rao-result/rao-result-api/src/test/java/com/powsybl/openrao/data/raoresultapi/MockRaoResultExporter.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024, 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/. + */ + +package com.powsybl.openrao.data.raoresultapi; + +import com.google.auto.service.AutoService; +import com.powsybl.openrao.commons.Unit; +import com.powsybl.openrao.data.cracapi.Crac; +import com.powsybl.openrao.data.raoresultapi.io.Exporter; + +import java.io.OutputStream; +import java.util.Set; + +/** + * @author Thomas Bouquet {@literal } + */ +@AutoService(Exporter.class) +public class MockRaoResultExporter implements Exporter { + @Override + public String getFormat() { + return "Mock"; + } + + @Override + public void exportData(RaoResult raoResult, Crac crac, Set flowUnits, OutputStream outputStream) { + if (raoResult instanceof MockRaoResult mockRaoResult) { + mockRaoResult.setExportSuccessful(); + } + } +} diff --git a/data/rao-result/rao-result-api/src/test/java/com/powsybl/openrao/data/raoresultapi/MockRaoResultImporter.java b/data/rao-result/rao-result-api/src/test/java/com/powsybl/openrao/data/raoresultapi/MockRaoResultImporter.java new file mode 100644 index 0000000000..a30d735356 --- /dev/null +++ b/data/rao-result/rao-result-api/src/test/java/com/powsybl/openrao/data/raoresultapi/MockRaoResultImporter.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024, 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/. + */ + +package com.powsybl.openrao.data.raoresultapi; + +import com.google.auto.service.AutoService; +import com.powsybl.openrao.data.cracapi.Crac; +import com.powsybl.openrao.data.raoresultapi.io.Importer; + +import java.io.InputStream; + +/** + * @author Thomas Bouquet {@literal } + */ +@AutoService(Importer.class) +public class MockRaoResultImporter implements Importer { + @Override + public String getFormat() { + return "Mock"; + } + + @Override + public boolean exists(InputStream inputStream) { + return true; + } + + @Override + public RaoResult importData(InputStream inputStream, Crac crac) { + return new MockRaoResult(); + } +} diff --git a/data/rao-result/rao-result-api/src/test/java/com/powsybl/openrao/data/raoresultapi/RaoResultExportTest.java b/data/rao-result/rao-result-api/src/test/java/com/powsybl/openrao/data/raoresultapi/RaoResultExportTest.java new file mode 100644 index 0000000000..752f0fd612 --- /dev/null +++ b/data/rao-result/rao-result-api/src/test/java/com/powsybl/openrao/data/raoresultapi/RaoResultExportTest.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024, 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/. + */ + +package com.powsybl.openrao.data.raoresultapi; + +import com.powsybl.openrao.commons.OpenRaoException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.Set; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * @author Thomas Bouquet {@literal } + */ +class RaoResultExportTest { + + private MockRaoResult raoResult; + + @BeforeEach + void setUp() { + raoResult = new MockRaoResult(); + } + + @Test + void testExportWithUnknownExporter() { + OpenRaoException exception = assertThrows(OpenRaoException.class, () -> raoResult.write("unknownFormat", null, Set.of(), null)); + assertEquals("Export format unknownFormat not supported", exception.getMessage()); + assertFalse(raoResult.wasExportSuccessful()); + } + + @Test + void testExportCracWithValidExporter() { + raoResult.write("Mock", null, Set.of(), null); + assertTrue(raoResult.wasExportSuccessful()); + } +} diff --git a/data/rao-result/rao-result-api/src/test/java/com/powsybl/openrao/data/raoresultapi/RaoResultImportTest.java b/data/rao-result/rao-result-api/src/test/java/com/powsybl/openrao/data/raoresultapi/RaoResultImportTest.java new file mode 100644 index 0000000000..20cd939fe6 --- /dev/null +++ b/data/rao-result/rao-result-api/src/test/java/com/powsybl/openrao/data/raoresultapi/RaoResultImportTest.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024, 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/. + */ + +package com.powsybl.openrao.data.raoresultapi; + +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * @author Thomas Bouquet {@literal } + */ +class RaoResultImportTest { + + @Test + void testImportFromInputStream() throws IOException { + assertTrue(RaoResult.read(getClass().getResourceAsStream("/raoResult.txt"), null) instanceof MockRaoResult); + } +} diff --git a/data/rao-result/rao-result-api/src/test/resources/raoResult.txt b/data/rao-result/rao-result-api/src/test/resources/raoResult.txt new file mode 100644 index 0000000000..c7e3c73e3d --- /dev/null +++ b/data/rao-result/rao-result-api/src/test/resources/raoResult.txt @@ -0,0 +1 @@ +Example of RAO Result \ No newline at end of file diff --git a/data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/RaoResultExporter.java b/data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/RaoResultJsonExporter.java similarity index 83% rename from data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/RaoResultExporter.java rename to data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/RaoResultJsonExporter.java index 128f46cd22..9c0f3f6e96 100644 --- a/data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/RaoResultExporter.java +++ b/data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/RaoResultJsonExporter.java @@ -7,9 +7,11 @@ package com.powsybl.openrao.data.raoresultjson; +import com.google.auto.service.AutoService; import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.Crac; +import com.powsybl.openrao.data.raoresultapi.io.Exporter; import com.powsybl.openrao.data.raoresultapi.RaoResult; import com.powsybl.openrao.data.raoresultjson.serializers.RaoResultJsonSerializerModule; import com.powsybl.commons.json.JsonUtil; @@ -25,9 +27,15 @@ /** * @author Baptiste Seguinot {@literal } */ -public class RaoResultExporter { +@AutoService(Exporter.class) +public class RaoResultJsonExporter implements Exporter { + @Override + public String getFormat() { + return "JSON"; + } - public void export(RaoResult raoResult, Crac crac, Set flowUnits, OutputStream outputStream) { + @Override + public void exportData(RaoResult raoResult, Crac crac, Set flowUnits, OutputStream outputStream) { if (flowUnits.isEmpty()) { throw new OpenRaoException("At least one flow unit should be defined"); } diff --git a/data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/RaoResultImporter.java b/data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/RaoResultJsonImporter.java similarity index 56% rename from data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/RaoResultImporter.java rename to data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/RaoResultJsonImporter.java index 1d9306fb84..dad0c79eea 100644 --- a/data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/RaoResultImporter.java +++ b/data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/RaoResultJsonImporter.java @@ -6,7 +6,10 @@ */ package com.powsybl.openrao.data.raoresultjson; +import com.google.auto.service.AutoService; +import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.data.cracapi.Crac; +import com.powsybl.openrao.data.raoresultapi.io.Importer; import com.powsybl.openrao.data.raoresultapi.RaoResult; import com.powsybl.openrao.data.raoresultjson.deserializers.RaoResultDeserializer; import com.fasterxml.jackson.databind.ObjectMapper; @@ -21,9 +24,30 @@ /** * @author Baptiste Seguinot {@literal } */ -public class RaoResultImporter { +@AutoService(Importer.class) +public class RaoResultJsonImporter implements Importer { + @Override + public String getFormat() { + return "JSON"; + } - public RaoResult importRaoResult(InputStream inputStream, Crac crac) { + @Override + public boolean exists(InputStream inputStream) { + try { + ObjectMapper objectMapper = createObjectMapper(); + SimpleModule module = new SimpleModule(); + module.addDeserializer(RaoResult.class, new RaoResultDeserializer(true)); + objectMapper.registerModule(module); + // TODO: replace this by a call to RaoResultDeserializer.isValid + objectMapper.readValue(inputStream, RaoResult.class); + return true; + } catch (OpenRaoException | IOException e) { + return false; + } + } + + @Override + public RaoResult importData(InputStream inputStream, Crac crac) { try { ObjectMapper objectMapper = createObjectMapper(); SimpleModule module = new SimpleModule(); @@ -34,5 +58,4 @@ public RaoResult importRaoResult(InputStream inputStream, Crac crac) { throw new UncheckedIOException(e); } } - } diff --git a/data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/deserializers/RaoResultDeserializer.java b/data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/deserializers/RaoResultDeserializer.java index 0ec9de4066..d0d79cd4be 100644 --- a/data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/deserializers/RaoResultDeserializer.java +++ b/data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/deserializers/RaoResultDeserializer.java @@ -33,11 +33,15 @@ public class RaoResultDeserializer extends JsonDeserializer { private Crac crac; - private RaoResultDeserializer() { + private final boolean checkHeaderOnly; + + public RaoResultDeserializer(boolean checkHeaderOnly) { + this.checkHeaderOnly = checkHeaderOnly; } public RaoResultDeserializer(Crac crac) { this.crac = crac; + this.checkHeaderOnly = false; } @Override @@ -45,28 +49,11 @@ public RaoResult deserialize(JsonParser jsonParser, DeserializationContext deser RaoResultImpl raoResult = new RaoResultImpl(crac); - String firstFieldName = jsonParser.nextFieldName(); - String jsonFileVersion; - - if (firstFieldName.equals(COMPUTATION_STATUS)) { - /* - it is assumed that the document version is 1.0 - at this time, there were not the headers with TYPE, VERSION and INFO of the document - */ - jsonFileVersion = "1.0"; - raoResult.setComputationStatus(deserializeStatus(jsonParser.nextTextValue())); - } else { - if (!jsonParser.nextTextValue().equals(RAO_RESULT_TYPE)) { - throw new OpenRaoException(String.format("type of document must be %s", RAO_RESULT_TYPE)); - } - if (!jsonParser.nextFieldName().equals(VERSION)) { - throw new OpenRaoException(String.format("%s must contain a version in its second field", RAO_RESULT_TYPE)); - } - jsonFileVersion = jsonParser.nextTextValue(); + String jsonFileVersion = isValid(jsonParser, raoResult); + if (checkHeaderOnly) { + return null; } - checkVersion(jsonFileVersion); - while (jsonParser.nextToken() != JsonToken.END_OBJECT) { switch (jsonParser.getCurrentName()) { @@ -134,12 +121,37 @@ public RaoResult deserialize(JsonParser jsonParser, DeserializationContext deser return raoResult; } + public static String isValid(JsonParser jsonParser, RaoResultImpl raoResult) throws IOException { + String firstFieldName = jsonParser.nextFieldName(); + String jsonFileVersion; + + if (firstFieldName.equals(COMPUTATION_STATUS)) { + /* + it is assumed that the document version is 1.0 + at this time, there were not the headers with TYPE, VERSION and INFO of the document + */ + jsonFileVersion = "1.0"; + raoResult.setComputationStatus(deserializeStatus(jsonParser.nextTextValue())); + } else { + if (!jsonParser.nextTextValue().equals(RAO_RESULT_TYPE)) { + throw new OpenRaoException(String.format("type of document must be %s", RAO_RESULT_TYPE)); + } + if (!jsonParser.nextFieldName().equals(VERSION)) { + throw new OpenRaoException(String.format("%s must contain a version in its second field", RAO_RESULT_TYPE)); + } + jsonFileVersion = jsonParser.nextTextValue(); + } + + checkVersion(jsonFileVersion); + return jsonFileVersion; + } + private void importRangeAction(JsonParser jsonParser, RaoResultImpl raoResult, String jsonFileVersion) throws IOException { jsonParser.nextToken(); RangeActionResultArrayDeserializer.deserialize(jsonParser, raoResult, crac, jsonFileVersion); } - private void checkVersion(String raoResultVersion) { + private static void checkVersion(String raoResultVersion) { if (getPrimaryVersionNumber(RAO_RESULT_IO_VERSION) > getPrimaryVersionNumber(raoResultVersion)) { throw new OpenRaoException(String.format("RAO-result importer %s is no longer compatible with json RAO-result version %s", RAO_RESULT_IO_VERSION, raoResultVersion)); diff --git a/data/rao-result/rao-result-json/src/test/java/com/powsybl/openrao/data/raoresultjson/ImporterRetrocompatibilityTest.java b/data/rao-result/rao-result-json/src/test/java/com/powsybl/openrao/data/raoresultjson/ImporterRetrocompatibilityTest.java index 92878da15c..42d06cbe3c 100644 --- a/data/rao-result/rao-result-json/src/test/java/com/powsybl/openrao/data/raoresultjson/ImporterRetrocompatibilityTest.java +++ b/data/rao-result/rao-result-json/src/test/java/com/powsybl/openrao/data/raoresultjson/ImporterRetrocompatibilityTest.java @@ -21,12 +21,12 @@ import com.powsybl.openrao.data.cracapi.rangeaction.HvdcRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.InjectionRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; -import com.powsybl.openrao.data.craciojson.JsonImport; import com.powsybl.openrao.data.raoresultapi.ComputationStatus; import com.powsybl.openrao.data.raoresultapi.RaoResult; import org.junit.jupiter.api.Test; import org.mockito.Mockito; +import java.io.IOException; import java.io.InputStream; import java.util.Set; @@ -72,7 +72,12 @@ private static Network mockNetworkWithLines(String... lineIds) { } @Test - void importV1Point0Test() { + void testFormat() { + assertEquals("JSON", new RaoResultJsonImporter().getFormat()); + } + + @Test + void importV1Point0Test() throws IOException { // JSON file of open-rao v3.4.3 /* @@ -82,14 +87,14 @@ void importV1Point0Test() { InputStream raoResultFile = getClass().getResourceAsStream("/retrocompatibility/v1.0/rao-result-v1.0.json"); InputStream cracFile = getClass().getResourceAsStream("/retrocompatibility/v1.0/crac-for-rao-result-v1.0.json"); - Crac crac = new JsonImport().importCrac(cracFile, mockNetworkWithLines("ne1Id", "ne2Id", "ne3Id")); - RaoResult raoResult = new RaoResultImporter().importRaoResult(raoResultFile, crac); + Crac crac = Crac.read(cracFile, mockNetworkWithLines("ne1Id", "ne2Id", "ne3Id")); + RaoResult raoResult = new RaoResultJsonImporter().importData(raoResultFile, crac); testBaseContentOfV1RaoResult(raoResult, crac); } @Test - void importV1Point1Test() { + void importV1Point1Test() throws IOException { // JSON file of open-rao v3.5.0 /* @@ -100,85 +105,85 @@ void importV1Point1Test() { InputStream raoResultFile = getClass().getResourceAsStream("/retrocompatibility/v1.1/rao-result-v1.1.json"); InputStream cracFile = getClass().getResourceAsStream("/retrocompatibility/v1.1/crac-for-rao-result-v1.1.json"); - Crac crac = new JsonImport().importCrac(cracFile, mockNetworkWithLines("ne1Id", "ne2Id", "ne3Id")); - RaoResult raoResult = new RaoResultImporter().importRaoResult(raoResultFile, crac); + Crac crac = Crac.read(cracFile, mockNetworkWithLines("ne1Id", "ne2Id", "ne3Id")); + RaoResult raoResult = new RaoResultJsonImporter().importData(raoResultFile, crac); testBaseContentOfV1RaoResult(raoResult, crac); testExtraContentOfV1Point1RaoResult(raoResult, crac); } @Test - void importAfterV1Point1FieldDeprecationTest() { + void importAfterV1Point1FieldDeprecationTest() throws IOException { // unused field should throw an exception InputStream raoResultFile = getClass().getResourceAsStream("/retrocompatibility/v1.1/rao-result-v1.2-error.json"); InputStream cracFile = getClass().getResourceAsStream("/retrocompatibility/v1.1/crac-for-rao-result-v1.1.json"); - Crac crac = new JsonImport().importCrac(cracFile, mockNetworkWithLines("ne1Id", "ne2Id", "ne3Id")); - RaoResultImporter importer = new RaoResultImporter(); - OpenRaoException exception = assertThrows(OpenRaoException.class, () -> importer.importRaoResult(raoResultFile, crac)); + Crac crac = Crac.read(cracFile, mockNetworkWithLines("ne1Id", "ne2Id", "ne3Id")); + RaoResultJsonImporter importer = new RaoResultJsonImporter(); + OpenRaoException exception = assertThrows(OpenRaoException.class, () -> importer.importData(raoResultFile, crac)); assertEquals("Cannot deserialize RaoResult: field flow in flowCnecResults in not supported in file version 1.2 (last supported in version 1.1)", exception.getMessage()); } @Test - void importV1Point2Test() { + void importV1Point2Test() throws IOException { InputStream raoResultFile = getClass().getResourceAsStream("/retrocompatibility/v1.2/rao-result-v1.2.json"); InputStream cracFile = getClass().getResourceAsStream("/retrocompatibility/v1.2/crac-for-rao-result-v1.2.json"); - Crac crac = new JsonImport().importCrac(cracFile, mockNetworkWithLines("ne1Id", "ne2Id", "ne3Id")); - RaoResult raoResult = new RaoResultImporter().importRaoResult(raoResultFile, crac); + Crac crac = Crac.read(cracFile, mockNetworkWithLines("ne1Id", "ne2Id", "ne3Id")); + RaoResult raoResult = new RaoResultJsonImporter().importData(raoResultFile, crac); testBaseContentOfV1Point2RaoResult(raoResult, crac); } @Test - void importV1Point2FieldDeprecationTest() { + void importV1Point2FieldDeprecationTest() throws IOException { // RaoResult copied from v1.1 but version set to v1.2 // Should not be imported because CNEC side is not defined properly InputStream raoResultFile = getClass().getResourceAsStream("/retrocompatibility/v1.2/rao-result-v1.2-error.json"); InputStream cracFile = getClass().getResourceAsStream("/retrocompatibility/v1.2/crac-for-rao-result-v1.2.json"); - Crac crac = new JsonImport().importCrac(cracFile, mockNetworkWithLines("ne1Id", "ne2Id", "ne3Id")); - RaoResultImporter importer = new RaoResultImporter(); - OpenRaoException exception = assertThrows(OpenRaoException.class, () -> importer.importRaoResult(raoResultFile, crac)); + Crac crac = Crac.read(cracFile, mockNetworkWithLines("ne1Id", "ne2Id", "ne3Id")); + RaoResultJsonImporter importer = new RaoResultJsonImporter(); + OpenRaoException exception = assertThrows(OpenRaoException.class, () -> importer.importData(raoResultFile, crac)); assertEquals("Cannot deserialize RaoResult: field flow in flowCnecResults in not supported in file version 1.2 (last supported in version 1.1)", exception.getMessage()); } @Test - void importV1Point3Test() { + void importV1Point3Test() throws IOException { InputStream raoResultFile = getClass().getResourceAsStream("/retrocompatibility/v1.3/rao-result-v1.3.json"); InputStream cracFile = getClass().getResourceAsStream("/retrocompatibility/v1.3/crac-for-rao-result-v1.3.json"); - Crac crac = new JsonImport().importCrac(cracFile, mockNetworkWithLines("ne1Id", "ne2Id", "ne3Id")); - RaoResult raoResult = new RaoResultImporter().importRaoResult(raoResultFile, crac); + Crac crac = Crac.read(cracFile, mockNetworkWithLines("ne1Id", "ne2Id", "ne3Id")); + RaoResult raoResult = new RaoResultJsonImporter().importData(raoResultFile, crac); testBaseContentOfV1Point3RaoResult(raoResult, crac); } @Test - void importV1Point4Test() { + void importV1Point4Test() throws IOException { InputStream raoResultFile = getClass().getResourceAsStream("/retrocompatibility/v1.4/rao-result-v1.4.json"); InputStream cracFile = getClass().getResourceAsStream("/retrocompatibility/v1.4/crac-for-rao-result-v1.4.json"); - Crac crac = new JsonImport().importCrac(cracFile, mockNetworkWithLines("ne1Id", "ne2Id", "ne3Id")); - RaoResult raoResult = new RaoResultImporter().importRaoResult(raoResultFile, crac); + Crac crac = Crac.read(cracFile, mockNetworkWithLines("ne1Id", "ne2Id", "ne3Id")); + RaoResult raoResult = new RaoResultJsonImporter().importData(raoResultFile, crac); testBaseContentOfV1Point3RaoResult(raoResult, crac); } @Test - void importV1Point3TestFieldDeprecationTest() { + void importV1Point3TestFieldDeprecationTest() throws IOException { InputStream cracFile = getClass().getResourceAsStream("/retrocompatibility/v1.3/crac-for-rao-result-v1.3.json"); - Crac crac = new JsonImport().importCrac(cracFile, mockNetworkWithLines("ne1Id", "ne2Id", "ne3Id")); - RaoResultImporter importer = new RaoResultImporter(); + Crac crac = Crac.read(cracFile, mockNetworkWithLines("ne1Id", "ne2Id", "ne3Id")); + RaoResultJsonImporter importer = new RaoResultJsonImporter(); InputStream raoResultFile = getClass().getResourceAsStream("/retrocompatibility/v1.3/rao-result-v1.3-error1.json"); - OpenRaoException exception = assertThrows(OpenRaoException.class, () -> importer.importRaoResult(raoResultFile, crac)); + OpenRaoException exception = assertThrows(OpenRaoException.class, () -> importer.importData(raoResultFile, crac)); assertEquals("Cannot deserialize RaoResult: field pstRangeActionId in RAO_RESULT in not supported in file version 1.3 (last supported in version 1.2)", exception.getMessage()); InputStream raoResultFile2 = getClass().getResourceAsStream("/retrocompatibility/v1.3/rao-result-v1.3-error2.json"); - exception = assertThrows(OpenRaoException.class, () -> importer.importRaoResult(raoResultFile2, crac)); + exception = assertThrows(OpenRaoException.class, () -> importer.importData(raoResultFile2, crac)); assertEquals("Cannot deserialize RaoResult: field afterPraTap in rangeActionResults in not supported in file version 1.3 (last supported in version 1.2)", exception.getMessage()); } diff --git a/data/rao-result/rao-result-json/src/test/java/com/powsybl/openrao/data/raoresultjson/RaoResultRoundTripTest.java b/data/rao-result/rao-result-json/src/test/java/com/powsybl/openrao/data/raoresultjson/RaoResultRoundTripTest.java index b077e2b844..06303780c9 100644 --- a/data/rao-result/rao-result-json/src/test/java/com/powsybl/openrao/data/raoresultjson/RaoResultRoundTripTest.java +++ b/data/rao-result/rao-result-json/src/test/java/com/powsybl/openrao/data/raoresultjson/RaoResultRoundTripTest.java @@ -20,7 +20,6 @@ import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.usagerule.UsageMethod; import com.powsybl.openrao.data.cracimpl.utils.ExhaustiveCracCreation; -import com.powsybl.openrao.data.craciojson.JsonExport; import com.powsybl.openrao.data.raoresultapi.ComputationStatus; import com.powsybl.openrao.data.raoresultapi.RaoResult; import com.powsybl.openrao.data.raoresultimpl.RaoResultImpl; @@ -29,6 +28,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.util.Collections; import java.util.Map; import java.util.Set; @@ -51,65 +51,87 @@ class RaoResultRoundTripTest { private static final String CURATIVE_INSTANT_ID = "curative"; @Test - void roundTripTest() { + void explicitJsonRoundTripTest() { // get exhaustive CRAC and RaoResult Crac crac = ExhaustiveCracCreation.create(); - Instant preventiveInstant = crac.getInstant(PREVENTIVE_INSTANT_ID); - Instant outageInstant = crac.getInstant(OUTAGE_INSTANT_ID); - Instant autoInstant = crac.getInstant(AUTO_INSTANT_ID); - Instant curativeInstant = crac.getInstant(CURATIVE_INSTANT_ID); + RaoResult raoResult = ExhaustiveRaoResultCreation.create(crac); + + // export RaoResult + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + new RaoResultJsonExporter().exportData(raoResult, crac, Set.of(MEGAWATT, AMPERE), outputStream); + + ByteArrayOutputStream outputStream2 = new ByteArrayOutputStream(); + crac.write("JSON", outputStream2); + + // import RaoResult + ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); + RaoResult importedRaoResult = new RaoResultJsonImporter().importData(inputStream, crac); + checkContent(importedRaoResult, crac); + } + @Test + void implicitJsonRoundTripTest() throws IOException { + // get exhaustive CRAC and RaoResult + Crac crac = ExhaustiveCracCreation.create(); RaoResult raoResult = ExhaustiveRaoResultCreation.create(crac); // export RaoResult ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - new RaoResultExporter().export(raoResult, crac, Set.of(MEGAWATT, AMPERE), outputStream); + raoResult.write("JSON", crac, Set.of(MEGAWATT, AMPERE), outputStream); ByteArrayOutputStream outputStream2 = new ByteArrayOutputStream(); - new JsonExport().exportCrac(crac, outputStream2); + crac.write("JSON", outputStream2); // import RaoResult ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); - RaoResult importedRaoResult = new RaoResultImporter().importRaoResult(inputStream, crac); + RaoResult importedRaoResult = RaoResult.read(inputStream, crac); + checkContent(importedRaoResult, crac); + } + + private void checkContent(RaoResult raoResult, Crac crac) { + Instant preventiveInstant = crac.getInstant(PREVENTIVE_INSTANT_ID); + Instant outageInstant = crac.getInstant(OUTAGE_INSTANT_ID); + Instant autoInstant = crac.getInstant(AUTO_INSTANT_ID); + Instant curativeInstant = crac.getInstant(CURATIVE_INSTANT_ID); // -------------------------- // --- Computation status --- // -------------------------- - assertEquals(ComputationStatus.DEFAULT, importedRaoResult.getComputationStatus()); + assertEquals(ComputationStatus.DEFAULT, raoResult.getComputationStatus()); assertEquals(ComputationStatus.DEFAULT, raoResult.getComputationStatus(crac.getPreventiveState())); - assertEquals(ComputationStatus.DEFAULT, importedRaoResult.getComputationStatus(crac.getState("contingency1Id", outageInstant))); - assertEquals(ComputationStatus.DEFAULT, importedRaoResult.getComputationStatus(crac.getState("contingency1Id", curativeInstant))); - assertEquals(ComputationStatus.DEFAULT, importedRaoResult.getComputationStatus(crac.getState("contingency2Id", autoInstant))); - assertEquals(ComputationStatus.DEFAULT, importedRaoResult.getComputationStatus(crac.getState("contingency2Id", curativeInstant))); + assertEquals(ComputationStatus.DEFAULT, raoResult.getComputationStatus(crac.getState("contingency1Id", outageInstant))); + assertEquals(ComputationStatus.DEFAULT, raoResult.getComputationStatus(crac.getState("contingency1Id", curativeInstant))); + assertEquals(ComputationStatus.DEFAULT, raoResult.getComputationStatus(crac.getState("contingency2Id", autoInstant))); + assertEquals(ComputationStatus.DEFAULT, raoResult.getComputationStatus(crac.getState("contingency2Id", curativeInstant))); // -------------------------- // --- test Costs results --- // -------------------------- - assertEquals(Set.of("loopFlow", "MNEC"), importedRaoResult.getVirtualCostNames()); - - assertEquals(100., importedRaoResult.getFunctionalCost(null), DOUBLE_TOLERANCE); - assertEquals(0., importedRaoResult.getVirtualCost(null, "loopFlow"), DOUBLE_TOLERANCE); - assertEquals(0., importedRaoResult.getVirtualCost(null, "MNEC"), DOUBLE_TOLERANCE); - assertEquals(0., importedRaoResult.getVirtualCost(null), DOUBLE_TOLERANCE); - assertEquals(100., importedRaoResult.getCost(null), DOUBLE_TOLERANCE); - - assertEquals(80., importedRaoResult.getFunctionalCost(preventiveInstant), DOUBLE_TOLERANCE); - assertEquals(0., importedRaoResult.getVirtualCost(preventiveInstant, "loopFlow"), DOUBLE_TOLERANCE); - assertEquals(0., importedRaoResult.getVirtualCost(preventiveInstant, "MNEC"), DOUBLE_TOLERANCE); - assertEquals(0., importedRaoResult.getVirtualCost(preventiveInstant), DOUBLE_TOLERANCE); - assertEquals(80., importedRaoResult.getCost(preventiveInstant), DOUBLE_TOLERANCE); - - assertEquals(-20., importedRaoResult.getFunctionalCost(autoInstant), DOUBLE_TOLERANCE); - assertEquals(15., importedRaoResult.getVirtualCost(autoInstant, "loopFlow"), DOUBLE_TOLERANCE); - assertEquals(20., importedRaoResult.getVirtualCost(autoInstant, "MNEC"), DOUBLE_TOLERANCE); - assertEquals(35., importedRaoResult.getVirtualCost(autoInstant), DOUBLE_TOLERANCE); - assertEquals(15., importedRaoResult.getCost(autoInstant), DOUBLE_TOLERANCE); - - assertEquals(-50., importedRaoResult.getFunctionalCost(curativeInstant), DOUBLE_TOLERANCE); - assertEquals(10., importedRaoResult.getVirtualCost(curativeInstant, "loopFlow"), DOUBLE_TOLERANCE); - assertEquals(2., importedRaoResult.getVirtualCost(curativeInstant, "MNEC"), DOUBLE_TOLERANCE); - assertEquals(12., importedRaoResult.getVirtualCost(curativeInstant), DOUBLE_TOLERANCE); - assertEquals(-38, importedRaoResult.getCost(curativeInstant), DOUBLE_TOLERANCE); + assertEquals(Set.of("loopFlow", "MNEC"), raoResult.getVirtualCostNames()); + + assertEquals(100., raoResult.getFunctionalCost(null), DOUBLE_TOLERANCE); + assertEquals(0., raoResult.getVirtualCost(null, "loopFlow"), DOUBLE_TOLERANCE); + assertEquals(0., raoResult.getVirtualCost(null, "MNEC"), DOUBLE_TOLERANCE); + assertEquals(0., raoResult.getVirtualCost(null), DOUBLE_TOLERANCE); + assertEquals(100., raoResult.getCost(null), DOUBLE_TOLERANCE); + + assertEquals(80., raoResult.getFunctionalCost(preventiveInstant), DOUBLE_TOLERANCE); + assertEquals(0., raoResult.getVirtualCost(preventiveInstant, "loopFlow"), DOUBLE_TOLERANCE); + assertEquals(0., raoResult.getVirtualCost(preventiveInstant, "MNEC"), DOUBLE_TOLERANCE); + assertEquals(0., raoResult.getVirtualCost(preventiveInstant), DOUBLE_TOLERANCE); + assertEquals(80., raoResult.getCost(preventiveInstant), DOUBLE_TOLERANCE); + + assertEquals(-20., raoResult.getFunctionalCost(autoInstant), DOUBLE_TOLERANCE); + assertEquals(15., raoResult.getVirtualCost(autoInstant, "loopFlow"), DOUBLE_TOLERANCE); + assertEquals(20., raoResult.getVirtualCost(autoInstant, "MNEC"), DOUBLE_TOLERANCE); + assertEquals(35., raoResult.getVirtualCost(autoInstant), DOUBLE_TOLERANCE); + assertEquals(15., raoResult.getCost(autoInstant), DOUBLE_TOLERANCE); + + assertEquals(-50., raoResult.getFunctionalCost(curativeInstant), DOUBLE_TOLERANCE); + assertEquals(10., raoResult.getVirtualCost(curativeInstant, "loopFlow"), DOUBLE_TOLERANCE); + assertEquals(2., raoResult.getVirtualCost(curativeInstant, "MNEC"), DOUBLE_TOLERANCE); + assertEquals(12., raoResult.getVirtualCost(curativeInstant), DOUBLE_TOLERANCE); + assertEquals(-38, raoResult.getCost(curativeInstant), DOUBLE_TOLERANCE); // ----------------------------- // --- test FlowCnec results --- @@ -121,31 +143,31 @@ void roundTripTest() { - contains result relative margin and PTDF sum but not for loop and commercial flows */ FlowCnec cnecP = crac.getFlowCnec("cnec4prevId"); - assertEquals(4110., importedRaoResult.getFlow(null, cnecP, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(importedRaoResult.getFlow(null, cnecP, Side.RIGHT, MEGAWATT))); - assertEquals(4111., importedRaoResult.getMargin(null, cnecP, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(4112., importedRaoResult.getRelativeMargin(null, cnecP, MEGAWATT), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecP, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecP, Side.RIGHT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecP, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecP, Side.RIGHT, MEGAWATT))); - - assertEquals(4220., importedRaoResult.getFlow(preventiveInstant, cnecP, Side.LEFT, AMPERE), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(importedRaoResult.getFlow(preventiveInstant, cnecP, Side.RIGHT, AMPERE))); - assertEquals(4221., importedRaoResult.getMargin(preventiveInstant, cnecP, AMPERE), DOUBLE_TOLERANCE); - assertEquals(4222., importedRaoResult.getRelativeMargin(preventiveInstant, cnecP, AMPERE), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecP, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecP, Side.RIGHT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecP, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecP, Side.RIGHT, MEGAWATT))); - - assertEquals(0.4, importedRaoResult.getPtdfZonalSum(preventiveInstant, cnecP, Side.LEFT), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(importedRaoResult.getPtdfZonalSum(preventiveInstant, cnecP, Side.RIGHT))); - - assertEquals(importedRaoResult.getFlow(autoInstant, cnecP, LEFT, AMPERE), importedRaoResult.getFlow(preventiveInstant, cnecP, LEFT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(importedRaoResult.getFlow(autoInstant, cnecP, RIGHT, AMPERE), importedRaoResult.getFlow(preventiveInstant, cnecP, RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(importedRaoResult.getFlow(curativeInstant, cnecP, LEFT, AMPERE), importedRaoResult.getFlow(preventiveInstant, cnecP, LEFT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(importedRaoResult.getFlow(curativeInstant, cnecP, RIGHT, AMPERE), importedRaoResult.getFlow(preventiveInstant, cnecP, RIGHT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(4110., raoResult.getFlow(null, cnecP, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getFlow(null, cnecP, Side.RIGHT, MEGAWATT))); + assertEquals(4111., raoResult.getMargin(null, cnecP, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(4112., raoResult.getRelativeMargin(null, cnecP, MEGAWATT), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getLoopFlow(null, cnecP, Side.LEFT, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getLoopFlow(null, cnecP, Side.RIGHT, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getCommercialFlow(null, cnecP, Side.LEFT, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getCommercialFlow(null, cnecP, Side.RIGHT, MEGAWATT))); + + assertEquals(4220., raoResult.getFlow(preventiveInstant, cnecP, Side.LEFT, AMPERE), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getFlow(preventiveInstant, cnecP, Side.RIGHT, AMPERE))); + assertEquals(4221., raoResult.getMargin(preventiveInstant, cnecP, AMPERE), DOUBLE_TOLERANCE); + assertEquals(4222., raoResult.getRelativeMargin(preventiveInstant, cnecP, AMPERE), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getLoopFlow(null, cnecP, Side.LEFT, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getLoopFlow(null, cnecP, Side.RIGHT, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getCommercialFlow(null, cnecP, Side.LEFT, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getCommercialFlow(null, cnecP, Side.RIGHT, MEGAWATT))); + + assertEquals(0.4, raoResult.getPtdfZonalSum(preventiveInstant, cnecP, Side.LEFT), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getPtdfZonalSum(preventiveInstant, cnecP, Side.RIGHT))); + + assertEquals(raoResult.getFlow(autoInstant, cnecP, LEFT, AMPERE), raoResult.getFlow(preventiveInstant, cnecP, LEFT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(raoResult.getFlow(autoInstant, cnecP, RIGHT, AMPERE), raoResult.getFlow(preventiveInstant, cnecP, RIGHT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(raoResult.getFlow(curativeInstant, cnecP, LEFT, AMPERE), raoResult.getFlow(preventiveInstant, cnecP, LEFT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(raoResult.getFlow(curativeInstant, cnecP, RIGHT, AMPERE), raoResult.getFlow(preventiveInstant, cnecP, RIGHT, AMPERE), DOUBLE_TOLERANCE); /* cnec1outageId: outage, with loop-flows, optimized @@ -154,31 +176,31 @@ void roundTripTest() { */ FlowCnec cnecO = crac.getFlowCnec("cnec1outageId"); - assertTrue(Double.isNaN(importedRaoResult.getFlow(null, cnecO, Side.LEFT, AMPERE))); - assertEquals(1120.5, importedRaoResult.getFlow(null, cnecO, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(1121., importedRaoResult.getMargin(null, cnecO, AMPERE), DOUBLE_TOLERANCE); - assertEquals(1122., importedRaoResult.getRelativeMargin(null, cnecO, AMPERE), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecO, Side.LEFT, AMPERE))); - assertEquals(1123.5, importedRaoResult.getLoopFlow(null, cnecO, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecO, Side.LEFT, AMPERE))); - assertEquals(1124.5, importedRaoResult.getCommercialFlow(null, cnecO, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); - - assertTrue(Double.isNaN(importedRaoResult.getFlow(preventiveInstant, cnecO, Side.LEFT, MEGAWATT))); - assertEquals(1210.5, importedRaoResult.getFlow(preventiveInstant, cnecO, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(1211., importedRaoResult.getMargin(preventiveInstant, cnecO, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(1212., importedRaoResult.getRelativeMargin(preventiveInstant, cnecO, MEGAWATT), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(preventiveInstant, cnecO, Side.LEFT, MEGAWATT))); - assertEquals(1213.5, importedRaoResult.getLoopFlow(preventiveInstant, cnecO, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(preventiveInstant, cnecO, Side.LEFT, MEGAWATT))); - assertEquals(1214.5, importedRaoResult.getCommercialFlow(preventiveInstant, cnecO, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); - - assertTrue(Double.isNaN(importedRaoResult.getPtdfZonalSum(preventiveInstant, cnecO, Side.LEFT))); - assertEquals(0.6, importedRaoResult.getPtdfZonalSum(preventiveInstant, cnecO, Side.RIGHT), DOUBLE_TOLERANCE); - - assertTrue(Double.isNaN(importedRaoResult.getFlow(autoInstant, cnecO, Side.LEFT, MEGAWATT))); - assertEquals(importedRaoResult.getFlow(autoInstant, cnecO, RIGHT, MEGAWATT), importedRaoResult.getFlow(preventiveInstant, cnecO, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(importedRaoResult.getFlow(curativeInstant, cnecO, Side.LEFT, MEGAWATT))); - assertEquals(importedRaoResult.getFlow(curativeInstant, cnecO, RIGHT, MEGAWATT), importedRaoResult.getFlow(preventiveInstant, cnecO, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getFlow(null, cnecO, Side.LEFT, AMPERE))); + assertEquals(1120.5, raoResult.getFlow(null, cnecO, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(1121., raoResult.getMargin(null, cnecO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(1122., raoResult.getRelativeMargin(null, cnecO, AMPERE), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getLoopFlow(null, cnecO, Side.LEFT, AMPERE))); + assertEquals(1123.5, raoResult.getLoopFlow(null, cnecO, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getCommercialFlow(null, cnecO, Side.LEFT, AMPERE))); + assertEquals(1124.5, raoResult.getCommercialFlow(null, cnecO, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); + + assertTrue(Double.isNaN(raoResult.getFlow(preventiveInstant, cnecO, Side.LEFT, MEGAWATT))); + assertEquals(1210.5, raoResult.getFlow(preventiveInstant, cnecO, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(1211., raoResult.getMargin(preventiveInstant, cnecO, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(1212., raoResult.getRelativeMargin(preventiveInstant, cnecO, MEGAWATT), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getLoopFlow(preventiveInstant, cnecO, Side.LEFT, MEGAWATT))); + assertEquals(1213.5, raoResult.getLoopFlow(preventiveInstant, cnecO, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getCommercialFlow(preventiveInstant, cnecO, Side.LEFT, MEGAWATT))); + assertEquals(1214.5, raoResult.getCommercialFlow(preventiveInstant, cnecO, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + + assertTrue(Double.isNaN(raoResult.getPtdfZonalSum(preventiveInstant, cnecO, Side.LEFT))); + assertEquals(0.6, raoResult.getPtdfZonalSum(preventiveInstant, cnecO, Side.RIGHT), DOUBLE_TOLERANCE); + + assertTrue(Double.isNaN(raoResult.getFlow(autoInstant, cnecO, Side.LEFT, MEGAWATT))); + assertEquals(raoResult.getFlow(autoInstant, cnecO, RIGHT, MEGAWATT), raoResult.getFlow(preventiveInstant, cnecO, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getFlow(curativeInstant, cnecO, Side.LEFT, MEGAWATT))); + assertEquals(raoResult.getFlow(curativeInstant, cnecO, RIGHT, MEGAWATT), raoResult.getFlow(preventiveInstant, cnecO, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); /* cnec3autoId: auto, without loop-flows, pureMNEC @@ -187,27 +209,27 @@ void roundTripTest() { */ FlowCnec cnecA = crac.getFlowCnec("cnec3autoId"); - assertEquals(3110., importedRaoResult.getFlow(null, cnecA, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(3110.5, importedRaoResult.getFlow(null, cnecA, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(3111., importedRaoResult.getMargin(null, cnecA, MEGAWATT), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(importedRaoResult.getRelativeMargin(null, cnecA, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecA, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecA, Side.RIGHT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecA, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecA, Side.RIGHT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getPtdfZonalSum(null, cnecA, Side.LEFT))); - assertTrue(Double.isNaN(importedRaoResult.getPtdfZonalSum(null, cnecA, Side.RIGHT))); - - assertEquals(3220., importedRaoResult.getFlow(preventiveInstant, cnecA, Side.LEFT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(3220.5, importedRaoResult.getFlow(preventiveInstant, cnecA, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(3221., importedRaoResult.getMargin(preventiveInstant, cnecA, AMPERE), DOUBLE_TOLERANCE); - - assertEquals(3310., importedRaoResult.getFlow(autoInstant, cnecA, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(3310.5, importedRaoResult.getFlow(autoInstant, cnecA, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(3311., importedRaoResult.getMargin(autoInstant, cnecA, MEGAWATT), DOUBLE_TOLERANCE); - - assertEquals(importedRaoResult.getFlow(curativeInstant, cnecA, LEFT, MEGAWATT), importedRaoResult.getFlow(autoInstant, cnecA, LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(importedRaoResult.getFlow(curativeInstant, cnecA, RIGHT, MEGAWATT), importedRaoResult.getFlow(autoInstant, cnecA, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3110., raoResult.getFlow(null, cnecA, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3110.5, raoResult.getFlow(null, cnecA, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3111., raoResult.getMargin(null, cnecA, MEGAWATT), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getRelativeMargin(null, cnecA, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getLoopFlow(null, cnecA, Side.LEFT, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getLoopFlow(null, cnecA, Side.RIGHT, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getCommercialFlow(null, cnecA, Side.LEFT, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getCommercialFlow(null, cnecA, Side.RIGHT, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getPtdfZonalSum(null, cnecA, Side.LEFT))); + assertTrue(Double.isNaN(raoResult.getPtdfZonalSum(null, cnecA, Side.RIGHT))); + + assertEquals(3220., raoResult.getFlow(preventiveInstant, cnecA, Side.LEFT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(3220.5, raoResult.getFlow(preventiveInstant, cnecA, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(3221., raoResult.getMargin(preventiveInstant, cnecA, AMPERE), DOUBLE_TOLERANCE); + + assertEquals(3310., raoResult.getFlow(autoInstant, cnecA, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3310.5, raoResult.getFlow(autoInstant, cnecA, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3311., raoResult.getMargin(autoInstant, cnecA, MEGAWATT), DOUBLE_TOLERANCE); + + assertEquals(raoResult.getFlow(curativeInstant, cnecA, LEFT, MEGAWATT), raoResult.getFlow(autoInstant, cnecA, LEFT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(raoResult.getFlow(curativeInstant, cnecA, RIGHT, MEGAWATT), raoResult.getFlow(autoInstant, cnecA, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); /* cnec3curId: curative, without loop-flows, pureMNEC @@ -216,28 +238,28 @@ void roundTripTest() { */ FlowCnec cnecC = crac.getFlowCnec("cnec3curId"); - assertEquals(3110., importedRaoResult.getFlow(null, cnecC, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(3110.5, importedRaoResult.getFlow(null, cnecC, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(3111., importedRaoResult.getMargin(null, cnecC, MEGAWATT), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(importedRaoResult.getRelativeMargin(null, cnecC, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecC, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecC, Side.RIGHT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecC, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecC, Side.RIGHT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getPtdfZonalSum(null, cnecC, Side.LEFT))); - assertTrue(Double.isNaN(importedRaoResult.getPtdfZonalSum(null, cnecC, Side.RIGHT))); - - assertEquals(3220., importedRaoResult.getFlow(preventiveInstant, cnecC, Side.LEFT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(3220.5, importedRaoResult.getFlow(preventiveInstant, cnecC, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(3221., importedRaoResult.getMargin(preventiveInstant, cnecC, AMPERE), DOUBLE_TOLERANCE); - - assertEquals(3310., importedRaoResult.getFlow(autoInstant, cnecC, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(3310.5, importedRaoResult.getFlow(autoInstant, cnecC, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(3311., importedRaoResult.getMargin(autoInstant, cnecC, MEGAWATT), DOUBLE_TOLERANCE); - - assertEquals(3410., importedRaoResult.getFlow(curativeInstant, cnecC, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(3410.5, importedRaoResult.getFlow(curativeInstant, cnecC, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(3411., importedRaoResult.getMargin(curativeInstant, cnecC, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3110., raoResult.getFlow(null, cnecC, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3110.5, raoResult.getFlow(null, cnecC, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3111., raoResult.getMargin(null, cnecC, MEGAWATT), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getRelativeMargin(null, cnecC, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getLoopFlow(null, cnecC, Side.LEFT, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getLoopFlow(null, cnecC, Side.RIGHT, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getCommercialFlow(null, cnecC, Side.LEFT, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getCommercialFlow(null, cnecC, Side.RIGHT, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getPtdfZonalSum(null, cnecC, Side.LEFT))); + assertTrue(Double.isNaN(raoResult.getPtdfZonalSum(null, cnecC, Side.RIGHT))); + + assertEquals(3220., raoResult.getFlow(preventiveInstant, cnecC, Side.LEFT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(3220.5, raoResult.getFlow(preventiveInstant, cnecC, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(3221., raoResult.getMargin(preventiveInstant, cnecC, AMPERE), DOUBLE_TOLERANCE); + + assertEquals(3310., raoResult.getFlow(autoInstant, cnecC, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3310.5, raoResult.getFlow(autoInstant, cnecC, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3311., raoResult.getMargin(autoInstant, cnecC, MEGAWATT), DOUBLE_TOLERANCE); + + assertEquals(3410., raoResult.getFlow(curativeInstant, cnecC, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3410.5, raoResult.getFlow(curativeInstant, cnecC, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3411., raoResult.getMargin(curativeInstant, cnecC, MEGAWATT), DOUBLE_TOLERANCE); // ----------------------------- // --- NetworkAction results --- @@ -253,53 +275,53 @@ void roundTripTest() { complexNetworkActionId, activated in preventive */ NetworkAction naP = crac.getNetworkAction("complexNetworkActionId"); - assertTrue(importedRaoResult.isActivatedDuringState(pState, naP)); - assertTrue(importedRaoResult.isActivated(pState, naP)); - assertFalse(importedRaoResult.isActivatedDuringState(oState2, naP)); - assertFalse(importedRaoResult.isActivatedDuringState(aState2, naP)); - assertFalse(importedRaoResult.isActivatedDuringState(cState1, naP)); - assertFalse(importedRaoResult.isActivatedDuringState(cState2, naP)); - assertTrue(importedRaoResult.isActivated(cState1, naP)); - assertTrue(importedRaoResult.isActivated(cState2, naP)); + assertTrue(raoResult.isActivatedDuringState(pState, naP)); + assertTrue(raoResult.isActivated(pState, naP)); + assertFalse(raoResult.isActivatedDuringState(oState2, naP)); + assertFalse(raoResult.isActivatedDuringState(aState2, naP)); + assertFalse(raoResult.isActivatedDuringState(cState1, naP)); + assertFalse(raoResult.isActivatedDuringState(cState2, naP)); + assertTrue(raoResult.isActivated(cState1, naP)); + assertTrue(raoResult.isActivated(cState2, naP)); /* injectionSetpointRaId, activated in auto */ NetworkAction naA = crac.getNetworkAction("injectionSetpointRaId"); - assertFalse(importedRaoResult.isActivatedDuringState(pState, naA)); - assertFalse(importedRaoResult.isActivated(pState, naA)); - assertFalse(importedRaoResult.isActivatedDuringState(oState2, naA)); - assertTrue(importedRaoResult.isActivatedDuringState(aState2, naA)); - assertFalse(importedRaoResult.isActivatedDuringState(cState1, naA)); - assertFalse(importedRaoResult.isActivatedDuringState(cState2, naA)); - assertFalse(importedRaoResult.isActivated(cState1, naA)); - assertTrue(importedRaoResult.isActivated(cState2, naA)); + assertFalse(raoResult.isActivatedDuringState(pState, naA)); + assertFalse(raoResult.isActivated(pState, naA)); + assertFalse(raoResult.isActivatedDuringState(oState2, naA)); + assertTrue(raoResult.isActivatedDuringState(aState2, naA)); + assertFalse(raoResult.isActivatedDuringState(cState1, naA)); + assertFalse(raoResult.isActivatedDuringState(cState2, naA)); + assertFalse(raoResult.isActivated(cState1, naA)); + assertTrue(raoResult.isActivated(cState2, naA)); /* pstSetpointRaId, activated curative1 */ NetworkAction naC = crac.getNetworkAction("pstSetpointRaId"); - assertFalse(importedRaoResult.isActivatedDuringState(pState, naC)); - assertFalse(importedRaoResult.isActivated(pState, naC)); - assertFalse(importedRaoResult.isActivatedDuringState(oState2, naC)); - assertFalse(importedRaoResult.isActivatedDuringState(aState2, naC)); - assertTrue(importedRaoResult.isActivatedDuringState(cState1, naC)); - assertFalse(importedRaoResult.isActivatedDuringState(cState2, naC)); - assertTrue(importedRaoResult.isActivated(cState1, naC)); - assertFalse(importedRaoResult.isActivated(cState2, naC)); + assertFalse(raoResult.isActivatedDuringState(pState, naC)); + assertFalse(raoResult.isActivated(pState, naC)); + assertFalse(raoResult.isActivatedDuringState(oState2, naC)); + assertFalse(raoResult.isActivatedDuringState(aState2, naC)); + assertTrue(raoResult.isActivatedDuringState(cState1, naC)); + assertFalse(raoResult.isActivatedDuringState(cState2, naC)); + assertTrue(raoResult.isActivated(cState1, naC)); + assertFalse(raoResult.isActivated(cState2, naC)); /* switchPairRaId, never activated */ NetworkAction naN = crac.getNetworkAction("switchPairRaId"); - assertFalse(importedRaoResult.isActivatedDuringState(pState, naN)); - assertFalse(importedRaoResult.isActivated(pState, naN)); - assertFalse(importedRaoResult.isActivatedDuringState(oState2, naN)); - assertFalse(importedRaoResult.isActivatedDuringState(aState2, naN)); - assertFalse(importedRaoResult.isActivatedDuringState(cState1, naN)); - assertFalse(importedRaoResult.isActivatedDuringState(cState2, naN)); - assertFalse(importedRaoResult.isActivated(cState1, naN)); - assertFalse(importedRaoResult.isActivated(cState2, naN)); + assertFalse(raoResult.isActivatedDuringState(pState, naN)); + assertFalse(raoResult.isActivated(pState, naN)); + assertFalse(raoResult.isActivatedDuringState(oState2, naN)); + assertFalse(raoResult.isActivatedDuringState(aState2, naN)); + assertFalse(raoResult.isActivatedDuringState(cState1, naN)); + assertFalse(raoResult.isActivatedDuringState(cState2, naN)); + assertFalse(raoResult.isActivated(cState1, naN)); + assertFalse(raoResult.isActivated(cState2, naN)); // ------------------------------ // --- PstRangeAction results --- @@ -309,29 +331,29 @@ void roundTripTest() { pstRange1Id, activated in preventive */ PstRangeAction pstP = crac.getPstRangeAction("pstRange1Id"); - assertTrue(importedRaoResult.isActivatedDuringState(pState, pstP)); - assertFalse(importedRaoResult.isActivatedDuringState(cState1, pstP)); - assertFalse(importedRaoResult.isActivatedDuringState(cState2, pstP)); - assertEquals(-3, importedRaoResult.getPreOptimizationTapOnState(pState, pstP)); - assertEquals(0., importedRaoResult.getPreOptimizationSetPointOnState(pState, pstP), DOUBLE_TOLERANCE); - assertEquals(3, importedRaoResult.getOptimizedTapOnState(pState, pstP)); - assertEquals(3., importedRaoResult.getOptimizedSetPointOnState(pState, pstP), DOUBLE_TOLERANCE); - assertEquals(3., importedRaoResult.getPreOptimizationSetPointOnState(cState1, pstP), DOUBLE_TOLERANCE); - assertEquals(3, importedRaoResult.getPreOptimizationTapOnState(cState1, pstP)); - assertEquals(3, importedRaoResult.getOptimizedTapOnState(cState1, pstP)); - assertEquals(3, importedRaoResult.getOptimizedTapOnState(cState2, pstP)); + assertTrue(raoResult.isActivatedDuringState(pState, pstP)); + assertFalse(raoResult.isActivatedDuringState(cState1, pstP)); + assertFalse(raoResult.isActivatedDuringState(cState2, pstP)); + assertEquals(-3, raoResult.getPreOptimizationTapOnState(pState, pstP)); + assertEquals(0., raoResult.getPreOptimizationSetPointOnState(pState, pstP), DOUBLE_TOLERANCE); + assertEquals(3, raoResult.getOptimizedTapOnState(pState, pstP)); + assertEquals(3., raoResult.getOptimizedSetPointOnState(pState, pstP), DOUBLE_TOLERANCE); + assertEquals(3., raoResult.getPreOptimizationSetPointOnState(cState1, pstP), DOUBLE_TOLERANCE); + assertEquals(3, raoResult.getPreOptimizationTapOnState(cState1, pstP)); + assertEquals(3, raoResult.getOptimizedTapOnState(cState1, pstP)); + assertEquals(3, raoResult.getOptimizedTapOnState(cState2, pstP)); /* pstRange2Id, not activated */ PstRangeAction pstN = crac.getPstRangeAction("pstRange2Id"); - assertFalse(importedRaoResult.isActivatedDuringState(pState, pstN)); - assertFalse(importedRaoResult.isActivatedDuringState(cState1, pstN)); - assertFalse(importedRaoResult.isActivatedDuringState(cState2, pstN)); - assertEquals(0, importedRaoResult.getPreOptimizationTapOnState(pState, pstN)); - assertEquals(0, importedRaoResult.getOptimizedTapOnState(pState, pstN)); - assertEquals(0, importedRaoResult.getOptimizedTapOnState(cState1, pstN)); - assertEquals(0, importedRaoResult.getOptimizedTapOnState(cState2, pstN)); + assertFalse(raoResult.isActivatedDuringState(pState, pstN)); + assertFalse(raoResult.isActivatedDuringState(cState1, pstN)); + assertFalse(raoResult.isActivatedDuringState(cState2, pstN)); + assertEquals(0, raoResult.getPreOptimizationTapOnState(pState, pstN)); + assertEquals(0, raoResult.getOptimizedTapOnState(pState, pstN)); + assertEquals(0, raoResult.getOptimizedTapOnState(cState1, pstN)); + assertEquals(0, raoResult.getOptimizedTapOnState(cState2, pstN)); // --------------------------- // --- RangeAction results --- @@ -341,94 +363,132 @@ void roundTripTest() { hvdcRange2Id, two different activations in the two curative states */ HvdcRangeAction hvdcC = crac.getHvdcRangeAction("hvdcRange2Id"); - assertFalse(importedRaoResult.isActivatedDuringState(pState, hvdcC)); - assertTrue(importedRaoResult.isActivatedDuringState(cState1, hvdcC)); - assertTrue(importedRaoResult.isActivatedDuringState(cState2, hvdcC)); - assertEquals(-100, importedRaoResult.getPreOptimizationSetPointOnState(pState, hvdcC), DOUBLE_TOLERANCE); - assertEquals(-100, importedRaoResult.getOptimizedSetPointOnState(pState, hvdcC), DOUBLE_TOLERANCE); - assertEquals(-100, importedRaoResult.getPreOptimizationSetPointOnState(cState1, hvdcC), DOUBLE_TOLERANCE); - assertEquals(100, importedRaoResult.getOptimizedSetPointOnState(cState1, hvdcC), DOUBLE_TOLERANCE); - assertEquals(400, importedRaoResult.getOptimizedSetPointOnState(cState2, hvdcC), DOUBLE_TOLERANCE); + assertFalse(raoResult.isActivatedDuringState(pState, hvdcC)); + assertTrue(raoResult.isActivatedDuringState(cState1, hvdcC)); + assertTrue(raoResult.isActivatedDuringState(cState2, hvdcC)); + assertEquals(-100, raoResult.getPreOptimizationSetPointOnState(pState, hvdcC), DOUBLE_TOLERANCE); + assertEquals(-100, raoResult.getOptimizedSetPointOnState(pState, hvdcC), DOUBLE_TOLERANCE); + assertEquals(-100, raoResult.getPreOptimizationSetPointOnState(cState1, hvdcC), DOUBLE_TOLERANCE); + assertEquals(100, raoResult.getOptimizedSetPointOnState(cState1, hvdcC), DOUBLE_TOLERANCE); + assertEquals(400, raoResult.getOptimizedSetPointOnState(cState2, hvdcC), DOUBLE_TOLERANCE); /* InjectionRange1Id, one activation in curative */ InjectionRangeAction injectionC = crac.getInjectionRangeAction("injectionRange1Id"); - assertFalse(importedRaoResult.isActivatedDuringState(pState, injectionC)); - assertTrue(importedRaoResult.isActivatedDuringState(cState1, injectionC)); - assertFalse(importedRaoResult.isActivatedDuringState(cState2, injectionC)); - assertEquals(100, importedRaoResult.getPreOptimizationSetPointOnState(pState, injectionC), DOUBLE_TOLERANCE); - assertEquals(100, importedRaoResult.getPreOptimizationSetPointOnState(cState1, injectionC), DOUBLE_TOLERANCE); - assertEquals(-300, importedRaoResult.getOptimizedSetPointOnState(cState1, injectionC), DOUBLE_TOLERANCE); + assertFalse(raoResult.isActivatedDuringState(pState, injectionC)); + assertTrue(raoResult.isActivatedDuringState(cState1, injectionC)); + assertFalse(raoResult.isActivatedDuringState(cState2, injectionC)); + assertEquals(100, raoResult.getPreOptimizationSetPointOnState(pState, injectionC), DOUBLE_TOLERANCE); + assertEquals(100, raoResult.getPreOptimizationSetPointOnState(cState1, injectionC), DOUBLE_TOLERANCE); + assertEquals(-300, raoResult.getOptimizedSetPointOnState(cState1, injectionC), DOUBLE_TOLERANCE); /* AngleCnec */ AngleCnec angleCnec = crac.getAngleCnec("angleCnecId"); - assertEquals(3135., importedRaoResult.getAngle(null, angleCnec, DEGREE), DOUBLE_TOLERANCE); - assertEquals(3131., importedRaoResult.getMargin(null, angleCnec, DEGREE), DOUBLE_TOLERANCE); - assertEquals(3235., importedRaoResult.getAngle(preventiveInstant, angleCnec, DEGREE), DOUBLE_TOLERANCE); - assertEquals(3231., importedRaoResult.getMargin(preventiveInstant, angleCnec, DEGREE), DOUBLE_TOLERANCE); - assertEquals(3335., importedRaoResult.getAngle(autoInstant, angleCnec, DEGREE), DOUBLE_TOLERANCE); - assertEquals(3331., importedRaoResult.getMargin(autoInstant, angleCnec, DEGREE), DOUBLE_TOLERANCE); - assertEquals(3435., importedRaoResult.getAngle(curativeInstant, angleCnec, DEGREE), DOUBLE_TOLERANCE); - assertEquals(3431., importedRaoResult.getMargin(curativeInstant, angleCnec, DEGREE), DOUBLE_TOLERANCE); + assertEquals(3135., raoResult.getAngle(null, angleCnec, DEGREE), DOUBLE_TOLERANCE); + assertEquals(3131., raoResult.getMargin(null, angleCnec, DEGREE), DOUBLE_TOLERANCE); + assertEquals(3235., raoResult.getAngle(preventiveInstant, angleCnec, DEGREE), DOUBLE_TOLERANCE); + assertEquals(3231., raoResult.getMargin(preventiveInstant, angleCnec, DEGREE), DOUBLE_TOLERANCE); + assertEquals(3335., raoResult.getAngle(autoInstant, angleCnec, DEGREE), DOUBLE_TOLERANCE); + assertEquals(3331., raoResult.getMargin(autoInstant, angleCnec, DEGREE), DOUBLE_TOLERANCE); + assertEquals(3435., raoResult.getAngle(curativeInstant, angleCnec, DEGREE), DOUBLE_TOLERANCE); + assertEquals(3431., raoResult.getMargin(curativeInstant, angleCnec, DEGREE), DOUBLE_TOLERANCE); /* VoltageCnec */ VoltageCnec voltageCnec = crac.getVoltageCnec("voltageCnecId"); - assertEquals(4146., importedRaoResult.getVoltage(null, voltageCnec, KILOVOLT), DOUBLE_TOLERANCE); - assertEquals(4141., importedRaoResult.getMargin(null, voltageCnec, KILOVOLT), DOUBLE_TOLERANCE); - assertEquals(4246., importedRaoResult.getVoltage(preventiveInstant, voltageCnec, KILOVOLT), DOUBLE_TOLERANCE); - assertEquals(4241., importedRaoResult.getMargin(preventiveInstant, voltageCnec, KILOVOLT), DOUBLE_TOLERANCE); - assertEquals(4346., importedRaoResult.getVoltage(autoInstant, voltageCnec, KILOVOLT), DOUBLE_TOLERANCE); - assertEquals(4341., importedRaoResult.getMargin(autoInstant, voltageCnec, KILOVOLT), DOUBLE_TOLERANCE); - assertEquals(4446., importedRaoResult.getVoltage(curativeInstant, voltageCnec, KILOVOLT), DOUBLE_TOLERANCE); - assertEquals(4441., importedRaoResult.getMargin(curativeInstant, voltageCnec, KILOVOLT), DOUBLE_TOLERANCE); + assertEquals(4146., raoResult.getVoltage(null, voltageCnec, KILOVOLT), DOUBLE_TOLERANCE); + assertEquals(4141., raoResult.getMargin(null, voltageCnec, KILOVOLT), DOUBLE_TOLERANCE); + assertEquals(4246., raoResult.getVoltage(preventiveInstant, voltageCnec, KILOVOLT), DOUBLE_TOLERANCE); + assertEquals(4241., raoResult.getMargin(preventiveInstant, voltageCnec, KILOVOLT), DOUBLE_TOLERANCE); + assertEquals(4346., raoResult.getVoltage(autoInstant, voltageCnec, KILOVOLT), DOUBLE_TOLERANCE); + assertEquals(4341., raoResult.getMargin(autoInstant, voltageCnec, KILOVOLT), DOUBLE_TOLERANCE); + assertEquals(4446., raoResult.getVoltage(curativeInstant, voltageCnec, KILOVOLT), DOUBLE_TOLERANCE); + assertEquals(4441., raoResult.getMargin(curativeInstant, voltageCnec, KILOVOLT), DOUBLE_TOLERANCE); + } + + @Test + void testExplicitRoundTripRangeActionsCrossResults() { + Crac crac = initCrac(); + RaoResult raoResult = initRaoResult(crac); + + // export RaoResult + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + new RaoResultJsonExporter().exportData(raoResult, crac, Set.of(MEGAWATT, AMPERE), outputStream); + + // import RaoResult + ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); + RaoResult importedRaoResult = new RaoResultJsonImporter().importData(inputStream, crac); + + checkContentRangeActionCrossResult(importedRaoResult, crac); } @Test - void testRoundTripRangeActionsCrossResults() { + void testImplicitRoundTripRangeActionsCrossResults() throws IOException { + Crac crac = initCrac(); + RaoResult raoResult = initRaoResult(crac); + + // export RaoResult + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + raoResult.write("JSON", crac, Set.of(MEGAWATT, AMPERE), outputStream); + + // import RaoResult + ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); + RaoResult importedRaoResult = RaoResult.read(inputStream, crac); + + checkContentRangeActionCrossResult(importedRaoResult, crac); + } + + private Crac initCrac() { Crac crac = CracFactory.findDefault().create("crac") .newInstant(PREVENTIVE_INSTANT_ID, InstantKind.PREVENTIVE) .newInstant(OUTAGE_INSTANT_ID, InstantKind.OUTAGE) .newInstant(AUTO_INSTANT_ID, InstantKind.AUTO) .newInstant(CURATIVE_INSTANT_ID, InstantKind.CURATIVE); - Instant outageInstant = crac.getInstant(OUTAGE_INSTANT_ID); - Instant autoInstant = crac.getInstant(AUTO_INSTANT_ID); - Instant curativeInstant = crac.getInstant(CURATIVE_INSTANT_ID); - PstRangeAction pstPrev = crac.newPstRangeAction().withId("pst-prev").withNetworkElement("pst").withInitialTap(-1) - .withTapToAngleConversionMap(Map.of(-1, -10., 0, 0., 1, 10., 2, 20., 3, 30.)) - .withSpeed(1) - .newOnInstantUsageRule().withInstant(PREVENTIVE_INSTANT_ID).withUsageMethod(UsageMethod.AVAILABLE).add() - .add(); - PstRangeAction pstAuto = crac.newPstRangeAction().withId("pst-auto").withNetworkElement("pst").withInitialTap(-1) - .withTapToAngleConversionMap(Map.of(-1, -10., 0, 0., 1, 10., 2, 20., 3, 30.)) - .withSpeed(1) - .newOnInstantUsageRule().withInstant(AUTO_INSTANT_ID).withUsageMethod(UsageMethod.FORCED).add() - .add(); - PstRangeAction pstCur = crac.newPstRangeAction().withId("pst-cur").withNetworkElement("pst").withInitialTap(-1) - .withTapToAngleConversionMap(Map.of(-1, -10., 0, 0., 1, 10., 2, 20., 3, 30.)) - .newOnInstantUsageRule().withInstant(CURATIVE_INSTANT_ID).withUsageMethod(UsageMethod.AVAILABLE).add() - .add(); + crac.newPstRangeAction().withId("pst-prev").withNetworkElement("pst").withInitialTap(-1) + .withTapToAngleConversionMap(Map.of(-1, -10., 0, 0., 1, 10., 2, 20., 3, 30.)) + .withSpeed(1) + .newOnInstantUsageRule().withInstant(PREVENTIVE_INSTANT_ID).withUsageMethod(UsageMethod.AVAILABLE).add() + .add(); + crac.newPstRangeAction().withId("pst-auto").withNetworkElement("pst").withInitialTap(-1) + .withTapToAngleConversionMap(Map.of(-1, -10., 0, 0., 1, 10., 2, 20., 3, 30.)) + .withSpeed(1) + .newOnInstantUsageRule().withInstant(AUTO_INSTANT_ID).withUsageMethod(UsageMethod.FORCED).add() + .add(); + crac.newPstRangeAction().withId("pst-cur").withNetworkElement("pst").withInitialTap(-1) + .withTapToAngleConversionMap(Map.of(-1, -10., 0, 0., 1, 10., 2, 20., 3, 30.)) + .newOnInstantUsageRule().withInstant(CURATIVE_INSTANT_ID).withUsageMethod(UsageMethod.AVAILABLE).add() + .add(); // dummy flow cnecs crac.newContingency().withId("contingency").withContingencyElement("co-ne", ContingencyElementType.LINE).add(); crac.newFlowCnec().withId("dummy-preventive").withInstant(PREVENTIVE_INSTANT_ID).withNetworkElement("ne") - .newThreshold().withMax(1.).withSide(Side.LEFT).withUnit(Unit.MEGAWATT).add() - .add(); + .newThreshold().withMax(1.).withSide(Side.LEFT).withUnit(Unit.MEGAWATT).add() + .add(); crac.newFlowCnec().withId("dummy-outage").withContingency("contingency").withInstant(OUTAGE_INSTANT_ID).withNetworkElement("ne") - .newThreshold().withMax(1.).withSide(Side.LEFT).withUnit(Unit.MEGAWATT).add() - .add(); + .newThreshold().withMax(1.).withSide(Side.LEFT).withUnit(Unit.MEGAWATT).add() + .add(); crac.newFlowCnec().withId("dummy-auto").withContingency("contingency").withInstant(AUTO_INSTANT_ID).withNetworkElement("ne") - .newThreshold().withMax(1.).withSide(Side.LEFT).withUnit(Unit.MEGAWATT).add() - .add(); + .newThreshold().withMax(1.).withSide(Side.LEFT).withUnit(Unit.MEGAWATT).add() + .add(); crac.newFlowCnec().withId("dummy-cur").withContingency("contingency").withInstant(CURATIVE_INSTANT_ID).withNetworkElement("ne") - .newThreshold().withMax(1.).withSide(Side.LEFT).withUnit(Unit.MEGAWATT).add() - .add(); + .newThreshold().withMax(1.).withSide(Side.LEFT).withUnit(Unit.MEGAWATT).add() + .add(); + + return crac; + } + + private RaoResult initRaoResult(Crac crac) { + Instant autoInstant = crac.getInstant(AUTO_INSTANT_ID); + Instant curativeInstant = crac.getInstant(CURATIVE_INSTANT_ID); + + PstRangeAction pstPrev = crac.getPstRangeAction("pst-prev"); + PstRangeAction pstAuto = crac.getPstRangeAction("pst-auto"); + PstRangeAction pstCur = crac.getPstRangeAction("pst-cur"); - State outageState = crac.getState("contingency", outageInstant); State autoState = crac.getState("contingency", autoInstant); State curativeState = crac.getState("contingency", curativeInstant); @@ -441,13 +501,21 @@ void testRoundTripRangeActionsCrossResults() { raoResult.getAndCreateIfAbsentRangeActionResult(pstCur).addActivationForState(curativeState, 30.); raoResult.setComputationStatus(ComputationStatus.DEFAULT); - // export RaoResult - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - new RaoResultExporter().export(raoResult, crac, Set.of(MEGAWATT, AMPERE), outputStream); + return raoResult; + } - // import RaoResult - ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); - RaoResult importedRaoResult = new RaoResultImporter().importRaoResult(inputStream, crac); + private void checkContentRangeActionCrossResult(RaoResult importedRaoResult, Crac crac) { + Instant outageInstant = crac.getInstant(OUTAGE_INSTANT_ID); + Instant autoInstant = crac.getInstant(AUTO_INSTANT_ID); + Instant curativeInstant = crac.getInstant(CURATIVE_INSTANT_ID); + + PstRangeAction pstPrev = crac.getPstRangeAction("pst-prev"); + PstRangeAction pstAuto = crac.getPstRangeAction("pst-auto"); + PstRangeAction pstCur = crac.getPstRangeAction("pst-cur"); + + State outageState = crac.getState("contingency", outageInstant); + State autoState = crac.getState("contingency", autoInstant); + State curativeState = crac.getState("contingency", curativeInstant); // Before & after Preventive state assertEquals(-1, importedRaoResult.getPreOptimizationTapOnState(crac.getPreventiveState(), pstPrev)); @@ -517,60 +585,92 @@ void testFailWithWrongFlowUnits() { RaoResult raoResult = ExhaustiveRaoResultCreation.create(crac); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - RaoResultExporter raoResultExporter = new RaoResultExporter(); + RaoResultJsonExporter raoResultExporter = new RaoResultJsonExporter(); // Empty set Set emptySet = Collections.emptySet(); - Exception exception = assertThrows(OpenRaoException.class, () -> raoResultExporter.export(raoResult, crac, emptySet, outputStream)); + Exception exception = assertThrows(OpenRaoException.class, () -> new RaoResultJsonExporter().exportData(raoResult, crac, emptySet, outputStream)); assertEquals("At least one flow unit should be defined", exception.getMessage()); // "TAP" unit Set tapSingleton = Set.of(TAP); - exception = assertThrows(OpenRaoException.class, () -> raoResultExporter.export(raoResult, crac, tapSingleton, outputStream)); + exception = assertThrows(OpenRaoException.class, () -> new RaoResultJsonExporter().exportData(raoResult, crac, tapSingleton, outputStream)); assertEquals("Flow unit should be AMPERE and/or MEGAWATT", exception.getMessage()); // "DEGREE" unit Set degreeSingleton = Set.of(DEGREE); - exception = assertThrows(OpenRaoException.class, () -> raoResultExporter.export(raoResult, crac, degreeSingleton, outputStream)); + exception = assertThrows(OpenRaoException.class, () -> new RaoResultJsonExporter().exportData(raoResult, crac, degreeSingleton, outputStream)); assertEquals("Flow unit should be AMPERE and/or MEGAWATT", exception.getMessage()); // "KILOVOLT" + "AMPERE" units Set kvAndAmp = Set.of(KILOVOLT, AMPERE); - exception = assertThrows(OpenRaoException.class, () -> raoResultExporter.export(raoResult, crac, kvAndAmp, outputStream)); + exception = assertThrows(OpenRaoException.class, () -> new RaoResultJsonExporter().exportData(raoResult, crac, kvAndAmp, outputStream)); assertEquals("Flow unit should be AMPERE and/or MEGAWATT", exception.getMessage()); } @Test - void testRoundTripWithUnits() { + void testExplicitRoundTripWithUnits() throws IOException { // get exhaustive CRAC and RaoResult Crac crac = ExhaustiveCracCreation.create(); RaoResult raoResult = ExhaustiveRaoResultCreation.create(crac); // RoundTrip with Ampere only ByteArrayOutputStream outputStreamAmpere = new ByteArrayOutputStream(); - new RaoResultExporter().export(raoResult, crac, Set.of(AMPERE), outputStreamAmpere); + new RaoResultJsonExporter().exportData(raoResult, crac, Set.of(AMPERE), outputStreamAmpere); ByteArrayInputStream inputStreamAmpere = new ByteArrayInputStream(outputStreamAmpere.toByteArray()); - RaoResult importedRaoResultAmpere = new RaoResultImporter().importRaoResult(inputStreamAmpere, crac); + RaoResult importedRaoResultAmpere = new RaoResultJsonImporter().importData(inputStreamAmpere, crac); FlowCnec cnecP = crac.getFlowCnec("cnec4prevId"); - assertTrue(Double.isNaN(importedRaoResultAmpere.getFlow(null, cnecP, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResultAmpere.getFlow(null, cnecP, Side.RIGHT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResultAmpere.getMargin(null, cnecP, MEGAWATT))); - assertEquals(4120, importedRaoResultAmpere.getFlow(null, cnecP, Side.LEFT, AMPERE), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(importedRaoResultAmpere.getFlow(null, cnecP, Side.RIGHT, AMPERE))); - assertEquals(4121, importedRaoResultAmpere.getMargin(null, cnecP, AMPERE), DOUBLE_TOLERANCE); + checkContentAmpere(importedRaoResultAmpere, cnecP); // RoundTrip with MW only ByteArrayOutputStream outputStreamMegawatt = new ByteArrayOutputStream(); - new RaoResultExporter().export(raoResult, crac, Set.of(MEGAWATT), outputStreamMegawatt); + raoResult.write("JSON", crac, Set.of(MEGAWATT), outputStreamMegawatt); ByteArrayInputStream inputStreamMegawatt = new ByteArrayInputStream(outputStreamMegawatt.toByteArray()); - RaoResult importedRaoResultMegawatt = new RaoResultImporter().importRaoResult(inputStreamMegawatt, crac); - - assertEquals(4110, importedRaoResultMegawatt.getFlow(null, cnecP, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(importedRaoResultMegawatt.getFlow(null, cnecP, Side.RIGHT, MEGAWATT))); - assertEquals(4111, importedRaoResultMegawatt.getMargin(null, cnecP, MEGAWATT), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(importedRaoResultMegawatt.getFlow(null, cnecP, Side.LEFT, AMPERE))); - assertTrue(Double.isNaN(importedRaoResultMegawatt.getFlow(null, cnecP, Side.RIGHT, AMPERE))); - assertTrue(Double.isNaN(importedRaoResultMegawatt.getMargin(null, cnecP, AMPERE))); + RaoResult importedRaoResultMegawatt = RaoResult.read(inputStreamMegawatt, crac); + + checkContentMegawatt(importedRaoResultMegawatt, cnecP); + } + + @Test + void testImplicitRoundTripWithUnits() throws IOException { + // get exhaustive CRAC and RaoResult + Crac crac = ExhaustiveCracCreation.create(); + RaoResult raoResult = ExhaustiveRaoResultCreation.create(crac); + + // RoundTrip with Ampere only + ByteArrayOutputStream outputStreamAmpere = new ByteArrayOutputStream(); + raoResult.write("JSON", crac, Set.of(AMPERE), outputStreamAmpere); + ByteArrayInputStream inputStreamAmpere = new ByteArrayInputStream(outputStreamAmpere.toByteArray()); + RaoResult importedRaoResultAmpere = RaoResult.read(inputStreamAmpere, crac); + + FlowCnec cnecP = crac.getFlowCnec("cnec4prevId"); + checkContentAmpere(importedRaoResultAmpere, cnecP); + + // RoundTrip with MW only + ByteArrayOutputStream outputStreamMegawatt = new ByteArrayOutputStream(); + raoResult.write("JSON", crac, Set.of(MEGAWATT), outputStreamMegawatt); + ByteArrayInputStream inputStreamMegawatt = new ByteArrayInputStream(outputStreamMegawatt.toByteArray()); + RaoResult importedRaoResultMegawatt = RaoResult.read(inputStreamMegawatt, crac); + + checkContentMegawatt(importedRaoResultMegawatt, cnecP); + } + + private void checkContentAmpere(RaoResult raoResult, FlowCnec cnecP) { + assertTrue(Double.isNaN(raoResult.getFlow(null, cnecP, Side.LEFT, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getFlow(null, cnecP, Side.RIGHT, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getMargin(null, cnecP, MEGAWATT))); + assertEquals(4120, raoResult.getFlow(null, cnecP, Side.LEFT, AMPERE), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getFlow(null, cnecP, Side.RIGHT, AMPERE))); + assertEquals(4121, raoResult.getMargin(null, cnecP, AMPERE), DOUBLE_TOLERANCE); + } + + private void checkContentMegawatt(RaoResult raoResult, FlowCnec cnecP) { + assertEquals(4110, raoResult.getFlow(null, cnecP, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getFlow(null, cnecP, Side.RIGHT, MEGAWATT))); + assertEquals(4111, raoResult.getMargin(null, cnecP, MEGAWATT), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getFlow(null, cnecP, Side.LEFT, AMPERE))); + assertTrue(Double.isNaN(raoResult.getFlow(null, cnecP, Side.RIGHT, AMPERE))); + assertTrue(Double.isNaN(raoResult.getMargin(null, cnecP, AMPERE))); } } diff --git a/data/result-exporter/swe-cne-exporter/src/test/java/com/powsybl/openrao/data/swecneexporter/SweCneDivergentAngleMonitoringTest.java b/data/result-exporter/swe-cne-exporter/src/test/java/com/powsybl/openrao/data/swecneexporter/SweCneDivergentAngleMonitoringTest.java index 46210d71b9..ea94e1b52a 100644 --- a/data/result-exporter/swe-cne-exporter/src/test/java/com/powsybl/openrao/data/swecneexporter/SweCneDivergentAngleMonitoringTest.java +++ b/data/result-exporter/swe-cne-exporter/src/test/java/com/powsybl/openrao/data/swecneexporter/SweCneDivergentAngleMonitoringTest.java @@ -18,7 +18,6 @@ import com.powsybl.openrao.data.craccreation.creator.cim.parameters.CimCracCreationParameters; import com.powsybl.openrao.data.craccreation.creator.cim.parameters.RangeActionSpeed; import com.powsybl.openrao.data.raoresultapi.RaoResult; -import com.powsybl.openrao.data.raoresultjson.RaoResultImporter; import com.powsybl.openrao.monitoring.anglemonitoring.AngleMonitoringResult; import com.powsybl.openrao.monitoring.anglemonitoring.RaoResultWithAngleMonitoring; import com.powsybl.openrao.monitoring.anglemonitoring.json.AngleMonitoringResultImporter; @@ -45,7 +44,7 @@ class SweCneDivergentAngleMonitoringTest { private RaoResultWithAngleMonitoring raoResultWithAngleMonitoring; @BeforeEach - public void setUp() { + public void setUp() throws IOException { network = Network.read(new File(SweCneTest.class.getResource("/TestCase16NodesWith2Hvdc.xiidm").getFile()).toString()); InputStream is = getClass().getResourceAsStream("/CIM_CRAC.xml"); CimCracImporter cracImporter = new CimCracImporter(); @@ -67,7 +66,7 @@ public void setUp() { } catch (FileNotFoundException e) { e.printStackTrace(); } - RaoResult raoResult = new RaoResultImporter().importRaoResult(inputStream, crac); + RaoResult raoResult = RaoResult.read(inputStream, crac); InputStream inputStream2 = null; try { inputStream2 = new FileInputStream(SweCneDivergentAngleMonitoringTest.class.getResource("/AngleMonitoringDivergentResult.json").getFile()); diff --git a/data/result-exporter/swe-cne-exporter/src/test/java/com/powsybl/openrao/data/swecneexporter/SweCneTest.java b/data/result-exporter/swe-cne-exporter/src/test/java/com/powsybl/openrao/data/swecneexporter/SweCneTest.java index 37b6f12ecf..038f9991c9 100644 --- a/data/result-exporter/swe-cne-exporter/src/test/java/com/powsybl/openrao/data/swecneexporter/SweCneTest.java +++ b/data/result-exporter/swe-cne-exporter/src/test/java/com/powsybl/openrao/data/swecneexporter/SweCneTest.java @@ -18,7 +18,6 @@ import com.powsybl.openrao.data.craccreation.creator.cim.parameters.CimCracCreationParameters; import com.powsybl.openrao.data.craccreation.creator.cim.parameters.RangeActionSpeed; import com.powsybl.openrao.data.raoresultapi.RaoResult; -import com.powsybl.openrao.data.raoresultjson.RaoResultImporter; import com.powsybl.openrao.monitoring.anglemonitoring.AngleMonitoringResult; import com.powsybl.openrao.monitoring.anglemonitoring.RaoResultWithAngleMonitoring; import com.powsybl.openrao.monitoring.anglemonitoring.json.AngleMonitoringResultImporter; @@ -53,7 +52,7 @@ class SweCneTest { private RaoResultWithAngleMonitoring raoResultFailureWithAngle; @BeforeEach - public void setUp() { + public void setUp() throws IOException { network = Network.read(new File(SweCneTest.class.getResource("/TestCase16NodesWith2Hvdc.xiidm").getFile()).toString()); InputStream is = getClass().getResourceAsStream("/CIM_CRAC.xml"); CimCracImporter cracImporter = new CimCracImporter(); @@ -75,7 +74,7 @@ public void setUp() { } catch (FileNotFoundException e) { e.printStackTrace(); } - RaoResult raoResult = new RaoResultImporter().importRaoResult(inputStream, crac); + RaoResult raoResult = RaoResult.read(inputStream, crac); InputStream inputStream2 = null; try { inputStream2 = new FileInputStream(SweCneTest.class.getResource("/AngleMonitoringResult.json").getFile()); @@ -89,7 +88,7 @@ public void setUp() { } catch (FileNotFoundException e) { e.printStackTrace(); } - RaoResult raoResultWithFailure = new RaoResultImporter().importRaoResult(inputStream3, crac); + RaoResult raoResultWithFailure = RaoResult.read(inputStream3, crac); raoResultWithAngle = new RaoResultWithAngleMonitoring(raoResult, angleMonitoringResult); raoResultFailureWithAngle = new RaoResultWithAngleMonitoring(raoResultWithFailure, angleMonitoringResult); } diff --git a/distribution/pom.xml b/distribution/pom.xml index a3491fa019..345aa44b1a 100755 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -47,11 +47,6 @@ open-rao-crac-impl ${project.version} - - ${project.groupId} - open-rao-crac-io-api - ${project.version} - ${project.groupId} open-rao-crac-io-json diff --git a/docs/input-data/crac/import.md b/docs/input-data/crac/import.md index d268abaff0..c33f6ccfb2 100644 --- a/docs/input-data/crac/import.md +++ b/docs/input-data/crac/import.md @@ -2,28 +2,24 @@ ## CRAC import/export -The [OpenRAO CRAC object model](json) can be directly imported and exported using the open-rao-crac-io-api. +The [OpenRAO CRAC object model](json) can be directly imported and exported using the CRAC API. The JSON format - also called OpenRAO internal format - is a raw image of the CRAC object model of OpenRAO. It is particularly suited to exchange a CRAC java object through files, for instance to exchange CRAC data between microservices or Kubernetes pods of an application. It has an importer and an exporter. The complete round-trip (java object → export → json file → import → java object) has been designed so that the CRAC at the beginning of the chain is exactly the same as the one at the end of the chain. Examples of JSON formats are given on this [page](json). -Examples of uses of the OPEN-RAO-crac-io-api are given below: +Examples of uses of CRAC import/export are given below: ~~~java // import a CRAC from a PATH // (a network is required to reconstruct the contingency elements from the network elements id) -Crac crac = CracImporters.importCrac(Paths.get("/tmp/crac.json"), network); +Crac crac = Crac.read(Paths.get("/tmp/crac.json"), network); // import a CRAC from an input stream -Crac crac = CracImporters.importCrac("crac.json", new FileInputStream(new File("/tmp/crac.json")), network); +Crac crac = Crac.read("crac.json", new FileInputStream(new File("/tmp/crac.json")), network); // export a CRAC in JSON in a file -CracExporters.exportCrac(crac, "Json", Paths.get("/tmp/crac.json")); - -// export a CRAC in security limit format in an output stream -// (a network is required for this exporter) -CracExporters.exportCrac(crac, network, "SecurityLimit", outputStream); +crac.write("JSON", Paths.get("/tmp/crac.json")); ~~~ ## Versioning of internal JSON CRAC files diff --git a/docs/output-data/rao-result.md b/docs/output-data/rao-result.md index d1ce63c329..bb38923df4 100644 --- a/docs/output-data/rao-result.md +++ b/docs/output-data/rao-result.md @@ -32,7 +32,7 @@ A RaoResult JSON file can be imported into a [RaoResultImpl](https://github.com/ Example: ~~~java -new RaoResultExporter().export(raoResult, crac, flowUnits, outputStream); +raoResult.write("JSON", crac, flowUnits, outputStream); ~~~ Where: @@ -46,7 +46,7 @@ Where: Example: ~~~java -RaoResult importedRaoResult = new RaoResultImporter().importRaoResult(inputStream, crac); +RaoResult importedRaoResult = RaoResult.read(inputStream, crac); ~~~ Where: diff --git a/flowbased-computation/flowbased-computation-api/pom.xml b/flowbased-computation/flowbased-computation-api/pom.xml index cb4f9044bb..36a0e10c7b 100755 --- a/flowbased-computation/flowbased-computation-api/pom.xml +++ b/flowbased-computation/flowbased-computation-api/pom.xml @@ -22,11 +22,6 @@ open-rao-crac-api ${project.version} - - ${project.groupId} - open-rao-crac-io-api - ${project.version} - ${project.groupId} open-rao-crac-util diff --git a/flowbased-computation/flowbased-computation-impl/src/test/java/com/powsybl/openrao/flowbasedcomputation/impl/ExampleGenerator.java b/flowbased-computation/flowbased-computation-impl/src/test/java/com/powsybl/openrao/flowbasedcomputation/impl/ExampleGenerator.java index 84990d9e95..60e4d3ab0f 100644 --- a/flowbased-computation/flowbased-computation-impl/src/test/java/com/powsybl/openrao/flowbasedcomputation/impl/ExampleGenerator.java +++ b/flowbased-computation/flowbased-computation-impl/src/test/java/com/powsybl/openrao/flowbasedcomputation/impl/ExampleGenerator.java @@ -9,12 +9,12 @@ import com.powsybl.glsk.commons.ZonalData; import com.powsybl.glsk.commons.ZonalDataImpl; import com.powsybl.openrao.data.cracapi.*; -import com.powsybl.openrao.data.cracioapi.CracImporters; import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.VoltageLevel; import com.powsybl.sensitivity.SensitivityVariableSet; import com.powsybl.sensitivity.WeightedSensitivityVariable; +import java.io.IOException; import java.util.*; /** @@ -258,8 +258,8 @@ static Network network() { return network; } - static Crac crac(String fileName, Network network) { - return CracImporters.importCrac(fileName, ExampleGenerator.class.getResourceAsStream("/" + fileName), network); + static Crac crac(String fileName, Network network) throws IOException { + return Crac.read(ExampleGenerator.class.getResourceAsStream("/" + fileName), network); } static ZonalData glskProvider() { diff --git a/flowbased-computation/flowbased-computation-impl/src/test/java/com/powsybl/openrao/flowbasedcomputation/impl/FlowbasedComputationImplTest.java b/flowbased-computation/flowbased-computation-impl/src/test/java/com/powsybl/openrao/flowbasedcomputation/impl/FlowbasedComputationImplTest.java index 1350021880..80a42f9899 100644 --- a/flowbased-computation/flowbased-computation-impl/src/test/java/com/powsybl/openrao/flowbasedcomputation/impl/FlowbasedComputationImplTest.java +++ b/flowbased-computation/flowbased-computation-impl/src/test/java/com/powsybl/openrao/flowbasedcomputation/impl/FlowbasedComputationImplTest.java @@ -27,6 +27,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.io.IOException; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @@ -66,7 +67,7 @@ void testProviderVersion() { } @Test - void testRunWithCra() { + void testRunWithCra() throws IOException { Crac crac = ExampleGenerator.crac("crac.json", network); assertTrue(network.getBranch("FR-BE").getTerminal1().isConnected()); assertTrue(network.getBranch("FR-BE").getTerminal2().isConnected()); @@ -76,7 +77,7 @@ void testRunWithCra() { } @Test - void testRunWithCraRaoResult() { + void testRunWithCraRaoResult() throws IOException { Crac crac = ExampleGenerator.crac("crac_for_rao_result.json", network); assertTrue(network.getBranch("FR-BE").getTerminal1().isConnected()); assertTrue(network.getBranch("FR-BE").getTerminal2().isConnected()); @@ -87,14 +88,14 @@ void testRunWithCraRaoResult() { } @Test - void testRunPraWithForced() { + void testRunPraWithForced() throws IOException { Crac crac = ExampleGenerator.crac("crac_with_forced.json", network); FlowbasedComputationResult result = flowBasedComputationProvider.run(network, crac, null, glsk, parameters).join(); checkAssertions(result); } @Test - void testRunPraWithExtension() { + void testRunPraWithExtension() throws IOException { Crac crac = ExampleGenerator.crac("crac_with_extension.json", network); FlowbasedComputationResult result = flowBasedComputationProvider.run(network, crac, null, glsk, parameters).join(); checkAssertions(result); diff --git a/monitoring/angle-monitoring/src/test/java/com/powsybl/openrao/monitoring/anglemonitoring/RaoResultWithAngleMonitoringTest.java b/monitoring/angle-monitoring/src/test/java/com/powsybl/openrao/monitoring/anglemonitoring/RaoResultWithAngleMonitoringTest.java index dce8f496bf..9ecf55bea8 100644 --- a/monitoring/angle-monitoring/src/test/java/com/powsybl/openrao/monitoring/anglemonitoring/RaoResultWithAngleMonitoringTest.java +++ b/monitoring/angle-monitoring/src/test/java/com/powsybl/openrao/monitoring/anglemonitoring/RaoResultWithAngleMonitoringTest.java @@ -16,15 +16,14 @@ import com.powsybl.openrao.data.cracapi.Identifiable; import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.InstantKind; -import com.powsybl.openrao.data.craciojson.JsonImport; import com.powsybl.openrao.data.raoresultapi.ComputationStatus; import com.powsybl.openrao.data.raoresultapi.RaoResult; -import com.powsybl.openrao.data.raoresultjson.RaoResultImporter; import com.powsybl.openrao.monitoring.anglemonitoring.json.AngleMonitoringResultImporter; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mockito; +import java.io.IOException; import java.io.InputStream; import java.util.Set; import java.util.stream.Collectors; @@ -51,11 +50,11 @@ private static Network mockNetworkWithLines(String... lineIds) { } @BeforeEach - public void setUp() { + public void setUp() throws IOException { InputStream raoResultFile = getClass().getResourceAsStream("/rao-result-v1.4.json"); InputStream cracFile = getClass().getResourceAsStream("/crac-for-rao-result-v1.4.json"); - crac = new JsonImport().importCrac(cracFile, mockNetworkWithLines("ne1Id", "ne2Id", "ne3Id")); - raoResult = new RaoResultImporter().importRaoResult(raoResultFile, crac); + crac = Crac.read(cracFile, mockNetworkWithLines("ne1Id", "ne2Id", "ne3Id")); + raoResult = RaoResult.read(raoResultFile, crac); } @Test diff --git a/monitoring/voltage-monitoring/src/test/java/com/powsybl/openrao/monitoring/voltagemonitoring/RaoResultWithVoltageMonitoringTest.java b/monitoring/voltage-monitoring/src/test/java/com/powsybl/openrao/monitoring/voltagemonitoring/RaoResultWithVoltageMonitoringTest.java index 7bfa032ab9..48f4a079ff 100644 --- a/monitoring/voltage-monitoring/src/test/java/com/powsybl/openrao/monitoring/voltagemonitoring/RaoResultWithVoltageMonitoringTest.java +++ b/monitoring/voltage-monitoring/src/test/java/com/powsybl/openrao/monitoring/voltagemonitoring/RaoResultWithVoltageMonitoringTest.java @@ -14,14 +14,13 @@ import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.Identifiable; import com.powsybl.openrao.data.cracapi.Instant; -import com.powsybl.openrao.data.craciojson.JsonImport; import com.powsybl.openrao.data.raoresultapi.ComputationStatus; import com.powsybl.openrao.data.raoresultapi.RaoResult; -import com.powsybl.openrao.data.raoresultjson.RaoResultImporter; import com.powsybl.openrao.monitoring.voltagemonitoring.json.VoltageMonitoringResultImporter; import org.junit.jupiter.api.Test; import org.mockito.Mockito; +import java.io.IOException; import java.io.InputStream; import java.util.Set; import java.util.stream.Collectors; @@ -46,13 +45,13 @@ private static Network mockNetworkWithLines(String... lineIds) { } @Test - void testRaoResultWithVoltageMonitoring() { + void testRaoResultWithVoltageMonitoring() throws IOException { InputStream raoResultFile = getClass().getResourceAsStream("/rao-result-v1.4.json"); InputStream cracFile = getClass().getResourceAsStream("/crac-for-rao-result-v1.4.json"); - Crac crac = new JsonImport().importCrac(cracFile, mockNetworkWithLines("ne1Id", "ne2Id", "ne3Id")); + Crac crac = Crac.read(cracFile, mockNetworkWithLines("ne1Id", "ne2Id", "ne3Id")); Instant curativeInstant = crac.getInstant("curative"); - RaoResult raoResult = new RaoResultImporter().importRaoResult(raoResultFile, crac); + RaoResult raoResult = RaoResult.read(raoResultFile, crac); VoltageMonitoringResult voltageMonitoringResult = new VoltageMonitoringResultImporter().importVoltageMonitoringResult(getClass().getResourceAsStream("/voltage-monitoring-result.json"), crac); RaoResult raoResultWithVoltageMonitoring = new RaoResultWithVoltageMonitoring(raoResult, voltageMonitoringResult); diff --git a/ra-optimisation/rao-api/pom.xml b/ra-optimisation/rao-api/pom.xml index 6c832861e8..c21292eb4f 100644 --- a/ra-optimisation/rao-api/pom.xml +++ b/ra-optimisation/rao-api/pom.xml @@ -22,11 +22,6 @@ open-rao-crac-api ${project.version} - - ${project.groupId} - open-rao-crac-io-api - ${project.version} - ${project.groupId} open-rao-rao-result-api diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/CastorFullOptimizationTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/CastorFullOptimizationTest.java index 4951488a7d..bdb34e286d 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/CastorFullOptimizationTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/CastorFullOptimizationTest.java @@ -26,7 +26,6 @@ import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; import com.powsybl.openrao.data.cracapi.usagerule.UsageMethod; import com.powsybl.openrao.data.cracimpl.utils.NetworkImportsUtil; -import com.powsybl.openrao.data.cracioapi.CracImporters; import com.powsybl.openrao.data.raoresultapi.RaoResult; import com.powsybl.openrao.data.raoresultapi.OptimizationStepsExecuted; import com.powsybl.openrao.raoapi.RaoInput; @@ -42,8 +41,7 @@ import org.mockito.Mockito; import org.slf4j.LoggerFactory; -import java.io.File; -import java.nio.file.Paths; +import java.io.IOException; import java.util.*; import java.util.stream.Collectors; @@ -81,9 +79,9 @@ class CastorFullOptimizationTest { private Instant curativeInstant; @BeforeEach - public void setup() { + public void setup() throws IOException { network = Network.read("network_with_alegro_hub.xiidm", getClass().getResourceAsStream("/network/network_with_alegro_hub.xiidm")); - crac = CracImporters.importCrac("crac/small-crac.json", getClass().getResourceAsStream("/crac/small-crac.json"), network); + crac = Crac.read(getClass().getResourceAsStream("/crac/small-crac.json"), network); preventiveInstant = crac.getInstant(PREVENTIVE_INSTANT_ID); autoInstant = crac.getInstant(AUTO_INSTANT_ID); curativeInstant = crac.getInstant(CURATIVE_INSTANT_ID); @@ -573,12 +571,12 @@ void testGetAppliedRemedialActionsInCurative() { } @Test - void smallRaoWithDivergingInitialSensi() { + void smallRaoWithDivergingInitialSensi() throws IOException { // Small RAO with diverging initial sensi // Cannot optimize range actions in unit tests (needs OR-Tools installed) Network network = Network.read("small-network-2P.uct", getClass().getResourceAsStream("/network/small-network-2P.uct")); - crac = CracImporters.importCrac("crac/small-crac-2P.json", getClass().getResourceAsStream("/crac/small-crac-2P.json"), network); + crac = Crac.read(getClass().getResourceAsStream("/crac/small-crac-2P.json"), network); RaoInput raoInput = RaoInput.build(network, crac).build(); RaoParameters raoParameters = JsonRaoParameters.read(getClass().getResourceAsStream("/parameters/RaoParameters_oneIteration_v2.json")); @@ -588,12 +586,12 @@ void smallRaoWithDivergingInitialSensi() { } @Test - void smallRaoWithout2P() { + void smallRaoWithout2P() throws IOException { // Small RAO without second preventive optimization and only topological actions // Cannot optimize range actions in unit tests (needs OR-Tools installed) Network network = Network.read("small-network-2P.uct", getClass().getResourceAsStream("/network/small-network-2P.uct")); - crac = CracImporters.importCrac("crac/small-crac-2P.json", getClass().getResourceAsStream("/crac/small-crac-2P.json"), network); + crac = Crac.read(getClass().getResourceAsStream("/crac/small-crac-2P.json"), network); RaoInput raoInput = RaoInput.build(network, crac).build(); RaoParameters raoParameters = JsonRaoParameters.read(getClass().getResourceAsStream("/parameters/RaoParameters_2P_v2.json")); @@ -608,11 +606,11 @@ void smallRaoWithout2P() { } @Test - void smallRaoWith2P() { + void smallRaoWith2P() throws IOException { // Same RAO as before but activating 2P => results should be better Network network = Network.read("small-network-2P.uct", getClass().getResourceAsStream("/network/small-network-2P.uct")); - crac = CracImporters.importCrac("crac/small-crac-2P.json", getClass().getResourceAsStream("/crac/small-crac-2P.json"), network); + crac = Crac.read(getClass().getResourceAsStream("/crac/small-crac-2P.json"), network); RaoInput raoInput = RaoInput.build(network, crac).build(); RaoParameters raoParameters = JsonRaoParameters.read(getClass().getResourceAsStream("/parameters/RaoParameters_2P_v2.json")); @@ -632,11 +630,11 @@ void smallRaoWith2P() { } @Test - void smallRaoWithGlobal2P() { + void smallRaoWithGlobal2P() throws IOException { // Same RAO as before but activating Global 2P => results should be the same (there are no range actions) Network network = Network.read("small-network-2P.uct", getClass().getResourceAsStream("/network/small-network-2P.uct")); - crac = CracImporters.importCrac("crac/small-crac-2P.json", getClass().getResourceAsStream("/crac/small-crac-2P.json"), network); + crac = Crac.read(getClass().getResourceAsStream("/crac/small-crac-2P.json"), network); RaoInput raoInput = RaoInput.build(network, crac).build(); RaoParameters raoParameters = JsonRaoParameters.read(getClass().getResourceAsStream("/parameters/RaoParameters_2P_v2.json")); @@ -657,7 +655,7 @@ void smallRaoWithGlobal2P() { } @Test - void testOptimizationStepsExecutedAndLogsWhenFallbackOnFirstPrev() { + void testOptimizationStepsExecutedAndLogsWhenFallbackOnFirstPrev() throws IOException { // Catch future logs Logger logger = (Logger) LoggerFactory.getLogger(RaoBusinessLogs.class); ListAppender listAppender = new ListAppender<>(); @@ -666,7 +664,7 @@ void testOptimizationStepsExecutedAndLogsWhenFallbackOnFirstPrev() { // Set up RAO and run Network network = Network.read("small-network-2P.uct", getClass().getResourceAsStream("/network/small-network-2P.uct")); - crac = CracImporters.importCrac("crac/small-crac-2P.json", getClass().getResourceAsStream("/crac/small-crac-2P_cost_increase.json"), network); + crac = Crac.read(getClass().getResourceAsStream("/crac/small-crac-2P_cost_increase.json"), network); RaoInput raoInput = RaoInput.build(network, crac).build(); RaoParameters raoParameters = JsonRaoParameters.read(getClass().getResourceAsStream("/parameters/RaoParameters_2P_v2.json")); raoParameters.getObjectiveFunctionParameters().setForbidCostIncrease(true); @@ -879,9 +877,9 @@ void testThreeCurativeInstants() { } @Test - void optimizationWithAutoSearchTree() { + void optimizationWithAutoSearchTree() throws IOException { Network network = Network.read("12Nodes_2_twin_lines.uct", getClass().getResourceAsStream("/network/12Nodes_2_twin_lines.uct")); - Crac crac = CracImporters.importCrac("crac/small-crac-available-aras.json", getClass().getResourceAsStream("/crac/small-crac-available-aras.json"), network); + Crac crac = Crac.read(getClass().getResourceAsStream("/crac/small-crac-available-aras.json"), network); RaoInput raoInput = RaoInput.build(network, crac).build(); RaoParameters raoParameters = JsonRaoParameters.read(getClass().getResourceAsStream("/parameters/RaoParameters_DC.json")); @@ -906,9 +904,9 @@ void optimizationWithAutoSearchTree() { } @Test - void optimizationWithAutoSearchTreeAndAutoPsts() { + void optimizationWithAutoSearchTreeAndAutoPsts() throws IOException { Network network = Network.read("12Nodes_2_twin_lines.uct", getClass().getResourceAsStream("/network/12Nodes_2_twin_lines.uct")); - Crac crac = CracImporters.importCrac("crac/small-crac-available-aras-low-limits-thresholds.json", getClass().getResourceAsStream("/crac/small-crac-available-aras-low-limits-thresholds.json"), network); + Crac crac = Crac.read(getClass().getResourceAsStream("/crac/small-crac-available-aras-low-limits-thresholds.json"), network); RaoInput raoInput = RaoInput.build(network, crac).build(); RaoParameters raoParameters = JsonRaoParameters.read(getClass().getResourceAsStream("/parameters/RaoParameters_DC.json")); @@ -933,10 +931,10 @@ void optimizationWithAutoSearchTreeAndAutoPsts() { } @Test - void threeCurativeInstantsWithCumulativeMaximumNumberOfApplicableRemedialActions() { + void threeCurativeInstantsWithCumulativeMaximumNumberOfApplicableRemedialActions() throws IOException { Network network = Network.read("12Nodes_4ParallelLines.uct", getClass().getResourceAsStream("/network/12Nodes_4ParallelLines.uct")); - Crac crac = CracImporters.importCrac( - Paths.get(new File(Objects.requireNonNull(CastorFullOptimizationTest.class.getResource("/crac/small-crac-ra-limits-per-instant.json")).getFile()).toString()), + Crac crac = Crac.read( + CastorFullOptimizationTest.class.getResourceAsStream("/crac/small-crac-ra-limits-per-instant.json"), network ); @@ -952,10 +950,10 @@ void threeCurativeInstantsWithCumulativeMaximumNumberOfApplicableRemedialActions } @Test - void threeCurativeInstantsWithCumulativeMaximumNumberOfTsos() { + void threeCurativeInstantsWithCumulativeMaximumNumberOfTsos() throws IOException { Network network = Network.read("12Nodes_4ParallelLines.uct", getClass().getResourceAsStream("/network/12Nodes_4ParallelLines.uct")); - Crac crac = CracImporters.importCrac( - Paths.get(new File(Objects.requireNonNull(CastorFullOptimizationTest.class.getResource("/crac/small-crac-ra-limits-per-instant-3-tsos.json")).getFile()).toString()), + Crac crac = Crac.read( + CastorFullOptimizationTest.class.getResourceAsStream("/crac/small-crac-ra-limits-per-instant-3-tsos.json"), network ); @@ -972,9 +970,9 @@ void threeCurativeInstantsWithCumulativeMaximumNumberOfTsos() { } @Test - void curativeOptimizationShouldNotBeDoneIfPreventiveUnsecure() { + void curativeOptimizationShouldNotBeDoneIfPreventiveUnsecure() throws IOException { Network network = Network.read("small-network-2P.uct", getClass().getResourceAsStream("/network/small-network-2P.uct")); - crac = CracImporters.importCrac("crac/small-crac-to-check-curative-optimization-if-preventive-unsecure.json", getClass().getResourceAsStream("/crac/small-crac-to-check-curative-optimization-if-preventive-unsecure.json"), network); + crac = Crac.read(getClass().getResourceAsStream("/crac/small-crac-to-check-curative-optimization-if-preventive-unsecure.json"), network); RaoInput raoInput = RaoInput.build(network, crac).build(); RaoParameters raoParameters = JsonRaoParameters.read(getClass().getResourceAsStream("/parameters/RaoParameters_2P_v2.json")); @@ -987,9 +985,9 @@ void curativeOptimizationShouldNotBeDoneIfPreventiveUnsecure() { } @Test - void curativeOptimizationShouldBeDoneIfPreventiveSecure() { + void curativeOptimizationShouldBeDoneIfPreventiveSecure() throws IOException { Network network = Network.read("small-network-2P.uct", getClass().getResourceAsStream("/network/small-network-2P.uct")); - crac = CracImporters.importCrac("crac/small-crac-to-check-curative-optimization-if-preventive-secure.json", getClass().getResourceAsStream("/crac/small-crac-to-check-curative-optimization-if-preventive-secure.json"), network); + crac = Crac.read(getClass().getResourceAsStream("/crac/small-crac-to-check-curative-optimization-if-preventive-secure.json"), network); RaoInput raoInput = RaoInput.build(network, crac).build(); RaoParameters raoParameters = JsonRaoParameters.read(getClass().getResourceAsStream("/parameters/RaoParameters_2P_v2.json")); @@ -1002,9 +1000,9 @@ void curativeOptimizationShouldBeDoneIfPreventiveSecure() { } @Test - void curativeOptimizationShouldBeDoneIfPreventiveMinMarginNegative() { + void curativeOptimizationShouldBeDoneIfPreventiveMinMarginNegative() throws IOException { Network network = Network.read("small-network-2P.uct", getClass().getResourceAsStream("/network/small-network-2P.uct")); - crac = CracImporters.importCrac("crac/small-crac-to-check-curative-optimization-if-preventive-unsecure.json", getClass().getResourceAsStream("/crac/small-crac-to-check-curative-optimization-if-preventive-unsecure.json"), network); + crac = Crac.read(getClass().getResourceAsStream("/crac/small-crac-to-check-curative-optimization-if-preventive-unsecure.json"), network); RaoInput raoInput = RaoInput.build(network, crac).build(); RaoParameters raoParameters = JsonRaoParameters.read(getClass().getResourceAsStream("/parameters/RaoParameters_2P_v2.json")); @@ -1016,9 +1014,9 @@ void curativeOptimizationShouldBeDoneIfPreventiveMinMarginNegative() { } @Test - void curativeOptimizationShouldBeDoneIfPreventiveUnsecureAndAssociatedParameterSet() { + void curativeOptimizationShouldBeDoneIfPreventiveUnsecureAndAssociatedParameterSet() throws IOException { Network network = Network.read("small-network-2P.uct", getClass().getResourceAsStream("/network/small-network-2P.uct")); - crac = CracImporters.importCrac("crac/small-crac-to-check-curative-optimization-if-preventive-unsecure.json", getClass().getResourceAsStream("/crac/small-crac-to-check-curative-optimization-if-preventive-unsecure.json"), network); + crac = Crac.read(getClass().getResourceAsStream("/crac/small-crac-to-check-curative-optimization-if-preventive-unsecure.json"), network); RaoInput raoInput = RaoInput.build(network, crac).build(); RaoParameters raoParameters = JsonRaoParameters.read(getClass().getResourceAsStream("/parameters/RaoParameters_2P_v2.json")); @@ -1031,9 +1029,9 @@ void curativeOptimizationShouldBeDoneIfPreventiveUnsecureAndAssociatedParameterS } @Test - void curativeOptimizationShouldBeDoneIfPreventiveSecureAndAssociatedParameterSet() { + void curativeOptimizationShouldBeDoneIfPreventiveSecureAndAssociatedParameterSet() throws IOException { Network network = Network.read("small-network-2P.uct", getClass().getResourceAsStream("/network/small-network-2P.uct")); - crac = CracImporters.importCrac("crac/small-crac-to-check-curative-optimization-if-preventive-secure.json", getClass().getResourceAsStream("/crac/small-crac-to-check-curative-optimization-if-preventive-secure.json"), network); + crac = Crac.read(getClass().getResourceAsStream("/crac/small-crac-to-check-curative-optimization-if-preventive-secure.json"), network); RaoInput raoInput = RaoInput.build(network, crac).build(); RaoParameters raoParameters = JsonRaoParameters.read(getClass().getResourceAsStream("/parameters/RaoParameters_2P_v2.json")); @@ -1046,9 +1044,9 @@ void curativeOptimizationShouldBeDoneIfPreventiveSecureAndAssociatedParameterSet } @Test - void curativeOptimizationShouldBeDoneIfPreventiveMinMarginNegativeAndAssociatedParameterSet() { + void curativeOptimizationShouldBeDoneIfPreventiveMinMarginNegativeAndAssociatedParameterSet() throws IOException { Network network = Network.read("small-network-2P.uct", getClass().getResourceAsStream("/network/small-network-2P.uct")); - crac = CracImporters.importCrac("crac/small-crac-to-check-curative-optimization-if-preventive-unsecure.json", getClass().getResourceAsStream("/crac/small-crac-to-check-curative-optimization-if-preventive-unsecure.json"), network); + crac = Crac.read(getClass().getResourceAsStream("/crac/small-crac-to-check-curative-optimization-if-preventive-unsecure.json"), network); RaoInput raoInput = RaoInput.build(network, crac).build(); RaoParameters raoParameters = JsonRaoParameters.read(getClass().getResourceAsStream("/parameters/RaoParameters_2P_v2.json")); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/AbstractFillerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/AbstractFillerTest.java index 8d4c118da8..9e78a520b9 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/AbstractFillerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/AbstractFillerTest.java @@ -14,13 +14,13 @@ import com.powsybl.openrao.data.cracapi.range.RangeType; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracimpl.utils.NetworkImportsUtil; -import com.powsybl.openrao.data.cracioapi.CracImporters; import com.powsybl.openrao.data.raoresultapi.ComputationStatus; import com.powsybl.openrao.searchtreerao.linearoptimisation.algorithms.linearproblem.LinearProblem; import com.powsybl.openrao.searchtreerao.result.api.FlowResult; import com.powsybl.openrao.searchtreerao.result.api.SensitivityResult; import org.mockito.Mockito; +import java.io.IOException; import java.util.Map; import static org.mockito.ArgumentMatchers.any; @@ -67,11 +67,11 @@ abstract class AbstractFillerTest { Crac crac; Network network; - void init() { + void init() throws IOException { // arrange some data for all fillers test // crac and network network = NetworkImportsUtil.import12NodesNetwork(); - crac = CracImporters.importCrac("crac/small-crac.json", getClass().getResourceAsStream("/crac/small-crac.json"), network); + crac = Crac.read(getClass().getResourceAsStream("/crac/small-crac.json"), network); // get cnec and rangeAction cnec1 = crac.getFlowCnec(CNEC_1_ID); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/ContinuousRangeActionGroupFillerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/ContinuousRangeActionGroupFillerTest.java index b6b62cb037..2c3cf0cab3 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/ContinuousRangeActionGroupFillerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/ContinuousRangeActionGroupFillerTest.java @@ -23,6 +23,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; +import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -36,7 +37,7 @@ class ContinuousRangeActionGroupFillerTest extends AbstractFillerTest { @Test - void testFillAndUpdateMethods() { + void testFillAndUpdateMethods() throws IOException { // prepare data init(); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/CoreProblemFillerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/CoreProblemFillerTest.java index 13dc8c6b75..578c674d0c 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/CoreProblemFillerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/CoreProblemFillerTest.java @@ -27,6 +27,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; +import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -48,7 +49,7 @@ class CoreProblemFillerTest extends AbstractFillerTest { private double initialAlpha; @BeforeEach - public void setUp() { + public void setUp() throws IOException { init(); // arrange some additional data network.getTwoWindingsTransformer(RANGE_ACTION_ELEMENT_ID).getPhaseTapChanger().setTapPosition(TAP_INITIAL); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/DiscretePstGroupFillerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/DiscretePstGroupFillerTest.java index 05ec223b0c..335560a343 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/DiscretePstGroupFillerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/DiscretePstGroupFillerTest.java @@ -24,6 +24,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; +import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -37,7 +38,7 @@ class DiscretePstGroupFillerTest extends AbstractFillerTest { @Test - void testFillAndUpdateMethods() { + void testFillAndUpdateMethods() throws IOException { // prepare data init(); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/DiscretePstTapFillerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/DiscretePstTapFillerTest.java index 2775217c21..a1de1ad2d5 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/DiscretePstTapFillerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/DiscretePstTapFillerTest.java @@ -24,6 +24,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; +import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -37,7 +38,7 @@ class DiscretePstTapFillerTest extends AbstractFillerTest { @Test - void testFillAndUpdateMethods() { + void testFillAndUpdateMethods() throws IOException { // prepare data init(); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxLoopFlowFillerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxLoopFlowFillerTest.java index 59558c4cd8..2a0043ac9d 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxLoopFlowFillerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxLoopFlowFillerTest.java @@ -31,6 +31,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; +import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -50,7 +51,7 @@ class MaxLoopFlowFillerTest extends AbstractFillerTest { private FlowCnec cnecOn2sides; @BeforeEach - public void setUp() { + public void setUp() throws IOException { init(); cnecOn2sides = crac.newFlowCnec() diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxMinMarginFillerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxMinMarginFillerTest.java index 6a3c0d84bb..5a06a6ba2d 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxMinMarginFillerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxMinMarginFillerTest.java @@ -25,6 +25,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; +import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -42,7 +43,7 @@ class MaxMinMarginFillerTest extends AbstractFillerTest { private MaxMinMarginFiller maxMinMarginFiller; @BeforeEach - public void setUp() { + public void setUp() throws IOException { init(); network.getTwoWindingsTransformer(RANGE_ACTION_ELEMENT_ID).getPhaseTapChanger().setTapPosition(TAP_INITIAL); double initialAlpha = network.getTwoWindingsTransformer(RANGE_ACTION_ELEMENT_ID).getPhaseTapChanger().getCurrentStep().getAlpha(); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxMinRelativeMarginFillerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxMinRelativeMarginFillerTest.java index c633eade9c..96665c7064 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxMinRelativeMarginFillerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxMinRelativeMarginFillerTest.java @@ -29,6 +29,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; +import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -53,7 +54,7 @@ class MaxMinRelativeMarginFillerTest extends AbstractFillerTest { private RangeActionSetpointResult initialRangeActionSetpointResult; @BeforeEach - public void setUp() { + public void setUp() throws IOException { init(); network.getTwoWindingsTransformer(RANGE_ACTION_ELEMENT_ID).getPhaseTapChanger().setTapPosition(TAP_INITIAL); double initialAlpha = network.getTwoWindingsTransformer(RANGE_ACTION_ELEMENT_ID).getPhaseTapChanger().getCurrentStep().getAlpha(); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MnecFillerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MnecFillerTest.java index 868ab3e016..d77d949851 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MnecFillerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MnecFillerTest.java @@ -29,6 +29,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; +import java.io.IOException; import java.util.*; import static org.junit.jupiter.api.Assertions.*; @@ -45,7 +46,7 @@ class MnecFillerTest extends AbstractFillerTest { private FlowCnec mnec3; @BeforeEach - public void setUp() { + public void setUp() throws IOException { init(); mnec1 = crac.newFlowCnec() .withId("MNEC1 - N - preventive") diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/RaUsageLimitsFillerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/RaUsageLimitsFillerTest.java index f7c4ed6535..84deb1d717 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/RaUsageLimitsFillerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/RaUsageLimitsFillerTest.java @@ -26,6 +26,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; +import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -54,7 +55,7 @@ class RaUsageLimitsFillerTest extends AbstractFillerTest { private CoreProblemFiller coreProblemFiller; @BeforeEach - public void setup() { + public void setup() throws IOException { init(); state = crac.getPreventiveState(); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/UnoptimizedCnecFillerMarginDecreaseRuleTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/UnoptimizedCnecFillerMarginDecreaseRuleTest.java index 9a3e9d53ad..de3799e85d 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/UnoptimizedCnecFillerMarginDecreaseRuleTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/UnoptimizedCnecFillerMarginDecreaseRuleTest.java @@ -31,6 +31,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; +import java.io.IOException; import java.util.*; import static com.powsybl.openrao.commons.Unit.MEGAWATT; @@ -53,7 +54,7 @@ class UnoptimizedCnecFillerMarginDecreaseRuleTest extends AbstractFillerTest { private RangeActionsOptimizationParameters rangeActionParameters; @BeforeEach - public void setUp() { + public void setUp() throws IOException { init(); // Add a cnec diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/searchtree/parameters/SearchTreeParametersTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/searchtree/parameters/SearchTreeParametersTest.java index efe5829fcc..2206d7ae2e 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/searchtree/parameters/SearchTreeParametersTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/searchtree/parameters/SearchTreeParametersTest.java @@ -11,7 +11,6 @@ import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.RaUsageLimits; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; -import com.powsybl.openrao.data.cracioapi.CracImporters; import com.powsybl.openrao.raoapi.parameters.ObjectiveFunctionParameters; import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; import com.powsybl.openrao.raoapi.parameters.RaoParameters; @@ -25,6 +24,7 @@ import org.mockito.Mockito; import java.io.File; +import java.io.IOException; import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; @@ -153,9 +153,9 @@ void testRaLimitsSetter() { } @Test - void testDecreaseRemedialActionUsageLimits() { - Crac crac = CracImporters.importCrac( - Paths.get(new File(Objects.requireNonNull(SearchTreeParametersTest.class.getResource("/crac/small-crac-with-comprehensive-usage-limits.json")).getFile()).toString()), + void testDecreaseRemedialActionUsageLimits() throws IOException { + Crac crac = Crac.read( + SearchTreeParametersTest.class.getResourceAsStream("/crac/small-crac-with-comprehensive-usage-limits.json"), Network.read(Paths.get(new File(Objects.requireNonNull(SearchTreeParametersTest.class.getResource("/network/small-network-2P.uct")).getFile()).toString())) ); diff --git a/tests/pom.xml b/tests/pom.xml index b76c6d1545..f96fbed993 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -116,12 +116,6 @@ ${project.version} test - - ${project.groupId} - open-rao-crac-io-api - ${project.version} - test - ${project.groupId} open-rao-crac-loopflow-extension diff --git a/tests/src/test/java/com/powsybl/openrao/tests/utils/Helpers.java b/tests/src/test/java/com/powsybl/openrao/tests/utils/Helpers.java index d0ee98226f..8300d68829 100644 --- a/tests/src/test/java/com/powsybl/openrao/tests/utils/Helpers.java +++ b/tests/src/test/java/com/powsybl/openrao/tests/utils/Helpers.java @@ -22,14 +22,10 @@ import com.powsybl.openrao.data.craccreation.creator.csaprofile.craccreator.CsaProfileCracCreationContext; import com.powsybl.openrao.data.craccreation.creator.cse.CseCracCreationContext; import com.powsybl.openrao.data.craccreation.creator.fbconstraint.craccreator.FbConstraintCreationContext; -import com.powsybl.openrao.data.cracioapi.CracExporters; -import com.powsybl.openrao.data.cracioapi.CracImporters; -import com.powsybl.openrao.data.craciojson.JsonImport; import com.powsybl.openrao.data.nativecracapi.NativeCrac; import com.powsybl.openrao.data.nativecracioapi.NativeCracImporter; import com.powsybl.openrao.data.nativecracioapi.NativeCracImporters; import com.powsybl.openrao.data.raoresultapi.RaoResult; -import com.powsybl.openrao.data.raoresultjson.RaoResultImporter; import com.powsybl.openrao.data.refprog.referenceprogram.ReferenceProgram; import com.powsybl.openrao.data.refprog.refprogxmlimporter.RefProgImporter; import com.powsybl.openrao.monitoring.anglemonitoring.AngleMonitoringResult; @@ -63,7 +59,7 @@ public static Network importNetwork(File networkFile, boolean useRdfId) { return Network.read(Paths.get(networkFile.toString()), LocalComputationManager.getDefault(), Suppliers.memoize(ImportConfig::load).get(), importParams); } - public static Pair importCrac(File cracFile, Network network, String timestamp, CracCreationParameters cracCreationParameters) { + public static Pair importCrac(File cracFile, Network network, String timestamp, CracCreationParameters cracCreationParameters) throws IOException { if (cracFile.getName().endsWith(".json")) { // for now, the only JSON format is the farao internal format return Pair.of(importCracFromInternalFormat(cracFile, network), null); @@ -75,13 +71,13 @@ public static Pair importCrac(File cracFile, Network public static Crac importCracFromInternalFormat(File cracFile, Network network) { try { - return roundTripOnCrac(new JsonImport().importCrac(new FileInputStream(cracFile), network), network); + return roundTripOnCrac(Crac.read(new FileInputStream(cracFile), network), network); } catch (IOException e) { throw new UncheckedIOException(e); } } - public static CracCreationContext importCracFromNativeCrac(File cracFile, Network network, String timestamp, CracCreationParameters cracCreationParameters) { + public static CracCreationContext importCracFromNativeCrac(File cracFile, Network network, String timestamp, CracCreationParameters cracCreationParameters) throws IOException { byte[] cracBytes = null; try (InputStream cracInputStream = new BufferedInputStream(new FileInputStream(cracFile))) { cracBytes = getBytesFromInputStream(cracInputStream); @@ -112,7 +108,7 @@ public static String getCracFormat(File cracFile) { return NativeCracImporters.findImporter(cracFile.getName(), new ByteArrayInputStream(cracBytes)).getFormat(); } - private static CracCreationContext roundTripOnCracCreationContext(CracCreationContext cracCreationContext, Network network) { + private static CracCreationContext roundTripOnCracCreationContext(CracCreationContext cracCreationContext, Network network) throws IOException { Crac crac = roundTripOnCrac(cracCreationContext.getCrac(), network); if (cracCreationContext instanceof FbConstraintCreationContext) { return new RoundTripFbConstraintCreationContext((FbConstraintCreationContext) cracCreationContext, crac); @@ -127,14 +123,14 @@ private static CracCreationContext roundTripOnCracCreationContext(CracCreationCo } } - private static Crac roundTripOnCrac(Crac crac, Network network) { + private static Crac roundTripOnCrac(Crac crac, Network network) throws IOException { // export Crac ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - CracExporters.exportCrac(crac, "Json", outputStream); + crac.write("JSON", outputStream); // import Crac ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); - return CracImporters.importCrac("crac.json", inputStream, network); + return Crac.read(inputStream, network); } public static ZonalData importUcteGlskFile(File glskFile, String timestamp, Network network) throws IOException { @@ -180,7 +176,7 @@ public static ReferenceProgram importRefProg(File refProgFile, String timestamp) public static RaoResult importRaoResult(File raoResultFile) throws IOException { InputStream inputStream = new FileInputStream(raoResultFile); - RaoResult raoResult = new RaoResultImporter().importRaoResult(inputStream, CommonTestData.getCrac()); + RaoResult raoResult = RaoResult.read(inputStream, CommonTestData.getCrac()); inputStream.close(); return raoResult; } diff --git a/tests/src/test/java/com/powsybl/openrao/tests/utils/RaoUtils.java b/tests/src/test/java/com/powsybl/openrao/tests/utils/RaoUtils.java index c5a89d9a4c..f027f8fbfb 100644 --- a/tests/src/test/java/com/powsybl/openrao/tests/utils/RaoUtils.java +++ b/tests/src/test/java/com/powsybl/openrao/tests/utils/RaoUtils.java @@ -14,8 +14,6 @@ import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; import com.powsybl.openrao.data.cracloopflowextension.LoopFlowThresholdAdder; import com.powsybl.openrao.data.raoresultapi.RaoResult; -import com.powsybl.openrao.data.raoresultjson.RaoResultExporter; -import com.powsybl.openrao.data.raoresultjson.RaoResultImporter; import com.powsybl.openrao.data.refprog.referenceprogram.ReferenceProgram; import com.powsybl.openrao.raoapi.Rao; import com.powsybl.openrao.raoapi.RaoInput; @@ -26,6 +24,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.util.Objects; import java.util.Optional; import java.util.Set; @@ -62,7 +61,7 @@ private static Optional getTerminalCountry(Terminal terminal) { } public static RaoResult runRao(String contingencyId, InstantKind instantKind, String raoType, Double loopflowAsPmaxPercentage, - Integer timeLimitInSeconds) { + Integer timeLimitInSeconds) throws IOException { RaoParameters raoParameters = CommonTestData.getRaoParameters(); ZonalData glsks = CommonTestData.getGlsks(); // Rao with loop-flows @@ -76,7 +75,7 @@ public static RaoResult runRao(String contingencyId, InstantKind instantKind, St private static RaoResult runRaoInMemory(Rao.Runner raoRunner, Network network, Crac crac, String contingencyId, InstantKind instantKind, ZonalData glsks, ReferenceProgram referenceProgram, RaoParameters config, - Integer timeLimitInSeconds) { + Integer timeLimitInSeconds) throws IOException { RaoInput.RaoInputBuilder raoInputBuilder; if (contingencyId == null) { @@ -113,14 +112,14 @@ private static RaoResult runRaoInMemory(Rao.Runner raoRunner, Network network, C return roundTripOnRaoResult(raoResult, crac); } - private static RaoResult roundTripOnRaoResult(RaoResult raoResult, Crac crac) { + private static RaoResult roundTripOnRaoResult(RaoResult raoResult, Crac crac) throws IOException { // export RaoResult ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - new RaoResultExporter().export(raoResult, crac, Set.of(Unit.AMPERE, Unit.MEGAWATT), outputStream); + raoResult.write("JSON", crac, Set.of(Unit.AMPERE, Unit.MEGAWATT), outputStream); // import RaoResult ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); - return new RaoResultImporter().importRaoResult(inputStream, crac); + return RaoResult.read(inputStream, crac); } } From 37a7605b6cddb7c78e2c58f54dc572d3604b5421 Mon Sep 17 00:00:00 2001 From: Thomas Bouquet <63302082+bqth29@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:34:49 +0200 Subject: [PATCH 3/8] [CSA] Fixes for Angle and Voltage CNECs import (#1039) * Fixes for Angle and Voltage CNECs Signed-off-by: Thomas Bouquet * Rollback configuration Signed-off-by: Thomas Bouquet --------- Signed-off-by: Thomas Bouquet --- .../creator/csaprofile/craccreator/cnec/AngleCnecCreator.java | 2 +- .../csaprofile/craccreator/cnec/VoltageCnecCreator.java | 2 +- .../csaprofile/craccreator/CsaProfileCracCreationTestUtil.java | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/cnec/AngleCnecCreator.java b/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/cnec/AngleCnecCreator.java index 523956f8c3..a0cf4107b9 100644 --- a/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/cnec/AngleCnecCreator.java +++ b/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/cnec/AngleCnecCreator.java @@ -70,7 +70,7 @@ private String checkAngleNetworkElementAndGetId(String terminalId) { if (networkElement == null) { throw new OpenRaoImportException(ImportStatus.ELEMENT_NOT_FOUND_IN_NETWORK, writeAssessedElementIgnoredReasonMessage("the angle limit equipment " + terminalId + " is missing in network")); } - if (!networkElement.getType().equals(IdentifiableType.BUS)) { + if (!networkElement.getType().equals(IdentifiableType.BUS) && !networkElement.getType().equals(IdentifiableType.BUSBAR_SECTION)) { throw new OpenRaoImportException(ImportStatus.INCONSISTENCY_IN_DATA, writeAssessedElementIgnoredReasonMessage("the network element " + networkElement.getId() + " is not a bus bar section")); } return networkElement.getId(); diff --git a/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/cnec/VoltageCnecCreator.java b/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/cnec/VoltageCnecCreator.java index 4935574c60..0d26b14a16 100644 --- a/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/cnec/VoltageCnecCreator.java +++ b/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/cnec/VoltageCnecCreator.java @@ -67,7 +67,7 @@ private void addVoltageLimit(VoltageCnecAdder voltageCnecAdder) { throw new OpenRaoImportException(ImportStatus.ELEMENT_NOT_FOUND_IN_NETWORK, writeAssessedElementIgnoredReasonMessage("the voltage limit equipment " + nativeVoltageLimit.equipment() + " is missing in network")); } - if (!networkElement.getType().equals(IdentifiableType.BUS)) { + if (!networkElement.getType().equals(IdentifiableType.BUS) && !networkElement.getType().equals(IdentifiableType.BUSBAR_SECTION)) { throw new OpenRaoImportException(ImportStatus.INCONSISTENCY_IN_DATA, writeAssessedElementIgnoredReasonMessage("the network element " + networkElement.getId() + " is not a bus bar section")); } diff --git a/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/CsaProfileCracCreationTestUtil.java b/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/CsaProfileCracCreationTestUtil.java index 538dda4f4a..13f7343b51 100644 --- a/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/CsaProfileCracCreationTestUtil.java +++ b/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/CsaProfileCracCreationTestUtil.java @@ -3,6 +3,7 @@ import ch.qos.logback.classic.Logger; import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.core.read.ListAppender; +import com.powsybl.cgmes.conversion.CgmesImport; import com.powsybl.openrao.commons.Unit; import com.powsybl.contingency.ContingencyElement; import com.powsybl.contingency.Contingency; @@ -279,7 +280,7 @@ public static CsaProfileCracCreationContext getCsaCracCreationContext(String csa public static Network getNetworkFromResource(String filename) { Properties importParams = new Properties(); - importParams.put("iidm.import.cgmes.cgm-with-subnetworks", false); + importParams.put(CgmesImport.IMPORT_CGM_WITH_SUBNETWORKS, false); return Network.read(Paths.get(new File(CsaProfileCracCreationTestUtil.class.getResource(filename).getFile()).toString()), LocalComputationManager.getDefault(), Suppliers.memoize(ImportConfig::load).get(), importParams); } } From f0a6cb986cfff08e374171eb35171f0e373e9087 Mon Sep 17 00:00:00 2001 From: pjeanmarie <72982611+pjeanmarie@users.noreply.github.com> Date: Thu, 27 Jun 2024 15:47:46 +0200 Subject: [PATCH 4/8] Use powsybl's twosides instead of Side (#1027) --- .../parameters/CracCreationParameters.java | 16 +- .../JsonCracCreationParametersConstants.java | 36 +- .../cim/craccreator/CimCracCreator.java | 4 +- .../cnec/MonitoredSeriesCreator.java | 29 +- .../cim/craccreator/CimCracCreatorTest.java | 114 ++-- .../craccreator/cnec/AbstractCnecCreator.java | 6 +- .../craccreator/cnec/FlowCnecCreator.java | 70 +-- .../CsaProfileCracCreationTestUtil.java | 10 +- .../cnec/FlowCnecCreationTest.java | 342 +++++------ .../cnec/FlowCnecInstantHelperTest.java | 2 +- .../csaprofile/craccreator/cnec/MnecTest.java | 28 +- .../GroupRemedialActionTest.java | 12 +- .../OnConstraintUsageRuleHelperTest.java | 38 +- .../PstRangeActionCreationTest.java | 54 +- .../RemedialActionCreationTest.java | 336 +++++------ .../criticalbranch/CriticalBranchReader.java | 23 +- .../TCriticalBranchesAdder.java | 6 +- .../TMonitoredElementsAdder.java | 6 +- .../creator/cse/CseCracCreatorTest.java | 74 +-- .../cse/CseCracCreatorWithMneTest.java | 28 +- .../craccreator/CriticalBranchReader.java | 23 +- .../craccreator/FbConstraintCracCreator.java | 4 +- .../FbConstraintCracCreatorTest.java | 90 +-- .../JsonSerializationConstants.java | 61 +- .../BranchThresholdArrayDeserializer.java | 14 +- .../FlowCnecArrayDeserializer.java | 10 +- .../BranchThresholdSerializer.java | 2 +- .../serializers/FlowCnecSerializer.java | 6 +- .../data/craciojson/CracImportExportTest.java | 20 +- .../JsonRetrocompatibilityTest.java | 26 +- .../JsonSerializationConstantsTest.java | 20 +- .../retrocompatibility/v2/crac-v2.4.json | 20 +- .../openrao/data/cracapi/cnec/BranchCnec.java | 17 +- .../openrao/data/cracapi/cnec/FlowCnec.java | 7 +- .../data/cracapi/cnec/FlowCnecAdder.java | 5 +- .../openrao/data/cracapi/cnec/Side.java | 42 -- .../cracapi/threshold/BranchThreshold.java | 6 +- .../threshold/BranchThresholdAdder.java | 4 +- .../openrao/data/cracapi/SideTest.java | 27 - .../data/cracimpl/AbstractBranchCnec.java | 8 +- .../data/cracimpl/BranchBoundsCache.java | 28 +- .../cracimpl/BranchThresholdAdderImpl.java | 6 +- .../data/cracimpl/BranchThresholdImpl.java | 8 +- .../data/cracimpl/FlowCnecAdderImpl.java | 18 +- .../openrao/data/cracimpl/FlowCnecImpl.java | 12 +- .../BranchThresholdAdderImplTest.java | 26 +- .../openrao/data/cracimpl/CracImplTest.java | 24 +- .../data/cracimpl/FlowCnecAdderImplTest.java | 90 +-- .../data/cracimpl/FlowCnecImplTest.java | 450 +++++++------- .../cracimpl/OnConstraintAdderImplTest.java | 10 +- ...nFlowConstraintInCountryAdderImplTest.java | 6 +- .../cracimpl/utils/CommonCracCreation.java | 20 +- .../utils/ExhaustiveCracCreation.java | 33 +- .../LoopFlowThresholdImpl.java | 14 +- ...LoopFlowThresholdImplImportExportTest.java | 8 +- .../LoopFlowThresholdAdderImplTest.java | 4 +- .../openrao/data/cracutil/CracValidator.java | 10 +- .../data/cracutil/CracValidatorTest.java | 44 +- .../openrao/data/raoresultapi/RaoResult.java | 10 +- .../data/raoresultapi/RaoResultClone.java | 10 +- .../data/raoresultapi/MockRaoResult.java | 10 +- .../data/raoresultapi/RaoResultCloneTest.java | 126 ++-- .../ElementaryFlowCnecResult.java | 28 +- .../data/raoresultimpl/RaoResultImpl.java | 10 +- .../ElementaryFlowCnecResultTest.java | 74 +-- .../raoresultimpl/FlowCnecResultTest.java | 24 +- .../raoresultimpl/RangeActionResultTest.java | 8 +- .../data/raoresultimpl/RaoResultImplTest.java | 58 +- .../utils/ExhaustiveRaoResultCreation.java | 8 +- .../raoresultjson/RaoResultJsonConstants.java | 31 +- .../FlowCnecResultArrayDeserializer.java | 34 +- .../raoresultjson/deserializers/Utils.java | 2 +- .../FlowCnecResultArraySerializer.java | 20 +- .../ImporterRetrocompatibilityTest.java | 213 +++---- .../raoresultjson/RaoResultRoundTripTest.java | 162 ++--- .../v1.5/crac-for-rao-result-v1.5.json | 410 +++++++++++++ .../v1.5/rao-result-v1.5.json | 552 ++++++++++++++++++ .../corecneexporter/CoreCneCnecsCreator.java | 16 +- .../CoreCneCnecsCreatorTest.java | 22 +- .../CoreCneRemedialActionsCreatorTest.java | 4 +- .../SweMonitoredSeriesCreator.java | 8 +- .../SweMonitoredSeriesCreatorTest.java | 14 +- docs/input-data/crac/creation-context.md | 4 +- docs/input-data/crac/creation-parameters.md | 4 +- docs/input-data/crac/csa.md | 4 +- docs/input-data/crac/json.md | 18 +- docs/output-data/rao-logs/example.md | 4 +- docs/output-data/rao-result/flow-cnecs.md | 72 +-- docs/tutorial.md | 14 +- .../impl/FlowbasedComputationImpl.java | 10 +- .../impl/FlowbasedComputationImplTest.java | 26 +- .../loopflowcomputation/LoopFlowResult.java | 14 +- .../loopflowcomputation/ExampleGenerator.java | 62 +- .../LoopFlowComputationImplTest.java | 104 ++-- .../LoopFlowResultTest.java | 12 +- .../castor/algorithm/AutomatonSimulator.java | 22 +- .../commons/AbsolutePtdfSumsComputation.java | 10 +- .../searchtreerao/commons/RaoLogger.java | 16 +- .../searchtreerao/commons/RaoUtil.java | 4 +- .../adapter/BranchResultAdapterImpl.java | 20 +- .../BasicMarginEvaluator.java | 4 +- .../BasicRelativeMarginEvaluator.java | 4 +- .../LoopFlowViolationCostEvaluator.java | 4 +- .../MarginEvaluator.java | 4 +- ...torWithMarginDecreaseUnoptimizedCnecs.java | 4 +- .../MinMarginEvaluator.java | 10 +- .../algorithms/BestTapFinder.java | 4 +- .../algorithms/fillers/CoreProblemFiller.java | 6 +- .../algorithms/fillers/MaxLoopFlowFiller.java | 8 +- .../fillers/MaxMinRelativeMarginFiller.java | 4 +- .../linearproblem/LinearProblem.java | 42 +- .../LinearProblemIdGenerator.java | 22 +- .../searchtreerao/result/api/FlowResult.java | 20 +- .../result/api/SensitivityResult.java | 6 +- .../impl/AutomatonPerimeterResultImpl.java | 14 +- .../impl/CurativeWithSecondPraoResult.java | 14 +- .../result/impl/EmptyFlowResultImpl.java | 10 +- .../result/impl/FailedRaoResultImpl.java | 10 +- .../result/impl/FlowResultFromMapImpl.java | 18 +- .../result/impl/FlowResultImpl.java | 10 +- ...IteratingLinearOptimizationResultImpl.java | 14 +- .../impl/OneStateOnlyRaoResultImpl.java | 10 +- .../result/impl/PerimeterResultImpl.java | 14 +- .../PrePerimeterSensitivityResultImpl.java | 18 +- .../PreventiveAndCurativesRaoResultImpl.java | 10 +- .../result/impl/SensitivityResultImpl.java | 6 +- .../impl/SkippedOptimizationResultImpl.java | 14 +- .../result/impl/UnoptimizedRaoResultImpl.java | 10 +- .../searchtree/algorithms/Leaf.java | 14 +- .../searchtree/algorithms/SearchTree.java | 4 +- .../algorithm/AutomatonSimulatorTest.java | 86 +-- .../algorithm/CastorFullOptimizationTest.java | 92 +-- .../PrePerimeterSensitivityAnalysisTest.java | 14 +- .../castor/algorithm/StateTreeTest.java | 28 +- .../AbsolutePtdfSumsComputationTest.java | 20 +- .../searchtreerao/commons/RaoLoggerTest.java | 6 +- .../searchtreerao/commons/RaoUtilTest.java | 48 +- .../adapter/FlowResultAdapterImplTest.java | 56 +- .../LoopFlowViolationCostEvaluatorTest.java | 10 +- ...ithMarginDecreaseUnoptimizedCnecsTest.java | 16 +- .../AbstractOptimizationPerimeterTest.java | 12 +- .../AutoOptimizationPerimeterTest.java | 10 +- .../algorithms/BestTapFinderTest.java | 18 +- .../algorithms/LinearProblemTest.java | 64 +- .../fillers/AbstractFillerTest.java | 10 +- .../fillers/CoreProblemFillerTest.java | 124 ++-- .../algorithms/fillers/FillersUtilTest.java | 32 +- .../fillers/MaxLoopFlowFillerTest.java | 70 +-- .../fillers/MaxMinMarginFillerTest.java | 20 +- .../MaxMinRelativeMarginFillerTest.java | 30 +- .../algorithms/fillers/MnecFillerTest.java | 76 +-- ...mizedCnecFillerMarginDecreaseRuleTest.java | 96 +-- .../AutomatonPerimeterResultImplTest.java | 60 +- .../result/impl/EmptyFlowResultImplTest.java | 18 +- .../result/impl/FailedRaoResultImplTest.java | 12 +- .../impl/FlowResultFromMapImplTest.java | 82 +-- .../result/impl/FlowResultImplTest.java | 62 +- .../impl/OneStateOnlyRaoResultImplTest.java | 160 ++--- .../result/impl/PerimeterResultImplTest.java | 40 +- ...PrePerimeterSensitivityResultImplTest.java | 60 +- ...eventiveAndCurativesRaoResultImplTest.java | 172 +++--- .../RangeActionActivationResultImplTest.java | 4 +- .../impl/SensitivityResultImplTest.java | 20 +- .../SkippedOptimizationResultImplTest.java | 4 +- .../impl/UnoptimizedRaoResultImplTest.java | 86 +-- .../searchtree/algorithms/LeafTest.java | 60 +- .../NetworkActionCombinationsUtils.java | 4 +- .../searchtree/algorithms/SearchTreeTest.java | 10 +- .../sensitivityanalysis/LoadflowProvider.java | 16 +- .../PtdfSensitivityProvider.java | 8 +- .../SystematicSensitivityResult.java | 46 +- .../HvdcRangeActionSensiHandler.java | 4 +- .../InjectionRangeActionSensiHandler.java | 4 +- .../PstRangeActionSensiHandler.java | 4 +- .../RangeActionSensiHandler.java | 4 +- .../AppliedRemedialActionsTest.java | 6 +- .../LoadflowProviderTest.java | 6 +- .../RangeActionSensitivityProviderTest.java | 20 +- .../SystematicSensitivityAdapterTest.java | 154 ++--- .../SystematicSensitivityInterfaceTest.java | 26 +- .../SystematicSensitivityResultTest.java | 88 +-- .../HvdcRangeActionSensiHandlerTest.java | 10 +- .../InjectionRangeActionSensiHandlerTest.java | 22 +- .../PstRangeActionSensiHandlerTest.java | 10 +- .../openrao/tests/steps/CracImportSteps.java | 21 +- .../tests/steps/SearchTreeRaoSteps.java | 22 +- .../US15_3.feature | 4 +- .../US15_4.feature | 8 +- .../epic1_PRA_network_actions/US1_2.feature | 12 +- .../epic3_cnec_direction/US3_1.feature | 18 +- .../tests/features/epic4_dc_mw/US4_1.feature | 12 +- .../epic90_robust_crac/US90_7.feature | 8 +- .../CracCreationParameters_default.json | 2 +- ...racCreationParameters_MonitorLeftSide.json | 2 +- .../epic15/us15_13_4.json | 2 +- .../epic15/us_15_13_3.json | 2 +- .../epic15/us_15_2_7.json | 2 +- .../epic19/us19_8_1.json | 2 +- .../epic19/us19_8_11.json | 2 +- .../epic19/us19_8_3&4.json | 2 +- .../epic19/us19_8_5.json | 2 +- .../epic19/us19_8_7.json | 2 +- .../epic19/us19_8_9.json | 2 +- 203 files changed, 4161 insertions(+), 3249 deletions(-) delete mode 100644 data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/cnec/Side.java delete mode 100644 data/crac/crac-api/src/test/java/com/powsybl/openrao/data/cracapi/SideTest.java create mode 100644 data/rao-result/rao-result-json/src/test/resources/retrocompatibility/v1.5/crac-for-rao-result-v1.5.json create mode 100644 data/rao-result/rao-result-json/src/test/resources/retrocompatibility/v1.5/rao-result-v1.5.json diff --git a/data/crac-creation/crac-creator-api/src/main/java/com/powsybl/openrao/data/craccreation/creator/api/parameters/CracCreationParameters.java b/data/crac-creation/crac-creator-api/src/main/java/com/powsybl/openrao/data/craccreation/creator/api/parameters/CracCreationParameters.java index 91bcde4db1..c327b36186 100644 --- a/data/crac-creation/crac-creator-api/src/main/java/com/powsybl/openrao/data/craccreation/creator/api/parameters/CracCreationParameters.java +++ b/data/crac-creation/crac-creator-api/src/main/java/com/powsybl/openrao/data/craccreation/creator/api/parameters/CracCreationParameters.java @@ -8,7 +8,7 @@ import com.powsybl.openrao.data.cracapi.CracFactory; import com.powsybl.openrao.data.cracapi.RaUsageLimits; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.google.common.base.Suppliers; import com.powsybl.commons.config.PlatformConfig; import com.powsybl.commons.extensions.AbstractExtendable; @@ -42,17 +42,17 @@ public interface ConfigLoader> exten private String cracFactoryName = DEFAULT_CRAC_FACTORY_NAME; public enum MonitoredLineSide { - MONITOR_LINES_ON_LEFT_SIDE(Set.of(Side.LEFT)), - MONITOR_LINES_ON_RIGHT_SIDE(Set.of(Side.RIGHT)), - MONITOR_LINES_ON_BOTH_SIDES(Set.of(Side.LEFT, Side.RIGHT)); + MONITOR_LINES_ON_SIDE_ONE(Set.of(TwoSides.ONE)), + MONITOR_LINES_ON_SIDE_TWO(Set.of(TwoSides.TWO)), + MONITOR_LINES_ON_BOTH_SIDES(Set.of(TwoSides.ONE, TwoSides.TWO)); - private final Set monitoredSides; + private final Set monitoredSides; - MonitoredLineSide(Set monitoredSides) { + MonitoredLineSide(Set monitoredSides) { this.monitoredSides = monitoredSides; } - Set getMonitoredSides() { + Set getMonitoredSides() { return monitoredSides; } } @@ -88,7 +88,7 @@ public CracFactory getCracFactory() { return CracFactory.find(cracFactoryName); } - public Set getDefaultMonitoredSides() { + public Set getDefaultMonitoredSides() { return defaultMonitoredLineSide.getMonitoredSides(); } diff --git a/data/crac-creation/crac-creator-api/src/main/java/com/powsybl/openrao/data/craccreation/creator/api/parameters/JsonCracCreationParametersConstants.java b/data/crac-creation/crac-creator-api/src/main/java/com/powsybl/openrao/data/craccreation/creator/api/parameters/JsonCracCreationParametersConstants.java index e735367d36..1021da08cc 100644 --- a/data/crac-creation/crac-creator-api/src/main/java/com/powsybl/openrao/data/craccreation/creator/api/parameters/JsonCracCreationParametersConstants.java +++ b/data/crac-creation/crac-creator-api/src/main/java/com/powsybl/openrao/data/craccreation/creator/api/parameters/JsonCracCreationParametersConstants.java @@ -27,7 +27,9 @@ public final class JsonCracCreationParametersConstants { static final String DEFAULT_MONITORED_LINE_SIDE = "default-monitored-line-side"; private static final String MONITOR_LINES_ON_LEFT_SIDE_TEXT = "monitor-lines-on-left-side"; + private static final String MONITOR_LINES_ON_SIDE_ONE_TEXT = "monitor-lines-on-side-one"; private static final String MONITOR_LINES_ON_RIGHT_SIDE_TEXT = "monitor-lines-on-right-side"; + private static final String MONITOR_LINES_ON_SIDE_TWO_TEXT = "monitor-lines-on-side-two"; private static final String MONITOR_LINES_ON_BOTH_SIDES_TEXT = "monitor-lines-on-both-sides"; public static final String RA_USAGE_LIMITS_PER_INSTANT = "ra-usage-limits-per-instant"; public static final String INSTANT = "instant"; @@ -42,29 +44,23 @@ private JsonCracCreationParametersConstants() { } static String serializeMonitoredLineSide(CracCreationParameters.MonitoredLineSide monitoredLineSide) { - switch (monitoredLineSide) { - case MONITOR_LINES_ON_LEFT_SIDE: - return MONITOR_LINES_ON_LEFT_SIDE_TEXT; - case MONITOR_LINES_ON_RIGHT_SIDE: - return MONITOR_LINES_ON_RIGHT_SIDE_TEXT; - case MONITOR_LINES_ON_BOTH_SIDES: - return MONITOR_LINES_ON_BOTH_SIDES_TEXT; - default: - throw new OpenRaoException(String.format("Unknown monitored line side: %s", monitoredLineSide)); - } + return switch (monitoredLineSide) { + case MONITOR_LINES_ON_SIDE_ONE -> MONITOR_LINES_ON_SIDE_ONE_TEXT; + case MONITOR_LINES_ON_SIDE_TWO -> MONITOR_LINES_ON_SIDE_TWO_TEXT; + case MONITOR_LINES_ON_BOTH_SIDES -> MONITOR_LINES_ON_BOTH_SIDES_TEXT; + }; } static CracCreationParameters.MonitoredLineSide deserializeMonitoredLineSide(String monitoredLineSide) { - switch (monitoredLineSide) { - case MONITOR_LINES_ON_LEFT_SIDE_TEXT: - return CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_LEFT_SIDE; - case MONITOR_LINES_ON_RIGHT_SIDE_TEXT: - return CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_RIGHT_SIDE; - case MONITOR_LINES_ON_BOTH_SIDES_TEXT: - return CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_BOTH_SIDES; - default: - throw new OpenRaoException(String.format("Unknown monitored line side: %s", monitoredLineSide)); - } + return switch (monitoredLineSide) { + case MONITOR_LINES_ON_SIDE_ONE_TEXT, MONITOR_LINES_ON_LEFT_SIDE_TEXT -> + CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_SIDE_ONE; + case MONITOR_LINES_ON_SIDE_TWO_TEXT, MONITOR_LINES_ON_RIGHT_SIDE_TEXT -> + CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_SIDE_TWO; + case MONITOR_LINES_ON_BOTH_SIDES_TEXT -> + CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_BOTH_SIDES; + default -> throw new OpenRaoException(String.format("Unknown monitored line side: %s", monitoredLineSide)); + }; } static void serializeRaUsageLimits(CracCreationParameters parameters, JsonGenerator jsonGenerator) throws IOException { diff --git a/data/crac-creation/crac-creator-cim/src/main/java/com/powsybl/openrao/data/craccreation/creator/cim/craccreator/CimCracCreator.java b/data/crac-creation/crac-creator-cim/src/main/java/com/powsybl/openrao/data/craccreation/creator/cim/craccreator/CimCracCreator.java index 088e975ed7..b3dff0caf5 100644 --- a/data/crac-creation/crac-creator-cim/src/main/java/com/powsybl/openrao/data/craccreation/creator/cim/craccreator/CimCracCreator.java +++ b/data/crac-creation/crac-creator-cim/src/main/java/com/powsybl/openrao/data/craccreation/creator/cim/craccreator/CimCracCreator.java @@ -9,7 +9,7 @@ import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.InstantKind; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.craccreation.creator.api.CracCreator; import com.powsybl.openrao.data.craccreation.creator.api.parameters.CracCreationParameters; import com.powsybl.openrao.data.craccreation.creator.cim.CimCrac; @@ -98,7 +98,7 @@ private void createContingencies() { new CimContingencyCreator(cimTimeSeries, crac, network, creationContext).createAndAddContingencies(); } - private void createCnecs(Set defaultMonitoredSides) { + private void createCnecs(Set defaultMonitoredSides) { new MonitoredSeriesCreator(cimTimeSeries, network, creationContext, defaultMonitoredSides).createAndAddMonitoredSeries(); } diff --git a/data/crac-creation/crac-creator-cim/src/main/java/com/powsybl/openrao/data/craccreation/creator/cim/craccreator/cnec/MonitoredSeriesCreator.java b/data/crac-creation/crac-creator-cim/src/main/java/com/powsybl/openrao/data/craccreation/creator/cim/craccreator/cnec/MonitoredSeriesCreator.java index c539960077..e051b45d80 100644 --- a/data/crac-creation/crac-creator-cim/src/main/java/com/powsybl/openrao/data/craccreation/creator/cim/craccreator/cnec/MonitoredSeriesCreator.java +++ b/data/crac-creation/crac-creator-cim/src/main/java/com/powsybl/openrao/data/craccreation/creator/cim/craccreator/cnec/MonitoredSeriesCreator.java @@ -14,7 +14,7 @@ import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.InstantKind; import com.powsybl.openrao.data.cracapi.cnec.FlowCnecAdder; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.craccreation.creator.api.ImportStatus; import com.powsybl.openrao.data.craccreation.creator.cim.craccreator.CimCracCreationContext; import com.powsybl.openrao.data.craccreation.creator.cim.craccreator.CimCracUtils; @@ -22,7 +22,6 @@ import com.powsybl.openrao.data.craccreation.util.cgmes.CgmesBranchHelper; import com.powsybl.iidm.network.Branch; import com.powsybl.iidm.network.Network; -import com.powsybl.iidm.network.TwoSides; import org.apache.commons.lang3.StringUtils; import java.util.*; @@ -41,9 +40,9 @@ public class MonitoredSeriesCreator { private final List cimTimeSeries; private Map monitoredSeriesCreationContexts; private final CimCracCreationContext cracCreationContext; - private final Set defaultMonitoredSides; + private final Set defaultMonitoredSides; - public MonitoredSeriesCreator(List cimTimeSeries, Network network, CimCracCreationContext cracCreationContext, Set defaultMonitoredSides) { + public MonitoredSeriesCreator(List cimTimeSeries, Network network, CimCracCreationContext cracCreationContext, Set defaultMonitoredSides) { this.cimTimeSeries = cimTimeSeries; this.crac = cracCreationContext.getCrac(); this.network = network; @@ -301,7 +300,7 @@ private void addCnecsOnContingency(String cnecNativeId, CgmesBranchHelper branch // If a CNEC with the same ID has already been created, we assume that the 2 CNECs are the same // (we know network element and state are the same, we assume that thresholds are the same. // This is true if the TSO is consistent in the definition of its CNECs; and two different TSOs can only - // share tielines, but those are distinguished by the RIGHT/LEFT label) + // share tielines, but those are distinguished by the TWO/ONE label) cracCreationContext.getCreationReport().warn( String.format("Multiple CNECs on same network element (%s) and same state (%s%s%s) have been detected. Only one CNEC will be created.", branchHelper.getBranch().getId(), contingencyId, Objects.isNull(contingency) ? "" : " - ", instant) ); @@ -312,18 +311,18 @@ private void addCnecsOnContingency(String cnecNativeId, CgmesBranchHelper branch private String addThreshold(FlowCnecAdder flowCnecAdder, Unit unit, CgmesBranchHelper branchHelper, String cnecId, String direction, double threshold) { String modifiedCnecId = cnecId; - Set monitoredSides = defaultMonitoredSides; + Set monitoredSides = defaultMonitoredSides; if (branchHelper.isHalfLine()) { - modifiedCnecId += " - " + (branchHelper.getTieLineSide() == TwoSides.ONE ? "LEFT" : "RIGHT"); - monitoredSides = Set.of(Side.fromIidmSide(branchHelper.getTieLineSide())); + modifiedCnecId += " - " + (branchHelper.getTieLineSide() == TwoSides.ONE ? "ONE" : "TWO"); + monitoredSides = Set.of(branchHelper.getTieLineSide()); } else if (unit.equals(Unit.AMPERE) && Math.abs(branchHelper.getBranch().getTerminal1().getVoltageLevel().getNominalV() - branchHelper.getBranch().getTerminal2().getVoltageLevel().getNominalV()) > 1.) { // If unit is absolute amperes, monitor low voltage side monitoredSides = branchHelper.getBranch().getTerminal1().getVoltageLevel().getNominalV() <= branchHelper.getBranch().getTerminal2().getVoltageLevel().getNominalV() ? - Set.of(Side.LEFT) : Set.of(Side.RIGHT); + Set.of(TwoSides.ONE) : Set.of(TwoSides.TWO); } else if (unit.equals(Unit.PERCENT_IMAX)) { // If unit is %Imax, check that Imax exists - monitoredSides = monitoredSides.stream().filter(side -> hasCurrentLimit(branchHelper.getBranch(), side.iidmSide())).collect(Collectors.toSet()); + monitoredSides = monitoredSides.stream().filter(side -> hasCurrentLimit(branchHelper.getBranch(), side)).collect(Collectors.toSet()); if (monitoredSides.isEmpty()) { throw new OpenRaoException(String.format("Cannot create any PERCENT_IMAX threshold on branch %s, as it holds no current limit at the wanted side", branchHelper.getIdInNetwork())); } @@ -343,7 +342,7 @@ private String addThreshold(FlowCnecAdder flowCnecAdder, Unit unit, CgmesBranchH return modifiedCnecId; } - private void addThreshold(FlowCnecAdder flowCnecAdder, Unit unit, Double min, Double max, Set sides) { + private void addThreshold(FlowCnecAdder flowCnecAdder, Unit unit, Double min, Double max, Set sides) { sides.forEach(side -> flowCnecAdder.newThreshold() .withUnit(unit) @@ -358,8 +357,8 @@ private void setNominalVoltage(FlowCnecAdder flowCnecAdder, CgmesBranchHelper br double voltageLevelLeft = branchHelper.getBranch().getTerminal1().getVoltageLevel().getNominalV(); double voltageLevelRight = branchHelper.getBranch().getTerminal2().getVoltageLevel().getNominalV(); if (voltageLevelLeft > 1e-6 && voltageLevelRight > 1e-6) { - flowCnecAdder.withNominalVoltage(voltageLevelLeft, Side.LEFT); - flowCnecAdder.withNominalVoltage(voltageLevelRight, Side.RIGHT); + flowCnecAdder.withNominalVoltage(voltageLevelLeft, TwoSides.ONE); + flowCnecAdder.withNominalVoltage(voltageLevelRight, TwoSides.TWO); } else { throw new OpenRaoException(String.format("Voltage level for branch %s is 0 in network.", branchHelper.getBranch().getId())); } @@ -369,8 +368,8 @@ private void setCurrentsLimit(FlowCnecAdder flowCnecAdder, CgmesBranchHelper bra Double currentLimitLeft = getCurrentLimit(branchHelper.getBranch(), TwoSides.ONE); Double currentLimitRight = getCurrentLimit(branchHelper.getBranch(), TwoSides.TWO); if (Objects.nonNull(currentLimitLeft) && Objects.nonNull(currentLimitRight)) { - flowCnecAdder.withIMax(currentLimitLeft, Side.LEFT); - flowCnecAdder.withIMax(currentLimitRight, Side.RIGHT); + flowCnecAdder.withIMax(currentLimitLeft, TwoSides.ONE); + flowCnecAdder.withIMax(currentLimitRight, TwoSides.TWO); } else { throw new OpenRaoException(String.format("Unable to get branch current limits from network for branch %s", branchHelper.getBranch().getId())); } diff --git a/data/crac-creation/crac-creator-cim/src/test/java/com/powsybl/openrao/data/craccreation/creator/cim/craccreator/CimCracCreatorTest.java b/data/crac-creation/crac-creator-cim/src/test/java/com/powsybl/openrao/data/craccreation/creator/cim/craccreator/CimCracCreatorTest.java index c06f600f4d..cc10f4fc84 100644 --- a/data/crac-creation/crac-creator-cim/src/test/java/com/powsybl/openrao/data/craccreation/creator/cim/craccreator/CimCracCreatorTest.java +++ b/data/crac-creation/crac-creator-cim/src/test/java/com/powsybl/openrao/data/craccreation/creator/cim/craccreator/CimCracCreatorTest.java @@ -12,7 +12,7 @@ import com.powsybl.openrao.data.cracapi.*; import com.powsybl.openrao.data.cracapi.cnec.AngleCnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.*; import com.powsybl.openrao.data.cracapi.range.RangeType; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; @@ -101,7 +101,7 @@ private void setUp(String fileName, Network network, OffsetDateTime parametrable private void setUpWithGroupId(String fileName, Network network, OffsetDateTime parametrableOffsetDateTime, List> alignedRangeActions) { CracCreationParameters cracCreationParameters = new CracCreationParameters(); - cracCreationParameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_LEFT_SIDE); + cracCreationParameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_SIDE_ONE); cracCreationParameters = Mockito.spy(cracCreationParameters); CimCracCreationParameters cimCracCreationParameters = Mockito.mock(CimCracCreationParameters.class); Mockito.when(cracCreationParameters.getExtension(CimCracCreationParameters.class)).thenReturn(cimCracCreationParameters); @@ -123,7 +123,7 @@ private void setUpWithGroupId(String fileName, Network network, OffsetDateTime p private void setUpWithSpeed(String fileName, Network network, OffsetDateTime parametrableOffsetDateTime, Set rangeActionSpeeds) { CracCreationParameters cracCreationParameters = new CracCreationParameters(); - cracCreationParameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_LEFT_SIDE); + cracCreationParameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_SIDE_ONE); cracCreationParameters = Mockito.spy(cracCreationParameters); CimCracCreationParameters cimCracCreationParameters = Mockito.mock(CimCracCreationParameters.class); Mockito.when(cracCreationParameters.getExtension(CimCracCreationParameters.class)).thenReturn(cimCracCreationParameters); @@ -142,7 +142,7 @@ private void setUpWithSpeed(String fileName, Network network, OffsetDateTime par private void setUpWithTimeseriesMrids(String fileName, Network network, OffsetDateTime parametrableOffsetDateTime, Set timeseriesMrids) { CracCreationParameters cracCreationParameters = new CracCreationParameters(); - cracCreationParameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_LEFT_SIDE); + cracCreationParameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_SIDE_ONE); cracCreationParameters = Mockito.spy(cracCreationParameters); CimCracCreationParameters cimCracCreationParameters = Mockito.mock(CimCracCreationParameters.class); Mockito.when(cracCreationParameters.getExtension(CimCracCreationParameters.class)).thenReturn(cimCracCreationParameters); @@ -305,7 +305,7 @@ private void assertHasOnAngleUsageRule(String raId, String angleCnecId) { )); } - private void assertHasOneThreshold(String cnecId, Side side, Unit unit, double min, double max) { + private void assertHasOneThreshold(String cnecId, TwoSides side, Unit unit, double min, double max) { FlowCnec cnec = importedCrac.getFlowCnec(cnecId); assertEquals(1, cnec.getThresholds().size()); BranchThreshold threshold = cnec.getThresholds().iterator().next(); @@ -320,8 +320,8 @@ private void assertHasOneThreshold(String cnecId, Side side, Unit unit, double m private void assertHasTwoThresholds(String cnecId, Unit unit, double min, double max) { FlowCnec cnec = importedCrac.getFlowCnec(cnecId); assertEquals(2, cnec.getThresholds().size()); - assertTrue(cnec.getThresholds().stream().anyMatch(threshold -> threshold.getSide().equals(Side.LEFT))); - assertTrue(cnec.getThresholds().stream().anyMatch(threshold -> threshold.getSide().equals(Side.RIGHT))); + assertTrue(cnec.getThresholds().stream().anyMatch(threshold -> threshold.getSide().equals(TwoSides.ONE))); + assertTrue(cnec.getThresholds().stream().anyMatch(threshold -> threshold.getSide().equals(TwoSides.TWO))); cnec.getThresholds().forEach(threshold -> { assertEquals(unit, threshold.getUnit()); assertTrue(threshold.limitsByMin()); @@ -398,7 +398,7 @@ void testImportContingencyOnTieLine() { @Test void testImportFakeCnecs() { CracCreationParameters cracCreationParameters = new CracCreationParameters(); - cracCreationParameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_LEFT_SIDE); + cracCreationParameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_SIDE_ONE); setUp("/cracs/CIM_21_2_1.xml", baseNetwork, OffsetDateTime.parse("2021-04-01T23:00Z"), cracCreationParameters); assertEquals(10, importedCrac.getFlowCnecs().size()); @@ -408,25 +408,25 @@ void testImportFakeCnecs() { // CNEC 3 assertCnecImported("CNEC-3", Set.of("CNEC-3 - preventive", "CNEC-3 - Co-1 - auto", "CNEC-3 - Co-2 - auto")); - assertHasOneThreshold("CNEC-3 - preventive", Side.LEFT, Unit.MEGAWATT, -3, 3); - assertHasOneThreshold("CNEC-3 - Co-1 - auto", Side.LEFT, Unit.AMPERE, -3, 3); - assertHasOneThreshold("CNEC-3 - Co-2 - auto", Side.LEFT, Unit.AMPERE, -3, 3); + assertHasOneThreshold("CNEC-3 - preventive", TwoSides.ONE, Unit.MEGAWATT, -3, 3); + assertHasOneThreshold("CNEC-3 - Co-1 - auto", TwoSides.ONE, Unit.AMPERE, -3, 3); + assertHasOneThreshold("CNEC-3 - Co-2 - auto", TwoSides.ONE, Unit.AMPERE, -3, 3); // CNEC 4 assertCnecImported("CNEC-4", Set.of("CNEC-4 - preventive", "CNEC-4 - Co-1 - curative", "CNEC-4 - Co-2 - curative")); - assertHasOneThreshold("CNEC-4 - preventive", Side.LEFT, Unit.PERCENT_IMAX, -0.04, 0.04); - assertHasOneThreshold("CNEC-4 - Co-1 - curative", Side.LEFT, Unit.PERCENT_IMAX, -0.04, 0.04); - assertHasOneThreshold("CNEC-4 - Co-2 - curative", Side.LEFT, Unit.PERCENT_IMAX, -0.04, 0.04); + assertHasOneThreshold("CNEC-4 - preventive", TwoSides.ONE, Unit.PERCENT_IMAX, -0.04, 0.04); + assertHasOneThreshold("CNEC-4 - Co-1 - curative", TwoSides.ONE, Unit.PERCENT_IMAX, -0.04, 0.04); + assertHasOneThreshold("CNEC-4 - Co-2 - curative", TwoSides.ONE, Unit.PERCENT_IMAX, -0.04, 0.04); // CNEC 5 assertCnecImported("MNEC-1", Set.of("CNEC-5 - MONITORED - preventive", "CNEC-5 - MONITORED - Co-1 - curative")); - assertHasOneThreshold("CNEC-5 - MONITORED - preventive", Side.LEFT, Unit.PERCENT_IMAX, -0.05, 0.05); - assertHasOneThreshold("CNEC-5 - MONITORED - Co-1 - curative", Side.LEFT, Unit.PERCENT_IMAX, -0.05, 0.05); + assertHasOneThreshold("CNEC-5 - MONITORED - preventive", TwoSides.ONE, Unit.PERCENT_IMAX, -0.05, 0.05); + assertHasOneThreshold("CNEC-5 - MONITORED - Co-1 - curative", TwoSides.ONE, Unit.PERCENT_IMAX, -0.05, 0.05); // CNEC 6 assertCnecImported("MNEC-2", Set.of("CNEC-6 - MONITORED - preventive", "CNEC-6 - MONITORED - Co-1 - outage")); - assertHasOneThreshold("CNEC-6 - MONITORED - preventive", Side.LEFT, Unit.PERCENT_IMAX, -0.06, 0.06); - assertHasOneThreshold("CNEC-6 - MONITORED - Co-1 - outage", Side.LEFT, Unit.PERCENT_IMAX, -0.06, 0.06); + assertHasOneThreshold("CNEC-6 - MONITORED - preventive", TwoSides.ONE, Unit.PERCENT_IMAX, -0.06, 0.06); + assertHasOneThreshold("CNEC-6 - MONITORED - Co-1 - outage", TwoSides.ONE, Unit.PERCENT_IMAX, -0.06, 0.06); } @Test @@ -907,7 +907,7 @@ AUTO_INSTANT_ID, new VoltageMonitoredContingenciesAndThresholds(Set.of("Co-2-nam @Test void testImportCnecOnRightSide() { CracCreationParameters cracCreationParameters = new CracCreationParameters(); - cracCreationParameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_RIGHT_SIDE); + cracCreationParameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_SIDE_TWO); setUp("/cracs/CIM_21_2_1.xml", baseNetwork, OffsetDateTime.parse("2021-04-01T23:00Z"), cracCreationParameters); assertEquals(8, importedCrac.getFlowCnecs().size()); @@ -917,20 +917,20 @@ void testImportCnecOnRightSide() { // CNEC 3 assertCnecImported("CNEC-3", Set.of("CNEC-3 - preventive", "CNEC-3 - Co-1 - auto", "CNEC-3 - Co-2 - auto")); - assertHasOneThreshold("CNEC-3 - preventive", Side.RIGHT, Unit.MEGAWATT, -3, 3); - assertHasOneThreshold("CNEC-3 - Co-1 - auto", Side.RIGHT, Unit.AMPERE, -3, 3); - assertHasOneThreshold("CNEC-3 - Co-2 - auto", Side.RIGHT, Unit.AMPERE, -3, 3); + assertHasOneThreshold("CNEC-3 - preventive", TwoSides.TWO, Unit.MEGAWATT, -3, 3); + assertHasOneThreshold("CNEC-3 - Co-1 - auto", TwoSides.TWO, Unit.AMPERE, -3, 3); + assertHasOneThreshold("CNEC-3 - Co-2 - auto", TwoSides.TWO, Unit.AMPERE, -3, 3); // CNEC 4 assertCnecImported("CNEC-4", Set.of("CNEC-4 - preventive", "CNEC-4 - Co-1 - curative", "CNEC-4 - Co-2 - curative")); - assertHasOneThreshold("CNEC-4 - preventive", Side.RIGHT, Unit.PERCENT_IMAX, -0.04, 0.04); - assertHasOneThreshold("CNEC-4 - Co-1 - curative", Side.RIGHT, Unit.PERCENT_IMAX, -0.04, 0.04); - assertHasOneThreshold("CNEC-4 - Co-2 - curative", Side.RIGHT, Unit.PERCENT_IMAX, -0.04, 0.04); + assertHasOneThreshold("CNEC-4 - preventive", TwoSides.TWO, Unit.PERCENT_IMAX, -0.04, 0.04); + assertHasOneThreshold("CNEC-4 - Co-1 - curative", TwoSides.TWO, Unit.PERCENT_IMAX, -0.04, 0.04); + assertHasOneThreshold("CNEC-4 - Co-2 - curative", TwoSides.TWO, Unit.PERCENT_IMAX, -0.04, 0.04); // CNEC 5 assertCnecImported("MNEC-1", Set.of("CNEC-5 - MONITORED - preventive", "CNEC-5 - MONITORED - Co-1 - curative")); - assertHasOneThreshold("CNEC-5 - MONITORED - preventive", Side.RIGHT, Unit.PERCENT_IMAX, -0.05, 0.05); - assertHasOneThreshold("CNEC-5 - MONITORED - Co-1 - curative", Side.RIGHT, Unit.PERCENT_IMAX, -0.05, 0.05); + assertHasOneThreshold("CNEC-5 - MONITORED - preventive", TwoSides.TWO, Unit.PERCENT_IMAX, -0.05, 0.05); + assertHasOneThreshold("CNEC-5 - MONITORED - Co-1 - curative", TwoSides.TWO, Unit.PERCENT_IMAX, -0.05, 0.05); // CNEC 6 - Cannot be imported because has no Imax on right side assertCnecNotImported("MNEC-2", OTHER); @@ -964,10 +964,10 @@ void testImportCnecOnBothSides() { assertHasTwoThresholds("CNEC-5 - MONITORED - preventive", Unit.PERCENT_IMAX, -0.05, 0.05); assertHasTwoThresholds("CNEC-5 - MONITORED - Co-1 - curative", Unit.PERCENT_IMAX, -0.05, 0.05); - // CNEC 6 - Only one threshold because has only Imax on LEFT side in network + // CNEC 6 - Only one threshold because has only Imax on ONE side in network assertCnecImported("MNEC-2", Set.of("CNEC-6 - MONITORED - preventive", "CNEC-6 - MONITORED - Co-1 - outage")); - assertHasOneThreshold("CNEC-6 - MONITORED - preventive", Side.LEFT, Unit.PERCENT_IMAX, -0.06, 0.06); - assertHasOneThreshold("CNEC-6 - MONITORED - Co-1 - outage", Side.LEFT, Unit.PERCENT_IMAX, -0.06, 0.06); + assertHasOneThreshold("CNEC-6 - MONITORED - preventive", TwoSides.ONE, Unit.PERCENT_IMAX, -0.06, 0.06); + assertHasOneThreshold("CNEC-6 - MONITORED - Co-1 - outage", TwoSides.ONE, Unit.PERCENT_IMAX, -0.06, 0.06); } @Test @@ -983,24 +983,24 @@ void testTransformerCnecThresholds() { assertHasTwoThresholds("OJLJJ_5_400_220 - preventive", Unit.PERCENT_IMAX, -1., 1.); assertHasTwoThresholds("OJLJJ_5_400_220 - CO_2 - outage", Unit.MEGAWATT, -1000., 1000.); assertHasTwoThresholds("OJLJJ_5_400_220 - CO_3 - outage", Unit.MEGAWATT, -1000., 1000.); - assertHasOneThreshold("OJLJJ_5_400_220 - CO_2 - curative", Side.RIGHT, Unit.AMPERE, -2000., 2000.); - assertHasOneThreshold("OJLJJ_5_400_220 - CO_3 - curative", Side.RIGHT, Unit.AMPERE, -2000., 2000.); + assertHasOneThreshold("OJLJJ_5_400_220 - CO_2 - curative", TwoSides.TWO, Unit.AMPERE, -2000., 2000.); + assertHasOneThreshold("OJLJJ_5_400_220 - CO_3 - curative", TwoSides.TWO, Unit.AMPERE, -2000., 2000.); - cracCreationParameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_LEFT_SIDE); + cracCreationParameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_SIDE_ONE); setUp("/cracs/CIM_21_5_2.xml", baseNetwork, OffsetDateTime.parse("2021-04-02T03:00Z"), cracCreationParameters); - assertHasOneThreshold("OJLJJ_5_400_220 - preventive", Side.LEFT, Unit.PERCENT_IMAX, -1., 1.); - assertHasOneThreshold("OJLJJ_5_400_220 - CO_2 - outage", Side.LEFT, Unit.MEGAWATT, -1000., 1000.); - assertHasOneThreshold("OJLJJ_5_400_220 - CO_3 - outage", Side.LEFT, Unit.MEGAWATT, -1000., 1000.); - assertHasOneThreshold("OJLJJ_5_400_220 - CO_2 - curative", Side.RIGHT, Unit.AMPERE, -2000., 2000.); - assertHasOneThreshold("OJLJJ_5_400_220 - CO_3 - curative", Side.RIGHT, Unit.AMPERE, -2000., 2000.); + assertHasOneThreshold("OJLJJ_5_400_220 - preventive", TwoSides.ONE, Unit.PERCENT_IMAX, -1., 1.); + assertHasOneThreshold("OJLJJ_5_400_220 - CO_2 - outage", TwoSides.ONE, Unit.MEGAWATT, -1000., 1000.); + assertHasOneThreshold("OJLJJ_5_400_220 - CO_3 - outage", TwoSides.ONE, Unit.MEGAWATT, -1000., 1000.); + assertHasOneThreshold("OJLJJ_5_400_220 - CO_2 - curative", TwoSides.TWO, Unit.AMPERE, -2000., 2000.); + assertHasOneThreshold("OJLJJ_5_400_220 - CO_3 - curative", TwoSides.TWO, Unit.AMPERE, -2000., 2000.); - cracCreationParameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_RIGHT_SIDE); + cracCreationParameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_SIDE_TWO); setUp("/cracs/CIM_21_5_2.xml", baseNetwork, OffsetDateTime.parse("2021-04-02T05:00Z"), cracCreationParameters); - assertHasOneThreshold("OJLJJ_5_400_220 - preventive", Side.RIGHT, Unit.PERCENT_IMAX, -1., 1.); - assertHasOneThreshold("OJLJJ_5_400_220 - CO_2 - outage", Side.RIGHT, Unit.MEGAWATT, -1000., 1000.); - assertHasOneThreshold("OJLJJ_5_400_220 - CO_3 - outage", Side.RIGHT, Unit.MEGAWATT, -1000., 1000.); - assertHasOneThreshold("OJLJJ_5_400_220 - CO_2 - curative", Side.RIGHT, Unit.AMPERE, -2000., 2000.); - assertHasOneThreshold("OJLJJ_5_400_220 - CO_3 - curative", Side.RIGHT, Unit.AMPERE, -2000., 2000.); + assertHasOneThreshold("OJLJJ_5_400_220 - preventive", TwoSides.TWO, Unit.PERCENT_IMAX, -1., 1.); + assertHasOneThreshold("OJLJJ_5_400_220 - CO_2 - outage", TwoSides.TWO, Unit.MEGAWATT, -1000., 1000.); + assertHasOneThreshold("OJLJJ_5_400_220 - CO_3 - outage", TwoSides.TWO, Unit.MEGAWATT, -1000., 1000.); + assertHasOneThreshold("OJLJJ_5_400_220 - CO_2 - curative", TwoSides.TWO, Unit.AMPERE, -2000., 2000.); + assertHasOneThreshold("OJLJJ_5_400_220 - CO_3 - curative", TwoSides.TWO, Unit.AMPERE, -2000., 2000.); } @Test @@ -1011,7 +1011,7 @@ void testCreateTwiceWithSameNativeCrac() { CimCrac cimCrac = cracImporter.importNativeCrac(is); CracCreationParameters cracCreationParameters = new CracCreationParameters(); - cracCreationParameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_LEFT_SIDE); + cracCreationParameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_SIDE_ONE); cracCreationParameters = Mockito.spy(cracCreationParameters); CimCracCreationParameters cimCracCreationParameters = Mockito.mock(CimCracCreationParameters.class); Mockito.when(cracCreationParameters.getExtension(CimCracCreationParameters.class)).thenReturn(cimCracCreationParameters); @@ -1038,10 +1038,10 @@ private void assertCnecHasOutageDuplicate(String flowCnecId) { assertEquals(flowCnec.isOptimized(), duplicate.isOptimized()); assertEquals(flowCnec.isMonitored(), duplicate.isMonitored()); assertEquals(flowCnec.getReliabilityMargin(), duplicate.getReliabilityMargin(), 1e-6); - assertEquals(flowCnec.getIMax(Side.LEFT), duplicate.getIMax(Side.LEFT), 1e-6); - assertEquals(flowCnec.getIMax(Side.RIGHT), duplicate.getIMax(Side.RIGHT), 1e-6); - assertEquals(flowCnec.getNominalVoltage(Side.LEFT), duplicate.getNominalVoltage(Side.LEFT), 1e-6); - assertEquals(flowCnec.getNominalVoltage(Side.RIGHT), duplicate.getNominalVoltage(Side.RIGHT), 1e-6); + assertEquals(flowCnec.getIMax(TwoSides.ONE), duplicate.getIMax(TwoSides.ONE), 1e-6); + assertEquals(flowCnec.getIMax(TwoSides.TWO), duplicate.getIMax(TwoSides.TWO), 1e-6); + assertEquals(flowCnec.getNominalVoltage(TwoSides.ONE), duplicate.getNominalVoltage(TwoSides.ONE), 1e-6); + assertEquals(flowCnec.getNominalVoltage(TwoSides.TWO), duplicate.getNominalVoltage(TwoSides.TWO), 1e-6); assertEquals(flowCnec.getThresholds(), duplicate.getThresholds()); assertTrue(cracCreationContext.getCreationReport().getReport().contains(String.format("[ADDED] CNEC \"%s\" has no associated automaton. It will be cloned on the OUTAGE instant in order to be secured during preventive RAO.", flowCnecId))); } @@ -1077,19 +1077,19 @@ void testPermissiveImports() { "GHIOL_QSDFGH_1_220 - Co-one-3 - auto", "GHIOL_QSDFGH_1_220 - Co-one-1 - curative", "GHIOL_QSDFGH_1_220 - Co-one-2 - auto", "GHIOL_QSDFGH_1_220 - Co-one-2 - outage" )); - assertHasOneThreshold("GHIOL_QSDFGH_1_220 - preventive", Side.LEFT, Unit.PERCENT_IMAX, -1, 1); - assertHasOneThreshold("GHIOL_QSDFGH_1_220 - Co-one-1 - outage", Side.LEFT, Unit.PERCENT_IMAX, -1.15, 1.15); - assertHasOneThreshold("GHIOL_QSDFGH_1_220 - Co-one-2 - auto", Side.LEFT, Unit.PERCENT_IMAX, -1.1, 1.1); - assertHasOneThreshold("GHIOL_QSDFGH_1_220 - Co-one-3 - curative", Side.LEFT, Unit.PERCENT_IMAX, -1.05, 1.05); + assertHasOneThreshold("GHIOL_QSDFGH_1_220 - preventive", TwoSides.ONE, Unit.PERCENT_IMAX, -1, 1); + assertHasOneThreshold("GHIOL_QSDFGH_1_220 - Co-one-1 - outage", TwoSides.ONE, Unit.PERCENT_IMAX, -1.15, 1.15); + assertHasOneThreshold("GHIOL_QSDFGH_1_220 - Co-one-2 - auto", TwoSides.ONE, Unit.PERCENT_IMAX, -1.1, 1.1); + assertHasOneThreshold("GHIOL_QSDFGH_1_220 - Co-one-3 - curative", TwoSides.ONE, Unit.PERCENT_IMAX, -1.05, 1.05); assertCnecImported("TUU_MR_56", Set.of( "GHIOL_QSRBJH_1_400 - Co-one-1 - auto", "GHIOL_QSRBJH_1_400 - preventive", "GHIOL_QSRBJH_1_400 - Co-one-1 - outage", "GHIOL_QSRBJH_1_400 - Co-one-1 - curative" )); - assertHasOneThreshold("GHIOL_QSRBJH_1_400 - preventive", Side.LEFT, Unit.PERCENT_IMAX, -1, 1); - assertHasOneThreshold("GHIOL_QSRBJH_1_400 - Co-one-1 - outage", Side.LEFT, Unit.PERCENT_IMAX, -1.5, 1.5); - assertHasOneThreshold("GHIOL_QSRBJH_1_400 - Co-one-1 - auto", Side.LEFT, Unit.PERCENT_IMAX, -1.3, 1.3); - assertHasOneThreshold("GHIOL_QSRBJH_1_400 - Co-one-1 - curative", Side.LEFT, Unit.PERCENT_IMAX, -1.05, 1.05); + assertHasOneThreshold("GHIOL_QSRBJH_1_400 - preventive", TwoSides.ONE, Unit.PERCENT_IMAX, -1, 1); + assertHasOneThreshold("GHIOL_QSRBJH_1_400 - Co-one-1 - outage", TwoSides.ONE, Unit.PERCENT_IMAX, -1.5, 1.5); + assertHasOneThreshold("GHIOL_QSRBJH_1_400 - Co-one-1 - auto", TwoSides.ONE, Unit.PERCENT_IMAX, -1.3, 1.3); + assertHasOneThreshold("GHIOL_QSRBJH_1_400 - Co-one-1 - curative", TwoSides.ONE, Unit.PERCENT_IMAX, -1.05, 1.05); // PRA_1 assertPstRangeActionImported("PRA_1", "_a708c3bc-465d-4fe7-b6ef-6fa6408a62b0", false); diff --git a/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/cnec/AbstractCnecCreator.java b/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/cnec/AbstractCnecCreator.java index edb595d5a0..b54b61e35b 100644 --- a/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/cnec/AbstractCnecCreator.java +++ b/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/cnec/AbstractCnecCreator.java @@ -9,7 +9,7 @@ import com.powsybl.contingency.Contingency; import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.cnec.CnecAdder; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.craccreation.creator.csaprofile.craccreator.CsaProfileCracCreationContext; import com.powsybl.openrao.data.craccreation.creator.csaprofile.craccreator.CsaProfileCracUtils; import com.powsybl.openrao.data.craccreation.creator.csaprofile.craccreator.CsaProfileElementaryCreationContext; @@ -77,7 +77,7 @@ protected String getCnecName(String instantId, Contingency contingency) { return "%s (%s) - %s%s".formatted(nativeAssessedElement.getUniqueName(), nativeAssessedElement.mrid(), contingency == null ? "" : contingency.getName().orElse(contingency.getId()) + " - ", instantId); } - protected String getCnecName(String instantId, Contingency contingency, Side side, int acceptableDuration) { + protected String getCnecName(String instantId, Contingency contingency, TwoSides side, int acceptableDuration) { // Need to include the mRID in the name in case the AssessedElement's name is not unique // Add TATL duration in case to CNECs of the same instant are created with different TATLs return "%s (%s) - %s%s - %s%s".formatted(nativeAssessedElement.getUniqueName(), nativeAssessedElement.mrid(), contingency == null ? "" : contingency.getName().orElse(contingency.getId()) + " - ", instantId, side.name(), acceptableDuration == Integer.MAX_VALUE ? "" : " - TATL " + acceptableDuration); @@ -88,7 +88,7 @@ protected void addCnecBaseInformation(CnecAdder cnecAdder, Contingency contin initCnecAdder(cnecAdder, contingency, instantId, cnecName); } - protected void addCnecBaseInformation(CnecAdder cnecAdder, Contingency contingency, String instantId, Side side, int acceptableDuration) { + protected void addCnecBaseInformation(CnecAdder cnecAdder, Contingency contingency, String instantId, TwoSides side, int acceptableDuration) { initCnecAdder(cnecAdder, contingency, instantId, getCnecName(instantId, contingency, side, acceptableDuration)); } diff --git a/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/cnec/FlowCnecCreator.java b/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/cnec/FlowCnecCreator.java index ee4bbab27f..3629fffc20 100644 --- a/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/cnec/FlowCnecCreator.java +++ b/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/cnec/FlowCnecCreator.java @@ -10,7 +10,7 @@ import com.powsybl.contingency.Contingency; import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.cnec.FlowCnecAdder; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.threshold.BranchThresholdAdder; import com.powsybl.openrao.data.craccreation.creator.api.ImportStatus; import com.powsybl.openrao.data.craccreation.creator.api.parameters.CracCreationParameters; @@ -35,7 +35,7 @@ * @author Thomas Bouquet {@literal } */ public class FlowCnecCreator extends AbstractCnecCreator { - private final Set defaultMonitoredSides; + private final Set defaultMonitoredSides; private final FlowCnecInstantHelper instantHelper; private final CurrentLimit nativeCurrentLimit; @@ -95,7 +95,7 @@ private Identifiable getFlowCnecBranch(String networkElementId) { return networkElement; } - private Side getSideFromNetworkElement(Identifiable networkElement, String terminalId) { + private TwoSides getSideFromNetworkElement(Identifiable networkElement, String terminalId) { if (networkElement instanceof TieLine tieLine) { return getSideFromTieLine(tieLine, terminalId); } else { @@ -103,39 +103,39 @@ private Side getSideFromNetworkElement(Identifiable networkElement, String te } } - private Side getSideFromTieLine(TieLine tieLine, String terminalId) { + private TwoSides getSideFromTieLine(TieLine tieLine, String terminalId) { for (String key : CURRENT_LIMIT_POSSIBLE_ALIASES_BY_TYPE_TIE_LINE) { Optional oAlias = tieLine.getDanglingLine1().getAliasFromType(key); if (oAlias.isPresent() && oAlias.get().equals(terminalId)) { - return Side.LEFT; + return TwoSides.ONE; } oAlias = tieLine.getDanglingLine2().getAliasFromType(key); if (oAlias.isPresent() && oAlias.get().equals(terminalId)) { - return Side.RIGHT; + return TwoSides.TWO; } } return null; } - private Side getSideFromNonTieLine(Identifiable networkElement, String terminalId) { + private TwoSides getSideFromNonTieLine(Identifiable networkElement, String terminalId) { for (String key : CURRENT_LIMIT_POSSIBLE_ALIASES_BY_TYPE_LEFT) { Optional oAlias = networkElement.getAliasFromType(key); if (oAlias.isPresent() && oAlias.get().equals(terminalId)) { - return Side.LEFT; + return TwoSides.ONE; } } for (String key : CURRENT_LIMIT_POSSIBLE_ALIASES_BY_TYPE_RIGHT) { Optional oAlias = networkElement.getAliasFromType(key); if (oAlias.isPresent() && oAlias.get().equals(terminalId)) { - return Side.RIGHT; + return TwoSides.TWO; } } return null; } - private void addFlowCnecThreshold(FlowCnecAdder flowCnecAdder, Side side, double threshold, boolean useMaxAndMinThresholds) { + private void addFlowCnecThreshold(FlowCnecAdder flowCnecAdder, TwoSides side, double threshold, boolean useMaxAndMinThresholds) { if (nativeAssessedElement.flowReliabilityMargin() < 0 || nativeAssessedElement.flowReliabilityMargin() > 100) { throw new OpenRaoImportException(ImportStatus.INCONSISTENCY_IN_DATA, writeAssessedElementIgnoredReasonMessage("of an invalid flow reliability margin (expected a value between 0 and 100)")); } @@ -153,8 +153,8 @@ private void setNominalVoltage(FlowCnecAdder flowCnecAdder, Branch branch) { double voltageLevelLeft = branch.getTerminal1().getVoltageLevel().getNominalV(); double voltageLevelRight = branch.getTerminal2().getVoltageLevel().getNominalV(); if (voltageLevelLeft > 1e-6 && voltageLevelRight > 1e-6) { - flowCnecAdder.withNominalVoltage(voltageLevelLeft, Side.LEFT); - flowCnecAdder.withNominalVoltage(voltageLevelRight, Side.RIGHT); + flowCnecAdder.withNominalVoltage(voltageLevelLeft, TwoSides.ONE); + flowCnecAdder.withNominalVoltage(voltageLevelRight, TwoSides.TWO); } else { throw new OpenRaoImportException(ImportStatus.INCONSISTENCY_IN_DATA, "Voltage level for branch " + branch.getId() + " is 0 in network"); } @@ -164,8 +164,8 @@ private void setCurrentLimitsFromBranch(FlowCnecAdder flowCnecAdder, Branch b Double currentLimitLeft = getCurrentLimitFromBranch(branch, TwoSides.ONE); Double currentLimitRight = getCurrentLimitFromBranch(branch, TwoSides.TWO); if (Objects.nonNull(currentLimitLeft) && Objects.nonNull(currentLimitRight)) { - flowCnecAdder.withIMax(currentLimitLeft, Side.LEFT); - flowCnecAdder.withIMax(currentLimitRight, Side.RIGHT); + flowCnecAdder.withIMax(currentLimitLeft, TwoSides.ONE); + flowCnecAdder.withIMax(currentLimitRight, TwoSides.TWO); } else { throw new OpenRaoImportException(ImportStatus.INCONSISTENCY_IN_DATA, writeAssessedElementIgnoredReasonMessage("RAO was unable to retrieve the current limits of branch %s from the network".formatted(branch.getId()))); } @@ -188,7 +188,7 @@ private Double getCurrentLimitFromBranch(Branch branch, TwoSides side) { return null; } - private void addFlowCnec(Branch networkElement, Contingency contingency, String instantId, Side side, double threshold, int limitDuration, boolean useMaxAndMinThresholds) { + private void addFlowCnec(Branch networkElement, Contingency contingency, String instantId, TwoSides side, double threshold, int limitDuration, boolean useMaxAndMinThresholds) { FlowCnecAdder cnecAdder = initFlowCnec(); addCnecBaseInformation(cnecAdder, contingency, instantId, side, limitDuration); addFlowCnecThreshold(cnecAdder, side, threshold, useMaxAndMinThresholds); @@ -202,8 +202,8 @@ private void addAllFlowCnecsFromBranchAndOperationalLimits(Branch networkElem // Preventive CNEC if (nativeAssessedElement.inBaseCase()) { thresholds.getOrDefault(Integer.MAX_VALUE, Map.of()).forEach((twoSides, threshold) -> { - String cnecName = getCnecName(crac.getPreventiveInstant().getId(), null, Side.fromIidmSide(twoSides), Integer.MAX_VALUE); - addFlowCnec(networkElement, null, crac.getPreventiveInstant().getId(), Side.fromIidmSide(twoSides), threshold, Integer.MAX_VALUE, useMaxAndMinThresholds); + String cnecName = getCnecName(crac.getPreventiveInstant().getId(), null, twoSides, Integer.MAX_VALUE); + addFlowCnec(networkElement, null, crac.getPreventiveInstant().getId(), twoSides, threshold, Integer.MAX_VALUE, useMaxAndMinThresholds); csaProfileCnecCreationContexts.add(CsaProfileElementaryCreationContext.imported(nativeAssessedElement.mrid(), cnecName, cnecName, "", false)); }); } @@ -230,10 +230,10 @@ private void addAllFlowCnecsFromBranchAndOperationalLimits(Branch networkElem private void addCurativeFlowCnec(Branch networkElement, boolean useMaxAndMinThresholds, Map> instantToDurationMaps, Map forceUseOfPatl, Contingency contingency, Integer acceptableDuration, TwoSides twoSides, Double threshold) { instantHelper.getPostContingencyInstantsAssociatedToLimitDuration(instantToDurationMaps.get(twoSides), acceptableDuration).forEach( instant -> { - String cnecName = getCnecName(instant, contingency, Side.fromIidmSide(twoSides), acceptableDuration); - addFlowCnec(networkElement, contingency, instant, Side.fromIidmSide(twoSides), threshold, acceptableDuration, useMaxAndMinThresholds); + String cnecName = getCnecName(instant, contingency, twoSides, acceptableDuration); + addFlowCnec(networkElement, contingency, instant, twoSides, threshold, acceptableDuration, useMaxAndMinThresholds); if (acceptableDuration == Integer.MAX_VALUE && Boolean.TRUE.equals(forceUseOfPatl.get(twoSides))) { - csaProfileCnecCreationContexts.add(CsaProfileElementaryCreationContext.imported(nativeAssessedElement.mrid(), cnecName, cnecName, "TSO %s does not use PATL in final state but has no TATL defined for branch %s on side %s, PATL will be used".formatted(CsaProfileCracUtils.getTsoNameFromUrl(nativeAssessedElement.operator()), networkElement.getId(), Side.fromIidmSide(twoSides)), true)); + csaProfileCnecCreationContexts.add(CsaProfileElementaryCreationContext.imported(nativeAssessedElement.mrid(), cnecName, cnecName, "TSO %s does not use PATL in final state but has no TATL defined for branch %s on side %s, PATL will be used".formatted(CsaProfileCracUtils.getTsoNameFromUrl(nativeAssessedElement.operator()), networkElement.getId(), twoSides), true)); } else { csaProfileCnecCreationContexts.add(CsaProfileElementaryCreationContext.imported(nativeAssessedElement.mrid(), cnecName, cnecName, "", false)); } @@ -244,7 +244,7 @@ private void addCurativeFlowCnec(Branch networkElement, boolean useMaxAndMinT private Map> getPermanentAndTemporaryLimitsOfOperationalLimit(Identifiable branch, String terminalId) { Map> thresholds = new HashMap<>(); - Side side = getSideFromNetworkElement(branch, terminalId); + TwoSides side = getSideFromNetworkElement(branch, terminalId); if (side != null) { int acceptableDuration; @@ -255,19 +255,19 @@ private Map> getPermanentAndTemporaryLimitsOfOper } else { return thresholds; } - thresholds.put(acceptableDuration, Map.of(side.iidmSide(), nativeCurrentLimit.value())); + thresholds.put(acceptableDuration, Map.of(side, nativeCurrentLimit.value())); } return thresholds; } private Map> getPermanentAndTemporaryLimitsOfBranch(Branch branch) { - Set sidesToCheck = getSidesToCheck(branch); + Set sidesToCheck = getSidesToCheck(branch); Map> thresholds = new HashMap<>(); - for (Side side : sidesToCheck) { - Optional currentLimits = branch.getCurrentLimits(side.iidmSide()); + for (TwoSides side : sidesToCheck) { + Optional currentLimits = branch.getCurrentLimits(side); if (currentLimits.isPresent()) { // Retrieve PATL double permanentThreshold = currentLimits.get().getPermanentLimit(); @@ -284,26 +284,26 @@ private Map> getPermanentAndTemporaryLimitsOfBran return thresholds; } - private static void addLimitThreshold(Map> thresholds, int acceptableDuration, double threshold, Side side) { + private static void addLimitThreshold(Map> thresholds, int acceptableDuration, double threshold, TwoSides side) { if (thresholds.containsKey(acceptableDuration)) { - thresholds.get(acceptableDuration).put(side.iidmSide(), threshold); + thresholds.get(acceptableDuration).put(side, threshold); } else { - thresholds.put(acceptableDuration, new EnumMap<>(Map.of(side.iidmSide(), threshold))); + thresholds.put(acceptableDuration, new EnumMap<>(Map.of(side, threshold))); } } - private Set getSidesToCheck(Branch branch) { - Set sidesToCheck = new HashSet<>(); + private Set getSidesToCheck(Branch branch) { + Set sidesToCheck = new HashSet<>(); if (defaultMonitoredSides.size() == 2) { // TODO: if TieLine, only put relevant side? ask TSOs what is the expected behavior - sidesToCheck.add(Side.LEFT); - sidesToCheck.add(Side.RIGHT); + sidesToCheck.add(TwoSides.ONE); + sidesToCheck.add(TwoSides.TWO); } else { // Only one side in the set -> check the default side. // If no limit for the default side, check the other side. - Side defaultSide = defaultMonitoredSides.stream().toList().get(0); - Side otherSide = defaultSide == Side.LEFT ? Side.RIGHT : Side.LEFT; - sidesToCheck.add(branch.getCurrentLimits(defaultSide.iidmSide()).isPresent() ? defaultSide : otherSide); + TwoSides defaultSide = defaultMonitoredSides.stream().toList().get(0); + TwoSides otherSide = defaultSide == TwoSides.ONE ? TwoSides.TWO : TwoSides.ONE; + sidesToCheck.add(branch.getCurrentLimits(defaultSide).isPresent() ? defaultSide : otherSide); } return sidesToCheck; } diff --git a/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/CsaProfileCracCreationTestUtil.java b/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/CsaProfileCracCreationTestUtil.java index 13f7343b51..f6114ea9d3 100644 --- a/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/CsaProfileCracCreationTestUtil.java +++ b/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/CsaProfileCracCreationTestUtil.java @@ -12,7 +12,7 @@ import com.powsybl.openrao.data.cracapi.cnec.AngleCnec; import com.powsybl.openrao.data.cracapi.cnec.Cnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.cnec.VoltageCnec; import com.powsybl.openrao.data.cracapi.networkaction.ActionType; import com.powsybl.openrao.data.cracapi.networkaction.ElementaryAction; @@ -78,7 +78,7 @@ public static void assertCnecNotImported(CsaProfileCracCreationContext cracCreat assertTrue(cracCreationContext.getCnecCreationContexts().stream().anyMatch(context -> !context.isImported() && assessedElementId.equals(context.getNativeId()) && importStatus.equals(context.getImportStatus()) && importStatusDetail.equals(context.getImportStatusDetail()))); } - public static void assertFlowCnecEquality(FlowCnec flowCnec, String expectedFlowCnecIdAndName, String expectedNetworkElementId, String expectedInstant, String expectedContingencyId, Double expectedThresholdMaxLeft, Double expectedThresholdMinLeft, Double expectedThresholdMaxRight, Double expectedThresholdMinRight, Set expectedThresholdSides, String expectedOperator) { + public static void assertFlowCnecEquality(FlowCnec flowCnec, String expectedFlowCnecIdAndName, String expectedNetworkElementId, String expectedInstant, String expectedContingencyId, Double expectedThresholdMaxLeft, Double expectedThresholdMinLeft, Double expectedThresholdMaxRight, Double expectedThresholdMinRight, Set expectedThresholdSides, String expectedOperator) { assertEquals(expectedFlowCnecIdAndName, flowCnec.getId()); assertEquals(expectedFlowCnecIdAndName, flowCnec.getName()); assertEquals(expectedNetworkElementId, flowCnec.getNetworkElement().getId()); @@ -91,9 +91,9 @@ public static void assertFlowCnecEquality(FlowCnec flowCnec, String expectedFlow List thresholds = flowCnec.getThresholds().stream().sorted(Comparator.comparing(BranchThreshold::getSide)).toList(); for (BranchThreshold threshold : thresholds) { - Side side = threshold.getSide(); - assertEquals(side == Side.LEFT ? expectedThresholdMaxLeft : expectedThresholdMaxRight, threshold.max().orElse(null)); - assertEquals(side == Side.LEFT ? expectedThresholdMinLeft : expectedThresholdMinRight, threshold.min().orElse(null)); + TwoSides side = threshold.getSide(); + assertEquals(side == TwoSides.ONE ? expectedThresholdMaxLeft : expectedThresholdMaxRight, threshold.max().orElse(null)); + assertEquals(side == TwoSides.ONE ? expectedThresholdMinLeft : expectedThresholdMinRight, threshold.min().orElse(null)); } assertEquals(expectedThresholdSides, flowCnec.getMonitoredSides()); diff --git a/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/cnec/FlowCnecCreationTest.java b/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/cnec/FlowCnecCreationTest.java index 8c1768adc9..7459b06700 100644 --- a/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/cnec/FlowCnecCreationTest.java +++ b/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/cnec/FlowCnecCreationTest.java @@ -1,7 +1,7 @@ package com.powsybl.openrao.data.craccreation.creator.csaprofile.craccreator.cnec; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; import com.powsybl.openrao.data.cracapi.usagerule.UsageMethod; import com.powsybl.openrao.data.craccreation.creator.api.ImportStatus; import com.powsybl.openrao.data.craccreation.creator.csaprofile.craccreator.CsaProfileCracCreationContext; @@ -34,7 +34,7 @@ void importFlowCnecs() { CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(0), - "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - RIGHT", + "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - TWO", "FFR2AA1 FFR3AA1 1", CURATIVE_2_INSTANT_ID, "contingency-1", @@ -42,12 +42,12 @@ void importFlowCnecs() { null, +2500d, -2500d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(1), - "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - RIGHT", + "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - TWO", "FFR2AA1 FFR3AA1 1", CURATIVE_3_INSTANT_ID, "contingency-1", @@ -55,12 +55,12 @@ void importFlowCnecs() { null, +2500d, -2500d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(2), - "RTE_AE1 (assessed-element-1) - preventive - RIGHT", + "RTE_AE1 (assessed-element-1) - preventive - TWO", "FFR2AA1 FFR3AA1 1", PREVENTIVE_INSTANT_ID, null, @@ -68,12 +68,12 @@ void importFlowCnecs() { null, +2500d, -2500d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(3), - "RTE_AE11 (assessed-element-11) - RTE_CO1 - curative 2 - RIGHT", + "RTE_AE11 (assessed-element-11) - RTE_CO1 - curative 2 - TWO", "FFR2AA1 FFR3AA1 1", CURATIVE_2_INSTANT_ID, "contingency-1", @@ -81,12 +81,12 @@ void importFlowCnecs() { null, +2500d, -2500d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(4), - "RTE_AE11 (assessed-element-11) - RTE_CO1 - curative 3 - RIGHT", + "RTE_AE11 (assessed-element-11) - RTE_CO1 - curative 3 - TWO", "FFR2AA1 FFR3AA1 1", CURATIVE_3_INSTANT_ID, "contingency-1", @@ -94,12 +94,12 @@ void importFlowCnecs() { null, +2500d, -2500d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(5), - "RTE_AE2 (assessed-element-2) - RTE_CO1 - outage - RIGHT - TATL 60", + "RTE_AE2 (assessed-element-2) - RTE_CO1 - outage - TWO - TATL 60", "FFR2AA1 FFR3AA1 1", OUTAGE_INSTANT_ID, "contingency-1", @@ -107,12 +107,12 @@ void importFlowCnecs() { null, +5000d, -5000d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(6), - "RTE_AE2 (assessed-element-2) - RTE_CO2 - outage - RIGHT - TATL 60", + "RTE_AE2 (assessed-element-2) - RTE_CO2 - outage - TWO - TATL 60", "FFR2AA1 FFR3AA1 1", OUTAGE_INSTANT_ID, "contingency-2", @@ -120,12 +120,12 @@ void importFlowCnecs() { null, +5000d, -5000d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(7), - "RTE_AE3 (assessed-element-3) - RTE_CO2 - auto - RIGHT - TATL 900", + "RTE_AE3 (assessed-element-3) - RTE_CO2 - auto - TWO - TATL 900", "FFR2AA1 FFR3AA1 1", AUTO_INSTANT_ID, "contingency-2", @@ -133,12 +133,12 @@ void importFlowCnecs() { null, +4000d, -4000d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(8), - "RTE_AE3 (assessed-element-3) - RTE_CO2 - curative 1 - RIGHT - TATL 900", + "RTE_AE3 (assessed-element-3) - RTE_CO2 - curative 1 - TWO - TATL 900", "FFR2AA1 FFR3AA1 1", CURATIVE_1_INSTANT_ID, "contingency-2", @@ -146,12 +146,12 @@ void importFlowCnecs() { null, +4000d, -4000d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(9), - "RTE_AE4 (assessed-element-4) - RTE_CO1 - curative 2 - RIGHT", + "RTE_AE4 (assessed-element-4) - RTE_CO1 - curative 2 - TWO", "FFR2AA1 FFR3AA1 1", CURATIVE_2_INSTANT_ID, "contingency-1", @@ -159,12 +159,12 @@ void importFlowCnecs() { null, +2500d, -2500d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(10), - "RTE_AE4 (assessed-element-4) - RTE_CO1 - curative 3 - RIGHT", + "RTE_AE4 (assessed-element-4) - RTE_CO1 - curative 3 - TWO", "FFR2AA1 FFR3AA1 1", CURATIVE_3_INSTANT_ID, "contingency-1", @@ -172,12 +172,12 @@ void importFlowCnecs() { null, +2500d, -2500d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(11), - "RTE_AE4 (assessed-element-4) - RTE_CO2 - curative 2 - RIGHT", + "RTE_AE4 (assessed-element-4) - RTE_CO2 - curative 2 - TWO", "FFR2AA1 FFR3AA1 1", CURATIVE_2_INSTANT_ID, "contingency-2", @@ -185,12 +185,12 @@ void importFlowCnecs() { null, +2500d, -2500d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(12), - "RTE_AE4 (assessed-element-4) - RTE_CO2 - curative 3 - RIGHT", + "RTE_AE4 (assessed-element-4) - RTE_CO2 - curative 3 - TWO", "FFR2AA1 FFR3AA1 1", CURATIVE_3_INSTANT_ID, "contingency-2", @@ -198,12 +198,12 @@ void importFlowCnecs() { null, +2500d, -2500d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(13), - "RTE_AE5 (assessed-element-5) - RTE_CO1 - auto - LEFT - TATL 900", + "RTE_AE5 (assessed-element-5) - RTE_CO1 - auto - ONE - TATL 900", "FFR2AA1 FFR3AA1 1", AUTO_INSTANT_ID, "contingency-1", @@ -211,12 +211,12 @@ void importFlowCnecs() { -4000d, +4000d, -4000d, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(14), - "RTE_AE5 (assessed-element-5) - RTE_CO1 - auto - RIGHT - TATL 900", + "RTE_AE5 (assessed-element-5) - RTE_CO1 - auto - TWO - TATL 900", "FFR2AA1 FFR3AA1 1", AUTO_INSTANT_ID, "contingency-1", @@ -224,12 +224,12 @@ void importFlowCnecs() { -4000d, +4000d, -4000d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(15), - "RTE_AE5 (assessed-element-5) - RTE_CO1 - curative 1 - LEFT - TATL 900", + "RTE_AE5 (assessed-element-5) - RTE_CO1 - curative 1 - ONE - TATL 900", "FFR2AA1 FFR3AA1 1", CURATIVE_1_INSTANT_ID, "contingency-1", @@ -237,12 +237,12 @@ void importFlowCnecs() { -4000d, +4000d, -4000d, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(16), - "RTE_AE5 (assessed-element-5) - RTE_CO1 - curative 1 - RIGHT - TATL 900", + "RTE_AE5 (assessed-element-5) - RTE_CO1 - curative 1 - TWO - TATL 900", "FFR2AA1 FFR3AA1 1", CURATIVE_1_INSTANT_ID, "contingency-1", @@ -250,12 +250,12 @@ void importFlowCnecs() { -4000d, +4000d, -4000d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(17), - "RTE_AE5 (assessed-element-5) - RTE_CO1 - curative 2 - LEFT", + "RTE_AE5 (assessed-element-5) - RTE_CO1 - curative 2 - ONE", "FFR2AA1 FFR3AA1 1", CURATIVE_2_INSTANT_ID, "contingency-1", @@ -263,12 +263,12 @@ void importFlowCnecs() { -2500d, +2500d, -2500d, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(18), - "RTE_AE5 (assessed-element-5) - RTE_CO1 - curative 2 - RIGHT", + "RTE_AE5 (assessed-element-5) - RTE_CO1 - curative 2 - TWO", "FFR2AA1 FFR3AA1 1", CURATIVE_2_INSTANT_ID, "contingency-1", @@ -276,12 +276,12 @@ void importFlowCnecs() { -2500d, +2500d, -2500d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(19), - "RTE_AE5 (assessed-element-5) - RTE_CO1 - curative 3 - LEFT", + "RTE_AE5 (assessed-element-5) - RTE_CO1 - curative 3 - ONE", "FFR2AA1 FFR3AA1 1", CURATIVE_3_INSTANT_ID, "contingency-1", @@ -289,12 +289,12 @@ void importFlowCnecs() { -2500d, +2500d, -2500d, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(20), - "RTE_AE5 (assessed-element-5) - RTE_CO1 - curative 3 - RIGHT", + "RTE_AE5 (assessed-element-5) - RTE_CO1 - curative 3 - TWO", "FFR2AA1 FFR3AA1 1", CURATIVE_3_INSTANT_ID, "contingency-1", @@ -302,12 +302,12 @@ void importFlowCnecs() { -2500d, +2500d, -2500d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(21), - "RTE_AE5 (assessed-element-5) - RTE_CO1 - outage - LEFT - TATL 60", + "RTE_AE5 (assessed-element-5) - RTE_CO1 - outage - ONE - TATL 60", "FFR2AA1 FFR3AA1 1", OUTAGE_INSTANT_ID, "contingency-1", @@ -315,12 +315,12 @@ void importFlowCnecs() { -5000d, +5000d, -5000d, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(22), - "RTE_AE5 (assessed-element-5) - RTE_CO1 - outage - RIGHT - TATL 60", + "RTE_AE5 (assessed-element-5) - RTE_CO1 - outage - TWO - TATL 60", "FFR2AA1 FFR3AA1 1", OUTAGE_INSTANT_ID, "contingency-1", @@ -328,12 +328,12 @@ void importFlowCnecs() { -5000d, +5000d, -5000d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(23), - "RTE_AE5 (assessed-element-5) - RTE_CO2 - auto - LEFT - TATL 900", + "RTE_AE5 (assessed-element-5) - RTE_CO2 - auto - ONE - TATL 900", "FFR2AA1 FFR3AA1 1", AUTO_INSTANT_ID, "contingency-2", @@ -341,12 +341,12 @@ void importFlowCnecs() { -4000d, +4000d, -4000d, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(24), - "RTE_AE5 (assessed-element-5) - RTE_CO2 - auto - RIGHT - TATL 900", + "RTE_AE5 (assessed-element-5) - RTE_CO2 - auto - TWO - TATL 900", "FFR2AA1 FFR3AA1 1", AUTO_INSTANT_ID, "contingency-2", @@ -354,12 +354,12 @@ void importFlowCnecs() { -4000d, +4000d, -4000d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(25), - "RTE_AE5 (assessed-element-5) - RTE_CO2 - curative 1 - LEFT - TATL 900", + "RTE_AE5 (assessed-element-5) - RTE_CO2 - curative 1 - ONE - TATL 900", "FFR2AA1 FFR3AA1 1", CURATIVE_1_INSTANT_ID, "contingency-2", @@ -367,12 +367,12 @@ void importFlowCnecs() { -4000d, +4000d, -4000d, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(26), - "RTE_AE5 (assessed-element-5) - RTE_CO2 - curative 1 - RIGHT - TATL 900", + "RTE_AE5 (assessed-element-5) - RTE_CO2 - curative 1 - TWO - TATL 900", "FFR2AA1 FFR3AA1 1", CURATIVE_1_INSTANT_ID, "contingency-2", @@ -380,12 +380,12 @@ void importFlowCnecs() { -4000d, +4000d, -4000d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(27), - "RTE_AE5 (assessed-element-5) - RTE_CO2 - curative 2 - LEFT", + "RTE_AE5 (assessed-element-5) - RTE_CO2 - curative 2 - ONE", "FFR2AA1 FFR3AA1 1", CURATIVE_2_INSTANT_ID, "contingency-2", @@ -393,12 +393,12 @@ void importFlowCnecs() { -2500d, +2500d, -2500d, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(28), - "RTE_AE5 (assessed-element-5) - RTE_CO2 - curative 2 - RIGHT", + "RTE_AE5 (assessed-element-5) - RTE_CO2 - curative 2 - TWO", "FFR2AA1 FFR3AA1 1", CURATIVE_2_INSTANT_ID, "contingency-2", @@ -406,12 +406,12 @@ void importFlowCnecs() { -2500d, +2500d, -2500d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(29), - "RTE_AE5 (assessed-element-5) - RTE_CO2 - curative 3 - LEFT", + "RTE_AE5 (assessed-element-5) - RTE_CO2 - curative 3 - ONE", "FFR2AA1 FFR3AA1 1", CURATIVE_3_INSTANT_ID, "contingency-2", @@ -419,12 +419,12 @@ void importFlowCnecs() { -2500d, +2500d, -2500d, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(30), - "RTE_AE5 (assessed-element-5) - RTE_CO2 - curative 3 - RIGHT", + "RTE_AE5 (assessed-element-5) - RTE_CO2 - curative 3 - TWO", "FFR2AA1 FFR3AA1 1", CURATIVE_3_INSTANT_ID, "contingency-2", @@ -432,12 +432,12 @@ void importFlowCnecs() { -2500d, +2500d, -2500d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(31), - "RTE_AE5 (assessed-element-5) - RTE_CO2 - outage - LEFT - TATL 60", + "RTE_AE5 (assessed-element-5) - RTE_CO2 - outage - ONE - TATL 60", "FFR2AA1 FFR3AA1 1", OUTAGE_INSTANT_ID, "contingency-2", @@ -445,12 +445,12 @@ void importFlowCnecs() { -5000d, +5000d, -5000d, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(32), - "RTE_AE5 (assessed-element-5) - RTE_CO2 - outage - RIGHT - TATL 60", + "RTE_AE5 (assessed-element-5) - RTE_CO2 - outage - TWO - TATL 60", "FFR2AA1 FFR3AA1 1", OUTAGE_INSTANT_ID, "contingency-2", @@ -458,12 +458,12 @@ void importFlowCnecs() { -5000d, +5000d, -5000d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(33), - "RTE_AE5 (assessed-element-5) - preventive - LEFT", + "RTE_AE5 (assessed-element-5) - preventive - ONE", "FFR2AA1 FFR3AA1 1", PREVENTIVE_INSTANT_ID, null, @@ -471,12 +471,12 @@ void importFlowCnecs() { -2500d, +2500d, -2500d, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(34), - "RTE_AE5 (assessed-element-5) - preventive - RIGHT", + "RTE_AE5 (assessed-element-5) - preventive - TWO", "FFR2AA1 FFR3AA1 1", PREVENTIVE_INSTANT_ID, null, @@ -484,12 +484,12 @@ void importFlowCnecs() { -2500d, +2500d, -2500d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(35), - "RTE_AE6 (assessed-element-6) - RTE_CO1 - auto - LEFT - TATL 900", + "RTE_AE6 (assessed-element-6) - RTE_CO1 - auto - ONE - TATL 900", "FFR2AA1 FFR3AA1 1", AUTO_INSTANT_ID, "contingency-1", @@ -497,12 +497,12 @@ void importFlowCnecs() { -4000d, +4000d, -4000d, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(36), - "RTE_AE6 (assessed-element-6) - RTE_CO1 - auto - RIGHT - TATL 900", + "RTE_AE6 (assessed-element-6) - RTE_CO1 - auto - TWO - TATL 900", "FFR2AA1 FFR3AA1 1", AUTO_INSTANT_ID, "contingency-1", @@ -510,12 +510,12 @@ void importFlowCnecs() { -4000d, +4000d, -4000d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(37), - "RTE_AE6 (assessed-element-6) - RTE_CO1 - curative 1 - LEFT - TATL 900", + "RTE_AE6 (assessed-element-6) - RTE_CO1 - curative 1 - ONE - TATL 900", "FFR2AA1 FFR3AA1 1", CURATIVE_1_INSTANT_ID, "contingency-1", @@ -523,12 +523,12 @@ void importFlowCnecs() { -4000d, +4000d, -4000d, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(38), - "RTE_AE6 (assessed-element-6) - RTE_CO1 - curative 1 - RIGHT - TATL 900", + "RTE_AE6 (assessed-element-6) - RTE_CO1 - curative 1 - TWO - TATL 900", "FFR2AA1 FFR3AA1 1", CURATIVE_1_INSTANT_ID, "contingency-1", @@ -536,12 +536,12 @@ void importFlowCnecs() { -4000d, +4000d, -4000d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(39), - "RTE_AE6 (assessed-element-6) - RTE_CO1 - curative 2 - LEFT", + "RTE_AE6 (assessed-element-6) - RTE_CO1 - curative 2 - ONE", "FFR2AA1 FFR3AA1 1", CURATIVE_2_INSTANT_ID, "contingency-1", @@ -549,12 +549,12 @@ void importFlowCnecs() { -2500d, +2500d, -2500d, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(40), - "RTE_AE6 (assessed-element-6) - RTE_CO1 - curative 2 - RIGHT", + "RTE_AE6 (assessed-element-6) - RTE_CO1 - curative 2 - TWO", "FFR2AA1 FFR3AA1 1", CURATIVE_2_INSTANT_ID, "contingency-1", @@ -562,12 +562,12 @@ void importFlowCnecs() { -2500d, +2500d, -2500d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(41), - "RTE_AE6 (assessed-element-6) - RTE_CO1 - curative 3 - LEFT", + "RTE_AE6 (assessed-element-6) - RTE_CO1 - curative 3 - ONE", "FFR2AA1 FFR3AA1 1", CURATIVE_3_INSTANT_ID, "contingency-1", @@ -575,12 +575,12 @@ void importFlowCnecs() { -2500d, +2500d, -2500d, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(42), - "RTE_AE6 (assessed-element-6) - RTE_CO1 - curative 3 - RIGHT", + "RTE_AE6 (assessed-element-6) - RTE_CO1 - curative 3 - TWO", "FFR2AA1 FFR3AA1 1", CURATIVE_3_INSTANT_ID, "contingency-1", @@ -588,12 +588,12 @@ void importFlowCnecs() { -2500d, +2500d, -2500d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(43), - "RTE_AE6 (assessed-element-6) - RTE_CO1 - outage - LEFT - TATL 60", + "RTE_AE6 (assessed-element-6) - RTE_CO1 - outage - ONE - TATL 60", "FFR2AA1 FFR3AA1 1", OUTAGE_INSTANT_ID, "contingency-1", @@ -601,12 +601,12 @@ void importFlowCnecs() { -5000d, +5000d, -5000d, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(44), - "RTE_AE6 (assessed-element-6) - RTE_CO1 - outage - RIGHT - TATL 60", + "RTE_AE6 (assessed-element-6) - RTE_CO1 - outage - TWO - TATL 60", "FFR2AA1 FFR3AA1 1", OUTAGE_INSTANT_ID, "contingency-1", @@ -614,12 +614,12 @@ void importFlowCnecs() { -5000d, +5000d, -5000d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(45), - "RTE_AE7 (assessed-element-7) - RTE_CO1 - auto - LEFT", + "RTE_AE7 (assessed-element-7) - RTE_CO1 - auto - ONE", "NNL2AA1 BBE3AA1 1", AUTO_INSTANT_ID, "contingency-1", @@ -627,12 +627,12 @@ void importFlowCnecs() { null, null, null, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(46), - "RTE_AE7 (assessed-element-7) - RTE_CO1 - curative 1 - LEFT", + "RTE_AE7 (assessed-element-7) - RTE_CO1 - curative 1 - ONE", "NNL2AA1 BBE3AA1 1", CURATIVE_1_INSTANT_ID, "contingency-1", @@ -640,12 +640,12 @@ void importFlowCnecs() { null, null, null, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(47), - "RTE_AE7 (assessed-element-7) - RTE_CO1 - curative 2 - LEFT", + "RTE_AE7 (assessed-element-7) - RTE_CO1 - curative 2 - ONE", "NNL2AA1 BBE3AA1 1", CURATIVE_2_INSTANT_ID, "contingency-1", @@ -653,12 +653,12 @@ void importFlowCnecs() { null, null, null, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(48), - "RTE_AE7 (assessed-element-7) - RTE_CO1 - curative 3 - LEFT", + "RTE_AE7 (assessed-element-7) - RTE_CO1 - curative 3 - ONE", "NNL2AA1 BBE3AA1 1", CURATIVE_3_INSTANT_ID, "contingency-1", @@ -666,12 +666,12 @@ void importFlowCnecs() { null, null, null, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(49), - "RTE_AE7 (assessed-element-7) - RTE_CO1 - outage - LEFT", + "RTE_AE7 (assessed-element-7) - RTE_CO1 - outage - ONE", "NNL2AA1 BBE3AA1 1", OUTAGE_INSTANT_ID, "contingency-1", @@ -679,12 +679,12 @@ void importFlowCnecs() { null, null, null, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(50), - "RTE_AE7 (assessed-element-7) - RTE_CO2 - auto - LEFT", + "RTE_AE7 (assessed-element-7) - RTE_CO2 - auto - ONE", "NNL2AA1 BBE3AA1 1", AUTO_INSTANT_ID, "contingency-2", @@ -692,12 +692,12 @@ void importFlowCnecs() { null, null, null, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(51), - "RTE_AE7 (assessed-element-7) - RTE_CO2 - curative 1 - LEFT", + "RTE_AE7 (assessed-element-7) - RTE_CO2 - curative 1 - ONE", "NNL2AA1 BBE3AA1 1", CURATIVE_1_INSTANT_ID, "contingency-2", @@ -705,12 +705,12 @@ void importFlowCnecs() { null, null, null, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(52), - "RTE_AE7 (assessed-element-7) - RTE_CO2 - curative 2 - LEFT", + "RTE_AE7 (assessed-element-7) - RTE_CO2 - curative 2 - ONE", "NNL2AA1 BBE3AA1 1", CURATIVE_2_INSTANT_ID, "contingency-2", @@ -718,12 +718,12 @@ void importFlowCnecs() { null, null, null, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(53), - "RTE_AE7 (assessed-element-7) - RTE_CO2 - curative 3 - LEFT", + "RTE_AE7 (assessed-element-7) - RTE_CO2 - curative 3 - ONE", "NNL2AA1 BBE3AA1 1", CURATIVE_3_INSTANT_ID, "contingency-2", @@ -731,12 +731,12 @@ void importFlowCnecs() { null, null, null, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE"); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(54), - "RTE_AE7 (assessed-element-7) - RTE_CO2 - outage - LEFT", + "RTE_AE7 (assessed-element-7) - RTE_CO2 - outage - ONE", "NNL2AA1 BBE3AA1 1", OUTAGE_INSTANT_ID, "contingency-2", @@ -744,7 +744,7 @@ void importFlowCnecs() { null, null, null, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE"); assertEquals(8, cracCreationContext.getCnecCreationContexts().stream().filter(context -> !context.isImported()).toList().size()); @@ -760,23 +760,23 @@ void importFlowCnecs() { assertEquals(15, cracCreationContext.getCrac().getRemedialAction("remedial-action-1").getUsageRules().size()); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_1_INSTANT_ID), UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_1_INSTANT_ID), UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_3_INSTANT_ID), UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_1_INSTANT_ID), UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_1_INSTANT_ID), UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_3_INSTANT_ID), UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE4 (assessed-element-4) - RTE_CO1 - curative 2 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_1_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE4 (assessed-element-4) - RTE_CO1 - curative 3 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_1_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE4 (assessed-element-4) - RTE_CO1 - curative 2 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE4 (assessed-element-4) - RTE_CO1 - curative 3 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE4 (assessed-element-4) - RTE_CO1 - curative 3 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_3_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE4 (assessed-element-4) - RTE_CO1 - curative 2 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_1_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE4 (assessed-element-4) - RTE_CO1 - curative 3 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_1_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE4 (assessed-element-4) - RTE_CO1 - curative 2 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE4 (assessed-element-4) - RTE_CO1 - curative 3 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE4 (assessed-element-4) - RTE_CO1 - curative 3 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_3_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE4 (assessed-element-4) - RTE_CO2 - curative 2 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_1_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE4 (assessed-element-4) - RTE_CO2 - curative 3 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_1_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE4 (assessed-element-4) - RTE_CO2 - curative 2 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE4 (assessed-element-4) - RTE_CO2 - curative 3 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE4 (assessed-element-4) - RTE_CO2 - curative 3 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_3_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE4 (assessed-element-4) - RTE_CO2 - curative 2 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_1_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE4 (assessed-element-4) - RTE_CO2 - curative 3 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_1_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE4 (assessed-element-4) - RTE_CO2 - curative 2 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE4 (assessed-element-4) - RTE_CO2 - curative 3 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE4 (assessed-element-4) - RTE_CO2 - curative 3 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_3_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); assertEquals(13, cracCreationContext.getCrac().getRemedialAction("remedial-action-2").getUsageRules().size()); @@ -784,17 +784,17 @@ void importFlowCnecs() { assertHasOnInstantUsageRule(cracCreationContext, "remedial-action-2", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE); assertHasOnInstantUsageRule(cracCreationContext, "remedial-action-2", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE4 (assessed-element-4) - RTE_CO1 - curative 2 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_1_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE4 (assessed-element-4) - RTE_CO1 - curative 3 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_1_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE4 (assessed-element-4) - RTE_CO1 - curative 2 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE4 (assessed-element-4) - RTE_CO1 - curative 3 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE4 (assessed-element-4) - RTE_CO1 - curative 3 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_3_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); - - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE4 (assessed-element-4) - RTE_CO2 - curative 2 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_1_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE4 (assessed-element-4) - RTE_CO2 - curative 3 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_1_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE4 (assessed-element-4) - RTE_CO2 - curative 2 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE4 (assessed-element-4) - RTE_CO2 - curative 3 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE4 (assessed-element-4) - RTE_CO2 - curative 3 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_3_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE4 (assessed-element-4) - RTE_CO1 - curative 2 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_1_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE4 (assessed-element-4) - RTE_CO1 - curative 3 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_1_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE4 (assessed-element-4) - RTE_CO1 - curative 2 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE4 (assessed-element-4) - RTE_CO1 - curative 3 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE4 (assessed-element-4) - RTE_CO1 - curative 3 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_3_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); + + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE4 (assessed-element-4) - RTE_CO2 - curative 2 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_1_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE4 (assessed-element-4) - RTE_CO2 - curative 3 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_1_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE4 (assessed-element-4) - RTE_CO2 - curative 2 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE4 (assessed-element-4) - RTE_CO2 - curative 3 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE4 (assessed-element-4) - RTE_CO2 - curative 3 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_3_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); } @Test @@ -806,7 +806,7 @@ void importFlowCnecsWithFlowReliabilityMargin() { CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(0), - "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - RIGHT", + "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - TWO", "FFR2AA1 FFR3AA1 1", CURATIVE_2_INSTANT_ID, "contingency-1", @@ -814,13 +814,13 @@ void importFlowCnecsWithFlowReliabilityMargin() { null, +2250d, -2250d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE" ); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(1), - "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - RIGHT", + "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - TWO", "FFR2AA1 FFR3AA1 1", CURATIVE_3_INSTANT_ID, "contingency-1", @@ -828,13 +828,13 @@ void importFlowCnecsWithFlowReliabilityMargin() { null, +2250d, -2250d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE" ); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(2), - "RTE_AE1 (assessed-element-1) - preventive - RIGHT", + "RTE_AE1 (assessed-element-1) - preventive - TWO", "FFR2AA1 FFR3AA1 1", PREVENTIVE_INSTANT_ID, null, @@ -842,13 +842,13 @@ void importFlowCnecsWithFlowReliabilityMargin() { null, +2250d, -2250d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE" ); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(3), - "RTE_AE2 (assessed-element-2) - RTE_CO2 - auto - RIGHT - TATL 900", + "RTE_AE2 (assessed-element-2) - RTE_CO2 - auto - TWO - TATL 900", "FFR2AA1 FFR3AA1 1", AUTO_INSTANT_ID, "contingency-2", @@ -856,13 +856,13 @@ void importFlowCnecsWithFlowReliabilityMargin() { null, +3400d, -3400d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE" ); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(4), - "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 1 - RIGHT - TATL 900", + "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 1 - TWO - TATL 900", "FFR2AA1 FFR3AA1 1", CURATIVE_1_INSTANT_ID, "contingency-2", @@ -870,13 +870,13 @@ void importFlowCnecsWithFlowReliabilityMargin() { null, +3400d, -3400d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE" ); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(5), - "RTE_AE3 (assessed-element-3) - RTE_CO3 - auto - LEFT - TATL 900", + "RTE_AE3 (assessed-element-3) - RTE_CO3 - auto - ONE - TATL 900", "FFR2AA1 FFR3AA1 1", AUTO_INSTANT_ID, "contingency-3", @@ -884,13 +884,13 @@ void importFlowCnecsWithFlowReliabilityMargin() { -3200d, +3200d, -3200d, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE" ); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(6), - "RTE_AE3 (assessed-element-3) - RTE_CO3 - auto - RIGHT - TATL 900", + "RTE_AE3 (assessed-element-3) - RTE_CO3 - auto - TWO - TATL 900", "FFR2AA1 FFR3AA1 1", AUTO_INSTANT_ID, "contingency-3", @@ -898,13 +898,13 @@ void importFlowCnecsWithFlowReliabilityMargin() { -3200d, +3200d, -3200d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE" ); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(7), - "RTE_AE3 (assessed-element-3) - RTE_CO3 - curative 1 - LEFT - TATL 900", + "RTE_AE3 (assessed-element-3) - RTE_CO3 - curative 1 - ONE - TATL 900", "FFR2AA1 FFR3AA1 1", CURATIVE_1_INSTANT_ID, "contingency-3", @@ -912,13 +912,13 @@ void importFlowCnecsWithFlowReliabilityMargin() { -3200d, +3200d, -3200d, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE" ); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(8), - "RTE_AE3 (assessed-element-3) - RTE_CO3 - curative 1 - RIGHT - TATL 900", + "RTE_AE3 (assessed-element-3) - RTE_CO3 - curative 1 - TWO - TATL 900", "FFR2AA1 FFR3AA1 1", CURATIVE_1_INSTANT_ID, "contingency-3", @@ -926,13 +926,13 @@ void importFlowCnecsWithFlowReliabilityMargin() { -3200d, +3200d, -3200d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE" ); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(9), - "RTE_AE3 (assessed-element-3) - RTE_CO3 - curative 2 - LEFT", + "RTE_AE3 (assessed-element-3) - RTE_CO3 - curative 2 - ONE", "FFR2AA1 FFR3AA1 1", CURATIVE_2_INSTANT_ID, "contingency-3", @@ -940,13 +940,13 @@ void importFlowCnecsWithFlowReliabilityMargin() { -2000d, +2000d, -2000d, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE" ); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(10), - "RTE_AE3 (assessed-element-3) - RTE_CO3 - curative 2 - RIGHT", + "RTE_AE3 (assessed-element-3) - RTE_CO3 - curative 2 - TWO", "FFR2AA1 FFR3AA1 1", CURATIVE_2_INSTANT_ID, "contingency-3", @@ -954,13 +954,13 @@ void importFlowCnecsWithFlowReliabilityMargin() { -2000d, +2000d, -2000d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE" ); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(11), - "RTE_AE3 (assessed-element-3) - RTE_CO3 - curative 3 - LEFT", + "RTE_AE3 (assessed-element-3) - RTE_CO3 - curative 3 - ONE", "FFR2AA1 FFR3AA1 1", CURATIVE_3_INSTANT_ID, "contingency-3", @@ -968,13 +968,13 @@ void importFlowCnecsWithFlowReliabilityMargin() { -2000d, +2000d, -2000d, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE" ); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(12), - "RTE_AE3 (assessed-element-3) - RTE_CO3 - curative 3 - RIGHT", + "RTE_AE3 (assessed-element-3) - RTE_CO3 - curative 3 - TWO", "FFR2AA1 FFR3AA1 1", CURATIVE_3_INSTANT_ID, "contingency-3", @@ -982,13 +982,13 @@ void importFlowCnecsWithFlowReliabilityMargin() { -2000d, +2000d, -2000d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE" ); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(13), - "RTE_AE3 (assessed-element-3) - RTE_CO3 - outage - LEFT - TATL 60", + "RTE_AE3 (assessed-element-3) - RTE_CO3 - outage - ONE - TATL 60", "FFR2AA1 FFR3AA1 1", OUTAGE_INSTANT_ID, "contingency-3", @@ -996,13 +996,13 @@ void importFlowCnecsWithFlowReliabilityMargin() { -4000d, +4000d, -4000d, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE" ); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(14), - "RTE_AE3 (assessed-element-3) - RTE_CO3 - outage - RIGHT - TATL 60", + "RTE_AE3 (assessed-element-3) - RTE_CO3 - outage - TWO - TATL 60", "FFR2AA1 FFR3AA1 1", OUTAGE_INSTANT_ID, "contingency-3", @@ -1010,13 +1010,13 @@ void importFlowCnecsWithFlowReliabilityMargin() { -4000d, +4000d, -4000d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE" ); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(15), - "RTE_AE3 (assessed-element-3) - preventive - LEFT", + "RTE_AE3 (assessed-element-3) - preventive - ONE", "FFR2AA1 FFR3AA1 1", PREVENTIVE_INSTANT_ID, null, @@ -1024,13 +1024,13 @@ void importFlowCnecsWithFlowReliabilityMargin() { -2000d, +2000d, -2000d, - Set.of(Side.LEFT), + Set.of(TwoSides.ONE), "RTE" ); CsaProfileCracCreationTestUtil.assertFlowCnecEquality( importedFlowCnecs.get(16), - "RTE_AE3 (assessed-element-3) - preventive - RIGHT", + "RTE_AE3 (assessed-element-3) - preventive - TWO", "FFR2AA1 FFR3AA1 1", PREVENTIVE_INSTANT_ID, null, @@ -1038,7 +1038,7 @@ void importFlowCnecsWithFlowReliabilityMargin() { -2000d, +2000d, -2000d, - Set.of(Side.RIGHT), + Set.of(TwoSides.TWO), "RTE" ); } diff --git a/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/cnec/FlowCnecInstantHelperTest.java b/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/cnec/FlowCnecInstantHelperTest.java index 2db2ac0c66..fb1ddbd539 100644 --- a/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/cnec/FlowCnecInstantHelperTest.java +++ b/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/cnec/FlowCnecInstantHelperTest.java @@ -94,7 +94,7 @@ void checkCracCreationParametersWithCurative2LongerThanCurative3() { void getAllTatlDurationsOnSide() { Branch branch = Mockito.mock(Branch.class); - // No TATL on LEFT side / TATLs on RIGHT side + // No TATL on side ONE / TATLs on side TWO CurrentLimits currentLimitsRight = Mockito.mock(CurrentLimits.class); Mockito.when(currentLimitsRight.getTemporaryLimits()).thenReturn(mockBranchTatls(true, true, true, true, true, true)); Mockito.when(branch.getCurrentLimits(TwoSides.ONE)).thenReturn(Optional.empty()); diff --git a/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/cnec/MnecTest.java b/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/cnec/MnecTest.java index 58b038fecf..3a712b83c8 100644 --- a/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/cnec/MnecTest.java +++ b/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/cnec/MnecTest.java @@ -27,26 +27,26 @@ void importOptimizedAndMonitoredAssessedElements() { CsaProfileCracCreationContext cracCreationContext = getCsaCracCreationContext("/profiles/cnecs/SecuredAndScannedAssessedElements.zip", NETWORK); assertEquals(7, cracCreationContext.getCrac().getFlowCnecs().size()); - assertTrue(cracCreationContext.getCrac().getFlowCnec("RTE_AE2 (ae-2) - preventive - RIGHT").isOptimized()); - assertFalse(cracCreationContext.getCrac().getFlowCnec("RTE_AE2 (ae-2) - preventive - RIGHT").isMonitored()); + assertTrue(cracCreationContext.getCrac().getFlowCnec("RTE_AE2 (ae-2) - preventive - TWO").isOptimized()); + assertFalse(cracCreationContext.getCrac().getFlowCnec("RTE_AE2 (ae-2) - preventive - TWO").isMonitored()); - assertFalse(cracCreationContext.getCrac().getFlowCnec("RTE_AE3 (ae-3) - preventive - RIGHT").isOptimized()); - assertTrue(cracCreationContext.getCrac().getFlowCnec("RTE_AE3 (ae-3) - preventive - RIGHT").isMonitored()); + assertFalse(cracCreationContext.getCrac().getFlowCnec("RTE_AE3 (ae-3) - preventive - TWO").isOptimized()); + assertTrue(cracCreationContext.getCrac().getFlowCnec("RTE_AE3 (ae-3) - preventive - TWO").isMonitored()); - assertTrue(cracCreationContext.getCrac().getFlowCnec("RTE_AE5 (ae-5) - preventive - RIGHT").isOptimized()); - assertFalse(cracCreationContext.getCrac().getFlowCnec("RTE_AE5 (ae-5) - preventive - RIGHT").isMonitored()); + assertTrue(cracCreationContext.getCrac().getFlowCnec("RTE_AE5 (ae-5) - preventive - TWO").isOptimized()); + assertFalse(cracCreationContext.getCrac().getFlowCnec("RTE_AE5 (ae-5) - preventive - TWO").isMonitored()); - assertFalse(cracCreationContext.getCrac().getFlowCnec("RTE_AE6 (ae-6) - preventive - RIGHT").isOptimized()); - assertFalse(cracCreationContext.getCrac().getFlowCnec("RTE_AE6 (ae-6) - preventive - RIGHT").isMonitored()); + assertFalse(cracCreationContext.getCrac().getFlowCnec("RTE_AE6 (ae-6) - preventive - TWO").isOptimized()); + assertFalse(cracCreationContext.getCrac().getFlowCnec("RTE_AE6 (ae-6) - preventive - TWO").isMonitored()); - assertFalse(cracCreationContext.getCrac().getFlowCnec("RTE_AE7 (ae-7) - preventive - RIGHT").isOptimized()); - assertTrue(cracCreationContext.getCrac().getFlowCnec("RTE_AE7 (ae-7) - preventive - RIGHT").isMonitored()); + assertFalse(cracCreationContext.getCrac().getFlowCnec("RTE_AE7 (ae-7) - preventive - TWO").isOptimized()); + assertTrue(cracCreationContext.getCrac().getFlowCnec("RTE_AE7 (ae-7) - preventive - TWO").isMonitored()); - assertFalse(cracCreationContext.getCrac().getFlowCnec("RTE_AE8 (ae-8) - preventive - RIGHT").isOptimized()); - assertFalse(cracCreationContext.getCrac().getFlowCnec("RTE_AE8 (ae-8) - preventive - RIGHT").isMonitored()); + assertFalse(cracCreationContext.getCrac().getFlowCnec("RTE_AE8 (ae-8) - preventive - TWO").isOptimized()); + assertFalse(cracCreationContext.getCrac().getFlowCnec("RTE_AE8 (ae-8) - preventive - TWO").isMonitored()); - assertFalse(cracCreationContext.getCrac().getFlowCnec("RTE_AE9 (ae-9) - preventive - RIGHT").isOptimized()); - assertFalse(cracCreationContext.getCrac().getFlowCnec("RTE_AE9 (ae-9) - preventive - RIGHT").isMonitored()); + assertFalse(cracCreationContext.getCrac().getFlowCnec("RTE_AE9 (ae-9) - preventive - TWO").isOptimized()); + assertFalse(cracCreationContext.getCrac().getFlowCnec("RTE_AE9 (ae-9) - preventive - TWO").isMonitored()); List notImportedCnecCreationContexts = cracCreationContext.getCnecCreationContexts().stream().filter(c -> !c.isImported()) .sorted(Comparator.comparing(CsaProfileElementaryCreationContext::getNativeId)).toList(); diff --git a/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/remedialaction/GroupRemedialActionTest.java b/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/remedialaction/GroupRemedialActionTest.java index 9d52baf252..492e753be8 100644 --- a/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/remedialaction/GroupRemedialActionTest.java +++ b/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/remedialaction/GroupRemedialActionTest.java @@ -55,12 +55,12 @@ void importGroupedRemedialActions() { assertNetworkActionImported(cracCreationContext, "7d2833e4-c5a8-4d79-b936-c735a58f1774", Set.of("DDE3AA1 DDE4AA1 1", "BBE1AA1 BBE4AA1 1"), true, 6, "RTE"); assertEquals("Topo 1 + Topo 2 - CRA x AE1", cracCreationContext.getCrac().getRemedialAction("7d2833e4-c5a8-4d79-b936-c735a58f1774").getName()); - assertHasOnConstraintUsageRule(cracCreationContext, "7d2833e4-c5a8-4d79-b936-c735a58f1774", "RTE_AE1 (f7708112-b880-4674-98a1-b005a01a61d5) - RTE_CO1 - curative 1 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_1_INSTANT_ID), UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "7d2833e4-c5a8-4d79-b936-c735a58f1774", "RTE_AE1 (f7708112-b880-4674-98a1-b005a01a61d5) - RTE_CO1 - curative 2 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "7d2833e4-c5a8-4d79-b936-c735a58f1774", "RTE_AE1 (f7708112-b880-4674-98a1-b005a01a61d5) - RTE_CO1 - curative 2 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "7d2833e4-c5a8-4d79-b936-c735a58f1774", "RTE_AE1 (f7708112-b880-4674-98a1-b005a01a61d5) - RTE_CO1 - curative 3 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_1_INSTANT_ID), UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "7d2833e4-c5a8-4d79-b936-c735a58f1774", "RTE_AE1 (f7708112-b880-4674-98a1-b005a01a61d5) - RTE_CO1 - curative 3 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "7d2833e4-c5a8-4d79-b936-c735a58f1774", "RTE_AE1 (f7708112-b880-4674-98a1-b005a01a61d5) - RTE_CO1 - curative 3 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_3_INSTANT_ID), UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "7d2833e4-c5a8-4d79-b936-c735a58f1774", "RTE_AE1 (f7708112-b880-4674-98a1-b005a01a61d5) - RTE_CO1 - curative 1 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_1_INSTANT_ID), UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "7d2833e4-c5a8-4d79-b936-c735a58f1774", "RTE_AE1 (f7708112-b880-4674-98a1-b005a01a61d5) - RTE_CO1 - curative 2 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "7d2833e4-c5a8-4d79-b936-c735a58f1774", "RTE_AE1 (f7708112-b880-4674-98a1-b005a01a61d5) - RTE_CO1 - curative 2 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "7d2833e4-c5a8-4d79-b936-c735a58f1774", "RTE_AE1 (f7708112-b880-4674-98a1-b005a01a61d5) - RTE_CO1 - curative 3 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_1_INSTANT_ID), UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "7d2833e4-c5a8-4d79-b936-c735a58f1774", "RTE_AE1 (f7708112-b880-4674-98a1-b005a01a61d5) - RTE_CO1 - curative 3 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "7d2833e4-c5a8-4d79-b936-c735a58f1774", "RTE_AE1 (f7708112-b880-4674-98a1-b005a01a61d5) - RTE_CO1 - curative 3 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_3_INSTANT_ID), UsageMethod.FORCED, FlowCnec.class); assertNetworkActionImported(cracCreationContext, "66979f64-3c52-486c-84f7-b5439cd71765", Set.of("BBE1AA1 BBE4AA1 1"), true, 1, "RTE"); assertEquals("Topo 1 - PRA", cracCreationContext.getCrac().getRemedialAction("66979f64-3c52-486c-84f7-b5439cd71765").getName()); diff --git a/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/remedialaction/OnConstraintUsageRuleHelperTest.java b/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/remedialaction/OnConstraintUsageRuleHelperTest.java index 59adfa085e..cccbef34d5 100644 --- a/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/remedialaction/OnConstraintUsageRuleHelperTest.java +++ b/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/remedialaction/OnConstraintUsageRuleHelperTest.java @@ -9,7 +9,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.InstantKind; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.craccreation.creator.csaprofile.craccreator.CsaProfileElementaryCreationContext; import com.powsybl.openrao.data.craccreation.creator.csaprofile.craccreator.constants.ElementCombinationConstraintKind; import com.powsybl.openrao.data.craccreation.creator.csaprofile.nc.AssessedElement; @@ -58,24 +58,24 @@ void setUp() { // Add FlowCNECs - crac.newFlowCnec().withId("Line 1 - curative - CO1").withNominalVoltage(400d).withNetworkElement("Line 1").withInstant("curative").withContingency("contingency-1").newThreshold().withSide(Side.LEFT).withMax(1000d).withUnit(Unit.AMPERE).add().add(); - crac.newFlowCnec().withId("Line 2 - preventive").withNominalVoltage(400d).withNetworkElement("Line 2").withInstant("preventive").newThreshold().withSide(Side.LEFT).withMax(1000d).withUnit(Unit.AMPERE).add().add(); - crac.newFlowCnec().withId("Line 2 - curative - CO1").withNominalVoltage(400d).withNetworkElement("Line 2").withInstant("curative").withContingency("contingency-1").newThreshold().withSide(Side.LEFT).withMax(1000d).withUnit(Unit.AMPERE).add().add(); - crac.newFlowCnec().withId("Line 2 - curative - CO2").withNominalVoltage(400d).withNetworkElement("Line 2").withInstant("curative").withContingency("contingency-2").newThreshold().withSide(Side.LEFT).withMax(1000d).withUnit(Unit.AMPERE).add().add(); - crac.newFlowCnec().withId("Line 2 - curative - CO3").withNominalVoltage(400d).withNetworkElement("Line 2").withInstant("curative").withContingency("contingency-3").newThreshold().withSide(Side.LEFT).withMax(1000d).withUnit(Unit.AMPERE).add().add(); - crac.newFlowCnec().withId("Line 2 - curative - CO4").withNominalVoltage(400d).withNetworkElement("Line 2").withInstant("curative").withContingency("contingency-4").newThreshold().withSide(Side.LEFT).withMax(1000d).withUnit(Unit.AMPERE).add().add(); - crac.newFlowCnec().withId("Line 2 - curative - CO5").withNominalVoltage(400d).withNetworkElement("Line 2").withInstant("curative").withContingency("contingency-5").newThreshold().withSide(Side.LEFT).withMax(1000d).withUnit(Unit.AMPERE).add().add(); - crac.newFlowCnec().withId("Line 2 - curative - CO6").withNominalVoltage(400d).withNetworkElement("Line 2").withInstant("curative").withContingency("contingency-6").newThreshold().withSide(Side.LEFT).withMax(1000d).withUnit(Unit.AMPERE).add().add(); - crac.newFlowCnec().withId("Line 3 - preventive").withNominalVoltage(400d).withNetworkElement("Line 3").withInstant("preventive").newThreshold().withSide(Side.LEFT).withMax(1000d).withUnit(Unit.AMPERE).add().add(); - crac.newFlowCnec().withId("Line 3 - curative - CO1").withNominalVoltage(400d).withNetworkElement("Line 3").withInstant("curative").withContingency("contingency-1").newThreshold().withSide(Side.LEFT).withMax(1000d).withUnit(Unit.AMPERE).add().add(); - crac.newFlowCnec().withId("Line 3 - curative - CO2").withNominalVoltage(400d).withNetworkElement("Line 3").withInstant("curative").withContingency("contingency-2").newThreshold().withSide(Side.LEFT).withMax(1000d).withUnit(Unit.AMPERE).add().add(); - crac.newFlowCnec().withId("Line 3 - curative - CO3").withNominalVoltage(400d).withNetworkElement("Line 3").withInstant("curative").withContingency("contingency-3").newThreshold().withSide(Side.LEFT).withMax(1000d).withUnit(Unit.AMPERE).add().add(); - crac.newFlowCnec().withId("Line 3 - curative - CO4").withNominalVoltage(400d).withNetworkElement("Line 3").withInstant("curative").withContingency("contingency-4").newThreshold().withSide(Side.LEFT).withMax(1000d).withUnit(Unit.AMPERE).add().add(); - crac.newFlowCnec().withId("Line 3 - curative - CO5").withNominalVoltage(400d).withNetworkElement("Line 3").withInstant("curative").withContingency("contingency-5").newThreshold().withSide(Side.LEFT).withMax(1000d).withUnit(Unit.AMPERE).add().add(); - crac.newFlowCnec().withId("Line 3 - curative - CO6").withNominalVoltage(400d).withNetworkElement("Line 3").withInstant("curative").withContingency("contingency-6").newThreshold().withSide(Side.LEFT).withMax(1000d).withUnit(Unit.AMPERE).add().add(); - crac.newFlowCnec().withId("Line 4 - curative - CO1").withNominalVoltage(400d).withNetworkElement("Line 4").withInstant("curative").withContingency("contingency-1").newThreshold().withSide(Side.LEFT).withMax(1000d).withUnit(Unit.AMPERE).add().add(); - crac.newFlowCnec().withId("Line 6 - curative - CO1").withNominalVoltage(400d).withNetworkElement("Line 6").withInstant("curative").withContingency("contingency-1").newThreshold().withSide(Side.LEFT).withMax(1000d).withUnit(Unit.AMPERE).add().add(); - crac.newFlowCnec().withId("Line 8 - curative - CO1").withNominalVoltage(400d).withNetworkElement("Line 8").withInstant("curative").withContingency("contingency-1").newThreshold().withSide(Side.LEFT).withMax(1000d).withUnit(Unit.AMPERE).add().add(); + crac.newFlowCnec().withId("Line 1 - curative - CO1").withNominalVoltage(400d).withNetworkElement("Line 1").withInstant("curative").withContingency("contingency-1").newThreshold().withSide(TwoSides.ONE).withMax(1000d).withUnit(Unit.AMPERE).add().add(); + crac.newFlowCnec().withId("Line 2 - preventive").withNominalVoltage(400d).withNetworkElement("Line 2").withInstant("preventive").newThreshold().withSide(TwoSides.ONE).withMax(1000d).withUnit(Unit.AMPERE).add().add(); + crac.newFlowCnec().withId("Line 2 - curative - CO1").withNominalVoltage(400d).withNetworkElement("Line 2").withInstant("curative").withContingency("contingency-1").newThreshold().withSide(TwoSides.ONE).withMax(1000d).withUnit(Unit.AMPERE).add().add(); + crac.newFlowCnec().withId("Line 2 - curative - CO2").withNominalVoltage(400d).withNetworkElement("Line 2").withInstant("curative").withContingency("contingency-2").newThreshold().withSide(TwoSides.ONE).withMax(1000d).withUnit(Unit.AMPERE).add().add(); + crac.newFlowCnec().withId("Line 2 - curative - CO3").withNominalVoltage(400d).withNetworkElement("Line 2").withInstant("curative").withContingency("contingency-3").newThreshold().withSide(TwoSides.ONE).withMax(1000d).withUnit(Unit.AMPERE).add().add(); + crac.newFlowCnec().withId("Line 2 - curative - CO4").withNominalVoltage(400d).withNetworkElement("Line 2").withInstant("curative").withContingency("contingency-4").newThreshold().withSide(TwoSides.ONE).withMax(1000d).withUnit(Unit.AMPERE).add().add(); + crac.newFlowCnec().withId("Line 2 - curative - CO5").withNominalVoltage(400d).withNetworkElement("Line 2").withInstant("curative").withContingency("contingency-5").newThreshold().withSide(TwoSides.ONE).withMax(1000d).withUnit(Unit.AMPERE).add().add(); + crac.newFlowCnec().withId("Line 2 - curative - CO6").withNominalVoltage(400d).withNetworkElement("Line 2").withInstant("curative").withContingency("contingency-6").newThreshold().withSide(TwoSides.ONE).withMax(1000d).withUnit(Unit.AMPERE).add().add(); + crac.newFlowCnec().withId("Line 3 - preventive").withNominalVoltage(400d).withNetworkElement("Line 3").withInstant("preventive").newThreshold().withSide(TwoSides.ONE).withMax(1000d).withUnit(Unit.AMPERE).add().add(); + crac.newFlowCnec().withId("Line 3 - curative - CO1").withNominalVoltage(400d).withNetworkElement("Line 3").withInstant("curative").withContingency("contingency-1").newThreshold().withSide(TwoSides.ONE).withMax(1000d).withUnit(Unit.AMPERE).add().add(); + crac.newFlowCnec().withId("Line 3 - curative - CO2").withNominalVoltage(400d).withNetworkElement("Line 3").withInstant("curative").withContingency("contingency-2").newThreshold().withSide(TwoSides.ONE).withMax(1000d).withUnit(Unit.AMPERE).add().add(); + crac.newFlowCnec().withId("Line 3 - curative - CO3").withNominalVoltage(400d).withNetworkElement("Line 3").withInstant("curative").withContingency("contingency-3").newThreshold().withSide(TwoSides.ONE).withMax(1000d).withUnit(Unit.AMPERE).add().add(); + crac.newFlowCnec().withId("Line 3 - curative - CO4").withNominalVoltage(400d).withNetworkElement("Line 3").withInstant("curative").withContingency("contingency-4").newThreshold().withSide(TwoSides.ONE).withMax(1000d).withUnit(Unit.AMPERE).add().add(); + crac.newFlowCnec().withId("Line 3 - curative - CO5").withNominalVoltage(400d).withNetworkElement("Line 3").withInstant("curative").withContingency("contingency-5").newThreshold().withSide(TwoSides.ONE).withMax(1000d).withUnit(Unit.AMPERE).add().add(); + crac.newFlowCnec().withId("Line 3 - curative - CO6").withNominalVoltage(400d).withNetworkElement("Line 3").withInstant("curative").withContingency("contingency-6").newThreshold().withSide(TwoSides.ONE).withMax(1000d).withUnit(Unit.AMPERE).add().add(); + crac.newFlowCnec().withId("Line 4 - curative - CO1").withNominalVoltage(400d).withNetworkElement("Line 4").withInstant("curative").withContingency("contingency-1").newThreshold().withSide(TwoSides.ONE).withMax(1000d).withUnit(Unit.AMPERE).add().add(); + crac.newFlowCnec().withId("Line 6 - curative - CO1").withNominalVoltage(400d).withNetworkElement("Line 6").withInstant("curative").withContingency("contingency-1").newThreshold().withSide(TwoSides.ONE).withMax(1000d).withUnit(Unit.AMPERE).add().add(); + crac.newFlowCnec().withId("Line 8 - curative - CO1").withNominalVoltage(400d).withNetworkElement("Line 8").withInstant("curative").withContingency("contingency-1").newThreshold().withSide(TwoSides.ONE).withMax(1000d).withUnit(Unit.AMPERE).add().add(); // Add CNEC creation contexts diff --git a/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/remedialaction/PstRangeActionCreationTest.java b/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/remedialaction/PstRangeActionCreationTest.java index f6f526f701..4fb266b19e 100644 --- a/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/remedialaction/PstRangeActionCreationTest.java +++ b/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/remedialaction/PstRangeActionCreationTest.java @@ -7,8 +7,8 @@ package com.powsybl.openrao.data.craccreation.creator.csaprofile.craccreator.remedialaction; import com.powsybl.contingency.Contingency; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.usagerule.UsageMethod; import com.powsybl.openrao.data.craccreation.creator.api.ImportStatus; @@ -90,28 +90,28 @@ void importPstSps0second() { List importedFlowCnecs = cracCreationContext.getCrac().getFlowCnecs().stream().sorted(Comparator.comparing(FlowCnec::getId)).toList(); assertEquals(5, importedFlowCnecs.size()); - assertFlowCnecEquality(importedFlowCnecs.get(0), "RTE_AE1 (ae-1) - RTE_CO - auto - RIGHT - TATL 900", "FFR2AA1 FFR3AA1 1", - AUTO_INSTANT_ID, "contingency", null, null, 4000.0, -4000.0, Set.of(Side.RIGHT), "RTE"); - assertFlowCnecEquality(importedFlowCnecs.get(1), "RTE_AE1 (ae-1) - RTE_CO - curative 1 - RIGHT - TATL 900", "FFR2AA1 FFR3AA1 1", - CURATIVE_1_INSTANT_ID, "contingency", null, null, 4000.0, -4000.0, Set.of(Side.RIGHT), "RTE"); - assertFlowCnecEquality(importedFlowCnecs.get(2), "RTE_AE2 (ae-2) - RTE_CO - curative 2 - RIGHT", "FFR2AA1 FFR3AA1 1", - CURATIVE_2_INSTANT_ID, "contingency", null, null, 2500.0, -2500.0, Set.of(Side.RIGHT), "RTE"); - assertFlowCnecEquality(importedFlowCnecs.get(3), "RTE_AE2 (ae-2) - RTE_CO - curative 3 - RIGHT", "FFR2AA1 FFR3AA1 1", - CURATIVE_3_INSTANT_ID, "contingency", null, null, 2500.0, -2500.0, Set.of(Side.RIGHT), "RTE"); - assertFlowCnecEquality(importedFlowCnecs.get(4), "RTE_AE2 (ae-2) - preventive - RIGHT", "FFR2AA1 FFR3AA1 1", - PREVENTIVE_INSTANT_ID, null, null, null, 2500.0, -2500.0, Set.of(Side.RIGHT), "RTE"); + assertFlowCnecEquality(importedFlowCnecs.get(0), "RTE_AE1 (ae-1) - RTE_CO - auto - TWO - TATL 900", "FFR2AA1 FFR3AA1 1", + AUTO_INSTANT_ID, "contingency", null, null, 4000.0, -4000.0, Set.of(TwoSides.TWO), "RTE"); + assertFlowCnecEquality(importedFlowCnecs.get(1), "RTE_AE1 (ae-1) - RTE_CO - curative 1 - TWO - TATL 900", "FFR2AA1 FFR3AA1 1", + CURATIVE_1_INSTANT_ID, "contingency", null, null, 4000.0, -4000.0, Set.of(TwoSides.TWO), "RTE"); + assertFlowCnecEquality(importedFlowCnecs.get(2), "RTE_AE2 (ae-2) - RTE_CO - curative 2 - TWO", "FFR2AA1 FFR3AA1 1", + CURATIVE_2_INSTANT_ID, "contingency", null, null, 2500.0, -2500.0, Set.of(TwoSides.TWO), "RTE"); + assertFlowCnecEquality(importedFlowCnecs.get(3), "RTE_AE2 (ae-2) - RTE_CO - curative 3 - TWO", "FFR2AA1 FFR3AA1 1", + CURATIVE_3_INSTANT_ID, "contingency", null, null, 2500.0, -2500.0, Set.of(TwoSides.TWO), "RTE"); + assertFlowCnecEquality(importedFlowCnecs.get(4), "RTE_AE2 (ae-2) - preventive - TWO", "FFR2AA1 FFR3AA1 1", + PREVENTIVE_INSTANT_ID, null, null, null, 2500.0, -2500.0, Set.of(TwoSides.TWO), "RTE"); List importedPstRangeActions = cracCreationContext.getCrac().getPstRangeActions().stream().sorted(Comparator.comparing(PstRangeAction::getId)).toList(); assertEquals(3, importedPstRangeActions.size()); assertPstRangeActionImported(cracCreationContext, "auto-pst-be2-be3", "BBE2AA1 BBE3AA1 1", false, 1, null); - assertHasOnConstraintUsageRule(cracCreationContext, "auto-pst-be2-be3", "RTE_AE1 (ae-1) - RTE_CO - auto - RIGHT - TATL 900", cracCreationContext.getCrac().getInstant(AUTO_INSTANT_ID), UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "auto-pst-be2-be3", "RTE_AE1 (ae-1) - RTE_CO - auto - TWO - TATL 900", cracCreationContext.getCrac().getInstant(AUTO_INSTANT_ID), UsageMethod.FORCED, FlowCnec.class); assertPstRangeActionImported(cracCreationContext, "cra-pst-be2-be3", "BBE2AA1 BBE3AA1 1", false, 5, null); - assertHasOnConstraintUsageRule(cracCreationContext, "cra-pst-be2-be3", "RTE_AE2 (ae-2) - RTE_CO - curative 2 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_1_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "cra-pst-be2-be3", "RTE_AE2 (ae-2) - RTE_CO - curative 2 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "cra-pst-be2-be3", "RTE_AE2 (ae-2) - RTE_CO - curative 3 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_1_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "cra-pst-be2-be3", "RTE_AE2 (ae-2) - RTE_CO - curative 3 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "cra-pst-be2-be3", "RTE_AE2 (ae-2) - RTE_CO - curative 3 - RIGHT", cracCreationContext.getCrac().getInstant(CURATIVE_3_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "cra-pst-be2-be3", "RTE_AE2 (ae-2) - RTE_CO - curative 2 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_1_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "cra-pst-be2-be3", "RTE_AE2 (ae-2) - RTE_CO - curative 2 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "cra-pst-be2-be3", "RTE_AE2 (ae-2) - RTE_CO - curative 3 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_1_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "cra-pst-be2-be3", "RTE_AE2 (ae-2) - RTE_CO - curative 3 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_2_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "cra-pst-be2-be3", "RTE_AE2 (ae-2) - RTE_CO - curative 3 - TWO", cracCreationContext.getCrac().getInstant(CURATIVE_3_INSTANT_ID), UsageMethod.AVAILABLE, FlowCnec.class); assertPstRangeActionImported(cracCreationContext, "cra-pst-fr2-fr4", "FFR2AA1 FFR4AA1 1", false, 3, null); assertHasOnInstantUsageRule(cracCreationContext, "cra-pst-fr2-fr4", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE); assertHasOnInstantUsageRule(cracCreationContext, "cra-pst-fr2-fr4", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE); @@ -131,16 +131,16 @@ void importPstSps60seconds() { List importedFlowCnecs = cracCreationContext.getCrac().getFlowCnecs().stream().sorted(Comparator.comparing(FlowCnec::getId)).toList(); assertEquals(5, importedFlowCnecs.size()); - assertFlowCnecEquality(importedFlowCnecs.get(0), "RTE_AE1 (ae-1) - RTE_CO - auto - RIGHT - TATL 900", "FFR2AA1 FFR3AA1 1", - AUTO_INSTANT_ID, "contingency", null, null, 4000.0, -4000.0, Set.of(Side.RIGHT), "RTE"); - assertFlowCnecEquality(importedFlowCnecs.get(1), "RTE_AE1 (ae-1) - RTE_CO - curative 1 - RIGHT - TATL 900", "FFR2AA1 FFR3AA1 1", - CURATIVE_1_INSTANT_ID, "contingency", null, null, 4000.0, -4000.0, Set.of(Side.RIGHT), "RTE"); - assertFlowCnecEquality(importedFlowCnecs.get(2), "RTE_AE2 (ae-2) - RTE_CO - curative 2 - RIGHT", "FFR2AA1 FFR3AA1 1", - CURATIVE_2_INSTANT_ID, "contingency", null, null, 2500.0, -2500.0, Set.of(Side.RIGHT), "RTE"); - assertFlowCnecEquality(importedFlowCnecs.get(3), "RTE_AE2 (ae-2) - RTE_CO - curative 3 - RIGHT", "FFR2AA1 FFR3AA1 1", - CURATIVE_3_INSTANT_ID, "contingency", null, null, 2500.0, -2500.0, Set.of(Side.RIGHT), "RTE"); - assertFlowCnecEquality(importedFlowCnecs.get(4), "RTE_AE2 (ae-2) - preventive - RIGHT", "FFR2AA1 FFR3AA1 1", - PREVENTIVE_INSTANT_ID, null, null, null, 2500.0, -2500.0, Set.of(Side.RIGHT), "RTE"); + assertFlowCnecEquality(importedFlowCnecs.get(0), "RTE_AE1 (ae-1) - RTE_CO - auto - TWO - TATL 900", "FFR2AA1 FFR3AA1 1", + AUTO_INSTANT_ID, "contingency", null, null, 4000.0, -4000.0, Set.of(TwoSides.TWO), "RTE"); + assertFlowCnecEquality(importedFlowCnecs.get(1), "RTE_AE1 (ae-1) - RTE_CO - curative 1 - TWO - TATL 900", "FFR2AA1 FFR3AA1 1", + CURATIVE_1_INSTANT_ID, "contingency", null, null, 4000.0, -4000.0, Set.of(TwoSides.TWO), "RTE"); + assertFlowCnecEquality(importedFlowCnecs.get(2), "RTE_AE2 (ae-2) - RTE_CO - curative 2 - TWO", "FFR2AA1 FFR3AA1 1", + CURATIVE_2_INSTANT_ID, "contingency", null, null, 2500.0, -2500.0, Set.of(TwoSides.TWO), "RTE"); + assertFlowCnecEquality(importedFlowCnecs.get(3), "RTE_AE2 (ae-2) - RTE_CO - curative 3 - TWO", "FFR2AA1 FFR3AA1 1", + CURATIVE_3_INSTANT_ID, "contingency", null, null, 2500.0, -2500.0, Set.of(TwoSides.TWO), "RTE"); + assertFlowCnecEquality(importedFlowCnecs.get(4), "RTE_AE2 (ae-2) - preventive - TWO", "FFR2AA1 FFR3AA1 1", + PREVENTIVE_INSTANT_ID, null, null, null, 2500.0, -2500.0, Set.of(TwoSides.TWO), "RTE"); List importedPstRangeActions = cracCreationContext.getCrac().getPstRangeActions().stream().sorted(Comparator.comparing(PstRangeAction::getId)).toList(); assertEquals(3, importedPstRangeActions.size()); diff --git a/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/remedialaction/RemedialActionCreationTest.java b/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/remedialaction/RemedialActionCreationTest.java index 6c728ad2ba..23d1a4d7ab 100644 --- a/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/remedialaction/RemedialActionCreationTest.java +++ b/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/powsybl/openrao/data/craccreation/creator/csaprofile/craccreator/remedialaction/RemedialActionCreationTest.java @@ -88,67 +88,67 @@ void testUsageRulesCreation() { assertPstRangeActionImported((PstRangeAction) importedRemedialActions.get(0), "remedial-action-1", "RTE_RA1", "BBE2AA1 BBE3AA1 1", null, null, "RTE"); assertEquals(23, importedRemedialActions.get(0).getUsageRules().size()); assertHasOnInstantUsageRule(cracCreationContext, "remedial-action-1", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - preventive - LEFT", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - preventive - RIGHT", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - outage - LEFT - TATL 60", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - outage - RIGHT - TATL 60", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - auto - LEFT - TATL 900", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - auto - RIGHT - TATL 900", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 1 - LEFT - TATL 900", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 1 - RIGHT - TATL 900", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - LEFT", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - RIGHT", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - LEFT", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - RIGHT", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO2 - outage - LEFT - TATL 60", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO2 - outage - RIGHT - TATL 60", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO2 - auto - LEFT - TATL 900", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO2 - auto - RIGHT - TATL 900", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 1 - LEFT - TATL 900", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 1 - RIGHT - TATL 900", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - LEFT", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - RIGHT", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - LEFT", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - RIGHT", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - preventive - ONE", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - preventive - TWO", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - outage - ONE - TATL 60", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - outage - TWO - TATL 60", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - auto - ONE - TATL 900", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - auto - TWO - TATL 900", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 1 - ONE - TATL 900", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 1 - TWO - TATL 900", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - ONE", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - TWO", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - ONE", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - TWO", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO2 - outage - ONE - TATL 60", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO2 - outage - TWO - TATL 60", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO2 - auto - ONE - TATL 900", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO2 - auto - TWO - TATL 900", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 1 - ONE - TATL 900", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 1 - TWO - TATL 900", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - ONE", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - TWO", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - ONE", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-1", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - TWO", PREVENTIVE_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); assertPstRangeActionImported((PstRangeAction) importedRemedialActions.get(2), "remedial-action-2", "RTE_RA2", "BBE2AA1 BBE3AA1 1", null, null, "RTE"); assertEquals(27, importedRemedialActions.get(2).getUsageRules().size()); assertHasOnInstantUsageRule(cracCreationContext, "remedial-action-2", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE); assertHasOnInstantUsageRule(cracCreationContext, "remedial-action-2", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE); assertHasOnInstantUsageRule(cracCreationContext, "remedial-action-2", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 1 - LEFT - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 1 - RIGHT - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - LEFT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - RIGHT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - LEFT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - RIGHT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - LEFT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - RIGHT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - LEFT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - RIGHT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - LEFT", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - RIGHT", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 1 - LEFT - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 1 - RIGHT - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - LEFT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - RIGHT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - LEFT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - RIGHT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - LEFT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - RIGHT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - LEFT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - RIGHT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - LEFT", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - RIGHT", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 1 - ONE - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 1 - TWO - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - ONE", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - TWO", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - ONE", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - TWO", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - ONE", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - TWO", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - ONE", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - TWO", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - ONE", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - TWO", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 1 - ONE - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 1 - TWO - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - ONE", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - TWO", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - ONE", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - TWO", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - ONE", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - TWO", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - ONE", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - TWO", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - ONE", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-2", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - TWO", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); assertPstRangeActionImported((PstRangeAction) importedRemedialActions.get(3), "remedial-action-3", "RTE_RA3", "BBE2AA1 BBE3AA1 1", null, null, "RTE"); assertEquals(6, importedRemedialActions.get(3).getUsageRules().size()); assertHasOnContingencyStateUsageRule(cracCreationContext, "remedial-action-3", "contingency-1", AUTO_INSTANT_ID, UsageMethod.FORCED); assertHasOnContingencyStateUsageRule(cracCreationContext, "remedial-action-3", "contingency-2", AUTO_INSTANT_ID, UsageMethod.FORCED); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-3", "RTE_AE1 (assessed-element-1) - RTE_CO1 - auto - LEFT - TATL 900", AUTO_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-3", "RTE_AE1 (assessed-element-1) - RTE_CO1 - auto - RIGHT - TATL 900", AUTO_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-3", "RTE_AE1 (assessed-element-1) - RTE_CO2 - auto - LEFT - TATL 900", AUTO_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-3", "RTE_AE1 (assessed-element-1) - RTE_CO2 - auto - RIGHT - TATL 900", AUTO_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-3", "RTE_AE1 (assessed-element-1) - RTE_CO1 - auto - ONE - TATL 900", AUTO_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-3", "RTE_AE1 (assessed-element-1) - RTE_CO1 - auto - TWO - TATL 900", AUTO_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-3", "RTE_AE1 (assessed-element-1) - RTE_CO2 - auto - ONE - TATL 900", AUTO_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-3", "RTE_AE1 (assessed-element-1) - RTE_CO2 - auto - TWO - TATL 900", AUTO_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); assertPstRangeActionImported((PstRangeAction) importedRemedialActions.get(4), "remedial-action-4", "RTE_RA4", "BBE2AA1 BBE3AA1 1", null, null, "RTE"); assertEquals(30, importedRemedialActions.get(4).getUsageRules().size()); @@ -158,139 +158,139 @@ void testUsageRulesCreation() { assertHasOnContingencyStateUsageRule(cracCreationContext, "remedial-action-4", "contingency-2", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE); assertHasOnContingencyStateUsageRule(cracCreationContext, "remedial-action-4", "contingency-2", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE); assertHasOnContingencyStateUsageRule(cracCreationContext, "remedial-action-4", "contingency-2", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 1 - LEFT - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 1 - RIGHT - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - LEFT", CURATIVE_1_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - RIGHT", CURATIVE_1_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - LEFT", CURATIVE_1_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - RIGHT", CURATIVE_1_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - LEFT", CURATIVE_2_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - RIGHT", CURATIVE_2_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - LEFT", CURATIVE_2_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - RIGHT", CURATIVE_2_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - LEFT", CURATIVE_3_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - RIGHT", CURATIVE_3_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 1 - LEFT - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 1 - RIGHT - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - LEFT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - RIGHT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - LEFT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - RIGHT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - LEFT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - RIGHT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - LEFT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - RIGHT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - LEFT", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - RIGHT", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 1 - ONE - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 1 - TWO - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - ONE", CURATIVE_1_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - TWO", CURATIVE_1_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - ONE", CURATIVE_1_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - TWO", CURATIVE_1_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - ONE", CURATIVE_2_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - TWO", CURATIVE_2_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - ONE", CURATIVE_2_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - TWO", CURATIVE_2_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - ONE", CURATIVE_3_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - TWO", CURATIVE_3_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 1 - ONE - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 1 - TWO - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - ONE", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - TWO", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - ONE", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - TWO", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - ONE", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - TWO", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - ONE", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - TWO", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - ONE", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-4", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - TWO", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); assertPstRangeActionImported((PstRangeAction) importedRemedialActions.get(5), "remedial-action-5", "RTE_RA5", "BBE2AA1 BBE3AA1 1", null, null, "RTE"); assertEquals(4, importedRemedialActions.get(5).getUsageRules().size()); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-5", "RTE_AE1 (assessed-element-1) - RTE_CO2 - auto - LEFT - TATL 900", AUTO_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-5", "RTE_AE1 (assessed-element-1) - RTE_CO2 - auto - RIGHT - TATL 900", AUTO_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-5", "RTE_AE2 (assessed-element-2) - RTE_CO2 - auto - LEFT - TATL 900", AUTO_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-5", "RTE_AE2 (assessed-element-2) - RTE_CO2 - auto - RIGHT - TATL 900", AUTO_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-5", "RTE_AE1 (assessed-element-1) - RTE_CO2 - auto - ONE - TATL 900", AUTO_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-5", "RTE_AE1 (assessed-element-1) - RTE_CO2 - auto - TWO - TATL 900", AUTO_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-5", "RTE_AE2 (assessed-element-2) - RTE_CO2 - auto - ONE - TATL 900", AUTO_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-5", "RTE_AE2 (assessed-element-2) - RTE_CO2 - auto - TWO - TATL 900", AUTO_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); assertPstRangeActionImported((PstRangeAction) importedRemedialActions.get(6), "remedial-action-6", "RTE_RA6", "BBE2AA1 BBE3AA1 1", null, null, "RTE"); assertEquals(24, importedRemedialActions.get(6).getUsageRules().size()); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 1 - LEFT - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 1 - RIGHT - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - LEFT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - RIGHT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - LEFT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - RIGHT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - LEFT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - RIGHT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - LEFT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - RIGHT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - LEFT", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - RIGHT", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 1 - LEFT - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 1 - RIGHT - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 2 - LEFT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 2 - RIGHT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 3 - LEFT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 3 - RIGHT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 2 - LEFT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 2 - RIGHT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 3 - LEFT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 3 - RIGHT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 3 - LEFT", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 3 - RIGHT", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 1 - ONE - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 1 - TWO - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - ONE", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - TWO", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - ONE", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - TWO", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - ONE", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - TWO", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - ONE", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - TWO", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - ONE", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - TWO", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 1 - ONE - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 1 - TWO - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 2 - ONE", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 2 - TWO", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 3 - ONE", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 3 - TWO", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 2 - ONE", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 2 - TWO", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 3 - ONE", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 3 - TWO", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 3 - ONE", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-6", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 3 - TWO", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); assertPstRangeActionImported((PstRangeAction) importedRemedialActions.get(7), "remedial-action-7", "RTE_RA7", "BBE2AA1 BBE3AA1 1", null, null, "RTE"); assertEquals(6, importedRemedialActions.get(7).getUsageRules().size()); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-7", "RTE_AE1 (assessed-element-1) - RTE_CO1 - auto - LEFT - TATL 900", AUTO_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-7", "RTE_AE1 (assessed-element-1) - RTE_CO1 - auto - RIGHT - TATL 900", AUTO_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-7", "RTE_AE1 (assessed-element-1) - RTE_CO2 - auto - LEFT - TATL 900", AUTO_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-7", "RTE_AE1 (assessed-element-1) - RTE_CO2 - auto - RIGHT - TATL 900", AUTO_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-7", "RTE_AE2 (assessed-element-2) - RTE_CO2 - auto - LEFT - TATL 900", AUTO_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-7", "RTE_AE2 (assessed-element-2) - RTE_CO2 - auto - RIGHT - TATL 900", AUTO_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-7", "RTE_AE1 (assessed-element-1) - RTE_CO1 - auto - ONE - TATL 900", AUTO_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-7", "RTE_AE1 (assessed-element-1) - RTE_CO1 - auto - TWO - TATL 900", AUTO_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-7", "RTE_AE1 (assessed-element-1) - RTE_CO2 - auto - ONE - TATL 900", AUTO_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-7", "RTE_AE1 (assessed-element-1) - RTE_CO2 - auto - TWO - TATL 900", AUTO_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-7", "RTE_AE2 (assessed-element-2) - RTE_CO2 - auto - ONE - TATL 900", AUTO_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-7", "RTE_AE2 (assessed-element-2) - RTE_CO2 - auto - TWO - TATL 900", AUTO_INSTANT_ID, UsageMethod.FORCED, FlowCnec.class); assertPstRangeActionImported((PstRangeAction) importedRemedialActions.get(8), "remedial-action-8", "RTE_RA8", "BBE2AA1 BBE3AA1 1", null, null, "RTE"); assertEquals(36, importedRemedialActions.get(8).getUsageRules().size()); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 1 - LEFT - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 1 - RIGHT - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - LEFT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - RIGHT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - LEFT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - RIGHT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - LEFT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - RIGHT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - LEFT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - RIGHT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - LEFT", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - RIGHT", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 1 - LEFT - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 1 - RIGHT - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - LEFT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - RIGHT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - LEFT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - RIGHT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - LEFT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - RIGHT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - LEFT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - RIGHT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - LEFT", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - RIGHT", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 1 - LEFT - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 1 - RIGHT - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 2 - LEFT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 2 - RIGHT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 3 - LEFT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 3 - RIGHT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 2 - LEFT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 2 - RIGHT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 3 - LEFT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 3 - RIGHT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 3 - LEFT", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 3 - RIGHT", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 1 - ONE - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 1 - TWO - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - ONE", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - TWO", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - ONE", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - TWO", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - ONE", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - TWO", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - ONE", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - TWO", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - ONE", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - TWO", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 1 - ONE - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 1 - TWO - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - ONE", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - TWO", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - ONE", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - TWO", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - ONE", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - TWO", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - ONE", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - TWO", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - ONE", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - TWO", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 1 - ONE - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 1 - TWO - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 2 - ONE", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 2 - TWO", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 3 - ONE", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 3 - TWO", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 2 - ONE", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 2 - TWO", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 3 - ONE", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 3 - TWO", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 3 - ONE", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-8", "RTE_AE2 (assessed-element-2) - RTE_CO2 - curative 3 - TWO", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); assertPstRangeActionImported((PstRangeAction) importedRemedialActions.get(9), "remedial-action-9", "RTE_RA9", "BBE2AA1 BBE3AA1 1", null, null, "RTE"); assertEquals(24, importedRemedialActions.get(9).getUsageRules().size()); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 1 - LEFT - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 1 - RIGHT - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - LEFT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - RIGHT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - LEFT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - RIGHT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - LEFT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - RIGHT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - LEFT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - RIGHT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - LEFT", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - RIGHT", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 1 - LEFT - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 1 - RIGHT - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - LEFT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - RIGHT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - LEFT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - RIGHT", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - LEFT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - RIGHT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - LEFT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - RIGHT", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - LEFT", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); - assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - RIGHT", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 1 - ONE - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 1 - TWO - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - ONE", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - TWO", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - ONE", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - TWO", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - ONE", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 2 - TWO", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - ONE", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - TWO", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - ONE", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO1 - curative 3 - TWO", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 1 - ONE - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 1 - TWO - TATL 900", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - ONE", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - TWO", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - ONE", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - TWO", CURATIVE_1_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - ONE", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 2 - TWO", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - ONE", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - TWO", CURATIVE_2_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - ONE", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); + assertHasOnConstraintUsageRule(cracCreationContext, "remedial-action-9", "RTE_AE1 (assessed-element-1) - RTE_CO2 - curative 3 - TWO", CURATIVE_3_INSTANT_ID, UsageMethod.AVAILABLE, FlowCnec.class); assertPstRangeActionImported((PstRangeAction) importedRemedialActions.get(1), "remedial-action-10", "RTE_RA10", "BBE2AA1 BBE3AA1 1", null, null, "RTE"); assertTrue(importedRemedialActions.get(1).getUsageRules().isEmpty()); diff --git a/data/crac-creation/crac-creator-cse/src/main/java/com/powsybl/openrao/data/craccreation/creator/cse/criticalbranch/CriticalBranchReader.java b/data/crac-creation/crac-creator-cse/src/main/java/com/powsybl/openrao/data/craccreation/creator/cse/criticalbranch/CriticalBranchReader.java index e2186c2664..ddaaabffc2 100644 --- a/data/crac-creation/crac-creator-cse/src/main/java/com/powsybl/openrao/data/craccreation/creator/cse/criticalbranch/CriticalBranchReader.java +++ b/data/crac-creation/crac-creator-cse/src/main/java/com/powsybl/openrao/data/craccreation/creator/cse/criticalbranch/CriticalBranchReader.java @@ -11,7 +11,7 @@ import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.InstantKind; import com.powsybl.openrao.data.cracapi.cnec.FlowCnecAdder; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.threshold.BranchThresholdAdder; import com.powsybl.openrao.data.craccreation.creator.api.ImportStatus; import com.powsybl.openrao.data.craccreation.creator.api.stdcreationcontext.NativeBranch; @@ -20,7 +20,6 @@ import com.powsybl.openrao.data.craccreation.creator.cse.xsd.TOutage; import com.powsybl.openrao.data.craccreation.util.ucte.UcteFlowElementHelper; import com.powsybl.openrao.data.craccreation.util.ucte.UcteNetworkAnalyzer; -import com.powsybl.iidm.network.TwoSides; import javax.annotation.Nullable; import java.util.*; @@ -41,7 +40,7 @@ public class CriticalBranchReader { private boolean selected; private final Set remedialActionIds = new HashSet<>(); private final ImportStatus criticalBranchImportStatus; - private Set monitoredSides; + private Set monitoredSides; public String getCriticalBranchName() { return criticalBranchName; @@ -79,7 +78,7 @@ public boolean isSelected() { return selected; } - public CriticalBranchReader(List tBranches, @Nullable TOutage tOutage, Crac crac, UcteNetworkAnalyzer ucteNetworkAnalyzer, Set defaultMonitoredSides, boolean isMonitored) { + public CriticalBranchReader(List tBranches, @Nullable TOutage tOutage, Crac crac, UcteNetworkAnalyzer ucteNetworkAnalyzer, Set defaultMonitoredSides, boolean isMonitored) { if (tBranches.size() > 1) { this.criticalBranchName = tBranches.stream().map(tBranch -> tBranch.getName().getV()).collect(Collectors.joining(" ; ")); this.nativeBranch = new NativeBranch(tBranches.get(0).getFromNode().toString(), tBranches.get(0).getToNode().toString(), tBranches.get(0).getOrder().toString()); @@ -99,7 +98,7 @@ public CriticalBranchReader(List tBranches, @Nullable TOutage tOutage, this.criticalBranchImportStatus = ImportStatus.ELEMENT_NOT_FOUND_IN_NETWORK; return; } - this.monitoredSides = branchHelper.isHalfLine() ? Set.of(Side.fromIidmSide(branchHelper.getHalfLineSide())) : defaultMonitoredSides; + this.monitoredSides = branchHelper.isHalfLine() ? Set.of(branchHelper.getHalfLineSide()) : defaultMonitoredSides; if (tOutage != null && crac.getContingency(outage) == null) { this.isImported = false; this.criticalBranchImportStatus = ImportStatus.INCOMPLETE_DATA; @@ -155,18 +154,18 @@ private void importCnec(Crac crac, TBranch tBranch, UcteFlowElementHelper branch .withContingency(outage) .withOptimized(selected).withMonitored(isMonitored) .withNetworkElement(branchHelper.getIdInNetwork()) - .withIMax(branchHelper.getCurrentLimit(TwoSides.ONE), Side.LEFT) - .withIMax(branchHelper.getCurrentLimit(TwoSides.TWO), Side.RIGHT) - .withNominalVoltage(branchHelper.getNominalVoltage(TwoSides.ONE), Side.LEFT) - .withNominalVoltage(branchHelper.getNominalVoltage(TwoSides.TWO), Side.RIGHT); + .withIMax(branchHelper.getCurrentLimit(TwoSides.ONE), TwoSides.ONE) + .withIMax(branchHelper.getCurrentLimit(TwoSides.TWO), TwoSides.TWO) + .withNominalVoltage(branchHelper.getNominalVoltage(TwoSides.ONE), TwoSides.ONE) + .withNominalVoltage(branchHelper.getNominalVoltage(TwoSides.TWO), TwoSides.TWO); - Set monitoredSidesForThreshold = monitoredSides; + Set monitoredSidesForThreshold = monitoredSides; Unit unit = convertUnit(tImax.getUnit()); // For transformers, if unit is absolute amperes, monitor low voltage side if (!branchHelper.isHalfLine() && unit.equals(Unit.AMPERE) && Math.abs(branchHelper.getNominalVoltage(TwoSides.ONE) - branchHelper.getNominalVoltage(TwoSides.TWO)) > 1) { monitoredSidesForThreshold = (branchHelper.getNominalVoltage(TwoSides.ONE) <= branchHelper.getNominalVoltage(TwoSides.TWO)) ? - Set.of(Side.LEFT) : Set.of(Side.RIGHT); + Set.of(TwoSides.ONE) : Set.of(TwoSides.TWO); } addThreshold(cnecAdder, tImax.getV(), unit, tBranch.getDirection().getV(), isDirectionInverted, monitoredSidesForThreshold); cnecAdder.add(); @@ -182,7 +181,7 @@ private void storeRemedialActions(TBranch tBranch) { ); } - private static void addThreshold(FlowCnecAdder cnecAdder, double positiveLimit, Unit unit, String direction, boolean invert, Set monitoredSides) { + private static void addThreshold(FlowCnecAdder cnecAdder, double positiveLimit, Unit unit, String direction, boolean invert, Set monitoredSides) { monitoredSides.forEach(side -> { BranchThresholdAdder branchThresholdAdder = cnecAdder.newThreshold() .withSide(side) diff --git a/data/crac-creation/crac-creator-cse/src/main/java/com/powsybl/openrao/data/craccreation/creator/cse/criticalbranch/TCriticalBranchesAdder.java b/data/crac-creation/crac-creator-cse/src/main/java/com/powsybl/openrao/data/craccreation/creator/cse/criticalbranch/TCriticalBranchesAdder.java index 923598f66f..bc93f59e85 100644 --- a/data/crac-creation/crac-creator-cse/src/main/java/com/powsybl/openrao/data/craccreation/creator/cse/criticalbranch/TCriticalBranchesAdder.java +++ b/data/crac-creation/crac-creator-cse/src/main/java/com/powsybl/openrao/data/craccreation/creator/cse/criticalbranch/TCriticalBranchesAdder.java @@ -7,7 +7,7 @@ package com.powsybl.openrao.data.craccreation.creator.cse.criticalbranch; import com.powsybl.openrao.data.cracapi.Crac; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.craccreation.creator.cse.*; import com.powsybl.openrao.data.craccreation.creator.cse.xsd.*; import com.powsybl.openrao.data.craccreation.util.ucte.UcteNetworkAnalyzer; @@ -23,9 +23,9 @@ public class TCriticalBranchesAdder { private final UcteNetworkAnalyzer ucteNetworkAnalyzer; private final CseCracCreationContext cseCracCreationContext; private final Map> remedialActionsForCnecsMap = new HashMap<>(); // contains for each RA the set of CNEC IDs for which it can be activated - private final Set defaultMonitoredSides; + private final Set defaultMonitoredSides; - public TCriticalBranchesAdder(TCRACSeries tcracSeries, Crac crac, UcteNetworkAnalyzer ucteNetworkAnalyzer, CseCracCreationContext cseCracCreationContext, Set defaultMonitoredSides) { + public TCriticalBranchesAdder(TCRACSeries tcracSeries, Crac crac, UcteNetworkAnalyzer ucteNetworkAnalyzer, CseCracCreationContext cseCracCreationContext, Set defaultMonitoredSides) { this.tcracSeries = tcracSeries; this.crac = crac; this.ucteNetworkAnalyzer = ucteNetworkAnalyzer; diff --git a/data/crac-creation/crac-creator-cse/src/main/java/com/powsybl/openrao/data/craccreation/creator/cse/criticalbranch/TMonitoredElementsAdder.java b/data/crac-creation/crac-creator-cse/src/main/java/com/powsybl/openrao/data/craccreation/creator/cse/criticalbranch/TMonitoredElementsAdder.java index 22c5adaba2..989342b00b 100644 --- a/data/crac-creation/crac-creator-cse/src/main/java/com/powsybl/openrao/data/craccreation/creator/cse/criticalbranch/TMonitoredElementsAdder.java +++ b/data/crac-creation/crac-creator-cse/src/main/java/com/powsybl/openrao/data/craccreation/creator/cse/criticalbranch/TMonitoredElementsAdder.java @@ -7,7 +7,7 @@ package com.powsybl.openrao.data.craccreation.creator.cse.criticalbranch; import com.powsybl.openrao.data.cracapi.Crac; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.craccreation.creator.cse.*; import com.powsybl.openrao.data.craccreation.creator.cse.xsd.*; import com.powsybl.openrao.data.craccreation.util.ucte.UcteNetworkAnalyzer; @@ -23,9 +23,9 @@ public class TMonitoredElementsAdder { private final Crac crac; private final UcteNetworkAnalyzer ucteNetworkAnalyzer; private final CseCracCreationContext cseCracCreationContext; - private final Set defaultMonitoredSides; + private final Set defaultMonitoredSides; - public TMonitoredElementsAdder(TCRACSeries tcracSeries, Crac crac, UcteNetworkAnalyzer ucteNetworkAnalyzer, CseCracCreationContext cseCracCreationContext, Set defaultMonitoredSides) { + public TMonitoredElementsAdder(TCRACSeries tcracSeries, Crac crac, UcteNetworkAnalyzer ucteNetworkAnalyzer, CseCracCreationContext cseCracCreationContext, Set defaultMonitoredSides) { this.tcracSeries = tcracSeries; this.crac = crac; this.ucteNetworkAnalyzer = ucteNetworkAnalyzer; diff --git a/data/crac-creation/crac-creator-cse/src/test/java/com/powsybl/openrao/data/craccreation/creator/cse/CseCracCreatorTest.java b/data/crac-creation/crac-creator-cse/src/test/java/com/powsybl/openrao/data/craccreation/creator/cse/CseCracCreatorTest.java index eaed483c24..691bcb807f 100644 --- a/data/crac-creation/crac-creator-cse/src/test/java/com/powsybl/openrao/data/craccreation/creator/cse/CseCracCreatorTest.java +++ b/data/crac-creation/crac-creator-cse/src/test/java/com/powsybl/openrao/data/craccreation/creator/cse/CseCracCreatorTest.java @@ -9,7 +9,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.*; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.networkaction.SwitchPair; import com.powsybl.openrao.data.cracapi.range.RangeType; @@ -362,52 +362,52 @@ void testRaOnConstraint() { @Test void testPercentageThresholdsOnLeftSide() { - parameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_LEFT_SIDE); + parameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_SIDE_ONE); setUp("/cracs/cse_crac_pct_limit.xml"); FlowCnec flowCnec1 = importedCrac.getFlowCnec("basecase_branch_1 - NNL2AA1 ->NNL3AA1 - preventive"); assertEquals(1, flowCnec1.getThresholds().size()); assertEquals(0.7, flowCnec1.getThresholds().iterator().next().max().get(), DOUBLE_TOLERANCE); assertTrue(flowCnec1.getThresholds().iterator().next().min().isEmpty()); - assertEquals(0.7 * 5000., flowCnec1.getUpperBound(Side.LEFT, Unit.AMPERE).get(), DOUBLE_TOLERANCE); + assertEquals(0.7 * 5000., flowCnec1.getUpperBound(TwoSides.ONE, Unit.AMPERE).get(), DOUBLE_TOLERANCE); FlowCnec flowCnec2 = importedCrac.getFlowCnec("basecase_branch_2 - NNL1AA1 ->NNL3AA1 - preventive"); assertEquals(1, flowCnec2.getThresholds().size()); assertEquals(-1., flowCnec2.getThresholds().iterator().next().min().get(), DOUBLE_TOLERANCE); assertTrue(flowCnec2.getThresholds().iterator().next().max().isEmpty()); - assertEquals(-5000., flowCnec2.getLowerBound(Side.LEFT, Unit.AMPERE).get(), DOUBLE_TOLERANCE); + assertEquals(-5000., flowCnec2.getLowerBound(TwoSides.ONE, Unit.AMPERE).get(), DOUBLE_TOLERANCE); FlowCnec flowCnec3 = importedCrac.getFlowCnec("basecase_branch_3 - NNL1AA1 ->NNL2AA1 - preventive"); assertEquals(1, flowCnec3.getThresholds().size()); assertEquals(-0.2, flowCnec3.getThresholds().iterator().next().min().get(), DOUBLE_TOLERANCE); assertEquals(0.2, flowCnec3.getThresholds().iterator().next().max().get(), DOUBLE_TOLERANCE); - assertEquals(-0.2 * 5000., flowCnec3.getLowerBound(Side.LEFT, Unit.AMPERE).get(), DOUBLE_TOLERANCE); - assertEquals(0.2 * 5000., flowCnec3.getUpperBound(Side.LEFT, Unit.AMPERE).get(), DOUBLE_TOLERANCE); + assertEquals(-0.2 * 5000., flowCnec3.getLowerBound(TwoSides.ONE, Unit.AMPERE).get(), DOUBLE_TOLERANCE); + assertEquals(0.2 * 5000., flowCnec3.getUpperBound(TwoSides.ONE, Unit.AMPERE).get(), DOUBLE_TOLERANCE); } @Test void testPercentageThresholdsOnRightSide() { - parameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_RIGHT_SIDE); + parameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_SIDE_TWO); setUp("/cracs/cse_crac_pct_limit.xml"); FlowCnec flowCnec1 = importedCrac.getFlowCnec("basecase_branch_1 - NNL2AA1 ->NNL3AA1 - preventive"); assertEquals(1, flowCnec1.getThresholds().size()); assertEquals(0.7, flowCnec1.getThresholds().iterator().next().max().get(), DOUBLE_TOLERANCE); assertTrue(flowCnec1.getThresholds().iterator().next().min().isEmpty()); - assertEquals(0.7 * 5000., flowCnec1.getUpperBound(Side.RIGHT, Unit.AMPERE).get(), DOUBLE_TOLERANCE); + assertEquals(0.7 * 5000., flowCnec1.getUpperBound(TwoSides.TWO, Unit.AMPERE).get(), DOUBLE_TOLERANCE); FlowCnec flowCnec2 = importedCrac.getFlowCnec("basecase_branch_2 - NNL1AA1 ->NNL3AA1 - preventive"); assertEquals(1, flowCnec2.getThresholds().size()); assertEquals(-1., flowCnec2.getThresholds().iterator().next().min().get(), DOUBLE_TOLERANCE); assertTrue(flowCnec2.getThresholds().iterator().next().max().isEmpty()); - assertEquals(-5000., flowCnec2.getLowerBound(Side.RIGHT, Unit.AMPERE).get(), DOUBLE_TOLERANCE); + assertEquals(-5000., flowCnec2.getLowerBound(TwoSides.TWO, Unit.AMPERE).get(), DOUBLE_TOLERANCE); FlowCnec flowCnec3 = importedCrac.getFlowCnec("basecase_branch_3 - NNL1AA1 ->NNL2AA1 - preventive"); assertEquals(1, flowCnec3.getThresholds().size()); assertEquals(-0.2, flowCnec3.getThresholds().iterator().next().min().get(), DOUBLE_TOLERANCE); assertEquals(0.2, flowCnec3.getThresholds().iterator().next().max().get(), DOUBLE_TOLERANCE); - assertEquals(-0.2 * 5000., flowCnec3.getLowerBound(Side.RIGHT, Unit.AMPERE).get(), DOUBLE_TOLERANCE); - assertEquals(0.2 * 5000., flowCnec3.getUpperBound(Side.RIGHT, Unit.AMPERE).get(), DOUBLE_TOLERANCE); + assertEquals(-0.2 * 5000., flowCnec3.getLowerBound(TwoSides.TWO, Unit.AMPERE).get(), DOUBLE_TOLERANCE); + assertEquals(0.2 * 5000., flowCnec3.getUpperBound(TwoSides.TWO, Unit.AMPERE).get(), DOUBLE_TOLERANCE); } @Test @@ -417,20 +417,20 @@ void testPercentageThresholdsOnBothSides() { FlowCnec flowCnec1 = importedCrac.getFlowCnec("basecase_branch_1 - NNL2AA1 ->NNL3AA1 - preventive"); assertEquals(2, flowCnec1.getThresholds().size()); - assertEquals(0.7 * 5000., flowCnec1.getUpperBound(Side.LEFT, Unit.AMPERE).get(), DOUBLE_TOLERANCE); - assertEquals(0.7 * 5000., flowCnec1.getUpperBound(Side.RIGHT, Unit.AMPERE).get(), DOUBLE_TOLERANCE); + assertEquals(0.7 * 5000., flowCnec1.getUpperBound(TwoSides.ONE, Unit.AMPERE).get(), DOUBLE_TOLERANCE); + assertEquals(0.7 * 5000., flowCnec1.getUpperBound(TwoSides.TWO, Unit.AMPERE).get(), DOUBLE_TOLERANCE); FlowCnec flowCnec2 = importedCrac.getFlowCnec("basecase_branch_2 - NNL1AA1 ->NNL3AA1 - preventive"); assertEquals(2, flowCnec2.getThresholds().size()); - assertEquals(-5000., flowCnec2.getLowerBound(Side.LEFT, Unit.AMPERE).get(), DOUBLE_TOLERANCE); - assertEquals(-5000., flowCnec2.getLowerBound(Side.RIGHT, Unit.AMPERE).get(), DOUBLE_TOLERANCE); + assertEquals(-5000., flowCnec2.getLowerBound(TwoSides.ONE, Unit.AMPERE).get(), DOUBLE_TOLERANCE); + assertEquals(-5000., flowCnec2.getLowerBound(TwoSides.TWO, Unit.AMPERE).get(), DOUBLE_TOLERANCE); FlowCnec flowCnec3 = importedCrac.getFlowCnec("basecase_branch_3 - NNL1AA1 ->NNL2AA1 - preventive"); assertEquals(2, flowCnec3.getThresholds().size()); - assertEquals(-0.2 * 5000., flowCnec3.getLowerBound(Side.LEFT, Unit.AMPERE).get(), DOUBLE_TOLERANCE); - assertEquals(0.2 * 5000., flowCnec3.getUpperBound(Side.LEFT, Unit.AMPERE).get(), DOUBLE_TOLERANCE); - assertEquals(-0.2 * 5000., flowCnec3.getLowerBound(Side.RIGHT, Unit.AMPERE).get(), DOUBLE_TOLERANCE); - assertEquals(0.2 * 5000., flowCnec3.getUpperBound(Side.RIGHT, Unit.AMPERE).get(), DOUBLE_TOLERANCE); + assertEquals(-0.2 * 5000., flowCnec3.getLowerBound(TwoSides.ONE, Unit.AMPERE).get(), DOUBLE_TOLERANCE); + assertEquals(0.2 * 5000., flowCnec3.getUpperBound(TwoSides.ONE, Unit.AMPERE).get(), DOUBLE_TOLERANCE); + assertEquals(-0.2 * 5000., flowCnec3.getLowerBound(TwoSides.TWO, Unit.AMPERE).get(), DOUBLE_TOLERANCE); + assertEquals(0.2 * 5000., flowCnec3.getUpperBound(TwoSides.TWO, Unit.AMPERE).get(), DOUBLE_TOLERANCE); } @Test @@ -560,7 +560,7 @@ void testImportEmptyRa() { assertEquals(1, cracCreationContext.getRemedialActionCreationContexts().size()); } - private void assertHasOneThreshold(String cnecId, Side side) { + private void assertHasOneThreshold(String cnecId, TwoSides side) { FlowCnec cnec = importedCrac.getFlowCnec(cnecId); assertEquals(1, cnec.getThresholds().size()); assertEquals(side, cnec.getThresholds().iterator().next().getSide()); @@ -569,26 +569,26 @@ private void assertHasOneThreshold(String cnecId, Side side) { private void assertHasTwoThresholds(String cnecId) { FlowCnec cnec = importedCrac.getFlowCnec(cnecId); assertEquals(2, cnec.getThresholds().size()); - assertTrue(cnec.getThresholds().stream().anyMatch(branchThreshold -> branchThreshold.getSide().equals(Side.LEFT))); - assertTrue(cnec.getThresholds().stream().anyMatch(branchThreshold -> branchThreshold.getSide().equals(Side.RIGHT))); + assertTrue(cnec.getThresholds().stream().anyMatch(branchThreshold -> branchThreshold.getSide().equals(TwoSides.ONE))); + assertTrue(cnec.getThresholds().stream().anyMatch(branchThreshold -> branchThreshold.getSide().equals(TwoSides.TWO))); } @Test void testImportThresholdOnHalfLine() { parameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_BOTH_SIDES); setUp("/cracs/cse_crac_halflines.xml"); - assertHasOneThreshold("basecase_branch_1 - FFR2AA1 ->X_DEFR1 - preventive", Side.RIGHT); - assertHasOneThreshold("basecase_branch_2 - DDE2AA1 ->X_NLDE1 - preventive", Side.LEFT); + assertHasOneThreshold("basecase_branch_1 - FFR2AA1 ->X_DEFR1 - preventive", TwoSides.TWO); + assertHasOneThreshold("basecase_branch_2 - DDE2AA1 ->X_NLDE1 - preventive", TwoSides.ONE); - parameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_RIGHT_SIDE); + parameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_SIDE_TWO); setUp("/cracs/cse_crac_halflines.xml"); - assertHasOneThreshold("basecase_branch_1 - FFR2AA1 ->X_DEFR1 - preventive", Side.RIGHT); - assertHasOneThreshold("basecase_branch_2 - DDE2AA1 ->X_NLDE1 - preventive", Side.LEFT); + assertHasOneThreshold("basecase_branch_1 - FFR2AA1 ->X_DEFR1 - preventive", TwoSides.TWO); + assertHasOneThreshold("basecase_branch_2 - DDE2AA1 ->X_NLDE1 - preventive", TwoSides.ONE); - parameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_LEFT_SIDE); + parameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_SIDE_ONE); setUp("/cracs/cse_crac_halflines.xml"); - assertHasOneThreshold("basecase_branch_1 - FFR2AA1 ->X_DEFR1 - preventive", Side.RIGHT); - assertHasOneThreshold("basecase_branch_2 - DDE2AA1 ->X_NLDE1 - preventive", Side.LEFT); + assertHasOneThreshold("basecase_branch_1 - FFR2AA1 ->X_DEFR1 - preventive", TwoSides.TWO); + assertHasOneThreshold("basecase_branch_2 - DDE2AA1 ->X_NLDE1 - preventive", TwoSides.ONE); } @Test @@ -598,18 +598,18 @@ void testTransformerCnecThresholds() { parameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_BOTH_SIDES); setUpWithTransformer("/cracs/cse_crac_transformer_cnec.xml"); - assertHasOneThreshold("basecase_branch_1 - BBE2AA1 ->BBE3AA2 - preventive", Side.LEFT); + assertHasOneThreshold("basecase_branch_1 - BBE2AA1 ->BBE3AA2 - preventive", TwoSides.ONE); assertHasTwoThresholds("basecase_branch_2 - BBE2AA1 ->BBE3AA2 - preventive"); - parameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_RIGHT_SIDE); + parameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_SIDE_TWO); setUpWithTransformer("/cracs/cse_crac_transformer_cnec.xml"); - assertHasOneThreshold("basecase_branch_1 - BBE2AA1 ->BBE3AA2 - preventive", Side.LEFT); - assertHasOneThreshold("basecase_branch_2 - BBE2AA1 ->BBE3AA2 - preventive", Side.RIGHT); + assertHasOneThreshold("basecase_branch_1 - BBE2AA1 ->BBE3AA2 - preventive", TwoSides.ONE); + assertHasOneThreshold("basecase_branch_2 - BBE2AA1 ->BBE3AA2 - preventive", TwoSides.TWO); - parameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_LEFT_SIDE); + parameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_SIDE_ONE); setUpWithTransformer("/cracs/cse_crac_transformer_cnec.xml"); - assertHasOneThreshold("basecase_branch_1 - BBE2AA1 ->BBE3AA2 - preventive", Side.LEFT); - assertHasOneThreshold("basecase_branch_2 - BBE2AA1 ->BBE3AA2 - preventive", Side.LEFT); + assertHasOneThreshold("basecase_branch_1 - BBE2AA1 ->BBE3AA2 - preventive", TwoSides.ONE); + assertHasOneThreshold("basecase_branch_2 - BBE2AA1 ->BBE3AA2 - preventive", TwoSides.ONE); } @Test diff --git a/data/crac-creation/crac-creator-cse/src/test/java/com/powsybl/openrao/data/craccreation/creator/cse/CseCracCreatorWithMneTest.java b/data/crac-creation/crac-creator-cse/src/test/java/com/powsybl/openrao/data/craccreation/creator/cse/CseCracCreatorWithMneTest.java index 12e7fab8ac..e8ece3d9e1 100644 --- a/data/crac-creation/crac-creator-cse/src/test/java/com/powsybl/openrao/data/craccreation/creator/cse/CseCracCreatorWithMneTest.java +++ b/data/crac-creation/crac-creator-cse/src/test/java/com/powsybl/openrao/data/craccreation/creator/cse/CseCracCreatorWithMneTest.java @@ -10,7 +10,7 @@ import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.craccreation.creator.api.ImportStatus; import com.powsybl.openrao.data.craccreation.creator.api.parameters.CracCreationParameters; import com.powsybl.openrao.data.craccreation.creator.cse.criticalbranch.CseCriticalBranchCreationContext; @@ -116,10 +116,10 @@ public void assertMneWithContingencyInCrac(String name, String fromNode, String assertEquals(name, flowCnec.getName()); assertTrue(flowCnec.isMonitored()); assertFalse(flowCnec.isOptimized()); - assertEquals(expectedIMax, flowCnec.getIMax(Side.LEFT), 0.00001); - assertEquals(expectedIMax, flowCnec.getIMax(Side.RIGHT), 0.00001); - assertTrue(hasThreshold(nativeId, expectedThreshold, expectedThresholdUnit, flowCnec, direction, Side.LEFT)); - assertTrue(hasThreshold(nativeId, expectedThreshold, expectedThresholdUnit, flowCnec, direction, Side.RIGHT)); + assertEquals(expectedIMax, flowCnec.getIMax(TwoSides.ONE), 0.00001); + assertEquals(expectedIMax, flowCnec.getIMax(TwoSides.TWO), 0.00001); + assertTrue(hasThreshold(nativeId, expectedThreshold, expectedThresholdUnit, flowCnec, direction, TwoSides.ONE)); + assertTrue(hasThreshold(nativeId, expectedThreshold, expectedThresholdUnit, flowCnec, direction, TwoSides.TWO)); assertEquals(contingencyId, flowCnec.getState().getContingency().get().getId()); assertEquals(instant, flowCnec.getState().getInstant()); assertEquals(flowCnec.getNetworkElement().getId(), crac.getFlowCnec(createdCnecId).getNetworkElement().getName()); @@ -129,8 +129,8 @@ public void assertMneWithContingencyInCrac(String name, String fromNode, String } else { assertEquals(fromNode + " " + toNode + " " + suffix, flowCnec.getNetworkElement().getId()); } - assertEquals(expectedNV, flowCnec.getNominalVoltage(Side.RIGHT), 0.00001); - assertEquals(expectedNV, flowCnec.getNominalVoltage(Side.LEFT), 0.00001); + assertEquals(expectedNV, flowCnec.getNominalVoltage(TwoSides.TWO), 0.00001); + assertEquals(expectedNV, flowCnec.getNominalVoltage(TwoSides.ONE), 0.00001); } public void assertMneBaseCaseInCrac(String name, String fromNode, String toNode, String suffix, String direction, Instant instant, double expectedIMax, double expectedThreshold, Unit expectedThresholdUnit, double expectedNV) { @@ -142,11 +142,11 @@ public void assertMneBaseCaseInCrac(String name, String fromNode, String toNode, assertEquals(name, flowCnec.getName()); assertTrue(flowCnec.isMonitored()); assertFalse(flowCnec.isOptimized()); - assertEquals(expectedIMax, flowCnec.getIMax(Side.LEFT), 0.00001); - assertEquals(expectedIMax, flowCnec.getIMax(Side.RIGHT), 0.00001); + assertEquals(expectedIMax, flowCnec.getIMax(TwoSides.ONE), 0.00001); + assertEquals(expectedIMax, flowCnec.getIMax(TwoSides.TWO), 0.00001); - assertTrue(hasThreshold(nativeId, expectedThreshold, expectedThresholdUnit, flowCnec, direction, Side.LEFT)); - assertTrue(hasThreshold(nativeId, expectedThreshold, expectedThresholdUnit, flowCnec, direction, Side.RIGHT)); + assertTrue(hasThreshold(nativeId, expectedThreshold, expectedThresholdUnit, flowCnec, direction, TwoSides.ONE)); + assertTrue(hasThreshold(nativeId, expectedThreshold, expectedThresholdUnit, flowCnec, direction, TwoSides.TWO)); assertTrue(flowCnec.getState().isPreventive()); boolean directionInvertedInNetwork = cracCreationContext.getBranchCnecCreationContext(nativeId).isDirectionInvertedInNetwork(); if (directionInvertedInNetwork) { @@ -154,11 +154,11 @@ public void assertMneBaseCaseInCrac(String name, String fromNode, String toNode, } else { assertEquals(fromNode + " " + toNode + " " + suffix, flowCnec.getNetworkElement().getId()); } - assertEquals(expectedNV, flowCnec.getNominalVoltage(Side.RIGHT), 0.00001); - assertEquals(expectedNV, flowCnec.getNominalVoltage(Side.LEFT), 0.00001); + assertEquals(expectedNV, flowCnec.getNominalVoltage(TwoSides.TWO), 0.00001); + assertEquals(expectedNV, flowCnec.getNominalVoltage(TwoSides.ONE), 0.00001); } - private boolean hasThreshold(String nativeId, double expectedThreshold, Unit expectedThresholdUnit, FlowCnec flowCnec, String direction, Side side) { + private boolean hasThreshold(String nativeId, double expectedThreshold, Unit expectedThresholdUnit, FlowCnec flowCnec, String direction, TwoSides side) { boolean directionInvertedInNetwork = cracCreationContext.getBranchCnecCreationContext(nativeId).isDirectionInvertedInNetwork(); if (!directionInvertedInNetwork && direction.equals("DIRECT") || directionInvertedInNetwork && direction.equals("OPPOSITE")) { diff --git a/data/crac-creation/crac-creator-fb-constraint/src/main/java/com/powsybl/openrao/data/craccreation/creator/fbconstraint/craccreator/CriticalBranchReader.java b/data/crac-creation/crac-creator-fb-constraint/src/main/java/com/powsybl/openrao/data/craccreation/creator/fbconstraint/craccreator/CriticalBranchReader.java index d3c1227d39..bcf3071c21 100644 --- a/data/crac-creation/crac-creator-fb-constraint/src/main/java/com/powsybl/openrao/data/craccreation/creator/fbconstraint/craccreator/CriticalBranchReader.java +++ b/data/crac-creation/crac-creator-fb-constraint/src/main/java/com/powsybl/openrao/data/craccreation/creator/fbconstraint/craccreator/CriticalBranchReader.java @@ -11,7 +11,7 @@ import com.powsybl.openrao.data.cracapi.InstantKind; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnecAdder; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.threshold.BranchThresholdAdder; import com.powsybl.openrao.data.craccreation.creator.api.ImportStatus; import com.powsybl.openrao.data.craccreation.creator.api.stdcreationcontext.NativeBranch; @@ -20,7 +20,6 @@ import com.powsybl.openrao.data.craccreation.util.ucte.UcteNetworkAnalyzer; import com.powsybl.openrao.data.cracloopflowextension.LoopFlowThresholdAdder; import com.powsybl.iidm.network.Country; -import com.powsybl.iidm.network.TwoSides; import java.util.*; import java.util.regex.Pattern; @@ -38,12 +37,12 @@ class CriticalBranchReader { private ImportStatus importStatus; private final CriticalBranchType criticalBranch; - private Set monitoredSides; + private Set monitoredSides; private boolean isBaseCase; private boolean isInvertedInNetwork; private OutageReader outageReader; private UcteFlowElementHelper ucteFlowElementHelper; - private Side ampereThresholdSide = null; + private TwoSides ampereThresholdSide = null; boolean isCriticialBranchValid() { return importStatus.equals(ImportStatus.IMPORTED); @@ -98,7 +97,7 @@ boolean isInvertedInNetwork() { return isInvertedInNetwork; } - CriticalBranchReader(CriticalBranchType criticalBranch, UcteNetworkAnalyzer ucteNetworkAnalyzer, Set defaultMonitoredSides) { + CriticalBranchReader(CriticalBranchType criticalBranch, UcteNetworkAnalyzer ucteNetworkAnalyzer, Set defaultMonitoredSides) { this.criticalBranch = criticalBranch; this.monitoredSides = defaultMonitoredSides; interpretWithNetwork(ucteNetworkAnalyzer); @@ -124,7 +123,7 @@ private void interpretWithNetwork(UcteNetworkAnalyzer ucteNetworkAnalyzer) { if (ucteFlowElementHelper.isValid()) { this.isInvertedInNetwork = ucteFlowElementHelper.isInvertedInNetwork(); if (ucteFlowElementHelper.isHalfLine()) { - this.monitoredSides = Set.of(Side.fromIidmSide(ucteFlowElementHelper.getHalfLineSide())); + this.monitoredSides = Set.of(ucteFlowElementHelper.getHalfLineSide()); } } else { this.importStatus = ImportStatus.ELEMENT_NOT_FOUND_IN_NETWORK; @@ -165,7 +164,7 @@ private void initAmpereThresholdSide() { && Math.abs(ucteFlowElementHelper.getNominalVoltage(TwoSides.ONE) - ucteFlowElementHelper.getNominalVoltage(TwoSides.TWO)) > 1) { // For transformers, if unit is absolute amperes, monitor low voltage side ampereThresholdSide = ucteFlowElementHelper.getNominalVoltage(TwoSides.ONE) <= ucteFlowElementHelper.getNominalVoltage(TwoSides.TWO) ? - Side.LEFT : Side.RIGHT; + TwoSides.ONE : TwoSides.TWO; } } @@ -195,10 +194,10 @@ private FlowCnecAdder createCnecAdder(Crac crac, String instantId) { .withOperator(criticalBranch.getTsoOrigin()) .withMonitored(criticalBranch.isMNEC()) .withOptimized(criticalBranch.isCNEC()) - .withIMax(ucteFlowElementHelper.getCurrentLimit(TwoSides.ONE), Side.LEFT) - .withIMax(ucteFlowElementHelper.getCurrentLimit(TwoSides.TWO), Side.RIGHT) - .withNominalVoltage(ucteFlowElementHelper.getNominalVoltage(TwoSides.ONE), Side.LEFT) - .withNominalVoltage(ucteFlowElementHelper.getNominalVoltage(TwoSides.TWO), Side.RIGHT); + .withIMax(ucteFlowElementHelper.getCurrentLimit(TwoSides.ONE), TwoSides.ONE) + .withIMax(ucteFlowElementHelper.getCurrentLimit(TwoSides.TWO), TwoSides.TWO) + .withNominalVoltage(ucteFlowElementHelper.getNominalVoltage(TwoSides.ONE), TwoSides.ONE) + .withNominalVoltage(ucteFlowElementHelper.getNominalVoltage(TwoSides.TWO), TwoSides.TWO); if (!isBaseCase) { adder.withContingency(outageReader.getOutage().getId()); @@ -249,7 +248,7 @@ private void addThreshold(FlowCnecAdder cnecAdder, double threshold, Unit unit) //idea: create threshold in AMPERE instead of PERCENT_IMAX to avoid synchronisation afterwards // can be tricky for transformers - Set monitoredSidesForThreshold = (unit.equals(Unit.AMPERE) && ampereThresholdSide != null) ? + Set monitoredSidesForThreshold = (unit.equals(Unit.AMPERE) && ampereThresholdSide != null) ? Set.of(ampereThresholdSide) : monitoredSides; monitoredSidesForThreshold.forEach(side -> { BranchThresholdAdder branchThresholdAdder = cnecAdder.newThreshold() diff --git a/data/crac-creation/crac-creator-fb-constraint/src/main/java/com/powsybl/openrao/data/craccreation/creator/fbconstraint/craccreator/FbConstraintCracCreator.java b/data/crac-creation/crac-creator-fb-constraint/src/main/java/com/powsybl/openrao/data/craccreation/creator/fbconstraint/craccreator/FbConstraintCracCreator.java index 387ab160b1..92b675f56d 100644 --- a/data/crac-creation/crac-creator-fb-constraint/src/main/java/com/powsybl/openrao/data/craccreation/creator/fbconstraint/craccreator/FbConstraintCracCreator.java +++ b/data/crac-creation/crac-creator-fb-constraint/src/main/java/com/powsybl/openrao/data/craccreation/creator/fbconstraint/craccreator/FbConstraintCracCreator.java @@ -8,7 +8,7 @@ import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.InstantKind; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.craccreation.creator.api.CracCreator; import com.powsybl.openrao.data.craccreation.creator.api.ImportStatus; import com.powsybl.openrao.data.craccreation.creator.api.parameters.CracCreationParameters; @@ -85,7 +85,7 @@ private void createContingencies(Crac crac, List outageReaders) { outageReaders.forEach(or -> or.addContingency(crac)); } - private void readCriticalBranches(FbConstraint fbConstraintDocument, OffsetDateTime offsetDateTime, Crac crac, FbConstraintCreationContext creationContext, UcteNetworkAnalyzer ucteNetworkAnalyzer, List outageReaders, Set defaultMonitoredSides) { + private void readCriticalBranches(FbConstraint fbConstraintDocument, OffsetDateTime offsetDateTime, Crac crac, FbConstraintCreationContext creationContext, UcteNetworkAnalyzer ucteNetworkAnalyzer, List outageReaders, Set defaultMonitoredSides) { List criticalBranchForTimeStamp = selectCriticalBranchesForTimeStamp(fbConstraintDocument.getDocument(), offsetDateTime); if (!isEmpty(criticalBranchForTimeStamp)) { diff --git a/data/crac-creation/crac-creator-fb-constraint/src/test/java/com/powsybl/openrao/data/craccreation/creator/fbconstraint/craccreator/FbConstraintCracCreatorTest.java b/data/crac-creation/crac-creator-fb-constraint/src/test/java/com/powsybl/openrao/data/craccreation/creator/fbconstraint/craccreator/FbConstraintCracCreatorTest.java index 9c6310f151..0076f0d01e 100644 --- a/data/crac-creation/crac-creator-fb-constraint/src/test/java/com/powsybl/openrao/data/craccreation/creator/fbconstraint/craccreator/FbConstraintCracCreatorTest.java +++ b/data/crac-creation/crac-creator-fb-constraint/src/test/java/com/powsybl/openrao/data/craccreation/creator/fbconstraint/craccreator/FbConstraintCracCreatorTest.java @@ -12,7 +12,7 @@ import com.powsybl.openrao.data.cracapi.CracFactory; import com.powsybl.openrao.data.cracapi.RaUsageLimits; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.range.RangeType; import com.powsybl.openrao.data.cracapi.range.TapRange; @@ -257,7 +257,7 @@ void importMnecs() { assertCriticalBranchNotImported("BE_CBCO_000004", NOT_FOR_RAO); } - private void assertHasThresholds(FlowCnec cnec, Set monitoredSides, Unit unit, Double min, Double max) { + private void assertHasThresholds(FlowCnec cnec, Set monitoredSides, Unit unit, Double min, Double max) { assertEquals(monitoredSides.size(), cnec.getThresholds().size()); monitoredSides.forEach(side -> assertTrue(cnec.getThresholds().stream().anyMatch(branchThreshold -> branchThreshold.getSide().equals(side)))); cnec.getThresholds().forEach(branchThreshold -> { @@ -269,7 +269,7 @@ private void assertHasThresholds(FlowCnec cnec, Set monitoredSides, Unit u @Test void importThresholdsOnLeftSide() { - parameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_LEFT_SIDE); + parameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_SIDE_ONE); Network network = Network.read("TestCase12Nodes_for_thresholds_test.uct", getClass().getResourceAsStream("/network/TestCase12Nodes_for_thresholds_test.uct")); FbConstraint fbConstraint = new FbConstraintImporter().importNativeCrac(getClass().getResourceAsStream("/merged_cb/thresholds_test.xml")); OffsetDateTime timestamp = OffsetDateTime.parse("2019-01-08T00:30Z"); @@ -279,63 +279,63 @@ void importThresholdsOnLeftSide() { assertEquals(9, crac.getFlowCnecs().size()); // No threshold specification will be set to default relative-100 - assertHasThresholds(crac.getFlowCnec("CBCO_000001 - preventive"), Set.of(Side.LEFT), Unit.PERCENT_IMAX, null, 1.); + assertHasThresholds(crac.getFlowCnec("CBCO_000001 - preventive"), Set.of(TwoSides.ONE), Unit.PERCENT_IMAX, null, 1.); // ImaxA set to 200 - assertHasThresholds(crac.getFlowCnec("CBCO_000002 - preventive"), Set.of(Side.LEFT), Unit.AMPERE, null, 200.); + assertHasThresholds(crac.getFlowCnec("CBCO_000002 - preventive"), Set.of(TwoSides.ONE), Unit.AMPERE, null, 200.); // ImaxFactor set to 0.8 - assertHasThresholds(crac.getFlowCnec("CBCO_000003 - preventive"), Set.of(Side.LEFT), Unit.PERCENT_IMAX, null, 0.8); + assertHasThresholds(crac.getFlowCnec("CBCO_000003 - preventive"), Set.of(TwoSides.ONE), Unit.PERCENT_IMAX, null, 0.8); // PermanentImaxA set to 300 - assertHasThresholds(crac.getFlowCnec("CBCO_000004 - preventive"), Set.of(Side.LEFT), Unit.AMPERE, null, 300.); + assertHasThresholds(crac.getFlowCnec("CBCO_000004 - preventive"), Set.of(TwoSides.ONE), Unit.AMPERE, null, 300.); // PermanentImaxFactor set to 1.2 - assertHasThresholds(crac.getFlowCnec("CBCO_000005 - preventive"), Set.of(Side.LEFT), Unit.PERCENT_IMAX, null, 1.2); + assertHasThresholds(crac.getFlowCnec("CBCO_000005 - preventive"), Set.of(TwoSides.ONE), Unit.PERCENT_IMAX, null, 1.2); // TemporaryImaxA set to 200 will be set to default relative-100 - assertHasThresholds(crac.getFlowCnec("CBCO_000006 - preventive"), Set.of(Side.LEFT), Unit.PERCENT_IMAX, null, 1.); + assertHasThresholds(crac.getFlowCnec("CBCO_000006 - preventive"), Set.of(TwoSides.ONE), Unit.PERCENT_IMAX, null, 1.); // TemporaryImaxFactor set to 0.8 will be set to default relative-100 - assertHasThresholds(crac.getFlowCnec("CBCO_000006 - preventive"), Set.of(Side.LEFT), Unit.PERCENT_IMAX, null, 1.); + assertHasThresholds(crac.getFlowCnec("CBCO_000006 - preventive"), Set.of(TwoSides.ONE), Unit.PERCENT_IMAX, null, 1.); // ImaxA, PermanentImaxA and TemporaryImaxA set to 300, 200 and 100 assertEquals(1, crac.getFlowCnec("CBCO_000008 - preventive").getThresholds().size()); - assertEquals(300., crac.getFlowCnec("CBCO_000008 - preventive").getUpperBound(Side.LEFT, Unit.AMPERE).orElseThrow(), 0.1); + assertEquals(300., crac.getFlowCnec("CBCO_000008 - preventive").getUpperBound(TwoSides.ONE, Unit.AMPERE).orElseThrow(), 0.1); } @Test void importThresholdsOnRightSide() { - parameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_RIGHT_SIDE); + parameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_SIDE_TWO); Network network = Network.read("TestCase12Nodes_for_thresholds_test.uct", getClass().getResourceAsStream("/network/TestCase12Nodes_for_thresholds_test.uct")); FbConstraint fbConstraint = new FbConstraintImporter().importNativeCrac(getClass().getResourceAsStream("/merged_cb/thresholds_test.xml")); OffsetDateTime timestamp = OffsetDateTime.parse("2019-01-08T00:30Z"); Crac crac = new FbConstraintCracCreator().createCrac(fbConstraint, network, timestamp, parameters).getCrac(); // No threshold specification will be set to default relative-100 - assertHasThresholds(crac.getFlowCnec("CBCO_000001 - preventive"), Set.of(Side.RIGHT), Unit.PERCENT_IMAX, null, 1.); + assertHasThresholds(crac.getFlowCnec("CBCO_000001 - preventive"), Set.of(TwoSides.TWO), Unit.PERCENT_IMAX, null, 1.); // ImaxA set to 200 - assertHasThresholds(crac.getFlowCnec("CBCO_000002 - preventive"), Set.of(Side.RIGHT), Unit.AMPERE, null, 200.); + assertHasThresholds(crac.getFlowCnec("CBCO_000002 - preventive"), Set.of(TwoSides.TWO), Unit.AMPERE, null, 200.); // ImaxFactor set to 0.8 - assertHasThresholds(crac.getFlowCnec("CBCO_000003 - preventive"), Set.of(Side.RIGHT), Unit.PERCENT_IMAX, null, 0.8); + assertHasThresholds(crac.getFlowCnec("CBCO_000003 - preventive"), Set.of(TwoSides.TWO), Unit.PERCENT_IMAX, null, 0.8); // PermanentImaxA set to 300 - assertHasThresholds(crac.getFlowCnec("CBCO_000004 - preventive"), Set.of(Side.RIGHT), Unit.AMPERE, null, 300.); + assertHasThresholds(crac.getFlowCnec("CBCO_000004 - preventive"), Set.of(TwoSides.TWO), Unit.AMPERE, null, 300.); // PermanentImaxFactor set to 1.2 - assertHasThresholds(crac.getFlowCnec("CBCO_000005 - preventive"), Set.of(Side.RIGHT), Unit.PERCENT_IMAX, null, 1.2); + assertHasThresholds(crac.getFlowCnec("CBCO_000005 - preventive"), Set.of(TwoSides.TWO), Unit.PERCENT_IMAX, null, 1.2); // TemporaryImaxA set to 200 will be set to default relative-100 - assertHasThresholds(crac.getFlowCnec("CBCO_000006 - preventive"), Set.of(Side.RIGHT), Unit.PERCENT_IMAX, null, 1.); + assertHasThresholds(crac.getFlowCnec("CBCO_000006 - preventive"), Set.of(TwoSides.TWO), Unit.PERCENT_IMAX, null, 1.); // TemporaryImaxFactor set to 0.8 will be set to default relative-100 - assertHasThresholds(crac.getFlowCnec("CBCO_000006 - preventive"), Set.of(Side.RIGHT), Unit.PERCENT_IMAX, null, 1.); + assertHasThresholds(crac.getFlowCnec("CBCO_000006 - preventive"), Set.of(TwoSides.TWO), Unit.PERCENT_IMAX, null, 1.); // ImaxA, PermanentImaxA and TemporaryImaxA set to 300, 200 and 100 assertEquals(1, crac.getFlowCnec("CBCO_000008 - preventive").getThresholds().size()); - assertEquals(300., crac.getFlowCnec("CBCO_000008 - preventive").getUpperBound(Side.RIGHT, Unit.AMPERE).orElseThrow(), 0.1); + assertEquals(300., crac.getFlowCnec("CBCO_000008 - preventive").getUpperBound(TwoSides.TWO, Unit.AMPERE).orElseThrow(), 0.1); } @Test @@ -347,30 +347,30 @@ void importThresholdsOnBothSides() { Crac crac = new FbConstraintCracCreator().createCrac(fbConstraint, network, timestamp, parameters).getCrac(); // No threshold specification will be set to default relative-100 - assertHasThresholds(crac.getFlowCnec("CBCO_000001 - preventive"), Set.of(Side.LEFT, Side.RIGHT), Unit.PERCENT_IMAX, null, 1.); + assertHasThresholds(crac.getFlowCnec("CBCO_000001 - preventive"), Set.of(TwoSides.ONE, TwoSides.TWO), Unit.PERCENT_IMAX, null, 1.); // ImaxA set to 200 - assertHasThresholds(crac.getFlowCnec("CBCO_000002 - preventive"), Set.of(Side.LEFT, Side.RIGHT), Unit.AMPERE, null, 200.); + assertHasThresholds(crac.getFlowCnec("CBCO_000002 - preventive"), Set.of(TwoSides.ONE, TwoSides.TWO), Unit.AMPERE, null, 200.); // ImaxFactor set to 0.8 - assertHasThresholds(crac.getFlowCnec("CBCO_000003 - preventive"), Set.of(Side.LEFT, Side.RIGHT), Unit.PERCENT_IMAX, null, 0.8); + assertHasThresholds(crac.getFlowCnec("CBCO_000003 - preventive"), Set.of(TwoSides.ONE, TwoSides.TWO), Unit.PERCENT_IMAX, null, 0.8); // PermanentImaxA set to 300 - assertHasThresholds(crac.getFlowCnec("CBCO_000004 - preventive"), Set.of(Side.LEFT, Side.RIGHT), Unit.AMPERE, null, 300.); + assertHasThresholds(crac.getFlowCnec("CBCO_000004 - preventive"), Set.of(TwoSides.ONE, TwoSides.TWO), Unit.AMPERE, null, 300.); // PermanentImaxFactor set to 1.2 - assertHasThresholds(crac.getFlowCnec("CBCO_000005 - preventive"), Set.of(Side.LEFT, Side.RIGHT), Unit.PERCENT_IMAX, null, 1.2); + assertHasThresholds(crac.getFlowCnec("CBCO_000005 - preventive"), Set.of(TwoSides.ONE, TwoSides.TWO), Unit.PERCENT_IMAX, null, 1.2); // TemporaryImaxA set to 200 will be set to default relative-100 - assertHasThresholds(crac.getFlowCnec("CBCO_000006 - preventive"), Set.of(Side.LEFT, Side.RIGHT), Unit.PERCENT_IMAX, null, 1.); + assertHasThresholds(crac.getFlowCnec("CBCO_000006 - preventive"), Set.of(TwoSides.ONE, TwoSides.TWO), Unit.PERCENT_IMAX, null, 1.); // TemporaryImaxFactor set to 0.8 will be set to default relative-100 - assertHasThresholds(crac.getFlowCnec("CBCO_000006 - preventive"), Set.of(Side.LEFT, Side.RIGHT), Unit.PERCENT_IMAX, null, 1.); + assertHasThresholds(crac.getFlowCnec("CBCO_000006 - preventive"), Set.of(TwoSides.ONE, TwoSides.TWO), Unit.PERCENT_IMAX, null, 1.); // ImaxA, PermanentImaxA and TemporaryImaxA set to 300, 200 and 100 assertEquals(2, crac.getFlowCnec("CBCO_000008 - preventive").getThresholds().size()); - assertEquals(300., crac.getFlowCnec("CBCO_000008 - preventive").getUpperBound(Side.LEFT, Unit.AMPERE).orElseThrow(), 0.1); - assertEquals(300., crac.getFlowCnec("CBCO_000008 - preventive").getUpperBound(Side.RIGHT, Unit.AMPERE).orElseThrow(), 0.1); + assertEquals(300., crac.getFlowCnec("CBCO_000008 - preventive").getUpperBound(TwoSides.ONE, Unit.AMPERE).orElseThrow(), 0.1); + assertEquals(300., crac.getFlowCnec("CBCO_000008 - preventive").getUpperBound(TwoSides.TWO, Unit.AMPERE).orElseThrow(), 0.1); } @Test @@ -573,18 +573,18 @@ void importHalflineThresholds() { parameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_BOTH_SIDES); crac = new FbConstraintCracCreator().createCrac(fbConstraint, network, timestamp, parameters).getCrac(); - assertHasThresholds(crac.getFlowCnec("FR_CBCO_000001 - preventive"), Set.of(Side.RIGHT), Unit.PERCENT_IMAX, -1., null); - assertHasThresholds(crac.getFlowCnec("FR_CBCO_000002 - preventive"), Set.of(Side.LEFT), Unit.PERCENT_IMAX, null, 1.); + assertHasThresholds(crac.getFlowCnec("FR_CBCO_000001 - preventive"), Set.of(TwoSides.TWO), Unit.PERCENT_IMAX, -1., null); + assertHasThresholds(crac.getFlowCnec("FR_CBCO_000002 - preventive"), Set.of(TwoSides.ONE), Unit.PERCENT_IMAX, null, 1.); - parameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_LEFT_SIDE); + parameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_SIDE_ONE); crac = new FbConstraintCracCreator().createCrac(fbConstraint, network, timestamp, parameters).getCrac(); - assertHasThresholds(crac.getFlowCnec("FR_CBCO_000001 - preventive"), Set.of(Side.RIGHT), Unit.PERCENT_IMAX, -1., null); - assertHasThresholds(crac.getFlowCnec("FR_CBCO_000002 - preventive"), Set.of(Side.LEFT), Unit.PERCENT_IMAX, null, 1.); + assertHasThresholds(crac.getFlowCnec("FR_CBCO_000001 - preventive"), Set.of(TwoSides.TWO), Unit.PERCENT_IMAX, -1., null); + assertHasThresholds(crac.getFlowCnec("FR_CBCO_000002 - preventive"), Set.of(TwoSides.ONE), Unit.PERCENT_IMAX, null, 1.); - parameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_RIGHT_SIDE); + parameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_SIDE_TWO); crac = new FbConstraintCracCreator().createCrac(fbConstraint, network, timestamp, parameters).getCrac(); - assertHasThresholds(crac.getFlowCnec("FR_CBCO_000001 - preventive"), Set.of(Side.RIGHT), Unit.PERCENT_IMAX, -1., null); - assertHasThresholds(crac.getFlowCnec("FR_CBCO_000002 - preventive"), Set.of(Side.LEFT), Unit.PERCENT_IMAX, null, 1.); + assertHasThresholds(crac.getFlowCnec("FR_CBCO_000001 - preventive"), Set.of(TwoSides.TWO), Unit.PERCENT_IMAX, -1., null); + assertHasThresholds(crac.getFlowCnec("FR_CBCO_000002 - preventive"), Set.of(TwoSides.ONE), Unit.PERCENT_IMAX, null, 1.); } @Test @@ -598,18 +598,18 @@ void testTransformerCnecThresholds() { parameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_BOTH_SIDES); Crac crac = new FbConstraintCracCreator().createCrac(fbConstraint, network, timestamp, parameters).getCrac(); - assertHasThresholds(crac.getFlowCnec("CBCO_1 - preventive"), Set.of(Side.LEFT, Side.RIGHT), Unit.PERCENT_IMAX, -1.0, null); - assertHasThresholds(crac.getFlowCnec("CBCO_2 - preventive"), Set.of(Side.LEFT), Unit.AMPERE, -100., null); + assertHasThresholds(crac.getFlowCnec("CBCO_1 - preventive"), Set.of(TwoSides.ONE, TwoSides.TWO), Unit.PERCENT_IMAX, -1.0, null); + assertHasThresholds(crac.getFlowCnec("CBCO_2 - preventive"), Set.of(TwoSides.ONE), Unit.AMPERE, -100., null); - parameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_LEFT_SIDE); + parameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_SIDE_ONE); crac = new FbConstraintCracCreator().createCrac(fbConstraint, network, timestamp, parameters).getCrac(); - assertHasThresholds(crac.getFlowCnec("CBCO_1 - preventive"), Set.of(Side.LEFT), Unit.PERCENT_IMAX, -1.0, null); - assertHasThresholds(crac.getFlowCnec("CBCO_2 - preventive"), Set.of(Side.LEFT), Unit.AMPERE, -100., null); + assertHasThresholds(crac.getFlowCnec("CBCO_1 - preventive"), Set.of(TwoSides.ONE), Unit.PERCENT_IMAX, -1.0, null); + assertHasThresholds(crac.getFlowCnec("CBCO_2 - preventive"), Set.of(TwoSides.ONE), Unit.AMPERE, -100., null); - parameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_RIGHT_SIDE); + parameters.setDefaultMonitoredLineSide(CracCreationParameters.MonitoredLineSide.MONITOR_LINES_ON_SIDE_TWO); crac = new FbConstraintCracCreator().createCrac(fbConstraint, network, timestamp, parameters).getCrac(); - assertHasThresholds(crac.getFlowCnec("CBCO_1 - preventive"), Set.of(Side.RIGHT), Unit.PERCENT_IMAX, -1.0, null); - assertHasThresholds(crac.getFlowCnec("CBCO_2 - preventive"), Set.of(Side.LEFT), Unit.AMPERE, -100., null); + assertHasThresholds(crac.getFlowCnec("CBCO_1 - preventive"), Set.of(TwoSides.TWO), Unit.PERCENT_IMAX, -1.0, null); + assertHasThresholds(crac.getFlowCnec("CBCO_2 - preventive"), Set.of(TwoSides.ONE), Unit.AMPERE, -100., null); } } diff --git a/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/JsonSerializationConstants.java b/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/JsonSerializationConstants.java index 98066f2b5f..7fa727a008 100644 --- a/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/JsonSerializationConstants.java +++ b/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/JsonSerializationConstants.java @@ -10,7 +10,7 @@ import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.InstantKind; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.ActionType; import com.powsybl.openrao.data.cracapi.range.RangeType; import com.powsybl.openrao.data.cracapi.threshold.BranchThreshold; @@ -45,6 +45,7 @@ private JsonSerializationConstants() { v2.1: addition of ra-usage-limits v2.2: addition of contingency id in on-flow-constraint-in-country v2.3: addition of RELATIVE_TO_PREVIOUS_TIME_STEP RangeType, and border attribute for cnecs + v2.4: new names for onConstraint and cnecId + side left/right -> one/two */ // headers @@ -172,7 +173,8 @@ private JsonSerializationConstants() { // threshold side public static final String LEFT_SIDE = "left"; public static final String RIGHT_SIDE = "right"; - + public static final int SIDE_ONE = 1; + public static final int SIDE_TWO = 2; // usage methods public static final String UNAVAILABLE_USAGE_METHOD = "unavailable"; public static final String FORCED_USAGE_METHOD = "forced"; @@ -280,55 +282,56 @@ public static Unit deserializeUnit(String stringValue) { } } - public static String serializeSide(Side side) { - switch (side) { - case LEFT: - return LEFT_SIDE; - case RIGHT: - return RIGHT_SIDE; - default: - throw new OpenRaoException(String.format("Unsupported side %s", side)); - } + public static int serializeSide(TwoSides side) { + return switch (side) { + case ONE -> SIDE_ONE; + case TWO -> SIDE_TWO; + }; } - public static Side deserializeSide(String stringValue) { - switch (stringValue) { - case LEFT_SIDE: - return Side.LEFT; - case RIGHT_SIDE: - return Side.RIGHT; - default: - throw new OpenRaoException(String.format("Unrecognized side %s", stringValue)); - } + public static TwoSides deserializeSide(int value) { + return switch (value) { + case SIDE_ONE -> TwoSides.ONE; + case SIDE_TWO -> TwoSides.TWO; + default -> throw new OpenRaoException(String.format("Unrecognized side %d", value)); + }; + } + + public static TwoSides deserializeSide(String stringValue) { + return switch (stringValue) { + case LEFT_SIDE -> TwoSides.ONE; + case RIGHT_SIDE -> TwoSides.TWO; + default -> throw new OpenRaoException(String.format("Unrecognized side %s", stringValue)); + }; } /** - * Converts old BranchThresholdRule to Side + * Converts old BranchThresholdRule to TwoSides * For retro-compatibility purposes only */ - public static Side convertBranchThresholdRuleToSide(String branchThresholdRule, Pair nominalV) { + public static TwoSides convertBranchThresholdRuleToSide(String branchThresholdRule, Pair nominalV) { switch (branchThresholdRule) { case ON_LEFT_SIDE_RULE, ON_REGULATED_SIDE_RULE: // This is true only when the network is in UCTE format - return Side.LEFT; + return TwoSides.ONE; case ON_RIGHT_SIDE_RULE, ON_NON_REGULATED_SIDE_RULE: // This is true only when the network is in UCTE format. - return Side.RIGHT; + return TwoSides.TWO; case ON_LOW_VOLTAGE_LEVEL_RULE: if (Objects.isNull(nominalV) || Objects.isNull(nominalV.getLeft()) || Objects.isNull(nominalV.getRight()) || Double.isNaN(nominalV.getLeft()) || Double.isNaN(nominalV.getRight())) { throw new OpenRaoException("ON_LOW_VOLTAGE_LEVEL thresholds can only be defined on FlowCnec whose nominalVoltages have been set on both sides"); } if (nominalV.getLeft() <= nominalV.getRight()) { - return Side.LEFT; + return TwoSides.ONE; } else { - return Side.RIGHT; + return TwoSides.TWO; } case ON_HIGH_VOLTAGE_LEVEL_RULE: if (Objects.isNull(nominalV) || Objects.isNull(nominalV.getLeft()) || Objects.isNull(nominalV.getRight()) || Double.isNaN(nominalV.getLeft()) || Double.isNaN(nominalV.getRight())) { throw new OpenRaoException("ON_HIGH_VOLTAGE_LEVEL thresholds can only be defined on FlowCnec whose nominalVoltages have been set on both sides"); } if (nominalV.getLeft() < nominalV.getRight()) { - return Side.RIGHT; + return TwoSides.TWO; } else { - return Side.LEFT; + return TwoSides.ONE; } default: throw new OpenRaoException(String.format("Rule %s is not yet handled for thresholds on FlowCnec", branchThresholdRule)); @@ -425,7 +428,7 @@ public int compare(Threshold o1, Threshold o2) { if (unit1.equals(unit2)) { if (o1 instanceof BranchThreshold bt1 && o2 instanceof BranchThreshold bt2 && !bt1.getSide().equals(bt2.getSide())) { - return serializeSide(bt1.getSide()).compareTo(serializeSide(bt2.getSide())); + return Integer.compare(serializeSide(bt1.getSide()), serializeSide(bt2.getSide())); } if (o1.min().isPresent()) { return -1; diff --git a/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/deserializers/BranchThresholdArrayDeserializer.java b/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/deserializers/BranchThresholdArrayDeserializer.java index 87791bc7f5..4a69efae20 100644 --- a/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/deserializers/BranchThresholdArrayDeserializer.java +++ b/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/deserializers/BranchThresholdArrayDeserializer.java @@ -15,6 +15,7 @@ import org.apache.commons.lang3.tuple.Pair; import java.io.IOException; +import java.util.Objects; import static com.powsybl.openrao.data.craciojson.JsonSerializationConstants.*; @@ -50,7 +51,18 @@ public static void deserialize(JsonParser jsonParser, FlowCnecAdder ownerAdder, } break; case SIDE: - branchThresholdAdder.withSide(deserializeSide(jsonParser.nextTextValue())); + JsonToken side = jsonParser.nextToken(); + if (getPrimaryVersionNumber(version) > 2 || getPrimaryVersionNumber(version) == 2 && getSubVersionNumber(version) > 3) { + if (side == JsonToken.VALUE_NUMBER_INT) { + branchThresholdAdder.withSide(deserializeSide(jsonParser.getIntValue())); + } else if (Objects.equals(jsonParser.getValueAsString(), LEFT_SIDE) || Objects.equals(jsonParser.getValueAsString(), RIGHT_SIDE)) { + throw new OpenRaoException(String.format("Side should be %d/%d and not %s/%s since CRAC version 2.4", SIDE_ONE, SIDE_TWO, LEFT_SIDE, RIGHT_SIDE)); + } else { + throw new OpenRaoException(String.format("Unrecognized side %s", jsonParser.getValueAsString())); + } + } else { + branchThresholdAdder.withSide(deserializeSide(jsonParser.getValueAsString())); + } break; default: throw new OpenRaoException("Unexpected field in BranchThreshold: " + jsonParser.getCurrentName()); diff --git a/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/deserializers/FlowCnecArrayDeserializer.java b/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/deserializers/FlowCnecArrayDeserializer.java index 9e0be53385..93ef8d632a 100644 --- a/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/deserializers/FlowCnecArrayDeserializer.java +++ b/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/deserializers/FlowCnecArrayDeserializer.java @@ -9,10 +9,10 @@ import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.data.cracapi.Crac; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.craciojson.ExtensionsHandler; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnecAdder; -import com.powsybl.openrao.data.cracapi.cnec.Side; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.DeserializationContext; @@ -108,8 +108,8 @@ private static Pair readNominalVoltage(JsonParser jsonParser, Fl flowCnecAdder.withNominalVoltage(nominalV[0]); return Pair.of(nominalV[0], nominalV[0]); } else if (nominalV.length == 2) { - flowCnecAdder.withNominalVoltage(nominalV[0], Side.LEFT); - flowCnecAdder.withNominalVoltage(nominalV[1], Side.RIGHT); + flowCnecAdder.withNominalVoltage(nominalV[0], TwoSides.ONE); + flowCnecAdder.withNominalVoltage(nominalV[1], TwoSides.TWO); return Pair.of(nominalV[0], nominalV[1]); } else if (nominalV.length > 2) { throw new OpenRaoException("nominalVoltage array of a flowCnec cannot contain more than 2 values"); @@ -123,8 +123,8 @@ private static void readImax(JsonParser jsonParser, FlowCnecAdder flowCnecAdder) if (iMax.length == 1) { flowCnecAdder.withIMax(iMax[0]); } else if (iMax.length == 2) { - flowCnecAdder.withIMax(iMax[0], Side.LEFT); - flowCnecAdder.withIMax(iMax[1], Side.RIGHT); + flowCnecAdder.withIMax(iMax[0], TwoSides.ONE); + flowCnecAdder.withIMax(iMax[1], TwoSides.TWO); } else if (iMax.length > 2) { throw new OpenRaoException("iMax array of a flowCnec cannot contain more than 2 values"); } diff --git a/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/serializers/BranchThresholdSerializer.java b/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/serializers/BranchThresholdSerializer.java index 9f5b0ab493..ae755978ef 100644 --- a/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/serializers/BranchThresholdSerializer.java +++ b/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/serializers/BranchThresholdSerializer.java @@ -32,7 +32,7 @@ public void serialize(BranchThreshold value, JsonGenerator gen, SerializerProvid if (max.isPresent()) { gen.writeNumberField(MAX, max.get()); } - gen.writeStringField(SIDE, serializeSide(value.getSide())); + gen.writeNumberField(SIDE, serializeSide(value.getSide())); gen.writeEndObject(); } diff --git a/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/serializers/FlowCnecSerializer.java b/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/serializers/FlowCnecSerializer.java index 00160f2f4b..0fd64fbdaf 100644 --- a/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/serializers/FlowCnecSerializer.java +++ b/data/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/craciojson/serializers/FlowCnecSerializer.java @@ -9,7 +9,7 @@ import com.powsybl.contingency.Contingency; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.threshold.BranchThreshold; import com.powsybl.openrao.data.craciojson.ExtensionsHandler; import com.fasterxml.jackson.core.JsonGenerator; @@ -54,11 +54,11 @@ public void serialize(I flowCnec, JsonGenerator gen, SerializerProvider serializ } private void serializeIMax(FlowCnec flowCnec, JsonGenerator gen) throws IOException { - serializeDoubleValuesOnBothSide(gen, flowCnec.getIMax(Side.LEFT), flowCnec.getIMax(Side.RIGHT), I_MAX); + serializeDoubleValuesOnBothSide(gen, flowCnec.getIMax(TwoSides.ONE), flowCnec.getIMax(TwoSides.TWO), I_MAX); } private void serializeNominalVoltage(FlowCnec flowCnec, JsonGenerator gen) throws IOException { - serializeDoubleValuesOnBothSide(gen, flowCnec.getNominalVoltage(Side.LEFT), flowCnec.getNominalVoltage(Side.RIGHT), NOMINAL_VOLTAGE); + serializeDoubleValuesOnBothSide(gen, flowCnec.getNominalVoltage(TwoSides.ONE), flowCnec.getNominalVoltage(TwoSides.TWO), NOMINAL_VOLTAGE); } private void serializeDoubleValuesOnBothSide(JsonGenerator gen, Double valueSideLeft, Double valueSideRight, String fieldName) throws IOException { diff --git a/data/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/craciojson/CracImportExportTest.java b/data/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/craciojson/CracImportExportTest.java index 6294465f46..b35343dad8 100644 --- a/data/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/craciojson/CracImportExportTest.java +++ b/data/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/craciojson/CracImportExportTest.java @@ -6,6 +6,7 @@ */ package com.powsybl.openrao.data.craciojson; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.Instant; @@ -13,7 +14,6 @@ import com.powsybl.openrao.data.cracapi.RaUsageLimits; import com.powsybl.openrao.data.cracapi.cnec.AngleCnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; import com.powsybl.openrao.data.cracapi.cnec.VoltageCnec; import com.powsybl.openrao.data.cracapi.networkaction.InjectionSetpoint; import com.powsybl.openrao.data.cracapi.networkaction.PstSetpoint; @@ -146,20 +146,20 @@ private void checkContent(Crac crac) { assertEquals("operator4", crac.getFlowCnec("cnec4prevId").getOperator()); // check iMax and nominal voltage - assertEquals(2000., crac.getFlowCnec("cnec2prevId").getIMax(Side.LEFT), 1e-3); - assertEquals(2000., crac.getFlowCnec("cnec2prevId").getIMax(Side.RIGHT), 1e-3); - assertEquals(380., crac.getFlowCnec("cnec2prevId").getNominalVoltage(Side.LEFT), 1e-3); - assertEquals(220., crac.getFlowCnec("cnec2prevId").getNominalVoltage(Side.RIGHT), 1e-3); - assertEquals(Double.NaN, crac.getFlowCnec("cnec1prevId").getIMax(Side.LEFT), 1e-3); - assertEquals(1000., crac.getFlowCnec("cnec1prevId").getIMax(Side.RIGHT), 1e-3); - assertEquals(220., crac.getFlowCnec("cnec1prevId").getNominalVoltage(Side.LEFT), 1e-3); - assertEquals(220., crac.getFlowCnec("cnec1prevId").getNominalVoltage(Side.RIGHT), 1e-3); + assertEquals(2000., crac.getFlowCnec("cnec2prevId").getIMax(TwoSides.ONE), 1e-3); + assertEquals(2000., crac.getFlowCnec("cnec2prevId").getIMax(TwoSides.TWO), 1e-3); + assertEquals(380., crac.getFlowCnec("cnec2prevId").getNominalVoltage(TwoSides.ONE), 1e-3); + assertEquals(220., crac.getFlowCnec("cnec2prevId").getNominalVoltage(TwoSides.TWO), 1e-3); + assertEquals(Double.NaN, crac.getFlowCnec("cnec1prevId").getIMax(TwoSides.ONE), 1e-3); + assertEquals(1000., crac.getFlowCnec("cnec1prevId").getIMax(TwoSides.TWO), 1e-3); + assertEquals(220., crac.getFlowCnec("cnec1prevId").getNominalVoltage(TwoSides.ONE), 1e-3); + assertEquals(220., crac.getFlowCnec("cnec1prevId").getNominalVoltage(TwoSides.TWO), 1e-3); // check threshold assertEquals(1, crac.getFlowCnec("cnec4prevId").getThresholds().size()); BranchThreshold threshold = crac.getFlowCnec("cnec4prevId").getThresholds().iterator().next(); assertEquals(Unit.MEGAWATT, threshold.getUnit()); - assertEquals(Side.LEFT, threshold.getSide()); + assertEquals(TwoSides.ONE, threshold.getSide()); assertTrue(threshold.min().isEmpty()); assertEquals(500., threshold.max().orElse(0.0), 1e-3); assertEquals(4, crac.getFlowCnec("cnec2prevId").getThresholds().size()); diff --git a/data/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/craciojson/JsonRetrocompatibilityTest.java b/data/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/craciojson/JsonRetrocompatibilityTest.java index 7c77278506..8dee64e4de 100644 --- a/data/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/craciojson/JsonRetrocompatibilityTest.java +++ b/data/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/craciojson/JsonRetrocompatibilityTest.java @@ -8,11 +8,11 @@ import com.powsybl.iidm.network.Network; import com.powsybl.openrao.commons.OpenRaoException; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.*; import com.powsybl.openrao.data.cracapi.cnec.AngleCnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; import com.powsybl.openrao.data.cracapi.cnec.VoltageCnec; import com.powsybl.openrao.data.cracapi.networkaction.InjectionSetpoint; import com.powsybl.openrao.data.cracapi.networkaction.PstSetpoint; @@ -367,29 +367,29 @@ private void testContentOfV1Point0Crac(Crac crac) { assertEquals("operator4", crac.getFlowCnec("cnec4prevId").getOperator()); // check iMax and nominal voltage - assertEquals(2000., crac.getFlowCnec("cnec2prevId").getIMax(Side.LEFT), 1e-3); - assertEquals(2000., crac.getFlowCnec("cnec2prevId").getIMax(Side.RIGHT), 1e-3); - assertEquals(380., crac.getFlowCnec("cnec2prevId").getNominalVoltage(Side.LEFT), 1e-3); - assertEquals(220., crac.getFlowCnec("cnec2prevId").getNominalVoltage(Side.RIGHT), 1e-3); - assertEquals(Double.NaN, crac.getFlowCnec("cnec1prevId").getIMax(Side.LEFT), 1e-3); - assertEquals(1000., crac.getFlowCnec("cnec1prevId").getIMax(Side.RIGHT), 1e-3); - assertEquals(220., crac.getFlowCnec("cnec1prevId").getNominalVoltage(Side.LEFT), 1e-3); - assertEquals(220., crac.getFlowCnec("cnec1prevId").getNominalVoltage(Side.RIGHT), 1e-3); + assertEquals(2000., crac.getFlowCnec("cnec2prevId").getIMax(TwoSides.ONE), 1e-3); + assertEquals(2000., crac.getFlowCnec("cnec2prevId").getIMax(TwoSides.TWO), 1e-3); + assertEquals(380., crac.getFlowCnec("cnec2prevId").getNominalVoltage(TwoSides.ONE), 1e-3); + assertEquals(220., crac.getFlowCnec("cnec2prevId").getNominalVoltage(TwoSides.TWO), 1e-3); + assertEquals(Double.NaN, crac.getFlowCnec("cnec1prevId").getIMax(TwoSides.ONE), 1e-3); + assertEquals(1000., crac.getFlowCnec("cnec1prevId").getIMax(TwoSides.TWO), 1e-3); + assertEquals(220., crac.getFlowCnec("cnec1prevId").getNominalVoltage(TwoSides.ONE), 1e-3); + assertEquals(220., crac.getFlowCnec("cnec1prevId").getNominalVoltage(TwoSides.TWO), 1e-3); // check threshold assertEquals(1, crac.getFlowCnec("cnec4prevId").getThresholds().size()); BranchThreshold threshold = crac.getFlowCnec("cnec4prevId").getThresholds().iterator().next(); assertEquals(Unit.MEGAWATT, threshold.getUnit()); - assertEquals(Side.LEFT, threshold.getSide()); + assertEquals(TwoSides.ONE, threshold.getSide()); assertTrue(threshold.min().isEmpty()); assertEquals(500., threshold.max().orElse(0.0), 1e-3); assertEquals(3, crac.getFlowCnec("cnec2prevId").getThresholds().size()); assertTrue(crac.getFlowCnec("cnec2prevId").getThresholds().stream() - .anyMatch(thr -> thr.getSide().equals(Side.LEFT) && thr.getUnit().equals(Unit.AMPERE) && thr.min().orElse(-999.).equals(-800.))); + .anyMatch(thr -> thr.getSide().equals(TwoSides.ONE) && thr.getUnit().equals(Unit.AMPERE) && thr.min().orElse(-999.).equals(-800.))); assertTrue(crac.getFlowCnec("cnec2prevId").getThresholds().stream() - .anyMatch(thr -> thr.getSide().equals(Side.LEFT) && thr.getUnit().equals(Unit.PERCENT_IMAX) && thr.min().orElse(-999.).equals(-0.3))); + .anyMatch(thr -> thr.getSide().equals(TwoSides.ONE) && thr.getUnit().equals(Unit.PERCENT_IMAX) && thr.min().orElse(-999.).equals(-0.3))); assertTrue(crac.getFlowCnec("cnec2prevId").getThresholds().stream() - .anyMatch(thr -> thr.getSide().equals(Side.RIGHT) && thr.getUnit().equals(Unit.AMPERE) && thr.max().orElse(-999.).equals(1200.))); + .anyMatch(thr -> thr.getSide().equals(TwoSides.TWO) && thr.getUnit().equals(Unit.AMPERE) && thr.max().orElse(-999.).equals(1200.))); // --------------------------- // --- test NetworkActions --- diff --git a/data/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/craciojson/JsonSerializationConstantsTest.java b/data/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/craciojson/JsonSerializationConstantsTest.java index 999b203ae8..cf803b0453 100644 --- a/data/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/craciojson/JsonSerializationConstantsTest.java +++ b/data/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/craciojson/JsonSerializationConstantsTest.java @@ -13,7 +13,7 @@ import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.AngleCnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.cnec.VoltageCnec; import com.powsybl.openrao.data.cracapi.threshold.BranchThreshold; import com.powsybl.openrao.data.cracapi.usagerule.*; @@ -50,7 +50,7 @@ void versionNumberNokTest(String version) { assertEquals("json CRAC version number must be of the form vX.Y", exception.getMessage()); } - private BranchThreshold mockBranchThreshold(Unit unit, Side side, Double min) { + private BranchThreshold mockBranchThreshold(Unit unit, TwoSides side, Double min) { BranchThreshold branchThreshold = mock(BranchThreshold.class); when(branchThreshold.getUnit()).thenReturn(unit); when(branchThreshold.getSide()).thenReturn(side); @@ -61,21 +61,21 @@ private BranchThreshold mockBranchThreshold(Unit unit, Side side, Double min) { @Test void testThresholdComparator() { ThresholdComparator comparator = new ThresholdComparator(); - BranchThreshold bt1 = mockBranchThreshold(Unit.AMPERE, Side.LEFT, -10.); - BranchThreshold bt2 = mockBranchThreshold(Unit.AMPERE, Side.LEFT, null); + BranchThreshold bt1 = mockBranchThreshold(Unit.AMPERE, TwoSides.ONE, -10.); + BranchThreshold bt2 = mockBranchThreshold(Unit.AMPERE, TwoSides.ONE, null); assertTrue(comparator.compare(bt1, bt2) < 0); - bt1 = mockBranchThreshold(Unit.AMPERE, Side.LEFT, null); - bt2 = mockBranchThreshold(Unit.AMPERE, Side.LEFT, null); + bt1 = mockBranchThreshold(Unit.AMPERE, TwoSides.ONE, null); + bt2 = mockBranchThreshold(Unit.AMPERE, TwoSides.ONE, null); assertTrue(comparator.compare(bt1, bt2) > 0); - bt1 = mockBranchThreshold(Unit.AMPERE, Side.RIGHT, -10.); - bt2 = mockBranchThreshold(Unit.AMPERE, Side.LEFT, null); + bt1 = mockBranchThreshold(Unit.AMPERE, TwoSides.TWO, -10.); + bt2 = mockBranchThreshold(Unit.AMPERE, TwoSides.ONE, null); assertTrue(comparator.compare(bt1, bt2) > 0); - bt1 = mockBranchThreshold(Unit.AMPERE, Side.RIGHT, -10.); - bt2 = mockBranchThreshold(Unit.MEGAWATT, Side.LEFT, null); + bt1 = mockBranchThreshold(Unit.AMPERE, TwoSides.TWO, -10.); + bt2 = mockBranchThreshold(Unit.MEGAWATT, TwoSides.ONE, null); assertTrue(comparator.compare(bt1, bt2) < 0); } diff --git a/data/crac-io/crac-io-json/src/test/resources/retrocompatibility/v2/crac-v2.4.json b/data/crac-io/crac-io-json/src/test/resources/retrocompatibility/v2/crac-v2.4.json index 124e95ecab..59cd619d89 100644 --- a/data/crac-io/crac-io-json/src/test/resources/retrocompatibility/v2/crac-v2.4.json +++ b/data/crac-io/crac-io-json/src/test/resources/retrocompatibility/v2/crac-v2.4.json @@ -49,7 +49,7 @@ "thresholds" : [ { "unit" : "ampere", "min" : -800.0, - "side" : "left" + "side" : 1 } ] }, { "id" : "cnec1prevId", @@ -66,7 +66,7 @@ "thresholds" : [ { "unit" : "ampere", "min" : -500.0, - "side" : "right" + "side" : 2 } ] }, { "id" : "cnec2prevId", @@ -83,19 +83,19 @@ "thresholds" : [ { "unit" : "ampere", "min" : -800.0, - "side" : "left" + "side" : 1 }, { "unit" : "ampere", "min" : -800.0, - "side" : "left" + "side" : 1 }, { "unit" : "ampere", "max" : 1200.0, - "side" : "right" + "side" : 2 }, { "unit" : "percent_imax", "min" : -0.3, - "side" : "left" + "side" : 1 } ] }, { "id" : "cnec3autoId", @@ -113,7 +113,7 @@ "thresholds" : [ { "unit" : "megawatt", "max" : 500.0, - "side" : "left" + "side" : 1 } ] }, { "id" : "cnec3curId", @@ -131,7 +131,7 @@ "thresholds" : [ { "unit" : "megawatt", "max" : 500.0, - "side" : "left" + "side" : 1 } ] }, { "id" : "cnec3prevId", @@ -148,7 +148,7 @@ "thresholds" : [ { "unit" : "megawatt", "max" : 500.0, - "side" : "left" + "side" : 1 } ] }, { "id" : "cnec4prevId", @@ -165,7 +165,7 @@ "thresholds" : [ { "unit" : "megawatt", "max" : 500.0, - "side" : "left" + "side" : 1 } ] } ], "angleCnecs" : [ { diff --git a/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/cnec/BranchCnec.java b/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/cnec/BranchCnec.java index de2263ff0c..ae48f067e3 100644 --- a/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/cnec/BranchCnec.java +++ b/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/cnec/BranchCnec.java @@ -7,6 +7,7 @@ package com.powsybl.openrao.data.cracapi.cnec; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.commons.PhysicalParameter; import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.NetworkElement; @@ -39,12 +40,12 @@ public interface BranchCnec> extends Cnec { Set getThresholds(); /** - * Getter of the nominal voltage on each {@link Side} of the {@code BranchCnec}. + * Getter of the nominal voltage on each {@link TwoSides} of the {@code BranchCnec}. * - * @param side: The {@link Side} on which the nominal voltage is queried. + * @param side: The {@link TwoSides} on which the nominal voltage is queried. * @return The value of nominal voltage. */ - Double getNominalVoltage(Side side); + Double getNominalVoltage(TwoSides side); /** * Getter that returns the lower acceptable value of the {@link PhysicalParameter} with the given {@link Unit}. @@ -58,7 +59,7 @@ public interface BranchCnec> extends Cnec { * defined in a different unit that the one requested. * @return The lower bound of the {@link PhysicalParameter} on this {@code BranchCnec}. */ - Optional getLowerBound(Side side, Unit unit); + Optional getLowerBound(TwoSides side, Unit unit); /** * Getter that returns the upper acceptable value of the {@link PhysicalParameter} with the given {@link Unit}. @@ -72,7 +73,7 @@ public interface BranchCnec> extends Cnec { * defined in a different unit that the one requested. * @return The upper bound of the {@link PhysicalParameter} on this {@code BranchCnec}. */ - Optional getUpperBound(Side side, Unit unit); + Optional getUpperBound(TwoSides side, Unit unit); /** * A margin can be computed on a {@code BranchCnec}. It is the worst (minimal including negative) difference @@ -91,12 +92,12 @@ public interface BranchCnec> extends Cnec { * @return The margin of the {@code BranchCnec} on the given {@code side} with the given {@code unit} taking * {@code reliabilityMargin} into account. */ - double computeMargin(double actualValue, Side side, Unit unit); + double computeMargin(double actualValue, TwoSides side, Unit unit); /** - * Getter of the one or two {@link Side}s on which the {@code Cnec} is defined. + * Getter of the one or two {@link TwoSides}s on which the {@code Cnec} is defined. */ - default Set getMonitoredSides() { + default Set getMonitoredSides() { return getThresholds().stream().map(BranchThreshold::getSide).collect(Collectors.toUnmodifiableSet()); } } diff --git a/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/cnec/FlowCnec.java b/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/cnec/FlowCnec.java index 267ae280c0..c5089263b5 100644 --- a/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/cnec/FlowCnec.java +++ b/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/cnec/FlowCnec.java @@ -1,5 +1,6 @@ package com.powsybl.openrao.data.cracapi.cnec; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.commons.PhysicalParameter; import com.powsybl.iidm.network.Network; @@ -10,12 +11,12 @@ public interface FlowCnec extends BranchCnec { /** - * Getter of the Imax on each {@link Side} of the {@code FlowCnec}. + * Getter of the Imax on each {@link TwoSides} of the {@code FlowCnec}. * - * @param side: The {@link Side} on which the Imax is queried. + * @param side: The {@link TwoSides} on which the Imax is queried. * @return The value of the iMax, given in Unit.AMPERE. */ - Double getIMax(Side side); + Double getIMax(TwoSides side); /** * Says if a FlowCnec's NetworkElement is connected in a Network diff --git a/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/cnec/FlowCnecAdder.java b/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/cnec/FlowCnecAdder.java index d915462fe9..5144109bbd 100644 --- a/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/cnec/FlowCnecAdder.java +++ b/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/cnec/FlowCnecAdder.java @@ -7,6 +7,7 @@ package com.powsybl.openrao.data.cracapi.cnec; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.threshold.BranchThresholdAdder; /** @@ -16,11 +17,11 @@ public interface FlowCnecAdder extends CnecAdder { FlowCnecAdder withIMax(double iMaxInAmpere); - FlowCnecAdder withIMax(double iMaxInAmpere, Side side); + FlowCnecAdder withIMax(double iMaxInAmpere, TwoSides side); FlowCnecAdder withNominalVoltage(double nominalVoltageInKiloVolt); - FlowCnecAdder withNominalVoltage(double nominalVoltageInKiloVolt, Side side); + FlowCnecAdder withNominalVoltage(double nominalVoltageInKiloVolt, TwoSides side); BranchThresholdAdder newThreshold(); diff --git a/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/cnec/Side.java b/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/cnec/Side.java deleted file mode 100644 index eef46691c0..0000000000 --- a/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/cnec/Side.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2019, 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/. - */ - -package com.powsybl.openrao.data.cracapi.cnec; - -import com.powsybl.openrao.commons.OpenRaoException; -import com.powsybl.iidm.network.TwoSides; - -/** - * Side of a branch - * - * @author Viktor Terrier {@literal } - */ -public enum Side { - LEFT(TwoSides.ONE), - RIGHT(TwoSides.TWO); - - private final TwoSides iidmSide; - - Side(TwoSides iidmSide) { - this.iidmSide = iidmSide; - } - - public TwoSides iidmSide() { - return iidmSide; - } - - public static Side fromIidmSide(TwoSides side) { - switch (side) { - case ONE: - return LEFT; - case TWO: - return RIGHT; - default: - throw new OpenRaoException(String.format("Unhandled iidm side: %s", side)); - } - } -} diff --git a/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/threshold/BranchThreshold.java b/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/threshold/BranchThreshold.java index c588aa3c26..de838a2ca8 100644 --- a/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/threshold/BranchThreshold.java +++ b/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/threshold/BranchThreshold.java @@ -8,7 +8,7 @@ package com.powsybl.openrao.data.cracapi.threshold; import com.powsybl.openrao.data.cracapi.cnec.BranchCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; /** * Specific {@link Threshold} for {@link BranchCnec} @@ -20,8 +20,8 @@ */ public interface BranchThreshold extends Threshold { /** - * Get the {@link Side} of the Branch on which the threshold is defined, which is + * Get the {@link TwoSides} of the Branch on which the threshold is defined, which is * implicitly deduced from the rule of the threshold */ - Side getSide(); + TwoSides getSide(); } diff --git a/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/threshold/BranchThresholdAdder.java b/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/threshold/BranchThresholdAdder.java index 0169cdb320..27ed5d5bbf 100644 --- a/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/threshold/BranchThresholdAdder.java +++ b/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/threshold/BranchThresholdAdder.java @@ -8,14 +8,14 @@ package com.powsybl.openrao.data.cracapi.threshold; import com.powsybl.openrao.data.cracapi.cnec.FlowCnecAdder; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; /** * @author Joris Mancini {@literal } */ public interface BranchThresholdAdder extends ThresholdAdder { - BranchThresholdAdder withSide(Side side); + BranchThresholdAdder withSide(TwoSides side); FlowCnecAdder add(); } diff --git a/data/crac/crac-api/src/test/java/com/powsybl/openrao/data/cracapi/SideTest.java b/data/crac/crac-api/src/test/java/com/powsybl/openrao/data/cracapi/SideTest.java deleted file mode 100644 index e634dc0aa6..0000000000 --- a/data/crac/crac-api/src/test/java/com/powsybl/openrao/data/cracapi/SideTest.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2022, 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/. - */ - -package com.powsybl.openrao.data.cracapi; - -import com.powsybl.openrao.data.cracapi.cnec.Side; -import com.powsybl.iidm.network.TwoSides; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -/** - * @author Peter Mitri {@literal } - */ -class SideTest { - @Test - void basicTests() { - assertEquals(TwoSides.ONE, Side.LEFT.iidmSide()); - assertEquals(TwoSides.TWO, Side.RIGHT.iidmSide()); - assertEquals(Side.LEFT, Side.fromIidmSide(TwoSides.ONE)); - assertEquals(Side.RIGHT, Side.fromIidmSide(TwoSides.TWO)); - } -} diff --git a/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/cracimpl/AbstractBranchCnec.java b/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/cracimpl/AbstractBranchCnec.java index 37c95fbf12..074cfb98ed 100644 --- a/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/cracimpl/AbstractBranchCnec.java +++ b/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/cracimpl/AbstractBranchCnec.java @@ -11,7 +11,7 @@ import com.powsybl.openrao.data.cracapi.NetworkElement; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.BranchCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.threshold.BranchThreshold; import java.util.Collections; @@ -52,7 +52,7 @@ public NetworkElement getNetworkElement() { } @Override - public double computeMargin(double actualValue, Side side, Unit unit) { + public double computeMargin(double actualValue, TwoSides side, Unit unit) { double marginOnLowerBound = actualValue - getLowerBound(side, unit).orElse(Double.NEGATIVE_INFINITY); double marginOnUpperBound = getUpperBound(side, unit).orElse(Double.POSITIVE_INFINITY) - actualValue; return Math.min(marginOnLowerBound, marginOnUpperBound); @@ -64,8 +64,8 @@ public final Set getThresholds() { } @Override - public Double getNominalVoltage(Side side) { - return nominalVoltages[side.equals(Side.LEFT) ? 0 : 1]; + public Double getNominalVoltage(TwoSides side) { + return nominalVoltages[side.equals(TwoSides.ONE) ? 0 : 1]; } @Override diff --git a/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/cracimpl/BranchBoundsCache.java b/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/cracimpl/BranchBoundsCache.java index be2f590ceb..0f6e975728 100644 --- a/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/cracimpl/BranchBoundsCache.java +++ b/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/cracimpl/BranchBoundsCache.java @@ -9,7 +9,7 @@ import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.commons.Unit; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import java.util.*; @@ -31,7 +31,7 @@ private enum Bound { private List boundsComputed = Arrays.asList(false, false, false, false, false, false, false, false); private List boundValues = Arrays.asList(Double.NaN, Double.NaN, Double.NaN, Double.NaN, Double.NaN, Double.NaN, Double.NaN, Double.NaN); - private static int getIndex(Side side, Unit unit, Bound bound) { + private static int getIndex(TwoSides side, Unit unit, Bound bound) { if (unit.equals(Unit.AMPERE)) { return getAmpereIndex(side, bound); } else if (unit.equals(Unit.MEGAWATT)) { @@ -41,50 +41,50 @@ private static int getIndex(Side side, Unit unit, Bound bound) { } } - private static int getMegawattIndex(Side side, Bound bound) { + private static int getMegawattIndex(TwoSides side, Bound bound) { if (bound.equals(Bound.LOWER)) { - return side.equals(Side.LEFT) ? 0 : 1; + return side.equals(TwoSides.ONE) ? 0 : 1; } else { - return side.equals(Side.LEFT) ? 2 : 3; + return side.equals(TwoSides.ONE) ? 2 : 3; } } - private static int getAmpereIndex(Side side, Bound bound) { + private static int getAmpereIndex(TwoSides side, Bound bound) { if (bound.equals(Bound.LOWER)) { - return side.equals(Side.LEFT) ? 4 : 5; + return side.equals(TwoSides.ONE) ? 4 : 5; } else { - return side.equals(Side.LEFT) ? 6 : 7; + return side.equals(TwoSides.ONE) ? 6 : 7; } } - public boolean isLowerBoundComputed(Side side, Unit unit) { + public boolean isLowerBoundComputed(TwoSides side, Unit unit) { return boundsComputed.get(getIndex(side, unit, Bound.LOWER)); } - public boolean isUpperBoundComputed(Side side, Unit unit) { + public boolean isUpperBoundComputed(TwoSides side, Unit unit) { return boundsComputed.get(getIndex(side, unit, Bound.UPPER)); } - public Double getLowerBound(Side side, Unit unit) { + public Double getLowerBound(TwoSides side, Unit unit) { if (!isLowerBoundComputed(side, unit)) { throw new OpenRaoException("Trying to access not computed bound"); } return boundValues.get(getIndex(side, unit, Bound.LOWER)); } - public void setLowerBound(Double lowerBound, Side side, Unit unit) { + public void setLowerBound(Double lowerBound, TwoSides side, Unit unit) { boundValues.set(getIndex(side, unit, Bound.LOWER), lowerBound); boundsComputed.set(getIndex(side, unit, Bound.LOWER), true); } - public Double getUpperBound(Side side, Unit unit) { + public Double getUpperBound(TwoSides side, Unit unit) { if (!isUpperBoundComputed(side, unit)) { throw new OpenRaoException("Trying to access not computed bound"); } return boundValues.get(getIndex(side, unit, Bound.UPPER)); } - public void setUpperBound(Double upperBound, Side side, Unit unit) { + public void setUpperBound(Double upperBound, TwoSides side, Unit unit) { boundValues.set(getIndex(side, unit, Bound.UPPER), upperBound); boundsComputed.set(getIndex(side, unit, Bound.UPPER), true); } diff --git a/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/cracimpl/BranchThresholdAdderImpl.java b/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/cracimpl/BranchThresholdAdderImpl.java index 547a600752..ee4cd157be 100644 --- a/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/cracimpl/BranchThresholdAdderImpl.java +++ b/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/cracimpl/BranchThresholdAdderImpl.java @@ -10,7 +10,7 @@ import com.powsybl.openrao.commons.PhysicalParameter; import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.cnec.FlowCnecAdder; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.threshold.BranchThresholdAdder; import java.util.Objects; @@ -21,7 +21,7 @@ public class BranchThresholdAdderImpl extends AbstractThresholdAdderImpl implements BranchThresholdAdder { private final FlowCnecAdderImpl ownerAdder; - private Side side; + private TwoSides side; BranchThresholdAdderImpl(FlowCnecAdder ownerAdder) { Objects.requireNonNull(ownerAdder); @@ -36,7 +36,7 @@ public BranchThresholdAdderImpl withUnit(Unit unit) { } @Override - public BranchThresholdAdder withSide(Side side) { + public BranchThresholdAdder withSide(TwoSides side) { this.side = side; return this; } diff --git a/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/cracimpl/BranchThresholdImpl.java b/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/cracimpl/BranchThresholdImpl.java index e81bd04cd3..69c69cae20 100644 --- a/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/cracimpl/BranchThresholdImpl.java +++ b/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/cracimpl/BranchThresholdImpl.java @@ -8,7 +8,7 @@ package com.powsybl.openrao.data.cracimpl; import com.powsybl.openrao.commons.Unit; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.threshold.BranchThreshold; /** @@ -23,19 +23,19 @@ public class BranchThresholdImpl extends ThresholdImpl implements BranchThreshol /** * Side of the network element which is monitored */ - protected Side side; + protected TwoSides side; /** * Direction in which the flow is monitored */ - BranchThresholdImpl(Side side, Unit unit, Double min, Double max) { + BranchThresholdImpl(TwoSides side, Unit unit, Double min, Double max) { super(unit, min, max); this.side = side; } @Override - public Side getSide() { + public TwoSides getSide() { return side; } diff --git a/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/cracimpl/FlowCnecAdderImpl.java b/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/cracimpl/FlowCnecAdderImpl.java index db3fa67e52..8f518d0938 100644 --- a/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/cracimpl/FlowCnecAdderImpl.java +++ b/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/cracimpl/FlowCnecAdderImpl.java @@ -13,7 +13,7 @@ import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnecAdder; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.threshold.BranchThreshold; import com.powsybl.openrao.data.cracapi.threshold.BranchThresholdAdder; @@ -54,10 +54,10 @@ public FlowCnecAdder withIMax(double iMaxInAmpere) { } @Override - public FlowCnecAdder withIMax(double iMaxInAmpere, Side side) { - if (side.equals(Side.LEFT)) { + public FlowCnecAdder withIMax(double iMaxInAmpere, TwoSides side) { + if (side.equals(TwoSides.ONE)) { this.iMaxLeft = iMaxInAmpere; - } else if (side.equals(Side.RIGHT)) { + } else if (side.equals(TwoSides.TWO)) { this.iMaxRight = iMaxInAmpere; } return this; @@ -71,10 +71,10 @@ public FlowCnecAdder withNominalVoltage(double nominalVoltageInKiloVolt) { } @Override - public FlowCnecAdder withNominalVoltage(double nominalVoltageInKiloVolt, Side side) { - if (side.equals(Side.LEFT)) { + public FlowCnecAdder withNominalVoltage(double nominalVoltageInKiloVolt, TwoSides side) { + if (side.equals(TwoSides.ONE)) { this.nominalVLeft = nominalVoltageInKiloVolt; - } else if (side.equals(Side.RIGHT)) { + } else if (side.equals(TwoSides.TWO)) { this.nominalVRight = nominalVoltageInKiloVolt; } return this; @@ -149,13 +149,13 @@ private void checkAndInitThresholds() { private void checkImax(BranchThresholdImpl branchThreshold) { if (branchThreshold.getUnit().equals(Unit.PERCENT_IMAX) - && branchThreshold.getSide().equals(Side.LEFT) + && branchThreshold.getSide().equals(TwoSides.ONE) && (iMaxLeft == null || Double.isNaN(iMaxLeft))) { throw new OpenRaoException(String.format("iMax on left side of FlowCnec %s must be defined, as one of its threshold is on PERCENT_IMAX on the left side. Please use withIMax()", id)); } if (branchThreshold.getUnit().equals(Unit.PERCENT_IMAX) - && branchThreshold.getSide().equals(Side.RIGHT) + && branchThreshold.getSide().equals(TwoSides.TWO) && (iMaxRight == null || Double.isNaN(iMaxRight))) { throw new OpenRaoException(String.format("iMax on right side of FlowCnec %s must be defined, as one of its threshold is on PERCENT_IMAX on the right side. Please use withIMax()", id)); } diff --git a/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/cracimpl/FlowCnecImpl.java b/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/cracimpl/FlowCnecImpl.java index 310f5674c2..9d02d7545f 100644 --- a/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/cracimpl/FlowCnecImpl.java +++ b/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/cracimpl/FlowCnecImpl.java @@ -13,7 +13,7 @@ import com.powsybl.openrao.data.cracapi.NetworkElement; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.threshold.BranchThreshold; import com.powsybl.openrao.data.cracapi.threshold.Threshold; import com.powsybl.iidm.network.Connectable; @@ -52,8 +52,8 @@ public class FlowCnecImpl extends AbstractBranchCnec implements FlowCn } @Override - public Double getIMax(Side side) { - if (side.equals(Side.LEFT)) { + public Double getIMax(TwoSides side) { + if (side.equals(TwoSides.ONE)) { return iMax[0]; } else { return iMax[1]; @@ -61,7 +61,7 @@ public Double getIMax(Side side) { } @Override - public Optional getLowerBound(Side side, Unit requestedUnit) { + public Optional getLowerBound(TwoSides side, Unit requestedUnit) { if (!requestedUnit.equals(Unit.AMPERE) && !requestedUnit.equals(Unit.MEGAWATT)) { throw new OpenRaoException("FlowCnec lowerBound can only be requested in AMPERE or MEGAWATT"); @@ -91,7 +91,7 @@ public Optional getLowerBound(Side side, Unit requestedUnit) { } @Override - public Optional getUpperBound(Side side, Unit requestedUnit) { + public Optional getUpperBound(TwoSides side, Unit requestedUnit) { if (!requestedUnit.equals(Unit.AMPERE) && !requestedUnit.equals(Unit.MEGAWATT)) { throw new OpenRaoException("FlowCnec upperBound can only be requested in AMPERE or MEGAWATT"); @@ -129,7 +129,7 @@ private double getRawBound(BranchThreshold threshold, double thresholdValue) { } } - private double changeValueUnit(double value, Unit oldUnit, Unit newUnit, Side side) { + private double changeValueUnit(double value, Unit oldUnit, Unit newUnit, TwoSides side) { if (oldUnit.equals(newUnit) || oldUnit.equals(Unit.PERCENT_IMAX) && newUnit.equals(Unit.AMPERE)) { return value; diff --git a/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/BranchThresholdAdderImplTest.java b/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/BranchThresholdAdderImplTest.java index 6a7842559d..138ec91943 100644 --- a/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/BranchThresholdAdderImplTest.java +++ b/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/BranchThresholdAdderImplTest.java @@ -13,12 +13,12 @@ import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.InstantKind; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.threshold.BranchThresholdAdder; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.powsybl.openrao.data.cracapi.cnec.Side.LEFT; +import static com.powsybl.iidm.network.TwoSides.ONE; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -46,10 +46,10 @@ void testAddThresholdInMW() { FlowCnec cnec = crac.newFlowCnec() .withId("test-cnec").withInstant("outage").withContingency(contingency.getId()) .withNetworkElement("neID") - .newThreshold().withUnit(Unit.MEGAWATT).withMin(-250.0).withMax(1000.0).withSide(Side.LEFT).add() + .newThreshold().withUnit(Unit.MEGAWATT).withMin(-250.0).withMax(1000.0).withSide(TwoSides.ONE).add() .add(); - assertEquals(1000.0, cnec.getUpperBound(LEFT, Unit.MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); - assertEquals(-250.0, cnec.getLowerBound(LEFT, Unit.MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); + assertEquals(1000.0, cnec.getUpperBound(ONE, Unit.MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); + assertEquals(-250.0, cnec.getLowerBound(ONE, Unit.MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); } @Test @@ -57,11 +57,11 @@ void testAddThresholdInA() { FlowCnec cnec = crac.newFlowCnec() .withId("test-cnec").withInstant("outage").withContingency(contingency.getId()) .withNetworkElement("BBE1AA1 BBE2AA1 1") - .newThreshold().withUnit(Unit.AMPERE).withMin(-1000.).withMax(1000.).withSide(Side.LEFT).add() + .newThreshold().withUnit(Unit.AMPERE).withMin(-1000.).withMax(1000.).withSide(TwoSides.ONE).add() .withNominalVoltage(220.) .add(); - assertEquals(1000.0, cnec.getUpperBound(LEFT, Unit.AMPERE).orElseThrow(), DOUBLE_TOLERANCE); - assertEquals(-1000.0, cnec.getLowerBound(LEFT, Unit.AMPERE).orElseThrow(), DOUBLE_TOLERANCE); + assertEquals(1000.0, cnec.getUpperBound(ONE, Unit.AMPERE).orElseThrow(), DOUBLE_TOLERANCE); + assertEquals(-1000.0, cnec.getLowerBound(ONE, Unit.AMPERE).orElseThrow(), DOUBLE_TOLERANCE); } @Test @@ -69,13 +69,13 @@ void testAddThresholdInPercent() { FlowCnec cnec = crac.newFlowCnec() .withId("test-cnec").withInstant("curative").withContingency(contingency.getId()) .withNetworkElement("BBE1AA1 BBE2AA1 1") - .newThreshold().withUnit(Unit.PERCENT_IMAX).withMin(-0.8).withMax(0.5).withSide(Side.LEFT).add() + .newThreshold().withUnit(Unit.PERCENT_IMAX).withMin(-0.8).withMax(0.5).withSide(TwoSides.ONE).add() .withNominalVoltage(220.) .withIMax(5000.) .add(); - assertEquals(0.5 * 5000., cnec.getUpperBound(LEFT, Unit.AMPERE).orElseThrow(), DOUBLE_TOLERANCE); - assertEquals(-0.8 * 5000., cnec.getLowerBound(LEFT, Unit.AMPERE).orElseThrow(), DOUBLE_TOLERANCE); + assertEquals(0.5 * 5000., cnec.getUpperBound(ONE, Unit.AMPERE).orElseThrow(), DOUBLE_TOLERANCE); + assertEquals(-0.8 * 5000., cnec.getLowerBound(ONE, Unit.AMPERE).orElseThrow(), DOUBLE_TOLERANCE); } @Test @@ -94,7 +94,7 @@ void testUnsupportedUnitFail() { void testNoUnitFail() { BranchThresholdAdder branchThresholdAdder = crac.newFlowCnec().newThreshold() .withMax(1000.0) - .withSide(Side.LEFT); + .withSide(TwoSides.ONE); OpenRaoException exception = assertThrows(OpenRaoException.class, branchThresholdAdder::add); assertEquals("Cannot add Threshold without a Unit. Please use withUnit() with a non null value", exception.getMessage()); } @@ -103,7 +103,7 @@ void testNoUnitFail() { void testNoValueFail() { BranchThresholdAdder branchThresholdAdder = crac.newFlowCnec().newThreshold() .withUnit(Unit.AMPERE) - .withSide(Side.LEFT); + .withSide(TwoSides.ONE); OpenRaoException exception = assertThrows(OpenRaoException.class, branchThresholdAdder::add); assertEquals("Cannot add a threshold without min nor max values. Please use withMin() or withMax().", exception.getMessage()); } diff --git a/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/CracImplTest.java b/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/CracImplTest.java index ec7ed042da..841cab67fd 100644 --- a/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/CracImplTest.java +++ b/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/CracImplTest.java @@ -16,7 +16,7 @@ import com.powsybl.openrao.data.cracapi.*; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnecAdder; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.ActionType; import com.powsybl.openrao.data.cracapi.networkaction.ElementaryAction; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; @@ -159,7 +159,7 @@ void testGetCnecandGetFlowCnec() { .withOptimized(true) .withInstant(CURATIVE_INSTANT_ID) .withContingency("co") - .newThreshold().withMin(-1000.).withUnit(Unit.MEGAWATT).withSide(Side.LEFT).add() + .newThreshold().withMin(-1000.).withUnit(Unit.MEGAWATT).withSide(TwoSides.ONE).add() .add(); assertNotNull(crac.getFlowCnec("cnec-id")); @@ -209,7 +209,7 @@ void testSafeRemoveNetworkElements() { .withNetworkElement("ne3") .withOperator("operator") .withInstant(PREVENTIVE_INSTANT_ID) - .newThreshold().withMin(-1000.).withUnit(Unit.MEGAWATT).withSide(Side.LEFT).add() + .newThreshold().withMin(-1000.).withUnit(Unit.MEGAWATT).withSide(TwoSides.ONE).add() .add(); crac.newNetworkAction() @@ -260,7 +260,7 @@ void testSafeRemoveStates() { .withOperator("operator") .withContingency("co1") .withInstant(CURATIVE_INSTANT_ID) - .newThreshold().withMin(-1000.).withUnit(Unit.MEGAWATT).withSide(Side.LEFT).add() + .newThreshold().withMin(-1000.).withUnit(Unit.MEGAWATT).withSide(TwoSides.ONE).add() .add(); crac.newNetworkAction() @@ -326,7 +326,7 @@ void testRemoveUsedContingencyError() { .withNetworkElement("anyNetworkElement") .withInstant(CURATIVE_INSTANT_ID) .withContingency("co1") - .newThreshold().withMax(1000.).withUnit(Unit.MEGAWATT).withSide(Side.LEFT).add() + .newThreshold().withMax(1000.).withUnit(Unit.MEGAWATT).withSide(TwoSides.ONE).add() .add(); assertEquals(1, crac.getContingencies().size()); @@ -466,21 +466,21 @@ void testGetCnecsFromState() { .withNetworkElement("anyNetworkElement") .withInstant(CURATIVE_INSTANT_ID) .withContingency("co1") - .newThreshold().withMax(1000.).withUnit(Unit.MEGAWATT).withSide(Side.LEFT).add() + .newThreshold().withMax(1000.).withUnit(Unit.MEGAWATT).withSide(TwoSides.ONE).add() .add(); FlowCnec cnec2 = crac.newFlowCnec() .withId("cnec2") .withNetworkElement("anyNetworkElement") .withInstant(CURATIVE_INSTANT_ID) .withContingency("co1") - .newThreshold().withMax(1000.).withUnit(Unit.MEGAWATT).withSide(Side.LEFT).add() + .newThreshold().withMax(1000.).withUnit(Unit.MEGAWATT).withSide(TwoSides.ONE).add() .add(); FlowCnec cnec3 = crac.newFlowCnec() .withId("cnec3") .withNetworkElement("anyNetworkElement") .withInstant(OUTAGE_INSTANT_ID) .withContingency("co2") - .newThreshold().withMax(1000.).withUnit(Unit.MEGAWATT).withSide(Side.LEFT).add() + .newThreshold().withMax(1000.).withUnit(Unit.MEGAWATT).withSide(TwoSides.ONE).add() .add(); State state1 = crac.getState("co1", curativeInstant); @@ -512,28 +512,28 @@ void testRemoveCnec() { .withNetworkElement("ne1") .withInstant(CURATIVE_INSTANT_ID) .withContingency("co1") - .newThreshold().withMax(1000.).withUnit(Unit.MEGAWATT).withSide(Side.LEFT).add() + .newThreshold().withMax(1000.).withUnit(Unit.MEGAWATT).withSide(TwoSides.ONE).add() .add(); crac.newFlowCnec() .withId("cnec2") .withNetworkElement("ne1") .withInstant(OUTAGE_INSTANT_ID) .withContingency("co1") - .newThreshold().withMax(1000.).withUnit(Unit.MEGAWATT).withSide(Side.LEFT).add() + .newThreshold().withMax(1000.).withUnit(Unit.MEGAWATT).withSide(TwoSides.ONE).add() .add(); crac.newFlowCnec() .withId("cnec3") .withNetworkElement("ne2") .withInstant(CURATIVE_INSTANT_ID) .withContingency("co1") - .newThreshold().withMax(1000.).withUnit(Unit.MEGAWATT).withSide(Side.LEFT).add() + .newThreshold().withMax(1000.).withUnit(Unit.MEGAWATT).withSide(TwoSides.ONE).add() .add(); crac.newFlowCnec() .withId("cnec4") .withNetworkElement("ne2") .withInstant(OUTAGE_INSTANT_ID) .withContingency("co1") - .newThreshold().withMax(1000.).withUnit(Unit.MEGAWATT).withSide(Side.LEFT).add() + .newThreshold().withMax(1000.).withUnit(Unit.MEGAWATT).withSide(TwoSides.ONE).add() .add(); assertEquals(4, crac.getFlowCnecs().size()); diff --git a/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/FlowCnecAdderImplTest.java b/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/FlowCnecAdderImplTest.java index f67ecd08c6..73ad5b5c74 100644 --- a/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/FlowCnecAdderImplTest.java +++ b/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/FlowCnecAdderImplTest.java @@ -20,8 +20,8 @@ import java.util.Optional; -import static com.powsybl.openrao.data.cracapi.cnec.Side.LEFT; -import static com.powsybl.openrao.data.cracapi.cnec.Side.RIGHT; +import static com.powsybl.iidm.network.TwoSides.ONE; +import static com.powsybl.iidm.network.TwoSides.TWO; import static org.junit.jupiter.api.Assertions.*; /** @@ -61,14 +61,14 @@ void testAdd() { .withContingency(contingency1Id) .withOperator("cnec1Operator") .withNetworkElement("neId1", "neName1") - .newThreshold().withUnit(Unit.MEGAWATT).withSide(LEFT).withMax(1000.0).withMin(-1000.0).add() + .newThreshold().withUnit(Unit.MEGAWATT).withSide(ONE).withMax(1000.0).withMin(-1000.0).add() .add(); FlowCnec cnec2 = crac.newFlowCnec() .withId("cnecId2") .withInstant(PREVENTIVE_INSTANT_ID) .withOperator("cnec2Operator") .withNetworkElement("neId2") - .newThreshold().withUnit(Unit.MEGAWATT).withSide(LEFT).withMax(500.0).add() + .newThreshold().withUnit(Unit.MEGAWATT).withSide(ONE).withMax(500.0).add() .add(); assertEquals(2, crac.getFlowCnecs().size()); @@ -79,8 +79,8 @@ void testAdd() { assertEquals(outageInstant, cnec1.getState().getInstant()); assertEquals("cnec1Operator", cnec1.getOperator()); assertEquals("neName1", cnec1.getNetworkElement().getName()); - assertEquals(1000.0, cnec1.getUpperBound(LEFT, Unit.MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); - assertEquals(-1000.0, cnec1.getLowerBound(LEFT, Unit.MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); + assertEquals(1000.0, cnec1.getUpperBound(ONE, Unit.MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); + assertEquals(-1000.0, cnec1.getLowerBound(ONE, Unit.MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); // Verify 2nd cnec content assertEquals(cnec2, crac.getFlowCnec("cnecId2")); @@ -89,8 +89,8 @@ void testAdd() { assertEquals("cnec2Operator", cnec2.getOperator()); assertEquals(Optional.empty(), cnec2.getState().getContingency()); assertEquals("neId2", cnec2.getNetworkElement().getName()); - assertEquals(500.0, cnec2.getUpperBound(LEFT, Unit.MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); - assertFalse(cnec2.getLowerBound(LEFT, Unit.MEGAWATT).isPresent()); + assertEquals(500.0, cnec2.getUpperBound(ONE, Unit.MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); + assertFalse(cnec2.getLowerBound(ONE, Unit.MEGAWATT).isPresent()); // Verify that network elements were created crac.newFlowCnec() @@ -98,7 +98,7 @@ void testAdd() { .withInstant(PREVENTIVE_INSTANT_ID) .withOperator("cnec2Operator") .withNetworkElement("neId2") // same as cnec2 - .newThreshold().withUnit(Unit.MEGAWATT).withSide(LEFT).withMax(500.0).add() + .newThreshold().withUnit(Unit.MEGAWATT).withSide(ONE).withMax(500.0).add() .add(); assertEquals(2, crac.getNetworkElements().size()); assertNotNull(crac.getNetworkElement("neId1")); @@ -118,11 +118,11 @@ void testFrmHandling() { .withInstant(OUTAGE_INSTANT_ID) .withContingency(contingency1Id) .withNetworkElement("Network Element ID") - .newThreshold().withUnit(Unit.MEGAWATT).withSide(LEFT).withMax(maxValueInMw).withMin(-maxValueInMw).add() + .newThreshold().withUnit(Unit.MEGAWATT).withSide(ONE).withMax(maxValueInMw).withMin(-maxValueInMw).add() .withReliabilityMargin(frmInMw) .add(); - assertEquals(maxValueInMw - frmInMw, cnec.getUpperBound(LEFT, Unit.MEGAWATT).orElseThrow(OpenRaoException::new), 0.0); - assertEquals(frmInMw - maxValueInMw, cnec.getLowerBound(LEFT, Unit.MEGAWATT).orElseThrow(OpenRaoException::new), 0.0); + assertEquals(maxValueInMw - frmInMw, cnec.getUpperBound(ONE, Unit.MEGAWATT).orElseThrow(OpenRaoException::new), 0.0); + assertEquals(frmInMw - maxValueInMw, cnec.getLowerBound(ONE, Unit.MEGAWATT).orElseThrow(OpenRaoException::new), 0.0); } @Test @@ -131,7 +131,7 @@ void testNotOptimizedMonitored() { .withInstant(OUTAGE_INSTANT_ID) .withContingency(contingency1Id) .withNetworkElement("Network Element ID") - .newThreshold().withUnit(Unit.MEGAWATT).withSide(LEFT).withMax(100.0).withMin(-100.0).add() + .newThreshold().withUnit(Unit.MEGAWATT).withSide(ONE).withMax(100.0).withMin(-100.0).add() .withMonitored() .add(); assertFalse(cnec.isOptimized()); @@ -144,7 +144,7 @@ void testOptimizedNotMonitored() { .withInstant(OUTAGE_INSTANT_ID) .withContingency(contingency1Id) .withNetworkElement("Network Element ID") - .newThreshold().withUnit(Unit.MEGAWATT).withSide(LEFT).withMax(100.0).withMin(-100.0).add() + .newThreshold().withUnit(Unit.MEGAWATT).withSide(ONE).withMax(100.0).withMin(-100.0).add() .withOptimized() .add(); assertTrue(cnec.isOptimized()); @@ -157,9 +157,9 @@ void testNotOptimizedNotMonitored() { .withInstant(OUTAGE_INSTANT_ID) .withContingency(contingency1Id) .withNetworkElement("Network Element ID") - .newThreshold().withUnit(Unit.PERCENT_IMAX).withSide(LEFT).withMax(100.0).withMin(-100.0).add() + .newThreshold().withUnit(Unit.PERCENT_IMAX).withSide(ONE).withMax(100.0).withMin(-100.0).add() .withNominalVoltage(380.) - .withIMax(1200., LEFT) + .withIMax(1200., ONE) .add(); assertFalse(cnec.isOptimized()); assertFalse(cnec.isMonitored()); @@ -171,7 +171,7 @@ void testNotOptimizedNotMonitored2() { .withInstant(OUTAGE_INSTANT_ID) .withContingency(contingency1Id) .withNetworkElement("Network Element ID") - .newThreshold().withUnit(Unit.AMPERE).withSide(LEFT).withMax(100.0).withMin(-100.0).add() + .newThreshold().withUnit(Unit.AMPERE).withSide(ONE).withMax(100.0).withMin(-100.0).add() .withOptimized(false) .withMonitored(false) .withNominalVoltage(380.) @@ -186,18 +186,18 @@ void checkThresholdSideInitialisation1() { .withInstant(OUTAGE_INSTANT_ID) .withContingency(contingency1Id) .withNetworkElement("Network Element ID") - .newThreshold().withUnit(Unit.PERCENT_IMAX).withSide(LEFT).withMax(1.).withMin(-100.0).add() - .newThreshold().withUnit(Unit.AMPERE).withSide(LEFT).withMax(100.0).withMin(-100.0).add() - .newThreshold().withUnit(Unit.AMPERE).withSide(LEFT).withMax(200.0).withMin(-100.0).add() + .newThreshold().withUnit(Unit.PERCENT_IMAX).withSide(ONE).withMax(1.).withMin(-100.0).add() + .newThreshold().withUnit(Unit.AMPERE).withSide(ONE).withMax(100.0).withMin(-100.0).add() + .newThreshold().withUnit(Unit.AMPERE).withSide(ONE).withMax(200.0).withMin(-100.0).add() .withOptimized(false) .withMonitored(false) - .withNominalVoltage(380., LEFT) - .withNominalVoltage(220., RIGHT) + .withNominalVoltage(380., ONE) + .withNominalVoltage(220., TWO) .withIMax(2000.) .add(); assertEquals(3, cnec.getThresholds().size()); - assertTrue(cnec.getThresholds().stream().allMatch(th -> th.getSide().equals(LEFT))); + assertTrue(cnec.getThresholds().stream().allMatch(th -> th.getSide().equals(ONE))); } @Test @@ -206,18 +206,18 @@ void checkThresholdSideInitialisation2() { .withInstant(OUTAGE_INSTANT_ID) .withContingency(contingency1Id) .withNetworkElement("Network Element ID") - .newThreshold().withUnit(Unit.MEGAWATT).withSide(RIGHT).withMax(100.0).withMin(-200.0).add() - .newThreshold().withUnit(Unit.MEGAWATT).withSide(RIGHT).withMax(100.0).withMin(-100.0).add() - .newThreshold().withUnit(Unit.PERCENT_IMAX).withSide(RIGHT).withMax(1.).withMin(-100.0).add() + .newThreshold().withUnit(Unit.MEGAWATT).withSide(TWO).withMax(100.0).withMin(-200.0).add() + .newThreshold().withUnit(Unit.MEGAWATT).withSide(TWO).withMax(100.0).withMin(-100.0).add() + .newThreshold().withUnit(Unit.PERCENT_IMAX).withSide(TWO).withMax(1.).withMin(-100.0).add() .withOptimized(false) .withMonitored(false) - .withNominalVoltage(380., LEFT) - .withNominalVoltage(220., RIGHT) + .withNominalVoltage(380., ONE) + .withNominalVoltage(220., TWO) .withIMax(2000.) .add(); assertEquals(3, cnec.getThresholds().size()); - assertTrue(cnec.getThresholds().stream().allMatch(th -> th.getSide().equals(RIGHT))); + assertTrue(cnec.getThresholds().stream().allMatch(th -> th.getSide().equals(TWO))); } @Test @@ -240,7 +240,7 @@ void testNoIdFail() { .withInstant(OUTAGE_INSTANT_ID) .withContingency(contingency1Id) .withNetworkElement("neId1", "neName1") - .newThreshold().withUnit(Unit.MEGAWATT).withSide(LEFT).withMax(1000.0).add() + .newThreshold().withUnit(Unit.MEGAWATT).withSide(ONE).withMax(1000.0).add() .withNominalVoltage(220) .withIMax(2000.); OpenRaoException exception = assertThrows(OpenRaoException.class, flowCnecAdder::add); @@ -253,7 +253,7 @@ void testNoStateInstantFail() { .withId("cnecId1") .withName("cnecName1") .withContingency(contingency1Id) - .newThreshold().withUnit(Unit.MEGAWATT).withMax(1000.0).withSide(LEFT).add() + .newThreshold().withUnit(Unit.MEGAWATT).withMax(1000.0).withSide(ONE).add() .withNetworkElement("neId1", "neName1") .withNominalVoltage(220) .withIMax(2000.); @@ -268,7 +268,7 @@ void testNoNetworkElementFail() { .withName("cnecName1") .withInstant(OUTAGE_INSTANT_ID) .withContingency(contingency1Id) - .newThreshold().withSide(LEFT).withUnit(Unit.MEGAWATT).withMax(1000.0).add() + .newThreshold().withSide(ONE).withUnit(Unit.MEGAWATT).withMax(1000.0).add() .withNominalVoltage(220) .withIMax(2000.); OpenRaoException exception = assertThrows(OpenRaoException.class, flowCnecAdder::add); @@ -294,14 +294,14 @@ void testAddTwiceError() { crac.newFlowCnec().withId("Cnec ID") .withInstant(PREVENTIVE_INSTANT_ID) .withNetworkElement("Network Element ID") - .newThreshold().withUnit(Unit.MEGAWATT).withSide(LEFT).withMax(100.0).withMin(-100.0).add() + .newThreshold().withUnit(Unit.MEGAWATT).withSide(ONE).withMax(100.0).withMin(-100.0).add() .withNominalVoltage(220) .withIMax(2000.) .add(); FlowCnecAdder flowCnecAdder = crac.newFlowCnec().withId("Cnec ID") .withInstant(PREVENTIVE_INSTANT_ID) .withNetworkElement("Network Element ID") - .newThreshold().withUnit(Unit.MEGAWATT).withSide(LEFT).withMax(100.0).withMin(-100.0).add() + .newThreshold().withUnit(Unit.MEGAWATT).withSide(ONE).withMax(100.0).withMin(-100.0).add() .withNominalVoltage(220) .withIMax(2000.); OpenRaoException exception = assertThrows(OpenRaoException.class, flowCnecAdder::add); @@ -314,7 +314,7 @@ void testAddPreventiveCnecWithContingencyError() { .withInstant(PREVENTIVE_INSTANT_ID) .withContingency(contingency1Id) .withNetworkElement("Network Element ID") - .newThreshold().withUnit(Unit.MEGAWATT).withSide(LEFT).withMax(100.0).withMin(-100.0).add() + .newThreshold().withUnit(Unit.MEGAWATT).withSide(ONE).withMax(100.0).withMin(-100.0).add() .withNominalVoltage(220) .withIMax(2000.); OpenRaoException exception = assertThrows(OpenRaoException.class, flowCnecAdder::add); @@ -326,7 +326,7 @@ void testAddOutageCnecWithNoContingencyError() { FlowCnecAdder flowCnecAdder = crac.newFlowCnec().withId("Cnec ID") .withInstant(OUTAGE_INSTANT_ID) .withNetworkElement("Network Element ID") - .newThreshold().withUnit(Unit.MEGAWATT).withSide(LEFT).withMax(100.0).withMin(-100.0).add() + .newThreshold().withUnit(Unit.MEGAWATT).withSide(ONE).withMax(100.0).withMin(-100.0).add() .withNominalVoltage(220) .withIMax(2000.); OpenRaoException exception = assertThrows(OpenRaoException.class, flowCnecAdder::add); @@ -338,7 +338,7 @@ void testAddAutoCnecWithNoContingencyError() { FlowCnecAdder flowCnecAdder = crac.newFlowCnec().withId("Cnec ID") .withInstant(AUTO_INSTANT_ID) .withNetworkElement("Network Element ID") - .newThreshold().withUnit(Unit.MEGAWATT).withSide(LEFT).withMax(100.0).withMin(-100.0).add() + .newThreshold().withUnit(Unit.MEGAWATT).withSide(ONE).withMax(100.0).withMin(-100.0).add() .withNominalVoltage(220) .withIMax(2000.); OpenRaoException exception = assertThrows(OpenRaoException.class, flowCnecAdder::add); @@ -350,7 +350,7 @@ void testAddCurativeCnecWithNoContingencyError() { FlowCnecAdder flowCnecAdder = crac.newFlowCnec().withId("Cnec ID") .withInstant(CURATIVE_INSTANT_ID) .withNetworkElement("Network Element ID") - .newThreshold().withUnit(Unit.MEGAWATT).withSide(LEFT).withMax(100.0).withMin(-100.0).add() + .newThreshold().withUnit(Unit.MEGAWATT).withSide(ONE).withMax(100.0).withMin(-100.0).add() .withNominalVoltage(220) .withIMax(2000.); OpenRaoException exception = assertThrows(OpenRaoException.class, flowCnecAdder::add); @@ -363,7 +363,7 @@ void testAddCurativeCnecWithAbsentContingencyError() { .withInstant(CURATIVE_INSTANT_ID) .withContingency("absent-from-crac-contingency") .withNetworkElement("Network Element ID") - .newThreshold().withUnit(Unit.MEGAWATT).withSide(LEFT).withMax(100.0).withMin(-100.0).add() + .newThreshold().withUnit(Unit.MEGAWATT).withSide(ONE).withMax(100.0).withMin(-100.0).add() .withNominalVoltage(220) .withIMax(2000.); OpenRaoException exception = assertThrows(OpenRaoException.class, flowCnecAdder::add); @@ -375,7 +375,7 @@ void testThresholdInPercentImaxButNoIMax1() { FlowCnecAdder flowCnecAdder = crac.newFlowCnec().withId("Cnec ID") .withInstant(PREVENTIVE_INSTANT_ID) .withNetworkElement("Network Element ID") - .newThreshold().withUnit(Unit.PERCENT_IMAX).withSide(LEFT).withMax(1.).withMin(-1.).add() + .newThreshold().withUnit(Unit.PERCENT_IMAX).withSide(ONE).withMax(1.).withMin(-1.).add() .withNominalVoltage(220.); OpenRaoException exception = assertThrows(OpenRaoException.class, flowCnecAdder::add); assertEquals("iMax on left side of FlowCnec Cnec ID must be defined, as one of its threshold is on PERCENT_IMAX on the left side. Please use withIMax()", exception.getMessage()); @@ -386,9 +386,9 @@ void testThresholdInPercentImaxButNoIMax2() { FlowCnecAdder flowCnecAdder = crac.newFlowCnec().withId("Cnec ID") .withInstant(PREVENTIVE_INSTANT_ID) .withNetworkElement("Network Element ID") - .newThreshold().withUnit(Unit.PERCENT_IMAX).withSide(LEFT).withMax(1.).withMin(-1.).add() + .newThreshold().withUnit(Unit.PERCENT_IMAX).withSide(ONE).withMax(1.).withMin(-1.).add() .withNominalVoltage(220.) - .withIMax(1000., RIGHT); // threshold on left side cannot be interpreted + .withIMax(1000., TWO); // threshold on left side cannot be interpreted OpenRaoException exception = assertThrows(OpenRaoException.class, flowCnecAdder::add); assertEquals("iMax on left side of FlowCnec Cnec ID must be defined, as one of its threshold is on PERCENT_IMAX on the left side. Please use withIMax()", exception.getMessage()); } @@ -398,7 +398,7 @@ void testThresholdInAmpereButNoNominalVoltage() { FlowCnecAdder flowCnecAdder = crac.newFlowCnec().withId("Cnec ID") .withInstant(PREVENTIVE_INSTANT_ID) .withNetworkElement("Network Element ID") - .newThreshold().withUnit(Unit.AMPERE).withSide(LEFT).withMax(1000.).add() + .newThreshold().withUnit(Unit.AMPERE).withSide(ONE).withMax(1000.).add() .withIMax(1000.); OpenRaoException exception = assertThrows(OpenRaoException.class, flowCnecAdder::add); assertEquals("nominal voltages on both side of FlowCnec Cnec ID must be defined, as one of its threshold is on PERCENT_IMAX or AMPERE. Please use withNominalVoltage()", exception.getMessage()); @@ -409,8 +409,8 @@ void testThresholdInPercentImaxButNoNominalVoltage() { FlowCnecAdder flowCnecAdder = crac.newFlowCnec().withId("Cnec ID") .withInstant(PREVENTIVE_INSTANT_ID) .withNetworkElement("Network Element ID") - .newThreshold().withUnit(Unit.PERCENT_IMAX).withSide(LEFT).withMax(1000.).add() - .withNominalVoltage(220., LEFT) // should be defined on both side + .newThreshold().withUnit(Unit.PERCENT_IMAX).withSide(ONE).withMax(1000.).add() + .withNominalVoltage(220., ONE) // should be defined on both side .withIMax(1000.); OpenRaoException exception = assertThrows(OpenRaoException.class, flowCnecAdder::add); assertEquals("nominal voltages on both side of FlowCnec Cnec ID must be defined, as one of its threshold is on PERCENT_IMAX or AMPERE. Please use withNominalVoltage()", exception.getMessage()); diff --git a/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/FlowCnecImplTest.java b/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/FlowCnecImplTest.java index 3418be2e97..f82d4478f7 100644 --- a/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/FlowCnecImplTest.java +++ b/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/FlowCnecImplTest.java @@ -10,7 +10,7 @@ import com.powsybl.openrao.data.cracapi.InstantKind; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnecAdder; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracimpl.utils.NetworkImportsUtil; import com.powsybl.iidm.network.Country; import com.powsybl.iidm.network.Network; @@ -21,8 +21,8 @@ import java.util.Set; import static com.powsybl.openrao.commons.Unit.*; -import static com.powsybl.openrao.data.cracapi.cnec.Side.LEFT; -import static com.powsybl.openrao.data.cracapi.cnec.Side.RIGHT; +import static com.powsybl.iidm.network.TwoSides.ONE; +import static com.powsybl.iidm.network.TwoSides.TWO; import static org.junit.jupiter.api.Assertions.*; /** @@ -49,9 +49,9 @@ void testGetLocation1() { Network network = NetworkImportsUtil.import12NodesNetwork(); - FlowCnec cnec1 = crac.newFlowCnec().withId("cnec-1-id").withNetworkElement("BBE1AA1 BBE2AA1 1").withInstant(PREVENTIVE_INSTANT_ID).newThreshold().withUnit(MEGAWATT).withMax(1000.).withSide(Side.LEFT).add().add(); + FlowCnec cnec1 = crac.newFlowCnec().withId("cnec-1-id").withNetworkElement("BBE1AA1 BBE2AA1 1").withInstant(PREVENTIVE_INSTANT_ID).newThreshold().withUnit(MEGAWATT).withMax(1000.).withSide(TwoSides.ONE).add().add(); - FlowCnec cnec2 = crac.newFlowCnec().withId("cnec-2-id").withNetworkElement("DDE2AA1 NNL3AA1 1").withInstant(PREVENTIVE_INSTANT_ID).newThreshold().withUnit(MEGAWATT).withMax(1000.).withSide(Side.LEFT).add().add(); + FlowCnec cnec2 = crac.newFlowCnec().withId("cnec-2-id").withNetworkElement("DDE2AA1 NNL3AA1 1").withInstant(PREVENTIVE_INSTANT_ID).newThreshold().withUnit(MEGAWATT).withMax(1000.).withSide(TwoSides.ONE).add().add(); Set> countries = cnec1.getLocation(network); assertEquals(1, countries.size()); @@ -68,150 +68,150 @@ void testGetLocation1() { @Test void testBranchWithOneMaxThresholdOnLeftInMW() { - FlowCnec cnec = initPreventiveCnecAdder().withNominalVoltage(380.).newThreshold().withUnit(MEGAWATT).withMax(500.).withSide(Side.LEFT).add().add(); + FlowCnec cnec = initPreventiveCnecAdder().withNominalVoltage(380.).newThreshold().withUnit(MEGAWATT).withMax(500.).withSide(TwoSides.ONE).add().add(); - // bounds on LEFT side - assertEquals(500., cnec.getUpperBound(LEFT, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); - assertEquals(500. / (0.38 * Math.sqrt(3)), cnec.getUpperBound(LEFT, AMPERE).orElseThrow(), DOUBLE_TOLERANCE); // = 760 A - assertFalse(cnec.getLowerBound(LEFT, MEGAWATT).isPresent()); - assertFalse(cnec.getLowerBound(LEFT, AMPERE).isPresent()); + // bounds on ONE side + assertEquals(500., cnec.getUpperBound(ONE, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); + assertEquals(500. / (0.38 * Math.sqrt(3)), cnec.getUpperBound(ONE, AMPERE).orElseThrow(), DOUBLE_TOLERANCE); // = 760 A + assertFalse(cnec.getLowerBound(ONE, MEGAWATT).isPresent()); + assertFalse(cnec.getLowerBound(ONE, AMPERE).isPresent()); - // bounds on RIGHT side - assertFalse(cnec.getUpperBound(RIGHT, MEGAWATT).isPresent()); - assertFalse(cnec.getUpperBound(RIGHT, AMPERE).isPresent()); - assertFalse(cnec.getLowerBound(RIGHT, MEGAWATT).isPresent()); - assertFalse(cnec.getLowerBound(RIGHT, AMPERE).isPresent()); + // bounds on TWO side + assertFalse(cnec.getUpperBound(TWO, MEGAWATT).isPresent()); + assertFalse(cnec.getUpperBound(TWO, AMPERE).isPresent()); + assertFalse(cnec.getLowerBound(TWO, MEGAWATT).isPresent()); + assertFalse(cnec.getLowerBound(TWO, AMPERE).isPresent()); // margin - assertEquals(200., cnec.computeMargin(300, LEFT, MEGAWATT), DOUBLE_TOLERANCE); // bound: 500 MW - assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(300, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); // bound: 500 MW - assertEquals(460., cnec.computeMargin(300, LEFT, AMPERE), DOUBLE_TOLERANCE); // bound: 760 A - assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(-300, RIGHT, AMPERE), DOUBLE_TOLERANCE); // bound: 760 A + assertEquals(200., cnec.computeMargin(300, ONE, MEGAWATT), DOUBLE_TOLERANCE); // bound: 500 MW + assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(300, TWO, MEGAWATT), DOUBLE_TOLERANCE); // bound: 500 MW + assertEquals(460., cnec.computeMargin(300, ONE, AMPERE), DOUBLE_TOLERANCE); // bound: 760 A + assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(-300, TWO, AMPERE), DOUBLE_TOLERANCE); // bound: 760 A } @Test void testBranchWithOneMinThresholdOnRightInMW() { - FlowCnec cnec = initPreventiveCnecAdder().withNominalVoltage(380.).newThreshold().withUnit(MEGAWATT).withMin(-500.).withSide(Side.RIGHT).add().add(); + FlowCnec cnec = initPreventiveCnecAdder().withNominalVoltage(380.).newThreshold().withUnit(MEGAWATT).withMin(-500.).withSide(TwoSides.TWO).add().add(); - // bounds on LEFT side - assertFalse(cnec.getUpperBound(LEFT, MEGAWATT).isPresent()); - assertFalse(cnec.getUpperBound(LEFT, AMPERE).isPresent()); - assertFalse(cnec.getLowerBound(LEFT, MEGAWATT).isPresent()); - assertFalse(cnec.getLowerBound(LEFT, AMPERE).isPresent()); + // bounds on ONE side + assertFalse(cnec.getUpperBound(ONE, MEGAWATT).isPresent()); + assertFalse(cnec.getUpperBound(ONE, AMPERE).isPresent()); + assertFalse(cnec.getLowerBound(ONE, MEGAWATT).isPresent()); + assertFalse(cnec.getLowerBound(ONE, AMPERE).isPresent()); - // bounds on RIGHT side - assertFalse(cnec.getUpperBound(RIGHT, MEGAWATT).isPresent()); - assertFalse(cnec.getUpperBound(RIGHT, AMPERE).isPresent()); - assertEquals(-500., cnec.getLowerBound(RIGHT, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); - assertEquals(-500. / (0.38 * Math.sqrt(3)), cnec.getLowerBound(RIGHT, AMPERE).orElseThrow(), DOUBLE_TOLERANCE); // = -760 A + // bounds on TWO side + assertFalse(cnec.getUpperBound(TWO, MEGAWATT).isPresent()); + assertFalse(cnec.getUpperBound(TWO, AMPERE).isPresent()); + assertEquals(-500., cnec.getLowerBound(TWO, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); + assertEquals(-500. / (0.38 * Math.sqrt(3)), cnec.getLowerBound(TWO, AMPERE).orElseThrow(), DOUBLE_TOLERANCE); // = -760 A // margin - assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(300, LEFT, MEGAWATT), DOUBLE_TOLERANCE); // bound: -500 MW - assertEquals(800., cnec.computeMargin(300, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); // bound: -500 MW - assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(300, LEFT, AMPERE), DOUBLE_TOLERANCE); // bound: -760 A - assertEquals(-240., cnec.computeMargin(-1000, RIGHT, AMPERE), DOUBLE_TOLERANCE); // bound: -760 A + assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(300, ONE, MEGAWATT), DOUBLE_TOLERANCE); // bound: -500 MW + assertEquals(800., cnec.computeMargin(300, TWO, MEGAWATT), DOUBLE_TOLERANCE); // bound: -500 MW + assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(300, ONE, AMPERE), DOUBLE_TOLERANCE); // bound: -760 A + assertEquals(-240., cnec.computeMargin(-1000, TWO, AMPERE), DOUBLE_TOLERANCE); // bound: -760 A } @Test void testBranchWithOneMinThresholdOnLeftInAmpere() { - FlowCnec cnec = initPreventiveCnecAdder().withNominalVoltage(380.).newThreshold().withUnit(AMPERE).withMin(-450.).withSide(Side.LEFT).add().add(); + FlowCnec cnec = initPreventiveCnecAdder().withNominalVoltage(380.).newThreshold().withUnit(AMPERE).withMin(-450.).withSide(TwoSides.ONE).add().add(); - // bounds on LEFT side - assertFalse(cnec.getUpperBound(LEFT, MEGAWATT).isPresent()); - assertFalse(cnec.getUpperBound(LEFT, AMPERE).isPresent()); - assertEquals(-450., cnec.getLowerBound(LEFT, AMPERE).orElseThrow(), DOUBLE_TOLERANCE); - assertEquals(-450. * (0.38 * Math.sqrt(3)), cnec.getLowerBound(LEFT, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); // -296 MW + // bounds on ONE side + assertFalse(cnec.getUpperBound(ONE, MEGAWATT).isPresent()); + assertFalse(cnec.getUpperBound(ONE, AMPERE).isPresent()); + assertEquals(-450., cnec.getLowerBound(ONE, AMPERE).orElseThrow(), DOUBLE_TOLERANCE); + assertEquals(-450. * (0.38 * Math.sqrt(3)), cnec.getLowerBound(ONE, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); // -296 MW - // bounds on RIGHT side - assertFalse(cnec.getUpperBound(RIGHT, MEGAWATT).isPresent()); - assertFalse(cnec.getUpperBound(RIGHT, AMPERE).isPresent()); - assertFalse(cnec.getLowerBound(RIGHT, MEGAWATT).isPresent()); - assertFalse(cnec.getLowerBound(RIGHT, AMPERE).isPresent()); + // bounds on TWO side + assertFalse(cnec.getUpperBound(TWO, MEGAWATT).isPresent()); + assertFalse(cnec.getUpperBound(TWO, AMPERE).isPresent()); + assertFalse(cnec.getLowerBound(TWO, MEGAWATT).isPresent()); + assertFalse(cnec.getLowerBound(TWO, AMPERE).isPresent()); // margin - assertEquals(750., cnec.computeMargin(300, LEFT, AMPERE), DOUBLE_TOLERANCE); // bound: -450 A - assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(300, RIGHT, AMPERE), DOUBLE_TOLERANCE); // bound: -450 A - assertEquals(596., cnec.computeMargin(300, LEFT, MEGAWATT), DOUBLE_TOLERANCE); // bound: -296 MW - assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(-300, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); // bound: -296 MW + assertEquals(750., cnec.computeMargin(300, ONE, AMPERE), DOUBLE_TOLERANCE); // bound: -450 A + assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(300, TWO, AMPERE), DOUBLE_TOLERANCE); // bound: -450 A + assertEquals(596., cnec.computeMargin(300, ONE, MEGAWATT), DOUBLE_TOLERANCE); // bound: -296 MW + assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(-300, TWO, MEGAWATT), DOUBLE_TOLERANCE); // bound: -296 MW } @Test void testBranchWithOneMaxThresholdOnRightInAmpere() { - FlowCnec cnec = initPreventiveCnecAdder().withNominalVoltage(220.).newThreshold().withUnit(AMPERE).withMax(110.).withSide(Side.RIGHT).add().add(); + FlowCnec cnec = initPreventiveCnecAdder().withNominalVoltage(220.).newThreshold().withUnit(AMPERE).withMax(110.).withSide(TwoSides.TWO).add().add(); - // bounds on LEFT side - assertFalse(cnec.getUpperBound(LEFT, MEGAWATT).isPresent()); - assertFalse(cnec.getUpperBound(LEFT, AMPERE).isPresent()); - assertFalse(cnec.getLowerBound(LEFT, MEGAWATT).isPresent()); - assertFalse(cnec.getLowerBound(LEFT, AMPERE).isPresent()); + // bounds on ONE side + assertFalse(cnec.getUpperBound(ONE, MEGAWATT).isPresent()); + assertFalse(cnec.getUpperBound(ONE, AMPERE).isPresent()); + assertFalse(cnec.getLowerBound(ONE, MEGAWATT).isPresent()); + assertFalse(cnec.getLowerBound(ONE, AMPERE).isPresent()); - // bounds on RIGHT side - assertEquals(110., cnec.getUpperBound(RIGHT, AMPERE).orElseThrow(), DOUBLE_TOLERANCE); - assertEquals(110. * (0.22 * Math.sqrt(3)), cnec.getUpperBound(RIGHT, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); // 42 MW - assertFalse(cnec.getLowerBound(RIGHT, MEGAWATT).isPresent()); - assertFalse(cnec.getLowerBound(RIGHT, AMPERE).isPresent()); + // bounds on TWO side + assertEquals(110., cnec.getUpperBound(TWO, AMPERE).orElseThrow(), DOUBLE_TOLERANCE); + assertEquals(110. * (0.22 * Math.sqrt(3)), cnec.getUpperBound(TWO, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); // 42 MW + assertFalse(cnec.getLowerBound(TWO, MEGAWATT).isPresent()); + assertFalse(cnec.getLowerBound(TWO, AMPERE).isPresent()); // margin - assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(300, LEFT, AMPERE), DOUBLE_TOLERANCE); // bound: 110 A - assertEquals(-190., cnec.computeMargin(300, RIGHT, AMPERE), DOUBLE_TOLERANCE); // bound: 110 A - assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(300, LEFT, MEGAWATT), DOUBLE_TOLERANCE); // bound: 42 MW - assertEquals(342., cnec.computeMargin(-300, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); // bound: 42 MW + assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(300, ONE, AMPERE), DOUBLE_TOLERANCE); // bound: 110 A + assertEquals(-190., cnec.computeMargin(300, TWO, AMPERE), DOUBLE_TOLERANCE); // bound: 110 A + assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(300, ONE, MEGAWATT), DOUBLE_TOLERANCE); // bound: 42 MW + assertEquals(342., cnec.computeMargin(-300, TWO, MEGAWATT), DOUBLE_TOLERANCE); // bound: 42 MW } @Test void testBranchWithOneMaxThresholdOnLeftInPercentImax() { - FlowCnec cnec = initPreventiveCnecAdder().withNominalVoltage(380.).withIMax(1000.).newThreshold().withUnit(PERCENT_IMAX).withMax(1.1).withSide(Side.LEFT).add() // 1.1 = 110 % + FlowCnec cnec = initPreventiveCnecAdder().withNominalVoltage(380.).withIMax(1000.).newThreshold().withUnit(PERCENT_IMAX).withMax(1.1).withSide(TwoSides.ONE).add() // 1.1 = 110 % .add(); - // bounds on LEFT side - assertEquals(1100., cnec.getUpperBound(LEFT, AMPERE).orElseThrow(), DOUBLE_TOLERANCE); // 1100 A - assertEquals(1100. * (0.38 * Math.sqrt(3)), cnec.getUpperBound(LEFT, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); // 724 MW - assertFalse(cnec.getLowerBound(LEFT, MEGAWATT).isPresent()); - assertFalse(cnec.getLowerBound(LEFT, AMPERE).isPresent()); + // bounds on ONE side + assertEquals(1100., cnec.getUpperBound(ONE, AMPERE).orElseThrow(), DOUBLE_TOLERANCE); // 1100 A + assertEquals(1100. * (0.38 * Math.sqrt(3)), cnec.getUpperBound(ONE, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); // 724 MW + assertFalse(cnec.getLowerBound(ONE, MEGAWATT).isPresent()); + assertFalse(cnec.getLowerBound(ONE, AMPERE).isPresent()); - // bounds on RIGHT side - assertFalse(cnec.getUpperBound(RIGHT, MEGAWATT).isPresent()); - assertFalse(cnec.getUpperBound(RIGHT, AMPERE).isPresent()); - assertFalse(cnec.getLowerBound(RIGHT, MEGAWATT).isPresent()); - assertFalse(cnec.getLowerBound(RIGHT, AMPERE).isPresent()); + // bounds on TWO side + assertFalse(cnec.getUpperBound(TWO, MEGAWATT).isPresent()); + assertFalse(cnec.getUpperBound(TWO, AMPERE).isPresent()); + assertFalse(cnec.getLowerBound(TWO, MEGAWATT).isPresent()); + assertFalse(cnec.getLowerBound(TWO, AMPERE).isPresent()); // margin - assertEquals(-100, cnec.computeMargin(1200, LEFT, AMPERE), DOUBLE_TOLERANCE); // bound: 1100 A - assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(1200, RIGHT, AMPERE), DOUBLE_TOLERANCE); // bound: 1100 A - assertEquals(-26., cnec.computeMargin(750, LEFT, MEGAWATT), DOUBLE_TOLERANCE); // bound: 724 MW - assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(100, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); // bound: 724 MW + assertEquals(-100, cnec.computeMargin(1200, ONE, AMPERE), DOUBLE_TOLERANCE); // bound: 1100 A + assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(1200, TWO, AMPERE), DOUBLE_TOLERANCE); // bound: 1100 A + assertEquals(-26., cnec.computeMargin(750, ONE, MEGAWATT), DOUBLE_TOLERANCE); // bound: 724 MW + assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(100, TWO, MEGAWATT), DOUBLE_TOLERANCE); // bound: 724 MW } @Test void testBranchWithOneMinThresholdOnRightInPercentImax() { - FlowCnec cnec = initPreventiveCnecAdder().withNominalVoltage(220.).withIMax(1000., RIGHT).withIMax(0., LEFT) // should not be considered as the threshold is on the right side - .newThreshold().withUnit(PERCENT_IMAX).withMin(-0.9).withSide(Side.RIGHT).add() // 0.9 = 90 % + FlowCnec cnec = initPreventiveCnecAdder().withNominalVoltage(220.).withIMax(1000., TWO).withIMax(0., ONE) // should not be considered as the threshold is on the right side + .newThreshold().withUnit(PERCENT_IMAX).withMin(-0.9).withSide(TwoSides.TWO).add() // 0.9 = 90 % .add(); - assertEquals(Set.of(RIGHT), cnec.getMonitoredSides()); + assertEquals(Set.of(TWO), cnec.getMonitoredSides()); - // bounds on LEFT side - assertFalse(cnec.getUpperBound(LEFT, MEGAWATT).isPresent()); - assertFalse(cnec.getUpperBound(LEFT, AMPERE).isPresent()); - assertFalse(cnec.getLowerBound(LEFT, MEGAWATT).isPresent()); - assertFalse(cnec.getLowerBound(LEFT, AMPERE).isPresent()); + // bounds on ONE side + assertFalse(cnec.getUpperBound(ONE, MEGAWATT).isPresent()); + assertFalse(cnec.getUpperBound(ONE, AMPERE).isPresent()); + assertFalse(cnec.getLowerBound(ONE, MEGAWATT).isPresent()); + assertFalse(cnec.getLowerBound(ONE, AMPERE).isPresent()); - // bounds on RIGHT side - assertFalse(cnec.getUpperBound(RIGHT, MEGAWATT).isPresent()); - assertFalse(cnec.getUpperBound(RIGHT, AMPERE).isPresent()); - assertEquals(-900., cnec.getLowerBound(RIGHT, AMPERE).orElseThrow(), DOUBLE_TOLERANCE); // -900 A - assertEquals(-900. * (0.22 * Math.sqrt(3)), cnec.getLowerBound(RIGHT, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); // -343 MW + // bounds on TWO side + assertFalse(cnec.getUpperBound(TWO, MEGAWATT).isPresent()); + assertFalse(cnec.getUpperBound(TWO, AMPERE).isPresent()); + assertEquals(-900., cnec.getLowerBound(TWO, AMPERE).orElseThrow(), DOUBLE_TOLERANCE); // -900 A + assertEquals(-900. * (0.22 * Math.sqrt(3)), cnec.getLowerBound(TWO, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); // -343 MW // margin - assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(1200, LEFT, AMPERE), DOUBLE_TOLERANCE); // bound: -900 A - assertEquals(2100., cnec.computeMargin(1200, RIGHT, AMPERE), DOUBLE_TOLERANCE); // bound: -900 A - assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(-500, LEFT, MEGAWATT), DOUBLE_TOLERANCE); // bound: -343 MW - assertEquals(443., cnec.computeMargin(100, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); // bound: -343 MW + assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(1200, ONE, AMPERE), DOUBLE_TOLERANCE); // bound: -900 A + assertEquals(2100., cnec.computeMargin(1200, TWO, AMPERE), DOUBLE_TOLERANCE); // bound: -900 A + assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(-500, ONE, MEGAWATT), DOUBLE_TOLERANCE); // bound: -343 MW + assertEquals(443., cnec.computeMargin(100, TWO, MEGAWATT), DOUBLE_TOLERANCE); // bound: -343 MW } // test threshold on transformer whose nominal voltage is NOT the same on both side @@ -231,146 +231,146 @@ void testBranchWithOneMinThresholdOnRightInPercentImax() { @Test void testTransformerWithOneMaxThresholdOnLeftInMW() { - FlowCnec cnec = initPreventiveCnecAdder().withNominalVoltage(220., LEFT).withNominalVoltage(380., RIGHT).newThreshold().withUnit(MEGAWATT).withMax(500.).withSide(Side.LEFT).add().add(); + FlowCnec cnec = initPreventiveCnecAdder().withNominalVoltage(220., ONE).withNominalVoltage(380., TWO).newThreshold().withUnit(MEGAWATT).withMax(500.).withSide(TwoSides.ONE).add().add(); - // bounds on LEFT side - assertEquals(500., cnec.getUpperBound(LEFT, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); - assertEquals(500. / (0.22 * Math.sqrt(3)), cnec.getUpperBound(LEFT, AMPERE).orElseThrow(), DOUBLE_TOLERANCE); // 1312 A - assertFalse(cnec.getLowerBound(LEFT, MEGAWATT).isPresent()); - assertFalse(cnec.getLowerBound(LEFT, AMPERE).isPresent()); + // bounds on ONE side + assertEquals(500., cnec.getUpperBound(ONE, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); + assertEquals(500. / (0.22 * Math.sqrt(3)), cnec.getUpperBound(ONE, AMPERE).orElseThrow(), DOUBLE_TOLERANCE); // 1312 A + assertFalse(cnec.getLowerBound(ONE, MEGAWATT).isPresent()); + assertFalse(cnec.getLowerBound(ONE, AMPERE).isPresent()); - // bounds on RIGHT side - assertFalse(cnec.getUpperBound(RIGHT, MEGAWATT).isPresent()); - assertFalse(cnec.getUpperBound(RIGHT, AMPERE).isPresent()); - assertFalse(cnec.getLowerBound(RIGHT, MEGAWATT).isPresent()); - assertFalse(cnec.getLowerBound(RIGHT, AMPERE).isPresent()); + // bounds on TWO side + assertFalse(cnec.getUpperBound(TWO, MEGAWATT).isPresent()); + assertFalse(cnec.getUpperBound(TWO, AMPERE).isPresent()); + assertFalse(cnec.getLowerBound(TWO, MEGAWATT).isPresent()); + assertFalse(cnec.getLowerBound(TWO, AMPERE).isPresent()); // margins - assertEquals(400., cnec.computeMargin(100, LEFT, MEGAWATT), DOUBLE_TOLERANCE); // bound: 500 MW - assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(1000, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); // bound: 500 MW - assertEquals(1512., cnec.computeMargin(-200, LEFT, AMPERE), DOUBLE_TOLERANCE); // bound: 1312 A - assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(2000, RIGHT, AMPERE), DOUBLE_TOLERANCE); // bound: 759 A + assertEquals(400., cnec.computeMargin(100, ONE, MEGAWATT), DOUBLE_TOLERANCE); // bound: 500 MW + assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(1000, TWO, MEGAWATT), DOUBLE_TOLERANCE); // bound: 500 MW + assertEquals(1512., cnec.computeMargin(-200, ONE, AMPERE), DOUBLE_TOLERANCE); // bound: 1312 A + assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(2000, TWO, AMPERE), DOUBLE_TOLERANCE); // bound: 759 A } @Test void testTransformerWithOneMinThresholdOnRightInMW() { - FlowCnec cnec = initPreventiveCnecAdder().withNominalVoltage(220., LEFT).withNominalVoltage(380., RIGHT).newThreshold().withUnit(MEGAWATT).withMin(-600.).withSide(Side.RIGHT).add().add(); + FlowCnec cnec = initPreventiveCnecAdder().withNominalVoltage(220., ONE).withNominalVoltage(380., TWO).newThreshold().withUnit(MEGAWATT).withMin(-600.).withSide(TwoSides.TWO).add().add(); - // bounds on LEFT side - assertFalse(cnec.getUpperBound(LEFT, MEGAWATT).isPresent()); - assertFalse(cnec.getUpperBound(LEFT, AMPERE).isPresent()); - assertFalse(cnec.getLowerBound(LEFT, MEGAWATT).isPresent()); - assertFalse(cnec.getLowerBound(LEFT, AMPERE).isPresent()); + // bounds on ONE side + assertFalse(cnec.getUpperBound(ONE, MEGAWATT).isPresent()); + assertFalse(cnec.getUpperBound(ONE, AMPERE).isPresent()); + assertFalse(cnec.getLowerBound(ONE, MEGAWATT).isPresent()); + assertFalse(cnec.getLowerBound(ONE, AMPERE).isPresent()); - // bounds on RIGHT side - assertFalse(cnec.getUpperBound(RIGHT, MEGAWATT).isPresent()); - assertFalse(cnec.getUpperBound(RIGHT, AMPERE).isPresent()); - assertEquals(-600., cnec.getLowerBound(RIGHT, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); - assertEquals(-600. / (0.38 * Math.sqrt(3)), cnec.getLowerBound(RIGHT, AMPERE).orElseThrow(), DOUBLE_TOLERANCE); // - 912 A + // bounds on TWO side + assertFalse(cnec.getUpperBound(TWO, MEGAWATT).isPresent()); + assertFalse(cnec.getUpperBound(TWO, AMPERE).isPresent()); + assertEquals(-600., cnec.getLowerBound(TWO, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); + assertEquals(-600. / (0.38 * Math.sqrt(3)), cnec.getLowerBound(TWO, AMPERE).orElseThrow(), DOUBLE_TOLERANCE); // - 912 A // margin - assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(500, LEFT, MEGAWATT), DOUBLE_TOLERANCE); // bound: -600 MW - assertEquals(-400., cnec.computeMargin(-1000, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); // bound: -600 MW - assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(-500, LEFT, AMPERE), DOUBLE_TOLERANCE); // bound: -1575 A - assertEquals(1012., cnec.computeMargin(100, RIGHT, AMPERE), DOUBLE_TOLERANCE); // bound: -912 A + assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(500, ONE, MEGAWATT), DOUBLE_TOLERANCE); // bound: -600 MW + assertEquals(-400., cnec.computeMargin(-1000, TWO, MEGAWATT), DOUBLE_TOLERANCE); // bound: -600 MW + assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(-500, ONE, AMPERE), DOUBLE_TOLERANCE); // bound: -1575 A + assertEquals(1012., cnec.computeMargin(100, TWO, AMPERE), DOUBLE_TOLERANCE); // bound: -912 A } @Test void testTransformerWithOneMinThresholdOnLeftInA() { - FlowCnec cnec = initPreventiveCnecAdder().withNominalVoltage(220., LEFT).withNominalVoltage(380., RIGHT).newThreshold().withUnit(AMPERE).withMin(-1000.).withSide(Side.LEFT).add().add(); + FlowCnec cnec = initPreventiveCnecAdder().withNominalVoltage(220., ONE).withNominalVoltage(380., TWO).newThreshold().withUnit(AMPERE).withMin(-1000.).withSide(TwoSides.ONE).add().add(); - // bounds on LEFT side - assertFalse(cnec.getUpperBound(LEFT, MEGAWATT).isPresent()); - assertFalse(cnec.getUpperBound(LEFT, AMPERE).isPresent()); - assertEquals(-1000., cnec.getLowerBound(LEFT, AMPERE).orElseThrow(), DOUBLE_TOLERANCE); - assertEquals(-1000. * (0.22 * Math.sqrt(3)), cnec.getLowerBound(LEFT, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); // - 381 MW + // bounds on ONE side + assertFalse(cnec.getUpperBound(ONE, MEGAWATT).isPresent()); + assertFalse(cnec.getUpperBound(ONE, AMPERE).isPresent()); + assertEquals(-1000., cnec.getLowerBound(ONE, AMPERE).orElseThrow(), DOUBLE_TOLERANCE); + assertEquals(-1000. * (0.22 * Math.sqrt(3)), cnec.getLowerBound(ONE, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); // - 381 MW - // bounds on RIGHT side - assertFalse(cnec.getUpperBound(RIGHT, MEGAWATT).isPresent()); - assertFalse(cnec.getUpperBound(RIGHT, AMPERE).isPresent()); - assertFalse(cnec.getLowerBound(RIGHT, MEGAWATT).isPresent()); - assertFalse(cnec.getLowerBound(RIGHT, AMPERE).isPresent()); + // bounds on TWO side + assertFalse(cnec.getUpperBound(TWO, MEGAWATT).isPresent()); + assertFalse(cnec.getUpperBound(TWO, AMPERE).isPresent()); + assertFalse(cnec.getLowerBound(TWO, MEGAWATT).isPresent()); + assertFalse(cnec.getLowerBound(TWO, AMPERE).isPresent()); // margin - assertEquals(1300., cnec.computeMargin(300, LEFT, AMPERE), DOUBLE_TOLERANCE); // bound: -1000 A - assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(-800, RIGHT, AMPERE), DOUBLE_TOLERANCE); // bound: -579 A - assertEquals(-319., cnec.computeMargin(-700, LEFT, MEGAWATT), DOUBLE_TOLERANCE); // bound: -381 MW - assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(1000, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); // bound: -381 MW + assertEquals(1300., cnec.computeMargin(300, ONE, AMPERE), DOUBLE_TOLERANCE); // bound: -1000 A + assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(-800, TWO, AMPERE), DOUBLE_TOLERANCE); // bound: -579 A + assertEquals(-319., cnec.computeMargin(-700, ONE, MEGAWATT), DOUBLE_TOLERANCE); // bound: -381 MW + assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(1000, TWO, MEGAWATT), DOUBLE_TOLERANCE); // bound: -381 MW } @Test void testTransformerWithOneMaxThresholdOnRightInA() { - FlowCnec cnec = initPreventiveCnecAdder().withNominalVoltage(220., LEFT).withNominalVoltage(380., RIGHT).newThreshold().withUnit(AMPERE).withMax(500.).withSide(Side.RIGHT).add().add(); + FlowCnec cnec = initPreventiveCnecAdder().withNominalVoltage(220., ONE).withNominalVoltage(380., TWO).newThreshold().withUnit(AMPERE).withMax(500.).withSide(TwoSides.TWO).add().add(); - // bounds on LEFT side - assertFalse(cnec.getUpperBound(LEFT, MEGAWATT).isPresent()); - assertFalse(cnec.getUpperBound(LEFT, AMPERE).isPresent()); - assertFalse(cnec.getLowerBound(LEFT, MEGAWATT).isPresent()); - assertFalse(cnec.getLowerBound(LEFT, AMPERE).isPresent()); + // bounds on ONE side + assertFalse(cnec.getUpperBound(ONE, MEGAWATT).isPresent()); + assertFalse(cnec.getUpperBound(ONE, AMPERE).isPresent()); + assertFalse(cnec.getLowerBound(ONE, MEGAWATT).isPresent()); + assertFalse(cnec.getLowerBound(ONE, AMPERE).isPresent()); - // bounds on RIGHT side - assertEquals(500., cnec.getUpperBound(RIGHT, AMPERE).orElseThrow(), DOUBLE_TOLERANCE); // 500 A - assertEquals(500. * (0.38 * Math.sqrt(3)), cnec.getUpperBound(RIGHT, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); // 329 MW - assertFalse(cnec.getLowerBound(RIGHT, MEGAWATT).isPresent()); - assertFalse(cnec.getLowerBound(RIGHT, AMPERE).isPresent()); + // bounds on TWO side + assertEquals(500., cnec.getUpperBound(TWO, AMPERE).orElseThrow(), DOUBLE_TOLERANCE); // 500 A + assertEquals(500. * (0.38 * Math.sqrt(3)), cnec.getUpperBound(TWO, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); // 329 MW + assertFalse(cnec.getLowerBound(TWO, MEGAWATT).isPresent()); + assertFalse(cnec.getLowerBound(TWO, AMPERE).isPresent()); // margin - assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(800, LEFT, AMPERE), DOUBLE_TOLERANCE); // bound: 864 A - assertEquals(-100., cnec.computeMargin(600, RIGHT, AMPERE), DOUBLE_TOLERANCE); // bound: 500 A - assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(300, LEFT, MEGAWATT), DOUBLE_TOLERANCE); // bound: 329 MW - assertEquals(-71., cnec.computeMargin(400, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); // bound: 329 MW + assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(800, ONE, AMPERE), DOUBLE_TOLERANCE); // bound: 864 A + assertEquals(-100., cnec.computeMargin(600, TWO, AMPERE), DOUBLE_TOLERANCE); // bound: 500 A + assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(300, ONE, MEGAWATT), DOUBLE_TOLERANCE); // bound: 329 MW + assertEquals(-71., cnec.computeMargin(400, TWO, MEGAWATT), DOUBLE_TOLERANCE); // bound: 329 MW } @Test void testTransformerWithOneMinThresholdOnLeftInPercentImax() { - FlowCnec cnec = initPreventiveCnecAdder().withNominalVoltage(220., LEFT).withNominalVoltage(380., RIGHT).withIMax(2000.).newThreshold().withUnit(PERCENT_IMAX).withMin(-1.).withSide(Side.LEFT).add().add(); + FlowCnec cnec = initPreventiveCnecAdder().withNominalVoltage(220., ONE).withNominalVoltage(380., TWO).withIMax(2000.).newThreshold().withUnit(PERCENT_IMAX).withMin(-1.).withSide(TwoSides.ONE).add().add(); - // bounds on LEFT side - assertFalse(cnec.getUpperBound(LEFT, MEGAWATT).isPresent()); - assertFalse(cnec.getUpperBound(LEFT, AMPERE).isPresent()); - assertEquals(-2000., cnec.getLowerBound(LEFT, AMPERE).orElseThrow(), DOUBLE_TOLERANCE); - assertEquals(-2000. * (0.22 * Math.sqrt(3)), cnec.getLowerBound(LEFT, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); // - 762 MW + // bounds on ONE side + assertFalse(cnec.getUpperBound(ONE, MEGAWATT).isPresent()); + assertFalse(cnec.getUpperBound(ONE, AMPERE).isPresent()); + assertEquals(-2000., cnec.getLowerBound(ONE, AMPERE).orElseThrow(), DOUBLE_TOLERANCE); + assertEquals(-2000. * (0.22 * Math.sqrt(3)), cnec.getLowerBound(ONE, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); // - 762 MW - // bounds on RIGHT side - assertFalse(cnec.getUpperBound(RIGHT, MEGAWATT).isPresent()); - assertFalse(cnec.getUpperBound(RIGHT, AMPERE).isPresent()); - assertFalse(cnec.getLowerBound(RIGHT, MEGAWATT).isPresent()); - assertFalse(cnec.getLowerBound(RIGHT, AMPERE).isPresent()); + // bounds on TWO side + assertFalse(cnec.getUpperBound(TWO, MEGAWATT).isPresent()); + assertFalse(cnec.getUpperBound(TWO, AMPERE).isPresent()); + assertFalse(cnec.getLowerBound(TWO, MEGAWATT).isPresent()); + assertFalse(cnec.getLowerBound(TWO, AMPERE).isPresent()); // margin - assertEquals(2300., cnec.computeMargin(300, LEFT, AMPERE), DOUBLE_TOLERANCE); // bound: -2000 A - assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(-800, RIGHT, AMPERE), DOUBLE_TOLERANCE); // bound: -1158 A - assertEquals(62., cnec.computeMargin(-700, LEFT, MEGAWATT), DOUBLE_TOLERANCE); // bound: -762 MW - assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(-1000, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); // bound: -762 MW + assertEquals(2300., cnec.computeMargin(300, ONE, AMPERE), DOUBLE_TOLERANCE); // bound: -2000 A + assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(-800, TWO, AMPERE), DOUBLE_TOLERANCE); // bound: -1158 A + assertEquals(62., cnec.computeMargin(-700, ONE, MEGAWATT), DOUBLE_TOLERANCE); // bound: -762 MW + assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(-1000, TWO, MEGAWATT), DOUBLE_TOLERANCE); // bound: -762 MW } @Test void testTransformerWithOneMaxThresholdOnRightInPercentImax() { - FlowCnec cnec = initPreventiveCnecAdder().withNominalVoltage(220., LEFT).withNominalVoltage(380., RIGHT).withIMax(0., LEFT) // shouldn't be used as threshold is defined on right side - .withIMax(2000., RIGHT).newThreshold().withUnit(PERCENT_IMAX).withMax(0.25).withSide(Side.RIGHT).add().add(); + FlowCnec cnec = initPreventiveCnecAdder().withNominalVoltage(220., ONE).withNominalVoltage(380., TWO).withIMax(0., ONE) // shouldn't be used as threshold is defined on right side + .withIMax(2000., TWO).newThreshold().withUnit(PERCENT_IMAX).withMax(0.25).withSide(TwoSides.TWO).add().add(); - // bounds on LEFT side - assertFalse(cnec.getUpperBound(LEFT, MEGAWATT).isPresent()); - assertFalse(cnec.getUpperBound(LEFT, AMPERE).isPresent()); - assertFalse(cnec.getLowerBound(LEFT, MEGAWATT).isPresent()); - assertFalse(cnec.getLowerBound(LEFT, AMPERE).isPresent()); + // bounds on ONE side + assertFalse(cnec.getUpperBound(ONE, MEGAWATT).isPresent()); + assertFalse(cnec.getUpperBound(ONE, AMPERE).isPresent()); + assertFalse(cnec.getLowerBound(ONE, MEGAWATT).isPresent()); + assertFalse(cnec.getLowerBound(ONE, AMPERE).isPresent()); - // bounds on RIGHT side - assertEquals(500., cnec.getUpperBound(RIGHT, AMPERE).orElseThrow(), DOUBLE_TOLERANCE); // 500 A - assertEquals(500. * (0.38 * Math.sqrt(3)), cnec.getUpperBound(RIGHT, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); // 329 MW - assertFalse(cnec.getLowerBound(RIGHT, MEGAWATT).isPresent()); - assertFalse(cnec.getLowerBound(RIGHT, AMPERE).isPresent()); + // bounds on TWO side + assertEquals(500., cnec.getUpperBound(TWO, AMPERE).orElseThrow(), DOUBLE_TOLERANCE); // 500 A + assertEquals(500. * (0.38 * Math.sqrt(3)), cnec.getUpperBound(TWO, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); // 329 MW + assertFalse(cnec.getLowerBound(TWO, MEGAWATT).isPresent()); + assertFalse(cnec.getLowerBound(TWO, AMPERE).isPresent()); // margin - assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(800, LEFT, AMPERE), DOUBLE_TOLERANCE); // bound: 864 A - assertEquals(-100., cnec.computeMargin(600, RIGHT, AMPERE), DOUBLE_TOLERANCE); // bound: 500 A - assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(300, LEFT, MEGAWATT), DOUBLE_TOLERANCE); // bound: 329 MW - assertEquals(-71., cnec.computeMargin(400, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); // bound: 329 MW + assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(800, ONE, AMPERE), DOUBLE_TOLERANCE); // bound: 864 A + assertEquals(-100., cnec.computeMargin(600, TWO, AMPERE), DOUBLE_TOLERANCE); // bound: 500 A + assertEquals(Double.POSITIVE_INFINITY, cnec.computeMargin(300, ONE, MEGAWATT), DOUBLE_TOLERANCE); // bound: 329 MW + assertEquals(-71., cnec.computeMargin(400, TWO, MEGAWATT), DOUBLE_TOLERANCE); // bound: 329 MW } // Tests on concurrency between thresholds @@ -378,78 +378,78 @@ void testTransformerWithOneMaxThresholdOnRightInPercentImax() { @Test void testBranchWithSeveralThresholdsWithLimitingOnLeftOrRightSide() { - FlowCnec cnec = initPreventiveCnecAdder().newThreshold().withUnit(MEGAWATT).withMax(100.).withSide(Side.LEFT).add().newThreshold().withUnit(MEGAWATT).withMin(-200.).withSide(Side.LEFT).add().newThreshold().withUnit(MEGAWATT).withMax(500.).withSide(Side.RIGHT).add().newThreshold().withUnit(MEGAWATT).withMin(-300.).withSide(Side.RIGHT).add().add(); + FlowCnec cnec = initPreventiveCnecAdder().newThreshold().withUnit(MEGAWATT).withMax(100.).withSide(TwoSides.ONE).add().newThreshold().withUnit(MEGAWATT).withMin(-200.).withSide(TwoSides.ONE).add().newThreshold().withUnit(MEGAWATT).withMax(500.).withSide(TwoSides.TWO).add().newThreshold().withUnit(MEGAWATT).withMin(-300.).withSide(TwoSides.TWO).add().add(); - assertEquals(100., cnec.getUpperBound(LEFT, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); - assertEquals(-200., cnec.getLowerBound(LEFT, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); - assertEquals(-200., cnec.computeMargin(300, LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(0., cnec.computeMargin(-200, LEFT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(100., cnec.getUpperBound(ONE, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); + assertEquals(-200., cnec.getLowerBound(ONE, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); + assertEquals(-200., cnec.computeMargin(300, ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(0., cnec.computeMargin(-200, ONE, MEGAWATT), DOUBLE_TOLERANCE); } @Test void testBranchWithSeveralThresholdsWithBoth() { - FlowCnec cnec = initPreventiveCnecAdder().newThreshold().withUnit(MEGAWATT).withMax(100.).withSide(Side.LEFT).add().newThreshold().withUnit(MEGAWATT).withMin(-200.).withSide(Side.LEFT).add().newThreshold().withUnit(MEGAWATT).withMax(500.).withSide(Side.RIGHT).add().newThreshold().withUnit(MEGAWATT).withMin(-300.).withSide(Side.RIGHT).add().newThreshold().withUnit(MEGAWATT).withMin(-50.).withMax(150.).withSide(Side.RIGHT).add().add(); + FlowCnec cnec = initPreventiveCnecAdder().newThreshold().withUnit(MEGAWATT).withMax(100.).withSide(TwoSides.ONE).add().newThreshold().withUnit(MEGAWATT).withMin(-200.).withSide(TwoSides.ONE).add().newThreshold().withUnit(MEGAWATT).withMax(500.).withSide(TwoSides.TWO).add().newThreshold().withUnit(MEGAWATT).withMin(-300.).withSide(TwoSides.TWO).add().newThreshold().withUnit(MEGAWATT).withMin(-50.).withMax(150.).withSide(TwoSides.TWO).add().add(); - assertEquals(100., cnec.getUpperBound(LEFT, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); - assertEquals(-200., cnec.getLowerBound(LEFT, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); - assertEquals(-200., cnec.computeMargin(300, LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(0., cnec.computeMargin(-200, LEFT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(100., cnec.getUpperBound(ONE, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); + assertEquals(-200., cnec.getLowerBound(ONE, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); + assertEquals(-200., cnec.computeMargin(300, ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(0., cnec.computeMargin(-200, ONE, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(150., cnec.getUpperBound(RIGHT, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); - assertEquals(-50., cnec.getLowerBound(RIGHT, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); - assertEquals(-150, cnec.computeMargin(300, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(-150., cnec.computeMargin(-200, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(150., cnec.getUpperBound(TWO, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); + assertEquals(-50., cnec.getLowerBound(TWO, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); + assertEquals(-150, cnec.computeMargin(300, TWO, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(-150., cnec.computeMargin(-200, TWO, MEGAWATT), DOUBLE_TOLERANCE); } @Test void testComputeMarginOnTransformerWithSeveralThresholdsInAmps() { - FlowCnec cnec = initPreventiveCnecAdder().withNominalVoltage(220., LEFT).withNominalVoltage(380., RIGHT).newThreshold().withUnit(AMPERE).withMax(100.).withSide(Side.LEFT).add().newThreshold().withUnit(AMPERE).withMin(-70.).withSide(Side.LEFT).add().newThreshold().withUnit(AMPERE).withMin(-50.).withMax(50.).withSide(Side.RIGHT).add().add(); + FlowCnec cnec = initPreventiveCnecAdder().withNominalVoltage(220., ONE).withNominalVoltage(380., TWO).newThreshold().withUnit(AMPERE).withMax(100.).withSide(TwoSides.ONE).add().newThreshold().withUnit(AMPERE).withMin(-70.).withSide(TwoSides.ONE).add().newThreshold().withUnit(AMPERE).withMin(-50.).withMax(50.).withSide(TwoSides.TWO).add().add(); - assertEquals(100, cnec.getUpperBound(LEFT, AMPERE).orElseThrow(), DOUBLE_TOLERANCE); - assertEquals(-70, cnec.getLowerBound(LEFT, AMPERE).orElseThrow(), DOUBLE_TOLERANCE); - assertEquals(0., cnec.computeMargin(100, LEFT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(-30, cnec.computeMargin(-100, LEFT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(100, cnec.getUpperBound(ONE, AMPERE).orElseThrow(), DOUBLE_TOLERANCE); + assertEquals(-70, cnec.getLowerBound(ONE, AMPERE).orElseThrow(), DOUBLE_TOLERANCE); + assertEquals(0., cnec.computeMargin(100, ONE, AMPERE), DOUBLE_TOLERANCE); + assertEquals(-30, cnec.computeMargin(-100, ONE, AMPERE), DOUBLE_TOLERANCE); } @Test void unboundedCnecInOppositeDirection() { - FlowCnec cnec = initPreventiveCnecAdder().newThreshold().withUnit(MEGAWATT).withMax(500.).withSide(Side.LEFT).add().newThreshold().withUnit(MEGAWATT).withMax(200.).withSide(Side.LEFT).add().add(); + FlowCnec cnec = initPreventiveCnecAdder().newThreshold().withUnit(MEGAWATT).withMax(500.).withSide(TwoSides.ONE).add().newThreshold().withUnit(MEGAWATT).withMax(200.).withSide(TwoSides.ONE).add().add(); - assertEquals(200, cnec.getUpperBound(LEFT, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); - assertEquals(200, cnec.computeMargin(0., LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertFalse(cnec.getLowerBound(LEFT, MEGAWATT).isPresent()); + assertEquals(200, cnec.getUpperBound(ONE, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); + assertEquals(200, cnec.computeMargin(0., ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertFalse(cnec.getLowerBound(ONE, MEGAWATT).isPresent()); } @Test void unboundedCnecInDirectDirection() { - FlowCnec cnec = initPreventiveCnecAdder().newThreshold().withUnit(MEGAWATT).withMin(-500.).withSide(Side.LEFT).add().newThreshold().withUnit(MEGAWATT).withMin(-200.).withSide(Side.LEFT).add().add(); + FlowCnec cnec = initPreventiveCnecAdder().newThreshold().withUnit(MEGAWATT).withMin(-500.).withSide(TwoSides.ONE).add().newThreshold().withUnit(MEGAWATT).withMin(-200.).withSide(TwoSides.ONE).add().add(); - assertEquals(-200, cnec.getLowerBound(LEFT, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); - assertEquals(200, cnec.computeMargin(0., LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertFalse(cnec.getUpperBound(LEFT, MEGAWATT).isPresent()); + assertEquals(-200, cnec.getLowerBound(ONE, MEGAWATT).orElseThrow(), DOUBLE_TOLERANCE); + assertEquals(200, cnec.computeMargin(0., ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertFalse(cnec.getUpperBound(ONE, MEGAWATT).isPresent()); } @Test void marginsWithNegativeAndPositiveLimits() { - FlowCnec cnec = initPreventiveCnecAdder().newThreshold().withUnit(MEGAWATT).withMin(-200.).withMax(500.).withSide(Side.LEFT).add().add(); + FlowCnec cnec = initPreventiveCnecAdder().newThreshold().withUnit(MEGAWATT).withMin(-200.).withMax(500.).withSide(TwoSides.ONE).add().add(); - assertEquals(-100, cnec.computeMargin(-300, LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(200, cnec.computeMargin(0, LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(100, cnec.computeMargin(400, LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(-300, cnec.computeMargin(800, LEFT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(-100, cnec.computeMargin(-300, ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(200, cnec.computeMargin(0, ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(100, cnec.computeMargin(400, ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(-300, cnec.computeMargin(800, ONE, MEGAWATT), DOUBLE_TOLERANCE); } // other @Test void testEqualsAndHashCode() { - FlowCnec cnec1 = initPreventiveCnecAdder().newThreshold().withUnit(MEGAWATT).withMax(1000.).withSide(Side.LEFT).add().add(); - FlowCnec cnec2 = initPreventiveCnecAdder().withId("anotherId").newThreshold().withUnit(AMPERE).withMin(-1000.).withSide(Side.LEFT).add().withNominalVoltage(220.).add(); + FlowCnec cnec1 = initPreventiveCnecAdder().newThreshold().withUnit(MEGAWATT).withMax(1000.).withSide(TwoSides.ONE).add().add(); + FlowCnec cnec2 = initPreventiveCnecAdder().withId("anotherId").newThreshold().withUnit(AMPERE).withMin(-1000.).withSide(TwoSides.ONE).add().withNominalVoltage(220.).add(); assertEquals(cnec1, cnec1); assertNotEquals(cnec1, cnec2); @@ -466,7 +466,7 @@ void testIsConnected() { NetworkImportsUtil.addDanglingLine(network); // Branch - FlowCnec cnec1 = crac.newFlowCnec().withId("cnec-1-id").withNetworkElement("BBE1AA1 BBE2AA1 1").withInstant(PREVENTIVE_INSTANT_ID).newThreshold().withUnit(MEGAWATT).withMax(1000.).withSide(LEFT).add().add(); + FlowCnec cnec1 = crac.newFlowCnec().withId("cnec-1-id").withNetworkElement("BBE1AA1 BBE2AA1 1").withInstant(PREVENTIVE_INSTANT_ID).newThreshold().withUnit(MEGAWATT).withMax(1000.).withSide(ONE).add().add(); assertTrue(cnec1.isConnected(network)); network.getBranch("BBE1AA1 BBE2AA1 1").getTerminal1().disconnect(); @@ -477,14 +477,14 @@ void testIsConnected() { assertFalse(cnec1.isConnected(network)); // DanglingLine - FlowCnec cnec2 = crac.newFlowCnec().withId("cnec-2-id").withNetworkElement("DL1").withInstant(PREVENTIVE_INSTANT_ID).newThreshold().withUnit(MEGAWATT).withMax(1000.).withSide(LEFT).add().add(); + FlowCnec cnec2 = crac.newFlowCnec().withId("cnec-2-id").withNetworkElement("DL1").withInstant(PREVENTIVE_INSTANT_ID).newThreshold().withUnit(MEGAWATT).withMax(1000.).withSide(ONE).add().add(); assertTrue(cnec2.isConnected(network)); network.getDanglingLine("DL1").getTerminal().disconnect(); assertFalse(cnec2.isConnected(network)); // Generator - FlowCnec cnec3 = crac.newFlowCnec().withId("cnec-3-id").withNetworkElement("BBE2AA1 _generator").withInstant(PREVENTIVE_INSTANT_ID).newThreshold().withUnit(MEGAWATT).withMax(1000.).withSide(LEFT).add().add(); + FlowCnec cnec3 = crac.newFlowCnec().withId("cnec-3-id").withNetworkElement("BBE2AA1 _generator").withInstant(PREVENTIVE_INSTANT_ID).newThreshold().withUnit(MEGAWATT).withMax(1000.).withSide(ONE).add().add(); assertTrue(cnec3.isConnected(network)); network.getGenerator("BBE2AA1 _generator").getTerminal().disconnect(); diff --git a/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/OnConstraintAdderImplTest.java b/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/OnConstraintAdderImplTest.java index c529963e93..caa823c2c8 100644 --- a/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/OnConstraintAdderImplTest.java +++ b/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/OnConstraintAdderImplTest.java @@ -7,6 +7,7 @@ package com.powsybl.openrao.data.cracimpl; import com.powsybl.contingency.ContingencyElementType; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.Crac; @@ -18,7 +19,6 @@ import com.powsybl.openrao.data.cracapi.cnec.Cnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnecAdder; -import com.powsybl.openrao.data.cracapi.cnec.Side; import com.powsybl.openrao.data.cracapi.cnec.VoltageCnec; import com.powsybl.openrao.data.cracapi.cnec.VoltageCnecAdder; import com.powsybl.openrao.data.cracapi.networkaction.ActionType; @@ -87,13 +87,13 @@ public void setUp() { .withOperator("operator2") .newThreshold() .withUnit(Unit.MEGAWATT) - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .withMin(-1500.) .withMax(1500.) .add() .newThreshold() .withUnit(Unit.PERCENT_IMAX) - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .withMin(-0.3) .withMax(0.3) .add() @@ -286,8 +286,8 @@ private void addFlowCnec(String id, String instantId) { .withInstant(instantId) .withOptimized(true) .withOperator("operator2") - .newThreshold().withUnit(Unit.MEGAWATT).withSide(Side.LEFT).withMin(-1500.).withMax(1500.).add() - .newThreshold().withUnit(Unit.PERCENT_IMAX).withSide(Side.LEFT).withMin(-0.3).withMax(0.3).add() + .newThreshold().withUnit(Unit.MEGAWATT).withSide(TwoSides.ONE).withMin(-1500.).withMax(1500.).add() + .newThreshold().withUnit(Unit.PERCENT_IMAX).withSide(TwoSides.ONE).withMin(-0.3).withMax(0.3).add() .withNominalVoltage(380.) .withIMax(5000.); if (!crac.getInstant(instantId).isPreventive()) { diff --git a/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/OnFlowConstraintInCountryAdderImplTest.java b/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/OnFlowConstraintInCountryAdderImplTest.java index e38482e848..aada1cb191 100644 --- a/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/OnFlowConstraintInCountryAdderImplTest.java +++ b/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/OnFlowConstraintInCountryAdderImplTest.java @@ -13,7 +13,7 @@ import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.InstantKind; import com.powsybl.openrao.data.cracapi.RemedialAction; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.ActionType; import com.powsybl.openrao.data.cracapi.networkaction.NetworkActionAdder; import com.powsybl.openrao.data.cracapi.usagerule.*; @@ -62,13 +62,13 @@ public void setUp() { .withOperator("operator2") .newThreshold() .withUnit(Unit.MEGAWATT) - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .withMin(-1500.) .withMax(1500.) .add() .newThreshold() .withUnit(Unit.PERCENT_IMAX) - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .withMin(-0.3) .withMax(0.3) .add() diff --git a/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/utils/CommonCracCreation.java b/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/utils/CommonCracCreation.java index a73ad38552..73d4322774 100644 --- a/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/utils/CommonCracCreation.java +++ b/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/utils/CommonCracCreation.java @@ -11,8 +11,8 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.*; import com.powsybl.openrao.data.cracapi.cnec.FlowCnecAdder; -import com.powsybl.openrao.data.cracapi.cnec.Side; import com.powsybl.openrao.data.cracapi.networkaction.ActionType; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.range.RangeType; import com.powsybl.openrao.data.cracapi.usagerule.UsageMethod; import com.powsybl.iidm.network.Network; @@ -78,15 +78,15 @@ private CommonCracCreation() { // nothing } - public static Crac create(Set monitoredCnecSides) { + public static Crac create(Set monitoredCnecSides) { return create(new CracImplFactory(), monitoredCnecSides); } public static Crac create() { - return create(new CracImplFactory(), Set.of(Side.LEFT)); + return create(new CracImplFactory(), Set.of(TwoSides.ONE)); } - public static Crac create(CracFactory cracFactory, Set monitoredCnecSides) { + public static Crac create(CracFactory cracFactory, Set monitoredCnecSides) { Crac crac = cracFactory.create("idSimpleCracTestUS", "nameSimpleCracTestUS") .newInstant(PREVENTIVE_INSTANT_ID, InstantKind.PREVENTIVE) @@ -220,13 +220,13 @@ public static Crac create(CracFactory cracFactory, Set monitoredCnecSides) monitoredCnecSides.forEach(side -> cnecAdder6.newThreshold() .withUnit(Unit.MEGAWATT) - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .withMin(-1500.) .withMax(1500.) .add() .newThreshold() .withUnit(Unit.PERCENT_IMAX) - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .withMin(-0.3) .withMax(0.3) .add()); @@ -236,10 +236,10 @@ public static Crac create(CracFactory cracFactory, Set monitoredCnecSides) } public static Crac createWithPreventivePstRange() { - return createWithPreventivePstRange(Set.of(Side.LEFT)); + return createWithPreventivePstRange(Set.of(TwoSides.ONE)); } - public static Crac createWithPreventivePstRange(Set monitoredCnecSides) { + public static Crac createWithPreventivePstRange(Set monitoredCnecSides) { Crac crac = create(monitoredCnecSides); Network network = import12NodesNetwork(); IidmPstHelper pstHelper = new IidmPstHelper("BBE2AA1 BBE3AA1 1", network); @@ -265,10 +265,10 @@ public static Crac createWithPreventivePstRange(Set monitoredCnecSides) { } public static Crac createWithCurativePstRange() { - return createWithCurativePstRange(Set.of(Side.LEFT)); + return createWithCurativePstRange(Set.of(TwoSides.ONE)); } - public static Crac createWithCurativePstRange(Set monitoredCnecSides) { + public static Crac createWithCurativePstRange(Set monitoredCnecSides) { Crac crac = create(); Network network = import12NodesNetwork(); IidmPstHelper pstHelper = new IidmPstHelper("BBE2AA1 BBE3AA1 1", network); diff --git a/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/utils/ExhaustiveCracCreation.java b/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/utils/ExhaustiveCracCreation.java index 1db14a804e..7ad09ca150 100644 --- a/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/utils/ExhaustiveCracCreation.java +++ b/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/cracimpl/utils/ExhaustiveCracCreation.java @@ -13,7 +13,6 @@ import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.CracFactory; import com.powsybl.openrao.data.cracapi.InstantKind; -import com.powsybl.openrao.data.cracapi.cnec.Side; import com.powsybl.openrao.data.cracapi.networkaction.ActionType; import com.powsybl.openrao.data.cracapi.range.RangeType; import com.powsybl.openrao.data.cracapi.usagerule.UsageMethod; @@ -83,8 +82,8 @@ public static Crac create(CracFactory cracFactory) { .withInstant(PREVENTIVE_INSTANT_ID) .withOperator("operator1") .withOptimized() - .newThreshold().withSide(Side.RIGHT).withUnit(Unit.AMPERE).withMin(-500.).add() - .withIMax(1000., Side.RIGHT) + .newThreshold().withSide(TwoSides.TWO).withUnit(Unit.AMPERE).withMin(-500.).add() + .withIMax(1000., TwoSides.TWO) .withNominalVoltage(220.) .add(); @@ -94,7 +93,7 @@ public static Crac create(CracFactory cracFactory) { .withContingency(contingency1Id) .withOperator("operator1") .withOptimized() - .newThreshold().withSide(Side.RIGHT).withUnit(Unit.AMPERE).withMin(-800.).add() + .newThreshold().withSide(TwoSides.TWO).withUnit(Unit.AMPERE).withMin(-800.).add() .withNominalVoltage(220.) .add(); @@ -103,12 +102,12 @@ public static Crac create(CracFactory cracFactory) { .withInstant(PREVENTIVE_INSTANT_ID) .withOperator("operator2") .withOptimized() - .newThreshold().withSide(Side.LEFT).withUnit(Unit.PERCENT_IMAX).withMin(-0.3).add() - .newThreshold().withSide(Side.LEFT).withUnit(Unit.AMPERE).withMin(-800.).add() - .newThreshold().withSide(Side.RIGHT).withUnit(Unit.AMPERE).withMin(-800.).add() - .newThreshold().withSide(Side.RIGHT).withUnit(Unit.AMPERE).withMax(1200.).add() - .withNominalVoltage(220., Side.RIGHT) - .withNominalVoltage(380., Side.LEFT) + .newThreshold().withSide(TwoSides.ONE).withUnit(Unit.PERCENT_IMAX).withMin(-0.3).add() + .newThreshold().withSide(TwoSides.ONE).withUnit(Unit.AMPERE).withMin(-800.).add() + .newThreshold().withSide(TwoSides.TWO).withUnit(Unit.AMPERE).withMin(-800.).add() + .newThreshold().withSide(TwoSides.TWO).withUnit(Unit.AMPERE).withMax(1200.).add() + .withNominalVoltage(220., TwoSides.TWO) + .withNominalVoltage(380., TwoSides.ONE) .withIMax(2000.) .add(); @@ -117,8 +116,8 @@ public static Crac create(CracFactory cracFactory) { .withNetworkElement("ne2Id", "ne2Name") .withInstant(PREVENTIVE_INSTANT_ID) .withOperator("operator3") - .newThreshold().withUnit(Unit.MEGAWATT).withMax(500.).withSide(Side.LEFT).add() - .newThreshold().withUnit(Unit.MEGAWATT).withMax(500.).withSide(Side.RIGHT).add() + .newThreshold().withUnit(Unit.MEGAWATT).withMax(500.).withSide(TwoSides.ONE).add() + .newThreshold().withUnit(Unit.MEGAWATT).withMax(500.).withSide(TwoSides.TWO).add() .withReliabilityMargin(20.) .withMonitored() .add(); @@ -129,8 +128,8 @@ public static Crac create(CracFactory cracFactory) { .withInstant(AUTO_INSTANT_ID) .withContingency(contingency2Id) .withOperator("operator3") - .newThreshold().withUnit(Unit.MEGAWATT).withMax(500.).withSide(Side.LEFT).add() - .newThreshold().withUnit(Unit.MEGAWATT).withMax(500.).withSide(Side.RIGHT).add() + .newThreshold().withUnit(Unit.MEGAWATT).withMax(500.).withSide(TwoSides.ONE).add() + .newThreshold().withUnit(Unit.MEGAWATT).withMax(500.).withSide(TwoSides.TWO).add() .withReliabilityMargin(20.) .withMonitored() .add(); @@ -140,8 +139,8 @@ public static Crac create(CracFactory cracFactory) { .withInstant(CURATIVE_INSTANT_ID) .withContingency(contingency2Id) .withOperator("operator3") - .newThreshold().withUnit(Unit.MEGAWATT).withMax(500.).withSide(Side.LEFT).add() - .newThreshold().withUnit(Unit.MEGAWATT).withMax(500.).withSide(Side.RIGHT).add() + .newThreshold().withUnit(Unit.MEGAWATT).withMax(500.).withSide(TwoSides.ONE).add() + .newThreshold().withUnit(Unit.MEGAWATT).withMax(500.).withSide(TwoSides.TWO).add() .withReliabilityMargin(20.) .withMonitored() .add(); @@ -151,7 +150,7 @@ public static Crac create(CracFactory cracFactory) { .withNetworkElement("ne3Id") .withInstant(PREVENTIVE_INSTANT_ID) .withOperator("operator4") - .newThreshold().withUnit(Unit.MEGAWATT).withMax(500.).withSide(Side.LEFT).add() + .newThreshold().withUnit(Unit.MEGAWATT).withMax(500.).withSide(TwoSides.ONE).add() .withReliabilityMargin(0.) .withOptimized() .withMonitored() diff --git a/data/crac/crac-loopflow-extension/src/main/java/com/powsybl/openrao/data/cracloopflowextension/LoopFlowThresholdImpl.java b/data/crac/crac-loopflow-extension/src/main/java/com/powsybl/openrao/data/cracloopflowextension/LoopFlowThresholdImpl.java index cb2ae657f9..fa47af4e9e 100644 --- a/data/crac/crac-loopflow-extension/src/main/java/com/powsybl/openrao/data/cracloopflowextension/LoopFlowThresholdImpl.java +++ b/data/crac/crac-loopflow-extension/src/main/java/com/powsybl/openrao/data/cracloopflowextension/LoopFlowThresholdImpl.java @@ -10,7 +10,7 @@ import com.powsybl.openrao.commons.PhysicalParameter; import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.commons.extensions.AbstractExtension; /** @@ -100,11 +100,11 @@ public double getThreshold(Unit requestedUnit) { } private double convertMWToA(double valueInMW) { - return valueInMW * 1000 / (getExtendable().getNominalVoltage(Side.LEFT) * Math.sqrt(3)); + return valueInMW * 1000 / (getExtendable().getNominalVoltage(TwoSides.ONE) * Math.sqrt(3)); } private double convertAToMW(double valueInA) { - return valueInA * getExtendable().getNominalVoltage(Side.LEFT) * Math.sqrt(3) / 1000; + return valueInA * getExtendable().getNominalVoltage(TwoSides.ONE) * Math.sqrt(3) / 1000; } private double convertAToPercentImax(double valueInA) { @@ -117,12 +117,12 @@ private double convertPercentImaxToA(double valueInPercent) { private double getCnecFmaxWithoutFrmInA() { double minUpperBound = Math.min( - getExtendable().getUpperBound(Side.LEFT, Unit.AMPERE).orElse(Double.POSITIVE_INFINITY), - getExtendable().getUpperBound(Side.RIGHT, Unit.AMPERE).orElse(Double.POSITIVE_INFINITY) + getExtendable().getUpperBound(TwoSides.ONE, Unit.AMPERE).orElse(Double.POSITIVE_INFINITY), + getExtendable().getUpperBound(TwoSides.TWO, Unit.AMPERE).orElse(Double.POSITIVE_INFINITY) ); double maxLowerBound = Math.max( - getExtendable().getLowerBound(Side.LEFT, Unit.AMPERE).orElse(Double.NEGATIVE_INFINITY), - getExtendable().getLowerBound(Side.RIGHT, Unit.AMPERE).orElse(Double.NEGATIVE_INFINITY) + getExtendable().getLowerBound(TwoSides.ONE, Unit.AMPERE).orElse(Double.NEGATIVE_INFINITY), + getExtendable().getLowerBound(TwoSides.TWO, Unit.AMPERE).orElse(Double.NEGATIVE_INFINITY) ); return Math.min(minUpperBound, -maxLowerBound) + convertMWToA(getExtendable().getReliabilityMargin()); } diff --git a/data/crac/crac-loopflow-extension/src/test/java/com/powsybl/openrao/data/cracloopflowextension/JsonLoopFlowThresholdImplImportExportTest.java b/data/crac/crac-loopflow-extension/src/test/java/com/powsybl/openrao/data/cracloopflowextension/JsonLoopFlowThresholdImplImportExportTest.java index 3da33064c3..5527201ba8 100644 --- a/data/crac/crac-loopflow-extension/src/test/java/com/powsybl/openrao/data/cracloopflowextension/JsonLoopFlowThresholdImplImportExportTest.java +++ b/data/crac/crac-loopflow-extension/src/test/java/com/powsybl/openrao/data/cracloopflowextension/JsonLoopFlowThresholdImplImportExportTest.java @@ -11,7 +11,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.InstantKind; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracimpl.CracImplFactory; import org.junit.jupiter.api.Test; @@ -37,7 +37,7 @@ void roundTripTest() { .withId("cnec1") .withNetworkElement("ne1") .withInstant(PREVENTIVE_INSTANT_ID) - .newThreshold().withSide(Side.LEFT).withUnit(Unit.AMPERE).withMin(-500.).add() + .newThreshold().withSide(TwoSides.ONE).withUnit(Unit.AMPERE).withMin(-500.).add() .withNominalVoltage(380.) .add() .newExtension(LoopFlowThresholdAdder.class).withValue(100).withUnit(Unit.AMPERE).add(); @@ -46,7 +46,7 @@ void roundTripTest() { .withId("cnec2") .withNetworkElement("ne2") .withInstant(PREVENTIVE_INSTANT_ID) - .newThreshold().withSide(Side.LEFT).withUnit(Unit.PERCENT_IMAX).withMin(-0.3).add() + .newThreshold().withSide(TwoSides.ONE).withUnit(Unit.PERCENT_IMAX).withMin(-0.3).add() .withNominalVoltage(380.) .withIMax(5000.) .add() @@ -56,7 +56,7 @@ void roundTripTest() { .withId("cnec3") .withNetworkElement("ne3") .withInstant(PREVENTIVE_INSTANT_ID) - .newThreshold().withSide(Side.LEFT).withUnit(Unit.MEGAWATT).withMin(-700.).withMax(700.).add() + .newThreshold().withSide(TwoSides.ONE).withUnit(Unit.MEGAWATT).withMin(-700.).withMax(700.).add() .add(); // export Crac diff --git a/data/crac/crac-loopflow-extension/src/test/java/com/powsybl/openrao/data/cracloopflowextension/LoopFlowThresholdAdderImplTest.java b/data/crac/crac-loopflow-extension/src/test/java/com/powsybl/openrao/data/cracloopflowextension/LoopFlowThresholdAdderImplTest.java index a038add686..86d3ceb0c4 100644 --- a/data/crac/crac-loopflow-extension/src/test/java/com/powsybl/openrao/data/cracloopflowextension/LoopFlowThresholdAdderImplTest.java +++ b/data/crac/crac-loopflow-extension/src/test/java/com/powsybl/openrao/data/cracloopflowextension/LoopFlowThresholdAdderImplTest.java @@ -6,7 +6,7 @@ import com.powsybl.openrao.data.cracapi.CracFactory; import com.powsybl.openrao.data.cracapi.InstantKind; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -29,7 +29,7 @@ public void setUp() { .withOperator("operator") .withOptimized(true) .newThreshold() - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .withUnit(Unit.MEGAWATT) .withMax(1000.0) .withMin(-1000.0) diff --git a/data/crac/crac-util/src/main/java/com/powsybl/openrao/data/cracutil/CracValidator.java b/data/crac/crac-util/src/main/java/com/powsybl/openrao/data/cracutil/CracValidator.java index bb5bbc8057..ee2740632a 100644 --- a/data/crac/crac-util/src/main/java/com/powsybl/openrao/data/cracutil/CracValidator.java +++ b/data/crac/crac-util/src/main/java/com/powsybl/openrao/data/cracutil/CracValidator.java @@ -10,7 +10,7 @@ import com.powsybl.openrao.data.cracapi.*; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnecAdder; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.threshold.BranchThresholdAdder; import com.powsybl.openrao.data.cracapi.usagerule.*; import com.powsybl.iidm.network.Network; @@ -75,10 +75,10 @@ private static void duplicateCnecOnOutageInstant(Crac crac, FlowCnec cnec) { FlowCnecAdder adder = crac.newFlowCnec() .withId(cnec.getId() + " - OUTAGE DUPLICATE") .withNetworkElement(cnec.getNetworkElement().getId()) - .withIMax(cnec.getIMax(Side.LEFT), Side.LEFT) - .withIMax(cnec.getIMax(Side.RIGHT), Side.RIGHT) - .withNominalVoltage(cnec.getNominalVoltage(Side.LEFT), Side.LEFT) - .withNominalVoltage(cnec.getNominalVoltage(Side.RIGHT), Side.RIGHT) + .withIMax(cnec.getIMax(TwoSides.ONE), TwoSides.ONE) + .withIMax(cnec.getIMax(TwoSides.TWO), TwoSides.TWO) + .withNominalVoltage(cnec.getNominalVoltage(TwoSides.ONE), TwoSides.ONE) + .withNominalVoltage(cnec.getNominalVoltage(TwoSides.TWO), TwoSides.TWO) .withReliabilityMargin(cnec.getReliabilityMargin()) .withInstant(outageInstant.getId()).withContingency(cnec.getState().getContingency().orElseThrow().getId()) .withOptimized(cnec.isOptimized()) diff --git a/data/crac/crac-util/src/test/java/com/powsybl/openrao/data/cracutil/CracValidatorTest.java b/data/crac/crac-util/src/test/java/com/powsybl/openrao/data/cracutil/CracValidatorTest.java index 82054f1ac0..fad7a6cedf 100644 --- a/data/crac/crac-util/src/test/java/com/powsybl/openrao/data/cracutil/CracValidatorTest.java +++ b/data/crac/crac-util/src/test/java/com/powsybl/openrao/data/cracutil/CracValidatorTest.java @@ -15,7 +15,7 @@ import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.InstantKind; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.ActionType; import com.powsybl.openrao.data.cracapi.usagerule.UsageMethod; import com.powsybl.iidm.network.Country; @@ -59,40 +59,40 @@ public void setUp() { .withId("auto-cnec-1") .withNetworkElement("BBE1AA1 BBE2AA1 1") .withContingency("co-1").withInstant(AUTO_INSTANT_ID) - .withNominalVoltage(400., Side.LEFT) - .withNominalVoltage(200., Side.RIGHT) - .withIMax(2000., Side.LEFT) - .withIMax(4000., Side.RIGHT) + .withNominalVoltage(400., TwoSides.ONE) + .withNominalVoltage(200., TwoSides.TWO) + .withIMax(2000., TwoSides.ONE) + .withIMax(4000., TwoSides.TWO) .withReliabilityMargin(15.) .withOptimized() - .newThreshold().withMin(-100.).withMax(100.).withUnit(Unit.MEGAWATT).withSide(Side.LEFT).add() - .newThreshold().withMin(-100.).withMax(100.).withUnit(Unit.MEGAWATT).withSide(Side.RIGHT).add() - .newThreshold().withMin(-1.).withMax(1.).withUnit(Unit.PERCENT_IMAX).withSide(Side.LEFT).add() + .newThreshold().withMin(-100.).withMax(100.).withUnit(Unit.MEGAWATT).withSide(TwoSides.ONE).add() + .newThreshold().withMin(-100.).withMax(100.).withUnit(Unit.MEGAWATT).withSide(TwoSides.TWO).add() + .newThreshold().withMin(-1.).withMax(1.).withUnit(Unit.PERCENT_IMAX).withSide(TwoSides.ONE).add() .add(); crac.newFlowCnec() .withId("auto-cnec-2") .withNetworkElement("FFR2AA1 DDE3AA1 1") .withContingency("co-1").withInstant(AUTO_INSTANT_ID) - .withNominalVoltage(300., Side.LEFT) - .withNominalVoltage(900., Side.RIGHT) - .withIMax(40, Side.LEFT) - .withIMax(40., Side.RIGHT) + .withNominalVoltage(300., TwoSides.ONE) + .withNominalVoltage(900., TwoSides.TWO) + .withIMax(40, TwoSides.ONE) + .withIMax(40., TwoSides.TWO) .withReliabilityMargin(0.) - .newThreshold().withMax(1000.).withUnit(Unit.AMPERE).withSide(Side.LEFT).add() + .newThreshold().withMax(1000.).withUnit(Unit.AMPERE).withSide(TwoSides.ONE).add() .add(); crac.newFlowCnec() .withId("auto-cnec-3") .withNetworkElement("BBE1AA1 BBE3AA1 1") .withContingency("co-2").withInstant(AUTO_INSTANT_ID) - .withNominalVoltage(500., Side.LEFT) - .withNominalVoltage(700., Side.RIGHT) - .withIMax(200., Side.LEFT) - .withIMax(400., Side.RIGHT) + .withNominalVoltage(500., TwoSides.ONE) + .withNominalVoltage(700., TwoSides.TWO) + .withIMax(200., TwoSides.ONE) + .withIMax(400., TwoSides.TWO) .withReliabilityMargin(1.) .withMonitored() - .newThreshold().withMin(-1.).withUnit(Unit.PERCENT_IMAX).withSide(Side.RIGHT).add() + .newThreshold().withMin(-1.).withUnit(Unit.PERCENT_IMAX).withSide(TwoSides.TWO).add() .add(); } @@ -107,10 +107,10 @@ private void assertCnecHasOutageDuplicate(String flowCnecId) { assertEquals(flowCnec.isOptimized(), duplicate.isOptimized()); assertEquals(flowCnec.isMonitored(), duplicate.isMonitored()); assertEquals(flowCnec.getReliabilityMargin(), duplicate.getReliabilityMargin(), 1e-6); - assertEquals(flowCnec.getIMax(Side.LEFT), duplicate.getIMax(Side.LEFT), 1e-6); - assertEquals(flowCnec.getIMax(Side.RIGHT), duplicate.getIMax(Side.RIGHT), 1e-6); - assertEquals(flowCnec.getNominalVoltage(Side.LEFT), duplicate.getNominalVoltage(Side.LEFT), 1e-6); - assertEquals(flowCnec.getNominalVoltage(Side.RIGHT), duplicate.getNominalVoltage(Side.RIGHT), 1e-6); + assertEquals(flowCnec.getIMax(TwoSides.ONE), duplicate.getIMax(TwoSides.ONE), 1e-6); + assertEquals(flowCnec.getIMax(TwoSides.TWO), duplicate.getIMax(TwoSides.TWO), 1e-6); + assertEquals(flowCnec.getNominalVoltage(TwoSides.ONE), duplicate.getNominalVoltage(TwoSides.ONE), 1e-6); + assertEquals(flowCnec.getNominalVoltage(TwoSides.TWO), duplicate.getNominalVoltage(TwoSides.TWO), 1e-6); assertEquals(flowCnec.getThresholds(), duplicate.getThresholds()); } diff --git a/data/rao-result/rao-result-api/src/main/java/com/powsybl/openrao/data/raoresultapi/RaoResult.java b/data/rao-result/rao-result-api/src/main/java/com/powsybl/openrao/data/raoresultapi/RaoResult.java index cdd0995cfe..2ddc213990 100644 --- a/data/rao-result/rao-result-api/src/main/java/com/powsybl/openrao/data/raoresultapi/RaoResult.java +++ b/data/rao-result/rao-result-api/src/main/java/com/powsybl/openrao/data/raoresultapi/RaoResult.java @@ -17,7 +17,7 @@ import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.AngleCnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.cnec.VoltageCnec; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; @@ -64,7 +64,7 @@ public interface RaoResult { * @param unit: The unit in which the flow is queried. Only accepted values are MEGAWATT or AMPERE. * @return The flow on the branch at the optimization state in the given unit. */ - double getFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit); + double getFlow(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side, Unit unit); /** * It gives the angle on an {@link AngleCnec} at a given {@link Instant} and in a @@ -157,7 +157,7 @@ default double getMargin(Instant optimizedInstant, VoltageCnec voltageCnec, Unit * @param unit: The unit in which the commercial flow is queried. Only accepted values are MEGAWATT or AMPERE. * @return The commercial flow on the branch at the optimization state in the given unit. */ - double getCommercialFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit); + double getCommercialFlow(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side, Unit unit); /** * It gives the value of loop flow (according to CORE D-2 CC methodology) on a {@link FlowCnec} at a given @@ -169,7 +169,7 @@ default double getMargin(Instant optimizedInstant, VoltageCnec voltageCnec, Unit * @param unit: The unit in which the loop flow is queried. Only accepted values are MEGAWATT or AMPERE. * @return The loop flow on the branch at the optimization state in the given unit. */ - double getLoopFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit); + double getLoopFlow(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side, Unit unit); /** * It gives the sum of the computation areas' zonal PTDFs on a {@link FlowCnec} at a given @@ -180,7 +180,7 @@ default double getMargin(Instant optimizedInstant, VoltageCnec voltageCnec, Unit * @param flowCnec: The branch to be studied. * @return The sum of the computation areas' zonal PTDFs on the branch at the optimization state. */ - double getPtdfZonalSum(Instant optimizedInstant, FlowCnec flowCnec, Side side); + double getPtdfZonalSum(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side); /** * It gives the global cost of the situation at a given {@link Instant} according to the objective diff --git a/data/rao-result/rao-result-api/src/main/java/com/powsybl/openrao/data/raoresultapi/RaoResultClone.java b/data/rao-result/rao-result-api/src/main/java/com/powsybl/openrao/data/raoresultapi/RaoResultClone.java index ba02962f07..554d1dfc40 100644 --- a/data/rao-result/rao-result-api/src/main/java/com/powsybl/openrao/data/raoresultapi/RaoResultClone.java +++ b/data/rao-result/rao-result-api/src/main/java/com/powsybl/openrao/data/raoresultapi/RaoResultClone.java @@ -14,7 +14,7 @@ import com.powsybl.openrao.data.cracapi.RemedialAction; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; @@ -47,7 +47,7 @@ public ComputationStatus getComputationStatus(State state) { } @Override - public double getFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit) { + public double getFlow(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side, Unit unit) { return raoResult.getFlow(optimizedInstant, flowCnec, side, unit); } @@ -62,17 +62,17 @@ public double getRelativeMargin(Instant optimizedInstant, FlowCnec flowCnec, Uni } @Override - public double getLoopFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit) { + public double getLoopFlow(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side, Unit unit) { return raoResult.getLoopFlow(optimizedInstant, flowCnec, side, unit); } @Override - public double getCommercialFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit) { + public double getCommercialFlow(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side, Unit unit) { return raoResult.getCommercialFlow(optimizedInstant, flowCnec, side, unit); } @Override - public double getPtdfZonalSum(Instant optimizedInstant, FlowCnec flowCnec, Side side) { + public double getPtdfZonalSum(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side) { return raoResult.getPtdfZonalSum(optimizedInstant, flowCnec, side); } diff --git a/data/rao-result/rao-result-api/src/test/java/com/powsybl/openrao/data/raoresultapi/MockRaoResult.java b/data/rao-result/rao-result-api/src/test/java/com/powsybl/openrao/data/raoresultapi/MockRaoResult.java index a1f5c4b414..1d8c68bc85 100644 --- a/data/rao-result/rao-result-api/src/test/java/com/powsybl/openrao/data/raoresultapi/MockRaoResult.java +++ b/data/rao-result/rao-result-api/src/test/java/com/powsybl/openrao/data/raoresultapi/MockRaoResult.java @@ -7,13 +7,13 @@ package com.powsybl.openrao.data.raoresultapi; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.commons.PhysicalParameter; import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.RemedialAction; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; @@ -51,7 +51,7 @@ public ComputationStatus getComputationStatus(State state) { } @Override - public double getFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit) { + public double getFlow(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side, Unit unit) { return 0; } @@ -66,17 +66,17 @@ public double getRelativeMargin(Instant optimizedInstant, FlowCnec flowCnec, Uni } @Override - public double getCommercialFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit) { + public double getCommercialFlow(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side, Unit unit) { return 0; } @Override - public double getLoopFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit) { + public double getLoopFlow(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side, Unit unit) { return 0; } @Override - public double getPtdfZonalSum(Instant optimizedInstant, FlowCnec flowCnec, Side side) { + public double getPtdfZonalSum(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side) { return 0; } diff --git a/data/rao-result/rao-result-api/src/test/java/com/powsybl/openrao/data/raoresultapi/RaoResultCloneTest.java b/data/rao-result/rao-result-api/src/test/java/com/powsybl/openrao/data/raoresultapi/RaoResultCloneTest.java index a48ff79291..d8d891b33e 100644 --- a/data/rao-result/rao-result-api/src/test/java/com/powsybl/openrao/data/raoresultapi/RaoResultCloneTest.java +++ b/data/rao-result/rao-result-api/src/test/java/com/powsybl/openrao/data/raoresultapi/RaoResultCloneTest.java @@ -11,7 +11,7 @@ import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.cnec.VoltageCnec; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.HvdcRangeAction; @@ -24,8 +24,8 @@ import java.util.Set; import static com.powsybl.openrao.commons.Unit.*; -import static com.powsybl.openrao.data.cracapi.cnec.Side.LEFT; -import static com.powsybl.openrao.data.cracapi.cnec.Side.RIGHT; +import static com.powsybl.iidm.network.TwoSides.ONE; +import static com.powsybl.iidm.network.TwoSides.TWO; import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; @@ -84,15 +84,15 @@ void testAbstractRaoResultClone() { // Mocking flowCnec results FlowCnec cnecP = mock(FlowCnec.class); when(crac.getFlowCnec("cnec4prevId")).thenReturn(cnecP); - Mockito.when(raoResult.getFlow(null, cnecP, RIGHT, MEGAWATT)).thenReturn(Double.NaN); - Mockito.when(raoResult.getFlow(null, cnecP, LEFT, MEGAWATT)).thenReturn(4110.0); + Mockito.when(raoResult.getFlow(null, cnecP, TWO, MEGAWATT)).thenReturn(Double.NaN); + Mockito.when(raoResult.getFlow(null, cnecP, ONE, MEGAWATT)).thenReturn(4110.0); - Mockito.when(raoResult.getFlow(preventiveInstant, cnecP, RIGHT, AMPERE)).thenReturn(Double.NaN); - Mockito.when(raoResult.getFlow(preventiveInstant, cnecP, LEFT, AMPERE)).thenReturn(4220.); - Mockito.when(raoResult.getFlow(autoInstant, cnecP, RIGHT, AMPERE)).thenReturn(Double.NaN); - Mockito.when(raoResult.getFlow(autoInstant, cnecP, LEFT, AMPERE)).thenReturn(4220.); - Mockito.when(raoResult.getFlow(curativeInstant, cnecP, RIGHT, AMPERE)).thenReturn(Double.NaN); - Mockito.when(raoResult.getFlow(curativeInstant, cnecP, LEFT, AMPERE)).thenReturn(4220.); + Mockito.when(raoResult.getFlow(preventiveInstant, cnecP, TWO, AMPERE)).thenReturn(Double.NaN); + Mockito.when(raoResult.getFlow(preventiveInstant, cnecP, ONE, AMPERE)).thenReturn(4220.); + Mockito.when(raoResult.getFlow(autoInstant, cnecP, TWO, AMPERE)).thenReturn(Double.NaN); + Mockito.when(raoResult.getFlow(autoInstant, cnecP, ONE, AMPERE)).thenReturn(4220.); + Mockito.when(raoResult.getFlow(curativeInstant, cnecP, TWO, AMPERE)).thenReturn(Double.NaN); + Mockito.when(raoResult.getFlow(curativeInstant, cnecP, ONE, AMPERE)).thenReturn(4220.); Mockito.when(raoResult.getMargin(null, cnecP, MEGAWATT)).thenReturn(4111.); Mockito.when(raoResult.getMargin(preventiveInstant, cnecP, AMPERE)).thenReturn(4221.); @@ -101,36 +101,36 @@ void testAbstractRaoResultClone() { Mockito.when(raoResult.getRelativeMargin(null, cnecP, AMPERE)).thenReturn(4221.); Mockito.when(raoResult.getRelativeMargin(preventiveInstant, cnecP, AMPERE)).thenReturn(4222.); - Mockito.when(raoResult.getLoopFlow(null, cnecP, RIGHT, MEGAWATT)).thenReturn(Double.NaN); - Mockito.when(raoResult.getLoopFlow(null, cnecP, LEFT, MEGAWATT)).thenReturn(Double.NaN); + Mockito.when(raoResult.getLoopFlow(null, cnecP, TWO, MEGAWATT)).thenReturn(Double.NaN); + Mockito.when(raoResult.getLoopFlow(null, cnecP, ONE, MEGAWATT)).thenReturn(Double.NaN); - Mockito.when(raoResult.getCommercialFlow(null, cnecP, RIGHT, MEGAWATT)).thenReturn(Double.NaN); - Mockito.when(raoResult.getCommercialFlow(null, cnecP, LEFT, MEGAWATT)).thenReturn(Double.NaN); + Mockito.when(raoResult.getCommercialFlow(null, cnecP, TWO, MEGAWATT)).thenReturn(Double.NaN); + Mockito.when(raoResult.getCommercialFlow(null, cnecP, ONE, MEGAWATT)).thenReturn(Double.NaN); - Mockito.when(raoResult.getPtdfZonalSum(preventiveInstant, cnecP, LEFT)).thenReturn(0.4); - Mockito.when(raoResult.getPtdfZonalSum(preventiveInstant, cnecP, RIGHT)).thenReturn(Double.NaN); + Mockito.when(raoResult.getPtdfZonalSum(preventiveInstant, cnecP, ONE)).thenReturn(0.4); + Mockito.when(raoResult.getPtdfZonalSum(preventiveInstant, cnecP, TWO)).thenReturn(Double.NaN); FlowCnec cnecO = Mockito.mock(FlowCnec.class); Mockito.when(cnecO.getId()).thenReturn("cnec1outageId"); Mockito.when(crac.getFlowCnec("cnec1outageId")).thenReturn(cnecO); - Mockito.when(raoResult.getFlow(null, cnecO, Side.LEFT, AMPERE)).thenReturn(Double.NaN); - Mockito.when(raoResult.getFlow(null, cnecO, Side.RIGHT, AMPERE)).thenReturn(1120.5); + Mockito.when(raoResult.getFlow(null, cnecO, TwoSides.ONE, AMPERE)).thenReturn(Double.NaN); + Mockito.when(raoResult.getFlow(null, cnecO, TwoSides.TWO, AMPERE)).thenReturn(1120.5); Mockito.when(raoResult.getMargin(null, cnecO, AMPERE)).thenReturn(1121.); Mockito.when(raoResult.getRelativeMargin(null, cnecO, AMPERE)).thenReturn(1122.); - Mockito.when(raoResult.getLoopFlow(null, cnecO, Side.LEFT, AMPERE)).thenReturn(Double.NaN); - Mockito.when(raoResult.getLoopFlow(null, cnecO, Side.RIGHT, AMPERE)).thenReturn(1123.5); - Mockito.when(raoResult.getCommercialFlow(null, cnecO, Side.LEFT, AMPERE)).thenReturn(Double.NaN); - Mockito.when(raoResult.getCommercialFlow(null, cnecO, Side.RIGHT, AMPERE)).thenReturn(1124.5); - Mockito.when(raoResult.getFlow(preventiveInstant, cnecO, Side.LEFT, MEGAWATT)).thenReturn(Double.NaN); - Mockito.when(raoResult.getFlow(preventiveInstant, cnecO, Side.RIGHT, MEGAWATT)).thenReturn(1210.5); + Mockito.when(raoResult.getLoopFlow(null, cnecO, TwoSides.ONE, AMPERE)).thenReturn(Double.NaN); + Mockito.when(raoResult.getLoopFlow(null, cnecO, TwoSides.TWO, AMPERE)).thenReturn(1123.5); + Mockito.when(raoResult.getCommercialFlow(null, cnecO, TwoSides.ONE, AMPERE)).thenReturn(Double.NaN); + Mockito.when(raoResult.getCommercialFlow(null, cnecO, TwoSides.TWO, AMPERE)).thenReturn(1124.5); + Mockito.when(raoResult.getFlow(preventiveInstant, cnecO, TwoSides.ONE, MEGAWATT)).thenReturn(Double.NaN); + Mockito.when(raoResult.getFlow(preventiveInstant, cnecO, TwoSides.TWO, MEGAWATT)).thenReturn(1210.5); Mockito.when(raoResult.getMargin(preventiveInstant, cnecO, MEGAWATT)).thenReturn(1211.); Mockito.when(raoResult.getRelativeMargin(preventiveInstant, cnecO, MEGAWATT)).thenReturn(1212.); - Mockito.when(raoResult.getLoopFlow(preventiveInstant, cnecO, Side.LEFT, MEGAWATT)).thenReturn(Double.NaN); - Mockito.when(raoResult.getLoopFlow(preventiveInstant, cnecO, Side.RIGHT, MEGAWATT)).thenReturn(1213.5); - Mockito.when(raoResult.getCommercialFlow(preventiveInstant, cnecO, Side.LEFT, MEGAWATT)).thenReturn(Double.NaN); - Mockito.when(raoResult.getCommercialFlow(preventiveInstant, cnecO, Side.RIGHT, MEGAWATT)).thenReturn(1214.5); - Mockito.when(raoResult.getPtdfZonalSum(preventiveInstant, cnecO, Side.LEFT)).thenReturn(Double.NaN); - Mockito.when(raoResult.getPtdfZonalSum(preventiveInstant, cnecO, Side.RIGHT)).thenReturn(0.6); + Mockito.when(raoResult.getLoopFlow(preventiveInstant, cnecO, TwoSides.ONE, MEGAWATT)).thenReturn(Double.NaN); + Mockito.when(raoResult.getLoopFlow(preventiveInstant, cnecO, TwoSides.TWO, MEGAWATT)).thenReturn(1213.5); + Mockito.when(raoResult.getCommercialFlow(preventiveInstant, cnecO, TwoSides.ONE, MEGAWATT)).thenReturn(Double.NaN); + Mockito.when(raoResult.getCommercialFlow(preventiveInstant, cnecO, TwoSides.TWO, MEGAWATT)).thenReturn(1214.5); + Mockito.when(raoResult.getPtdfZonalSum(preventiveInstant, cnecO, TwoSides.ONE)).thenReturn(Double.NaN); + Mockito.when(raoResult.getPtdfZonalSum(preventiveInstant, cnecO, TwoSides.TWO)).thenReturn(0.6); // Mocking networkAction results State pState = mock(State.class); @@ -243,31 +243,31 @@ void testRaoResultClone(RaoResult raoResultClone, Crac crac) { - contains result relative margin and PTDF sum but not for loop and commercial flows */ FlowCnec cnecP = crac.getFlowCnec("cnec4prevId"); - assertEquals(4110., raoResultClone.getFlow(null, cnecP, Side.LEFT, MEGAWATT), 0.001); - assertTrue(Double.isNaN(raoResultClone.getFlow(null, cnecP, Side.RIGHT, MEGAWATT))); + assertEquals(4110., raoResultClone.getFlow(null, cnecP, TwoSides.ONE, MEGAWATT), 0.001); + assertTrue(Double.isNaN(raoResultClone.getFlow(null, cnecP, TwoSides.TWO, MEGAWATT))); assertEquals(4111., raoResultClone.getMargin(null, cnecP, MEGAWATT), 0.001); assertEquals(4112., raoResultClone.getRelativeMargin(null, cnecP, MEGAWATT), 0.001); - assertTrue(Double.isNaN(raoResultClone.getLoopFlow(null, cnecP, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(raoResultClone.getLoopFlow(null, cnecP, Side.RIGHT, MEGAWATT))); - assertTrue(Double.isNaN(raoResultClone.getCommercialFlow(null, cnecP, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(raoResultClone.getCommercialFlow(null, cnecP, Side.RIGHT, MEGAWATT))); + assertTrue(Double.isNaN(raoResultClone.getLoopFlow(null, cnecP, TwoSides.ONE, MEGAWATT))); + assertTrue(Double.isNaN(raoResultClone.getLoopFlow(null, cnecP, TwoSides.TWO, MEGAWATT))); + assertTrue(Double.isNaN(raoResultClone.getCommercialFlow(null, cnecP, TwoSides.ONE, MEGAWATT))); + assertTrue(Double.isNaN(raoResultClone.getCommercialFlow(null, cnecP, TwoSides.TWO, MEGAWATT))); - assertEquals(4220., raoResultClone.getFlow(preventiveInstant, cnecP, Side.LEFT, AMPERE), 0.001); - assertTrue(Double.isNaN(raoResultClone.getFlow(preventiveInstant, cnecP, Side.RIGHT, AMPERE))); + assertEquals(4220., raoResultClone.getFlow(preventiveInstant, cnecP, TwoSides.ONE, AMPERE), 0.001); + assertTrue(Double.isNaN(raoResultClone.getFlow(preventiveInstant, cnecP, TwoSides.TWO, AMPERE))); assertEquals(4221., raoResultClone.getMargin(preventiveInstant, cnecP, AMPERE), 0.001); assertEquals(4222., raoResultClone.getRelativeMargin(preventiveInstant, cnecP, AMPERE), 0.001); - assertTrue(Double.isNaN(raoResultClone.getLoopFlow(null, cnecP, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(raoResultClone.getLoopFlow(null, cnecP, Side.RIGHT, MEGAWATT))); - assertTrue(Double.isNaN(raoResultClone.getCommercialFlow(null, cnecP, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(raoResultClone.getCommercialFlow(null, cnecP, Side.RIGHT, MEGAWATT))); + assertTrue(Double.isNaN(raoResultClone.getLoopFlow(null, cnecP, TwoSides.ONE, MEGAWATT))); + assertTrue(Double.isNaN(raoResultClone.getLoopFlow(null, cnecP, TwoSides.TWO, MEGAWATT))); + assertTrue(Double.isNaN(raoResultClone.getCommercialFlow(null, cnecP, TwoSides.ONE, MEGAWATT))); + assertTrue(Double.isNaN(raoResultClone.getCommercialFlow(null, cnecP, TwoSides.TWO, MEGAWATT))); - assertEquals(0.4, raoResultClone.getPtdfZonalSum(preventiveInstant, cnecP, Side.LEFT), 0.001); - assertTrue(Double.isNaN(raoResultClone.getPtdfZonalSum(preventiveInstant, cnecP, Side.RIGHT))); + assertEquals(0.4, raoResultClone.getPtdfZonalSum(preventiveInstant, cnecP, TwoSides.ONE), 0.001); + assertTrue(Double.isNaN(raoResultClone.getPtdfZonalSum(preventiveInstant, cnecP, TwoSides.TWO))); - assertEquals(raoResultClone.getFlow(autoInstant, cnecP, LEFT, AMPERE), raoResultClone.getFlow(preventiveInstant, cnecP, LEFT, AMPERE), 0.001); - assertEquals(raoResultClone.getFlow(autoInstant, cnecP, RIGHT, AMPERE), raoResultClone.getFlow(preventiveInstant, cnecP, RIGHT, AMPERE), 0.001); - assertEquals(raoResultClone.getFlow(curativeInstant, cnecP, LEFT, AMPERE), raoResultClone.getFlow(preventiveInstant, cnecP, LEFT, AMPERE), 0.001); - assertEquals(raoResultClone.getFlow(curativeInstant, cnecP, RIGHT, AMPERE), raoResultClone.getFlow(preventiveInstant, cnecP, RIGHT, AMPERE), 0.001); + assertEquals(raoResultClone.getFlow(autoInstant, cnecP, ONE, AMPERE), raoResultClone.getFlow(preventiveInstant, cnecP, ONE, AMPERE), 0.001); + assertEquals(raoResultClone.getFlow(autoInstant, cnecP, TWO, AMPERE), raoResultClone.getFlow(preventiveInstant, cnecP, TWO, AMPERE), 0.001); + assertEquals(raoResultClone.getFlow(curativeInstant, cnecP, ONE, AMPERE), raoResultClone.getFlow(preventiveInstant, cnecP, ONE, AMPERE), 0.001); + assertEquals(raoResultClone.getFlow(curativeInstant, cnecP, TWO, AMPERE), raoResultClone.getFlow(preventiveInstant, cnecP, TWO, AMPERE), 0.001); /* cnec1outageId: outage, with loop-flows, optimized @@ -276,26 +276,26 @@ void testRaoResultClone(RaoResult raoResultClone, Crac crac) { */ FlowCnec cnecO = crac.getFlowCnec("cnec1outageId"); - assertTrue(Double.isNaN(raoResultClone.getFlow(null, cnecO, Side.LEFT, AMPERE))); - assertEquals(1120.5, raoResultClone.getFlow(null, cnecO, Side.RIGHT, AMPERE), 0.001); + assertTrue(Double.isNaN(raoResultClone.getFlow(null, cnecO, TwoSides.ONE, AMPERE))); + assertEquals(1120.5, raoResultClone.getFlow(null, cnecO, TwoSides.TWO, AMPERE), 0.001); assertEquals(1121., raoResultClone.getMargin(null, cnecO, AMPERE), 0.001); assertEquals(1122., raoResultClone.getRelativeMargin(null, cnecO, AMPERE), 0.001); - assertTrue(Double.isNaN(raoResultClone.getLoopFlow(null, cnecO, Side.LEFT, AMPERE))); - assertEquals(1123.5, raoResultClone.getLoopFlow(null, cnecO, Side.RIGHT, AMPERE), 0.001); - assertTrue(Double.isNaN(raoResultClone.getCommercialFlow(null, cnecO, Side.LEFT, AMPERE))); - assertEquals(1124.5, raoResultClone.getCommercialFlow(null, cnecO, Side.RIGHT, AMPERE), 0.001); + assertTrue(Double.isNaN(raoResultClone.getLoopFlow(null, cnecO, TwoSides.ONE, AMPERE))); + assertEquals(1123.5, raoResultClone.getLoopFlow(null, cnecO, TwoSides.TWO, AMPERE), 0.001); + assertTrue(Double.isNaN(raoResultClone.getCommercialFlow(null, cnecO, TwoSides.ONE, AMPERE))); + assertEquals(1124.5, raoResultClone.getCommercialFlow(null, cnecO, TwoSides.TWO, AMPERE), 0.001); - assertTrue(Double.isNaN(raoResultClone.getFlow(preventiveInstant, cnecO, Side.LEFT, MEGAWATT))); - assertEquals(1210.5, raoResultClone.getFlow(preventiveInstant, cnecO, Side.RIGHT, MEGAWATT), 0.001); + assertTrue(Double.isNaN(raoResultClone.getFlow(preventiveInstant, cnecO, TwoSides.ONE, MEGAWATT))); + assertEquals(1210.5, raoResultClone.getFlow(preventiveInstant, cnecO, TwoSides.TWO, MEGAWATT), 0.001); assertEquals(1211., raoResultClone.getMargin(preventiveInstant, cnecO, MEGAWATT), 0.001); assertEquals(1212., raoResultClone.getRelativeMargin(preventiveInstant, cnecO, MEGAWATT), 0.001); - assertTrue(Double.isNaN(raoResultClone.getLoopFlow(preventiveInstant, cnecO, Side.LEFT, MEGAWATT))); - assertEquals(1213.5, raoResultClone.getLoopFlow(preventiveInstant, cnecO, Side.RIGHT, MEGAWATT), 0.001); - assertTrue(Double.isNaN(raoResultClone.getCommercialFlow(preventiveInstant, cnecO, Side.LEFT, MEGAWATT))); - assertEquals(1214.5, raoResultClone.getCommercialFlow(preventiveInstant, cnecO, Side.RIGHT, MEGAWATT), 0.001); + assertTrue(Double.isNaN(raoResultClone.getLoopFlow(preventiveInstant, cnecO, TwoSides.ONE, MEGAWATT))); + assertEquals(1213.5, raoResultClone.getLoopFlow(preventiveInstant, cnecO, TwoSides.TWO, MEGAWATT), 0.001); + assertTrue(Double.isNaN(raoResultClone.getCommercialFlow(preventiveInstant, cnecO, TwoSides.ONE, MEGAWATT))); + assertEquals(1214.5, raoResultClone.getCommercialFlow(preventiveInstant, cnecO, TwoSides.TWO, MEGAWATT), 0.001); - assertTrue(Double.isNaN(raoResultClone.getPtdfZonalSum(preventiveInstant, cnecO, Side.LEFT))); - assertEquals(0.6, raoResultClone.getPtdfZonalSum(preventiveInstant, cnecO, Side.RIGHT), 0.001); + assertTrue(Double.isNaN(raoResultClone.getPtdfZonalSum(preventiveInstant, cnecO, TwoSides.ONE))); + assertEquals(0.6, raoResultClone.getPtdfZonalSum(preventiveInstant, cnecO, TwoSides.TWO), 0.001); // ----------------------------- // --- NetworkAction results --- diff --git a/data/rao-result/rao-result-impl/src/main/java/com/powsybl/openrao/data/raoresultimpl/ElementaryFlowCnecResult.java b/data/rao-result/rao-result-impl/src/main/java/com/powsybl/openrao/data/raoresultimpl/ElementaryFlowCnecResult.java index ea2243b0e3..06e19d832d 100644 --- a/data/rao-result/rao-result-impl/src/main/java/com/powsybl/openrao/data/raoresultimpl/ElementaryFlowCnecResult.java +++ b/data/rao-result/rao-result-impl/src/main/java/com/powsybl/openrao/data/raoresultimpl/ElementaryFlowCnecResult.java @@ -9,7 +9,7 @@ import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.commons.PhysicalParameter; import com.powsybl.openrao.commons.Unit; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import java.util.EnumMap; import java.util.Map; @@ -22,22 +22,22 @@ public class ElementaryFlowCnecResult { private static final FlowCnecResultPerUnit DEFAULT_RESULT = new FlowCnecResultPerUnit(); private final Map resultPerUnit; - private final Map ptdfZonalSum; + private final Map ptdfZonalSum; private static class FlowCnecResultPerUnit { - private final Map flow = new EnumMap<>(Map.of(Side.LEFT, Double.NaN, Side.RIGHT, Double.NaN)); + private final Map flow = new EnumMap<>(Map.of(TwoSides.ONE, Double.NaN, TwoSides.TWO, Double.NaN)); private double margin = Double.NaN; private double relativeMargin = Double.NaN; - private final Map loopFlow = new EnumMap<>(Map.of(Side.LEFT, Double.NaN, Side.RIGHT, Double.NaN)); - private final Map commercialFlow = new EnumMap<>(Map.of(Side.LEFT, Double.NaN, Side.RIGHT, Double.NaN)); + private final Map loopFlow = new EnumMap<>(Map.of(TwoSides.ONE, Double.NaN, TwoSides.TWO, Double.NaN)); + private final Map commercialFlow = new EnumMap<>(Map.of(TwoSides.ONE, Double.NaN, TwoSides.TWO, Double.NaN)); } ElementaryFlowCnecResult() { this.resultPerUnit = new EnumMap<>(Unit.class); - this.ptdfZonalSum = new EnumMap<>(Map.of(Side.LEFT, Double.NaN, Side.RIGHT, Double.NaN)); + this.ptdfZonalSum = new EnumMap<>(Map.of(TwoSides.ONE, Double.NaN, TwoSides.TWO, Double.NaN)); } - public double getFlow(Side side, Unit unit) { + public double getFlow(TwoSides side, Unit unit) { if (!resultPerUnit.containsKey(unit)) { return DEFAULT_RESULT.flow.get(side); } @@ -52,25 +52,25 @@ public double getRelativeMargin(Unit unit) { return resultPerUnit.getOrDefault(unit, DEFAULT_RESULT).relativeMargin; } - public double getLoopFlow(Side side, Unit unit) { + public double getLoopFlow(TwoSides side, Unit unit) { if (!resultPerUnit.containsKey(unit)) { return DEFAULT_RESULT.loopFlow.get(side); } return resultPerUnit.get(unit).loopFlow.getOrDefault(side, DEFAULT_RESULT.loopFlow.get(side)); } - public double getCommercialFlow(Side side, Unit unit) { + public double getCommercialFlow(TwoSides side, Unit unit) { if (!resultPerUnit.containsKey(unit)) { return DEFAULT_RESULT.commercialFlow.get(side); } return resultPerUnit.get(unit).commercialFlow.getOrDefault(side, DEFAULT_RESULT.commercialFlow.get(side)); } - public double getPtdfZonalSum(Side side) { + public double getPtdfZonalSum(TwoSides side) { return ptdfZonalSum.get(side); } - public void setFlow(Side side, double flow, Unit unit) { + public void setFlow(TwoSides side, double flow, Unit unit) { setMapForUnitIfNecessary(unit); resultPerUnit.get(unit).flow.put(side, flow); } @@ -85,17 +85,17 @@ public void setRelativeMargin(double relativeMargin, Unit unit) { resultPerUnit.get(unit).relativeMargin = relativeMargin; } - public void setLoopFlow(Side side, double loopFlow, Unit unit) { + public void setLoopFlow(TwoSides side, double loopFlow, Unit unit) { setMapForUnitIfNecessary(unit); resultPerUnit.get(unit).loopFlow.put(side, loopFlow); } - public void setCommercialFlow(Side side, double commercialFlow, Unit unit) { + public void setCommercialFlow(TwoSides side, double commercialFlow, Unit unit) { setMapForUnitIfNecessary(unit); resultPerUnit.get(unit).commercialFlow.put(side, commercialFlow); } - public void setPtdfZonalSum(Side side, double ptdfZonalSum) { + public void setPtdfZonalSum(TwoSides side, double ptdfZonalSum) { this.ptdfZonalSum.put(side, ptdfZonalSum); } diff --git a/data/rao-result/rao-result-impl/src/main/java/com/powsybl/openrao/data/raoresultimpl/RaoResultImpl.java b/data/rao-result/rao-result-impl/src/main/java/com/powsybl/openrao/data/raoresultimpl/RaoResultImpl.java index 5d44e027fb..6bca73c5e4 100644 --- a/data/rao-result/rao-result-impl/src/main/java/com/powsybl/openrao/data/raoresultimpl/RaoResultImpl.java +++ b/data/rao-result/rao-result-impl/src/main/java/com/powsybl/openrao/data/raoresultimpl/RaoResultImpl.java @@ -12,7 +12,7 @@ import com.powsybl.openrao.data.cracapi.*; import com.powsybl.openrao.data.cracapi.cnec.AngleCnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.cnec.VoltageCnec; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; @@ -87,7 +87,7 @@ private Instant checkOptimizedInstant(Instant optimizedInstant, FlowCnec flowCne } @Override - public double getFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit) { + public double getFlow(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side, Unit unit) { return flowCnecResults.getOrDefault(flowCnec, DEFAULT_FLOWCNEC_RESULT).getResult(checkOptimizedInstant(optimizedInstant, flowCnec)).getFlow(side, unit); } @@ -122,17 +122,17 @@ public double getRelativeMargin(Instant optimizedInstant, FlowCnec flowCnec, Uni } @Override - public double getLoopFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit) { + public double getLoopFlow(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side, Unit unit) { return flowCnecResults.getOrDefault(flowCnec, DEFAULT_FLOWCNEC_RESULT).getResult(checkOptimizedInstant(optimizedInstant, flowCnec)).getLoopFlow(side, unit); } @Override - public double getCommercialFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit) { + public double getCommercialFlow(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side, Unit unit) { return flowCnecResults.getOrDefault(flowCnec, DEFAULT_FLOWCNEC_RESULT).getResult(checkOptimizedInstant(optimizedInstant, flowCnec)).getCommercialFlow(side, unit); } @Override - public double getPtdfZonalSum(Instant optimizedInstant, FlowCnec flowCnec, Side side) { + public double getPtdfZonalSum(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side) { return flowCnecResults.getOrDefault(flowCnec, DEFAULT_FLOWCNEC_RESULT).getResult(checkOptimizedInstant(optimizedInstant, flowCnec)).getPtdfZonalSum(side); } diff --git a/data/rao-result/rao-result-impl/src/test/java/com/powsybl/openrao/data/raoresultimpl/ElementaryFlowCnecResultTest.java b/data/rao-result/rao-result-impl/src/test/java/com/powsybl/openrao/data/raoresultimpl/ElementaryFlowCnecResultTest.java index 192c5b02f9..d3dd461434 100644 --- a/data/rao-result/rao-result-impl/src/test/java/com/powsybl/openrao/data/raoresultimpl/ElementaryFlowCnecResultTest.java +++ b/data/rao-result/rao-result-impl/src/test/java/com/powsybl/openrao/data/raoresultimpl/ElementaryFlowCnecResultTest.java @@ -8,7 +8,7 @@ import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.commons.Unit; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -24,7 +24,7 @@ private void assertMarginsAreNan(ElementaryFlowCnecResult elementaryFlowCnecResu assertEquals(Double.NaN, elementaryFlowCnecResult.getRelativeMargin(unit), 1e-3); } - private void assertFlowsAreNan(ElementaryFlowCnecResult elementaryFlowCnecResult, Unit unit, Side side) { + private void assertFlowsAreNan(ElementaryFlowCnecResult elementaryFlowCnecResult, Unit unit, TwoSides side) { assertEquals(Double.NaN, elementaryFlowCnecResult.getFlow(side, unit), 1e-3); assertEquals(Double.NaN, elementaryFlowCnecResult.getCommercialFlow(side, unit), 1e-3); assertEquals(Double.NaN, elementaryFlowCnecResult.getLoopFlow(side, unit), 1e-3); @@ -37,13 +37,13 @@ void defaultValuesTest() { assertMarginsAreNan(elementaryFlowCnecResult, Unit.MEGAWATT); assertMarginsAreNan(elementaryFlowCnecResult, Unit.AMPERE); - assertFlowsAreNan(elementaryFlowCnecResult, Unit.MEGAWATT, Side.LEFT); - assertFlowsAreNan(elementaryFlowCnecResult, Unit.MEGAWATT, Side.RIGHT); - assertFlowsAreNan(elementaryFlowCnecResult, Unit.AMPERE, Side.LEFT); - assertFlowsAreNan(elementaryFlowCnecResult, Unit.AMPERE, Side.RIGHT); + assertFlowsAreNan(elementaryFlowCnecResult, Unit.MEGAWATT, TwoSides.ONE); + assertFlowsAreNan(elementaryFlowCnecResult, Unit.MEGAWATT, TwoSides.TWO); + assertFlowsAreNan(elementaryFlowCnecResult, Unit.AMPERE, TwoSides.ONE); + assertFlowsAreNan(elementaryFlowCnecResult, Unit.AMPERE, TwoSides.TWO); - assertEquals(Double.NaN, elementaryFlowCnecResult.getPtdfZonalSum(Side.LEFT), 1e-3); - assertEquals(Double.NaN, elementaryFlowCnecResult.getPtdfZonalSum(Side.RIGHT), 1e-3); + assertEquals(Double.NaN, elementaryFlowCnecResult.getPtdfZonalSum(TwoSides.ONE), 1e-3); + assertEquals(Double.NaN, elementaryFlowCnecResult.getPtdfZonalSum(TwoSides.TWO), 1e-3); } @Test @@ -61,42 +61,42 @@ void getterAndSetters() { assertEquals(202, elementaryFlowCnecResult.getRelativeMargin(Unit.AMPERE), 1e-3); // Per side - elementaryFlowCnecResult.setPtdfZonalSum(Side.LEFT, 1); - elementaryFlowCnecResult.setPtdfZonalSum(Side.RIGHT, 2); - assertEquals(1, elementaryFlowCnecResult.getPtdfZonalSum(Side.LEFT), 1e-3); - assertEquals(2, elementaryFlowCnecResult.getPtdfZonalSum(Side.RIGHT), 1e-3); + elementaryFlowCnecResult.setPtdfZonalSum(TwoSides.ONE, 1); + elementaryFlowCnecResult.setPtdfZonalSum(TwoSides.TWO, 2); + assertEquals(1, elementaryFlowCnecResult.getPtdfZonalSum(TwoSides.ONE), 1e-3); + assertEquals(2, elementaryFlowCnecResult.getPtdfZonalSum(TwoSides.TWO), 1e-3); // Per unit per side - elementaryFlowCnecResult.setFlow(Side.LEFT, 100, Unit.MEGAWATT); - elementaryFlowCnecResult.setCommercialFlow(Side.LEFT, 103, Unit.MEGAWATT); - elementaryFlowCnecResult.setLoopFlow(Side.LEFT, 104, Unit.MEGAWATT); - elementaryFlowCnecResult.setFlow(Side.RIGHT, 105, Unit.MEGAWATT); - elementaryFlowCnecResult.setCommercialFlow(Side.RIGHT, 106, Unit.MEGAWATT); - elementaryFlowCnecResult.setLoopFlow(Side.RIGHT, 107, Unit.MEGAWATT); - assertEquals(100, elementaryFlowCnecResult.getFlow(Side.LEFT, Unit.MEGAWATT), 1e-3); - assertEquals(103, elementaryFlowCnecResult.getCommercialFlow(Side.LEFT, Unit.MEGAWATT), 1e-3); - assertEquals(104, elementaryFlowCnecResult.getLoopFlow(Side.LEFT, Unit.MEGAWATT), 1e-3); - assertEquals(105, elementaryFlowCnecResult.getFlow(Side.RIGHT, Unit.MEGAWATT), 1e-3); - assertEquals(106, elementaryFlowCnecResult.getCommercialFlow(Side.RIGHT, Unit.MEGAWATT), 1e-3); - assertEquals(107, elementaryFlowCnecResult.getLoopFlow(Side.RIGHT, Unit.MEGAWATT), 1e-3); + elementaryFlowCnecResult.setFlow(TwoSides.ONE, 100, Unit.MEGAWATT); + elementaryFlowCnecResult.setCommercialFlow(TwoSides.ONE, 103, Unit.MEGAWATT); + elementaryFlowCnecResult.setLoopFlow(TwoSides.ONE, 104, Unit.MEGAWATT); + elementaryFlowCnecResult.setFlow(TwoSides.TWO, 105, Unit.MEGAWATT); + elementaryFlowCnecResult.setCommercialFlow(TwoSides.TWO, 106, Unit.MEGAWATT); + elementaryFlowCnecResult.setLoopFlow(TwoSides.TWO, 107, Unit.MEGAWATT); + assertEquals(100, elementaryFlowCnecResult.getFlow(TwoSides.ONE, Unit.MEGAWATT), 1e-3); + assertEquals(103, elementaryFlowCnecResult.getCommercialFlow(TwoSides.ONE, Unit.MEGAWATT), 1e-3); + assertEquals(104, elementaryFlowCnecResult.getLoopFlow(TwoSides.ONE, Unit.MEGAWATT), 1e-3); + assertEquals(105, elementaryFlowCnecResult.getFlow(TwoSides.TWO, Unit.MEGAWATT), 1e-3); + assertEquals(106, elementaryFlowCnecResult.getCommercialFlow(TwoSides.TWO, Unit.MEGAWATT), 1e-3); + assertEquals(107, elementaryFlowCnecResult.getLoopFlow(TwoSides.TWO, Unit.MEGAWATT), 1e-3); - elementaryFlowCnecResult.setFlow(Side.LEFT, 200, Unit.AMPERE); - elementaryFlowCnecResult.setCommercialFlow(Side.LEFT, 203, Unit.AMPERE); - elementaryFlowCnecResult.setLoopFlow(Side.LEFT, 204, Unit.AMPERE); - elementaryFlowCnecResult.setFlow(Side.RIGHT, 205, Unit.AMPERE); - elementaryFlowCnecResult.setCommercialFlow(Side.RIGHT, 206, Unit.AMPERE); - elementaryFlowCnecResult.setLoopFlow(Side.RIGHT, 207, Unit.AMPERE); - assertEquals(200, elementaryFlowCnecResult.getFlow(Side.LEFT, Unit.AMPERE), 1e-3); - assertEquals(203, elementaryFlowCnecResult.getCommercialFlow(Side.LEFT, Unit.AMPERE), 1e-3); - assertEquals(204, elementaryFlowCnecResult.getLoopFlow(Side.LEFT, Unit.AMPERE), 1e-3); - assertEquals(205, elementaryFlowCnecResult.getFlow(Side.RIGHT, Unit.AMPERE), 1e-3); - assertEquals(206, elementaryFlowCnecResult.getCommercialFlow(Side.RIGHT, Unit.AMPERE), 1e-3); - assertEquals(207, elementaryFlowCnecResult.getLoopFlow(Side.RIGHT, Unit.AMPERE), 1e-3); + elementaryFlowCnecResult.setFlow(TwoSides.ONE, 200, Unit.AMPERE); + elementaryFlowCnecResult.setCommercialFlow(TwoSides.ONE, 203, Unit.AMPERE); + elementaryFlowCnecResult.setLoopFlow(TwoSides.ONE, 204, Unit.AMPERE); + elementaryFlowCnecResult.setFlow(TwoSides.TWO, 205, Unit.AMPERE); + elementaryFlowCnecResult.setCommercialFlow(TwoSides.TWO, 206, Unit.AMPERE); + elementaryFlowCnecResult.setLoopFlow(TwoSides.TWO, 207, Unit.AMPERE); + assertEquals(200, elementaryFlowCnecResult.getFlow(TwoSides.ONE, Unit.AMPERE), 1e-3); + assertEquals(203, elementaryFlowCnecResult.getCommercialFlow(TwoSides.ONE, Unit.AMPERE), 1e-3); + assertEquals(204, elementaryFlowCnecResult.getLoopFlow(TwoSides.ONE, Unit.AMPERE), 1e-3); + assertEquals(205, elementaryFlowCnecResult.getFlow(TwoSides.TWO, Unit.AMPERE), 1e-3); + assertEquals(206, elementaryFlowCnecResult.getCommercialFlow(TwoSides.TWO, Unit.AMPERE), 1e-3); + assertEquals(207, elementaryFlowCnecResult.getLoopFlow(TwoSides.TWO, Unit.AMPERE), 1e-3); } @Test void notAFlowUnitTest() { ElementaryFlowCnecResult elementaryFlowCnecResult = new ElementaryFlowCnecResult(); - assertThrows(OpenRaoException.class, () -> elementaryFlowCnecResult.setLoopFlow(Side.RIGHT, 100, Unit.KILOVOLT)); + assertThrows(OpenRaoException.class, () -> elementaryFlowCnecResult.setLoopFlow(TwoSides.TWO, 100, Unit.KILOVOLT)); } } diff --git a/data/rao-result/rao-result-impl/src/test/java/com/powsybl/openrao/data/raoresultimpl/FlowCnecResultTest.java b/data/rao-result/rao-result-impl/src/test/java/com/powsybl/openrao/data/raoresultimpl/FlowCnecResultTest.java index a805ce71a8..13008c488e 100644 --- a/data/rao-result/rao-result-impl/src/test/java/com/powsybl/openrao/data/raoresultimpl/FlowCnecResultTest.java +++ b/data/rao-result/rao-result-impl/src/test/java/com/powsybl/openrao/data/raoresultimpl/FlowCnecResultTest.java @@ -8,7 +8,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.Instant; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -24,27 +24,27 @@ void defaultValuesTest() { Instant preventiveInstant = mock(Instant.class); Instant curativeInstant = mock(Instant.class); FlowCnecResult defaultFlowCnecResult = new FlowCnecResult(); - assertEquals(Double.NaN, defaultFlowCnecResult.getResult(null).getCommercialFlow(Side.LEFT, Unit.MEGAWATT), 1e-3); - assertEquals(Double.NaN, defaultFlowCnecResult.getResult(null).getFlow(Side.RIGHT, Unit.AMPERE), 1e-3); + assertEquals(Double.NaN, defaultFlowCnecResult.getResult(null).getCommercialFlow(TwoSides.ONE, Unit.MEGAWATT), 1e-3); + assertEquals(Double.NaN, defaultFlowCnecResult.getResult(null).getFlow(TwoSides.TWO, Unit.AMPERE), 1e-3); assertEquals(Double.NaN, defaultFlowCnecResult.getResult(preventiveInstant).getMargin(Unit.MEGAWATT), 1e-3); assertEquals(Double.NaN, defaultFlowCnecResult.getResult(preventiveInstant).getRelativeMargin(Unit.AMPERE), 1e-3); - assertEquals(Double.NaN, defaultFlowCnecResult.getResult(curativeInstant).getLoopFlow(Side.LEFT, Unit.MEGAWATT), 1e-3); - assertEquals(Double.NaN, defaultFlowCnecResult.getResult(curativeInstant).getPtdfZonalSum(Side.RIGHT), 1e-3); + assertEquals(Double.NaN, defaultFlowCnecResult.getResult(curativeInstant).getLoopFlow(TwoSides.ONE, Unit.MEGAWATT), 1e-3); + assertEquals(Double.NaN, defaultFlowCnecResult.getResult(curativeInstant).getPtdfZonalSum(TwoSides.TWO), 1e-3); } @Test void testGetAndCreateIfAbsent() { FlowCnecResult flowCnecResult = new FlowCnecResult(); - assertEquals(Double.NaN, flowCnecResult.getResult(null).getFlow(Side.LEFT, Unit.MEGAWATT)); - assertEquals(Double.NaN, flowCnecResult.getResult(null).getFlow(Side.RIGHT, Unit.MEGAWATT)); + assertEquals(Double.NaN, flowCnecResult.getResult(null).getFlow(TwoSides.ONE, Unit.MEGAWATT)); + assertEquals(Double.NaN, flowCnecResult.getResult(null).getFlow(TwoSides.TWO, Unit.MEGAWATT)); - flowCnecResult.getAndCreateIfAbsentResultForOptimizationState(null).setFlow(Side.LEFT, 100., Unit.MEGAWATT); - assertEquals(100., flowCnecResult.getResult(null).getFlow(Side.LEFT, Unit.MEGAWATT), 1e-3); - assertEquals(Double.NaN, flowCnecResult.getResult(null).getFlow(Side.RIGHT, Unit.MEGAWATT)); + flowCnecResult.getAndCreateIfAbsentResultForOptimizationState(null).setFlow(TwoSides.ONE, 100., Unit.MEGAWATT); + assertEquals(100., flowCnecResult.getResult(null).getFlow(TwoSides.ONE, Unit.MEGAWATT), 1e-3); + assertEquals(Double.NaN, flowCnecResult.getResult(null).getFlow(TwoSides.TWO, Unit.MEGAWATT)); flowCnecResult.getAndCreateIfAbsentResultForOptimizationState(null).setMargin(150., Unit.MEGAWATT); - assertEquals(100., flowCnecResult.getResult(null).getFlow(Side.LEFT, Unit.MEGAWATT), 1e-3); - assertEquals(Double.NaN, flowCnecResult.getResult(null).getFlow(Side.RIGHT, Unit.MEGAWATT)); + assertEquals(100., flowCnecResult.getResult(null).getFlow(TwoSides.ONE, Unit.MEGAWATT), 1e-3); + assertEquals(Double.NaN, flowCnecResult.getResult(null).getFlow(TwoSides.TWO, Unit.MEGAWATT)); assertEquals(150., flowCnecResult.getResult(null).getMargin(Unit.MEGAWATT), 1e-3); assertEquals(Double.NaN, flowCnecResult.getResult(null).getMargin(Unit.AMPERE), 1e-3); } diff --git a/data/rao-result/rao-result-impl/src/test/java/com/powsybl/openrao/data/raoresultimpl/RangeActionResultTest.java b/data/rao-result/rao-result-impl/src/test/java/com/powsybl/openrao/data/raoresultimpl/RangeActionResultTest.java index 153bec909a..ba5b7e4a61 100644 --- a/data/rao-result/rao-result-impl/src/test/java/com/powsybl/openrao/data/raoresultimpl/RangeActionResultTest.java +++ b/data/rao-result/rao-result-impl/src/test/java/com/powsybl/openrao/data/raoresultimpl/RangeActionResultTest.java @@ -9,7 +9,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.Instant; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracimpl.utils.CommonCracCreation; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -42,7 +42,7 @@ public void setUp() { .withNetworkElement("anyNetworkElement") .withContingency("Contingency FR1 FR2") .withInstant(OUTAGE_INSTANT_ID) - .newThreshold().withSide(Side.LEFT).withUnit(Unit.MEGAWATT).withMax(1000.).add() + .newThreshold().withSide(TwoSides.ONE).withUnit(Unit.MEGAWATT).withMax(1000.).add() .add(); crac.newFlowCnec() @@ -50,7 +50,7 @@ public void setUp() { .withNetworkElement("anyNetworkElement") .withContingency("Contingency FR1 FR3") .withInstant(OUTAGE_INSTANT_ID) - .newThreshold().withSide(Side.LEFT).withUnit(Unit.MEGAWATT).withMax(1000.).add() + .newThreshold().withSide(TwoSides.ONE).withUnit(Unit.MEGAWATT).withMax(1000.).add() .add(); } @@ -154,7 +154,7 @@ void pstActivatedInPreventiveAndAutoAndCurative() { // Add dummy flow cnec to create auto state crac.newFlowCnec().withId("dummy").withContingency("Contingency FR1 FR2").withInstant(AUTO_INSTANT_ID).withNetworkElement("ne") - .newThreshold().withMax(1.).withSide(Side.LEFT).withUnit(Unit.MEGAWATT).add() + .newThreshold().withMax(1.).withSide(TwoSides.ONE).withUnit(Unit.MEGAWATT).add() .add(); rangeActionResult.setInitialSetpoint(0.3); diff --git a/data/rao-result/rao-result-impl/src/test/java/com/powsybl/openrao/data/raoresultimpl/RaoResultImplTest.java b/data/rao-result/rao-result-impl/src/test/java/com/powsybl/openrao/data/raoresultimpl/RaoResultImplTest.java index 2529bebf41..2b4d880047 100644 --- a/data/rao-result/rao-result-impl/src/test/java/com/powsybl/openrao/data/raoresultimpl/RaoResultImplTest.java +++ b/data/rao-result/rao-result-impl/src/test/java/com/powsybl/openrao/data/raoresultimpl/RaoResultImplTest.java @@ -14,7 +14,7 @@ import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.AngleCnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.cnec.VoltageCnec; import com.powsybl.openrao.data.cracapi.networkaction.ActionType; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; @@ -75,34 +75,34 @@ private void setUp() { flowCnecResult.getAndCreateIfAbsentResultForOptimizationState(null); ElementaryFlowCnecResult elementaryFlowCnecResult = flowCnecResult.getResult(null); - elementaryFlowCnecResult.setFlow(Side.LEFT, 100., MEGAWATT); + elementaryFlowCnecResult.setFlow(TwoSides.ONE, 100., MEGAWATT); elementaryFlowCnecResult.setMargin(101., MEGAWATT); elementaryFlowCnecResult.setRelativeMargin(102., MEGAWATT); - elementaryFlowCnecResult.setLoopFlow(Side.LEFT, 103., MEGAWATT); - elementaryFlowCnecResult.setCommercialFlow(Side.LEFT, 104., MEGAWATT); + elementaryFlowCnecResult.setLoopFlow(TwoSides.ONE, 103., MEGAWATT); + elementaryFlowCnecResult.setCommercialFlow(TwoSides.ONE, 104., MEGAWATT); - elementaryFlowCnecResult.setFlow(Side.LEFT, 110., AMPERE); + elementaryFlowCnecResult.setFlow(TwoSides.ONE, 110., AMPERE); elementaryFlowCnecResult.setMargin(111., AMPERE); elementaryFlowCnecResult.setRelativeMargin(112., AMPERE); - elementaryFlowCnecResult.setLoopFlow(Side.LEFT, 113., AMPERE); - elementaryFlowCnecResult.setCommercialFlow(Side.LEFT, 114., AMPERE); + elementaryFlowCnecResult.setLoopFlow(TwoSides.ONE, 113., AMPERE); + elementaryFlowCnecResult.setCommercialFlow(TwoSides.ONE, 114., AMPERE); - elementaryFlowCnecResult.setPtdfZonalSum(Side.LEFT, 0.1); + elementaryFlowCnecResult.setPtdfZonalSum(TwoSides.ONE, 0.1); flowCnecResult.getAndCreateIfAbsentResultForOptimizationState(preventiveInstant); elementaryFlowCnecResult = flowCnecResult.getResult(preventiveInstant); - elementaryFlowCnecResult.setFlow(Side.LEFT, 200., MEGAWATT); + elementaryFlowCnecResult.setFlow(TwoSides.ONE, 200., MEGAWATT); elementaryFlowCnecResult.setMargin(201., MEGAWATT); elementaryFlowCnecResult.setRelativeMargin(202., MEGAWATT); - elementaryFlowCnecResult.setLoopFlow(Side.LEFT, 203., MEGAWATT); + elementaryFlowCnecResult.setLoopFlow(TwoSides.ONE, 203., MEGAWATT); - elementaryFlowCnecResult.setFlow(Side.LEFT, 210., AMPERE); + elementaryFlowCnecResult.setFlow(TwoSides.ONE, 210., AMPERE); elementaryFlowCnecResult.setMargin(211., AMPERE); elementaryFlowCnecResult.setRelativeMargin(212., AMPERE); - elementaryFlowCnecResult.setLoopFlow(Side.LEFT, 213., AMPERE); + elementaryFlowCnecResult.setLoopFlow(TwoSides.ONE, 213., AMPERE); - elementaryFlowCnecResult.setPtdfZonalSum(Side.LEFT, 0.1); + elementaryFlowCnecResult.setPtdfZonalSum(TwoSides.ONE, 0.1); raoResult.getAndCreateIfAbsentNetworkActionResult(na).addActivationForState(crac.getState("Contingency FR1 FR3", autoInstant)); raoResult.getAndCreateIfAbsentNetworkActionResult(na).addActivationForState(crac.getState("Contingency FR1 FR2", curativeInstant)); @@ -125,38 +125,38 @@ private void setUp() { } private void getResultAtAGivenState(Instant optimizedInstant) { - assertEquals(200., raoResult.getFlow(optimizedInstant, cnec, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(200., raoResult.getFlow(optimizedInstant, cnec, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(201., raoResult.getMargin(optimizedInstant, cnec, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(202., raoResult.getRelativeMargin(optimizedInstant, cnec, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(203., raoResult.getLoopFlow(optimizedInstant, cnec, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(raoResult.getCommercialFlow(optimizedInstant, cnec, Side.LEFT, MEGAWATT))); + assertEquals(203., raoResult.getLoopFlow(optimizedInstant, cnec, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getCommercialFlow(optimizedInstant, cnec, TwoSides.ONE, MEGAWATT))); - assertEquals(210., raoResult.getFlow(optimizedInstant, cnec, Side.LEFT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(210., raoResult.getFlow(optimizedInstant, cnec, TwoSides.ONE, AMPERE), DOUBLE_TOLERANCE); assertEquals(211., raoResult.getMargin(optimizedInstant, cnec, AMPERE), DOUBLE_TOLERANCE); assertEquals(212., raoResult.getRelativeMargin(optimizedInstant, cnec, AMPERE), DOUBLE_TOLERANCE); - assertEquals(213., raoResult.getLoopFlow(optimizedInstant, cnec, Side.LEFT, AMPERE), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(raoResult.getCommercialFlow(optimizedInstant, cnec, Side.LEFT, AMPERE))); + assertEquals(213., raoResult.getLoopFlow(optimizedInstant, cnec, TwoSides.ONE, AMPERE), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getCommercialFlow(optimizedInstant, cnec, TwoSides.ONE, AMPERE))); - assertEquals(0.1, raoResult.getPtdfZonalSum(optimizedInstant, cnec, Side.LEFT), DOUBLE_TOLERANCE); + assertEquals(0.1, raoResult.getPtdfZonalSum(optimizedInstant, cnec, TwoSides.ONE), DOUBLE_TOLERANCE); } @Test void testPreventiveCnecResults() { setUp(); - assertEquals(100., raoResult.getFlow(null, cnec, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(100., raoResult.getFlow(null, cnec, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(101., raoResult.getMargin(null, cnec, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(102., raoResult.getRelativeMargin(null, cnec, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(103., raoResult.getLoopFlow(null, cnec, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(104., raoResult.getCommercialFlow(null, cnec, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(103., raoResult.getLoopFlow(null, cnec, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(104., raoResult.getCommercialFlow(null, cnec, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(110., raoResult.getFlow(null, cnec, Side.LEFT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(110., raoResult.getFlow(null, cnec, TwoSides.ONE, AMPERE), DOUBLE_TOLERANCE); assertEquals(111., raoResult.getMargin(null, cnec, AMPERE), DOUBLE_TOLERANCE); assertEquals(112., raoResult.getRelativeMargin(null, cnec, AMPERE), DOUBLE_TOLERANCE); - assertEquals(113., raoResult.getLoopFlow(null, cnec, Side.LEFT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(114., raoResult.getCommercialFlow(null, cnec, Side.LEFT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(113., raoResult.getLoopFlow(null, cnec, TwoSides.ONE, AMPERE), DOUBLE_TOLERANCE); + assertEquals(114., raoResult.getCommercialFlow(null, cnec, TwoSides.ONE, AMPERE), DOUBLE_TOLERANCE); - assertEquals(0.1, raoResult.getPtdfZonalSum(null, cnec, Side.LEFT), DOUBLE_TOLERANCE); + assertEquals(0.1, raoResult.getPtdfZonalSum(null, cnec, TwoSides.ONE), DOUBLE_TOLERANCE); // should always return after pra results because the cnec is Preventive getResultAtAGivenState(preventiveInstant); @@ -481,13 +481,13 @@ private void addOutageFlowCnec() { .withIMax(5000.) .newThreshold() .withUnit(Unit.MEGAWATT) - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .withMin(-2000.) .withMax(2000.) .add() .newThreshold() .withUnit(Unit.MEGAWATT) - .withSide(Side.RIGHT) + .withSide(TwoSides.TWO) .withMin(-2000.) .withMax(2000.) .add() diff --git a/data/rao-result/rao-result-impl/src/test/java/com/powsybl/openrao/data/raoresultimpl/utils/ExhaustiveRaoResultCreation.java b/data/rao-result/rao-result-impl/src/test/java/com/powsybl/openrao/data/raoresultimpl/utils/ExhaustiveRaoResultCreation.java index 528a601362..76ad38be79 100644 --- a/data/rao-result/rao-result-impl/src/test/java/com/powsybl/openrao/data/raoresultimpl/utils/ExhaustiveRaoResultCreation.java +++ b/data/rao-result/rao-result-impl/src/test/java/com/powsybl/openrao/data/raoresultimpl/utils/ExhaustiveRaoResultCreation.java @@ -10,7 +10,7 @@ import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.cnec.AngleCnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.cnec.VoltageCnec; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.HvdcRangeAction; @@ -255,12 +255,12 @@ private static void fillVoltageCnecResult(VoltageCnecResult voltageCnecResult, V } } - private static void fillElementaryResult(ElementaryFlowCnecResult elementaryFlowCnecResult, double x, double y, boolean hasLoopFlow, boolean isPureMnec, Set sides) { + private static void fillElementaryResult(ElementaryFlowCnecResult elementaryFlowCnecResult, double x, double y, boolean hasLoopFlow, boolean isPureMnec, Set sides) { sides.forEach(side -> fillElementaryResult(elementaryFlowCnecResult, x, y, hasLoopFlow, isPureMnec, side)); } - private static void fillElementaryResult(ElementaryFlowCnecResult elementaryFlowCnecResult, double x, double y, boolean hasLoopFlow, boolean isPureMnec, Side side) { - double perturb = side.equals(Side.LEFT) ? 0 : 0.5; + private static void fillElementaryResult(ElementaryFlowCnecResult elementaryFlowCnecResult, double x, double y, boolean hasLoopFlow, boolean isPureMnec, TwoSides side) { + double perturb = side.equals(TwoSides.ONE) ? 0 : 0.5; elementaryFlowCnecResult.setFlow(side, perturb + x + y + 10, MEGAWATT); elementaryFlowCnecResult.setFlow(side, perturb + x + y + 20, AMPERE); diff --git a/data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/RaoResultJsonConstants.java b/data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/RaoResultJsonConstants.java index 2dc37245e1..5c21fa478f 100644 --- a/data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/RaoResultJsonConstants.java +++ b/data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/RaoResultJsonConstants.java @@ -11,7 +11,7 @@ import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.State; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.raoresultapi.ComputationStatus; import com.powsybl.openrao.data.raoresultapi.OptimizationStepsExecuted; import org.apache.commons.lang3.StringUtils; @@ -28,7 +28,7 @@ public final class RaoResultJsonConstants { private RaoResultJsonConstants() { } - public static final String RAO_RESULT_IO_VERSION = "1.4"; + public static final String RAO_RESULT_IO_VERSION = "1.5"; // header public static final String TYPE = "type"; @@ -99,6 +99,8 @@ private RaoResultJsonConstants() { // branch side public static final String LEFT_SIDE = "leftSide"; public static final String RIGHT_SIDE = "rightSide"; + public static final String SIDE_ONE = "side1"; + public static final String SIDE_TWO = "side2"; // optimization states - for retro-compatibility only public static final String INITIAL_OPT_STATE = "initial"; @@ -177,26 +179,11 @@ public static Unit deserializeUnit(String stringValue) { } // serialization of enums - public static String serializeSide(Side side) { - switch (side) { - case LEFT: - return LEFT_SIDE; - case RIGHT: - return RIGHT_SIDE; - default: - throw new OpenRaoException(String.format("Unsupported side %s", side)); - } - } - - public static Side deserializeSide(String stringValue) { - switch (stringValue) { - case LEFT_SIDE: - return Side.LEFT; - case RIGHT_SIDE: - return Side.RIGHT; - default: - throw new OpenRaoException(String.format("Unrecognized side %s", stringValue)); - } + public static String serializeSide(TwoSides side) { + return switch (side) { + case ONE -> SIDE_ONE; + case TWO -> SIDE_TWO; + }; } public static String serializeInstantId(Instant instant) { diff --git a/data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/deserializers/FlowCnecResultArrayDeserializer.java b/data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/deserializers/FlowCnecResultArrayDeserializer.java index 47b077d041..ecb89463f1 100644 --- a/data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/deserializers/FlowCnecResultArrayDeserializer.java +++ b/data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/deserializers/FlowCnecResultArrayDeserializer.java @@ -12,7 +12,7 @@ import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.raoresultimpl.ElementaryFlowCnecResult; import com.powsybl.openrao.data.raoresultimpl.FlowCnecResult; import com.powsybl.openrao.data.raoresultimpl.RaoResultImpl; @@ -76,8 +76,8 @@ private static void deserializeElementaryFlowCnecResult(JsonParser jsonParser, E checkSideHandlingVersion(jsonFileVersion, ZONAL_PTDF_SUM); // For older versions, suppose both sides are used jsonParser.nextToken(); - eFlowCnecResult.setPtdfZonalSum(Side.LEFT, jsonParser.getDoubleValue()); - eFlowCnecResult.setPtdfZonalSum(Side.RIGHT, jsonParser.getDoubleValue()); + eFlowCnecResult.setPtdfZonalSum(TwoSides.ONE, jsonParser.getDoubleValue()); + eFlowCnecResult.setPtdfZonalSum(TwoSides.TWO, jsonParser.getDoubleValue()); break; default: throw new OpenRaoException(String.format(UNEXPECTED_FIELD, FLOWCNEC_RESULTS, jsonParser.getCurrentName())); @@ -96,34 +96,44 @@ private static void deserializeElementaryFlowCnecResultForUnit(JsonParser jsonPa jsonParser.nextToken(); eFlowCnecResult.setRelativeMargin(jsonParser.getDoubleValue(), unit); break; + case SIDE_ONE: + jsonParser.nextToken(); + deserializeElementaryFlowCnecResultForUnitAndSide(jsonParser, eFlowCnecResult, unit, TwoSides.ONE); + break; + case SIDE_TWO: + jsonParser.nextToken(); + deserializeElementaryFlowCnecResultForUnitAndSide(jsonParser, eFlowCnecResult, unit, TwoSides.TWO); + break; case LEFT_SIDE: + Utils.checkDeprecatedField(LEFT_SIDE, FLOWCNEC_RESULTS, jsonFileVersion, "1.4"); jsonParser.nextToken(); - deserializeElementaryFlowCnecResultForUnitAndSide(jsonParser, eFlowCnecResult, unit, Side.LEFT); + deserializeElementaryFlowCnecResultForUnitAndSide(jsonParser, eFlowCnecResult, unit, TwoSides.ONE); break; case RIGHT_SIDE: + Utils.checkDeprecatedField(RIGHT_SIDE, FLOWCNEC_RESULTS, jsonFileVersion, "1.4"); jsonParser.nextToken(); - deserializeElementaryFlowCnecResultForUnitAndSide(jsonParser, eFlowCnecResult, unit, Side.RIGHT); + deserializeElementaryFlowCnecResultForUnitAndSide(jsonParser, eFlowCnecResult, unit, TwoSides.TWO); break; case FLOW: checkSideHandlingVersion(jsonFileVersion, FLOW); // For older versions, suppose both sides are used jsonParser.nextToken(); - eFlowCnecResult.setFlow(Side.LEFT, jsonParser.getDoubleValue(), unit); - eFlowCnecResult.setFlow(Side.RIGHT, jsonParser.getDoubleValue(), unit); + eFlowCnecResult.setFlow(TwoSides.ONE, jsonParser.getDoubleValue(), unit); + eFlowCnecResult.setFlow(TwoSides.TWO, jsonParser.getDoubleValue(), unit); break; case COMMERCIAL_FLOW: checkSideHandlingVersion(jsonFileVersion, COMMERCIAL_FLOW); // For older versions, suppose both sides are used jsonParser.nextToken(); - eFlowCnecResult.setCommercialFlow(Side.LEFT, jsonParser.getDoubleValue(), unit); - eFlowCnecResult.setCommercialFlow(Side.RIGHT, jsonParser.getDoubleValue(), unit); + eFlowCnecResult.setCommercialFlow(TwoSides.ONE, jsonParser.getDoubleValue(), unit); + eFlowCnecResult.setCommercialFlow(TwoSides.TWO, jsonParser.getDoubleValue(), unit); break; case LOOP_FLOW: checkSideHandlingVersion(jsonFileVersion, LOOP_FLOW); // For older versions, suppose both sides are used jsonParser.nextToken(); - eFlowCnecResult.setLoopFlow(Side.LEFT, jsonParser.getDoubleValue(), unit); - eFlowCnecResult.setLoopFlow(Side.RIGHT, jsonParser.getDoubleValue(), unit); + eFlowCnecResult.setLoopFlow(TwoSides.ONE, jsonParser.getDoubleValue(), unit); + eFlowCnecResult.setLoopFlow(TwoSides.TWO, jsonParser.getDoubleValue(), unit); break; default: throw new OpenRaoException(String.format(UNEXPECTED_FIELD, FLOWCNEC_RESULTS, jsonParser.getCurrentName())); @@ -135,7 +145,7 @@ private static void checkSideHandlingVersion(String jsonFileVersion, String fiel Utils.checkDeprecatedField(fieldName, FLOWCNEC_RESULTS, jsonFileVersion, "1.1"); } - private static void deserializeElementaryFlowCnecResultForUnitAndSide(JsonParser jsonParser, ElementaryFlowCnecResult eFlowCnecResult, Unit unit, Side side) throws IOException { + private static void deserializeElementaryFlowCnecResultForUnitAndSide(JsonParser jsonParser, ElementaryFlowCnecResult eFlowCnecResult, Unit unit, TwoSides side) throws IOException { while (!jsonParser.nextToken().isStructEnd()) { switch (jsonParser.getCurrentName()) { case FLOW: diff --git a/data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/deserializers/Utils.java b/data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/deserializers/Utils.java index 93d39e89ea..98dad1e47c 100644 --- a/data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/deserializers/Utils.java +++ b/data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/deserializers/Utils.java @@ -28,7 +28,7 @@ static void checkDeprecatedField(JsonParser jsonParser, String parentName, Strin static void checkDeprecatedField(String fieldName, String parentName, String jsonFileVersion, String lastSupportedVersion) { if (getPrimaryVersionNumber(jsonFileVersion) > getPrimaryVersionNumber(lastSupportedVersion) - || getSubVersionNumber(jsonFileVersion) > getSubVersionNumber(lastSupportedVersion)) { + || getPrimaryVersionNumber(jsonFileVersion) == getPrimaryVersionNumber(lastSupportedVersion) && getSubVersionNumber(jsonFileVersion) > getSubVersionNumber(lastSupportedVersion)) { throw new OpenRaoException(String.format("Cannot deserialize RaoResult: field %s in %s in not supported in file version %s (last supported in version %s)", fieldName, parentName, jsonFileVersion, lastSupportedVersion)); } } diff --git a/data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/serializers/FlowCnecResultArraySerializer.java b/data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/serializers/FlowCnecResultArraySerializer.java index fd0976eea3..8a325c5996 100644 --- a/data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/serializers/FlowCnecResultArraySerializer.java +++ b/data/rao-result/rao-result-json/src/main/java/com/powsybl/openrao/data/raoresultjson/serializers/FlowCnecResultArraySerializer.java @@ -12,7 +12,7 @@ import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.InstantKind; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.raoresultapi.RaoResult; import com.fasterxml.jackson.core.JsonGenerator; @@ -88,7 +88,7 @@ private static void serializeFlowCnecResultForOptimizationStateAndUnit(Instant o } jsonGenerator.writeObjectFieldStart(serializeUnit(unit)); serializeFlowCnecMargin(optInstant, unit, flowCnec, raoResult, jsonGenerator); - for (Side side : flowCnec.getMonitoredSides().stream().sorted(Comparator.comparing(Side::toString)).toList()) { + for (TwoSides side : flowCnec.getMonitoredSides().stream().sorted(Comparator.comparing(TwoSides::toString)).toList()) { serializeFlowCnecFlows(optInstant, unit, flowCnec, side, raoResult, jsonGenerator); } jsonGenerator.writeEndObject(); @@ -109,7 +109,7 @@ private static void serializeFlowCnecMargin(Instant optInstant, Unit unit, FlowC } } - private static void serializeFlowCnecFlows(Instant optInstant, Unit unit, FlowCnec flowCnec, Side side, RaoResult raoResult, JsonGenerator jsonGenerator) throws IOException { + private static void serializeFlowCnecFlows(Instant optInstant, Unit unit, FlowCnec flowCnec, TwoSides side, RaoResult raoResult, JsonGenerator jsonGenerator) throws IOException { double flow = safeGetFlow(raoResult, flowCnec, side, optInstant, unit); double loopFlow = safeGetLoopFlow(raoResult, flowCnec, side, optInstant, unit); double commercialFlow = safeGetCommercialFlow(raoResult, flowCnec, side, optInstant, unit); @@ -150,18 +150,18 @@ private static boolean containsAnyResultForFlowCnec(RaoResult raoResult, FlowCne private static boolean containsAnyResultForOptimizationState(RaoResult raoResult, FlowCnec flowCnec, Instant optInstant, Unit unit) { return !Double.isNaN(safeGetMargin(raoResult, flowCnec, optInstant, unit)) || !Double.isNaN(safeGetRelativeMargin(raoResult, flowCnec, optInstant, unit)) || - containsAnyResultForOptimizationStateAndSide(raoResult, flowCnec, Side.LEFT, optInstant, unit) || - containsAnyResultForOptimizationStateAndSide(raoResult, flowCnec, Side.RIGHT, optInstant, unit); + containsAnyResultForOptimizationStateAndSide(raoResult, flowCnec, TwoSides.ONE, optInstant, unit) || + containsAnyResultForOptimizationStateAndSide(raoResult, flowCnec, TwoSides.TWO, optInstant, unit); } - private static boolean containsAnyResultForOptimizationStateAndSide(RaoResult raoResult, FlowCnec flowCnec, Side side, Instant optInstant, Unit unit) { + private static boolean containsAnyResultForOptimizationStateAndSide(RaoResult raoResult, FlowCnec flowCnec, TwoSides side, Instant optInstant, Unit unit) { return !Double.isNaN(safeGetFlow(raoResult, flowCnec, side, optInstant, unit)) || !Double.isNaN(safeGetLoopFlow(raoResult, flowCnec, side, optInstant, unit)) || !Double.isNaN(safeGetCommercialFlow(raoResult, flowCnec, side, optInstant, unit)) || !Double.isNaN(safeGetPtdfZonalSum(raoResult, flowCnec, side, optInstant)) && unit.equals(MEGAWATT); } - private static double safeGetFlow(RaoResult raoResult, FlowCnec flowCnec, Side side, Instant optInstant, Unit unit) { + private static double safeGetFlow(RaoResult raoResult, FlowCnec flowCnec, TwoSides side, Instant optInstant, Unit unit) { // methods getFlow can return an exception if RAO is executed on one state only try { return raoResult.getFlow(optInstant, flowCnec, side, unit); @@ -188,7 +188,7 @@ private static double safeGetRelativeMargin(RaoResult raoResult, FlowCnec flowCn } } - private static double safeGetLoopFlow(RaoResult raoResult, FlowCnec flowCnec, Side side, Instant optInstant, Unit unit) { + private static double safeGetLoopFlow(RaoResult raoResult, FlowCnec flowCnec, TwoSides side, Instant optInstant, Unit unit) { // methods getLoopFlow can throw an exception if queried in AMPERE try { return raoResult.getLoopFlow(optInstant, flowCnec, side, unit); @@ -197,7 +197,7 @@ private static double safeGetLoopFlow(RaoResult raoResult, FlowCnec flowCnec, Si } } - private static double safeGetCommercialFlow(RaoResult raoResult, FlowCnec flowCnec, Side side, Instant optInstant, Unit unit) { + private static double safeGetCommercialFlow(RaoResult raoResult, FlowCnec flowCnec, TwoSides side, Instant optInstant, Unit unit) { // methods getCommercialFlow can throw an exception if queried in AMPERE try { return raoResult.getCommercialFlow(optInstant, flowCnec, side, unit); @@ -206,7 +206,7 @@ private static double safeGetCommercialFlow(RaoResult raoResult, FlowCnec flowCn } } - private static double safeGetPtdfZonalSum(RaoResult raoResult, FlowCnec flowCnec, Side side, Instant optInstant) { + private static double safeGetPtdfZonalSum(RaoResult raoResult, FlowCnec flowCnec, TwoSides side, Instant optInstant) { // methods getPtdfZonalSum can throw an exception if RAO is executed on one state only try { return raoResult.getPtdfZonalSum(optInstant, flowCnec, side); diff --git a/data/rao-result/rao-result-json/src/test/java/com/powsybl/openrao/data/raoresultjson/ImporterRetrocompatibilityTest.java b/data/rao-result/rao-result-json/src/test/java/com/powsybl/openrao/data/raoresultjson/ImporterRetrocompatibilityTest.java index 42d06cbe3c..dae3606fbd 100644 --- a/data/rao-result/rao-result-json/src/test/java/com/powsybl/openrao/data/raoresultjson/ImporterRetrocompatibilityTest.java +++ b/data/rao-result/rao-result-json/src/test/java/com/powsybl/openrao/data/raoresultjson/ImporterRetrocompatibilityTest.java @@ -15,7 +15,7 @@ import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.AngleCnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.cnec.VoltageCnec; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.HvdcRangeAction; @@ -31,8 +31,8 @@ import java.util.Set; import static com.powsybl.openrao.commons.Unit.*; -import static com.powsybl.openrao.data.cracapi.cnec.Side.LEFT; -import static com.powsybl.openrao.data.cracapi.cnec.Side.RIGHT; +import static com.powsybl.iidm.network.TwoSides.ONE; +import static com.powsybl.iidm.network.TwoSides.TWO; import static org.junit.jupiter.api.Assertions.*; /** @@ -172,6 +172,17 @@ void importV1Point4Test() throws IOException { testBaseContentOfV1Point3RaoResult(raoResult, crac); } + @Test + void importV1Point5Test() throws IOException { + InputStream raoResultFile = getClass().getResourceAsStream("/retrocompatibility/v1.5/rao-result-v1.5.json"); + InputStream cracFile = getClass().getResourceAsStream("/retrocompatibility/v1.5/crac-for-rao-result-v1.5.json"); + + Crac crac = Crac.read(cracFile, mockNetworkWithLines("ne1Id", "ne2Id", "ne3Id")); + RaoResult raoResult = new RaoResultJsonImporter().importData(raoResultFile, crac); + + testBaseContentOfV1Point3RaoResult(raoResult, crac); + } + @Test void importV1Point3TestFieldDeprecationTest() throws IOException { InputStream cracFile = getClass().getResourceAsStream("/retrocompatibility/v1.3/crac-for-rao-result-v1.3.json"); @@ -237,22 +248,22 @@ private void testBaseContentOfV1RaoResult(RaoResult importedRaoResult, Crac crac - contains result relative margin and PTDF sum but not for loop and commercial flows */ FlowCnec cnecP = crac.getFlowCnec("cnec4prevId"); - assertEquals(4110., importedRaoResult.getFlow(null, cnecP, LEFT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(4110., importedRaoResult.getFlow(null, cnecP, ONE, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(4111., importedRaoResult.getMargin(null, cnecP, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(4112., importedRaoResult.getRelativeMargin(null, cnecP, MEGAWATT), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecP, LEFT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecP, LEFT, MEGAWATT))); + assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecP, ONE, MEGAWATT))); + assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecP, ONE, MEGAWATT))); - assertEquals(4220., importedRaoResult.getFlow(preventiveInstant, cnecP, LEFT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(4220., importedRaoResult.getFlow(preventiveInstant, cnecP, ONE, AMPERE), DOUBLE_TOLERANCE); assertEquals(4221., importedRaoResult.getMargin(preventiveInstant, cnecP, AMPERE), DOUBLE_TOLERANCE); assertEquals(4222., importedRaoResult.getRelativeMargin(preventiveInstant, cnecP, AMPERE), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecP, LEFT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecP, LEFT, MEGAWATT))); + assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecP, ONE, MEGAWATT))); + assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecP, ONE, MEGAWATT))); - assertEquals(0.4, importedRaoResult.getPtdfZonalSum(preventiveInstant, cnecP, LEFT), DOUBLE_TOLERANCE); + assertEquals(0.4, importedRaoResult.getPtdfZonalSum(preventiveInstant, cnecP, ONE), DOUBLE_TOLERANCE); - assertEquals(importedRaoResult.getFlow(autoInstant, cnecP, LEFT, AMPERE), importedRaoResult.getFlow(preventiveInstant, cnecP, LEFT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(importedRaoResult.getFlow(curativeInstant, cnecP, LEFT, AMPERE), importedRaoResult.getFlow(preventiveInstant, cnecP, LEFT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(importedRaoResult.getFlow(autoInstant, cnecP, ONE, AMPERE), importedRaoResult.getFlow(preventiveInstant, cnecP, ONE, AMPERE), DOUBLE_TOLERANCE); + assertEquals(importedRaoResult.getFlow(curativeInstant, cnecP, ONE, AMPERE), importedRaoResult.getFlow(preventiveInstant, cnecP, ONE, AMPERE), DOUBLE_TOLERANCE); /* cnec1outageId: outage, with loop-flows, optimized @@ -261,22 +272,22 @@ private void testBaseContentOfV1RaoResult(RaoResult importedRaoResult, Crac crac */ FlowCnec cnecO = crac.getFlowCnec("cnec1outageId"); - assertEquals(1120., importedRaoResult.getFlow(null, cnecO, LEFT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(1120., importedRaoResult.getFlow(null, cnecO, ONE, AMPERE), DOUBLE_TOLERANCE); assertEquals(1121., importedRaoResult.getMargin(null, cnecO, AMPERE), DOUBLE_TOLERANCE); assertEquals(1122., importedRaoResult.getRelativeMargin(null, cnecO, AMPERE), DOUBLE_TOLERANCE); - assertEquals(1123., importedRaoResult.getLoopFlow(null, cnecO, LEFT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(1124., importedRaoResult.getCommercialFlow(null, cnecO, LEFT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(1123., importedRaoResult.getLoopFlow(null, cnecO, ONE, AMPERE), DOUBLE_TOLERANCE); + assertEquals(1124., importedRaoResult.getCommercialFlow(null, cnecO, ONE, AMPERE), DOUBLE_TOLERANCE); - assertEquals(1210., importedRaoResult.getFlow(preventiveInstant, cnecO, LEFT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(1210., importedRaoResult.getFlow(preventiveInstant, cnecO, ONE, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(1211., importedRaoResult.getMargin(preventiveInstant, cnecO, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(1212., importedRaoResult.getRelativeMargin(preventiveInstant, cnecO, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(1213., importedRaoResult.getLoopFlow(preventiveInstant, cnecO, LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(1214., importedRaoResult.getCommercialFlow(preventiveInstant, cnecO, LEFT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(1213., importedRaoResult.getLoopFlow(preventiveInstant, cnecO, ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(1214., importedRaoResult.getCommercialFlow(preventiveInstant, cnecO, ONE, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(0.1, importedRaoResult.getPtdfZonalSum(preventiveInstant, cnecO, LEFT), DOUBLE_TOLERANCE); + assertEquals(0.1, importedRaoResult.getPtdfZonalSum(preventiveInstant, cnecO, ONE), DOUBLE_TOLERANCE); - assertEquals(importedRaoResult.getFlow(autoInstant, cnecO, LEFT, MEGAWATT), importedRaoResult.getFlow(preventiveInstant, cnecO, LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(importedRaoResult.getFlow(curativeInstant, cnecO, LEFT, MEGAWATT), importedRaoResult.getFlow(preventiveInstant, cnecO, LEFT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(importedRaoResult.getFlow(autoInstant, cnecO, ONE, MEGAWATT), importedRaoResult.getFlow(preventiveInstant, cnecO, ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(importedRaoResult.getFlow(curativeInstant, cnecO, ONE, MEGAWATT), importedRaoResult.getFlow(preventiveInstant, cnecO, ONE, MEGAWATT), DOUBLE_TOLERANCE); /* cnec3autoId: auto, without loop-flows, pureMNEC @@ -285,20 +296,20 @@ private void testBaseContentOfV1RaoResult(RaoResult importedRaoResult, Crac crac */ FlowCnec cnecA = crac.getFlowCnec("cnec3autoId"); - assertEquals(3110., importedRaoResult.getFlow(null, cnecA, LEFT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3110., importedRaoResult.getFlow(null, cnecA, ONE, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(3111., importedRaoResult.getMargin(null, cnecA, MEGAWATT), DOUBLE_TOLERANCE); assertTrue(Double.isNaN(importedRaoResult.getRelativeMargin(null, cnecA, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecA, LEFT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecA, LEFT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getPtdfZonalSum(null, cnecA, LEFT))); + assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecA, ONE, MEGAWATT))); + assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecA, ONE, MEGAWATT))); + assertTrue(Double.isNaN(importedRaoResult.getPtdfZonalSum(null, cnecA, ONE))); - assertEquals(3220., importedRaoResult.getFlow(preventiveInstant, cnecA, LEFT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(3220., importedRaoResult.getFlow(preventiveInstant, cnecA, ONE, AMPERE), DOUBLE_TOLERANCE); assertEquals(3221., importedRaoResult.getMargin(preventiveInstant, cnecA, AMPERE), DOUBLE_TOLERANCE); - assertEquals(3310., importedRaoResult.getFlow(autoInstant, cnecA, LEFT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3310., importedRaoResult.getFlow(autoInstant, cnecA, ONE, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(3311., importedRaoResult.getMargin(autoInstant, cnecA, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(importedRaoResult.getFlow(curativeInstant, cnecO, LEFT, MEGAWATT), importedRaoResult.getFlow(autoInstant, cnecO, LEFT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(importedRaoResult.getFlow(curativeInstant, cnecO, ONE, MEGAWATT), importedRaoResult.getFlow(autoInstant, cnecO, ONE, MEGAWATT), DOUBLE_TOLERANCE); /* cnec3curId: curative, without loop-flows, pureMNEC @@ -307,20 +318,20 @@ private void testBaseContentOfV1RaoResult(RaoResult importedRaoResult, Crac crac */ FlowCnec cnecC = crac.getFlowCnec("cnec3curId"); - assertEquals(3110., importedRaoResult.getFlow(null, cnecC, LEFT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3110., importedRaoResult.getFlow(null, cnecC, ONE, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(3111., importedRaoResult.getMargin(null, cnecC, MEGAWATT), DOUBLE_TOLERANCE); assertTrue(Double.isNaN(importedRaoResult.getRelativeMargin(null, cnecC, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecC, LEFT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecC, LEFT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getPtdfZonalSum(null, cnecC, LEFT))); + assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecC, ONE, MEGAWATT))); + assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecC, ONE, MEGAWATT))); + assertTrue(Double.isNaN(importedRaoResult.getPtdfZonalSum(null, cnecC, ONE))); - assertEquals(3220., importedRaoResult.getFlow(preventiveInstant, cnecC, LEFT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(3220., importedRaoResult.getFlow(preventiveInstant, cnecC, ONE, AMPERE), DOUBLE_TOLERANCE); assertEquals(3221., importedRaoResult.getMargin(preventiveInstant, cnecC, AMPERE), DOUBLE_TOLERANCE); - assertEquals(3310., importedRaoResult.getFlow(autoInstant, cnecC, LEFT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3310., importedRaoResult.getFlow(autoInstant, cnecC, ONE, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(3311., importedRaoResult.getMargin(autoInstant, cnecC, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(3410., importedRaoResult.getFlow(curativeInstant, cnecC, LEFT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3410., importedRaoResult.getFlow(curativeInstant, cnecC, ONE, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(3411., importedRaoResult.getMargin(curativeInstant, cnecC, MEGAWATT), DOUBLE_TOLERANCE); // ----------------------------- @@ -517,31 +528,31 @@ private void testBaseContentOfV1Point2RaoResult(RaoResult importedRaoResult, Cra - contains result relative margin and PTDF sum but not for loop and commercial flows */ FlowCnec cnecP = crac.getFlowCnec("cnec4prevId"); - assertEquals(4110., importedRaoResult.getFlow(null, cnecP, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(importedRaoResult.getFlow(null, cnecP, Side.RIGHT, MEGAWATT))); + assertEquals(4110., importedRaoResult.getFlow(null, cnecP, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(importedRaoResult.getFlow(null, cnecP, TwoSides.TWO, MEGAWATT))); assertEquals(4111., importedRaoResult.getMargin(null, cnecP, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(4112., importedRaoResult.getRelativeMargin(null, cnecP, MEGAWATT), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecP, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecP, Side.RIGHT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecP, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecP, Side.RIGHT, MEGAWATT))); + assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecP, TwoSides.ONE, MEGAWATT))); + assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecP, TwoSides.TWO, MEGAWATT))); + assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecP, TwoSides.ONE, MEGAWATT))); + assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecP, TwoSides.TWO, MEGAWATT))); - assertEquals(4220., importedRaoResult.getFlow(preventiveInstant, cnecP, Side.LEFT, AMPERE), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(importedRaoResult.getFlow(preventiveInstant, cnecP, Side.RIGHT, AMPERE))); + assertEquals(4220., importedRaoResult.getFlow(preventiveInstant, cnecP, TwoSides.ONE, AMPERE), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(importedRaoResult.getFlow(preventiveInstant, cnecP, TwoSides.TWO, AMPERE))); assertEquals(4221., importedRaoResult.getMargin(preventiveInstant, cnecP, AMPERE), DOUBLE_TOLERANCE); assertEquals(4222., importedRaoResult.getRelativeMargin(preventiveInstant, cnecP, AMPERE), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecP, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecP, Side.RIGHT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecP, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecP, Side.RIGHT, MEGAWATT))); + assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecP, TwoSides.ONE, MEGAWATT))); + assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecP, TwoSides.TWO, MEGAWATT))); + assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecP, TwoSides.ONE, MEGAWATT))); + assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecP, TwoSides.TWO, MEGAWATT))); - assertEquals(0.4, importedRaoResult.getPtdfZonalSum(preventiveInstant, cnecP, Side.LEFT), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(importedRaoResult.getPtdfZonalSum(preventiveInstant, cnecP, Side.RIGHT))); + assertEquals(0.4, importedRaoResult.getPtdfZonalSum(preventiveInstant, cnecP, TwoSides.ONE), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(importedRaoResult.getPtdfZonalSum(preventiveInstant, cnecP, TwoSides.TWO))); - assertEquals(importedRaoResult.getFlow(autoInstant, cnecP, LEFT, AMPERE), importedRaoResult.getFlow(preventiveInstant, cnecP, LEFT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(importedRaoResult.getFlow(autoInstant, cnecP, RIGHT, AMPERE), importedRaoResult.getFlow(preventiveInstant, cnecP, RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(importedRaoResult.getFlow(curativeInstant, cnecP, LEFT, AMPERE), importedRaoResult.getFlow(preventiveInstant, cnecP, LEFT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(importedRaoResult.getFlow(curativeInstant, cnecP, RIGHT, AMPERE), importedRaoResult.getFlow(preventiveInstant, cnecP, RIGHT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(importedRaoResult.getFlow(autoInstant, cnecP, ONE, AMPERE), importedRaoResult.getFlow(preventiveInstant, cnecP, ONE, AMPERE), DOUBLE_TOLERANCE); + assertEquals(importedRaoResult.getFlow(autoInstant, cnecP, TWO, AMPERE), importedRaoResult.getFlow(preventiveInstant, cnecP, TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(importedRaoResult.getFlow(curativeInstant, cnecP, ONE, AMPERE), importedRaoResult.getFlow(preventiveInstant, cnecP, ONE, AMPERE), DOUBLE_TOLERANCE); + assertEquals(importedRaoResult.getFlow(curativeInstant, cnecP, TWO, AMPERE), importedRaoResult.getFlow(preventiveInstant, cnecP, TWO, AMPERE), DOUBLE_TOLERANCE); /* cnec1outageId: outage, with loop-flows, optimized @@ -550,31 +561,31 @@ private void testBaseContentOfV1Point2RaoResult(RaoResult importedRaoResult, Cra */ FlowCnec cnecO = crac.getFlowCnec("cnec1outageId"); - assertTrue(Double.isNaN(importedRaoResult.getFlow(null, cnecO, Side.LEFT, AMPERE))); - assertEquals(1120.5, importedRaoResult.getFlow(null, cnecO, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(importedRaoResult.getFlow(null, cnecO, TwoSides.ONE, AMPERE))); + assertEquals(1120.5, importedRaoResult.getFlow(null, cnecO, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); assertEquals(1121., importedRaoResult.getMargin(null, cnecO, AMPERE), DOUBLE_TOLERANCE); assertEquals(1122., importedRaoResult.getRelativeMargin(null, cnecO, AMPERE), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecO, Side.LEFT, AMPERE))); - assertEquals(1123.5, importedRaoResult.getLoopFlow(null, cnecO, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecO, Side.LEFT, AMPERE))); - assertEquals(1124.5, importedRaoResult.getCommercialFlow(null, cnecO, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecO, TwoSides.ONE, AMPERE))); + assertEquals(1123.5, importedRaoResult.getLoopFlow(null, cnecO, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecO, TwoSides.ONE, AMPERE))); + assertEquals(1124.5, importedRaoResult.getCommercialFlow(null, cnecO, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(importedRaoResult.getFlow(preventiveInstant, cnecO, Side.LEFT, MEGAWATT))); - assertEquals(1210.5, importedRaoResult.getFlow(preventiveInstant, cnecO, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(importedRaoResult.getFlow(preventiveInstant, cnecO, TwoSides.ONE, MEGAWATT))); + assertEquals(1210.5, importedRaoResult.getFlow(preventiveInstant, cnecO, TwoSides.TWO, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(1211., importedRaoResult.getMargin(preventiveInstant, cnecO, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(1212., importedRaoResult.getRelativeMargin(preventiveInstant, cnecO, MEGAWATT), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(preventiveInstant, cnecO, Side.LEFT, MEGAWATT))); - assertEquals(1213.5, importedRaoResult.getLoopFlow(preventiveInstant, cnecO, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(preventiveInstant, cnecO, Side.LEFT, MEGAWATT))); - assertEquals(1214.5, importedRaoResult.getCommercialFlow(preventiveInstant, cnecO, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(preventiveInstant, cnecO, TwoSides.ONE, MEGAWATT))); + assertEquals(1213.5, importedRaoResult.getLoopFlow(preventiveInstant, cnecO, TwoSides.TWO, MEGAWATT), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(preventiveInstant, cnecO, TwoSides.ONE, MEGAWATT))); + assertEquals(1214.5, importedRaoResult.getCommercialFlow(preventiveInstant, cnecO, TwoSides.TWO, MEGAWATT), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(importedRaoResult.getPtdfZonalSum(preventiveInstant, cnecO, Side.LEFT))); - assertEquals(0.6, importedRaoResult.getPtdfZonalSum(preventiveInstant, cnecO, Side.RIGHT), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(importedRaoResult.getPtdfZonalSum(preventiveInstant, cnecO, TwoSides.ONE))); + assertEquals(0.6, importedRaoResult.getPtdfZonalSum(preventiveInstant, cnecO, TwoSides.TWO), DOUBLE_TOLERANCE); - assertEquals(importedRaoResult.getFlow(autoInstant, cnecO, LEFT, MEGAWATT), importedRaoResult.getFlow(preventiveInstant, cnecO, LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(importedRaoResult.getFlow(autoInstant, cnecO, RIGHT, MEGAWATT), importedRaoResult.getFlow(preventiveInstant, cnecO, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(importedRaoResult.getFlow(curativeInstant, cnecO, LEFT, MEGAWATT), importedRaoResult.getFlow(preventiveInstant, cnecO, LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(importedRaoResult.getFlow(curativeInstant, cnecO, RIGHT, MEGAWATT), importedRaoResult.getFlow(preventiveInstant, cnecO, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(importedRaoResult.getFlow(autoInstant, cnecO, ONE, MEGAWATT), importedRaoResult.getFlow(preventiveInstant, cnecO, ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(importedRaoResult.getFlow(autoInstant, cnecO, TWO, MEGAWATT), importedRaoResult.getFlow(preventiveInstant, cnecO, TWO, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(importedRaoResult.getFlow(curativeInstant, cnecO, ONE, MEGAWATT), importedRaoResult.getFlow(preventiveInstant, cnecO, ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(importedRaoResult.getFlow(curativeInstant, cnecO, TWO, MEGAWATT), importedRaoResult.getFlow(preventiveInstant, cnecO, TWO, MEGAWATT), DOUBLE_TOLERANCE); /* cnec3autoId: auto, without loop-flows, pureMNEC @@ -583,27 +594,27 @@ private void testBaseContentOfV1Point2RaoResult(RaoResult importedRaoResult, Cra */ FlowCnec cnecA = crac.getFlowCnec("cnec3autoId"); - assertEquals(3110., importedRaoResult.getFlow(null, cnecA, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(3110.5, importedRaoResult.getFlow(null, cnecA, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3110., importedRaoResult.getFlow(null, cnecA, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3110.5, importedRaoResult.getFlow(null, cnecA, TwoSides.TWO, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(3111., importedRaoResult.getMargin(null, cnecA, MEGAWATT), DOUBLE_TOLERANCE); assertTrue(Double.isNaN(importedRaoResult.getRelativeMargin(null, cnecA, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecA, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecA, Side.RIGHT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecA, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecA, Side.RIGHT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getPtdfZonalSum(null, cnecA, Side.LEFT))); - assertTrue(Double.isNaN(importedRaoResult.getPtdfZonalSum(null, cnecA, Side.RIGHT))); - - assertEquals(3220., importedRaoResult.getFlow(preventiveInstant, cnecA, Side.LEFT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(3220.5, importedRaoResult.getFlow(preventiveInstant, cnecA, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecA, TwoSides.ONE, MEGAWATT))); + assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecA, TwoSides.TWO, MEGAWATT))); + assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecA, TwoSides.ONE, MEGAWATT))); + assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecA, TwoSides.TWO, MEGAWATT))); + assertTrue(Double.isNaN(importedRaoResult.getPtdfZonalSum(null, cnecA, TwoSides.ONE))); + assertTrue(Double.isNaN(importedRaoResult.getPtdfZonalSum(null, cnecA, TwoSides.TWO))); + + assertEquals(3220., importedRaoResult.getFlow(preventiveInstant, cnecA, TwoSides.ONE, AMPERE), DOUBLE_TOLERANCE); + assertEquals(3220.5, importedRaoResult.getFlow(preventiveInstant, cnecA, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); assertEquals(3221., importedRaoResult.getMargin(preventiveInstant, cnecA, AMPERE), DOUBLE_TOLERANCE); - assertEquals(3310., importedRaoResult.getFlow(autoInstant, cnecA, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(3310.5, importedRaoResult.getFlow(autoInstant, cnecA, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3310., importedRaoResult.getFlow(autoInstant, cnecA, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3310.5, importedRaoResult.getFlow(autoInstant, cnecA, TwoSides.TWO, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(3311., importedRaoResult.getMargin(autoInstant, cnecA, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(importedRaoResult.getFlow(curativeInstant, cnecO, LEFT, MEGAWATT), importedRaoResult.getFlow(autoInstant, cnecO, LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(importedRaoResult.getFlow(curativeInstant, cnecO, RIGHT, MEGAWATT), importedRaoResult.getFlow(autoInstant, cnecO, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(importedRaoResult.getFlow(curativeInstant, cnecO, ONE, MEGAWATT), importedRaoResult.getFlow(autoInstant, cnecO, ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(importedRaoResult.getFlow(curativeInstant, cnecO, TWO, MEGAWATT), importedRaoResult.getFlow(autoInstant, cnecO, TWO, MEGAWATT), DOUBLE_TOLERANCE); /* cnec3curId: curative, without loop-flows, pureMNEC @@ -612,27 +623,27 @@ private void testBaseContentOfV1Point2RaoResult(RaoResult importedRaoResult, Cra */ FlowCnec cnecC = crac.getFlowCnec("cnec3curId"); - assertEquals(3110., importedRaoResult.getFlow(null, cnecC, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(3110.5, importedRaoResult.getFlow(null, cnecC, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3110., importedRaoResult.getFlow(null, cnecC, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3110.5, importedRaoResult.getFlow(null, cnecC, TwoSides.TWO, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(3111., importedRaoResult.getMargin(null, cnecC, MEGAWATT), DOUBLE_TOLERANCE); assertTrue(Double.isNaN(importedRaoResult.getRelativeMargin(null, cnecC, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecC, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecC, Side.RIGHT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecC, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecC, Side.RIGHT, MEGAWATT))); - assertTrue(Double.isNaN(importedRaoResult.getPtdfZonalSum(null, cnecC, Side.LEFT))); - assertTrue(Double.isNaN(importedRaoResult.getPtdfZonalSum(null, cnecC, Side.RIGHT))); - - assertEquals(3220., importedRaoResult.getFlow(preventiveInstant, cnecC, Side.LEFT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(3220.5, importedRaoResult.getFlow(preventiveInstant, cnecC, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecC, TwoSides.ONE, MEGAWATT))); + assertTrue(Double.isNaN(importedRaoResult.getLoopFlow(null, cnecC, TwoSides.TWO, MEGAWATT))); + assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecC, TwoSides.ONE, MEGAWATT))); + assertTrue(Double.isNaN(importedRaoResult.getCommercialFlow(null, cnecC, TwoSides.TWO, MEGAWATT))); + assertTrue(Double.isNaN(importedRaoResult.getPtdfZonalSum(null, cnecC, TwoSides.ONE))); + assertTrue(Double.isNaN(importedRaoResult.getPtdfZonalSum(null, cnecC, TwoSides.TWO))); + + assertEquals(3220., importedRaoResult.getFlow(preventiveInstant, cnecC, TwoSides.ONE, AMPERE), DOUBLE_TOLERANCE); + assertEquals(3220.5, importedRaoResult.getFlow(preventiveInstant, cnecC, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); assertEquals(3221., importedRaoResult.getMargin(preventiveInstant, cnecC, AMPERE), DOUBLE_TOLERANCE); - assertEquals(3310., importedRaoResult.getFlow(autoInstant, cnecC, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(3310.5, importedRaoResult.getFlow(autoInstant, cnecC, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3310., importedRaoResult.getFlow(autoInstant, cnecC, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3310.5, importedRaoResult.getFlow(autoInstant, cnecC, TwoSides.TWO, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(3311., importedRaoResult.getMargin(autoInstant, cnecC, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(3410., importedRaoResult.getFlow(curativeInstant, cnecC, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(3410.5, importedRaoResult.getFlow(curativeInstant, cnecC, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3410., importedRaoResult.getFlow(curativeInstant, cnecC, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3410.5, importedRaoResult.getFlow(curativeInstant, cnecC, TwoSides.TWO, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(3411., importedRaoResult.getMargin(curativeInstant, cnecC, MEGAWATT), DOUBLE_TOLERANCE); // ----------------------------- diff --git a/data/rao-result/rao-result-json/src/test/java/com/powsybl/openrao/data/raoresultjson/RaoResultRoundTripTest.java b/data/rao-result/rao-result-json/src/test/java/com/powsybl/openrao/data/raoresultjson/RaoResultRoundTripTest.java index 06303780c9..8de5ab6785 100644 --- a/data/rao-result/rao-result-json/src/test/java/com/powsybl/openrao/data/raoresultjson/RaoResultRoundTripTest.java +++ b/data/rao-result/rao-result-json/src/test/java/com/powsybl/openrao/data/raoresultjson/RaoResultRoundTripTest.java @@ -12,7 +12,7 @@ import com.powsybl.openrao.data.cracapi.*; import com.powsybl.openrao.data.cracapi.cnec.AngleCnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.cnec.VoltageCnec; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.HvdcRangeAction; @@ -34,8 +34,8 @@ import java.util.Set; import static com.powsybl.openrao.commons.Unit.*; -import static com.powsybl.openrao.data.cracapi.cnec.Side.LEFT; -import static com.powsybl.openrao.data.cracapi.cnec.Side.RIGHT; +import static com.powsybl.iidm.network.TwoSides.ONE; +import static com.powsybl.iidm.network.TwoSides.TWO; import static org.junit.jupiter.api.Assertions.*; /** @@ -143,31 +143,31 @@ private void checkContent(RaoResult raoResult, Crac crac) { - contains result relative margin and PTDF sum but not for loop and commercial flows */ FlowCnec cnecP = crac.getFlowCnec("cnec4prevId"); - assertEquals(4110., raoResult.getFlow(null, cnecP, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(raoResult.getFlow(null, cnecP, Side.RIGHT, MEGAWATT))); + assertEquals(4110., raoResult.getFlow(null, cnecP, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getFlow(null, cnecP, TwoSides.TWO, MEGAWATT))); assertEquals(4111., raoResult.getMargin(null, cnecP, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(4112., raoResult.getRelativeMargin(null, cnecP, MEGAWATT), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(raoResult.getLoopFlow(null, cnecP, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(raoResult.getLoopFlow(null, cnecP, Side.RIGHT, MEGAWATT))); - assertTrue(Double.isNaN(raoResult.getCommercialFlow(null, cnecP, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(raoResult.getCommercialFlow(null, cnecP, Side.RIGHT, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getLoopFlow(null, cnecP, TwoSides.ONE, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getLoopFlow(null, cnecP, TwoSides.TWO, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getCommercialFlow(null, cnecP, TwoSides.ONE, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getCommercialFlow(null, cnecP, TwoSides.TWO, MEGAWATT))); - assertEquals(4220., raoResult.getFlow(preventiveInstant, cnecP, Side.LEFT, AMPERE), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(raoResult.getFlow(preventiveInstant, cnecP, Side.RIGHT, AMPERE))); + assertEquals(4220., raoResult.getFlow(preventiveInstant, cnecP, TwoSides.ONE, AMPERE), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getFlow(preventiveInstant, cnecP, TwoSides.TWO, AMPERE))); assertEquals(4221., raoResult.getMargin(preventiveInstant, cnecP, AMPERE), DOUBLE_TOLERANCE); assertEquals(4222., raoResult.getRelativeMargin(preventiveInstant, cnecP, AMPERE), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(raoResult.getLoopFlow(null, cnecP, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(raoResult.getLoopFlow(null, cnecP, Side.RIGHT, MEGAWATT))); - assertTrue(Double.isNaN(raoResult.getCommercialFlow(null, cnecP, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(raoResult.getCommercialFlow(null, cnecP, Side.RIGHT, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getLoopFlow(null, cnecP, TwoSides.ONE, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getLoopFlow(null, cnecP, TwoSides.TWO, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getCommercialFlow(null, cnecP, TwoSides.ONE, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getCommercialFlow(null, cnecP, TwoSides.TWO, MEGAWATT))); - assertEquals(0.4, raoResult.getPtdfZonalSum(preventiveInstant, cnecP, Side.LEFT), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(raoResult.getPtdfZonalSum(preventiveInstant, cnecP, Side.RIGHT))); + assertEquals(0.4, raoResult.getPtdfZonalSum(preventiveInstant, cnecP, TwoSides.ONE), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getPtdfZonalSum(preventiveInstant, cnecP, TwoSides.TWO))); - assertEquals(raoResult.getFlow(autoInstant, cnecP, LEFT, AMPERE), raoResult.getFlow(preventiveInstant, cnecP, LEFT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(raoResult.getFlow(autoInstant, cnecP, RIGHT, AMPERE), raoResult.getFlow(preventiveInstant, cnecP, RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(raoResult.getFlow(curativeInstant, cnecP, LEFT, AMPERE), raoResult.getFlow(preventiveInstant, cnecP, LEFT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(raoResult.getFlow(curativeInstant, cnecP, RIGHT, AMPERE), raoResult.getFlow(preventiveInstant, cnecP, RIGHT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(raoResult.getFlow(autoInstant, cnecP, ONE, AMPERE), raoResult.getFlow(preventiveInstant, cnecP, ONE, AMPERE), DOUBLE_TOLERANCE); + assertEquals(raoResult.getFlow(autoInstant, cnecP, TWO, AMPERE), raoResult.getFlow(preventiveInstant, cnecP, TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(raoResult.getFlow(curativeInstant, cnecP, ONE, AMPERE), raoResult.getFlow(preventiveInstant, cnecP, ONE, AMPERE), DOUBLE_TOLERANCE); + assertEquals(raoResult.getFlow(curativeInstant, cnecP, TWO, AMPERE), raoResult.getFlow(preventiveInstant, cnecP, TWO, AMPERE), DOUBLE_TOLERANCE); /* cnec1outageId: outage, with loop-flows, optimized @@ -176,31 +176,31 @@ private void checkContent(RaoResult raoResult, Crac crac) { */ FlowCnec cnecO = crac.getFlowCnec("cnec1outageId"); - assertTrue(Double.isNaN(raoResult.getFlow(null, cnecO, Side.LEFT, AMPERE))); - assertEquals(1120.5, raoResult.getFlow(null, cnecO, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getFlow(null, cnecO, TwoSides.ONE, AMPERE))); + assertEquals(1120.5, raoResult.getFlow(null, cnecO, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); assertEquals(1121., raoResult.getMargin(null, cnecO, AMPERE), DOUBLE_TOLERANCE); assertEquals(1122., raoResult.getRelativeMargin(null, cnecO, AMPERE), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(raoResult.getLoopFlow(null, cnecO, Side.LEFT, AMPERE))); - assertEquals(1123.5, raoResult.getLoopFlow(null, cnecO, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(raoResult.getCommercialFlow(null, cnecO, Side.LEFT, AMPERE))); - assertEquals(1124.5, raoResult.getCommercialFlow(null, cnecO, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getLoopFlow(null, cnecO, TwoSides.ONE, AMPERE))); + assertEquals(1123.5, raoResult.getLoopFlow(null, cnecO, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getCommercialFlow(null, cnecO, TwoSides.ONE, AMPERE))); + assertEquals(1124.5, raoResult.getCommercialFlow(null, cnecO, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(raoResult.getFlow(preventiveInstant, cnecO, Side.LEFT, MEGAWATT))); - assertEquals(1210.5, raoResult.getFlow(preventiveInstant, cnecO, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getFlow(preventiveInstant, cnecO, TwoSides.ONE, MEGAWATT))); + assertEquals(1210.5, raoResult.getFlow(preventiveInstant, cnecO, TwoSides.TWO, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(1211., raoResult.getMargin(preventiveInstant, cnecO, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(1212., raoResult.getRelativeMargin(preventiveInstant, cnecO, MEGAWATT), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(raoResult.getLoopFlow(preventiveInstant, cnecO, Side.LEFT, MEGAWATT))); - assertEquals(1213.5, raoResult.getLoopFlow(preventiveInstant, cnecO, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(raoResult.getCommercialFlow(preventiveInstant, cnecO, Side.LEFT, MEGAWATT))); - assertEquals(1214.5, raoResult.getCommercialFlow(preventiveInstant, cnecO, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getLoopFlow(preventiveInstant, cnecO, TwoSides.ONE, MEGAWATT))); + assertEquals(1213.5, raoResult.getLoopFlow(preventiveInstant, cnecO, TwoSides.TWO, MEGAWATT), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getCommercialFlow(preventiveInstant, cnecO, TwoSides.ONE, MEGAWATT))); + assertEquals(1214.5, raoResult.getCommercialFlow(preventiveInstant, cnecO, TwoSides.TWO, MEGAWATT), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(raoResult.getPtdfZonalSum(preventiveInstant, cnecO, Side.LEFT))); - assertEquals(0.6, raoResult.getPtdfZonalSum(preventiveInstant, cnecO, Side.RIGHT), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getPtdfZonalSum(preventiveInstant, cnecO, TwoSides.ONE))); + assertEquals(0.6, raoResult.getPtdfZonalSum(preventiveInstant, cnecO, TwoSides.TWO), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(raoResult.getFlow(autoInstant, cnecO, Side.LEFT, MEGAWATT))); - assertEquals(raoResult.getFlow(autoInstant, cnecO, RIGHT, MEGAWATT), raoResult.getFlow(preventiveInstant, cnecO, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(raoResult.getFlow(curativeInstant, cnecO, Side.LEFT, MEGAWATT))); - assertEquals(raoResult.getFlow(curativeInstant, cnecO, RIGHT, MEGAWATT), raoResult.getFlow(preventiveInstant, cnecO, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getFlow(autoInstant, cnecO, TwoSides.ONE, MEGAWATT))); + assertEquals(raoResult.getFlow(autoInstant, cnecO, TWO, MEGAWATT), raoResult.getFlow(preventiveInstant, cnecO, TWO, MEGAWATT), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getFlow(curativeInstant, cnecO, TwoSides.ONE, MEGAWATT))); + assertEquals(raoResult.getFlow(curativeInstant, cnecO, TWO, MEGAWATT), raoResult.getFlow(preventiveInstant, cnecO, TWO, MEGAWATT), DOUBLE_TOLERANCE); /* cnec3autoId: auto, without loop-flows, pureMNEC @@ -209,27 +209,27 @@ private void checkContent(RaoResult raoResult, Crac crac) { */ FlowCnec cnecA = crac.getFlowCnec("cnec3autoId"); - assertEquals(3110., raoResult.getFlow(null, cnecA, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(3110.5, raoResult.getFlow(null, cnecA, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3110., raoResult.getFlow(null, cnecA, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3110.5, raoResult.getFlow(null, cnecA, TwoSides.TWO, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(3111., raoResult.getMargin(null, cnecA, MEGAWATT), DOUBLE_TOLERANCE); assertTrue(Double.isNaN(raoResult.getRelativeMargin(null, cnecA, MEGAWATT))); - assertTrue(Double.isNaN(raoResult.getLoopFlow(null, cnecA, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(raoResult.getLoopFlow(null, cnecA, Side.RIGHT, MEGAWATT))); - assertTrue(Double.isNaN(raoResult.getCommercialFlow(null, cnecA, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(raoResult.getCommercialFlow(null, cnecA, Side.RIGHT, MEGAWATT))); - assertTrue(Double.isNaN(raoResult.getPtdfZonalSum(null, cnecA, Side.LEFT))); - assertTrue(Double.isNaN(raoResult.getPtdfZonalSum(null, cnecA, Side.RIGHT))); - - assertEquals(3220., raoResult.getFlow(preventiveInstant, cnecA, Side.LEFT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(3220.5, raoResult.getFlow(preventiveInstant, cnecA, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getLoopFlow(null, cnecA, TwoSides.ONE, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getLoopFlow(null, cnecA, TwoSides.TWO, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getCommercialFlow(null, cnecA, TwoSides.ONE, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getCommercialFlow(null, cnecA, TwoSides.TWO, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getPtdfZonalSum(null, cnecA, TwoSides.ONE))); + assertTrue(Double.isNaN(raoResult.getPtdfZonalSum(null, cnecA, TwoSides.TWO))); + + assertEquals(3220., raoResult.getFlow(preventiveInstant, cnecA, TwoSides.ONE, AMPERE), DOUBLE_TOLERANCE); + assertEquals(3220.5, raoResult.getFlow(preventiveInstant, cnecA, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); assertEquals(3221., raoResult.getMargin(preventiveInstant, cnecA, AMPERE), DOUBLE_TOLERANCE); - assertEquals(3310., raoResult.getFlow(autoInstant, cnecA, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(3310.5, raoResult.getFlow(autoInstant, cnecA, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3310., raoResult.getFlow(autoInstant, cnecA, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3310.5, raoResult.getFlow(autoInstant, cnecA, TwoSides.TWO, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(3311., raoResult.getMargin(autoInstant, cnecA, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(raoResult.getFlow(curativeInstant, cnecA, LEFT, MEGAWATT), raoResult.getFlow(autoInstant, cnecA, LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(raoResult.getFlow(curativeInstant, cnecA, RIGHT, MEGAWATT), raoResult.getFlow(autoInstant, cnecA, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(raoResult.getFlow(curativeInstant, cnecA, ONE, MEGAWATT), raoResult.getFlow(autoInstant, cnecA, ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(raoResult.getFlow(curativeInstant, cnecA, TWO, MEGAWATT), raoResult.getFlow(autoInstant, cnecA, TWO, MEGAWATT), DOUBLE_TOLERANCE); /* cnec3curId: curative, without loop-flows, pureMNEC @@ -238,27 +238,27 @@ private void checkContent(RaoResult raoResult, Crac crac) { */ FlowCnec cnecC = crac.getFlowCnec("cnec3curId"); - assertEquals(3110., raoResult.getFlow(null, cnecC, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(3110.5, raoResult.getFlow(null, cnecC, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3110., raoResult.getFlow(null, cnecC, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3110.5, raoResult.getFlow(null, cnecC, TwoSides.TWO, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(3111., raoResult.getMargin(null, cnecC, MEGAWATT), DOUBLE_TOLERANCE); assertTrue(Double.isNaN(raoResult.getRelativeMargin(null, cnecC, MEGAWATT))); - assertTrue(Double.isNaN(raoResult.getLoopFlow(null, cnecC, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(raoResult.getLoopFlow(null, cnecC, Side.RIGHT, MEGAWATT))); - assertTrue(Double.isNaN(raoResult.getCommercialFlow(null, cnecC, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(raoResult.getCommercialFlow(null, cnecC, Side.RIGHT, MEGAWATT))); - assertTrue(Double.isNaN(raoResult.getPtdfZonalSum(null, cnecC, Side.LEFT))); - assertTrue(Double.isNaN(raoResult.getPtdfZonalSum(null, cnecC, Side.RIGHT))); - - assertEquals(3220., raoResult.getFlow(preventiveInstant, cnecC, Side.LEFT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(3220.5, raoResult.getFlow(preventiveInstant, cnecC, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getLoopFlow(null, cnecC, TwoSides.ONE, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getLoopFlow(null, cnecC, TwoSides.TWO, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getCommercialFlow(null, cnecC, TwoSides.ONE, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getCommercialFlow(null, cnecC, TwoSides.TWO, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getPtdfZonalSum(null, cnecC, TwoSides.ONE))); + assertTrue(Double.isNaN(raoResult.getPtdfZonalSum(null, cnecC, TwoSides.TWO))); + + assertEquals(3220., raoResult.getFlow(preventiveInstant, cnecC, TwoSides.ONE, AMPERE), DOUBLE_TOLERANCE); + assertEquals(3220.5, raoResult.getFlow(preventiveInstant, cnecC, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); assertEquals(3221., raoResult.getMargin(preventiveInstant, cnecC, AMPERE), DOUBLE_TOLERANCE); - assertEquals(3310., raoResult.getFlow(autoInstant, cnecC, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(3310.5, raoResult.getFlow(autoInstant, cnecC, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3310., raoResult.getFlow(autoInstant, cnecC, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3310.5, raoResult.getFlow(autoInstant, cnecC, TwoSides.TWO, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(3311., raoResult.getMargin(autoInstant, cnecC, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(3410., raoResult.getFlow(curativeInstant, cnecC, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(3410.5, raoResult.getFlow(curativeInstant, cnecC, Side.RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3410., raoResult.getFlow(curativeInstant, cnecC, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(3410.5, raoResult.getFlow(curativeInstant, cnecC, TwoSides.TWO, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(3411., raoResult.getMargin(curativeInstant, cnecC, MEGAWATT), DOUBLE_TOLERANCE); // ----------------------------- @@ -466,16 +466,16 @@ private Crac initCrac() { // dummy flow cnecs crac.newContingency().withId("contingency").withContingencyElement("co-ne", ContingencyElementType.LINE).add(); crac.newFlowCnec().withId("dummy-preventive").withInstant(PREVENTIVE_INSTANT_ID).withNetworkElement("ne") - .newThreshold().withMax(1.).withSide(Side.LEFT).withUnit(Unit.MEGAWATT).add() + .newThreshold().withMax(1.).withSide(TwoSides.ONE).withUnit(Unit.MEGAWATT).add() .add(); crac.newFlowCnec().withId("dummy-outage").withContingency("contingency").withInstant(OUTAGE_INSTANT_ID).withNetworkElement("ne") - .newThreshold().withMax(1.).withSide(Side.LEFT).withUnit(Unit.MEGAWATT).add() + .newThreshold().withMax(1.).withSide(TwoSides.ONE).withUnit(Unit.MEGAWATT).add() .add(); crac.newFlowCnec().withId("dummy-auto").withContingency("contingency").withInstant(AUTO_INSTANT_ID).withNetworkElement("ne") - .newThreshold().withMax(1.).withSide(Side.LEFT).withUnit(Unit.MEGAWATT).add() + .newThreshold().withMax(1.).withSide(TwoSides.ONE).withUnit(Unit.MEGAWATT).add() .add(); crac.newFlowCnec().withId("dummy-cur").withContingency("contingency").withInstant(CURATIVE_INSTANT_ID).withNetworkElement("ne") - .newThreshold().withMax(1.).withSide(Side.LEFT).withUnit(Unit.MEGAWATT).add() + .newThreshold().withMax(1.).withSide(TwoSides.ONE).withUnit(Unit.MEGAWATT).add() .add(); return crac; @@ -657,20 +657,20 @@ void testImplicitRoundTripWithUnits() throws IOException { } private void checkContentAmpere(RaoResult raoResult, FlowCnec cnecP) { - assertTrue(Double.isNaN(raoResult.getFlow(null, cnecP, Side.LEFT, MEGAWATT))); - assertTrue(Double.isNaN(raoResult.getFlow(null, cnecP, Side.RIGHT, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getFlow(null, cnecP, ONE, MEGAWATT))); + assertTrue(Double.isNaN(raoResult.getFlow(null, cnecP, TWO, MEGAWATT))); assertTrue(Double.isNaN(raoResult.getMargin(null, cnecP, MEGAWATT))); - assertEquals(4120, raoResult.getFlow(null, cnecP, Side.LEFT, AMPERE), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(raoResult.getFlow(null, cnecP, Side.RIGHT, AMPERE))); + assertEquals(4120, raoResult.getFlow(null, cnecP, ONE, AMPERE), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getFlow(null, cnecP, TWO, AMPERE))); assertEquals(4121, raoResult.getMargin(null, cnecP, AMPERE), DOUBLE_TOLERANCE); } private void checkContentMegawatt(RaoResult raoResult, FlowCnec cnecP) { - assertEquals(4110, raoResult.getFlow(null, cnecP, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(raoResult.getFlow(null, cnecP, Side.RIGHT, MEGAWATT))); + assertEquals(4110, raoResult.getFlow(null, cnecP, ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(raoResult.getFlow(null, cnecP, TWO, MEGAWATT))); assertEquals(4111, raoResult.getMargin(null, cnecP, MEGAWATT), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(raoResult.getFlow(null, cnecP, Side.LEFT, AMPERE))); - assertTrue(Double.isNaN(raoResult.getFlow(null, cnecP, Side.RIGHT, AMPERE))); + assertTrue(Double.isNaN(raoResult.getFlow(null, cnecP, ONE, AMPERE))); + assertTrue(Double.isNaN(raoResult.getFlow(null, cnecP, TWO, AMPERE))); assertTrue(Double.isNaN(raoResult.getMargin(null, cnecP, AMPERE))); } } diff --git a/data/rao-result/rao-result-json/src/test/resources/retrocompatibility/v1.5/crac-for-rao-result-v1.5.json b/data/rao-result/rao-result-json/src/test/resources/retrocompatibility/v1.5/crac-for-rao-result-v1.5.json new file mode 100644 index 0000000000..6b25436b20 --- /dev/null +++ b/data/rao-result/rao-result-json/src/test/resources/retrocompatibility/v1.5/crac-for-rao-result-v1.5.json @@ -0,0 +1,410 @@ +{ + "type" : "CRAC", + "version" : "1.5", + "info" : "Generated by FARAO http://farao-community.github.io", + "id" : "exhaustiveCracId", + "name" : "exhaustiveCracName", + "networkElementsNamePerId" : { + "ineId" : "ineName", + "ne5Id" : "ne5Name", + "eneId" : "eneName", + "ne2Id" : "ne2Name", + "voltageCnecNeId" : "voltageCnecNeName", + "generator2Id" : "generator2Name", + "to-close" : "to-close-name" + }, + "contingencies" : [ { + "id" : "contingency1Id", + "networkElementsIds" : [ "ne1Id" ] + }, { + "id" : "contingency2Id", + "networkElementsIds" : [ "ne2Id", "ne3Id" ] + } ], + "flowCnecs" : [ { + "id" : "cnec1outageId", + "name" : "cnec1outageId", + "networkElementId" : "ne4Id", + "operator" : "operator1", + "instant" : "outage", + "contingencyId" : "contingency1Id", + "optimized" : true, + "monitored" : false, + "reliabilityMargin" : 0.0, + "iMax" : [ NaN ], + "nominalV" : [ 220.0 ], + "thresholds" : [ { + "unit" : "ampere", + "min" : -800.0, + "side" : "right" + } ] + }, { + "id" : "cnec1prevId", + "name" : "cnec1prevId", + "networkElementId" : "ne4Id", + "operator" : "operator1", + "instant" : "preventive", + "optimized" : true, + "monitored" : false, + "reliabilityMargin" : 0.0, + "iMax" : [ NaN, 1000.0 ], + "nominalV" : [ 220.0 ], + "thresholds" : [ { + "unit" : "ampere", + "min" : -500.0, + "side" : "right" + } ] + }, { + "id" : "cnec2prevId", + "name" : "cnec2prevId", + "networkElementId" : "ne5Id", + "operator" : "operator2", + "instant" : "preventive", + "optimized" : true, + "monitored" : false, + "reliabilityMargin" : 0.0, + "iMax" : [ 2000.0 ], + "nominalV" : [ 380.0, 220.0 ], + "thresholds" : [ { + "unit" : "ampere", + "min" : -800.0, + "side" : "left" + }, { + "unit" : "ampere", + "min" : -800.0, + "side" : "right" + }, { + "unit" : "ampere", + "max" : 1200.0, + "side" : "right" + }, { + "unit" : "percent_imax", + "min" : -0.3, + "side" : "left" + } ] + }, { + "id" : "cnec3autoId", + "name" : "cnec3autoName", + "networkElementId" : "ne2Id", + "operator" : "operator3", + "instant" : "auto", + "contingencyId" : "contingency2Id", + "optimized" : false, + "monitored" : true, + "reliabilityMargin" : 20.0, + "iMax" : [ NaN ], + "nominalV" : [ NaN ], + "thresholds" : [ { + "unit" : "megawatt", + "max" : 500.0, + "side" : "left" + }, { + "unit" : "megawatt", + "max" : 500.0, + "side" : "right" + } ] + }, { + "id" : "cnec3curId", + "name" : "cnec3curId", + "networkElementId" : "ne2Id", + "operator" : "operator3", + "instant" : "curative", + "contingencyId" : "contingency2Id", + "optimized" : false, + "monitored" : true, + "reliabilityMargin" : 20.0, + "iMax" : [ NaN ], + "nominalV" : [ NaN ], + "thresholds" : [ { + "unit" : "megawatt", + "max" : 500.0, + "side" : "left" + }, { + "unit" : "megawatt", + "max" : 500.0, + "side" : "right" + } ] + }, { + "id" : "cnec3prevId", + "name" : "cnec3prevName", + "networkElementId" : "ne2Id", + "operator" : "operator3", + "instant" : "preventive", + "optimized" : false, + "monitored" : true, + "reliabilityMargin" : 20.0, + "iMax" : [ NaN ], + "nominalV" : [ NaN ], + "thresholds" : [ { + "unit" : "megawatt", + "max" : 500.0, + "side" : "left" + }, { + "unit" : "megawatt", + "max" : 500.0, + "side" : "right" + } ] + }, { + "id" : "cnec4prevId", + "name" : "cnec4prevName", + "networkElementId" : "ne3Id", + "operator" : "operator4", + "instant" : "preventive", + "optimized" : true, + "monitored" : true, + "reliabilityMargin" : 0.0, + "iMax" : [ NaN ], + "nominalV" : [ NaN ], + "thresholds" : [ { + "unit" : "megawatt", + "max" : 500.0, + "side" : "left" + } ] + } ], + "angleCnecs" : [ { + "id" : "angleCnecId", + "name" : "angleCnecName", + "exportingNetworkElementId" : "eneId", + "importingNetworkElementId" : "ineId", + "operator" : "operator1", + "instant" : "curative", + "contingencyId" : "contingency1Id", + "optimized" : false, + "monitored" : true, + "reliabilityMargin" : 10.0, + "thresholds" : [ { + "unit" : "degree", + "min" : -100.0, + "max" : 100.0 + } ] + } ], + "voltageCnecs" : [ { + "id" : "voltageCnecId", + "name" : "voltageCnecName", + "networkElementId" : "voltageCnecNeId", + "operator" : "operator1", + "instant" : "curative", + "contingencyId" : "contingency1Id", + "optimized" : false, + "monitored" : true, + "reliabilityMargin" : 1.0, + "thresholds" : [ { + "unit" : "kilovolt", + "min" : 380.0 + } ] + } ], + "pstRangeActions" : [ { + "id" : "pstRange1Id", + "name" : "pstRange1Name", + "operator" : "RTE", + "freeToUseUsageRules" : [ { + "instant" : "preventive", + "usageMethod" : "available" + } ], + "networkElementId" : "pst", + "initialTap" : 2, + "tapToAngleConversionMap" : { + "-3" : 0.0, + "-2" : 0.5, + "-1" : 1.0, + "0" : 1.5, + "1" : 2.0, + "2" : 2.5, + "3" : 3.0 + }, + "ranges" : [ { + "min" : 1, + "max" : 7, + "rangeType" : "absolute" + }, { + "min" : -3, + "max" : 3, + "rangeType" : "relativeToInitialNetwork" + } ] + }, { + "id" : "pstRange2Id", + "name" : "pstRange2Name", + "operator" : "RTE", + "onFlowConstraintUsageRules" : [ { + "instant" : "preventive", + "flowCnecId" : "cnec3prevId" + } ], + "networkElementId" : "pst2", + "groupId" : "group-1-pst", + "initialTap" : 1, + "tapToAngleConversionMap" : { + "-3" : 0.0, + "-2" : 0.5, + "-1" : 1.0, + "0" : 1.5, + "1" : 2.0, + "2" : 2.5, + "3" : 3.0 + }, + "ranges" : [ { + "min" : 1, + "max" : 7, + "rangeType" : "absolute" + }, { + "min" : -3, + "max" : 3, + "rangeType" : "relativeToInitialNetwork" + } ] + }, { + "id" : "pstRange3Id", + "name" : "pstRange3Name", + "operator" : "RTE", + "onAngleConstraintUsageRules" : [ { + "instant" : "curative", + "angleCnecId" : "angleCnecId" + } ], + "networkElementId" : "pst3", + "groupId" : "group-3-pst", + "initialTap" : 1, + "tapToAngleConversionMap" : { + "-3" : 0.0, + "-2" : 0.5, + "-1" : 1.0, + "0" : 1.5, + "1" : 2.0, + "2" : 2.5, + "3" : 3.0 + }, + "ranges" : [ { + "min" : 1, + "max" : 7, + "rangeType" : "absolute" + }, { + "min" : -3, + "max" : 3, + "rangeType" : "relativeToInitialNetwork" + } ] + } ], + "hvdcRangeActions" : [ { + "id" : "hvdcRange1Id", + "name" : "hvdcRange1Name", + "operator" : "RTE", + "onFlowConstraintInCountryUsageRules" : [ { + "instant" : "preventive", + "country" : "FR" + } ], + "networkElementId" : "hvdc", + "initialSetpoint" : 0.0, + "ranges" : [ { + "min" : -1000.0, + "max" : 1000.0 + } ] + }, { + "id" : "hvdcRange2Id", + "name" : "hvdcRange2Name", + "operator" : "RTE", + "onStateUsageRules" : [ { + "instant" : "curative", + "contingencyId" : "contingency1Id", + "usageMethod" : "available" + }, { + "instant" : "curative", + "contingencyId" : "contingency2Id", + "usageMethod" : "available" + } ], + "onFlowConstraintUsageRules" : [ { + "instant" : "preventive", + "flowCnecId" : "cnec3curId" + } ], + "networkElementId" : "hvdc2", + "groupId" : "group-1-hvdc", + "initialSetpoint" : 0.0, + "ranges" : [ { + "min" : -1000.0, + "max" : 1000.0 + } ] + } ], + "injectionRangeActions" : [ { + "id" : "injectionRange1Id", + "name" : "injectionRange1Name", + "operator" : null, + "onStateUsageRules" : [ { + "instant" : "curative", + "contingencyId" : "contingency1Id", + "usageMethod" : "available" + } ], + "onFlowConstraintInCountryUsageRules" : [ { + "instant" : "curative", + "country" : "ES" + } ], + "networkElementIdsAndKeys" : { + "generator1Id" : 1.0, + "generator2Id" : -1.0 + }, + "initialSetpoint" : 0.0, + "ranges" : [ { + "min" : -500.0, + "max" : 500.0 + }, { + "min" : -1000.0, + "max" : 1000.0 + } ] + } ], + "networkActions" : [ { + "id" : "complexNetworkActionId", + "name" : "complexNetworkActionName", + "operator" : "RTE", + "freeToUseUsageRules" : [ { + "instant" : "preventive", + "usageMethod" : "available" + } ], + "onStateUsageRules" : [ { + "instant" : "preventive", + "usageMethod" : "forced" + } ], + "topologicalActions" : [ { + "networkElementId" : "ne1Id", + "actionType" : "close" + } ], + "pstSetpoints" : [ { + "networkElementId" : "pst", + "setpoint" : 5 + } ] + }, { + "id" : "injectionSetpointRaId", + "name" : "injectionSetpointRaName", + "operator" : "RTE", + "onFlowConstraintUsageRules" : [ { + "instant" : "auto", + "flowCnecId" : "cnec3autoId" + } ], + "injectionSetpoints" : [ { + "networkElementId" : "injection", + "setpoint" : 260.0 + } ] + }, { + "id" : "pstSetpointRaId", + "name" : "pstSetpointRaName", + "operator" : "RTE", + "freeToUseUsageRules" : [ { + "instant" : "preventive", + "usageMethod" : "available" + } ], + "onStateUsageRules" : [ { + "instant" : "curative", + "contingencyId" : "contingency1Id", + "usageMethod" : "forced" + } ], + "pstSetpoints" : [ { + "networkElementId" : "pst", + "setpoint" : 15 + } ] + }, { + "id" : "switchPairRaId", + "name" : "switchPairRaName", + "operator" : "RTE", + "onStateUsageRules" : [ { + "instant" : "curative", + "contingencyId" : "contingency2Id", + "usageMethod" : "available" + } ], + "switchPairs" : [ { + "open" : "to-open", + "close" : "to-close" + } ] + } ] +} \ No newline at end of file diff --git a/data/rao-result/rao-result-json/src/test/resources/retrocompatibility/v1.5/rao-result-v1.5.json b/data/rao-result/rao-result-json/src/test/resources/retrocompatibility/v1.5/rao-result-v1.5.json new file mode 100644 index 0000000000..b3e15e12ca --- /dev/null +++ b/data/rao-result/rao-result-json/src/test/resources/retrocompatibility/v1.5/rao-result-v1.5.json @@ -0,0 +1,552 @@ +{ + "type" : "RAO_RESULT", + "version" : "1.5", + "info" : "Generated by FARAO http://farao-community.github.io", + "computationStatus" : "default", + "optimizationStepsExecuted" : "The RAO only went through first preventive", + "costResults" : { + "initial" : { + "functionalCost" : 100.0, + "virtualCost" : { + "loopFlow" : 0.0, + "MNEC" : 0.0 + } + }, + "preventive" : { + "functionalCost" : 80.0, + "virtualCost" : { + "loopFlow" : 0.0, + "MNEC" : 0.0 + } + }, + "auto" : { + "functionalCost" : -20.0, + "virtualCost" : { + "loopFlow" : 15.0, + "MNEC" : 20.0 + } + }, + "curative" : { + "functionalCost" : -50.0, + "virtualCost" : { + "loopFlow" : 10.0, + "MNEC" : 2.0 + } + } + }, + "computationStatusMap" : [ { + "computationStatus" : "FAILURE", + "instant" : "curative", + "contingency" : "contingency1Id" + } ], + "flowCnecResults" : [ { + "flowCnecId" : "cnec1outageId", + "initial" : { + "ampere" : { + "margin" : 1121.0, + "relativeMargin" : 1122.0, + "side2" : { + "flow" : 1120.5, + "loopFlow" : 1123.5, + "commercialFlow" : 1124.5 + } + }, + "megawatt" : { + "margin" : 1111.0, + "relativeMargin" : 1112.0, + "side2" : { + "flow" : 1110.5, + "loopFlow" : 1113.5, + "commercialFlow" : 1114.5, + "zonalPtdfSum" : 0.6 + } + } + }, + "preventive" : { + "ampere" : { + "margin" : 1221.0, + "relativeMargin" : 1222.0, + "side2" : { + "flow" : 1220.5, + "loopFlow" : 1223.5, + "commercialFlow" : 1224.5 + } + }, + "megawatt" : { + "margin" : 1211.0, + "relativeMargin" : 1212.0, + "side2" : { + "flow" : 1210.5, + "loopFlow" : 1213.5, + "commercialFlow" : 1214.5, + "zonalPtdfSum" : 0.6 + } + } + } + }, { + "flowCnecId" : "cnec1prevId", + "initial" : { + "ampere" : { + "margin" : 1121.0, + "relativeMargin" : 1122.0, + "side2" : { + "flow" : 1120.5, + "loopFlow" : 1123.5, + "commercialFlow" : 1124.5 + } + }, + "megawatt" : { + "margin" : 1111.0, + "relativeMargin" : 1112.0, + "side2" : { + "flow" : 1110.5, + "loopFlow" : 1113.5, + "commercialFlow" : 1114.5, + "zonalPtdfSum" : 0.6 + } + } + }, + "preventive" : { + "ampere" : { + "margin" : 1221.0, + "relativeMargin" : 1222.0, + "side2" : { + "flow" : 1220.5, + "loopFlow" : 1223.5, + "commercialFlow" : 1224.5 + } + }, + "megawatt" : { + "margin" : 1211.0, + "relativeMargin" : 1212.0, + "side2" : { + "flow" : 1210.5, + "loopFlow" : 1213.5, + "commercialFlow" : 1214.5, + "zonalPtdfSum" : 0.6 + } + } + } + }, { + "flowCnecId" : "cnec2prevId", + "initial" : { + "ampere" : { + "margin" : 2121.0, + "relativeMargin" : 2122.0, + "side1" : { + "flow" : 2120.0, + "loopFlow" : 2123.0, + "commercialFlow" : 2124.0 + }, + "side2" : { + "flow" : 2120.5, + "loopFlow" : 2123.5, + "commercialFlow" : 2124.5 + } + }, + "megawatt" : { + "margin" : 2111.0, + "relativeMargin" : 2112.0, + "side1" : { + "flow" : 2110.0, + "loopFlow" : 2113.0, + "commercialFlow" : 2114.0, + "zonalPtdfSum" : 0.2 + }, + "side2" : { + "flow" : 2110.5, + "loopFlow" : 2113.5, + "commercialFlow" : 2114.5, + "zonalPtdfSum" : 0.7 + } + } + }, + "preventive" : { + "ampere" : { + "margin" : 2221.0, + "relativeMargin" : 2222.0, + "side1" : { + "flow" : 2220.0, + "loopFlow" : 2223.0, + "commercialFlow" : 2224.0 + }, + "side2" : { + "flow" : 2220.5, + "loopFlow" : 2223.5, + "commercialFlow" : 2224.5 + } + }, + "megawatt" : { + "margin" : 2211.0, + "relativeMargin" : 2212.0, + "side1" : { + "flow" : 2210.0, + "loopFlow" : 2213.0, + "commercialFlow" : 2214.0, + "zonalPtdfSum" : 0.2 + }, + "side2" : { + "flow" : 2210.5, + "loopFlow" : 2213.5, + "commercialFlow" : 2214.5, + "zonalPtdfSum" : 0.7 + } + } + } + }, { + "flowCnecId" : "cnec3autoId", + "initial" : { + "ampere" : { + "margin" : 3121.0, + "side1" : { + "flow" : 3120.0 + }, + "side2" : { + "flow" : 3120.5 + } + }, + "megawatt" : { + "margin" : 3111.0, + "side1" : { + "flow" : 3110.0 + }, + "side2" : { + "flow" : 3110.5 + } + } + }, + "preventive" : { + "ampere" : { + "margin" : 3221.0, + "side1" : { + "flow" : 3220.0 + }, + "side2" : { + "flow" : 3220.5 + } + }, + "megawatt" : { + "margin" : 3211.0, + "side1" : { + "flow" : 3210.0 + }, + "side2" : { + "flow" : 3210.5 + } + } + }, + "auto" : { + "ampere" : { + "margin" : 3321.0, + "side1" : { + "flow" : 3320.0 + }, + "side2" : { + "flow" : 3320.5 + } + }, + "megawatt" : { + "margin" : 3311.0, + "side1" : { + "flow" : 3310.0 + }, + "side2" : { + "flow" : 3310.5 + } + } + }, + "curative" : { + "ampere" : { + "margin" : 3321.0, + "side1" : { + "flow" : 3320.0 + }, + "side2" : { + "flow" : 3320.5 + } + }, + "megawatt" : { + "margin" : 3311.0, + "side1" : { + "flow" : 3310.0 + }, + "side2" : { + "flow" : 3310.5 + } + } + } + }, { + "flowCnecId" : "cnec3curId", + "initial" : { + "ampere" : { + "margin" : 3121.0, + "side1" : { + "flow" : 3120.0 + }, + "side2" : { + "flow" : 3120.5 + } + }, + "megawatt" : { + "margin" : 3111.0, + "side1" : { + "flow" : 3110.0 + }, + "side2" : { + "flow" : 3110.5 + } + } + }, + "preventive" : { + "ampere" : { + "margin" : 3221.0, + "side1" : { + "flow" : 3220.0 + }, + "side2" : { + "flow" : 3220.5 + } + }, + "megawatt" : { + "margin" : 3211.0, + "side1" : { + "flow" : 3210.0 + }, + "side2" : { + "flow" : 3210.5 + } + } + }, + "auto" : { + "ampere" : { + "margin" : 3321.0, + "side1" : { + "flow" : 3320.0 + }, + "side2" : { + "flow" : 3320.5 + } + }, + "megawatt" : { + "margin" : 3311.0, + "side1" : { + "flow" : 3310.0 + }, + "side2" : { + "flow" : 3310.5 + } + } + }, + "curative" : { + "ampere" : { + "margin" : 3421.0, + "side1" : { + "flow" : 3420.0 + }, + "side2" : { + "flow" : 3420.5 + } + }, + "megawatt" : { + "margin" : 3411.0, + "side1" : { + "flow" : 3410.0 + }, + "side2" : { + "flow" : 3410.5 + } + } + } + }, { + "flowCnecId" : "cnec3prevId", + "initial" : { + "ampere" : { + "margin" : 3121.0, + "side1" : { + "flow" : 3120.0 + }, + "side2" : { + "flow" : 3120.5 + } + }, + "megawatt" : { + "margin" : 3111.0, + "side1" : { + "flow" : 3110.0 + }, + "side2" : { + "flow" : 3110.5 + } + } + }, + "preventive" : { + "ampere" : { + "margin" : 3221.0, + "side1" : { + "flow" : 3220.0 + }, + "side2" : { + "flow" : 3220.5 + } + }, + "megawatt" : { + "margin" : 3211.0, + "side1" : { + "flow" : 3210.0 + }, + "side2" : { + "flow" : 3210.5 + } + } + } + }, { + "flowCnecId" : "cnec4prevId", + "initial" : { + "ampere" : { + "margin" : 4121.0, + "relativeMargin" : 4122.0, + "side1" : { + "flow" : 4120.0 + } + }, + "megawatt" : { + "margin" : 4111.0, + "relativeMargin" : 4112.0, + "side1" : { + "flow" : 4110.0, + "zonalPtdfSum" : 0.4 + } + } + }, + "preventive" : { + "ampere" : { + "margin" : 4221.0, + "relativeMargin" : 4222.0, + "side1" : { + "flow" : 4220.0 + } + }, + "megawatt" : { + "margin" : 4211.0, + "relativeMargin" : 4212.0, + "side1" : { + "flow" : 4210.0, + "zonalPtdfSum" : 0.4 + } + } + } + } ], + "angleCnecResults" : [ { + "angleCnecId" : "angleCnecId", + "initial" : { + "degree" : { + "angle" : 3135.0, + "margin" : 3131.0 + } + }, + "preventive" : { + "degree" : { + "angle" : 3235.0, + "margin" : 3231.0 + } + }, + "auto" : { + "degree" : { + "angle" : 3335.0, + "margin" : 3331.0 + } + }, + "curative" : { + "degree" : { + "angle" : 3435.0, + "margin" : 3431.0 + } + } + } ], + "voltageCnecResults" : [ { + "voltageCnecId" : "voltageCnecId", + "initial" : { + "kilovolt" : { + "voltage" : 4146.0, + "margin" : 4141.0 + } + }, + "preventive" : { + "kilovolt" : { + "voltage" : 4246.0, + "margin" : 4241.0 + } + }, + "auto" : { + "kilovolt" : { + "voltage" : 4346.0, + "margin" : 4341.0 + } + }, + "curative" : { + "kilovolt" : { + "voltage" : 4446.0, + "margin" : 4441.0 + } + } + } ], + "networkActionResults" : [ { + "networkActionId" : "complexNetworkActionId", + "activatedStates" : [ { + "instant" : "preventive" + } ] + }, { + "networkActionId" : "injectionSetpointRaId", + "activatedStates" : [ { + "instant" : "auto", + "contingency" : "contingency2Id" + } ] + }, { + "networkActionId" : "pstSetpointRaId", + "activatedStates" : [ { + "instant" : "curative", + "contingency" : "contingency1Id" + } ] + } ], + "rangeActionResults" : [ { + "rangeActionId" : "hvdcRange1Id", + "initialSetpoint" : 0.0, + "activatedStates" : [ { + "instant" : "preventive", + "setpoint" : -1000.0 + } ] + }, { + "rangeActionId" : "hvdcRange2Id", + "initialSetpoint" : -100.0, + "activatedStates" : [ { + "instant" : "curative", + "contingency" : "contingency2Id", + "setpoint" : 400.0 + }, { + "instant" : "curative", + "contingency" : "contingency1Id", + "setpoint" : 100.0 + } ] + }, { + "rangeActionId" : "injectionRange1Id", + "initialSetpoint" : 100.0, + "activatedStates" : [ { + "instant" : "curative", + "contingency" : "contingency1Id", + "setpoint" : -300.0 + } ] + }, { + "rangeActionId" : "pstRange1Id", + "initialSetpoint" : 0.0, + "activatedStates" : [ { + "instant" : "preventive", + "setpoint" : 3.0 + } ] + }, { + "rangeActionId" : "pstRange2Id", + "initialSetpoint" : 1.5 + }, { + "rangeActionId" : "pstRange3Id", + "initialSetpoint" : 1.0 + } ] +} \ No newline at end of file diff --git a/data/result-exporter/core-cne-exporter/src/main/java/com/powsybl/openrao/data/corecneexporter/CoreCneCnecsCreator.java b/data/result-exporter/core-cne-exporter/src/main/java/com/powsybl/openrao/data/corecneexporter/CoreCneCnecsCreator.java index 403f33b7a0..f1c7ff0612 100644 --- a/data/result-exporter/core-cne-exporter/src/main/java/com/powsybl/openrao/data/corecneexporter/CoreCneCnecsCreator.java +++ b/data/result-exporter/core-cne-exporter/src/main/java/com/powsybl/openrao/data/corecneexporter/CoreCneCnecsCreator.java @@ -19,7 +19,7 @@ import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.InstantKind; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.craccreation.creator.api.stdcreationcontext.BranchCnecCreationContext; import com.powsybl.openrao.data.craccreation.creator.api.stdcreationcontext.UcteCracCreationContext; import com.powsybl.openrao.data.cracloopflowextension.LoopFlowThreshold; @@ -215,7 +215,7 @@ private List createMarginMeasurementsOfFlowCnec(FlowCnec cnec, Instant o return measurements; } - private double getCnecFlow(FlowCnec cnec, Side side, Instant optimizedInstant) { + private double getCnecFlow(FlowCnec cnec, TwoSides side, Instant optimizedInstant) { Instant resultState = optimizedInstant; if (resultState != null && resultState.isCurative() && cnec.getState().getInstant().isPreventive()) { resultState = cracCreationContext.getCrac().getPreventiveInstant(); @@ -287,7 +287,7 @@ private double getClosestThreshold(FlowCnec cnec, Instant optimizedInstant, bool */ private Map getThresholdToMarginMap(FlowCnec cnec, Instant optimizedInstant, boolean asMnec, Unit unit, boolean deductFrmFromThreshold) { Map thresholdToMarginMap = new HashMap<>(); - Side side = getMonitoredSide(cnec); + TwoSides side = getMonitoredSide(cnec); double flow = getCnecFlow(cnec, side, optimizedInstant); if (!Double.isNaN(flow)) { if (false) { @@ -300,7 +300,7 @@ private Map getThresholdToMarginMap(FlowCnec cnec, Instant optim return thresholdToMarginMap; } - private void getThresholdToMarginMapAsCnec(FlowCnec cnec, Unit unit, boolean deductFrmFromThreshold, Map thresholdToMarginMap, double flow, Side side) { + private void getThresholdToMarginMapAsCnec(FlowCnec cnec, Unit unit, boolean deductFrmFromThreshold, Map thresholdToMarginMap, double flow, TwoSides side) { // TODO : remove this when we go back to considering FRM in the exported threshold double flowUnitMultiplier = getFlowUnitMultiplier(cnec, side, Unit.MEGAWATT, unit); double frm = deductFrmFromThreshold ? 0 : cnec.getReliabilityMargin() * flowUnitMultiplier; @@ -314,7 +314,7 @@ private void getThresholdToMarginMapAsCnec(FlowCnec cnec, Unit unit, boolean ded thresholdToMarginMap.putIfAbsent(minThreshold, flow * flowUnitMultiplier - minThreshold); } - private void getThresholdToMarginMapAsMnec(FlowCnec cnec, Unit unit, Map thresholdToMarginMap, double flow, Side side) { + private void getThresholdToMarginMapAsMnec(FlowCnec cnec, Unit unit, Map thresholdToMarginMap, double flow, TwoSides side) { // Look at thresholds computed using initial flow double flowUnitMultiplier = getFlowUnitMultiplier(cnec, side, Unit.MEGAWATT, unit); double initialFlow = getCnecFlow(cnec, getMonitoredSide(cnec), null) * flowUnitMultiplier; @@ -359,7 +359,7 @@ private List createLoopflowMeasurements(FlowCnec cnec, Instant optimized return measurements; } - public static double getFlowUnitMultiplier(FlowCnec cnec, Side voltageSide, Unit unitFrom, Unit unitTo) { + public static double getFlowUnitMultiplier(FlowCnec cnec, TwoSides voltageSide, Unit unitFrom, Unit unitTo) { if (unitFrom == unitTo) { return 1; } @@ -373,7 +373,7 @@ public static double getFlowUnitMultiplier(FlowCnec cnec, Side voltageSide, Unit } } - private Side getMonitoredSide(FlowCnec cnec) { - return cnec.getMonitoredSides().contains(Side.LEFT) ? Side.LEFT : Side.RIGHT; + private TwoSides getMonitoredSide(FlowCnec cnec) { + return cnec.getMonitoredSides().contains(TwoSides.ONE) ? TwoSides.ONE : TwoSides.TWO; } } diff --git a/data/result-exporter/core-cne-exporter/src/test/java/com/powsybl/openrao/data/corecneexporter/CoreCneCnecsCreatorTest.java b/data/result-exporter/core-cne-exporter/src/test/java/com/powsybl/openrao/data/corecneexporter/CoreCneCnecsCreatorTest.java index c1360916c8..96d3bd8c27 100644 --- a/data/result-exporter/core-cne-exporter/src/test/java/com/powsybl/openrao/data/corecneexporter/CoreCneCnecsCreatorTest.java +++ b/data/result-exporter/core-cne-exporter/src/test/java/com/powsybl/openrao/data/corecneexporter/CoreCneCnecsCreatorTest.java @@ -17,7 +17,7 @@ import com.powsybl.openrao.data.corecneexporter.xsd.*; import com.powsybl.openrao.data.cracapi.*; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracloopflowextension.LoopFlowThresholdAdder; import com.powsybl.openrao.data.raoresultapi.RaoResult; @@ -133,7 +133,7 @@ private int checkMeasurement(List measurements, int index, String expect } private void mockCnecResult(FlowCnec cnec, double flowMw, double marginA, double marginMw, double relMarginA, double relMarginMw, double ptdf) { - Side monitoredSide = cnec.getMonitoredSides().contains(Side.LEFT) ? Side.LEFT : Side.RIGHT; + TwoSides monitoredSide = cnec.getMonitoredSides().contains(TwoSides.ONE) ? TwoSides.ONE : TwoSides.TWO; Mockito.when(raoResult.getFlow(any(), eq(cnec), eq(monitoredSide), eq(Unit.AMPERE))).thenThrow(new OpenRaoException("No ampere allowed")); Mockito.when(raoResult.getFlow(any(), eq(cnec), eq(monitoredSide), eq(Unit.MEGAWATT))).thenReturn(flowMw); Mockito.when(raoResult.getMargin(any(), eq(cnec), eq(Unit.AMPERE))).thenThrow(new OpenRaoException("No ampere allowed")); @@ -153,7 +153,7 @@ void testExportTwoPreventiveCnecs() { .withOptimized() .withNominalVoltage(400.) .withReliabilityMargin(0.) - .newThreshold().withUnit(Unit.MEGAWATT).withMax(100.).withSide(Side.RIGHT).add() + .newThreshold().withUnit(Unit.MEGAWATT).withMax(100.).withSide(TwoSides.TWO).add() .add(); mockCnecResult(cnec1, 80, 10, 20, 100, 200, .1); @@ -166,7 +166,7 @@ void testExportTwoPreventiveCnecs() { .withOptimized() .withNominalVoltage(400.) .withReliabilityMargin(10.) - .newThreshold().withUnit(Unit.MEGAWATT).withMax(1000.).withSide(Side.RIGHT).add() + .newThreshold().withUnit(Unit.MEGAWATT).withMax(1000.).withSide(TwoSides.TWO).add() .add(); mockCnecResult(cnec2, 800, -100, -200, -99999999, -999999999, .2); @@ -218,7 +218,7 @@ void testExportPreventivePureMnec() { .withMonitored() .withNominalVoltage(400.) .withReliabilityMargin(0.) - .newThreshold().withUnit(Unit.MEGAWATT).withMax(100.).withSide(Side.RIGHT).add() + .newThreshold().withUnit(Unit.MEGAWATT).withMax(100.).withSide(TwoSides.TWO).add() .add(); mockCnecResult(cnec1, 80, 10, 20, 100, 200, .1); @@ -256,7 +256,7 @@ void testExportPreventiveCnecAndMnec() { .withMonitored() .withNominalVoltage(400.) .withReliabilityMargin(10.) - .newThreshold().withUnit(Unit.MEGAWATT).withMax(100.).withSide(Side.RIGHT).add() + .newThreshold().withUnit(Unit.MEGAWATT).withMax(100.).withSide(TwoSides.TWO).add() .add(); mockCnecResult(cnec1, 80, 10, 20, 100, 200, .1); @@ -308,7 +308,7 @@ void testCurativeCnecs() { .withOptimized() .withNominalVoltage(400.) .withReliabilityMargin(30.) - .newThreshold().withUnit(Unit.MEGAWATT).withMax(100.).withSide(Side.RIGHT).add() + .newThreshold().withUnit(Unit.MEGAWATT).withMax(100.).withSide(TwoSides.TWO).add() .add(); FlowCnec cnecOutage = crac.newFlowCnec() .withId("cnec1 - Outage") @@ -319,7 +319,7 @@ void testCurativeCnecs() { .withOptimized() .withNominalVoltage(400.) .withReliabilityMargin(20.) - .newThreshold().withUnit(Unit.MEGAWATT).withMax(200.).withSide(Side.RIGHT).add() + .newThreshold().withUnit(Unit.MEGAWATT).withMax(200.).withSide(TwoSides.TWO).add() .add(); FlowCnec cnecCur = crac.newFlowCnec() .withId("cnec1 - Curative") @@ -330,7 +330,7 @@ void testCurativeCnecs() { .withOptimized() .withNominalVoltage(400.) .withReliabilityMargin(20.) - .newThreshold().withUnit(Unit.MEGAWATT).withMax(150.).withSide(Side.RIGHT).add() + .newThreshold().withUnit(Unit.MEGAWATT).withMax(150.).withSide(TwoSides.TWO).add() .add(); mockCnecResult(cnecPrev, 80, 10, 20, 100, 200, .1); @@ -384,12 +384,12 @@ void testWithLoopFlow() { .withOptimized() .withNominalVoltage(400.) .withReliabilityMargin(0.) - .newThreshold().withUnit(Unit.MEGAWATT).withMax(100.).withSide(Side.RIGHT).add() + .newThreshold().withUnit(Unit.MEGAWATT).withMax(100.).withSide(TwoSides.TWO).add() .add(); cnec1.newExtension(LoopFlowThresholdAdder.class).withValue(321.).withUnit(Unit.MEGAWATT).add(); mockCnecResult(cnec1, 80, 10, 20, 100, 200, .1); - Mockito.when(raoResult.getLoopFlow(any(), eq(cnec1), eq(Side.RIGHT), eq(Unit.MEGAWATT))).thenReturn(123.); + Mockito.when(raoResult.getLoopFlow(any(), eq(cnec1), eq(TwoSides.TWO), eq(Unit.MEGAWATT))).thenReturn(123.); raoParameters.getObjectiveFunctionParameters().setType(ObjectiveFunctionParameters.ObjectiveFunctionType.MAX_MIN_RELATIVE_MARGIN_IN_MEGAWATT); raoParameters.addExtension(LoopFlowParametersExtension.class, new LoopFlowParametersExtension()); diff --git a/data/result-exporter/core-cne-exporter/src/test/java/com/powsybl/openrao/data/corecneexporter/CoreCneRemedialActionsCreatorTest.java b/data/result-exporter/core-cne-exporter/src/test/java/com/powsybl/openrao/data/corecneexporter/CoreCneRemedialActionsCreatorTest.java index e78aefec7d..54bc52a772 100644 --- a/data/result-exporter/core-cne-exporter/src/test/java/com/powsybl/openrao/data/corecneexporter/CoreCneRemedialActionsCreatorTest.java +++ b/data/result-exporter/core-cne-exporter/src/test/java/com/powsybl/openrao/data/corecneexporter/CoreCneRemedialActionsCreatorTest.java @@ -20,7 +20,7 @@ import com.powsybl.openrao.data.cracapi.CracFactory; import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.InstantKind; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.ActionType; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; @@ -81,7 +81,7 @@ public void setUp() { .withNetworkElement("BBE2AA1 BBE3AA1 1") .withContingency("contingency-id") .withInstant(CURATIVE_INSTANT_ID) - .newThreshold().withUnit(Unit.MEGAWATT).withMax(100.).withSide(Side.RIGHT).add() + .newThreshold().withUnit(Unit.MEGAWATT).withMax(100.).withSide(TwoSides.TWO).add() .add(); raoResult = Mockito.mock(RaoResult.class); raoParameters = new RaoParameters(); diff --git a/data/result-exporter/swe-cne-exporter/src/main/java/com/powsybl/openrao/data/swecneexporter/SweMonitoredSeriesCreator.java b/data/result-exporter/swe-cne-exporter/src/main/java/com/powsybl/openrao/data/swecneexporter/SweMonitoredSeriesCreator.java index 33a667916b..b5ec0335e8 100644 --- a/data/result-exporter/swe-cne-exporter/src/main/java/com/powsybl/openrao/data/swecneexporter/SweMonitoredSeriesCreator.java +++ b/data/result-exporter/swe-cne-exporter/src/main/java/com/powsybl/openrao/data/swecneexporter/SweMonitoredSeriesCreator.java @@ -13,7 +13,7 @@ import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.craccreation.creator.cim.craccreator.CimCracCreationContext; import com.powsybl.openrao.data.craccreation.creator.cim.craccreator.cnec.CnecCreationContext; import com.powsybl.openrao.data.craccreation.creator.cim.craccreator.cnec.MeasurementCreationContext; @@ -89,7 +89,7 @@ public List generateMonitoredSeries(Contingency contingency) { private double getCnecFlowClosestToThreshold(Instant optimizedInstant, FlowCnec cnec) { double flow = 0.0; double margin = Double.POSITIVE_INFINITY; - for (Side side : cnec.getMonitoredSides()) { + for (TwoSides side : cnec.getMonitoredSides()) { double flowOnSide = sweCneHelper.getRaoResult().getFlow(optimizedInstant, cnec, side, Unit.AMPERE); if (Double.isNaN(flowOnSide)) { continue; @@ -122,7 +122,7 @@ private void mergeSeries(MonitoredSeries monitoredSeries, FlowCnec cnec) { Analog threshold = new Analog(); threshold.setMeasurementType(getThresholdMeasurementType(cnec)); threshold.setUnitSymbol(AMP_UNIT_SYMBOL); - Side side = cnec.getMonitoredSides().contains(Side.LEFT) ? Side.LEFT : cnec.getMonitoredSides().iterator().next(); + TwoSides side = cnec.getMonitoredSides().contains(TwoSides.ONE) ? TwoSides.ONE : cnec.getMonitoredSides().iterator().next(); float roundedThreshold = Math.round(Math.min( Math.abs(cnec.getLowerBound(side, Unit.AMPERE).orElse(Double.POSITIVE_INFINITY)), Math.abs(cnec.getUpperBound(side, Unit.AMPERE).orElse(Double.NEGATIVE_INFINITY)))); @@ -156,7 +156,7 @@ private MonitoredSeries generateMonitoredSeriesFromScratch(MonitoredSeriesCreati Analog threshold = new Analog(); threshold.setMeasurementType(getThresholdMeasurementType(cnec)); threshold.setUnitSymbol(AMP_UNIT_SYMBOL); - Side side = cnec.getMonitoredSides().contains(Side.LEFT) ? Side.LEFT : cnec.getMonitoredSides().iterator().next(); + TwoSides side = cnec.getMonitoredSides().contains(TwoSides.ONE) ? TwoSides.ONE : cnec.getMonitoredSides().iterator().next(); float roundedThreshold = Math.round(Math.min( Math.abs(cnec.getLowerBound(side, Unit.AMPERE).orElse(Double.POSITIVE_INFINITY)), Math.abs(cnec.getUpperBound(side, Unit.AMPERE).orElse(Double.NEGATIVE_INFINITY)))); diff --git a/data/result-exporter/swe-cne-exporter/src/test/java/com/powsybl/openrao/data/swecneexporter/SweMonitoredSeriesCreatorTest.java b/data/result-exporter/swe-cne-exporter/src/test/java/com/powsybl/openrao/data/swecneexporter/SweMonitoredSeriesCreatorTest.java index aa8a4fab76..ae884b2a8d 100644 --- a/data/result-exporter/swe-cne-exporter/src/test/java/com/powsybl/openrao/data/swecneexporter/SweMonitoredSeriesCreatorTest.java +++ b/data/result-exporter/swe-cne-exporter/src/test/java/com/powsybl/openrao/data/swecneexporter/SweMonitoredSeriesCreatorTest.java @@ -11,7 +11,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.*; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.craccreation.creator.cim.craccreator.CimCracCreationContext; import com.powsybl.openrao.data.craccreation.creator.cim.craccreator.cnec.CnecCreationContext; import com.powsybl.openrao.data.craccreation.creator.cim.craccreator.cnec.MeasurementCreationContext; @@ -173,7 +173,7 @@ private void addCnecToCracAndNetwork(String cnecId, Instant instant, Contingency Mockito.when(state.getContingency()).thenReturn(Objects.isNull(contingency) ? Optional.empty() : Optional.of(contingency)); Mockito.when(cnec.getState()).thenReturn(state); - Mockito.when(cnec.getIMax(Side.LEFT)).thenReturn(1000.); + Mockito.when(cnec.getIMax(TwoSides.ONE)).thenReturn(1000.); NetworkElement networkElement = Mockito.mock(NetworkElement.class); Mockito.when(networkElement.getId()).thenReturn(resourceId); @@ -203,10 +203,10 @@ private void setCnecResult(MonitoredSeriesCreationContext mscc, Instant instant, cnecId = mscc.getNativeName() + " - " + instant; } FlowCnec flowCnec = crac.getFlowCnec(cnecId); - Mockito.when(flowCnec.getMonitoredSides()).thenReturn(Set.of(Side.LEFT, Side.RIGHT)); - Mockito.when(raoResult.getFlow(instant, flowCnec, Side.LEFT, Unit.AMPERE)).thenReturn(flow); - Mockito.when(raoResult.getFlow(instant, flowCnec, Side.RIGHT, Unit.AMPERE)).thenReturn(flow + 10); - Mockito.when(flowCnec.computeMargin(flow, Side.LEFT, Unit.AMPERE)).thenReturn(1000 - flow); - Mockito.when(flowCnec.computeMargin(flow, Side.RIGHT, Unit.AMPERE)).thenReturn(1100 - flow); + Mockito.when(flowCnec.getMonitoredSides()).thenReturn(Set.of(TwoSides.ONE, TwoSides.TWO)); + Mockito.when(raoResult.getFlow(instant, flowCnec, TwoSides.ONE, Unit.AMPERE)).thenReturn(flow); + Mockito.when(raoResult.getFlow(instant, flowCnec, TwoSides.TWO, Unit.AMPERE)).thenReturn(flow + 10); + Mockito.when(flowCnec.computeMargin(flow, TwoSides.ONE, Unit.AMPERE)).thenReturn(1000 - flow); + Mockito.when(flowCnec.computeMargin(flow, TwoSides.TWO, Unit.AMPERE)).thenReturn(1100 - flow); } } diff --git a/docs/input-data/crac/creation-context.md b/docs/input-data/crac/creation-context.md index 45f9fdc650..99c7dbc07b 100644 --- a/docs/input-data/crac/creation-context.md +++ b/docs/input-data/crac/creation-context.md @@ -139,8 +139,8 @@ void printSomeResults(BranchCnecCreationContext context, CracCreationContext cra context.getCreatedCnecsIds().entrySet().forEach(entry -> { System.out.println(String.format("Created CNEC for instant %s: %s", entry.getKey(), entry.getValue())); FlowCnec flowCnec = cracCreationContext.getCrac().getFlowCnec(entry.getValue()); - System.out.println(String.format("The left-side flow on this native critical branch after RAO is: %.2f A", flowMultiplier * raoResult.getFlow(OptimizationState.afterOptimizing(flowCnec.getState()), flowCnec, Side.LEFT, Unit.AMPERE))); - System.out.println(String.format("The right-side flow on this native critical branch after RAO is: %.2f A", flowMultiplier * raoResult.getFlow(OptimizationState.afterOptimizing(flowCnec.getState()), flowCnec, Side.RIGHT, Unit.AMPERE))); + System.out.println(String.format("The left-side flow on this native critical branch after RAO is: %.2f A", flowMultiplier * raoResult.getFlow(OptimizationState.afterOptimizing(flowCnec.getState()), flowCnec, TwoSides.ONE, Unit.AMPERE))); + System.out.println(String.format("The right-side flow on this native critical branch after RAO is: %.2f A", flowMultiplier * raoResult.getFlow(OptimizationState.afterOptimizing(flowCnec.getState()), flowCnec, TwoSides.TWO, Unit.AMPERE))); System.out.println(String.format("The flow margin on this native critical branch after RAO is: %.2f A", raoResult.getMargin(OptimizationState.afterOptimizing(flowCnec.getState()), flowCnec, Unit.AMPERE))); } ); diff --git a/docs/input-data/crac/creation-parameters.md b/docs/input-data/crac/creation-parameters.md index 505524032f..9a7e78e03b 100644 --- a/docs/input-data/crac/creation-parameters.md +++ b/docs/input-data/crac/creation-parameters.md @@ -48,8 +48,8 @@ convention), when optimizing line's flow margin. Note that this parameter is ignored when the line side to monitor is defined by the native CRAC itself (e.g. when a cross-border tie-line is monitored by one TSO only, then the RAO will automatically detect on which side this TSO is). Possible values for this parameter are: -- **monitor-lines-on-left-side** to monitor lines on left side only (typically to be used in DC-loadflow mode) -- **monitor-lines-on-right-side** to monitor lines on right side only (alternatively in DC-loadflow mode) +- **monitor-lines-on-side-one** to monitor lines on side one only (typically to be used in DC-loadflow mode) +- **monitor-lines-on-side-two** to monitor lines on side two only (alternatively in DC-loadflow mode) - **monitor-lines-on-both-sides** to monitor lines on both sides; the flow limits defined in the native CRAC file will then apply to both sides (typically to be used in AC-loadflow mode) diff --git a/docs/input-data/crac/csa.md b/docs/input-data/crac/csa.md index 49df4c3732..1fea6fe92c 100644 --- a/docs/input-data/crac/csa.md +++ b/docs/input-data/crac/csa.md @@ -299,9 +299,9 @@ The CNEC's threshold side depends on the nature of the `OperationalLimitSet`'s ` existing line in the network and which also defines the CNEC's network element: - if the line is a `CGMES.Terminal1` or a `CGMES.Terminal_Boundary_1` in PowSyBl, the threshold of the CNEC is on the - **left** side + side **one** - if the line is a `CGMES.Terminal2` or a `CGMES.Terminal_Boundary_2` in PowSyBl, the threshold of the CNEC is on the - **right** side + side **two** Depending on the `OperationalLimitType`'s `kind` (PATL or TATL) and its `acceptableDuration` (if TATL), the FlowCNEC's instant can be deduced (see [this section](#tatl-to-flowcnec-instant-association) for more information). diff --git a/docs/input-data/crac/json.md b/docs/input-data/crac/json.md index 25e81b6170..79219746f0 100644 --- a/docs/input-data/crac/json.md +++ b/docs/input-data/crac/json.md @@ -334,7 +334,7 @@ crac.newFlowCnec() .withOptimized(true) .newThreshold() .withUnit(Unit.MEGAWATT) - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .withMin(-1500.) .withMax(1500.) .add() @@ -350,20 +350,20 @@ crac.newFlowCnec() .withBorder("border") .newThreshold() .withUnit(Unit.PERCENT_IMAX) - .withSide(Side.RIGHT) + .withSide(TwoSides.TWO) .withMax(0.95) .add() .newThreshold() .withUnit(Unit.AMPERE) - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .withMin(-450.) .add() .withReliabilityMargin(50.) .withOptimized(true) .withMonitored(false) - .withNominalVoltage(380., Side.LEFT) - .withNominalVoltage(220., Side.RIGHT) - .withIMax(500.) // this means that the value is the same on both sides, but the side could have been specified using "withImax(500., Side.RIGHT)" instead + .withNominalVoltage(380., TwoSides.ONE) + .withNominalVoltage(220., TwoSides.TWO) + .withIMax(500.) // this means that the value is the same on both sides, but the side could have been specified using "withImax(500., TwoSides.TWO)" instead .add(); ~~~ ::: @@ -383,7 +383,7 @@ crac.newFlowCnec() "unit" : "megawatt", "min" : -1500.0, "max" : 1500.0, - "side" : "left" + "side" : 1 } ] }, { "id" : "curative-cnec-with-two-thresholds-id", @@ -401,11 +401,11 @@ crac.newFlowCnec() "thresholds" : [ { "unit" : "ampere", "min" : -450.0, - "side" : "left" + "side" : 1 }, { "unit" : "percent_imax", "max" : 0.95, - "side" : "right" + "side" : 2 } ] } ] ~~~ diff --git a/docs/output-data/rao-logs/example.md b/docs/output-data/rao-logs/example.md index 5db3746b1a..8304b543e9 100644 --- a/docs/output-data/rao-logs/example.md +++ b/docs/output-data/rao-logs/example.md @@ -262,7 +262,7 @@ INFO c.p.openrao.commons.logs.TechnicalLogs - Optimizing automaton state Contin INFO c.p.openrao.commons.logs.TechnicalLogs - Initial situation: INFO c.p.openrao.commons.logs.TechnicalLogs - Limiting element #01: margin = -32.49 MW, element NNL2AA1 BBE3AA1 1 at state Contingency_FR1_FR3 - auto, CNEC ID = "NL2-BE3-O - auto" INFO c.p.openrao.commons.logs.TechnicalLogs - Topological automaton state Contingency_FR1_FR3 - auto has been skipped as no topological automatons were activated. -DEBUG c.p.openrao.commons.logs.TechnicalLogs - Shifting setpoint from 0.0 to 1.5583491300758083 on range action(s) ARA_PST_DE to improve margin on cnec NL2-BE3-O - auto on side LEFT (initial margin : -32.489056200328605 MW). +DEBUG c.p.openrao.commons.logs.TechnicalLogs - Shifting setpoint from 0.0 to 1.5583491300758083 on range action(s) ARA_PST_DE to improve margin on cnec NL2-BE3-O - auto on side ONE (initial margin : -32.489056200328605 MW). DEBUG c.p.openrao.commons.logs.TechnicalLogs - Systematic sensitivity analysis [start] DEBUG c.p.openrao.commons.logs.TechnicalLogs - Systematic sensitivity analysis [end] INFO c.p.openrao.commons.logs.TechnicalLogs - Limiting element #01: margin = 6.96 MW, element NNL2AA1 BBE3AA1 1 at state Contingency_FR1_FR3 - auto, CNEC ID = "NL2-BE3-O - auto" @@ -457,7 +457,7 @@ INFO c.p.openrao.commons.logs.TechnicalLogs - Optimizing automaton state Contin INFO c.p.openrao.commons.logs.TechnicalLogs - Initial situation: INFO c.p.openrao.commons.logs.TechnicalLogs - Limiting element #01: margin = -32.49 MW, element NNL2AA1 BBE3AA1 1 at state Contingency_FR1_FR3 - curative, CNEC ID = "NL2-BE3-O - curative" INFO c.p.openrao.commons.logs.TechnicalLogs - Topological automaton state Contingency_FR1_FR3 - auto has been skipped as no topological automatons were activated. -DEBUG c.p.openrao.commons.logs.TechnicalLogs - Shifting setpoint from 0.0 to 1.5583491300758083 on range action(s) ARA_PST_DE to improve margin on cnec NL2-BE3-O - auto on side LEFT} (initial margin : -32.489056200328605 MW). +DEBUG c.p.openrao.commons.logs.TechnicalLogs - Shifting setpoint from 0.0 to 1.5583491300758083 on range action(s) ARA_PST_DE to improve margin on cnec NL2-BE3-O - auto on side ONE} (initial margin : -32.489056200328605 MW). DEBUG c.p.openrao.commons.logs.TechnicalLogs - Systematic sensitivity analysis [start] DEBUG c.p.openrao.commons.logs.TechnicalLogs - Systematic sensitivity analysis [end] INFO c.p.openrao.commons.logs.TechnicalLogs - Limiting element #01: margin = 6.96 MW, element NNL2AA1 BBE3AA1 1 at state Contingency_FR1_FR3 - curative, CNEC ID = "NL2-BE3-O - curative" diff --git a/docs/output-data/rao-result/flow-cnecs.md b/docs/output-data/rao-result/flow-cnecs.md index b079636465..c0841faab6 100644 --- a/docs/output-data/rao-result/flow-cnecs.md +++ b/docs/output-data/rao-result/flow-cnecs.md @@ -1,7 +1,7 @@ These results contain important RAO information about flow CNECs. Note that you have to use [FlowCnec](/input-data/crac/json.md#flow-cnecs) objects from the CRAC in order to query the RaoResult Java API. Most results are power flow results (like flows & margins), and can be queried in two [units](https://github.com/powsybl/powsybl-open-rao/blob/main/commons/src/main/java/com/powsybl/openrao/commons/Unit.java) -(AMPERE & MEGAWATT) and on one or two sides (LEFT & RIGHT). +(AMPERE & MEGAWATT) and on one or two sides (ONE & TWO). #### Flow @@ -12,7 +12,7 @@ The actual power flow on the branch. ~~~java // get the flow on a given flow cnec, at a given side, in a given unit, after optimisation of a given instant -double getFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit); +double getFlow(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side, Unit unit); ~~~ ::: @@ -26,22 +26,22 @@ Example: "initial" : { "megawatt" : { ... - "rightSide" : { + "side2" : { "flow": 1110.0, ... }, - "leftSide" : { + "side1" : { "flow": 1105.0, ... } }, "ampere" : { ... - "rightSide" : { + "side2" : { "flow": 2220.0, ... }, - "leftSide" : { + "side1" : { "flow": 2210.0, ... } @@ -51,14 +51,14 @@ Example: "preventive" : { "megawatt" : { ... - "leftSide" : { + "side1" : { "flow": 1210.0, ... } }, "ampere" : { ... - "leftSide" : { + "side1" : { "flow": 505.0, ... } @@ -200,7 +200,7 @@ The loop-flow value on a CNEC. ~~~java // get the loop-flow on a given flow cnec, at a given side, in a given unit, after optimisation of a given instant -double getLoopFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit); +double getLoopFlow(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side, Unit unit); ~~~ ::: @@ -214,7 +214,7 @@ Example: "initial" : { "megawatt" : { ... - "leftSide" : { + "side1" : { ... "loopFlow": 1113.0, ... @@ -223,7 +223,7 @@ Example: }, "ampere" : { ... - "leftSide" : { + "side1" : { ... "loopFlow": 1123.0, ... @@ -235,7 +235,7 @@ Example: "preventive" : { "megawatt" : { ... - "rightSide" : { + "side2" : { ... "loopFlow": 1213.0, ... @@ -244,7 +244,7 @@ Example: }, "ampere" : { ... - "rightSide" : { + "side2" : { ... "loopFlow": 1223.0, ... @@ -272,7 +272,7 @@ The commercial flow on a CNEC. ~~~java // get the commercial flow on a given flow cnec, at a given side, in a given unit, after optimisation of a given instant -double getCommercialFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit); +double getCommercialFlow(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side, Unit unit); ~~~ ::: @@ -286,7 +286,7 @@ Example: "initial" : { "megawatt" : { ... - "leftSide" : { + "side1" : { ... "commercialFlow": 1114.0, ... @@ -295,7 +295,7 @@ Example: }, "ampere" : { ... - "leftSide" : { + "side1" : { ... "commercialFlow": 1124.0, ... @@ -307,7 +307,7 @@ Example: "preventive" : { "megawatt" : { ... - "rightSide" : { + "side2" : { ... "commercialFlow": 1214.0, ... @@ -316,7 +316,7 @@ Example: }, "ampere" : { ... - "rightSide" : { + "side2" : { ... "commercialFlow": 1224.0, ... @@ -344,7 +344,7 @@ The absolute sum of zonal PTDFs (influence factors) on a given CNEC. Reflects th ~~~java // get the absolute sum of zonal PTDFs for a given flow cnec, at a given side, after optimisation of a given instant -double getPtdfZonalSum(Instant optimizedInstant, FlowCnec flowCnec, Side side); +double getPtdfZonalSum(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side); ~~~ ::: @@ -359,7 +359,7 @@ Example: "initial" : { "megawatt" : { ... - "rightSide" : { + "side2" : { ... "zonalPtdfSum" : 0.1 ... @@ -386,7 +386,7 @@ This complete example was also enriched with two curative instants: `curative1` "megawatt" : { "margin" : 1111.0, "relativeMargin" : 1112.0, - "rightSide" : { + "side2" : { "flow" : 1110.5, "loopFlow" : 1113.5, "commercialFlow" : 1114.5, @@ -396,7 +396,7 @@ This complete example was also enriched with two curative instants: `curative1` "ampere" : { "margin" : 1121.0, "relativeMargin" : 1122.0, - "rightSide" : { + "side2" : { "flow" : 1120.5, "loopFlow" : 1123.5, "commercialFlow" : 1124.5 @@ -407,7 +407,7 @@ This complete example was also enriched with two curative instants: `curative1` "megawatt" : { "margin" : 1211.0, "relativeMargin" : 1212.0, - "rightSide" : { + "side2" : { "flow" : 1210.5, "loopFlow" : 1213.5, "commercialFlow" : 1214.5, @@ -417,7 +417,7 @@ This complete example was also enriched with two curative instants: `curative1` "ampere" : { "margin" : 1221.0, "relativeMargin" : 1222.0, - "rightSide" : { + "side2" : { "flow" : 1220.5, "loopFlow" : 1223.5, "commercialFlow" : 1224.5 @@ -428,7 +428,7 @@ This complete example was also enriched with two curative instants: `curative1` "megawatt" : { "margin" : 1311.0, "relativeMargin" : 1312.0, - "rightSide" : { + "side2" : { "flow" : 1310.5, "loopFlow" : 1313.5, "commercialFlow" : 1314.5, @@ -438,7 +438,7 @@ This complete example was also enriched with two curative instants: `curative1` "ampere" : { "margin" : 1321.0, "relativeMargin" : 1322.0, - "rightSide" : { + "side2" : { "flow" : 1320.5, "loopFlow" : 1323.5, "commercialFlow" : 1324.5 @@ -449,7 +449,7 @@ This complete example was also enriched with two curative instants: `curative1` "megawatt" : { "margin" : 1411.0, "relativeMargin" : 1412.0, - "rightSide" : { + "side2" : { "flow" : 1410.5, "loopFlow" : 1413.5, "commercialFlow" : 1414.5, @@ -459,7 +459,7 @@ This complete example was also enriched with two curative instants: `curative1` "ampere" : { "margin" : 1421.0, "relativeMargin" : 1422.0, - "rightSide" : { + "side2" : { "flow" : 1420.5, "loopFlow" : 1423.5, "commercialFlow" : 1424.5 @@ -472,7 +472,7 @@ This complete example was also enriched with two curative instants: `curative1` "megawatt" : { "margin" : 1111.0, "relativeMargin" : 1112.0, - "rightSide" : { + "side2" : { "flow" : 1110.5, "loopFlow" : 1113.5, "commercialFlow" : 1114.5, @@ -482,7 +482,7 @@ This complete example was also enriched with two curative instants: `curative1` "ampere" : { "margin" : 1121.0, "relativeMargin" : 1122.0, - "rightSide" : { + "side2" : { "flow" : 1120.5, "loopFlow" : 1123.5, "commercialFlow" : 1124.5 @@ -493,7 +493,7 @@ This complete example was also enriched with two curative instants: `curative1` "megawatt" : { "margin" : 1211.0, "relativeMargin" : 1212.0, - "rightSide" : { + "side2" : { "flow" : 1210.5, "loopFlow" : 1213.5, "commercialFlow" : 1214.5, @@ -503,7 +503,7 @@ This complete example was also enriched with two curative instants: `curative1` "ampere" : { "margin" : 1221.0, "relativeMargin" : 1222.0, - "rightSide" : { + "side2" : { "flow" : 1220.5, "loopFlow" : 1223.5, "commercialFlow" : 1224.5 @@ -514,7 +514,7 @@ This complete example was also enriched with two curative instants: `curative1` "megawatt" : { "margin" : 1311.0, "relativeMargin" : 1312.0, - "rightSide" : { + "side2" : { "flow" : 1310.5, "loopFlow" : 1313.5, "commercialFlow" : 1314.5, @@ -524,7 +524,7 @@ This complete example was also enriched with two curative instants: `curative1` "ampere" : { "margin" : 1321.0, "relativeMargin" : 1322.0, - "rightSide" : { + "side2" : { "flow" : 1320.5, "loopFlow" : 1323.5, "commercialFlow" : 1324.5 @@ -535,7 +535,7 @@ This complete example was also enriched with two curative instants: `curative1` "megawatt" : { "margin" : 1411.0, "relativeMargin" : 1412.0, - "rightSide" : { + "side2" : { "flow" : 1410.5, "loopFlow" : 1413.5, "commercialFlow" : 1414.5, @@ -545,7 +545,7 @@ This complete example was also enriched with two curative instants: `curative1` "ampere" : { "margin" : 1421.0, "relativeMargin" : 1422.0, - "rightSide" : { + "side2" : { "flow" : 1420.5, "loopFlow" : 1423.5, "commercialFlow" : 1424.5 diff --git a/docs/tutorial.md b/docs/tutorial.md index 4674c8c2d2..69a8979230 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -181,7 +181,7 @@ crac.newFlowCnec() .withMin(-410d) .withMax(+410d) .withUnit(Unit.MEGAWATT) - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .add() .add(); ``` @@ -200,7 +200,7 @@ crac.newFlowCnec() .withMin(-1000d) .withMax(+1000d) .withUnit(Unit.MEGAWATT) - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .add() .add(); ``` @@ -218,7 +218,7 @@ crac.newFlowCnec() .withMin(-410d) .withMax(+410d) .withUnit(Unit.MEGAWATT) - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .add() .add(); ``` @@ -446,7 +446,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.CracFactory; import com.powsybl.openrao.data.cracapi.InstantKind; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.ActionType; import com.powsybl.openrao.data.cracapi.range.RangeType; import com.powsybl.openrao.data.cracapi.usagerule.UsageMethod; @@ -491,7 +491,7 @@ public class Main { .withMin(-410d) .withMax(+410d) .withUnit(Unit.MEGAWATT) - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .add() .add(); @@ -505,7 +505,7 @@ public class Main { .withMin(-1000d) .withMax(+1000d) .withUnit(Unit.MEGAWATT) - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .add() .add(); @@ -519,7 +519,7 @@ public class Main { .withMin(-410d) .withMax(+410d) .withUnit(Unit.MEGAWATT) - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .add() .add(); diff --git a/flowbased-computation/flowbased-computation-impl/src/main/java/com/powsybl/openrao/flowbasedcomputation/impl/FlowbasedComputationImpl.java b/flowbased-computation/flowbased-computation-impl/src/main/java/com/powsybl/openrao/flowbasedcomputation/impl/FlowbasedComputationImpl.java index b4b3619e58..3cf4aa2d14 100644 --- a/flowbased-computation/flowbased-computation-impl/src/main/java/com/powsybl/openrao/flowbasedcomputation/impl/FlowbasedComputationImpl.java +++ b/flowbased-computation/flowbased-computation-impl/src/main/java/com/powsybl/openrao/flowbasedcomputation/impl/FlowbasedComputationImpl.java @@ -13,7 +13,7 @@ import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; import com.powsybl.openrao.data.cracapi.usagerule.UsageMethod; @@ -172,8 +172,8 @@ private List buildDataMonitoredBranches(Crac crac, Set glsk, SystematicSensitivityResult result) { - double maxThreshold = cnec.getUpperBound(Side.LEFT, Unit.MEGAWATT).orElse(Double.POSITIVE_INFINITY); - double minThreshold = cnec.getLowerBound(Side.LEFT, Unit.MEGAWATT).orElse(Double.NEGATIVE_INFINITY); + double maxThreshold = cnec.getUpperBound(TwoSides.ONE, Unit.MEGAWATT).orElse(Double.POSITIVE_INFINITY); + double minThreshold = cnec.getLowerBound(TwoSides.ONE, Unit.MEGAWATT).orElse(Double.NEGATIVE_INFINITY); return new DataMonitoredBranch( cnec.getId(), cnec.getName(), @@ -181,7 +181,7 @@ private DataMonitoredBranch buildDataMonitoredBranch(FlowCnec cnec, ZonalData buildDataPtdfPerCountry(FlowCnec cnec, ZonalDat .map(glsk -> new DataPtdfPerCountry( glsk.getId(), - zeroIfNaN(result.getSensitivityOnFlow(glsk.getId(), cnec, Side.LEFT)) // TODO : handle both sides if needed + zeroIfNaN(result.getSensitivityOnFlow(glsk.getId(), cnec, TwoSides.ONE)) // TODO : handle both sides if needed ) ).toList(); } diff --git a/flowbased-computation/flowbased-computation-impl/src/test/java/com/powsybl/openrao/flowbasedcomputation/impl/FlowbasedComputationImplTest.java b/flowbased-computation/flowbased-computation-impl/src/test/java/com/powsybl/openrao/flowbasedcomputation/impl/FlowbasedComputationImplTest.java index 80a42f9899..02bf98de8d 100644 --- a/flowbased-computation/flowbased-computation-impl/src/test/java/com/powsybl/openrao/flowbasedcomputation/impl/FlowbasedComputationImplTest.java +++ b/flowbased-computation/flowbased-computation-impl/src/test/java/com/powsybl/openrao/flowbasedcomputation/impl/FlowbasedComputationImplTest.java @@ -6,7 +6,7 @@ */ package com.powsybl.openrao.flowbasedcomputation.impl; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.glsk.commons.ZonalData; import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.Instant; @@ -255,34 +255,34 @@ private RaoResult createRaoResult(Crac crac, Set flowCnecs, NetworkAct flowCnecResult.getAndCreateIfAbsentResultForOptimizationState(null); ElementaryFlowCnecResult elementaryFlowCnecResult = flowCnecResult.getResult(null); - elementaryFlowCnecResult.setFlow(Side.LEFT, 100., MEGAWATT); + elementaryFlowCnecResult.setFlow(TwoSides.ONE, 100., MEGAWATT); elementaryFlowCnecResult.setMargin(101., MEGAWATT); elementaryFlowCnecResult.setRelativeMargin(102., MEGAWATT); - elementaryFlowCnecResult.setLoopFlow(Side.LEFT, 103., MEGAWATT); - elementaryFlowCnecResult.setCommercialFlow(Side.LEFT, 104., MEGAWATT); + elementaryFlowCnecResult.setLoopFlow(TwoSides.ONE, 103., MEGAWATT); + elementaryFlowCnecResult.setCommercialFlow(TwoSides.ONE, 104., MEGAWATT); - elementaryFlowCnecResult.setFlow(Side.LEFT, 110., AMPERE); + elementaryFlowCnecResult.setFlow(TwoSides.ONE, 110., AMPERE); elementaryFlowCnecResult.setMargin(111., AMPERE); elementaryFlowCnecResult.setRelativeMargin(112., AMPERE); - elementaryFlowCnecResult.setLoopFlow(Side.LEFT, 113., AMPERE); - elementaryFlowCnecResult.setCommercialFlow(Side.LEFT, 114., AMPERE); + elementaryFlowCnecResult.setLoopFlow(TwoSides.ONE, 113., AMPERE); + elementaryFlowCnecResult.setCommercialFlow(TwoSides.ONE, 114., AMPERE); - elementaryFlowCnecResult.setPtdfZonalSum(Side.LEFT, 0.1); + elementaryFlowCnecResult.setPtdfZonalSum(TwoSides.ONE, 0.1); flowCnecResult.getAndCreateIfAbsentResultForOptimizationState(curativeInstant); elementaryFlowCnecResult = flowCnecResult.getResult(curativeInstant); - elementaryFlowCnecResult.setFlow(Side.LEFT, 200., MEGAWATT); + elementaryFlowCnecResult.setFlow(TwoSides.ONE, 200., MEGAWATT); elementaryFlowCnecResult.setMargin(201., MEGAWATT); elementaryFlowCnecResult.setRelativeMargin(202., MEGAWATT); - elementaryFlowCnecResult.setLoopFlow(Side.LEFT, 203., MEGAWATT); + elementaryFlowCnecResult.setLoopFlow(TwoSides.ONE, 203., MEGAWATT); - elementaryFlowCnecResult.setFlow(Side.LEFT, 210., AMPERE); + elementaryFlowCnecResult.setFlow(TwoSides.ONE, 210., AMPERE); elementaryFlowCnecResult.setMargin(211., AMPERE); elementaryFlowCnecResult.setRelativeMargin(212., AMPERE); - elementaryFlowCnecResult.setLoopFlow(Side.LEFT, 213., AMPERE); + elementaryFlowCnecResult.setLoopFlow(TwoSides.ONE, 213., AMPERE); - elementaryFlowCnecResult.setPtdfZonalSum(Side.LEFT, 0.1); + elementaryFlowCnecResult.setPtdfZonalSum(TwoSides.ONE, 0.1); }); raoResult.getAndCreateIfAbsentNetworkActionResult(na).addActivationForState(crac.getState("N-1 FR-BE", curativeInstant)); diff --git a/loopflow-computation/src/main/java/com/powsybl/openrao/loopflowcomputation/LoopFlowResult.java b/loopflow-computation/src/main/java/com/powsybl/openrao/loopflowcomputation/LoopFlowResult.java index 3edb978699..423123e08e 100644 --- a/loopflow-computation/src/main/java/com/powsybl/openrao/loopflowcomputation/LoopFlowResult.java +++ b/loopflow-computation/src/main/java/com/powsybl/openrao/loopflowcomputation/LoopFlowResult.java @@ -8,7 +8,7 @@ import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.data.cracapi.cnec.BranchCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import java.util.EnumMap; import java.util.HashMap; @@ -19,7 +19,7 @@ */ public class LoopFlowResult { - private final Map, Map> loopFlowMap; + private final Map, Map> loopFlowMap; private static class LoopFlow { double loopFlowValue; @@ -49,25 +49,25 @@ public LoopFlowResult() { this.loopFlowMap = new HashMap<>(); } - public void addCnecResult(BranchCnec cnec, Side side, double loopFlowValue, double commercialFlowValue, double referenceFlowValue) { - loopFlowMap.computeIfAbsent(cnec, k -> new EnumMap<>(Side.class)).put(side, new LoopFlow(loopFlowValue, commercialFlowValue, referenceFlowValue)); + public void addCnecResult(BranchCnec cnec, TwoSides side, double loopFlowValue, double commercialFlowValue, double referenceFlowValue) { + loopFlowMap.computeIfAbsent(cnec, k -> new EnumMap<>(TwoSides.class)).put(side, new LoopFlow(loopFlowValue, commercialFlowValue, referenceFlowValue)); } - public double getLoopFlow(BranchCnec cnec, Side side) { + public double getLoopFlow(BranchCnec cnec, TwoSides side) { if (!loopFlowMap.containsKey(cnec) || !loopFlowMap.get(cnec).containsKey(side)) { throw new OpenRaoException(String.format("No loop-flow value found for cnec %s on side %s", cnec.getId(), side)); } return loopFlowMap.get(cnec).get(side).getLoopFlow(); } - public double getCommercialFlow(BranchCnec cnec, Side side) { + public double getCommercialFlow(BranchCnec cnec, TwoSides side) { if (!loopFlowMap.containsKey(cnec) || !loopFlowMap.get(cnec).containsKey(side)) { throw new OpenRaoException(String.format("No commercial flow value found for cnec %s on side %s", cnec.getId(), side)); } return loopFlowMap.get(cnec).get(side).getCommercialFlow(); } - public double getReferenceFlow(BranchCnec cnec, Side side) { + public double getReferenceFlow(BranchCnec cnec, TwoSides side) { if (!loopFlowMap.containsKey(cnec) || !loopFlowMap.get(cnec).containsKey(side)) { throw new OpenRaoException(String.format("No reference flow value found for cnec %s on side %s", cnec.getId(), side)); } diff --git a/loopflow-computation/src/test/java/com/powsybl/openrao/loopflowcomputation/ExampleGenerator.java b/loopflow-computation/src/test/java/com/powsybl/openrao/loopflowcomputation/ExampleGenerator.java index 3f4159534a..7362e9cc18 100644 --- a/loopflow-computation/src/test/java/com/powsybl/openrao/loopflowcomputation/ExampleGenerator.java +++ b/loopflow-computation/src/test/java/com/powsybl/openrao/loopflowcomputation/ExampleGenerator.java @@ -6,7 +6,7 @@ */ package com.powsybl.openrao.loopflowcomputation; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.glsk.commons.ZonalData; import com.powsybl.glsk.commons.ZonalDataImpl; import com.powsybl.openrao.data.cracapi.*; @@ -333,7 +333,7 @@ static Crac crac() { .withMin(-200.) .withMax(200.) .withUnit(MEGAWATT) - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .add() .add(); @@ -345,7 +345,7 @@ static Crac crac() { .withMin(-200.) .withMax(200.) .withUnit(MEGAWATT) - .withSide(Side.RIGHT) + .withSide(TwoSides.TWO) .add() .add(); @@ -357,7 +357,7 @@ static Crac crac() { .withMin(-200.) .withMax(200.) .withUnit(MEGAWATT) - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .add() .add(); @@ -369,7 +369,7 @@ static Crac crac() { .withMin(-200.) .withMax(200.) .withUnit(MEGAWATT) - .withSide(Side.RIGHT) + .withSide(TwoSides.TWO) .add() .add(); @@ -381,7 +381,7 @@ static Crac crac() { .withMin(-200.) .withMax(200.) .withUnit(MEGAWATT) - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .add() .add(); @@ -419,11 +419,11 @@ static SystematicSensitivityResult systematicSensitivityResult(Crac crac, ZonalD SystematicSensitivityResult sensisResults = Mockito.mock(SystematicSensitivityResult.class); // flow results - Mockito.when(sensisResults.getReferenceFlow(crac.getFlowCnec("FR-BE1"), Side.LEFT)).thenReturn(30.); - Mockito.when(sensisResults.getReferenceFlow(crac.getFlowCnec("BE1-BE2"), Side.LEFT)).thenReturn(280.); - Mockito.when(sensisResults.getReferenceFlow(crac.getFlowCnec("FR-DE"), Side.RIGHT)).thenReturn(170.); - Mockito.when(sensisResults.getReferenceFlow(crac.getFlowCnec("BE2-NL"), Side.LEFT)).thenReturn(30.); - Mockito.when(sensisResults.getReferenceFlow(crac.getFlowCnec("DE-NL"), Side.RIGHT)).thenReturn(170.); + Mockito.when(sensisResults.getReferenceFlow(crac.getFlowCnec("FR-BE1"), TwoSides.ONE)).thenReturn(30.); + Mockito.when(sensisResults.getReferenceFlow(crac.getFlowCnec("BE1-BE2"), TwoSides.ONE)).thenReturn(280.); + Mockito.when(sensisResults.getReferenceFlow(crac.getFlowCnec("FR-DE"), TwoSides.TWO)).thenReturn(170.); + Mockito.when(sensisResults.getReferenceFlow(crac.getFlowCnec("BE2-NL"), TwoSides.ONE)).thenReturn(30.); + Mockito.when(sensisResults.getReferenceFlow(crac.getFlowCnec("DE-NL"), TwoSides.TWO)).thenReturn(170.); // sensi results SensitivityVariableSet glskFr = glsk.getData("10YFR-RTE------C"); @@ -431,30 +431,30 @@ static SystematicSensitivityResult systematicSensitivityResult(Crac crac, ZonalD SensitivityVariableSet glskDe = glsk.getData("10YCB-GERMANY--8"); SensitivityVariableSet glskNl = glsk.getData("10YNL----------L"); - Mockito.when(sensisResults.getSensitivityOnFlow(glskFr, crac.getFlowCnec("FR-BE1"), Side.LEFT)).thenReturn(0.); - Mockito.when(sensisResults.getSensitivityOnFlow(glskBe, crac.getFlowCnec("FR-BE1"), Side.LEFT)).thenReturn(-1.5); - Mockito.when(sensisResults.getSensitivityOnFlow(glskDe, crac.getFlowCnec("FR-BE1"), Side.LEFT)).thenReturn(-0.4); - Mockito.when(sensisResults.getSensitivityOnFlow(glskNl, crac.getFlowCnec("FR-BE1"), Side.LEFT)).thenReturn(-0.8); + Mockito.when(sensisResults.getSensitivityOnFlow(glskFr, crac.getFlowCnec("FR-BE1"), TwoSides.ONE)).thenReturn(0.); + Mockito.when(sensisResults.getSensitivityOnFlow(glskBe, crac.getFlowCnec("FR-BE1"), TwoSides.ONE)).thenReturn(-1.5); + Mockito.when(sensisResults.getSensitivityOnFlow(glskDe, crac.getFlowCnec("FR-BE1"), TwoSides.ONE)).thenReturn(-0.4); + Mockito.when(sensisResults.getSensitivityOnFlow(glskNl, crac.getFlowCnec("FR-BE1"), TwoSides.ONE)).thenReturn(-0.8); - Mockito.when(sensisResults.getSensitivityOnFlow(glskFr, crac.getFlowCnec("BE1-BE2"), Side.LEFT)).thenReturn(0.); - Mockito.when(sensisResults.getSensitivityOnFlow(glskBe, crac.getFlowCnec("BE1-BE2"), Side.LEFT)).thenReturn(0.); - Mockito.when(sensisResults.getSensitivityOnFlow(glskDe, crac.getFlowCnec("BE1-BE2"), Side.LEFT)).thenReturn(-0.4); - Mockito.when(sensisResults.getSensitivityOnFlow(glskNl, crac.getFlowCnec("BE1-BE2"), Side.LEFT)).thenReturn(-0.8); + Mockito.when(sensisResults.getSensitivityOnFlow(glskFr, crac.getFlowCnec("BE1-BE2"), TwoSides.ONE)).thenReturn(0.); + Mockito.when(sensisResults.getSensitivityOnFlow(glskBe, crac.getFlowCnec("BE1-BE2"), TwoSides.ONE)).thenReturn(0.); + Mockito.when(sensisResults.getSensitivityOnFlow(glskDe, crac.getFlowCnec("BE1-BE2"), TwoSides.ONE)).thenReturn(-0.4); + Mockito.when(sensisResults.getSensitivityOnFlow(glskNl, crac.getFlowCnec("BE1-BE2"), TwoSides.ONE)).thenReturn(-0.8); - Mockito.when(sensisResults.getSensitivityOnFlow(glskFr, crac.getFlowCnec("FR-DE"), Side.RIGHT)).thenReturn(0.); - Mockito.when(sensisResults.getSensitivityOnFlow(glskBe, crac.getFlowCnec("FR-DE"), Side.RIGHT)).thenReturn(-0.5); - Mockito.when(sensisResults.getSensitivityOnFlow(glskDe, crac.getFlowCnec("FR-DE"), Side.RIGHT)).thenReturn(-1.6); - Mockito.when(sensisResults.getSensitivityOnFlow(glskNl, crac.getFlowCnec("FR-DE"), Side.RIGHT)).thenReturn(-1.2); + Mockito.when(sensisResults.getSensitivityOnFlow(glskFr, crac.getFlowCnec("FR-DE"), TwoSides.TWO)).thenReturn(0.); + Mockito.when(sensisResults.getSensitivityOnFlow(glskBe, crac.getFlowCnec("FR-DE"), TwoSides.TWO)).thenReturn(-0.5); + Mockito.when(sensisResults.getSensitivityOnFlow(glskDe, crac.getFlowCnec("FR-DE"), TwoSides.TWO)).thenReturn(-1.6); + Mockito.when(sensisResults.getSensitivityOnFlow(glskNl, crac.getFlowCnec("FR-DE"), TwoSides.TWO)).thenReturn(-1.2); - Mockito.when(sensisResults.getSensitivityOnFlow(glskFr, crac.getFlowCnec("BE2-NL"), Side.LEFT)).thenReturn(0.); - Mockito.when(sensisResults.getSensitivityOnFlow(glskBe, crac.getFlowCnec("BE2-NL"), Side.LEFT)).thenReturn(0.5); - Mockito.when(sensisResults.getSensitivityOnFlow(glskDe, crac.getFlowCnec("BE2-NL"), Side.LEFT)).thenReturn(-0.4); - Mockito.when(sensisResults.getSensitivityOnFlow(glskNl, crac.getFlowCnec("BE2-NL"), Side.LEFT)).thenReturn(-0.8); + Mockito.when(sensisResults.getSensitivityOnFlow(glskFr, crac.getFlowCnec("BE2-NL"), TwoSides.ONE)).thenReturn(0.); + Mockito.when(sensisResults.getSensitivityOnFlow(glskBe, crac.getFlowCnec("BE2-NL"), TwoSides.ONE)).thenReturn(0.5); + Mockito.when(sensisResults.getSensitivityOnFlow(glskDe, crac.getFlowCnec("BE2-NL"), TwoSides.ONE)).thenReturn(-0.4); + Mockito.when(sensisResults.getSensitivityOnFlow(glskNl, crac.getFlowCnec("BE2-NL"), TwoSides.ONE)).thenReturn(-0.8); - Mockito.when(sensisResults.getSensitivityOnFlow(glskFr, crac.getFlowCnec("DE-NL"), Side.RIGHT)).thenReturn(0.); - Mockito.when(sensisResults.getSensitivityOnFlow(glskBe, crac.getFlowCnec("DE-NL"), Side.RIGHT)).thenReturn(-0.5); - Mockito.when(sensisResults.getSensitivityOnFlow(glskDe, crac.getFlowCnec("DE-NL"), Side.RIGHT)).thenReturn(0.4); - Mockito.when(sensisResults.getSensitivityOnFlow(glskNl, crac.getFlowCnec("DE-NL"), Side.RIGHT)).thenReturn(-1.2); + Mockito.when(sensisResults.getSensitivityOnFlow(glskFr, crac.getFlowCnec("DE-NL"), TwoSides.TWO)).thenReturn(0.); + Mockito.when(sensisResults.getSensitivityOnFlow(glskBe, crac.getFlowCnec("DE-NL"), TwoSides.TWO)).thenReturn(-0.5); + Mockito.when(sensisResults.getSensitivityOnFlow(glskDe, crac.getFlowCnec("DE-NL"), TwoSides.TWO)).thenReturn(0.4); + Mockito.when(sensisResults.getSensitivityOnFlow(glskNl, crac.getFlowCnec("DE-NL"), TwoSides.TWO)).thenReturn(-1.2); return sensisResults; } diff --git a/loopflow-computation/src/test/java/com/powsybl/openrao/loopflowcomputation/LoopFlowComputationImplTest.java b/loopflow-computation/src/test/java/com/powsybl/openrao/loopflowcomputation/LoopFlowComputationImplTest.java index b14c7def16..6aba3d3403 100644 --- a/loopflow-computation/src/test/java/com/powsybl/openrao/loopflowcomputation/LoopFlowComputationImplTest.java +++ b/loopflow-computation/src/test/java/com/powsybl/openrao/loopflowcomputation/LoopFlowComputationImplTest.java @@ -7,7 +7,7 @@ package com.powsybl.openrao.loopflowcomputation; import com.powsybl.openrao.commons.OpenRaoException; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.glsk.commons.ZonalData; import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracloopflowextension.LoopFlowThresholdImpl; @@ -75,23 +75,23 @@ void calculateLoopFlowTest() { LoopFlowComputation loopFlowComputation = new LoopFlowComputationImpl(glsk, referenceProgram); LoopFlowResult loopFlowResult = loopFlowComputation.buildLoopFlowsFromReferenceFlowAndPtdf(ptdfsAndFlows, crac.getFlowCnecs(), network); - assertEquals(-50., loopFlowResult.getLoopFlow(crac.getFlowCnec("FR-BE1"), Side.LEFT), DOUBLE_TOLERANCE); - assertEquals(200., loopFlowResult.getLoopFlow(crac.getFlowCnec("BE1-BE2"), Side.LEFT), DOUBLE_TOLERANCE); - assertEquals(-50., loopFlowResult.getLoopFlow(crac.getFlowCnec("BE2-NL"), Side.LEFT), DOUBLE_TOLERANCE); - assertEquals(50., loopFlowResult.getLoopFlow(crac.getFlowCnec("FR-DE"), Side.RIGHT), DOUBLE_TOLERANCE); - assertEquals(50., loopFlowResult.getLoopFlow(crac.getFlowCnec("DE-NL"), Side.RIGHT), DOUBLE_TOLERANCE); - - assertEquals(80, loopFlowResult.getCommercialFlow(crac.getFlowCnec("FR-BE1"), Side.LEFT), DOUBLE_TOLERANCE); - assertEquals(80., loopFlowResult.getCommercialFlow(crac.getFlowCnec("BE1-BE2"), Side.LEFT), DOUBLE_TOLERANCE); - assertEquals(80, loopFlowResult.getCommercialFlow(crac.getFlowCnec("BE2-NL"), Side.LEFT), DOUBLE_TOLERANCE); - assertEquals(120., loopFlowResult.getCommercialFlow(crac.getFlowCnec("FR-DE"), Side.RIGHT), DOUBLE_TOLERANCE); - assertEquals(120., loopFlowResult.getCommercialFlow(crac.getFlowCnec("DE-NL"), Side.RIGHT), DOUBLE_TOLERANCE); - - assertEquals(30., loopFlowResult.getReferenceFlow(crac.getFlowCnec("FR-BE1"), Side.LEFT), DOUBLE_TOLERANCE); - assertEquals(280., loopFlowResult.getReferenceFlow(crac.getFlowCnec("BE1-BE2"), Side.LEFT), DOUBLE_TOLERANCE); - assertEquals(30., loopFlowResult.getReferenceFlow(crac.getFlowCnec("BE2-NL"), Side.LEFT), DOUBLE_TOLERANCE); - assertEquals(170., loopFlowResult.getReferenceFlow(crac.getFlowCnec("FR-DE"), Side.RIGHT), DOUBLE_TOLERANCE); - assertEquals(170., loopFlowResult.getReferenceFlow(crac.getFlowCnec("DE-NL"), Side.RIGHT), DOUBLE_TOLERANCE); + assertEquals(-50., loopFlowResult.getLoopFlow(crac.getFlowCnec("FR-BE1"), TwoSides.ONE), DOUBLE_TOLERANCE); + assertEquals(200., loopFlowResult.getLoopFlow(crac.getFlowCnec("BE1-BE2"), TwoSides.ONE), DOUBLE_TOLERANCE); + assertEquals(-50., loopFlowResult.getLoopFlow(crac.getFlowCnec("BE2-NL"), TwoSides.ONE), DOUBLE_TOLERANCE); + assertEquals(50., loopFlowResult.getLoopFlow(crac.getFlowCnec("FR-DE"), TwoSides.TWO), DOUBLE_TOLERANCE); + assertEquals(50., loopFlowResult.getLoopFlow(crac.getFlowCnec("DE-NL"), TwoSides.TWO), DOUBLE_TOLERANCE); + + assertEquals(80, loopFlowResult.getCommercialFlow(crac.getFlowCnec("FR-BE1"), TwoSides.ONE), DOUBLE_TOLERANCE); + assertEquals(80., loopFlowResult.getCommercialFlow(crac.getFlowCnec("BE1-BE2"), TwoSides.ONE), DOUBLE_TOLERANCE); + assertEquals(80, loopFlowResult.getCommercialFlow(crac.getFlowCnec("BE2-NL"), TwoSides.ONE), DOUBLE_TOLERANCE); + assertEquals(120., loopFlowResult.getCommercialFlow(crac.getFlowCnec("FR-DE"), TwoSides.TWO), DOUBLE_TOLERANCE); + assertEquals(120., loopFlowResult.getCommercialFlow(crac.getFlowCnec("DE-NL"), TwoSides.TWO), DOUBLE_TOLERANCE); + + assertEquals(30., loopFlowResult.getReferenceFlow(crac.getFlowCnec("FR-BE1"), TwoSides.ONE), DOUBLE_TOLERANCE); + assertEquals(280., loopFlowResult.getReferenceFlow(crac.getFlowCnec("BE1-BE2"), TwoSides.ONE), DOUBLE_TOLERANCE); + assertEquals(30., loopFlowResult.getReferenceFlow(crac.getFlowCnec("BE2-NL"), TwoSides.ONE), DOUBLE_TOLERANCE); + assertEquals(170., loopFlowResult.getReferenceFlow(crac.getFlowCnec("FR-DE"), TwoSides.TWO), DOUBLE_TOLERANCE); + assertEquals(170., loopFlowResult.getReferenceFlow(crac.getFlowCnec("DE-NL"), TwoSides.TWO), DOUBLE_TOLERANCE); } @Test @@ -222,23 +222,23 @@ void testComputeLoopFlowsWithIsolatedGlsk() { LoopFlowComputation loopFlowComputation = new LoopFlowComputationImpl(glsk, referenceProgram); LoopFlowResult loopFlowResult = loopFlowComputation.buildLoopFlowsFromReferenceFlowAndPtdf(ptdfsAndFlows, crac.getFlowCnecs(), network); - assertEquals(30., loopFlowResult.getLoopFlow(crac.getFlowCnec("FR-BE1"), Side.LEFT), DOUBLE_TOLERANCE); - assertEquals(280., loopFlowResult.getLoopFlow(crac.getFlowCnec("BE1-BE2"), Side.LEFT), DOUBLE_TOLERANCE); - assertEquals(30., loopFlowResult.getLoopFlow(crac.getFlowCnec("BE2-NL"), Side.LEFT), DOUBLE_TOLERANCE); - assertEquals(170., loopFlowResult.getLoopFlow(crac.getFlowCnec("FR-DE"), Side.RIGHT), DOUBLE_TOLERANCE); - assertEquals(170., loopFlowResult.getLoopFlow(crac.getFlowCnec("DE-NL"), Side.RIGHT), DOUBLE_TOLERANCE); - - assertEquals(0, loopFlowResult.getCommercialFlow(crac.getFlowCnec("FR-BE1"), Side.LEFT), DOUBLE_TOLERANCE); - assertEquals(0., loopFlowResult.getCommercialFlow(crac.getFlowCnec("BE1-BE2"), Side.LEFT), DOUBLE_TOLERANCE); - assertEquals(0., loopFlowResult.getCommercialFlow(crac.getFlowCnec("BE2-NL"), Side.LEFT), DOUBLE_TOLERANCE); - assertEquals(0., loopFlowResult.getCommercialFlow(crac.getFlowCnec("FR-DE"), Side.RIGHT), DOUBLE_TOLERANCE); - assertEquals(0., loopFlowResult.getCommercialFlow(crac.getFlowCnec("DE-NL"), Side.RIGHT), DOUBLE_TOLERANCE); - - assertEquals(30., loopFlowResult.getReferenceFlow(crac.getFlowCnec("FR-BE1"), Side.LEFT), DOUBLE_TOLERANCE); - assertEquals(280., loopFlowResult.getReferenceFlow(crac.getFlowCnec("BE1-BE2"), Side.LEFT), DOUBLE_TOLERANCE); - assertEquals(30., loopFlowResult.getReferenceFlow(crac.getFlowCnec("BE2-NL"), Side.LEFT), DOUBLE_TOLERANCE); - assertEquals(170., loopFlowResult.getReferenceFlow(crac.getFlowCnec("FR-DE"), Side.RIGHT), DOUBLE_TOLERANCE); - assertEquals(170., loopFlowResult.getReferenceFlow(crac.getFlowCnec("DE-NL"), Side.RIGHT), DOUBLE_TOLERANCE); + assertEquals(30., loopFlowResult.getLoopFlow(crac.getFlowCnec("FR-BE1"), TwoSides.ONE), DOUBLE_TOLERANCE); + assertEquals(280., loopFlowResult.getLoopFlow(crac.getFlowCnec("BE1-BE2"), TwoSides.ONE), DOUBLE_TOLERANCE); + assertEquals(30., loopFlowResult.getLoopFlow(crac.getFlowCnec("BE2-NL"), TwoSides.ONE), DOUBLE_TOLERANCE); + assertEquals(170., loopFlowResult.getLoopFlow(crac.getFlowCnec("FR-DE"), TwoSides.TWO), DOUBLE_TOLERANCE); + assertEquals(170., loopFlowResult.getLoopFlow(crac.getFlowCnec("DE-NL"), TwoSides.TWO), DOUBLE_TOLERANCE); + + assertEquals(0, loopFlowResult.getCommercialFlow(crac.getFlowCnec("FR-BE1"), TwoSides.ONE), DOUBLE_TOLERANCE); + assertEquals(0., loopFlowResult.getCommercialFlow(crac.getFlowCnec("BE1-BE2"), TwoSides.ONE), DOUBLE_TOLERANCE); + assertEquals(0., loopFlowResult.getCommercialFlow(crac.getFlowCnec("BE2-NL"), TwoSides.ONE), DOUBLE_TOLERANCE); + assertEquals(0., loopFlowResult.getCommercialFlow(crac.getFlowCnec("FR-DE"), TwoSides.TWO), DOUBLE_TOLERANCE); + assertEquals(0., loopFlowResult.getCommercialFlow(crac.getFlowCnec("DE-NL"), TwoSides.TWO), DOUBLE_TOLERANCE); + + assertEquals(30., loopFlowResult.getReferenceFlow(crac.getFlowCnec("FR-BE1"), TwoSides.ONE), DOUBLE_TOLERANCE); + assertEquals(280., loopFlowResult.getReferenceFlow(crac.getFlowCnec("BE1-BE2"), TwoSides.ONE), DOUBLE_TOLERANCE); + assertEquals(30., loopFlowResult.getReferenceFlow(crac.getFlowCnec("BE2-NL"), TwoSides.ONE), DOUBLE_TOLERANCE); + assertEquals(170., loopFlowResult.getReferenceFlow(crac.getFlowCnec("FR-DE"), TwoSides.TWO), DOUBLE_TOLERANCE); + assertEquals(170., loopFlowResult.getReferenceFlow(crac.getFlowCnec("DE-NL"), TwoSides.TWO), DOUBLE_TOLERANCE); } @Test @@ -250,22 +250,22 @@ void testCalculateLoopFlows() { sensitivityAnalysisParameters.getLoadFlowParameters().setDc(true); LoopFlowResult loopFlowResult = new LoopFlowComputationImpl(glsk, referenceProgram).calculateLoopFlows(network, "OpenLoadFlow", sensitivityAnalysisParameters, crac.getFlowCnecs(), crac.getOutageInstant()); - assertEquals(-20., loopFlowResult.getLoopFlow(crac.getFlowCnec("FR-BE1"), Side.LEFT), DOUBLE_TOLERANCE); - assertEquals(80., loopFlowResult.getLoopFlow(crac.getFlowCnec("BE1-BE2"), Side.LEFT), DOUBLE_TOLERANCE); - assertEquals(-20., loopFlowResult.getLoopFlow(crac.getFlowCnec("BE2-NL"), Side.LEFT), DOUBLE_TOLERANCE); - assertEquals(20., loopFlowResult.getLoopFlow(crac.getFlowCnec("FR-DE"), Side.RIGHT), DOUBLE_TOLERANCE); - assertEquals(20., loopFlowResult.getLoopFlow(crac.getFlowCnec("DE-NL"), Side.RIGHT), DOUBLE_TOLERANCE); - - assertEquals(40., loopFlowResult.getCommercialFlow(crac.getFlowCnec("FR-BE1"), Side.LEFT), DOUBLE_TOLERANCE); - assertEquals(40., loopFlowResult.getCommercialFlow(crac.getFlowCnec("BE1-BE2"), Side.LEFT), DOUBLE_TOLERANCE); - assertEquals(40., loopFlowResult.getCommercialFlow(crac.getFlowCnec("BE2-NL"), Side.LEFT), DOUBLE_TOLERANCE); - assertEquals(60., loopFlowResult.getCommercialFlow(crac.getFlowCnec("FR-DE"), Side.RIGHT), DOUBLE_TOLERANCE); - assertEquals(60., loopFlowResult.getCommercialFlow(crac.getFlowCnec("DE-NL"), Side.RIGHT), DOUBLE_TOLERANCE); - - assertEquals(20., loopFlowResult.getReferenceFlow(crac.getFlowCnec("FR-BE1"), Side.LEFT), DOUBLE_TOLERANCE); - assertEquals(120., loopFlowResult.getReferenceFlow(crac.getFlowCnec("BE1-BE2"), Side.LEFT), DOUBLE_TOLERANCE); - assertEquals(20., loopFlowResult.getReferenceFlow(crac.getFlowCnec("BE2-NL"), Side.LEFT), DOUBLE_TOLERANCE); - assertEquals(80., loopFlowResult.getReferenceFlow(crac.getFlowCnec("FR-DE"), Side.RIGHT), DOUBLE_TOLERANCE); - assertEquals(80., loopFlowResult.getReferenceFlow(crac.getFlowCnec("DE-NL"), Side.RIGHT), DOUBLE_TOLERANCE); + assertEquals(-20., loopFlowResult.getLoopFlow(crac.getFlowCnec("FR-BE1"), TwoSides.ONE), DOUBLE_TOLERANCE); + assertEquals(80., loopFlowResult.getLoopFlow(crac.getFlowCnec("BE1-BE2"), TwoSides.ONE), DOUBLE_TOLERANCE); + assertEquals(-20., loopFlowResult.getLoopFlow(crac.getFlowCnec("BE2-NL"), TwoSides.ONE), DOUBLE_TOLERANCE); + assertEquals(20., loopFlowResult.getLoopFlow(crac.getFlowCnec("FR-DE"), TwoSides.TWO), DOUBLE_TOLERANCE); + assertEquals(20., loopFlowResult.getLoopFlow(crac.getFlowCnec("DE-NL"), TwoSides.TWO), DOUBLE_TOLERANCE); + + assertEquals(40., loopFlowResult.getCommercialFlow(crac.getFlowCnec("FR-BE1"), TwoSides.ONE), DOUBLE_TOLERANCE); + assertEquals(40., loopFlowResult.getCommercialFlow(crac.getFlowCnec("BE1-BE2"), TwoSides.ONE), DOUBLE_TOLERANCE); + assertEquals(40., loopFlowResult.getCommercialFlow(crac.getFlowCnec("BE2-NL"), TwoSides.ONE), DOUBLE_TOLERANCE); + assertEquals(60., loopFlowResult.getCommercialFlow(crac.getFlowCnec("FR-DE"), TwoSides.TWO), DOUBLE_TOLERANCE); + assertEquals(60., loopFlowResult.getCommercialFlow(crac.getFlowCnec("DE-NL"), TwoSides.TWO), DOUBLE_TOLERANCE); + + assertEquals(20., loopFlowResult.getReferenceFlow(crac.getFlowCnec("FR-BE1"), TwoSides.ONE), DOUBLE_TOLERANCE); + assertEquals(120., loopFlowResult.getReferenceFlow(crac.getFlowCnec("BE1-BE2"), TwoSides.ONE), DOUBLE_TOLERANCE); + assertEquals(20., loopFlowResult.getReferenceFlow(crac.getFlowCnec("BE2-NL"), TwoSides.ONE), DOUBLE_TOLERANCE); + assertEquals(80., loopFlowResult.getReferenceFlow(crac.getFlowCnec("FR-DE"), TwoSides.TWO), DOUBLE_TOLERANCE); + assertEquals(80., loopFlowResult.getReferenceFlow(crac.getFlowCnec("DE-NL"), TwoSides.TWO), DOUBLE_TOLERANCE); } } diff --git a/loopflow-computation/src/test/java/com/powsybl/openrao/loopflowcomputation/LoopFlowResultTest.java b/loopflow-computation/src/test/java/com/powsybl/openrao/loopflowcomputation/LoopFlowResultTest.java index 9d3d7f55c5..e67409e808 100644 --- a/loopflow-computation/src/test/java/com/powsybl/openrao/loopflowcomputation/LoopFlowResultTest.java +++ b/loopflow-computation/src/test/java/com/powsybl/openrao/loopflowcomputation/LoopFlowResultTest.java @@ -8,7 +8,7 @@ import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.data.cracapi.cnec.BranchCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -32,16 +32,16 @@ public void setUp() { @Test void loopFlowResultTest() { LoopFlowResult loopFlowResult = new LoopFlowResult(); - loopFlowResult.addCnecResult(cnec, Side.RIGHT, 1., 2., 3.); - assertEquals(1., loopFlowResult.getLoopFlow(cnec, Side.RIGHT), DOUBLE_TOLERANCE); - assertEquals(2., loopFlowResult.getCommercialFlow(cnec, Side.RIGHT), DOUBLE_TOLERANCE); - assertEquals(3., loopFlowResult.getReferenceFlow(cnec, Side.RIGHT), DOUBLE_TOLERANCE); + loopFlowResult.addCnecResult(cnec, TwoSides.TWO, 1., 2., 3.); + assertEquals(1., loopFlowResult.getLoopFlow(cnec, TwoSides.TWO), DOUBLE_TOLERANCE); + assertEquals(2., loopFlowResult.getCommercialFlow(cnec, TwoSides.TWO), DOUBLE_TOLERANCE); + assertEquals(3., loopFlowResult.getReferenceFlow(cnec, TwoSides.TWO), DOUBLE_TOLERANCE); } @Test void loopFlowResultCnecNotFound() { LoopFlowResult loopFlowResult = new LoopFlowResult(); - assertThrows(OpenRaoException.class, () -> loopFlowResult.getLoopFlow(cnec, Side.RIGHT)); + assertThrows(OpenRaoException.class, () -> loopFlowResult.getLoopFlow(cnec, TwoSides.TWO)); } } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/AutomatonSimulator.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/AutomatonSimulator.java index aa58b2720e..08b60fb909 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/AutomatonSimulator.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/AutomatonSimulator.java @@ -15,7 +15,7 @@ import com.powsybl.openrao.data.cracapi.Identifiable; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.HvdcRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; @@ -608,10 +608,10 @@ RangeAutomatonSimulationResult shiftRangeActionsUntilFlowCnecsSecure(List> flowCnecsToBeExcluded = new HashSet<>(); + Set> flowCnecsToBeExcluded = new HashSet<>(); PrePerimeterResult automatonRangeActionOptimizationSensitivityAnalysisOutput = prePerimeterSensitivityOutput; Map, Double> activatedRangeActionsWithSetpoint = new HashMap<>(); - List> flowCnecsWithNegativeMargin = getCnecsWithNegativeMarginWithoutExcludedCnecs(flowCnecs, flowCnecsToBeExcluded, automatonRangeActionOptimizationSensitivityAnalysisOutput, activatedRangeActionsWithSetpoint); + List> flowCnecsWithNegativeMargin = getCnecsWithNegativeMarginWithoutExcludedCnecs(flowCnecs, flowCnecsToBeExcluded, automatonRangeActionOptimizationSensitivityAnalysisOutput, activatedRangeActionsWithSetpoint); if (alignedRangeActions.stream().allMatch(HvdcRangeAction.class::isInstance) && !flowCnecsWithNegativeMargin.isEmpty()) { // Disable HvdcAngleDroopActivePowerControl for HVDC lines, fetch their set-point, re-run sensitivity analysis and fetch new negative margins @@ -640,7 +640,7 @@ RangeAutomatonSimulationResult shiftRangeActionsUntilFlowCnecsSecure(List> alignedRangeAction } } - private double computeTotalSensitivityValue(List> alignedRangeActions, double sensitivityUnderestimator, PrePerimeterResult automatonRangeActionOptimizationSensitivityAnalysisOutput, FlowCnec toBeShiftedCnec, Side side) { + private double computeTotalSensitivityValue(List> alignedRangeActions, double sensitivityUnderestimator, PrePerimeterResult automatonRangeActionOptimizationSensitivityAnalysisOutput, FlowCnec toBeShiftedCnec, TwoSides side) { double sensitivityValue = 0; // Under-estimate range action sensitivity if convergence to margin = 0 is slow (ie if multiple passes // through this loop have been needed to secure the same CNEC) @@ -737,13 +737,13 @@ private static int safeDiffSignum(double newValue, double oldValue) { /** * This function builds a list of cnecs with negative margin, except cnecs in cnecsToBeExcluded. * N.B : margin is retrieved in MEGAWATT as only the sign matters. - * Returns a sorted list of FlowCnecs-Side pairs with negative margins. + * Returns a sorted list of FlowCnecs-TwoSides pairs with negative margins. */ - List> getCnecsWithNegativeMarginWithoutExcludedCnecs(Set flowCnecs, - Set> cnecsToBeExcluded, - PrePerimeterResult prePerimeterSensitivityOutput, - Map, Double> activatedRangeActionsWithSetpoint) { - Map, Double> cnecsAndMargins = new HashMap<>(); + List> getCnecsWithNegativeMarginWithoutExcludedCnecs(Set flowCnecs, + Set> cnecsToBeExcluded, + PrePerimeterResult prePerimeterSensitivityOutput, + Map, Double> activatedRangeActionsWithSetpoint) { + Map, Double> cnecsAndMargins = new HashMap<>(); flowCnecs.forEach(flowCnec -> flowCnec.getMonitoredSides().forEach(side -> { double margin = prePerimeterSensitivityOutput.getMargin(flowCnec, side, flowUnit); if (!cnecsToBeExcluded.contains(Pair.of(flowCnec, side)) && margin < 0) { diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/AbsolutePtdfSumsComputation.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/AbsolutePtdfSumsComputation.java index 117f701605..9853f24a95 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/AbsolutePtdfSumsComputation.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/AbsolutePtdfSumsComputation.java @@ -7,7 +7,7 @@ package com.powsybl.openrao.searchtreerao.commons; import com.powsybl.openrao.commons.EICode; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.glsk.commons.ZonalData; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; import com.powsybl.openrao.raoapi.ZoneToZonePtdfDefinition; @@ -32,21 +32,21 @@ public AbsolutePtdfSumsComputation(ZonalData glskProvide this.zTozPtdfs = zTozPtdfs; } - public Map> computeAbsolutePtdfSums(Set flowCnecs, SystematicSensitivityResult sensitivityResult) { - Map> ptdfSums = new HashMap<>(); + public Map> computeAbsolutePtdfSums(Set flowCnecs, SystematicSensitivityResult sensitivityResult) { + Map> ptdfSums = new HashMap<>(); List eiCodesInPtdfs = zTozPtdfs.stream().flatMap(zToz -> zToz.getEiCodes().stream()).toList(); for (FlowCnec flowCnec : flowCnecs) { flowCnec.getMonitoredSides().forEach(side -> { Map ptdfMap = buildZoneToSlackPtdfMap(flowCnec, side, glskProvider, eiCodesInPtdfs, sensitivityResult); double sumOfZToZPtdf = zTozPtdfs.stream().mapToDouble(zToz -> Math.abs(computeZToZPtdf(zToz, ptdfMap))).sum(); - ptdfSums.computeIfAbsent(flowCnec, k -> new EnumMap<>(Side.class)).put(side, sumOfZToZPtdf); + ptdfSums.computeIfAbsent(flowCnec, k -> new EnumMap<>(TwoSides.class)).put(side, sumOfZToZPtdf); }); } return ptdfSums; } - private Map buildZoneToSlackPtdfMap(FlowCnec flowCnec, Side side, ZonalData glsks, List eiCodesInBoundaries, SystematicSensitivityResult sensitivityResult) { + private Map buildZoneToSlackPtdfMap(FlowCnec flowCnec, TwoSides side, ZonalData glsks, List eiCodesInBoundaries, SystematicSensitivityResult sensitivityResult) { Map ptdfs = new HashMap<>(); for (EICode eiCode : eiCodesInBoundaries) { SensitivityVariableSet linearGlsk = glsks.getData(eiCode.getAreaCode()); diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/RaoLogger.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/RaoLogger.java index 8c45324e96..ddd7b1b6c8 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/RaoLogger.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/RaoLogger.java @@ -12,7 +12,7 @@ import com.powsybl.openrao.data.cracapi.Identifiable; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; @@ -129,7 +129,7 @@ static List getMostLimitingElementsResults(ObjectiveFunctionResult objec double cnecMargin = relativePositiveMargins ? flowResult.getRelativeMargin(cnec, unit) : flowResult.getMargin(cnec, unit); String isRelativeMargin = (relativePositiveMargins && cnecMargin > 0) ? " relative" : ""; - Side mostConstrainedSide = getMostConstrainedSide(cnec, flowResult, objectiveFunction); + TwoSides mostConstrainedSide = getMostConstrainedSide(cnec, flowResult, objectiveFunction); String ptdfIfRelative = (relativePositiveMargins && cnecMargin > 0) ? format(" (PTDF %f)", flowResult.getPtdfZonalSum(cnec, mostConstrainedSide)) : ""; summary.add(String.format(Locale.ENGLISH, "Limiting element #%02d:%s margin = %.2f %s%s, element %s at state %s, CNEC ID = \"%s\"", i + 1, @@ -144,17 +144,17 @@ static List getMostLimitingElementsResults(ObjectiveFunctionResult objec return summary; } - private static Side getMostConstrainedSide(FlowCnec cnec, - FlowResult flowResult, - ObjectiveFunctionParameters.ObjectiveFunctionType objectiveFunction) { + private static TwoSides getMostConstrainedSide(FlowCnec cnec, + FlowResult flowResult, + ObjectiveFunctionParameters.ObjectiveFunctionType objectiveFunction) { if (cnec.getMonitoredSides().size() == 1) { return cnec.getMonitoredSides().iterator().next(); } Unit unit = objectiveFunction.getUnit(); boolean relativePositiveMargins = objectiveFunction.relativePositiveMargins(); - double marginLeft = relativePositiveMargins ? flowResult.getRelativeMargin(cnec, Side.LEFT, unit) : flowResult.getMargin(cnec, Side.LEFT, unit); - double marginRight = relativePositiveMargins ? flowResult.getRelativeMargin(cnec, Side.RIGHT, unit) : flowResult.getMargin(cnec, Side.RIGHT, unit); - return marginRight < marginLeft ? Side.RIGHT : Side.LEFT; + double marginLeft = relativePositiveMargins ? flowResult.getRelativeMargin(cnec, TwoSides.ONE, unit) : flowResult.getMargin(cnec, TwoSides.ONE, unit); + double marginRight = relativePositiveMargins ? flowResult.getRelativeMargin(cnec, TwoSides.TWO, unit) : flowResult.getMargin(cnec, TwoSides.TWO, unit); + return marginRight < marginLeft ? TwoSides.TWO : TwoSides.ONE; } public static void logMostLimitingElementsResults(OpenRaoLogger logger, diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/RaoUtil.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/RaoUtil.java index 274e6ab977..d3ff42aadd 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/RaoUtil.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/RaoUtil.java @@ -14,7 +14,7 @@ import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.Cnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; import com.powsybl.openrao.data.cracapi.usagerule.*; import com.powsybl.openrao.data.refprog.referenceprogram.ReferenceProgramBuilder; @@ -81,7 +81,7 @@ public static void checkParameters(RaoParameters raoParameters, RaoInput raoInpu } } - public static double getFlowUnitMultiplier(FlowCnec cnec, Side voltageSide, Unit unitFrom, Unit unitTo) { + public static double getFlowUnitMultiplier(FlowCnec cnec, TwoSides voltageSide, Unit unitFrom, Unit unitTo) { if (unitFrom == unitTo) { return 1; } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/adapter/BranchResultAdapterImpl.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/adapter/BranchResultAdapterImpl.java index 02662fd695..9abcc0fbe3 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/adapter/BranchResultAdapterImpl.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/adapter/BranchResultAdapterImpl.java @@ -10,7 +10,7 @@ import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.loopflowcomputation.LoopFlowComputation; import com.powsybl.openrao.loopflowcomputation.LoopFlowResult; import com.powsybl.openrao.searchtreerao.commons.AbsolutePtdfSumsComputation; @@ -47,21 +47,21 @@ public static BranchResultAdpaterBuilder create() { public FlowResult getResult(SystematicSensitivityResult systematicSensitivityResult, Network network) { FlowResult ptdfs; if (absolutePtdfSumsComputation != null) { - Map> ptdfsMap = absolutePtdfSumsComputation.computeAbsolutePtdfSums(flowCnecs, systematicSensitivityResult); + Map> ptdfsMap = absolutePtdfSumsComputation.computeAbsolutePtdfSums(flowCnecs, systematicSensitivityResult); ptdfs = new FlowResult() { @Override - public double getFlow(FlowCnec flowCnec, Side side, Unit unit) { + public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { throw new NotImplementedException(); } @Override - public double getCommercialFlow(FlowCnec flowCnec, Side side, Unit unit) { + public double getCommercialFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { throw new NotImplementedException(); } @Override - public double getPtdfZonalSum(FlowCnec flowCnec, Side side) { + public double getPtdfZonalSum(FlowCnec flowCnec, TwoSides side) { if (ptdfsMap.containsKey(flowCnec) && ptdfsMap.get(flowCnec).containsKey(side)) { return ptdfsMap.get(flowCnec).get(side); } else { @@ -70,7 +70,7 @@ public double getPtdfZonalSum(FlowCnec flowCnec, Side side) { } @Override - public Map> getPtdfZonalSums() { + public Map> getPtdfZonalSums() { return ptdfsMap; } }; @@ -87,12 +87,12 @@ public Map> getPtdfZonalSums() { ); commercialFlows = new FlowResult() { @Override - public double getFlow(FlowCnec flowCnec, Side side, Unit unit) { + public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { throw new NotImplementedException(); } @Override - public double getCommercialFlow(FlowCnec flowCnec, Side side, Unit unit) { + public double getCommercialFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { if (unit == Unit.MEGAWATT) { return loopFlowResult.getCommercialFlow(flowCnec, side); } else { @@ -102,12 +102,12 @@ public double getCommercialFlow(FlowCnec flowCnec, Side side, Unit unit) { } @Override - public double getPtdfZonalSum(FlowCnec flowCnec, Side side) { + public double getPtdfZonalSum(FlowCnec flowCnec, TwoSides side) { throw new NotImplementedException(); } @Override - public Map> getPtdfZonalSums() { + public Map> getPtdfZonalSums() { throw new NotImplementedException(); } }; diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/BasicMarginEvaluator.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/BasicMarginEvaluator.java index fc98cefed5..853539cce0 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/BasicMarginEvaluator.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/BasicMarginEvaluator.java @@ -9,7 +9,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.searchtreerao.result.api.FlowResult; import com.powsybl.openrao.searchtreerao.result.api.RangeActionActivationResult; import com.powsybl.openrao.searchtreerao.result.api.SensitivityResult; @@ -31,7 +31,7 @@ public double getMargin(FlowResult flowResult, FlowCnec flowCnec, RangeActionAct } @Override - public double getMargin(FlowResult flowResult, FlowCnec flowCnec, Side side, RangeActionActivationResult rangeActionActivationResult, SensitivityResult sensitivityResult, Unit unit) { + public double getMargin(FlowResult flowResult, FlowCnec flowCnec, TwoSides side, RangeActionActivationResult rangeActionActivationResult, SensitivityResult sensitivityResult, Unit unit) { return flowResult.getMargin(flowCnec, side, unit); } } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/BasicRelativeMarginEvaluator.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/BasicRelativeMarginEvaluator.java index e0e71fba86..be3c515094 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/BasicRelativeMarginEvaluator.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/BasicRelativeMarginEvaluator.java @@ -9,7 +9,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.searchtreerao.result.api.FlowResult; import com.powsybl.openrao.searchtreerao.result.api.RangeActionActivationResult; import com.powsybl.openrao.searchtreerao.result.api.SensitivityResult; @@ -31,7 +31,7 @@ public double getMargin(FlowResult flowResult, FlowCnec flowCnec, RangeActionAct } @Override - public double getMargin(FlowResult flowResult, FlowCnec flowCnec, Side side, RangeActionActivationResult rangeActionActivationResult, SensitivityResult sensitivityResult, Unit unit) { + public double getMargin(FlowResult flowResult, FlowCnec flowCnec, TwoSides side, RangeActionActivationResult rangeActionActivationResult, SensitivityResult sensitivityResult, Unit unit) { return flowResult.getRelativeMargin(flowCnec, side, unit); } } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/LoopFlowViolationCostEvaluator.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/LoopFlowViolationCostEvaluator.java index 1c0d4cec54..3a97fd2cf4 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/LoopFlowViolationCostEvaluator.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/LoopFlowViolationCostEvaluator.java @@ -9,7 +9,7 @@ import com.powsybl.openrao.commons.logs.OpenRaoLoggerProvider; import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracloopflowextension.LoopFlowThreshold; import com.powsybl.openrao.data.raoresultapi.ComputationStatus; import com.powsybl.openrao.raoapi.parameters.extensions.LoopFlowParametersExtension; @@ -94,7 +94,7 @@ public Set getFlowCnecs() { .max(Double::compareTo).orElse(0.0); } - private double getLoopFlowUpperBound(FlowCnec cnec, Side side) { + private double getLoopFlowUpperBound(FlowCnec cnec, TwoSides side) { double loopFlowThreshold = cnec.getExtension(LoopFlowThreshold.class).getThresholdWithReliabilityMargin(Unit.MEGAWATT); double initialLoopFlow = initialLoopFLowResult.getLoopFlow(cnec, side, Unit.MEGAWATT); return Math.max(0.0, Math.max(loopFlowThreshold, Math.abs(initialLoopFlow) + loopFlowAcceptableAugmentation)); diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/MarginEvaluator.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/MarginEvaluator.java index b07094e505..8d6ef9eca2 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/MarginEvaluator.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/MarginEvaluator.java @@ -9,7 +9,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.searchtreerao.result.api.FlowResult; import com.powsybl.openrao.searchtreerao.result.api.RangeActionActivationResult; import com.powsybl.openrao.searchtreerao.result.api.SensitivityResult; @@ -21,5 +21,5 @@ public interface MarginEvaluator { double getMargin(FlowResult flowResult, FlowCnec flowCnec, RangeActionActivationResult rangeActionActivationResult, SensitivityResult sensitivityResult, Unit unit); - double getMargin(FlowResult flowResult, FlowCnec flowCnec, Side side, RangeActionActivationResult rangeActionActivationResult, SensitivityResult sensitivityResult, Unit unit); + double getMargin(FlowResult flowResult, FlowCnec flowCnec, TwoSides side, RangeActionActivationResult rangeActionActivationResult, SensitivityResult sensitivityResult, Unit unit); } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/MarginEvaluatorWithMarginDecreaseUnoptimizedCnecs.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/MarginEvaluatorWithMarginDecreaseUnoptimizedCnecs.java index 93ada14ad7..e8f62bcd79 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/MarginEvaluatorWithMarginDecreaseUnoptimizedCnecs.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/MarginEvaluatorWithMarginDecreaseUnoptimizedCnecs.java @@ -9,7 +9,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.searchtreerao.result.api.FlowResult; import com.powsybl.openrao.searchtreerao.result.api.RangeActionActivationResult; import com.powsybl.openrao.searchtreerao.result.api.SensitivityResult; @@ -45,7 +45,7 @@ public double getMargin(FlowResult flowResult, FlowCnec flowCnec, RangeActionAct } @Override - public double getMargin(FlowResult flowResult, FlowCnec flowCnec, Side side, RangeActionActivationResult rangeActionActivationResult, SensitivityResult sensitivityResult, Unit unit) { + public double getMargin(FlowResult flowResult, FlowCnec flowCnec, TwoSides side, RangeActionActivationResult rangeActionActivationResult, SensitivityResult sensitivityResult, Unit unit) { double newMargin = marginEvaluator.getMargin(flowResult, flowCnec, side, rangeActionActivationResult, sensitivityResult, unit); double prePerimeterMargin = marginEvaluator.getMargin(prePerimeterFlowResult, flowCnec, side, rangeActionActivationResult, sensitivityResult, unit); return computeMargin(flowCnec, newMargin, prePerimeterMargin); diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/MinMarginEvaluator.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/MinMarginEvaluator.java index 4fa52e7b1b..f2f767be8a 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/MinMarginEvaluator.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/MinMarginEvaluator.java @@ -10,7 +10,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.cnec.Cnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.raoresultapi.ComputationStatus; import com.powsybl.openrao.searchtreerao.result.api.FlowResult; import com.powsybl.openrao.searchtreerao.result.api.RangeActionActivationResult; @@ -94,10 +94,10 @@ private double getHighestThresholdAmongFlowCnecs() { private double getHighestThreshold(FlowCnec flowCnec) { return Math.max( Math.max( - flowCnec.getUpperBound(Side.LEFT, unit).orElse(0.0), - flowCnec.getUpperBound(Side.RIGHT, unit).orElse(0.0)), + flowCnec.getUpperBound(TwoSides.ONE, unit).orElse(0.0), + flowCnec.getUpperBound(TwoSides.TWO, unit).orElse(0.0)), Math.max( - -flowCnec.getLowerBound(Side.LEFT, unit).orElse(0.0), - -flowCnec.getLowerBound(Side.RIGHT, unit).orElse(0.0))); + -flowCnec.getLowerBound(TwoSides.ONE, unit).orElse(0.0), + -flowCnec.getLowerBound(TwoSides.TWO, unit).orElse(0.0))); } } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/BestTapFinder.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/BestTapFinder.java index 73756a398e..d666f749ae 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/BestTapFinder.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/BestTapFinder.java @@ -13,7 +13,7 @@ import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.searchtreerao.commons.RaoUtil; import com.powsybl.openrao.searchtreerao.commons.optimizationperimeters.OptimizationPerimeter; import com.powsybl.openrao.searchtreerao.result.api.*; @@ -234,7 +234,7 @@ static Pair computeMinMargins(Network network, double minMargin1 = Double.MAX_VALUE; double minMargin2 = Double.MAX_VALUE; for (FlowCnec flowCnec : linearOptimizationResult.getMostLimitingElements(10)) { - for (Side side : flowCnec.getMonitoredSides()) { + for (TwoSides side : flowCnec.getMonitoredSides()) { double sensitivity = linearOptimizationResult.getSensitivityValue(flowCnec, side, pstRangeAction, MEGAWATT); double currentSetPoint = pstRangeAction.getCurrentSetpoint(network); double referenceFlow = linearOptimizationResult.getFlow(flowCnec, side, unit) * RaoUtil.getFlowUnitMultiplier(flowCnec, side, unit, MEGAWATT); diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/CoreProblemFiller.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/CoreProblemFiller.java index 6f8161dbee..fc92c1100f 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/CoreProblemFiller.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/CoreProblemFiller.java @@ -12,7 +12,7 @@ import com.powsybl.openrao.data.cracapi.Identifiable; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.range.RangeType; import com.powsybl.openrao.data.cracapi.range.StandardRange; import com.powsybl.openrao.data.cracapi.range.TapRange; @@ -169,7 +169,7 @@ private void updateFlowConstraints(LinearProblem linearProblem, Set va })); } - private void addImpactOfRangeActionOnCnec(LinearProblem linearProblem, SensitivityResult sensitivityResult, FlowCnec cnec, Side side, RangeActionActivationResult rangeActionActivationResult) { + private void addImpactOfRangeActionOnCnec(LinearProblem linearProblem, SensitivityResult sensitivityResult, FlowCnec cnec, TwoSides side, RangeActionActivationResult rangeActionActivationResult) { OpenRaoMPConstraint flowConstraint = linearProblem.getFlowConstraint(cnec, side); List statesBeforeCnec = FillersUtil.getPreviousStates(cnec.getState(), optimizationContext).stream() @@ -191,7 +191,7 @@ private void addImpactOfRangeActionOnCnec(LinearProblem linearProblem, Sensitivi } } - private void addImpactOfRangeActionOnCnec(LinearProblem linearProblem, SensitivityResult sensitivityResult, RangeAction rangeAction, State state, FlowCnec cnec, Side side, OpenRaoMPConstraint flowConstraint, RangeActionActivationResult rangeActionActivationResult) { + private void addImpactOfRangeActionOnCnec(LinearProblem linearProblem, SensitivityResult sensitivityResult, RangeAction rangeAction, State state, FlowCnec cnec, TwoSides side, OpenRaoMPConstraint flowConstraint, RangeActionActivationResult rangeActionActivationResult) { OpenRaoMPVariable setPointVariable = linearProblem.getRangeActionSetpointVariable(rangeAction, state); double sensitivity = sensitivityResult.getSensitivityValue(cnec, side, rangeAction, Unit.MEGAWATT); diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxLoopFlowFiller.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxLoopFlowFiller.java index ac0b7d16dd..856704eb4c 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxLoopFlowFiller.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxLoopFlowFiller.java @@ -9,7 +9,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.Identifiable; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracloopflowextension.LoopFlowThreshold; import com.powsybl.openrao.raoapi.parameters.extensions.LoopFlowParametersExtension; import com.powsybl.openrao.raoapi.parameters.extensions.PtdfApproximation; @@ -89,7 +89,7 @@ public void updateBetweenMipIteration(LinearProblem linearProblem, RangeActionAc private void buildLoopFlowConstraintsAndUpdateObjectiveFunction(LinearProblem linearProblem, Set validLoopFlowCnecs, FlowResult flowResult) { for (FlowCnec cnec : validLoopFlowCnecs) { - for (Side side : cnec.getMonitoredSides()) { + for (TwoSides side : cnec.getMonitoredSides()) { // build loopFlow upper bound, with inputThreshold, initial loop-flows, and configuration parameters double loopFlowUpperBound = getLoopFlowUpperBound(cnec, side); @@ -148,7 +148,7 @@ private void updateLoopFlowConstraints(LinearProblem linearProblem, Set ran return rangeAction.getId() + SEPARATOR + state.getId() + SEPARATOR + ABSOLUTE_VARIATION + positiveOrNegative.toString().toLowerCase() + SEPARATOR + CONSTRAINT_SUFFIX; } - public static String minimumMarginConstraintId(FlowCnec flowCnec, Side side, LinearProblem.MarginExtension belowOrAboveThreshold) { + public static String minimumMarginConstraintId(FlowCnec flowCnec, TwoSides side, LinearProblem.MarginExtension belowOrAboveThreshold) { return String.join(SEPARATOR, flowCnec.getId(), side.toString().toLowerCase(), MIN_MARGIN, belowOrAboveThreshold.toString().toLowerCase(), CONSTRAINT_SUFFIX); } @@ -132,7 +132,7 @@ public static String minimumRelativeMarginVariableId() { return MIN_RELATIVE_MARGIN + SEPARATOR + VARIABLE_SUFFIX; } - public static String minimumRelativeMarginConstraintId(FlowCnec flowCnec, Side side, LinearProblem.MarginExtension belowOrAboveThreshold) { + public static String minimumRelativeMarginConstraintId(FlowCnec flowCnec, TwoSides side, LinearProblem.MarginExtension belowOrAboveThreshold) { return String.join(SEPARATOR, flowCnec.getId(), side.toString().toLowerCase(), MIN_RELATIVE_MARGIN, belowOrAboveThreshold.toString().toLowerCase(), CONSTRAINT_SUFFIX); } @@ -148,27 +148,27 @@ public static String minimumRelativeMarginSetToZeroConstraintId() { return MIN_RELATIVE_MARGIN + SEPARATOR + CONSTRAINT_SUFFIX; } - public static String maxLoopFlowConstraintId(FlowCnec flowCnec, Side side, LinearProblem.BoundExtension lbOrUb) { + public static String maxLoopFlowConstraintId(FlowCnec flowCnec, TwoSides side, LinearProblem.BoundExtension lbOrUb) { return String.join(SEPARATOR, flowCnec.getId(), side.toString().toLowerCase(), MAX_LOOPFLOW, lbOrUb.toString().toLowerCase(), CONSTRAINT_SUFFIX); } - public static String loopflowViolationVariableId(FlowCnec flowCnec, Side side) { + public static String loopflowViolationVariableId(FlowCnec flowCnec, TwoSides side) { return String.join(SEPARATOR, flowCnec.getId(), side.toString().toLowerCase(), LOOPFLOWVIOLATION, VARIABLE_SUFFIX); } - public static String mnecViolationVariableId(FlowCnec mnec, Side side) { + public static String mnecViolationVariableId(FlowCnec mnec, TwoSides side) { return String.join(SEPARATOR, mnec.getId(), side.toString().toLowerCase(), MNEC_VIOLATION, VARIABLE_SUFFIX); } - public static String mnecFlowConstraintId(FlowCnec mnec, Side side, LinearProblem.MarginExtension belowOrAboveThreshold) { + public static String mnecFlowConstraintId(FlowCnec mnec, TwoSides side, LinearProblem.MarginExtension belowOrAboveThreshold) { return String.join(SEPARATOR, mnec.getId(), side.toString().toLowerCase(), MNEC_FLOW, belowOrAboveThreshold.toString().toLowerCase(), CONSTRAINT_SUFFIX); } - public static String optimizeCnecBinaryVariableId(FlowCnec flowCnec, Side side) { + public static String optimizeCnecBinaryVariableId(FlowCnec flowCnec, TwoSides side) { return String.join(SEPARATOR, flowCnec.getId(), side.toString().toLowerCase(), OPTIMIZE_CNEC, VARIABLE_SUFFIX); } - public static String dontOptimizeCnecConstraintId(FlowCnec flowCnec, Side side, LinearProblem.MarginExtension belowOrAboveThreshold) { + public static String dontOptimizeCnecConstraintId(FlowCnec flowCnec, TwoSides side, LinearProblem.MarginExtension belowOrAboveThreshold) { return String.join(SEPARATOR, flowCnec.getId(), side.toString().toLowerCase(), OPTIMIZE_CNEC + belowOrAboveThreshold.toString().toLowerCase(), CONSTRAINT_SUFFIX); } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/api/FlowResult.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/api/FlowResult.java index 08d11df263..db31333322 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/api/FlowResult.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/api/FlowResult.java @@ -9,7 +9,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.raoapi.parameters.RaoParameters; import java.util.Map; @@ -27,7 +27,7 @@ public interface FlowResult { * @param unit: The unit in which the flow is queried. Only accepted values are MEGAWATT or AMPERE. * @return The flow on the branch in the given unit. */ - double getFlow(FlowCnec flowCnec, Side side, Unit unit); + double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit); /** * It gives the margin on a {@link FlowCnec} in a given {@link Unit}. It is basically the difference between the @@ -45,7 +45,7 @@ default double getMargin(FlowCnec flowCnec, Unit unit) { } /** - * It gives the margin on a {@link FlowCnec} at a given {@link Side} in a given {@link Unit}. It is the difference + * It gives the margin on a {@link FlowCnec} at a given {@link TwoSides} in a given {@link Unit}. It is the difference * between the flow and the most constraining threshold in the flow direction of the given branch. * If it is negative the branch is under constraint. * @@ -54,7 +54,7 @@ default double getMargin(FlowCnec flowCnec, Unit unit) { * @param unit: The unit in which the margin is queried. Only accepted values are MEGAWATT or AMPERE. * @return The margin on the branch in the given unit. */ - default double getMargin(FlowCnec flowCnec, Side side, Unit unit) { + default double getMargin(FlowCnec flowCnec, TwoSides side, Unit unit) { return flowCnec.computeMargin(getFlow(flowCnec, side, unit), side, unit); } @@ -78,7 +78,7 @@ default double getRelativeMargin(FlowCnec flowCnec, Unit unit) { .orElse(Double.NaN); } - default double getRelativeMargin(FlowCnec flowCnec, Side side, Unit unit) { + default double getRelativeMargin(FlowCnec flowCnec, TwoSides side, Unit unit) { if (Double.isNaN(getPtdfZonalSum(flowCnec, side)) || getPtdfZonalSum(flowCnec, side) == 0) { return Double.NaN; } @@ -96,7 +96,7 @@ default double getRelativeMargin(FlowCnec flowCnec, Side side, Unit unit) { * @param unit: The unit in which the commercial flow is queried. Only accepted values are MEGAWATT or AMPERE. * @return The commercial flow on the branch in the given unit. */ - double getCommercialFlow(FlowCnec flowCnec, Side side, Unit unit); + double getCommercialFlow(FlowCnec flowCnec, TwoSides side, Unit unit); /** * It gives the value of loop flow (according to CORE D-2 CC methodology) on a {@link FlowCnec} in a given @@ -108,7 +108,7 @@ default double getRelativeMargin(FlowCnec flowCnec, Side side, Unit unit) { * @param unit: The unit in which the loop flow is queried. Only accepted values are MEGAWATT or AMPERE. * @return The loop flow on the branch in the given unit. */ - default double getLoopFlow(FlowCnec flowCnec, Side side, Unit unit) { + default double getLoopFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { return getFlow(flowCnec, side, unit) - getCommercialFlow(flowCnec, side, unit); } @@ -121,14 +121,14 @@ default double getLoopFlow(FlowCnec flowCnec, Side side, Unit unit) { * @param side: The side of the branch to be queried. * @return The sum of the computation areas' zonal PTDFs on the branch. */ - double getPtdfZonalSum(FlowCnec flowCnec, Side side); + double getPtdfZonalSum(FlowCnec flowCnec, TwoSides side); /** * It gives a map of the sums of the computation areas' zonal PTDFs for each {@link FlowCnec}, on each of its - * monitored {@link Side}s. If the computation does not consider PTDF values or if the {@link RaoParameters} does + * monitored {@link TwoSides}s. If the computation does not consider PTDF values or if the {@link RaoParameters} does * not define any list of considered areas, this method could return a map containing {@code Double.NaN} values. * * @return A map of the sums of the computation areas' zonal PTDFs on each branch. */ - Map> getPtdfZonalSums(); + Map> getPtdfZonalSums(); } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/api/SensitivityResult.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/api/SensitivityResult.java index 46939bf872..ae0f953e1a 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/api/SensitivityResult.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/api/SensitivityResult.java @@ -10,7 +10,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; import com.powsybl.openrao.data.raoresultapi.ComputationStatus; import com.powsybl.sensitivity.SensitivityVariableSet; @@ -28,7 +28,7 @@ public interface SensitivityResult { Set getContingencies(); - double getSensitivityValue(FlowCnec flowCnec, Side side, RangeAction rangeAction, Unit unit); + double getSensitivityValue(FlowCnec flowCnec, TwoSides side, RangeAction rangeAction, Unit unit); - double getSensitivityValue(FlowCnec flowCnec, Side side, SensitivityVariableSet linearGlsk, Unit unit); + double getSensitivityValue(FlowCnec flowCnec, TwoSides side, SensitivityVariableSet linearGlsk, Unit unit); } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/AutomatonPerimeterResultImpl.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/AutomatonPerimeterResultImpl.java index 7548119cf0..76f6bb39e3 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/AutomatonPerimeterResultImpl.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/AutomatonPerimeterResultImpl.java @@ -11,7 +11,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; @@ -52,22 +52,22 @@ public PrePerimeterResult getPostAutomatonSensitivityAnalysisOutput() { } @Override - public double getFlow(FlowCnec flowCnec, Side side, Unit unit) { + public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { return postAutomatonSensitivityAnalysisOutput.getFlow(flowCnec, side, unit); } @Override - public double getCommercialFlow(FlowCnec flowCnec, Side side, Unit unit) { + public double getCommercialFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { return postAutomatonSensitivityAnalysisOutput.getCommercialFlow(flowCnec, side, unit); } @Override - public double getPtdfZonalSum(FlowCnec flowCnec, Side side) { + public double getPtdfZonalSum(FlowCnec flowCnec, TwoSides side) { return postAutomatonSensitivityAnalysisOutput.getPtdfZonalSum(flowCnec, side); } @Override - public Map> getPtdfZonalSums() { + public Map> getPtdfZonalSums() { return postAutomatonSensitivityAnalysisOutput.getPtdfZonalSums(); } @@ -195,12 +195,12 @@ public Set getContingencies() { } @Override - public double getSensitivityValue(FlowCnec flowCnec, Side side, RangeAction rangeAction, Unit unit) { + public double getSensitivityValue(FlowCnec flowCnec, TwoSides side, RangeAction rangeAction, Unit unit) { return postAutomatonSensitivityAnalysisOutput.getSensitivityValue(flowCnec, side, rangeAction, unit); } @Override - public double getSensitivityValue(FlowCnec flowCnec, Side side, SensitivityVariableSet linearGlsk, Unit unit) { + public double getSensitivityValue(FlowCnec flowCnec, TwoSides side, SensitivityVariableSet linearGlsk, Unit unit) { return postAutomatonSensitivityAnalysisOutput.getSensitivityValue(flowCnec, side, linearGlsk, unit); } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/CurativeWithSecondPraoResult.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/CurativeWithSecondPraoResult.java index f60eb97091..6859c98982 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/CurativeWithSecondPraoResult.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/CurativeWithSecondPraoResult.java @@ -6,7 +6,7 @@ import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.Cnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; @@ -62,25 +62,25 @@ private boolean isCraIncludedInSecondPreventiveRao(RemedialAction remedialAct } @Override - public double getFlow(FlowCnec flowCnec, Side side, Unit unit) { + public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { checkCnec(flowCnec); return postCraSensitivityFlowResult.getFlow(flowCnec, side, unit); } @Override - public double getCommercialFlow(FlowCnec flowCnec, Side side, Unit unit) { + public double getCommercialFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { checkCnec(flowCnec); return postCraSensitivityFlowResult.getCommercialFlow(flowCnec, side, unit); } @Override - public double getPtdfZonalSum(FlowCnec flowCnec, Side side) { + public double getPtdfZonalSum(FlowCnec flowCnec, TwoSides side) { checkCnec(flowCnec); return postCraSensitivityFlowResult.getPtdfZonalSum(flowCnec, side); } @Override - public Map> getPtdfZonalSums() { + public Map> getPtdfZonalSums() { return postCraSensitivityFlowResult.getPtdfZonalSums(); } @@ -216,7 +216,7 @@ public Set getContingencies() { } @Override - public double getSensitivityValue(FlowCnec flowCnec, Side side, RangeAction rangeAction, Unit unit) { + public double getSensitivityValue(FlowCnec flowCnec, TwoSides side, RangeAction rangeAction, Unit unit) { checkCnec(flowCnec); if (!firstCraoResult.getRangeActions().contains(rangeAction)) { throw new OpenRaoException(String.format("RangeAction %s does not belong to this result's state (%s)", rangeAction.getId(), state)); @@ -225,7 +225,7 @@ public double getSensitivityValue(FlowCnec flowCnec, Side side, RangeAction r } @Override - public double getSensitivityValue(FlowCnec flowCnec, Side side, SensitivityVariableSet linearGlsk, Unit unit) { + public double getSensitivityValue(FlowCnec flowCnec, TwoSides side, SensitivityVariableSet linearGlsk, Unit unit) { checkCnec(flowCnec); return postCraSensitivitySensitivityResult.getSensitivityValue(flowCnec, side, linearGlsk, unit); } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/EmptyFlowResultImpl.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/EmptyFlowResultImpl.java index fbeabe4e09..e0e7ba0b89 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/EmptyFlowResultImpl.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/EmptyFlowResultImpl.java @@ -9,7 +9,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.searchtreerao.result.api.FlowResult; import java.util.Collections; @@ -21,22 +21,22 @@ public class EmptyFlowResultImpl implements FlowResult { @Override - public double getFlow(FlowCnec flowCnec, Side side, Unit unit) { + public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { return Double.NaN; } @Override - public double getCommercialFlow(FlowCnec flowCnec, Side side, Unit unit) { + public double getCommercialFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { return Double.NaN; } @Override - public double getPtdfZonalSum(FlowCnec flowCnec, Side side) { + public double getPtdfZonalSum(FlowCnec flowCnec, TwoSides side) { return Double.NaN; } @Override - public Map> getPtdfZonalSums() { + public Map> getPtdfZonalSums() { return Collections.emptyMap(); } } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/FailedRaoResultImpl.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/FailedRaoResultImpl.java index 77edac71e0..bf7081f47d 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/FailedRaoResultImpl.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/FailedRaoResultImpl.java @@ -12,7 +12,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.*; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; @@ -50,22 +50,22 @@ public double getRelativeMargin(Instant optimizedInstant, FlowCnec flowCnec, Uni } @Override - public double getFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit) { + public double getFlow(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side, Unit unit) { throw new OpenRaoException(SHOULD_NOT_BE_USED); } @Override - public double getCommercialFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit) { + public double getCommercialFlow(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side, Unit unit) { throw new OpenRaoException(SHOULD_NOT_BE_USED); } @Override - public double getLoopFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit) { + public double getLoopFlow(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side, Unit unit) { throw new OpenRaoException(SHOULD_NOT_BE_USED); } @Override - public double getPtdfZonalSum(Instant optimizedInstant, FlowCnec flowCnec, Side side) { + public double getPtdfZonalSum(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side) { throw new OpenRaoException(SHOULD_NOT_BE_USED); } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultFromMapImpl.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultFromMapImpl.java index e037a7ce81..608b5537f7 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultFromMapImpl.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultFromMapImpl.java @@ -10,7 +10,7 @@ import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.searchtreerao.commons.RaoUtil; import com.powsybl.openrao.searchtreerao.result.api.FlowResult; import com.powsybl.openrao.sensitivityanalysis.SystematicSensitivityResult; @@ -24,19 +24,19 @@ */ public class FlowResultFromMapImpl implements FlowResult { protected final SystematicSensitivityResult systematicSensitivityResult; - private final Map> commercialFlows; - private final Map> ptdfZonalSums; + private final Map> commercialFlows; + private final Map> ptdfZonalSums; public FlowResultFromMapImpl(SystematicSensitivityResult systematicSensitivityResult, - Map> commercialFlows, - Map> ptdfZonalSums) { + Map> commercialFlows, + Map> ptdfZonalSums) { this.systematicSensitivityResult = systematicSensitivityResult; this.commercialFlows = commercialFlows; this.ptdfZonalSums = ptdfZonalSums; } @Override - public double getFlow(FlowCnec flowCnec, Side side, Unit unit) { + public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { if (unit == Unit.MEGAWATT) { return systematicSensitivityResult.getReferenceFlow(flowCnec, side); } else if (unit == Unit.AMPERE) { @@ -52,7 +52,7 @@ public double getFlow(FlowCnec flowCnec, Side side, Unit unit) { } @Override - public double getCommercialFlow(FlowCnec flowCnec, Side side, Unit unit) { + public double getCommercialFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { if (unit != Unit.MEGAWATT) { throw new OpenRaoException("Commercial flows only in MW."); } @@ -63,7 +63,7 @@ public double getCommercialFlow(FlowCnec flowCnec, Side side, Unit unit) { } @Override - public double getPtdfZonalSum(FlowCnec flowCnec, Side side) { + public double getPtdfZonalSum(FlowCnec flowCnec, TwoSides side) { if (!ptdfZonalSums.containsKey(flowCnec) || !ptdfZonalSums.get(flowCnec).containsKey(side)) { throw new OpenRaoException(format("No PTDF computed on the CNEC %s on side %s", flowCnec.getName(), side)); } @@ -71,7 +71,7 @@ public double getPtdfZonalSum(FlowCnec flowCnec, Side side) { } @Override - public Map> getPtdfZonalSums() { + public Map> getPtdfZonalSums() { return ptdfZonalSums; } } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultImpl.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultImpl.java index 174fc7e5bc..41be1423e7 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultImpl.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultImpl.java @@ -10,7 +10,7 @@ import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.searchtreerao.commons.RaoUtil; import com.powsybl.openrao.searchtreerao.result.api.FlowResult; import com.powsybl.openrao.sensitivityanalysis.SystematicSensitivityResult; @@ -34,7 +34,7 @@ public FlowResultImpl(SystematicSensitivityResult systematicSensitivityResult, } @Override - public double getFlow(FlowCnec flowCnec, Side side, Unit unit) { + public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { if (unit == Unit.MEGAWATT) { return systematicSensitivityResult.getReferenceFlow(flowCnec, side); } else if (unit == Unit.AMPERE) { @@ -50,7 +50,7 @@ public double getFlow(FlowCnec flowCnec, Side side, Unit unit) { } @Override - public double getCommercialFlow(FlowCnec flowCnec, Side side, Unit unit) { + public double getCommercialFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { if (unit == Unit.MEGAWATT) { return fixedCommercialFlows.getCommercialFlow(flowCnec, side, unit); } else { @@ -59,12 +59,12 @@ public double getCommercialFlow(FlowCnec flowCnec, Side side, Unit unit) { } @Override - public double getPtdfZonalSum(FlowCnec flowCnec, Side side) { + public double getPtdfZonalSum(FlowCnec flowCnec, TwoSides side) { return fixedPtdfs.getPtdfZonalSum(flowCnec, side); } @Override - public Map> getPtdfZonalSums() { + public Map> getPtdfZonalSums() { return fixedPtdfs.getPtdfZonalSums(); } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/IteratingLinearOptimizationResultImpl.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/IteratingLinearOptimizationResultImpl.java index dc3adbcad6..780ce0ce65 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/IteratingLinearOptimizationResultImpl.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/IteratingLinearOptimizationResultImpl.java @@ -10,7 +10,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; import com.powsybl.openrao.data.raoresultapi.ComputationStatus; @@ -118,22 +118,22 @@ public LinearProblemStatus getStatus() { } @Override - public double getFlow(FlowCnec branchCnec, Side side, Unit unit) { + public double getFlow(FlowCnec branchCnec, TwoSides side, Unit unit) { return flowResult.getFlow(branchCnec, side, unit); } @Override - public double getCommercialFlow(FlowCnec branchCnec, Side side, Unit unit) { + public double getCommercialFlow(FlowCnec branchCnec, TwoSides side, Unit unit) { return flowResult.getCommercialFlow(branchCnec, side, unit); } @Override - public double getPtdfZonalSum(FlowCnec branchCnec, Side side) { + public double getPtdfZonalSum(FlowCnec branchCnec, TwoSides side) { return flowResult.getPtdfZonalSum(branchCnec, side); } @Override - public Map> getPtdfZonalSums() { + public Map> getPtdfZonalSums() { return flowResult.getPtdfZonalSums(); } @@ -183,12 +183,12 @@ public Set getContingencies() { } @Override - public double getSensitivityValue(FlowCnec branchCnec, Side side, RangeAction rangeAction, Unit unit) { + public double getSensitivityValue(FlowCnec branchCnec, TwoSides side, RangeAction rangeAction, Unit unit) { return sensitivityResult.getSensitivityValue(branchCnec, side, rangeAction, unit); } @Override - public double getSensitivityValue(FlowCnec branchCnec, Side side, SensitivityVariableSet linearGlsk, Unit unit) { + public double getSensitivityValue(FlowCnec branchCnec, TwoSides side, SensitivityVariableSet linearGlsk, Unit unit) { return sensitivityResult.getSensitivityValue(branchCnec, side, linearGlsk, unit); } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/OneStateOnlyRaoResultImpl.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/OneStateOnlyRaoResultImpl.java index c4945b090e..0f6e7dd4b4 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/OneStateOnlyRaoResultImpl.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/OneStateOnlyRaoResultImpl.java @@ -13,7 +13,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.*; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; @@ -94,22 +94,22 @@ public double getRelativeMargin(Instant optimizedInstant, FlowCnec flowCnec, Uni } @Override - public double getFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit) { + public double getFlow(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side, Unit unit) { return getAppropriateResult(optimizedInstant, flowCnec).getFlow(flowCnec, side, unit); } @Override - public double getCommercialFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit) { + public double getCommercialFlow(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side, Unit unit) { return getAppropriateResult(optimizedInstant, flowCnec).getCommercialFlow(flowCnec, side, unit); } @Override - public double getLoopFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit) { + public double getLoopFlow(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side, Unit unit) { return getAppropriateResult(optimizedInstant, flowCnec).getLoopFlow(flowCnec, side, unit); } @Override - public double getPtdfZonalSum(Instant optimizedInstant, FlowCnec flowCnec, Side side) { + public double getPtdfZonalSum(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side) { return getAppropriateResult(optimizedInstant, flowCnec).getPtdfZonalSum(flowCnec, side); } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/PerimeterResultImpl.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/PerimeterResultImpl.java index 44aa9a0da4..604e1076f8 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/PerimeterResultImpl.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/PerimeterResultImpl.java @@ -11,7 +11,7 @@ import com.powsybl.openrao.data.cracapi.NetworkElement; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; @@ -38,22 +38,22 @@ public PerimeterResultImpl(RangeActionSetpointResult prePerimeterRangeActionSetp } @Override - public double getFlow(FlowCnec flowCnec, Side side, Unit unit) { + public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { return optimizationResult.getFlow(flowCnec, side, unit); } @Override - public double getCommercialFlow(FlowCnec flowCnec, Side side, Unit unit) { + public double getCommercialFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { return optimizationResult.getCommercialFlow(flowCnec, side, unit); } @Override - public double getPtdfZonalSum(FlowCnec flowCnec, Side side) { + public double getPtdfZonalSum(FlowCnec flowCnec, TwoSides side) { return optimizationResult.getPtdfZonalSum(flowCnec, side); } @Override - public Map> getPtdfZonalSums() { + public Map> getPtdfZonalSums() { return optimizationResult.getPtdfZonalSums(); } @@ -200,12 +200,12 @@ public Set getContingencies() { } @Override - public double getSensitivityValue(FlowCnec flowCnec, Side side, RangeAction rangeAction, Unit unit) { + public double getSensitivityValue(FlowCnec flowCnec, TwoSides side, RangeAction rangeAction, Unit unit) { throw new NotImplementedException("This method is not implemented"); } @Override - public double getSensitivityValue(FlowCnec flowCnec, Side side, SensitivityVariableSet linearGlsk, Unit unit) { + public double getSensitivityValue(FlowCnec flowCnec, TwoSides side, SensitivityVariableSet linearGlsk, Unit unit) { throw new NotImplementedException("This method is not implemented"); } } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/PrePerimeterSensitivityResultImpl.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/PrePerimeterSensitivityResultImpl.java index 20906079da..f237419f34 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/PrePerimeterSensitivityResultImpl.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/PrePerimeterSensitivityResultImpl.java @@ -9,7 +9,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; import com.powsybl.openrao.data.raoresultapi.ComputationStatus; @@ -67,17 +67,17 @@ public ComputationStatus getSensitivityStatus(State state) { } @Override - public double getSensitivityValue(FlowCnec flowCnec, Side side, RangeAction rangeAction, Unit unit) { + public double getSensitivityValue(FlowCnec flowCnec, TwoSides side, RangeAction rangeAction, Unit unit) { return sensitivityResult.getSensitivityValue(flowCnec, side, rangeAction, unit); } @Override - public double getSensitivityValue(FlowCnec flowCnec, Side side, SensitivityVariableSet linearGlsk, Unit unit) { + public double getSensitivityValue(FlowCnec flowCnec, TwoSides side, SensitivityVariableSet linearGlsk, Unit unit) { return sensitivityResult.getSensitivityValue(flowCnec, side, linearGlsk, unit); } @Override - public double getFlow(FlowCnec flowCnec, Side side, Unit unit) { + public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { return flowResult.getFlow(flowCnec, side, unit); } @@ -87,27 +87,27 @@ public double getRelativeMargin(FlowCnec flowCnec, Unit unit) { } @Override - public double getRelativeMargin(FlowCnec flowCnec, Side side, Unit unit) { + public double getRelativeMargin(FlowCnec flowCnec, TwoSides side, Unit unit) { return flowResult.getRelativeMargin(flowCnec, side, unit); } @Override - public double getLoopFlow(FlowCnec flowCnec, Side side, Unit unit) { + public double getLoopFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { return flowResult.getLoopFlow(flowCnec, side, unit); } @Override - public double getCommercialFlow(FlowCnec flowCnec, Side side, Unit unit) { + public double getCommercialFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { return flowResult.getCommercialFlow(flowCnec, side, unit); } @Override - public double getPtdfZonalSum(FlowCnec flowCnec, Side side) { + public double getPtdfZonalSum(FlowCnec flowCnec, TwoSides side) { return flowResult.getPtdfZonalSum(flowCnec, side); } @Override - public Map> getPtdfZonalSums() { + public Map> getPtdfZonalSums() { return flowResult.getPtdfZonalSums(); } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/PreventiveAndCurativesRaoResultImpl.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/PreventiveAndCurativesRaoResultImpl.java index c11e7a0a00..29413786e2 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/PreventiveAndCurativesRaoResultImpl.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/PreventiveAndCurativesRaoResultImpl.java @@ -13,7 +13,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.*; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; @@ -277,7 +277,7 @@ public double getRelativeMargin(Instant optimizedInstant, FlowCnec flowCnec, Uni } @Override - public double getFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit) { + public double getFlow(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side, Unit unit) { FlowResult flowResult = getFlowResult(optimizedInstant, flowCnec); if (Objects.nonNull(flowResult)) { return flowResult.getFlow(flowCnec, side, unit); @@ -287,7 +287,7 @@ public double getFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Un } @Override - public double getCommercialFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit) { + public double getCommercialFlow(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side, Unit unit) { FlowResult flowResult = getFlowResult(optimizedInstant, flowCnec); if (Objects.nonNull(flowResult)) { return flowResult.getCommercialFlow(flowCnec, side, unit); @@ -297,7 +297,7 @@ public double getCommercialFlow(Instant optimizedInstant, FlowCnec flowCnec, Sid } @Override - public double getLoopFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit) { + public double getLoopFlow(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side, Unit unit) { FlowResult flowResult = getFlowResult(optimizedInstant, flowCnec); if (Objects.nonNull(flowResult)) { return flowResult.getLoopFlow(flowCnec, side, unit); @@ -307,7 +307,7 @@ public double getLoopFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side } @Override - public double getPtdfZonalSum(Instant optimizedInstant, FlowCnec flowCnec, Side side) { + public double getPtdfZonalSum(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side) { FlowResult flowResult = getFlowResult(optimizedInstant, flowCnec); if (Objects.nonNull(flowResult)) { return flowResult.getPtdfZonalSum(flowCnec, side); diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/SensitivityResultImpl.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/SensitivityResultImpl.java index 48f85e8d6b..0f2bebf940 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/SensitivityResultImpl.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/SensitivityResultImpl.java @@ -11,7 +11,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; import com.powsybl.openrao.data.raoresultapi.ComputationStatus; import com.powsybl.openrao.searchtreerao.result.api.SensitivityResult; @@ -59,7 +59,7 @@ public Set getContingencies() { } @Override - public double getSensitivityValue(FlowCnec flowCnec, Side side, RangeAction rangeAction, Unit unit) { + public double getSensitivityValue(FlowCnec flowCnec, TwoSides side, RangeAction rangeAction, Unit unit) { if (unit == Unit.MEGAWATT) { return systematicSensitivityResult.getSensitivityOnFlow(rangeAction, flowCnec, side); } else { @@ -68,7 +68,7 @@ public double getSensitivityValue(FlowCnec flowCnec, Side side, RangeAction r } @Override - public double getSensitivityValue(FlowCnec flowCnec, Side side, SensitivityVariableSet linearGlsk, Unit unit) { + public double getSensitivityValue(FlowCnec flowCnec, TwoSides side, SensitivityVariableSet linearGlsk, Unit unit) { if (unit == Unit.MEGAWATT) { return systematicSensitivityResult.getSensitivityOnFlow(linearGlsk, flowCnec, side); } else { diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/SkippedOptimizationResultImpl.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/SkippedOptimizationResultImpl.java index 3c4836b325..b2a75c29b4 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/SkippedOptimizationResultImpl.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/SkippedOptimizationResultImpl.java @@ -12,7 +12,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.*; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; @@ -66,32 +66,32 @@ public Set getContingencies() { } @Override - public double getSensitivityValue(FlowCnec flowCnec, Side side, RangeAction rangeAction, Unit unit) { + public double getSensitivityValue(FlowCnec flowCnec, TwoSides side, RangeAction rangeAction, Unit unit) { throw new OpenRaoException(SHOULD_NOT_BE_USED); } @Override - public double getSensitivityValue(FlowCnec flowCnec, Side side, SensitivityVariableSet linearGlsk, Unit unit) { + public double getSensitivityValue(FlowCnec flowCnec, TwoSides side, SensitivityVariableSet linearGlsk, Unit unit) { throw new OpenRaoException(SHOULD_NOT_BE_USED); } @Override - public double getFlow(FlowCnec flowCnec, Side side, Unit unit) { + public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { throw new OpenRaoException(SHOULD_NOT_BE_USED); } @Override - public double getCommercialFlow(FlowCnec flowCnec, Side side, Unit unit) { + public double getCommercialFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { throw new OpenRaoException(SHOULD_NOT_BE_USED); } @Override - public double getPtdfZonalSum(FlowCnec flowCnec, Side side) { + public double getPtdfZonalSum(FlowCnec flowCnec, TwoSides side) { throw new OpenRaoException(SHOULD_NOT_BE_USED); } @Override - public Map> getPtdfZonalSums() { + public Map> getPtdfZonalSums() { throw new OpenRaoException(SHOULD_NOT_BE_USED); } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/UnoptimizedRaoResultImpl.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/UnoptimizedRaoResultImpl.java index 4d99e08d99..20ad0803ec 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/UnoptimizedRaoResultImpl.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/UnoptimizedRaoResultImpl.java @@ -13,7 +13,7 @@ import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; @@ -51,7 +51,7 @@ public ComputationStatus getComputationStatus(State state) { } @Override - public double getFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit) { + public double getFlow(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side, Unit unit) { return initialResult.getFlow(flowCnec, side, unit); } @@ -66,17 +66,17 @@ public double getRelativeMargin(Instant optimizedInstant, FlowCnec flowCnec, Uni } @Override - public double getCommercialFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit) { + public double getCommercialFlow(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side, Unit unit) { return initialResult.getCommercialFlow(flowCnec, side, unit); } @Override - public double getLoopFlow(Instant optimizedInstant, FlowCnec flowCnec, Side side, Unit unit) { + public double getLoopFlow(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side, Unit unit) { return initialResult.getLoopFlow(flowCnec, side, unit); } @Override - public double getPtdfZonalSum(Instant optimizedInstant, FlowCnec flowCnec, Side side) { + public double getPtdfZonalSum(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side) { return initialResult.getPtdfZonalSum(flowCnec, side); } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/Leaf.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/Leaf.java index 69d560e308..770002687a 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/Leaf.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/Leaf.java @@ -12,7 +12,7 @@ import com.powsybl.openrao.data.cracapi.RemedialAction; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; @@ -330,7 +330,7 @@ long getNumberOfActivatedRangeActions() { } @Override - public double getFlow(FlowCnec flowCnec, Side side, Unit unit) { + public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { if (status == Status.EVALUATED) { return preOptimFlowResult.getFlow(flowCnec, side, unit); } else if (status == Status.OPTIMIZED) { @@ -341,7 +341,7 @@ public double getFlow(FlowCnec flowCnec, Side side, Unit unit) { } @Override - public double getCommercialFlow(FlowCnec flowCnec, Side side, Unit unit) { + public double getCommercialFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { if (status == Status.EVALUATED) { return preOptimFlowResult.getCommercialFlow(flowCnec, side, unit); } else if (status == Status.OPTIMIZED) { @@ -352,7 +352,7 @@ public double getCommercialFlow(FlowCnec flowCnec, Side side, Unit unit) { } @Override - public double getPtdfZonalSum(FlowCnec flowCnec, Side side) { + public double getPtdfZonalSum(FlowCnec flowCnec, TwoSides side) { if (status == Status.EVALUATED) { return preOptimFlowResult.getPtdfZonalSum(flowCnec, side); } else if (status == Status.OPTIMIZED) { @@ -363,7 +363,7 @@ public double getPtdfZonalSum(FlowCnec flowCnec, Side side) { } @Override - public Map> getPtdfZonalSums() { + public Map> getPtdfZonalSums() { if (status == Status.EVALUATED) { return preOptimFlowResult.getPtdfZonalSums(); } else if (status == Status.OPTIMIZED) { @@ -574,7 +574,7 @@ public Set getContingencies() { } @Override - public double getSensitivityValue(FlowCnec flowCnec, Side side, RangeAction rangeAction, Unit unit) { + public double getSensitivityValue(FlowCnec flowCnec, TwoSides side, RangeAction rangeAction, Unit unit) { if (status == Status.EVALUATED || status == Status.OPTIMIZED && !postOptimResult.getRangeActions().contains(rangeAction)) { return preOptimSensitivityResult.getSensitivityValue(flowCnec, side, rangeAction, unit); @@ -586,7 +586,7 @@ public double getSensitivityValue(FlowCnec flowCnec, Side side, RangeAction r } @Override - public double getSensitivityValue(FlowCnec flowCnec, Side side, SensitivityVariableSet linearGlsk, Unit unit) { + public double getSensitivityValue(FlowCnec flowCnec, TwoSides side, SensitivityVariableSet linearGlsk, Unit unit) { if (status == Status.EVALUATED) { return preOptimSensitivityResult.getSensitivityValue(flowCnec, side, linearGlsk, unit); } else if (status == Status.OPTIMIZED) { diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/SearchTree.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/SearchTree.java index fa8794f355..70454e842d 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/SearchTree.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/SearchTree.java @@ -11,7 +11,7 @@ import com.powsybl.openrao.commons.logs.OpenRaoLogger; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.searchtreerao.commons.NetworkActionCombination; import com.powsybl.openrao.searchtreerao.commons.RaoLogger; @@ -511,7 +511,7 @@ List getVirtualCostlyElementsLogs(Leaf leaf, String virtualCostName, Str List logs = new ArrayList<>(); int i = 1; for (FlowCnec flowCnec : leaf.getCostlyElements(virtualCostName, NUMBER_LOGGED_VIRTUAL_COSTLY_ELEMENTS)) { - Side limitingSide = leaf.getMargin(flowCnec, Side.LEFT, unit) < leaf.getMargin(flowCnec, Side.RIGHT, unit) ? Side.LEFT : Side.RIGHT; + TwoSides limitingSide = leaf.getMargin(flowCnec, TwoSides.ONE, unit) < leaf.getMargin(flowCnec, TwoSides.TWO, unit) ? TwoSides.ONE : TwoSides.TWO; double flow = leaf.getFlow(flowCnec, limitingSide, unit); Double limitingThreshold = flow >= 0 ? flowCnec.getUpperBound(limitingSide, unit).orElse(flowCnec.getLowerBound(limitingSide, unit).orElse(Double.NaN)) : flowCnec.getLowerBound(limitingSide, unit).orElse(flowCnec.getUpperBound(limitingSide, unit).orElse(Double.NaN)); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/AutomatonSimulatorTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/AutomatonSimulatorTest.java index 9b7835bdea..4a6403424c 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/AutomatonSimulatorTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/AutomatonSimulatorTest.java @@ -13,7 +13,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.*; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.ActionType; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.HvdcRangeAction; @@ -106,7 +106,7 @@ public void setup() { .withNetworkElement("cnec-ne") .withInstant(PREVENTIVE_INSTANT_ID) .withNominalVoltage(220.) - .newThreshold().withSide(Side.RIGHT).withMax(1000.).withUnit(Unit.AMPERE).add() + .newThreshold().withSide(TwoSides.TWO).withMax(1000.).withUnit(Unit.AMPERE).add() .add(); cnec1 = crac.newFlowCnec() .withId("cnec1") @@ -114,7 +114,7 @@ public void setup() { .withContingency("contingency1") .withInstant(AUTO_INSTANT_ID) .withNominalVoltage(220.) - .newThreshold().withSide(Side.RIGHT).withMax(1000.).withUnit(Unit.AMPERE).add() + .newThreshold().withSide(TwoSides.TWO).withMax(1000.).withUnit(Unit.AMPERE).add() .add(); cnec2 = crac.newFlowCnec() .withId("cnec2") @@ -122,7 +122,7 @@ public void setup() { .withContingency("contingency1") .withInstant(AUTO_INSTANT_ID) .withNominalVoltage(220.) - .newThreshold().withSide(Side.RIGHT).withMax(1000.).withUnit(Unit.AMPERE).add() + .newThreshold().withSide(TwoSides.TWO).withMax(1000.).withUnit(Unit.AMPERE).add() .add(); Instant autoInstant = crac.getInstant(AUTO_INSTANT_ID); autoState = crac.getState(contingency1, autoInstant); @@ -438,20 +438,20 @@ void testComputeOptimalSetpoint() { @Test void testShiftRangeActionsUntilFlowCnecsSecureCase1() { FlowCnec cnec = mock(FlowCnec.class); - when(cnec.getMonitoredSides()).thenReturn(Set.of(Side.RIGHT)); + when(cnec.getMonitoredSides()).thenReturn(Set.of(TwoSides.TWO)); when(mockedPreAutoPerimeterSensitivityAnalysis.runBasedOnInitialResults(any(), any(), any(), any(), any(), any())).thenReturn(mockedPrePerimeterResult); // suppose threshold is -1000, flow is -1100 then -1010 then -1000 // getFlow is called once in every iteration - when(mockedPrePerimeterResult.getFlow(cnec, Side.RIGHT, Unit.MEGAWATT)).thenReturn(-1100., -1010., -1000.); + when(mockedPrePerimeterResult.getFlow(cnec, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(-1100., -1010., -1000.); // getMargin is called once before loop, once in 1st iteration, once in second iteration when(mockedPrePerimeterResult.getMargin(cnec, Unit.MEGAWATT)).thenReturn(-100., -10., 0.); // getMargin with side is called once before loop, once in 1st iteration, once in second iteration - when(mockedPrePerimeterResult.getMargin(cnec, Side.RIGHT, Unit.MEGAWATT)).thenReturn(-100., -100., -10., -10., 0.); + when(mockedPrePerimeterResult.getMargin(cnec, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(-100., -100., -10., -10., 0.); // suppose approx sensi is +50 on both RAs first, then +5 (so +100 then +10 total) - when(mockedPrePerimeterResult.getSensitivityValue(cnec, Side.RIGHT, ara1, Unit.MEGAWATT)).thenReturn(50., 5.); - when(mockedPrePerimeterResult.getSensitivityValue(cnec, Side.RIGHT, ara2, Unit.MEGAWATT)).thenReturn(50., 5.); + when(mockedPrePerimeterResult.getSensitivityValue(cnec, TwoSides.TWO, ara1, Unit.MEGAWATT)).thenReturn(50., 5.); + when(mockedPrePerimeterResult.getSensitivityValue(cnec, TwoSides.TWO, ara2, Unit.MEGAWATT)).thenReturn(50., 5.); // so PSTs should be shifted to setpoint +1.1 on first iteration, then +3.1 on second because of under-estimator AutomatonSimulator.RangeAutomatonSimulationResult shiftResult = @@ -463,23 +463,23 @@ void testShiftRangeActionsUntilFlowCnecsSecureCase1() { @Test void testShiftRangeActionsUntilFlowCnecsSecureCase2() { FlowCnec cnec = mock(FlowCnec.class); - when(cnec.getMonitoredSides()).thenReturn(Set.of(Side.LEFT, Side.RIGHT)); + when(cnec.getMonitoredSides()).thenReturn(Set.of(TwoSides.ONE, TwoSides.TWO)); when(mockedPreAutoPerimeterSensitivityAnalysis.runBasedOnInitialResults(any(), any(), any(), any(), any(), any())).thenReturn(mockedPrePerimeterResult); // same as case 1 but flows & sensi are inverted -> setpoints should be the same // getFlow is called once in every iteration - when(mockedPrePerimeterResult.getFlow(cnec, Side.LEFT, Unit.MEGAWATT)).thenReturn(1100., 1010., 1000.); - when(mockedPrePerimeterResult.getFlow(cnec, Side.RIGHT, Unit.MEGAWATT)).thenReturn(0., 0., 0.); + when(mockedPrePerimeterResult.getFlow(cnec, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(1100., 1010., 1000.); + when(mockedPrePerimeterResult.getFlow(cnec, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(0., 0., 0.); // getMargin is called once before loop, once in 1st iteration, once in second iteration when(mockedPrePerimeterResult.getMargin(cnec, Unit.MEGAWATT)).thenReturn(-100., -10., 0.); // getMargin with side is called once before loop, once in 1st iteration, once in second iteration - when(mockedPrePerimeterResult.getMargin(cnec, Side.LEFT, Unit.MEGAWATT)).thenReturn(-100., -100., -10., -10., 0.); - when(mockedPrePerimeterResult.getMargin(cnec, Side.RIGHT, Unit.MEGAWATT)).thenReturn(100.); - when(mockedPrePerimeterResult.getSensitivityValue(cnec, Side.LEFT, ara1, Unit.MEGAWATT)).thenReturn(-50., -5.); - when(mockedPrePerimeterResult.getSensitivityValue(cnec, Side.LEFT, ara2, Unit.MEGAWATT)).thenReturn(-50., -5.); - when(mockedPrePerimeterResult.getSensitivityValue(cnec, Side.RIGHT, ara1, Unit.MEGAWATT)).thenReturn(-50., -5.); - when(mockedPrePerimeterResult.getSensitivityValue(cnec, Side.RIGHT, ara2, Unit.MEGAWATT)).thenReturn(-50., -5.); + when(mockedPrePerimeterResult.getMargin(cnec, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(-100., -100., -10., -10., 0.); + when(mockedPrePerimeterResult.getMargin(cnec, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(100.); + when(mockedPrePerimeterResult.getSensitivityValue(cnec, TwoSides.ONE, ara1, Unit.MEGAWATT)).thenReturn(-50., -5.); + when(mockedPrePerimeterResult.getSensitivityValue(cnec, TwoSides.ONE, ara2, Unit.MEGAWATT)).thenReturn(-50., -5.); + when(mockedPrePerimeterResult.getSensitivityValue(cnec, TwoSides.TWO, ara1, Unit.MEGAWATT)).thenReturn(-50., -5.); + when(mockedPrePerimeterResult.getSensitivityValue(cnec, TwoSides.TWO, ara2, Unit.MEGAWATT)).thenReturn(-50., -5.); AutomatonSimulator.RangeAutomatonSimulationResult shiftResult = automatonSimulator.shiftRangeActionsUntilFlowCnecsSecure(List.of(ara1, ara2), Set.of(cnec), network, mockedPreAutoPerimeterSensitivityAnalysis, mockedPrePerimeterResult, autoState); @@ -490,19 +490,19 @@ void testShiftRangeActionsUntilFlowCnecsSecureCase2() { @Test void testShiftRangeActionsUntilFlowCnecsSecureCase3() { FlowCnec cnec = mock(FlowCnec.class); - when(cnec.getMonitoredSides()).thenReturn(Set.of(Side.LEFT)); + when(cnec.getMonitoredSides()).thenReturn(Set.of(TwoSides.ONE)); when(mockedPreAutoPerimeterSensitivityAnalysis.runBasedOnInitialResults(any(), any(), any(), any(), any(), any())).thenReturn(mockedPrePerimeterResult); // same as case 1 but flows are inverted -> setpoints should be inverted // getFlow is called once in every iteration - when(mockedPrePerimeterResult.getFlow(cnec, Side.LEFT, Unit.MEGAWATT)).thenReturn(1100., 1010., 1000.); + when(mockedPrePerimeterResult.getFlow(cnec, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(1100., 1010., 1000.); // getMargin is called once before loop, once in second iteration when(mockedPrePerimeterResult.getMargin(cnec, Unit.MEGAWATT)).thenReturn(-100., -10., 0.); // getMargin with side is called once before loop, once in 1st iteration, once in second iteration - when(mockedPrePerimeterResult.getMargin(cnec, Side.LEFT, Unit.MEGAWATT)).thenReturn(-100., -100., -10., -10., 0.); - when(mockedPrePerimeterResult.getSensitivityValue(cnec, Side.LEFT, ara1, Unit.MEGAWATT)).thenReturn(50., 5.); - when(mockedPrePerimeterResult.getSensitivityValue(cnec, Side.LEFT, ara2, Unit.MEGAWATT)).thenReturn(50., 5.); + when(mockedPrePerimeterResult.getMargin(cnec, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(-100., -100., -10., -10., 0.); + when(mockedPrePerimeterResult.getSensitivityValue(cnec, TwoSides.ONE, ara1, Unit.MEGAWATT)).thenReturn(50., 5.); + when(mockedPrePerimeterResult.getSensitivityValue(cnec, TwoSides.ONE, ara2, Unit.MEGAWATT)).thenReturn(50., 5.); AutomatonSimulator.RangeAutomatonSimulationResult shiftResult = automatonSimulator.shiftRangeActionsUntilFlowCnecsSecure(List.of(ara1, ara2), Set.of(cnec), network, mockedPreAutoPerimeterSensitivityAnalysis, mockedPrePerimeterResult, autoState); @@ -513,29 +513,29 @@ void testShiftRangeActionsUntilFlowCnecsSecureCase3() { @Test void testShiftRangeActionsUntilFlowCnecsSecureCase4() { FlowCnec cnec = mock(FlowCnec.class); - when(cnec.getMonitoredSides()).thenReturn(Set.of(Side.RIGHT)); + when(cnec.getMonitoredSides()).thenReturn(Set.of(TwoSides.TWO)); when(mockedPreAutoPerimeterSensitivityAnalysis.runBasedOnInitialResults(any(), any(), any(), any(), any(), any())).thenReturn(mockedPrePerimeterResult); // same as case 1 but sensi are inverted -> setpoints should be inverted // + added a cnec with sensi = 0 // getFlow is called once in every iteration - when(mockedPrePerimeterResult.getFlow(cnec, Side.RIGHT, Unit.MEGAWATT)).thenReturn(-1100., -1010., -1000.); + when(mockedPrePerimeterResult.getFlow(cnec, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(-1100., -1010., -1000.); // getMargin is called once before loop, once in 1st iteration when most limiting cnec is different, once in second iteration, once in third iteration when(mockedPrePerimeterResult.getMargin(cnec, Unit.MEGAWATT)).thenReturn(-100., -100., -100., -10., 0.); // getMargin with side is called once before loop, once in 1st iteration when most limiting cnec is different, once in second iteration, once in third iteration - when(mockedPrePerimeterResult.getMargin(cnec, Side.RIGHT, Unit.MEGAWATT)).thenReturn(-100., -100., -100., -100., -10., -10., 0.); + when(mockedPrePerimeterResult.getMargin(cnec, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(-100., -100., -100., -100., -10., -10., 0.); // computeMargin is called once in 1st iteration, once in second iteration, once in third iteration - when(mockedPrePerimeterResult.getSensitivityValue(cnec, Side.RIGHT, ara1, Unit.MEGAWATT)).thenReturn(-50., -5.); - when(mockedPrePerimeterResult.getSensitivityValue(cnec, Side.RIGHT, ara2, Unit.MEGAWATT)).thenReturn(-50., -5.); + when(mockedPrePerimeterResult.getSensitivityValue(cnec, TwoSides.TWO, ara1, Unit.MEGAWATT)).thenReturn(-50., -5.); + when(mockedPrePerimeterResult.getSensitivityValue(cnec, TwoSides.TWO, ara2, Unit.MEGAWATT)).thenReturn(-50., -5.); FlowCnec cnec2 = mock(FlowCnec.class); - when(cnec2.getMonitoredSides()).thenReturn(Set.of(Side.RIGHT)); - when(mockedPrePerimeterResult.getFlow(cnec2, Side.RIGHT, Unit.MEGAWATT)).thenReturn(2200.); + when(cnec2.getMonitoredSides()).thenReturn(Set.of(TwoSides.TWO)); + when(mockedPrePerimeterResult.getFlow(cnec2, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(2200.); when(mockedPrePerimeterResult.getMargin(cnec2, Unit.MEGAWATT)).thenReturn(-200.); - when(mockedPrePerimeterResult.getMargin(cnec2, Side.RIGHT, Unit.MEGAWATT)).thenReturn(-200.); - when(mockedPrePerimeterResult.getSensitivityValue(cnec2, Side.RIGHT, ara1, Unit.MEGAWATT)).thenReturn(0.); - when(mockedPrePerimeterResult.getSensitivityValue(cnec2, Side.RIGHT, ara2, Unit.MEGAWATT)).thenReturn(0.); + when(mockedPrePerimeterResult.getMargin(cnec2, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(-200.); + when(mockedPrePerimeterResult.getSensitivityValue(cnec2, TwoSides.TWO, ara1, Unit.MEGAWATT)).thenReturn(0.); + when(mockedPrePerimeterResult.getSensitivityValue(cnec2, TwoSides.TWO, ara2, Unit.MEGAWATT)).thenReturn(0.); AutomatonSimulator.RangeAutomatonSimulationResult shiftResult = automatonSimulator.shiftRangeActionsUntilFlowCnecsSecure(List.of(ara1, ara2), Set.of(cnec, cnec2), network, mockedPreAutoPerimeterSensitivityAnalysis, mockedPrePerimeterResult, autoState); @@ -556,10 +556,10 @@ void testSimulateRangeAutomatons() { toRemove.remove("ara2"); toRemove.forEach(ra -> crac.removeRemedialAction(ra)); - when(mockedPrePerimeterResult.getFlow(cnec1, Side.RIGHT, Unit.MEGAWATT)).thenReturn(1100.); + when(mockedPrePerimeterResult.getFlow(cnec1, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(1100.); when(mockedPrePerimeterResult.getMargin(cnec1, Unit.MEGAWATT)).thenReturn(-100.); - when(mockedPrePerimeterResult.getSensitivityValue(cnec1, Side.RIGHT, ara1, Unit.MEGAWATT)).thenReturn(0.); - when(mockedPrePerimeterResult.getSensitivityValue(cnec1, Side.RIGHT, ara2, Unit.MEGAWATT)).thenReturn(0.); + when(mockedPrePerimeterResult.getSensitivityValue(cnec1, TwoSides.TWO, ara1, Unit.MEGAWATT)).thenReturn(0.); + when(mockedPrePerimeterResult.getSensitivityValue(cnec1, TwoSides.TWO, ara2, Unit.MEGAWATT)).thenReturn(0.); AutomatonSimulator.RangeAutomatonSimulationResult result = automatonSimulator.simulateRangeAutomatons(autoState, Set.of(curativeState), network, mockedPreAutoPerimeterSensitivityAnalysis, mockedPrePerimeterResult); @@ -635,10 +635,10 @@ void testSimulateAutomatonState() { toRemove.forEach(ra -> crac.removeRemedialAction(ra)); when(mockedPrePerimeterResult.getMargin(cnec2, Unit.MEGAWATT)).thenReturn(100.); - when(mockedPrePerimeterResult.getFlow(cnec1, Side.RIGHT, Unit.MEGAWATT)).thenReturn(1100.); + when(mockedPrePerimeterResult.getFlow(cnec1, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(1100.); when(mockedPrePerimeterResult.getMargin(cnec1, Unit.MEGAWATT)).thenReturn(-100.); - when(mockedPrePerimeterResult.getSensitivityValue(cnec1, Side.RIGHT, ara1, Unit.MEGAWATT)).thenReturn(0.); - when(mockedPrePerimeterResult.getSensitivityValue(cnec1, Side.RIGHT, ara2, Unit.MEGAWATT)).thenReturn(0.); + when(mockedPrePerimeterResult.getSensitivityValue(cnec1, TwoSides.TWO, ara1, Unit.MEGAWATT)).thenReturn(0.); + when(mockedPrePerimeterResult.getSensitivityValue(cnec1, TwoSides.TWO, ara2, Unit.MEGAWATT)).thenReturn(0.); ObjectiveFunction objectiveFunction = Mockito.mock(ObjectiveFunction.class); when(mockedPrePerimeterResult.getObjectiveFunction()).thenReturn(objectiveFunction); @@ -677,15 +677,15 @@ void testDisableHvdcAngleDroopControlBeforeShifting() { when(mockedPreAutoPerimeterSensitivityAnalysis.runBasedOnInitialResults(any(), any(), any(), any(), any(), any())).thenReturn(mockedPrePerimeterResult); // check that angle-droop control was not disabled when margins are positive - when(prePerimeterResult.getMargin(cnec1, Side.RIGHT, Unit.MEGAWATT)).thenReturn(0.); - when(prePerimeterResult.getMargin(cnec2, Side.RIGHT, Unit.MEGAWATT)).thenReturn(100.); + when(prePerimeterResult.getMargin(cnec1, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(0.); + when(prePerimeterResult.getMargin(cnec2, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(100.); automatonSimulator.shiftRangeActionsUntilFlowCnecsSecure(List.of(hvdcRa1, hvdcRa2), Set.of(cnec1, cnec2), network, mockedPreAutoPerimeterSensitivityAnalysis, prePerimeterResult, autoState); assertTrue(network.getHvdcLine("BBE2AA11 FFR3AA11 1").getExtension(HvdcAngleDroopActivePowerControl.class).isEnabled()); assertTrue(network.getHvdcLine("BBE2AA12 FFR3AA12 1").getExtension(HvdcAngleDroopActivePowerControl.class).isEnabled()); // check that angle-droop control is disabled when one margin is negative - when(prePerimeterResult.getMargin(cnec1, Side.RIGHT, Unit.MEGAWATT)).thenReturn(-1.); - when(prePerimeterResult.getMargin(cnec2, Side.RIGHT, Unit.MEGAWATT)).thenReturn(100.); + when(prePerimeterResult.getMargin(cnec1, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(-1.); + when(prePerimeterResult.getMargin(cnec2, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(100.); automatonSimulator.shiftRangeActionsUntilFlowCnecsSecure(List.of(hvdcRa1, hvdcRa2), Set.of(cnec1, cnec2), network, mockedPreAutoPerimeterSensitivityAnalysis, prePerimeterResult, autoState); assertFalse(network.getHvdcLine("BBE2AA11 FFR3AA11 1").getExtension(HvdcAngleDroopActivePowerControl.class).isEnabled()); assertFalse(network.getHvdcLine("BBE2AA12 FFR3AA12 1").getExtension(HvdcAngleDroopActivePowerControl.class).isEnabled()); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/CastorFullOptimizationTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/CastorFullOptimizationTest.java index bdb34e286d..3975f31be3 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/CastorFullOptimizationTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/CastorFullOptimizationTest.java @@ -18,7 +18,7 @@ import com.powsybl.openrao.commons.logs.RaoBusinessLogs; import com.powsybl.openrao.data.cracapi.*; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.ActionType; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.range.RangeType; @@ -253,7 +253,7 @@ private void setUpCracWithRAs() { .withContingency("contingency1") .withInstant(CURATIVE_INSTANT_ID) .withNominalVoltage(220.) - .newThreshold().withSide(Side.RIGHT).withMax(1000.).withUnit(Unit.AMPERE).add() + .newThreshold().withSide(TwoSides.TWO).withMax(1000.).withUnit(Unit.AMPERE).add() .add(); // ra1 : preventive only ra1 = crac.newPstRangeAction() @@ -696,16 +696,16 @@ void testThreeCurativeInstantsWithSecondCurativeHavingNoCnecAndNoRa() { Contingency co = crac.newContingency().withId("co1").withContingencyElement("FFR2AA1 FFR3AA1 1", ContingencyElementType.LINE).add(); crac.newFlowCnec().withId("c1-prev").withInstant("preventive").withNetworkElement("FFR1AA1 FFR4AA1 1").withNominalVoltage(400.) - .newThreshold().withSide(Side.LEFT).withMax(2000.).withUnit(Unit.AMPERE).add() + .newThreshold().withSide(TwoSides.ONE).withMax(2000.).withUnit(Unit.AMPERE).add() .withOptimized().add(); crac.newFlowCnec().withId("c1-out").withInstant("auto").withContingency("co1").withNetworkElement("FFR1AA1 FFR4AA1 1").withNominalVoltage(400.) - .newThreshold().withSide(Side.LEFT).withMax(2500.).withUnit(Unit.AMPERE).add() + .newThreshold().withSide(TwoSides.ONE).withMax(2500.).withUnit(Unit.AMPERE).add() .withOptimized().add(); crac.newFlowCnec().withId("c1-cur1").withInstant("curative1").withContingency("co1").withNetworkElement("FFR1AA1 FFR4AA1 1").withNominalVoltage(400.) - .newThreshold().withSide(Side.LEFT).withMax(2400.).withUnit(Unit.AMPERE).add() + .newThreshold().withSide(TwoSides.ONE).withMax(2400.).withUnit(Unit.AMPERE).add() .withOptimized().add(); crac.newFlowCnec().withId("c1-cur3").withInstant("curative3").withContingency("co1").withNetworkElement("FFR1AA1 FFR4AA1 1").withNominalVoltage(400.) - .newThreshold().withSide(Side.LEFT).withMax(1700.).withUnit(Unit.AMPERE).add() + .newThreshold().withSide(TwoSides.ONE).withMax(1700.).withUnit(Unit.AMPERE).add() .withOptimized().add(); NetworkAction pstPrev = crac.newNetworkAction().withId("pst_fr@10-prev") @@ -733,30 +733,30 @@ void testThreeCurativeInstantsWithSecondCurativeHavingNoCnecAndNoRa() { FlowCnec cnec; cnec = crac.getFlowCnec("c1-prev"); - assertEquals(2228.9, raoResult.getFlow(null, cnec, Side.LEFT, Unit.AMPERE), 1.); - assertEquals(1979.7, raoResult.getFlow(crac.getInstant(InstantKind.PREVENTIVE), cnec, Side.LEFT, Unit.AMPERE), 1.); + assertEquals(2228.9, raoResult.getFlow(null, cnec, TwoSides.ONE, Unit.AMPERE), 1.); + assertEquals(1979.7, raoResult.getFlow(crac.getInstant(InstantKind.PREVENTIVE), cnec, TwoSides.ONE, Unit.AMPERE), 1.); assertEquals(-228.9, raoResult.getMargin(null, cnec, Unit.AMPERE), 1.); assertEquals(20.3, raoResult.getMargin(crac.getInstant(InstantKind.PREVENTIVE), cnec, Unit.AMPERE), 1.); cnec = crac.getFlowCnec("c1-out"); - assertEquals(2371.88, raoResult.getFlow(null, cnec, Side.LEFT, Unit.AMPERE), 1.); - assertEquals(2129.22, raoResult.getFlow(crac.getInstant(InstantKind.PREVENTIVE), cnec, Side.LEFT, Unit.AMPERE), 1.); + assertEquals(2371.88, raoResult.getFlow(null, cnec, TwoSides.ONE, Unit.AMPERE), 1.); + assertEquals(2129.22, raoResult.getFlow(crac.getInstant(InstantKind.PREVENTIVE), cnec, TwoSides.ONE, Unit.AMPERE), 1.); assertEquals(128.12, raoResult.getMargin(null, cnec, Unit.AMPERE), 1.); assertEquals(370.78, raoResult.getMargin(crac.getInstant(InstantKind.PREVENTIVE), cnec, Unit.AMPERE), 1.); cnec = crac.getFlowCnec("c1-cur1"); - assertEquals(2371.88, raoResult.getFlow(null, cnec, Side.LEFT, Unit.AMPERE), 1.); - assertEquals(2129.22, raoResult.getFlow(crac.getInstant(InstantKind.PREVENTIVE), cnec, Side.LEFT, Unit.AMPERE), 1.); - assertEquals(1549.18, raoResult.getFlow(crac.getInstant("curative1"), cnec, Side.LEFT, Unit.AMPERE), 1.); + assertEquals(2371.88, raoResult.getFlow(null, cnec, TwoSides.ONE, Unit.AMPERE), 1.); + assertEquals(2129.22, raoResult.getFlow(crac.getInstant(InstantKind.PREVENTIVE), cnec, TwoSides.ONE, Unit.AMPERE), 1.); + assertEquals(1549.18, raoResult.getFlow(crac.getInstant("curative1"), cnec, TwoSides.ONE, Unit.AMPERE), 1.); assertEquals(28.12, raoResult.getMargin(null, cnec, Unit.AMPERE), 1.); assertEquals(270.78, raoResult.getMargin(crac.getInstant(InstantKind.PREVENTIVE), cnec, Unit.AMPERE), 1.); assertEquals(850.82, raoResult.getMargin(crac.getInstant("curative1"), cnec, Unit.AMPERE), 1.); cnec = crac.getFlowCnec("c1-cur3"); - assertEquals(2371.88, raoResult.getFlow(null, cnec, Side.LEFT, Unit.AMPERE), 1.); - assertEquals(2129.22, raoResult.getFlow(crac.getInstant(InstantKind.PREVENTIVE), cnec, Side.LEFT, Unit.AMPERE), 1.); - assertEquals(1549.18, raoResult.getFlow(crac.getInstant("curative1"), cnec, Side.LEFT, Unit.AMPERE), 1.); - assertEquals(432.73, raoResult.getFlow(crac.getInstant("curative3"), cnec, Side.LEFT, Unit.AMPERE), 1.); + assertEquals(2371.88, raoResult.getFlow(null, cnec, TwoSides.ONE, Unit.AMPERE), 1.); + assertEquals(2129.22, raoResult.getFlow(crac.getInstant(InstantKind.PREVENTIVE), cnec, TwoSides.ONE, Unit.AMPERE), 1.); + assertEquals(1549.18, raoResult.getFlow(crac.getInstant("curative1"), cnec, TwoSides.ONE, Unit.AMPERE), 1.); + assertEquals(432.73, raoResult.getFlow(crac.getInstant("curative3"), cnec, TwoSides.ONE, Unit.AMPERE), 1.); assertEquals(-671.88, raoResult.getMargin(null, cnec, Unit.AMPERE), 1.); assertEquals(-429.22, raoResult.getMargin(crac.getInstant(InstantKind.PREVENTIVE), cnec, Unit.AMPERE), 1.); assertEquals(150.82, raoResult.getMargin(crac.getInstant("curative1"), cnec, Unit.AMPERE), 1.); @@ -783,19 +783,19 @@ void testThreeCurativeInstants() { Contingency co = crac.newContingency().withId("co1").withContingencyElement("FFR2AA1 FFR3AA1 1", ContingencyElementType.LINE).add(); crac.newFlowCnec().withId("c1-prev").withInstant("preventive").withNetworkElement("FFR1AA1 FFR4AA1 1").withNominalVoltage(400.) - .newThreshold().withSide(Side.LEFT).withMax(2000.).withUnit(Unit.AMPERE).add() + .newThreshold().withSide(TwoSides.ONE).withMax(2000.).withUnit(Unit.AMPERE).add() .withOptimized().add(); crac.newFlowCnec().withId("c1-out").withInstant("auto").withContingency("co1").withNetworkElement("FFR1AA1 FFR4AA1 1").withNominalVoltage(400.) - .newThreshold().withSide(Side.LEFT).withMax(2500.).withUnit(Unit.AMPERE).add() + .newThreshold().withSide(TwoSides.ONE).withMax(2500.).withUnit(Unit.AMPERE).add() .withOptimized().add(); crac.newFlowCnec().withId("c1-cur1").withInstant("curative1").withContingency("co1").withNetworkElement("FFR1AA1 FFR4AA1 1").withNominalVoltage(400.) - .newThreshold().withSide(Side.LEFT).withMax(2400.).withUnit(Unit.AMPERE).add() + .newThreshold().withSide(TwoSides.ONE).withMax(2400.).withUnit(Unit.AMPERE).add() .withOptimized().add(); crac.newFlowCnec().withId("c1-cur2").withInstant("curative2").withContingency("co1").withNetworkElement("FFR1AA1 FFR4AA1 1").withNominalVoltage(400.) - .newThreshold().withSide(Side.LEFT).withMax(2300.).withUnit(Unit.AMPERE).add() + .newThreshold().withSide(TwoSides.ONE).withMax(2300.).withUnit(Unit.AMPERE).add() .withOptimized().add(); crac.newFlowCnec().withId("c1-cur3").withInstant("curative3").withContingency("co1").withNetworkElement("FFR1AA1 FFR4AA1 1").withNominalVoltage(400.) - .newThreshold().withSide(Side.LEFT).withMax(1700.).withUnit(Unit.AMPERE).add() + .newThreshold().withSide(TwoSides.ONE).withMax(1700.).withUnit(Unit.AMPERE).add() .withOptimized().add(); NetworkAction pstPrev = crac.newNetworkAction().withId("pst_fr@10-prev") @@ -828,41 +828,41 @@ void testThreeCurativeInstants() { FlowCnec cnec; cnec = crac.getFlowCnec("c1-prev"); - assertEquals(2228.9, raoResult.getFlow(null, cnec, Side.LEFT, Unit.AMPERE), 1.); - assertEquals(1979.7, raoResult.getFlow(crac.getInstant(InstantKind.PREVENTIVE), cnec, Side.LEFT, Unit.AMPERE), 1.); + assertEquals(2228.9, raoResult.getFlow(null, cnec, TwoSides.ONE, Unit.AMPERE), 1.); + assertEquals(1979.7, raoResult.getFlow(crac.getInstant(InstantKind.PREVENTIVE), cnec, TwoSides.ONE, Unit.AMPERE), 1.); assertEquals(-228.9, raoResult.getMargin(null, cnec, Unit.AMPERE), 1.); assertEquals(20.3, raoResult.getMargin(crac.getInstant(InstantKind.PREVENTIVE), cnec, Unit.AMPERE), 1.); cnec = crac.getFlowCnec("c1-out"); - assertEquals(2371.88, raoResult.getFlow(null, cnec, Side.LEFT, Unit.AMPERE), 1.); - assertEquals(2129.22, raoResult.getFlow(crac.getInstant(InstantKind.PREVENTIVE), cnec, Side.LEFT, Unit.AMPERE), 1.); + assertEquals(2371.88, raoResult.getFlow(null, cnec, TwoSides.ONE, Unit.AMPERE), 1.); + assertEquals(2129.22, raoResult.getFlow(crac.getInstant(InstantKind.PREVENTIVE), cnec, TwoSides.ONE, Unit.AMPERE), 1.); assertEquals(128.12, raoResult.getMargin(null, cnec, Unit.AMPERE), 1.); assertEquals(370.78, raoResult.getMargin(crac.getInstant(InstantKind.PREVENTIVE), cnec, Unit.AMPERE), 1.); cnec = crac.getFlowCnec("c1-cur1"); - assertEquals(2371.88, raoResult.getFlow(null, cnec, Side.LEFT, Unit.AMPERE), 1.); - assertEquals(2129.22, raoResult.getFlow(crac.getInstant(InstantKind.PREVENTIVE), cnec, Side.LEFT, Unit.AMPERE), 1.); - assertEquals(1549.18, raoResult.getFlow(crac.getInstant("curative1"), cnec, Side.LEFT, Unit.AMPERE), 1.); + assertEquals(2371.88, raoResult.getFlow(null, cnec, TwoSides.ONE, Unit.AMPERE), 1.); + assertEquals(2129.22, raoResult.getFlow(crac.getInstant(InstantKind.PREVENTIVE), cnec, TwoSides.ONE, Unit.AMPERE), 1.); + assertEquals(1549.18, raoResult.getFlow(crac.getInstant("curative1"), cnec, TwoSides.ONE, Unit.AMPERE), 1.); assertEquals(28.12, raoResult.getMargin(null, cnec, Unit.AMPERE), 1.); assertEquals(270.78, raoResult.getMargin(crac.getInstant(InstantKind.PREVENTIVE), cnec, Unit.AMPERE), 1.); assertEquals(850.82, raoResult.getMargin(crac.getInstant("curative1"), cnec, Unit.AMPERE), 1.); cnec = crac.getFlowCnec("c1-cur2"); - assertEquals(2371.88, raoResult.getFlow(null, cnec, Side.LEFT, Unit.AMPERE), 1.); - assertEquals(2129.22, raoResult.getFlow(crac.getInstant(InstantKind.PREVENTIVE), cnec, Side.LEFT, Unit.AMPERE), 1.); - assertEquals(1549.18, raoResult.getFlow(crac.getInstant("curative1"), cnec, Side.LEFT, Unit.AMPERE), 1.); - assertEquals(990.32, raoResult.getFlow(crac.getInstant("curative2"), cnec, Side.LEFT, Unit.AMPERE), 1.); + assertEquals(2371.88, raoResult.getFlow(null, cnec, TwoSides.ONE, Unit.AMPERE), 1.); + assertEquals(2129.22, raoResult.getFlow(crac.getInstant(InstantKind.PREVENTIVE), cnec, TwoSides.ONE, Unit.AMPERE), 1.); + assertEquals(1549.18, raoResult.getFlow(crac.getInstant("curative1"), cnec, TwoSides.ONE, Unit.AMPERE), 1.); + assertEquals(990.32, raoResult.getFlow(crac.getInstant("curative2"), cnec, TwoSides.ONE, Unit.AMPERE), 1.); assertEquals(-71.88, raoResult.getMargin(null, cnec, Unit.AMPERE), 1.); assertEquals(170.78, raoResult.getMargin(crac.getInstant(InstantKind.PREVENTIVE), cnec, Unit.AMPERE), 1.); assertEquals(750.82, raoResult.getMargin(crac.getInstant("curative1"), cnec, Unit.AMPERE), 1.); assertEquals(1309.68, raoResult.getMargin(crac.getInstant("curative2"), cnec, Unit.AMPERE), 1.); cnec = crac.getFlowCnec("c1-cur3"); - assertEquals(2371.88, raoResult.getFlow(null, cnec, Side.LEFT, Unit.AMPERE), 1.); - assertEquals(2129.22, raoResult.getFlow(crac.getInstant(InstantKind.PREVENTIVE), cnec, Side.LEFT, Unit.AMPERE), 1.); - assertEquals(1549.18, raoResult.getFlow(crac.getInstant("curative1"), cnec, Side.LEFT, Unit.AMPERE), 1.); - assertEquals(990.32, raoResult.getFlow(crac.getInstant("curative2"), cnec, Side.LEFT, Unit.AMPERE), 1.); - assertEquals(432.73, raoResult.getFlow(crac.getInstant("curative3"), cnec, Side.LEFT, Unit.AMPERE), 1.); + assertEquals(2371.88, raoResult.getFlow(null, cnec, TwoSides.ONE, Unit.AMPERE), 1.); + assertEquals(2129.22, raoResult.getFlow(crac.getInstant(InstantKind.PREVENTIVE), cnec, TwoSides.ONE, Unit.AMPERE), 1.); + assertEquals(1549.18, raoResult.getFlow(crac.getInstant("curative1"), cnec, TwoSides.ONE, Unit.AMPERE), 1.); + assertEquals(990.32, raoResult.getFlow(crac.getInstant("curative2"), cnec, TwoSides.ONE, Unit.AMPERE), 1.); + assertEquals(432.73, raoResult.getFlow(crac.getInstant("curative3"), cnec, TwoSides.ONE, Unit.AMPERE), 1.); assertEquals(-671.88, raoResult.getMargin(null, cnec, Unit.AMPERE), 1.); assertEquals(-429.22, raoResult.getMargin(crac.getInstant(InstantKind.PREVENTIVE), cnec, Unit.AMPERE), 1.); assertEquals(150.82, raoResult.getMargin(crac.getInstant("curative1"), cnec, Unit.AMPERE), 1.); @@ -897,10 +897,10 @@ void optimizationWithAutoSearchTree() throws IOException { assertEquals(Set.of("ARA_CLOSE_DE2_NL3_2", "ARA_CLOSE_NL2_BE3_2"), raoResult.getActivatedNetworkActionsDuringState(automatonState).stream().map(NetworkAction::getId).collect(Collectors.toSet())); assertTrue(appliedPstAras.isEmpty()); - assertEquals(-382.0, raoResult.getFlow(crac.getInstant("preventive"), crac.getFlowCnec("NNL2AA1 BBE3AA1 1 - preventive"), Side.LEFT, Unit.MEGAWATT), 1.); - assertEquals(-1000.0, raoResult.getFlow(crac.getInstant("outage"), crac.getFlowCnec("NNL2AA1 BBE3AA1 1 - Contingency DE2 NL3 1 - outage"), Side.LEFT, Unit.MEGAWATT), 1.); - assertEquals(-207.0, raoResult.getFlow(crac.getInstant("auto"), crac.getFlowCnec("NNL2AA1 BBE3AA1 1 - Contingency DE2 NL3 1 - auto"), Side.LEFT, Unit.MEGAWATT), 1.); - assertEquals(-207.0, raoResult.getFlow(crac.getInstant("curative"), crac.getFlowCnec("NNL2AA1 BBE3AA1 1 - Contingency DE2 NL3 1 - curative"), Side.LEFT, Unit.MEGAWATT), 1.); + assertEquals(-382.0, raoResult.getFlow(crac.getInstant("preventive"), crac.getFlowCnec("NNL2AA1 BBE3AA1 1 - preventive"), TwoSides.ONE, Unit.MEGAWATT), 1.); + assertEquals(-1000.0, raoResult.getFlow(crac.getInstant("outage"), crac.getFlowCnec("NNL2AA1 BBE3AA1 1 - Contingency DE2 NL3 1 - outage"), TwoSides.ONE, Unit.MEGAWATT), 1.); + assertEquals(-207.0, raoResult.getFlow(crac.getInstant("auto"), crac.getFlowCnec("NNL2AA1 BBE3AA1 1 - Contingency DE2 NL3 1 - auto"), TwoSides.ONE, Unit.MEGAWATT), 1.); + assertEquals(-207.0, raoResult.getFlow(crac.getInstant("curative"), crac.getFlowCnec("NNL2AA1 BBE3AA1 1 - Contingency DE2 NL3 1 - curative"), TwoSides.ONE, Unit.MEGAWATT), 1.); } @Test @@ -924,10 +924,10 @@ void optimizationWithAutoSearchTreeAndAutoPsts() throws IOException { assertEquals(1, appliedPstAras.size()); assertEquals("ARA_PST_BE", appliedPstAras.iterator().next().getId()); - assertEquals(-382.0, raoResult.getFlow(crac.getInstant("preventive"), crac.getFlowCnec("NNL2AA1 BBE3AA1 1 - preventive"), Side.LEFT, Unit.MEGAWATT), 1.); - assertEquals(-1000.0, raoResult.getFlow(crac.getInstant("outage"), crac.getFlowCnec("NNL2AA1 BBE3AA1 1 - Contingency DE2 NL3 1 - outage"), Side.LEFT, Unit.MEGAWATT), 1.); - assertEquals(-131.0, raoResult.getFlow(crac.getInstant("auto"), crac.getFlowCnec("NNL2AA1 BBE3AA1 1 - Contingency DE2 NL3 1 - auto"), Side.LEFT, Unit.MEGAWATT), 1.); - assertEquals(-131.0, raoResult.getFlow(crac.getInstant("curative"), crac.getFlowCnec("NNL2AA1 BBE3AA1 1 - Contingency DE2 NL3 1 - curative"), Side.LEFT, Unit.MEGAWATT), 1.); + assertEquals(-382.0, raoResult.getFlow(crac.getInstant("preventive"), crac.getFlowCnec("NNL2AA1 BBE3AA1 1 - preventive"), TwoSides.ONE, Unit.MEGAWATT), 1.); + assertEquals(-1000.0, raoResult.getFlow(crac.getInstant("outage"), crac.getFlowCnec("NNL2AA1 BBE3AA1 1 - Contingency DE2 NL3 1 - outage"), TwoSides.ONE, Unit.MEGAWATT), 1.); + assertEquals(-131.0, raoResult.getFlow(crac.getInstant("auto"), crac.getFlowCnec("NNL2AA1 BBE3AA1 1 - Contingency DE2 NL3 1 - auto"), TwoSides.ONE, Unit.MEGAWATT), 1.); + assertEquals(-131.0, raoResult.getFlow(crac.getInstant("curative"), crac.getFlowCnec("NNL2AA1 BBE3AA1 1 - Contingency DE2 NL3 1 - curative"), TwoSides.ONE, Unit.MEGAWATT), 1.); } @Test diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/PrePerimeterSensitivityAnalysisTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/PrePerimeterSensitivityAnalysisTest.java index 6c47bf8543..75715f68b8 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/PrePerimeterSensitivityAnalysisTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/PrePerimeterSensitivityAnalysisTest.java @@ -11,7 +11,7 @@ import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracimpl.utils.CommonCracCreation; import com.powsybl.openrao.data.cracimpl.utils.NetworkImportsUtil; import com.powsybl.openrao.loopflowcomputation.LoopFlowComputation; @@ -68,8 +68,8 @@ public void setUp() { cnec = Mockito.mock(FlowCnec.class); optimizationResult = Mockito.mock(OptimizationResult.class); - when(optimizationResult.getPtdfZonalSums()).thenReturn(Map.of(cnec, Map.of(Side.LEFT, 0.1))); - when(optimizationResult.getCommercialFlow(cnec, Side.LEFT, Unit.MEGAWATT)).thenReturn(150.); + when(optimizationResult.getPtdfZonalSums()).thenReturn(Map.of(cnec, Map.of(TwoSides.ONE, 0.1))); + when(optimizationResult.getCommercialFlow(cnec, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(150.); rangeActionSetpointResult = Mockito.mock(RangeActionSetpointResult.class); @@ -78,7 +78,7 @@ public void setUp() { toolProvider = Mockito.mock(ToolProvider.class); when(toolProvider.getLoopFlowComputation()).thenReturn(Mockito.mock(LoopFlowComputation.class)); AbsolutePtdfSumsComputation absolutePtdfSumsComputation = Mockito.mock(AbsolutePtdfSumsComputation.class); - when(absolutePtdfSumsComputation.computeAbsolutePtdfSums(any(), any())).thenReturn(Map.of(cnec, Map.of(Side.LEFT, 0.987))); + when(absolutePtdfSumsComputation.computeAbsolutePtdfSums(any(), any())).thenReturn(Map.of(cnec, Map.of(TwoSides.ONE, 0.987))); when(toolProvider.getAbsolutePtdfSumsComputation()).thenReturn(absolutePtdfSumsComputation); prePerimeterSensitivityAnalysis = new PrePerimeterSensitivityAnalysis(crac.getFlowCnecs(), crac.getRangeActions(), raoParameters, toolProvider); @@ -146,8 +146,8 @@ void testRunWithFixedPtdfAndLf() { PrePerimeterResult result = prePerimeterSensitivityAnalysis.runBasedOnInitialResults(network, crac, optimizationResult, rangeActionSetpointResult, Collections.emptySet(), new AppliedRemedialActions()); assertNotNull(result.getSensitivityResult()); - assertEquals(Map.of(cnec, Map.of(Side.LEFT, 0.1)), result.getFlowResult().getPtdfZonalSums()); - assertEquals(150., result.getFlowResult().getCommercialFlow(cnec, Side.LEFT, Unit.MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(Map.of(cnec, Map.of(TwoSides.ONE, 0.1)), result.getFlowResult().getPtdfZonalSums()); + assertEquals(150., result.getFlowResult().getCommercialFlow(cnec, TwoSides.ONE, Unit.MEGAWATT), DOUBLE_TOLERANCE); } @Test @@ -161,6 +161,6 @@ void testRunAndRecomputePtdf() { PrePerimeterResult result = prePerimeterSensitivityAnalysis.runBasedOnInitialResults(network, crac, optimizationResult, rangeActionSetpointResult, Collections.emptySet(), new AppliedRemedialActions()); assertNotNull(result.getSensitivityResult()); - assertEquals(Map.of(cnec, Map.of(Side.LEFT, 0.987)), result.getFlowResult().getPtdfZonalSums()); + assertEquals(Map.of(cnec, Map.of(TwoSides.ONE, 0.987)), result.getFlowResult().getPtdfZonalSums()); } } diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/StateTreeTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/StateTreeTest.java index 9dd36ab99d..2e0fab4fe0 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/StateTreeTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/StateTreeTest.java @@ -11,7 +11,7 @@ import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.*; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.ActionType; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.usagerule.UsageMethod; @@ -56,7 +56,7 @@ private void setUpCommonCrac(boolean withCra) { if (withCra) { crac = CommonCracCreation.createWithCurativePstRange(); } else { - crac = CommonCracCreation.create(new CracImplFactory(), Set.of(Side.LEFT)); + crac = CommonCracCreation.create(new CracImplFactory(), Set.of(TwoSides.ONE)); } outageInstant = crac.getInstant(OUTAGE_INSTANT_ID); autoInstant = crac.getInstant(AUTO_INSTANT_ID); @@ -113,7 +113,7 @@ private void setUpCustomCrac() { .withInstant(PREVENTIVE_INSTANT_ID) .withId("cnec1-preventive") .withNetworkElement("ne1") - .newThreshold().withSide(Side.LEFT).withUnit(Unit.AMPERE).withMax(200.).withMin(-200.).add() + .newThreshold().withSide(TwoSides.ONE).withUnit(Unit.AMPERE).withMax(200.).withMin(-200.).add() .withNominalVoltage(400.) .add(); crac.newFlowCnec() @@ -121,7 +121,7 @@ private void setUpCustomCrac() { .withContingency("contingency-1") .withId("cnec1-outage1") .withNetworkElement("ne1") - .newThreshold().withSide(Side.LEFT).withUnit(Unit.AMPERE).withMax(400.).withMin(-400.).add() + .newThreshold().withSide(TwoSides.ONE).withUnit(Unit.AMPERE).withMax(400.).withMin(-400.).add() .withNominalVoltage(400.) .add(); crac.newFlowCnec() @@ -129,7 +129,7 @@ private void setUpCustomCrac() { .withContingency("contingency-1") .withId("cnec1-curative1") .withNetworkElement("ne1") - .newThreshold().withSide(Side.LEFT).withUnit(Unit.AMPERE).withMax(200.).withMin(-200.).add() + .newThreshold().withSide(TwoSides.ONE).withUnit(Unit.AMPERE).withMax(200.).withMin(-200.).add() .withNominalVoltage(400.) .add(); crac.newFlowCnec() @@ -137,7 +137,7 @@ private void setUpCustomCrac() { .withContingency("contingency-2") .withId("cnec1-outage2") .withNetworkElement("ne1") - .newThreshold().withSide(Side.LEFT).withUnit(Unit.AMPERE).withMax(500.).withMin(-500.).add() + .newThreshold().withSide(TwoSides.ONE).withUnit(Unit.AMPERE).withMax(500.).withMin(-500.).add() .withNominalVoltage(400.) .add(); crac.newFlowCnec() @@ -145,7 +145,7 @@ private void setUpCustomCrac() { .withContingency("contingency-2") .withId("cnec1-curative2") .withNetworkElement("ne1") - .newThreshold().withSide(Side.LEFT).withUnit(Unit.AMPERE).withMax(200.).withMin(-200.).add() + .newThreshold().withSide(TwoSides.ONE).withUnit(Unit.AMPERE).withMax(200.).withMin(-200.).add() .withNominalVoltage(400.) .add(); crac.newFlowCnec() @@ -153,7 +153,7 @@ private void setUpCustomCrac() { .withContingency("contingency-3") .withId("cnec1-outage3") .withNetworkElement("ne1") - .newThreshold().withSide(Side.LEFT).withUnit(Unit.AMPERE).withMax(200.).withMin(-200.).add() + .newThreshold().withSide(TwoSides.ONE).withUnit(Unit.AMPERE).withMax(200.).withMin(-200.).add() .withNominalVoltage(400.) .add(); crac.newFlowCnec() @@ -161,7 +161,7 @@ private void setUpCustomCrac() { .withContingency("contingency-3") .withId("cnec1-curative3") .withNetworkElement("ne1") - .newThreshold().withSide(Side.LEFT).withUnit(Unit.AMPERE).withMax(200.).withMin(-200.).add() + .newThreshold().withSide(TwoSides.ONE).withUnit(Unit.AMPERE).withMax(200.).withMin(-200.).add() .withNominalVoltage(400.) .add(); } @@ -269,7 +269,7 @@ private void setUpCustomCracWithAutoInstant(boolean withAutoState, boolean withA .withInstant(PREVENTIVE_INSTANT_ID) .withId("cnec-preventive") .withNetworkElement("ne1") - .newThreshold().withSide(Side.LEFT).withUnit(Unit.AMPERE).withMax(200.).withMin(-200.).add() + .newThreshold().withSide(TwoSides.ONE).withUnit(Unit.AMPERE).withMax(200.).withMin(-200.).add() .withNominalVoltage(400.) .add(); preventiveState = crac.getPreventiveState(); @@ -278,7 +278,7 @@ private void setUpCustomCracWithAutoInstant(boolean withAutoState, boolean withA .withContingency("contingency") .withId("cnec-outage") .withNetworkElement("ne1") - .newThreshold().withSide(Side.LEFT).withUnit(Unit.AMPERE).withMax(400.).withMin(-400.).add() + .newThreshold().withSide(TwoSides.ONE).withUnit(Unit.AMPERE).withMax(400.).withMin(-400.).add() .withNominalVoltage(400.) .add(); outageState = crac.getState("contingency", outageInstant); @@ -288,7 +288,7 @@ private void setUpCustomCracWithAutoInstant(boolean withAutoState, boolean withA .withContingency("contingency") .withId("cnec-auto") .withNetworkElement("ne1") - .newThreshold().withSide(Side.LEFT).withUnit(Unit.AMPERE).withMax(200.).withMin(-200.).add() + .newThreshold().withSide(TwoSides.ONE).withUnit(Unit.AMPERE).withMax(200.).withMin(-200.).add() .withNominalVoltage(400.) .add(); if (withAutoRa) { @@ -309,7 +309,7 @@ private void setUpCustomCracWithAutoInstant(boolean withAutoState, boolean withA .withContingency("contingency") .withId("cnec-curative") .withNetworkElement("ne1") - .newThreshold().withSide(Side.LEFT).withUnit(Unit.AMPERE).withMax(400.).withMin(-400.).add() + .newThreshold().withSide(TwoSides.ONE).withUnit(Unit.AMPERE).withMax(400.).withMin(-400.).add() .withNominalVoltage(400.) .add(); if (withCurativeRa) { @@ -1240,7 +1240,7 @@ private static void addFlowCnecToCrac(Crac crac, String instantId, String contin .withNetworkElement("line") .withNominalVoltage(400) .newThreshold() - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .withUnit(Unit.AMPERE) .withMax(500d) .withMin(-500d) diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/AbsolutePtdfSumsComputationTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/AbsolutePtdfSumsComputationTest.java index 1a7a0cbcd0..8aac3479a0 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/AbsolutePtdfSumsComputationTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/AbsolutePtdfSumsComputationTest.java @@ -9,7 +9,7 @@ import com.powsybl.openrao.commons.EICode; import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracimpl.utils.CommonCracCreation; import com.powsybl.openrao.data.cracimpl.utils.NetworkImportsUtil; import com.powsybl.openrao.raoapi.ZoneToZonePtdfDefinition; @@ -43,7 +43,7 @@ class AbsolutePtdfSumsComputationTest { public void setUp() { systematicSensitivityResult = Mockito.mock(SystematicSensitivityResult.class); - Mockito.when(systematicSensitivityResult.getSensitivityOnFlow(Mockito.any(SensitivityVariableSet.class), Mockito.any(FlowCnec.class), Mockito.any(Side.class))) + Mockito.when(systematicSensitivityResult.getSensitivityOnFlow(Mockito.any(SensitivityVariableSet.class), Mockito.any(FlowCnec.class), Mockito.any(TwoSides.class))) .thenAnswer( (Answer) invocation -> { SensitivityVariableSet linearGlsk = (SensitivityVariableSet) invocation.getArguments()[0]; @@ -89,7 +89,7 @@ void testComputation() { Network network = NetworkImportsUtil.import12NodesNetwork(); ZonalData glskProvider = UcteGlskDocument.importGlsk(getClass().getResourceAsStream("/glsk/glsk_proportional_12nodes_with_alegro.xml")) .getZonalGlsks(network, Instant.parse("2016-07-28T22:30:00Z")); - Crac crac = CommonCracCreation.create(Set.of(Side.LEFT, Side.RIGHT)); + Crac crac = CommonCracCreation.create(Set.of(TwoSides.ONE, TwoSides.TWO)); List boundaries = Arrays.asList( new ZoneToZonePtdfDefinition("{FR}-{BE}"), new ZoneToZonePtdfDefinition("{FR}-{DE}"), @@ -98,11 +98,11 @@ void testComputation() { // compute zToz PTDF sum AbsolutePtdfSumsComputation absolutePtdfSumsComputation = new AbsolutePtdfSumsComputation(glskProvider, boundaries); - Map> ptdfSums = absolutePtdfSumsComputation.computeAbsolutePtdfSums(crac.getFlowCnecs(), systematicSensitivityResult); + Map> ptdfSums = absolutePtdfSumsComputation.computeAbsolutePtdfSums(crac.getFlowCnecs(), systematicSensitivityResult); // test results - assertEquals(0.6, ptdfSums.get(crac.getFlowCnec("cnec1basecase")).get(Side.LEFT), DOUBLE_TOLERANCE); // abs(0.1 - 0.2) + abs(0.1 - 0.3) + abs(0.3 - 0.2) + abs(0.2 - 0.1 - 0.3 + 0.4) = 0.1 + 0.2 + 0.1 + 0.2 - assertEquals(0.9, ptdfSums.get(crac.getFlowCnec("cnec2basecase")).get(Side.RIGHT), DOUBLE_TOLERANCE); // abs(0.3 - 0.3) + abs(0.3 - 0.2) + abs(0.2 - 0.3) + abs(0.3 - 0.9 - 0.2 + 0.1) = 0 + 0.1 + 0.1 + 0.7 + assertEquals(0.6, ptdfSums.get(crac.getFlowCnec("cnec1basecase")).get(TwoSides.ONE), DOUBLE_TOLERANCE); // abs(0.1 - 0.2) + abs(0.1 - 0.3) + abs(0.3 - 0.2) + abs(0.2 - 0.1 - 0.3 + 0.4) = 0.1 + 0.2 + 0.1 + 0.2 + assertEquals(0.9, ptdfSums.get(crac.getFlowCnec("cnec2basecase")).get(TwoSides.TWO), DOUBLE_TOLERANCE); // abs(0.3 - 0.3) + abs(0.3 - 0.2) + abs(0.2 - 0.3) + abs(0.3 - 0.9 - 0.2 + 0.1) = 0 + 0.1 + 0.1 + 0.7 } @Test @@ -112,7 +112,7 @@ void testIgnoreZtoZWithLessThan2ZtoS() { Network network = NetworkImportsUtil.import12NodesNetwork(); ZonalData glskProvider = UcteGlskDocument.importGlsk(getClass().getResourceAsStream("/glsk/glsk_proportional_12nodes_with_alegro.xml")) .getZonalGlsks(network, Instant.parse("2016-07-28T22:30:00Z")); - Crac crac = CommonCracCreation.create(Set.of(Side.LEFT, Side.RIGHT)); + Crac crac = CommonCracCreation.create(Set.of(TwoSides.ONE, TwoSides.TWO)); List boundaries = Arrays.asList( new ZoneToZonePtdfDefinition("{FR}-{BE}"), new ZoneToZonePtdfDefinition("{FR}-{DE}"), @@ -123,10 +123,10 @@ void testIgnoreZtoZWithLessThan2ZtoS() { // compute zToz PTDF sum AbsolutePtdfSumsComputation absolutePtdfSumsComputation = new AbsolutePtdfSumsComputation(glskProvider, boundaries); - Map> ptdfSums = absolutePtdfSumsComputation.computeAbsolutePtdfSums(crac.getFlowCnecs(), systematicSensitivityResult); + Map> ptdfSums = absolutePtdfSumsComputation.computeAbsolutePtdfSums(crac.getFlowCnecs(), systematicSensitivityResult); // Test that these 3 new boundaries are ignored (results should be the same as previous test) - assertEquals(0.5, ptdfSums.get(crac.getFlowCnec("cnec1basecase")).get(Side.RIGHT), DOUBLE_TOLERANCE); // abs(0.1 - 0.2) + abs(0.1 - 0.3) + abs(0.3 - 0.2) + abs(0.2 - 0.3) = 0.1 + 0.2 + 0.1 + 0.1 - assertEquals(0.3, ptdfSums.get(crac.getFlowCnec("cnec2basecase")).get(Side.LEFT), DOUBLE_TOLERANCE); // abs(0.3 - 0.3) + abs(0.3 - 0.2) + abs(0.2 - 0.3) + abs(0.3 - 0.2) = 0 + 0.1 + 0.1 + 0.1 + assertEquals(0.5, ptdfSums.get(crac.getFlowCnec("cnec1basecase")).get(TwoSides.TWO), DOUBLE_TOLERANCE); // abs(0.1 - 0.2) + abs(0.1 - 0.3) + abs(0.3 - 0.2) + abs(0.2 - 0.3) = 0.1 + 0.2 + 0.1 + 0.1 + assertEquals(0.3, ptdfSums.get(crac.getFlowCnec("cnec2basecase")).get(TwoSides.ONE), DOUBLE_TOLERANCE); // abs(0.3 - 0.3) + abs(0.3 - 0.2) + abs(0.2 - 0.3) + abs(0.3 - 0.2) = 0 + 0.1 + 0.1 + 0.1 } } diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/RaoLoggerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/RaoLoggerTest.java index 18e5a00760..e6f843e8f3 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/RaoLoggerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/RaoLoggerTest.java @@ -17,7 +17,7 @@ import com.powsybl.openrao.commons.logs.RaoBusinessLogs; import com.powsybl.openrao.data.cracapi.*; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; import com.powsybl.openrao.raoapi.parameters.ObjectiveFunctionParameters; @@ -104,7 +104,7 @@ private FlowCnec mockCnec(String neName, State state, double marginMw, double re when(cnec.getId()).thenReturn(cnecId); mockCnecFlowResult(flowResult, cnec, marginMw, relMarginMw, marginA, relMarginA, ptdf); mockCnecFlowResult(basecaseOptimResult, cnec, marginMw, relMarginMw, marginA, relMarginA, ptdf); - when(cnec.getMonitoredSides()).thenReturn(Set.of(Side.LEFT)); + when(cnec.getMonitoredSides()).thenReturn(Set.of(TwoSides.ONE)); return cnec; } @@ -113,7 +113,7 @@ private void mockCnecFlowResult(FlowResult flowResult, FlowCnec cnec, double mar when(flowResult.getRelativeMargin(cnec, Unit.MEGAWATT)).thenReturn(relMarginMw); when(flowResult.getMargin(cnec, Unit.AMPERE)).thenReturn(marginA); when(flowResult.getRelativeMargin(cnec, Unit.AMPERE)).thenReturn(relMarginA); - when(flowResult.getPtdfZonalSum(cnec, Side.LEFT)).thenReturn(ptdf); + when(flowResult.getPtdfZonalSum(cnec, TwoSides.ONE)).thenReturn(ptdf); } private String absoluteMarginLog(int order, double margin, Unit unit, FlowCnec cnec) { diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/RaoUtilTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/RaoUtilTest.java index 1b537fe7c3..6c248feb32 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/RaoUtilTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/RaoUtilTest.java @@ -14,7 +14,7 @@ import com.powsybl.openrao.data.cracapi.RemedialAction; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.ActionType; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.usagerule.OnConstraint; @@ -129,27 +129,27 @@ void testAmpereWithDc() { @Test void testGetBranchFlowUnitMultiplier() { FlowCnec cnec = Mockito.mock(FlowCnec.class); - Mockito.when(cnec.getNominalVoltage(Side.LEFT)).thenReturn(400.); - Mockito.when(cnec.getNominalVoltage(Side.RIGHT)).thenReturn(200.); + Mockito.when(cnec.getNominalVoltage(TwoSides.ONE)).thenReturn(400.); + Mockito.when(cnec.getNominalVoltage(TwoSides.TWO)).thenReturn(200.); - assertEquals(1., RaoUtil.getFlowUnitMultiplier(cnec, Side.LEFT, Unit.MEGAWATT, Unit.MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(1., RaoUtil.getFlowUnitMultiplier(cnec, Side.RIGHT, Unit.MEGAWATT, Unit.MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(1., RaoUtil.getFlowUnitMultiplier(cnec, Side.LEFT, Unit.AMPERE, Unit.AMPERE), DOUBLE_TOLERANCE); - assertEquals(1., RaoUtil.getFlowUnitMultiplier(cnec, Side.RIGHT, Unit.AMPERE, Unit.AMPERE), DOUBLE_TOLERANCE); + assertEquals(1., RaoUtil.getFlowUnitMultiplier(cnec, TwoSides.ONE, Unit.MEGAWATT, Unit.MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(1., RaoUtil.getFlowUnitMultiplier(cnec, TwoSides.TWO, Unit.MEGAWATT, Unit.MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(1., RaoUtil.getFlowUnitMultiplier(cnec, TwoSides.ONE, Unit.AMPERE, Unit.AMPERE), DOUBLE_TOLERANCE); + assertEquals(1., RaoUtil.getFlowUnitMultiplier(cnec, TwoSides.TWO, Unit.AMPERE, Unit.AMPERE), DOUBLE_TOLERANCE); - assertEquals(1000 / 400. / Math.sqrt(3), RaoUtil.getFlowUnitMultiplier(cnec, Side.LEFT, Unit.MEGAWATT, Unit.AMPERE), DOUBLE_TOLERANCE); - assertEquals(400 * Math.sqrt(3) / 1000., RaoUtil.getFlowUnitMultiplier(cnec, Side.LEFT, Unit.AMPERE, Unit.MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(1000 / 400. / Math.sqrt(3), RaoUtil.getFlowUnitMultiplier(cnec, TwoSides.ONE, Unit.MEGAWATT, Unit.AMPERE), DOUBLE_TOLERANCE); + assertEquals(400 * Math.sqrt(3) / 1000., RaoUtil.getFlowUnitMultiplier(cnec, TwoSides.ONE, Unit.AMPERE, Unit.MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(1000 / 200. / Math.sqrt(3), RaoUtil.getFlowUnitMultiplier(cnec, Side.RIGHT, Unit.MEGAWATT, Unit.AMPERE), DOUBLE_TOLERANCE); - assertEquals(200 * Math.sqrt(3) / 1000., RaoUtil.getFlowUnitMultiplier(cnec, Side.RIGHT, Unit.AMPERE, Unit.MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(1000 / 200. / Math.sqrt(3), RaoUtil.getFlowUnitMultiplier(cnec, TwoSides.TWO, Unit.MEGAWATT, Unit.AMPERE), DOUBLE_TOLERANCE); + assertEquals(200 * Math.sqrt(3) / 1000., RaoUtil.getFlowUnitMultiplier(cnec, TwoSides.TWO, Unit.AMPERE, Unit.MEGAWATT), DOUBLE_TOLERANCE); - OpenRaoException exception = assertThrows(OpenRaoException.class, () -> RaoUtil.getFlowUnitMultiplier(cnec, Side.LEFT, Unit.MEGAWATT, Unit.PERCENT_IMAX)); + OpenRaoException exception = assertThrows(OpenRaoException.class, () -> RaoUtil.getFlowUnitMultiplier(cnec, TwoSides.ONE, Unit.MEGAWATT, Unit.PERCENT_IMAX)); assertEquals("Only conversions between MW and A are supported.", exception.getMessage()); - exception = assertThrows(OpenRaoException.class, () -> RaoUtil.getFlowUnitMultiplier(cnec, Side.LEFT, Unit.KILOVOLT, Unit.MEGAWATT)); + exception = assertThrows(OpenRaoException.class, () -> RaoUtil.getFlowUnitMultiplier(cnec, TwoSides.ONE, Unit.KILOVOLT, Unit.MEGAWATT)); assertEquals("Only conversions between MW and A are supported.", exception.getMessage()); - exception = assertThrows(OpenRaoException.class, () -> RaoUtil.getFlowUnitMultiplier(cnec, Side.RIGHT, Unit.AMPERE, Unit.TAP)); + exception = assertThrows(OpenRaoException.class, () -> RaoUtil.getFlowUnitMultiplier(cnec, TwoSides.TWO, Unit.AMPERE, Unit.TAP)); assertEquals("Only conversions between MW and A are supported.", exception.getMessage()); - exception = assertThrows(OpenRaoException.class, () -> RaoUtil.getFlowUnitMultiplier(cnec, Side.RIGHT, Unit.DEGREE, Unit.AMPERE)); + exception = assertThrows(OpenRaoException.class, () -> RaoUtil.getFlowUnitMultiplier(cnec, TwoSides.TWO, Unit.DEGREE, Unit.AMPERE)); assertEquals("Only conversions between MW and A are supported.", exception.getMessage()); } @@ -163,15 +163,15 @@ void testGetLargestCnecThreshold() { Mockito.when(cnecB.isOptimized()).thenReturn(true); Mockito.when(cnecC.isOptimized()).thenReturn(true); Mockito.when(cnecD.isOptimized()).thenReturn(false); - Mockito.when(cnecA.getUpperBound(Side.LEFT, Unit.MEGAWATT)).thenReturn(Optional.of(1000.)); - Mockito.when(cnecA.getLowerBound(Side.LEFT, Unit.MEGAWATT)).thenReturn(Optional.empty()); - Mockito.when(cnecB.getUpperBound(Side.LEFT, Unit.MEGAWATT)).thenReturn(Optional.empty()); - Mockito.when(cnecB.getLowerBound(Side.LEFT, Unit.MEGAWATT)).thenReturn(Optional.of(-1500.)); - Mockito.when(cnecC.getUpperBound(Side.LEFT, Unit.MEGAWATT)).thenReturn(Optional.empty()); - Mockito.when(cnecC.getLowerBound(Side.LEFT, Unit.MEGAWATT)).thenReturn(Optional.empty()); - Mockito.when(cnecD.getUpperBound(Side.LEFT, Unit.MEGAWATT)).thenReturn(Optional.of(-16000.)); - Mockito.when(cnecD.getLowerBound(Side.LEFT, Unit.MEGAWATT)).thenReturn(Optional.of(-16000.)); - Set.of(cnecA, cnecB, cnecC, cnecD).forEach(cnec -> when(cnec.getMonitoredSides()).thenReturn(Set.of(Side.LEFT))); + Mockito.when(cnecA.getUpperBound(TwoSides.ONE, Unit.MEGAWATT)).thenReturn(Optional.of(1000.)); + Mockito.when(cnecA.getLowerBound(TwoSides.ONE, Unit.MEGAWATT)).thenReturn(Optional.empty()); + Mockito.when(cnecB.getUpperBound(TwoSides.ONE, Unit.MEGAWATT)).thenReturn(Optional.empty()); + Mockito.when(cnecB.getLowerBound(TwoSides.ONE, Unit.MEGAWATT)).thenReturn(Optional.of(-1500.)); + Mockito.when(cnecC.getUpperBound(TwoSides.ONE, Unit.MEGAWATT)).thenReturn(Optional.empty()); + Mockito.when(cnecC.getLowerBound(TwoSides.ONE, Unit.MEGAWATT)).thenReturn(Optional.empty()); + Mockito.when(cnecD.getUpperBound(TwoSides.ONE, Unit.MEGAWATT)).thenReturn(Optional.of(-16000.)); + Mockito.when(cnecD.getLowerBound(TwoSides.ONE, Unit.MEGAWATT)).thenReturn(Optional.of(-16000.)); + Set.of(cnecA, cnecB, cnecC, cnecD).forEach(cnec -> when(cnec.getMonitoredSides()).thenReturn(Set.of(TwoSides.ONE))); assertEquals(1000., RaoUtil.getLargestCnecThreshold(Set.of(cnecA), Unit.MEGAWATT), DOUBLE_TOLERANCE); assertEquals(1500., RaoUtil.getLargestCnecThreshold(Set.of(cnecB), Unit.MEGAWATT), DOUBLE_TOLERANCE); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/adapter/FlowResultAdapterImplTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/adapter/FlowResultAdapterImplTest.java index 0df06add09..44a1a1b68d 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/adapter/FlowResultAdapterImplTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/adapter/FlowResultAdapterImplTest.java @@ -10,7 +10,7 @@ import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.loopflowcomputation.LoopFlowComputation; import com.powsybl.openrao.loopflowcomputation.LoopFlowResult; import com.powsybl.openrao.searchtreerao.commons.AbsolutePtdfSumsComputation; @@ -30,8 +30,8 @@ import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; -import static com.powsybl.openrao.data.cracapi.cnec.Side.LEFT; -import static com.powsybl.openrao.data.cracapi.cnec.Side.RIGHT; +import static com.powsybl.iidm.network.TwoSides.ONE; +import static com.powsybl.iidm.network.TwoSides.TWO; /** * @author Joris Mancini {@literal } @@ -48,9 +48,9 @@ class FlowResultAdapterImplTest { @BeforeEach public void setUp() { cnec1 = Mockito.mock(FlowCnec.class); - when(cnec1.getMonitoredSides()).thenReturn(Collections.singleton(LEFT)); + when(cnec1.getMonitoredSides()).thenReturn(Collections.singleton(ONE)); cnec2 = Mockito.mock(FlowCnec.class); - when(cnec1.getMonitoredSides()).thenReturn(Collections.singleton(RIGHT)); + when(cnec1.getMonitoredSides()).thenReturn(Collections.singleton(TWO)); systematicSensitivityResult = Mockito.mock(SystematicSensitivityResult.class); branchResultAdpaterBuilder = BranchResultAdapterImpl.create(); network = Mockito.mock(Network.class); @@ -61,35 +61,35 @@ void testBasicReturns() { BranchResultAdapter branchResultAdapter = branchResultAdpaterBuilder .build(); - when(systematicSensitivityResult.getReferenceFlow(cnec1, LEFT)).thenReturn(200.); - when(systematicSensitivityResult.getReferenceIntensity(cnec1, LEFT)).thenReturn(58.); - when(systematicSensitivityResult.getReferenceFlow(cnec2, RIGHT)).thenReturn(500.); - when(systematicSensitivityResult.getReferenceIntensity(cnec2, RIGHT)).thenReturn(235.); + when(systematicSensitivityResult.getReferenceFlow(cnec1, ONE)).thenReturn(200.); + when(systematicSensitivityResult.getReferenceIntensity(cnec1, ONE)).thenReturn(58.); + when(systematicSensitivityResult.getReferenceFlow(cnec2, TWO)).thenReturn(500.); + when(systematicSensitivityResult.getReferenceIntensity(cnec2, TWO)).thenReturn(235.); FlowResult flowResult = branchResultAdapter.getResult(systematicSensitivityResult, network); - assertEquals(200., flowResult.getFlow(cnec1, LEFT, Unit.MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(58., flowResult.getFlow(cnec1, LEFT, Unit.AMPERE), DOUBLE_TOLERANCE); - assertEquals(500., flowResult.getFlow(cnec2, RIGHT, Unit.MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(235., flowResult.getFlow(cnec2, RIGHT, Unit.AMPERE), DOUBLE_TOLERANCE); - assertTrue(Double.isNaN(flowResult.getPtdfZonalSum(cnec1, LEFT))); + assertEquals(200., flowResult.getFlow(cnec1, ONE, Unit.MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(58., flowResult.getFlow(cnec1, ONE, Unit.AMPERE), DOUBLE_TOLERANCE); + assertEquals(500., flowResult.getFlow(cnec2, TWO, Unit.MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(235., flowResult.getFlow(cnec2, TWO, Unit.AMPERE), DOUBLE_TOLERANCE); + assertTrue(Double.isNaN(flowResult.getPtdfZonalSum(cnec1, ONE))); } @Test void testWithFixedPtdfs() { - FlowResult fixedPtdfFlowResult = new FlowResultFromMapImpl(systematicSensitivityResult, new HashMap<>(), Map.of(cnec1, Map.of(LEFT, 20.))); + FlowResult fixedPtdfFlowResult = new FlowResultFromMapImpl(systematicSensitivityResult, new HashMap<>(), Map.of(cnec1, Map.of(ONE, 20.))); BranchResultAdapter branchResultAdapter = branchResultAdpaterBuilder .withPtdfsResults(fixedPtdfFlowResult) .build(); FlowResult flowResult = branchResultAdapter.getResult(systematicSensitivityResult, network); - assertEquals(20., flowResult.getPtdfZonalSum(cnec1, LEFT), DOUBLE_TOLERANCE); + assertEquals(20., flowResult.getPtdfZonalSum(cnec1, ONE), DOUBLE_TOLERANCE); } @Test void testWithFixedPtdfsAndCommercialFlows() { - FlowResult ptdfFlowResult = new FlowResultFromMapImpl(systematicSensitivityResult, new HashMap<>(), Map.of(cnec1, Map.of(LEFT, 20.))); - FlowResult commercialFlowFlowResult = new FlowResultFromMapImpl(systematicSensitivityResult, Map.of(cnec2, Map.of(RIGHT, 300.)), new HashMap<>()); + FlowResult ptdfFlowResult = new FlowResultFromMapImpl(systematicSensitivityResult, new HashMap<>(), Map.of(cnec1, Map.of(ONE, 20.))); + FlowResult commercialFlowFlowResult = new FlowResultFromMapImpl(systematicSensitivityResult, Map.of(cnec2, Map.of(TWO, 300.)), new HashMap<>()); BranchResultAdapter branchResultAdapter = branchResultAdpaterBuilder .withPtdfsResults(ptdfFlowResult) .withCommercialFlowsResults(commercialFlowFlowResult) @@ -97,14 +97,14 @@ void testWithFixedPtdfsAndCommercialFlows() { FlowResult flowResult = branchResultAdapter.getResult(systematicSensitivityResult, network); - assertEquals(20., flowResult.getPtdfZonalSum(cnec1, LEFT), DOUBLE_TOLERANCE); - assertEquals(300., flowResult.getCommercialFlow(cnec2, RIGHT, Unit.MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(20., flowResult.getPtdfZonalSum(cnec1, ONE), DOUBLE_TOLERANCE); + assertEquals(300., flowResult.getCommercialFlow(cnec2, TWO, Unit.MEGAWATT), DOUBLE_TOLERANCE); } @Test void testWithFixedPtdfsAndUpdatedCommercialFlows() { LoopFlowComputation loopFlowComputation = Mockito.mock(LoopFlowComputation.class); - FlowResult ptdfFlowResult = new FlowResultFromMapImpl(systematicSensitivityResult, new HashMap<>(), Map.of(cnec1, Map.of(LEFT, 20.))); + FlowResult ptdfFlowResult = new FlowResultFromMapImpl(systematicSensitivityResult, new HashMap<>(), Map.of(cnec1, Map.of(ONE, 20.))); BranchResultAdapter branchResultAdapter = branchResultAdpaterBuilder.withPtdfsResults(ptdfFlowResult) .withCommercialFlowsResults(loopFlowComputation, Set.of(cnec2)) .build(); @@ -112,25 +112,25 @@ void testWithFixedPtdfsAndUpdatedCommercialFlows() { LoopFlowResult loopFlowResult = Mockito.mock(LoopFlowResult.class); when(loopFlowComputation.buildLoopFlowsFromReferenceFlowAndPtdf(systematicSensitivityResult, Set.of(cnec2), network)) .thenReturn(loopFlowResult); - when(loopFlowResult.getCommercialFlow(cnec2, RIGHT)).thenReturn(300.); + when(loopFlowResult.getCommercialFlow(cnec2, TWO)).thenReturn(300.); FlowResult flowResult = branchResultAdapter.getResult(systematicSensitivityResult, network); - assertEquals(20., flowResult.getPtdfZonalSum(cnec1, LEFT), DOUBLE_TOLERANCE); - assertEquals(300., flowResult.getCommercialFlow(cnec2, RIGHT, Unit.MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(20., flowResult.getPtdfZonalSum(cnec1, ONE), DOUBLE_TOLERANCE); + assertEquals(300., flowResult.getCommercialFlow(cnec2, TWO, Unit.MEGAWATT), DOUBLE_TOLERANCE); } @Test void testWithAbsolutePtdfSumsComputation() { AbsolutePtdfSumsComputation absolutePtdfSumsComputation = Mockito.mock(AbsolutePtdfSumsComputation.class); - Map> ptdfZonalSums = Map.of(cnec1, Map.of(LEFT, 1.63), cnec2, Map.of(RIGHT, 0.57)); + Map> ptdfZonalSums = Map.of(cnec1, Map.of(ONE, 1.63), cnec2, Map.of(TWO, 0.57)); when(absolutePtdfSumsComputation.computeAbsolutePtdfSums(any(), any())).thenReturn(ptdfZonalSums); BranchResultAdapter branchResultAdapter = branchResultAdpaterBuilder .withPtdfsResults(absolutePtdfSumsComputation, Set.of(cnec1, cnec2)) .build(); FlowResult flowResult = branchResultAdapter.getResult(systematicSensitivityResult, network); - assertEquals(1.63, flowResult.getPtdfZonalSum(cnec1, LEFT), DOUBLE_TOLERANCE); - assertEquals(0.57, flowResult.getPtdfZonalSum(cnec2, RIGHT), DOUBLE_TOLERANCE); + assertEquals(1.63, flowResult.getPtdfZonalSum(cnec1, ONE), DOUBLE_TOLERANCE); + assertEquals(0.57, flowResult.getPtdfZonalSum(cnec2, TWO), DOUBLE_TOLERANCE); assertEquals(ptdfZonalSums, flowResult.getPtdfZonalSums()); - assertThrows(OpenRaoException.class, () -> flowResult.getPtdfZonalSum(Mockito.mock(FlowCnec.class), LEFT)); + assertThrows(OpenRaoException.class, () -> flowResult.getPtdfZonalSum(Mockito.mock(FlowCnec.class), ONE)); } } diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/LoopFlowViolationCostEvaluatorTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/LoopFlowViolationCostEvaluatorTest.java index b57e7bdae9..e2edfc3177 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/LoopFlowViolationCostEvaluatorTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/LoopFlowViolationCostEvaluatorTest.java @@ -9,7 +9,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracloopflowextension.LoopFlowThreshold; import com.powsybl.openrao.data.raoresultapi.ComputationStatus; import com.powsybl.openrao.raoapi.parameters.extensions.LoopFlowParametersExtension; @@ -50,13 +50,13 @@ public void setUp() { when(state.getContingency()).thenReturn(Optional.empty()); LoopFlowThreshold cnec1Extension = Mockito.mock(LoopFlowThreshold.class); cnec1 = Mockito.mock(FlowCnec.class); - when(cnec1.getMonitoredSides()).thenReturn(Set.of(Side.LEFT)); + when(cnec1.getMonitoredSides()).thenReturn(Set.of(TwoSides.ONE)); when(cnec1.getExtension(LoopFlowThreshold.class)).thenReturn(cnec1Extension); when(cnec1.getState()).thenReturn(state); LoopFlowThreshold cnec2Extension = Mockito.mock(LoopFlowThreshold.class); cnec2 = Mockito.mock(FlowCnec.class); - when(cnec2.getMonitoredSides()).thenReturn(Set.of(Side.LEFT)); + when(cnec2.getMonitoredSides()).thenReturn(Set.of(TwoSides.ONE)); when(cnec2.getExtension(LoopFlowThreshold.class)).thenReturn(cnec2Extension); when(cnec2.getState()).thenReturn(state); @@ -74,11 +74,11 @@ private void setInputThresholdWithReliabilityMargin(FlowCnec branchCnec, double } private void setInitialLoopFLow(FlowCnec branchCnec, double initialLoopFLow) { - when(initialLoopFlows.getLoopFlow(branchCnec, Side.LEFT, Unit.MEGAWATT)).thenReturn(initialLoopFLow); + when(initialLoopFlows.getLoopFlow(branchCnec, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(initialLoopFLow); } private void setCurrentLoopFLow(FlowCnec branchCnec, double currentLoopFlow) { - when(currentLoopFlows.getLoopFlow(branchCnec, Side.LEFT, Unit.MEGAWATT)).thenReturn(currentLoopFlow); + when(currentLoopFlows.getLoopFlow(branchCnec, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(currentLoopFlow); } private void setAcceptableAugmentationInMW(double acceptableAugmentationInMW) { diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/MarginEvaluatorWithMarginDecreaseUnoptimizedCnecsTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/MarginEvaluatorWithMarginDecreaseUnoptimizedCnecsTest.java index 6608b21d99..83f1c07b9f 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/MarginEvaluatorWithMarginDecreaseUnoptimizedCnecsTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/MarginEvaluatorWithMarginDecreaseUnoptimizedCnecsTest.java @@ -9,7 +9,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.searchtreerao.result.api.FlowResult; import com.powsybl.openrao.searchtreerao.result.api.RangeActionActivationResult; import com.powsybl.openrao.searchtreerao.result.api.SensitivityResult; @@ -42,13 +42,13 @@ class MarginEvaluatorWithMarginDecreaseUnoptimizedCnecsTest { @BeforeEach public void setUp() { - when(flowCnec.getMonitoredSides()).thenReturn(Set.of(Side.LEFT)); + when(flowCnec.getMonitoredSides()).thenReturn(Set.of(TwoSides.ONE)); } @Test void getMarginInMegawattOnOptimizedCnec() { when(flowCnec.getOperator()).thenReturn("NL"); - when(currentFlowResult.getMargin(flowCnec, Side.LEFT, Unit.MEGAWATT)).thenReturn(200.); + when(currentFlowResult.getMargin(flowCnec, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(200.); double margin = marginEvaluatorWithUnoptimizedCnecs.getMargin(currentFlowResult, flowCnec, rangeActionActivationResult, sensitivityResult, Unit.MEGAWATT); assertEquals(200., margin, DOUBLE_TOLERANCE); @@ -57,7 +57,7 @@ void getMarginInMegawattOnOptimizedCnec() { @Test void getMarginInAmpereOnOptimizedCnec() { when(flowCnec.getOperator()).thenReturn("NL"); - when(currentFlowResult.getMargin(flowCnec, Side.LEFT, Unit.AMPERE)).thenReturn(50.); + when(currentFlowResult.getMargin(flowCnec, TwoSides.ONE, Unit.AMPERE)).thenReturn(50.); double margin = marginEvaluatorWithUnoptimizedCnecs.getMargin(currentFlowResult, flowCnec, rangeActionActivationResult, sensitivityResult, Unit.AMPERE); assertEquals(50., margin, DOUBLE_TOLERANCE); @@ -66,8 +66,8 @@ void getMarginInAmpereOnOptimizedCnec() { @Test void getMarginInMegawattOnConstrainedUnoptimizedCnec() { when(flowCnec.getOperator()).thenReturn("FR"); - when(currentFlowResult.getMargin(flowCnec, Side.LEFT, Unit.MEGAWATT)).thenReturn(200.); - when(prePerimeterFlowResult.getMargin(flowCnec, Side.LEFT, Unit.MEGAWATT)).thenReturn(400.); + when(currentFlowResult.getMargin(flowCnec, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(200.); + when(prePerimeterFlowResult.getMargin(flowCnec, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(400.); double margin = marginEvaluatorWithUnoptimizedCnecs.getMargin(currentFlowResult, flowCnec, rangeActionActivationResult, sensitivityResult, Unit.MEGAWATT); assertEquals(200., margin, DOUBLE_TOLERANCE); @@ -76,8 +76,8 @@ void getMarginInMegawattOnConstrainedUnoptimizedCnec() { @Test void getMarginInMegawattOnUnconstrainedUnoptimizedCnec() { when(flowCnec.getOperator()).thenReturn("FR"); - when(currentFlowResult.getMargin(flowCnec, Side.LEFT, Unit.MEGAWATT)).thenReturn(200.); - when(prePerimeterFlowResult.getMargin(flowCnec, Side.LEFT, Unit.MEGAWATT)).thenReturn(100.); + when(currentFlowResult.getMargin(flowCnec, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(200.); + when(prePerimeterFlowResult.getMargin(flowCnec, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(100.); double margin = marginEvaluatorWithUnoptimizedCnecs.getMargin(currentFlowResult, flowCnec, rangeActionActivationResult, sensitivityResult, Unit.MEGAWATT); assertEquals(Double.MAX_VALUE, margin, DOUBLE_TOLERANCE); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/optimizationperimeters/AbstractOptimizationPerimeterTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/optimizationperimeters/AbstractOptimizationPerimeterTest.java index 944452d2ab..5ada35be2e 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/optimizationperimeters/AbstractOptimizationPerimeterTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/optimizationperimeters/AbstractOptimizationPerimeterTest.java @@ -4,7 +4,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.*; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.ActionType; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; import com.powsybl.openrao.data.cracapi.usagerule.UsageMethod; @@ -62,7 +62,7 @@ public void setUp() { .withNetworkElement("BBE2AA1 FFR3AA1 1") .withInstant(PREVENTIVE_INSTANT_ID) .withOptimized(true) - .newThreshold().withUnit(Unit.MEGAWATT).withMax(500.).withMin(-500.).withSide(Side.LEFT).add() + .newThreshold().withUnit(Unit.MEGAWATT).withMax(500.).withMin(-500.).withSide(TwoSides.ONE).add() .add(); // one outage CNEC for each CO @@ -72,7 +72,7 @@ public void setUp() { .withInstant(OUTAGE_INSTANT_ID) .withContingency("outage-1") .withMonitored(true) - .newThreshold().withUnit(Unit.MEGAWATT).withMax(500.).withMin(-500.).withSide(Side.LEFT).add() + .newThreshold().withUnit(Unit.MEGAWATT).withMax(500.).withMin(-500.).withSide(TwoSides.ONE).add() .add(); oCnec1.newExtension(LoopFlowThresholdAdder.class).withUnit(Unit.MEGAWATT).withValue(100.).add(); @@ -82,7 +82,7 @@ public void setUp() { .withInstant(OUTAGE_INSTANT_ID) .withContingency("outage-2") .withOptimized(true).withMonitored(true) - .newThreshold().withUnit(Unit.MEGAWATT).withMax(500.).withMin(-500.).withSide(Side.LEFT).add() + .newThreshold().withUnit(Unit.MEGAWATT).withMax(500.).withMin(-500.).withSide(TwoSides.ONE).add() .add(); cCnec1 = crac.newFlowCnec() @@ -91,7 +91,7 @@ public void setUp() { .withInstant(CURATIVE_INSTANT_ID) .withContingency("outage-1") .withMonitored(true) - .newThreshold().withUnit(Unit.MEGAWATT).withMax(500.).withMin(-500.).withSide(Side.LEFT).add() + .newThreshold().withUnit(Unit.MEGAWATT).withMax(500.).withMin(-500.).withSide(TwoSides.ONE).add() .add(); cCnec2 = crac.newFlowCnec() @@ -100,7 +100,7 @@ public void setUp() { .withInstant(CURATIVE_INSTANT_ID) .withContingency("outage-2") .withOptimized(true) - .newThreshold().withUnit(Unit.MEGAWATT).withMax(500.).withMin(-500.).withSide(Side.LEFT).add() + .newThreshold().withUnit(Unit.MEGAWATT).withMax(500.).withMin(-500.).withSide(TwoSides.ONE).add() .add(); cCnec2.newExtension(LoopFlowThresholdAdder.class).withUnit(Unit.MEGAWATT).withValue(100.).add(); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/optimizationperimeters/AutoOptimizationPerimeterTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/optimizationperimeters/AutoOptimizationPerimeterTest.java index 1587e28db3..c01e9e34be 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/optimizationperimeters/AutoOptimizationPerimeterTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/optimizationperimeters/AutoOptimizationPerimeterTest.java @@ -13,7 +13,7 @@ import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.InstantKind; import com.powsybl.openrao.data.cracapi.State; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.ActionType; import com.powsybl.openrao.data.cracapi.usagerule.UsageMethod; import com.powsybl.openrao.data.cracimpl.CracImplFactory; @@ -75,7 +75,7 @@ private Crac initCrac() { .withNetworkElement("line") .withNominalVoltage(400) .newThreshold() - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .withMin(-1000d) .withMax(1000d) .withUnit(Unit.AMPERE) @@ -90,7 +90,7 @@ private Crac initCrac() { .withNetworkElement("line") .withNominalVoltage(400) .newThreshold() - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .withMin(-2500d) .withMax(2500d) .withUnit(Unit.AMPERE) @@ -105,7 +105,7 @@ private Crac initCrac() { .withNetworkElement("line") .withNominalVoltage(400) .newThreshold() - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .withMin(-1500d) .withMax(1500d) .withUnit(Unit.AMPERE) @@ -120,7 +120,7 @@ private Crac initCrac() { .withNetworkElement("line") .withNominalVoltage(400) .newThreshold() - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .withMin(-1000d) .withMax(1000d) .withUnit(Unit.AMPERE) diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/BestTapFinderTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/BestTapFinderTest.java index 7260a27f70..62659ce82d 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/BestTapFinderTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/BestTapFinderTest.java @@ -12,7 +12,7 @@ import com.powsybl.openrao.data.cracapi.NetworkElement; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; import com.powsybl.openrao.searchtreerao.commons.optimizationperimeters.OptimizationPerimeter; @@ -57,16 +57,16 @@ class BestTapFinderTest { @BeforeEach public void setUp() { cnec1 = Mockito.mock(FlowCnec.class); - when(cnec1.getMonitoredSides()).thenReturn(Collections.singleton(Side.LEFT)); + when(cnec1.getMonitoredSides()).thenReturn(Collections.singleton(TwoSides.ONE)); cnec2 = Mockito.mock(FlowCnec.class); - when(cnec2.getMonitoredSides()).thenReturn(Collections.singleton(Side.RIGHT)); + when(cnec2.getMonitoredSides()).thenReturn(Collections.singleton(TwoSides.TWO)); network = Mockito.mock(Network.class); linearOptimizationResult = mock(LinearOptimizationResult.class); when(linearOptimizationResult.getMostLimitingElements(anyInt())).thenReturn(List.of(cnec1, cnec2)); - when(linearOptimizationResult.getFlow(cnec1, Side.LEFT, Unit.MEGAWATT)).thenReturn(REF_FLOW_1); - when(linearOptimizationResult.getFlow(cnec2, Side.RIGHT, Unit.MEGAWATT)).thenReturn(REF_FLOW_2); + when(linearOptimizationResult.getFlow(cnec1, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(REF_FLOW_1); + when(linearOptimizationResult.getFlow(cnec2, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(REF_FLOW_2); rangeActionActivationResult = Mockito.mock(RangeActionActivationResult.class); pstRangeAction = createPst(); @@ -82,8 +82,8 @@ public void setUp() { } private void setSensitivityValues(PstRangeAction pstRangeAction) { - when(linearOptimizationResult.getSensitivityValue(cnec1, Side.LEFT, pstRangeAction, Unit.MEGAWATT)).thenReturn(SENSI_1); - when(linearOptimizationResult.getSensitivityValue(cnec2, Side.RIGHT, pstRangeAction, Unit.MEGAWATT)).thenReturn(SENSI_2); + when(linearOptimizationResult.getSensitivityValue(cnec1, TwoSides.ONE, pstRangeAction, Unit.MEGAWATT)).thenReturn(SENSI_1); + when(linearOptimizationResult.getSensitivityValue(cnec2, TwoSides.TWO, pstRangeAction, Unit.MEGAWATT)).thenReturn(SENSI_2); } private void mockPstRangeAction(PstRangeAction pstRangeAction) { @@ -107,12 +107,12 @@ private void setMarginsForTap(PstRangeAction pstRangeAction, int tap, double mar private void mockMarginOnCnec1(PstRangeAction pstRangeAction, int tap, double margin) { double flow = REF_FLOW_1 + (pstRangeAction.convertTapToAngle(tap) - INITIAL_PST_SET_POINT) * SENSI_1; - when(cnec1.computeMargin(flow, Side.LEFT, Unit.MEGAWATT)).thenReturn(margin); + when(cnec1.computeMargin(flow, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(margin); } private void mockMarginOnCnec2(PstRangeAction pstRangeAction, int tap, double margin) { double flow = REF_FLOW_2 + (pstRangeAction.convertTapToAngle(tap) - INITIAL_PST_SET_POINT) * SENSI_2; - when(cnec2.computeMargin(flow, Side.RIGHT, Unit.MEGAWATT)).thenReturn(margin); + when(cnec2.computeMargin(flow, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(margin); } private Map computeMinMarginsForBestTaps(double startingSetPoint) { diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/LinearProblemTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/LinearProblemTest.java index 8a63466feb..f6a873d4e8 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/LinearProblemTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/LinearProblemTest.java @@ -10,7 +10,7 @@ import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; import com.powsybl.openrao.searchtreerao.linearoptimisation.algorithms.linearproblem.LinearProblem; @@ -52,7 +52,7 @@ public void setUp() { rangeAction = Mockito.mock(PstRangeAction.class); cnec = Mockito.mock(FlowCnec.class); - Mockito.when(cnec.getMonitoredSides()).thenReturn(Collections.singleton(Side.LEFT)); + Mockito.when(cnec.getMonitoredSides()).thenReturn(Collections.singleton(TwoSides.ONE)); state = Mockito.mock(State.class); Mockito.when(rangeAction.getId()).thenReturn(RANGE_ACTION_ID); @@ -62,22 +62,22 @@ public void setUp() { @Test void flowVariableTest() { - Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowVariable(cnec, Side.LEFT)); - assertEquals("Variable cnec_id_left_flow_variable has not been created yet", e.getMessage()); - linearProblem.addFlowVariable(LB, UB, cnec, Side.LEFT); - assertNotNull(linearProblem.getFlowVariable(cnec, Side.LEFT)); - assertEquals(LB, linearProblem.getFlowVariable(cnec, Side.LEFT).lb(), DOUBLE_TOLERANCE); - assertEquals(UB, linearProblem.getFlowVariable(cnec, Side.LEFT).ub(), DOUBLE_TOLERANCE); + Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowVariable(cnec, TwoSides.ONE)); + assertEquals("Variable cnec_id_one_flow_variable has not been created yet", e.getMessage()); + linearProblem.addFlowVariable(LB, UB, cnec, TwoSides.ONE); + assertNotNull(linearProblem.getFlowVariable(cnec, TwoSides.ONE)); + assertEquals(LB, linearProblem.getFlowVariable(cnec, TwoSides.ONE).lb(), DOUBLE_TOLERANCE); + assertEquals(UB, linearProblem.getFlowVariable(cnec, TwoSides.ONE).ub(), DOUBLE_TOLERANCE); } @Test void flowConstraintTest() { - Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowConstraint(cnec, Side.LEFT)); - assertEquals("Constraint cnec_id_left_flow_constraint has not been created yet", e.getMessage()); - linearProblem.addFlowConstraint(LB, UB, cnec, Side.LEFT); - assertNotNull(linearProblem.getFlowConstraint(cnec, Side.LEFT)); - assertEquals(LB, linearProblem.getFlowConstraint(cnec, Side.LEFT).lb(), DOUBLE_TOLERANCE); - assertEquals(UB, linearProblem.getFlowConstraint(cnec, Side.LEFT).ub(), DOUBLE_TOLERANCE); + Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowConstraint(cnec, TwoSides.ONE)); + assertEquals("Constraint cnec_id_one_flow_constraint has not been created yet", e.getMessage()); + linearProblem.addFlowConstraint(LB, UB, cnec, TwoSides.ONE); + assertNotNull(linearProblem.getFlowConstraint(cnec, TwoSides.ONE)); + assertEquals(LB, linearProblem.getFlowConstraint(cnec, TwoSides.ONE).lb(), DOUBLE_TOLERANCE); + assertEquals(UB, linearProblem.getFlowConstraint(cnec, TwoSides.ONE).ub(), DOUBLE_TOLERANCE); } @Test @@ -178,16 +178,16 @@ void pstGroupVariablesAndConstraintsTest() { @Test void minimumMarginConstraintTest() { - Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getMinimumMarginConstraint(cnec, Side.LEFT, LinearProblem.MarginExtension.ABOVE_THRESHOLD)); - assertEquals("Constraint cnec_id_left_minmargin_above_threshold_constraint has not been created yet", e.getMessage()); - e = assertThrows(OpenRaoException.class, () -> linearProblem.getMinimumMarginConstraint(cnec, Side.LEFT, LinearProblem.MarginExtension.BELOW_THRESHOLD)); - assertEquals("Constraint cnec_id_left_minmargin_below_threshold_constraint has not been created yet", e.getMessage()); - linearProblem.addMinimumMarginConstraint(LB, UB, cnec, Side.LEFT, LinearProblem.MarginExtension.ABOVE_THRESHOLD); - linearProblem.addMinimumMarginConstraint(LB, UB, cnec, Side.LEFT, LinearProblem.MarginExtension.BELOW_THRESHOLD); - assertNotNull(linearProblem.getMinimumMarginConstraint(cnec, Side.LEFT, LinearProblem.MarginExtension.ABOVE_THRESHOLD)); - assertNotNull(linearProblem.getMinimumMarginConstraint(cnec, Side.LEFT, LinearProblem.MarginExtension.BELOW_THRESHOLD)); - assertEquals(LB, linearProblem.getMinimumMarginConstraint(cnec, Side.LEFT, LinearProblem.MarginExtension.ABOVE_THRESHOLD).lb(), DOUBLE_TOLERANCE); - assertEquals(UB, linearProblem.getMinimumMarginConstraint(cnec, Side.LEFT, LinearProblem.MarginExtension.BELOW_THRESHOLD).ub(), DOUBLE_TOLERANCE); + Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getMinimumMarginConstraint(cnec, TwoSides.ONE, LinearProblem.MarginExtension.ABOVE_THRESHOLD)); + assertEquals("Constraint cnec_id_one_minmargin_above_threshold_constraint has not been created yet", e.getMessage()); + e = assertThrows(OpenRaoException.class, () -> linearProblem.getMinimumMarginConstraint(cnec, TwoSides.ONE, LinearProblem.MarginExtension.BELOW_THRESHOLD)); + assertEquals("Constraint cnec_id_one_minmargin_below_threshold_constraint has not been created yet", e.getMessage()); + linearProblem.addMinimumMarginConstraint(LB, UB, cnec, TwoSides.ONE, LinearProblem.MarginExtension.ABOVE_THRESHOLD); + linearProblem.addMinimumMarginConstraint(LB, UB, cnec, TwoSides.ONE, LinearProblem.MarginExtension.BELOW_THRESHOLD); + assertNotNull(linearProblem.getMinimumMarginConstraint(cnec, TwoSides.ONE, LinearProblem.MarginExtension.ABOVE_THRESHOLD)); + assertNotNull(linearProblem.getMinimumMarginConstraint(cnec, TwoSides.ONE, LinearProblem.MarginExtension.BELOW_THRESHOLD)); + assertEquals(LB, linearProblem.getMinimumMarginConstraint(cnec, TwoSides.ONE, LinearProblem.MarginExtension.ABOVE_THRESHOLD).lb(), DOUBLE_TOLERANCE); + assertEquals(UB, linearProblem.getMinimumMarginConstraint(cnec, TwoSides.ONE, LinearProblem.MarginExtension.BELOW_THRESHOLD).ub(), DOUBLE_TOLERANCE); } @Test @@ -226,16 +226,16 @@ void minimumRelMarginSetToZeroConstraintTest() { @Test void maxLoopFlowConstraintTest() { - Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getMaxLoopFlowConstraint(cnec, Side.LEFT, LinearProblem.BoundExtension.UPPER_BOUND)); - assertEquals("Constraint cnec_id_left_maxloopflow_upper_bound_constraint has not been created yet", e.getMessage()); - e = assertThrows(OpenRaoException.class, () -> linearProblem.getMaxLoopFlowConstraint(cnec, Side.LEFT, LinearProblem.BoundExtension.LOWER_BOUND)); - assertEquals("Constraint cnec_id_left_maxloopflow_lower_bound_constraint has not been created yet", e.getMessage()); + Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getMaxLoopFlowConstraint(cnec, TwoSides.ONE, LinearProblem.BoundExtension.UPPER_BOUND)); + assertEquals("Constraint cnec_id_one_maxloopflow_upper_bound_constraint has not been created yet", e.getMessage()); + e = assertThrows(OpenRaoException.class, () -> linearProblem.getMaxLoopFlowConstraint(cnec, TwoSides.ONE, LinearProblem.BoundExtension.LOWER_BOUND)); + assertEquals("Constraint cnec_id_one_maxloopflow_lower_bound_constraint has not been created yet", e.getMessage()); - linearProblem.addMaxLoopFlowConstraint(LB, UB, cnec, Side.LEFT, LinearProblem.BoundExtension.UPPER_BOUND); - linearProblem.addMaxLoopFlowConstraint(LB, UB, cnec, Side.LEFT, LinearProblem.BoundExtension.LOWER_BOUND); + linearProblem.addMaxLoopFlowConstraint(LB, UB, cnec, TwoSides.ONE, LinearProblem.BoundExtension.UPPER_BOUND); + linearProblem.addMaxLoopFlowConstraint(LB, UB, cnec, TwoSides.ONE, LinearProblem.BoundExtension.LOWER_BOUND); - assertEquals(LB, linearProblem.getMaxLoopFlowConstraint(cnec, Side.LEFT, LinearProblem.BoundExtension.UPPER_BOUND).lb(), DOUBLE_TOLERANCE); - assertEquals(UB, linearProblem.getMaxLoopFlowConstraint(cnec, Side.LEFT, LinearProblem.BoundExtension.UPPER_BOUND).ub(), DOUBLE_TOLERANCE); + assertEquals(LB, linearProblem.getMaxLoopFlowConstraint(cnec, TwoSides.ONE, LinearProblem.BoundExtension.UPPER_BOUND).lb(), DOUBLE_TOLERANCE); + assertEquals(UB, linearProblem.getMaxLoopFlowConstraint(cnec, TwoSides.ONE, LinearProblem.BoundExtension.UPPER_BOUND).ub(), DOUBLE_TOLERANCE); } @Test diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/AbstractFillerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/AbstractFillerTest.java index 9e78a520b9..f5589bc28a 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/AbstractFillerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/AbstractFillerTest.java @@ -10,7 +10,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.range.RangeType; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracimpl.utils.NetworkImportsUtil; @@ -79,12 +79,12 @@ void init() throws IOException { pstRangeAction = crac.getPstRangeAction(RANGE_ACTION_ID); flowResult = Mockito.mock(FlowResult.class); - when(flowResult.getFlow(cnec1, Side.LEFT, Unit.MEGAWATT)).thenReturn(REF_FLOW_CNEC1_IT1); - when(flowResult.getFlow(cnec2, Side.RIGHT, Unit.MEGAWATT)).thenReturn(REF_FLOW_CNEC2_IT1); + when(flowResult.getFlow(cnec1, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(REF_FLOW_CNEC1_IT1); + when(flowResult.getFlow(cnec2, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(REF_FLOW_CNEC2_IT1); sensitivityResult = Mockito.mock(SensitivityResult.class); - when(sensitivityResult.getSensitivityValue(cnec1, Side.LEFT, pstRangeAction, Unit.MEGAWATT)).thenReturn(SENSI_CNEC1_IT1); - when(sensitivityResult.getSensitivityValue(cnec2, Side.RIGHT, pstRangeAction, Unit.MEGAWATT)).thenReturn(SENSI_CNEC2_IT1); + when(sensitivityResult.getSensitivityValue(cnec1, TwoSides.ONE, pstRangeAction, Unit.MEGAWATT)).thenReturn(SENSI_CNEC1_IT1); + when(sensitivityResult.getSensitivityValue(cnec2, TwoSides.TWO, pstRangeAction, Unit.MEGAWATT)).thenReturn(SENSI_CNEC2_IT1); when(sensitivityResult.getSensitivityStatus(any())).thenReturn(ComputationStatus.DEFAULT); } diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/CoreProblemFillerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/CoreProblemFillerTest.java index 578c674d0c..f42f6e240e 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/CoreProblemFillerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/CoreProblemFillerTest.java @@ -10,7 +10,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; import com.powsybl.openrao.data.raoresultapi.ComputationStatus; import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; @@ -118,13 +118,13 @@ void fillTestOnPreventive() { assertEquals(LinearProblem.infinity(), absoluteVariationVariable.ub(), INFINITY_TOLERANCE); // check flow variable for cnec1 - OpenRaoMPVariable flowVariable = linearProblem.getFlowVariable(cnec1, Side.LEFT); + OpenRaoMPVariable flowVariable = linearProblem.getFlowVariable(cnec1, TwoSides.ONE); assertNotNull(flowVariable); assertEquals(-LinearProblem.infinity(), flowVariable.lb(), INFINITY_TOLERANCE); assertEquals(LinearProblem.infinity(), flowVariable.ub(), INFINITY_TOLERANCE); // check flow constraint for cnec1 - OpenRaoMPConstraint flowConstraint = linearProblem.getFlowConstraint(cnec1, Side.LEFT); + OpenRaoMPConstraint flowConstraint = linearProblem.getFlowConstraint(cnec1, TwoSides.ONE); assertNotNull(flowConstraint); assertEquals(REF_FLOW_CNEC1_IT1 - initialAlpha * SENSI_CNEC1_IT1, flowConstraint.lb(), DOUBLE_TOLERANCE); assertEquals(REF_FLOW_CNEC1_IT1 - initialAlpha * SENSI_CNEC1_IT1, flowConstraint.ub(), DOUBLE_TOLERANCE); @@ -132,12 +132,12 @@ void fillTestOnPreventive() { assertEquals(-SENSI_CNEC1_IT1, flowConstraint.getCoefficient(setPointVariable), DOUBLE_TOLERANCE); // check flow variable for cnec2 does not exist - Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowVariable(cnec2, Side.RIGHT)); - assertEquals("Variable Tieline BE FR - Defaut - N-1 NL1-NL3_right_flow_variable has not been created yet", e.getMessage()); + Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowVariable(cnec2, TwoSides.TWO)); + assertEquals("Variable Tieline BE FR - Defaut - N-1 NL1-NL3_two_flow_variable has not been created yet", e.getMessage()); // check flow constraint for cnec2 does not exist - e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowConstraint(cnec2, Side.RIGHT)); - assertEquals("Constraint Tieline BE FR - Defaut - N-1 NL1-NL3_right_flow_constraint has not been created yet", e.getMessage()); + e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowConstraint(cnec2, TwoSides.TWO)); + assertEquals("Constraint Tieline BE FR - Defaut - N-1 NL1-NL3_two_flow_constraint has not been created yet", e.getMessage()); // check absolute variation constraints OpenRaoMPConstraint absoluteVariationConstraint1 = linearProblem.getAbsoluteRangeActionVariationConstraint(pstRangeAction, state, LinearProblem.AbsExtension.NEGATIVE); @@ -178,13 +178,13 @@ void fillTestOnPreventiveFiltered() { assertEquals(LinearProblem.infinity(), absoluteVariationVariable.ub(), INFINITY_TOLERANCE); // check flow variable for cnec1 - OpenRaoMPVariable flowVariable = linearProblem.getFlowVariable(cnec1, Side.LEFT); + OpenRaoMPVariable flowVariable = linearProblem.getFlowVariable(cnec1, TwoSides.ONE); assertNotNull(flowVariable); assertEquals(-LinearProblem.infinity(), flowVariable.lb(), INFINITY_TOLERANCE); assertEquals(LinearProblem.infinity(), flowVariable.ub(), INFINITY_TOLERANCE); // check flow constraint for cnec1 - OpenRaoMPConstraint flowConstraint = linearProblem.getFlowConstraint(cnec1, Side.LEFT); + OpenRaoMPConstraint flowConstraint = linearProblem.getFlowConstraint(cnec1, TwoSides.ONE); assertNotNull(flowConstraint); assertEquals(REF_FLOW_CNEC1_IT1 - initialAlpha * 0, flowConstraint.lb(), DOUBLE_TOLERANCE); // sensitivity filtered (= 0) assertEquals(REF_FLOW_CNEC1_IT1 - initialAlpha * 0, flowConstraint.ub(), DOUBLE_TOLERANCE); // sensitivity filtered (= 0) @@ -192,12 +192,12 @@ void fillTestOnPreventiveFiltered() { assertEquals(0, flowConstraint.getCoefficient(setPointVariable), DOUBLE_TOLERANCE); // sensitivity filtered (= 0) // check flow variable for cnec2 does not exist - Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowVariable(cnec2, Side.RIGHT)); - assertEquals("Variable Tieline BE FR - Defaut - N-1 NL1-NL3_right_flow_variable has not been created yet", e.getMessage()); + Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowVariable(cnec2, TwoSides.TWO)); + assertEquals("Variable Tieline BE FR - Defaut - N-1 NL1-NL3_two_flow_variable has not been created yet", e.getMessage()); // check flow constraint for cnec2 does not exist - e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowConstraint(cnec2, Side.RIGHT)); - assertEquals("Constraint Tieline BE FR - Defaut - N-1 NL1-NL3_right_flow_constraint has not been created yet", e.getMessage()); + e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowConstraint(cnec2, TwoSides.TWO)); + assertEquals("Constraint Tieline BE FR - Defaut - N-1 NL1-NL3_two_flow_constraint has not been created yet", e.getMessage()); // check absolute variation constraints OpenRaoMPConstraint absoluteVariationConstraint1 = linearProblem.getAbsoluteRangeActionVariationConstraint(pstRangeAction, state, LinearProblem.AbsExtension.NEGATIVE); @@ -238,21 +238,21 @@ void fillTestOnCurative() { assertEquals(LinearProblem.infinity(), absoluteVariationVariable.ub(), INFINITY_TOLERANCE); // check flow variable for cnec1 does not exist - Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowVariable(cnec1, Side.LEFT)); - assertEquals("Variable Tieline BE FR - N - preventive_left_flow_variable has not been created yet", e.getMessage()); + Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowVariable(cnec1, TwoSides.ONE)); + assertEquals("Variable Tieline BE FR - N - preventive_one_flow_variable has not been created yet", e.getMessage()); // check flow constraint for cnec1 does not exist - e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowConstraint(cnec1, Side.LEFT)); - assertEquals("Constraint Tieline BE FR - N - preventive_left_flow_constraint has not been created yet", e.getMessage()); + e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowConstraint(cnec1, TwoSides.ONE)); + assertEquals("Constraint Tieline BE FR - N - preventive_one_flow_constraint has not been created yet", e.getMessage()); // check flow variable for cnec2 - OpenRaoMPVariable flowVariable2 = linearProblem.getFlowVariable(cnec2, Side.RIGHT); + OpenRaoMPVariable flowVariable2 = linearProblem.getFlowVariable(cnec2, TwoSides.TWO); assertNotNull(flowVariable2); assertEquals(-LinearProblem.infinity(), flowVariable2.lb(), INFINITY_TOLERANCE); assertEquals(LinearProblem.infinity(), flowVariable2.ub(), INFINITY_TOLERANCE); // check flow constraint for cnec2 - OpenRaoMPConstraint flowConstraint2 = linearProblem.getFlowConstraint(cnec2, Side.RIGHT); + OpenRaoMPConstraint flowConstraint2 = linearProblem.getFlowConstraint(cnec2, TwoSides.TWO); assertNotNull(flowConstraint2); assertEquals(REF_FLOW_CNEC2_IT1 - initialAlpha * SENSI_CNEC2_IT1, flowConstraint2.lb(), DOUBLE_TOLERANCE); assertEquals(REF_FLOW_CNEC2_IT1 - initialAlpha * SENSI_CNEC2_IT1, flowConstraint2.ub(), DOUBLE_TOLERANCE); @@ -311,13 +311,13 @@ void fillTestOnGlobal() { assertEquals(LinearProblem.infinity(), curAbsoluteVariationVariable.ub(), INFINITY_TOLERANCE); // check flow variable for cnec1 - OpenRaoMPVariable flowVariable = linearProblem.getFlowVariable(cnec1, Side.LEFT); + OpenRaoMPVariable flowVariable = linearProblem.getFlowVariable(cnec1, TwoSides.ONE); assertNotNull(flowVariable); assertEquals(-LinearProblem.infinity(), flowVariable.lb(), INFINITY_TOLERANCE); assertEquals(LinearProblem.infinity(), flowVariable.ub(), INFINITY_TOLERANCE); // check flow constraint for cnec1 - OpenRaoMPConstraint flowConstraint = linearProblem.getFlowConstraint(cnec1, Side.LEFT); + OpenRaoMPConstraint flowConstraint = linearProblem.getFlowConstraint(cnec1, TwoSides.ONE); assertNotNull(flowConstraint); assertEquals(REF_FLOW_CNEC1_IT1 - initialAlpha * SENSI_CNEC1_IT1, flowConstraint.lb(), DOUBLE_TOLERANCE); assertEquals(REF_FLOW_CNEC1_IT1 - initialAlpha * SENSI_CNEC1_IT1, flowConstraint.ub(), DOUBLE_TOLERANCE); @@ -325,13 +325,13 @@ void fillTestOnGlobal() { assertEquals(-SENSI_CNEC1_IT1, flowConstraint.getCoefficient(prevSetPointVariable), DOUBLE_TOLERANCE); // check flow variable for cnec2 - OpenRaoMPVariable flowVariable2 = linearProblem.getFlowVariable(cnec2, Side.RIGHT); + OpenRaoMPVariable flowVariable2 = linearProblem.getFlowVariable(cnec2, TwoSides.TWO); assertNotNull(flowVariable2); assertEquals(-LinearProblem.infinity(), flowVariable2.lb(), INFINITY_TOLERANCE); assertEquals(LinearProblem.infinity(), flowVariable2.ub(), INFINITY_TOLERANCE); // check flow constraint for cnec2 - OpenRaoMPConstraint flowConstraint2 = linearProblem.getFlowConstraint(cnec2, Side.RIGHT); + OpenRaoMPConstraint flowConstraint2 = linearProblem.getFlowConstraint(cnec2, TwoSides.TWO); assertNotNull(flowConstraint2); assertEquals(REF_FLOW_CNEC2_IT1 - initialAlpha * SENSI_CNEC2_IT1, flowConstraint2.lb(), DOUBLE_TOLERANCE); assertEquals(REF_FLOW_CNEC2_IT1 - initialAlpha * SENSI_CNEC2_IT1, flowConstraint2.ub(), DOUBLE_TOLERANCE); @@ -379,10 +379,10 @@ private void updateLinearProblem() { network.getTwoWindingsTransformer(RANGE_ACTION_ELEMENT_ID).getPhaseTapChanger().setTapPosition(TAP_IT2); initialAlpha = network.getTwoWindingsTransformer(RANGE_ACTION_ELEMENT_ID).getPhaseTapChanger().getCurrentStep().getAlpha(); - when(flowResult.getFlow(cnec1, Side.LEFT, Unit.MEGAWATT)).thenReturn(REF_FLOW_CNEC1_IT2); - when(flowResult.getFlow(cnec2, Side.RIGHT, Unit.MEGAWATT)).thenReturn(REF_FLOW_CNEC2_IT2); - when(sensitivityResult.getSensitivityValue(cnec1, Side.LEFT, pstRangeAction, Unit.MEGAWATT)).thenReturn(SENSI_CNEC1_IT2); - when(sensitivityResult.getSensitivityValue(cnec2, Side.RIGHT, pstRangeAction, Unit.MEGAWATT)).thenReturn(SENSI_CNEC2_IT2); + when(flowResult.getFlow(cnec1, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(REF_FLOW_CNEC1_IT2); + when(flowResult.getFlow(cnec2, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(REF_FLOW_CNEC2_IT2); + when(sensitivityResult.getSensitivityValue(cnec1, TwoSides.ONE, pstRangeAction, Unit.MEGAWATT)).thenReturn(SENSI_CNEC1_IT2); + when(sensitivityResult.getSensitivityValue(cnec2, TwoSides.TWO, pstRangeAction, Unit.MEGAWATT)).thenReturn(SENSI_CNEC2_IT2); // update the problem RangeActionSetpointResult rangeActionSetpointResult = new RangeActionSetpointResultImpl(Map.of(pstRangeAction, initialAlpha)); @@ -402,13 +402,13 @@ void updateTestOnPreventive() { OpenRaoMPVariable setPointVariable = linearProblem.getRangeActionSetpointVariable(pstRangeAction, state); // check flow variable for cnec1 - OpenRaoMPVariable flowVariable = linearProblem.getFlowVariable(cnec1, Side.LEFT); + OpenRaoMPVariable flowVariable = linearProblem.getFlowVariable(cnec1, TwoSides.ONE); assertNotNull(flowVariable); assertEquals(-LinearProblem.infinity(), flowVariable.lb(), INFINITY_TOLERANCE); assertEquals(LinearProblem.infinity(), flowVariable.ub(), INFINITY_TOLERANCE); // check flow constraint for cnec1 - OpenRaoMPConstraint flowConstraint = linearProblem.getFlowConstraint(cnec1, Side.LEFT); + OpenRaoMPConstraint flowConstraint = linearProblem.getFlowConstraint(cnec1, TwoSides.ONE); assertNotNull(flowConstraint); assertEquals(REF_FLOW_CNEC1_IT2 - currentAlpha * SENSI_CNEC1_IT2, flowConstraint.lb(), DOUBLE_TOLERANCE); assertEquals(REF_FLOW_CNEC1_IT2 - currentAlpha * SENSI_CNEC1_IT2, flowConstraint.ub(), DOUBLE_TOLERANCE); @@ -416,12 +416,12 @@ void updateTestOnPreventive() { assertEquals(-SENSI_CNEC1_IT2, flowConstraint.getCoefficient(setPointVariable), DOUBLE_TOLERANCE); // check flow variable for cnec2 does not exist - Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowVariable(cnec2, Side.RIGHT)); - assertEquals("Variable Tieline BE FR - Defaut - N-1 NL1-NL3_right_flow_variable has not been created yet", e.getMessage()); + Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowVariable(cnec2, TwoSides.TWO)); + assertEquals("Variable Tieline BE FR - Defaut - N-1 NL1-NL3_two_flow_variable has not been created yet", e.getMessage()); // check flow constraint for cnec2 does not exist - e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowConstraint(cnec2, Side.RIGHT)); - assertEquals("Constraint Tieline BE FR - Defaut - N-1 NL1-NL3_right_flow_constraint has not been created yet", e.getMessage()); + e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowConstraint(cnec2, TwoSides.TWO)); + assertEquals("Constraint Tieline BE FR - Defaut - N-1 NL1-NL3_two_flow_constraint has not been created yet", e.getMessage()); // check the number of variables and constraints // No iterative relative variation constraint should be created since CoreProblemFiller.raRangeShrinking = false @@ -449,21 +449,21 @@ void updateTestOnCurativeWithRaRangeShrinking() { OpenRaoMPVariable setPointVariable = linearProblem.getRangeActionSetpointVariable(pstRangeAction, state); // check flow variable for cnec1 does not exist - Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowVariable(cnec1, Side.LEFT)); - assertEquals("Variable Tieline BE FR - N - preventive_left_flow_variable has not been created yet", e.getMessage()); + Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowVariable(cnec1, TwoSides.ONE)); + assertEquals("Variable Tieline BE FR - N - preventive_one_flow_variable has not been created yet", e.getMessage()); // check flow constraint for cnec1 does not exist - e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowConstraint(cnec1, Side.LEFT)); - assertEquals("Constraint Tieline BE FR - N - preventive_left_flow_constraint has not been created yet", e.getMessage()); + e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowConstraint(cnec1, TwoSides.ONE)); + assertEquals("Constraint Tieline BE FR - N - preventive_one_flow_constraint has not been created yet", e.getMessage()); // check flow variable for cnec2 - OpenRaoMPVariable flowVariable2 = linearProblem.getFlowVariable(cnec2, Side.RIGHT); + OpenRaoMPVariable flowVariable2 = linearProblem.getFlowVariable(cnec2, TwoSides.TWO); assertNotNull(flowVariable2); assertEquals(-LinearProblem.infinity(), flowVariable2.lb(), INFINITY_TOLERANCE); assertEquals(LinearProblem.infinity(), flowVariable2.ub(), INFINITY_TOLERANCE); // check flow constraint for cnec2 - OpenRaoMPConstraint flowConstraint2 = linearProblem.getFlowConstraint(cnec2, Side.RIGHT); + OpenRaoMPConstraint flowConstraint2 = linearProblem.getFlowConstraint(cnec2, TwoSides.TWO); assertNotNull(flowConstraint2); assertEquals(REF_FLOW_CNEC2_IT2 - currentAlpha * SENSI_CNEC2_IT2, flowConstraint2.lb(), DOUBLE_TOLERANCE); assertEquals(REF_FLOW_CNEC2_IT2 - currentAlpha * SENSI_CNEC2_IT2, flowConstraint2.ub(), DOUBLE_TOLERANCE); @@ -489,12 +489,12 @@ void updateTestOnCurativeWithRaRangeShrinking() { void testSensitivityFilter1() { OpenRaoMPConstraint flowConstraint; OpenRaoMPVariable rangeActionSetpoint; - when(flowResult.getPtdfZonalSum(cnec1, Side.LEFT)).thenReturn(0.5); + when(flowResult.getPtdfZonalSum(cnec1, TwoSides.ONE)).thenReturn(0.5); // (sensi = 2) < 2.5 should be filtered when(flowResult.getMargin(cnec1, Unit.MEGAWATT)).thenReturn(-1.0); initialize(Set.of(cnec1), 2.5, 2.5, 2.5, crac.getPreventiveState(), false); - flowConstraint = linearProblem.getFlowConstraint(cnec1, Side.LEFT); + flowConstraint = linearProblem.getFlowConstraint(cnec1, TwoSides.ONE); rangeActionSetpoint = linearProblem.getRangeActionSetpointVariable(pstRangeAction, cnec1.getState()); assertEquals(0, flowConstraint.getCoefficient(rangeActionSetpoint), DOUBLE_TOLERANCE); assertEquals(500., flowConstraint.lb(), DOUBLE_TOLERANCE); @@ -505,13 +505,13 @@ void testSensitivityFilter1() { void testSensitivityFilter2() { OpenRaoMPConstraint flowConstraint; OpenRaoMPVariable rangeActionSetpoint; - when(flowResult.getPtdfZonalSum(cnec1, Side.LEFT)).thenReturn(0.5); + when(flowResult.getPtdfZonalSum(cnec1, TwoSides.ONE)).thenReturn(0.5); Map tapToAngle = pstRangeAction.getTapToAngleConversionMap(); // (sensi = 2) > 1/.5 should not be filtered - when(flowResult.getMargin(cnec1, Side.LEFT, Unit.MEGAWATT)).thenReturn(-1.0); + when(flowResult.getMargin(cnec1, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(-1.0); initialize(Set.of(cnec1), 1.5, 1.5, 1.5, crac.getPreventiveState(), false); - flowConstraint = linearProblem.getFlowConstraint(cnec1, Side.LEFT); + flowConstraint = linearProblem.getFlowConstraint(cnec1, TwoSides.ONE); rangeActionSetpoint = linearProblem.getRangeActionSetpointVariable(pstRangeAction, cnec1.getState()); assertEquals(-2, flowConstraint.getCoefficient(rangeActionSetpoint), DOUBLE_TOLERANCE); assertEquals(500. - 2 * tapToAngle.get(TAP_INITIAL), flowConstraint.lb(), DOUBLE_TOLERANCE); @@ -529,21 +529,21 @@ void testFilterCnecWithSensiFailure() { OpenRaoMPVariable setPointVariable = linearProblem.getRangeActionSetpointVariable(pstRangeAction, cnec2.getState()); // check flow variable for cnec1 does not exist - Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowVariable(cnec1, Side.LEFT)); - assertEquals("Variable Tieline BE FR - N - preventive_left_flow_variable has not been created yet", e.getMessage()); + Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowVariable(cnec1, TwoSides.ONE)); + assertEquals("Variable Tieline BE FR - N - preventive_one_flow_variable has not been created yet", e.getMessage()); // check flow constraint for cnec1 does not exist - e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowConstraint(cnec1, Side.LEFT)); - assertEquals("Constraint Tieline BE FR - N - preventive_left_flow_constraint has not been created yet", e.getMessage()); + e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowConstraint(cnec1, TwoSides.ONE)); + assertEquals("Constraint Tieline BE FR - N - preventive_one_flow_constraint has not been created yet", e.getMessage()); // check flow variable for cnec2 - OpenRaoMPVariable flowVariable2 = linearProblem.getFlowVariable(cnec2, Side.RIGHT); + OpenRaoMPVariable flowVariable2 = linearProblem.getFlowVariable(cnec2, TwoSides.TWO); assertNotNull(flowVariable2); assertEquals(-LinearProblem.infinity(), flowVariable2.lb(), INFINITY_TOLERANCE); assertEquals(LinearProblem.infinity(), flowVariable2.ub(), INFINITY_TOLERANCE); // check flow constraint for cnec2 - OpenRaoMPConstraint flowConstraint2 = linearProblem.getFlowConstraint(cnec2, Side.RIGHT); + OpenRaoMPConstraint flowConstraint2 = linearProblem.getFlowConstraint(cnec2, TwoSides.TWO); assertNotNull(flowConstraint2); assertEquals(REF_FLOW_CNEC2_IT1 - initialAlpha * SENSI_CNEC2_IT1, flowConstraint2.lb(), DOUBLE_TOLERANCE); assertEquals(REF_FLOW_CNEC2_IT1 - initialAlpha * SENSI_CNEC2_IT1, flowConstraint2.ub(), DOUBLE_TOLERANCE); @@ -564,22 +564,22 @@ void testFilterCnecWithSensiFailureAndUpdateWithoutChange() { OpenRaoMPVariable setPointVariable = linearProblem.getRangeActionSetpointVariable(pstRangeAction, cnec2.getState()); // check flow variable for cnec1 does not exist - Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowVariable(cnec1, Side.LEFT)); - assertEquals("Variable Tieline BE FR - N - preventive_left_flow_variable has not been created yet", e.getMessage()); + Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowVariable(cnec1, TwoSides.ONE)); + assertEquals("Variable Tieline BE FR - N - preventive_one_flow_variable has not been created yet", e.getMessage()); // check flow constraint for cnec1 does not exist - e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowConstraint(cnec1, Side.LEFT)); - assertEquals("Constraint Tieline BE FR - N - preventive_left_flow_constraint has not been created yet", e.getMessage()); + e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowConstraint(cnec1, TwoSides.ONE)); + assertEquals("Constraint Tieline BE FR - N - preventive_one_flow_constraint has not been created yet", e.getMessage()); // check flow variable for cnec2 - OpenRaoMPVariable flowVariable2 = linearProblem.getFlowVariable(cnec2, Side.RIGHT); + OpenRaoMPVariable flowVariable2 = linearProblem.getFlowVariable(cnec2, TwoSides.TWO); assertNotNull(flowVariable2); assertEquals(-LinearProblem.infinity(), flowVariable2.lb(), INFINITY_TOLERANCE); assertEquals(LinearProblem.infinity(), flowVariable2.ub(), INFINITY_TOLERANCE); // check flow constraint for cnec2 final double currentAlpha = pstRangeAction.convertTapToAngle(network.getTwoWindingsTransformer(RANGE_ACTION_ELEMENT_ID).getPhaseTapChanger().getTapPosition()); - OpenRaoMPConstraint flowConstraint2 = linearProblem.getFlowConstraint(cnec2, Side.RIGHT); + OpenRaoMPConstraint flowConstraint2 = linearProblem.getFlowConstraint(cnec2, TwoSides.TWO); assertEquals(REF_FLOW_CNEC2_IT2 - currentAlpha * SENSI_CNEC2_IT2, flowConstraint2.lb(), DOUBLE_TOLERANCE); assertEquals(REF_FLOW_CNEC2_IT2 - currentAlpha * SENSI_CNEC2_IT2, flowConstraint2.ub(), DOUBLE_TOLERANCE); assertEquals(1, flowConstraint2.getCoefficient(flowVariable2), DOUBLE_TOLERANCE); @@ -601,15 +601,15 @@ void testFilterCnecWithSensiFailureAndUpdateWithChange() { updateLinearProblem(); // check flow variable for cnec2 does not exist - Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowVariable(cnec2, Side.RIGHT)); - assertEquals("Variable Tieline BE FR - Defaut - N-1 NL1-NL3_right_flow_variable has not been created yet", e.getMessage()); + Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowVariable(cnec2, TwoSides.TWO)); + assertEquals("Variable Tieline BE FR - Defaut - N-1 NL1-NL3_two_flow_variable has not been created yet", e.getMessage()); // check flow constraint for cnec2 does not exist - e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowConstraint(cnec2, Side.RIGHT)); - assertEquals("Constraint Tieline BE FR - Defaut - N-1 NL1-NL3_right_flow_constraint has not been created yet", e.getMessage()); + e = assertThrows(OpenRaoException.class, () -> linearProblem.getFlowConstraint(cnec2, TwoSides.TWO)); + assertEquals("Constraint Tieline BE FR - Defaut - N-1 NL1-NL3_two_flow_constraint has not been created yet", e.getMessage()); // check flow variable for cnec1 - OpenRaoMPVariable flowVariable1 = linearProblem.getFlowVariable(cnec1, Side.LEFT); + OpenRaoMPVariable flowVariable1 = linearProblem.getFlowVariable(cnec1, TwoSides.ONE); assertNotNull(flowVariable1); assertEquals(-LinearProblem.infinity(), flowVariable1.lb(), INFINITY_TOLERANCE); assertEquals(LinearProblem.infinity(), flowVariable1.ub(), INFINITY_TOLERANCE); @@ -618,7 +618,7 @@ void testFilterCnecWithSensiFailureAndUpdateWithChange() { OpenRaoMPVariable setPointVariable = linearProblem.getRangeActionSetpointVariable(pstRangeAction, cnec1.getState()); // check flow constraint for cnec1 - OpenRaoMPConstraint flowConstraint1 = linearProblem.getFlowConstraint(cnec1, Side.LEFT); + OpenRaoMPConstraint flowConstraint1 = linearProblem.getFlowConstraint(cnec1, TwoSides.ONE); assertNotNull(flowConstraint1); assertEquals(REF_FLOW_CNEC1_IT2 - currentAlpha * SENSI_CNEC1_IT2, flowConstraint1.lb(), DOUBLE_TOLERANCE); assertEquals(REF_FLOW_CNEC1_IT2 - currentAlpha * SENSI_CNEC1_IT2, flowConstraint1.ub(), DOUBLE_TOLERANCE); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/FillersUtilTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/FillersUtilTest.java index e0ad04a3cb..d84bff55db 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/FillersUtilTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/FillersUtilTest.java @@ -10,7 +10,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.raoresultapi.ComputationStatus; import com.powsybl.openrao.searchtreerao.result.api.FlowResult; import com.powsybl.openrao.searchtreerao.result.api.SensitivityResult; @@ -38,10 +38,10 @@ void setUp() { state2 = Mockito.mock(State.class); cnec1 = Mockito.mock(FlowCnec.class); Mockito.when(cnec1.getState()).thenReturn(state1); - Mockito.when(cnec1.getMonitoredSides()).thenReturn(Set.of(Side.LEFT, Side.RIGHT)); + Mockito.when(cnec1.getMonitoredSides()).thenReturn(Set.of(TwoSides.ONE, TwoSides.TWO)); cnec2 = Mockito.mock(FlowCnec.class); Mockito.when(cnec2.getState()).thenReturn(state2); - Mockito.when(cnec2.getMonitoredSides()).thenReturn(Set.of(Side.RIGHT)); + Mockito.when(cnec2.getMonitoredSides()).thenReturn(Set.of(TwoSides.TWO)); cnecs = Set.of(cnec1, cnec2); } @@ -78,23 +78,23 @@ void testGetValidFlowCnecsSensi() { void testGetValidFlowCnecsFlow() { FlowResult flowResult = Mockito.mock(FlowResult.class); - Mockito.when(flowResult.getFlow(cnec1, Side.LEFT, Unit.MEGAWATT)).thenReturn(1.0); - Mockito.when(flowResult.getFlow(cnec1, Side.RIGHT, Unit.MEGAWATT)).thenReturn(Double.NaN); - Mockito.when(flowResult.getFlow(cnec2, Side.LEFT, Unit.MEGAWATT)).thenReturn(Double.NaN); - Mockito.when(flowResult.getFlow(cnec2, Side.RIGHT, Unit.MEGAWATT)).thenReturn(Double.NaN); + Mockito.when(flowResult.getFlow(cnec1, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(1.0); + Mockito.when(flowResult.getFlow(cnec1, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(Double.NaN); + Mockito.when(flowResult.getFlow(cnec2, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(Double.NaN); + Mockito.when(flowResult.getFlow(cnec2, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(Double.NaN); assertEquals(Set.of(), FillersUtil.getFlowCnecsNotNaNFlow(cnecs, flowResult)); - Mockito.when(flowResult.getFlow(cnec1, Side.LEFT, Unit.MEGAWATT)).thenReturn(1.0); - Mockito.when(flowResult.getFlow(cnec1, Side.RIGHT, Unit.MEGAWATT)).thenReturn(1.0); - Mockito.when(flowResult.getFlow(cnec2, Side.LEFT, Unit.MEGAWATT)).thenReturn(1.0); - Mockito.when(flowResult.getFlow(cnec2, Side.RIGHT, Unit.MEGAWATT)).thenReturn(Double.NaN); + Mockito.when(flowResult.getFlow(cnec1, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(1.0); + Mockito.when(flowResult.getFlow(cnec1, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(1.0); + Mockito.when(flowResult.getFlow(cnec2, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(1.0); + Mockito.when(flowResult.getFlow(cnec2, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(Double.NaN); assertEquals(Set.of(cnec1), FillersUtil.getFlowCnecsNotNaNFlow(cnecs, flowResult)); - Mockito.when(flowResult.getFlow(cnec1, Side.LEFT, Unit.MEGAWATT)).thenReturn(1.0); - Mockito.when(flowResult.getFlow(cnec1, Side.RIGHT, Unit.MEGAWATT)).thenReturn(Double.NaN); - Mockito.when(flowResult.getFlow(cnec1, Side.RIGHT, Unit.AMPERE)).thenReturn(4.0); - Mockito.when(flowResult.getFlow(cnec2, Side.LEFT, Unit.MEGAWATT)).thenReturn(Double.NaN); - Mockito.when(flowResult.getFlow(cnec2, Side.RIGHT, Unit.MEGAWATT)).thenReturn(3.0); + Mockito.when(flowResult.getFlow(cnec1, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(1.0); + Mockito.when(flowResult.getFlow(cnec1, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(Double.NaN); + Mockito.when(flowResult.getFlow(cnec1, TwoSides.TWO, Unit.AMPERE)).thenReturn(4.0); + Mockito.when(flowResult.getFlow(cnec2, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(Double.NaN); + Mockito.when(flowResult.getFlow(cnec2, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(3.0); assertEquals(Set.of(cnec2), FillersUtil.getFlowCnecsNotNaNFlow(cnecs, flowResult)); } } diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxLoopFlowFillerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxLoopFlowFillerTest.java index 2a0043ac9d..961ab55a5e 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxLoopFlowFillerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxLoopFlowFillerTest.java @@ -11,7 +11,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; import com.powsybl.openrao.data.cracloopflowextension.LoopFlowThresholdAdder; import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; @@ -58,8 +58,8 @@ public void setUp() throws IOException { .withId("cnec-2-sides") .withNetworkElement("BBE2AA1 FFR3AA1 1") .withInstant(PREVENTIVE_INSTANT_ID) - .newThreshold().withUnit(Unit.MEGAWATT).withMax(1000.).withSide(Side.LEFT).add() - .newThreshold().withUnit(Unit.MEGAWATT).withMax(1000.).withSide(Side.RIGHT).add() + .newThreshold().withUnit(Unit.MEGAWATT).withMax(1000.).withSide(TwoSides.ONE).add() + .newThreshold().withUnit(Unit.MEGAWATT).withMax(1000.).withSide(TwoSides.TWO).add() .add(); cnecOn2sides.newExtension(LoopFlowThresholdAdder.class).withValue(100.).withUnit(Unit.MEGAWATT).add(); @@ -87,7 +87,7 @@ public void setUp() throws IOException { private void createMaxLoopFlowFiller(double initialLoopFlowValue) { FlowResult initialFlowResult = Mockito.mock(FlowResult.class); - when(initialFlowResult.getLoopFlow(cnec1, Side.LEFT, Unit.MEGAWATT)).thenReturn(initialLoopFlowValue); + when(initialFlowResult.getLoopFlow(cnec1, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(initialLoopFlowValue); maxLoopFlowFiller = new MaxLoopFlowFiller( Set.of(cnec1), initialFlowResult, @@ -96,7 +96,7 @@ private void createMaxLoopFlowFiller(double initialLoopFlowValue) { } private void setCommercialFlowValue(double commercialFlowValue) { - when(flowResult.getCommercialFlow(cnec1, Side.LEFT, Unit.MEGAWATT)).thenReturn(commercialFlowValue); + when(flowResult.getCommercialFlow(cnec1, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(commercialFlowValue); } private void buildLinearProblem() { @@ -125,8 +125,8 @@ void testFill1() { buildLinearProblem(); // check flow constraint for cnec1 - OpenRaoMPConstraint loopFlowConstraintUb = linearProblem.getMaxLoopFlowConstraint(cnec1, Side.LEFT, LinearProblem.BoundExtension.UPPER_BOUND); - OpenRaoMPConstraint loopFlowConstraintLb = linearProblem.getMaxLoopFlowConstraint(cnec1, Side.LEFT, LinearProblem.BoundExtension.LOWER_BOUND); + OpenRaoMPConstraint loopFlowConstraintUb = linearProblem.getMaxLoopFlowConstraint(cnec1, TwoSides.ONE, LinearProblem.BoundExtension.UPPER_BOUND); + OpenRaoMPConstraint loopFlowConstraintLb = linearProblem.getMaxLoopFlowConstraint(cnec1, TwoSides.ONE, LinearProblem.BoundExtension.LOWER_BOUND); assertNotNull(loopFlowConstraintUb); assertNotNull(loopFlowConstraintLb); @@ -134,12 +134,12 @@ void testFill1() { assertEquals(-(100 - 5.) + 49.0 - 0.01, loopFlowConstraintLb.lb(), DOUBLE_TOLERANCE); assertEquals((100 - 5.) + 49.0 + 0.01, loopFlowConstraintUb.ub(), DOUBLE_TOLERANCE); - OpenRaoMPVariable flowVariable = linearProblem.getFlowVariable(cnec1, Side.LEFT); + OpenRaoMPVariable flowVariable = linearProblem.getFlowVariable(cnec1, TwoSides.ONE); assertEquals(1, loopFlowConstraintUb.getCoefficient(flowVariable), 0.1); assertEquals(1, loopFlowConstraintLb.getCoefficient(flowVariable), 0.1); // violation cost - assertEquals(10., linearProblem.getObjective().getCoefficient(linearProblem.getLoopflowViolationVariable(cnec1, Side.LEFT)), DOUBLE_TOLERANCE); + assertEquals(10., linearProblem.getObjective().getCoefficient(linearProblem.getLoopflowViolationVariable(cnec1, TwoSides.ONE)), DOUBLE_TOLERANCE); } @Test @@ -155,8 +155,8 @@ void testFill2() { buildLinearProblem(); // check flow constraint for cnec1 - OpenRaoMPConstraint loopFlowConstraintUb = linearProblem.getMaxLoopFlowConstraint(cnec1, Side.LEFT, LinearProblem.BoundExtension.UPPER_BOUND); - OpenRaoMPConstraint loopFlowConstraintLb = linearProblem.getMaxLoopFlowConstraint(cnec1, Side.LEFT, LinearProblem.BoundExtension.LOWER_BOUND); + OpenRaoMPConstraint loopFlowConstraintUb = linearProblem.getMaxLoopFlowConstraint(cnec1, TwoSides.ONE, LinearProblem.BoundExtension.UPPER_BOUND); + OpenRaoMPConstraint loopFlowConstraintLb = linearProblem.getMaxLoopFlowConstraint(cnec1, TwoSides.ONE, LinearProblem.BoundExtension.LOWER_BOUND); assertNotNull(loopFlowConstraintUb); assertNotNull(loopFlowConstraintLb); @@ -164,7 +164,7 @@ void testFill2() { assertEquals(-(110 - 5.) + 49.0 - 0.01, loopFlowConstraintLb.lb(), DOUBLE_TOLERANCE); assertEquals((110 - 5.) + 49.0 + 0.01, loopFlowConstraintUb.ub(), DOUBLE_TOLERANCE); - OpenRaoMPVariable flowVariable = linearProblem.getFlowVariable(cnec1, Side.LEFT); + OpenRaoMPVariable flowVariable = linearProblem.getFlowVariable(cnec1, TwoSides.ONE); assertEquals(1, loopFlowConstraintUb.getCoefficient(flowVariable), DOUBLE_TOLERANCE); assertEquals(1, loopFlowConstraintLb.getCoefficient(flowVariable), DOUBLE_TOLERANCE); } @@ -186,13 +186,13 @@ void testShouldUpdate() { updateLinearProblem(); // check flow constraint for cnec1 - OpenRaoMPConstraint loopFlowConstraintUb = linearProblem.getMaxLoopFlowConstraint(cnec1, Side.LEFT, LinearProblem.BoundExtension.UPPER_BOUND); - OpenRaoMPConstraint loopFlowConstraintLb = linearProblem.getMaxLoopFlowConstraint(cnec1, Side.LEFT, LinearProblem.BoundExtension.LOWER_BOUND); + OpenRaoMPConstraint loopFlowConstraintUb = linearProblem.getMaxLoopFlowConstraint(cnec1, TwoSides.ONE, LinearProblem.BoundExtension.UPPER_BOUND); + OpenRaoMPConstraint loopFlowConstraintLb = linearProblem.getMaxLoopFlowConstraint(cnec1, TwoSides.ONE, LinearProblem.BoundExtension.LOWER_BOUND); assertEquals(-(100 - 5.) + 67.0 - 0.01, loopFlowConstraintLb.lb(), DOUBLE_TOLERANCE); assertEquals((100 - 5.) + 67.0 + 0.01, loopFlowConstraintUb.ub(), DOUBLE_TOLERANCE); - OpenRaoMPVariable flowVariable = linearProblem.getFlowVariable(cnec1, Side.LEFT); + OpenRaoMPVariable flowVariable = linearProblem.getFlowVariable(cnec1, TwoSides.ONE); assertEquals(1, loopFlowConstraintUb.getCoefficient(flowVariable), DOUBLE_TOLERANCE); assertEquals(1, loopFlowConstraintLb.getCoefficient(flowVariable), DOUBLE_TOLERANCE); } @@ -206,22 +206,22 @@ void testFill2Sides() { loopFlowParameters.setConstraintAdjustmentCoefficient(5); FlowResult initialFlowResult = Mockito.mock(FlowResult.class); - when(initialFlowResult.getLoopFlow(cnecOn2sides, Side.LEFT, Unit.MEGAWATT)).thenReturn(0.); - when(initialFlowResult.getLoopFlow(cnecOn2sides, Side.RIGHT, Unit.MEGAWATT)).thenReturn(10.); + when(initialFlowResult.getLoopFlow(cnecOn2sides, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(0.); + when(initialFlowResult.getLoopFlow(cnecOn2sides, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(10.); maxLoopFlowFiller = new MaxLoopFlowFiller( Set.of(cnecOn2sides), initialFlowResult, loopFlowParameters ); - when(flowResult.getCommercialFlow(cnecOn2sides, Side.LEFT, Unit.MEGAWATT)).thenReturn(49.); - when(flowResult.getCommercialFlow(cnecOn2sides, Side.RIGHT, Unit.MEGAWATT)).thenReturn(69.); + when(flowResult.getCommercialFlow(cnecOn2sides, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(49.); + when(flowResult.getCommercialFlow(cnecOn2sides, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(69.); buildLinearProblem(); // Check left side - OpenRaoMPConstraint loopFlowConstraintUb = linearProblem.getMaxLoopFlowConstraint(cnecOn2sides, Side.LEFT, LinearProblem.BoundExtension.UPPER_BOUND); - OpenRaoMPConstraint loopFlowConstraintLb = linearProblem.getMaxLoopFlowConstraint(cnecOn2sides, Side.LEFT, LinearProblem.BoundExtension.LOWER_BOUND); + OpenRaoMPConstraint loopFlowConstraintUb = linearProblem.getMaxLoopFlowConstraint(cnecOn2sides, TwoSides.ONE, LinearProblem.BoundExtension.UPPER_BOUND); + OpenRaoMPConstraint loopFlowConstraintLb = linearProblem.getMaxLoopFlowConstraint(cnecOn2sides, TwoSides.ONE, LinearProblem.BoundExtension.LOWER_BOUND); assertNotNull(loopFlowConstraintUb); assertNotNull(loopFlowConstraintLb); @@ -229,13 +229,13 @@ void testFill2Sides() { assertEquals(-(100 - 5.) + 49.0 - 0.01, loopFlowConstraintLb.lb(), DOUBLE_TOLERANCE); assertEquals((100 - 5.) + 49.0 + 0.01, loopFlowConstraintUb.ub(), DOUBLE_TOLERANCE); - OpenRaoMPVariable flowVariable = linearProblem.getFlowVariable(cnecOn2sides, Side.LEFT); + OpenRaoMPVariable flowVariable = linearProblem.getFlowVariable(cnecOn2sides, TwoSides.ONE); assertEquals(1, loopFlowConstraintUb.getCoefficient(flowVariable), 0.1); assertEquals(1, loopFlowConstraintLb.getCoefficient(flowVariable), 0.1); // Check right side - loopFlowConstraintUb = linearProblem.getMaxLoopFlowConstraint(cnecOn2sides, Side.RIGHT, LinearProblem.BoundExtension.UPPER_BOUND); - loopFlowConstraintLb = linearProblem.getMaxLoopFlowConstraint(cnecOn2sides, Side.RIGHT, LinearProblem.BoundExtension.LOWER_BOUND); + loopFlowConstraintUb = linearProblem.getMaxLoopFlowConstraint(cnecOn2sides, TwoSides.TWO, LinearProblem.BoundExtension.UPPER_BOUND); + loopFlowConstraintLb = linearProblem.getMaxLoopFlowConstraint(cnecOn2sides, TwoSides.TWO, LinearProblem.BoundExtension.LOWER_BOUND); assertNotNull(loopFlowConstraintUb); assertNotNull(loopFlowConstraintLb); @@ -243,13 +243,13 @@ void testFill2Sides() { assertEquals(-(100 - 5.) + 69.0 - 0.01, loopFlowConstraintLb.lb(), DOUBLE_TOLERANCE); assertEquals((100 - 5.) + 69.0 + 0.01, loopFlowConstraintUb.ub(), DOUBLE_TOLERANCE); - flowVariable = linearProblem.getFlowVariable(cnecOn2sides, Side.RIGHT); + flowVariable = linearProblem.getFlowVariable(cnecOn2sides, TwoSides.TWO); assertEquals(1, loopFlowConstraintUb.getCoefficient(flowVariable), 0.1); assertEquals(1, loopFlowConstraintLb.getCoefficient(flowVariable), 0.1); // violation cost - assertEquals(10. / 2, linearProblem.getObjective().getCoefficient(linearProblem.getLoopflowViolationVariable(cnecOn2sides, Side.LEFT)), DOUBLE_TOLERANCE); - assertEquals(10. / 2, linearProblem.getObjective().getCoefficient(linearProblem.getLoopflowViolationVariable(cnecOn2sides, Side.RIGHT)), DOUBLE_TOLERANCE); + assertEquals(10. / 2, linearProblem.getObjective().getCoefficient(linearProblem.getLoopflowViolationVariable(cnecOn2sides, TwoSides.ONE)), DOUBLE_TOLERANCE); + assertEquals(10. / 2, linearProblem.getObjective().getCoefficient(linearProblem.getLoopflowViolationVariable(cnecOn2sides, TwoSides.TWO)), DOUBLE_TOLERANCE); } @Test @@ -261,8 +261,8 @@ void testFilterCnecWithNoInitialFlow() { loopFlowParameters.setConstraintAdjustmentCoefficient(5); FlowResult initialFlowResult = Mockito.mock(FlowResult.class); - when(initialFlowResult.getLoopFlow(cnec1, Side.LEFT, Unit.MEGAWATT)).thenReturn(90.); - when(initialFlowResult.getFlow(cnec1, Side.LEFT, Unit.MEGAWATT)).thenReturn(Double.NaN); + when(initialFlowResult.getLoopFlow(cnec1, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(90.); + when(initialFlowResult.getFlow(cnec1, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(Double.NaN); maxLoopFlowFiller = new MaxLoopFlowFiller( Set.of(cnec1), initialFlowResult, @@ -271,11 +271,11 @@ void testFilterCnecWithNoInitialFlow() { setCommercialFlowValue(49); buildLinearProblem(); - Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getMaxLoopFlowConstraint(cnec1, Side.LEFT, LinearProblem.BoundExtension.UPPER_BOUND)); - assertEquals("Constraint Tieline BE FR - N - preventive_left_maxloopflow_upper_bound_constraint has not been created yet", e.getMessage()); - e = assertThrows(OpenRaoException.class, () -> linearProblem.getMaxLoopFlowConstraint(cnec1, Side.LEFT, LinearProblem.BoundExtension.LOWER_BOUND)); - assertEquals("Constraint Tieline BE FR - N - preventive_left_maxloopflow_lower_bound_constraint has not been created yet", e.getMessage()); - e = assertThrows(OpenRaoException.class, () -> linearProblem.getLoopflowViolationVariable(cnec1, Side.LEFT)); - assertEquals("Variable Tieline BE FR - N - preventive_left_loopflowviolation_variable has not been created yet", e.getMessage()); + Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getMaxLoopFlowConstraint(cnec1, TwoSides.ONE, LinearProblem.BoundExtension.UPPER_BOUND)); + assertEquals("Constraint Tieline BE FR - N - preventive_one_maxloopflow_upper_bound_constraint has not been created yet", e.getMessage()); + e = assertThrows(OpenRaoException.class, () -> linearProblem.getMaxLoopFlowConstraint(cnec1, TwoSides.ONE, LinearProblem.BoundExtension.LOWER_BOUND)); + assertEquals("Constraint Tieline BE FR - N - preventive_one_maxloopflow_lower_bound_constraint has not been created yet", e.getMessage()); + e = assertThrows(OpenRaoException.class, () -> linearProblem.getLoopflowViolationVariable(cnec1, TwoSides.ONE)); + assertEquals("Variable Tieline BE FR - N - preventive_one_loopflowviolation_variable has not been created yet", e.getMessage()); } } diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxMinMarginFillerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxMinMarginFillerTest.java index 5a06a6ba2d..cc99226e86 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxMinMarginFillerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxMinMarginFillerTest.java @@ -9,7 +9,7 @@ import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.State; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; import com.powsybl.openrao.raoapi.parameters.RaoParameters; @@ -89,7 +89,7 @@ void fillWithMaxMinMarginInMegawatt() { createMaxMinMarginFiller(Unit.MEGAWATT); buildLinearProblem(); - OpenRaoMPVariable flowCnec1 = linearProblem.getFlowVariable(cnec1, Side.LEFT); + OpenRaoMPVariable flowCnec1 = linearProblem.getFlowVariable(cnec1, TwoSides.ONE); OpenRaoMPVariable absoluteVariation = linearProblem.getAbsoluteRangeActionVariationVariable(pstRangeAction, cnec1.getState()); // check minimum margin variable @@ -97,8 +97,8 @@ void fillWithMaxMinMarginInMegawatt() { assertNotNull(minimumMargin); // check minimum margin constraints - OpenRaoMPConstraint cnec1AboveThreshold = linearProblem.getMinimumMarginConstraint(cnec1, Side.LEFT, LinearProblem.MarginExtension.ABOVE_THRESHOLD); - OpenRaoMPConstraint cnec1BelowThreshold = linearProblem.getMinimumMarginConstraint(cnec1, Side.LEFT, LinearProblem.MarginExtension.BELOW_THRESHOLD); + OpenRaoMPConstraint cnec1AboveThreshold = linearProblem.getMinimumMarginConstraint(cnec1, TwoSides.ONE, LinearProblem.MarginExtension.ABOVE_THRESHOLD); + OpenRaoMPConstraint cnec1BelowThreshold = linearProblem.getMinimumMarginConstraint(cnec1, TwoSides.ONE, LinearProblem.MarginExtension.BELOW_THRESHOLD); assertNotNull(cnec1AboveThreshold); assertNotNull(cnec1BelowThreshold); assertEquals(-LinearProblem.infinity(), cnec1BelowThreshold.lb(), INFINITY_TOLERANCE); @@ -131,7 +131,7 @@ void fillWithMaxMinMarginInAmpere() { createMaxMinMarginFiller(Unit.AMPERE); buildLinearProblem(); - OpenRaoMPVariable flowCnec1 = linearProblem.getFlowVariable(cnec1, Side.LEFT); + OpenRaoMPVariable flowCnec1 = linearProblem.getFlowVariable(cnec1, TwoSides.ONE); OpenRaoMPVariable absoluteVariation = linearProblem.getAbsoluteRangeActionVariationVariable(pstRangeAction, cnec1.getState()); // check minimum margin variable @@ -139,8 +139,8 @@ void fillWithMaxMinMarginInAmpere() { assertNotNull(minimumMargin); // check minimum margin constraints - OpenRaoMPConstraint cnec1AboveThreshold = linearProblem.getMinimumMarginConstraint(cnec1, Side.LEFT, LinearProblem.MarginExtension.ABOVE_THRESHOLD); - OpenRaoMPConstraint cnec1BelowThreshold = linearProblem.getMinimumMarginConstraint(cnec1, Side.LEFT, LinearProblem.MarginExtension.BELOW_THRESHOLD); + OpenRaoMPConstraint cnec1AboveThreshold = linearProblem.getMinimumMarginConstraint(cnec1, TwoSides.ONE, LinearProblem.MarginExtension.ABOVE_THRESHOLD); + OpenRaoMPConstraint cnec1BelowThreshold = linearProblem.getMinimumMarginConstraint(cnec1, TwoSides.ONE, LinearProblem.MarginExtension.BELOW_THRESHOLD); assertNotNull(cnec1AboveThreshold); assertNotNull(cnec1BelowThreshold); assertEquals(-LinearProblem.infinity(), cnec1BelowThreshold.lb(), INFINITY_TOLERANCE); @@ -174,7 +174,7 @@ void fillWithMissingFlowVariables() { // AbsoluteRangeActionVariables present, but no the FlowVariables linearProblem.addAbsoluteRangeActionVariationVariable(0.0, 0.0, pstRangeAction, cnec1.getState()); Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.fill(flowResult, sensitivityResult)); - assertEquals("Variable Tieline BE FR - N - preventive_left_flow_variable has not been created yet", e.getMessage()); + assertEquals("Variable Tieline BE FR - N - preventive_one_flow_variable has not been created yet", e.getMessage()); } @Test @@ -189,8 +189,8 @@ void fillWithMissingRangeActionVariables() { // FlowVariables present , but not the absoluteRangeActionVariables present, // This should work since range actions can be filtered out by the CoreProblemFiller if their number // exceeds the max-pst-per-tso parameter - linearProblem.addFlowVariable(0.0, 0.0, cnec1, Side.LEFT); - linearProblem.addFlowVariable(0.0, 0.0, cnec2, Side.RIGHT); + linearProblem.addFlowVariable(0.0, 0.0, cnec1, TwoSides.ONE); + linearProblem.addFlowVariable(0.0, 0.0, cnec2, TwoSides.TWO); linearProblem.fill(flowResult, sensitivityResult); } catch (Exception e) { fail(); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxMinRelativeMarginFillerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxMinRelativeMarginFillerTest.java index 96665c7064..f0673aa77a 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxMinRelativeMarginFillerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxMinRelativeMarginFillerTest.java @@ -9,7 +9,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.State; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; import com.powsybl.openrao.raoapi.parameters.ObjectiveFunctionParameters; import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; @@ -88,7 +88,7 @@ public void setUp() throws IOException { private void createMaxMinRelativeMarginFiller(Unit unit, double cnecInitialAbsolutePtdfSum) { FlowResult initialFlowResult = Mockito.mock(FlowResult.class); - when(initialFlowResult.getPtdfZonalSum(cnec1, Side.LEFT)).thenReturn(cnecInitialAbsolutePtdfSum); + when(initialFlowResult.getPtdfZonalSum(cnec1, TwoSides.ONE)).thenReturn(cnecInitialAbsolutePtdfSum); maxMinRelativeMarginFiller = new MaxMinRelativeMarginFiller( Set.of(cnec1), initialFlowResult, @@ -118,7 +118,7 @@ void fillWithMaxMinRelativeMarginInAmpere() { createMaxMinRelativeMarginFiller(AMPERE, 0.005); buildLinearProblem(); - OpenRaoMPVariable flowCnec1 = linearProblem.getFlowVariable(cnec1, Side.LEFT); + OpenRaoMPVariable flowCnec1 = linearProblem.getFlowVariable(cnec1, TwoSides.ONE); OpenRaoMPVariable absoluteVariation = linearProblem.getAbsoluteRangeActionVariationVariable(pstRangeAction, cnec1.getState()); // check minimum margin variable @@ -129,10 +129,10 @@ void fillWithMaxMinRelativeMarginInAmpere() { assertNotNull(minimumRelativeMargin); // check minimum margin constraints - OpenRaoMPConstraint cnec1AboveThreshold = linearProblem.getMinimumMarginConstraint(cnec1, Side.LEFT, LinearProblem.MarginExtension.ABOVE_THRESHOLD); - OpenRaoMPConstraint cnec1BelowThreshold = linearProblem.getMinimumMarginConstraint(cnec1, Side.LEFT, LinearProblem.MarginExtension.BELOW_THRESHOLD); - OpenRaoMPConstraint cnec1AboveThresholdRelative = linearProblem.getMinimumRelativeMarginConstraint(cnec1, Side.LEFT, LinearProblem.MarginExtension.ABOVE_THRESHOLD); - OpenRaoMPConstraint cnec1BelowThresholdRelative = linearProblem.getMinimumRelativeMarginConstraint(cnec1, Side.LEFT, LinearProblem.MarginExtension.BELOW_THRESHOLD); + OpenRaoMPConstraint cnec1AboveThreshold = linearProblem.getMinimumMarginConstraint(cnec1, TwoSides.ONE, LinearProblem.MarginExtension.ABOVE_THRESHOLD); + OpenRaoMPConstraint cnec1BelowThreshold = linearProblem.getMinimumMarginConstraint(cnec1, TwoSides.ONE, LinearProblem.MarginExtension.BELOW_THRESHOLD); + OpenRaoMPConstraint cnec1AboveThresholdRelative = linearProblem.getMinimumRelativeMarginConstraint(cnec1, TwoSides.ONE, LinearProblem.MarginExtension.ABOVE_THRESHOLD); + OpenRaoMPConstraint cnec1BelowThresholdRelative = linearProblem.getMinimumRelativeMarginConstraint(cnec1, TwoSides.ONE, LinearProblem.MarginExtension.BELOW_THRESHOLD); assertNotNull(cnec1AboveThreshold); assertNotNull(cnec1BelowThreshold); assertEquals(-LinearProblem.infinity(), cnec1BelowThreshold.lb(), INFINITY_TOLERANCE); @@ -162,7 +162,7 @@ void fillWithMaxMinRelativeMarginInAmpere() { private FlowResult mockFlowResult(double cnecAbsolutePtdfSum) { FlowResult mockedFlowResult = Mockito.mock(FlowResult.class); - when(mockedFlowResult.getPtdfZonalSum(cnec1, Side.LEFT)).thenReturn(cnecAbsolutePtdfSum); + when(mockedFlowResult.getPtdfZonalSum(cnec1, TwoSides.ONE)).thenReturn(cnecAbsolutePtdfSum); return mockedFlowResult; } @@ -178,7 +178,7 @@ void testMustNotUpdatePtdf() { void testMustUpdatePtdf() { parameters.setPtdfApproximation(PtdfApproximation.UPDATE_PTDF_WITH_TOPO_AND_PST); FlowResult initialFlowResult = Mockito.mock(FlowResult.class); - when(initialFlowResult.getPtdfZonalSum(cnec1, Side.LEFT)).thenReturn(0.9); + when(initialFlowResult.getPtdfZonalSum(cnec1, TwoSides.ONE)).thenReturn(0.9); maxMinRelativeMarginFiller = new MaxMinRelativeMarginFiller( Set.of(cnec1), initialFlowResult, @@ -191,7 +191,7 @@ void testMustUpdatePtdf() { } private void checkFillerContentMw(double expectedPtdfSum) { - OpenRaoMPVariable flowCnec1 = linearProblem.getFlowVariable(cnec1, Side.LEFT); + OpenRaoMPVariable flowCnec1 = linearProblem.getFlowVariable(cnec1, TwoSides.ONE); OpenRaoMPVariable absoluteVariation = linearProblem.getAbsoluteRangeActionVariationVariable(pstRangeAction, cnec1.getState()); // check minimum margin variable @@ -200,10 +200,10 @@ private void checkFillerContentMw(double expectedPtdfSum) { OpenRaoMPVariable minimumRelativeMargin = linearProblem.getMinimumRelativeMarginVariable(); // check minimum margin constraints - OpenRaoMPConstraint cnec1AboveThreshold = linearProblem.getMinimumMarginConstraint(cnec1, Side.LEFT, LinearProblem.MarginExtension.ABOVE_THRESHOLD); - OpenRaoMPConstraint cnec1BelowThreshold = linearProblem.getMinimumMarginConstraint(cnec1, Side.LEFT, LinearProblem.MarginExtension.BELOW_THRESHOLD); - OpenRaoMPConstraint cnec1AboveThresholdRelative = linearProblem.getMinimumRelativeMarginConstraint(cnec1, Side.LEFT, LinearProblem.MarginExtension.ABOVE_THRESHOLD); - OpenRaoMPConstraint cnec1BelowThresholdRelative = linearProblem.getMinimumRelativeMarginConstraint(cnec1, Side.LEFT, LinearProblem.MarginExtension.BELOW_THRESHOLD); + OpenRaoMPConstraint cnec1AboveThreshold = linearProblem.getMinimumMarginConstraint(cnec1, TwoSides.ONE, LinearProblem.MarginExtension.ABOVE_THRESHOLD); + OpenRaoMPConstraint cnec1BelowThreshold = linearProblem.getMinimumMarginConstraint(cnec1, TwoSides.ONE, LinearProblem.MarginExtension.BELOW_THRESHOLD); + OpenRaoMPConstraint cnec1AboveThresholdRelative = linearProblem.getMinimumRelativeMarginConstraint(cnec1, TwoSides.ONE, LinearProblem.MarginExtension.ABOVE_THRESHOLD); + OpenRaoMPConstraint cnec1BelowThresholdRelative = linearProblem.getMinimumRelativeMarginConstraint(cnec1, TwoSides.ONE, LinearProblem.MarginExtension.BELOW_THRESHOLD); assertEquals(-LinearProblem.infinity(), cnec1BelowThreshold.lb(), INFINITY_TOLERANCE); assertEquals(-MIN_FLOW_1, cnec1BelowThreshold.ub(), DOUBLE_TOLERANCE); assertEquals(-LinearProblem.infinity(), cnec1AboveThreshold.lb(), INFINITY_TOLERANCE); @@ -232,7 +232,7 @@ void testPtdfIsNaN() { parameters.setPtdfApproximation(PtdfApproximation.UPDATE_PTDF_WITH_TOPO_AND_PST); parameters.setPtdfSumLowerBound(0.1234); FlowResult initialFlowResult = Mockito.mock(FlowResult.class); - when(initialFlowResult.getPtdfZonalSum(cnec1, Side.LEFT)).thenReturn(Double.NaN); + when(initialFlowResult.getPtdfZonalSum(cnec1, TwoSides.ONE)).thenReturn(Double.NaN); maxMinRelativeMarginFiller = new MaxMinRelativeMarginFiller( Set.of(cnec1), initialFlowResult, diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MnecFillerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MnecFillerTest.java index d77d949851..56ad7840f2 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MnecFillerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MnecFillerTest.java @@ -13,7 +13,7 @@ import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.Cnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; import com.powsybl.openrao.data.raoresultapi.ComputationStatus; import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; @@ -53,7 +53,7 @@ public void setUp() throws IOException { .withNetworkElement("DDE2AA1 NNL3AA1 1") .newThreshold() .withMin(-1000.) - .withSide(Side.RIGHT) + .withSide(TwoSides.TWO) .withMax(1000.0) .withUnit(Unit.MEGAWATT) .add() @@ -68,7 +68,7 @@ public void setUp() throws IOException { .withNetworkElement("NNL2AA1 BBE3AA1 1") .newThreshold() .withMin(-100.) - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .withMax(100.0) .withUnit(Unit.MEGAWATT) .add() @@ -81,8 +81,8 @@ public void setUp() throws IOException { mnec3 = crac.newFlowCnec() .withId("MNEC3 - curative") .withNetworkElement("NNL2AA1 BBE3AA1 1") - .newThreshold().withMin(-100.).withSide(Side.LEFT).withMax(100.0).withUnit(Unit.MEGAWATT).add() - .newThreshold().withMin(-100.).withSide(Side.RIGHT).withMax(100.0).withUnit(Unit.MEGAWATT).add() + .newThreshold().withMin(-100.).withSide(TwoSides.ONE).withMax(100.0).withUnit(Unit.MEGAWATT).add() + .newThreshold().withMin(-100.).withSide(TwoSides.TWO).withMax(100.0).withUnit(Unit.MEGAWATT).add() .withNominalVoltage(380.) .withOptimized(true) .withMonitored(true) @@ -120,10 +120,10 @@ private void fillProblemWithFiller(Unit unit) { parameters.setViolationCost(10); parameters.setConstraintAdjustmentCoefficient(3.5); FlowResult flowResult = Mockito.mock(FlowResult.class); - when(flowResult.getFlow(mnec1, Side.RIGHT, Unit.MEGAWATT)).thenReturn(900.); - when(flowResult.getFlow(mnec2, Side.LEFT, Unit.MEGAWATT)).thenReturn(-200.); - when(flowResult.getFlow(mnec3, Side.LEFT, Unit.MEGAWATT)).thenReturn(-200.); - when(flowResult.getFlow(mnec3, Side.RIGHT, Unit.MEGAWATT)).thenReturn(-200.); + when(flowResult.getFlow(mnec1, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(900.); + when(flowResult.getFlow(mnec2, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(-200.); + when(flowResult.getFlow(mnec3, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(-200.); + when(flowResult.getFlow(mnec3, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(-200.); MnecFiller mnecFiller = new MnecFiller( flowResult, Set.of(mnec1, mnec2, mnec3), @@ -162,37 +162,37 @@ void testAddMnecMinFlowConstraints() { assertEquals(String.format("Constraint %s has not been created yet", LinearProblemIdGenerator.mnecFlowConstraintId(cnec, side, LinearProblem.MarginExtension.BELOW_THRESHOLD)), e.getMessage()); })); - OpenRaoMPConstraint ct1Max = linearProblem.getMnecFlowConstraint(mnec1, Side.RIGHT, LinearProblem.MarginExtension.BELOW_THRESHOLD); + OpenRaoMPConstraint ct1Max = linearProblem.getMnecFlowConstraint(mnec1, TwoSides.TWO, LinearProblem.MarginExtension.BELOW_THRESHOLD); assertNotNull(ct1Max); assertEquals(-LinearProblem.infinity(), ct1Max.lb(), INFINITY_TOLERANCE); double mnec1MaxFlow = 1000 - 3.5; assertEquals(mnec1MaxFlow, ct1Max.ub(), DOUBLE_TOLERANCE); - assertEquals(1, ct1Max.getCoefficient(linearProblem.getFlowVariable(mnec1, Side.RIGHT)), DOUBLE_TOLERANCE); - assertEquals(-1, ct1Max.getCoefficient(linearProblem.getMnecViolationVariable(mnec1, Side.RIGHT)), DOUBLE_TOLERANCE); + assertEquals(1, ct1Max.getCoefficient(linearProblem.getFlowVariable(mnec1, TwoSides.TWO)), DOUBLE_TOLERANCE); + assertEquals(-1, ct1Max.getCoefficient(linearProblem.getMnecViolationVariable(mnec1, TwoSides.TWO)), DOUBLE_TOLERANCE); - OpenRaoMPConstraint ct1Min = linearProblem.getMnecFlowConstraint(mnec1, Side.RIGHT, LinearProblem.MarginExtension.ABOVE_THRESHOLD); + OpenRaoMPConstraint ct1Min = linearProblem.getMnecFlowConstraint(mnec1, TwoSides.TWO, LinearProblem.MarginExtension.ABOVE_THRESHOLD); assertNotNull(ct1Min); double mnec1MinFlow = -1000 + 3.5; assertEquals(mnec1MinFlow, ct1Min.lb(), DOUBLE_TOLERANCE); assertEquals(LinearProblem.infinity(), ct1Min.ub(), INFINITY_TOLERANCE); - assertEquals(1, ct1Min.getCoefficient(linearProblem.getFlowVariable(mnec1, Side.RIGHT)), DOUBLE_TOLERANCE); - assertEquals(1, ct1Min.getCoefficient(linearProblem.getMnecViolationVariable(mnec1, Side.RIGHT)), DOUBLE_TOLERANCE); + assertEquals(1, ct1Min.getCoefficient(linearProblem.getFlowVariable(mnec1, TwoSides.TWO)), DOUBLE_TOLERANCE); + assertEquals(1, ct1Min.getCoefficient(linearProblem.getMnecViolationVariable(mnec1, TwoSides.TWO)), DOUBLE_TOLERANCE); - OpenRaoMPConstraint ct2Max = linearProblem.getMnecFlowConstraint(mnec2, Side.LEFT, LinearProblem.MarginExtension.BELOW_THRESHOLD); + OpenRaoMPConstraint ct2Max = linearProblem.getMnecFlowConstraint(mnec2, TwoSides.ONE, LinearProblem.MarginExtension.BELOW_THRESHOLD); assertNotNull(ct2Max); assertEquals(-LinearProblem.infinity(), ct2Max.lb(), INFINITY_TOLERANCE); double mnec2MaxFlow = 100 - 3.5; assertEquals(mnec2MaxFlow, ct2Max.ub(), DOUBLE_TOLERANCE); - assertEquals(1, ct2Max.getCoefficient(linearProblem.getFlowVariable(mnec2, Side.LEFT)), DOUBLE_TOLERANCE); - assertEquals(-1, ct2Max.getCoefficient(linearProblem.getMnecViolationVariable(mnec2, Side.LEFT)), DOUBLE_TOLERANCE); + assertEquals(1, ct2Max.getCoefficient(linearProblem.getFlowVariable(mnec2, TwoSides.ONE)), DOUBLE_TOLERANCE); + assertEquals(-1, ct2Max.getCoefficient(linearProblem.getMnecViolationVariable(mnec2, TwoSides.ONE)), DOUBLE_TOLERANCE); - OpenRaoMPConstraint ct2Min = linearProblem.getMnecFlowConstraint(mnec2, Side.LEFT, LinearProblem.MarginExtension.ABOVE_THRESHOLD); + OpenRaoMPConstraint ct2Min = linearProblem.getMnecFlowConstraint(mnec2, TwoSides.ONE, LinearProblem.MarginExtension.ABOVE_THRESHOLD); assertNotNull(ct2Min); double mnec2MinFlow = -250 + 3.5; assertEquals(mnec2MinFlow, ct2Min.lb(), DOUBLE_TOLERANCE); assertEquals(LinearProblem.infinity(), ct2Min.ub(), INFINITY_TOLERANCE); - assertEquals(1, ct2Min.getCoefficient(linearProblem.getFlowVariable(mnec2, Side.LEFT)), DOUBLE_TOLERANCE); - assertEquals(1, ct2Min.getCoefficient(linearProblem.getMnecViolationVariable(mnec2, Side.LEFT)), DOUBLE_TOLERANCE); + assertEquals(1, ct2Min.getCoefficient(linearProblem.getFlowVariable(mnec2, TwoSides.ONE)), DOUBLE_TOLERANCE); + assertEquals(1, ct2Min.getCoefficient(linearProblem.getMnecViolationVariable(mnec2, TwoSides.ONE)), DOUBLE_TOLERANCE); } @Test @@ -220,10 +220,10 @@ void testFilterCnecWithNoInitialFlow() { parameters.setViolationCost(10); parameters.setConstraintAdjustmentCoefficient(3.5); FlowResult flowResult = Mockito.mock(FlowResult.class); - when(flowResult.getFlow(mnec1, Side.RIGHT, Unit.MEGAWATT)).thenReturn(900.); - when(flowResult.getFlow(mnec2, Side.LEFT, Unit.MEGAWATT)).thenReturn(-200.); - when(flowResult.getFlow(mnec3, Side.LEFT, Unit.MEGAWATT)).thenReturn(-200.); - when(flowResult.getFlow(mnec3, Side.RIGHT, Unit.MEGAWATT)).thenReturn(Double.NaN); + when(flowResult.getFlow(mnec1, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(900.); + when(flowResult.getFlow(mnec2, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(-200.); + when(flowResult.getFlow(mnec3, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(-200.); + when(flowResult.getFlow(mnec3, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(Double.NaN); when(sensitivityResult.getSensitivityStatus(crac.getState("N-1 NL1-NL3", crac.getInstant(InstantKind.CURATIVE)))).thenReturn(ComputationStatus.FAILURE); MnecFiller mnecFiller = new MnecFiller( flowResult, @@ -237,18 +237,18 @@ void testFilterCnecWithNoInitialFlow() { .build(); linearProblem.fill(flowResult, sensitivityResult); - Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getMnecFlowConstraint(mnec3, Side.LEFT, LinearProblem.MarginExtension.ABOVE_THRESHOLD)); - assertEquals("Constraint MNEC3 - curative_left_mnecflow_above_threshold_constraint has not been created yet", e.getMessage()); - e = assertThrows(OpenRaoException.class, () -> linearProblem.getMnecFlowConstraint(mnec3, Side.LEFT, LinearProblem.MarginExtension.BELOW_THRESHOLD)); - assertEquals("Constraint MNEC3 - curative_left_mnecflow_below_threshold_constraint has not been created yet", e.getMessage()); - e = assertThrows(OpenRaoException.class, () -> linearProblem.getMnecFlowConstraint(mnec3, Side.RIGHT, LinearProblem.MarginExtension.ABOVE_THRESHOLD)); - assertEquals("Constraint MNEC3 - curative_right_mnecflow_above_threshold_constraint has not been created yet", e.getMessage()); - e = assertThrows(OpenRaoException.class, () -> linearProblem.getMnecFlowConstraint(mnec3, Side.RIGHT, LinearProblem.MarginExtension.BELOW_THRESHOLD)); - assertEquals("Constraint MNEC3 - curative_right_mnecflow_below_threshold_constraint has not been created yet", e.getMessage()); - - e = assertThrows(OpenRaoException.class, () -> linearProblem.getMnecViolationVariable(mnec3, Side.LEFT)); - assertEquals("Variable MNEC3 - curative_left_mnecviolation_variable has not been created yet", e.getMessage()); - e = assertThrows(OpenRaoException.class, () -> linearProblem.getMnecViolationVariable(mnec3, Side.RIGHT)); - assertEquals("Variable MNEC3 - curative_right_mnecviolation_variable has not been created yet", e.getMessage()); + Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getMnecFlowConstraint(mnec3, TwoSides.ONE, LinearProblem.MarginExtension.ABOVE_THRESHOLD)); + assertEquals("Constraint MNEC3 - curative_one_mnecflow_above_threshold_constraint has not been created yet", e.getMessage()); + e = assertThrows(OpenRaoException.class, () -> linearProblem.getMnecFlowConstraint(mnec3, TwoSides.ONE, LinearProblem.MarginExtension.BELOW_THRESHOLD)); + assertEquals("Constraint MNEC3 - curative_one_mnecflow_below_threshold_constraint has not been created yet", e.getMessage()); + e = assertThrows(OpenRaoException.class, () -> linearProblem.getMnecFlowConstraint(mnec3, TwoSides.TWO, LinearProblem.MarginExtension.ABOVE_THRESHOLD)); + assertEquals("Constraint MNEC3 - curative_two_mnecflow_above_threshold_constraint has not been created yet", e.getMessage()); + e = assertThrows(OpenRaoException.class, () -> linearProblem.getMnecFlowConstraint(mnec3, TwoSides.TWO, LinearProblem.MarginExtension.BELOW_THRESHOLD)); + assertEquals("Constraint MNEC3 - curative_two_mnecflow_below_threshold_constraint has not been created yet", e.getMessage()); + + e = assertThrows(OpenRaoException.class, () -> linearProblem.getMnecViolationVariable(mnec3, TwoSides.ONE)); + assertEquals("Variable MNEC3 - curative_one_mnecviolation_variable has not been created yet", e.getMessage()); + e = assertThrows(OpenRaoException.class, () -> linearProblem.getMnecViolationVariable(mnec3, TwoSides.TWO)); + assertEquals("Variable MNEC3 - curative_two_mnecviolation_variable has not been created yet", e.getMessage()); } } diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/UnoptimizedCnecFillerMarginDecreaseRuleTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/UnoptimizedCnecFillerMarginDecreaseRuleTest.java index de3799e85d..c55e915de3 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/UnoptimizedCnecFillerMarginDecreaseRuleTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/UnoptimizedCnecFillerMarginDecreaseRuleTest.java @@ -11,7 +11,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; import com.powsybl.openrao.raoapi.parameters.RaoParameters; @@ -61,7 +61,7 @@ public void setUp() throws IOException { cnecNl = crac.newFlowCnec() .withId("Line NL - N - preventive") .withNetworkElement("NNL1AA1 NNL2AA1 1") - .newThreshold().withSide(Side.RIGHT).withMax(800.0).withMin(-1000.).withUnit(Unit.MEGAWATT).add() + .newThreshold().withSide(TwoSides.TWO).withMax(800.0).withMin(-1000.).withUnit(Unit.MEGAWATT).add() .withOptimized(true) .withInstant(PREVENTIVE_INSTANT_ID) .withOperator("NL") @@ -102,11 +102,11 @@ private void buildLinearProblemWithMaxMinMargin(boolean initialFlowsAreNan) { UnoptimizedCnecParameters unoptimizedCnecParameters = new UnoptimizedCnecParameters(Set.of("NL")); MaxMinMarginFiller maxMinMarginFiller = new MaxMinMarginFiller(Set.of(cnecNl, cnecFr), Unit.MEGAWATT); FlowResult initialFlowResult = Mockito.mock(FlowResult.class); - when(initialFlowResult.getMargin(cnecNl, Side.RIGHT, Unit.MEGAWATT)).thenReturn(400.); - when(initialFlowResult.getMargin(cnecFr, Side.LEFT, Unit.MEGAWATT)).thenReturn(600.); + when(initialFlowResult.getMargin(cnecNl, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(400.); + when(initialFlowResult.getMargin(cnecFr, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(600.); if (initialFlowsAreNan) { - when(initialFlowResult.getFlow(cnecNl, Side.RIGHT, MEGAWATT)).thenReturn(Double.NaN); - when(initialFlowResult.getFlow(cnecFr, Side.LEFT, MEGAWATT)).thenReturn(Double.NaN); + when(initialFlowResult.getFlow(cnecNl, TwoSides.TWO, MEGAWATT)).thenReturn(Double.NaN); + when(initialFlowResult.getFlow(cnecFr, TwoSides.ONE, MEGAWATT)).thenReturn(Double.NaN); } unoptimizedCnecFiller = new UnoptimizedCnecFiller( Set.of(cnecNl, cnecFr), @@ -127,18 +127,18 @@ private void buildLinearProblemWithMaxMinRelativeMargin() { UnoptimizedCnecParameters unoptimizedCnecParameters = new UnoptimizedCnecParameters(Set.of("NL")); FlowResult initialFlowResult = Mockito.mock(FlowResult.class); - when(initialFlowResult.getMargin(cnecNl, Side.RIGHT, Unit.MEGAWATT)).thenReturn(400.); - when(initialFlowResult.getMargin(cnecFr, Side.LEFT, Unit.MEGAWATT)).thenReturn(600.); - when(initialFlowResult.getPtdfZonalSum(cnecNl, Side.RIGHT)).thenReturn(0.5); - when(initialFlowResult.getPtdfZonalSum(cnecFr, Side.LEFT)).thenReturn(2.6); + when(initialFlowResult.getMargin(cnecNl, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(400.); + when(initialFlowResult.getMargin(cnecFr, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(600.); + when(initialFlowResult.getPtdfZonalSum(cnecNl, TwoSides.TWO)).thenReturn(0.5); + when(initialFlowResult.getPtdfZonalSum(cnecFr, TwoSides.ONE)).thenReturn(2.6); MaxMinRelativeMarginFiller maxMinRelativeMarginFiller = new MaxMinRelativeMarginFiller( Set.of(cnecNl, cnecFr), initialFlowResult, Unit.MEGAWATT, maxMinRelativeMarginParameters ); - double relMarginCoef = Math.max(initialFlowResult.getPtdfZonalSum(cnecFr, Side.LEFT), maxMinRelativeMarginParameters.getPtdfSumLowerBound()); - double unitConversionCoefficient = RaoUtil.getFlowUnitMultiplier(cnecFr, Side.LEFT, MEGAWATT, MEGAWATT); + double relMarginCoef = Math.max(initialFlowResult.getPtdfZonalSum(cnecFr, TwoSides.ONE), maxMinRelativeMarginParameters.getPtdfSumLowerBound()); + double unitConversionCoefficient = RaoUtil.getFlowUnitMultiplier(cnecFr, TwoSides.ONE, MEGAWATT, MEGAWATT); constraintCoeff = 5 * RaoUtil.getLargestCnecThreshold(Set.of(cnecNl, cnecFr), MEGAWATT) / maxMinRelativeMarginParameters.getPtdfSumLowerBound() * unitConversionCoefficient * relMarginCoef; unoptimizedCnecFiller = new UnoptimizedCnecFiller( @@ -160,28 +160,28 @@ void testCnecsNotToOptimizeBinaryVar() { buildLinearProblemWithMaxMinMargin(); // Verify existence of margin_decrease binary variable - Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getOptimizeCnecBinaryVariable(cnecFr, Side.LEFT)); - assertEquals("Variable Tieline BE FR - N - preventive_left_optimizecnec_variable has not been created yet", e.getMessage()); - OpenRaoMPVariable binaryVar = linearProblem.getOptimizeCnecBinaryVariable(cnecNl, Side.RIGHT); + Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getOptimizeCnecBinaryVariable(cnecFr, TwoSides.ONE)); + assertEquals("Variable Tieline BE FR - N - preventive_one_optimizecnec_variable has not been created yet", e.getMessage()); + OpenRaoMPVariable binaryVar = linearProblem.getOptimizeCnecBinaryVariable(cnecNl, TwoSides.TWO); assertNotNull(binaryVar); // Get flow variable - OpenRaoMPVariable flowVar = linearProblem.getFlowVariable(cnecNl, Side.RIGHT); + OpenRaoMPVariable flowVar = linearProblem.getFlowVariable(cnecNl, TwoSides.TWO); // Verify existence of margin_decrease definition constraints - e = assertThrows(OpenRaoException.class, () -> linearProblem.getDontOptimizeCnecConstraint(cnecFr, Side.LEFT, LinearProblem.MarginExtension.BELOW_THRESHOLD)); - assertEquals("Constraint Tieline BE FR - N - preventive_left_optimizecnecbelow_threshold_constraint has not been created yet", e.getMessage()); - e = assertThrows(OpenRaoException.class, () -> linearProblem.getDontOptimizeCnecConstraint(cnecFr, Side.LEFT, LinearProblem.MarginExtension.ABOVE_THRESHOLD)); - assertEquals("Constraint Tieline BE FR - N - preventive_left_optimizecnecabove_threshold_constraint has not been created yet", e.getMessage()); + e = assertThrows(OpenRaoException.class, () -> linearProblem.getDontOptimizeCnecConstraint(cnecFr, TwoSides.ONE, LinearProblem.MarginExtension.BELOW_THRESHOLD)); + assertEquals("Constraint Tieline BE FR - N - preventive_one_optimizecnecbelow_threshold_constraint has not been created yet", e.getMessage()); + e = assertThrows(OpenRaoException.class, () -> linearProblem.getDontOptimizeCnecConstraint(cnecFr, TwoSides.ONE, LinearProblem.MarginExtension.ABOVE_THRESHOLD)); + assertEquals("Constraint Tieline BE FR - N - preventive_one_optimizecnecabove_threshold_constraint has not been created yet", e.getMessage()); - OpenRaoMPConstraint marginDecreaseConstraintMin = linearProblem.getDontOptimizeCnecConstraint(cnecNl, Side.RIGHT, LinearProblem.MarginExtension.BELOW_THRESHOLD); + OpenRaoMPConstraint marginDecreaseConstraintMin = linearProblem.getDontOptimizeCnecConstraint(cnecNl, TwoSides.TWO, LinearProblem.MarginExtension.BELOW_THRESHOLD); assertNotNull(marginDecreaseConstraintMin); assertEquals(LinearProblem.infinity(), marginDecreaseConstraintMin.ub(), INFINITY_TOLERANCE); assertEquals(-1000 + (800 - 400), marginDecreaseConstraintMin.lb(), DOUBLE_TOLERANCE); assertEquals(1.0, marginDecreaseConstraintMin.getCoefficient(flowVar), DOUBLE_TOLERANCE); assertEquals(20 * 1000, marginDecreaseConstraintMin.getCoefficient(binaryVar), DOUBLE_TOLERANCE); // 1000 being the largest cnec threshold - OpenRaoMPConstraint marginDecreaseConstraintMax = linearProblem.getDontOptimizeCnecConstraint(cnecNl, Side.RIGHT, LinearProblem.MarginExtension.ABOVE_THRESHOLD); + OpenRaoMPConstraint marginDecreaseConstraintMax = linearProblem.getDontOptimizeCnecConstraint(cnecNl, TwoSides.TWO, LinearProblem.MarginExtension.ABOVE_THRESHOLD); assertNotNull(marginDecreaseConstraintMax); assertEquals(LinearProblem.infinity(), marginDecreaseConstraintMax.ub(), INFINITY_TOLERANCE); assertEquals(-800 + (800 - 400), marginDecreaseConstraintMax.lb(), DOUBLE_TOLERANCE); @@ -194,15 +194,15 @@ void testExcludeCnecsNotToOptimizeInMinMargin() { buildLinearProblemWithMaxMinMargin(); // Test that cnecFr's constraint does not have a bigM - assertEquals(750.0, linearProblem.getMinimumMarginConstraint(cnecFr, Side.LEFT, LinearProblem.MarginExtension.BELOW_THRESHOLD).ub(), DOUBLE_TOLERANCE); - assertEquals(750.0, linearProblem.getMinimumMarginConstraint(cnecFr, Side.LEFT, LinearProblem.MarginExtension.ABOVE_THRESHOLD).ub(), DOUBLE_TOLERANCE); + assertEquals(750.0, linearProblem.getMinimumMarginConstraint(cnecFr, TwoSides.ONE, LinearProblem.MarginExtension.BELOW_THRESHOLD).ub(), DOUBLE_TOLERANCE); + assertEquals(750.0, linearProblem.getMinimumMarginConstraint(cnecFr, TwoSides.ONE, LinearProblem.MarginExtension.ABOVE_THRESHOLD).ub(), DOUBLE_TOLERANCE); // Test that cnecNl's constraint does have a bigM - OpenRaoMPVariable marginDecreaseVariable = linearProblem.getOptimizeCnecBinaryVariable(cnecNl, Side.RIGHT); - OpenRaoMPConstraint minMarginDefMin = linearProblem.getMinimumMarginConstraint(cnecNl, Side.RIGHT, LinearProblem.MarginExtension.BELOW_THRESHOLD); + OpenRaoMPVariable marginDecreaseVariable = linearProblem.getOptimizeCnecBinaryVariable(cnecNl, TwoSides.TWO); + OpenRaoMPConstraint minMarginDefMin = linearProblem.getMinimumMarginConstraint(cnecNl, TwoSides.TWO, LinearProblem.MarginExtension.BELOW_THRESHOLD); assertEquals(1000 + 2 * MAX_ABS_THRESHOLD, minMarginDefMin.ub(), DOUBLE_TOLERANCE); assertEquals(2 * MAX_ABS_THRESHOLD, minMarginDefMin.getCoefficient(marginDecreaseVariable), DOUBLE_TOLERANCE); - OpenRaoMPConstraint minMarginDefMax = linearProblem.getMinimumMarginConstraint(cnecNl, Side.RIGHT, LinearProblem.MarginExtension.ABOVE_THRESHOLD); + OpenRaoMPConstraint minMarginDefMax = linearProblem.getMinimumMarginConstraint(cnecNl, TwoSides.TWO, LinearProblem.MarginExtension.ABOVE_THRESHOLD); assertEquals(800 + 2 * MAX_ABS_THRESHOLD, minMarginDefMax.ub(), DOUBLE_TOLERANCE); assertEquals(2 * MAX_ABS_THRESHOLD, minMarginDefMax.getCoefficient(marginDecreaseVariable), DOUBLE_TOLERANCE); } @@ -212,28 +212,28 @@ void testCnecsNotToOptimizeBinaryVarRelative() { buildLinearProblemWithMaxMinRelativeMargin(); // Verify existence of margin_decrease binary variable - Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getOptimizeCnecBinaryVariable(cnecFr, Side.LEFT)); - assertEquals("Variable Tieline BE FR - N - preventive_left_optimizecnec_variable has not been created yet", e.getMessage()); - OpenRaoMPVariable binaryVar = linearProblem.getOptimizeCnecBinaryVariable(cnecNl, Side.RIGHT); + Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getOptimizeCnecBinaryVariable(cnecFr, TwoSides.ONE)); + assertEquals("Variable Tieline BE FR - N - preventive_one_optimizecnec_variable has not been created yet", e.getMessage()); + OpenRaoMPVariable binaryVar = linearProblem.getOptimizeCnecBinaryVariable(cnecNl, TwoSides.TWO); assertNotNull(binaryVar); // Get flow variable - OpenRaoMPVariable flowVar = linearProblem.getFlowVariable(cnecNl, Side.RIGHT); + OpenRaoMPVariable flowVar = linearProblem.getFlowVariable(cnecNl, TwoSides.TWO); // Verify existence of margin_decrease definition constraints - e = assertThrows(OpenRaoException.class, () -> linearProblem.getDontOptimizeCnecConstraint(cnecFr, Side.LEFT, LinearProblem.MarginExtension.BELOW_THRESHOLD)); - assertEquals("Constraint Tieline BE FR - N - preventive_left_optimizecnecbelow_threshold_constraint has not been created yet", e.getMessage()); - e = assertThrows(OpenRaoException.class, () -> linearProblem.getDontOptimizeCnecConstraint(cnecFr, Side.LEFT, LinearProblem.MarginExtension.ABOVE_THRESHOLD)); - assertEquals("Constraint Tieline BE FR - N - preventive_left_optimizecnecabove_threshold_constraint has not been created yet", e.getMessage()); + e = assertThrows(OpenRaoException.class, () -> linearProblem.getDontOptimizeCnecConstraint(cnecFr, TwoSides.ONE, LinearProblem.MarginExtension.BELOW_THRESHOLD)); + assertEquals("Constraint Tieline BE FR - N - preventive_one_optimizecnecbelow_threshold_constraint has not been created yet", e.getMessage()); + e = assertThrows(OpenRaoException.class, () -> linearProblem.getDontOptimizeCnecConstraint(cnecFr, TwoSides.ONE, LinearProblem.MarginExtension.ABOVE_THRESHOLD)); + assertEquals("Constraint Tieline BE FR - N - preventive_one_optimizecnecabove_threshold_constraint has not been created yet", e.getMessage()); - OpenRaoMPConstraint marginDecreaseConstraintMin = linearProblem.getDontOptimizeCnecConstraint(cnecNl, Side.RIGHT, LinearProblem.MarginExtension.BELOW_THRESHOLD); + OpenRaoMPConstraint marginDecreaseConstraintMin = linearProblem.getDontOptimizeCnecConstraint(cnecNl, TwoSides.TWO, LinearProblem.MarginExtension.BELOW_THRESHOLD); assertNotNull(marginDecreaseConstraintMin); assertEquals(LinearProblem.infinity(), marginDecreaseConstraintMin.ub(), INFINITY_TOLERANCE); assertEquals(-1000 + (800 - 400), marginDecreaseConstraintMin.lb(), DOUBLE_TOLERANCE); assertEquals(1.0, marginDecreaseConstraintMin.getCoefficient(flowVar), DOUBLE_TOLERANCE); assertEquals(20 * 1000, marginDecreaseConstraintMin.getCoefficient(binaryVar), DOUBLE_TOLERANCE); // 1000 being the largest cnec threshold - OpenRaoMPConstraint marginDecreaseConstraintMax = linearProblem.getDontOptimizeCnecConstraint(cnecNl, Side.RIGHT, LinearProblem.MarginExtension.ABOVE_THRESHOLD); + OpenRaoMPConstraint marginDecreaseConstraintMax = linearProblem.getDontOptimizeCnecConstraint(cnecNl, TwoSides.TWO, LinearProblem.MarginExtension.ABOVE_THRESHOLD); assertNotNull(marginDecreaseConstraintMax); assertEquals(LinearProblem.infinity(), marginDecreaseConstraintMax.ub(), INFINITY_TOLERANCE); assertEquals(-800 + (800 - 400), marginDecreaseConstraintMax.lb(), DOUBLE_TOLERANCE); @@ -246,18 +246,18 @@ void testExcludeCnecsNotToOptimizeInMinMarginRelative() { buildLinearProblemWithMaxMinRelativeMargin(); // Test that cnecFr's constraint does not have a bigM - assertEquals(750.0, linearProblem.getMinimumMarginConstraint(cnecFr, Side.LEFT, LinearProblem.MarginExtension.BELOW_THRESHOLD).ub(), DOUBLE_TOLERANCE); - assertEquals(750.0, linearProblem.getMinimumMarginConstraint(cnecFr, Side.LEFT, LinearProblem.MarginExtension.ABOVE_THRESHOLD).ub(), DOUBLE_TOLERANCE); + assertEquals(750.0, linearProblem.getMinimumMarginConstraint(cnecFr, TwoSides.ONE, LinearProblem.MarginExtension.BELOW_THRESHOLD).ub(), DOUBLE_TOLERANCE); + assertEquals(750.0, linearProblem.getMinimumMarginConstraint(cnecFr, TwoSides.ONE, LinearProblem.MarginExtension.ABOVE_THRESHOLD).ub(), DOUBLE_TOLERANCE); // All cnecs now have fmax + maxNegativeRelativeRam * unitConversionCoefficient * relMarginCoef OR - fmin + maxNegativeRelativeRam * unitConversionCoefficient * relMarginCoef as mMRM ub - assertEquals(750.0 + constraintCoeff, linearProblem.getMinimumRelativeMarginConstraint(cnecFr, Side.LEFT, LinearProblem.MarginExtension.BELOW_THRESHOLD).ub(), DOUBLE_TOLERANCE); - assertEquals(750.0 + constraintCoeff, linearProblem.getMinimumRelativeMarginConstraint(cnecFr, Side.LEFT, LinearProblem.MarginExtension.ABOVE_THRESHOLD).ub(), DOUBLE_TOLERANCE); + assertEquals(750.0 + constraintCoeff, linearProblem.getMinimumRelativeMarginConstraint(cnecFr, TwoSides.ONE, LinearProblem.MarginExtension.BELOW_THRESHOLD).ub(), DOUBLE_TOLERANCE); + assertEquals(750.0 + constraintCoeff, linearProblem.getMinimumRelativeMarginConstraint(cnecFr, TwoSides.ONE, LinearProblem.MarginExtension.ABOVE_THRESHOLD).ub(), DOUBLE_TOLERANCE); // Test that cnecNl's constraint does have a bigM - OpenRaoMPVariable marginDecreaseVariable = linearProblem.getOptimizeCnecBinaryVariable(cnecNl, Side.RIGHT); - OpenRaoMPConstraint minMarginDefMin = linearProblem.getMinimumMarginConstraint(cnecNl, Side.RIGHT, LinearProblem.MarginExtension.BELOW_THRESHOLD); + OpenRaoMPVariable marginDecreaseVariable = linearProblem.getOptimizeCnecBinaryVariable(cnecNl, TwoSides.TWO); + OpenRaoMPConstraint minMarginDefMin = linearProblem.getMinimumMarginConstraint(cnecNl, TwoSides.TWO, LinearProblem.MarginExtension.BELOW_THRESHOLD); assertEquals(1000 + 2 * MAX_ABS_THRESHOLD, minMarginDefMin.ub(), DOUBLE_TOLERANCE); assertEquals(2 * MAX_ABS_THRESHOLD, minMarginDefMin.getCoefficient(marginDecreaseVariable), DOUBLE_TOLERANCE); - OpenRaoMPConstraint minMarginDefMax = linearProblem.getMinimumMarginConstraint(cnecNl, Side.RIGHT, LinearProblem.MarginExtension.ABOVE_THRESHOLD); + OpenRaoMPConstraint minMarginDefMax = linearProblem.getMinimumMarginConstraint(cnecNl, TwoSides.TWO, LinearProblem.MarginExtension.ABOVE_THRESHOLD); assertEquals(800 + 2 * MAX_ABS_THRESHOLD, minMarginDefMax.ub(), DOUBLE_TOLERANCE); assertEquals(2 * MAX_ABS_THRESHOLD, minMarginDefMax.getCoefficient(marginDecreaseVariable), DOUBLE_TOLERANCE); } @@ -266,10 +266,10 @@ void testExcludeCnecsNotToOptimizeInMinMarginRelative() { void testFilterCnecWithInitialNanFlow() { buildLinearProblemWithMaxMinMargin(true); - Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getOptimizeCnecBinaryVariable(cnecFr, Side.RIGHT)); - assertEquals("Variable Tieline BE FR - N - preventive_right_optimizecnec_variable has not been created yet", e.getMessage()); + Exception e = assertThrows(OpenRaoException.class, () -> linearProblem.getOptimizeCnecBinaryVariable(cnecFr, TwoSides.TWO)); + assertEquals("Variable Tieline BE FR - N - preventive_two_optimizecnec_variable has not been created yet", e.getMessage()); - e = assertThrows(OpenRaoException.class, () -> linearProblem.getOptimizeCnecBinaryVariable(cnecNl, Side.LEFT)); - assertEquals("Variable Line NL - N - preventive_left_optimizecnec_variable has not been created yet", e.getMessage()); + e = assertThrows(OpenRaoException.class, () -> linearProblem.getOptimizeCnecBinaryVariable(cnecNl, TwoSides.ONE)); + assertEquals("Variable Line NL - N - preventive_one_optimizecnec_variable has not been created yet", e.getMessage()); } } diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/AutomatonPerimeterResultImplTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/AutomatonPerimeterResultImplTest.java index 029ebd2c27..f3d3b8dce2 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/AutomatonPerimeterResultImplTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/AutomatonPerimeterResultImplTest.java @@ -28,8 +28,8 @@ import static org.mockito.Mockito.when; import static org.junit.jupiter.api.Assertions.*; import static com.powsybl.openrao.commons.Unit.*; -import static com.powsybl.openrao.data.cracapi.cnec.Side.LEFT; -import static com.powsybl.openrao.data.cracapi.cnec.Side.RIGHT; +import static com.powsybl.iidm.network.TwoSides.ONE; +import static com.powsybl.iidm.network.TwoSides.TWO; /** * @author Peter Mitri {@literal } @@ -75,30 +75,30 @@ void testGetPostAutomatonSensitivityAnalysisOutput() { @Test void testGetFlow() { - when(postAutoSensitivity.getFlow(cnec1, RIGHT, AMPERE)).thenReturn(10.); - when(postAutoSensitivity.getFlow(cnec1, RIGHT, MEGAWATT)).thenReturn(100.); - assertEquals(10., result.getFlow(cnec1, RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(100., result.getFlow(cnec1, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + when(postAutoSensitivity.getFlow(cnec1, TWO, AMPERE)).thenReturn(10.); + when(postAutoSensitivity.getFlow(cnec1, TWO, MEGAWATT)).thenReturn(100.); + assertEquals(10., result.getFlow(cnec1, TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(100., result.getFlow(cnec1, TWO, MEGAWATT), DOUBLE_TOLERANCE); } @Test void testGetCommercialFlow() { - when(postAutoSensitivity.getCommercialFlow(cnec1, RIGHT, AMPERE)).thenReturn(10.); - when(postAutoSensitivity.getCommercialFlow(cnec1, RIGHT, MEGAWATT)).thenReturn(100.); - assertEquals(10., result.getCommercialFlow(cnec1, RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(100., result.getCommercialFlow(cnec1, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + when(postAutoSensitivity.getCommercialFlow(cnec1, TWO, AMPERE)).thenReturn(10.); + when(postAutoSensitivity.getCommercialFlow(cnec1, TWO, MEGAWATT)).thenReturn(100.); + assertEquals(10., result.getCommercialFlow(cnec1, TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(100., result.getCommercialFlow(cnec1, TWO, MEGAWATT), DOUBLE_TOLERANCE); } @Test void testGetPtdfZonalSum() { - when(postAutoSensitivity.getPtdfZonalSum(cnec1, RIGHT)).thenReturn(10.); - assertEquals(10., result.getPtdfZonalSum(cnec1, RIGHT), DOUBLE_TOLERANCE); + when(postAutoSensitivity.getPtdfZonalSum(cnec1, TWO)).thenReturn(10.); + assertEquals(10., result.getPtdfZonalSum(cnec1, TWO), DOUBLE_TOLERANCE); } @Test void testGetPtdfZonalSums() { - when(postAutoSensitivity.getPtdfZonalSums()).thenReturn(Map.of(cnec1, Map.of(RIGHT, 0.1))); - assertEquals(Map.of(cnec1, Map.of(RIGHT, 0.1)), result.getPtdfZonalSums()); + when(postAutoSensitivity.getPtdfZonalSums()).thenReturn(Map.of(cnec1, Map.of(TWO, 0.1))); + assertEquals(Map.of(cnec1, Map.of(TWO, 0.1)), result.getPtdfZonalSums()); } @Test @@ -196,26 +196,26 @@ void testGetSensitivityStatus() { @Test void testGetSensitivityOnRangeAction() { RangeAction rangeAction = mock(RangeAction.class); - when(postAutoSensitivity.getSensitivityValue(cnec1, RIGHT, rangeAction, MEGAWATT)).thenReturn(100.); - when(postAutoSensitivity.getSensitivityValue(cnec1, RIGHT, rangeAction, AMPERE)).thenReturn(1000.); - when(postAutoSensitivity.getSensitivityValue(cnec2, LEFT, rangeAction, MEGAWATT)).thenReturn(200.); - when(postAutoSensitivity.getSensitivityValue(cnec2, LEFT, rangeAction, AMPERE)).thenReturn(2000.); - assertEquals(100., result.getSensitivityValue(cnec1, RIGHT, rangeAction, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(1000., result.getSensitivityValue(cnec1, RIGHT, rangeAction, AMPERE), DOUBLE_TOLERANCE); - assertEquals(200., result.getSensitivityValue(cnec2, LEFT, rangeAction, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(2000., result.getSensitivityValue(cnec2, LEFT, rangeAction, AMPERE), DOUBLE_TOLERANCE); + when(postAutoSensitivity.getSensitivityValue(cnec1, TWO, rangeAction, MEGAWATT)).thenReturn(100.); + when(postAutoSensitivity.getSensitivityValue(cnec1, TWO, rangeAction, AMPERE)).thenReturn(1000.); + when(postAutoSensitivity.getSensitivityValue(cnec2, ONE, rangeAction, MEGAWATT)).thenReturn(200.); + when(postAutoSensitivity.getSensitivityValue(cnec2, ONE, rangeAction, AMPERE)).thenReturn(2000.); + assertEquals(100., result.getSensitivityValue(cnec1, TWO, rangeAction, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(1000., result.getSensitivityValue(cnec1, TWO, rangeAction, AMPERE), DOUBLE_TOLERANCE); + assertEquals(200., result.getSensitivityValue(cnec2, ONE, rangeAction, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(2000., result.getSensitivityValue(cnec2, ONE, rangeAction, AMPERE), DOUBLE_TOLERANCE); } @Test void testGetSensitivityOnLinearGlsk() { SensitivityVariableSet linearGlsk = mock(SensitivityVariableSet.class); - when(postAutoSensitivity.getSensitivityValue(cnec1, RIGHT, linearGlsk, MEGAWATT)).thenReturn(100.); - when(postAutoSensitivity.getSensitivityValue(cnec1, RIGHT, linearGlsk, AMPERE)).thenReturn(1000.); - when(postAutoSensitivity.getSensitivityValue(cnec2, LEFT, linearGlsk, MEGAWATT)).thenReturn(200.); - when(postAutoSensitivity.getSensitivityValue(cnec2, LEFT, linearGlsk, AMPERE)).thenReturn(2000.); - assertEquals(100., result.getSensitivityValue(cnec1, RIGHT, linearGlsk, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(1000., result.getSensitivityValue(cnec1, RIGHT, linearGlsk, AMPERE), DOUBLE_TOLERANCE); - assertEquals(200., result.getSensitivityValue(cnec2, LEFT, linearGlsk, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(2000., result.getSensitivityValue(cnec2, LEFT, linearGlsk, AMPERE), DOUBLE_TOLERANCE); + when(postAutoSensitivity.getSensitivityValue(cnec1, TWO, linearGlsk, MEGAWATT)).thenReturn(100.); + when(postAutoSensitivity.getSensitivityValue(cnec1, TWO, linearGlsk, AMPERE)).thenReturn(1000.); + when(postAutoSensitivity.getSensitivityValue(cnec2, ONE, linearGlsk, MEGAWATT)).thenReturn(200.); + when(postAutoSensitivity.getSensitivityValue(cnec2, ONE, linearGlsk, AMPERE)).thenReturn(2000.); + assertEquals(100., result.getSensitivityValue(cnec1, TWO, linearGlsk, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(1000., result.getSensitivityValue(cnec1, TWO, linearGlsk, AMPERE), DOUBLE_TOLERANCE); + assertEquals(200., result.getSensitivityValue(cnec2, ONE, linearGlsk, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(2000., result.getSensitivityValue(cnec2, ONE, linearGlsk, AMPERE), DOUBLE_TOLERANCE); } } diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/EmptyFlowResultImplTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/EmptyFlowResultImplTest.java index 89529099ad..09591c5330 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/EmptyFlowResultImplTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/EmptyFlowResultImplTest.java @@ -9,7 +9,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -23,14 +23,14 @@ class EmptyFlowResultImplTest { void testBasicReturns() { FlowCnec cnec = Mockito.mock(FlowCnec.class); EmptyFlowResultImpl branchResult = new EmptyFlowResultImpl(); - assertTrue(Double.isNaN(branchResult.getFlow(cnec, Side.LEFT, Unit.MEGAWATT))); - assertTrue(Double.isNaN(branchResult.getFlow(cnec, Side.RIGHT, Unit.MEGAWATT))); - assertTrue(Double.isNaN(branchResult.getFlow(cnec, Side.LEFT, Unit.AMPERE))); - assertTrue(Double.isNaN(branchResult.getFlow(cnec, Side.RIGHT, Unit.AMPERE))); - assertTrue(Double.isNaN(branchResult.getCommercialFlow(cnec, Side.LEFT, Unit.MEGAWATT))); - assertTrue(Double.isNaN(branchResult.getCommercialFlow(cnec, Side.RIGHT, Unit.MEGAWATT))); - assertTrue(Double.isNaN(branchResult.getPtdfZonalSum(cnec, Side.LEFT))); - assertTrue(Double.isNaN(branchResult.getPtdfZonalSum(cnec, Side.RIGHT))); + assertTrue(Double.isNaN(branchResult.getFlow(cnec, TwoSides.ONE, Unit.MEGAWATT))); + assertTrue(Double.isNaN(branchResult.getFlow(cnec, TwoSides.TWO, Unit.MEGAWATT))); + assertTrue(Double.isNaN(branchResult.getFlow(cnec, TwoSides.ONE, Unit.AMPERE))); + assertTrue(Double.isNaN(branchResult.getFlow(cnec, TwoSides.TWO, Unit.AMPERE))); + assertTrue(Double.isNaN(branchResult.getCommercialFlow(cnec, TwoSides.ONE, Unit.MEGAWATT))); + assertTrue(Double.isNaN(branchResult.getCommercialFlow(cnec, TwoSides.TWO, Unit.MEGAWATT))); + assertTrue(Double.isNaN(branchResult.getPtdfZonalSum(cnec, TwoSides.ONE))); + assertTrue(Double.isNaN(branchResult.getPtdfZonalSum(cnec, TwoSides.TWO))); assertTrue(branchResult.getPtdfZonalSums().isEmpty()); } } diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/FailedRaoResultImplTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/FailedRaoResultImplTest.java index e6cb11587e..7bf76748cf 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/FailedRaoResultImplTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/FailedRaoResultImplTest.java @@ -12,7 +12,7 @@ import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.cnec.AngleCnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.cnec.VoltageCnec; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; @@ -83,11 +83,11 @@ void testgetFlowAndMargin() { Instant optInstant = mock(Instant.class); FailedRaoResultImpl failedRaoResultImpl = new FailedRaoResultImpl(); FlowCnec flowCnec = mock(FlowCnec.class); - assertThrows(OpenRaoException.class, () -> failedRaoResultImpl.getFlow(optInstant, flowCnec, Side.LEFT, MEGAWATT)); - assertThrows(OpenRaoException.class, () -> failedRaoResultImpl.getCommercialFlow(optInstant, flowCnec, Side.LEFT, MEGAWATT)); - assertThrows(OpenRaoException.class, () -> failedRaoResultImpl.getLoopFlow(optInstant, flowCnec, Side.LEFT, MEGAWATT)); - assertThrows(OpenRaoException.class, () -> failedRaoResultImpl.getPtdfZonalSum(optInstant, flowCnec, Side.LEFT)); - assertThrows(OpenRaoException.class, () -> failedRaoResultImpl.getFlow(optInstant, flowCnec, Side.LEFT, MEGAWATT)); + assertThrows(OpenRaoException.class, () -> failedRaoResultImpl.getFlow(optInstant, flowCnec, TwoSides.ONE, MEGAWATT)); + assertThrows(OpenRaoException.class, () -> failedRaoResultImpl.getCommercialFlow(optInstant, flowCnec, TwoSides.ONE, MEGAWATT)); + assertThrows(OpenRaoException.class, () -> failedRaoResultImpl.getLoopFlow(optInstant, flowCnec, TwoSides.ONE, MEGAWATT)); + assertThrows(OpenRaoException.class, () -> failedRaoResultImpl.getPtdfZonalSum(optInstant, flowCnec, TwoSides.ONE)); + assertThrows(OpenRaoException.class, () -> failedRaoResultImpl.getFlow(optInstant, flowCnec, TwoSides.ONE, MEGAWATT)); assertThrows(OpenRaoException.class, () -> failedRaoResultImpl.getMargin(optInstant, flowCnec, MEGAWATT)); assertThrows(OpenRaoException.class, () -> failedRaoResultImpl.getRelativeMargin(optInstant, flowCnec, MEGAWATT)); } diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultFromMapImplTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultFromMapImplTest.java index f815be0af5..d0beb55323 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultFromMapImplTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultFromMapImplTest.java @@ -17,8 +17,8 @@ import java.util.Map; import static com.powsybl.openrao.commons.Unit.*; -import static com.powsybl.openrao.data.cracapi.cnec.Side.LEFT; -import static com.powsybl.openrao.data.cracapi.cnec.Side.RIGHT; +import static com.powsybl.iidm.network.TwoSides.ONE; +import static com.powsybl.iidm.network.TwoSides.TWO; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; @@ -42,62 +42,62 @@ public void setUp() { optimizedCnec = Mockito.mock(FlowCnec.class); branchResultFromMap = new FlowResultFromMapImpl( systematicSensitivityResult, - Map.of(loopFlowCnec, Map.of(LEFT, 200., RIGHT, 250.)), - Map.of(optimizedCnec, Map.of(LEFT, 30., RIGHT, 35.)) + Map.of(loopFlowCnec, Map.of(ONE, 200., TWO, 250.)), + Map.of(optimizedCnec, Map.of(ONE, 30., TWO, 35.)) ); } @Test void testBasicReturns() { - when(systematicSensitivityResult.getReferenceFlow(loopFlowCnec, LEFT)).thenReturn(200.); - when(systematicSensitivityResult.getReferenceFlow(loopFlowCnec, RIGHT)).thenReturn(250.); - when(systematicSensitivityResult.getReferenceIntensity(loopFlowCnec, LEFT)).thenReturn(58.); - when(systematicSensitivityResult.getReferenceIntensity(loopFlowCnec, RIGHT)).thenReturn(63.); - when(systematicSensitivityResult.getReferenceFlow(optimizedCnec, LEFT)).thenReturn(500.); - when(systematicSensitivityResult.getReferenceFlow(optimizedCnec, RIGHT)).thenReturn(550.); - when(systematicSensitivityResult.getReferenceIntensity(optimizedCnec, LEFT)).thenReturn(235.); - when(systematicSensitivityResult.getReferenceIntensity(optimizedCnec, RIGHT)).thenReturn(285.); + when(systematicSensitivityResult.getReferenceFlow(loopFlowCnec, ONE)).thenReturn(200.); + when(systematicSensitivityResult.getReferenceFlow(loopFlowCnec, TWO)).thenReturn(250.); + when(systematicSensitivityResult.getReferenceIntensity(loopFlowCnec, ONE)).thenReturn(58.); + when(systematicSensitivityResult.getReferenceIntensity(loopFlowCnec, TWO)).thenReturn(63.); + when(systematicSensitivityResult.getReferenceFlow(optimizedCnec, ONE)).thenReturn(500.); + when(systematicSensitivityResult.getReferenceFlow(optimizedCnec, TWO)).thenReturn(550.); + when(systematicSensitivityResult.getReferenceIntensity(optimizedCnec, ONE)).thenReturn(235.); + when(systematicSensitivityResult.getReferenceIntensity(optimizedCnec, TWO)).thenReturn(285.); - assertEquals(200, branchResultFromMap.getFlow(loopFlowCnec, LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(250, branchResultFromMap.getFlow(loopFlowCnec, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(58, branchResultFromMap.getFlow(loopFlowCnec, LEFT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(63, branchResultFromMap.getFlow(loopFlowCnec, RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(500, branchResultFromMap.getFlow(optimizedCnec, LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(550, branchResultFromMap.getFlow(optimizedCnec, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(235, branchResultFromMap.getFlow(optimizedCnec, LEFT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(285, branchResultFromMap.getFlow(optimizedCnec, RIGHT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(200, branchResultFromMap.getFlow(loopFlowCnec, ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(250, branchResultFromMap.getFlow(loopFlowCnec, TWO, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(58, branchResultFromMap.getFlow(loopFlowCnec, ONE, AMPERE), DOUBLE_TOLERANCE); + assertEquals(63, branchResultFromMap.getFlow(loopFlowCnec, TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(500, branchResultFromMap.getFlow(optimizedCnec, ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(550, branchResultFromMap.getFlow(optimizedCnec, TWO, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(235, branchResultFromMap.getFlow(optimizedCnec, ONE, AMPERE), DOUBLE_TOLERANCE); + assertEquals(285, branchResultFromMap.getFlow(optimizedCnec, TWO, AMPERE), DOUBLE_TOLERANCE); - assertThrows(OpenRaoException.class, () -> branchResultFromMap.getPtdfZonalSum(loopFlowCnec, LEFT)); - assertThrows(OpenRaoException.class, () -> branchResultFromMap.getPtdfZonalSum(loopFlowCnec, RIGHT)); - assertEquals(30., branchResultFromMap.getPtdfZonalSum(optimizedCnec, LEFT), DOUBLE_TOLERANCE); - assertEquals(35., branchResultFromMap.getPtdfZonalSum(optimizedCnec, RIGHT), DOUBLE_TOLERANCE); - assertEquals(Map.of(optimizedCnec, Map.of(LEFT, 30., RIGHT, 35.)), branchResultFromMap.getPtdfZonalSums()); + assertThrows(OpenRaoException.class, () -> branchResultFromMap.getPtdfZonalSum(loopFlowCnec, ONE)); + assertThrows(OpenRaoException.class, () -> branchResultFromMap.getPtdfZonalSum(loopFlowCnec, TWO)); + assertEquals(30., branchResultFromMap.getPtdfZonalSum(optimizedCnec, ONE), DOUBLE_TOLERANCE); + assertEquals(35., branchResultFromMap.getPtdfZonalSum(optimizedCnec, TWO), DOUBLE_TOLERANCE); + assertEquals(Map.of(optimizedCnec, Map.of(ONE, 30., TWO, 35.)), branchResultFromMap.getPtdfZonalSums()); - assertEquals(200, branchResultFromMap.getCommercialFlow(loopFlowCnec, LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(250, branchResultFromMap.getCommercialFlow(loopFlowCnec, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); - assertThrows(OpenRaoException.class, () -> branchResultFromMap.getCommercialFlow(loopFlowCnec, LEFT, AMPERE)); - assertThrows(OpenRaoException.class, () -> branchResultFromMap.getCommercialFlow(loopFlowCnec, RIGHT, AMPERE)); - assertThrows(OpenRaoException.class, () -> branchResultFromMap.getCommercialFlow(optimizedCnec, LEFT, MEGAWATT)); - assertThrows(OpenRaoException.class, () -> branchResultFromMap.getCommercialFlow(optimizedCnec, RIGHT, MEGAWATT)); + assertEquals(200, branchResultFromMap.getCommercialFlow(loopFlowCnec, ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(250, branchResultFromMap.getCommercialFlow(loopFlowCnec, TWO, MEGAWATT), DOUBLE_TOLERANCE); + assertThrows(OpenRaoException.class, () -> branchResultFromMap.getCommercialFlow(loopFlowCnec, ONE, AMPERE)); + assertThrows(OpenRaoException.class, () -> branchResultFromMap.getCommercialFlow(loopFlowCnec, TWO, AMPERE)); + assertThrows(OpenRaoException.class, () -> branchResultFromMap.getCommercialFlow(optimizedCnec, ONE, MEGAWATT)); + assertThrows(OpenRaoException.class, () -> branchResultFromMap.getCommercialFlow(optimizedCnec, TWO, MEGAWATT)); } @Test void testNanFlow() { - when(systematicSensitivityResult.getReferenceIntensity(optimizedCnec, LEFT)).thenReturn(Double.NaN); - when(systematicSensitivityResult.getReferenceIntensity(optimizedCnec, RIGHT)).thenReturn(Double.NaN); - when(systematicSensitivityResult.getReferenceFlow(optimizedCnec, LEFT)).thenReturn(500.); - when(systematicSensitivityResult.getReferenceFlow(optimizedCnec, RIGHT)).thenReturn(550.); + when(systematicSensitivityResult.getReferenceIntensity(optimizedCnec, ONE)).thenReturn(Double.NaN); + when(systematicSensitivityResult.getReferenceIntensity(optimizedCnec, TWO)).thenReturn(Double.NaN); + when(systematicSensitivityResult.getReferenceFlow(optimizedCnec, ONE)).thenReturn(500.); + when(systematicSensitivityResult.getReferenceFlow(optimizedCnec, TWO)).thenReturn(550.); when(optimizedCnec.getNominalVoltage(any())).thenReturn(400.); - assertEquals(721.69, branchResultFromMap.getFlow(optimizedCnec, LEFT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(793.86, branchResultFromMap.getFlow(optimizedCnec, RIGHT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(721.69, branchResultFromMap.getFlow(optimizedCnec, ONE, AMPERE), DOUBLE_TOLERANCE); + assertEquals(793.86, branchResultFromMap.getFlow(optimizedCnec, TWO, AMPERE), DOUBLE_TOLERANCE); } @Test void testWrongFlowUnit() { - assertThrows(OpenRaoException.class, () -> branchResultFromMap.getFlow(optimizedCnec, LEFT, KILOVOLT)); - assertThrows(OpenRaoException.class, () -> branchResultFromMap.getFlow(optimizedCnec, RIGHT, DEGREE)); - assertThrows(OpenRaoException.class, () -> branchResultFromMap.getFlow(optimizedCnec, LEFT, PERCENT_IMAX)); - assertThrows(OpenRaoException.class, () -> branchResultFromMap.getFlow(optimizedCnec, RIGHT, TAP)); + assertThrows(OpenRaoException.class, () -> branchResultFromMap.getFlow(optimizedCnec, ONE, KILOVOLT)); + assertThrows(OpenRaoException.class, () -> branchResultFromMap.getFlow(optimizedCnec, TWO, DEGREE)); + assertThrows(OpenRaoException.class, () -> branchResultFromMap.getFlow(optimizedCnec, ONE, PERCENT_IMAX)); + assertThrows(OpenRaoException.class, () -> branchResultFromMap.getFlow(optimizedCnec, TWO, TAP)); } } diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultImplTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultImplTest.java index f54b25ce34..de396f543b 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultImplTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultImplTest.java @@ -23,8 +23,8 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; -import static com.powsybl.openrao.data.cracapi.cnec.Side.LEFT; -import static com.powsybl.openrao.data.cracapi.cnec.Side.RIGHT; +import static com.powsybl.iidm.network.TwoSides.ONE; +import static com.powsybl.iidm.network.TwoSides.TWO; /** * @author Peter Mitri {@literal } @@ -44,13 +44,13 @@ public void setUp() { optimizedCnec = Mockito.mock(FlowCnec.class); FlowResult fixedCommercialFlows = Mockito.mock(FlowResult.class); - when(fixedCommercialFlows.getCommercialFlow(loopFlowCnec, LEFT, Unit.MEGAWATT)).thenReturn(200.); - when(fixedCommercialFlows.getCommercialFlow(eq(optimizedCnec), eq(RIGHT), any())).thenThrow(new OpenRaoException("a mock of what would happen if trying to access LF")); + when(fixedCommercialFlows.getCommercialFlow(loopFlowCnec, ONE, Unit.MEGAWATT)).thenReturn(200.); + when(fixedCommercialFlows.getCommercialFlow(eq(optimizedCnec), eq(TWO), any())).thenThrow(new OpenRaoException("a mock of what would happen if trying to access LF")); FlowResult fixedPtdfs = Mockito.mock(FlowResult.class); - when(fixedPtdfs.getPtdfZonalSums()).thenReturn(Map.of(optimizedCnec, Map.of(RIGHT, 30.))); - when(fixedPtdfs.getPtdfZonalSum(optimizedCnec, RIGHT)).thenReturn(30.); - when(fixedPtdfs.getPtdfZonalSum(loopFlowCnec, LEFT)).thenThrow(new OpenRaoException("a mock of what would happen if trying to access ptdf sum")); + when(fixedPtdfs.getPtdfZonalSums()).thenReturn(Map.of(optimizedCnec, Map.of(TWO, 30.))); + when(fixedPtdfs.getPtdfZonalSum(optimizedCnec, TWO)).thenReturn(30.); + when(fixedPtdfs.getPtdfZonalSum(loopFlowCnec, ONE)).thenThrow(new OpenRaoException("a mock of what would happen if trying to access ptdf sum")); branchResult = new FlowResultImpl( systematicSensitivityResult, @@ -61,39 +61,39 @@ public void setUp() { @Test void testBasicReturns() { - when(systematicSensitivityResult.getReferenceFlow(loopFlowCnec, LEFT)).thenReturn(200.); - when(systematicSensitivityResult.getReferenceIntensity(loopFlowCnec, LEFT)).thenReturn(58.); - when(systematicSensitivityResult.getReferenceFlow(optimizedCnec, RIGHT)).thenReturn(500.); - when(systematicSensitivityResult.getReferenceIntensity(optimizedCnec, RIGHT)).thenReturn(235.); - - assertEquals(200, branchResult.getFlow(loopFlowCnec, LEFT, Unit.MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(58, branchResult.getFlow(loopFlowCnec, LEFT, Unit.AMPERE), DOUBLE_TOLERANCE); - assertEquals(500, branchResult.getFlow(optimizedCnec, RIGHT, Unit.MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(235, branchResult.getFlow(optimizedCnec, RIGHT, Unit.AMPERE), DOUBLE_TOLERANCE); - - assertThrows(OpenRaoException.class, () -> branchResult.getPtdfZonalSum(loopFlowCnec, LEFT)); - assertEquals(30., branchResult.getPtdfZonalSum(optimizedCnec, RIGHT), DOUBLE_TOLERANCE); - assertEquals(Map.of(optimizedCnec, Map.of(RIGHT, 30.)), branchResult.getPtdfZonalSums()); - - assertEquals(200, branchResult.getCommercialFlow(loopFlowCnec, LEFT, Unit.MEGAWATT), DOUBLE_TOLERANCE); - assertThrows(OpenRaoException.class, () -> branchResult.getCommercialFlow(loopFlowCnec, LEFT, Unit.AMPERE)); - assertThrows(OpenRaoException.class, () -> branchResult.getCommercialFlow(optimizedCnec, RIGHT, Unit.MEGAWATT)); + when(systematicSensitivityResult.getReferenceFlow(loopFlowCnec, ONE)).thenReturn(200.); + when(systematicSensitivityResult.getReferenceIntensity(loopFlowCnec, ONE)).thenReturn(58.); + when(systematicSensitivityResult.getReferenceFlow(optimizedCnec, TWO)).thenReturn(500.); + when(systematicSensitivityResult.getReferenceIntensity(optimizedCnec, TWO)).thenReturn(235.); + + assertEquals(200, branchResult.getFlow(loopFlowCnec, ONE, Unit.MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(58, branchResult.getFlow(loopFlowCnec, ONE, Unit.AMPERE), DOUBLE_TOLERANCE); + assertEquals(500, branchResult.getFlow(optimizedCnec, TWO, Unit.MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(235, branchResult.getFlow(optimizedCnec, TWO, Unit.AMPERE), DOUBLE_TOLERANCE); + + assertThrows(OpenRaoException.class, () -> branchResult.getPtdfZonalSum(loopFlowCnec, ONE)); + assertEquals(30., branchResult.getPtdfZonalSum(optimizedCnec, TWO), DOUBLE_TOLERANCE); + assertEquals(Map.of(optimizedCnec, Map.of(TWO, 30.)), branchResult.getPtdfZonalSums()); + + assertEquals(200, branchResult.getCommercialFlow(loopFlowCnec, ONE, Unit.MEGAWATT), DOUBLE_TOLERANCE); + assertThrows(OpenRaoException.class, () -> branchResult.getCommercialFlow(loopFlowCnec, ONE, Unit.AMPERE)); + assertThrows(OpenRaoException.class, () -> branchResult.getCommercialFlow(optimizedCnec, TWO, Unit.MEGAWATT)); } @Test void testNanFlow() { - when(systematicSensitivityResult.getReferenceIntensity(optimizedCnec, RIGHT)).thenReturn(Double.NaN); - when(systematicSensitivityResult.getReferenceFlow(optimizedCnec, RIGHT)).thenReturn(500.); + when(systematicSensitivityResult.getReferenceIntensity(optimizedCnec, TWO)).thenReturn(Double.NaN); + when(systematicSensitivityResult.getReferenceFlow(optimizedCnec, TWO)).thenReturn(500.); when(optimizedCnec.getNominalVoltage(any())).thenReturn(400.); - assertEquals(721.69, branchResult.getFlow(optimizedCnec, RIGHT, Unit.AMPERE), DOUBLE_TOLERANCE); + assertEquals(721.69, branchResult.getFlow(optimizedCnec, TWO, Unit.AMPERE), DOUBLE_TOLERANCE); } @Test void testWrongFlowUnit() { - assertThrows(OpenRaoException.class, () -> branchResult.getFlow(optimizedCnec, RIGHT, Unit.KILOVOLT)); - assertThrows(OpenRaoException.class, () -> branchResult.getFlow(optimizedCnec, RIGHT, Unit.DEGREE)); - assertThrows(OpenRaoException.class, () -> branchResult.getFlow(optimizedCnec, RIGHT, Unit.PERCENT_IMAX)); - assertThrows(OpenRaoException.class, () -> branchResult.getFlow(optimizedCnec, RIGHT, Unit.TAP)); + assertThrows(OpenRaoException.class, () -> branchResult.getFlow(optimizedCnec, TWO, Unit.KILOVOLT)); + assertThrows(OpenRaoException.class, () -> branchResult.getFlow(optimizedCnec, TWO, Unit.DEGREE)); + assertThrows(OpenRaoException.class, () -> branchResult.getFlow(optimizedCnec, TWO, Unit.PERCENT_IMAX)); + assertThrows(OpenRaoException.class, () -> branchResult.getFlow(optimizedCnec, TWO, Unit.TAP)); } } diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/OneStateOnlyRaoResultImplTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/OneStateOnlyRaoResultImplTest.java index f25aa19454..48f98ca197 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/OneStateOnlyRaoResultImplTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/OneStateOnlyRaoResultImplTest.java @@ -14,7 +14,7 @@ import com.powsybl.openrao.data.cracapi.*; import com.powsybl.openrao.data.cracapi.cnec.AngleCnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.cnec.VoltageCnec; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; @@ -93,22 +93,22 @@ public void setUp() { when(initialResult.getMargin(cnec1, Unit.AMPERE)).thenReturn(-500.); when(initialResult.getRelativeMargin(cnec1, Unit.MEGAWATT)).thenReturn(-2000.); when(initialResult.getRelativeMargin(cnec1, Unit.AMPERE)).thenReturn(-1000.); - when(initialResult.getFlow(cnec1, Side.LEFT, MEGAWATT)).thenReturn(-300.); - when(initialResult.getFlow(cnec1, Side.RIGHT, Unit.AMPERE)).thenReturn(-150.); - when(initialResult.getCommercialFlow(cnec1, Side.LEFT, MEGAWATT)).thenReturn(-300.); - when(initialResult.getCommercialFlow(cnec1, Side.RIGHT, Unit.AMPERE)).thenReturn(-150.); - when(initialResult.getLoopFlow(cnec1, Side.LEFT, MEGAWATT)).thenReturn(0.); - when(initialResult.getLoopFlow(cnec1, Side.RIGHT, Unit.AMPERE)).thenReturn(-0.); + when(initialResult.getFlow(cnec1, TwoSides.ONE, MEGAWATT)).thenReturn(-300.); + when(initialResult.getFlow(cnec1, TwoSides.TWO, Unit.AMPERE)).thenReturn(-150.); + when(initialResult.getCommercialFlow(cnec1, TwoSides.ONE, MEGAWATT)).thenReturn(-300.); + when(initialResult.getCommercialFlow(cnec1, TwoSides.TWO, Unit.AMPERE)).thenReturn(-150.); + when(initialResult.getLoopFlow(cnec1, TwoSides.ONE, MEGAWATT)).thenReturn(0.); + when(initialResult.getLoopFlow(cnec1, TwoSides.TWO, Unit.AMPERE)).thenReturn(-0.); when(initialResult.getMargin(cnec2, Unit.MEGAWATT)).thenReturn(-500.); when(initialResult.getMargin(cnec2, Unit.AMPERE)).thenReturn(-250.); when(initialResult.getRelativeMargin(cnec2, Unit.MEGAWATT)).thenReturn(-1500.); when(initialResult.getRelativeMargin(cnec2, Unit.AMPERE)).thenReturn(-750.); - when(initialResult.getFlow(cnec2, Side.LEFT, MEGAWATT)).thenReturn(-1000.); - when(initialResult.getFlow(cnec2, Side.RIGHT, Unit.AMPERE)).thenReturn(500.); - when(initialResult.getCommercialFlow(cnec2, Side.LEFT, MEGAWATT)).thenReturn(-700.); - when(initialResult.getCommercialFlow(cnec2, Side.RIGHT, Unit.AMPERE)).thenReturn(450.); - when(initialResult.getLoopFlow(cnec2, Side.LEFT, MEGAWATT)).thenReturn(-300.); - when(initialResult.getLoopFlow(cnec2, Side.RIGHT, Unit.AMPERE)).thenReturn(50.); + when(initialResult.getFlow(cnec2, TwoSides.ONE, MEGAWATT)).thenReturn(-1000.); + when(initialResult.getFlow(cnec2, TwoSides.TWO, Unit.AMPERE)).thenReturn(500.); + when(initialResult.getCommercialFlow(cnec2, TwoSides.ONE, MEGAWATT)).thenReturn(-700.); + when(initialResult.getCommercialFlow(cnec2, TwoSides.TWO, Unit.AMPERE)).thenReturn(450.); + when(initialResult.getLoopFlow(cnec2, TwoSides.ONE, MEGAWATT)).thenReturn(-300.); + when(initialResult.getLoopFlow(cnec2, TwoSides.TWO, Unit.AMPERE)).thenReturn(50.); when(postOptimizationResult.getFunctionalCost()).thenReturn(-1000.); when(postOptimizationResult.getMostLimitingElements(anyInt())).thenReturn(List.of(cnec2)); @@ -130,22 +130,22 @@ public void setUp() { when(postOptimizationResult.getMargin(cnec2, Unit.AMPERE)).thenReturn(500.); when(postOptimizationResult.getRelativeMargin(cnec2, Unit.MEGAWATT)).thenReturn(2000.); when(postOptimizationResult.getRelativeMargin(cnec2, Unit.AMPERE)).thenReturn(1000.); - when(postOptimizationResult.getFlow(cnec2, Side.LEFT, MEGAWATT)).thenReturn(-700.); - when(postOptimizationResult.getFlow(cnec2, Side.RIGHT, Unit.AMPERE)).thenReturn(300.); - when(postOptimizationResult.getCommercialFlow(cnec2, Side.LEFT, MEGAWATT)).thenReturn(-600.); - when(postOptimizationResult.getCommercialFlow(cnec2, Side.RIGHT, Unit.AMPERE)).thenReturn(250.); - when(postOptimizationResult.getLoopFlow(cnec2, Side.LEFT, MEGAWATT)).thenReturn(-100.); - when(postOptimizationResult.getLoopFlow(cnec2, Side.RIGHT, Unit.AMPERE)).thenReturn(50.); + when(postOptimizationResult.getFlow(cnec2, TwoSides.ONE, MEGAWATT)).thenReturn(-700.); + when(postOptimizationResult.getFlow(cnec2, TwoSides.TWO, Unit.AMPERE)).thenReturn(300.); + when(postOptimizationResult.getCommercialFlow(cnec2, TwoSides.ONE, MEGAWATT)).thenReturn(-600.); + when(postOptimizationResult.getCommercialFlow(cnec2, TwoSides.TWO, Unit.AMPERE)).thenReturn(250.); + when(postOptimizationResult.getLoopFlow(cnec2, TwoSides.ONE, MEGAWATT)).thenReturn(-100.); + when(postOptimizationResult.getLoopFlow(cnec2, TwoSides.TWO, Unit.AMPERE)).thenReturn(50.); when(postOptimizationResult.getMargin(cnec1, Unit.MEGAWATT)).thenReturn(500.); when(postOptimizationResult.getMargin(cnec1, Unit.AMPERE)).thenReturn(250.); when(postOptimizationResult.getRelativeMargin(cnec1, Unit.MEGAWATT)).thenReturn(1500.); when(postOptimizationResult.getRelativeMargin(cnec1, Unit.AMPERE)).thenReturn(750.); - when(postOptimizationResult.getFlow(cnec1, Side.LEFT, MEGAWATT)).thenReturn(20.); - when(postOptimizationResult.getFlow(cnec1, Side.RIGHT, Unit.AMPERE)).thenReturn(10.); - when(postOptimizationResult.getCommercialFlow(cnec1, Side.LEFT, MEGAWATT)).thenReturn(20.); - when(postOptimizationResult.getCommercialFlow(cnec1, Side.RIGHT, Unit.AMPERE)).thenReturn(10.); - when(postOptimizationResult.getLoopFlow(cnec1, Side.LEFT, MEGAWATT)).thenReturn(0.); - when(postOptimizationResult.getLoopFlow(cnec1, Side.RIGHT, Unit.AMPERE)).thenReturn(0.); + when(postOptimizationResult.getFlow(cnec1, TwoSides.ONE, MEGAWATT)).thenReturn(20.); + when(postOptimizationResult.getFlow(cnec1, TwoSides.TWO, Unit.AMPERE)).thenReturn(10.); + when(postOptimizationResult.getCommercialFlow(cnec1, TwoSides.ONE, MEGAWATT)).thenReturn(20.); + when(postOptimizationResult.getCommercialFlow(cnec1, TwoSides.TWO, Unit.AMPERE)).thenReturn(10.); + when(postOptimizationResult.getLoopFlow(cnec1, TwoSides.ONE, MEGAWATT)).thenReturn(0.); + when(postOptimizationResult.getLoopFlow(cnec1, TwoSides.TWO, Unit.AMPERE)).thenReturn(0.); Set cnecs = new HashSet<>(); cnecs.add(cnec1); @@ -222,73 +222,73 @@ void testPreventiveCase() { assertEquals(-500., output.getMargin(null, cnec1, Unit.AMPERE), DOUBLE_TOLERANCE); assertEquals(-2000., output.getRelativeMargin(null, cnec1, Unit.MEGAWATT), DOUBLE_TOLERANCE); assertEquals(-1000., output.getRelativeMargin(null, cnec1, Unit.AMPERE), DOUBLE_TOLERANCE); - assertEquals(-300, output.getFlow(null, cnec1, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(-150, output.getFlow(null, cnec1, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(-300, output.getCommercialFlow(null, cnec1, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(-150, output.getCommercialFlow(null, cnec1, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(0, output.getLoopFlow(null, cnec1, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(0, output.getLoopFlow(null, cnec1, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(0, output.getPtdfZonalSum(null, cnec1, Side.RIGHT), DOUBLE_TOLERANCE); + assertEquals(-300, output.getFlow(null, cnec1, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(-150, output.getFlow(null, cnec1, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(-300, output.getCommercialFlow(null, cnec1, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(-150, output.getCommercialFlow(null, cnec1, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(0, output.getLoopFlow(null, cnec1, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(0, output.getLoopFlow(null, cnec1, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(0, output.getPtdfZonalSum(null, cnec1, TwoSides.TWO), DOUBLE_TOLERANCE); // cnec2 initial assertEquals(-500., output.getMargin(null, cnec2, Unit.MEGAWATT), DOUBLE_TOLERANCE); assertEquals(-250., output.getMargin(null, cnec2, Unit.AMPERE), DOUBLE_TOLERANCE); assertEquals(-1500., output.getRelativeMargin(null, cnec2, Unit.MEGAWATT), DOUBLE_TOLERANCE); assertEquals(-750., output.getRelativeMargin(null, cnec2, Unit.AMPERE), DOUBLE_TOLERANCE); - assertEquals(-1000, output.getFlow(null, cnec2, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(500, output.getFlow(null, cnec2, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(-700, output.getCommercialFlow(null, cnec2, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(450, output.getCommercialFlow(null, cnec2, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(-300, output.getLoopFlow(null, cnec2, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(50, output.getLoopFlow(null, cnec2, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(-1000, output.getFlow(null, cnec2, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(500, output.getFlow(null, cnec2, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(-700, output.getCommercialFlow(null, cnec2, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(450, output.getCommercialFlow(null, cnec2, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(-300, output.getLoopFlow(null, cnec2, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(50, output.getLoopFlow(null, cnec2, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); // cnec1 afterPRA assertEquals(500., output.getMargin(preventiveInstant, cnec1, Unit.MEGAWATT), DOUBLE_TOLERANCE); assertEquals(250., output.getMargin(preventiveInstant, cnec1, Unit.AMPERE), DOUBLE_TOLERANCE); assertEquals(1500., output.getRelativeMargin(preventiveInstant, cnec1, Unit.MEGAWATT), DOUBLE_TOLERANCE); assertEquals(750., output.getRelativeMargin(preventiveInstant, cnec1, Unit.AMPERE), DOUBLE_TOLERANCE); - assertEquals(20, output.getFlow(preventiveInstant, cnec1, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(10, output.getFlow(preventiveInstant, cnec1, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(20, output.getCommercialFlow(preventiveInstant, cnec1, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(10, output.getCommercialFlow(preventiveInstant, cnec1, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(0, output.getLoopFlow(preventiveInstant, cnec1, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(0, output.getLoopFlow(preventiveInstant, cnec1, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(20, output.getFlow(preventiveInstant, cnec1, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(10, output.getFlow(preventiveInstant, cnec1, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(20, output.getCommercialFlow(preventiveInstant, cnec1, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(10, output.getCommercialFlow(preventiveInstant, cnec1, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(0, output.getLoopFlow(preventiveInstant, cnec1, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(0, output.getLoopFlow(preventiveInstant, cnec1, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); // cnec2 afterPRA assertEquals(1000., output.getMargin(preventiveInstant, cnec2, Unit.MEGAWATT), DOUBLE_TOLERANCE); assertEquals(500., output.getMargin(preventiveInstant, cnec2, Unit.AMPERE), DOUBLE_TOLERANCE); assertEquals(2000., output.getRelativeMargin(preventiveInstant, cnec2, Unit.MEGAWATT), DOUBLE_TOLERANCE); assertEquals(1000., output.getRelativeMargin(preventiveInstant, cnec2, Unit.AMPERE), DOUBLE_TOLERANCE); - assertEquals(-700, output.getFlow(preventiveInstant, cnec2, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(300, output.getFlow(preventiveInstant, cnec2, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(-600, output.getCommercialFlow(preventiveInstant, cnec2, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(250, output.getCommercialFlow(preventiveInstant, cnec2, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(-100, output.getLoopFlow(preventiveInstant, cnec2, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(50, output.getLoopFlow(preventiveInstant, cnec2, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(-700, output.getFlow(preventiveInstant, cnec2, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(300, output.getFlow(preventiveInstant, cnec2, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(-600, output.getCommercialFlow(preventiveInstant, cnec2, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(250, output.getCommercialFlow(preventiveInstant, cnec2, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(-100, output.getLoopFlow(preventiveInstant, cnec2, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(50, output.getLoopFlow(preventiveInstant, cnec2, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); // cnec1 afterCRA assertEquals(500., output.getMargin(curativeInstant, cnec1, Unit.MEGAWATT), DOUBLE_TOLERANCE); assertEquals(250., output.getMargin(curativeInstant, cnec1, Unit.AMPERE), DOUBLE_TOLERANCE); assertEquals(1500., output.getRelativeMargin(curativeInstant, cnec1, Unit.MEGAWATT), DOUBLE_TOLERANCE); assertEquals(750., output.getRelativeMargin(curativeInstant, cnec1, Unit.AMPERE), DOUBLE_TOLERANCE); - assertEquals(20, output.getFlow(curativeInstant, cnec1, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(10, output.getFlow(curativeInstant, cnec1, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(20, output.getCommercialFlow(curativeInstant, cnec1, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(10, output.getCommercialFlow(curativeInstant, cnec1, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(0, output.getLoopFlow(curativeInstant, cnec1, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(0, output.getLoopFlow(curativeInstant, cnec1, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(20, output.getFlow(curativeInstant, cnec1, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(10, output.getFlow(curativeInstant, cnec1, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(20, output.getCommercialFlow(curativeInstant, cnec1, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(10, output.getCommercialFlow(curativeInstant, cnec1, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(0, output.getLoopFlow(curativeInstant, cnec1, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(0, output.getLoopFlow(curativeInstant, cnec1, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); // cnec2 afterCRA assertEquals(1000., output.getMargin(curativeInstant, cnec2, Unit.MEGAWATT), DOUBLE_TOLERANCE); assertEquals(500., output.getMargin(curativeInstant, cnec2, Unit.AMPERE), DOUBLE_TOLERANCE); assertEquals(2000., output.getRelativeMargin(curativeInstant, cnec2, Unit.MEGAWATT), DOUBLE_TOLERANCE); assertEquals(1000., output.getRelativeMargin(curativeInstant, cnec2, Unit.AMPERE), DOUBLE_TOLERANCE); - assertEquals(-700, output.getFlow(curativeInstant, cnec2, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(300, output.getFlow(curativeInstant, cnec2, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(-600, output.getCommercialFlow(curativeInstant, cnec2, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(250, output.getCommercialFlow(curativeInstant, cnec2, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(-100, output.getLoopFlow(curativeInstant, cnec2, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(50, output.getLoopFlow(curativeInstant, cnec2, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(-700, output.getFlow(curativeInstant, cnec2, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(300, output.getFlow(curativeInstant, cnec2, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(-600, output.getCommercialFlow(curativeInstant, cnec2, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(250, output.getCommercialFlow(curativeInstant, cnec2, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(-100, output.getLoopFlow(curativeInstant, cnec2, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(50, output.getLoopFlow(curativeInstant, cnec2, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); // using another state State otherState = mock(State.class); @@ -341,32 +341,32 @@ void testCurativeCase1() { assertEquals(-500., output.getMargin(null, cnec1, Unit.AMPERE), DOUBLE_TOLERANCE); assertEquals(-2000., output.getRelativeMargin(null, cnec1, Unit.MEGAWATT), DOUBLE_TOLERANCE); assertEquals(-1000., output.getRelativeMargin(null, cnec1, Unit.AMPERE), DOUBLE_TOLERANCE); - assertEquals(-300, output.getFlow(null, cnec1, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(-150, output.getFlow(null, cnec1, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(-300, output.getCommercialFlow(null, cnec1, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(-150, output.getCommercialFlow(null, cnec1, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(0, output.getLoopFlow(null, cnec1, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(0, output.getLoopFlow(null, cnec1, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(-300, output.getFlow(null, cnec1, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(-150, output.getFlow(null, cnec1, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(-300, output.getCommercialFlow(null, cnec1, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(-150, output.getCommercialFlow(null, cnec1, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(0, output.getLoopFlow(null, cnec1, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(0, output.getLoopFlow(null, cnec1, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); assertEquals(-1000., output.getMargin(preventiveInstant, cnec1, Unit.MEGAWATT), DOUBLE_TOLERANCE); assertEquals(-500., output.getMargin(preventiveInstant, cnec1, Unit.AMPERE), DOUBLE_TOLERANCE); assertEquals(-2000., output.getRelativeMargin(preventiveInstant, cnec1, Unit.MEGAWATT), DOUBLE_TOLERANCE); assertEquals(-1000., output.getRelativeMargin(preventiveInstant, cnec1, Unit.AMPERE), DOUBLE_TOLERANCE); - assertEquals(-300, output.getFlow(preventiveInstant, cnec1, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(-150, output.getFlow(preventiveInstant, cnec1, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(-300, output.getCommercialFlow(preventiveInstant, cnec1, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(-150, output.getCommercialFlow(preventiveInstant, cnec1, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(0, output.getLoopFlow(preventiveInstant, cnec1, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(0, output.getLoopFlow(preventiveInstant, cnec1, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(-300, output.getFlow(preventiveInstant, cnec1, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(-150, output.getFlow(preventiveInstant, cnec1, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(-300, output.getCommercialFlow(preventiveInstant, cnec1, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(-150, output.getCommercialFlow(preventiveInstant, cnec1, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(0, output.getLoopFlow(preventiveInstant, cnec1, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(0, output.getLoopFlow(preventiveInstant, cnec1, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); assertEquals(-1000., output.getMargin(curativeInstant, cnec1, Unit.MEGAWATT), DOUBLE_TOLERANCE); assertEquals(-500., output.getMargin(curativeInstant, cnec1, Unit.AMPERE), DOUBLE_TOLERANCE); assertEquals(-2000., output.getRelativeMargin(curativeInstant, cnec1, Unit.MEGAWATT), DOUBLE_TOLERANCE); assertEquals(-1000., output.getRelativeMargin(curativeInstant, cnec1, Unit.AMPERE), DOUBLE_TOLERANCE); - assertEquals(-300, output.getFlow(curativeInstant, cnec1, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(-150, output.getFlow(curativeInstant, cnec1, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(-300, output.getCommercialFlow(curativeInstant, cnec1, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(-150, output.getCommercialFlow(curativeInstant, cnec1, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(0, output.getLoopFlow(curativeInstant, cnec1, Side.LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(0, output.getLoopFlow(curativeInstant, cnec1, Side.RIGHT, AMPERE), DOUBLE_TOLERANCE); + assertEquals(-300, output.getFlow(curativeInstant, cnec1, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(-150, output.getFlow(curativeInstant, cnec1, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(-300, output.getCommercialFlow(curativeInstant, cnec1, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(-150, output.getCommercialFlow(curativeInstant, cnec1, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(0, output.getLoopFlow(curativeInstant, cnec1, TwoSides.ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(0, output.getLoopFlow(curativeInstant, cnec1, TwoSides.TWO, AMPERE), DOUBLE_TOLERANCE); // cnec2 assertEquals(-500., output.getMargin(null, cnec2, Unit.MEGAWATT), DOUBLE_TOLERANCE); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/PerimeterResultImplTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/PerimeterResultImplTest.java index df28cdc03b..5821dd773f 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/PerimeterResultImplTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/PerimeterResultImplTest.java @@ -11,7 +11,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; @@ -27,8 +27,8 @@ import java.util.Map; import java.util.Set; -import static com.powsybl.openrao.data.cracapi.cnec.Side.LEFT; -import static com.powsybl.openrao.data.cracapi.cnec.Side.RIGHT; +import static com.powsybl.iidm.network.TwoSides.ONE; +import static com.powsybl.iidm.network.TwoSides.TWO; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.mock; @@ -88,31 +88,31 @@ void testGetActivatedRangeActions() { @Test void testGetFlow() { - when(optimizationResult.getFlow(flowCnec1, LEFT, Unit.MEGAWATT)).thenReturn(100.); - when(optimizationResult.getFlow(flowCnec2, RIGHT, Unit.AMPERE)).thenReturn(200.); - assertEquals(100., perimeterResultImpl.getFlow(flowCnec1, LEFT, Unit.MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(200., perimeterResultImpl.getFlow(flowCnec2, RIGHT, Unit.AMPERE), DOUBLE_TOLERANCE); + when(optimizationResult.getFlow(flowCnec1, ONE, Unit.MEGAWATT)).thenReturn(100.); + when(optimizationResult.getFlow(flowCnec2, TWO, Unit.AMPERE)).thenReturn(200.); + assertEquals(100., perimeterResultImpl.getFlow(flowCnec1, ONE, Unit.MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(200., perimeterResultImpl.getFlow(flowCnec2, TWO, Unit.AMPERE), DOUBLE_TOLERANCE); } @Test void testGetCommercialFlow() { - when(optimizationResult.getCommercialFlow(flowCnec1, LEFT, Unit.MEGAWATT)).thenReturn(100.); - when(optimizationResult.getCommercialFlow(flowCnec2, RIGHT, Unit.AMPERE)).thenReturn(200.); - assertEquals(100., perimeterResultImpl.getCommercialFlow(flowCnec1, LEFT, Unit.MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(200., perimeterResultImpl.getCommercialFlow(flowCnec2, RIGHT, Unit.AMPERE), DOUBLE_TOLERANCE); + when(optimizationResult.getCommercialFlow(flowCnec1, ONE, Unit.MEGAWATT)).thenReturn(100.); + when(optimizationResult.getCommercialFlow(flowCnec2, TWO, Unit.AMPERE)).thenReturn(200.); + assertEquals(100., perimeterResultImpl.getCommercialFlow(flowCnec1, ONE, Unit.MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(200., perimeterResultImpl.getCommercialFlow(flowCnec2, TWO, Unit.AMPERE), DOUBLE_TOLERANCE); } @Test void testGetPtdfZonalSum() { - when(optimizationResult.getPtdfZonalSum(flowCnec1, LEFT)).thenReturn(100.); - when(optimizationResult.getPtdfZonalSum(flowCnec2, RIGHT)).thenReturn(200.); - assertEquals(100., perimeterResultImpl.getPtdfZonalSum(flowCnec1, LEFT), DOUBLE_TOLERANCE); - assertEquals(200., perimeterResultImpl.getPtdfZonalSum(flowCnec2, RIGHT), DOUBLE_TOLERANCE); + when(optimizationResult.getPtdfZonalSum(flowCnec1, ONE)).thenReturn(100.); + when(optimizationResult.getPtdfZonalSum(flowCnec2, TWO)).thenReturn(200.); + assertEquals(100., perimeterResultImpl.getPtdfZonalSum(flowCnec1, ONE), DOUBLE_TOLERANCE); + assertEquals(200., perimeterResultImpl.getPtdfZonalSum(flowCnec2, TWO), DOUBLE_TOLERANCE); } @Test void testGetPtdfZonalSums() { - Map> map = Map.of(flowCnec1, Map.of(LEFT, 100.), flowCnec2, Map.of(RIGHT, 200.)); + Map> map = Map.of(flowCnec1, Map.of(ONE, 100.), flowCnec2, Map.of(TWO, 200.)); when(optimizationResult.getPtdfZonalSums()).thenReturn(map); assertEquals(map, perimeterResultImpl.getPtdfZonalSums()); } @@ -220,13 +220,13 @@ void testGetSensitivityStatus() { @Test void testGetSensitivityValueOnRa() { - assertThrows(NotImplementedException.class, () -> perimeterResultImpl.getSensitivityValue(flowCnec1, LEFT, ra1, Unit.MEGAWATT)); - assertThrows(NotImplementedException.class, () -> perimeterResultImpl.getSensitivityValue(flowCnec1, LEFT, ra2, Unit.AMPERE)); + assertThrows(NotImplementedException.class, () -> perimeterResultImpl.getSensitivityValue(flowCnec1, ONE, ra1, Unit.MEGAWATT)); + assertThrows(NotImplementedException.class, () -> perimeterResultImpl.getSensitivityValue(flowCnec1, ONE, ra2, Unit.AMPERE)); } @Test void testGetSensitivityValueOnGlsk() { - assertThrows(NotImplementedException.class, () -> perimeterResultImpl.getSensitivityValue(flowCnec1, LEFT, mock(SensitivityVariableSet.class), Unit.MEGAWATT)); - assertThrows(NotImplementedException.class, () -> perimeterResultImpl.getSensitivityValue(flowCnec1, LEFT, mock(SensitivityVariableSet.class), Unit.AMPERE)); + assertThrows(NotImplementedException.class, () -> perimeterResultImpl.getSensitivityValue(flowCnec1, ONE, mock(SensitivityVariableSet.class), Unit.MEGAWATT)); + assertThrows(NotImplementedException.class, () -> perimeterResultImpl.getSensitivityValue(flowCnec1, ONE, mock(SensitivityVariableSet.class), Unit.AMPERE)); } } diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/PrePerimeterSensitivityResultImplTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/PrePerimeterSensitivityResultImplTest.java index dc406ccf72..a934f210c0 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/PrePerimeterSensitivityResultImplTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/PrePerimeterSensitivityResultImplTest.java @@ -25,8 +25,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.when; -import static com.powsybl.openrao.data.cracapi.cnec.Side.LEFT; -import static com.powsybl.openrao.data.cracapi.cnec.Side.RIGHT; +import static com.powsybl.iidm.network.TwoSides.ONE; +import static com.powsybl.iidm.network.TwoSides.TWO; /** * @author Peter Mitri {@literal } @@ -53,46 +53,46 @@ void testBasicReturns() { when(sensitivityResult.getSensitivityStatus()).thenReturn(ComputationStatus.DEFAULT); assertEquals(ComputationStatus.DEFAULT, output.getSensitivityStatus()); - when(sensitivityResult.getSensitivityValue(cnec1, RIGHT, ra1, Unit.MEGAWATT)).thenReturn(0.5); - when(sensitivityResult.getSensitivityValue(cnec2, LEFT, ra1, Unit.AMPERE)).thenReturn(0.1); - assertEquals(0.5, output.getSensitivityValue(cnec1, RIGHT, ra1, Unit.MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(0.1, output.getSensitivityValue(cnec2, LEFT, ra1, Unit.AMPERE), DOUBLE_TOLERANCE); + when(sensitivityResult.getSensitivityValue(cnec1, TWO, ra1, Unit.MEGAWATT)).thenReturn(0.5); + when(sensitivityResult.getSensitivityValue(cnec2, ONE, ra1, Unit.AMPERE)).thenReturn(0.1); + assertEquals(0.5, output.getSensitivityValue(cnec1, TWO, ra1, Unit.MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(0.1, output.getSensitivityValue(cnec2, ONE, ra1, Unit.AMPERE), DOUBLE_TOLERANCE); - when(sensitivityResult.getSensitivityValue(cnec2, LEFT, linearGlsk, Unit.MEGAWATT)).thenReturn(51.); - assertEquals(51., output.getSensitivityValue(cnec2, LEFT, linearGlsk, Unit.MEGAWATT), DOUBLE_TOLERANCE); + when(sensitivityResult.getSensitivityValue(cnec2, ONE, linearGlsk, Unit.MEGAWATT)).thenReturn(51.); + assertEquals(51., output.getSensitivityValue(cnec2, ONE, linearGlsk, Unit.MEGAWATT), DOUBLE_TOLERANCE); - when(flowResult.getFlow(cnec1, RIGHT, Unit.MEGAWATT)).thenReturn(10.); - when(flowResult.getFlow(cnec2, LEFT, Unit.AMPERE)).thenReturn(117.); - assertEquals(10., output.getFlow(cnec1, RIGHT, Unit.MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(117., output.getFlow(cnec2, LEFT, Unit.AMPERE), DOUBLE_TOLERANCE); + when(flowResult.getFlow(cnec1, TWO, Unit.MEGAWATT)).thenReturn(10.); + when(flowResult.getFlow(cnec2, ONE, Unit.AMPERE)).thenReturn(117.); + assertEquals(10., output.getFlow(cnec1, TWO, Unit.MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(117., output.getFlow(cnec2, ONE, Unit.AMPERE), DOUBLE_TOLERANCE); - when(flowResult.getRelativeMargin(cnec1, RIGHT, Unit.MEGAWATT)).thenReturn(564.); - when(flowResult.getRelativeMargin(cnec2, LEFT, Unit.AMPERE)).thenReturn(-451.); - assertEquals(564., output.getRelativeMargin(cnec1, RIGHT, Unit.MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(-451., output.getRelativeMargin(cnec2, LEFT, Unit.AMPERE), DOUBLE_TOLERANCE); + when(flowResult.getRelativeMargin(cnec1, TWO, Unit.MEGAWATT)).thenReturn(564.); + when(flowResult.getRelativeMargin(cnec2, ONE, Unit.AMPERE)).thenReturn(-451.); + assertEquals(564., output.getRelativeMargin(cnec1, TWO, Unit.MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(-451., output.getRelativeMargin(cnec2, ONE, Unit.AMPERE), DOUBLE_TOLERANCE); when(flowResult.getRelativeMargin(cnec1, Unit.MEGAWATT)).thenReturn(564.); when(flowResult.getRelativeMargin(cnec1, Unit.AMPERE)).thenReturn(-451.); assertEquals(564., output.getRelativeMargin(cnec1, Unit.MEGAWATT), DOUBLE_TOLERANCE); assertEquals(-451., output.getRelativeMargin(cnec1, Unit.AMPERE), DOUBLE_TOLERANCE); - when(flowResult.getLoopFlow(cnec1, RIGHT, Unit.MEGAWATT)).thenReturn(5064.); - when(flowResult.getLoopFlow(cnec2, LEFT, Unit.AMPERE)).thenReturn(-4510.); - assertEquals(5064., output.getLoopFlow(cnec1, RIGHT, Unit.MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(-4510., output.getLoopFlow(cnec2, LEFT, Unit.AMPERE), DOUBLE_TOLERANCE); + when(flowResult.getLoopFlow(cnec1, TWO, Unit.MEGAWATT)).thenReturn(5064.); + when(flowResult.getLoopFlow(cnec2, ONE, Unit.AMPERE)).thenReturn(-4510.); + assertEquals(5064., output.getLoopFlow(cnec1, TWO, Unit.MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(-4510., output.getLoopFlow(cnec2, ONE, Unit.AMPERE), DOUBLE_TOLERANCE); - when(flowResult.getCommercialFlow(cnec1, RIGHT, Unit.MEGAWATT)).thenReturn(50464.); - when(flowResult.getCommercialFlow(cnec2, LEFT, Unit.AMPERE)).thenReturn(-45104.); - assertEquals(50464., output.getCommercialFlow(cnec1, RIGHT, Unit.MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(-45104., output.getCommercialFlow(cnec2, LEFT, Unit.AMPERE), DOUBLE_TOLERANCE); + when(flowResult.getCommercialFlow(cnec1, TWO, Unit.MEGAWATT)).thenReturn(50464.); + when(flowResult.getCommercialFlow(cnec2, ONE, Unit.AMPERE)).thenReturn(-45104.); + assertEquals(50464., output.getCommercialFlow(cnec1, TWO, Unit.MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(-45104., output.getCommercialFlow(cnec2, ONE, Unit.AMPERE), DOUBLE_TOLERANCE); - when(flowResult.getPtdfZonalSum(cnec1, RIGHT)).thenReturn(0.4); - when(flowResult.getPtdfZonalSum(cnec2, LEFT)).thenReturn(0.75); - assertEquals(0.4, output.getPtdfZonalSum(cnec1, RIGHT), DOUBLE_TOLERANCE); - assertEquals(0.75, output.getPtdfZonalSum(cnec2, LEFT), DOUBLE_TOLERANCE); + when(flowResult.getPtdfZonalSum(cnec1, TWO)).thenReturn(0.4); + when(flowResult.getPtdfZonalSum(cnec2, ONE)).thenReturn(0.75); + assertEquals(0.4, output.getPtdfZonalSum(cnec1, TWO), DOUBLE_TOLERANCE); + assertEquals(0.75, output.getPtdfZonalSum(cnec2, ONE), DOUBLE_TOLERANCE); - when(flowResult.getPtdfZonalSums()).thenReturn(Map.of(cnec1, Map.of(RIGHT, 0.1), cnec2, Map.of(LEFT, 0.2))); - assertEquals(Map.of(cnec1, Map.of(RIGHT, 0.1), cnec2, Map.of(LEFT, 0.2)), output.getPtdfZonalSums()); + when(flowResult.getPtdfZonalSums()).thenReturn(Map.of(cnec1, Map.of(TWO, 0.1), cnec2, Map.of(ONE, 0.2))); + assertEquals(Map.of(cnec1, Map.of(TWO, 0.1), cnec2, Map.of(ONE, 0.2)), output.getPtdfZonalSums()); when(rangeActionSetpointResult.getRangeActions()).thenReturn(Set.of(ra1, ra2)); assertEquals(Set.of(ra1, ra2), output.getRangeActions()); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/PreventiveAndCurativesRaoResultImplTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/PreventiveAndCurativesRaoResultImplTest.java index 3f4f7efd48..ae74cdc540 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/PreventiveAndCurativesRaoResultImplTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/PreventiveAndCurativesRaoResultImplTest.java @@ -13,7 +13,7 @@ import com.powsybl.openrao.data.cracapi.*; import com.powsybl.openrao.data.cracapi.cnec.AngleCnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.cnec.VoltageCnec; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; @@ -41,8 +41,8 @@ import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static com.powsybl.openrao.data.cracapi.cnec.Side.LEFT; -import static com.powsybl.openrao.data.cracapi.cnec.Side.RIGHT; +import static com.powsybl.iidm.network.TwoSides.ONE; +import static com.powsybl.iidm.network.TwoSides.TWO; import static com.powsybl.openrao.commons.Unit.*; /** @@ -104,7 +104,7 @@ private void initCrac() { .withOptimized(true) .withMonitored(false) .newThreshold() - .withSide(LEFT) + .withSide(ONE) .withUnit(MEGAWATT) .withMin(-1000d) .withMax(1000d) @@ -118,7 +118,7 @@ private void initCrac() { .withOptimized(true) .withMonitored(false) .newThreshold() - .withSide(LEFT) + .withSide(ONE) .withUnit(MEGAWATT) .withMin(-1000d) .withMax(1000d) @@ -132,7 +132,7 @@ private void initCrac() { .withOptimized(true) .withMonitored(false) .newThreshold() - .withSide(LEFT) + .withSide(ONE) .withUnit(MEGAWATT) .withMin(-1000d) .withMax(1000d) @@ -146,7 +146,7 @@ private void initCrac() { .withOptimized(true) .withMonitored(false) .newThreshold() - .withSide(LEFT) + .withSide(ONE) .withUnit(MEGAWATT) .withMin(-1000d) .withMax(1000d) @@ -297,7 +297,7 @@ private void mockCnecResults(FlowResult flowResult, FlowCnec cnec, double margin when(flowResult.getMargin(cnec, AMPERE)).thenReturn(marginA); when(flowResult.getRelativeMargin(cnec, MEGAWATT)).thenReturn(relMarginMw); when(flowResult.getRelativeMargin(cnec, AMPERE)).thenReturn(relMarginA); - when(flowResult.getPtdfZonalSum(cnec, Side.LEFT)).thenReturn(1.); + when(flowResult.getPtdfZonalSum(cnec, TwoSides.ONE)).thenReturn(1.); } private void mockVirtualCosts(ObjectiveFunctionResult objectiveFunctionResult, double virtualCost, double mnecCost, List mnecCostlyElements, double lfCost, List lfCostlyElements) { @@ -309,17 +309,17 @@ private void mockVirtualCosts(ObjectiveFunctionResult objectiveFunctionResult, d } private void flowResultThrows(Instant instant, FlowCnec cnec) { - OpenRaoException exception = assertThrows(OpenRaoException.class, () -> output.getFlow(instant, cnec, Side.LEFT, Unit.MEGAWATT)); + OpenRaoException exception = assertThrows(OpenRaoException.class, () -> output.getFlow(instant, cnec, TwoSides.ONE, Unit.MEGAWATT)); assertEquals(String.format("Trying to access results for instant %s at optimization state %s is not allowed", cnec.getState().getInstant().getId(), instant.toString()), exception.getMessage()); exception = assertThrows(OpenRaoException.class, () -> output.getMargin(instant, cnec, Unit.MEGAWATT)); assertEquals(String.format("Trying to access results for instant %s at optimization state %s is not allowed", cnec.getState().getInstant().getId(), instant), exception.getMessage()); exception = assertThrows(OpenRaoException.class, () -> output.getRelativeMargin(instant, cnec, Unit.MEGAWATT)); assertEquals(String.format("Trying to access results for instant %s at optimization state %s is not allowed", cnec.getState().getInstant().getId(), instant), exception.getMessage()); - exception = assertThrows(OpenRaoException.class, () -> output.getCommercialFlow(instant, cnec, Side.LEFT, Unit.MEGAWATT)); + exception = assertThrows(OpenRaoException.class, () -> output.getCommercialFlow(instant, cnec, TwoSides.ONE, Unit.MEGAWATT)); assertEquals(String.format("Trying to access results for instant %s at optimization state %s is not allowed", cnec.getState().getInstant().getId(), instant), exception.getMessage()); - exception = assertThrows(OpenRaoException.class, () -> output.getLoopFlow(instant, cnec, Side.LEFT, Unit.MEGAWATT)); + exception = assertThrows(OpenRaoException.class, () -> output.getLoopFlow(instant, cnec, TwoSides.ONE, Unit.MEGAWATT)); assertEquals(String.format("Trying to access results for instant %s at optimization state %s is not allowed", cnec.getState().getInstant().getId(), instant), exception.getMessage()); - exception = assertThrows(OpenRaoException.class, () -> output.getPtdfZonalSum(instant, cnec, Side.LEFT)); + exception = assertThrows(OpenRaoException.class, () -> output.getPtdfZonalSum(instant, cnec, TwoSides.ONE)); assertEquals(String.format("Trying to access results for instant %s at optimization state %s is not allowed", cnec.getState().getInstant().getId(), instant), exception.getMessage()); } @@ -562,13 +562,13 @@ void testGetOptimizedSetPointsOnState() { @Test void testGetFlow() { - when(initialResult.getFlow(cnec1, LEFT, MEGAWATT)).thenReturn(10.); - when(preCurativeResult.getFlow(cnec2, RIGHT, AMPERE)).thenReturn(20.); - when(postPrevResult.getFlow(cnec3, RIGHT, MEGAWATT)).thenReturn(30.); + when(initialResult.getFlow(cnec1, ONE, MEGAWATT)).thenReturn(10.); + when(preCurativeResult.getFlow(cnec2, TWO, AMPERE)).thenReturn(20.); + when(postPrevResult.getFlow(cnec3, TWO, MEGAWATT)).thenReturn(30.); when(cnec3.getState()).thenReturn(curativeState3); - assertEquals(10., output.getFlow(null, cnec1, LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(20., output.getFlow(preventiveInstant, cnec2, RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(30., output.getFlow(curativeInstant, cnec3, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(10., output.getFlow(null, cnec1, ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(20., output.getFlow(preventiveInstant, cnec2, TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(30., output.getFlow(curativeInstant, cnec3, TWO, MEGAWATT), DOUBLE_TOLERANCE); } @Test @@ -595,37 +595,37 @@ void testGetRelativeMargin() { @Test void testGetCommercialFlow() { - when(initialResult.getCommercialFlow(cnec1, LEFT, MEGAWATT)).thenReturn(10.); - when(preCurativeResult.getCommercialFlow(cnec2, RIGHT, AMPERE)).thenReturn(20.); - when(curativeResult1.getCommercialFlow(cnec3, RIGHT, MEGAWATT)).thenReturn(30.); + when(initialResult.getCommercialFlow(cnec1, ONE, MEGAWATT)).thenReturn(10.); + when(preCurativeResult.getCommercialFlow(cnec2, TWO, AMPERE)).thenReturn(20.); + when(curativeResult1.getCommercialFlow(cnec3, TWO, MEGAWATT)).thenReturn(30.); when(cnec3.getState()).thenReturn(curativeState1); - assertEquals(10., output.getCommercialFlow(null, cnec1, LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(20., output.getCommercialFlow(preventiveInstant, cnec2, RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(30., output.getCommercialFlow(curativeInstant, cnec3, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(10., output.getCommercialFlow(null, cnec1, ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(20., output.getCommercialFlow(preventiveInstant, cnec2, TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(30., output.getCommercialFlow(curativeInstant, cnec3, TWO, MEGAWATT), DOUBLE_TOLERANCE); } @Test void testGetLoopFlow() { - when(initialResult.getLoopFlow(cnec1, LEFT, MEGAWATT)).thenReturn(10.); - when(preCurativeResult.getLoopFlow(cnec2, RIGHT, AMPERE)).thenReturn(20.); - when(curativeResult2.getFlow(cnec3, RIGHT, MEGAWATT)).thenReturn(90.); - when(curativeResult2.getCommercialFlow(cnec3, RIGHT, MEGAWATT)).thenReturn(60.); + when(initialResult.getLoopFlow(cnec1, ONE, MEGAWATT)).thenReturn(10.); + when(preCurativeResult.getLoopFlow(cnec2, TWO, AMPERE)).thenReturn(20.); + when(curativeResult2.getFlow(cnec3, TWO, MEGAWATT)).thenReturn(90.); + when(curativeResult2.getCommercialFlow(cnec3, TWO, MEGAWATT)).thenReturn(60.); when(cnec3.getState()).thenReturn(curativeState2); - assertEquals(10., output.getLoopFlow(null, cnec1, LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(20., output.getLoopFlow(preventiveInstant, cnec2, RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(30., output.getLoopFlow(curativeInstant, cnec3, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(10., output.getLoopFlow(null, cnec1, ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(20., output.getLoopFlow(preventiveInstant, cnec2, TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(30., output.getLoopFlow(curativeInstant, cnec3, TWO, MEGAWATT), DOUBLE_TOLERANCE); } @Test void testGetPtdfZonalSum() { - when(initialResult.getPtdfZonalSum(cnec1, LEFT)).thenReturn(10.); - when(preCurativeResult.getPtdfZonalSum(cnec2, RIGHT)).thenReturn(20.); - when(autoResult1.getPtdfZonalSum(cnec1auto, LEFT)).thenReturn(25.); - when(curativeResult2.getPtdfZonalSum(cnec3, RIGHT)).thenReturn(30.); + when(initialResult.getPtdfZonalSum(cnec1, ONE)).thenReturn(10.); + when(preCurativeResult.getPtdfZonalSum(cnec2, TWO)).thenReturn(20.); + when(autoResult1.getPtdfZonalSum(cnec1auto, ONE)).thenReturn(25.); + when(curativeResult2.getPtdfZonalSum(cnec3, TWO)).thenReturn(30.); when(cnec3.getState()).thenReturn(curativeState2); - assertEquals(10., output.getPtdfZonalSum(null, cnec1, LEFT), DOUBLE_TOLERANCE); - assertEquals(20., output.getPtdfZonalSum(preventiveInstant, cnec2, RIGHT), DOUBLE_TOLERANCE); - assertEquals(30., output.getPtdfZonalSum(curativeInstant, cnec3, RIGHT), DOUBLE_TOLERANCE); + assertEquals(10., output.getPtdfZonalSum(null, cnec1, ONE), DOUBLE_TOLERANCE); + assertEquals(20., output.getPtdfZonalSum(preventiveInstant, cnec2, TWO), DOUBLE_TOLERANCE); + assertEquals(30., output.getPtdfZonalSum(curativeInstant, cnec3, TWO), DOUBLE_TOLERANCE); } @Test @@ -640,11 +640,11 @@ void testGetPerimeter() { State outageState = mock(State.class); when(outageState.getInstant()).thenReturn(outageInstant); - when(initialResult.getPtdfZonalSum(cnec1, LEFT)).thenReturn(1.); - when(postPrevResult.getPtdfZonalSum(cnec1, LEFT)).thenReturn(2.); - when(autoResult1.getPtdfZonalSum(cnec1, LEFT)).thenReturn(3.); - when(curativeResult1.getPtdfZonalSum(cnec1, LEFT)).thenReturn(4.); - when(curativeResult2.getPtdfZonalSum(cnec1, LEFT)).thenReturn(5.); + when(initialResult.getPtdfZonalSum(cnec1, ONE)).thenReturn(1.); + when(postPrevResult.getPtdfZonalSum(cnec1, ONE)).thenReturn(2.); + when(autoResult1.getPtdfZonalSum(cnec1, ONE)).thenReturn(3.); + when(curativeResult1.getPtdfZonalSum(cnec1, ONE)).thenReturn(4.); + when(curativeResult2.getPtdfZonalSum(cnec1, ONE)).thenReturn(5.); when(curativeResult2.getSensitivityStatus(curativeState2)).thenReturn(ComputationStatus.DEFAULT); @@ -664,15 +664,15 @@ void testGetPerimeter() { // PREVENTIVE perimeterResult = output.getPerimeterResult(preventiveInstant, preventiveState); - assertEquals(2., perimeterResult.getPtdfZonalSum(cnec1, LEFT), DOUBLE_TOLERANCE); + assertEquals(2., perimeterResult.getPtdfZonalSum(cnec1, ONE), DOUBLE_TOLERANCE); perimeterResult = output.getPerimeterResult(preventiveInstant, outageState); - assertEquals(2., perimeterResult.getPtdfZonalSum(cnec1, LEFT), DOUBLE_TOLERANCE); + assertEquals(2., perimeterResult.getPtdfZonalSum(cnec1, ONE), DOUBLE_TOLERANCE); perimeterResult = output.getPerimeterResult(preventiveInstant, autoState1); - assertEquals(2., perimeterResult.getPtdfZonalSum(cnec1, LEFT), DOUBLE_TOLERANCE); + assertEquals(2., perimeterResult.getPtdfZonalSum(cnec1, ONE), DOUBLE_TOLERANCE); perimeterResult = output.getPerimeterResult(preventiveInstant, curativeState1); - assertEquals(2., perimeterResult.getPtdfZonalSum(cnec1, LEFT), DOUBLE_TOLERANCE); + assertEquals(2., perimeterResult.getPtdfZonalSum(cnec1, ONE), DOUBLE_TOLERANCE); perimeterResult = output.getPerimeterResult(preventiveInstant, curativeState2); - assertEquals(2., perimeterResult.getPtdfZonalSum(cnec1, LEFT), DOUBLE_TOLERANCE); + assertEquals(2., perimeterResult.getPtdfZonalSum(cnec1, ONE), DOUBLE_TOLERANCE); // AUTO exception = assertThrows(OpenRaoException.class, () -> output.getPerimeterResult(autoInstant, preventiveState)); @@ -680,9 +680,9 @@ void testGetPerimeter() { exception = assertThrows(OpenRaoException.class, () -> output.getPerimeterResult(autoInstant, outageState)); assertEquals("Trying to access results for instant outage at optimization state auto is not allowed", exception.getMessage()); perimeterResult = output.getPerimeterResult(autoInstant, autoState1); - assertEquals(3., perimeterResult.getPtdfZonalSum(cnec1, LEFT), DOUBLE_TOLERANCE); + assertEquals(3., perimeterResult.getPtdfZonalSum(cnec1, ONE), DOUBLE_TOLERANCE); perimeterResult = output.getPerimeterResult(autoInstant, curativeState1); - assertEquals(3., perimeterResult.getPtdfZonalSum(cnec1, LEFT), DOUBLE_TOLERANCE); + assertEquals(3., perimeterResult.getPtdfZonalSum(cnec1, ONE), DOUBLE_TOLERANCE); assertNull(output.getPerimeterResult(autoInstant, curativeState2)); // CURATIVE @@ -693,9 +693,9 @@ void testGetPerimeter() { exception = assertThrows(OpenRaoException.class, () -> output.getPerimeterResult(curativeInstant, autoState1)); assertEquals("Trying to access results for instant auto at optimization state curative is not allowed", exception.getMessage()); perimeterResult = output.getPerimeterResult(curativeInstant, curativeState1); - assertEquals(4., perimeterResult.getPtdfZonalSum(cnec1, LEFT), DOUBLE_TOLERANCE); + assertEquals(4., perimeterResult.getPtdfZonalSum(cnec1, ONE), DOUBLE_TOLERANCE); perimeterResult = output.getPerimeterResult(curativeInstant, curativeState2); - assertEquals(5., perimeterResult.getPtdfZonalSum(cnec1, LEFT), DOUBLE_TOLERANCE); + assertEquals(5., perimeterResult.getPtdfZonalSum(cnec1, ONE), DOUBLE_TOLERANCE); assertEquals(ComputationStatus.DEFAULT, output.getComputationStatus(curativeState2)); } @@ -839,13 +839,13 @@ void testNoPostContingencyResultGetters() { assertEquals(Map.of(pstRangeAction, 222., rangeAction, 111.), output.getOptimizedSetPointsOnState(curativeState3)); // Test get flow - when(initialResult.getFlow(cnec1, LEFT, MEGAWATT)).thenReturn(10.); - when(preCurativeResult.getFlow(cnec2, RIGHT, AMPERE)).thenReturn(20.); - when(preCurativeResult.getFlow(cnec3, RIGHT, MEGAWATT)).thenReturn(30.); + when(initialResult.getFlow(cnec1, ONE, MEGAWATT)).thenReturn(10.); + when(preCurativeResult.getFlow(cnec2, TWO, AMPERE)).thenReturn(20.); + when(preCurativeResult.getFlow(cnec3, TWO, MEGAWATT)).thenReturn(30.); when(cnec3.getState()).thenReturn(curativeState3); - assertEquals(10., output.getFlow(null, cnec1, LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(20., output.getFlow(preventiveInstant, cnec2, RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(30., output.getFlow(curativeInstant, cnec3, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(10., output.getFlow(null, cnec1, ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(20., output.getFlow(preventiveInstant, cnec2, TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(30., output.getFlow(curativeInstant, cnec3, TWO, MEGAWATT), DOUBLE_TOLERANCE); // Test get margin when(initialResult.getMargin(cnec1, MEGAWATT)).thenReturn(10.); @@ -866,31 +866,31 @@ void testNoPostContingencyResultGetters() { assertEquals(30., output.getRelativeMargin(curativeInstant, cnec3, MEGAWATT), DOUBLE_TOLERANCE); // Test get commercial flow - when(initialResult.getCommercialFlow(cnec1, LEFT, MEGAWATT)).thenReturn(10.); - when(preCurativeResult.getCommercialFlow(cnec2, RIGHT, AMPERE)).thenReturn(20.); - when(preCurativeResult.getCommercialFlow(cnec3, RIGHT, MEGAWATT)).thenReturn(25.); + when(initialResult.getCommercialFlow(cnec1, ONE, MEGAWATT)).thenReturn(10.); + when(preCurativeResult.getCommercialFlow(cnec2, TWO, AMPERE)).thenReturn(20.); + when(preCurativeResult.getCommercialFlow(cnec3, TWO, MEGAWATT)).thenReturn(25.); when(cnec3.getState()).thenReturn(curativeState1); - assertEquals(10., output.getCommercialFlow(null, cnec1, LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(20., output.getCommercialFlow(preventiveInstant, cnec2, RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(25., output.getCommercialFlow(curativeInstant, cnec3, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(10., output.getCommercialFlow(null, cnec1, ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(20., output.getCommercialFlow(preventiveInstant, cnec2, TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(25., output.getCommercialFlow(curativeInstant, cnec3, TWO, MEGAWATT), DOUBLE_TOLERANCE); // Test get loopflow - when(initialResult.getLoopFlow(cnec1, LEFT, MEGAWATT)).thenReturn(10.); - when(preCurativeResult.getLoopFlow(cnec2, RIGHT, AMPERE)).thenReturn(20.); - when(preCurativeResult.getLoopFlow(cnec3, RIGHT, MEGAWATT)).thenReturn(25.); + when(initialResult.getLoopFlow(cnec1, ONE, MEGAWATT)).thenReturn(10.); + when(preCurativeResult.getLoopFlow(cnec2, TWO, AMPERE)).thenReturn(20.); + when(preCurativeResult.getLoopFlow(cnec3, TWO, MEGAWATT)).thenReturn(25.); when(cnec3.getState()).thenReturn(curativeState2); - assertEquals(10., output.getLoopFlow(null, cnec1, LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(20., output.getLoopFlow(preventiveInstant, cnec2, RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(25., output.getLoopFlow(curativeInstant, cnec3, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(10., output.getLoopFlow(null, cnec1, ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(20., output.getLoopFlow(preventiveInstant, cnec2, TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(25., output.getLoopFlow(curativeInstant, cnec3, TWO, MEGAWATT), DOUBLE_TOLERANCE); // Test get ptdf zonal sum - when(initialResult.getPtdfZonalSum(cnec1, LEFT)).thenReturn(10.); - when(preCurativeResult.getPtdfZonalSum(cnec2, RIGHT)).thenReturn(20.); - when(preCurativeResult.getPtdfZonalSum(cnec3, RIGHT)).thenReturn(30.); + when(initialResult.getPtdfZonalSum(cnec1, ONE)).thenReturn(10.); + when(preCurativeResult.getPtdfZonalSum(cnec2, TWO)).thenReturn(20.); + when(preCurativeResult.getPtdfZonalSum(cnec3, TWO)).thenReturn(30.); when(cnec3.getState()).thenReturn(curativeState2); - assertEquals(10., output.getPtdfZonalSum(null, cnec1, LEFT), DOUBLE_TOLERANCE); - assertEquals(20., output.getPtdfZonalSum(preventiveInstant, cnec2, RIGHT), DOUBLE_TOLERANCE); - assertEquals(30., output.getPtdfZonalSum(curativeInstant, cnec3, RIGHT), DOUBLE_TOLERANCE); + assertEquals(10., output.getPtdfZonalSum(null, cnec1, ONE), DOUBLE_TOLERANCE); + assertEquals(20., output.getPtdfZonalSum(preventiveInstant, cnec2, TWO), DOUBLE_TOLERANCE); + assertEquals(30., output.getPtdfZonalSum(curativeInstant, cnec3, TWO), DOUBLE_TOLERANCE); } @Test @@ -901,11 +901,11 @@ void testNoPostContingencyResultGetPerimeterResult() { State outageState = mock(State.class); when(outageState.getInstant()).thenReturn(outageInstant); - when(initialResult.getPtdfZonalSum(cnec1, LEFT)).thenReturn(1.); - when(postPrevResult.getPtdfZonalSum(cnec1, LEFT)).thenReturn(2.); - when(autoResult1.getPtdfZonalSum(cnec1, LEFT)).thenReturn(3.); - when(curativeResult1.getPtdfZonalSum(cnec1, LEFT)).thenReturn(4.); - when(curativeResult2.getPtdfZonalSum(cnec1, LEFT)).thenReturn(5.); + when(initialResult.getPtdfZonalSum(cnec1, ONE)).thenReturn(1.); + when(postPrevResult.getPtdfZonalSum(cnec1, ONE)).thenReturn(2.); + when(autoResult1.getPtdfZonalSum(cnec1, ONE)).thenReturn(3.); + when(curativeResult1.getPtdfZonalSum(cnec1, ONE)).thenReturn(4.); + when(curativeResult2.getPtdfZonalSum(cnec1, ONE)).thenReturn(5.); PerimeterResult perimeterResult; @@ -923,15 +923,15 @@ void testNoPostContingencyResultGetPerimeterResult() { // PREVENTIVE perimeterResult = output.getPerimeterResult(preventiveInstant, preventiveState); - assertEquals(2., perimeterResult.getPtdfZonalSum(cnec1, LEFT), DOUBLE_TOLERANCE); + assertEquals(2., perimeterResult.getPtdfZonalSum(cnec1, ONE), DOUBLE_TOLERANCE); perimeterResult = output.getPerimeterResult(preventiveInstant, outageState); - assertEquals(2., perimeterResult.getPtdfZonalSum(cnec1, LEFT), DOUBLE_TOLERANCE); + assertEquals(2., perimeterResult.getPtdfZonalSum(cnec1, ONE), DOUBLE_TOLERANCE); perimeterResult = output.getPerimeterResult(preventiveInstant, autoState1); - assertEquals(2., perimeterResult.getPtdfZonalSum(cnec1, LEFT), DOUBLE_TOLERANCE); + assertEquals(2., perimeterResult.getPtdfZonalSum(cnec1, ONE), DOUBLE_TOLERANCE); perimeterResult = output.getPerimeterResult(preventiveInstant, curativeState1); - assertEquals(2., perimeterResult.getPtdfZonalSum(cnec1, LEFT), DOUBLE_TOLERANCE); + assertEquals(2., perimeterResult.getPtdfZonalSum(cnec1, ONE), DOUBLE_TOLERANCE); perimeterResult = output.getPerimeterResult(preventiveInstant, curativeState2); - assertEquals(2., perimeterResult.getPtdfZonalSum(cnec1, LEFT), DOUBLE_TOLERANCE); + assertEquals(2., perimeterResult.getPtdfZonalSum(cnec1, ONE), DOUBLE_TOLERANCE); // AUTO exception = assertThrows(OpenRaoException.class, () -> output.getPerimeterResult(autoInstant, preventiveState)); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/RangeActionActivationResultImplTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/RangeActionActivationResultImplTest.java index 1bafa04e6f..f666aa72ac 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/RangeActionActivationResultImplTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/RangeActionActivationResultImplTest.java @@ -11,7 +11,7 @@ import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.State; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.usagerule.UsageMethod; import com.powsybl.openrao.data.cracimpl.utils.CommonCracCreation; @@ -53,7 +53,7 @@ public void setUp() { .withNetworkElement("BBE2AA1 FFR3AA1 1") .withInstant(OUTAGE_INSTANT_ID) .withContingency("Contingency FR1 FR3") - .newThreshold().withUnit(Unit.MEGAWATT).withSide(Side.LEFT).withMin(-1500.).withMax(1500.).add() + .newThreshold().withUnit(Unit.MEGAWATT).withSide(TwoSides.ONE).withMin(-1500.).withMax(1500.).add() .add(); pState = crac.getPreventiveState(); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/SensitivityResultImplTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/SensitivityResultImplTest.java index 3a8d2486bc..bcaa2427a3 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/SensitivityResultImplTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/SensitivityResultImplTest.java @@ -17,7 +17,7 @@ import org.mockito.Mockito; import static org.junit.jupiter.api.Assertions.*; -import static com.powsybl.openrao.data.cracapi.cnec.Side.LEFT; +import static com.powsybl.iidm.network.TwoSides.ONE; import static com.powsybl.openrao.commons.Unit.*; import static org.mockito.Mockito.when; @@ -36,14 +36,14 @@ void testSensitivitiesOnRangeAction() { RangeAction rangeAction = Mockito.mock(RangeAction.class); FlowCnec cnec = Mockito.mock(FlowCnec.class); - when(systematicSensitivityResult.getSensitivityOnFlow(rangeAction, cnec, LEFT)).thenReturn(8.); + when(systematicSensitivityResult.getSensitivityOnFlow(rangeAction, cnec, ONE)).thenReturn(8.); - assertEquals(8, sensitivityResultImpl.getSensitivityValue(cnec, LEFT, rangeAction, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(8, sensitivityResultImpl.getSensitivityValue(cnec, ONE, rangeAction, MEGAWATT), DOUBLE_TOLERANCE); - assertThrows(OpenRaoException.class, () -> sensitivityResultImpl.getSensitivityValue(cnec, LEFT, rangeAction, KILOVOLT)); - assertThrows(OpenRaoException.class, () -> sensitivityResultImpl.getSensitivityValue(cnec, LEFT, rangeAction, DEGREE)); - assertThrows(OpenRaoException.class, () -> sensitivityResultImpl.getSensitivityValue(cnec, LEFT, rangeAction, PERCENT_IMAX)); - assertThrows(OpenRaoException.class, () -> sensitivityResultImpl.getSensitivityValue(cnec, LEFT, rangeAction, TAP)); + assertThrows(OpenRaoException.class, () -> sensitivityResultImpl.getSensitivityValue(cnec, ONE, rangeAction, KILOVOLT)); + assertThrows(OpenRaoException.class, () -> sensitivityResultImpl.getSensitivityValue(cnec, ONE, rangeAction, DEGREE)); + assertThrows(OpenRaoException.class, () -> sensitivityResultImpl.getSensitivityValue(cnec, ONE, rangeAction, PERCENT_IMAX)); + assertThrows(OpenRaoException.class, () -> sensitivityResultImpl.getSensitivityValue(cnec, ONE, rangeAction, TAP)); } @Test @@ -55,10 +55,10 @@ void testSensitivitiesOnLinearGLSK() { SensitivityVariableSet linearGlsk = Mockito.mock(SensitivityVariableSet.class); FlowCnec cnec = Mockito.mock(FlowCnec.class); - when(systematicSensitivityResult.getSensitivityOnFlow(linearGlsk, cnec, LEFT)).thenReturn(8.); + when(systematicSensitivityResult.getSensitivityOnFlow(linearGlsk, cnec, ONE)).thenReturn(8.); - assertEquals(8, sensitivityResultImpl.getSensitivityValue(cnec, LEFT, linearGlsk, MEGAWATT), DOUBLE_TOLERANCE); - assertThrows(OpenRaoException.class, () -> sensitivityResultImpl.getSensitivityValue(cnec, LEFT, linearGlsk, AMPERE)); + assertEquals(8, sensitivityResultImpl.getSensitivityValue(cnec, ONE, linearGlsk, MEGAWATT), DOUBLE_TOLERANCE); + assertThrows(OpenRaoException.class, () -> sensitivityResultImpl.getSensitivityValue(cnec, ONE, linearGlsk, AMPERE)); } @Test diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/SkippedOptimizationResultImplTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/SkippedOptimizationResultImplTest.java index 451e798383..906bb680be 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/SkippedOptimizationResultImplTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/SkippedOptimizationResultImplTest.java @@ -12,7 +12,7 @@ import com.powsybl.contingency.Contingency; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; @@ -37,7 +37,7 @@ class SkippedOptimizationResultImplTest { @Test void testBasicReturns() { FlowCnec flowCnec = mock(FlowCnec.class); - Side side = mock(Side.class); + TwoSides side = mock(TwoSides.class); Unit unit = mock(Unit.class); SensitivityVariableSet sensitivityVariableSet = mock(SensitivityVariableSet.class); State state = mock(State.class); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/UnoptimizedRaoResultImplTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/UnoptimizedRaoResultImplTest.java index 3ef9a4a615..f7a51799cf 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/UnoptimizedRaoResultImplTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/UnoptimizedRaoResultImplTest.java @@ -26,8 +26,8 @@ import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.when; -import static com.powsybl.openrao.data.cracapi.cnec.Side.RIGHT; -import static com.powsybl.openrao.data.cracapi.cnec.Side.LEFT; +import static com.powsybl.iidm.network.TwoSides.TWO; +import static com.powsybl.iidm.network.TwoSides.ONE; import static com.powsybl.openrao.commons.Unit.*; /** @@ -60,18 +60,18 @@ void testGetComputationStatus() { @Test void testGetFlow() { - when(initialResult.getFlow(flowCnec, LEFT, AMPERE)).thenReturn(100.); - when(initialResult.getFlow(flowCnec, LEFT, MEGAWATT)).thenReturn(1000.); - - assertEquals(100., output.getFlow(null, flowCnec, LEFT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(100., output.getFlow(preventiveInstant, flowCnec, LEFT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(100., output.getFlow(autoInstant, flowCnec, LEFT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(100., output.getFlow(curativeInstant, flowCnec, LEFT, AMPERE), DOUBLE_TOLERANCE); - - assertEquals(1000., output.getFlow(null, flowCnec, LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(1000., output.getFlow(preventiveInstant, flowCnec, LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(1000., output.getFlow(autoInstant, flowCnec, LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(1000., output.getFlow(curativeInstant, flowCnec, LEFT, MEGAWATT), DOUBLE_TOLERANCE); + when(initialResult.getFlow(flowCnec, ONE, AMPERE)).thenReturn(100.); + when(initialResult.getFlow(flowCnec, ONE, MEGAWATT)).thenReturn(1000.); + + assertEquals(100., output.getFlow(null, flowCnec, ONE, AMPERE), DOUBLE_TOLERANCE); + assertEquals(100., output.getFlow(preventiveInstant, flowCnec, ONE, AMPERE), DOUBLE_TOLERANCE); + assertEquals(100., output.getFlow(autoInstant, flowCnec, ONE, AMPERE), DOUBLE_TOLERANCE); + assertEquals(100., output.getFlow(curativeInstant, flowCnec, ONE, AMPERE), DOUBLE_TOLERANCE); + + assertEquals(1000., output.getFlow(null, flowCnec, ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(1000., output.getFlow(preventiveInstant, flowCnec, ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(1000., output.getFlow(autoInstant, flowCnec, ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(1000., output.getFlow(curativeInstant, flowCnec, ONE, MEGAWATT), DOUBLE_TOLERANCE); } @Test @@ -108,44 +108,44 @@ void testGetRelativeMargin() { @Test void testGetCommercialFlow() { - when(initialResult.getCommercialFlow(flowCnec, RIGHT, AMPERE)).thenReturn(100.); - when(initialResult.getCommercialFlow(flowCnec, RIGHT, MEGAWATT)).thenReturn(1000.); - - assertEquals(100., output.getCommercialFlow(null, flowCnec, RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(100., output.getCommercialFlow(preventiveInstant, flowCnec, RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(100., output.getCommercialFlow(autoInstant, flowCnec, RIGHT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(100., output.getCommercialFlow(curativeInstant, flowCnec, RIGHT, AMPERE), DOUBLE_TOLERANCE); - - assertEquals(1000., output.getCommercialFlow(null, flowCnec, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(1000., output.getCommercialFlow(preventiveInstant, flowCnec, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(1000., output.getCommercialFlow(autoInstant, flowCnec, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(1000., output.getCommercialFlow(curativeInstant, flowCnec, RIGHT, MEGAWATT), DOUBLE_TOLERANCE); + when(initialResult.getCommercialFlow(flowCnec, TWO, AMPERE)).thenReturn(100.); + when(initialResult.getCommercialFlow(flowCnec, TWO, MEGAWATT)).thenReturn(1000.); + + assertEquals(100., output.getCommercialFlow(null, flowCnec, TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(100., output.getCommercialFlow(preventiveInstant, flowCnec, TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(100., output.getCommercialFlow(autoInstant, flowCnec, TWO, AMPERE), DOUBLE_TOLERANCE); + assertEquals(100., output.getCommercialFlow(curativeInstant, flowCnec, TWO, AMPERE), DOUBLE_TOLERANCE); + + assertEquals(1000., output.getCommercialFlow(null, flowCnec, TWO, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(1000., output.getCommercialFlow(preventiveInstant, flowCnec, TWO, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(1000., output.getCommercialFlow(autoInstant, flowCnec, TWO, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(1000., output.getCommercialFlow(curativeInstant, flowCnec, TWO, MEGAWATT), DOUBLE_TOLERANCE); } @Test void testGetLoopFlow() { - when(initialResult.getLoopFlow(flowCnec, LEFT, AMPERE)).thenReturn(100.); - when(initialResult.getLoopFlow(flowCnec, LEFT, MEGAWATT)).thenReturn(1000.); - - assertEquals(100., output.getLoopFlow(null, flowCnec, LEFT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(100., output.getLoopFlow(preventiveInstant, flowCnec, LEFT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(100., output.getLoopFlow(autoInstant, flowCnec, LEFT, AMPERE), DOUBLE_TOLERANCE); - assertEquals(100., output.getLoopFlow(curativeInstant, flowCnec, LEFT, AMPERE), DOUBLE_TOLERANCE); - - assertEquals(1000., output.getLoopFlow(null, flowCnec, LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(1000., output.getLoopFlow(preventiveInstant, flowCnec, LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(1000., output.getLoopFlow(autoInstant, flowCnec, LEFT, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(1000., output.getLoopFlow(curativeInstant, flowCnec, LEFT, MEGAWATT), DOUBLE_TOLERANCE); + when(initialResult.getLoopFlow(flowCnec, ONE, AMPERE)).thenReturn(100.); + when(initialResult.getLoopFlow(flowCnec, ONE, MEGAWATT)).thenReturn(1000.); + + assertEquals(100., output.getLoopFlow(null, flowCnec, ONE, AMPERE), DOUBLE_TOLERANCE); + assertEquals(100., output.getLoopFlow(preventiveInstant, flowCnec, ONE, AMPERE), DOUBLE_TOLERANCE); + assertEquals(100., output.getLoopFlow(autoInstant, flowCnec, ONE, AMPERE), DOUBLE_TOLERANCE); + assertEquals(100., output.getLoopFlow(curativeInstant, flowCnec, ONE, AMPERE), DOUBLE_TOLERANCE); + + assertEquals(1000., output.getLoopFlow(null, flowCnec, ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(1000., output.getLoopFlow(preventiveInstant, flowCnec, ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(1000., output.getLoopFlow(autoInstant, flowCnec, ONE, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(1000., output.getLoopFlow(curativeInstant, flowCnec, ONE, MEGAWATT), DOUBLE_TOLERANCE); } @Test void testGetPtdfZonalSum() { - when(initialResult.getPtdfZonalSum(flowCnec, RIGHT)).thenReturn(100.); + when(initialResult.getPtdfZonalSum(flowCnec, TWO)).thenReturn(100.); - assertEquals(100., output.getPtdfZonalSum(null, flowCnec, RIGHT), DOUBLE_TOLERANCE); - assertEquals(100., output.getPtdfZonalSum(preventiveInstant, flowCnec, RIGHT), DOUBLE_TOLERANCE); - assertEquals(100., output.getPtdfZonalSum(autoInstant, flowCnec, RIGHT), DOUBLE_TOLERANCE); - assertEquals(100., output.getPtdfZonalSum(curativeInstant, flowCnec, RIGHT), DOUBLE_TOLERANCE); + assertEquals(100., output.getPtdfZonalSum(null, flowCnec, TWO), DOUBLE_TOLERANCE); + assertEquals(100., output.getPtdfZonalSum(preventiveInstant, flowCnec, TWO), DOUBLE_TOLERANCE); + assertEquals(100., output.getPtdfZonalSum(autoInstant, flowCnec, TWO), DOUBLE_TOLERANCE); + assertEquals(100., output.getPtdfZonalSum(curativeInstant, flowCnec, TWO), DOUBLE_TOLERANCE); } @Test diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/LeafTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/LeafTest.java index 1b4835c0bf..96ca732e10 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/LeafTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/LeafTest.java @@ -14,7 +14,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.*; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; @@ -50,8 +50,8 @@ import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; -import static com.powsybl.openrao.data.cracapi.cnec.Side.RIGHT; -import static com.powsybl.openrao.data.cracapi.cnec.Side.LEFT; +import static com.powsybl.iidm.network.TwoSides.TWO; +import static com.powsybl.iidm.network.TwoSides.ONE; import static com.powsybl.openrao.commons.Unit.*; import static org.mockito.Mockito.*; @@ -335,16 +335,16 @@ void getFlowsAndPtdfsOnFlowCnecAfterEvaluation() { double expectedFlow = 3.; Unit unit = MEGAWATT; - when(flowResult.getFlow(flowCnec, LEFT, unit)).thenReturn(expectedFlow); - when(flowResult.getCommercialFlow(flowCnec, LEFT, unit)).thenReturn(expectedFlow); - assertEquals(expectedFlow, leaf.getFlow(flowCnec, LEFT, unit), DOUBLE_TOLERANCE); - assertEquals(expectedFlow, leaf.getCommercialFlow(flowCnec, LEFT, unit), DOUBLE_TOLERANCE); + when(flowResult.getFlow(flowCnec, ONE, unit)).thenReturn(expectedFlow); + when(flowResult.getCommercialFlow(flowCnec, ONE, unit)).thenReturn(expectedFlow); + assertEquals(expectedFlow, leaf.getFlow(flowCnec, ONE, unit), DOUBLE_TOLERANCE); + assertEquals(expectedFlow, leaf.getCommercialFlow(flowCnec, ONE, unit), DOUBLE_TOLERANCE); double expectedPtdf = 4.; - when(flowResult.getPtdfZonalSum(flowCnec, LEFT)).thenReturn(expectedPtdf); - assertEquals(expectedPtdf, leaf.getPtdfZonalSum(flowCnec, LEFT), DOUBLE_TOLERANCE); + when(flowResult.getPtdfZonalSum(flowCnec, ONE)).thenReturn(expectedPtdf); + assertEquals(expectedPtdf, leaf.getPtdfZonalSum(flowCnec, ONE), DOUBLE_TOLERANCE); - Map> expectedPtdfZonalSums = new HashMap<>(); + Map> expectedPtdfZonalSums = new HashMap<>(); when(flowResult.getPtdfZonalSums()).thenReturn(expectedPtdfZonalSums); assertEquals(expectedPtdfZonalSums, leaf.getPtdfZonalSums()); } @@ -362,16 +362,16 @@ void getFlowsAndPtdfsOnFlowCnecAfterOptimization() { double expectedFlow = 3.; Unit unit = MEGAWATT; - when(linearOptimizationResult.getFlow(flowCnec, LEFT, unit)).thenReturn(expectedFlow); - when(linearOptimizationResult.getCommercialFlow(flowCnec, LEFT, unit)).thenReturn(expectedFlow); - assertEquals(expectedFlow, leaf.getFlow(flowCnec, LEFT, unit), DOUBLE_TOLERANCE); - assertEquals(expectedFlow, leaf.getCommercialFlow(flowCnec, LEFT, unit), DOUBLE_TOLERANCE); + when(linearOptimizationResult.getFlow(flowCnec, ONE, unit)).thenReturn(expectedFlow); + when(linearOptimizationResult.getCommercialFlow(flowCnec, ONE, unit)).thenReturn(expectedFlow); + assertEquals(expectedFlow, leaf.getFlow(flowCnec, ONE, unit), DOUBLE_TOLERANCE); + assertEquals(expectedFlow, leaf.getCommercialFlow(flowCnec, ONE, unit), DOUBLE_TOLERANCE); double expectedPtdf = 4.; - when(linearOptimizationResult.getPtdfZonalSum(flowCnec, LEFT)).thenReturn(expectedPtdf); - assertEquals(expectedPtdf, leaf.getPtdfZonalSum(flowCnec, LEFT), DOUBLE_TOLERANCE); + when(linearOptimizationResult.getPtdfZonalSum(flowCnec, ONE)).thenReturn(expectedPtdf); + assertEquals(expectedPtdf, leaf.getPtdfZonalSum(flowCnec, ONE), DOUBLE_TOLERANCE); - Map> expectedPtdfZonalSums = new HashMap<>(); + Map> expectedPtdfZonalSums = new HashMap<>(); when(linearOptimizationResult.getPtdfZonalSums()).thenReturn(expectedPtdfZonalSums); assertEquals(expectedPtdfZonalSums, leaf.getPtdfZonalSums()); @@ -381,7 +381,7 @@ void getFlowsAndPtdfsOnFlowCnecAfterOptimization() { void getFlowOnFlowCnecBeforeEvaluation() { Leaf leaf = buildNotEvaluatedRootLeaf(); FlowCnec flowCnec = Mockito.mock(FlowCnec.class); - OpenRaoException exception = assertThrows(OpenRaoException.class, () -> leaf.getFlow(flowCnec, LEFT, MEGAWATT)); + OpenRaoException exception = assertThrows(OpenRaoException.class, () -> leaf.getFlow(flowCnec, ONE, MEGAWATT)); assertEquals("No results available.", exception.getMessage()); } @@ -389,7 +389,7 @@ void getFlowOnFlowCnecBeforeEvaluation() { void getCommercialFlowOnFlowCnecBeforeEvaluation() { Leaf leaf = buildNotEvaluatedRootLeaf(); FlowCnec flowCnec = Mockito.mock(FlowCnec.class); - OpenRaoException exception = assertThrows(OpenRaoException.class, () -> leaf.getCommercialFlow(flowCnec, LEFT, MEGAWATT)); + OpenRaoException exception = assertThrows(OpenRaoException.class, () -> leaf.getCommercialFlow(flowCnec, ONE, MEGAWATT)); assertEquals("No results available.", exception.getMessage()); } @@ -397,7 +397,7 @@ void getCommercialFlowOnFlowCnecBeforeEvaluation() { void getPtdfZonalSumOnCnecBeforeEvaluation() { Leaf leaf = buildNotEvaluatedRootLeaf(); FlowCnec flowCnec = Mockito.mock(FlowCnec.class); - OpenRaoException exception = assertThrows(OpenRaoException.class, () -> leaf.getPtdfZonalSum(flowCnec, LEFT)); + OpenRaoException exception = assertThrows(OpenRaoException.class, () -> leaf.getPtdfZonalSum(flowCnec, ONE)); assertEquals("No results available.", exception.getMessage()); } @@ -684,11 +684,11 @@ void getSensitivityValueAfterEvaluation() { SensitivityVariableSet linearGlsk = Mockito.mock(SensitivityVariableSet.class); double expectedSensi = 3.; - when(prePerimeterResult.getSensitivityValue(flowCnec, RIGHT, rangeAction, MEGAWATT)).thenReturn(expectedSensi); - when(prePerimeterResult.getSensitivityValue(flowCnec, RIGHT, linearGlsk, MEGAWATT)).thenReturn(expectedSensi); + when(prePerimeterResult.getSensitivityValue(flowCnec, TWO, rangeAction, MEGAWATT)).thenReturn(expectedSensi); + when(prePerimeterResult.getSensitivityValue(flowCnec, TWO, linearGlsk, MEGAWATT)).thenReturn(expectedSensi); - assertEquals(expectedSensi, leaf.getSensitivityValue(flowCnec, RIGHT, rangeAction, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(expectedSensi, leaf.getSensitivityValue(flowCnec, RIGHT, linearGlsk, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(expectedSensi, leaf.getSensitivityValue(flowCnec, TWO, rangeAction, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(expectedSensi, leaf.getSensitivityValue(flowCnec, TWO, linearGlsk, MEGAWATT), DOUBLE_TOLERANCE); } @Test @@ -703,12 +703,12 @@ void getSensitivityValueAfterOptimization() { SensitivityVariableSet linearGlsk = Mockito.mock(SensitivityVariableSet.class); double expectedSensi = 3.; - when(linearOptimizationResult.getSensitivityValue(flowCnec, RIGHT, rangeAction, MEGAWATT)).thenReturn(expectedSensi); - when(linearOptimizationResult.getSensitivityValue(flowCnec, RIGHT, linearGlsk, MEGAWATT)).thenReturn(expectedSensi); + when(linearOptimizationResult.getSensitivityValue(flowCnec, TWO, rangeAction, MEGAWATT)).thenReturn(expectedSensi); + when(linearOptimizationResult.getSensitivityValue(flowCnec, TWO, linearGlsk, MEGAWATT)).thenReturn(expectedSensi); when(linearOptimizationResult.getRangeActions()).thenReturn(Set.of(rangeAction)); - assertEquals(expectedSensi, leaf.getSensitivityValue(flowCnec, RIGHT, rangeAction, MEGAWATT), DOUBLE_TOLERANCE); - assertEquals(expectedSensi, leaf.getSensitivityValue(flowCnec, RIGHT, linearGlsk, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(expectedSensi, leaf.getSensitivityValue(flowCnec, TWO, rangeAction, MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(expectedSensi, leaf.getSensitivityValue(flowCnec, TWO, linearGlsk, MEGAWATT), DOUBLE_TOLERANCE); } @Test @@ -716,7 +716,7 @@ void getSensitivityValueOnRangeActionBeforeEvaluation() { Leaf leaf = buildNotEvaluatedRootLeaf(); FlowCnec flowCnec = Mockito.mock(FlowCnec.class); RangeAction rangeAction = Mockito.mock(RangeAction.class); - OpenRaoException exception = assertThrows(OpenRaoException.class, () -> leaf.getSensitivityValue(flowCnec, RIGHT, rangeAction, MEGAWATT)); + OpenRaoException exception = assertThrows(OpenRaoException.class, () -> leaf.getSensitivityValue(flowCnec, TWO, rangeAction, MEGAWATT)); assertEquals("No results available.", exception.getMessage()); } @@ -725,7 +725,7 @@ void getSensitivityValueOnLinearGlskBeforeEvaluation() { Leaf leaf = buildNotEvaluatedRootLeaf(); FlowCnec flowCnec = Mockito.mock(FlowCnec.class); SensitivityVariableSet linearGlsk = Mockito.mock(SensitivityVariableSet.class); - OpenRaoException exception = assertThrows(OpenRaoException.class, () -> leaf.getSensitivityValue(flowCnec, RIGHT, linearGlsk, MEGAWATT)); + OpenRaoException exception = assertThrows(OpenRaoException.class, () -> leaf.getSensitivityValue(flowCnec, TWO, linearGlsk, MEGAWATT)); assertEquals("No results available.", exception.getMessage()); } diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/NetworkActionCombinationsUtils.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/NetworkActionCombinationsUtils.java index f4094c3941..e0009a48d6 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/NetworkActionCombinationsUtils.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/NetworkActionCombinationsUtils.java @@ -10,7 +10,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.State; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.ActionType; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.range.RangeType; @@ -78,7 +78,7 @@ private static Crac initCrac() { .withInstant(PREVENTIVE_INSTANT_ID).withOptimized(true) .withOperator("operator1").newThreshold() .withUnit(Unit.MEGAWATT) - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .withMin(-1500.) .withMax(1500.) .add() diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/SearchTreeTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/SearchTreeTest.java index 853f267fe7..edcdae8527 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/SearchTreeTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/SearchTreeTest.java @@ -16,7 +16,7 @@ import com.powsybl.openrao.commons.logs.TechnicalLogs; import com.powsybl.openrao.data.cracapi.*; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; @@ -560,15 +560,15 @@ private void setUpForVirtualLogs() { when(cnec.getNetworkElement()).thenReturn(networkElement); when(cnec.getId()).thenReturn("cnec-id"); when(cnec.getName()).thenReturn("cnec-name"); - when(cnec.getUpperBound(Side.LEFT, Unit.MEGAWATT)).thenReturn(Optional.of(1000.)); + when(cnec.getUpperBound(TwoSides.ONE, Unit.MEGAWATT)).thenReturn(Optional.of(1000.)); when(state.getId()).thenReturn("state-id"); when(networkElement.getId()).thenReturn("ne-id"); when(rootLeaf.getCostlyElements(eq("loop-flow-cost"), anyInt())).thenReturn(List.of(cnec)); when(rootLeaf.getIdentifier()).thenReturn("leaf-id"); - when(rootLeaf.getMargin(cnec, Side.LEFT, Unit.MEGAWATT)).thenReturn(-135.); - when(rootLeaf.getMargin(cnec, Side.RIGHT, Unit.MEGAWATT)).thenReturn(-134.); - when(rootLeaf.getFlow(cnec, Side.LEFT, Unit.MEGAWATT)).thenReturn(1135.); + when(rootLeaf.getMargin(cnec, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(-135.); + when(rootLeaf.getMargin(cnec, TwoSides.TWO, Unit.MEGAWATT)).thenReturn(-134.); + when(rootLeaf.getFlow(cnec, TwoSides.ONE, Unit.MEGAWATT)).thenReturn(1135.); } @Test diff --git a/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/LoadflowProvider.java b/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/LoadflowProvider.java index 566aa124fb..8467cbee0d 100644 --- a/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/LoadflowProvider.java +++ b/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/LoadflowProvider.java @@ -9,7 +9,7 @@ import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.HvdcRangeAction; import com.powsybl.contingency.Contingency; import com.powsybl.contingency.ContingencyContext; @@ -139,7 +139,7 @@ List> getSensitivityFunctions(Network netw .collect(Collectors.toSet()); } - Map> networkElementsAndSides = new HashMap<>(); + Map> networkElementsAndSides = new HashMap<>(); flowCnecs.forEach(flowCnec -> networkElementsAndSides.computeIfAbsent(flowCnec.getNetworkElement().getId(), k -> new HashSet<>()).addAll(flowCnec.getMonitoredSides()) ); @@ -149,7 +149,7 @@ List> getSensitivityFunctions(Network netw return sensitivityFunctions; } - private List> cnecToSensitivityFunctions(Network network, String networkElementId, Set sides) { + private List> cnecToSensitivityFunctions(Network network, String networkElementId, Set sides) { Identifiable networkIdentifiable = network.getIdentifiable(networkElementId); if (networkIdentifiable instanceof Branch || networkIdentifiable instanceof DanglingLine) { return getSensitivityFunctionTypes(sides).stream().map(functionType -> Pair.of(networkElementId, functionType)).toList(); @@ -158,18 +158,18 @@ private List> cnecToSensitivityFunctions(N } } - private Set getSensitivityFunctionTypes(Set sides) { + private Set getSensitivityFunctionTypes(Set sides) { Set sensitivityFunctionTypes = new HashSet<>(); - if (factorsInMegawatt && sides.contains(Side.LEFT)) { + if (factorsInMegawatt && sides.contains(TwoSides.ONE)) { sensitivityFunctionTypes.add(SensitivityFunctionType.BRANCH_ACTIVE_POWER_1); } - if (factorsInMegawatt && sides.contains(Side.RIGHT)) { + if (factorsInMegawatt && sides.contains(TwoSides.TWO)) { sensitivityFunctionTypes.add(SensitivityFunctionType.BRANCH_ACTIVE_POWER_2); } - if (factorsInAmpere && sides.contains(Side.LEFT)) { + if (factorsInAmpere && sides.contains(TwoSides.ONE)) { sensitivityFunctionTypes.add(SensitivityFunctionType.BRANCH_CURRENT_1); } - if (factorsInAmpere && sides.contains(Side.RIGHT)) { + if (factorsInAmpere && sides.contains(TwoSides.TWO)) { sensitivityFunctionTypes.add(SensitivityFunctionType.BRANCH_CURRENT_2); } return sensitivityFunctionTypes; diff --git a/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/PtdfSensitivityProvider.java b/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/PtdfSensitivityProvider.java index afb2e641bd..2825e7bb6f 100644 --- a/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/PtdfSensitivityProvider.java +++ b/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/PtdfSensitivityProvider.java @@ -10,7 +10,7 @@ import com.powsybl.openrao.commons.logs.OpenRaoLoggerProvider; import com.powsybl.openrao.data.cracapi.NetworkElement; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.HvdcRangeAction; import com.powsybl.contingency.Contingency; import com.powsybl.contingency.ContingencyContext; @@ -78,7 +78,7 @@ public List getContingencyFactors(Network network, List getFactors(ContingencyContext contingencyContext, Stream flowCnecsStream) { Map mapCountryLinearGlsk = glsk.getDataPerZone(); List factors = new ArrayList<>(); - Map> networkElementsAndSides = new HashMap<>(); + Map> networkElementsAndSides = new HashMap<>(); flowCnecsStream.forEach(cnec -> networkElementsAndSides.computeIfAbsent(cnec.getNetworkElement(), k -> new HashSet<>()).addAll(cnec.getMonitoredSides())); networkElementsAndSides .forEach((ne, sides) -> @@ -100,8 +100,8 @@ public Map getHvdcs() { return new HashMap<>(); } - private SensitivityFunctionType sideToActivePowerFunctionType(Side side) { - if (side.equals(Side.LEFT)) { + private SensitivityFunctionType sideToActivePowerFunctionType(TwoSides side) { + if (side.equals(TwoSides.ONE)) { return SensitivityFunctionType.BRANCH_ACTIVE_POWER_1; } else { return SensitivityFunctionType.BRANCH_ACTIVE_POWER_2; diff --git a/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/SystematicSensitivityResult.java b/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/SystematicSensitivityResult.java index 96de81a413..b0bb231218 100644 --- a/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/SystematicSensitivityResult.java +++ b/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/SystematicSensitivityResult.java @@ -10,7 +10,7 @@ import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.Cnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.HvdcRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; import com.powsybl.openrao.sensitivityanalysis.rasensihandler.RangeActionSensiHandler; @@ -29,28 +29,28 @@ public class SystematicSensitivityResult { private static class StateResult { private SensitivityComputationStatus status; - private final Map> referenceFlows = new HashMap<>(); - private final Map> referenceIntensities = new HashMap<>(); - private final Map>> flowSensitivities = new HashMap<>(); - private final Map>> intensitySensitivities = new HashMap<>(); + private final Map> referenceFlows = new HashMap<>(); + private final Map> referenceIntensities = new HashMap<>(); + private final Map>> flowSensitivities = new HashMap<>(); + private final Map>> intensitySensitivities = new HashMap<>(); private SensitivityComputationStatus getSensitivityComputationStatus() { return status; } - private Map> getReferenceFlows() { + private Map> getReferenceFlows() { return referenceFlows; } - private Map> getReferenceIntensities() { + private Map> getReferenceIntensities() { return referenceIntensities; } - private Map>> getFlowSensitivities() { + private Map>> getFlowSensitivities() { return flowSensitivities; } - private Map>> getIntensitySensitivities() { + private Map>> getIntensitySensitivities() { return intensitySensitivities; } } @@ -120,7 +120,7 @@ private void postTreatIntensitiesOnState(StateResult stateResult) { if (stateResult.getIntensitySensitivities().containsKey(neId)) { sideAndFlow.forEach((side, flow) -> { if (flow < 0) { - Map> sensitivities = stateResult.getIntensitySensitivities().get(neId); + Map> sensitivities = stateResult.getIntensitySensitivities().get(neId); sensitivities.forEach((actionId, sideToSensi) -> sensitivities.get(actionId).put(side, -sideToSensi.get(side))); } }); @@ -154,8 +154,8 @@ private void postTreatHvdcsOnState(Network network, Map }); } - private Map invertMapValues(Map map) { - Map invertedMap = new EnumMap<>(Side.class); + private Map invertMapValues(Map map) { + Map invertedMap = new EnumMap<>(TwoSides.class); map.forEach((key, value) -> invertedMap.put(key, -value)); return invertedMap; } @@ -173,27 +173,27 @@ private void fillIndividualValue(SensitivityValue value, StateResult stateResult sensitivity = 0; } - Side side = null; + TwoSides side = null; double activePowerCoefficient = 0; if (factor.getFunctionType().equals(SensitivityFunctionType.BRANCH_ACTIVE_POWER_1) || factor.getFunctionType().equals(SensitivityFunctionType.BRANCH_CURRENT_1)) { - side = Side.LEFT; + side = TwoSides.ONE; activePowerCoefficient = 1; } else if (factor.getFunctionType().equals(SensitivityFunctionType.BRANCH_ACTIVE_POWER_2) || factor.getFunctionType().equals(SensitivityFunctionType.BRANCH_CURRENT_2)) { - side = Side.RIGHT; + side = TwoSides.TWO; activePowerCoefficient = -1; // Open RAO always considers flows as seen from Side 1. Sensitivity providers invert side flows. } if (factor.getFunctionType().equals(SensitivityFunctionType.BRANCH_ACTIVE_POWER_1) || factor.getFunctionType().equals(SensitivityFunctionType.BRANCH_ACTIVE_POWER_2)) { stateResult.getReferenceFlows() - .computeIfAbsent(factor.getFunctionId(), k -> new EnumMap<>(Side.class)) + .computeIfAbsent(factor.getFunctionId(), k -> new EnumMap<>(TwoSides.class)) .putIfAbsent(side, reference * activePowerCoefficient); stateResult.getFlowSensitivities() .computeIfAbsent(factor.getFunctionId(), k -> new HashMap<>()) - .computeIfAbsent(factor.getVariableId(), k -> new EnumMap<>(Side.class)) + .computeIfAbsent(factor.getVariableId(), k -> new EnumMap<>(TwoSides.class)) .putIfAbsent(side, sensitivity * activePowerCoefficient); } else if (factor.getFunctionType().equals(SensitivityFunctionType.BRANCH_CURRENT_1) || factor.getFunctionType().equals(SensitivityFunctionType.BRANCH_CURRENT_2)) { stateResult.getReferenceIntensities() - .computeIfAbsent(factor.getFunctionId(), k -> new EnumMap<>(Side.class)) + .computeIfAbsent(factor.getFunctionId(), k -> new EnumMap<>(TwoSides.class)) .putIfAbsent(side, reference); } } @@ -233,7 +233,7 @@ public Set getContingencies() { return postContingencyResults.values().stream().flatMap(contingencyResult -> contingencyResult.keySet().stream()).collect(Collectors.toSet()); } - public double getReferenceFlow(FlowCnec cnec, Side side) { + public double getReferenceFlow(FlowCnec cnec, TwoSides side) { StateResult stateResult = getCnecStateResult(cnec); if (stateResult == null || !stateResult.getReferenceFlows().containsKey(cnec.getNetworkElement().getId()) || @@ -243,7 +243,7 @@ public double getReferenceFlow(FlowCnec cnec, Side side) { return stateResult.getReferenceFlows().get(cnec.getNetworkElement().getId()).get(side); } - public double getReferenceIntensity(FlowCnec cnec, Side side) { + public double getReferenceIntensity(FlowCnec cnec, TwoSides side) { StateResult stateResult = getCnecStateResult(cnec); if (stateResult == null || !stateResult.getReferenceIntensities().containsKey(cnec.getNetworkElement().getId()) || @@ -253,15 +253,15 @@ public double getReferenceIntensity(FlowCnec cnec, Side side) { return stateResult.getReferenceIntensities().get(cnec.getNetworkElement().getId()).get(side); } - public double getSensitivityOnFlow(RangeAction rangeAction, FlowCnec cnec, Side side) { + public double getSensitivityOnFlow(RangeAction rangeAction, FlowCnec cnec, TwoSides side) { return RangeActionSensiHandler.get(rangeAction).getSensitivityOnFlow(cnec, side, this); } - public double getSensitivityOnFlow(SensitivityVariableSet glsk, FlowCnec cnec, Side side) { + public double getSensitivityOnFlow(SensitivityVariableSet glsk, FlowCnec cnec, TwoSides side) { return getSensitivityOnFlow(glsk.getId(), cnec, side); } - public double getSensitivityOnFlow(String variableId, FlowCnec cnec, Side side) { + public double getSensitivityOnFlow(String variableId, FlowCnec cnec, TwoSides side) { StateResult stateResult = getCnecStateResult(cnec); if (stateResult == null || !stateResult.getFlowSensitivities().containsKey(cnec.getNetworkElement().getId()) || diff --git a/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/rasensihandler/HvdcRangeActionSensiHandler.java b/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/rasensihandler/HvdcRangeActionSensiHandler.java index a14e980927..f2d31a7f1e 100644 --- a/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/rasensihandler/HvdcRangeActionSensiHandler.java +++ b/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/rasensihandler/HvdcRangeActionSensiHandler.java @@ -8,7 +8,7 @@ import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.HvdcRangeAction; import com.powsybl.openrao.sensitivityanalysis.SystematicSensitivityResult; import com.powsybl.iidm.network.HvdcLine; @@ -27,7 +27,7 @@ public HvdcRangeActionSensiHandler(HvdcRangeAction hvdcRangeAction) { } @Override - public double getSensitivityOnFlow(FlowCnec cnec, Side side, SystematicSensitivityResult sensitivityResult) { + public double getSensitivityOnFlow(FlowCnec cnec, TwoSides side, SystematicSensitivityResult sensitivityResult) { return sensitivityResult.getSensitivityOnFlow(hvdcRangeAction.getNetworkElement().getId(), cnec, side); } diff --git a/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/rasensihandler/InjectionRangeActionSensiHandler.java b/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/rasensihandler/InjectionRangeActionSensiHandler.java index 58c9591d5c..16b0b3ab28 100644 --- a/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/rasensihandler/InjectionRangeActionSensiHandler.java +++ b/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/rasensihandler/InjectionRangeActionSensiHandler.java @@ -8,7 +8,7 @@ import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.InjectionRangeAction; import com.powsybl.openrao.sensitivityanalysis.SystematicSensitivityResult; import com.powsybl.iidm.network.Generator; @@ -35,7 +35,7 @@ public InjectionRangeActionSensiHandler(InjectionRangeAction injectionRangeActio } @Override - public double getSensitivityOnFlow(FlowCnec cnec, Side side, SystematicSensitivityResult sensitivityResult) { + public double getSensitivityOnFlow(FlowCnec cnec, TwoSides side, SystematicSensitivityResult sensitivityResult) { return sensitivityResult.getSensitivityOnFlow(getPositiveGlskMapId(), cnec, side) * getKeySum(getPositiveGlskMap()) - sensitivityResult.getSensitivityOnFlow(getNegativeGlskMapId(), cnec, side) * getKeySum(getNegativeGlskMap()); } diff --git a/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/rasensihandler/PstRangeActionSensiHandler.java b/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/rasensihandler/PstRangeActionSensiHandler.java index 5739590038..ce8424d666 100644 --- a/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/rasensihandler/PstRangeActionSensiHandler.java +++ b/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/rasensihandler/PstRangeActionSensiHandler.java @@ -8,7 +8,7 @@ import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.sensitivityanalysis.SystematicSensitivityResult; import com.powsybl.iidm.network.*; @@ -25,7 +25,7 @@ public PstRangeActionSensiHandler(PstRangeAction pstRangeAction) { } @Override - public double getSensitivityOnFlow(FlowCnec cnec, Side side, SystematicSensitivityResult sensitivityResult) { + public double getSensitivityOnFlow(FlowCnec cnec, TwoSides side, SystematicSensitivityResult sensitivityResult) { return sensitivityResult.getSensitivityOnFlow(pstRangeAction.getNetworkElement().getId(), cnec, side); } diff --git a/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/rasensihandler/RangeActionSensiHandler.java b/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/rasensihandler/RangeActionSensiHandler.java index 0ffaabd7e4..e8b0155d02 100644 --- a/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/rasensihandler/RangeActionSensiHandler.java +++ b/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/rasensihandler/RangeActionSensiHandler.java @@ -8,7 +8,7 @@ import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.HvdcRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.InjectionRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; @@ -21,7 +21,7 @@ */ public interface RangeActionSensiHandler { - double getSensitivityOnFlow(FlowCnec cnec, Side side, SystematicSensitivityResult sensitivityResult); + double getSensitivityOnFlow(FlowCnec cnec, TwoSides side, SystematicSensitivityResult sensitivityResult); void checkConsistency(Network network); diff --git a/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/AppliedRemedialActionsTest.java b/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/AppliedRemedialActionsTest.java index 9499a57acd..fddb2e496e 100644 --- a/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/AppliedRemedialActionsTest.java +++ b/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/AppliedRemedialActionsTest.java @@ -11,7 +11,7 @@ import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.State; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.ActionType; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; @@ -159,7 +159,7 @@ void testCopyNetworkActionsAndAutomaticRangeActions() { .withIMax(5000.) .newThreshold() .withUnit(Unit.MEGAWATT) - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .withMin(-1500.) .withMax(1500.) .add() @@ -175,7 +175,7 @@ void testCopyNetworkActionsAndAutomaticRangeActions() { .withIMax(5000.) .newThreshold() .withUnit(Unit.MEGAWATT) - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .withMin(-1500.) .withMax(1500.) .add() diff --git a/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/LoadflowProviderTest.java b/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/LoadflowProviderTest.java index 58d827b4ea..79960e6a1b 100644 --- a/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/LoadflowProviderTest.java +++ b/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/LoadflowProviderTest.java @@ -8,7 +8,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.Crac; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracimpl.utils.CommonCracCreation; import com.powsybl.openrao.data.cracimpl.utils.NetworkImportsUtil; import com.powsybl.contingency.Contingency; @@ -32,7 +32,7 @@ class LoadflowProviderTest { @Test void inAmpereAndMegawattOnOneSide() { - Crac crac = CommonCracCreation.create(Set.of(Side.LEFT)); + Crac crac = CommonCracCreation.create(Set.of(TwoSides.ONE)); Network network = NetworkImportsUtil.import12NodesNetwork(); LoadflowProvider provider = new LoadflowProvider(crac.getFlowCnecs(), Set.of(Unit.MEGAWATT, Unit.AMPERE)); @@ -49,7 +49,7 @@ void inAmpereAndMegawattOnOneSide() { @Test void inAmpereAndMegawattOnTwoSides() { - Crac crac = CommonCracCreation.create(Set.of(Side.LEFT, Side.RIGHT)); + Crac crac = CommonCracCreation.create(Set.of(TwoSides.ONE, TwoSides.TWO)); Network network = NetworkImportsUtil.import12NodesNetwork(); LoadflowProvider provider = new LoadflowProvider(crac.getFlowCnecs(), Set.of(Unit.MEGAWATT, Unit.AMPERE)); diff --git a/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/RangeActionSensitivityProviderTest.java b/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/RangeActionSensitivityProviderTest.java index 73fe1be0dc..55c71cd1f4 100644 --- a/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/RangeActionSensitivityProviderTest.java +++ b/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/RangeActionSensitivityProviderTest.java @@ -11,7 +11,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.*; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.CounterTradeRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.HvdcRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; @@ -69,7 +69,7 @@ void contingenciesCracPstWithRange() { .withNetworkElement("BBE2AA1 FFR3AA1 1") .newThreshold() .withUnit(Unit.AMPERE) - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .withMin(-10.) .withMax(10.) .add() @@ -83,7 +83,7 @@ void contingenciesCracPstWithRange() { .withNetworkElement("BBE2AA1 FFR3AA1 1") .newThreshold() .withUnit(Unit.AMPERE) - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .withMin(-10.) .withMax(10.) .add() @@ -97,7 +97,7 @@ void contingenciesCracPstWithRange() { .withNetworkElement("BBE2AA1 FFR3AA1 1") .newThreshold() .withUnit(Unit.AMPERE) - .withSide(Side.LEFT) + .withSide(TwoSides.ONE) .withMin(-10.) .withMax(10.) .add() @@ -137,7 +137,7 @@ void testDisableFactorForBaseCase() { @Test void factorsCracPstWithRange() { - Crac crac = CommonCracCreation.createWithPreventivePstRange(Set.of(Side.LEFT, Side.RIGHT)); + Crac crac = CommonCracCreation.createWithPreventivePstRange(Set.of(TwoSides.ONE, TwoSides.TWO)); Network network = NetworkImportsUtil.import12NodesNetwork(); RangeActionSensitivityProvider provider = new RangeActionSensitivityProvider(crac.getRangeActions(), crac.getFlowCnecs(), Set.of(Unit.MEGAWATT, Unit.AMPERE)); @@ -180,7 +180,7 @@ void cracWithoutRangeActionButWithPst() { @Test void cracWithoutRangeActionNorPst() { - Crac crac = CommonCracCreation.create(Set.of(Side.LEFT, Side.RIGHT)); + Crac crac = CommonCracCreation.create(Set.of(TwoSides.ONE, TwoSides.TWO)); Network network = NetworkImportsUtil.import12NodesNoPstNetwork(); RangeActionSensitivityProvider provider = new RangeActionSensitivityProvider(crac.getRangeActions(), crac.getFlowCnecs(), Set.of(Unit.MEGAWATT, Unit.AMPERE)); @@ -210,8 +210,8 @@ void testHvdcSensi() { .withId("cnec") .withNetworkElement("BBE1AA11 FFR5AA11 1") .withInstant(PREVENTIVE_INSTANT_ID) - .newThreshold().withMax(1000.).withUnit(Unit.MEGAWATT).withSide(Side.LEFT).add() - .newThreshold().withMax(1000.).withUnit(Unit.MEGAWATT).withSide(Side.RIGHT).add() + .newThreshold().withMax(1000.).withUnit(Unit.MEGAWATT).withSide(TwoSides.ONE).add() + .newThreshold().withMax(1000.).withUnit(Unit.MEGAWATT).withSide(TwoSides.TWO).add() .add(); Network network = Network.read("TestCase16NodesWithHvdc.xiidm", getClass().getResourceAsStream("/TestCase16NodesWithHvdc.xiidm")); @@ -260,7 +260,7 @@ void testUnhandledElement() { .withId("cnec") .withNetworkElement("BBE1AA11 FFR5AA11 1") .withInstant(PREVENTIVE_INSTANT_ID) - .newThreshold().withMax(1000.).withUnit(Unit.MEGAWATT).withSide(Side.LEFT).add() + .newThreshold().withMax(1000.).withUnit(Unit.MEGAWATT).withSide(TwoSides.ONE).add() .add(); Network network = Network.read("TestCase16NodesWithHvdc.xiidm", getClass().getResourceAsStream("/TestCase16NodesWithHvdc.xiidm")); @@ -283,7 +283,7 @@ void testCTDoesNotThrow() { .withId("cnec") .withNetworkElement("BBE1AA11 FFR5AA11 1") .withInstant(PREVENTIVE_INSTANT_ID) - .newThreshold().withMax(1000.).withUnit(Unit.MEGAWATT).withSide(Side.LEFT).add() + .newThreshold().withMax(1000.).withUnit(Unit.MEGAWATT).withSide(TwoSides.ONE).add() .add(); Network network = Network.read("TestCase16NodesWithHvdc.xiidm", getClass().getResourceAsStream("/TestCase16NodesWithHvdc.xiidm")); diff --git a/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/SystematicSensitivityAdapterTest.java b/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/SystematicSensitivityAdapterTest.java index a90f62117c..344768588a 100644 --- a/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/SystematicSensitivityAdapterTest.java +++ b/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/SystematicSensitivityAdapterTest.java @@ -18,8 +18,8 @@ import java.util.Set; import static org.junit.jupiter.api.Assertions.assertEquals; -import static com.powsybl.openrao.data.cracapi.cnec.Side.LEFT; -import static com.powsybl.openrao.data.cracapi.cnec.Side.RIGHT; +import static com.powsybl.iidm.network.TwoSides.ONE; +import static com.powsybl.iidm.network.TwoSides.TWO; /** * @author Sebastien Murgey {@literal } @@ -33,75 +33,75 @@ class SystematicSensitivityAdapterTest { @Test void testWithoutAppliedRa() { Network network = NetworkImportsUtil.import12NodesNetwork(); - Crac crac = CommonCracCreation.createWithPreventivePstRange(Set.of(LEFT, RIGHT)); + Crac crac = CommonCracCreation.createWithPreventivePstRange(Set.of(ONE, TWO)); Instant outageInstant = crac.getInstant(OUTAGE_INSTANT_ID); RangeActionSensitivityProvider factorProvider = new RangeActionSensitivityProvider(crac.getRangeActions(), crac.getFlowCnecs(), Set.of(Unit.MEGAWATT, Unit.AMPERE)); SystematicSensitivityResult result = SystematicSensitivityAdapter.runSensitivity(network, factorProvider, new SensitivityAnalysisParameters(), "MockSensi", outageInstant); // "standard results" of the MockSensiProvider are expected - assertEquals(10, result.getReferenceFlow(crac.getFlowCnec("cnec2basecase"), LEFT), DOUBLE_TOLERANCE); - assertEquals(-15, result.getReferenceFlow(crac.getFlowCnec("cnec2basecase"), RIGHT), DOUBLE_TOLERANCE); - - assertEquals(-20, result.getReferenceFlow(crac.getFlowCnec("cnec1stateCurativeContingency2"), LEFT), DOUBLE_TOLERANCE); - assertEquals(-20, result.getReferenceFlow(crac.getFlowCnec("cnec2stateCurativeContingency1"), LEFT), DOUBLE_TOLERANCE); - assertEquals(25, result.getReferenceFlow(crac.getFlowCnec("cnec1stateCurativeContingency2"), RIGHT), DOUBLE_TOLERANCE); - assertEquals(25, result.getReferenceFlow(crac.getFlowCnec("cnec2stateCurativeContingency1"), RIGHT), DOUBLE_TOLERANCE); - - assertEquals(25, result.getReferenceIntensity(crac.getFlowCnec("cnec2basecase"), LEFT), DOUBLE_TOLERANCE); - assertEquals(-30, result.getReferenceIntensity(crac.getFlowCnec("cnec2basecase"), RIGHT), DOUBLE_TOLERANCE); - - assertEquals(-200, result.getReferenceIntensity(crac.getFlowCnec("cnec1stateCurativeContingency2"), LEFT), DOUBLE_TOLERANCE); - assertEquals(-200, result.getReferenceIntensity(crac.getFlowCnec("cnec2stateCurativeContingency1"), LEFT), DOUBLE_TOLERANCE); - assertEquals(205, result.getReferenceIntensity(crac.getFlowCnec("cnec1stateCurativeContingency2"), RIGHT), DOUBLE_TOLERANCE); - assertEquals(205, result.getReferenceIntensity(crac.getFlowCnec("cnec2stateCurativeContingency1"), RIGHT), DOUBLE_TOLERANCE); - - assertEquals(0.5, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec2basecase"), LEFT), DOUBLE_TOLERANCE); - assertEquals(-5, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec1stateCurativeContingency2"), LEFT), DOUBLE_TOLERANCE); - assertEquals(-5, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec2stateCurativeContingency1"), LEFT), DOUBLE_TOLERANCE); - assertEquals(-0.55, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec2basecase"), RIGHT), DOUBLE_TOLERANCE); - assertEquals(5.5, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec1stateCurativeContingency2"), RIGHT), DOUBLE_TOLERANCE); - assertEquals(5.5, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec2stateCurativeContingency1"), RIGHT), DOUBLE_TOLERANCE); + assertEquals(10, result.getReferenceFlow(crac.getFlowCnec("cnec2basecase"), ONE), DOUBLE_TOLERANCE); + assertEquals(-15, result.getReferenceFlow(crac.getFlowCnec("cnec2basecase"), TWO), DOUBLE_TOLERANCE); + + assertEquals(-20, result.getReferenceFlow(crac.getFlowCnec("cnec1stateCurativeContingency2"), ONE), DOUBLE_TOLERANCE); + assertEquals(-20, result.getReferenceFlow(crac.getFlowCnec("cnec2stateCurativeContingency1"), ONE), DOUBLE_TOLERANCE); + assertEquals(25, result.getReferenceFlow(crac.getFlowCnec("cnec1stateCurativeContingency2"), TWO), DOUBLE_TOLERANCE); + assertEquals(25, result.getReferenceFlow(crac.getFlowCnec("cnec2stateCurativeContingency1"), TWO), DOUBLE_TOLERANCE); + + assertEquals(25, result.getReferenceIntensity(crac.getFlowCnec("cnec2basecase"), ONE), DOUBLE_TOLERANCE); + assertEquals(-30, result.getReferenceIntensity(crac.getFlowCnec("cnec2basecase"), TWO), DOUBLE_TOLERANCE); + + assertEquals(-200, result.getReferenceIntensity(crac.getFlowCnec("cnec1stateCurativeContingency2"), ONE), DOUBLE_TOLERANCE); + assertEquals(-200, result.getReferenceIntensity(crac.getFlowCnec("cnec2stateCurativeContingency1"), ONE), DOUBLE_TOLERANCE); + assertEquals(205, result.getReferenceIntensity(crac.getFlowCnec("cnec1stateCurativeContingency2"), TWO), DOUBLE_TOLERANCE); + assertEquals(205, result.getReferenceIntensity(crac.getFlowCnec("cnec2stateCurativeContingency1"), TWO), DOUBLE_TOLERANCE); + + assertEquals(0.5, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec2basecase"), ONE), DOUBLE_TOLERANCE); + assertEquals(-5, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec1stateCurativeContingency2"), ONE), DOUBLE_TOLERANCE); + assertEquals(-5, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec2stateCurativeContingency1"), ONE), DOUBLE_TOLERANCE); + assertEquals(-0.55, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec2basecase"), TWO), DOUBLE_TOLERANCE); + assertEquals(5.5, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec1stateCurativeContingency2"), TWO), DOUBLE_TOLERANCE); + assertEquals(5.5, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec2stateCurativeContingency1"), TWO), DOUBLE_TOLERANCE); } @Test void testWithoutAppliedRaLeftSideOnly() { Network network = NetworkImportsUtil.import12NodesNetwork(); - Crac crac = CommonCracCreation.createWithPreventivePstRange(Set.of(LEFT)); + Crac crac = CommonCracCreation.createWithPreventivePstRange(Set.of(ONE)); Instant outageInstant = crac.getInstant(OUTAGE_INSTANT_ID); RangeActionSensitivityProvider factorProvider = new RangeActionSensitivityProvider(crac.getRangeActions(), crac.getFlowCnecs(), Set.of(Unit.MEGAWATT, Unit.AMPERE)); SystematicSensitivityResult result = SystematicSensitivityAdapter.runSensitivity(network, factorProvider, new SensitivityAnalysisParameters(), "MockSensi", outageInstant); // "standard results" of the MockSensiProvider are expected - assertEquals(10, result.getReferenceFlow(crac.getFlowCnec("cnec2basecase"), LEFT), DOUBLE_TOLERANCE); - assertEquals(0, result.getReferenceFlow(crac.getFlowCnec("cnec2basecase"), RIGHT), DOUBLE_TOLERANCE); - - assertEquals(-20, result.getReferenceFlow(crac.getFlowCnec("cnec1stateCurativeContingency2"), LEFT), DOUBLE_TOLERANCE); - assertEquals(-20, result.getReferenceFlow(crac.getFlowCnec("cnec2stateCurativeContingency1"), LEFT), DOUBLE_TOLERANCE); - assertEquals(0, result.getReferenceFlow(crac.getFlowCnec("cnec1stateCurativeContingency2"), RIGHT), DOUBLE_TOLERANCE); - assertEquals(0, result.getReferenceFlow(crac.getFlowCnec("cnec2stateCurativeContingency1"), RIGHT), DOUBLE_TOLERANCE); - - assertEquals(25, result.getReferenceIntensity(crac.getFlowCnec("cnec2basecase"), LEFT), DOUBLE_TOLERANCE); - assertEquals(0, result.getReferenceIntensity(crac.getFlowCnec("cnec2basecase"), RIGHT), DOUBLE_TOLERANCE); - - assertEquals(-200, result.getReferenceIntensity(crac.getFlowCnec("cnec1stateCurativeContingency2"), LEFT), DOUBLE_TOLERANCE); - assertEquals(-200, result.getReferenceIntensity(crac.getFlowCnec("cnec2stateCurativeContingency1"), LEFT), DOUBLE_TOLERANCE); - assertEquals(0, result.getReferenceIntensity(crac.getFlowCnec("cnec1stateCurativeContingency2"), RIGHT), DOUBLE_TOLERANCE); - assertEquals(0, result.getReferenceIntensity(crac.getFlowCnec("cnec2stateCurativeContingency1"), RIGHT), DOUBLE_TOLERANCE); - - assertEquals(0.5, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec2basecase"), LEFT), DOUBLE_TOLERANCE); - assertEquals(-5, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec1stateCurativeContingency2"), LEFT), DOUBLE_TOLERANCE); - assertEquals(-5, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec2stateCurativeContingency1"), LEFT), DOUBLE_TOLERANCE); - assertEquals(0, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec2basecase"), RIGHT), DOUBLE_TOLERANCE); - assertEquals(0, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec1stateCurativeContingency2"), RIGHT), DOUBLE_TOLERANCE); - assertEquals(0, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec2stateCurativeContingency1"), RIGHT), DOUBLE_TOLERANCE); + assertEquals(10, result.getReferenceFlow(crac.getFlowCnec("cnec2basecase"), ONE), DOUBLE_TOLERANCE); + assertEquals(0, result.getReferenceFlow(crac.getFlowCnec("cnec2basecase"), TWO), DOUBLE_TOLERANCE); + + assertEquals(-20, result.getReferenceFlow(crac.getFlowCnec("cnec1stateCurativeContingency2"), ONE), DOUBLE_TOLERANCE); + assertEquals(-20, result.getReferenceFlow(crac.getFlowCnec("cnec2stateCurativeContingency1"), ONE), DOUBLE_TOLERANCE); + assertEquals(0, result.getReferenceFlow(crac.getFlowCnec("cnec1stateCurativeContingency2"), TWO), DOUBLE_TOLERANCE); + assertEquals(0, result.getReferenceFlow(crac.getFlowCnec("cnec2stateCurativeContingency1"), TWO), DOUBLE_TOLERANCE); + + assertEquals(25, result.getReferenceIntensity(crac.getFlowCnec("cnec2basecase"), ONE), DOUBLE_TOLERANCE); + assertEquals(0, result.getReferenceIntensity(crac.getFlowCnec("cnec2basecase"), TWO), DOUBLE_TOLERANCE); + + assertEquals(-200, result.getReferenceIntensity(crac.getFlowCnec("cnec1stateCurativeContingency2"), ONE), DOUBLE_TOLERANCE); + assertEquals(-200, result.getReferenceIntensity(crac.getFlowCnec("cnec2stateCurativeContingency1"), ONE), DOUBLE_TOLERANCE); + assertEquals(0, result.getReferenceIntensity(crac.getFlowCnec("cnec1stateCurativeContingency2"), TWO), DOUBLE_TOLERANCE); + assertEquals(0, result.getReferenceIntensity(crac.getFlowCnec("cnec2stateCurativeContingency1"), TWO), DOUBLE_TOLERANCE); + + assertEquals(0.5, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec2basecase"), ONE), DOUBLE_TOLERANCE); + assertEquals(-5, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec1stateCurativeContingency2"), ONE), DOUBLE_TOLERANCE); + assertEquals(-5, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec2stateCurativeContingency1"), ONE), DOUBLE_TOLERANCE); + assertEquals(0, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec2basecase"), TWO), DOUBLE_TOLERANCE); + assertEquals(0, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec1stateCurativeContingency2"), TWO), DOUBLE_TOLERANCE); + assertEquals(0, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec2stateCurativeContingency1"), TWO), DOUBLE_TOLERANCE); } @Test void testWithAppliedRa() { Network network = NetworkImportsUtil.import12NodesNetwork(); - Crac crac = CommonCracCreation.createWithPreventivePstRange(Set.of(LEFT, RIGHT)); + Crac crac = CommonCracCreation.createWithPreventivePstRange(Set.of(ONE, TWO)); Instant curativeInstant = crac.getInstant(CURATIVE_INSTANT_ID); crac.newFlowCnec() .withId("cnec2stateOutageContingency1") @@ -110,10 +110,10 @@ void testWithAppliedRa() { .withContingency("Contingency FR1 FR3") .withOptimized(true) .withOperator("operator2") - .newThreshold().withUnit(Unit.MEGAWATT).withSide(LEFT).withMin(-1500.).withMax(1500.).add() - .newThreshold().withUnit(Unit.MEGAWATT).withSide(RIGHT).withMin(-1500.).withMax(1500.).add() - .newThreshold().withUnit(Unit.PERCENT_IMAX).withSide(LEFT).withMin(-0.3).withMax(0.3).add() - .newThreshold().withUnit(Unit.PERCENT_IMAX).withSide(RIGHT).withMin(-0.3).withMax(0.3).add() + .newThreshold().withUnit(Unit.MEGAWATT).withSide(ONE).withMin(-1500.).withMax(1500.).add() + .newThreshold().withUnit(Unit.MEGAWATT).withSide(TWO).withMin(-1500.).withMax(1500.).add() + .newThreshold().withUnit(Unit.PERCENT_IMAX).withSide(ONE).withMin(-0.3).withMax(0.3).add() + .newThreshold().withUnit(Unit.PERCENT_IMAX).withSide(TWO).withMin(-0.3).withMax(0.3).add() .withNominalVoltage(380.) .withIMax(5000.) .add(); @@ -124,42 +124,42 @@ void testWithAppliedRa() { SystematicSensitivityResult result = SystematicSensitivityAdapter.runSensitivity(network, factorProvider, appliedRemedialActions, new SensitivityAnalysisParameters(), "MockSensi", crac.getOutageInstant()); // after initial state or contingency without CRA, "standard results" of the MockSensiProvider are expected - assertEquals(10, result.getReferenceFlow(crac.getFlowCnec("cnec2basecase"), LEFT), DOUBLE_TOLERANCE); - assertEquals(-15, result.getReferenceFlow(crac.getFlowCnec("cnec2basecase"), RIGHT), DOUBLE_TOLERANCE); + assertEquals(10, result.getReferenceFlow(crac.getFlowCnec("cnec2basecase"), ONE), DOUBLE_TOLERANCE); + assertEquals(-15, result.getReferenceFlow(crac.getFlowCnec("cnec2basecase"), TWO), DOUBLE_TOLERANCE); - assertEquals(-20, result.getReferenceFlow(crac.getFlowCnec("cnec1stateCurativeContingency2"), LEFT), DOUBLE_TOLERANCE); - assertEquals(25, result.getReferenceFlow(crac.getFlowCnec("cnec1stateCurativeContingency2"), RIGHT), DOUBLE_TOLERANCE); + assertEquals(-20, result.getReferenceFlow(crac.getFlowCnec("cnec1stateCurativeContingency2"), ONE), DOUBLE_TOLERANCE); + assertEquals(25, result.getReferenceFlow(crac.getFlowCnec("cnec1stateCurativeContingency2"), TWO), DOUBLE_TOLERANCE); - assertEquals(25, result.getReferenceIntensity(crac.getFlowCnec("cnec2basecase"), LEFT), DOUBLE_TOLERANCE); - assertEquals(-30, result.getReferenceIntensity(crac.getFlowCnec("cnec2basecase"), RIGHT), DOUBLE_TOLERANCE); + assertEquals(25, result.getReferenceIntensity(crac.getFlowCnec("cnec2basecase"), ONE), DOUBLE_TOLERANCE); + assertEquals(-30, result.getReferenceIntensity(crac.getFlowCnec("cnec2basecase"), TWO), DOUBLE_TOLERANCE); - assertEquals(-200, result.getReferenceIntensity(crac.getFlowCnec("cnec1stateCurativeContingency2"), LEFT), DOUBLE_TOLERANCE); - assertEquals(205, result.getReferenceIntensity(crac.getFlowCnec("cnec1stateCurativeContingency2"), RIGHT), DOUBLE_TOLERANCE); + assertEquals(-200, result.getReferenceIntensity(crac.getFlowCnec("cnec1stateCurativeContingency2"), ONE), DOUBLE_TOLERANCE); + assertEquals(205, result.getReferenceIntensity(crac.getFlowCnec("cnec1stateCurativeContingency2"), TWO), DOUBLE_TOLERANCE); - assertEquals(0.5, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec2basecase"), LEFT), DOUBLE_TOLERANCE); - assertEquals(-0.55, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec2basecase"), RIGHT), DOUBLE_TOLERANCE); + assertEquals(0.5, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec2basecase"), ONE), DOUBLE_TOLERANCE); + assertEquals(-0.55, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec2basecase"), TWO), DOUBLE_TOLERANCE); - assertEquals(-5, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec1stateCurativeContingency2"), LEFT), DOUBLE_TOLERANCE); - assertEquals(5.5, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec1stateCurativeContingency2"), RIGHT), DOUBLE_TOLERANCE); + assertEquals(-5, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec1stateCurativeContingency2"), ONE), DOUBLE_TOLERANCE); + assertEquals(5.5, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec1stateCurativeContingency2"), TWO), DOUBLE_TOLERANCE); // after contingency with CRA, "alternative" results of the MockSensiProvider are expected - assertEquals(-40, result.getReferenceFlow(crac.getFlowCnec("cnec2stateCurativeContingency1"), LEFT), DOUBLE_TOLERANCE); - assertEquals(45, result.getReferenceFlow(crac.getFlowCnec("cnec2stateCurativeContingency1"), RIGHT), DOUBLE_TOLERANCE); + assertEquals(-40, result.getReferenceFlow(crac.getFlowCnec("cnec2stateCurativeContingency1"), ONE), DOUBLE_TOLERANCE); + assertEquals(45, result.getReferenceFlow(crac.getFlowCnec("cnec2stateCurativeContingency1"), TWO), DOUBLE_TOLERANCE); - assertEquals(-90, result.getReferenceIntensity(crac.getFlowCnec("cnec2stateCurativeContingency1"), LEFT), DOUBLE_TOLERANCE); - assertEquals(95, result.getReferenceIntensity(crac.getFlowCnec("cnec2stateCurativeContingency1"), RIGHT), DOUBLE_TOLERANCE); + assertEquals(-90, result.getReferenceIntensity(crac.getFlowCnec("cnec2stateCurativeContingency1"), ONE), DOUBLE_TOLERANCE); + assertEquals(95, result.getReferenceIntensity(crac.getFlowCnec("cnec2stateCurativeContingency1"), TWO), DOUBLE_TOLERANCE); - assertEquals(-2.5, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec2stateCurativeContingency1"), LEFT), DOUBLE_TOLERANCE); - assertEquals(3.0, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec2stateCurativeContingency1"), RIGHT), DOUBLE_TOLERANCE); + assertEquals(-2.5, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec2stateCurativeContingency1"), ONE), DOUBLE_TOLERANCE); + assertEquals(3.0, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec2stateCurativeContingency1"), TWO), DOUBLE_TOLERANCE); // for outage CNECs, do NOT take CRAs into account - assertEquals(-20, result.getReferenceFlow(crac.getFlowCnec("cnec2stateOutageContingency1"), LEFT), DOUBLE_TOLERANCE); - assertEquals(25, result.getReferenceFlow(crac.getFlowCnec("cnec2stateOutageContingency1"), RIGHT), DOUBLE_TOLERANCE); + assertEquals(-20, result.getReferenceFlow(crac.getFlowCnec("cnec2stateOutageContingency1"), ONE), DOUBLE_TOLERANCE); + assertEquals(25, result.getReferenceFlow(crac.getFlowCnec("cnec2stateOutageContingency1"), TWO), DOUBLE_TOLERANCE); - assertEquals(-200, result.getReferenceIntensity(crac.getFlowCnec("cnec2stateOutageContingency1"), LEFT), DOUBLE_TOLERANCE); - assertEquals(205, result.getReferenceIntensity(crac.getFlowCnec("cnec2stateOutageContingency1"), RIGHT), DOUBLE_TOLERANCE); + assertEquals(-200, result.getReferenceIntensity(crac.getFlowCnec("cnec2stateOutageContingency1"), ONE), DOUBLE_TOLERANCE); + assertEquals(205, result.getReferenceIntensity(crac.getFlowCnec("cnec2stateOutageContingency1"), TWO), DOUBLE_TOLERANCE); - assertEquals(-5, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec2stateOutageContingency1"), LEFT), DOUBLE_TOLERANCE); - assertEquals(5.5, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec2stateOutageContingency1"), RIGHT), DOUBLE_TOLERANCE); + assertEquals(-5, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec2stateOutageContingency1"), ONE), DOUBLE_TOLERANCE); + assertEquals(5.5, result.getSensitivityOnFlow(crac.getRangeAction("pst"), crac.getFlowCnec("cnec2stateOutageContingency1"), TWO), DOUBLE_TOLERANCE); } } diff --git a/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/SystematicSensitivityInterfaceTest.java b/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/SystematicSensitivityInterfaceTest.java index c861259250..5673833540 100644 --- a/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/SystematicSensitivityInterfaceTest.java +++ b/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/SystematicSensitivityInterfaceTest.java @@ -11,7 +11,7 @@ import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracimpl.utils.CommonCracCreation; import com.powsybl.openrao.data.cracimpl.utils.NetworkImportsUtil; import com.powsybl.iidm.network.Network; @@ -86,15 +86,15 @@ void testRunDefaultConfigOk() { assertNotNull(systematicSensitivityAnalysisResult); for (FlowCnec cnec : crac.getFlowCnecs()) { if (cnec.getId().equals("cnec2basecase")) { - assertEquals(1400., systematicSensitivityAnalysisResult.getReferenceFlow(cnec, Side.LEFT), FLOW_TOLERANCE); - assertEquals(2800., systematicSensitivityAnalysisResult.getReferenceFlow(cnec, Side.RIGHT), FLOW_TOLERANCE); - assertEquals(2000., systematicSensitivityAnalysisResult.getReferenceIntensity(cnec, Side.LEFT), FLOW_TOLERANCE); - assertEquals(4000., systematicSensitivityAnalysisResult.getReferenceIntensity(cnec, Side.RIGHT), FLOW_TOLERANCE); + assertEquals(1400., systematicSensitivityAnalysisResult.getReferenceFlow(cnec, TwoSides.ONE), FLOW_TOLERANCE); + assertEquals(2800., systematicSensitivityAnalysisResult.getReferenceFlow(cnec, TwoSides.TWO), FLOW_TOLERANCE); + assertEquals(2000., systematicSensitivityAnalysisResult.getReferenceIntensity(cnec, TwoSides.ONE), FLOW_TOLERANCE); + assertEquals(4000., systematicSensitivityAnalysisResult.getReferenceIntensity(cnec, TwoSides.TWO), FLOW_TOLERANCE); } else { - assertEquals(0., systematicSensitivityAnalysisResult.getReferenceFlow(cnec, Side.LEFT), FLOW_TOLERANCE); - assertEquals(0., systematicSensitivityAnalysisResult.getReferenceFlow(cnec, Side.RIGHT), FLOW_TOLERANCE); - assertEquals(0., systematicSensitivityAnalysisResult.getReferenceIntensity(cnec, Side.LEFT), FLOW_TOLERANCE); - assertEquals(0., systematicSensitivityAnalysisResult.getReferenceIntensity(cnec, Side.RIGHT), FLOW_TOLERANCE); + assertEquals(0., systematicSensitivityAnalysisResult.getReferenceFlow(cnec, TwoSides.ONE), FLOW_TOLERANCE); + assertEquals(0., systematicSensitivityAnalysisResult.getReferenceFlow(cnec, TwoSides.TWO), FLOW_TOLERANCE); + assertEquals(0., systematicSensitivityAnalysisResult.getReferenceIntensity(cnec, TwoSides.ONE), FLOW_TOLERANCE); + assertEquals(0., systematicSensitivityAnalysisResult.getReferenceIntensity(cnec, TwoSides.TWO), FLOW_TOLERANCE); } } } @@ -124,10 +124,10 @@ private SystematicSensitivityResult buildSystematicAnalysisResultOk() { Mockito.when(result.isSuccess()).thenReturn(true); crac.getFlowCnecs().forEach(cnec -> { if (cnec.getId().equals("cnec2basecase")) { - Mockito.when(result.getReferenceFlow(cnec, Side.LEFT)).thenReturn(1400.); - Mockito.when(result.getReferenceFlow(cnec, Side.RIGHT)).thenReturn(2800.); - Mockito.when(result.getReferenceIntensity(cnec, Side.LEFT)).thenReturn(2000.); - Mockito.when(result.getReferenceIntensity(cnec, Side.RIGHT)).thenReturn(4000.); + Mockito.when(result.getReferenceFlow(cnec, TwoSides.ONE)).thenReturn(1400.); + Mockito.when(result.getReferenceFlow(cnec, TwoSides.TWO)).thenReturn(2800.); + Mockito.when(result.getReferenceIntensity(cnec, TwoSides.ONE)).thenReturn(2000.); + Mockito.when(result.getReferenceIntensity(cnec, TwoSides.TWO)).thenReturn(4000.); crac.getRangeActions().forEach(rangeAction -> Mockito.when(result.getSensitivityOnFlow(Mockito.eq(rangeAction), Mockito.eq(cnec), Mockito.any())).thenReturn(random.nextDouble())); } else { Mockito.when(result.getReferenceFlow(Mockito.eq(cnec), Mockito.any())).thenReturn(0.0); diff --git a/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/SystematicSensitivityResultTest.java b/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/SystematicSensitivityResultTest.java index 7169f6bddb..6efecfc5ce 100644 --- a/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/SystematicSensitivityResultTest.java +++ b/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/SystematicSensitivityResultTest.java @@ -8,7 +8,7 @@ import com.powsybl.contingency.ContingencyElementType; import com.powsybl.openrao.commons.Unit; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.CracFactory; import com.powsybl.openrao.data.cracapi.rangeaction.HvdcRangeAction; import com.powsybl.glsk.commons.ZonalData; @@ -58,7 +58,7 @@ class SystematicSensitivityResultTest { public void setUpWith12Nodes() { network = NetworkImportsUtil.import12NodesNetwork(); - Crac crac = CommonCracCreation.createWithPreventivePstRange(Set.of(Side.LEFT, Side.RIGHT)); + Crac crac = CommonCracCreation.createWithPreventivePstRange(Set.of(TwoSides.ONE, TwoSides.TWO)); outageInstantOrder = crac.getInstant(CURATIVE_INSTANT_ID).getOrder(); ZonalData glskProvider = UcteGlskDocument.importGlsk(getClass().getResourceAsStream("/glsk_proportional_12nodes.xml")) @@ -88,17 +88,17 @@ void testPostTreatIntensities() { SystematicSensitivityResult result = new SystematicSensitivityResult().completeData(sensitivityAnalysisResult, outageInstantOrder); // Before postTreating intensities - assertEquals(-20, result.getReferenceFlow(contingencyCnec, Side.LEFT), EPSILON); - assertEquals(200, result.getReferenceIntensity(contingencyCnec, Side.LEFT), EPSILON); - assertEquals(25, result.getReferenceFlow(contingencyCnec, Side.RIGHT), EPSILON); - assertEquals(205, result.getReferenceIntensity(contingencyCnec, Side.RIGHT), EPSILON); + assertEquals(-20, result.getReferenceFlow(contingencyCnec, TwoSides.ONE), EPSILON); + assertEquals(200, result.getReferenceIntensity(contingencyCnec, TwoSides.ONE), EPSILON); + assertEquals(25, result.getReferenceFlow(contingencyCnec, TwoSides.TWO), EPSILON); + assertEquals(205, result.getReferenceIntensity(contingencyCnec, TwoSides.TWO), EPSILON); // After postTreating intensities result.postTreatIntensities(); - assertEquals(-20, result.getReferenceFlow(contingencyCnec, Side.LEFT), EPSILON); - assertEquals(-200, result.getReferenceIntensity(contingencyCnec, Side.LEFT), EPSILON); - assertEquals(25, result.getReferenceFlow(contingencyCnec, Side.RIGHT), EPSILON); - assertEquals(205, result.getReferenceIntensity(contingencyCnec, Side.RIGHT), EPSILON); + assertEquals(-20, result.getReferenceFlow(contingencyCnec, TwoSides.ONE), EPSILON); + assertEquals(-200, result.getReferenceIntensity(contingencyCnec, TwoSides.ONE), EPSILON); + assertEquals(25, result.getReferenceFlow(contingencyCnec, TwoSides.TWO), EPSILON); + assertEquals(205, result.getReferenceIntensity(contingencyCnec, TwoSides.TWO), EPSILON); } @Test @@ -117,20 +117,20 @@ void testPstResultManipulation() { assertEquals(SystematicSensitivityResult.SensitivityComputationStatus.SUCCESS, result.getStatus()); // in basecase - assertEquals(10, result.getReferenceFlow(nStateCnec, Side.LEFT), EPSILON); - assertEquals(25, result.getReferenceIntensity(nStateCnec, Side.LEFT), EPSILON); - assertEquals(0.5, result.getSensitivityOnFlow(rangeAction, nStateCnec, Side.LEFT), EPSILON); - assertEquals(-15, result.getReferenceFlow(nStateCnec, Side.RIGHT), EPSILON); - assertEquals(-30, result.getReferenceIntensity(nStateCnec, Side.RIGHT), EPSILON); - assertEquals(-0.55, result.getSensitivityOnFlow(rangeAction, nStateCnec, Side.RIGHT), EPSILON); + assertEquals(10, result.getReferenceFlow(nStateCnec, TwoSides.ONE), EPSILON); + assertEquals(25, result.getReferenceIntensity(nStateCnec, TwoSides.ONE), EPSILON); + assertEquals(0.5, result.getSensitivityOnFlow(rangeAction, nStateCnec, TwoSides.ONE), EPSILON); + assertEquals(-15, result.getReferenceFlow(nStateCnec, TwoSides.TWO), EPSILON); + assertEquals(-30, result.getReferenceIntensity(nStateCnec, TwoSides.TWO), EPSILON); + assertEquals(-0.55, result.getSensitivityOnFlow(rangeAction, nStateCnec, TwoSides.TWO), EPSILON); // after contingency - assertEquals(-20, result.getReferenceFlow(contingencyCnec, Side.LEFT), EPSILON); - assertEquals(-200, result.getReferenceIntensity(contingencyCnec, Side.LEFT), EPSILON); - assertEquals(-5, result.getSensitivityOnFlow(rangeAction, contingencyCnec, Side.LEFT), EPSILON); - assertEquals(25, result.getReferenceFlow(contingencyCnec, Side.RIGHT), EPSILON); - assertEquals(205, result.getReferenceIntensity(contingencyCnec, Side.RIGHT), EPSILON); - assertEquals(5.5, result.getSensitivityOnFlow(rangeAction, contingencyCnec, Side.RIGHT), EPSILON); + assertEquals(-20, result.getReferenceFlow(contingencyCnec, TwoSides.ONE), EPSILON); + assertEquals(-200, result.getReferenceIntensity(contingencyCnec, TwoSides.ONE), EPSILON); + assertEquals(-5, result.getSensitivityOnFlow(rangeAction, contingencyCnec, TwoSides.ONE), EPSILON); + assertEquals(25, result.getReferenceFlow(contingencyCnec, TwoSides.TWO), EPSILON); + assertEquals(205, result.getReferenceIntensity(contingencyCnec, TwoSides.TWO), EPSILON); + assertEquals(5.5, result.getSensitivityOnFlow(rangeAction, contingencyCnec, TwoSides.TWO), EPSILON); } @Test @@ -148,16 +148,16 @@ void testPtdfResultManipulation() { assertTrue(result.isSuccess()); // in basecase - assertEquals(10, result.getReferenceFlow(nStateCnec, Side.LEFT), EPSILON); - assertEquals(0.140, result.getSensitivityOnFlow(linearGlsk, nStateCnec, Side.LEFT), EPSILON); - assertEquals(-15, result.getReferenceFlow(nStateCnec, Side.RIGHT), EPSILON); - assertEquals(-0.19, result.getSensitivityOnFlow(linearGlsk, nStateCnec, Side.RIGHT), EPSILON); + assertEquals(10, result.getReferenceFlow(nStateCnec, TwoSides.ONE), EPSILON); + assertEquals(0.140, result.getSensitivityOnFlow(linearGlsk, nStateCnec, TwoSides.ONE), EPSILON); + assertEquals(-15, result.getReferenceFlow(nStateCnec, TwoSides.TWO), EPSILON); + assertEquals(-0.19, result.getSensitivityOnFlow(linearGlsk, nStateCnec, TwoSides.TWO), EPSILON); // after contingency - assertEquals(-20, result.getReferenceFlow(contingencyCnec, Side.LEFT), EPSILON); - assertEquals(6, result.getSensitivityOnFlow(linearGlsk, contingencyCnec, Side.LEFT), EPSILON); - assertEquals(25, result.getReferenceFlow(contingencyCnec, Side.RIGHT), EPSILON); - assertEquals(-6.5, result.getSensitivityOnFlow(linearGlsk, contingencyCnec, Side.RIGHT), EPSILON); + assertEquals(-20, result.getReferenceFlow(contingencyCnec, TwoSides.ONE), EPSILON); + assertEquals(6, result.getSensitivityOnFlow(linearGlsk, contingencyCnec, TwoSides.ONE), EPSILON); + assertEquals(25, result.getReferenceFlow(contingencyCnec, TwoSides.TWO), EPSILON); + assertEquals(-6.5, result.getSensitivityOnFlow(linearGlsk, contingencyCnec, TwoSides.TWO), EPSILON); } @Test @@ -186,14 +186,14 @@ private void setUpForHvdc() { .withId("cnec-prev") .withNetworkElement("BBE1AA11 FFR5AA11 1") .withInstant(PREVENTIVE_INSTANT_ID) - .newThreshold().withMax(1000.).withUnit(Unit.MEGAWATT).withSide(Side.LEFT).add() + .newThreshold().withMax(1000.).withUnit(Unit.MEGAWATT).withSide(TwoSides.ONE).add() .add(); contingencyCnec = crac.newFlowCnec() .withId("cnec-cur") .withNetworkElement("BBE1AA11 FFR5AA11 1") .withContingency("co") .withInstant(OUTAGE_INSTANT_ID) - .newThreshold().withMax(1000.).withUnit(Unit.MEGAWATT).withSide(Side.RIGHT).add() + .newThreshold().withMax(1000.).withUnit(Unit.MEGAWATT).withSide(TwoSides.TWO).add() .add(); hvdcRangeAction = crac.newHvdcRangeAction() .withId("hvdc-ra") @@ -220,13 +220,13 @@ void testPostTreatHvdcNoEffect() { .postTreatIntensities() .postTreatHvdcs(network, hvdcs); - assertEquals(30., result.getReferenceFlow(nStateCnec, Side.LEFT), EPSILON); - assertEquals(40., result.getReferenceIntensity(nStateCnec, Side.LEFT), EPSILON); - assertEquals(0.34, result.getSensitivityOnFlow(hvdcRangeAction, nStateCnec, Side.LEFT), EPSILON); + assertEquals(30., result.getReferenceFlow(nStateCnec, TwoSides.ONE), EPSILON); + assertEquals(40., result.getReferenceIntensity(nStateCnec, TwoSides.ONE), EPSILON); + assertEquals(0.34, result.getSensitivityOnFlow(hvdcRangeAction, nStateCnec, TwoSides.ONE), EPSILON); - assertEquals(26., result.getReferenceFlow(contingencyCnec, Side.RIGHT), EPSILON); - assertEquals(-31., result.getReferenceIntensity(contingencyCnec, Side.RIGHT), EPSILON); - assertEquals(-7.5, result.getSensitivityOnFlow(hvdcRangeAction, contingencyCnec, Side.RIGHT), EPSILON); + assertEquals(26., result.getReferenceFlow(contingencyCnec, TwoSides.TWO), EPSILON); + assertEquals(-31., result.getReferenceIntensity(contingencyCnec, TwoSides.TWO), EPSILON); + assertEquals(-7.5, result.getSensitivityOnFlow(hvdcRangeAction, contingencyCnec, TwoSides.TWO), EPSILON); } @Test @@ -244,13 +244,13 @@ void testPostTreatHvdcInvert() { .postTreatIntensities() .postTreatHvdcs(network, hvdcs); - assertEquals(30., result.getReferenceFlow(nStateCnec, Side.LEFT), EPSILON); - assertEquals(40., result.getReferenceIntensity(nStateCnec, Side.LEFT), EPSILON); - assertEquals(-0.34, result.getSensitivityOnFlow(hvdcRangeAction, nStateCnec, Side.LEFT), EPSILON); + assertEquals(30., result.getReferenceFlow(nStateCnec, TwoSides.ONE), EPSILON); + assertEquals(40., result.getReferenceIntensity(nStateCnec, TwoSides.ONE), EPSILON); + assertEquals(-0.34, result.getSensitivityOnFlow(hvdcRangeAction, nStateCnec, TwoSides.ONE), EPSILON); - assertEquals(26., result.getReferenceFlow(contingencyCnec, Side.RIGHT), EPSILON); - assertEquals(-31., result.getReferenceIntensity(contingencyCnec, Side.RIGHT), EPSILON); - assertEquals(7.5, result.getSensitivityOnFlow(hvdcRangeAction, contingencyCnec, Side.RIGHT), EPSILON); + assertEquals(26., result.getReferenceFlow(contingencyCnec, TwoSides.TWO), EPSILON); + assertEquals(-31., result.getReferenceIntensity(contingencyCnec, TwoSides.TWO), EPSILON); + assertEquals(7.5, result.getSensitivityOnFlow(hvdcRangeAction, contingencyCnec, TwoSides.TWO), EPSILON); } } diff --git a/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/rasensihandler/HvdcRangeActionSensiHandlerTest.java b/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/rasensihandler/HvdcRangeActionSensiHandlerTest.java index 221c75b5f0..59447f0120 100644 --- a/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/rasensihandler/HvdcRangeActionSensiHandlerTest.java +++ b/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/rasensihandler/HvdcRangeActionSensiHandlerTest.java @@ -11,7 +11,7 @@ import com.powsybl.openrao.data.cracapi.CracFactory; import com.powsybl.openrao.data.cracapi.InstantKind; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.HvdcRangeAction; import com.powsybl.openrao.data.cracapi.usagerule.UsageMethod; import com.powsybl.openrao.data.cracimpl.utils.CommonCracCreation; @@ -58,11 +58,11 @@ void getSensitivityOnFlowTest() { HvdcRangeActionSensiHandler sensiHandler = new HvdcRangeActionSensiHandler(hvdcRangeAction); SystematicSensitivityResult sensiResult = Mockito.mock(SystematicSensitivityResult.class); - Mockito.when(sensiResult.getSensitivityOnFlow("BBE2AA11 FFR3AA11 1", flowCnec, Side.LEFT)).thenReturn(-12.56); - Mockito.when(sensiResult.getSensitivityOnFlow("BBE2AA11 FFR3AA11 1", flowCnec, Side.RIGHT)).thenReturn(-10.56); + Mockito.when(sensiResult.getSensitivityOnFlow("BBE2AA11 FFR3AA11 1", flowCnec, TwoSides.ONE)).thenReturn(-12.56); + Mockito.when(sensiResult.getSensitivityOnFlow("BBE2AA11 FFR3AA11 1", flowCnec, TwoSides.TWO)).thenReturn(-10.56); - assertEquals(-12.56, sensiHandler.getSensitivityOnFlow(flowCnec, Side.LEFT, sensiResult), 1e-3); - assertEquals(-10.56, sensiHandler.getSensitivityOnFlow(flowCnec, Side.RIGHT, sensiResult), 1e-3); + assertEquals(-12.56, sensiHandler.getSensitivityOnFlow(flowCnec, TwoSides.ONE, sensiResult), 1e-3); + assertEquals(-10.56, sensiHandler.getSensitivityOnFlow(flowCnec, TwoSides.TWO, sensiResult), 1e-3); } @Test diff --git a/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/rasensihandler/InjectionRangeActionSensiHandlerTest.java b/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/rasensihandler/InjectionRangeActionSensiHandlerTest.java index c48de81f37..4f4a683027 100644 --- a/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/rasensihandler/InjectionRangeActionSensiHandlerTest.java +++ b/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/rasensihandler/InjectionRangeActionSensiHandlerTest.java @@ -11,7 +11,7 @@ import com.powsybl.openrao.data.cracapi.CracFactory; import com.powsybl.openrao.data.cracapi.InstantKind; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.InjectionRangeAction; import com.powsybl.openrao.data.cracapi.usagerule.UsageMethod; import com.powsybl.openrao.data.cracimpl.utils.CommonCracCreation; @@ -61,11 +61,11 @@ void getSensitivityOnFlowSimpleTest() { InjectionRangeActionSensiHandler sensiHandler = new InjectionRangeActionSensiHandler(injectionRangeAction); SystematicSensitivityResult sensiResult = Mockito.mock(SystematicSensitivityResult.class); - Mockito.when(sensiResult.getSensitivityOnFlow("injectionRangeId-positiveInjections", flowCnec, Side.LEFT)).thenReturn(-1.56); - Mockito.when(sensiResult.getSensitivityOnFlow("injectionRangeId-positiveInjections", flowCnec, Side.RIGHT)).thenReturn(-0.56); + Mockito.when(sensiResult.getSensitivityOnFlow("injectionRangeId-positiveInjections", flowCnec, TwoSides.ONE)).thenReturn(-1.56); + Mockito.when(sensiResult.getSensitivityOnFlow("injectionRangeId-positiveInjections", flowCnec, TwoSides.TWO)).thenReturn(-0.56); - assertEquals(-1.56, sensiHandler.getSensitivityOnFlow(flowCnec, Side.LEFT, sensiResult), 1e-3); - assertEquals(-0.56, sensiHandler.getSensitivityOnFlow(flowCnec, Side.RIGHT, sensiResult), 1e-3); + assertEquals(-1.56, sensiHandler.getSensitivityOnFlow(flowCnec, TwoSides.ONE, sensiResult), 1e-3); + assertEquals(-0.56, sensiHandler.getSensitivityOnFlow(flowCnec, TwoSides.TWO, sensiResult), 1e-3); } @Test @@ -84,13 +84,13 @@ void getSensitivityOnFlowComplexTest() { InjectionRangeActionSensiHandler sensiHandler = new InjectionRangeActionSensiHandler(injectionRangeAction); SystematicSensitivityResult sensiResult = Mockito.mock(SystematicSensitivityResult.class); - Mockito.when(sensiResult.getSensitivityOnFlow("injectionRangeId-positiveInjections", flowCnec, Side.LEFT)).thenReturn(4.); - Mockito.when(sensiResult.getSensitivityOnFlow("injectionRangeId-negativeInjections", flowCnec, Side.LEFT)).thenReturn(7.); - Mockito.when(sensiResult.getSensitivityOnFlow("injectionRangeId-positiveInjections", flowCnec, Side.RIGHT)).thenReturn(10.); - Mockito.when(sensiResult.getSensitivityOnFlow("injectionRangeId-negativeInjections", flowCnec, Side.RIGHT)).thenReturn(30.); + Mockito.when(sensiResult.getSensitivityOnFlow("injectionRangeId-positiveInjections", flowCnec, TwoSides.ONE)).thenReturn(4.); + Mockito.when(sensiResult.getSensitivityOnFlow("injectionRangeId-negativeInjections", flowCnec, TwoSides.ONE)).thenReturn(7.); + Mockito.when(sensiResult.getSensitivityOnFlow("injectionRangeId-positiveInjections", flowCnec, TwoSides.TWO)).thenReturn(10.); + Mockito.when(sensiResult.getSensitivityOnFlow("injectionRangeId-negativeInjections", flowCnec, TwoSides.TWO)).thenReturn(30.); - assertEquals(4 * 0.8 - 7 * 0.5, sensiHandler.getSensitivityOnFlow(flowCnec, Side.LEFT, sensiResult), 1e-3); - assertEquals(10 * 0.8 - 30 * 0.5, sensiHandler.getSensitivityOnFlow(flowCnec, Side.RIGHT, sensiResult), 1e-3); + assertEquals(4 * 0.8 - 7 * 0.5, sensiHandler.getSensitivityOnFlow(flowCnec, TwoSides.ONE, sensiResult), 1e-3); + assertEquals(10 * 0.8 - 30 * 0.5, sensiHandler.getSensitivityOnFlow(flowCnec, TwoSides.TWO, sensiResult), 1e-3); } @Test diff --git a/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/rasensihandler/PstRangeActionSensiHandlerTest.java b/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/rasensihandler/PstRangeActionSensiHandlerTest.java index c1eec19f63..b778f9f387 100644 --- a/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/rasensihandler/PstRangeActionSensiHandlerTest.java +++ b/sensitivity-analysis/src/test/java/com/powsybl/openrao/sensitivityanalysis/rasensihandler/PstRangeActionSensiHandlerTest.java @@ -9,7 +9,7 @@ import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.range.RangeType; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.usagerule.UsageMethod; @@ -44,11 +44,11 @@ void getSensitivityOnFlowTest() { PstRangeActionSensiHandler sensiHandler = new PstRangeActionSensiHandler(crac.getPstRangeAction("pst")); SystematicSensitivityResult sensiResult = Mockito.mock(SystematicSensitivityResult.class); - Mockito.when(sensiResult.getSensitivityOnFlow("BBE2AA1 BBE3AA1 1", flowCnec, Side.LEFT)).thenReturn(14.32); - Mockito.when(sensiResult.getSensitivityOnFlow("BBE2AA1 BBE3AA1 1", flowCnec, Side.RIGHT)).thenReturn(104.32); + Mockito.when(sensiResult.getSensitivityOnFlow("BBE2AA1 BBE3AA1 1", flowCnec, TwoSides.ONE)).thenReturn(14.32); + Mockito.when(sensiResult.getSensitivityOnFlow("BBE2AA1 BBE3AA1 1", flowCnec, TwoSides.TWO)).thenReturn(104.32); - assertEquals(14.32, sensiHandler.getSensitivityOnFlow(flowCnec, Side.LEFT, sensiResult), 1e-3); - assertEquals(104.32, sensiHandler.getSensitivityOnFlow(flowCnec, Side.RIGHT, sensiResult), 1e-3); + assertEquals(14.32, sensiHandler.getSensitivityOnFlow(flowCnec, TwoSides.ONE, sensiResult), 1e-3); + assertEquals(104.32, sensiHandler.getSensitivityOnFlow(flowCnec, TwoSides.TWO, sensiResult), 1e-3); } @Test diff --git a/tests/src/test/java/com/powsybl/openrao/tests/steps/CracImportSteps.java b/tests/src/test/java/com/powsybl/openrao/tests/steps/CracImportSteps.java index 1996476e3e..a782982911 100644 --- a/tests/src/test/java/com/powsybl/openrao/tests/steps/CracImportSteps.java +++ b/tests/src/test/java/com/powsybl/openrao/tests/steps/CracImportSteps.java @@ -8,6 +8,7 @@ import com.powsybl.contingency.Contingency; import com.powsybl.iidm.network.Country; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.*; @@ -224,24 +225,24 @@ public void itShouldHaveTheFollowingCNECs(DataTable arg1) throws Exception { .orElseThrow(Exception::new); if (expectedCnec.get("ImaxLeft") != null) { - assertEquals(Double.parseDouble(expectedCnec.get("ImaxLeft")), flowCnec.getIMax(Side.LEFT), DOUBLE_TOLERANCE); + assertEquals(Double.parseDouble(expectedCnec.get("ImaxLeft")), flowCnec.getIMax(TwoSides.ONE), DOUBLE_TOLERANCE); } else { - assertNull(flowCnec.getIMax(Side.LEFT)); + assertNull(flowCnec.getIMax(TwoSides.ONE)); } if (expectedCnec.get("ImaxRight") != null) { - assertEquals(Double.parseDouble(expectedCnec.get("ImaxRight")), flowCnec.getIMax(Side.RIGHT), DOUBLE_TOLERANCE); + assertEquals(Double.parseDouble(expectedCnec.get("ImaxRight")), flowCnec.getIMax(TwoSides.TWO), DOUBLE_TOLERANCE); } else { - assertNull(flowCnec.getIMax(Side.RIGHT)); + assertNull(flowCnec.getIMax(TwoSides.TWO)); } if (expectedCnec.get("NominalVoltageLeft") != null) { - assertEquals(Double.parseDouble(expectedCnec.get("NominalVoltageLeft")), flowCnec.getNominalVoltage(Side.LEFT), DOUBLE_TOLERANCE); + assertEquals(Double.parseDouble(expectedCnec.get("NominalVoltageLeft")), flowCnec.getNominalVoltage(TwoSides.ONE), DOUBLE_TOLERANCE); } else { - assertNull(flowCnec.getNominalVoltage(Side.LEFT)); + assertNull(flowCnec.getNominalVoltage(TwoSides.ONE)); } if (expectedCnec.get("NominalVoltageRight") != null) { - assertEquals(Double.parseDouble(expectedCnec.get("NominalVoltageRight")), flowCnec.getNominalVoltage(Side.RIGHT), DOUBLE_TOLERANCE); + assertEquals(Double.parseDouble(expectedCnec.get("NominalVoltageRight")), flowCnec.getNominalVoltage(TwoSides.TWO), DOUBLE_TOLERANCE); } else { - assertNull(flowCnec.getNominalVoltage(Side.RIGHT)); + assertNull(flowCnec.getNominalVoltage(TwoSides.TWO)); } } } @@ -253,14 +254,14 @@ public void theFlowCnecsShouldHaveTheFollowingThresholds(DataTable arg1) { BranchCnec branchCnec = crac.getFlowCnec(expectedThreshold.get("CnecId")); assertNotNull(branchCnec); Unit expectedUnit = Unit.valueOf(expectedThreshold.get("Unit")); - Side side = Side.valueOf(expectedThreshold.get("Side")); + TwoSides side = TwoSides.valueOf(expectedThreshold.get("Side")); Optional min = Optional.ofNullable(expectedThreshold.get("Min").equals("None") ? null : Double.parseDouble(expectedThreshold.get("Min"))); Optional max = Optional.ofNullable(expectedThreshold.get("Max").equals("None") ? null : Double.parseDouble(expectedThreshold.get("Max"))); assertTrue(branchCnec.getThresholds().stream().anyMatch(threshold -> matchThreshold(threshold, expectedUnit, side, min, max))); } } - private boolean matchThreshold(BranchThreshold threshold, Unit unit, Side side, Optional min, Optional max) { + private boolean matchThreshold(BranchThreshold threshold, Unit unit, TwoSides side, Optional min, Optional max) { if (!unit.equals(threshold.getUnit())) { return false; } diff --git a/tests/src/test/java/com/powsybl/openrao/tests/steps/SearchTreeRaoSteps.java b/tests/src/test/java/com/powsybl/openrao/tests/steps/SearchTreeRaoSteps.java index 2426713350..a7c4cc237a 100644 --- a/tests/src/test/java/com/powsybl/openrao/tests/steps/SearchTreeRaoSteps.java +++ b/tests/src/test/java/com/powsybl/openrao/tests/steps/SearchTreeRaoSteps.java @@ -17,7 +17,7 @@ import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.Cnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.openrao.data.cracapi.cnec.Side; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; @@ -449,25 +449,25 @@ public void worstRelativeMarginAndCnecInMW(double expectedMargin, String expecte // TODO : add steps to check flows on both sides @Then("the initial flow on cnec {string} should be {double} A") public void initialFlowInA(String cnecId, Double expectedFlow) { - Side side = crac.getFlowCnec(cnecId).getMonitoredSides().iterator().next(); + TwoSides side = crac.getFlowCnec(cnecId).getMonitoredSides().iterator().next(); assertEquals(expectedFlow, raoResult.getFlow(null, crac.getFlowCnec(cnecId), side, Unit.AMPERE), flowAmpereTolerance(expectedFlow)); } @Then("the flow on cnec {string} after PRA should be {double} A") public void afterPraFlowInA(String cnecId, Double expectedFlow) { - Side side = crac.getFlowCnec(cnecId).getMonitoredSides().iterator().next(); + TwoSides side = crac.getFlowCnec(cnecId).getMonitoredSides().iterator().next(); assertEquals(expectedFlow, raoResult.getFlow(crac.getPreventiveInstant(), crac.getFlowCnec(cnecId), side, Unit.AMPERE), flowAmpereTolerance(expectedFlow)); } @Then("the flow on cnec {string} after ARA should be {double} A") public void afterAraFlowInA(String cnecId, Double expectedFlow) { - Side side = crac.getFlowCnec(cnecId).getMonitoredSides().iterator().next(); + TwoSides side = crac.getFlowCnec(cnecId).getMonitoredSides().iterator().next(); assertEquals(expectedFlow, raoResult.getFlow(crac.getInstant(InstantKind.AUTO), crac.getFlowCnec(cnecId), side, Unit.AMPERE), flowAmpereTolerance(expectedFlow)); } @Then("the flow on cnec {string} after CRA should be {double} A") public void afterCraFlowInA(String cnecId, Double expectedFlow) { - Side side = crac.getFlowCnec(cnecId).getMonitoredSides().iterator().next(); + TwoSides side = crac.getFlowCnec(cnecId).getMonitoredSides().iterator().next(); assertEquals(expectedFlow, raoResult.getFlow(crac.getInstant(InstantKind.CURATIVE), crac.getFlowCnec(cnecId), side, Unit.AMPERE), flowAmpereTolerance(expectedFlow)); } @@ -477,32 +477,32 @@ public void afterCraFlowInA(String cnecId, Double expectedFlow) { @Then("the initial flow on cnec {string} should be {double} MW") public void initialFlowInMW(String cnecId, Double expectedFlow) { - Side side = crac.getFlowCnec(cnecId).getMonitoredSides().iterator().next(); + TwoSides side = crac.getFlowCnec(cnecId).getMonitoredSides().iterator().next(); assertEquals(expectedFlow, raoResult.getFlow(null, crac.getFlowCnec(cnecId), side, Unit.MEGAWATT), flowMegawattTolerance(expectedFlow)); } @Then("the flow on cnec {string} after PRA should be {double} MW") public void afterPraFlowInMW(String cnecId, Double expectedFlow) { - Side side = crac.getFlowCnec(cnecId).getMonitoredSides().iterator().next(); + TwoSides side = crac.getFlowCnec(cnecId).getMonitoredSides().iterator().next(); assertEquals(expectedFlow, raoResult.getFlow(crac.getPreventiveInstant(), crac.getFlowCnec(cnecId), side, Unit.MEGAWATT), flowMegawattTolerance(expectedFlow)); } @Then("the flow on cnec {string} after ARA should be {double} MW") public void afterAraFlowInMW(String cnecId, Double expectedFlow) { - Side side = crac.getFlowCnec(cnecId).getMonitoredSides().iterator().next(); + TwoSides side = crac.getFlowCnec(cnecId).getMonitoredSides().iterator().next(); assertEquals(expectedFlow, raoResult.getFlow(crac.getInstant(InstantKind.AUTO), crac.getFlowCnec(cnecId), side, Unit.MEGAWATT), flowMegawattTolerance(expectedFlow)); } @Then("the flow on cnec {string} after CRA should be {double} MW") public void afterCraFlowInMW(String cnecId, Double expectedFlow) { - Side side = crac.getFlowCnec(cnecId).getMonitoredSides().iterator().next(); + TwoSides side = crac.getFlowCnec(cnecId).getMonitoredSides().iterator().next(); Instant lastCurativeInstant = crac.getInstants(InstantKind.CURATIVE).stream().sorted(Comparator.comparingInt(instant -> -instant.getOrder())).toList().get(0); assertEquals(expectedFlow, raoResult.getFlow(lastCurativeInstant, crac.getFlowCnec(cnecId), side, Unit.MEGAWATT), flowMegawattTolerance(expectedFlow)); } @Then("the flow on cnec {string} after {string} instant remedial actions should be {double} MW") public void afterInstantFlowInMW(String cnecId, String instantId, Double expectedFlow) { - Side side = crac.getFlowCnec(cnecId).getMonitoredSides().iterator().next(); + TwoSides side = crac.getFlowCnec(cnecId).getMonitoredSides().iterator().next(); Instant instant = crac.getInstant(instantId); assertEquals(expectedFlow, raoResult.getFlow(instant, crac.getFlowCnec(cnecId), side, Unit.MEGAWATT), flowMegawattTolerance(expectedFlow)); } @@ -516,7 +516,7 @@ private void testThreshold(String upperOrLower, String cnecId, Double expectedBo if (cnec.getMonitoredSides().size() != 1) { throw new OpenRaoException("Cannot chose side"); } - Side side = cnec.getMonitoredSides().iterator().next(); + TwoSides side = cnec.getMonitoredSides().iterator().next(); Double bound = null; if (upperOrLower.equalsIgnoreCase("upper")) { bound = crac.getFlowCnec(cnecId).getUpperBound(side, unit).orElseThrow(); diff --git a/tests/src/test/resources/com/powsybl/openrao/tests/features/epic15_specific_network_elements/US15_3.feature b/tests/src/test/resources/com/powsybl/openrao/tests/features/epic15_specific_network_elements/US15_3.feature index 8eb18f824d..e8ac3b8156 100644 --- a/tests/src/test/resources/com/powsybl/openrao/tests/features/epic15_specific_network_elements/US15_3.feature +++ b/tests/src/test/resources/com/powsybl/openrao/tests/features/epic15_specific_network_elements/US15_3.feature @@ -26,7 +26,7 @@ Feature: US 15.3: Handle transformers And the margin on cnec "FFR1AA2 FFR1AA1 5 - co_fr - outage" after PRA should be 543 MW @fast @rao @mock @ac @preventive-only - Scenario: US 15.3.2: Handle transformers on a small test case in AC - On LEFT side + Scenario: US 15.3.2: Handle transformers on a small test case in AC - On side 1 Given network file is "epic15/TestCase12Nodes_with_2_voltage_levels_2.uct" Given crac file is "epic15/SL_ep15us3case2.json" Given configuration file is "common/RaoParameters_maxMargin_ampere.json" @@ -54,7 +54,7 @@ Feature: US 15.3: Handle transformers And the "upper" threshold on cnec "FFR1AA2 FFR1AA1 5 - co_fr - outage" should be 970 A @fast @rao @mock @ac @preventive-only - Scenario: US 15.3.2: Handle transformers on a small test case in AC - On RIGHT side + Scenario: US 15.3.2: Handle transformers on a small test case in AC - On side 2 Given network file is "epic15/TestCase12Nodes_with_2_voltage_levels_2.uct" Given crac file is "epic15/SL_ep15us3case2_RIGHT.json" Given configuration file is "common/RaoParameters_maxMargin_ampere.json" diff --git a/tests/src/test/resources/com/powsybl/openrao/tests/features/epic15_specific_network_elements/US15_4.feature b/tests/src/test/resources/com/powsybl/openrao/tests/features/epic15_specific_network_elements/US15_4.feature index a05f7aea08..021377bf04 100644 --- a/tests/src/test/resources/com/powsybl/openrao/tests/features/epic15_specific_network_elements/US15_4.feature +++ b/tests/src/test/resources/com/powsybl/openrao/tests/features/epic15_specific_network_elements/US15_4.feature @@ -16,10 +16,10 @@ Feature: US 15.4: Consider two margins on tie-lines for each half-line with rela | Cnec BE-FR Left | BBE2AA1 X_BEFR1 1 + FFR3AA1 X_BEFR1 1 | outage | N-1 DE-NL | yes | no | 5000.0 | 5000.0 | 400.0 | 400.0 | And the flow cnecs should have the following thresholds: | CnecId | Unit | Min | Max | Side | - | BBE2AA1 X_BEFR1 1 + FFR3AA1 X_BEFR1 1 - preventive | AMPERE | -1500 | 1500 | LEFT | - | BBE2AA1 X_BEFR1 1 + FFR3AA1 X_BEFR1 1 - preventive | AMPERE | -500 | 500 | RIGHT | - | BBE2AA1 X_BEFR1 1 + FFR3AA1 X_BEFR1 1 - N-1 DE-NL - outage | AMPERE | -1500 | 1500 | LEFT | - | BBE2AA1 X_BEFR1 1 + FFR3AA1 X_BEFR1 1 - N-1 DE-NL - outage | AMPERE | -500 | 500 | RIGHT | + | BBE2AA1 X_BEFR1 1 + FFR3AA1 X_BEFR1 1 - preventive | AMPERE | -1500 | 1500 | ONE | + | BBE2AA1 X_BEFR1 1 + FFR3AA1 X_BEFR1 1 - preventive | AMPERE | -500 | 500 | TWO | + | BBE2AA1 X_BEFR1 1 + FFR3AA1 X_BEFR1 1 - N-1 DE-NL - outage | AMPERE | -1500 | 1500 | ONE | + | BBE2AA1 X_BEFR1 1 + FFR3AA1 X_BEFR1 1 - N-1 DE-NL - outage | AMPERE | -500 | 500 | TWO | And it should have the following PST range actions: | PstRangeActionId | PstRangeActionName | NetworkElementId | InitialTap | MinTap | MaxTap | MinTapAngle | MaxTapAngle | | PST_BE | PST_BE | BBE2AA1 BBE3AA1 1 | 0 | -16 | 16 | -6.23 | 6.23 | diff --git a/tests/src/test/resources/com/powsybl/openrao/tests/features/epic1_PRA_network_actions/US1_2.feature b/tests/src/test/resources/com/powsybl/openrao/tests/features/epic1_PRA_network_actions/US1_2.feature index b6417f8682..043fc3e8a3 100644 --- a/tests/src/test/resources/com/powsybl/openrao/tests/features/epic1_PRA_network_actions/US1_2.feature +++ b/tests/src/test/resources/com/powsybl/openrao/tests/features/epic1_PRA_network_actions/US1_2.feature @@ -20,12 +20,12 @@ Feature: US 1.2: Import of simple network actions as preventive remedial action | Tie-line FR DE | FFR2AA1 DDE3AA1 1 | outage | Contingency FR1 FR3 | yes | no | 5000.0 | 5000.0 | 400.0 | 400.0 | Then the flow cnecs should have the following thresholds: | CnecId | Unit | Min | Max | Side | - | BBE2AA1 FFR3AA1 1 - preventive | AMPERE | -1500 | 1500 | RIGHT | - | BBE2AA1 FFR3AA1 1 - Contingency FR1 FR3 - outage | AMPERE | -1500 | 1500 | RIGHT | - | BBE2AA1 FFR3AA1 1 - Contingency FR1 FR3 - curative | AMPERE | -1500 | 1500 | RIGHT | - | FFR2AA1 DDE3AA1 1 - preventive | AMPERE | -1500 | 1500 | RIGHT | - | FFR2AA1 DDE3AA1 1 - Contingency FR1 FR3 - outage | AMPERE | -1500 | 1500 | RIGHT | - | FFR2AA1 DDE3AA1 1 - Contingency FR1 FR3 - curative | AMPERE | -1500 | 1500 | RIGHT | + | BBE2AA1 FFR3AA1 1 - preventive | AMPERE | -1500 | 1500 | TWO | + | BBE2AA1 FFR3AA1 1 - Contingency FR1 FR3 - outage | AMPERE | -1500 | 1500 | TWO | + | BBE2AA1 FFR3AA1 1 - Contingency FR1 FR3 - curative | AMPERE | -1500 | 1500 | TWO | + | FFR2AA1 DDE3AA1 1 - preventive | AMPERE | -1500 | 1500 | TWO | + | FFR2AA1 DDE3AA1 1 - Contingency FR1 FR3 - outage | AMPERE | -1500 | 1500 | TWO | + | FFR2AA1 DDE3AA1 1 - Contingency FR1 FR3 - curative | AMPERE | -1500 | 1500 | TWO | Then it should have the following network actions: | NetworkActionId | NetworkActionName | ElementaryActions | ElementaryActionType | NetworkElementId | Action/Setpoint | | Open tie-line FR DE | Open tie-line FR DE | 1 | TopologicalAction | FFR2AA1 DDE3AA1 1 | OPEN | diff --git a/tests/src/test/resources/com/powsybl/openrao/tests/features/epic3_cnec_direction/US3_1.feature b/tests/src/test/resources/com/powsybl/openrao/tests/features/epic3_cnec_direction/US3_1.feature index 5bda699015..46f228ea12 100644 --- a/tests/src/test/resources/com/powsybl/openrao/tests/features/epic3_cnec_direction/US3_1.feature +++ b/tests/src/test/resources/com/powsybl/openrao/tests/features/epic3_cnec_direction/US3_1.feature @@ -20,12 +20,12 @@ Feature: US 3.1: Import of a cnec monitored in a single direction | Tie-line FR DE | FFR2AA1 DDE3AA1 1 | outage | Contingency FR1 FR3 | yes | no | 5000.0 | 5000.0 | 400.0 | 400.0 | Then the flow cnecs should have the following thresholds: | CnecId | Unit | Min | Max | Side | - | BBE2AA1 FFR3AA1 1 - preventive | AMPERE | None | 1500 | RIGHT | - | BBE2AA1 FFR3AA1 1 - preventive | AMPERE | -500 | None | RIGHT | - | BBE2AA1 FFR3AA1 1 - Contingency FR1 FR3 - outage | AMPERE | None | 1500 | RIGHT | - | BBE2AA1 FFR3AA1 1 - Contingency FR1 FR3 - outage | AMPERE | -500 | None | RIGHT | - | BBE2AA1 FFR3AA1 1 - Contingency FR1 FR3 - curative | AMPERE | None | 1500 | RIGHT | - | BBE2AA1 FFR3AA1 1 - Contingency FR1 FR3 - curative | AMPERE | -500 | None | RIGHT | - | FFR2AA1 DDE3AA1 1 - preventive | AMPERE | -1500 | 1500 | RIGHT | - | FFR2AA1 DDE3AA1 1 - Contingency FR1 FR3 - outage | AMPERE | -1500 | 1500 | RIGHT | - | FFR2AA1 DDE3AA1 1 - Contingency FR1 FR3 - curative | AMPERE | -1500 | 1500 | RIGHT | \ No newline at end of file + | BBE2AA1 FFR3AA1 1 - preventive | AMPERE | None | 1500 | TWO | + | BBE2AA1 FFR3AA1 1 - preventive | AMPERE | -500 | None | TWO | + | BBE2AA1 FFR3AA1 1 - Contingency FR1 FR3 - outage | AMPERE | None | 1500 | TWO | + | BBE2AA1 FFR3AA1 1 - Contingency FR1 FR3 - outage | AMPERE | -500 | None | TWO | + | BBE2AA1 FFR3AA1 1 - Contingency FR1 FR3 - curative | AMPERE | None | 1500 | TWO | + | BBE2AA1 FFR3AA1 1 - Contingency FR1 FR3 - curative | AMPERE | -500 | None | TWO | + | FFR2AA1 DDE3AA1 1 - preventive | AMPERE | -1500 | 1500 | TWO | + | FFR2AA1 DDE3AA1 1 - Contingency FR1 FR3 - outage | AMPERE | -1500 | 1500 | TWO | + | FFR2AA1 DDE3AA1 1 - Contingency FR1 FR3 - curative | AMPERE | -1500 | 1500 | TWO | \ No newline at end of file diff --git a/tests/src/test/resources/com/powsybl/openrao/tests/features/epic4_dc_mw/US4_1.feature b/tests/src/test/resources/com/powsybl/openrao/tests/features/epic4_dc_mw/US4_1.feature index abe8900131..f0a093a87a 100644 --- a/tests/src/test/resources/com/powsybl/openrao/tests/features/epic4_dc_mw/US4_1.feature +++ b/tests/src/test/resources/com/powsybl/openrao/tests/features/epic4_dc_mw/US4_1.feature @@ -20,9 +20,9 @@ Feature: US 4.1: Import of a crac with MW threshold | Tie-line FR DE | FFR2AA1 DDE3AA1 1 | outage | Contingency FR1 FR3 | yes | no | 5000.0 | 5000.0 | 400.0 | 400.0 | Then the flow cnecs should have the following thresholds: | CnecId | Unit | Min | Max | Side | - | BBE2AA1 FFR3AA1 1 - preventive | MEGAWATT | None | 1500 | LEFT | - | BBE2AA1 FFR3AA1 1 - Contingency FR1 FR3 - curative | MEGAWATT | None | 1500 | LEFT | - | BBE2AA1 FFR3AA1 1 - Contingency FR1 FR3 - outage | MEGAWATT | None | 1500 | LEFT | - | FFR2AA1 DDE3AA1 1 - preventive | AMPERE | -1500 | 1500 | RIGHT | - | FFR2AA1 DDE3AA1 1 - Contingency FR1 FR3 - curative | AMPERE | -1500 | 1500 | RIGHT | - | FFR2AA1 DDE3AA1 1 - Contingency FR1 FR3 - outage | MEGAWATT | -1500 | 1500 | LEFT | \ No newline at end of file + | BBE2AA1 FFR3AA1 1 - preventive | MEGAWATT | None | 1500 | ONE | + | BBE2AA1 FFR3AA1 1 - Contingency FR1 FR3 - curative | MEGAWATT | None | 1500 | ONE | + | BBE2AA1 FFR3AA1 1 - Contingency FR1 FR3 - outage | MEGAWATT | None | 1500 | ONE | + | FFR2AA1 DDE3AA1 1 - preventive | AMPERE | -1500 | 1500 | TWO | + | FFR2AA1 DDE3AA1 1 - Contingency FR1 FR3 - curative | AMPERE | -1500 | 1500 | TWO | + | FFR2AA1 DDE3AA1 1 - Contingency FR1 FR3 - outage | MEGAWATT | -1500 | 1500 | ONE | \ No newline at end of file diff --git a/tests/src/test/resources/com/powsybl/openrao/tests/features/epic90_robust_crac/US90_7.feature b/tests/src/test/resources/com/powsybl/openrao/tests/features/epic90_robust_crac/US90_7.feature index 6d8bf60719..87dacbbb62 100644 --- a/tests/src/test/resources/com/powsybl/openrao/tests/features/epic90_robust_crac/US90_7.feature +++ b/tests/src/test/resources/com/powsybl/openrao/tests/features/epic90_robust_crac/US90_7.feature @@ -19,10 +19,10 @@ Feature: US 90.7: Handle Xnodes | Cnec DE-FR | DDE3AA1 X_DEFR1 1 + FFR2AA1 X_DEFR1 1 | outage | N-1 DE-NL | yes | no | 5000 | 5000 | 400 | 400 | And the flow cnecs should have the following thresholds: | CnecId | Unit | Min | Max | Side | - | BBE2AA1 X_BEFR1 1 + FFR3AA1 X_BEFR1 1 - preventive | AMPERE | -1500 | 1500 | LEFT | - | BBE2AA1 X_BEFR1 1 + FFR3AA1 X_BEFR1 1 - N-1 DE-NL - outage | AMPERE | -5000 | 5000 | LEFT | - | DDE3AA1 X_DEFR1 1 + FFR2AA1 X_DEFR1 1 - preventive | AMPERE | -1500 | 1500 | RIGHT | - | DDE3AA1 X_DEFR1 1 + FFR2AA1 X_DEFR1 1 - N-1 DE-NL - outage | AMPERE | -5000 | 5000 | RIGHT | + | BBE2AA1 X_BEFR1 1 + FFR3AA1 X_BEFR1 1 - preventive | AMPERE | -1500 | 1500 | ONE | + | BBE2AA1 X_BEFR1 1 + FFR3AA1 X_BEFR1 1 - N-1 DE-NL - outage | AMPERE | -5000 | 5000 | ONE | + | DDE3AA1 X_DEFR1 1 + FFR2AA1 X_DEFR1 1 - preventive | AMPERE | -1500 | 1500 | TWO | + | DDE3AA1 X_DEFR1 1 + FFR2AA1 X_DEFR1 1 - N-1 DE-NL - outage | AMPERE | -5000 | 5000 | TWO | And it should have 1 network actions @fast @rao @mock @ac @preventive-only diff --git a/tests/src/test/resources/files/cracCreationParameters/common/CracCreationParameters_default.json b/tests/src/test/resources/files/cracCreationParameters/common/CracCreationParameters_default.json index e2a5460b7c..2f3108539f 100644 --- a/tests/src/test/resources/files/cracCreationParameters/common/CracCreationParameters_default.json +++ b/tests/src/test/resources/files/cracCreationParameters/common/CracCreationParameters_default.json @@ -1,5 +1,5 @@ { "crac-factory": "CracImplFactory", - "default-monitored-line-side" : "monitor-lines-on-left-side", + "default-monitored-line-side" : "monitor-lines-on-side-one", "ra-usage-limits-per-instant": [] } diff --git a/tests/src/test/resources/files/cracCreationParameters/epic12/CimCracCreationParameters_MonitorLeftSide.json b/tests/src/test/resources/files/cracCreationParameters/epic12/CimCracCreationParameters_MonitorLeftSide.json index e7080d97db..24c2771e27 100644 --- a/tests/src/test/resources/files/cracCreationParameters/epic12/CimCracCreationParameters_MonitorLeftSide.json +++ b/tests/src/test/resources/files/cracCreationParameters/epic12/CimCracCreationParameters_MonitorLeftSide.json @@ -1,4 +1,4 @@ { "crac-factory": "CracImplFactory", - "default-monitored-line-side" : "monitor-lines-on-left-side" + "default-monitored-line-side" : "monitor-lines-on-side-one" } diff --git a/tests/src/test/resources/files/cracCreationParameters/epic15/us15_13_4.json b/tests/src/test/resources/files/cracCreationParameters/epic15/us15_13_4.json index 2acebeaa0c..3d0c8965a8 100644 --- a/tests/src/test/resources/files/cracCreationParameters/epic15/us15_13_4.json +++ b/tests/src/test/resources/files/cracCreationParameters/epic15/us15_13_4.json @@ -1,6 +1,6 @@ { "crac-factory": "CracImplFactory", - "default-monitored-line-side" : "monitor-lines-on-left-side", + "default-monitored-line-side" : "monitor-lines-on-side-one", "ra-usage-limits-per-instant" : [{ "instant": "curative", "max-ra" : 2147483647, diff --git a/tests/src/test/resources/files/cracCreationParameters/epic15/us_15_13_3.json b/tests/src/test/resources/files/cracCreationParameters/epic15/us_15_13_3.json index 33e510b052..bb7b9dd5f9 100644 --- a/tests/src/test/resources/files/cracCreationParameters/epic15/us_15_13_3.json +++ b/tests/src/test/resources/files/cracCreationParameters/epic15/us_15_13_3.json @@ -1,6 +1,6 @@ { "crac-factory": "CracImplFactory", - "default-monitored-line-side" : "monitor-lines-on-left-side", + "default-monitored-line-side" : "monitor-lines-on-side-one", "ra-usage-limits-per-instant": [{ "instant": "curative", "max-ra" : 2, diff --git a/tests/src/test/resources/files/cracCreationParameters/epic15/us_15_2_7.json b/tests/src/test/resources/files/cracCreationParameters/epic15/us_15_2_7.json index b5b7ab1431..a71688ba88 100644 --- a/tests/src/test/resources/files/cracCreationParameters/epic15/us_15_2_7.json +++ b/tests/src/test/resources/files/cracCreationParameters/epic15/us_15_2_7.json @@ -1,6 +1,6 @@ { "crac-factory": "CracImplFactory", - "default-monitored-line-side" : "monitor-lines-on-left-side", + "default-monitored-line-side" : "monitor-lines-on-side-one", "ra-usage-limits-per-instant": [{ "instant": "curative", "max-ra" : 2147483647, diff --git a/tests/src/test/resources/files/cracCreationParameters/epic19/us19_8_1.json b/tests/src/test/resources/files/cracCreationParameters/epic19/us19_8_1.json index 2846502e26..d035c36776 100644 --- a/tests/src/test/resources/files/cracCreationParameters/epic19/us19_8_1.json +++ b/tests/src/test/resources/files/cracCreationParameters/epic19/us19_8_1.json @@ -1,6 +1,6 @@ { "crac-factory": "CracImplFactory", - "default-monitored-line-side" : "monitor-lines-on-left-side", + "default-monitored-line-side" : "monitor-lines-on-side-one", "ra-usage-limits-per-instant": [ { "instant": "curative", "max-ra" : 3, diff --git a/tests/src/test/resources/files/cracCreationParameters/epic19/us19_8_11.json b/tests/src/test/resources/files/cracCreationParameters/epic19/us19_8_11.json index 46b0600990..d94a55501c 100644 --- a/tests/src/test/resources/files/cracCreationParameters/epic19/us19_8_11.json +++ b/tests/src/test/resources/files/cracCreationParameters/epic19/us19_8_11.json @@ -1,6 +1,6 @@ { "crac-factory": "CracImplFactory", - "default-monitored-line-side" : "monitor-lines-on-left-side", + "default-monitored-line-side" : "monitor-lines-on-side-one", "ra-usage-limits-per-instant": [ { "instant": "curative", "max-ra" : 3, diff --git a/tests/src/test/resources/files/cracCreationParameters/epic19/us19_8_3&4.json b/tests/src/test/resources/files/cracCreationParameters/epic19/us19_8_3&4.json index 28b62fa41d..746c75125d 100644 --- a/tests/src/test/resources/files/cracCreationParameters/epic19/us19_8_3&4.json +++ b/tests/src/test/resources/files/cracCreationParameters/epic19/us19_8_3&4.json @@ -1,6 +1,6 @@ { "crac-factory": "CracImplFactory", - "default-monitored-line-side" : "monitor-lines-on-left-side", + "default-monitored-line-side" : "monitor-lines-on-side-one", "ra-usage-limits-per-instant": [ { "instant": "curative", "max-ra" : 3, diff --git a/tests/src/test/resources/files/cracCreationParameters/epic19/us19_8_5.json b/tests/src/test/resources/files/cracCreationParameters/epic19/us19_8_5.json index 01656e50d8..8357f12c56 100644 --- a/tests/src/test/resources/files/cracCreationParameters/epic19/us19_8_5.json +++ b/tests/src/test/resources/files/cracCreationParameters/epic19/us19_8_5.json @@ -1,6 +1,6 @@ { "crac-factory": "CracImplFactory", - "default-monitored-line-side" : "monitor-lines-on-left-side", + "default-monitored-line-side" : "monitor-lines-on-side-one", "ra-usage-limits-per-instant": [ { "instant" : "curative", "max-ra" : 2, diff --git a/tests/src/test/resources/files/cracCreationParameters/epic19/us19_8_7.json b/tests/src/test/resources/files/cracCreationParameters/epic19/us19_8_7.json index 29b3df3f8b..419bc5537e 100644 --- a/tests/src/test/resources/files/cracCreationParameters/epic19/us19_8_7.json +++ b/tests/src/test/resources/files/cracCreationParameters/epic19/us19_8_7.json @@ -1,6 +1,6 @@ { "crac-factory": "CracImplFactory", - "default-monitored-line-side" : "monitor-lines-on-left-side", + "default-monitored-line-side" : "monitor-lines-on-side-one", "ra-usage-limits-per-instant": [ { "instant": "curative", "max-ra" : 1, diff --git a/tests/src/test/resources/files/cracCreationParameters/epic19/us19_8_9.json b/tests/src/test/resources/files/cracCreationParameters/epic19/us19_8_9.json index 7331cc1f64..c88203b51f 100644 --- a/tests/src/test/resources/files/cracCreationParameters/epic19/us19_8_9.json +++ b/tests/src/test/resources/files/cracCreationParameters/epic19/us19_8_9.json @@ -1,6 +1,6 @@ { "crac-factory": "CracImplFactory", - "default-monitored-line-side" : "monitor-lines-on-left-side", + "default-monitored-line-side" : "monitor-lines-on-side-one", "ra-usage-limits-per-instant": [ { "instant": "curative", "max-ra" : 3, From a30659baf9fc5f030b69c8d186053418f1927202 Mon Sep 17 00:00:00 2001 From: Peter Mitri Date: Fri, 28 Jun 2024 10:25:24 +0200 Subject: [PATCH 5/8] Allow multi-curative in second preventive optimisation (#1016) --- .../powsybl/openrao/data/cracapi/Crac.java | 2 +- .../loopflowcomputation/LoopFlowResult.java | 16 + .../LoopFlowResultTest.java | 28 +- .../algorithm/CastorFullOptimization.java | 66 ++-- .../adapter/BranchResultAdapterImpl.java | 74 +---- .../searchtreerao/result/api/FlowResult.java | 12 + .../impl/AutomatonPerimeterResultImpl.java | 6 + .../impl/CurativeWithSecondPraoResult.java | 21 +- .../result/impl/EmptyFlowResultImpl.java | 6 + .../result/impl/FlowResultFromMapImpl.java | 77 ----- .../result/impl/FlowResultImpl.java | 76 ++++- ...IteratingLinearOptimizationResultImpl.java | 6 + .../result/impl/PerimeterResultImpl.java | 6 + .../PrePerimeterSensitivityResultImpl.java | 6 + .../PreventiveAndCurativesRaoResultImpl.java | 9 +- .../impl/SkippedOptimizationResultImpl.java | 5 + .../searchtree/algorithms/Leaf.java | 12 + .../algorithm/CastorFullOptimizationTest.java | 122 +++++++- .../PrePerimeterSensitivityAnalysisTest.java | 6 +- .../adapter/FlowResultAdapterImplTest.java | 11 +- .../CurativeWithSecondPraoResultTest.java | 68 +++++ .../result/impl/EmptyFlowResultImplTest.java | 2 + .../impl/FlowResultFromMapImplTest.java | 4 +- .../result/impl/FlowResultImplTest.java | 67 ++++- ...eventiveAndCurativesRaoResultImplTest.java | 12 +- .../SystematicSensitivityResult.java | 47 +++ .../epic91_rao_enhancements/US91_12.feature | 150 +++++++++ ...RaoParameters_case_91_12_secure_2PRAO.json | 81 +++++ .../files/crac/epic91/crac_91_12_16.json | 259 ++++++++++++++++ .../files/crac/epic91/crac_91_12_17.json | 284 ++++++++++++++++++ .../files/crac/epic91/crac_91_12_18.json | 284 ++++++++++++++++++ .../files/crac/epic91/crac_91_12_19.json | 284 ++++++++++++++++++ .../files/crac/epic91/crac_91_12_20.json | 284 ++++++++++++++++++ 33 files changed, 2179 insertions(+), 214 deletions(-) delete mode 100644 ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultFromMapImpl.java create mode 100644 ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/CurativeWithSecondPraoResultTest.java create mode 100644 tests/src/test/resources/files/configurations/epic91/RaoParameters_case_91_12_secure_2PRAO.json create mode 100644 tests/src/test/resources/files/crac/epic91/crac_91_12_16.json create mode 100644 tests/src/test/resources/files/crac/epic91/crac_91_12_17.json create mode 100644 tests/src/test/resources/files/crac/epic91/crac_91_12_18.json create mode 100644 tests/src/test/resources/files/crac/epic91/crac_91_12_19.json create mode 100644 tests/src/test/resources/files/crac/epic91/crac_91_12_20.json diff --git a/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/Crac.java b/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/Crac.java index 0c3fc267e1..f72413f9e4 100644 --- a/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/Crac.java +++ b/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/Crac.java @@ -96,7 +96,7 @@ public interface Crac extends Identifiable { Instant getInstant(InstantKind instantKind); /** - * Gather all the instants present in the Crac with the correct instantKind. + * Returns all the instants present in the Crac with the correct instantKind. */ SortedSet getInstants(InstantKind instantKind); diff --git a/loopflow-computation/src/main/java/com/powsybl/openrao/loopflowcomputation/LoopFlowResult.java b/loopflow-computation/src/main/java/com/powsybl/openrao/loopflowcomputation/LoopFlowResult.java index 423123e08e..1cd1eaa5d4 100644 --- a/loopflow-computation/src/main/java/com/powsybl/openrao/loopflowcomputation/LoopFlowResult.java +++ b/loopflow-computation/src/main/java/com/powsybl/openrao/loopflowcomputation/LoopFlowResult.java @@ -8,6 +8,7 @@ import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.data.cracapi.cnec.BranchCnec; +import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; import com.powsybl.iidm.network.TwoSides; import java.util.EnumMap; @@ -73,4 +74,19 @@ public double getReferenceFlow(BranchCnec cnec, TwoSides side) { } return loopFlowMap.get(cnec).get(side).getTotalFlow(); } + + public Map> getCommercialFlowsMap() { + Map> map = new HashMap<>(); + loopFlowMap.keySet().stream() + .filter(FlowCnec.class::isInstance) + .map(FlowCnec.class::cast) + .forEach(cnec -> { + Map cnecMap = new EnumMap<>(TwoSides.class); + loopFlowMap.get(cnec).keySet().forEach(side -> + cnecMap.put(side, this.getCommercialFlow(cnec, side)) + ); + map.put(cnec, cnecMap); + }); + return map; + } } diff --git a/loopflow-computation/src/test/java/com/powsybl/openrao/loopflowcomputation/LoopFlowResultTest.java b/loopflow-computation/src/test/java/com/powsybl/openrao/loopflowcomputation/LoopFlowResultTest.java index e67409e808..2dad1afbb1 100644 --- a/loopflow-computation/src/test/java/com/powsybl/openrao/loopflowcomputation/LoopFlowResultTest.java +++ b/loopflow-computation/src/test/java/com/powsybl/openrao/loopflowcomputation/LoopFlowResultTest.java @@ -8,13 +8,15 @@ import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.data.cracapi.cnec.BranchCnec; +import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; import com.powsybl.iidm.network.TwoSides; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mockito; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.*; /** * @author Baptiste Seguinot {@literal } @@ -43,5 +45,27 @@ void loopFlowResultCnecNotFound() { LoopFlowResult loopFlowResult = new LoopFlowResult(); assertThrows(OpenRaoException.class, () -> loopFlowResult.getLoopFlow(cnec, TwoSides.TWO)); } + + @Test + void testGetCommercialFlowsMap() { + FlowCnec cnec1 = Mockito.mock(FlowCnec.class); + FlowCnec cnec2 = Mockito.mock(FlowCnec.class); + + LoopFlowResult loopFlowResult = new LoopFlowResult(); + loopFlowResult.addCnecResult(cnec, TwoSides.TWO, 1., 2., 3.); + loopFlowResult.addCnecResult(cnec1, TwoSides.TWO, 1., 20., 3.); + loopFlowResult.addCnecResult(cnec1, TwoSides.ONE, 1., 22., 3.); + loopFlowResult.addCnecResult(cnec2, TwoSides.ONE, 1., 30., 3.); + + Map> commercialFlowsMap = loopFlowResult.getCommercialFlowsMap(); + assertEquals(2, commercialFlowsMap.size()); + + assertEquals(2, commercialFlowsMap.get(cnec1).size()); + assertEquals(20., commercialFlowsMap.get(cnec1).get(TwoSides.TWO), DOUBLE_TOLERANCE); + assertEquals(22., commercialFlowsMap.get(cnec1).get(TwoSides.ONE), DOUBLE_TOLERANCE); + + assertEquals(1, commercialFlowsMap.get(cnec2).size()); + assertEquals(30., commercialFlowsMap.get(cnec2).get(TwoSides.ONE), DOUBLE_TOLERANCE); + } } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/CastorFullOptimization.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/CastorFullOptimization.java index 814e612494..69693dfa78 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/CastorFullOptimization.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/CastorFullOptimization.java @@ -534,7 +534,7 @@ private RaoResult runSecondPreventiveAndAutoRao(RaoInput raoInput, // -- Gather all post contingency remedial actions // ---- Curative remedial actions : // ------ appliedCras from secondPreventiveRaoResult - AppliedRemedialActions appliedArasAndCras = secondPreventiveRaoResult.appliedArasAndCras.copyCurative(); + AppliedRemedialActions appliedArasAndCras = secondPreventiveRaoResult.appliedArasAndCras().copyCurative(); // ------ + curative range actions optimized during second preventive with global optimization if (raoParameters.getSecondPreventiveRaoParameters().getReOptimizeCurativeRangeActions()) { for (Map.Entry entry : postContingencyResults.entrySet()) { @@ -542,7 +542,7 @@ private RaoResult runSecondPreventiveAndAutoRao(RaoInput raoInput, if (!state.getInstant().isCurative()) { continue; } - secondPreventiveRaoResult.perimeterResult.getActivatedRangeActions(state) + secondPreventiveRaoResult.perimeterResult().getActivatedRangeActions(state) .forEach(rangeAction -> appliedArasAndCras.addAppliedRangeAction(state, rangeAction, secondPreventiveRaoResult.perimeterResult.getOptimizedSetpoint(rangeAction, state))); } } @@ -572,7 +572,7 @@ private RaoResult runSecondPreventiveAndAutoRao(RaoInput raoInput, if (entry.getValue() instanceof SkippedOptimizationResultImpl) { newPostContingencyResults.put(state, new SkippedOptimizationResultImpl(state, new HashSet<>(), new HashSet<>(), postCraSensitivityAnalysisOutput.getSensitivityStatus(entry.getKey()), raoParameters.getLoadFlowAndSensitivityParameters().getSensitivityFailureOvercost())); } else { - newPostContingencyResults.put(state, new CurativeWithSecondPraoResult(state, entry.getValue(), secondPreventiveRaoResult.perimeterResult, secondPreventiveRaoResult.remedialActionsExcluded, postCraSensitivityAnalysisOutput)); + newPostContingencyResults.put(state, new CurativeWithSecondPraoResult(state, entry.getValue(), secondPreventiveRaoResult.perimeterResult(), secondPreventiveRaoResult.remedialActionsExcluded(), postCraSensitivityAnalysisOutput)); } } RaoLogger.logMostLimitingElementsResults(BUSINESS_LOGS, postCraSensitivityAnalysisOutput, parameters.getObjectiveFunctionParameters().getType(), NUMBER_LOGGED_ELEMENTS_END_RAO); @@ -580,26 +580,18 @@ private RaoResult runSecondPreventiveAndAutoRao(RaoInput raoInput, return new PreventiveAndCurativesRaoResultImpl(stateTree, initialOutput, firstPreventiveResult, - secondPreventiveRaoResult.perimeterResult, - secondPreventiveRaoResult.remedialActionsExcluded, - secondPreventiveRaoResult.postPraSensitivityAnalysisOutput, + secondPreventiveRaoResult.perimeterResult(), + secondPreventiveRaoResult.remedialActionsExcluded(), + secondPreventiveRaoResult.postPraSensitivityAnalysisOutput(), newPostContingencyResults, postCraSensitivityAnalysisOutput, raoInput.getCrac()); } - private static class SecondPreventiveRaoResult { - private final PerimeterResult perimeterResult; - private final PrePerimeterResult postPraSensitivityAnalysisOutput; - private final Set> remedialActionsExcluded; - private final AppliedRemedialActions appliedArasAndCras; - - public SecondPreventiveRaoResult(PerimeterResult perimeterResult, PrePerimeterResult postPraSensitivityAnalysisOutput, Set> remedialActionsExcluded, AppliedRemedialActions appliedArasAndCras) { - this.perimeterResult = perimeterResult; - this.postPraSensitivityAnalysisOutput = postPraSensitivityAnalysisOutput; - this.remedialActionsExcluded = remedialActionsExcluded; - this.appliedArasAndCras = appliedArasAndCras; - } + private record SecondPreventiveRaoResult(PerimeterResult perimeterResult, + PrePerimeterResult postPraSensitivityAnalysisOutput, + Set> remedialActionsExcluded, + AppliedRemedialActions appliedArasAndCras) { } /** @@ -622,15 +614,13 @@ private SecondPreventiveRaoResult runSecondPreventiveRao(RaoInput raoInput, // Get the applied network actions for every contingency perimeter AppliedRemedialActions appliedArasAndCras = new AppliedRemedialActions(); Crac crac = raoInput.getCrac(); - // TODO: see how to handle multiple curative instants here - Instant curativeInstant = crac.getInstant(InstantKind.CURATIVE); if (crac.hasAutoInstant()) { - addAppliedNetworkActionsPostContingency(crac.getInstant(InstantKind.AUTO), appliedArasAndCras, postContingencyResults); + addAppliedNetworkActionsPostContingency(crac.getInstants(InstantKind.AUTO), appliedArasAndCras, postContingencyResults); } - addAppliedNetworkActionsPostContingency(curativeInstant, appliedArasAndCras, postContingencyResults); + addAppliedNetworkActionsPostContingency(crac.getInstants(InstantKind.CURATIVE), appliedArasAndCras, postContingencyResults); // Get the applied range actions for every auto contingency perimeter if (crac.hasAutoInstant()) { - addAppliedRangeActionsPostContingency(crac.getInstant(InstantKind.AUTO), appliedArasAndCras, postContingencyResults); + addAppliedRangeActionsPostContingency(crac.getInstants(InstantKind.AUTO), appliedArasAndCras, postContingencyResults); } // Apply 1st preventive results for range actions that are both preventive and auto or curative. This way we are sure @@ -640,7 +630,7 @@ private SecondPreventiveRaoResult runSecondPreventiveRao(RaoInput raoInput, if (!parameters.getSecondPreventiveRaoParameters().getReOptimizeCurativeRangeActions()) { // keep old behaviour remedialActionsExcluded = new HashSet<>(getRangeActionsExcludedFromSecondPreventive(crac, firstPreventiveResult, postContingencyResults)); applyPreventiveResultsForAutoOrCurativeRangeActions(network, firstPreventiveResult, crac); - addAppliedRangeActionsPostContingency(curativeInstant, appliedArasAndCras, postContingencyResults); + addAppliedRangeActionsPostContingency(crac.getInstants(InstantKind.CURATIVE), appliedArasAndCras, postContingencyResults); } // Run a first sensitivity computation using initial network and applied CRAs @@ -673,22 +663,26 @@ private SecondPreventiveRaoResult runSecondPreventiveRao(RaoInput raoInput, return new SecondPreventiveRaoResult(secondPreventiveResult, postPraSensitivityAnalysisOutput, remedialActionsExcluded, appliedArasAndCras); } - static void addAppliedNetworkActionsPostContingency(Instant instant, AppliedRemedialActions appliedRemedialActions, Map postContingencyResults) { - postContingencyResults.forEach((state, optimizationResult) -> { - if (state.getInstant().equals(instant)) { - appliedRemedialActions.addAppliedNetworkActions(state, optimizationResult.getActivatedNetworkActions()); - } - }); + static void addAppliedNetworkActionsPostContingency(Set instants, AppliedRemedialActions appliedRemedialActions, Map postContingencyResults) { + instants.forEach(instant -> + postContingencyResults.forEach((state, optimizationResult) -> { + if (state.getInstant().equals(instant)) { + appliedRemedialActions.addAppliedNetworkActions(state, optimizationResult.getActivatedNetworkActions()); + } + }) + ); } - static void addAppliedRangeActionsPostContingency(Instant instant, AppliedRemedialActions appliedRemedialActions, Map postContingencyResults) { + static void addAppliedRangeActionsPostContingency(Set instants, AppliedRemedialActions appliedRemedialActions, Map postContingencyResults) { // Add all range actions that were activated. // Curative/ preventive duplicates are handled via exclusion from 2nd preventive - postContingencyResults.forEach((state, optimizationResult) -> { - if (state.getInstant().equals(instant)) { - optimizationResult.getActivatedRangeActions(state).forEach(rangeAction -> appliedRemedialActions.addAppliedRangeAction(state, rangeAction, optimizationResult.getOptimizedSetpoint(rangeAction, state))); - } - }); + instants.forEach(instant -> + postContingencyResults.forEach((state, optimizationResult) -> { + if (state.getInstant().equals(instant)) { + optimizationResult.getActivatedRangeActions(state).forEach(rangeAction -> appliedRemedialActions.addAppliedRangeAction(state, rangeAction, optimizationResult.getOptimizedSetpoint(rangeAction, state))); + } + }) + ); } private CompletableFuture optimizeSecondPreventivePerimeter(RaoInput raoInput, RaoParameters raoParameters, StateTree stateTree, ToolProvider toolProvider, PrePerimeterResult initialOutput, PrePerimeterResult prePerimeterResult, PerimeterResult firstPreventiveResult, Map postContingencyResults, AppliedRemedialActions appliedCras) { diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/adapter/BranchResultAdapterImpl.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/adapter/BranchResultAdapterImpl.java index 9abcc0fbe3..c026de0a8e 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/adapter/BranchResultAdapterImpl.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/adapter/BranchResultAdapterImpl.java @@ -7,19 +7,15 @@ package com.powsybl.openrao.searchtreerao.commons.adapter; -import com.powsybl.openrao.commons.OpenRaoException; -import com.powsybl.openrao.commons.Unit; +import com.powsybl.iidm.network.Network; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.loopflowcomputation.LoopFlowComputation; -import com.powsybl.openrao.loopflowcomputation.LoopFlowResult; import com.powsybl.openrao.searchtreerao.commons.AbsolutePtdfSumsComputation; -import com.powsybl.openrao.searchtreerao.result.impl.FlowResultImpl; import com.powsybl.openrao.searchtreerao.result.api.FlowResult; import com.powsybl.openrao.searchtreerao.result.impl.EmptyFlowResultImpl; +import com.powsybl.openrao.searchtreerao.result.impl.FlowResultImpl; import com.powsybl.openrao.sensitivityanalysis.SystematicSensitivityResult; -import com.powsybl.iidm.network.Network; -import org.apache.commons.lang3.NotImplementedException; import java.util.Map; import java.util.Set; @@ -45,76 +41,26 @@ public static BranchResultAdpaterBuilder create() { @Override public FlowResult getResult(SystematicSensitivityResult systematicSensitivityResult, Network network) { - FlowResult ptdfs; + FlowResult ptdfs = null; + Map> ptdfsMap = null; if (absolutePtdfSumsComputation != null) { - Map> ptdfsMap = absolutePtdfSumsComputation.computeAbsolutePtdfSums(flowCnecs, systematicSensitivityResult); - ptdfs = new FlowResult() { - - @Override - public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { - throw new NotImplementedException(); - } - - @Override - public double getCommercialFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { - throw new NotImplementedException(); - } - - @Override - public double getPtdfZonalSum(FlowCnec flowCnec, TwoSides side) { - if (ptdfsMap.containsKey(flowCnec) && ptdfsMap.get(flowCnec).containsKey(side)) { - return ptdfsMap.get(flowCnec).get(side); - } else { - throw new OpenRaoException(String.format("No PTDF zonal sum for cnec %s (side %s)", flowCnec.getId(), side)); - } - } - - @Override - public Map> getPtdfZonalSums() { - return ptdfsMap; - } - }; + ptdfsMap = absolutePtdfSumsComputation.computeAbsolutePtdfSums(flowCnecs, systematicSensitivityResult); } else { ptdfs = fixedPtdfs; } - FlowResult commercialFlows; + FlowResult commercialFlows = null; + Map> commercialFlowsMap = null; if (loopFlowComputation != null) { - LoopFlowResult loopFlowResult = loopFlowComputation.buildLoopFlowsFromReferenceFlowAndPtdf( + commercialFlowsMap = loopFlowComputation.buildLoopFlowsFromReferenceFlowAndPtdf( systematicSensitivityResult, loopFlowCnecs, network - ); - commercialFlows = new FlowResult() { - @Override - public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { - throw new NotImplementedException(); - } - - @Override - public double getCommercialFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { - if (unit == Unit.MEGAWATT) { - return loopFlowResult.getCommercialFlow(flowCnec, side); - } else { - throw new NotImplementedException(); - } - - } - - @Override - public double getPtdfZonalSum(FlowCnec flowCnec, TwoSides side) { - throw new NotImplementedException(); - } - - @Override - public Map> getPtdfZonalSums() { - throw new NotImplementedException(); - } - }; + ).getCommercialFlowsMap(); } else { commercialFlows = fixedCommercialFlows; } - return new FlowResultImpl(systematicSensitivityResult, commercialFlows, ptdfs); + return new FlowResultImpl(systematicSensitivityResult, commercialFlowsMap, commercialFlows, ptdfsMap, ptdfs); } public static final class BranchResultAdpaterBuilder { diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/api/FlowResult.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/api/FlowResult.java index db31333322..174c745cff 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/api/FlowResult.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/api/FlowResult.java @@ -8,6 +8,7 @@ package com.powsybl.openrao.searchtreerao.result.api; import com.powsybl.openrao.commons.Unit; +import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.raoapi.parameters.RaoParameters; @@ -29,6 +30,17 @@ public interface FlowResult { */ double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit); + /** + * It gives the flow on a {@link FlowCnec}, at a given {@link Instant} and in a given {@link Unit}. + * + * @param flowCnec: The branch to be studied. + * @param side: The side of the branch to be queried. + * @param unit: The unit in which the flow is queried. Only accepted values are MEGAWATT or AMPERE. + * @param optimizedInstant: The optimization instant for which the flow is queried. + * @return The flow on the branch in the given unit. + */ + double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit, Instant optimizedInstant); + /** * It gives the margin on a {@link FlowCnec} in a given {@link Unit}. It is basically the difference between the * flow and the most constraining threshold in the flow direction of the given branch. If it is negative the branch diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/AutomatonPerimeterResultImpl.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/AutomatonPerimeterResultImpl.java index 76f6bb39e3..fef9e9c149 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/AutomatonPerimeterResultImpl.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/AutomatonPerimeterResultImpl.java @@ -9,6 +9,7 @@ import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.commons.Unit; +import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; import com.powsybl.iidm.network.TwoSides; @@ -56,6 +57,11 @@ public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { return postAutomatonSensitivityAnalysisOutput.getFlow(flowCnec, side, unit); } + @Override + public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit, Instant instant) { + return postAutomatonSensitivityAnalysisOutput.getFlow(flowCnec, side, unit, instant); + } + @Override public double getCommercialFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { return postAutomatonSensitivityAnalysisOutput.getCommercialFlow(flowCnec, side, unit); diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/CurativeWithSecondPraoResult.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/CurativeWithSecondPraoResult.java index 6859c98982..6ef661a333 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/CurativeWithSecondPraoResult.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/CurativeWithSecondPraoResult.java @@ -1,7 +1,15 @@ +/* + * Copyright (c) 2024, 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/. + */ + package com.powsybl.openrao.searchtreerao.result.impl; import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.commons.Unit; +import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.RemedialAction; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.Cnec; @@ -21,6 +29,9 @@ import java.util.Set; import java.util.stream.Collectors; +/** + * @author Peter Mitri {@literal } + */ public class CurativeWithSecondPraoResult implements OptimizationResult { private final State state; // the optimized state of the curative RAO @@ -52,8 +63,8 @@ private void checkState(State stateToCheck) { } private void checkCnec(Cnec cnec) { - if (!cnec.getState().equals(state)) { - throw new OpenRaoException(String.format("Cnec %s has a different state than this result's state (%s)", cnec.getId(), state.getId())); + if (!cnec.getState().getContingency().equals(state.getContingency())) { + throw new OpenRaoException(String.format("Cnec %s has a different contingency than this result's state (%s)", cnec.getId(), state.getId())); } } @@ -67,6 +78,12 @@ public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { return postCraSensitivityFlowResult.getFlow(flowCnec, side, unit); } + @Override + public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit, Instant instant) { + checkCnec(flowCnec); + return postCraSensitivityFlowResult.getFlow(flowCnec, side, unit, instant); + } + @Override public double getCommercialFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { checkCnec(flowCnec); diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/EmptyFlowResultImpl.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/EmptyFlowResultImpl.java index e0e7ba0b89..7dd530b565 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/EmptyFlowResultImpl.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/EmptyFlowResultImpl.java @@ -8,6 +8,7 @@ package com.powsybl.openrao.searchtreerao.result.impl; import com.powsybl.openrao.commons.Unit; +import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.searchtreerao.result.api.FlowResult; @@ -25,6 +26,11 @@ public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { return Double.NaN; } + @Override + public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit, Instant instant) { + return Double.NaN; + } + @Override public double getCommercialFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { return Double.NaN; diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultFromMapImpl.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultFromMapImpl.java deleted file mode 100644 index 608b5537f7..0000000000 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultFromMapImpl.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2021, 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/. - */ - -package com.powsybl.openrao.searchtreerao.result.impl; - -import com.powsybl.openrao.commons.OpenRaoException; -import com.powsybl.openrao.commons.Unit; -import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.iidm.network.TwoSides; -import com.powsybl.openrao.searchtreerao.commons.RaoUtil; -import com.powsybl.openrao.searchtreerao.result.api.FlowResult; -import com.powsybl.openrao.sensitivityanalysis.SystematicSensitivityResult; - -import java.util.Map; - -import static java.lang.String.format; - -/** - * @author Joris Mancini {@literal } - */ -public class FlowResultFromMapImpl implements FlowResult { - protected final SystematicSensitivityResult systematicSensitivityResult; - private final Map> commercialFlows; - private final Map> ptdfZonalSums; - - public FlowResultFromMapImpl(SystematicSensitivityResult systematicSensitivityResult, - Map> commercialFlows, - Map> ptdfZonalSums) { - this.systematicSensitivityResult = systematicSensitivityResult; - this.commercialFlows = commercialFlows; - this.ptdfZonalSums = ptdfZonalSums; - } - - @Override - public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { - if (unit == Unit.MEGAWATT) { - return systematicSensitivityResult.getReferenceFlow(flowCnec, side); - } else if (unit == Unit.AMPERE) { - double intensity = systematicSensitivityResult.getReferenceIntensity(flowCnec, side); - if (Double.isNaN(intensity) || Math.abs(intensity) <= 1e-6) { - return systematicSensitivityResult.getReferenceFlow(flowCnec, side) * RaoUtil.getFlowUnitMultiplier(flowCnec, side, Unit.MEGAWATT, Unit.AMPERE); - } else { - return intensity; - } - } else { - throw new OpenRaoException("Unknown unit for flow."); - } - } - - @Override - public double getCommercialFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { - if (unit != Unit.MEGAWATT) { - throw new OpenRaoException("Commercial flows only in MW."); - } - if (!commercialFlows.containsKey(flowCnec) || !commercialFlows.get(flowCnec).containsKey(side)) { - throw new OpenRaoException(format("No commercial flow on the CNEC %s on side %s", flowCnec.getName(), side)); - } - return commercialFlows.get(flowCnec).get(side); - } - - @Override - public double getPtdfZonalSum(FlowCnec flowCnec, TwoSides side) { - if (!ptdfZonalSums.containsKey(flowCnec) || !ptdfZonalSums.get(flowCnec).containsKey(side)) { - throw new OpenRaoException(format("No PTDF computed on the CNEC %s on side %s", flowCnec.getName(), side)); - } - return ptdfZonalSums.get(flowCnec).get(side); - } - - @Override - public Map> getPtdfZonalSums() { - return ptdfZonalSums; - } -} diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultImpl.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultImpl.java index 41be1423e7..1da7955803 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultImpl.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultImpl.java @@ -9,6 +9,7 @@ import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.commons.Unit; +import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.searchtreerao.commons.RaoUtil; @@ -17,20 +18,48 @@ import java.util.Map; +import static java.lang.String.format; + /** * @author Joris Mancini {@literal } */ public class FlowResultImpl implements FlowResult { protected final SystematicSensitivityResult systematicSensitivityResult; + private final Map> commercialFlows; + private final Map> ptdfZonalSums; private final FlowResult fixedCommercialFlows; - private final FlowResult fixedPtdfs; + private final FlowResult fixedPtdfZonalSums; + + public FlowResultImpl(SystematicSensitivityResult systematicSensitivityResult, + Map> commercialFlows, + Map> ptdfZonalSums) { + this(systematicSensitivityResult, commercialFlows, null, ptdfZonalSums, null); + } public FlowResultImpl(SystematicSensitivityResult systematicSensitivityResult, FlowResult fixedCommercialFlows, - FlowResult fixedPtdfs) { + FlowResult fixedPtdfZonalSums) { + this(systematicSensitivityResult, null, fixedCommercialFlows, null, fixedPtdfZonalSums); + } + + public FlowResultImpl(SystematicSensitivityResult systematicSensitivityResult, + Map> commercialFlows, + FlowResult fixedCommercialFlows, + Map> ptdfZonalSums, + FlowResult fixedPtdfZonalSums) { this.systematicSensitivityResult = systematicSensitivityResult; + if (commercialFlows == null && fixedCommercialFlows == null + || commercialFlows != null && fixedCommercialFlows != null) { + throw new OpenRaoException("Either commercialFlows or fixedCommercialFlows should be non null"); + } + if (ptdfZonalSums == null && fixedPtdfZonalSums == null + || ptdfZonalSums != null && fixedPtdfZonalSums != null) { + throw new OpenRaoException("Either ptdfZonalSums or fixedPtdfZonalSums should be non null"); + } + this.commercialFlows = commercialFlows; + this.ptdfZonalSums = ptdfZonalSums; this.fixedCommercialFlows = fixedCommercialFlows; - this.fixedPtdfs = fixedPtdfs; + this.fixedPtdfZonalSums = fixedPtdfZonalSums; } @Override @@ -50,22 +79,55 @@ public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { } @Override - public double getCommercialFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { + public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit, Instant instant) { if (unit == Unit.MEGAWATT) { - return fixedCommercialFlows.getCommercialFlow(flowCnec, side, unit); + return systematicSensitivityResult.getReferenceFlow(flowCnec, side, instant); + } else if (unit == Unit.AMPERE) { + double intensity = systematicSensitivityResult.getReferenceIntensity(flowCnec, side, instant); + if (Double.isNaN(intensity) || Math.abs(intensity) <= 1e-6) { + return systematicSensitivityResult.getReferenceFlow(flowCnec, side, instant) * RaoUtil.getFlowUnitMultiplier(flowCnec, side, Unit.MEGAWATT, Unit.AMPERE); + } else { + return intensity; + } } else { + throw new OpenRaoException("Unknown unit for flow."); + } + } + + @Override + public double getCommercialFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { + if (unit != Unit.MEGAWATT) { throw new OpenRaoException("Commercial flows only in MW."); } + if (fixedCommercialFlows != null) { + return fixedCommercialFlows.getCommercialFlow(flowCnec, side, unit); + } else { + if (!commercialFlows.containsKey(flowCnec) || !commercialFlows.get(flowCnec).containsKey(side)) { + throw new OpenRaoException(format("No commercial flow on the CNEC %s on side %s", flowCnec.getName(), side)); + } + return commercialFlows.get(flowCnec).get(side); + } } @Override public double getPtdfZonalSum(FlowCnec flowCnec, TwoSides side) { - return fixedPtdfs.getPtdfZonalSum(flowCnec, side); + if (fixedPtdfZonalSums != null) { + return fixedPtdfZonalSums.getPtdfZonalSum(flowCnec, side); + } else { + if (!ptdfZonalSums.containsKey(flowCnec) || !ptdfZonalSums.get(flowCnec).containsKey(side)) { + throw new OpenRaoException(format("No PTDF computed on the CNEC %s on side %s", flowCnec.getName(), side)); + } + return ptdfZonalSums.get(flowCnec).get(side); + } } @Override public Map> getPtdfZonalSums() { - return fixedPtdfs.getPtdfZonalSums(); + if (fixedPtdfZonalSums != null) { + return fixedPtdfZonalSums.getPtdfZonalSums(); + } else { + return ptdfZonalSums; + } } } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/IteratingLinearOptimizationResultImpl.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/IteratingLinearOptimizationResultImpl.java index 780ce0ce65..bcd7a6c41e 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/IteratingLinearOptimizationResultImpl.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/IteratingLinearOptimizationResultImpl.java @@ -8,6 +8,7 @@ package com.powsybl.openrao.searchtreerao.result.impl; import com.powsybl.openrao.commons.Unit; +import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; import com.powsybl.iidm.network.TwoSides; @@ -122,6 +123,11 @@ public double getFlow(FlowCnec branchCnec, TwoSides side, Unit unit) { return flowResult.getFlow(branchCnec, side, unit); } + @Override + public double getFlow(FlowCnec branchCnec, TwoSides side, Unit unit, Instant instant) { + return flowResult.getFlow(branchCnec, side, unit, instant); + } + @Override public double getCommercialFlow(FlowCnec branchCnec, TwoSides side, Unit unit) { return flowResult.getCommercialFlow(branchCnec, side, unit); diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/PerimeterResultImpl.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/PerimeterResultImpl.java index 604e1076f8..bc550a42af 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/PerimeterResultImpl.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/PerimeterResultImpl.java @@ -8,6 +8,7 @@ package com.powsybl.openrao.searchtreerao.result.impl; import com.powsybl.openrao.commons.Unit; +import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.NetworkElement; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; @@ -42,6 +43,11 @@ public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { return optimizationResult.getFlow(flowCnec, side, unit); } + @Override + public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit, Instant instant) { + return optimizationResult.getFlow(flowCnec, side, unit, instant); + } + @Override public double getCommercialFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { return optimizationResult.getCommercialFlow(flowCnec, side, unit); diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/PrePerimeterSensitivityResultImpl.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/PrePerimeterSensitivityResultImpl.java index f237419f34..c63b138918 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/PrePerimeterSensitivityResultImpl.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/PrePerimeterSensitivityResultImpl.java @@ -7,6 +7,7 @@ package com.powsybl.openrao.searchtreerao.result.impl; import com.powsybl.openrao.commons.Unit; +import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; import com.powsybl.iidm.network.TwoSides; @@ -81,6 +82,11 @@ public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { return flowResult.getFlow(flowCnec, side, unit); } + @Override + public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit, Instant instant) { + return flowResult.getFlow(flowCnec, side, unit, instant); + } + @Override public double getRelativeMargin(FlowCnec flowCnec, Unit unit) { return flowResult.getRelativeMargin(flowCnec, unit); diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/PreventiveAndCurativesRaoResultImpl.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/PreventiveAndCurativesRaoResultImpl.java index 29413786e2..90c7154e2e 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/PreventiveAndCurativesRaoResultImpl.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/PreventiveAndCurativesRaoResultImpl.java @@ -280,7 +280,7 @@ public double getRelativeMargin(Instant optimizedInstant, FlowCnec flowCnec, Uni public double getFlow(Instant optimizedInstant, FlowCnec flowCnec, TwoSides side, Unit unit) { FlowResult flowResult = getFlowResult(optimizedInstant, flowCnec); if (Objects.nonNull(flowResult)) { - return flowResult.getFlow(flowCnec, side, unit); + return flowResult.getFlow(flowCnec, side, unit, optimizedInstant); } else { return Double.NaN; } @@ -589,8 +589,11 @@ private State getStateOptimizedBefore(State state) { // curative Contingency contingency = state.getContingency().orElseThrow(); return postContingencyResults.keySet().stream() - .filter(mapState -> mapState.getInstant().isAuto() && mapState.getContingency().equals(Optional.of(contingency))) - .findAny().orElse(preventiveState); + .filter(mapState -> mapState.getContingency().equals(Optional.of(contingency))) + .filter(mapState -> mapState.getInstant().isAuto() || mapState.getInstant().isCurative()) + .filter(mapState -> mapState.getInstant().comesBefore(state.getInstant())) + .max(Comparator.comparingInt(mapState -> mapState.getInstant().getOrder())) + .orElse(preventiveState); } } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/SkippedOptimizationResultImpl.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/SkippedOptimizationResultImpl.java index b2a75c29b4..e40457f13f 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/SkippedOptimizationResultImpl.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/result/impl/SkippedOptimizationResultImpl.java @@ -80,6 +80,11 @@ public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { throw new OpenRaoException(SHOULD_NOT_BE_USED); } + @Override + public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit, Instant instant) { + throw new OpenRaoException(SHOULD_NOT_BE_USED); + } + @Override public double getCommercialFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { throw new OpenRaoException(SHOULD_NOT_BE_USED); diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/Leaf.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/Leaf.java index 770002687a..f24e2131eb 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/Leaf.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/Leaf.java @@ -8,6 +8,7 @@ import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.commons.Unit; +import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.RaUsageLimits; import com.powsybl.openrao.data.cracapi.RemedialAction; import com.powsybl.openrao.data.cracapi.State; @@ -340,6 +341,17 @@ public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { } } + @Override + public double getFlow(FlowCnec flowCnec, TwoSides side, Unit unit, Instant instant) { + if (status == Status.EVALUATED) { + return preOptimFlowResult.getFlow(flowCnec, side, unit, instant); + } else if (status == Status.OPTIMIZED) { + return postOptimResult.getFlow(flowCnec, side, unit, instant); + } else { + throw new OpenRaoException(NO_RESULTS_AVAILABLE); + } + } + @Override public double getCommercialFlow(FlowCnec flowCnec, TwoSides side, Unit unit) { if (status == Status.EVALUATED) { diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/CastorFullOptimizationTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/CastorFullOptimizationTest.java index 3975f31be3..770adcdafa 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/CastorFullOptimizationTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/CastorFullOptimizationTest.java @@ -543,8 +543,8 @@ void testGetAppliedRemedialActionsInCurative() { Map curativeResults = Map.of(state1, optimResult1, state2, optimResult2); AppliedRemedialActions appliedRemedialActions = new AppliedRemedialActions(); - CastorFullOptimization.addAppliedNetworkActionsPostContingency(autoInstant, appliedRemedialActions, curativeResults); - CastorFullOptimization.addAppliedNetworkActionsPostContingency(curativeInstant, appliedRemedialActions, curativeResults); + CastorFullOptimization.addAppliedNetworkActionsPostContingency(Set.of(autoInstant), appliedRemedialActions, curativeResults); + CastorFullOptimization.addAppliedNetworkActionsPostContingency(Set.of(curativeInstant), appliedRemedialActions, curativeResults); // do not apply network action // do not apply range action as it was not yet added to applied RAs @@ -561,8 +561,8 @@ void testGetAppliedRemedialActionsInCurative() { assertFalse(network.getLine(naNeId).getTerminal1().isConnected()); // add range action - CastorFullOptimization.addAppliedRangeActionsPostContingency(autoInstant, appliedRemedialActions, curativeResults); - CastorFullOptimization.addAppliedRangeActionsPostContingency(curativeInstant, appliedRemedialActions, curativeResults); + CastorFullOptimization.addAppliedRangeActionsPostContingency(Set.of(autoInstant), appliedRemedialActions, curativeResults); + CastorFullOptimization.addAppliedRangeActionsPostContingency(Set.of(curativeInstant), appliedRemedialActions, curativeResults); // apply also range action appliedRemedialActions.applyOnNetwork(state1, network); @@ -1056,4 +1056,118 @@ void curativeOptimizationShouldBeDoneIfPreventiveMinMarginNegativeAndAssociatedP RaoResult raoResult = new CastorFullOptimization(raoInput, raoParameters, null).run().join(); assertEquals(Set.of(crac.getNetworkAction("Open FFR1AA1 FFR4AA1 1")), raoResult.getActivatedNetworkActionsDuringState(crac.getState("Contingency FFR2AA1 FFR3AA1 1", crac.getLastInstant()))); } + + private State mockState(Instant instant) { + State state = Mockito.mock(State.class); + when(state.getInstant()).thenReturn(instant); + return state; + } + + private OptimizationResult mockOptimizationResult(Set activatedNetworkActions) { + OptimizationResult optimizationResult = Mockito.mock(OptimizationResult.class); + when(optimizationResult.getActivatedNetworkActions()).thenReturn(activatedNetworkActions); + return optimizationResult; + } + + private OptimizationResult mockOptimizationResult(Set> activatedRangeActions, State state) { + OptimizationResult optimizationResult = Mockito.mock(OptimizationResult.class); + when(optimizationResult.getActivatedRangeActions(state)).thenReturn(activatedRangeActions); + return optimizationResult; + } + + @Test + void testAddAppliedNetworkActionsPostContingency() { + AppliedRemedialActions appliedRemedialActions = new AppliedRemedialActions(); + Instant instant1 = Mockito.mock(Instant.class); + when(instant1.isAuto()).thenReturn(true); + Instant instant2 = Mockito.mock(Instant.class); + when(instant2.isCurative()).thenReturn(true); + + State state11 = mockState(instant1); + State state12 = mockState(instant1); + State state21 = mockState(instant2); + State state22 = mockState(instant2); + + NetworkAction na111 = Mockito.mock(NetworkAction.class); + NetworkAction na112 = Mockito.mock(NetworkAction.class); + NetworkAction na121 = Mockito.mock(NetworkAction.class); + NetworkAction na211 = Mockito.mock(NetworkAction.class); + NetworkAction na221 = Mockito.mock(NetworkAction.class); + NetworkAction na222 = Mockito.mock(NetworkAction.class); + + OptimizationResult optimizationResult11 = mockOptimizationResult(Set.of(na111, na112)); + OptimizationResult optimizationResult12 = mockOptimizationResult(Set.of(na121)); + OptimizationResult optimizationResult21 = mockOptimizationResult(Set.of(na211)); + OptimizationResult optimizationResult22 = mockOptimizationResult(Set.of(na221, na222)); + + Map postContingencyResults = Map.of(state11, optimizationResult11, state12, optimizationResult12, + state21, optimizationResult21, state22, optimizationResult22); + + CastorFullOptimization.addAppliedNetworkActionsPostContingency(Set.of(), appliedRemedialActions, postContingencyResults); + + assertTrue(appliedRemedialActions.getAppliedNetworkActions(state11).isEmpty()); + assertTrue(appliedRemedialActions.getAppliedNetworkActions(state12).isEmpty()); + assertTrue(appliedRemedialActions.getAppliedNetworkActions(state21).isEmpty()); + assertTrue(appliedRemedialActions.getAppliedNetworkActions(state22).isEmpty()); + + CastorFullOptimization.addAppliedNetworkActionsPostContingency(Set.of(instant1), appliedRemedialActions, postContingencyResults); + assertEquals(Set.of(na111, na112), appliedRemedialActions.getAppliedNetworkActions(state11)); + assertEquals(Set.of(na121), appliedRemedialActions.getAppliedNetworkActions(state12)); + assertTrue(appliedRemedialActions.getAppliedNetworkActions(state21).isEmpty()); + assertTrue(appliedRemedialActions.getAppliedNetworkActions(state22).isEmpty()); + + CastorFullOptimization.addAppliedNetworkActionsPostContingency(Set.of(instant2), appliedRemedialActions, postContingencyResults); + assertEquals(Set.of(na111, na112), appliedRemedialActions.getAppliedNetworkActions(state11)); + assertEquals(Set.of(na121), appliedRemedialActions.getAppliedNetworkActions(state12)); + assertEquals(Set.of(na211), appliedRemedialActions.getAppliedNetworkActions(state21)); + assertEquals(Set.of(na221, na222), appliedRemedialActions.getAppliedNetworkActions(state22)); + } + + @Test + void testAddAppliedRangeActionsPostContingency() { + AppliedRemedialActions appliedRemedialActions = new AppliedRemedialActions(); + Instant instant1 = Mockito.mock(Instant.class); + when(instant1.isAuto()).thenReturn(true); + Instant instant2 = Mockito.mock(Instant.class); + when(instant2.isCurative()).thenReturn(true); + + State state11 = mockState(instant1); + State state12 = mockState(instant1); + State state21 = mockState(instant2); + State state22 = mockState(instant2); + + RangeAction ra111 = Mockito.mock(RangeAction.class); + RangeAction ra112 = Mockito.mock(RangeAction.class); + RangeAction ra121 = Mockito.mock(RangeAction.class); + RangeAction ra211 = Mockito.mock(RangeAction.class); + RangeAction ra221 = Mockito.mock(RangeAction.class); + RangeAction ra222 = Mockito.mock(RangeAction.class); + + OptimizationResult optimizationResult11 = mockOptimizationResult(Set.of(ra111, ra112), state11); + OptimizationResult optimizationResult12 = mockOptimizationResult(Set.of(ra121), state12); + OptimizationResult optimizationResult21 = mockOptimizationResult(Set.of(ra211), state21); + OptimizationResult optimizationResult22 = mockOptimizationResult(Set.of(ra221, ra222), state22); + + Map postContingencyResults = Map.of(state11, optimizationResult11, state12, optimizationResult12, + state21, optimizationResult21, state22, optimizationResult22); + + CastorFullOptimization.addAppliedRangeActionsPostContingency(Set.of(), appliedRemedialActions, postContingencyResults); + + assertTrue(appliedRemedialActions.getAppliedRangeActions(state11).isEmpty()); + assertTrue(appliedRemedialActions.getAppliedRangeActions(state12).isEmpty()); + assertTrue(appliedRemedialActions.getAppliedRangeActions(state21).isEmpty()); + assertTrue(appliedRemedialActions.getAppliedRangeActions(state22).isEmpty()); + + CastorFullOptimization.addAppliedRangeActionsPostContingency(Set.of(instant1), appliedRemedialActions, postContingencyResults); + assertEquals(Map.of(ra111, 0., ra112, 0.), appliedRemedialActions.getAppliedRangeActions(state11)); + assertEquals(Map.of(ra121, 0.), appliedRemedialActions.getAppliedRangeActions(state12)); + assertTrue(appliedRemedialActions.getAppliedRangeActions(state21).isEmpty()); + assertTrue(appliedRemedialActions.getAppliedRangeActions(state22).isEmpty()); + + CastorFullOptimization.addAppliedRangeActionsPostContingency(Set.of(instant2), appliedRemedialActions, postContingencyResults); + assertEquals(Map.of(ra111, 0., ra112, 0.), appliedRemedialActions.getAppliedRangeActions(state11)); + assertEquals(Map.of(ra121, 0.), appliedRemedialActions.getAppliedRangeActions(state12)); + assertEquals(Map.of(ra211, 0.), appliedRemedialActions.getAppliedRangeActions(state21)); + assertEquals(Map.of(ra221, 0., ra222, 0.), appliedRemedialActions.getAppliedRangeActions(state22)); + } } diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/PrePerimeterSensitivityAnalysisTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/PrePerimeterSensitivityAnalysisTest.java index 75715f68b8..7f2315e9f7 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/PrePerimeterSensitivityAnalysisTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/PrePerimeterSensitivityAnalysisTest.java @@ -15,6 +15,7 @@ import com.powsybl.openrao.data.cracimpl.utils.CommonCracCreation; import com.powsybl.openrao.data.cracimpl.utils.NetworkImportsUtil; import com.powsybl.openrao.loopflowcomputation.LoopFlowComputation; +import com.powsybl.openrao.loopflowcomputation.LoopFlowResult; import com.powsybl.openrao.raoapi.parameters.ObjectiveFunctionParameters; import com.powsybl.openrao.raoapi.parameters.RaoParameters; import com.powsybl.openrao.raoapi.parameters.extensions.LoopFlowParametersExtension; @@ -76,7 +77,10 @@ public void setUp() { rangeActionSetpointResult = Mockito.mock(RangeActionSetpointResult.class); toolProvider = Mockito.mock(ToolProvider.class); - when(toolProvider.getLoopFlowComputation()).thenReturn(Mockito.mock(LoopFlowComputation.class)); + LoopFlowComputation loopFlowComputation = Mockito.mock(LoopFlowComputation.class); + when(toolProvider.getLoopFlowComputation()).thenReturn(loopFlowComputation); + LoopFlowResult loopFlowResult = Mockito.mock(LoopFlowResult.class); + when(loopFlowComputation.buildLoopFlowsFromReferenceFlowAndPtdf(any(), any(), any())).thenReturn(loopFlowResult); AbsolutePtdfSumsComputation absolutePtdfSumsComputation = Mockito.mock(AbsolutePtdfSumsComputation.class); when(absolutePtdfSumsComputation.computeAbsolutePtdfSums(any(), any())).thenReturn(Map.of(cnec, Map.of(TwoSides.ONE, 0.987))); when(toolProvider.getAbsolutePtdfSumsComputation()).thenReturn(absolutePtdfSumsComputation); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/adapter/FlowResultAdapterImplTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/adapter/FlowResultAdapterImplTest.java index 44a1a1b68d..e3416523e3 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/adapter/FlowResultAdapterImplTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/adapter/FlowResultAdapterImplTest.java @@ -15,7 +15,7 @@ import com.powsybl.openrao.loopflowcomputation.LoopFlowResult; import com.powsybl.openrao.searchtreerao.commons.AbsolutePtdfSumsComputation; import com.powsybl.openrao.searchtreerao.result.api.FlowResult; -import com.powsybl.openrao.searchtreerao.result.impl.FlowResultFromMapImpl; +import com.powsybl.openrao.searchtreerao.result.impl.FlowResultImpl; import com.powsybl.openrao.sensitivityanalysis.SystematicSensitivityResult; import com.powsybl.iidm.network.Network; import org.junit.jupiter.api.BeforeEach; @@ -76,7 +76,7 @@ void testBasicReturns() { @Test void testWithFixedPtdfs() { - FlowResult fixedPtdfFlowResult = new FlowResultFromMapImpl(systematicSensitivityResult, new HashMap<>(), Map.of(cnec1, Map.of(ONE, 20.))); + FlowResult fixedPtdfFlowResult = new FlowResultImpl(systematicSensitivityResult, new HashMap<>(), Map.of(cnec1, Map.of(ONE, 20.))); BranchResultAdapter branchResultAdapter = branchResultAdpaterBuilder .withPtdfsResults(fixedPtdfFlowResult) .build(); @@ -88,8 +88,8 @@ void testWithFixedPtdfs() { @Test void testWithFixedPtdfsAndCommercialFlows() { - FlowResult ptdfFlowResult = new FlowResultFromMapImpl(systematicSensitivityResult, new HashMap<>(), Map.of(cnec1, Map.of(ONE, 20.))); - FlowResult commercialFlowFlowResult = new FlowResultFromMapImpl(systematicSensitivityResult, Map.of(cnec2, Map.of(TWO, 300.)), new HashMap<>()); + FlowResult ptdfFlowResult = new FlowResultImpl(systematicSensitivityResult, new HashMap<>(), Map.of(cnec1, Map.of(ONE, 20.))); + FlowResult commercialFlowFlowResult = new FlowResultImpl(systematicSensitivityResult, Map.of(cnec2, Map.of(TWO, 300.)), new HashMap<>()); BranchResultAdapter branchResultAdapter = branchResultAdpaterBuilder .withPtdfsResults(ptdfFlowResult) .withCommercialFlowsResults(commercialFlowFlowResult) @@ -104,7 +104,7 @@ void testWithFixedPtdfsAndCommercialFlows() { @Test void testWithFixedPtdfsAndUpdatedCommercialFlows() { LoopFlowComputation loopFlowComputation = Mockito.mock(LoopFlowComputation.class); - FlowResult ptdfFlowResult = new FlowResultFromMapImpl(systematicSensitivityResult, new HashMap<>(), Map.of(cnec1, Map.of(ONE, 20.))); + FlowResult ptdfFlowResult = new FlowResultImpl(systematicSensitivityResult, new HashMap<>(), Map.of(cnec1, Map.of(ONE, 20.))); BranchResultAdapter branchResultAdapter = branchResultAdpaterBuilder.withPtdfsResults(ptdfFlowResult) .withCommercialFlowsResults(loopFlowComputation, Set.of(cnec2)) .build(); @@ -113,6 +113,7 @@ void testWithFixedPtdfsAndUpdatedCommercialFlows() { when(loopFlowComputation.buildLoopFlowsFromReferenceFlowAndPtdf(systematicSensitivityResult, Set.of(cnec2), network)) .thenReturn(loopFlowResult); when(loopFlowResult.getCommercialFlow(cnec2, TWO)).thenReturn(300.); + when(loopFlowResult.getCommercialFlowsMap()).thenReturn(Map.of(cnec2, Map.of(TWO, 300.))); FlowResult flowResult = branchResultAdapter.getResult(systematicSensitivityResult, network); assertEquals(20., flowResult.getPtdfZonalSum(cnec1, ONE), DOUBLE_TOLERANCE); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/CurativeWithSecondPraoResultTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/CurativeWithSecondPraoResultTest.java new file mode 100644 index 0000000000..1ef4202cfc --- /dev/null +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/CurativeWithSecondPraoResultTest.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2024, 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/. + */ + +package com.powsybl.openrao.searchtreerao.result.impl; + +import com.powsybl.contingency.Contingency; +import com.powsybl.iidm.network.TwoSides; +import com.powsybl.openrao.commons.OpenRaoException; +import com.powsybl.openrao.commons.Unit; +import com.powsybl.openrao.data.cracapi.Instant; +import com.powsybl.openrao.data.cracapi.State; +import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; +import com.powsybl.openrao.searchtreerao.result.api.PrePerimeterResult; +import org.junit.jupiter.api.Test; + +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.*; + +/** + * @author Peter Mitri {@literal } + */ +class CurativeWithSecondPraoResultTest { + private static final double DOUBLE_TOLERANCE = 1e-6; + + private State mockStateWithContingency(String id) { + Contingency contingency = mock(Contingency.class); + State state = mock(State.class); + when(state.getContingency()).thenReturn(Optional.of(contingency)); + when(state.getId()).thenReturn(id); + return state; + } + + private FlowCnec mockFlowCnec(State state, String id) { + FlowCnec cnec = mock(FlowCnec.class); + when(cnec.getId()).thenReturn(id); + when(cnec.getState()).thenReturn(state); + return cnec; + } + + @Test + void testGetFlow() { + State state1 = mockStateWithContingency("state1"); + State state2 = mockStateWithContingency("state2"); + FlowCnec cnec1 = mockFlowCnec(state1, "cnec1"); + FlowCnec cnec2 = mockFlowCnec(state2, "cnec2"); + PrePerimeterResult postCraPrePerimeterResult = mock(PrePerimeterResult.class); + when(postCraPrePerimeterResult.getFlow(eq(cnec1), any(), any())).thenReturn(135.4); + when(postCraPrePerimeterResult.getFlow(eq(cnec1), any(), any(), any())).thenReturn(135.4); + + CurativeWithSecondPraoResult result = new CurativeWithSecondPraoResult(state1, null, null, null, postCraPrePerimeterResult); + + assertEquals(135.4, result.getFlow(cnec1, TwoSides.TWO, Unit.MEGAWATT), DOUBLE_TOLERANCE); + assertEquals(135.4, result.getFlow(cnec1, TwoSides.ONE, Unit.AMPERE, mock(Instant.class)), DOUBLE_TOLERANCE); + + Exception e = assertThrows(OpenRaoException.class, () -> result.getFlow(cnec2, TwoSides.TWO, Unit.MEGAWATT)); + assertEquals("Cnec cnec2 has a different contingency than this result's state (state1)", e.getMessage()); + + e = assertThrows(OpenRaoException.class, () -> result.getFlow(cnec2, TwoSides.ONE, Unit.AMPERE, mock(Instant.class))); + assertEquals("Cnec cnec2 has a different contingency than this result's state (state1)", e.getMessage()); + } +} diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/EmptyFlowResultImplTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/EmptyFlowResultImplTest.java index 09591c5330..ed9af8dc2a 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/EmptyFlowResultImplTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/EmptyFlowResultImplTest.java @@ -8,6 +8,7 @@ package com.powsybl.openrao.searchtreerao.result.impl; import com.powsybl.openrao.commons.Unit; +import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; import com.powsybl.iidm.network.TwoSides; import org.junit.jupiter.api.Test; @@ -27,6 +28,7 @@ void testBasicReturns() { assertTrue(Double.isNaN(branchResult.getFlow(cnec, TwoSides.TWO, Unit.MEGAWATT))); assertTrue(Double.isNaN(branchResult.getFlow(cnec, TwoSides.ONE, Unit.AMPERE))); assertTrue(Double.isNaN(branchResult.getFlow(cnec, TwoSides.TWO, Unit.AMPERE))); + assertTrue(Double.isNaN(branchResult.getFlow(cnec, TwoSides.TWO, Unit.AMPERE, Mockito.mock(Instant.class)))); assertTrue(Double.isNaN(branchResult.getCommercialFlow(cnec, TwoSides.ONE, Unit.MEGAWATT))); assertTrue(Double.isNaN(branchResult.getCommercialFlow(cnec, TwoSides.TWO, Unit.MEGAWATT))); assertTrue(Double.isNaN(branchResult.getPtdfZonalSum(cnec, TwoSides.ONE))); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultFromMapImplTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultFromMapImplTest.java index d0beb55323..109777e9d1 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultFromMapImplTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultFromMapImplTest.java @@ -33,14 +33,14 @@ class FlowResultFromMapImplTest { SystematicSensitivityResult systematicSensitivityResult; FlowCnec loopFlowCnec; FlowCnec optimizedCnec; - FlowResultFromMapImpl branchResultFromMap; + FlowResultImpl branchResultFromMap; @BeforeEach public void setUp() { systematicSensitivityResult = Mockito.mock(SystematicSensitivityResult.class); loopFlowCnec = Mockito.mock(FlowCnec.class); optimizedCnec = Mockito.mock(FlowCnec.class); - branchResultFromMap = new FlowResultFromMapImpl( + branchResultFromMap = new FlowResultImpl( systematicSensitivityResult, Map.of(loopFlowCnec, Map.of(ONE, 200., TWO, 250.)), Map.of(optimizedCnec, Map.of(ONE, 30., TWO, 35.)) diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultImplTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultImplTest.java index de396f543b..20e6651aab 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultImplTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/FlowResultImplTest.java @@ -7,8 +7,10 @@ package com.powsybl.openrao.searchtreerao.result.impl; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.commons.Unit; +import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; import com.powsybl.openrao.searchtreerao.result.api.FlowResult; import com.powsybl.openrao.sensitivityanalysis.SystematicSensitivityResult; @@ -16,6 +18,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; +import java.util.HashMap; import java.util.Map; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -80,6 +83,21 @@ void testBasicReturns() { assertThrows(OpenRaoException.class, () -> branchResult.getCommercialFlow(optimizedCnec, TWO, Unit.MEGAWATT)); } + @Test + void testGetFlowWithInstant() { + Instant instant = Mockito.mock(Instant.class); + + when(systematicSensitivityResult.getReferenceFlow(loopFlowCnec, ONE, instant)).thenReturn(200.); + when(systematicSensitivityResult.getReferenceIntensity(loopFlowCnec, ONE, instant)).thenReturn(58.); + when(systematicSensitivityResult.getReferenceFlow(optimizedCnec, TWO, instant)).thenReturn(500.); + when(systematicSensitivityResult.getReferenceIntensity(optimizedCnec, TWO, instant)).thenReturn(235.); + + assertEquals(200, branchResult.getFlow(loopFlowCnec, ONE, Unit.MEGAWATT, instant), DOUBLE_TOLERANCE); + assertEquals(58, branchResult.getFlow(loopFlowCnec, ONE, Unit.AMPERE, instant), DOUBLE_TOLERANCE); + assertEquals(500, branchResult.getFlow(optimizedCnec, TWO, Unit.MEGAWATT, instant), DOUBLE_TOLERANCE); + assertEquals(235, branchResult.getFlow(optimizedCnec, TWO, Unit.AMPERE, instant), DOUBLE_TOLERANCE); + } + @Test void testNanFlow() { when(systematicSensitivityResult.getReferenceIntensity(optimizedCnec, TWO)).thenReturn(Double.NaN); @@ -87,13 +105,54 @@ void testNanFlow() { when(optimizedCnec.getNominalVoltage(any())).thenReturn(400.); assertEquals(721.69, branchResult.getFlow(optimizedCnec, TWO, Unit.AMPERE), DOUBLE_TOLERANCE); + + Instant instant = Mockito.mock(Instant.class); + when(systematicSensitivityResult.getReferenceIntensity(optimizedCnec, TWO, instant)).thenReturn(Double.NaN); + when(systematicSensitivityResult.getReferenceFlow(optimizedCnec, TWO, instant)).thenReturn(500.); + when(optimizedCnec.getNominalVoltage(any())).thenReturn(400.); + + assertEquals(721.69, branchResult.getFlow(optimizedCnec, TWO, Unit.AMPERE, instant), DOUBLE_TOLERANCE); } @Test void testWrongFlowUnit() { - assertThrows(OpenRaoException.class, () -> branchResult.getFlow(optimizedCnec, TWO, Unit.KILOVOLT)); - assertThrows(OpenRaoException.class, () -> branchResult.getFlow(optimizedCnec, TWO, Unit.DEGREE)); - assertThrows(OpenRaoException.class, () -> branchResult.getFlow(optimizedCnec, TWO, Unit.PERCENT_IMAX)); - assertThrows(OpenRaoException.class, () -> branchResult.getFlow(optimizedCnec, TWO, Unit.TAP)); + Exception e = assertThrows(OpenRaoException.class, () -> branchResult.getFlow(optimizedCnec, TWO, Unit.KILOVOLT)); + assertEquals("Unknown unit for flow.", e.getMessage()); + e = assertThrows(OpenRaoException.class, () -> branchResult.getFlow(optimizedCnec, TWO, Unit.DEGREE)); + assertEquals("Unknown unit for flow.", e.getMessage()); + e = assertThrows(OpenRaoException.class, () -> branchResult.getFlow(optimizedCnec, TWO, Unit.PERCENT_IMAX)); + assertEquals("Unknown unit for flow.", e.getMessage()); + e = assertThrows(OpenRaoException.class, () -> branchResult.getFlow(optimizedCnec, TWO, Unit.TAP)); + assertEquals("Unknown unit for flow.", e.getMessage()); + + Instant instant = Mockito.mock(Instant.class); + e = assertThrows(OpenRaoException.class, () -> branchResult.getFlow(optimizedCnec, TWO, Unit.KILOVOLT, instant)); + assertEquals("Unknown unit for flow.", e.getMessage()); + e = assertThrows(OpenRaoException.class, () -> branchResult.getFlow(optimizedCnec, TWO, Unit.DEGREE, instant)); + assertEquals("Unknown unit for flow.", e.getMessage()); + e = assertThrows(OpenRaoException.class, () -> branchResult.getFlow(optimizedCnec, TWO, Unit.PERCENT_IMAX, instant)); + assertEquals("Unknown unit for flow.", e.getMessage()); + e = assertThrows(OpenRaoException.class, () -> branchResult.getFlow(optimizedCnec, TWO, Unit.TAP, instant)); + assertEquals("Unknown unit for flow.", e.getMessage()); + } + + @Test + void testConstructorWrongCases() { + Map> commercialFlows = new HashMap<>(); + FlowResult fixedCommercialFlows = Mockito.mock(FlowResult.class); + Map> ptdfZonalSums = new HashMap<>(); + FlowResult fixedPtdfZonalSums = Mockito.mock(FlowResult.class); + + Exception e = assertThrows(OpenRaoException.class, () -> new FlowResultImpl(systematicSensitivityResult, commercialFlows, fixedCommercialFlows, ptdfZonalSums, null)); + assertEquals("Either commercialFlows or fixedCommercialFlows should be non null", e.getMessage()); + + e = assertThrows(OpenRaoException.class, () -> new FlowResultImpl(systematicSensitivityResult, null, null, ptdfZonalSums, null)); + assertEquals("Either commercialFlows or fixedCommercialFlows should be non null", e.getMessage()); + + e = assertThrows(OpenRaoException.class, () -> new FlowResultImpl(systematicSensitivityResult, commercialFlows, null, ptdfZonalSums, fixedPtdfZonalSums)); + assertEquals("Either ptdfZonalSums or fixedPtdfZonalSums should be non null", e.getMessage()); + + e = assertThrows(OpenRaoException.class, () -> new FlowResultImpl(systematicSensitivityResult, commercialFlows, null, null, null)); + assertEquals("Either ptdfZonalSums or fixedPtdfZonalSums should be non null", e.getMessage()); } } diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/PreventiveAndCurativesRaoResultImplTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/PreventiveAndCurativesRaoResultImplTest.java index ae74cdc540..296b06d028 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/PreventiveAndCurativesRaoResultImplTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/result/impl/PreventiveAndCurativesRaoResultImplTest.java @@ -562,9 +562,9 @@ void testGetOptimizedSetPointsOnState() { @Test void testGetFlow() { - when(initialResult.getFlow(cnec1, ONE, MEGAWATT)).thenReturn(10.); - when(preCurativeResult.getFlow(cnec2, TWO, AMPERE)).thenReturn(20.); - when(postPrevResult.getFlow(cnec3, TWO, MEGAWATT)).thenReturn(30.); + when(initialResult.getFlow(cnec1, ONE, MEGAWATT, null)).thenReturn(10.); + when(preCurativeResult.getFlow(cnec2, TWO, AMPERE, preventiveInstant)).thenReturn(20.); + when(postPrevResult.getFlow(cnec3, TWO, MEGAWATT, curativeInstant)).thenReturn(30.); when(cnec3.getState()).thenReturn(curativeState3); assertEquals(10., output.getFlow(null, cnec1, ONE, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(20., output.getFlow(preventiveInstant, cnec2, TWO, AMPERE), DOUBLE_TOLERANCE); @@ -839,9 +839,9 @@ void testNoPostContingencyResultGetters() { assertEquals(Map.of(pstRangeAction, 222., rangeAction, 111.), output.getOptimizedSetPointsOnState(curativeState3)); // Test get flow - when(initialResult.getFlow(cnec1, ONE, MEGAWATT)).thenReturn(10.); - when(preCurativeResult.getFlow(cnec2, TWO, AMPERE)).thenReturn(20.); - when(preCurativeResult.getFlow(cnec3, TWO, MEGAWATT)).thenReturn(30.); + when(initialResult.getFlow(cnec1, ONE, MEGAWATT, null)).thenReturn(10.); + when(preCurativeResult.getFlow(cnec2, TWO, AMPERE, preventiveInstant)).thenReturn(20.); + when(preCurativeResult.getFlow(cnec3, TWO, MEGAWATT, curativeInstant)).thenReturn(30.); when(cnec3.getState()).thenReturn(curativeState3); assertEquals(10., output.getFlow(null, cnec1, ONE, MEGAWATT), DOUBLE_TOLERANCE); assertEquals(20., output.getFlow(preventiveInstant, cnec2, TWO, AMPERE), DOUBLE_TOLERANCE); diff --git a/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/SystematicSensitivityResult.java b/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/SystematicSensitivityResult.java index b0bb231218..3922a06e90 100644 --- a/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/SystematicSensitivityResult.java +++ b/sensitivity-analysis/src/main/java/com/powsybl/openrao/sensitivityanalysis/SystematicSensitivityResult.java @@ -7,6 +7,7 @@ package com.powsybl.openrao.sensitivityanalysis; import com.powsybl.contingency.Contingency; +import com.powsybl.openrao.data.cracapi.Instant; import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.Cnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; @@ -243,6 +244,16 @@ public double getReferenceFlow(FlowCnec cnec, TwoSides side) { return stateResult.getReferenceFlows().get(cnec.getNetworkElement().getId()).get(side); } + public double getReferenceFlow(FlowCnec cnec, TwoSides side, Instant instant) { + StateResult stateResult = getCnecStateResult(cnec, instant); + if (stateResult == null || + !stateResult.getReferenceFlows().containsKey(cnec.getNetworkElement().getId()) || + !stateResult.getReferenceFlows().get(cnec.getNetworkElement().getId()).containsKey(side)) { + return 0.0; + } + return stateResult.getReferenceFlows().get(cnec.getNetworkElement().getId()).get(side); + } + public double getReferenceIntensity(FlowCnec cnec, TwoSides side) { StateResult stateResult = getCnecStateResult(cnec); if (stateResult == null || @@ -253,6 +264,16 @@ public double getReferenceIntensity(FlowCnec cnec, TwoSides side) { return stateResult.getReferenceIntensities().get(cnec.getNetworkElement().getId()).get(side); } + public double getReferenceIntensity(FlowCnec cnec, TwoSides side, Instant instant) { + StateResult stateResult = getCnecStateResult(cnec, instant); + if (stateResult == null || + !stateResult.getReferenceIntensities().containsKey(cnec.getNetworkElement().getId()) || + !stateResult.getReferenceIntensities().get(cnec.getNetworkElement().getId()).containsKey(side)) { + return 0.0; + } + return stateResult.getReferenceIntensities().get(cnec.getNetworkElement().getId()).get(side); + } + public double getSensitivityOnFlow(RangeAction rangeAction, FlowCnec cnec, TwoSides side) { return RangeActionSensiHandler.get(rangeAction).getSensitivityOnFlow(cnec, side, this); } @@ -272,6 +293,17 @@ public double getSensitivityOnFlow(String variableId, FlowCnec cnec, TwoSides si return stateResult.getFlowSensitivities().get(cnec.getNetworkElement().getId()).get(variableId).get(side); } + public double getSensitivityOnFlow(String variableId, FlowCnec cnec, TwoSides side, Instant instant) { + StateResult stateResult = getCnecStateResult(cnec, instant); + if (stateResult == null || + !stateResult.getFlowSensitivities().containsKey(cnec.getNetworkElement().getId()) || + !stateResult.getFlowSensitivities().get(cnec.getNetworkElement().getId()).containsKey(variableId) || + !stateResult.getFlowSensitivities().get(cnec.getNetworkElement().getId()).get(variableId).containsKey(side)) { + return 0.0; + } + return stateResult.getFlowSensitivities().get(cnec.getNetworkElement().getId()).get(variableId).get(side); + } + private StateResult getCnecStateResult(Cnec cnec) { if (memoizedStateResultPerCnec.containsKey(cnec)) { return memoizedStateResultPerCnec.get(cnec); @@ -295,4 +327,19 @@ private StateResult getCnecStateResult(Cnec cnec) { return nStateResult; } } + + private StateResult getCnecStateResult(Cnec cnec, Instant instant) { + Optional optionalContingency = cnec.getState().getContingency(); + if (optionalContingency.isPresent()) { + int maxAdmissibleInstantOrder = instant == null ? 1 : Math.max(1, instant.getOrder()); // when dealing with post-contingency CNECs, a null instant refers to the outage instant + List possibleInstants = postContingencyResults.keySet().stream() + .filter(instantOrder -> instantOrder <= cnec.getState().getInstant().getOrder() && instantOrder <= maxAdmissibleInstantOrder) + .sorted(Comparator.reverseOrder()) + .toList(); + String contingencyId = optionalContingency.get().getId(); + return possibleInstants.isEmpty() ? null : postContingencyResults.get(possibleInstants.get(0)).get(contingencyId); + } else { + return nStateResult; // when dealing with preventive CNECs, a null instant refers to the initial instant + } + } } diff --git a/tests/src/test/resources/com/powsybl/openrao/tests/features/epic91_rao_enhancements/US91_12.feature b/tests/src/test/resources/com/powsybl/openrao/tests/features/epic91_rao_enhancements/US91_12.feature index 7f4773b3c1..4d5e546382 100644 --- a/tests/src/test/resources/com/powsybl/openrao/tests/features/epic91_rao_enhancements/US91_12.feature +++ b/tests/src/test/resources/com/powsybl/openrao/tests/features/epic91_rao_enhancements/US91_12.feature @@ -48,10 +48,13 @@ Feature: US 91.12: Multi-curative Then 1 remedial actions are used after "Contingency DE2 DE3 1" at "curative1" Then the tap of PstRangeAction "CRA_PST_BE" should be -11 after "Contingency DE2 DE3 1" at "curative1" Then the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative1" after "curative1" instant remedial actions should be 500.0 MW + Then the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative2" after "curative1" instant remedial actions should be 500.0 MW + Then the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative3" after "curative1" instant remedial actions should be 500.0 MW # After second curative Then 1 remedial actions are used after "Contingency DE2 DE3 1" at "curative2" Then the remedial action "CRA_CLOSE_NL2_BE3_2" is used after "Contingency DE2 DE3 1" at "curative2" Then the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative2" after "curative2" instant remedial actions should be 263.0 MW + Then the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative3" after "curative2" instant remedial actions should be 263.0 MW # After third curative Then 1 remedial actions are used after "Contingency DE2 DE3 1" at "curative3" Then the remedial action "CRA_CLOSE_NL2_BE3_3" is used after "Contingency DE2 DE3 1" at "curative3" @@ -541,3 +544,150 @@ Feature: US 91.12: Multi-curative Then the remedial action "CRA_CLOSE_BE3_BE4_1" is used after "Contingency DE2 NL3 1" at "curative3" Then the tap of PstRangeAction "CRA_PST_BE" should be 3 after "Contingency DE2 NL3 1" at "curative3" Then the flow on cnec "BBE1AA1 BBE3AA1 1 - Contingency DE2 NL3 1 - curative3" after "curative3" instant remedial actions should be -283.0 MW + + @fast @rao @ac @multi-curative + Scenario: US 91.12.16: Multi-curative CNECs with PRAs only + # This is a copy of US 91.12.2 but CRAs are transformed into PRAs + # Curative CNECs are now part of the preventive perimeter + # Then the 3 RAs should be applied in preventive in order to solve curative constraints + Given network file is "epic91/12Nodes3ParallelLines.uct" + Given crac file is "epic91/crac_91_12_16.json" + Given configuration file is "epic91/RaoParameters_case_91_12_secure.json" + When I launch search_tree_rao + Then the optimization steps executed by the RAO should be "FIRST_PREVENTIVE_ONLY" + And 3 remedial actions are used in preventive + And the remedial action "PRA_PST_BE" is used in preventive + And the tap of PstRangeAction "PRA_PST_BE" should be -11 in preventive + And the remedial action "PRA_CLOSE_NL2_BE3_2" is used in preventive + And the remedial action "PRA_CLOSE_NL2_BE3_3" is used in preventive + And the margin on cnec "NNL2AA1 BBE3AA1 1 - preventive" after PRA should be 654.8 MW + And the margin on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative1" after PRA should be 320.6 MW + And the margin on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative2" after PRA should be 120.6 MW + And the margin on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative3" after PRA should be 70.6 MW + + @fast @rao @ac @multi-curative + Scenario: US 91.12.17: Multi-curative CNECs with simple 2nd PRAO + # This is a copy of previous case, but some useless CRAs are added to keep curative perimeters + # Then the same PRAs should be applied in 2nd PRAO + Given network file is "epic91/12Nodes3ParallelLines.uct" + Given crac file is "epic91/crac_91_12_17.json" + Given configuration file is "epic91/RaoParameters_case_91_12_secure_2PRAO.json" + When I launch search_tree_rao + Then the optimization steps executed by the RAO should be "SECOND_PREVENTIVE_IMPROVED_FIRST" + And 3 remedial actions are used in preventive + And the remedial action "PRA_PST_BE" is used in preventive + And the tap of PstRangeAction "PRA_PST_BE" should be -11 in preventive + And the remedial action "PRA_CLOSE_NL2_BE3_2" is used in preventive + And the remedial action "PRA_CLOSE_NL2_BE3_3" is used in preventive + And the margin on cnec "NNL2AA1 BBE3AA1 1 - preventive" after PRA should be 654.8 MW + And the margin on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative1" after PRA should be 320.6 MW + And the margin on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative2" after PRA should be 120.6 MW + And the margin on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative3" after PRA should be 70.6 MW + + @fast @rao @ac @multi-curative + Scenario: US 91.12.18: Multi-curative CNECs with no CRA for curative1 and 2nd PRAO + # This is a copy of US 91.12.2 but only CRA that was available in curative1 is made a PRA + # (a useless CRA is added to keep all curative perimeters) + # Thus the other 2 CRAs should be applied as before, but the PST should be applied in 2nd PRAO + Given network file is "epic91/12Nodes3ParallelLines.uct" + Given crac file is "epic91/crac_91_12_18.json" + Given configuration file is "epic91/RaoParameters_case_91_12_secure_2PRAO.json" + When I launch search_tree_rao + Then the optimization steps executed by the RAO should be "SECOND_PREVENTIVE_IMPROVED_FIRST" + # Initial + And the initial flow on cnec "NNL2AA1 BBE3AA1 1 - preventive" should be 500.0 MW + And the initial flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - outage" should be 583.33 MW + And the initial flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative1" should be 583.33 MW + And the initial flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative2" should be 583.33 MW + And the initial flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative3" should be 583.33 MW + # Preventive + And 1 remedial actions are used in preventive + And the remedial action "PRA_PST_BE" is used in preventive + And the tap of PstRangeAction "PRA_PST_BE" should be -11 in preventive + And the flow on cnec "NNL2AA1 BBE3AA1 1 - preventive" after PRA should be 392.0 MW + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - outage" after PRA should be 493.4 MW + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative1" after PRA should be 493.4 MW + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative2" after PRA should be 493.4 MW + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative3" after PRA should be 493.4 MW + # Curative1 + And 0 remedial actions are used after "Contingency DE2 DE3 1" at "curative1" + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative1" after "curative1" instant remedial actions should be 493.4 MW + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative2" after "curative1" instant remedial actions should be 493.4 MW + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative3" after "curative1" instant remedial actions should be 493.4 MW + # Curative2 + And 1 remedial actions are used after "Contingency DE2 DE3 1" at "curative2" + And the remedial action "CRA_CLOSE_NL2_BE3_2" is used after "Contingency DE2 DE3 1" at "curative2" + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative2" after "curative2" instant remedial actions should be 263.1 MW + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative3" after "curative2" instant remedial actions should be 263.1 MW + # Curative3 + And 1 remedial actions are used after "Contingency DE2 DE3 1" at "curative3" + And the remedial action "CRA_CLOSE_NL2_BE3_3" is used after "Contingency DE2 DE3 1" at "curative3" + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative3" after "curative3" instant remedial actions should be 179.4 MW + + @fast @rao @ac @multi-curative + Scenario: US 91.12.19: Multi-curative CNECs with no CRA for curative2 and 2nd PRAO + # This is a copy of US 91.12.2 but only CRA that was available in curative2 is made a PRA + # (a useless CRA is added to keep all curative perimeters) + # Thus the other 2 CRAs should be applied as before, but the RA_CLOSE_NL2_BE3_2 should be applied in 2nd PRAO + Given network file is "epic91/12Nodes3ParallelLines.uct" + Given crac file is "epic91/crac_91_12_19.json" + Given configuration file is "epic91/RaoParameters_case_91_12_secure_2PRAO.json" + When I launch search_tree_rao + Then the optimization steps executed by the RAO should be "SECOND_PREVENTIVE_IMPROVED_FIRST" + # Preventive + And 1 remedial actions are used in preventive + And the remedial action "PRA_CLOSE_NL2_BE3_2" is used in preventive + And the flow on cnec "NNL2AA1 BBE3AA1 1 - preventive" after PRA should be 270.3 MW + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - outage" after PRA should be 311.1 MW + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative1" after PRA should be 311.1 MW + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative2" after PRA should be 311.1 MW + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative3" after PRA should be 311.1 MW + # Curative1 + And 1 remedial actions are used after "Contingency DE2 DE3 1" at "curative1" + And the remedial action "CRA_PST_BE" is used after "Contingency DE2 DE3 1" at "curative1" + And the tap of PstRangeAction "CRA_PST_BE" should be -11 after "Contingency DE2 DE3 1" at "curative1" + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative1" after "curative1" instant remedial actions should be 263.1 MW + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative2" after "curative1" instant remedial actions should be 263.1 MW + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative3" after "curative1" instant remedial actions should be 263.1 MW + # Curative2 + And 0 remedial actions are used after "Contingency DE2 DE3 1" at "curative2" + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative2" after "curative2" instant remedial actions should be 263.1 MW + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative3" after "curative2" instant remedial actions should be 263.1 MW + # Curative3 + And 1 remedial actions are used after "Contingency DE2 DE3 1" at "curative3" + And the remedial action "CRA_CLOSE_NL2_BE3_3" is used after "Contingency DE2 DE3 1" at "curative3" + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative3" after "curative3" instant remedial actions should be 179.4 MW + + @fast @rao @ac @multi-curative + Scenario: US 91.12.20: Multi-curative CNECs with no CRA for curative3 and 2nd PRAO + # This is a copy of US 91.12.2 but only CRA that was available in curative3 is made a PRA + # (a useless CRA is added to keep all curative perimeters) + # Thus the other 2 CRAs should be applied as before, but the RA_CLOSE_NL2_BE3_3 should be applied in 2nd PRAO + Given network file is "epic91/12Nodes3ParallelLines.uct" + Given crac file is "epic91/crac_91_12_20.json" + Given configuration file is "epic91/RaoParameters_case_91_12_secure_2PRAO.json" + When I launch search_tree_rao + Then the optimization steps executed by the RAO should be "SECOND_PREVENTIVE_IMPROVED_FIRST" + # Preventive + And 1 remedial actions are used in preventive + And the remedial action "PRA_CLOSE_NL2_BE3_3" is used in preventive + And the flow on cnec "NNL2AA1 BBE3AA1 1 - preventive" after PRA should be 270.3 MW + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - outage" after PRA should be 311.1 MW + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative1" after PRA should be 311.1 MW + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative2" after PRA should be 311.1 MW + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative3" after PRA should be 311.1 MW + # Curative1 + And 1 remedial actions are used after "Contingency DE2 DE3 1" at "curative1" + And the remedial action "CRA_PST_BE" is used after "Contingency DE2 DE3 1" at "curative1" + And the tap of PstRangeAction "CRA_PST_BE" should be -11 after "Contingency DE2 DE3 1" at "curative1" + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative1" after "curative1" instant remedial actions should be 263.1 MW + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative2" after "curative1" instant remedial actions should be 263.1 MW + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative3" after "curative1" instant remedial actions should be 263.1 MW + # Curative2 + And 1 remedial actions are used after "Contingency DE2 DE3 1" at "curative2" + And the remedial action "CRA_CLOSE_NL2_BE3_2" is used after "Contingency DE2 DE3 1" at "curative2" + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative2" after "curative2" instant remedial actions should be 179.4 MW + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative3" after "curative2" instant remedial actions should be 179.4 MW + # Curative3 + And 0 remedial actions are used after "Contingency DE2 DE3 1" at "curative3" + And the flow on cnec "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative3" after "curative3" instant remedial actions should be 179.4 MW diff --git a/tests/src/test/resources/files/configurations/epic91/RaoParameters_case_91_12_secure_2PRAO.json b/tests/src/test/resources/files/configurations/epic91/RaoParameters_case_91_12_secure_2PRAO.json new file mode 100644 index 0000000000..79db028d20 --- /dev/null +++ b/tests/src/test/resources/files/configurations/epic91/RaoParameters_case_91_12_secure_2PRAO.json @@ -0,0 +1,81 @@ +{ + "version" : "2.4", + "objective-function" : { + "type" : "MAX_MIN_MARGIN_IN_MEGAWATT", + "forbid-cost-increase" : false, + "curative-min-obj-improvement" : 0.0, + "preventive-stop-criterion" : "SECURE", + "curative-stop-criterion" : "SECURE" + }, + "range-actions-optimization" : { + "max-mip-iterations" : 10, + "pst-penalty-cost" : 0.01, + "pst-sensitivity-threshold" : 1.0E-6, + "pst-model" : "APPROXIMATED_INTEGERS", + "hvdc-penalty-cost" : 0.001, + "hvdc-sensitivity-threshold" : 1.0E-6, + "injection-ra-penalty-cost" : 0.001, + "injection-ra-sensitivity-threshold" : 1.0E-6, + "linear-optimization-solver" : { + "solver" : "CBC", + "relative-mip-gap" : 1.0E-4, + "solver-specific-parameters" : null + } + }, + "topological-actions-optimization" : { + "max-preventive-search-tree-depth" : 2147483647, + "max-auto-search-tree-depth" : 2147483647, + "max-curative-search-tree-depth" : 2147483647, + "predefined-combinations" : [ ], + "relative-minimum-impact-threshold" : 0.0, + "absolute-minimum-impact-threshold" : 1.0, + "skip-actions-far-from-most-limiting-element" : true, + "max-number-of-boundaries-for-skipping-actions" : 0 + }, + "multi-threading" : { + "contingency-scenarios-in-parallel" : 1, + "preventive-leaves-in-parallel" : 1, + "curative-leaves-in-parallel" : 1 + }, + "second-preventive-rao" : { + "execution-condition" : "POSSIBLE_CURATIVE_IMPROVEMENT", + "re-optimize-curative-range-actions" : false, + "hint-from-first-preventive-rao" : false + }, + "not-optimized-cnecs" : { + "do-not-optimize-curative-cnecs-for-tsos-without-cras" : false + }, + "load-flow-and-sensitivity-computation" : { + "load-flow-provider" : "OpenLoadFlow", + "sensitivity-provider" : "OpenLoadFlow", + "sensitivity-failure-overcost" : 10000.0, + "sensitivity-parameters" : { + "version" : "1.0", + "load-flow-parameters" : { + "version" : "1.9", + "voltageInitMode" : "UNIFORM_VALUES", + "transformerVoltageControlOn" : false, + "phaseShifterRegulationOn" : false, + "useReactiveLimits" : true, + "twtSplitShuntAdmittance" : false, + "shuntCompensatorVoltageControlOn" : false, + "readSlackBus" : true, + "writeSlackBus" : true, + "dc" : true, + "distributedSlack" : true, + "balanceType" : "PROPORTIONAL_TO_LOAD", + "dcUseTransformerRatio" : true, + "countriesToBalance" : [ ], + "connectedComponentMode" : "MAIN", + "hvdcAcEmulation" : true + } + } + }, + "extensions" : { + "mnec-parameters" : { + "acceptable-margin-decrease" : 50.0, + "violation-cost" : 10.0, + "constraint-adjustment-coefficient" : 0.0 + } + } +} \ No newline at end of file diff --git a/tests/src/test/resources/files/crac/epic91/crac_91_12_16.json b/tests/src/test/resources/files/crac/epic91/crac_91_12_16.json new file mode 100644 index 0000000000..38070caacd --- /dev/null +++ b/tests/src/test/resources/files/crac/epic91/crac_91_12_16.json @@ -0,0 +1,259 @@ +{ + "type": "CRAC", + "version": "2.0", + "info": "Generated by FARAO http://farao-community.github.io", + "id": "CRAC_91_12_2", + "name": "CRAC_91_12_2", + "instants": [ + { + "id" : "preventive", + "kind" : "PREVENTIVE" + }, + { + "id" : "outage", + "kind" : "OUTAGE" + }, + { + "id" : "curative1", + "kind" : "CURATIVE" + }, + { + "id" : "curative2", + "kind" : "CURATIVE" + }, + { + "id" : "curative3", + "kind" : "CURATIVE" + } + ], + "networkElementsNamePerId": {}, + "contingencies": [ + { + "id": "Contingency DE2 DE3 1", + "networkElementsIds": [ + "DDE2AA1 DDE3AA1 1" + ] + } + ], + "flowCnecs": [ + { + "id": "NNL2AA1 BBE3AA1 1 - preventive", + "name": "NNL2AA1 BBE3AA1 1 - preventive", + "networkElementId": "NNL2AA1 BBE3AA1 1", + "operator": null, + "instant": "preventive", + "optimized": true, + "monitored": false, + "reliabilityMargin": 0.0, + "iMax": [ + 5000.0 + ], + "nominalV": [ + 400.0 + ], + "thresholds": [ + { + "unit": "megawatt", + "min": -800.0, + "max": 800.0, + "side" : "left" + } + ] + }, + { + "id": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - outage", + "name": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - outage", + "networkElementId": "NNL2AA1 BBE3AA1 1", + "contingencyId": "Contingency DE2 DE3 1", + "operator": null, + "instant": "outage", + "optimized": true, + "monitored": false, + "reliabilityMargin": 0.0, + "iMax": [ + 50.0 + ], + "nominalV": [ + 400.0 + ], + "thresholds": [ + { + "unit": "megawatt", + "min": -1000.0, + "max": 1000.0, + "side" : "left" + } + ] + }, + { + "id": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative1", + "name": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative1", + "networkElementId": "NNL2AA1 BBE3AA1 1", + "contingencyId": "Contingency DE2 DE3 1", + "operator": null, + "instant": "curative1", + "optimized": true, + "monitored": false, + "reliabilityMargin": 0.0, + "iMax": [ + 50.0 + ], + "nominalV": [ + 400.0 + ], + "thresholds": [ + { + "unit": "megawatt", + "min": -500.0, + "max": 500.0, + "side" : "left" + } + ] + }, + { + "id": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative2", + "name": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative2", + "networkElementId": "NNL2AA1 BBE3AA1 1", + "contingencyId": "Contingency DE2 DE3 1", + "operator": null, + "instant": "curative2", + "optimized": true, + "monitored": false, + "reliabilityMargin": 0.0, + "iMax": [ + 50.0 + ], + "nominalV": [ + 400.0 + ], + "thresholds": [ + { + "unit": "megawatt", + "min": -300.0, + "max": 300.0, + "side" : "left" + } + ] + }, + { + "id": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative3", + "name": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative3", + "networkElementId": "NNL2AA1 BBE3AA1 1", + "contingencyId": "Contingency DE2 DE3 1", + "operator": null, + "instant": "curative3", + "optimized": true, + "monitored": false, + "reliabilityMargin": 0.0, + "iMax": [ + 50.0 + ], + "nominalV": [ + 400.0 + ], + "thresholds": [ + { + "unit": "megawatt", + "min": -250.0, + "max": 250.0, + "side" : "left" + } + ] + } + ], + "pstRangeActions": [ + { + "id": "PRA_PST_BE", + "name": "PRA_PST_BE", + "operator": "BE", + "onInstantUsageRules": [ + { + "instant": "preventive", + "usageMethod": "available" + } + ], + "networkElementId": "BBE2AA1 BBE3AA1 1", + "initialTap": 0, + "tapToAngleConversionMap": { + "-1": -0.3896097993971608, + "0": 0.0, + "-2": -0.7792105912934298, + "1": 0.3896097993971608, + "-3": -1.1687933694373345, + "2": 0.7792105912934298, + "-4": -1.5583491300758083, + "3": 1.1687933694373345, + "-5": -1.9478688732023104, + "4": 1.5583491300758083, + "-6": -2.337343603803646, + "5": 1.9478688732023104, + "-7": -2.7267643331050597, + "6": 2.337343603803646, + "-8": -3.1161220798131644, + "7": 2.7267643331050597, + "-9": -3.505407871356285, + "8": 3.1161220798131644, + "-10": -3.894612745121778, + "9": 3.505407871356285, + "-11": -4.283727749689918, + "10": 3.894612745121778, + "-12": -4.672743946063913, + "11": 4.283727749689918, + "-13": -5.061652408895631, + "12": 4.672743946063913, + "-14": -5.4504442277066305, + "13": 5.061652408895631, + "-15": -5.839110508104064, + "14": 5.4504442277066305, + "-16": -6.2276423729910535, + "15": 5.839110508104064, + "16": 6.2276423729910535 + }, + "ranges": [ + { + "min": -11, + "max": 16, + "rangeType": "absolute" + } + ] + } + ], + "hvdcRangeActions": [], + "injectionRangeActions": [], + "networkActions": [ + { + "id": "PRA_CLOSE_NL2_BE3_2", + "name": "PRA_CLOSE_NL2_BE3_2", + "operator": "BE", + "onInstantUsageRules": [ + { + "instant": "preventive", + "usageMethod": "available" + } + ], + "topologicalActions": [ + { + "networkElementId": "NNL2AA1 BBE3AA1 2", + "actionType": "close" + } + ] + }, + { + "id": "PRA_CLOSE_NL2_BE3_3", + "name": "PRA_CLOSE_NL2_BE3_3", + "operator": "BE", + "onInstantUsageRules": [ + { + "instant": "preventive", + "usageMethod": "available" + } + ], + "topologicalActions": [ + { + "networkElementId": "NNL2AA1 BBE3AA1 3", + "actionType": "close" + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/src/test/resources/files/crac/epic91/crac_91_12_17.json b/tests/src/test/resources/files/crac/epic91/crac_91_12_17.json new file mode 100644 index 0000000000..3de4299242 --- /dev/null +++ b/tests/src/test/resources/files/crac/epic91/crac_91_12_17.json @@ -0,0 +1,284 @@ +{ + "type": "CRAC", + "version": "2.0", + "info": "Generated by FARAO http://farao-community.github.io", + "id": "CRAC_91_12_2", + "name": "CRAC_91_12_2", + "instants": [ + { + "id" : "preventive", + "kind" : "PREVENTIVE" + }, + { + "id" : "outage", + "kind" : "OUTAGE" + }, + { + "id" : "curative1", + "kind" : "CURATIVE" + }, + { + "id" : "curative2", + "kind" : "CURATIVE" + }, + { + "id" : "curative3", + "kind" : "CURATIVE" + } + ], + "networkElementsNamePerId": {}, + "contingencies": [ + { + "id": "Contingency DE2 DE3 1", + "networkElementsIds": [ + "DDE2AA1 DDE3AA1 1" + ] + } + ], + "flowCnecs": [ + { + "id": "NNL2AA1 BBE3AA1 1 - preventive", + "name": "NNL2AA1 BBE3AA1 1 - preventive", + "networkElementId": "NNL2AA1 BBE3AA1 1", + "operator": null, + "instant": "preventive", + "optimized": true, + "monitored": false, + "reliabilityMargin": 0.0, + "iMax": [ + 5000.0 + ], + "nominalV": [ + 400.0 + ], + "thresholds": [ + { + "unit": "megawatt", + "min": -800.0, + "max": 800.0, + "side" : "left" + } + ] + }, + { + "id": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - outage", + "name": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - outage", + "networkElementId": "NNL2AA1 BBE3AA1 1", + "contingencyId": "Contingency DE2 DE3 1", + "operator": null, + "instant": "outage", + "optimized": true, + "monitored": false, + "reliabilityMargin": 0.0, + "iMax": [ + 50.0 + ], + "nominalV": [ + 400.0 + ], + "thresholds": [ + { + "unit": "megawatt", + "min": -1000.0, + "max": 1000.0, + "side" : "left" + } + ] + }, + { + "id": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative1", + "name": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative1", + "networkElementId": "NNL2AA1 BBE3AA1 1", + "contingencyId": "Contingency DE2 DE3 1", + "operator": null, + "instant": "curative1", + "optimized": true, + "monitored": false, + "reliabilityMargin": 0.0, + "iMax": [ + 50.0 + ], + "nominalV": [ + 400.0 + ], + "thresholds": [ + { + "unit": "megawatt", + "min": -500.0, + "max": 500.0, + "side" : "left" + } + ] + }, + { + "id": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative2", + "name": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative2", + "networkElementId": "NNL2AA1 BBE3AA1 1", + "contingencyId": "Contingency DE2 DE3 1", + "operator": null, + "instant": "curative2", + "optimized": true, + "monitored": false, + "reliabilityMargin": 0.0, + "iMax": [ + 50.0 + ], + "nominalV": [ + 400.0 + ], + "thresholds": [ + { + "unit": "megawatt", + "min": -300.0, + "max": 300.0, + "side" : "left" + } + ] + }, + { + "id": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative3", + "name": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative3", + "networkElementId": "NNL2AA1 BBE3AA1 1", + "contingencyId": "Contingency DE2 DE3 1", + "operator": null, + "instant": "curative3", + "optimized": true, + "monitored": false, + "reliabilityMargin": 0.0, + "iMax": [ + 50.0 + ], + "nominalV": [ + 400.0 + ], + "thresholds": [ + { + "unit": "megawatt", + "min": -250.0, + "max": 250.0, + "side" : "left" + } + ] + } + ], + "pstRangeActions": [ + { + "id": "PRA_PST_BE", + "name": "PRA_PST_BE", + "operator": "BE", + "onInstantUsageRules": [ + { + "instant": "preventive", + "usageMethod": "available" + } + ], + "networkElementId": "BBE2AA1 BBE3AA1 1", + "initialTap": 0, + "tapToAngleConversionMap": { + "-1": -0.3896097993971608, + "0": 0.0, + "-2": -0.7792105912934298, + "1": 0.3896097993971608, + "-3": -1.1687933694373345, + "2": 0.7792105912934298, + "-4": -1.5583491300758083, + "3": 1.1687933694373345, + "-5": -1.9478688732023104, + "4": 1.5583491300758083, + "-6": -2.337343603803646, + "5": 1.9478688732023104, + "-7": -2.7267643331050597, + "6": 2.337343603803646, + "-8": -3.1161220798131644, + "7": 2.7267643331050597, + "-9": -3.505407871356285, + "8": 3.1161220798131644, + "-10": -3.894612745121778, + "9": 3.505407871356285, + "-11": -4.283727749689918, + "10": 3.894612745121778, + "-12": -4.672743946063913, + "11": 4.283727749689918, + "-13": -5.061652408895631, + "12": 4.672743946063913, + "-14": -5.4504442277066305, + "13": 5.061652408895631, + "-15": -5.839110508104064, + "14": 5.4504442277066305, + "-16": -6.2276423729910535, + "15": 5.839110508104064, + "16": 6.2276423729910535 + }, + "ranges": [ + { + "min": -11, + "max": 16, + "rangeType": "absolute" + } + ] + } + ], + "hvdcRangeActions": [], + "injectionRangeActions": [], + "networkActions": [ + { + "id": "PRA_CLOSE_NL2_BE3_2", + "name": "PRA_CLOSE_NL2_BE3_2", + "operator": "BE", + "onInstantUsageRules": [ + { + "instant": "preventive", + "usageMethod": "available" + } + ], + "topologicalActions": [ + { + "networkElementId": "NNL2AA1 BBE3AA1 2", + "actionType": "close" + } + ] + }, + { + "id": "PRA_CLOSE_NL2_BE3_3", + "name": "PRA_CLOSE_NL2_BE3_3", + "operator": "BE", + "onInstantUsageRules": [ + { + "instant": "preventive", + "usageMethod": "available" + } + ], + "topologicalActions": [ + { + "networkElementId": "NNL2AA1 BBE3AA1 3", + "actionType": "close" + } + ] + }, + { + "id": "Useless_CRA", + "name": "Useless_CRA", + "operator": "BE", + "onInstantUsageRules": [ + { + "instant": "curative1", + "usageMethod": "available" + }, + { + "instant": "curative2", + "usageMethod": "available" + }, + { + "instant": "curative3", + "usageMethod": "available" + } + ], + "topologicalActions": [ + { + "networkElementId": "NNL2AA1 BBE3AA1 3", + "actionType": "open" + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/src/test/resources/files/crac/epic91/crac_91_12_18.json b/tests/src/test/resources/files/crac/epic91/crac_91_12_18.json new file mode 100644 index 0000000000..913d70bdf7 --- /dev/null +++ b/tests/src/test/resources/files/crac/epic91/crac_91_12_18.json @@ -0,0 +1,284 @@ +{ + "type": "CRAC", + "version": "2.0", + "info": "Generated by FARAO http://farao-community.github.io", + "id": "CRAC_91_12_2", + "name": "CRAC_91_12_2", + "instants": [ + { + "id" : "preventive", + "kind" : "PREVENTIVE" + }, + { + "id" : "outage", + "kind" : "OUTAGE" + }, + { + "id" : "curative1", + "kind" : "CURATIVE" + }, + { + "id" : "curative2", + "kind" : "CURATIVE" + }, + { + "id" : "curative3", + "kind" : "CURATIVE" + } + ], + "networkElementsNamePerId": {}, + "contingencies": [ + { + "id": "Contingency DE2 DE3 1", + "networkElementsIds": [ + "DDE2AA1 DDE3AA1 1" + ] + } + ], + "flowCnecs": [ + { + "id": "NNL2AA1 BBE3AA1 1 - preventive", + "name": "NNL2AA1 BBE3AA1 1 - preventive", + "networkElementId": "NNL2AA1 BBE3AA1 1", + "operator": null, + "instant": "preventive", + "optimized": true, + "monitored": false, + "reliabilityMargin": 0.0, + "iMax": [ + 5000.0 + ], + "nominalV": [ + 400.0 + ], + "thresholds": [ + { + "unit": "megawatt", + "min": -800.0, + "max": 800.0, + "side" : "left" + } + ] + }, + { + "id": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - outage", + "name": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - outage", + "networkElementId": "NNL2AA1 BBE3AA1 1", + "contingencyId": "Contingency DE2 DE3 1", + "operator": null, + "instant": "outage", + "optimized": true, + "monitored": false, + "reliabilityMargin": 0.0, + "iMax": [ + 50.0 + ], + "nominalV": [ + 400.0 + ], + "thresholds": [ + { + "unit": "megawatt", + "min": -1000.0, + "max": 1000.0, + "side" : "left" + } + ] + }, + { + "id": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative1", + "name": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative1", + "networkElementId": "NNL2AA1 BBE3AA1 1", + "contingencyId": "Contingency DE2 DE3 1", + "operator": null, + "instant": "curative1", + "optimized": true, + "monitored": false, + "reliabilityMargin": 0.0, + "iMax": [ + 50.0 + ], + "nominalV": [ + 400.0 + ], + "thresholds": [ + { + "unit": "megawatt", + "min": -500.0, + "max": 500.0, + "side" : "left" + } + ] + }, + { + "id": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative2", + "name": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative2", + "networkElementId": "NNL2AA1 BBE3AA1 1", + "contingencyId": "Contingency DE2 DE3 1", + "operator": null, + "instant": "curative2", + "optimized": true, + "monitored": false, + "reliabilityMargin": 0.0, + "iMax": [ + 50.0 + ], + "nominalV": [ + 400.0 + ], + "thresholds": [ + { + "unit": "megawatt", + "min": -300.0, + "max": 300.0, + "side" : "left" + } + ] + }, + { + "id": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative3", + "name": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative3", + "networkElementId": "NNL2AA1 BBE3AA1 1", + "contingencyId": "Contingency DE2 DE3 1", + "operator": null, + "instant": "curative3", + "optimized": true, + "monitored": false, + "reliabilityMargin": 0.0, + "iMax": [ + 50.0 + ], + "nominalV": [ + 400.0 + ], + "thresholds": [ + { + "unit": "megawatt", + "min": -250.0, + "max": 250.0, + "side" : "left" + } + ] + } + ], + "pstRangeActions": [ + { + "id": "PRA_PST_BE", + "name": "PRA_PST_BE", + "operator": "BE", + "onInstantUsageRules": [ + { + "instant": "preventive", + "usageMethod": "available" + } + ], + "networkElementId": "BBE2AA1 BBE3AA1 1", + "initialTap": 0, + "tapToAngleConversionMap": { + "-1": -0.3896097993971608, + "0": 0.0, + "-2": -0.7792105912934298, + "1": 0.3896097993971608, + "-3": -1.1687933694373345, + "2": 0.7792105912934298, + "-4": -1.5583491300758083, + "3": 1.1687933694373345, + "-5": -1.9478688732023104, + "4": 1.5583491300758083, + "-6": -2.337343603803646, + "5": 1.9478688732023104, + "-7": -2.7267643331050597, + "6": 2.337343603803646, + "-8": -3.1161220798131644, + "7": 2.7267643331050597, + "-9": -3.505407871356285, + "8": 3.1161220798131644, + "-10": -3.894612745121778, + "9": 3.505407871356285, + "-11": -4.283727749689918, + "10": 3.894612745121778, + "-12": -4.672743946063913, + "11": 4.283727749689918, + "-13": -5.061652408895631, + "12": 4.672743946063913, + "-14": -5.4504442277066305, + "13": 5.061652408895631, + "-15": -5.839110508104064, + "14": 5.4504442277066305, + "-16": -6.2276423729910535, + "15": 5.839110508104064, + "16": 6.2276423729910535 + }, + "ranges": [ + { + "min": -11, + "max": 16, + "rangeType": "absolute" + } + ] + } + ], + "hvdcRangeActions": [], + "injectionRangeActions": [], + "networkActions": [ + { + "id": "CRA_CLOSE_NL2_BE3_2", + "name": "CRA_CLOSE_NL2_BE3_2", + "operator": "BE", + "onInstantUsageRules": [ + { + "instant": "curative2", + "usageMethod": "available" + } + ], + "topologicalActions": [ + { + "networkElementId": "NNL2AA1 BBE3AA1 2", + "actionType": "close" + } + ] + }, + { + "id": "CRA_CLOSE_NL2_BE3_3", + "name": "CRA_CLOSE_NL2_BE3_3", + "operator": "BE", + "onInstantUsageRules": [ + { + "instant": "curative3", + "usageMethod": "available" + } + ], + "topologicalActions": [ + { + "networkElementId": "NNL2AA1 BBE3AA1 3", + "actionType": "close" + } + ] + }, + { + "id": "Useless_CRA", + "name": "Useless_CRA", + "operator": "BE", + "onInstantUsageRules": [ + { + "instant": "curative1", + "usageMethod": "available" + }, + { + "instant": "curative2", + "usageMethod": "available" + }, + { + "instant": "curative3", + "usageMethod": "available" + } + ], + "topologicalActions": [ + { + "networkElementId": "NNL2AA1 BBE3AA1 3", + "actionType": "open" + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/src/test/resources/files/crac/epic91/crac_91_12_19.json b/tests/src/test/resources/files/crac/epic91/crac_91_12_19.json new file mode 100644 index 0000000000..af3db60a4e --- /dev/null +++ b/tests/src/test/resources/files/crac/epic91/crac_91_12_19.json @@ -0,0 +1,284 @@ +{ + "type": "CRAC", + "version": "2.0", + "info": "Generated by FARAO http://farao-community.github.io", + "id": "CRAC_91_12_2", + "name": "CRAC_91_12_2", + "instants": [ + { + "id" : "preventive", + "kind" : "PREVENTIVE" + }, + { + "id" : "outage", + "kind" : "OUTAGE" + }, + { + "id" : "curative1", + "kind" : "CURATIVE" + }, + { + "id" : "curative2", + "kind" : "CURATIVE" + }, + { + "id" : "curative3", + "kind" : "CURATIVE" + } + ], + "networkElementsNamePerId": {}, + "contingencies": [ + { + "id": "Contingency DE2 DE3 1", + "networkElementsIds": [ + "DDE2AA1 DDE3AA1 1" + ] + } + ], + "flowCnecs": [ + { + "id": "NNL2AA1 BBE3AA1 1 - preventive", + "name": "NNL2AA1 BBE3AA1 1 - preventive", + "networkElementId": "NNL2AA1 BBE3AA1 1", + "operator": null, + "instant": "preventive", + "optimized": true, + "monitored": false, + "reliabilityMargin": 0.0, + "iMax": [ + 5000.0 + ], + "nominalV": [ + 400.0 + ], + "thresholds": [ + { + "unit": "megawatt", + "min": -800.0, + "max": 800.0, + "side" : "left" + } + ] + }, + { + "id": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - outage", + "name": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - outage", + "networkElementId": "NNL2AA1 BBE3AA1 1", + "contingencyId": "Contingency DE2 DE3 1", + "operator": null, + "instant": "outage", + "optimized": true, + "monitored": false, + "reliabilityMargin": 0.0, + "iMax": [ + 50.0 + ], + "nominalV": [ + 400.0 + ], + "thresholds": [ + { + "unit": "megawatt", + "min": -1000.0, + "max": 1000.0, + "side" : "left" + } + ] + }, + { + "id": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative1", + "name": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative1", + "networkElementId": "NNL2AA1 BBE3AA1 1", + "contingencyId": "Contingency DE2 DE3 1", + "operator": null, + "instant": "curative1", + "optimized": true, + "monitored": false, + "reliabilityMargin": 0.0, + "iMax": [ + 50.0 + ], + "nominalV": [ + 400.0 + ], + "thresholds": [ + { + "unit": "megawatt", + "min": -500.0, + "max": 500.0, + "side" : "left" + } + ] + }, + { + "id": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative2", + "name": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative2", + "networkElementId": "NNL2AA1 BBE3AA1 1", + "contingencyId": "Contingency DE2 DE3 1", + "operator": null, + "instant": "curative2", + "optimized": true, + "monitored": false, + "reliabilityMargin": 0.0, + "iMax": [ + 50.0 + ], + "nominalV": [ + 400.0 + ], + "thresholds": [ + { + "unit": "megawatt", + "min": -300.0, + "max": 300.0, + "side" : "left" + } + ] + }, + { + "id": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative3", + "name": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative3", + "networkElementId": "NNL2AA1 BBE3AA1 1", + "contingencyId": "Contingency DE2 DE3 1", + "operator": null, + "instant": "curative3", + "optimized": true, + "monitored": false, + "reliabilityMargin": 0.0, + "iMax": [ + 50.0 + ], + "nominalV": [ + 400.0 + ], + "thresholds": [ + { + "unit": "megawatt", + "min": -250.0, + "max": 250.0, + "side" : "left" + } + ] + } + ], + "pstRangeActions": [ + { + "id": "CRA_PST_BE", + "name": "CRA_PST_BE", + "operator": "BE", + "onInstantUsageRules": [ + { + "instant": "curative1", + "usageMethod": "available" + } + ], + "networkElementId": "BBE2AA1 BBE3AA1 1", + "initialTap": 0, + "tapToAngleConversionMap": { + "-1": -0.3896097993971608, + "0": 0.0, + "-2": -0.7792105912934298, + "1": 0.3896097993971608, + "-3": -1.1687933694373345, + "2": 0.7792105912934298, + "-4": -1.5583491300758083, + "3": 1.1687933694373345, + "-5": -1.9478688732023104, + "4": 1.5583491300758083, + "-6": -2.337343603803646, + "5": 1.9478688732023104, + "-7": -2.7267643331050597, + "6": 2.337343603803646, + "-8": -3.1161220798131644, + "7": 2.7267643331050597, + "-9": -3.505407871356285, + "8": 3.1161220798131644, + "-10": -3.894612745121778, + "9": 3.505407871356285, + "-11": -4.283727749689918, + "10": 3.894612745121778, + "-12": -4.672743946063913, + "11": 4.283727749689918, + "-13": -5.061652408895631, + "12": 4.672743946063913, + "-14": -5.4504442277066305, + "13": 5.061652408895631, + "-15": -5.839110508104064, + "14": 5.4504442277066305, + "-16": -6.2276423729910535, + "15": 5.839110508104064, + "16": 6.2276423729910535 + }, + "ranges": [ + { + "min": -11, + "max": 16, + "rangeType": "absolute" + } + ] + } + ], + "hvdcRangeActions": [], + "injectionRangeActions": [], + "networkActions": [ + { + "id": "PRA_CLOSE_NL2_BE3_2", + "name": "PRA_CLOSE_NL2_BE3_2", + "operator": "BE", + "onInstantUsageRules": [ + { + "instant": "preventive", + "usageMethod": "available" + } + ], + "topologicalActions": [ + { + "networkElementId": "NNL2AA1 BBE3AA1 2", + "actionType": "close" + } + ] + }, + { + "id": "CRA_CLOSE_NL2_BE3_3", + "name": "CRA_CLOSE_NL2_BE3_3", + "operator": "BE", + "onInstantUsageRules": [ + { + "instant": "curative3", + "usageMethod": "available" + } + ], + "topologicalActions": [ + { + "networkElementId": "NNL2AA1 BBE3AA1 3", + "actionType": "close" + } + ] + }, + { + "id": "Useless_CRA", + "name": "Useless_CRA", + "operator": "BE", + "onInstantUsageRules": [ + { + "instant": "curative1", + "usageMethod": "available" + }, + { + "instant": "curative2", + "usageMethod": "available" + }, + { + "instant": "curative3", + "usageMethod": "available" + } + ], + "topologicalActions": [ + { + "networkElementId": "NNL2AA1 BBE3AA1 3", + "actionType": "open" + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/src/test/resources/files/crac/epic91/crac_91_12_20.json b/tests/src/test/resources/files/crac/epic91/crac_91_12_20.json new file mode 100644 index 0000000000..b0c7073e65 --- /dev/null +++ b/tests/src/test/resources/files/crac/epic91/crac_91_12_20.json @@ -0,0 +1,284 @@ +{ + "type": "CRAC", + "version": "2.0", + "info": "Generated by FARAO http://farao-community.github.io", + "id": "CRAC_91_12_2", + "name": "CRAC_91_12_2", + "instants": [ + { + "id" : "preventive", + "kind" : "PREVENTIVE" + }, + { + "id" : "outage", + "kind" : "OUTAGE" + }, + { + "id" : "curative1", + "kind" : "CURATIVE" + }, + { + "id" : "curative2", + "kind" : "CURATIVE" + }, + { + "id" : "curative3", + "kind" : "CURATIVE" + } + ], + "networkElementsNamePerId": {}, + "contingencies": [ + { + "id": "Contingency DE2 DE3 1", + "networkElementsIds": [ + "DDE2AA1 DDE3AA1 1" + ] + } + ], + "flowCnecs": [ + { + "id": "NNL2AA1 BBE3AA1 1 - preventive", + "name": "NNL2AA1 BBE3AA1 1 - preventive", + "networkElementId": "NNL2AA1 BBE3AA1 1", + "operator": null, + "instant": "preventive", + "optimized": true, + "monitored": false, + "reliabilityMargin": 0.0, + "iMax": [ + 5000.0 + ], + "nominalV": [ + 400.0 + ], + "thresholds": [ + { + "unit": "megawatt", + "min": -800.0, + "max": 800.0, + "side" : "left" + } + ] + }, + { + "id": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - outage", + "name": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - outage", + "networkElementId": "NNL2AA1 BBE3AA1 1", + "contingencyId": "Contingency DE2 DE3 1", + "operator": null, + "instant": "outage", + "optimized": true, + "monitored": false, + "reliabilityMargin": 0.0, + "iMax": [ + 50.0 + ], + "nominalV": [ + 400.0 + ], + "thresholds": [ + { + "unit": "megawatt", + "min": -1000.0, + "max": 1000.0, + "side" : "left" + } + ] + }, + { + "id": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative1", + "name": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative1", + "networkElementId": "NNL2AA1 BBE3AA1 1", + "contingencyId": "Contingency DE2 DE3 1", + "operator": null, + "instant": "curative1", + "optimized": true, + "monitored": false, + "reliabilityMargin": 0.0, + "iMax": [ + 50.0 + ], + "nominalV": [ + 400.0 + ], + "thresholds": [ + { + "unit": "megawatt", + "min": -500.0, + "max": 500.0, + "side" : "left" + } + ] + }, + { + "id": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative2", + "name": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative2", + "networkElementId": "NNL2AA1 BBE3AA1 1", + "contingencyId": "Contingency DE2 DE3 1", + "operator": null, + "instant": "curative2", + "optimized": true, + "monitored": false, + "reliabilityMargin": 0.0, + "iMax": [ + 50.0 + ], + "nominalV": [ + 400.0 + ], + "thresholds": [ + { + "unit": "megawatt", + "min": -300.0, + "max": 300.0, + "side" : "left" + } + ] + }, + { + "id": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative3", + "name": "NNL2AA1 BBE3AA1 1 - Contingency DE2 DE3 1 - curative3", + "networkElementId": "NNL2AA1 BBE3AA1 1", + "contingencyId": "Contingency DE2 DE3 1", + "operator": null, + "instant": "curative3", + "optimized": true, + "monitored": false, + "reliabilityMargin": 0.0, + "iMax": [ + 50.0 + ], + "nominalV": [ + 400.0 + ], + "thresholds": [ + { + "unit": "megawatt", + "min": -250.0, + "max": 250.0, + "side" : "left" + } + ] + } + ], + "pstRangeActions": [ + { + "id": "CRA_PST_BE", + "name": "CRA_PST_BE", + "operator": "BE", + "onInstantUsageRules": [ + { + "instant": "curative1", + "usageMethod": "available" + } + ], + "networkElementId": "BBE2AA1 BBE3AA1 1", + "initialTap": 0, + "tapToAngleConversionMap": { + "-1": -0.3896097993971608, + "0": 0.0, + "-2": -0.7792105912934298, + "1": 0.3896097993971608, + "-3": -1.1687933694373345, + "2": 0.7792105912934298, + "-4": -1.5583491300758083, + "3": 1.1687933694373345, + "-5": -1.9478688732023104, + "4": 1.5583491300758083, + "-6": -2.337343603803646, + "5": 1.9478688732023104, + "-7": -2.7267643331050597, + "6": 2.337343603803646, + "-8": -3.1161220798131644, + "7": 2.7267643331050597, + "-9": -3.505407871356285, + "8": 3.1161220798131644, + "-10": -3.894612745121778, + "9": 3.505407871356285, + "-11": -4.283727749689918, + "10": 3.894612745121778, + "-12": -4.672743946063913, + "11": 4.283727749689918, + "-13": -5.061652408895631, + "12": 4.672743946063913, + "-14": -5.4504442277066305, + "13": 5.061652408895631, + "-15": -5.839110508104064, + "14": 5.4504442277066305, + "-16": -6.2276423729910535, + "15": 5.839110508104064, + "16": 6.2276423729910535 + }, + "ranges": [ + { + "min": -11, + "max": 16, + "rangeType": "absolute" + } + ] + } + ], + "hvdcRangeActions": [], + "injectionRangeActions": [], + "networkActions": [ + { + "id": "CRA_CLOSE_NL2_BE3_2", + "name": "CRA_CLOSE_NL2_BE3_2", + "operator": "BE", + "onInstantUsageRules": [ + { + "instant": "curative2", + "usageMethod": "available" + } + ], + "topologicalActions": [ + { + "networkElementId": "NNL2AA1 BBE3AA1 2", + "actionType": "close" + } + ] + }, + { + "id": "PRA_CLOSE_NL2_BE3_3", + "name": "PRA_CLOSE_NL2_BE3_3", + "operator": "BE", + "onInstantUsageRules": [ + { + "instant": "preventive", + "usageMethod": "available" + } + ], + "topologicalActions": [ + { + "networkElementId": "NNL2AA1 BBE3AA1 3", + "actionType": "close" + } + ] + }, + { + "id": "Useless_CRA", + "name": "Useless_CRA", + "operator": "BE", + "onInstantUsageRules": [ + { + "instant": "curative1", + "usageMethod": "available" + }, + { + "instant": "curative2", + "usageMethod": "available" + }, + { + "instant": "curative3", + "usageMethod": "available" + } + ], + "topologicalActions": [ + { + "networkElementId": "NNL2AA1 BBE3AA1 3", + "actionType": "open" + } + ] + } + ] +} \ No newline at end of file From cc4df1702f9e29f357337381342fc02f996de052 Mon Sep 17 00:00:00 2001 From: MartinBelthle Date: Fri, 28 Jun 2024 15:18:15 +0200 Subject: [PATCH 6/8] fix bug on 2P Global Optimization with PST modeled as `APPROXIMATED_INTEGERS` (#1068) fix bug on 2P Global Optimization with PST modeled as `APPROXIMATED_INTEGERS` Signed-off-by: belthlemar --- .../algorithms/fillers/CoreProblemFiller.java | 4 + .../fillers/DiscretePstTapFiller.java | 54 +++- .../linearproblem/LinearProblemBuilder.java | 2 +- .../fillers/DiscretePstGroupFillerTest.java | 2 +- .../fillers/DiscretePstTapFillerTest.java | 36 ++- .../US19_11.feature | 30 ++ .../files/cases/epic19/small-network-2P.uct | 56 ++++ .../epic19/RaoParameters_19_11_9.json | 107 +++++++ .../epic19/RaoParameters_19_11_9_bis.json | 107 +++++++ .../files/crac/epic19/SL_ep19us11case9.json | 303 ++++++++++++++++++ 10 files changed, 682 insertions(+), 19 deletions(-) create mode 100644 tests/src/test/resources/com/powsybl/openrao/tests/features/epic19_specific_rao_parameters/US19_11.feature create mode 100644 tests/src/test/resources/files/cases/epic19/small-network-2P.uct create mode 100644 tests/src/test/resources/files/configurations/epic19/RaoParameters_19_11_9.json create mode 100644 tests/src/test/resources/files/configurations/epic19/RaoParameters_19_11_9_bis.json create mode 100644 tests/src/test/resources/files/crac/epic19/SL_ep19us11case9.json diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/CoreProblemFiller.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/CoreProblemFiller.java index fc92c1100f..3d5eb64bac 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/CoreProblemFiller.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/CoreProblemFiller.java @@ -370,6 +370,8 @@ private List getMinAndMaxAbsoluteAndRelativeSetpoints(RangeAction ran minRelativeTap = Math.max(minRelativeTap, range.getMinTap()); maxRelativeTap = Math.min(maxRelativeTap, range.getMaxTap()); break; + default: + throw new OpenRaoException(String.format("Unsupported range type %s", rangeType)); } } // The taps are not necessarily in order of increasing angle. @@ -398,6 +400,8 @@ private List getMinAndMaxAbsoluteAndRelativeSetpoints(RangeAction ran minRelativeSetpoint = Math.max(minRelativeSetpoint, range.getMin()); maxRelativeSetpoint = Math.min(maxRelativeSetpoint, range.getMax()); break; + default: + throw new OpenRaoException(String.format("Unsupported range type %s", rangeType)); } } } else { diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/DiscretePstTapFiller.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/DiscretePstTapFiller.java index 89e593dc6a..d1531cf72c 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/DiscretePstTapFiller.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/DiscretePstTapFiller.java @@ -9,6 +9,9 @@ import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; +import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; +import com.powsybl.openrao.searchtreerao.commons.RaoUtil; +import com.powsybl.openrao.searchtreerao.commons.optimizationperimeters.OptimizationPerimeter; import com.powsybl.openrao.searchtreerao.linearoptimisation.algorithms.linearproblem.OpenRaoMPConstraint; import com.powsybl.openrao.searchtreerao.linearoptimisation.algorithms.linearproblem.OpenRaoMPVariable; import com.powsybl.openrao.searchtreerao.linearoptimisation.algorithms.linearproblem.LinearProblem; @@ -17,7 +20,9 @@ import com.powsybl.openrao.searchtreerao.result.api.RangeActionSetpointResult; import com.powsybl.openrao.searchtreerao.result.api.SensitivityResult; import com.powsybl.iidm.network.Network; +import org.apache.commons.lang3.tuple.Pair; +import java.util.IntSummaryStatistics; import java.util.Map; import java.util.Set; @@ -27,16 +32,16 @@ public class DiscretePstTapFiller implements ProblemFiller { private final Network network; - private final State optimizedState; + private final OptimizationPerimeter optimizationPerimeter; private final Map> rangeActions; private final RangeActionSetpointResult prePerimeterRangeActionSetpoints; public DiscretePstTapFiller(Network network, - State optimizedState, + OptimizationPerimeter optimizationPerimeter, Map> rangeActions, RangeActionSetpointResult prePerimeterRangeActionSetpoints) { this.network = network; - this.optimizedState = optimizedState; + this.optimizationPerimeter = optimizationPerimeter; this.rangeActions = rangeActions; this.prePerimeterRangeActionSetpoints = prePerimeterRangeActionSetpoints; } @@ -65,12 +70,12 @@ public void updateBetweenMipIteration(LinearProblem linearProblem, RangeActionAc private void buildPstTapVariablesAndConstraints(LinearProblem linearProblem, PstRangeAction pstRangeAction, State state) { // compute a few values on PST taps and angle - double prePerimeterAngle = prePerimeterRangeActionSetpoints.getSetpoint(pstRangeAction); double currentAngle = pstRangeAction.getCurrentSetpoint(network); int currentTap = pstRangeAction.getCurrentTapPosition(network); - int minAdmissibleTap = Math.min(pstRangeAction.convertAngleToTap(pstRangeAction.getMinAdmissibleSetpoint(prePerimeterAngle)), pstRangeAction.convertAngleToTap(pstRangeAction.getMaxAdmissibleSetpoint(prePerimeterAngle))); - int maxAdmissibleTap = Math.max(pstRangeAction.convertAngleToTap(pstRangeAction.getMinAdmissibleSetpoint(prePerimeterAngle)), pstRangeAction.convertAngleToTap(pstRangeAction.getMaxAdmissibleSetpoint(prePerimeterAngle))); + Pair admissibleTaps = getMinAndMaxAdmissibleTaps(pstRangeAction, state); + int minAdmissibleTap = admissibleTaps.getLeft(); + int maxAdmissibleTap = admissibleTaps.getRight(); int maxDownwardTapVariation = Math.max(0, currentTap - minAdmissibleTap); int maxUpwardTapVariation = Math.max(0, maxAdmissibleTap - currentTap); @@ -126,18 +131,16 @@ private void buildPstTapVariablesAndConstraints(LinearProblem linearProblem, Pst private void refineTapToAngleConversionCoefficientAndUpdateBounds(LinearProblem linearProblem, PstRangeAction pstRangeAction, RangeActionActivationResult rangeActionActivationResult, State state) { // compute a few values on PST taps and angle - double newAngle = rangeActionActivationResult.getOptimizedSetpoint(pstRangeAction, optimizedState); - int newTapPosition = rangeActionActivationResult.getOptimizedTap(pstRangeAction, optimizedState); + double newAngle = rangeActionActivationResult.getOptimizedSetpoint(pstRangeAction, state); + int newTapPosition = rangeActionActivationResult.getOptimizedTap(pstRangeAction, state); - double prePerimeterAngle = prePerimeterRangeActionSetpoints.getSetpoint(pstRangeAction); - int minAdmissibleTap = Math.min(pstRangeAction.convertAngleToTap(pstRangeAction.getMinAdmissibleSetpoint(prePerimeterAngle)), pstRangeAction.convertAngleToTap(pstRangeAction.getMaxAdmissibleSetpoint(prePerimeterAngle))); - int maxAdmissibleTap = Math.max(pstRangeAction.convertAngleToTap(pstRangeAction.getMinAdmissibleSetpoint(prePerimeterAngle)), pstRangeAction.convertAngleToTap(pstRangeAction.getMaxAdmissibleSetpoint(prePerimeterAngle))); + Pair admissibleTaps = getMinAndMaxAdmissibleTaps(pstRangeAction, state); + int minAdmissibleTap = admissibleTaps.getLeft(); + int maxAdmissibleTap = admissibleTaps.getRight(); int maxDownwardTapVariation = Math.max(0, newTapPosition - minAdmissibleTap); int maxUpwardTapVariation = Math.max(0, maxAdmissibleTap - newTapPosition); - Map tapToAngleConversionMap = pstRangeAction.getTapToAngleConversionMap(); - // get variables and constraints OpenRaoMPConstraint tapToAngleConversionConstraint = linearProblem.getTapToAngleConversionConstraint(pstRangeAction, state); OpenRaoMPVariable pstTapUpwardVariationVariable = linearProblem.getPstTapVariationVariable(pstRangeAction, state, LinearProblem.VariationDirectionExtension.UPWARD); @@ -153,6 +156,7 @@ private void refineTapToAngleConversionCoefficientAndUpdateBounds(LinearProblem // update coefficients of the constraint with newly calculated ones, except if the tap is already at the limit of the PST range // when updating the MIP, the factors are calibrated on a change of one tap + Map tapToAngleConversionMap = pstRangeAction.getTapToAngleConversionMap(); if (tapToAngleConversionMap.containsKey(newTapPosition + 1)) { double angleToTapUpwardConversionFactor = tapToAngleConversionMap.get(newTapPosition + 1) - tapToAngleConversionMap.get(newTapPosition); tapToAngleConversionConstraint.setCoefficient(pstTapUpwardVariationVariable, -angleToTapUpwardConversionFactor); @@ -167,4 +171,28 @@ private void refineTapToAngleConversionCoefficientAndUpdateBounds(LinearProblem downAuthorizationConstraint.setCoefficient(pstTapDownwardVariationBinary, -maxDownwardTapVariation); upAuthorizationConstraint.setCoefficient(pstTapUpwardVariationBinary, -maxUpwardTapVariation); } + + /** + * Returns min and max admissible taps for a given PST in a given state. + * In the nominal case, it computes these values with the PST ranges and its pre-perimeter setpoint. + * However, in Second Preventive with Global Optimization, we can optimize a PST in both preventive and curative. + * If so, we can't predict the curative limits as they depend on the preventive ones. + * In such a case, we return the network limits. + */ + private Pair getMinAndMaxAdmissibleTaps(PstRangeAction pstRangeAction, State state) { + double prePerimeterAngle = prePerimeterRangeActionSetpoints.getSetpoint(pstRangeAction); + int minTap = pstRangeAction.convertAngleToTap(pstRangeAction.getMinAdmissibleSetpoint(prePerimeterAngle)); + int maxTap = pstRangeAction.convertAngleToTap(pstRangeAction.getMaxAdmissibleSetpoint(prePerimeterAngle)); + int minAdmissibleTap = Math.min(maxTap, minTap); + int maxAdmissibleTap = Math.max(maxTap, minTap); + + Pair, State> lastAvailableRangeAction = RaoUtil.getLastAvailableRangeActionOnSameNetworkElement(optimizationPerimeter, pstRangeAction, state); + if (lastAvailableRangeAction != null) { + Set pstTapsSet = pstRangeAction.getTapToAngleConversionMap().keySet(); + IntSummaryStatistics tapStats = pstTapsSet.stream().mapToInt(k -> k).summaryStatistics(); + minAdmissibleTap = tapStats.getMin(); + maxAdmissibleTap = tapStats.getMax(); + } + return Pair.of(minAdmissibleTap, maxAdmissibleTap); + } } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/LinearProblemBuilder.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/LinearProblemBuilder.java index 34f70ca5b9..479972c97d 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/LinearProblemBuilder.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/LinearProblemBuilder.java @@ -164,7 +164,7 @@ private ProblemFiller buildUnoptimizedCnecFiller() { private ProblemFiller buildIntegerPstTapFiller(Map> pstRangeActions) { return new DiscretePstTapFiller( inputs.getNetwork(), - inputs.getOptimizationPerimeter().getMainOptimizationState(), + inputs.getOptimizationPerimeter(), pstRangeActions, inputs.getPrePerimeterSetpoints() ); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/DiscretePstGroupFillerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/DiscretePstGroupFillerTest.java index 335560a343..8974261478 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/DiscretePstGroupFillerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/DiscretePstGroupFillerTest.java @@ -72,7 +72,7 @@ void testFillAndUpdateMethods() throws IOException { pstRangeActions.put(state, Set.of(pstRa1, pstRa2)); DiscretePstTapFiller discretePstTapFiller = new DiscretePstTapFiller( network, - state, + optimizationPerimeter, pstRangeActions, initialRangeActionSetpointResult); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/DiscretePstTapFillerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/DiscretePstTapFillerTest.java index a1de1ad2d5..ca008cf0ab 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/DiscretePstTapFillerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/DiscretePstTapFillerTest.java @@ -8,6 +8,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.State; +import com.powsybl.openrao.data.cracapi.range.RangeType; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; @@ -29,6 +30,7 @@ import java.util.Map; import java.util.Set; +import static com.powsybl.openrao.data.cracapi.usagerule.UsageMethod.AVAILABLE; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -43,15 +45,30 @@ void testFillAndUpdateMethods() throws IOException { // prepare data init(); State state = crac.getPreventiveState(); - PstRangeAction pstRangeAction = crac.getPstRangeAction(RANGE_ACTION_ID); + State curativeState = crac.getCurativeStates().iterator().next(); Map tapToAngle = pstRangeAction.getTapToAngleConversionMap(); + PstRangeAction cra = crac.newPstRangeAction() + .withId("cra") + .withNetworkElement("BBE2AA1 BBE3AA1 1") + .newOnContingencyStateUsageRule().withUsageMethod(AVAILABLE).withContingency("N-1 NL1-NL3").withInstant("curative").add() + .withInitialTap(0) + .withTapToAngleConversionMap(tapToAngle) + .newTapRange() + .withMinTap(-10) + .withMaxTap(10) + .withRangeType(RangeType.RELATIVE_TO_PREVIOUS_INSTANT) + .add() + .add(); + PstRangeAction pstRangeAction = crac.getPstRangeAction(RANGE_ACTION_ID); double initialAlpha = network.getTwoWindingsTransformer(RANGE_ACTION_ELEMENT_ID).getPhaseTapChanger().getCurrentStep().getAlpha(); - RangeActionSetpointResult initialRangeActionSetpointResult = new RangeActionSetpointResultImpl(Map.of(pstRangeAction, initialAlpha)); + RangeActionSetpointResult initialRangeActionSetpointResult = new RangeActionSetpointResultImpl(Map.of(pstRangeAction, initialAlpha, cra, initialAlpha)); OptimizationPerimeter optimizationPerimeter = Mockito.mock(OptimizationPerimeter.class); Map>> rangeActions = new HashMap<>(); rangeActions.put(state, Set.of(pstRangeAction)); + rangeActions.put(curativeState, Set.of(cra)); Mockito.when(optimizationPerimeter.getRangeActionsPerState()).thenReturn(rangeActions); + Mockito.when(optimizationPerimeter.getMainOptimizationState()).thenReturn(state); RangeActionsOptimizationParameters rangeActionParameters = RangeActionsOptimizationParameters.buildFromRaoParameters(new RaoParameters()); @@ -65,9 +82,10 @@ void testFillAndUpdateMethods() throws IOException { Map> pstRangeActions = new HashMap<>(); pstRangeActions.put(state, Set.of(pstRangeAction)); + pstRangeActions.put(curativeState, Set.of(cra)); DiscretePstTapFiller discretePstTapFiller = new DiscretePstTapFiller( network, - state, + optimizationPerimeter, pstRangeActions, initialRangeActionSetpointResult); @@ -84,6 +102,8 @@ void testFillAndUpdateMethods() throws IOException { OpenRaoMPVariable setpointV = linearProblem.getRangeActionSetpointVariable(pstRangeAction, state); OpenRaoMPVariable variationUpV = linearProblem.getPstTapVariationVariable(pstRangeAction, state, LinearProblem.VariationDirectionExtension.UPWARD); OpenRaoMPVariable variationDownV = linearProblem.getPstTapVariationVariable(pstRangeAction, state, LinearProblem.VariationDirectionExtension.DOWNWARD); + OpenRaoMPVariable craVariationUpV = linearProblem.getPstTapVariationVariable(cra, curativeState, LinearProblem.VariationDirectionExtension.UPWARD); + OpenRaoMPVariable craVariationDownV = linearProblem.getPstTapVariationVariable(cra, curativeState, LinearProblem.VariationDirectionExtension.DOWNWARD); OpenRaoMPVariable binaryUpV = linearProblem.getPstTapVariationBinary(pstRangeAction, state, LinearProblem.VariationDirectionExtension.UPWARD); OpenRaoMPVariable binaryDownV = linearProblem.getPstTapVariationBinary(pstRangeAction, state, LinearProblem.VariationDirectionExtension.DOWNWARD); OpenRaoMPConstraint tapToAngleConversionC = linearProblem.getTapToAngleConversionConstraint(pstRangeAction, state); @@ -103,7 +123,11 @@ void testFillAndUpdateMethods() throws IOException { // check variable bounds assertEquals(0, variationUpV.lb(), 1e-6); + assertEquals(30, variationUpV.ub(), 1e-6); + assertEquals(32, craVariationUpV.ub(), 1e-6); assertEquals(0, variationDownV.lb(), 1e-6); + assertEquals(30, variationDownV.ub(), 1e-6); + assertEquals(32, craVariationDownV.ub(), 1e-6); assertEquals(0, binaryUpV.lb(), 1e-6); assertEquals(1, binaryUpV.ub(), 1e-6); assertEquals(0, binaryDownV.lb(), 1e-6); @@ -131,7 +155,7 @@ void testFillAndUpdateMethods() throws IOException { // update linear problem, with a new PST tap equal to -4 double alphaBeforeUpdate = tapToAngle.get(-4); - RangeActionActivationResult rangeActionActivationResultBeforeUpdate = new RangeActionActivationResultImpl(new RangeActionSetpointResultImpl(Map.of(this.pstRangeAction, alphaBeforeUpdate))); + RangeActionActivationResult rangeActionActivationResultBeforeUpdate = new RangeActionActivationResultImpl(new RangeActionSetpointResultImpl(Map.of(this.pstRangeAction, alphaBeforeUpdate, cra, alphaBeforeUpdate))); discretePstTapFiller.updateBetweenSensiIteration(linearProblem, flowResult, sensitivityResult, rangeActionActivationResultBeforeUpdate); // check tap to angle conversion constraints @@ -141,6 +165,10 @@ void testFillAndUpdateMethods() throws IOException { assertEquals(-(tapToAngle.get(-3) - tapToAngle.get(-4)), tapToAngleConversionC.getCoefficient(variationUpV), 1e-6); assertEquals(-(tapToAngle.get(-5) - tapToAngle.get(-4)), tapToAngleConversionC.getCoefficient(variationDownV), 1e-6); + // checks that variation is only capped by the network limits + assertEquals(32, craVariationUpV.ub(), 1e-6); + assertEquals(32, craVariationDownV.ub(), 1e-6); + // check other constraints assertEquals(0, upVariationC.ub(), 1e-6); assertEquals(1, upVariationC.getCoefficient(variationUpV), 1e-6); diff --git a/tests/src/test/resources/com/powsybl/openrao/tests/features/epic19_specific_rao_parameters/US19_11.feature b/tests/src/test/resources/com/powsybl/openrao/tests/features/epic19_specific_rao_parameters/US19_11.feature new file mode 100644 index 0000000000..c95fb6d88e --- /dev/null +++ b/tests/src/test/resources/com/powsybl/openrao/tests/features/epic19_specific_rao_parameters/US19_11.feature @@ -0,0 +1,30 @@ +# Copyright (c) 2024, 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/. + +Feature: US 19.11: Handle maximum number of elementary actions per TSO + + @fast @rao @second-preventive + Scenario: US.19.11.9: Reference case with optimal solution (no global optimization). + Given network file is "epic19/small-network-2P.uct" + Given crac file is "epic19/SL_ep19us11case9.json" + Given configuration file is "epic19/RaoParameters_19_11_9.json" + When I launch search_tree_rao + Then 1 remedial actions are used in preventive + And the tap of PstRangeAction "pst_be" should be -10 in preventive + And the tap of PstRangeAction "pst_be" should be -16 after "co1_fr2_fr3_1" at "curative" + And the tap of PstRangeAction "pst_fr" should be 13 after "co1_fr2_fr3_1" at "curative" + And the worst margin is -218.5 A + + @fast @rao @second-preventive + Scenario: US.19.11.9.bis: Same case with global optimization: should have the same results + Given network file is "epic19/small-network-2P.uct" + Given crac file is "epic19/SL_ep19us11case9.json" + Given configuration file is "epic19/RaoParameters_19_11_9_bis.json" + When I launch search_tree_rao + Then 1 remedial actions are used in preventive + And the tap of PstRangeAction "pst_be" should be -16 after "co1_fr2_fr3_1" at "curative" + And the tap of PstRangeAction "pst_fr" should be 13 after "co1_fr2_fr3_1" at "curative" + And the worst margin is -218.5 A + diff --git a/tests/src/test/resources/files/cases/epic19/small-network-2P.uct b/tests/src/test/resources/files/cases/epic19/small-network-2P.uct new file mode 100644 index 0000000000..f1b7888e59 --- /dev/null +++ b/tests/src/test/resources/files/cases/epic19/small-network-2P.uct @@ -0,0 +1,56 @@ +##C 2007.05.01 +##N +##ZBE +BBE1AA1 BE1 0 2 400.00 2500.00 0.00000 -1500.0 0.00000 9000.00 -9000.0 9000.00 -9000.0 +BBE2AA1 BE2 0 2 400.00 1000.00 0.00000 -3000.0 0.00000 9000.00 -9000.0 9000.00 -9000.0 +BBE3AA1 BE3 0 2 400.00 1500.00 0.00000 -2500.0 0.00000 9000.00 -9000.0 9000.00 -9000.0 +BBE4AA1 BE4 0 2 400.00 2000.00 0.00000 -2500.0 0.00000 9000.00 -9000.0 9000.00 -9000.0 +##ZDE +DDE1AA1 DE1 0 2 400.00 3500.00 0.00000 -2500.0 0.00000 9000.00 -9000.0 9000.00 -9000.0 +DDE2AA1 DE2 0 2 400.00 3000.00 0.00000 -2000.0 0.00000 9000.00 -9000.0 9000.00 -9000.0 +DDE3AA1 DE3 0 2 400.00 2000.00 0.00000 -1500.0 0.00000 9000.00 -9000.0 9000.00 -9000.0 +DDE4AA1 DE3 0 2 400.00 1000.00 0.00000 -1500.0 0.00000 9000.00 -9000.0 9000.00 -9000.0 +##ZFR +FFR1AA1 FR1 0 2 400.00 1000.00 0.00000 -2000.0 0.00000 9000.00 -9000.0 9000.00 -9000.0 +FFR2AA1 FR2 0 2 400.00 3500.00 0.00000 -2000.0 0.00000 9000.00 -9000.0 9000.00 -9000.0 +FFR3AA1 FR3 0 2 400.00 1500.00 0.00000 -3000.0 0.00000 9000.00 -9000.0 9000.00 -9000.0 +FFR4AA1 FR4 0 2 400.00 2000.00 0.00000 -1000.0 0.00000 9000.00 -9000.0 9000.00 -9000.0 +FFR5AA1 FR5 0 2 400.00 1500.00 0.00000 -1500.0 0.00000 9000.00 -9000.0 9000.00 -9000.0 +##ZNL +NNL1AA1 NL1 0 2 400.00 1000.00 0.00000 -1500.0 0.00000 9000.00 -9000.0 9000.00 -9000.0 +NNL2AA1 NL2 0 2 400.00 1000.00 0.00000 -500.00 0.00000 9000.00 -9000.0 9000.00 -9000.0 +NNL3AA1 NL3 0 2 400.00 2500.00 0.00000 -2000.0 0.00000 9000.00 -9000.0 9000.00 -9000.0 +##L +BBE1AA1 BBE2AA1 1 0 0.0000 10.000 0.000000 2000 +BBE1AA1 BBE3AA1 1 0 0.0000 10.000 0.000000 2000 +BBE1AA1 BBE3AA1 2 0 0.0000 10.000 0.000000 2000 +BBE1AA1 BBE4AA1 1 0 0.0000 0.0050 0.000000 2000 +BBE3AA1 BBE4AA1 1 0 0.0000 10.000 0.000000 2000 +FFR1AA1 FFR2AA1 1 0 0.0000 10.000 0.000000 2000 +FFR1AA1 FFR3AA1 1 0 0.0000 10.000 0.000000 2000 +FFR1AA1 FFR4AA1 1 0 0.0000 10.000 0.000000 2000 +FFR1AA1 FFR5AA1 1 8 0.0000 10.000 0.000000 2000 +FFR2AA1 FFR3AA1 1 0 0.0000 10.000 0.000000 2000 +FFR2AA1 FFR3AA1 2 0 0.0000 10.000 0.000000 2000 +FFR3AA1 FFR5AA1 1 0 0.0000 10.000 0.000000 2000 +DDE1AA1 DDE2AA1 1 0 0.0000 10.000 0.000000 2000 +DDE1AA1 DDE4AA1 1 0 0.0000 10.000 0.000000 2000 +DDE2AA1 DDE3AA1 1 0 0.0000 10.000 0.000000 2000 +DDE3AA1 DDE4AA1 1 7 0.0000 0.0050 0.000000 2000 +NNL1AA1 NNL2AA1 1 0 0.0000 10.000 0.000000 2000 +NNL1AA1 NNL3AA1 1 0 0.0000 10.000 0.000000 2000 +NNL2AA1 NNL3AA1 1 0 0.0000 10.000 0.000000 2000 +FFR4AA1 DDE1AA1 1 0 0.0000 10.000 0.000000 2000 +FFR4AA1 DDE4AA1 1 0 0.0000 10.000 0.000000 2000 +FFR2AA1 DDE3AA1 1 0 0.0000 10.000 0.000000 2000 +DDE2AA1 NNL3AA1 1 0 0.0000 10.000 0.000000 2000 +NNL2AA1 BBE3AA1 1 0 0.0000 10.000 0.000000 2000 +BBE2AA1 FFR3AA1 1 0 0.0000 10.000 0.000000 2000 +BBE1AA1 FFR5AA1 1 0 0.0000 10.000 0.000000 2000 +BBE4AA1 FFR5AA1 1 0 0.0000 10.000 0.000000 2000 +##T +BBE2AA1 BBE3AA1 1 0 400.0 400.0 1000. 0.0000 10.000 0.000000 0.0 2000 PST +FFR2AA1 FFR4AA1 1 0 400.0 400.0 1000. 0.0000 10.000 0.000000 0.0 2000 PST +##R +BBE2AA1 BBE3AA1 1 -0.68 90.00 16 0 SYMM +FFR2AA1 FFR4AA1 1 -0.68 90.00 16 15 SYMM \ No newline at end of file diff --git a/tests/src/test/resources/files/configurations/epic19/RaoParameters_19_11_9.json b/tests/src/test/resources/files/configurations/epic19/RaoParameters_19_11_9.json new file mode 100644 index 0000000000..4e41145898 --- /dev/null +++ b/tests/src/test/resources/files/configurations/epic19/RaoParameters_19_11_9.json @@ -0,0 +1,107 @@ +{ + "version" : "2.4", + "objective-function" : { + "type" : "MAX_MIN_MARGIN_IN_AMPERE", + "forbid-cost-increase" : false, + "curative-min-obj-improvement" : 0.0, + "preventive-stop-criterion" : "MIN_OBJECTIVE", + "curative-stop-criterion" : "MIN_OBJECTIVE" + }, + "range-actions-optimization" : { + "max-mip-iterations" : 5, + "pst-penalty-cost" : 0.01, + "pst-sensitivity-threshold" : 1.0E-6, + "pst-model" : "APPROXIMATED_INTEGERS", + "hvdc-penalty-cost" : 0.001, + "hvdc-sensitivity-threshold" : 1.0E-6, + "injection-ra-penalty-cost" : 0.001, + "injection-ra-sensitivity-threshold" : 1.0E-6, + "linear-optimization-solver" : { + "solver" : "CBC", + "relative-mip-gap" : 1.0E-4, + "solver-specific-parameters" : null + } + }, + "topological-actions-optimization" : { + "max-preventive-search-tree-depth" : 5, + "max-auto-search-tree-depth" : 2, + "max-curative-search-tree-depth" : 5, + "predefined-combinations" : [ ], + "relative-minimum-impact-threshold" : 0.0, + "absolute-minimum-impact-threshold" : 0.0, + "skip-actions-far-from-most-limiting-element" : false, + "max-number-of-boundaries-for-skipping-actions" : 2 + }, + "multi-threading" : { + "contingency-scenarios-in-parallel" : 1, + "preventive-leaves-in-parallel" : 1, + "curative-leaves-in-parallel" : 1 + }, + "second-preventive-rao" : { + "execution-condition" : "COST_INCREASE", + "re-optimize-curative-range-actions" : false, + "hint-from-first-preventive-rao" : false + }, + "not-optimized-cnecs" : { + "do-not-optimize-curative-cnecs-for-tsos-without-cras" : false + }, + "load-flow-and-sensitivity-computation" : { + "load-flow-provider" : "OpenLoadFlow", + "sensitivity-provider" : "OpenLoadFlow", + "sensitivity-failure-overcost" : 100000.0, + "sensitivity-parameters" : { + "version" : "1.0", + "load-flow-parameters" : { + "version" : "1.9", + "voltageInitMode" : "UNIFORM_VALUES", + "transformerVoltageControlOn" : false, + "phaseShifterRegulationOn" : false, + "useReactiveLimits" : true, + "twtSplitShuntAdmittance" : true, + "shuntCompensatorVoltageControlOn" : false, + "readSlackBus" : false, + "writeSlackBus" : true, + "dc" : false, + "distributedSlack" : true, + "balanceType" : "PROPORTIONAL_TO_GENERATION_P", + "dcUseTransformerRatio" : false, + "countriesToBalance" : [ "PL", "NL", "IT", "ES", "BA", "MK", "AT", "ME", "FR", "UA", "AL", "TR", "SK", "CH", "GR", "PT", "BE", "CZ", "HR", "SI", "RO", "RS", "DE", "BG", "HU" ], + "connectedComponentMode" : "MAIN", + "hvdcAcEmulation" : true, + "dcPowerFactor" : 1.0, + "extensions" : { + "open-load-flow-parameters" : { + "slackBusSelectionMode" : "MOST_MESHED", + "slackBusesIds" : [ ], + "slackDistributionFailureBehavior" : "LEAVE_ON_SLACK_BUS", + "voltageRemoteControl" : true, + "lowImpedanceBranchMode" : "REPLACE_BY_ZERO_IMPEDANCE_LINE", + "loadPowerFactorConstant" : false, + "plausibleActivePowerLimit" : 10000.0, + "slackBusPMaxMismatch" : 1.0, + "voltagePerReactivePowerControl" : false, + "maxNewtonRaphsonIterations" : 30, + "newtonRaphsonConvEpsPerEq" : 1.0E-4, + "voltageInitModeOverride" : "NONE", + "transformerVoltageControlMode" : "WITH_GENERATOR_VOLTAGE_CONTROL", + "shuntVoltageControlMode" : "WITH_GENERATOR_VOLTAGE_CONTROL", + "minPlausibleTargetVoltage" : 0.8, + "maxPlausibleTargetVoltage" : 1.2, + "minRealisticVoltage" : 0.5, + "maxRealisticVoltage" : 1.5, + "lowImpedanceThreshold" : 1.0E-8, + "reactiveRangeCheckMode" : "MAX", + "networkCacheEnabled" : false, + "svcVoltageMonitoring" : true, + "stateVectorScalingMode" : "NONE", + "maxSlackBusCount" : 1, + "debugDir" : null, + "incrementalTransformerRatioTapControlOuterLoopMaxTapShift" : 3, + "secondaryVoltageControl" : false, + "reactiveLimitsMaxPqPvSwitch" : 3 + } + } + } + } + } +} \ No newline at end of file diff --git a/tests/src/test/resources/files/configurations/epic19/RaoParameters_19_11_9_bis.json b/tests/src/test/resources/files/configurations/epic19/RaoParameters_19_11_9_bis.json new file mode 100644 index 0000000000..f2b0bb85f6 --- /dev/null +++ b/tests/src/test/resources/files/configurations/epic19/RaoParameters_19_11_9_bis.json @@ -0,0 +1,107 @@ +{ + "version" : "2.4", + "objective-function" : { + "type" : "MAX_MIN_MARGIN_IN_AMPERE", + "forbid-cost-increase" : false, + "curative-min-obj-improvement" : 0.0, + "preventive-stop-criterion" : "MIN_OBJECTIVE", + "curative-stop-criterion" : "MIN_OBJECTIVE" + }, + "range-actions-optimization" : { + "max-mip-iterations" : 5, + "pst-penalty-cost" : 0.01, + "pst-sensitivity-threshold" : 1.0E-6, + "pst-model" : "APPROXIMATED_INTEGERS", + "hvdc-penalty-cost" : 0.001, + "hvdc-sensitivity-threshold" : 1.0E-6, + "injection-ra-penalty-cost" : 0.001, + "injection-ra-sensitivity-threshold" : 1.0E-6, + "linear-optimization-solver" : { + "solver" : "CBC", + "relative-mip-gap" : 1.0E-4, + "solver-specific-parameters" : null + } + }, + "topological-actions-optimization" : { + "max-preventive-search-tree-depth" : 5, + "max-auto-search-tree-depth" : 2, + "max-curative-search-tree-depth" : 5, + "predefined-combinations" : [ ], + "relative-minimum-impact-threshold" : 0.0, + "absolute-minimum-impact-threshold" : 0.0, + "skip-actions-far-from-most-limiting-element" : false, + "max-number-of-boundaries-for-skipping-actions" : 2 + }, + "multi-threading" : { + "contingency-scenarios-in-parallel" : 1, + "preventive-leaves-in-parallel" : 1, + "curative-leaves-in-parallel" : 1 + }, + "second-preventive-rao" : { + "execution-condition" : "COST_INCREASE", + "re-optimize-curative-range-actions" : true, + "hint-from-first-preventive-rao" : false + }, + "not-optimized-cnecs" : { + "do-not-optimize-curative-cnecs-for-tsos-without-cras" : false + }, + "load-flow-and-sensitivity-computation" : { + "load-flow-provider" : "OpenLoadFlow", + "sensitivity-provider" : "OpenLoadFlow", + "sensitivity-failure-overcost" : 100000.0, + "sensitivity-parameters" : { + "version" : "1.0", + "load-flow-parameters" : { + "version" : "1.9", + "voltageInitMode" : "UNIFORM_VALUES", + "transformerVoltageControlOn" : false, + "phaseShifterRegulationOn" : false, + "useReactiveLimits" : true, + "twtSplitShuntAdmittance" : true, + "shuntCompensatorVoltageControlOn" : false, + "readSlackBus" : false, + "writeSlackBus" : true, + "dc" : false, + "distributedSlack" : true, + "balanceType" : "PROPORTIONAL_TO_GENERATION_P", + "dcUseTransformerRatio" : false, + "countriesToBalance" : [ "PL", "NL", "IT", "ES", "BA", "MK", "AT", "ME", "FR", "UA", "AL", "TR", "SK", "CH", "GR", "PT", "BE", "CZ", "HR", "SI", "RO", "RS", "DE", "BG", "HU" ], + "connectedComponentMode" : "MAIN", + "hvdcAcEmulation" : true, + "dcPowerFactor" : 1.0, + "extensions" : { + "open-load-flow-parameters" : { + "slackBusSelectionMode" : "MOST_MESHED", + "slackBusesIds" : [ ], + "slackDistributionFailureBehavior" : "LEAVE_ON_SLACK_BUS", + "voltageRemoteControl" : true, + "lowImpedanceBranchMode" : "REPLACE_BY_ZERO_IMPEDANCE_LINE", + "loadPowerFactorConstant" : false, + "plausibleActivePowerLimit" : 10000.0, + "slackBusPMaxMismatch" : 1.0, + "voltagePerReactivePowerControl" : false, + "maxNewtonRaphsonIterations" : 30, + "newtonRaphsonConvEpsPerEq" : 1.0E-4, + "voltageInitModeOverride" : "NONE", + "transformerVoltageControlMode" : "WITH_GENERATOR_VOLTAGE_CONTROL", + "shuntVoltageControlMode" : "WITH_GENERATOR_VOLTAGE_CONTROL", + "minPlausibleTargetVoltage" : 0.8, + "maxPlausibleTargetVoltage" : 1.2, + "minRealisticVoltage" : 0.5, + "maxRealisticVoltage" : 1.5, + "lowImpedanceThreshold" : 1.0E-8, + "reactiveRangeCheckMode" : "MAX", + "networkCacheEnabled" : false, + "svcVoltageMonitoring" : true, + "stateVectorScalingMode" : "NONE", + "maxSlackBusCount" : 1, + "debugDir" : null, + "incrementalTransformerRatioTapControlOuterLoopMaxTapShift" : 3, + "secondaryVoltageControl" : false, + "reactiveLimitsMaxPqPvSwitch" : 3 + } + } + } + } + } +} \ No newline at end of file diff --git a/tests/src/test/resources/files/crac/epic19/SL_ep19us11case9.json b/tests/src/test/resources/files/crac/epic19/SL_ep19us11case9.json new file mode 100644 index 0000000000..ed4174557a --- /dev/null +++ b/tests/src/test/resources/files/crac/epic19/SL_ep19us11case9.json @@ -0,0 +1,303 @@ +{ + "type" : "CRAC", + "version" : "1.3", + "info" : "Generated by FARAO http://farao-community.github.io", + "id" : "curative_8", + "name" : "curative_8", + "networkElementsNamePerId" : { }, + "contingencies" : [ { + "id" : "co1_fr2_fr3_1", + "networkElementsIds" : [ "FFR2AA1 FFR3AA1 1" ] + } ], + "flowCnecs" : [ { + "id" : "FFR1AA1 FFR4AA1 1 - co1_fr2_fr3_1 - curative", + "name" : "fr1_fr4", + "networkElementId" : "FFR1AA1 FFR4AA1 1", + "operator" : null, + "instant" : "curative", + "contingencyId" : "co1_fr2_fr3_1", + "optimized" : true, + "monitored" : false, + "frm" : 0.0, + "iMax" : [ 2000.0 ], + "nominalV" : [ 400.0 ], + "thresholds" : [ { + "unit" : "ampere", + "min" : -2000.0, + "max" : 2000.0, + "rule" : "onNonRegulatedSide" + } ] + }, { + "id" : "FFR3AA1 FFR5AA1 1 - co1_fr2_fr3_1 - curative", + "name" : "fr3_fr5", + "networkElementId" : "FFR3AA1 FFR5AA1 1", + "operator" : null, + "instant" : "curative", + "contingencyId" : "co1_fr2_fr3_1", + "optimized" : true, + "monitored" : false, + "frm" : 0.0, + "iMax" : [ 2000.0 ], + "nominalV" : [ 400.0 ], + "thresholds" : [ { + "unit" : "ampere", + "min" : -1000.0, + "max" : 1000.0, + "rule" : "onNonRegulatedSide" + } ] + }, { + "id" : "FFR3AA1 FFR5AA1 1 - co1_fr2_fr3_1 - outage", + "name" : "fr3_fr5", + "networkElementId" : "FFR3AA1 FFR5AA1 1", + "operator" : null, + "instant" : "outage", + "contingencyId" : "co1_fr2_fr3_1", + "optimized" : true, + "monitored" : false, + "frm" : 0.0, + "iMax" : [ 2000.0 ], + "nominalV" : [ 400.0 ], + "thresholds" : [ { + "unit" : "ampere", + "min" : -1200.0, + "max" : 1200.0, + "rule" : "onNonRegulatedSide" + } ] + }, { + "id" : "FFR4AA1 DDE1AA1 1 - co1_fr2_fr3_1 - curative", + "name" : "fr4_de1", + "networkElementId" : "FFR4AA1 DDE1AA1 1", + "operator" : null, + "instant" : "curative", + "contingencyId" : "co1_fr2_fr3_1", + "optimized" : true, + "monitored" : false, + "frm" : 0.0, + "iMax" : [ 2000.0 ], + "nominalV" : [ 400.0 ], + "thresholds" : [ { + "unit" : "ampere", + "min" : -1500.0, + "max" : 1500.0, + "rule" : "onNonRegulatedSide" + } ] + }, { + "id" : "FFR4AA1 DDE1AA1 1 - co1_fr2_fr3_1 - outage", + "name" : "fr4_de1", + "networkElementId" : "FFR4AA1 DDE1AA1 1", + "operator" : null, + "instant" : "outage", + "contingencyId" : "co1_fr2_fr3_1", + "optimized" : true, + "monitored" : false, + "frm" : 0.0, + "iMax" : [ 2000.0 ], + "nominalV" : [ 400.0 ], + "thresholds" : [ { + "unit" : "ampere", + "min" : -1700.0, + "max" : 1700.0, + "rule" : "onNonRegulatedSide" + } ] + }, { + "id" : "FFR4AA1 DDE1AA1 1 - preventive", + "name" : "fr4_de1", + "networkElementId" : "FFR4AA1 DDE1AA1 1", + "operator" : null, + "instant" : "preventive", + "optimized" : true, + "monitored" : false, + "frm" : 0.0, + "iMax" : [ 2000.0 ], + "nominalV" : [ 400.0 ], + "thresholds" : [ { + "unit" : "ampere", + "min" : -1500.0, + "max" : 1500.0, + "rule" : "onNonRegulatedSide" + } ] + }, { + "id" : "NNL2AA1 BBE3AA1 1 - preventive", + "name" : "nl2_be3", + "networkElementId" : "NNL2AA1 BBE3AA1 1", + "operator" : null, + "instant" : "preventive", + "optimized" : true, + "monitored" : false, + "frm" : 0.0, + "iMax" : [ 2000.0 ], + "nominalV" : [ 400.0 ], + "thresholds" : [ { + "unit" : "ampere", + "min" : -5000.0, + "max" : 5000.0, + "rule" : "onNonRegulatedSide" + } ] + } ], + "pstRangeActions" : [ { + "id" : "pst_be", + "name" : "pst_be", + "operator" : "be", + "onInstantUsageRules" : [ { + "instant" : "preventive", + "usageMethod" : "available" + }, { + "instant" : "curative", + "usageMethod" : "available" + } ], + "networkElementId" : "BBE2AA1 BBE3AA1 1", + "initialTap" : 0, + "tapToAngleConversionMap" : { + "-1" : -0.3896097993971608, + "0" : 0.0, + "-2" : -0.7792105912934298, + "1" : 0.3896097993971608, + "-3" : -1.1687933694373345, + "2" : 0.7792105912934298, + "-4" : -1.5583491300758083, + "3" : 1.1687933694373345, + "-5" : -1.9478688732023104, + "4" : 1.5583491300758083, + "-6" : -2.337343603803646, + "5" : 1.9478688732023104, + "-7" : -2.7267643331050597, + "6" : 2.337343603803646, + "-8" : -3.1161220798131644, + "7" : 2.7267643331050597, + "-9" : -3.505407871356285, + "8" : 3.1161220798131644, + "-10" : -3.894612745121778, + "9" : 3.505407871356285, + "-11" : -4.283727749689918, + "10" : 3.894612745121778, + "-12" : -4.672743946063913, + "11" : 4.283727749689918, + "-13" : -5.061652408895631, + "12" : 4.672743946063913, + "-14" : -5.4504442277066305, + "13" : 5.061652408895631, + "-15" : -5.839110508104064, + "14" : 5.4504442277066305, + "-16" : -6.2276423729910535, + "15" : 5.839110508104064, + "16" : 6.2276423729910535 + }, + "ranges" : [ { + "min" : -10, + "max" : 0, + "rangeType" : "relativeToPreviousInstant" + } ] + }, { + "id" : "pst_fr", + "name" : "pst_fr", + "operator" : "fr", + "onInstantUsageRules" : [ { + "instant" : "curative", + "usageMethod" : "available" + } ], + "networkElementId" : "FFR2AA1 FFR4AA1 1", + "initialTap" : 15, + "tapToAngleConversionMap" : { + "-1" : -0.3896097993971608, + "0" : 0.0, + "-2" : -0.7792105912934298, + "1" : 0.3896097993971608, + "-3" : -1.1687933694373345, + "2" : 0.7792105912934298, + "-4" : -1.5583491300758083, + "3" : 1.1687933694373345, + "-5" : -1.9478688732023104, + "4" : 1.5583491300758083, + "-6" : -2.337343603803646, + "5" : 1.9478688732023104, + "-7" : -2.7267643331050597, + "6" : 2.337343603803646, + "-8" : -3.1161220798131644, + "7" : 2.7267643331050597, + "-9" : -3.505407871356285, + "8" : 3.1161220798131644, + "-10" : -3.894612745121778, + "9" : 3.505407871356285, + "-11" : -4.283727749689918, + "10" : 3.894612745121778, + "-12" : -4.672743946063913, + "11" : 4.283727749689918, + "-13" : -5.061652408895631, + "12" : 4.672743946063913, + "-14" : -5.4504442277066305, + "13" : 5.061652408895631, + "-15" : -5.839110508104064, + "14" : 5.4504442277066305, + "-16" : -6.2276423729910535, + "15" : 5.839110508104064, + "16" : 6.2276423729910535 + }, + "ranges" : [ { + "min" : 13, + "max" : 15, + "rangeType" : "absolute" + } ] } ], + "hvdcRangeActions" : [ ], + "injectionRangeActions" : [ ], + "networkActions" : [ { + "id" : "close_de3_de4", + "name" : "close_de3_de4", + "operator" : "de", + "freeToUseUsageRules" : [ { + "instant" : "preventive", + "usageMethod" : "available" + } ], + "topologicalActions" : [ { + "networkElementId" : "DDE3AA1 DDE4AA1 1", + "actionType" : "open" + } ] + }, { + "id" : "close_fr1_fr5", + "name" : "close_fr1_fr5", + "operator" : "fr", + "freeToUseUsageRules" : [ { + "instant" : "preventive", + "usageMethod" : "available" + } ], + "topologicalActions" : [ { + "networkElementId" : "FFR1AA1 FFR5AA1 1", + "actionType" : "close" + } ] + }, { + "id" : "open_be1_be4", + "name" : "open_be1_be4", + "operator" : "be", + "freeToUseUsageRules" : [ { + "instant" : "preventive", + "usageMethod" : "available" + } ], + "topologicalActions" : [ { + "networkElementId" : "BBE1AA1 BBE4AA1 1", + "actionType" : "open" + } ] + }, { + "id" : "open_fr1_fr2", + "name" : "open_fr1_fr2", + "operator" : "fr", + "freeToUseUsageRules" : [ { + "instant" : "preventive", + "usageMethod" : "available" + } ], + "topologicalActions" : [ { + "networkElementId" : "FFR1AA1 FFR2AA1 1", + "actionType" : "open" + } ] + }, { + "id" : "open_fr1_fr3", + "name" : "open_fr1_fr3", + "operator" : "fr", + "freeToUseUsageRules" : [ { + "instant" : "curative", + "usageMethod" : "available" + } ], + "topologicalActions" : [ { + "networkElementId" : "FFR1AA1 FFR3AA1 1", + "actionType" : "close" + } ] + } ] +} \ No newline at end of file From 3db43e04d93b5835f272835b9f960616511f4a28 Mon Sep 17 00:00:00 2001 From: WalAmeni <42716685+WalAmeni@users.noreply.github.com> Date: Tue, 2 Jul 2024 14:05:21 +0200 Subject: [PATCH 7/8] Update timeInterval for SWE CNE header (#1075) --- .../java/com/powsybl/openrao/data/swecneexporter/SweCne.java | 1 - 1 file changed, 1 deletion(-) diff --git a/data/result-exporter/swe-cne-exporter/src/main/java/com/powsybl/openrao/data/swecneexporter/SweCne.java b/data/result-exporter/swe-cne-exporter/src/main/java/com/powsybl/openrao/data/swecneexporter/SweCne.java index 482f97720e..d8af452874 100644 --- a/data/result-exporter/swe-cne-exporter/src/main/java/com/powsybl/openrao/data/swecneexporter/SweCne.java +++ b/data/result-exporter/swe-cne-exporter/src/main/java/com/powsybl/openrao/data/swecneexporter/SweCne.java @@ -85,7 +85,6 @@ private void fillHeader(OffsetDateTime offsetDateTime) { marketDocument.setReceiverMarketParticipantMRID(createPartyIDString(A01_CODING_SCHEME, sweCneHelper.getExporterParameters().getReceiverId())); marketDocument.setReceiverMarketParticipantMarketRoleType(sweCneHelper.getExporterParameters().getReceiverRole().getCode()); marketDocument.setCreatedDateTime(createXMLGregorianCalendarNow()); - marketDocument.setTimePeriodTimeInterval(createEsmpDateTimeIntervalForWholeDay(sweCneHelper.getExporterParameters().getTimeInterval())); marketDocument.setTimePeriodTimeInterval(SweCneUtil.createEsmpDateTimeInterval(offsetDateTime)); } From 1a23e48c1b57228e1552bad0adb609c16a554bde Mon Sep 17 00:00:00 2001 From: MartinBelthle Date: Tue, 2 Jul 2024 17:22:56 +0200 Subject: [PATCH 8/8] fix broken links in doc (#1072) --- docs/README.md | 2 +- docs/castor.md | 18 +++++++------- docs/castor/applications.md | 2 +- docs/castor/linear-problem.md | 8 +++---- .../continuous-range-action-group-filler.md | 2 +- .../linear-problem/core-problem-filler.md | 10 ++++---- .../discrete-pst-group-filler.md | 2 +- .../linear-problem/discrete-pst-tap-filler.md | 2 +- .../linear-problem/max-loop-flow-filler.md | 24 +++++++++---------- .../linear-problem/max-min-margin-filler.md | 8 +++---- .../max-min-relative-margin-filler.md | 8 +++---- docs/castor/linear-problem/mnec-filler.md | 12 +++++----- .../linear-problem/ra-usage-limits-filler.md | 2 +- .../unoptimized-cnec-filler-cra.md | 6 ++--- .../monitoring/angle-monitoring/algorithm.md | 2 +- .../monitoring/angle-monitoring/java-api.md | 8 +++---- .../monitoring/angle-monitoring/result.md | 8 +++---- .../voltage-monitoring/algorithm.md | 2 +- .../monitoring/voltage-monitoring/java-api.md | 2 +- .../monitoring/voltage-monitoring/result.md | 8 +++---- docs/castor/performance.md | 6 ++--- docs/castor/rao-steps.md | 4 ++-- .../do-not-optimize-specific-cnecs.md | 2 +- docs/castor/special-features/loop-flows.md | 6 ++--- docs/input-data.md | 12 +++++----- docs/input-data/crac.md | 4 ++-- docs/input-data/crac/creation-context.md | 4 ++-- docs/input-data/crac/creation-parameters.md | 6 ++--- docs/input-data/crac/cse.md | 2 +- docs/input-data/crac/json.md | 12 +++++----- docs/output-data.md | 6 ++--- docs/output-data/core-cne/cnec-results.md | 4 ++-- docs/output-data/core-cne/header.md | 2 +- docs/output-data/core-cne/introduction.md | 6 ++--- docs/output-data/core-cne/java-api.md | 6 ++--- docs/output-data/rao-logs.md | 8 +++---- docs/output-data/rao-logs/example.md | 12 +++++----- docs/output-data/rao-result.md | 2 +- docs/output-data/rao-result/angle-cnecs.md | 4 ++-- docs/output-data/rao-result/steps.md | 4 ++-- docs/output-data/rao-result/voltage-cnecs.md | 4 ++-- docs/output-data/swe-cne/cnec-results.md | 6 ++--- docs/output-data/swe-cne/header.md | 2 +- docs/output-data/swe-cne/introduction.md | 6 ++--- docs/output-data/swe-cne/java-api.md | 10 ++++---- docs/output-data/swe-cne/ra-results.md | 2 +- docs/parameters.md | 8 +++---- docs/tutorial.md | 6 ++--- 48 files changed, 146 insertions(+), 146 deletions(-) diff --git a/docs/README.md b/docs/README.md index 85b1ea8185..9e448ded10 100644 --- a/docs/README.md +++ b/docs/README.md @@ -6,7 +6,7 @@ They are published on https://powsybl.readthedocs.org/projects/openrao and pull ### Readthedocs & Sphinx The website is hosted on [readthedocs](https://readthedocs.org/). The build workflow requires a configuration file: -[.readthedocs.yml](./.readthedocs.yml). This platform presents many advantages, +[.readthedocs.yml](./.readthedocs.yaml). This platform presents many advantages, thanks to its workflow of automatic branch/tag building & publication: - Multiple versions are activated: you can browse different versions of the documentation for different releases of OpenRAO - Pull requests are built automatically and the build status is reported in the PR's checks (["Build documentation" workflow](../.github/workflows/build_doc.yml)). diff --git a/docs/castor.md b/docs/castor.md index a843240d83..36c2ace10e 100644 --- a/docs/castor.md +++ b/docs/castor.md @@ -16,7 +16,7 @@ Unlike purely linear optimisation, a search-tree algorithm does not neglect the So far, the search-tree algorithm has proved for many years its relevance and efficiency on current daily operational processes on CWE, Northern Italy and SWE Capacity calculation. -For each topological remedial action applied, the search-tree will systematically optimise PST taps & HVDC setpoints by applying a [linear optimisation](/castor/linear-problem/linear-rao.md). By considering both topological remedial actions and linear remedial actions at every step, instead of considering only one after the other, CASTOR's results are optimal. +For each topological remedial action applied, the search-tree will systematically optimise PST taps & HVDC setpoints by applying a [linear optimisation](./castor/linear-problem.md). By considering both topological remedial actions and linear remedial actions at every step, instead of considering only one after the other, CASTOR's results are optimal. The optimisation problem is a non-convex and non-linear one, dealing with topology changes on the network, which represent discrete actions by definition. The problem treated by the optimiser is a combinatorial problem. Search-tree algorithms are commonly used for high complexity mathematical problems, containing combinatorial and discrete aspects. @@ -26,7 +26,7 @@ Some remedial actions such as PSTs & HVDCs are treated via a linear optimisation A search-tree algorithm will optimise all couples of critical branches and critical outages to define a set of remedial actions covering all these network states. This limits the impact of net position forecasts, which are highly uncertain because of the uncertainty in the power generation forecasts (renewables, unforeseeable events...). -For example, let’s assume there that is no available preventive remedial action (for simplicity) and focus on the [CNEC](/input-data/crac/introduction.md#cnec) with the minimum relative margin (let's call it CNE1C1). +For example, let’s assume there that is no available preventive remedial action (for simplicity) and focus on the [CNEC](./input-data/crac.md#cnec) with the minimum relative margin (let's call it CNE1C1). The optimiser will search for a curative remedial action increasing margin of CNE1C1. However, considering only CNE1C1 could be relevant if, and only if, the net position forecast is highly reliable and accurate. As stated before, this could not be acceptable for the security of the system. That is why the search tree will also identify optimised remedial actions for CNE1C2, CNE1C3… ## Remedial actions considered @@ -40,7 +40,7 @@ For Capacity calculation processes, CASTOR considers the following remedial acti The impact of some types of remedial actions on flows could be considered to be linear: optimisation of HVDC setpoints and optimisation of generation unit setpoints. In addition to these, CASTOR also considers phase shifter transformers as linear remedial actions.[^1] -[^1]: CASTOR offers different approximation levels for modelling PSTs. See [the relevant RAO parameter](/parameters/parameters.md#pst-model) for more information. +[^1]: CASTOR offers different approximation levels for modelling PSTs. See [the relevant RAO parameter](parameters.md#pst-model) for more information. A phase shifter transformer (PST) is defined by its range of acceptable tap settings. This acceptable tap setting can be defined by three different ways: @@ -62,7 +62,7 @@ As a matter of clarification, connecting/disconnecting a generation unit can als ### For Flow-based Capacity calculation – minimum margin The objective function is used to determine at each step of the search tree which remedial action is the best. -A variant of it is also used when solving the [linear optimisation problem](/castor/linear-problem/linear-rao.md). +A variant of it is also used when solving the [linear optimisation problem](./castor/linear-problem.md). The active flow $F_i$ on a CNEC $i$ is: @@ -116,7 +116,7 @@ This algorithm acts on sets of states that share common remedial actions, also c The main inputs of the algorithm are: - the [network](/input-data/network.md) at the root of the perimeter, -- an extract of the original [CRAC](/input-data/crac/introduction.md), containing only the remedial actions that are available in the given perimeter (filtered on usage rules). +- an extract of the original [CRAC](./input-data/crac.md), containing only the remedial actions that are available in the given perimeter (filtered on usage rules). ## Stop criterion @@ -129,9 +129,9 @@ As mentioned above, for NTC Capacity calculation/ CEP Validation, this stop crit These stop criteria only make sense for a minimum margin objective function (may it be absolute or relative). -On both stop criteria, [additional constraints](/parameters/parameters.md#network-actions-optimisation-parameters) can be added, for example: -- the maximal number of consecutive chosen network actions, also called search tree depth (for [preventive](/parameters/parameters.md#max-preventive-search-tree-depth), [auto](/parameters/parameters.md#max-auto-search-tree-depth) and [curative](/parameters/parameters.md#max-curative-search-tree-depth) search trees), -- the [minimal relative gain](/parameters/parameters.md#relative-minimum-impact-threshold) of objective function between two consecutive network actions (i.e. between two search tree depths). +On both stop criteria, [additional constraints](parameters.md#network-actions-optimisation-parameters) can be added, for example: +- the maximal number of consecutive chosen network actions, also called search tree depth (for [preventive](parameters.md#max-preventive-search-tree-depth), [auto](parameters.md#max-auto-search-tree-depth) and [curative](parameters.md#max-curative-search-tree-depth) search trees), +- the [minimal relative gain](parameters.md#relative-minimum-impact-threshold) of objective function between two consecutive network actions (i.e. between two search tree depths). ## Algorithm @@ -140,7 +140,7 @@ On both stop criteria, [additional constraints](/parameters/parameters.md#networ For each iteration/step (a level of depth in tree): - Determination of available remedial actions. - Once the list of available remedial actions is defined, candidates are created. Each candidate corresponds to a grid situation, where one (or more) remedial actions are applied. -- A skippable [optimisation of the linear remedial](/castor/linear-problem/linear-rao.md) actions is done. +- A skippable [optimisation of the linear remedial](./castor/linear-problem.md) actions is done. - A security analysis determines for each candidate the value of the objective function. The security analysis consists of a series of DC (or AC) load-flow computations (for each defined contingency). - In order to maximise the objective function, values obtained for each candidate are compared: the candidate leading to the best increase of objective function value is selected. The remedial actions corresponding to this candidate are applied. diff --git a/docs/castor/applications.md b/docs/castor/applications.md index 9cd15f7992..66f66855a0 100644 --- a/docs/castor/applications.md +++ b/docs/castor/applications.md @@ -1,7 +1,7 @@ # Operational applications Many operational applications involve optimising remedial actions for critical network elements; and these applications often need to achieve different goals. -The OpenRAO Toolbox can be used in a variety of cases thanks to the large scope of features it covers; its behaviour can be tuned using [configuration parameters](/parameters/parameters.md). +The OpenRAO Toolbox can be used in a variety of cases thanks to the large scope of features it covers; its behaviour can be tuned using [configuration parameters](/parameters.md). You can find examples of usages for OpenRAO below. diff --git a/docs/castor/linear-problem.md b/docs/castor/linear-problem.md index 054e49c1c1..09927cd639 100644 --- a/docs/castor/linear-problem.md +++ b/docs/castor/linear-problem.md @@ -23,13 +23,13 @@ of the remedial actions on the network flows with linear sensitivity coefficient It therefore solves linear optimisation problems to find the optimal set-points for the remedial actions. Moreover, it can iterate over several reference points in order to mitigate the linear approximation inherent to its optimisation problem. -In particular, the Linear RAO module is used in [CASTOR](/castor/search-tree-rao.md). +In particular, the Linear RAO module is used in [CASTOR](/castor.md#algorithm). ## Inputs The main inputs of the algorithm are: - the network of the "initial situation", where the remedial actions are supposed to be at their "initial position", -- an extract of the original [CRAC](/input-data/crac/introduction.md), containing only the range actions to be optimised. +- an extract of the original [CRAC](/input-data/crac.md), containing only the range actions to be optimised. ## Outputs @@ -54,7 +54,7 @@ CASTOR can be configured to define groups of "aligned" LRAs whose taps should be ### Minimum impact of a LRA in the linear optimisation -In order to control the usage of LRAs in the optimisation, it is possible to set a constraint in the optimisation problem: the change in set-point value of one particular LRA should not have an impact on the objective function smaller than a configurable value (see [pst-sensitivity-threshold](/parameters/parameters.md#pst-sensitivity-threshold), [hvdc-sensitivity-threshold](/parameters/parameters.md#hvdc-sensitivity-threshold), and [injection-ra-sensitivity-threshold](/parameters/parameters.md#injection-ra-sensitivity-threshold)). +In order to control the usage of LRAs in the optimisation, it is possible to set a constraint in the optimisation problem: the change in set-point value of one particular LRA should not have an impact on the objective function smaller than a configurable value (see [pst-sensitivity-threshold](/parameters.md#pst-sensitivity-threshold), [hvdc-sensitivity-threshold](/parameters.md#hvdc-sensitivity-threshold), and [injection-ra-sensitivity-threshold](/parameters.md#injection-ra-sensitivity-threshold)). When computing the LRA sensitivities, only the ones which are higher than these parameters are considered and the others are considered zero. This allows us to filter out the PSTs which don't have a big enough impact on the CNECs. @@ -64,7 +64,7 @@ $$\begin{equation} \max MM - \sum_{lra \in \mathcal{LRA}} \Delta_{lra} c^{LRA} \end{equation}$$ -with $MM$ the minimum margin, $\mathcal{LRA}$ the set of LRAs, $\Delta_{lra}$ the variation of setpoint of the LRA $lra$, and $c^{LRA}$ the penalty cost (see [pst-penalty-cost](/parameters/parameters.md#pst-penalty-cost), [hvdc-penalty-cost](/parameters/parameters.md#hvdc-penalty-cost), and [injection-ra-penalty-cost](/parameters/parameters.md#injection-ra-penalty-cost)). +with $MM$ the minimum margin, $\mathcal{LRA}$ the set of LRAs, $\Delta_{lra}$ the variation of setpoint of the LRA $lra$, and $c^{LRA}$ the penalty cost (see [pst-penalty-cost](/parameters.md#pst-penalty-cost), [hvdc-penalty-cost](/parameters.md#hvdc-penalty-cost), and [injection-ra-penalty-cost](/parameters.md#injection-ra-penalty-cost)). This way, if two solutions provide (almost) the same minimum margin, the problem will favor the one that changes the setpoints the least. diff --git a/docs/castor/linear-problem/continuous-range-action-group-filler.md b/docs/castor/linear-problem/continuous-range-action-group-filler.md index a1a4c8b452..59e7fc6314 100644 --- a/docs/castor/linear-problem/continuous-range-action-group-filler.md +++ b/docs/castor/linear-problem/continuous-range-action-group-filler.md @@ -10,7 +10,7 @@ | Name | Details | |--------------------------------------------------|--------------------------------------------------------------------| -| [pst-model](/parameters/parameters.md#pst-model) | This filler is used only if this parameters is set to *CONTINUOUS* | +| [pst-model](/parameters.md#pst-model) | This filler is used only if this parameters is set to *CONTINUOUS* | ## Defined optimization variables diff --git a/docs/castor/linear-problem/core-problem-filler.md b/docs/castor/linear-problem/core-problem-filler.md index 760ca602f2..39d58ced1d 100644 --- a/docs/castor/linear-problem/core-problem-filler.md +++ b/docs/castor/linear-problem/core-problem-filler.md @@ -18,10 +18,10 @@ ## Used parameters -| Name | Symbol | Details | Source | -|----------------------|--------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| sensitivityThreshold | | Set to zero the sensitivities of RangeActions below this threshold; thus avoiding the activation of RangeActions which have too small an impact on the flows (can also be achieved with penaltyCost). This simplifies & speeds up the resolution of the optimization problem (can be necessary when the problem contains integer variables). However, it also adds an approximation in the computation of the flows within the MILP, which can be tricky to handle when the MILP contains hard constraints on loop-flows or monitored FlowCnecs. | Equal to [pst-sensitivity-threshold](/parameters/parameters.md#pst-sensitivity-threshold) for PSTs, [hvdc-sensitivity-threshold](/parameters/parameters.md#hvdc-sensitivity-threshold) for HVDCs, and [injection-ra-sensitivity-threshold](/parameters/parameters.md#injection-ra-sensitivity-threshold) for injection range actions | -| penaltyCost | $c^{penalty}_{ra}$ | Supposedly a small penalization, in the use of the RangeActions. When several solutions are equivalent, this favours the one with the least change in the RangeActions' setpoints (compared to the initial situation). It also avoids the activation of RangeActions which have to small an impact on the objective function. | Equal to [pst-penalty-cost](/parameters/parameters.md#pst-penalty-cost) for PSTs, [hvdc-penalty-cost](/parameters/parameters.md#hvdc-penalty-cost) for HVDCs, and [injection-ra-penalty-cost](/parameters/parameters.md#injection-ra-penalty-cost) for injection range actions | +| Name | Symbol | Details | Source | +|----------------------|--------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| sensitivityThreshold | | Set to zero the sensitivities of RangeActions below this threshold; thus avoiding the activation of RangeActions which have too small an impact on the flows (can also be achieved with penaltyCost). This simplifies & speeds up the resolution of the optimization problem (can be necessary when the problem contains integer variables). However, it also adds an approximation in the computation of the flows within the MILP, which can be tricky to handle when the MILP contains hard constraints on loop-flows or monitored FlowCnecs. | Equal to [pst-sensitivity-threshold](/parameters.md#pst-sensitivity-threshold) for PSTs, [hvdc-sensitivity-threshold](/parameters.md#hvdc-sensitivity-threshold) for HVDCs, and [injection-ra-sensitivity-threshold](/parameters.md#injection-ra-sensitivity-threshold) for injection range actions | +| penaltyCost | $c^{penalty}_{ra}$ | Supposedly a small penalization, in the use of the RangeActions. When several solutions are equivalent, this favours the one with the least change in the RangeActions' setpoints (compared to the initial situation). It also avoids the activation of RangeActions which have to small an impact on the objective function. | Equal to [pst-penalty-cost](/parameters.md#pst-penalty-cost) for PSTs, [hvdc-penalty-cost](/parameters.md#hvdc-penalty-cost) for HVDCs, and [injection-ra-penalty-cost](/parameters.md#injection-ra-penalty-cost) for injection range actions | ## Defined optimization variables @@ -72,7 +72,7 @@ range actions exists, then $A(r,s') = \alpha_{0}(r)$ ### Shrinking the allowed range -If parameter [ra-range-shrinking](/parameters/parameters.md#ra-range-shrinking) is enabled, the allowed range for range actions +If parameter [ra-range-shrinking](/parameters.md#ra-range-shrinking) is enabled, the allowed range for range actions is shrunk after each iteration according to the following constraints: $$ diff --git a/docs/castor/linear-problem/discrete-pst-group-filler.md b/docs/castor/linear-problem/discrete-pst-group-filler.md index 1ae5e6fbd7..75e96ab51d 100644 --- a/docs/castor/linear-problem/discrete-pst-group-filler.md +++ b/docs/castor/linear-problem/discrete-pst-group-filler.md @@ -11,7 +11,7 @@ | Name | Details | |--------------------------------------------------|-------------------------------------------------------------------------------| -| [pst-model](/parameters/parameters.md#pst-model) | This filler is used only if this parameters is set to *APPROXIMATED_INTEGERS* | +| [pst-model](/parameters.md#pst-model) | This filler is used only if this parameters is set to *APPROXIMATED_INTEGERS* | ## Defined optimization variables diff --git a/docs/castor/linear-problem/discrete-pst-tap-filler.md b/docs/castor/linear-problem/discrete-pst-tap-filler.md index c6b2885ffa..000750cc2a 100644 --- a/docs/castor/linear-problem/discrete-pst-tap-filler.md +++ b/docs/castor/linear-problem/discrete-pst-tap-filler.md @@ -19,7 +19,7 @@ information [here](/input-data/crac/json.md#range-actions)) | Name | Details | |--------------------------------------------------|-------------------------------------------------------------------------------| -| [pst-model](/parameters/parameters.md#pst-model) | This filler is used only if this parameters is set to *APPROXIMATED_INTEGERS* | +| [pst-model](/parameters.md#pst-model) | This filler is used only if this parameters is set to *APPROXIMATED_INTEGERS* | ## Defined optimization variables diff --git a/docs/castor/linear-problem/max-loop-flow-filler.md b/docs/castor/linear-problem/max-loop-flow-filler.md index 05806d3502..d48eb6447b 100644 --- a/docs/castor/linear-problem/max-loop-flow-filler.md +++ b/docs/castor/linear-problem/max-loop-flow-filler.md @@ -2,24 +2,24 @@ ## Used input data -| Name | Symbol | Details | -|---------------------------|---------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| LoopFlowCnecs | $c \in \mathcal{C} ^{lf}$ | Set of FlowCnecs[^1] with a loop-flow threshold. (for example, in CORE CC, loop-flows are monitored on cross-border CNECs). LoopFlowCnecs is a subset of [FlowCnecs](core-problem-filler.md#input-data): $\mathcal{C} ^{lf} \subset \mathcal{C}$ | -| Reference commercial flow | $f^{commercial} (c)$ | Commercial flow[^2], of LoopFlowCnec $c$, at the beginning of the optimization, in MW. | -| initial loop-flow | $f^{loop} _ {0} (c)$ | loop-flow before RAO of LoopFlowCnec $c$, in MW | -| loop-flow threshold | $lf^{threshold} (c)$ | loop-flow threshold of the LoopFlowCnec $c$, in MW, as defined in the CRAC. | +| Name | Symbol | Details | +|---------------------------|---------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| LoopFlowCnecs | $c \in \mathcal{C} ^{lf}$ | Set of FlowCnecs[^1] with a loop-flow threshold. (for example, in CORE CC, loop-flows are monitored on cross-border CNECs). LoopFlowCnecs is a subset of [FlowCnecs](core-problem-filler.md#used-input-data): $\mathcal{C} ^{lf} \subset \mathcal{C}$ | +| Reference commercial flow | $f^{commercial} (c)$ | Commercial flow[^2], of LoopFlowCnec $c$, at the beginning of the optimization, in MW. | +| initial loop-flow | $f^{loop} _ {0} (c)$ | loop-flow before RAO of LoopFlowCnec $c$, in MW | +| loop-flow threshold | $lf^{threshold} (c)$ | loop-flow threshold of the LoopFlowCnec $c$, in MW, as defined in the CRAC. | [^1]: CNECs that belong to a state for which sensitivity computations failed are ignored in the MILP [^2]: The commercial flow is computed oustide the MILP, see [loop-flow computation](/castor/special-features/loop-flows.md#computation) ## Used parameters -| Name | Symbol | Details | -|--------------------------------------------------------------------------------------------------|-------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| [rao-loop-flow-parameters](/parameters/parameters.md#loop-flow-extension) | | This filler is only used if [this](/parameters/parameters.md#loop-flow-extension) extension is added. | -| [acceptable-increase](/parameters/parameters.md#acceptable-increase) | $c^{acc-increase}_{lf}$ | The increase of the initial loop-flow that is allowed by the optimisation, see [loop-flow-acceptable-increase](/parameters/parameters.md#acceptable-increase). | -| [constraint-adjustment-coefficient](/parameters/parameters.md#constraint-adjustment-coefficient) | $c^{adj-coeff}_{lf}$ | This parameter acts as a margin that tightens the loop-flow constraints bounds in the linear problem. It conceptually behaves as the coefficient $c^{adjustment}$ from the constraint below:
    $abs(F_{loop-flow}(c)) <= lf^{threshold} (c) - c^{adjustment}$
    This parameter is a safety margin which can absorb some of the approximations made in the linear optimization problem such as non integer PST taps, flows approximated by sensitivity coefficients, etc. It therefore increases the probability that the loop-flow constraints respected in the linear optimisation problem, remain respected once the loop-flows are re-computed without the linear approximations. | -| [violation-cost](/parameters/parameters.md#violation-cost) | $c^{penalty}_{lf}$ | penalisation, in the objective function, of the excess of 1 MW of loop-flow | +| Name | Symbol | Details | +|--------------------------------------------------------------------------------------------------|-------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| [rao-loop-flow-parameters](/parameters.md#loop-flow-extension) | | This filler is only used if [this](/parameters.md#loop-flow-extension) extension is added. | +| [acceptable-increase](/parameters.md#acceptable-increase) | $c^{acc-increase}_{lf}$ | The increase of the initial loop-flow that is allowed by the optimisation, see [loop-flow-acceptable-increase](/parameters.md#acceptable-increase). | +| [constraint-adjustment-coefficient](/parameters.md#constraint-adjustment-coefficient) | $c^{adj-coeff}_{lf}$ | This parameter acts as a margin that tightens the loop-flow constraints bounds in the linear problem. It conceptually behaves as the coefficient $c^{adjustment}$ from the constraint below:
    $abs(F_{loop-flow}(c)) <= lf^{threshold} (c) - c^{adjustment}$
    This parameter is a safety margin which can absorb some of the approximations made in the linear optimization problem such as non integer PST taps, flows approximated by sensitivity coefficients, etc. It therefore increases the probability that the loop-flow constraints respected in the linear optimisation problem, remain respected once the loop-flows are re-computed without the linear approximations. | +| [violation-cost](/parameters.md#violation-cost) | $c^{penalty}_{lf}$ | penalisation, in the objective function, of the excess of 1 MW of loop-flow | ## Defined optimization variables diff --git a/docs/castor/linear-problem/max-min-margin-filler.md b/docs/castor/linear-problem/max-min-margin-filler.md index 236b1f925b..1a025fab17 100644 --- a/docs/castor/linear-problem/max-min-margin-filler.md +++ b/docs/castor/linear-problem/max-min-margin-filler.md @@ -15,13 +15,13 @@ | Name | Details | |----------------------------------------|---| -| [type](/parameters/parameters.md#type) | Used to set the unit (AMPERE/MW) of the objective function | +| [type](/parameters.md#type) | Used to set the unit (AMPERE/MW) of the objective function | ## Defined optimization variables | Name | Symbol | Details | Type | Index | Unit | Lower bound | Upper bound | |---|---|---|---|---|---|---|---| -| Minimum margin | $MM$ | the minimum margin over all OptimizedFlowCnecs | Real value | one scalar variable for the whole problem | MW or AMPERE (depending on [objective-function](/parameters/parameters.md#objective-function-parameters) unit) | $-\infty$ | $+\infty$ | +| Minimum margin | $MM$ | the minimum margin over all OptimizedFlowCnecs | Real value | one scalar variable for the whole problem | MW or AMPERE (depending on [objective-function](/parameters.md#objective-function-parameters) unit) | $-\infty$ | $+\infty$ | ## Used optimization variables @@ -33,7 +33,7 @@ ### Define the minimum margin variable -#### If [objective-function](/parameters/parameters.md#objective-function-parameters) is in MW +#### If [objective-function](/parameters.md#objective-function-parameters) is in MW $$ \begin{equation} @@ -50,7 +50,7 @@ $$ Note that OptimizedFlowCnec might have only one threshold (upper or lower), in that case, only one of the two above constraints is defined.
    -#### If [objective-function](/parameters/parameters.md#objective-function-parameters) is in AMPERE +#### If [objective-function](/parameters.md#objective-function-parameters) is in AMPERE $$ \begin{equation} diff --git a/docs/castor/linear-problem/max-min-relative-margin-filler.md b/docs/castor/linear-problem/max-min-relative-margin-filler.md index d8fb27bfcb..aa4f3917b3 100644 --- a/docs/castor/linear-problem/max-min-relative-margin-filler.md +++ b/docs/castor/linear-problem/max-min-relative-margin-filler.md @@ -21,14 +21,14 @@ And $PTDF_{zTos}(z1, c)$, the zone-to-slack PTDF of bidding zone $z1$ on CNEC $c | Name | Symbol | Details | |------------------------------------------------------------------------|----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| [type](/parameters/parameters.md#type) | | This filler is only used if the objective function is MAX_MIN_MARGIN_IN_MEGAWATT, or MAX_MIN_MARGIN_IN_AMPERE. This parameter is also used to set the unit (AMPERE/MW) of the objective function | -| [ptdf-sum-lower-bound](/parameters/parameters.md#ptdf-sum-lower-bound) | $\varepsilon_{PTDF}$ | zToz PTDF sum below this value are lifted to the ptdf-sum-lower-bound, to avoid a bad conditionning of the problem where the value of relative margins are very high.
    *Its impact on the accuracy of the problem is insignificant, as high relative margins do not usually define the min. relative margin.* | +| [type](/parameters.md#type) | | This filler is only used if the objective function is MAX_MIN_MARGIN_IN_MEGAWATT, or MAX_MIN_MARGIN_IN_AMPERE. This parameter is also used to set the unit (AMPERE/MW) of the objective function | +| [ptdf-sum-lower-bound](/parameters.md#ptdf-sum-lower-bound) | $\varepsilon_{PTDF}$ | zToz PTDF sum below this value are lifted to the ptdf-sum-lower-bound, to avoid a bad conditionning of the problem where the value of relative margins are very high.
    *Its impact on the accuracy of the problem is insignificant, as high relative margins do not usually define the min. relative margin.* | ## Defined optimization variables | Name | Symbol | Details | Type | Index | Unit | Lower bound | Upper bound | |----------------------------|--------|------------------------------------------------------------------------|------------|-------------------------------------------|----------------------------------------------------------------------------------------------------------------------------|-------------|-------------| -| Minimum relative margin | $MRM$ | the minimum negative margin over all OptimizedFlowCnecs | Real value | one scalar variable for the whole problem | Relative MW or relative AMPERE (depending on [objective-function](/parameters/parameters.md#objective-function-parameters) | 0 | $+\infty$ | +| Minimum relative margin | $MRM$ | the minimum negative margin over all OptimizedFlowCnecs | Real value | one scalar variable for the whole problem | Relative MW or relative AMPERE (depending on [objective-function](/parameters.md#objective-function-parameters) | 0 | $+\infty$ | | Is minimum margin positive | $P$ | binary variable, equal to 1 if the min margin is positive, 0 otherwise | Binary | one scalar variable for the whole problem | no unit | 0 | 1 | ## Used optimization variables @@ -104,7 +104,7 @@ $$m_{max}^{relRAM} = MaxRAM / \varepsilon_{PTDF}$$ $$m_{min}^{relRAM} = m_{max}^{relRAM} * 5$$ - and the unit conversion coefficient is defined as follows: - - If the [objective-function](/parameters/parameters.md#objective-function-parameters) is in MW: $c^{unit}(c) = 1$ + - If the [objective-function](/parameters.md#objective-function-parameters) is in MW: $c^{unit}(c) = 1$ - If it is in AMPERE: $c^{unit}(c) = \frac{U_{nom}(c) \sqrt{3}}{1000}$ Note that an OptimizedFlowCnec might have only one threshold (upper or lower). In that case, only one of the two diff --git a/docs/castor/linear-problem/mnec-filler.md b/docs/castor/linear-problem/mnec-filler.md index 4c0f551f07..80326d3d22 100644 --- a/docs/castor/linear-problem/mnec-filler.md +++ b/docs/castor/linear-problem/mnec-filler.md @@ -13,12 +13,12 @@ ## Used parameters -| Name | Symbol | Details | -|-------------------------------------------------------------------------------------------------------|---------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| [MNEC extension](/parameters/parameters.md#mnec-extension) | | This filler is only used if this extension is defined | -| [mnec-acceptable-margin-decrease](/parameters/parameters.md#acceptable-margin-decrease) | $c^{acc-augm}_{m}$ | The decrease of the initial margin that is allowed by the optimisation on MNECs. | -| [mnec-constraint-adjustment-coefficient](/parameters/parameters.md#constraint-adjustment-coefficient) | $c^{adj-coeff}_{m}$ | This coefficient is here to mitigate the approximation made by the linear optimization (approximation = use of sensitivities to linearize the flows, rounding of the PST taps).
    It tightens the MNEC constraint, in order to take some margin for that constraint to stay respected once the approximations are removed (i.e. taps have been rounded and real flow calculated) | -| [mnec-violation-cost](/parameters/parameters.md#violation-cost) | $c^{penalty}_{lf}$ | penalisation, in the objective function, of the excess of 1 MW of a MNEC flow | +| Name | Symbol | Details | +|-----------------------------------------------------------------------------------------------------|---------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| [MNEC extension](/parameters.md#mnec-extension) | | This filler is only used if this extension is defined | +| [mnec-acceptable-margin-decrease](/parameters.md#acceptable-margin-decrease) | $c^{acc-augm}_{m}$ | The decrease of the initial margin that is allowed by the optimisation on MNECs. | +| [mnec-constraint-adjustment-coefficient](/parameters.md#constraint-adjustment-coefficient) | $c^{adj-coeff}_{m}$ | This coefficient is here to mitigate the approximation made by the linear optimization (approximation = use of sensitivities to linearize the flows, rounding of the PST taps).
    It tightens the MNEC constraint, in order to take some margin for that constraint to stay respected once the approximations are removed (i.e. taps have been rounded and real flow calculated) | +| [mnec-violation-cost](/parameters.md#violation-cost) | $c^{penalty}_{lf}$ | penalisation, in the objective function, of the excess of 1 MW of a MNEC flow | ## Defined optimization variables diff --git a/docs/castor/linear-problem/ra-usage-limits-filler.md b/docs/castor/linear-problem/ra-usage-limits-filler.md index 3f37ede9ea..850f81725a 100644 --- a/docs/castor/linear-problem/ra-usage-limits-filler.md +++ b/docs/castor/linear-problem/ra-usage-limits-filler.md @@ -53,7 +53,7 @@ $$ *⚠️ In order to mitigate rounding issues, and ensure that the max and min setpoints are feasible, a small "epsilon" ( 1e-4) is added to max / subtracted to min setpoint.* -*⚠️ In order to mitigate PST tap ↔ angle approximation in "[APPROXIMATED_INTEGERS](/parameters/parameters.md#pst-model)" +*⚠️ In order to mitigate PST tap ↔ angle approximation in "[APPROXIMATED_INTEGERS](/parameters.md#pst-model)" mode, and ensure that the initial setpoint is feasible, a correction factor is added or subtracted from the initial setpoint in the constraints above. This coefficient is computed as 30% of the average tap to angle conversion factor:* *correction = 0.3 x abs((max angle - min angle) / (max tap - min tap))* diff --git a/docs/castor/linear-problem/unoptimized-cnec-filler-cra.md b/docs/castor/linear-problem/unoptimized-cnec-filler-cra.md index d856ac48cc..96ab4c7a51 100644 --- a/docs/castor/linear-problem/unoptimized-cnec-filler-cra.md +++ b/docs/castor/linear-problem/unoptimized-cnec-filler-cra.md @@ -15,9 +15,9 @@ ## Used parameters -| Name | Details | -|----------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------| -| [do-not-optimize-curative-cnecs-for-tsos-without-cras](/parameters/parameters.md#do-not-optimize-curative-cnecs-for-tsos-without-cras) | This filler is only used if this parameter is activated, and only for curative RAO. | +| Name | Details | +|---------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------| +| [do-not-optimize-curative-cnecs-for-tsos-without-cras](/parameters.md#do-not-optimize-curative-cnecs-for-tsos-without-cras) | This filler is only used if this parameter is activated, and only for curative RAO. | ## Defined optimization variables diff --git a/docs/castor/monitoring/angle-monitoring/algorithm.md b/docs/castor/monitoring/angle-monitoring/algorithm.md index 21cd9407bd..a0fa07418a 100644 --- a/docs/castor/monitoring/angle-monitoring/algorithm.md +++ b/docs/castor/monitoring/angle-monitoring/algorithm.md @@ -30,6 +30,6 @@ Here is a detailed description of how the angle monitoring algorithm operates: - security DIVERGENT - Re-compute all angle values **(4)** - Create an intermediary result, with angles computed in **(4)**, list of applied remedial actions in **(2)**, and secure flag set to SECURE if there is no more overshoot (after re-verifying thresholds) -- Assemble all the state-specific result in one overall result and [update the RAO result object](#the-angle-monitoring-result) +- Assemble all the state-specific result in one overall result and [update the RAO result object](/castor/monitoring/angle-monitoring.md#the-angle-monitoring-result) ![Angle monitoring algorithm](/_static/img/angle_monitoring_algorithm.png){.forced-white-background} diff --git a/docs/castor/monitoring/angle-monitoring/java-api.md b/docs/castor/monitoring/angle-monitoring/java-api.md index ac0d2c6e1d..636480d77c 100644 --- a/docs/castor/monitoring/angle-monitoring/java-api.md +++ b/docs/castor/monitoring/angle-monitoring/java-api.md @@ -8,15 +8,15 @@ public AngleMonitoring(Crac crac, Network network, RaoResult raoResult, CimGlskD With: - crac: the CRAC object used for the RAO, and containing [AngleCnecs](/input-data/crac/json.md#angle-cnecs) to be monitored. - network: the network to be monitored. -- raoResult: the [RaoResult](/output-data/rao-result/rao-result-json.md) object containing selected remedial actions (that shall +- raoResult: the [RaoResult](/output-data/rao-result.md) object containing selected remedial actions (that shall be applied on the network before monitoring angle values) -- cimGlskDocument: the [CIM GLSK document](/input-data/glsk/glsk-cim.md) that will allow proper application of re-dispatch +- cimGlskDocument: the [CIM GLSK document](https://powsybl.readthedocs.io/projects/entsoe/en/latest/glsk/glsk-cim.html) that will allow proper application of re-dispatch remedial actions. - glskOffsetDateTime: the timestamp for which the computation is made, as it is necessary to correctly read relevant values from the CIM GLSK file. Otherwise, you can still run the angle monitoring algorithm, which will automatically generate a -**[proportional-to-target-power GLSK](/input-data/glsk.md#proportional-to-target-power-glsk)** +**[proportional-to-target-power GLSK](https://powsybl.readthedocs.io/projects/entsoe/en/latest/glsk/glsk.html#proportional-glsk)** for its internal functioning (ie in order to re-dispatch lost generation when generator-tripping remedial actions are activated): ~~~java @@ -25,7 +25,7 @@ public AngleMonitoring(Crac crac, Network network, RaoResult raoResult, Set 💡 **NOTE** > AngleCnecs currently cannot be optimised by the RAO, but they are monitored by an independent -> [AngleMonitoring](/castor/angle-monitoring/angle-monitoring.md) module. +> [AngleMonitoring](/castor/monitoring/angle-monitoring.md) module. #### Creating an AngleCnec In OpenRAO, AngleCnecs can be created by the java API, or written in the json CRAC internal format, as shown below: @@ -610,7 +610,7 @@ A "VoltageCnec" is a CNEC on which we monitor the voltage on substations. It has > 💡 **NOTE** > VoltageCnecs currently cannot be optimised by the RAO, but they are monitored by an independent -> [VoltageMonitoring](/castor/voltage-monitoring/voltage-monitoring.md) module. +> [VoltageMonitoring](/castor/monitoring/voltage-monitoring.md) module. #### Creating a VoltageCnec In OpenRAO, VoltageCnecs can be created by the java API, or written in the json CRAC internal format, as shown below: @@ -1023,7 +1023,7 @@ TapRanges can be of different types: The final validity range of the PstRangeAction is the intersection of its TapRanges, with the intersection of the min/max feasible taps of the PST. The PstRangeAction also requires additional data, notably to be able to interpret the TapRanges. Those additional data are: the initial tap of the PST, and a conversion map which gives for each feasible tap of the PST its corresponding angle. Utility methods have been developed in OpenRAO to ease the management of these additional data during the creation of a PstRangeAction. -Two or more [aligned PST range actions](introduction.md#range-action) must have the same (random) group ID defined. The RAO will +Two or more [aligned PST range actions](#range-actions) must have the same (random) group ID defined. The RAO will make sure their optimized set-points are always equal. If the PstRangeAction is an automaton, it has to have a speed assigned. This is an integer that defines the relative @@ -1121,7 +1121,7 @@ The HvdcRangeAction will be able to modify its active power set-point. The domain in which the HvdcRangeAction can modify the HvdcSetpoint is delimited by 'HvdcRanges'. An HvdcRangeAction contains a list of HvdcRanges. A range must be defined with a min and a max. -Two or more [aligned HVDC range actions](introduction.md#range-action) must have the same (random) group ID defined. The RAO will +Two or more [aligned HVDC range actions](#range-actions) must have the same (random) group ID defined. The RAO will make sure their optimized set-points are always equal. If the HvdcRangeAction is an automaton, it has to have a speed assigned. This is an integer that defines the relative @@ -1186,7 +1186,7 @@ replaced by two injections, one on each side of the line, with opposite keys of ![HVDC AC model](/_static/img/HVDC_AC_model.png){.forced-white-background} -Two or more [aligned injection range actions](introduction.md#range-action) must have the same (random) group ID defined. The RAO will +Two or more [aligned injection range actions](#range-actions) must have the same (random) group ID defined. The RAO will make sure their optimized set-points are always equal. If the InjectionRangeAction is an automaton, it has to have a speed assigned. This is an integer that defines the relative diff --git a/docs/output-data.md b/docs/output-data.md index a8210c436c..f1f4694a6d 100644 --- a/docs/output-data.md +++ b/docs/output-data.md @@ -8,7 +8,7 @@ output-data/core-cne.md output-data/swe-cne.md ``` -During input data import & RAO computation, CASTOR produces human-readable logs that detail each step of the optimisation. More info on logs [here](rao-logs/rao-logs). +During input data import & RAO computation, CASTOR produces human-readable logs that detail each step of the optimisation. More info on logs [here](output-data/rao-logs.md). -At the end of the RAO computation, CASTOR produces RAO results detailing the outcome of the optimisation. More info on this [here](rao-result/rao-result-json). -These results can be used, along with the [input data](/input-data/input-data.md), in order to produce context-specific output files. You can find examples of such workflows in one of the many [GridCapa applications](https://github.com/farao-community?q=gridcapa&type=all&language=&sort=). \ No newline at end of file +At the end of the RAO computation, CASTOR produces RAO results detailing the outcome of the optimisation. More info on this [here](output-data/rao-result.md). +These results can be used, along with the [input data](input-data.md), in order to produce context-specific output files. You can find examples of such workflows in one of the many [GridCapa applications](https://github.com/farao-community?q=gridcapa&type=all&language=&sort=). \ No newline at end of file diff --git a/docs/output-data/core-cne/cnec-results.md b/docs/output-data/core-cne/cnec-results.md index c436c14929..fdb1e4ed99 100644 --- a/docs/output-data/core-cne/cnec-results.md +++ b/docs/output-data/core-cne/cnec-results.md @@ -97,11 +97,11 @@ The name of the CNEC as defined in the native CRAC file. - **Z11**: absolute zonal PTDF sum - **Z12**: flow margin in regard to the PATL - **Z13**: objective function value for this CNEC in regard to the PATL - This value is equal to Z12 unless RAO is run with [relative positive margins](/parameters/parameters.md#type), + This value is equal to Z12 unless RAO is run with [relative positive margins](/parameters.md#type), in which case it will be equal to Z12 / Z11 when Z12 is positive. - **Z14**: flow margin in regard to the TATL - **Z15**: objective function value for this CNEC in regard to the TATL - This value is equal to Z14 unless RAO is run with [relative positive margins](/parameters/parameters.md#type), + This value is equal to Z14 unless RAO is run with [relative positive margins](/parameters.md#type), in which case it will be equal to Z14 / Z11 when Z14 is positive. - **Z16**: loop-flow - **Z17**: loop-flow threshold (input data) diff --git a/docs/output-data/core-cne/header.md b/docs/output-data/core-cne/header.md index 1c9f560b3e..16b6e60003 100644 --- a/docs/output-data/core-cne/header.md +++ b/docs/output-data/core-cne/header.md @@ -1,5 +1,5 @@ The header contains meta-information about the process. -Refer to the [JAVA API](#the-java-api) section for more details. +Refer to the [JAVA API](/output-data/core-cne/java-api.md) section for more details. Example: diff --git a/docs/output-data/core-cne/introduction.md b/docs/output-data/core-cne/introduction.md index e459ea048d..f73181b6fa 100644 --- a/docs/output-data/core-cne/introduction.md +++ b/docs/output-data/core-cne/introduction.md @@ -1,7 +1,7 @@ The CORE CNE file is the standard RAO output file for the CORE CC process. The [OpenRAO toolbox](https://github.com/powsybl/powsybl-open-rao/tree/main/data/result-exporter/core-cne-exporter) -allows exporting RAO results in a CORE CNE file using a network, an internal [RAO result](/output-data/rao-result/rao-result-json.md), -an [internal CRAC](/input-data/crac/json.md), a [UcteCracCreationContext](/input-data/crac/creation-context.md#ucte), -and [RAO parameters](/parameters/parameters.md). +allows exporting RAO results in a CORE CNE file using a network, an internal [RAO result](/output-data/rao-result.md), +an [internal CRAC](/input-data/crac/json.md), a [UcteCracCreationContext](/input-data/crac/creation-context.md#ucte-implementation), +and [RAO parameters](/parameters.md). ![CORE CNE](/_static/img/core-cne.png){.forced-white-background} \ No newline at end of file diff --git a/docs/output-data/core-cne/java-api.md b/docs/output-data/core-cne/java-api.md index 1bab359d6c..fd331f0030 100644 --- a/docs/output-data/core-cne/java-api.md +++ b/docs/output-data/core-cne/java-api.md @@ -11,11 +11,11 @@ With: - **crac**: the [CRAC object](/input-data/crac/json.md) used for the RAO. - **network**: the network used in the RAO (not modified with any remedial action). - **cracCreationContext**: the [CracCreationContext object](/input-data/crac/creation-context.md) generated during - [CRAC creation](/input-data/crac/import.md). CORE CNE export only handles [UcteCracCreationContext](/input-data/crac/creation-context.md#ucte) + [CRAC creation](/input-data/crac/import.md). CORE CNE export only handles [UcteCracCreationContext](/input-data/crac/creation-context.md#ucte-implementation) subtype, because it follows the UCTE conventions. -- **raoResult**: the [RaoResult](/output-data/rao-result/rao-result-json.md) object containing selected remedial actions and flow +- **raoResult**: the [RaoResult](/output-data/rao-result.md) object containing selected remedial actions and flow results. -- **raoParameters**: the [RaoParameters](/parameters/parameters.md) used in the RAO. +- **raoParameters**: the [RaoParameters](/parameters.md) used in the RAO. - **exporterParameters**: a specific object that te user should define, containing meta-information that will be written in the header of the CNE file: - **documentId**: document ID to be written in "mRID" field diff --git a/docs/output-data/rao-logs.md b/docs/output-data/rao-logs.md index d5d9b86b06..e6b6d8664d 100644 --- a/docs/output-data/rao-logs.md +++ b/docs/output-data/rao-logs.md @@ -9,11 +9,11 @@ rao-logs/example.md ``` CASTOR's logs are divided into three categories: -- [RAO Business Logs](rao-business-logs): log entries that contain business information about the remedial action optimisation steps -- [RAO Business Warnings](rao-business-warns): log entries that contain business warnings about the RAO steps -- [RAO Technical Logs](rao-technical-logs): log entries that contain technical logs that can be activated to debug detailed steps of the RAO +- [RAO Business Logs](./rao-logs/rao-business-logs.md): log entries that contain business information about the remedial action optimisation steps +- [RAO Business Warnings](./rao-logs/rao-business-warns.md): log entries that contain business warnings about the RAO steps +- [RAO Technical Logs](./rao-logs/rao-technical-logs.md): log entries that contain technical logs that can be activated to debug detailed steps of the RAO You can collect these logs and use them in your application to provide monitoring for the RAO process. For examples on how to do this, check out the [GridCapa applications](https://github.com/farao-community?q=gridcapa&type=all&language=&sort=). -You can check out our small but complete [RAO logs example](example). \ No newline at end of file +You can check out our small but complete [RAO logs example](/output-data/rao-logs/example.md). \ No newline at end of file diff --git a/docs/output-data/rao-logs/example.md b/docs/output-data/rao-logs/example.md index 8304b543e9..0dffa9a567 100644 --- a/docs/output-data/rao-logs/example.md +++ b/docs/output-data/rao-logs/example.md @@ -55,7 +55,7 @@ INFO c.p.o.commons.logs.RaoBusinessLogs - ----- Preventive perimeter optimizati ### Root leaf -Then it starts the [search-tree](/castor/search-tree-rao.md) algorithm, starting by evaluating the +Then it starts the [search-tree](/castor.md#algorithm) algorithm, starting by evaluating the "root leaf": it assesses CNEC constraints on the network, considering only CNECs that belong to the [preventive perimeter](/castor/rao-steps.md#preventive-perimeter), before applying any preventive remedial action. @@ -72,10 +72,10 @@ INFO c.p.openrao.commons.logs.TechnicalLogs - Limiting element #01: margin = -1 INFO c.p.openrao.commons.logs.TechnicalLogs - Limiting element #02: margin = -166.08 MW, element FFR2AA1 FFR3AA1 1 at state preventive, CNEC ID = "FR2-FR3-O - preventive" ~~~ -After root leaf evaluation, the RAO conducts [range action linear optimisation](/castor/linear-problem/linear-rao.md) -before applying any [network action](/input-data/crac/introduction.md#network-action). +After root leaf evaluation, the RAO conducts [range action linear optimisation](/castor/linear-problem.md) +before applying any [network action](/input-data/crac.md#network-action). This step is usually quick and allows the RAO to try to secure the network / improve margins using only remedial actions -with a linear impact on the network ([range actions](/input-data/crac/introduction.md#range-action)). +with a linear impact on the network ([range actions](/input-data/crac.md#range-action)). Multiple "MILP -> sensitivity analysis" iterations can be needed until the optimisation converges to an optimal set of set-point for range actions (in the example, 2 iterations are needed at the root leaf). @@ -101,12 +101,12 @@ The RAO successfully decreased the objection function value to 179.1 by setting (Note that the objective function seen by the RAO is the opposite of the minimum margin). So it increased the margin on the most limiting element from -182MW to -179MW. This is not a lot (but it's a good start); you can limit using range actions for small margin improvements using -[the dedicated parameters](/parameters/parameters.md#range-actions-optimisation-parameters). +[the dedicated parameters](/parameters.md#range-actions-optimisation-parameters). ### Network actions optimisation After getting the most out of range actions, the RAO then goes on to choosing the best network actions. -It does so by choosing the single best network action (or [pre-defined network action combination](/parameters/parameters.md#predefined-combinations)) +It does so by choosing the single best network action (or [pre-defined network action combination](/parameters.md#predefined-combinations)) first ("search depth 1"), then trying to combine it with the remaining actions to get a two-actions combo ("search depth 2"), ... until the minimum margin cannot be improved anymore, or until there are no remaining network actions to try. diff --git a/docs/output-data/rao-result.md b/docs/output-data/rao-result.md index bb38923df4..782c258825 100644 --- a/docs/output-data/rao-result.md +++ b/docs/output-data/rao-result.md @@ -2,7 +2,7 @@ ## Introduction -A **R**emedial **A**ction **O**ptimisation process provides an optimal list of remedial actions to be applied in basecase and after contingencies listed in the [CRAC](/input-data/crac/introduction.md). The decisions are based upon the impact of these remedial actions on the CRAC's [CNECs](/input-data/crac/introduction.md#cnec). +A **R**emedial **A**ction **O**ptimisation process provides an optimal list of remedial actions to be applied in basecase and after contingencies listed in the [CRAC](/input-data/crac.md). The decisions are based upon the impact of these remedial actions on the CRAC's [CNECs](/input-data/crac.md#cnec). A **RaoResult object model** has been designed in OpenRAO in order to hold all the important results of optimisation. In this page, we present: diff --git a/docs/output-data/rao-result/angle-cnecs.md b/docs/output-data/rao-result/angle-cnecs.md index 187eda94b7..6470b5e264 100644 --- a/docs/output-data/rao-result/angle-cnecs.md +++ b/docs/output-data/rao-result/angle-cnecs.md @@ -9,7 +9,7 @@ Access the angle value of an AngleCnec. :::{group-tab} JAVA API *Note that this feature is not implemented in the default RAO result implementation, as angle CNECs are not optimised -by the RAO, but monitored by an [angle monitoring module](/castor/angle-monitoring/angle-monitoring.md).* +by the RAO, but monitored by an [angle monitoring module](/castor/monitoring/angle-monitoring.md).* ~~~java // get the angle value for a given angle cnec, at a given state, in a given angle unit @@ -50,7 +50,7 @@ Access the angle margin value of an AngleCnec. :::{group-tab} JAVA API *Note that this feature is not implemented in the default RAO result implementation, as angle CNECs are not optimised -by the RAO, but monitored by an [angle monitoring module](/castor/angle-monitoring/angle-monitoring.md).* +by the RAO, but monitored by an [angle monitoring module](/castor/monitoring/angle-monitoring.md).* ~~~java // get the margin value for a given angle cnec, at a given state, in a given angle unit diff --git a/docs/output-data/rao-result/steps.md b/docs/output-data/rao-result/steps.md index f3611b3880..b5f521cf5d 100644 --- a/docs/output-data/rao-result/steps.md +++ b/docs/output-data/rao-result/steps.md @@ -1,5 +1,5 @@ -This field contains macro information about which steps the [CASTOR RAO](/castor/search-tree-rao.md) executed. -(See also: [Forbidding cost increase](/parameters/parameters.md#forbid-cost-increase), [Second preventive RAO parameters](/parameters/parameters.md#second-preventive-rao-parameters)) +This field contains macro information about which steps the [CASTOR RAO](/castor.md#algorithm) executed. +(See also: [Forbidding cost increase](/parameters.md#forbid-cost-increase), [Second preventive RAO parameters](/parameters.md#second-preventive-rao-parameters)) | Value | Did CASTOR run a 1st preventive RAO? | Did CASTOR run a 2nd preventive RAO? | Did the RAO fall back to initial situation? | Did the RAO fall back to 1st preventive RAO result even though a 2nd was run? | |----------------------------------------------------------|--------------------------------------|--------------------------------------|---------------------------------------------|-------------------------------------------------------------------------------| diff --git a/docs/output-data/rao-result/voltage-cnecs.md b/docs/output-data/rao-result/voltage-cnecs.md index 196e2e7b3e..9efe63a5d8 100644 --- a/docs/output-data/rao-result/voltage-cnecs.md +++ b/docs/output-data/rao-result/voltage-cnecs.md @@ -9,7 +9,7 @@ Access the voltage value of an VoltageCnec. :::{group-tab} JAVA API *Note that this feature is not implemented in the default RAO result implementation, as voltage CNECs are not optimised -by the RAO, but monitored by a [voltage monitoring module](/castor/voltage-monitoring/voltage-monitoring.md).* +by the RAO, but monitored by a [voltage monitoring module](/castor/monitoring/voltage-monitoring.md).* ~~~java // get the voltage value for a given voltage cnec, after optimisation of a given instant, in a given voltage unit @@ -49,7 +49,7 @@ Access the voltage margin value of a VoltageCnec. :::{group-tab} JAVA API *Note that this feature is not implemented in the default RAO result implementation, as voltage CNECs are not optimised -by the RAO, but monitored by a [voltage monitoring module](/castor/voltage-monitoring/voltage-monitoring.md).* +by the RAO, but monitored by a [voltage monitoring module](/castor/monitoring/voltage-monitoring.md).* ~~~java // get the margin value for a given voltage cnec, after optimisation of a given instant, in a given voltage unit diff --git a/docs/output-data/swe-cne/cnec-results.md b/docs/output-data/swe-cne/cnec-results.md index 8f681a64b5..0518b94191 100644 --- a/docs/output-data/swe-cne/cnec-results.md +++ b/docs/output-data/swe-cne/cnec-results.md @@ -77,7 +77,7 @@ If angle CNECs are monitored in the actual perimeter (in basecase or after a spe ##### mRID -Unique ID of the angle CNEC, as defined in the [orignal CRAC file](/input-data/crac/cim.md#angle-cnecs). +Unique ID of the angle CNEC, as defined in the [orignal CRAC file](/input-data/crac/cim.md#anglecnecs). ##### businessType @@ -85,7 +85,7 @@ One possible value: **B87** (angle monitoring). ##### name -Name of the angle CNEC, as defined in the [orignal CRAC file](/input-data/crac/cim.md#angle-cnecs). +Name of the angle CNEC, as defined in the [orignal CRAC file](/input-data/crac/cim.md#anglecnecs). ##### quantity.quantity @@ -121,7 +121,7 @@ Unique ID, in the network, of the voltage level on the branch's right side. ##### PTDF_Domain (optional) -Only in the hypothetical case of a [relative margins objective function](/parameters/parameters.md#type). +Only in the hypothetical case of a [relative margins objective function](/parameters.md#type). - **mRID**: [ENTSO-E EICode](https://www.entsoe.eu/data/energy-identification-codes-eic/) of the area - **pTDF_Quantity.quantity**: value of the PTDF associated to the bidding zone for the critical network element > ⚠️ **NOTE** diff --git a/docs/output-data/swe-cne/header.md b/docs/output-data/swe-cne/header.md index 1a58d6ac5b..c72dbd9962 100644 --- a/docs/output-data/swe-cne/header.md +++ b/docs/output-data/swe-cne/header.md @@ -1,5 +1,5 @@ The header contains meta-information about the process. -Refer to the [JAVA API](#the-java-api) section for more details. +Refer to the [JAVA API](/output-data/swe-cne/java-api.md) section for more details. Example: diff --git a/docs/output-data/swe-cne/introduction.md b/docs/output-data/swe-cne/introduction.md index 3d35404439..a03ec425a2 100644 --- a/docs/output-data/swe-cne/introduction.md +++ b/docs/output-data/swe-cne/introduction.md @@ -1,7 +1,7 @@ The SWE CNE file is the standard RAO output file for the SWE CC process. The [OpenRAO toolbox](https://github.com/powsybl/powsybl-open-rao/tree/main/data/result-exporter/swe-cne-exporter) -allows exporting RAO results in a SWE CNE file using an [internal CRAC](/input-data/crac/json.md), a network, an internal [RAO result](/output-data/rao-result/rao-result-json.md) -(containing [angle results](/castor/angle-monitoring/angle-monitoring.md) if the CRAC contains [Angle CNECs](/input-data/crac/json.md#angle-cnecs)), -a [CimCracCreationContext](/input-data/crac/creation-context.md#cim), and a [RAO parameters](/parameters/parameters.md). +allows exporting RAO results in a SWE CNE file using an [internal CRAC](/input-data/crac/json.md), a network, an internal [RAO result](/output-data/rao-result.md) +(containing [angle results](/castor/monitoring/angle-monitoring/result.md) if the CRAC contains [Angle CNECs](/input-data/crac/json.md#angle-cnecs)), +a [CimCracCreationContext](/input-data/crac/creation-context.md#cim-implementation), and a [RAO parameters](/parameters.md). ![SWE CNE](/_static/img/swe-cne.png){.forced-white-background} \ No newline at end of file diff --git a/docs/output-data/swe-cne/java-api.md b/docs/output-data/swe-cne/java-api.md index 5b5d682765..671a73afaf 100644 --- a/docs/output-data/swe-cne/java-api.md +++ b/docs/output-data/swe-cne/java-api.md @@ -10,14 +10,14 @@ public void exportCne(Crac crac, Network network, With: - **crac**: the [CRAC object](/input-data/crac/json.md) used for the RAO. - **network**: the network used in the RAO (not modified with any remedial action). -- **cracCreationContext**: the [CimCracCreationContext object](/input-data/crac/creation-context.md#cim) generated during +- **cracCreationContext**: the [CimCracCreationContext object](/input-data/crac/creation-context.md#cim-implementation) generated during [CRAC creation](/input-data/crac/import.md) from a native [CIM CRAC file](/input-data/crac/cim.md). -- **raoResult**: the [RaoResult](/output-data/rao-result-json.md) object containing selected remedial actions and flow - results, as well as [angle results](/castor/angle-monitoring/angle-monitoring.md) if the CRAC contains [Angle CNECs](/input-data/crac/json.md#angle-cnecs) +- **raoResult**: the [RaoResult](/output-data/rao-result.md) object containing selected remedial actions and flow + results, as well as [angle results](/castor/monitoring/angle-monitoring.md) if the CRAC contains [Angle CNECs](/input-data/crac/json.md#angle-cnecs) > ⚠️ **NOTE** > The exporter will fail if angle CNECs are present in the CRAC, but the RAO result does not contain angle results. - > See how to compute angle results [here](/castor/angle-monitoring/angle-monitoring.md). -- **raoParameters**: the [RaoParameters](/parameters/parameters.md) used in the RAO. + > See how to compute angle results [here](/castor/monitoring/angle-monitoring/algorithm.md). +- **raoParameters**: the [RaoParameters](/parameters.md) used in the RAO. - **exporterParameters**: a specific object that the user should define, containing meta-information that will be written in the header of the CNE file: - **documentId**: document ID to be written in "mRID" field diff --git a/docs/output-data/swe-cne/ra-results.md b/docs/output-data/swe-cne/ra-results.md index 64c4ed9a71..42fbde1480 100644 --- a/docs/output-data/swe-cne/ra-results.md +++ b/docs/output-data/swe-cne/ra-results.md @@ -1,5 +1,5 @@ Remedial actions have their own Constraint_Series to report the ones selected by the RAO **or by the -[angle monitoring module](/castor/angle-monitoring/angle-monitoring.md)**. +[angle monitoring module](/castor/monitoring/angle-monitoring.md)**. The remedial actions' Constraint_Series all have a **B56 businessType**. Example: diff --git a/docs/parameters.md b/docs/parameters.md index 62ad82780b..0fe6d552bc 100644 --- a/docs/parameters.md +++ b/docs/parameters.md @@ -101,7 +101,7 @@ These parameters (objective-function) configure the remedial action optimisation second preventive won't be run, even if curative cost is higher, in order to save computation time* ### Range actions optimisation parameters -These parameters (range-actions-optimization) tune the [linear optimiser](/castor/linear-problem/linear-rao.md) used to optimise range actions. +These parameters (range-actions-optimization) tune the [linear optimiser](/castor/linear-problem.md) used to optimise range actions. (See [Modelling CNECs and range actions](/castor/linear-problem/core-problem-filler.md)) #### max-mip-iterations @@ -195,7 +195,7 @@ These parameters (range-actions-optimization) tune the [linear optimiser](/casto active+reactive computations, this approximation may be incorrect. The linear problem can thus find a worse solution than in its previous iteration. - **DISABLED**: if this situation occurs, the linear problem stops and returns the previous solution, - see this schema : [Linear Remedial Actions Optimisation](/castor/linear-problem/linear-rao.md#algorithm). + see this schema : [Linear Remedial Actions Optimisation](/castor/linear-problem.md#algorithm). - **ENABLED**: this introduces two new behaviors to the iterating linear optimiser: 1. If the linear problem finds a solution worse than in its previous iteration, it continues iterating. When stop condition is met ([max-mip-iterations](#max-mip-iterations) reached, or two successive iterations have @@ -238,7 +238,7 @@ These are parameters that tune the solver used to solve the MIP problem. not enough. ### Network actions optimisation parameters -These parameters (topological-actions-optimization) tune the [search-tree algorithm](/castor/search-tree-rao.md) +These parameters (topological-actions-optimization) tune the [search-tree algorithm](/castor.md#algorithm) when searching for the best network actions. #### max-preventive-search-tree-depth @@ -701,7 +701,7 @@ Zones are seperated by + or -. ::: :::{group-tab} iTools Based on PowSyBl's [configuration mechanism](https://www.powsybl.org/pages/documentation/user/configuration/). -~~~yml +~~~yaml rao-objective-function: type: MAX_MIN_MARGIN_IN_AMPERE preventive-stop-criterion: SECURE diff --git a/docs/tutorial.md b/docs/tutorial.md index 69a8979230..1033d99ee5 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -114,7 +114,7 @@ resulting problems on the network thanks to remedial actions. ## Create CRAC -The [CRAC](/input-data/crac/introduction.md) is the data object that contains all the key information for the RAO, i.e. the +The [CRAC](/input-data/crac.md) is the data object that contains all the key information for the RAO, i.e. the contingencies to simulate, the CNECs to optimise and the remedial actions to apply. The RAO's Java API allows users to manually fill the CRAC with all the required and desired data. @@ -276,7 +276,7 @@ crac.newNetworkAction() ## RAO Parameters -Next, define the parameters to run the RAO using the [RaoParameters](/parameters/parameters.md) object +Next, define the parameters to run the RAO using the [RaoParameters](./parameters.md) object ```java RaoParameters raoParameters = new RaoParameters(); @@ -306,7 +306,7 @@ raoParameters.getRangeActionsOptimizationParameters().setPstModel(RangeActionsOp ## Run the RAO - Run the RAO using the following code to produce a [`RaoResult`](/output-data/rao-result/rao-result-json.md) object: + Run the RAO using the following code to produce a [`RaoResult`](/output-data/rao-result.md) object: ```java RaoInput.RaoInputBuilder raoInputBuilder = RaoInput.build(network, crac);