|
7 | 7 |
|
8 | 8 | package com.powsybl.openrao.data.crac.io.fbconstraint; |
9 | 9 |
|
| 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; |
10 | 17 | import com.powsybl.openrao.data.crac.io.fbconstraint.xsd.CriticalBranchType; |
11 | 18 | import org.junit.jupiter.api.Test; |
12 | 19 |
|
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.*; |
15 | 24 |
|
16 | 25 | /** |
17 | 26 | * @author Baptiste Seguinot {@literal <baptiste.seguinot at rte-france.com>} |
@@ -53,4 +62,38 @@ void isCrossZonalTest() { |
53 | 62 | branch.setName("[PL-PL] My Branch Name [OPP]"); |
54 | 63 | assertFalse(CriticalBranchReader.isCrossZonal(branch)); |
55 | 64 | } |
| 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 | + } |
56 | 99 | } |
0 commit comments