|
| 1 | +/** |
| 2 | + * Copyright (c) 2025, RTE (http://www.rte-france.com) |
| 3 | + * This Source Code Form is subject to the terms of the Mozilla Public |
| 4 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 6 | + */ |
| 7 | +package org.gridsuite.securityanalysis.server; |
| 8 | + |
| 9 | +import com.powsybl.iidm.network.Network; |
| 10 | +import com.powsybl.iidm.network.TwoSides; |
| 11 | +import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; |
| 12 | +import com.powsybl.iidm.network.util.LimitViolationUtils; |
| 13 | +import com.powsybl.security.LimitViolation; |
| 14 | +import com.powsybl.security.LimitViolationType; |
| 15 | +import org.gridsuite.securityanalysis.server.entities.AbstractLimitViolationEntity; |
| 16 | +import org.gridsuite.securityanalysis.server.entities.SubjectLimitViolationEntity; |
| 17 | +import org.junit.jupiter.api.Test; |
| 18 | + |
| 19 | +import static com.powsybl.iidm.network.test.EurostagTutorialExample1Factory.NGEN_NHV1; |
| 20 | +import static com.powsybl.iidm.network.test.EurostagTutorialExample1Factory.NHV1_NHV2_1; |
| 21 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 22 | + |
| 23 | +/** |
| 24 | + * @author Caroline Jeandat <caroline.jeandat at rte-france.com> |
| 25 | + */ |
| 26 | +abstract class AbstractLimitViolationTest<T extends AbstractLimitViolationEntity> { |
| 27 | + |
| 28 | + @Test |
| 29 | + void testLimitViolationEntityNewFields() { |
| 30 | + testLimitViolationMapping("10'", 10 * 60, 1200, 1, 1250, TwoSides.TWO, "1'", 1100, 10 * 60, null); |
| 31 | + } |
| 32 | + |
| 33 | + @Test |
| 34 | + void testLimitViolationEntityNewFieldsWithPermanentLimitReached() { |
| 35 | + testLimitViolationMapping(LimitViolationUtils.PERMANENT_LIMIT_NAME, Integer.MAX_VALUE, 1100, 1, 1150, |
| 36 | + TwoSides.TWO, "10'", 1100, Integer.MAX_VALUE, null); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + void testLimitViolationEntityNewFieldsWithPermanentLimitReachedAndNoTemporaryLimit() { |
| 41 | + testLimitViolationMapping(LimitViolationUtils.PERMANENT_LIMIT_NAME, Integer.MAX_VALUE, 500, 1, 1000, |
| 42 | + TwoSides.ONE, null, 500, Integer.MAX_VALUE, null); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + void testLimitViolationEntityNewFieldsWithLastLimitReached() { |
| 47 | + testLimitViolationMapping("N/A", 0, 1100, 1, 3000, TwoSides.TWO, null, 1100, 0, null); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + void testLimitViolationEntityNewFieldsWithLimitReductionEffective() { |
| 52 | + // for this test to be relevant, "value" needs to be less that "limit" |
| 53 | + testLimitViolationMapping("10'", 60, 1200, 0.8, 1150, TwoSides.TWO, "1'", 1100, 10 * 60, 60); |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + void test2wtLimitViolationEntityNewFieldsWithLimitReductionEffective() { |
| 58 | + // for this test to be relevant, "value" needs to be less that "limit" |
| 59 | + Network network = EurostagTutorialExample1Factory.createWithFixedCurrentLimits(); |
| 60 | + // create limit set for two windings transformer |
| 61 | + network.getTwoWindingsTransformer(NGEN_NHV1).getOrCreateSelectedOperationalLimitsGroup1().newCurrentLimits() |
| 62 | + .setPermanentLimit(100) |
| 63 | + .beginTemporaryLimit() |
| 64 | + .setName("10'") |
| 65 | + .setValue(200) |
| 66 | + .setAcceptableDuration(60 * 10) |
| 67 | + .endTemporaryLimit() |
| 68 | + .beginTemporaryLimit() |
| 69 | + .setName("1'") |
| 70 | + .setValue(300) |
| 71 | + .setAcceptableDuration(60) |
| 72 | + .endTemporaryLimit() |
| 73 | + .beginTemporaryLimit() |
| 74 | + .setName("N/A") |
| 75 | + .setValue(Double.MAX_VALUE) |
| 76 | + .setAcceptableDuration(0) |
| 77 | + .endTemporaryLimit() |
| 78 | + .add(); |
| 79 | + |
| 80 | + LimitViolation limitViolation = new LimitViolation(NGEN_NHV1, "NGEN_NHV1_name", LimitViolationType.CURRENT, |
| 81 | + "10'", 60, 200, 0.8, 180, TwoSides.ONE); |
| 82 | + |
| 83 | + SubjectLimitViolationEntity subjectLimitViolationEntity = new SubjectLimitViolationEntity(NGEN_NHV1, |
| 84 | + "NGEN_NHV1_name"); |
| 85 | + |
| 86 | + AbstractLimitViolationEntity limitViolationEntity = createLimitViolationEntity(network, limitViolation, |
| 87 | + subjectLimitViolationEntity); |
| 88 | + |
| 89 | + assertEquals("1'", limitViolationEntity.getNextLimitName()); |
| 90 | + assertEquals(100, limitViolationEntity.getPatlLimit()); |
| 91 | + assertEquals(60 * 10, limitViolationEntity.getAcceptableDuration()); |
| 92 | + assertEquals(60, limitViolationEntity.getUpcomingAcceptableDuration()); |
| 93 | + assertEquals(100 * limitViolation.getValue() / limitViolationEntity.getPatlLimit(), |
| 94 | + limitViolationEntity.getPatlLoading()); |
| 95 | + } |
| 96 | + |
| 97 | + private void testLimitViolationMapping(String limitName, int acceptableDuration, double limit, |
| 98 | + double limitReduction, double value, TwoSides side, String expectedNextLimitName, long expectedPatlLimit, |
| 99 | + Integer expectedAcceptableDuration, Integer expectedUpcomingAcceptableDuration) { |
| 100 | + Network network = EurostagTutorialExample1Factory.createWithFixedCurrentLimits(); |
| 101 | + LimitViolation limitViolation = new LimitViolation(NHV1_NHV2_1, "NHV1_NHV2_1_name", LimitViolationType.CURRENT, |
| 102 | + limitName, acceptableDuration, limit, limitReduction, value, side); |
| 103 | + |
| 104 | + SubjectLimitViolationEntity subjectLimitViolationEntity = new SubjectLimitViolationEntity(NHV1_NHV2_1, |
| 105 | + "NHV1_NHV2_1_name"); |
| 106 | + |
| 107 | + T limitViolationEntity = createLimitViolationEntity(network, limitViolation, |
| 108 | + subjectLimitViolationEntity); |
| 109 | + |
| 110 | + assertEquals(expectedNextLimitName, limitViolationEntity.getNextLimitName()); |
| 111 | + assertEquals(expectedPatlLimit, limitViolationEntity.getPatlLimit()); |
| 112 | + assertEquals(expectedAcceptableDuration, limitViolationEntity.getAcceptableDuration()); |
| 113 | + assertEquals(expectedUpcomingAcceptableDuration, limitViolationEntity.getUpcomingAcceptableDuration()); |
| 114 | + assertEquals(100 * limitViolation.getValue() / limitViolationEntity.getPatlLimit(), |
| 115 | + limitViolationEntity.getPatlLoading()); |
| 116 | + } |
| 117 | + |
| 118 | + protected abstract T createLimitViolationEntity(Network network, |
| 119 | + LimitViolation limitViolation, SubjectLimitViolationEntity subjectLimitViolationEntity); |
| 120 | +} |
0 commit comments