Skip to content

Commit 006b0e7

Browse files
committed
Set default imax values when importing curative cnec
Signed-off-by: thiriondan <[email protected]>
1 parent b1cbb14 commit 006b0e7

File tree

3 files changed

+50
-11
lines changed
  • data/crac-creation/crac-creator-cse/src
  • tests/src/test/resources/com/powsybl/openrao/tests/features/epic90_robust_crac

3 files changed

+50
-11
lines changed

data/crac-creation/crac-creator-cse/src/main/java/com/powsybl/openrao/data/craccreation/creator/cse/criticalbranch/CriticalBranchReader.java

+37-6
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ public CriticalBranchReader(List<TBranch> tBranches, @Nullable TOutage tOutage,
104104
this.criticalBranchImportStatus = ImportStatus.INCOMPLETE_DATA;
105105
this.invalidBranchReason = String.format("CNEC is defined on outage %s which is not defined", outage);
106106
} else {
107-
this.isImported = true;
108107
this.isDirectionInverted = branchHelper.isInvertedInNetwork();
109108
this.selected = !isMonitored && isSelected(tBranch);
110109
if (tOutage == null) {
110+
this.isImported = true;
111111
// preventive
112112
this.isBaseCase = true;
113113
this.contingencyId = null;
@@ -117,8 +117,14 @@ public CriticalBranchReader(List<TBranch> tBranches, @Nullable TOutage tOutage,
117117
// curative
118118
this.isBaseCase = false;
119119
this.contingencyId = outage;
120-
this.criticalBranchImportStatus = ImportStatus.IMPORTED;
121-
importCurativeCnecs(tBranch, branchHelper, outage, crac, isMonitored);
120+
if(importCurativeCnecs(tBranch, branchHelper, outage, crac, isMonitored)) {
121+
this.criticalBranchImportStatus = ImportStatus.IMPORTED;
122+
this.isImported = true;
123+
} else {
124+
this.criticalBranchImportStatus = ImportStatus.INCOMPLETE_DATA;
125+
this.invalidBranchReason = "Incomplete Imax data to create at least one preventive CNEC for the branch.";
126+
this.isImported = false;
127+
}
122128
}
123129
}
124130
}
@@ -134,12 +140,37 @@ private void importPreventiveCnec(TBranch tBranch, UcteFlowElementHelper branchH
134140
importCnec(crac, tBranch, branchHelper, isMonitored ? tBranch.getIlimitMNE() : tBranch.getImax(), null, crac.getPreventiveInstant().getId(), isMonitored);
135141
}
136142

137-
private void importCurativeCnecs(TBranch tBranch, UcteFlowElementHelper branchHelper, String outage, Crac crac, boolean isMonitored) {
143+
/**
144+
* Returns true if at least one CNEC has been correctly imported.
145+
* @param tBranch
146+
* @param branchHelper
147+
* @param outage
148+
* @param crac
149+
* @param isMonitored
150+
* @return
151+
*/
152+
private boolean importCurativeCnecs(TBranch tBranch, UcteFlowElementHelper branchHelper, String outage, Crac crac, boolean isMonitored) {
138153
HashMap<Instant, TImax> cnecCaracs = new HashMap<>();
139154
cnecCaracs.put(crac.getOutageInstant(), isMonitored ? tBranch.getIlimitMNEAfterOutage() : tBranch.getImaxAfterOutage());
140-
cnecCaracs.put(crac.getInstant(InstantKind.AUTO), isMonitored ? tBranch.getIlimitMNEAfterSPS() : tBranch.getImaxAfterSPS());
141-
cnecCaracs.put(crac.getInstant(InstantKind.CURATIVE), isMonitored ? tBranch.getIlimitMNEAfterCRA() : tBranch.getImaxAfterCRA());
155+
cnecCaracs.put(crac.getInstant(InstantKind.AUTO), isMonitored ? tBranch.getIlimitMNEAfterSPS() : findTargetImaxAfterSPS(tBranch));
156+
cnecCaracs.put(crac.getInstant(InstantKind.CURATIVE), isMonitored ? tBranch.getIlimitMNEAfterCRA() : findTargetImaxAfterCRA(tBranch.getImaxAfterCRA()));
142157
cnecCaracs.forEach((instant, iMax) -> importCnec(crac, tBranch, branchHelper, iMax, outage, instant.getId(), isMonitored));
158+
return cnecCaracs.values().stream().anyMatch(Objects::nonNull);
159+
}
160+
161+
private TImax findTargetImaxAfterCRA(final TImax imaxAfterCRA) {
162+
return imaxAfterCRA != null ? imaxAfterCRA : createDefaultImaxAfterCRA();
163+
}
164+
165+
private TImax createDefaultImaxAfterCRA() {
166+
final TImax tempImax = new TImax();
167+
tempImax.setUnit("Pct");
168+
tempImax.setV((short) 100);
169+
return tempImax;
170+
}
171+
172+
private TImax findTargetImaxAfterSPS(final TBranch tBranch) {
173+
return tBranch.getImaxAfterSPS() != null ? tBranch.getImaxAfterSPS() : tBranch.getImaxAfterOutage();
143174
}
144175

145176
private void importCnec(Crac crac, TBranch tBranch, UcteFlowElementHelper branchHelper, @Nullable TImax tImax, String outage, String instantId, boolean isMonitored) {

data/crac-creation/crac-creator-cse/src/test/java/com/powsybl/openrao/data/craccreation/creator/cse/CseCracCreatorTest.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class CseCracCreatorTest {
4848
private static final String PREVENTIVE_INSTANT_ID = "preventive";
4949
private static final String OUTAGE_INSTANT_ID = "outage";
5050
private static final String CURATIVE_INSTANT_ID = "curative";
51+
private static final String AUTO_INSTANT_ID = "auto";
5152

5253
private final OffsetDateTime offsetDateTime = null;
5354
private CracCreationParameters parameters = new CracCreationParameters();
@@ -226,9 +227,10 @@ void createCurativeCnecs() throws IOException {
226227
assertTrue(cnec2context.isImported());
227228
assertFalse(cnec2context.isDirectionInvertedInNetwork());
228229
assertEquals("outage_1", cnec2context.getContingencyId().get());
229-
assertEquals(2, cnec2context.getCreatedCnecsIds().size());
230+
assertEquals(3, cnec2context.getCreatedCnecsIds().size());
230231
assertEquals("French line 1 - FFR1AA1 ->FFR2AA1 - outage_1 - outage", cnec2context.getCreatedCnecsIds().get(OUTAGE_INSTANT_ID));
231232
assertEquals("French line 1 - FFR1AA1 ->FFR2AA1 - outage_1 - curative", cnec2context.getCreatedCnecsIds().get(CURATIVE_INSTANT_ID));
233+
assertEquals("French line 1 - FFR1AA1 ->FFR2AA1 - outage_1 - auto", cnec2context.getCreatedCnecsIds().get(AUTO_INSTANT_ID));
232234
}
233235

234236
@Test
@@ -323,22 +325,28 @@ void testRaOnConstraint() throws IOException {
323325

324326
FlowCnec outageCnec = importedCrac.getFlowCnec("French line 1 - FFR1AA1 ->FFR2AA1 - outage_1 - outage");
325327
FlowCnec curativeCnec = importedCrac.getFlowCnec("French line 1 - FFR1AA1 ->FFR2AA1 - outage_1 - curative");
328+
FlowCnec autoCnec = importedCrac.getFlowCnec("French line 1 - FFR1AA1 ->FFR2AA1 - outage_1 - auto");
326329

327330
// PRA
328331
RemedialAction<?> ra = importedCrac.getRangeAction("PST_pra_3_BBE2AA1 BBE3AA1 1");
329-
assertEquals(2, ra.getUsageRules().size());
332+
assertEquals(3, ra.getUsageRules().size());
330333
List<UsageRule> usageRuleList = ra.getUsageRules().stream().toList();
331334

332335
UsageRule usageRule1 = usageRuleList.get(0);
333336
UsageRule usageRule2 = usageRuleList.get(1);
337+
UsageRule usageRule3 = usageRuleList.get(2);
334338
assertTrue(usageRule1 instanceof OnConstraint<?>);
335339
assertTrue(usageRule2 instanceof OnConstraint<?>);
340+
assertTrue(usageRule3 instanceof OnConstraint<?>);
336341
assertEquals(preventiveInstant, usageRule1.getInstant());
337342
assertEquals(preventiveInstant, usageRule2.getInstant());
338-
assertTrue(((OnConstraint<?>) usageRule1).getCnec().equals(outageCnec) || ((OnConstraint<?>) usageRule2).getCnec().equals(outageCnec));
339-
assertTrue(((OnConstraint<?>) usageRule1).getCnec().equals(curativeCnec) || ((OnConstraint<?>) usageRule2).getCnec().equals(curativeCnec));
343+
assertEquals(preventiveInstant, usageRule3.getInstant());
344+
assertTrue(((OnConstraint<?>) usageRule1).getCnec().equals(outageCnec) || ((OnConstraint<?>) usageRule2).getCnec().equals(outageCnec) || ((OnConstraint<?>) usageRule3).getCnec().equals(outageCnec));
345+
assertTrue(((OnConstraint<?>) usageRule1).getCnec().equals(curativeCnec) || ((OnConstraint<?>) usageRule2).getCnec().equals(curativeCnec) || ((OnConstraint<?>) usageRule3).getCnec().equals(curativeCnec));
346+
assertTrue(((OnConstraint<?>) usageRule1).getCnec().equals(autoCnec) || ((OnConstraint<?>) usageRule2).getCnec().equals(autoCnec) || ((OnConstraint<?>) usageRule3).getCnec().equals(autoCnec));
340347
System.out.println(usageRule1.getUsageMethod(preventiveState));
341348
System.out.println(usageRule2.getUsageMethod(preventiveState));
349+
System.out.println(usageRule3.getUsageMethod(preventiveState));
342350
assertEquals(UsageMethod.AVAILABLE, usageRule1.getUsageMethod(preventiveState));
343351
assertEquals(UsageMethod.AVAILABLE, usageRule2.getUsageMethod(preventiveState));
344352
assertEquals(UsageMethod.UNDEFINED, usageRule1.getUsageMethod(outageState));

tests/src/test/resources/com/powsybl/openrao/tests/features/epic90_robust_crac/US90_2.feature

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Feature: US 90.2: asterisks* as wildcards in UCTE CRACs importers
2020
Given network file is "crac90/TestCase_severalVoltageLevels_Xnodes_8characters.uct"
2121
Given crac file is "crac90/cseCrac_ep90us2case2.xml"
2222
When I import crac
23-
Then it should have 8 cnecs
23+
Then it should have 11 cnecs
2424
And the native CNEC "basecase_branch_3 - DDE1AA1* - DDE2AA1* - basecase" should not be imported
2525
And the native CNEC "basecase_branch_4 - XFRDE111 - FFR2AA12 - basecase" should not be imported
2626
And the native remedial action "cra_2" should not be imported because of "INCONSISTENCY_IN_DATA"

0 commit comments

Comments
 (0)