Skip to content

Commit

Permalink
Add interface for min/max voltage limit parameters.
Browse files Browse the repository at this point in the history
Signed-off-by: parvy <pierre.arvy@artelys.com>
  • Loading branch information
p-arvy committed Nov 10, 2023
1 parent 7c201cd commit 34fbc8e
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public class OpenReacParameters {

private static final Logger LOGGER = LoggerFactory.getLogger(OpenReacParameters.class);

private static final String OBJECTIVE_DISTANCE_KEY = "ratio_voltage_target";

private final List<VoltageLimitOverride> specificVoltageLimits = new ArrayList<>();

private final List<String> variableShuntCompensators = new ArrayList<>();
Expand All @@ -39,10 +37,22 @@ public class OpenReacParameters {

private final List<OpenReacAlgoParam> algorithmParams = new ArrayList<>();

// Algo parameters

private OpenReacOptimisationObjective objective = OpenReacOptimisationObjective.MIN_GENERATION;

private static final String OBJECTIVE_DISTANCE_KEY = "ratio_voltage_target";

private Double objectiveDistance;

private static final String MIN_VOLTAGE_LIMIT_CONSISTENCY_KEY = "consistent_min_voltage";

private Double minVoltageLimitConsistency; // in pu

private static final String MAX_VOLTAGE_LIMIT_CONSISTENCY_KEY = "consistent_max_voltage";

private Double maxVoltageLimitConsistency; // in pu

/**
* Override some voltage level limits in the network. This will NOT modify the network object.
* <p>
Expand Down Expand Up @@ -137,6 +147,36 @@ public OpenReacParameters setObjectiveDistance(double objectiveDistance) {
return this;
}

/**
* @return the minimal voltage limit consistency value in p.u.
*/
public Double getMinVoltageLimitConsistency() {
return minVoltageLimitConsistency;
}

public OpenReacParameters setMinVoltageLimitConsistency(double minVoltageLimitConsistency) {
if (minVoltageLimitConsistency < 0) {
throw new InvalidParametersException("Minimal voltage limit must be >= 0 to be consistent.");
}
this.minVoltageLimitConsistency = minVoltageLimitConsistency;
return this;
}

/**
* @return the maximal voltage limit consistency value in p.u.
*/
public Double getMaxVoltageLimitConsistency() {
return maxVoltageLimitConsistency;
}

public OpenReacParameters setMaxVoltageLimitConsistency(double maxVoltageLimitConsistency) {
if (maxVoltageLimitConsistency <= 0) {
throw new InvalidParametersException("Maximal voltage limit must be > 0 to be consistent.");
}
this.maxVoltageLimitConsistency = maxVoltageLimitConsistency;
return this;
}

public List<String> getVariableShuntCompensators() {
return variableShuntCompensators;
}
Expand All @@ -154,14 +194,20 @@ public List<String> getVariableTwoWindingsTransformers() {
}

public List<OpenReacAlgoParam> getAllAlgorithmParams() {
ArrayList<OpenReacAlgoParam> allAlgoParams = new ArrayList<>(algorithmParams.size() + 2);
ArrayList<OpenReacAlgoParam> allAlgoParams = new ArrayList<>(algorithmParams.size() + 4);
allAlgoParams.addAll(algorithmParams);
if (objective != null) {
allAlgoParams.add(objective.toParam());
}
if (objectiveDistance != null) {
allAlgoParams.add(new OpenReacAlgoParamImpl(OBJECTIVE_DISTANCE_KEY, Double.toString(objectiveDistance / 100)));
}
if (minVoltageLimitConsistency != null) {
allAlgoParams.add(new OpenReacAlgoParamImpl(MIN_VOLTAGE_LIMIT_CONSISTENCY_KEY, Double.toString(minVoltageLimitConsistency)));
}
if (maxVoltageLimitConsistency != null) {
allAlgoParams.add(new OpenReacAlgoParamImpl(MAX_VOLTAGE_LIMIT_CONSISTENCY_KEY, Double.toString(maxVoltageLimitConsistency)));
}
return allAlgoParams;
}

Expand Down Expand Up @@ -201,11 +247,32 @@ public void checkIntegrity(Network network) throws InvalidParametersException {
throw new InvalidParametersException("At least one voltage level has an undefined or incorrect voltage limit.");
}

boolean integrityAlgorithmParameters = checkAlgorithmParametersIntegrity();
if (!integrityAlgorithmParameters) {
throw new InvalidParametersException("At least one algorithm parameter is inconsistent.");
}
}

/**
* @return true if the algorithm parameters are consistent, false otherwise.
*/
public boolean checkAlgorithmParametersIntegrity() {
boolean integrityAlgorithmParameters = true;

// Check integrity of objective function
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.");
LOGGER.warn("In using {} as objective, a distance in percent between low and high voltage limits is expected.", OpenReacOptimisationObjective.BETWEEN_HIGH_AND_LOW_VOLTAGE_LIMIT);
integrityAlgorithmParameters = false;
}

// Check integrity of min/max voltage limit consistency
if (minVoltageLimitConsistency != null && maxVoltageLimitConsistency != null
&& minVoltageLimitConsistency > maxVoltageLimitConsistency) {
LOGGER.warn("Minimal consistent voltage limit must be lower than the maximum consistent voltage limit.");
integrityAlgorithmParameters = false;
}

return integrityAlgorithmParameters;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.powsybl.iidm.network.*;
import com.powsybl.openreac.exceptions.InvalidParametersException;
import com.powsybl.openreac.parameters.input.OpenReacParameters;
import com.powsybl.openreac.parameters.input.algo.OpenReacAlgoParam;
import com.powsybl.openreac.parameters.input.algo.OpenReacOptimisationObjective;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -39,6 +40,52 @@ public void testObjectiveIntegrityChecks() {
assertDoesNotThrow(() -> parameters.checkIntegrity(network), "Default configuration with BETWEEN_HIGH_AND_LOW_VOLTAGE_LIMIT and ratio voltage set should not throw");
}

@Test
public void testMinMaxVoltageLimitIntegrityChecks() {
OpenReacParameters parameters = new OpenReacParameters();
assertNull(parameters.getMinVoltageLimitConsistency());
assertNull(parameters.getMaxVoltageLimitConsistency());

// Consistency of min voltage limit (>= 0)
assertThrows(InvalidParametersException.class, () -> parameters.setMinVoltageLimitConsistency(-0.25));
parameters.setMinVoltageLimitConsistency(0.8);
assertEquals(0.8, parameters.getMinVoltageLimitConsistency());

// Consistency of high voltage limit (> 0)
assertThrows(InvalidParametersException.class, () -> parameters.setMaxVoltageLimitConsistency(-0.15));
assertThrows(InvalidParametersException.class, () -> parameters.setMaxVoltageLimitConsistency(0));
parameters.setMaxVoltageLimitConsistency(0.75);
assertEquals(0.75, parameters.getMaxVoltageLimitConsistency());

// Check min < max
assertFalse(parameters.checkAlgorithmParametersIntegrity());
parameters.setMaxVoltageLimitConsistency(1.2);
assertTrue(parameters.checkAlgorithmParametersIntegrity());
}

@Test
void testAlgorithmParams() {
OpenReacParameters parameters = new OpenReacParameters();
parameters.addAlgorithmParam("myParam", "myValue");
parameters.setObjective(OpenReacOptimisationObjective.SPECIFIC_VOLTAGE_PROFILE);
parameters.setObjectiveDistance(0.4);
parameters.setMinVoltageLimitConsistency(0.8);
parameters.setMaxVoltageLimitConsistency(1.2);
List<OpenReacAlgoParam> algoParams = parameters.getAllAlgorithmParams();

assertEquals(5, algoParams.size());
assertEquals("myParam", algoParams.get(0).getName());
assertEquals("myValue", algoParams.get(0).getValue());
assertEquals("objective_choice", algoParams.get(1).getName());
assertEquals("2", algoParams.get(1).getValue());
assertEquals("ratio_voltage_target", algoParams.get(2).getName());
assertEquals("0.004", algoParams.get(2).getValue());
assertEquals("consistent_min_voltage", algoParams.get(3).getName());
assertEquals("0.8", algoParams.get(3).getValue());
assertEquals("consistent_max_voltage", algoParams.get(4).getName());
assertEquals("1.2", algoParams.get(4).getValue());
}

@Test
public void testParametersIntegrityChecks() {
Network network = IeeeCdfNetworkFactory.create118();
Expand Down

0 comments on commit 34fbc8e

Please sign in to comment.