Skip to content

Commit

Permalink
add ptdfSumLowerBound to ptdfSums in evaluator
Browse files Browse the repository at this point in the history
Signed-off-by: Godelaine de Montmorillon <[email protected]>
  • Loading branch information
Godelaine committed Jan 24, 2025
1 parent 9e9ea8b commit cc4a79a
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
public class AbsolutePtdfSumsComputation {
private final ZonalData<SensitivityVariableSet> glskProvider;
private final List<ZoneToZonePtdfDefinition> zTozPtdfs;
private final double ptdfSumLowerBound;

public AbsolutePtdfSumsComputation(ZonalData<SensitivityVariableSet> glskProvider, List<ZoneToZonePtdfDefinition> zTozPtdfs) {
public AbsolutePtdfSumsComputation(ZonalData<SensitivityVariableSet> glskProvider, List<ZoneToZonePtdfDefinition> zTozPtdfs, double ptdfSumLowerBound) {
this.glskProvider = glskProvider;
this.zTozPtdfs = zTozPtdfs;
this.ptdfSumLowerBound = ptdfSumLowerBound;
}

public Map<FlowCnec, Map<TwoSides, Double>> computeAbsolutePtdfSums(Set<FlowCnec> flowCnecs, SystematicSensitivityResult sensitivityResult) {
Expand All @@ -40,6 +42,7 @@ public Map<FlowCnec, Map<TwoSides, Double>> computeAbsolutePtdfSums(Set<FlowCnec
flowCnec.getMonitoredSides().forEach(side -> {
Map<EICode, Double> 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);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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.;
}
Expand All @@ -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<FlowCnec, Map<TwoSides, Double>> ptdfSums = absolutePtdfSumsComputation.computeAbsolutePtdfSums(crac.getFlowCnecs(), systematicSensitivityResult);

// test results
Expand All @@ -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<FlowCnec, Map<TwoSides, Double>> 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<SensitivityVariableSet> glskProvider = UcteGlskDocument.importGlsk(getClass().getResourceAsStream("/glsk/glsk_proportional_12nodes_with_alegro.xml"))
.getZonalGlsks(network, Instant.parse("2016-07-28T22:30:00Z"));

// Crac
Set<TwoSides> 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<ZoneToZonePtdfDefinition> 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<FlowCnec, Map<TwoSides, Double>> 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);
}
}

0 comments on commit cc4a79a

Please sign in to comment.