From 18fb750b35788fc4afb7420a80f1c73f8354cf76 Mon Sep 17 00:00:00 2001 From: Anne Tilloy Date: Fri, 20 Oct 2023 09:28:26 +0200 Subject: [PATCH 1/3] WIP. Signed-off-by: Anne Tilloy --- .../parameters/input/OpenReacParameters.java | 15 ++++++--------- .../input/VoltageLevelLimitsOverrideInput.java | 14 ++++++++++++-- .../parameters/input/VoltageLimitOverride.java | 2 +- .../src/main/resources/openreac/reactiveopf.mod | 4 ++-- .../VoltageLevelLimitsOverrideInputTest.java | 13 ++++++------- 5 files changed, 27 insertions(+), 21 deletions(-) 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 98cc1572..f46a6480 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 @@ -219,13 +219,6 @@ boolean checkLowVoltageLevelLimits(Network network) { for (VoltageLevel vl : network.getVoltageLevels()) { double lowLimit = vl.getLowVoltageLimit(); - 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; - } - } if (Double.isNaN(lowLimit)) { List overrides = getSpecificVoltageLimits(vl.getId(), VoltageLimitOverride.VoltageLimitType.LOW_VOLTAGE_LIMIT); if (overrides.size() != 1) { @@ -235,6 +228,8 @@ boolean checkLowVoltageLevelLimits(Network network) { LOGGER.warn("Relative voltage override impossible on undefined low voltage limit for voltage level {}.", vl.getId()); integrityVoltageLevelLimits = false; } + } else if (lowLimit < 0.5 * vl.getNominalV()) { + LOGGER.info("Voltage level {} has maybe an inconsistent low voltage limit ({} kV)", vl.getId(), lowLimit); } } return integrityVoltageLevelLimits; @@ -260,6 +255,8 @@ boolean checkHighVoltageLevelLimits(Network network) { LOGGER.warn("Relative voltage override impossible on undefined high voltage limit for voltage level {}.", vl.getId()); integrityVoltageLevelLimits = false; } + } else if (highLimit > 1.5 * vl.getNominalV()) { + LOGGER.info("Voltage level {} has maybe an inconsistent high voltage limit ({} kV)", vl.getId(), highLimit); } } return integrityVoltageLevelLimits; @@ -292,8 +289,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 or null {}.", + if (value + voltageLimitOverride.getLimit() < 0) { + LOGGER.warn("Voltage level {} relative override leads to a negative {}.", 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 adfacd64..991341d7 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 @@ -12,6 +12,8 @@ import com.powsybl.iidm.network.Network; import com.powsybl.openreac.exceptions.InvalidParametersException; import org.jgrapht.alg.util.Pair; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.BufferedWriter; import java.io.IOException; @@ -29,6 +31,8 @@ public class VoltageLevelLimitsOverrideInput implements AmplInputFile { private final Map> normalizedVoltageLimitsOverride; + private static final Logger LOGGER = LoggerFactory.getLogger(VoltageLevelLimitsOverrideInput.class); + public VoltageLevelLimitsOverrideInput(List voltageLimitsOverrides, Network network) { Objects.requireNonNull(voltageLimitsOverrides); Objects.requireNonNull(network); @@ -61,8 +65,14 @@ private void transformToNormalizedVoltage(List voltageLimi 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."); + if (newLimits.getFirst() >= newLimits.getSecond()) { + throw new InvalidParametersException("Override on voltage level " + voltageLevelId + " leads to low voltage limit >= high voltage limit."); + } + if (newLimits.getFirst() < 0.5) { + LOGGER.warn("Voltage level {} has a low voltage limit lower than 0.5 PU ({} PU)", voltageLevelId, newLimits.getFirst()); + } + if (newLimits.getSecond() < 1.5) { + LOGGER.warn("Voltage level {} has a high voltage limit greater than 1.5 PU ({} PU)", voltageLevelId, newLimits.getSecond()); } normalizedVoltageLimitsOverride.put(voltageLevelId, newLimits); } diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/VoltageLimitOverride.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/VoltageLimitOverride.java index e1ace00a..fccd4c0a 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/VoltageLimitOverride.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/VoltageLimitOverride.java @@ -56,7 +56,7 @@ public VoltageLimitOverride(String voltageLevelId, VoltageLimitType type, boolea if (Double.isNaN(limit)) { throw new InvalidParametersException("The voltage limit override must be defined."); } - if (limit <= 0 && Boolean.FALSE.equals(isRelative)) { + if (limit < 0 && Boolean.FALSE.equals(isRelative)) { throw new InvalidParametersException("The voltage limit override is in absolute value: must be positive."); } this.voltageLevelId = Objects.requireNonNull(voltageLevelId); diff --git a/open-reac/src/main/resources/openreac/reactiveopf.mod b/open-reac/src/main/resources/openreac/reactiveopf.mod index c94c39a9..7c78f6d3 100644 --- a/open-reac/src/main/resources/openreac/reactiveopf.mod +++ b/open-reac/src/main/resources/openreac/reactiveopf.mod @@ -72,8 +72,8 @@ param substation_new_checkId {BOUND_OVERRIDES} symbolic; # Consistency checks check {(t,s) in SUBSTATIONS: s in BOUND_OVERRIDES}: substation_id[t,s] == substation_new_checkId[s]; -check {(t,s) in SUBSTATIONS: s in BOUND_OVERRIDES}: substation_new_Vmin[s] > 0; -check {(t,s) in SUBSTATIONS: s in BOUND_OVERRIDES}: substation_new_Vmax[s] > 0; +check {(t,s) in SUBSTATIONS: s in BOUND_OVERRIDES}: substation_new_Vmin[s] >= 0; +check {(t,s) in SUBSTATIONS: s in BOUND_OVERRIDES}: substation_new_Vmax[s] >= 0; check {(t,s) in SUBSTATIONS: s in BOUND_OVERRIDES}: substation_new_Vmin[s] < substation_new_Vmax[s]; 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 8fb89d23..fe743bf5 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 @@ -24,8 +24,7 @@ import java.util.ArrayList; import java.util.List; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.*; /** * @author Geoffroy Jamgotchian @@ -86,16 +85,16 @@ void testValidAbsoluteVoltageOverride() throws IOException { } @Test - void testNullVoltageLimitWithoutOverride() { + void testZeroVoltageLimit() { 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 + // 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)); + assertDoesNotThrow(() -> params.checkIntegrity(network)); } @Test @@ -143,7 +142,7 @@ void testVoltageOverrideWithNegativeVoltageLimit() { voltageLimitsOverride.clear(); voltageLimitsOverride.add(new VoltageLimitOverride(vl.getId(), VoltageLimitOverride.VoltageLimitType.LOW_VOLTAGE_LIMIT, true, -400)); params.addSpecificVoltageLimits(voltageLimitsOverride); - assertThrows(InvalidParametersException.class, () -> params.checkIntegrity(network)); + assertDoesNotThrow(() -> params.checkIntegrity(network)); // zero value // if high relative voltage override leads to negative voltage limit, throws exception OpenReacParameters params2 = new OpenReacParameters(); @@ -157,7 +156,7 @@ void testVoltageOverrideWithNegativeVoltageLimit() { voltageLimitsOverride2.clear(); voltageLimitsOverride2.add(new VoltageLimitOverride(vl.getId(), VoltageLimitOverride.VoltageLimitType.HIGH_VOLTAGE_LIMIT, true, -480)); params2.addSpecificVoltageLimits(voltageLimitsOverride2); - assertThrows(InvalidParametersException.class, () -> params2.checkIntegrity(network)); + assertDoesNotThrow(() -> params2.checkIntegrity(network)); // zero value } @Test From 401cdade0be8e9a7f8307100dd72de484109b88f Mon Sep 17 00:00:00 2001 From: parvy Date: Fri, 20 Oct 2023 11:48:38 +0200 Subject: [PATCH 2/3] Add AMPL check on high voltage limit override. Signed-off-by: parvy --- open-reac/src/main/resources/openreac/reactiveopf.mod | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/open-reac/src/main/resources/openreac/reactiveopf.mod b/open-reac/src/main/resources/openreac/reactiveopf.mod index 7c78f6d3..0edb53ff 100644 --- a/open-reac/src/main/resources/openreac/reactiveopf.mod +++ b/open-reac/src/main/resources/openreac/reactiveopf.mod @@ -90,9 +90,9 @@ param voltage_lower_bound{(t,s) in SUBSTATIONS} := ); param voltage_upper_bound{(t,s) in SUBSTATIONS} := - if s in BOUND_OVERRIDES then substation_new_Vmax[s] else - if substation_Vmax[t,s] <= voltage_lower_bound[t,s] - then maximal_voltage_upper_bound + if s in BOUND_OVERRIDES and substation_new_Vmax[s] <= voltage_lower_bound[t,s] then maximal_voltage_upper_bound + else if s in BOUND_OVERRIDES then min(maximal_voltage_upper_bound,substation_new_Vmax[s]) + else if substation_Vmax[t,s] <= voltage_lower_bound[t,s] then maximal_voltage_upper_bound else min(maximal_voltage_upper_bound,substation_Vmax[t,s]); check {(t,s) in SUBSTATIONS}: voltage_lower_bound[t,s] < voltage_upper_bound[t,s]; From 1d4467f4ea407fe4d161de4b44232810694b7b0c Mon Sep 17 00:00:00 2001 From: parvy Date: Fri, 20 Oct 2023 11:49:05 +0200 Subject: [PATCH 3/3] small fix. Signed-off-by: parvy --- .../parameters/input/VoltageLevelLimitsOverrideInput.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 991341d7..f1ee0241 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 @@ -71,7 +71,7 @@ private void transformToNormalizedVoltage(List voltageLimi if (newLimits.getFirst() < 0.5) { LOGGER.warn("Voltage level {} has a low voltage limit lower than 0.5 PU ({} PU)", voltageLevelId, newLimits.getFirst()); } - if (newLimits.getSecond() < 1.5) { + if (newLimits.getSecond() > 1.5) { LOGGER.warn("Voltage level {} has a high voltage limit greater than 1.5 PU ({} PU)", voltageLevelId, newLimits.getSecond()); } normalizedVoltageLimitsOverride.put(voltageLevelId, newLimits);