Skip to content

Commit

Permalink
Add voltage level limit checks against the nominal voltage (#64)
Browse files Browse the repository at this point in the history
* Verify that low voltage limit is less than nominal voltage and high voltage limit is greater than nominal voltage.
* Fix sonar issue.
* Changes after code review.
---------

Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
  • Loading branch information
FranckLecuyer authored Apr 18, 2024
1 parent 6fd3cc9 commit 8a9e43a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class VoltageLevelLimitsOverrideInput implements AmplInputFile {
private final Map<String, Pair<Double, Double>> normalizedVoltageLimitsOverride;

private static final Logger LOGGER = LoggerFactory.getLogger(VoltageLevelLimitsOverrideInput.class);
private static final String OVERRIDE_ON_VOLTAGE_LEVEL = "Override on voltage level ";

public VoltageLevelLimitsOverrideInput(List<VoltageLimitOverride> voltageLimitsOverrides, Network network) {
Objects.requireNonNull(voltageLimitsOverrides);
Expand Down Expand Up @@ -67,7 +68,7 @@ private void transformToNormalizedVoltage(List<VoltageLimitOverride> voltageLimi
}

if (newLimits.getFirst() >= newLimits.getSecond()) {
throw new InvalidParametersException("Override on voltage level " + voltageLevelId + " leads to low voltage limit >= high voltage limit.");
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());
Expand All @@ -77,6 +78,16 @@ private void transformToNormalizedVoltage(List<VoltageLimitOverride> voltageLimi
}
normalizedVoltageLimitsOverride.put(voltageLevelId, newLimits);
}

for (Map.Entry<String, Pair<Double, Double>> entry : normalizedVoltageLimitsOverride.entrySet()) {
String voltageLevelId = entry.getKey();
if (entry.getValue().getFirst() > 1.) {
throw new InvalidParametersException(OVERRIDE_ON_VOLTAGE_LEVEL + voltageLevelId + " leads to low voltage limit > nominal voltage.");
}
if (entry.getValue().getSecond() < 1.) {
throw new InvalidParametersException(OVERRIDE_ON_VOLTAGE_LEVEL + voltageLevelId + " leads to high voltage limit < nominal voltage.");
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,42 @@ void testVoltageOverrideWithLowLimitGreaterHighLimit() {
assertEquals("Override on voltage level " + vl.getId() + " leads to low voltage limit >= high voltage limit.", e3.getMessage());
}

@Test
void testVoltageOverrideWithLowLimitGreaterThanNominalVoltage() {
Network network = IeeeCdfNetworkFactory.create57();
setDefaultVoltageLimits(network); // set default voltage limits to every voltage levels of the network

VoltageLevel vl = network.getVoltageLevels().iterator().next();
vl.setHighVoltageLimit(400);
vl.setLowVoltageLimit(350);
vl.setNominalV(380);

List<VoltageLimitOverride> voltageLimitsOverride = new ArrayList<>();
voltageLimitsOverride.add(new VoltageLimitOverride(vl.getId(), VoltageLimitOverride.VoltageLimitType.LOW_VOLTAGE_LIMIT, false, 390.));

// if after override, low limit > nominal voltage, wrong parameters
InvalidParametersException e = assertThrows(InvalidParametersException.class, () -> new VoltageLevelLimitsOverrideInput(voltageLimitsOverride, network));
assertEquals("Override on voltage level " + vl.getId() + " leads to low voltage limit > nominal voltage.", e.getMessage());
}

@Test
void testVoltageOverrideWithHighLimitLessThanNominalVoltage() {
Network network = IeeeCdfNetworkFactory.create57();
setDefaultVoltageLimits(network); // set default voltage limits to every voltage levels of the network

VoltageLevel vl = network.getVoltageLevels().iterator().next();
vl.setHighVoltageLimit(400);
vl.setLowVoltageLimit(350);
vl.setNominalV(380);

List<VoltageLimitOverride> voltageLimitsOverride = new ArrayList<>();
voltageLimitsOverride.add(new VoltageLimitOverride(vl.getId(), VoltageLimitOverride.VoltageLimitType.HIGH_VOLTAGE_LIMIT, false, 360.));

// if after override, high limit < nominal voltage, wrong parameters
InvalidParametersException e = assertThrows(InvalidParametersException.class, () -> new VoltageLevelLimitsOverrideInput(voltageLimitsOverride, network));
assertEquals("Override on voltage level " + vl.getId() + " leads to high voltage limit < nominal voltage.", e.getMessage());
}

@Test
void testVoltageOverrideOnInvalidVoltageLevel() {
Network network = IeeeCdfNetworkFactory.create57();
Expand Down

0 comments on commit 8a9e43a

Please sign in to comment.