Skip to content

Commit

Permalink
Add check for null voltage limit, and case with low voltage limit gre…
Browse files Browse the repository at this point in the history
…ater than high limit.

Signed-off-by: parvy <pierre.arvy@artelys.com>
  • Loading branch information
p-arvy committed Oct 18, 2023
1 parent 60ce8ec commit 82d35d2
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<VoltageLimitOverride> overrides = getSpecificVoltageLimits(vl.getId(), VoltageLimitOverride.VoltageLimitType.LOW_VOLTAGE_LIMIT);
if (overrides.size() != 1) {
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -60,6 +61,10 @@ private void transformToNormalizedVoltage(List<VoltageLimitOverride> 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<VoltageLimitOverride> 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
Expand Down Expand Up @@ -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<VoltageLimitOverride> 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<VoltageLimitOverride> voltageLimitsOverride = new ArrayList<>();
voltageLimitsOverride.add(new VoltageLimitOverride(vl.getId(), VoltageLimitOverride.VoltageLimitType.HIGH_VOLTAGE_LIMIT, true, -90));

List<VoltageLimitOverride> voltageLimitsOverride2 = new ArrayList<>();
voltageLimitsOverride2.add(new VoltageLimitOverride(vl.getId(), VoltageLimitOverride.VoltageLimitType.LOW_VOLTAGE_LIMIT, true, 90));

List<VoltageLimitOverride> 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
Expand Down

0 comments on commit 82d35d2

Please sign in to comment.