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 dcb5f842..005f6396 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 @@ -216,6 +216,17 @@ boolean checkVoltageLevelLimits(Network network) { double lowLimit = vl.getLowVoltageLimit(); double highLimit = vl.getHighVoltageLimit(); + if (lowLimit <= 0) { + List overrides = getSpecificVoltageLimits(vl.getId(), VoltageLimitOverride.VoltageLimitType.LOW_VOLTAGE_LIMIT); + 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) { 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 c51c79dc..6748b461 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,7 +10,6 @@ import com.powsybl.ampl.executor.AmplInputFile; import com.powsybl.commons.util.StringToIntMapper; import com.powsybl.iidm.network.Network; -import com.powsybl.openreac.parameters.AmplIOUtils; import org.jgrapht.alg.util.Pair; import java.io.ByteArrayInputStream; @@ -82,7 +81,7 @@ public InputStream getParameterFileAsStream(StringToIntMapper string if (!Double.isNaN(limits.getFirst()) || !Double.isNaN(limits.getSecond())) { int amplId = stringToIntMapper.getInt(AmplSubset.VOLTAGE_LEVEL, voltageLevelId); - String[] tokens = {Integer.toString(amplId), Double.toString(limits.getFirst()), Double.toString(limits.getSecond()), AmplIOUtils.addQuotes(voltageLevelId)}; + String[] tokens = {Integer.toString(amplId), Double.toString(limits.getFirst()), Double.toString(limits.getSecond()), "\"" + voltageLevelId + "\""}; dataBuilder.append(String.join(" ", tokens)); dataBuilder.append(System.lineSeparator()); } 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 1011eef0..c36dbd08 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 @@ -49,7 +49,7 @@ void testValidRelativeVoltageOverride() throws IOException { try (var is = input.getParameterFileAsStream(mapper)) { String data = new String(ByteStreams.toByteArray(is), StandardCharsets.UTF_8); String ref = String.join(System.lineSeparator(), "#num minV (pu) maxV (pu) id", - "1 0.7916666666666667 1.1666666666666665 'VLGEN'") + System.lineSeparator() + System.lineSeparator(); + "1 0.7916666666666667 1.1666666666666665 \"VLGEN\"") + System.lineSeparator() + System.lineSeparator(); assertEquals(ref, data); } } @@ -73,11 +73,31 @@ void testValidAbsoluteVoltageOverride() throws IOException { try (var is = input.getParameterFileAsStream(mapper)) { String data = new String(ByteStreams.toByteArray(is), StandardCharsets.UTF_8); String ref = String.join(System.lineSeparator(), "#num minV (pu) maxV (pu) id", - "1 0.8333333333333334 1.0833333333333333 'VLGEN'") + System.lineSeparator() + System.lineSeparator(); + "1 0.8333333333333334 1.0833333333333333 \"VLGEN\"") + System.lineSeparator() + System.lineSeparator(); assertEquals(ref, data); } } + @Test + void testNullVoltageLimitWithoutOverride() { + Network network = IeeeCdfNetworkFactory.create118(); + setDefaultVoltageLimits(network); // set default voltage limits to every voltage levels of the network + + VoltageLevel vl = network.getVoltageLevels().iterator().next(); + OpenReacParameters params = new OpenReacParameters(); + + // 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 void testUndefinedVoltageLimitsWithoutOverride() { Network network = IeeeCdfNetworkFactory.create118();