Skip to content

Commit

Permalink
Modify VoltageLimitOverride class to one side voltage limit override
Browse files Browse the repository at this point in the history
Signed-off-by: parvy <[email protected]>
  • Loading branch information
p-arvy committed Oct 10, 2023
1 parent 3dd9fc9 commit fd98b1f
Show file tree
Hide file tree
Showing 13 changed files with 337 additions and 389 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.jgrapht.alg.util.Pair;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -165,9 +166,11 @@ public OpenReacParameters createOpenReacParameters(CommandLine line,
String voltageId = node.get("id").asText();
double lowerPercent = node.get("lower").asDouble();
double upperPercent = node.get("upper").asDouble();
openReacParameters.addSpecificVoltageLimits(Map.of(voltageId,
new VoltageLimitOverride(VoltageLimitOverride.OverrideKind.RELATIVE, VoltageLimitOverride.OverrideKind.RELATIVE,
lowerPercent, upperPercent)));

List<Pair<String, VoltageLimitOverride>> voltageLimitOverrides = new ArrayList<>();
voltageLimitOverrides.add(new Pair<>(voltageId, new VoltageLimitOverride(VoltageLimitOverride.OverrideSide.LOW, true, lowerPercent)));
voltageLimitOverrides.add(new Pair<>(voltageId, new VoltageLimitOverride(VoltageLimitOverride.OverrideSide.HIGH, true, upperPercent)));
openReacParameters.addSpecificVoltageLimits(voltageLimitOverrides);
});
}
boolean objectiveSet = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.powsybl.openreac.parameters.input.algo.OpenReacAlgoParam;
import com.powsybl.openreac.parameters.input.algo.OpenReacAlgoParamImpl;
import com.powsybl.openreac.parameters.input.algo.OpenReacOptimisationObjective;
import org.jgrapht.alg.util.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -28,7 +29,7 @@ public class OpenReacParameters {

private static final String OBJECTIVE_DISTANCE_KEY = "ratio_voltage_target";

private final Map<String, VoltageLimitOverride> specificVoltageLimits = new HashMap<>();
private final List<Pair<String, VoltageLimitOverride>> specificVoltageLimits = new ArrayList<>();
private final List<String> variableShuntCompensators = new ArrayList<>();
private final List<String> constantQGenerators = new ArrayList<>();
private final List<String> variableTwoWindingsTransformers = new ArrayList<>();
Expand All @@ -49,8 +50,8 @@ public class OpenReacParameters {
* The override is ignored if one or both of the voltage limit are NaN.
* @param specificVoltageLimits keys: a VoltageLevel ID, values: low and high delta limits (kV).
*/
public OpenReacParameters addSpecificVoltageLimits(Map<String, VoltageLimitOverride> specificVoltageLimits) {
this.specificVoltageLimits.putAll(Objects.requireNonNull(specificVoltageLimits));
public OpenReacParameters addSpecificVoltageLimits(List<Pair<String, VoltageLimitOverride>> specificVoltageLimits) {
this.specificVoltageLimits.addAll(Objects.requireNonNull(specificVoltageLimits));
return this;
}

Expand Down Expand Up @@ -133,7 +134,7 @@ public List<String> getVariableShuntCompensators() {
return variableShuntCompensators;
}

public Map<String, VoltageLimitOverride> getSpecificVoltageLimits() {
public List<Pair<String, VoltageLimitOverride>> getSpecificVoltageLimits() {
return specificVoltageLimits;
}

Expand Down Expand Up @@ -181,102 +182,144 @@ public void checkIntegrity(Network network) throws InvalidParametersException {
}

// Check integrity of voltage overrides
boolean inconsistentOverride = false;
for (String voltageLevelId : getSpecificVoltageLimits().keySet()) {
VoltageLevel voltageLevel = network.getVoltageLevel(voltageLevelId);

// Check existence of voltage level on which is applied voltage limit override
if (voltageLevel == null) {
LOGGER.warn("Voltage level " + voltageLevelId + " not found in the network.");
inconsistentOverride = true;

} else {
// if low voltage override is relative, check new low voltage limit is > 0
VoltageLimitOverride override = getSpecificVoltageLimits().get(voltageLevelId);
if (override.getLowLimitKind() == VoltageLimitOverride.OverrideKind.RELATIVE &&
voltageLevel.getNominalV() + override.getLowLimitOverride() < 0) {
LOGGER.warn("Voltage level " + voltageLevelId + " relative override leads to negative low voltage limit.");
inconsistentOverride = true;
}
// if low voltage override is absolute, check new low voltage limit is > 0
if (override.getLowLimitKind() == VoltageLimitOverride.OverrideKind.ABSOLUTE &&
override.getLowLimitOverride() < 0) {
LOGGER.warn("Voltage level " + voltageLevelId + " absolute override leads to negative low voltage limit.");
inconsistentOverride = true;
}
// if low/high voltage overrides are absolute, check new low limit is < new high limit
if (override.getLowLimitKind() == VoltageLimitOverride.OverrideKind.ABSOLUTE &&
override.getHighLimitKind() == VoltageLimitOverride.OverrideKind.ABSOLUTE &&
override.getLowLimitOverride() > override.getHighLimitOverride()) {
LOGGER.warn("Voltage level " + voltageLevelId + " override leads to low voltage limit > high voltage limit.");
inconsistentOverride = true;
}
}
boolean integrityVoltageLimitOverrides = checkVoltageLimitOverrides(network);
if (!integrityVoltageLimitOverrides) {
throw new InvalidParametersException("At least one voltage limit override is inconsistent.");
}

// Check integrity of low/high voltage limits, taking into account voltage limit overrides
boolean integrityVoltageLevelLimits = checkVoltageLevelLimits(network);
if (!integrityVoltageLevelLimits) {
throw new InvalidParametersException("At least one voltage level has an undefined or incorrect voltage limit.");
}

if (inconsistentOverride) {
throw new InvalidParametersException("At least one voltage limit override is inconsistent.");
if (objective.equals(OpenReacOptimisationObjective.BETWEEN_HIGH_AND_LOW_VOLTAGE_LIMIT) && objectiveDistance == null) {
throw new InvalidParametersException("In using " + OpenReacOptimisationObjective.BETWEEN_HIGH_AND_LOW_VOLTAGE_LIMIT +
" as objective, a distance in percent between low and high voltage limits is expected.");
}

// Check integrity of low/high voltage limits, taking into account voltage limit overrides
boolean limitUndefined = false;
}

boolean checkVoltageLevelLimits(Network network) {
boolean integrityVoltageLevelLimits = true;

for (VoltageLevel vl : network.getVoltageLevels()) {
double lowLimit = vl.getLowVoltageLimit();
double highLimit = vl.getHighVoltageLimit();

if (lowLimit <= 0 || Double.isNaN(lowLimit)) {

// Check if voltage override exists
if (getSpecificVoltageLimits().containsKey(vl.getId())) {
VoltageLimitOverride override = getSpecificVoltageLimits().get(vl.getId());

// Relative override on undefined low voltage limit is incorrect
if (override.getLowLimitKind() == VoltageLimitOverride.OverrideKind.RELATIVE) {
LOGGER.warn("Relative voltage override impossible on undefined low voltage limit for voltage level '"
+ vl.getId() + "'.");
limitUndefined = true;
// If low voltage limit is undefined...
if (Double.isNaN(lowLimit)) {

// find associated override if it exists
boolean hasOverride = false;
VoltageLimitOverride associatedOverride = null;
for (Pair<String, VoltageLimitOverride> pair : getSpecificVoltageLimits()) {
if (pair.getFirst().equals(vl.getId()) && pair.getSecond().getSide() == VoltageLimitOverride.OverrideSide.LOW) {
hasOverride = true;
associatedOverride = pair.getSecond();
break;
}
}

// If no voltage override, low voltage limit is undefined or incorrect
} else {
// ... verify if there is an override for the undefined limit
if (!hasOverride) {
LOGGER.warn("Voltage level '" + vl.getId() + "' has no low voltage limit defined. " +
"Please add one or use a voltage limit override.");
limitUndefined = true;
integrityVoltageLevelLimits = false;

// ... verify override is not relative
} else if (associatedOverride.isRelative()) {
LOGGER.warn("Relative voltage override impossible on undefined low voltage limit for voltage level '"
+ vl.getId() + "'.");
integrityVoltageLevelLimits = false;
}
}

// If high voltage limit is undefined, check if voltage override exists
// If high voltage limit is undefined...
if (Double.isNaN(highLimit)) {

// Check if voltage override exists
if (getSpecificVoltageLimits().containsKey(vl.getId())) {
VoltageLimitOverride override = getSpecificVoltageLimits().get(vl.getId());

// Relative override on undefined high voltage limit is incorrect
if (override.getHighLimitKind() == VoltageLimitOverride.OverrideKind.RELATIVE) {
LOGGER.warn("Relative voltage override impossible on undefined high voltage limit for voltage level '"
+ vl.getId() + "'.");
limitUndefined = true;
// find associated override if it exists
boolean hasOverride = false;
VoltageLimitOverride associatedOverride = null;
for (Pair<String, VoltageLimitOverride> pair : getSpecificVoltageLimits()) {
if (pair.getFirst().equals(vl.getId()) && pair.getSecond().getSide() == VoltageLimitOverride.OverrideSide.HIGH) {
hasOverride = true;
associatedOverride = pair.getSecond();
break;
}
}

// If no voltage override, high voltage limit is undefined
} else {
// ... verify if there is an override for the undefined limit
if (!hasOverride) {
LOGGER.warn("Voltage level '" + vl.getId() + "' has no high voltage limit defined. " +
"Please add one or use a voltage limit override.");
limitUndefined = true;
integrityVoltageLevelLimits = false;

// ... verify override is not relative
} else if (associatedOverride.isRelative()) {
LOGGER.warn("Relative voltage override impossible on undefined high voltage limit for voltage level '"
+ vl.getId() + "'.");
integrityVoltageLevelLimits = false;
}
}
}

if (limitUndefined) {
throw new InvalidParametersException("At least one voltage level has an undefined or incorrect voltage limit.");
}
return integrityVoltageLevelLimits;
}

/**
* @param network the network on which are applied voltage limit overrides.
* @return true if the integrity of voltage limit overrides is verifies, false otherwise.
*/
boolean checkVoltageLimitOverrides(Network network) {
// Check integrity of voltage overrides
boolean integrityVoltageLimitOverrides = true;
for (Pair<String, VoltageLimitOverride> pair : getSpecificVoltageLimits()) {
String voltageLevelId = pair.getFirst();
VoltageLevel voltageLevel = network.getVoltageLevel(voltageLevelId);

// Check existence of voltage level on which is applied voltage limit override
if (voltageLevel == null) {
LOGGER.warn("Voltage level " + voltageLevelId + " not found in the network.");
integrityVoltageLimitOverrides = false;

} else {
VoltageLimitOverride override = pair.getSecond();

// if the override is relative...
if (override.isRelative()) {

// ... and on low limit ...
if (override.getSide() == VoltageLimitOverride.OverrideSide.LOW) {

// ... verify low voltage limit is defined
if (Double.isNaN(voltageLevel.getLowVoltageLimit())) {
LOGGER.warn("Voltage level '" + voltageLevelId + "' has undefined low voltage limit, " +
"relative voltage limit override impossible.");
integrityVoltageLimitOverrides = false;
}

// ... verify low voltage limit override does not lead to negative limit value
if (override.getLimitOverride() + voltageLevel.getLowVoltageLimit() < 0) {
LOGGER.warn("Voltage level " + voltageLevelId + " low relative override leads to negative low voltage limit.");
integrityVoltageLimitOverrides = false;
}
// ... and on high limit ...
} else {

// ... verify high voltage limit is defined
if (Double.isNaN(voltageLevel.getHighVoltageLimit())) {
LOGGER.warn("Voltage level '" + voltageLevelId + "' has undefined high voltage limit, " +
"relative voltage limit override impossible.");
integrityVoltageLimitOverrides = false;
}
}

}
}

if (objective.equals(OpenReacOptimisationObjective.BETWEEN_HIGH_AND_LOW_VOLTAGE_LIMIT) && objectiveDistance == null) {
throw new InvalidParametersException("In using " + OpenReacOptimisationObjective.BETWEEN_HIGH_AND_LOW_VOLTAGE_LIMIT +
" as objective, a distance in percent between low and high voltage limits is expected.");
}

return integrityVoltageLimitOverrides;
}
}
Loading

0 comments on commit fd98b1f

Please sign in to comment.