Skip to content

Commit

Permalink
Add check and fix export of substations ID for voltage overrides.
Browse files Browse the repository at this point in the history
Signed-off-by: parvy <[email protected]>
  • Loading branch information
p-arvy committed Oct 11, 2023
1 parent 5aa6b77 commit d1eedd3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,17 @@ boolean checkVoltageLevelLimits(Network network) {
double lowLimit = vl.getLowVoltageLimit();
double highLimit = vl.getHighVoltageLimit();

if (lowLimit <= 0) {
List<VoltageLimitOverride> 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<VoltageLimitOverride> overrides = getSpecificVoltageLimits(vl.getId(), VoltageLimitOverride.VoltageLimitType.LOW_VOLTAGE_LIMIT);
if (overrides.size() != 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -82,7 +81,7 @@ public InputStream getParameterFileAsStream(StringToIntMapper<AmplSubset> 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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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<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
void testUndefinedVoltageLimitsWithoutOverride() {
Network network = IeeeCdfNetworkFactory.create118();
Expand Down

0 comments on commit d1eedd3

Please sign in to comment.