Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix null ptdfSum in evaluator, relative margin case #1264

Merged
merged 14 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.import12NodesNetwork();
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)
Godelaine marked this conversation as resolved.
Show resolved Hide resolved
assertEquals(0.01, ptdfSums.get(crac.getFlowCnec("cnec3basecase")).get(TwoSides.TWO), DOUBLE_TOLERANCE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,18 @@ Feature: US 10.1: Linear RAO with relative margin
And the absolute PTDF sum on cnec "NNL2AA1 BBE3AA1 1 - preventive" initially should be 1.455
And the relative margin on cnec "FFR2AA1 DDE3AA1 1 - preventive" after PRA should be 2392.4 MW
And the absolute PTDF sum on cnec "FFR2AA1 DDE3AA1 1 - preventive" initially should be 1.477

@fast @rao @mock @ac @preventive-only @relative
Scenario: US 10.1.3: secured case with open monitored branch
Given network file is "common/TestCase12NodesWithOpenBranch.uct"
Given crac file is "epic10/ls_relative_margin_with_open_branch.json"
Given configuration file is "epic10/RaoParameters_relMargin_megawatt.json"
Given loopflow glsk file is "common/glsk_proportional_12nodes.xml"
When I launch search_tree_rao
Then its security status should be "SECURED"
And the value of the objective function after CRA should be -2385.0
And the tap of PstRangeAction "PRA_PST_BE" should be -3 in preventive
And the worst relative margin is 2383.0 MW on cnec "NNL2AA1 BBE3AA1 1 - preventive"
And the absolute PTDF sum on cnec "NNL2AA1 BBE3AA1 1 - preventive" initially should be 1.455
And the relative margin on cnec "FFR2AA1 DDE3AA1 1 - preventive" after PRA should be 2392.4 MW
And the absolute PTDF sum on cnec "FFR2AA1 DDE3AA1 1 - preventive" initially should be 1.477
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
Loading
Loading