Skip to content

Commit 97e6372

Browse files
fix(cbcora reader): filter out zero limits (#1601)
* filter zero limits Signed-off-by: CHEN Roxane <roxane.chen@rte-france.com> Co-authored-by: Godelaine <godelaine.demontmorillon@rte-france.com>
1 parent 38824a0 commit 97e6372

3 files changed

Lines changed: 127 additions & 10 deletions

File tree

data/crac/crac-io/crac-io-fb-constraint/src/main/java/com/powsybl/openrao/data/crac/io/fbconstraint/CriticalBranchReader.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,15 @@ private FlowCnecAdder createCnecAdder(Crac crac, String instantId) {
215215
}
216216

217217
private void addPermanentThresholds(FlowCnecAdder cnecAdder) {
218-
if (!Objects.isNull(criticalBranch.getPermanentImaxFactor())) {
218+
if (!Objects.isNull(criticalBranch.getPermanentImaxFactor()) && criticalBranch.getPermanentImaxFactor().doubleValue() > 1e-6) {
219219
addThreshold(cnecAdder, criticalBranch.getPermanentImaxFactor().doubleValue(), Unit.PERCENT_IMAX);
220-
} else if (!Objects.isNull(criticalBranch.getImaxFactor())) {
220+
} else if (!Objects.isNull(criticalBranch.getImaxFactor()) && criticalBranch.getImaxFactor().doubleValue() > 1e-6) {
221221
addThreshold(cnecAdder, criticalBranch.getImaxFactor().doubleValue(), Unit.PERCENT_IMAX);
222222
}
223223

224-
if (!Objects.isNull(criticalBranch.getPermanentImaxA())) {
224+
if (!Objects.isNull(criticalBranch.getPermanentImaxA()) && criticalBranch.getPermanentImaxA().doubleValue() > 1e-6) {
225225
addThreshold(cnecAdder, criticalBranch.getPermanentImaxA().doubleValue(), Unit.AMPERE);
226-
} else if (!Objects.isNull(criticalBranch.getImaxA())) {
226+
} else if (!Objects.isNull(criticalBranch.getImaxA()) && criticalBranch.getImaxA().doubleValue() > 1e-6) {
227227
addThreshold(cnecAdder, criticalBranch.getImaxA().doubleValue(), Unit.AMPERE);
228228
}
229229

@@ -234,15 +234,15 @@ private void addPermanentThresholds(FlowCnecAdder cnecAdder) {
234234
}
235235

236236
private void addTemporaryThresholds(FlowCnecAdder cnecAdder) {
237-
if (!Objects.isNull(criticalBranch.getTemporaryImaxFactor())) {
237+
if (!Objects.isNull(criticalBranch.getTemporaryImaxFactor()) && criticalBranch.getTemporaryImaxFactor().doubleValue() > 1e-6) {
238238
addThreshold(cnecAdder, criticalBranch.getTemporaryImaxFactor().doubleValue(), Unit.PERCENT_IMAX);
239-
} else if (!Objects.isNull(criticalBranch.getImaxFactor())) {
239+
} else if (!Objects.isNull(criticalBranch.getImaxFactor()) && criticalBranch.getImaxFactor().doubleValue() > 1e-6) {
240240
addThreshold(cnecAdder, criticalBranch.getImaxFactor().doubleValue(), Unit.PERCENT_IMAX);
241241
}
242242

243-
if (!Objects.isNull(criticalBranch.getTemporaryImaxA())) {
243+
if (!Objects.isNull(criticalBranch.getTemporaryImaxA()) && criticalBranch.getTemporaryImaxA().doubleValue() > 1e-6) {
244244
addThreshold(cnecAdder, criticalBranch.getTemporaryImaxA().doubleValue(), Unit.AMPERE);
245-
} else if (!Objects.isNull(criticalBranch.getImaxA())) {
245+
} else if (!Objects.isNull(criticalBranch.getImaxA()) && criticalBranch.getImaxA().doubleValue() > 1e-6) {
246246
addThreshold(cnecAdder, criticalBranch.getImaxA().doubleValue(), Unit.AMPERE);
247247
}
248248

data/crac/crac-io/crac-io-fb-constraint/src/test/java/com/powsybl/openrao/data/crac/io/fbconstraint/CriticalBranchReaderTest.java

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,20 @@
77

88
package com.powsybl.openrao.data.crac.io.fbconstraint;
99

10+
import com.powsybl.iidm.network.Network;
11+
import com.powsybl.openrao.commons.Unit;
12+
import com.powsybl.openrao.data.crac.api.Crac;
13+
import com.powsybl.openrao.data.crac.api.CracCreationContext;
14+
import com.powsybl.openrao.data.crac.api.CracFactory;
15+
import com.powsybl.openrao.data.crac.api.parameters.CracCreationParameters;
16+
import com.powsybl.openrao.data.crac.io.fbconstraint.parameters.FbConstraintCracCreationParameters;
1017
import com.powsybl.openrao.data.crac.io.fbconstraint.xsd.CriticalBranchType;
1118
import org.junit.jupiter.api.Test;
1219

13-
import static org.junit.jupiter.api.Assertions.assertFalse;
14-
import static org.junit.jupiter.api.Assertions.assertTrue;
20+
import java.io.IOException;
21+
import java.time.OffsetDateTime;
22+
23+
import static org.junit.jupiter.api.Assertions.*;
1524

1625
/**
1726
* @author Baptiste Seguinot {@literal <baptiste.seguinot at rte-france.com>}
@@ -53,4 +62,38 @@ void isCrossZonalTest() {
5362
branch.setName("[PL-PL] My Branch Name [OPP]");
5463
assertFalse(CriticalBranchReader.isCrossZonal(branch));
5564
}
65+
66+
@Test
67+
void testAddThresholdWithZeroThreshold() throws IOException {
68+
CracCreationParameters parameters = new CracCreationParameters();
69+
parameters.setCracFactoryName(CracFactory.findDefault().getName());
70+
parameters.addExtension(FbConstraintCracCreationParameters.class, new FbConstraintCracCreationParameters());
71+
72+
// Test that if a threshold is 0, it is not used
73+
Network network = Network.read("TestCase12Nodes_with_Xnodes.uct", getClass().getResourceAsStream("/network/TestCase12Nodes_with_Xnodes.uct"));
74+
OffsetDateTime timestamp = OffsetDateTime.parse("2019-01-08T10:30Z");
75+
parameters.getExtension(FbConstraintCracCreationParameters.class).setTimestamp(timestamp);
76+
CracCreationContext creationContext = Crac.readWithContext("with_zero_limits.xml", getClass().getResourceAsStream("/merged_cb/with_zero_limits.xml"), network, parameters);
77+
Crac crac = creationContext.getCrac();
78+
79+
// No ImaxFactor value, PermanentImaxA = 0 => use ImaxA = 10
80+
assertTrue(crac.getFlowCnec("BE_CBCO_000001 - preventive").getThresholds().stream().allMatch(branchThreshold -> branchThreshold.max().get() == 10.0));
81+
assertTrue(crac.getFlowCnec("BE_CBCO_000001 - preventive").getThresholds().stream().allMatch(branchThreshold -> branchThreshold.getUnit() == Unit.AMPERE));
82+
83+
// permanentImaxFactor is 0, have no value for ImaxFactor, no value for PermanentImaxA => should use imaxA value = 20
84+
// Same temporaryImaxFactor is 0, have no value for ImaxFactor, no value for TemporaryImaxA => should use imaxA value = 20
85+
assertTrue(crac.getFlowCnec("BE_CBCO_000003 - curative").getThresholds().stream().allMatch(branchThreshold -> branchThreshold.max().get() == 20.0));
86+
assertTrue(crac.getFlowCnec("BE_CBCO_000003 - curative").getThresholds().stream().allMatch(branchThreshold -> branchThreshold.getUnit() == Unit.AMPERE));
87+
assertTrue(crac.getFlowCnec("BE_CBCO_000003 - outage").getThresholds().stream().allMatch(branchThreshold -> branchThreshold.max().get() == 20.0));
88+
assertTrue(crac.getFlowCnec("BE_CBCO_000003 - outage").getThresholds().stream().allMatch(branchThreshold -> branchThreshold.getUnit() == Unit.AMPERE));
89+
90+
// permanentImaxFactor is 0, but we have a value for imaxFactor = -40 (negative because of direction==opposite)
91+
assertTrue(crac.getFlowCnec("BE_CBCO_000004 - curative").getThresholds().stream().allMatch(branchThreshold -> branchThreshold.min().get() == -40));
92+
assertTrue(crac.getFlowCnec("BE_CBCO_000004 - curative").getThresholds().stream().allMatch(branchThreshold -> branchThreshold.getUnit() == Unit.PERCENT_IMAX));
93+
94+
// No thresholds info, the threshold should be set to -1 IMAX_percent (negative because of direction==opposite)
95+
assertTrue(crac.getFlowCnec("BE_CBCO_000002 - preventive").getThresholds().stream().allMatch(branchThreshold -> branchThreshold.min().get() == -1));
96+
assertTrue(crac.getFlowCnec("BE_CBCO_000002 - preventive").getThresholds().stream().allMatch(branchThreshold -> branchThreshold.getUnit() == Unit.PERCENT_IMAX));
97+
98+
}
5699
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<FlowBasedConstraintDocument DtdRelease="4" DtdVersion="0" xmlns="flowbased" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="flowbasedconstraintdocument-17.xsd">
3+
<DocumentIdentification v="17XTSO-CS------W-20190108-F301v1"/>
4+
<DocumentVersion v="1"/>
5+
<DocumentType v="B06"/>
6+
<ProcessType v="A01"/>
7+
<SenderIdentification codingScheme="A01" v="17XTSO-CS------W"/>
8+
<SenderRole v="A36"/>
9+
<ReceiverIdentification codingScheme="A01" v="22XCORESO------S"/>
10+
<ReceiverRole v="A44"/>
11+
<CreationDateTime v="2019-08-15T14:07:28Z"/>
12+
<ConstraintTimeInterval v="2019-01-07T23:00Z/2019-01-08T23:00Z"/>
13+
<Domain codingScheme="A01" v="10YDOM-REGION-1V"/>
14+
<criticalBranches>
15+
<criticalBranch id="BE_CBCO_000001">
16+
<timeInterval v="2019-01-07T23:00Z/2019-01-08T23:00Z"/>
17+
<branch eic="1234567890123450" from="BBE1AA1 " name="[BE-BE] BBE1 - BBE2 [DIR]" order="1" to="BBE2AA1 "/>
18+
<imaxA>10</imaxA>
19+
<imaxType>SEASONAL</imaxType>
20+
<permanentImaxA>0</permanentImaxA>
21+
<frmMw>138</frmMw>
22+
<minRAMfactor>70</minRAMfactor>
23+
<CNEC>true</CNEC>
24+
<MNEC>false</MNEC>
25+
<direction>DIRECT</direction>
26+
<tsoOrigin>BE</tsoOrigin>
27+
</criticalBranch>
28+
<criticalBranch id="BE_CBCO_000003">
29+
<timeInterval v="2019-01-07T23:00Z/2019-01-08T23:00Z"/>
30+
<branch eic="1234567890123450" from="BBE3AA1 " name="[BE-BE] BBE3 - BBE2 [DIR]" order="1" to="BBE2AA1 "/>
31+
<imaxA>20</imaxA>
32+
<imaxType>SEASONAL</imaxType>
33+
<permanentImaxFactor>0</permanentImaxFactor>
34+
<temporaryImaxFactor>0</temporaryImaxFactor>
35+
<frmMw>150</frmMw>
36+
<minRAMfactor>70</minRAMfactor>
37+
<CNEC>true</CNEC>
38+
<MNEC>false</MNEC>
39+
<direction>DIRECT</direction>
40+
<tsoOrigin>BE</tsoOrigin>
41+
<outage id="BE_CO_00001" location="BE-NL" name="N-2 BE-NL">
42+
<branch eic="1234567890123450" from="X_NLBE1 " order="1" to="BBE3AA1 "/>
43+
<branch eic="1234567890123450" from="BBE3AA1 " order="1" to="BBE1AA1 "/>
44+
</outage>
45+
</criticalBranch>
46+
<criticalBranch id="BE_CBCO_000004">
47+
<timeInterval v="2019-01-07T23:00Z/2019-01-08T23:00Z"/>
48+
<branch eic="1234567890123450" from="BBE1AA1 " name="[BE-BE] BBE1 - BBE2 [OPP]" order="1" to="BBE2AA1 "/>
49+
<imaxFactor>40</imaxFactor>
50+
<imaxType>SEASONAL</imaxType>
51+
<permanentImaxFactor>0</permanentImaxFactor>
52+
<frmMw>138</frmMw>
53+
<minRAMfactor>70</minRAMfactor>
54+
<CNEC>true</CNEC>
55+
<MNEC>false</MNEC>
56+
<direction>OPPOSITE</direction>
57+
<tsoOrigin>BE</tsoOrigin>
58+
<outage id="BE_CO_00002" location="BE" name="N-1 BE">
59+
<branch eic="1234567890123450" from="BBE1AA1 " order="1" to="BBE3AA1 "/>
60+
</outage>
61+
</criticalBranch>
62+
<criticalBranch id="BE_CBCO_000002">
63+
<timeInterval v="2019-01-07T23:00Z/2019-01-08T23:00Z"/>
64+
<branch eic="1234567890123450" from="BBE1AA1 " name="[BE-BE] BBE1 - BBE2 [OPP]" order="1" to="BBE2AA1 "/>
65+
<imaxType>SEASONAL</imaxType>
66+
<frmMw>138</frmMw>
67+
<minRAMfactor>70</minRAMfactor>
68+
<CNEC>true</CNEC>
69+
<MNEC>false</MNEC>
70+
<direction>OPPOSITE</direction>
71+
<tsoOrigin>BE</tsoOrigin>
72+
</criticalBranch>
73+
</criticalBranches>
74+
</FlowBasedConstraintDocument>

0 commit comments

Comments
 (0)