diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java index b6d1578d..0763387b 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java @@ -223,12 +223,8 @@ boolean checkVoltageLevelLimits(Network network) { if (overrides.size() != 1) { LOGGER.warn("Voltage level {} has a negative or null low voltage limit. Please change it or use a voltage limit override.", vl.getId()); integrityVoltageLevelLimits = false; - } else if (overrides.get(0).isRelative() && overrides.get(0).getLimit() + lowLimit <= 0) { - LOGGER.warn("Voltage level {} has a negative low voltage limit, even taking into account voltage limit override.", vl.getId()); - integrityVoltageLevelLimits = false; } } - if (Double.isNaN(lowLimit)) { List overrides = getSpecificVoltageLimits(vl.getId(), VoltageLimitOverride.VoltageLimitType.LOW_VOLTAGE_LIMIT); if (overrides.size() != 1) { @@ -280,8 +276,8 @@ boolean checkVoltageLimitOverrides(Network network) { integrityVoltageLimitOverrides = false; } // verify voltage limit override does not lead to negative limit value - if (value + voltageLimitOverride.getLimit() < 0) { - LOGGER.warn("Voltage level {} relative override leads to a negative {}.", + if (value + voltageLimitOverride.getLimit() <= 0) { + LOGGER.warn("Voltage level {} relative override leads to a negative or null {}.", voltageLevelId, voltageLimitOverride.getVoltageLimitType()); integrityVoltageLimitOverrides = false; } diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/VoltageLevelLimitsOverrideInput.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/VoltageLevelLimitsOverrideInput.java index 6748b461..dbae0ad1 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/VoltageLevelLimitsOverrideInput.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/VoltageLevelLimitsOverrideInput.java @@ -10,6 +10,7 @@ import com.powsybl.ampl.executor.AmplInputFile; import com.powsybl.commons.util.StringToIntMapper; import com.powsybl.iidm.network.Network; +import com.powsybl.openreac.exceptions.InvalidParametersException; import org.jgrapht.alg.util.Pair; import java.io.ByteArrayInputStream; @@ -60,6 +61,10 @@ private void transformToNormalizedVoltage(List voltageLimi } else { throw new UnsupportedOperationException("Unsupported voltage limit type: " + voltageLimitOverride.getVoltageLimitType()); } + + if (newLimits.getFirst() > newLimits.getSecond()) { + throw new InvalidParametersException("Override on voltage level " + voltageLevelId + " leads to low voltage limit > high voltage limit."); + } normalizedVoltageLimitsOverride.put(voltageLevelId, newLimits); } } diff --git a/open-reac/src/test/java/com/powsybl/openreac/parameters/input/VoltageLevelLimitsOverrideInputTest.java b/open-reac/src/test/java/com/powsybl/openreac/parameters/input/VoltageLevelLimitsOverrideInputTest.java index 50c9c578..d78592e5 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/parameters/input/VoltageLevelLimitsOverrideInputTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/parameters/input/VoltageLevelLimitsOverrideInputTest.java @@ -89,13 +89,6 @@ void testNullVoltageLimitWithoutOverride() { // if one low voltage limit is <= 0 and there is no voltage limit override, invalid OpenReacParameters vl.setLowVoltageLimit(0); assertThrows(PowsyblException.class, () -> params.checkIntegrity(network)); - - // if one low voltage limit is <= 0 and the voltage limit override is not enough, invalid OpenReacParameters - List overrides = new ArrayList<>(); - overrides.add(new VoltageLimitOverride(vl.getId(), VoltageLimitOverride.VoltageLimitType.LOW_VOLTAGE_LIMIT, - true, 0)); - params.addSpecificVoltageLimits(overrides); - assertThrows(PowsyblException.class, () -> params.checkIntegrity(network)); } @Test @@ -138,12 +131,51 @@ void testVoltageOverrideWithNegativeVoltageLimit() { params.addSpecificVoltageLimits(voltageLimitsOverride); assertThrows(InvalidParametersException.class, () -> params.checkIntegrity(network)); + // if low relative voltage override leads to null voltage limit, throws exception + params.getSpecificVoltageLimits().clear(); + voltageLimitsOverride.clear(); + voltageLimitsOverride.add(new VoltageLimitOverride(vl.getId(), VoltageLimitOverride.VoltageLimitType.LOW_VOLTAGE_LIMIT, true, -400)); + params.addSpecificVoltageLimits(voltageLimitsOverride); + assertThrows(InvalidParametersException.class, () -> params.checkIntegrity(network)); + // if high relative voltage override leads to negative voltage limit, throws exception OpenReacParameters params2 = new OpenReacParameters(); List voltageLimitsOverride2 = new ArrayList<>(); voltageLimitsOverride2.add(new VoltageLimitOverride(vl.getId(), VoltageLimitOverride.VoltageLimitType.HIGH_VOLTAGE_LIMIT, true, -490)); params2.addSpecificVoltageLimits(voltageLimitsOverride2); assertThrows(InvalidParametersException.class, () -> params2.checkIntegrity(network)); + + // if high relative voltage override leads to null voltage limit, throws exception + params2.getSpecificVoltageLimits().clear(); + voltageLimitsOverride2.clear(); + voltageLimitsOverride2.add(new VoltageLimitOverride(vl.getId(), VoltageLimitOverride.VoltageLimitType.HIGH_VOLTAGE_LIMIT, true, -480)); + params2.addSpecificVoltageLimits(voltageLimitsOverride2); + assertThrows(InvalidParametersException.class, () -> params2.checkIntegrity(network)); + } + + @Test + void testVoltageOverrideWithLowLimitGreaterHighLimit() { + Network network = IeeeCdfNetworkFactory.create118(); + setDefaultVoltageLimits(network); // set default voltage limits to every voltage levels of the network + + VoltageLevel vl = network.getVoltageLevels().iterator().next(); + vl.setHighVoltageLimit(480); + vl.setLowVoltageLimit(400); + + List voltageLimitsOverride = new ArrayList<>(); + voltageLimitsOverride.add(new VoltageLimitOverride(vl.getId(), VoltageLimitOverride.VoltageLimitType.HIGH_VOLTAGE_LIMIT, true, -90)); + + List voltageLimitsOverride2 = new ArrayList<>(); + voltageLimitsOverride2.add(new VoltageLimitOverride(vl.getId(), VoltageLimitOverride.VoltageLimitType.LOW_VOLTAGE_LIMIT, true, 90)); + + List voltageLimitsOverride3 = new ArrayList<>(); + voltageLimitsOverride3.add(new VoltageLimitOverride(vl.getId(), VoltageLimitOverride.VoltageLimitType.LOW_VOLTAGE_LIMIT, false, 395)); + voltageLimitsOverride3.add(new VoltageLimitOverride(vl.getId(), VoltageLimitOverride.VoltageLimitType.HIGH_VOLTAGE_LIMIT, false, 390)); + + // if after relative override, low limit > high limit, wrong parameters + assertThrows(InvalidParametersException.class, () -> new VoltageLevelLimitsOverrideInput(voltageLimitsOverride, network)); + assertThrows(InvalidParametersException.class, () -> new VoltageLevelLimitsOverrideInput(voltageLimitsOverride2, network)); + assertThrows(InvalidParametersException.class, () -> new VoltageLevelLimitsOverrideInput(voltageLimitsOverride3, network)); } @Test