From cc4a79a746e2c598d0a4619dae2ee43fe2e9b488 Mon Sep 17 00:00:00 2001 From: Godelaine de Montmorillon Date: Fri, 24 Jan 2025 14:59:24 +0100 Subject: [PATCH] add ptdfSumLowerBound to ptdfSums in evaluator Signed-off-by: Godelaine de Montmorillon --- .../crac/impl/utils/NetworkImportsUtil.java | 4 ++ .../utils/TestCase12NodesWithOpenBranch.uct | 39 ++++++++++++ .../commons/AbsolutePtdfSumsComputation.java | 5 +- .../searchtreerao/commons/ToolProvider.java | 3 +- .../AbsolutePtdfSumsComputationTest.java | 59 ++++++++++++++++++- 5 files changed, 105 insertions(+), 5 deletions(-) create mode 100644 data/crac/crac-impl/src/test/resources/utils/TestCase12NodesWithOpenBranch.uct diff --git a/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/utils/NetworkImportsUtil.java b/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/utils/NetworkImportsUtil.java index ba91b16358..b463252842 100644 --- a/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/utils/NetworkImportsUtil.java +++ b/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/utils/NetworkImportsUtil.java @@ -43,6 +43,10 @@ public static Network import16NodesNetworkWithAngleDroopHvdcs() { return Network.read("utils/TestCase16NodesWithAngleDroopHvdcs.xiidm", NetworkImportsUtil.class.getResourceAsStream("/utils/TestCase16NodesWithAngleDroopHvdcs.xiidm")); } + public static Network import12NodesNetworkWithOpenBranch() { + return Network.read("utils/TestCase12NodesWithOpenBranch.uct", NetworkImportsUtil.class.getResourceAsStream("/utils/TestCase12NodesWithOpenBranch.uct")); + } + public static void addHvdcLine(Network network) { VoltageLevel vl1 = network.getVoltageLevel("BBE1AA1"); vl1.getBusBreakerView().newBus().setId("B1").add(); diff --git a/data/crac/crac-impl/src/test/resources/utils/TestCase12NodesWithOpenBranch.uct b/data/crac/crac-impl/src/test/resources/utils/TestCase12NodesWithOpenBranch.uct new file mode 100644 index 0000000000..9f1dbc2f51 --- /dev/null +++ b/data/crac/crac-impl/src/test/resources/utils/TestCase12NodesWithOpenBranch.uct @@ -0,0 +1,39 @@ +##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 +##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 +##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 +##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 5000 +BBE1AA1 BBE3AA1 1 0 0.0000 10.000 0.000000 5000 +FFR1AA1 FFR2AA1 1 0 0.0000 10.000 0.000000 5000 +FFR1AA1 FFR2AA1 2 8 0.0000 10.000 0.000000 5000 +FFR1AA1 FFR3AA1 1 0 0.0000 10.000 0.000000 5000 +FFR2AA1 FFR3AA1 1 0 0.0000 10.000 0.000000 5000 +DDE1AA1 DDE2AA1 1 0 0.0000 10.000 0.000000 5000 +DDE1AA1 DDE3AA1 1 0 0.0000 10.000 0.000000 5000 +DDE2AA1 DDE3AA1 1 0 0.0000 10.000 0.000000 5000 +NNL1AA1 NNL2AA1 1 0 0.0000 10.000 0.000000 5000 +NNL1AA1 NNL3AA1 1 0 0.0000 10.000 0.000000 5000 +NNL2AA1 NNL3AA1 1 0 0.0000 10.000 0.000000 5000 +FFR2AA1 DDE3AA1 1 0 0.0000 10.000 0.000000 5000 +DDE2AA1 NNL3AA1 1 0 0.0000 10.000 0.000000 5000 +NNL2AA1 BBE3AA1 1 0 0.0000 10.000 0.000000 5000 +BBE2AA1 FFR3AA1 1 0 0.0000 10.000 0.000000 5000 +##T +BBE2AA1 BBE3AA1 1 0 400.0 400.0 1000. 0.0000 10.000 0.000000 0.0 5000 PST +##R +BBE2AA1 BBE3AA1 1 -0.68 90.00 16 0 SYMM \ No newline at end of file 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 9a41b0265d..52309fadf8 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 @@ -26,10 +26,12 @@ public class AbsolutePtdfSumsComputation { private final ZonalData glskProvider; private final List zTozPtdfs; + private final double ptdfSumLowerBound; - public AbsolutePtdfSumsComputation(ZonalData glskProvider, List zTozPtdfs) { + public AbsolutePtdfSumsComputation(ZonalData glskProvider, List zTozPtdfs, double ptdfSumLowerBound) { this.glskProvider = glskProvider; this.zTozPtdfs = zTozPtdfs; + this.ptdfSumLowerBound = ptdfSumLowerBound; } public Map> computeAbsolutePtdfSums(Set flowCnecs, SystematicSensitivityResult sensitivityResult) { @@ -40,6 +42,7 @@ public Map> computeAbsolutePtdfSums(Set { Map ptdfMap = buildZoneToSlackPtdfMap(flowCnec, side, glskProvider, eiCodesInPtdfs, sensitivityResult); double sumOfZToZPtdf = zTozPtdfs.stream().mapToDouble(zToz -> Math.abs(computeZToZPtdf(zToz, ptdfMap))).sum(); + sumOfZToZPtdf = Math.max(sumOfZToZPtdf, ptdfSumLowerBound); ptdfSums.computeIfAbsent(flowCnec, k -> new EnumMap<>(TwoSides.class)).put(side, sumOfZToZPtdf); }); } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/ToolProvider.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/ToolProvider.java index e19100e717..8f34829dfa 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/ToolProvider.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/ToolProvider.java @@ -218,7 +218,8 @@ public static ToolProvider buildFromRaoInputAndParameters(RaoInput raoInput, Rao raoInput.getGlskProvider(), new AbsolutePtdfSumsComputation( raoInput.getGlskProvider(), - raoParameters.getExtension(RelativeMarginsParametersExtension.class).getPtdfBoundaries() + raoParameters.getExtension(RelativeMarginsParametersExtension.class).getPtdfBoundaries(), + raoParameters.getExtension(RelativeMarginsParametersExtension.class).getPtdfSumLowerBound() ) ); } 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 0264fe4920..860f0fb024 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 @@ -7,9 +7,13 @@ package com.powsybl.openrao.searchtreerao.commons; import com.powsybl.openrao.commons.EICode; +import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.crac.api.Crac; +import com.powsybl.openrao.data.crac.api.InstantKind; import com.powsybl.openrao.data.crac.api.cnec.FlowCnec; import com.powsybl.iidm.network.TwoSides; +import com.powsybl.openrao.data.crac.api.cnec.FlowCnecAdder; +import com.powsybl.openrao.data.crac.impl.CracImpl; import com.powsybl.openrao.data.crac.impl.utils.CommonCracCreation; import com.powsybl.openrao.data.crac.impl.utils.NetworkImportsUtil; import com.powsybl.openrao.raoapi.ZoneToZonePtdfDefinition; @@ -36,7 +40,7 @@ */ class AbsolutePtdfSumsComputationTest { private static final double DOUBLE_TOLERANCE = 0.001; - + private static final double PTDF_SUM_LOWER_BOUND = 0.01; private SystematicSensitivityResult systematicSensitivityResult; @BeforeEach @@ -64,6 +68,14 @@ public void setUp() { case "22Y201903144---9" -> 0.9; default -> 0.; }; + } else if (branchCnec.getId().contains("cnec3")) { + return switch (linearGlsk.getId().substring(0, EICode.EIC_LENGTH)) { + case "10YFR-RTE------C", "10YBE----------2" -> 0.0; + case "10YCB-GERMANY--8" -> 0.0; + case "22Y201903145---4" -> 0.0; + case "22Y201903144---9" -> 0.0; + default -> 0.; + }; } else { return 0.; } @@ -85,7 +97,7 @@ void testComputation() { new ZoneToZonePtdfDefinition("{BE}-{22Y201903144---9}-{DE}+{22Y201903145---4}")); // compute zToz PTDF sum - AbsolutePtdfSumsComputation absolutePtdfSumsComputation = new AbsolutePtdfSumsComputation(glskProvider, boundaries); + AbsolutePtdfSumsComputation absolutePtdfSumsComputation = new AbsolutePtdfSumsComputation(glskProvider, boundaries, PTDF_SUM_LOWER_BOUND); Map> ptdfSums = absolutePtdfSumsComputation.computeAbsolutePtdfSums(crac.getFlowCnecs(), systematicSensitivityResult); // test results @@ -110,11 +122,52 @@ void testIgnoreZtoZWithLessThan2ZtoS() { new ZoneToZonePtdfDefinition("{ES}-{DE}")); // ES doesn't exist in GLSK map, must be filtered // compute zToz PTDF sum - AbsolutePtdfSumsComputation absolutePtdfSumsComputation = new AbsolutePtdfSumsComputation(glskProvider, boundaries); + AbsolutePtdfSumsComputation absolutePtdfSumsComputation = new AbsolutePtdfSumsComputation(glskProvider, boundaries, PTDF_SUM_LOWER_BOUND); 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(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 } + + @Test + void testWithNullPtdfSum() { + Network network = NetworkImportsUtil.import12NodesNetworkWithOpenBranch(); + ZonalData glskProvider = UcteGlskDocument.importGlsk(getClass().getResourceAsStream("/glsk/glsk_proportional_12nodes_with_alegro.xml")) + .getZonalGlsks(network, Instant.parse("2016-07-28T22:30:00Z")); + + // Crac + Set monitoredCnecSides = Set.of(TwoSides.ONE, TwoSides.TWO); + Crac crac = new CracImpl("test-crac") + .newInstant("preventive", InstantKind.PREVENTIVE) + .newInstant("outage", InstantKind.OUTAGE); + // Cnecs + FlowCnecAdder cnecAdder1 = crac.newFlowCnec() + .withId("cnec3basecase") + .withNetworkElement("BBE2AA1 FFR3AA1 1") + .withInstant("preventive") + .withOptimized(true) + .withOperator("operator1") + .withNominalVoltage(380.) + .withIMax(5000.); + monitoredCnecSides.forEach(side -> + cnecAdder1.newThreshold() + .withUnit(Unit.MEGAWATT) + .withSide(side) + .withMin(-1500.) + .withMax(1500.) + .add()); + cnecAdder1.add(); + + List boundaries = Arrays.asList( + new ZoneToZonePtdfDefinition("{FR}-{BE}"), + new ZoneToZonePtdfDefinition("{FR}-{DE}")); + + // compute zToz PTDF sum + AbsolutePtdfSumsComputation absolutePtdfSumsComputation = new AbsolutePtdfSumsComputation(glskProvider, boundaries, PTDF_SUM_LOWER_BOUND); + 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.01, ptdfSums.get(crac.getFlowCnec("cnec3basecase")).get(TwoSides.TWO), DOUBLE_TOLERANCE); + } }