Skip to content

Commit

Permalink
Renaming.
Browse files Browse the repository at this point in the history
Signed-off-by: Anne Tilloy <anne.tilloy@rte-france.com>
  • Loading branch information
annetill committed Nov 24, 2023
1 parent abfae6f commit 80689a8
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class OpenReacAmplIOFiles implements AmplParameters {
private final AlgorithmInput algorithmParams;
private final ReactiveSlackOutput reactiveSlackOutput;
private final VoltageLevelLimitsOverrideInput voltageLimitsOverride;
private final ConfiguredBusesWithReactiveSlack configuredBusesWithReactiveSlack;
private final ConfiguredBusesWithReactiveSlack configuredReactiveSlackBuses;
private final NetworkModifications networkModifications;
private final boolean debug;

Expand All @@ -49,7 +49,7 @@ public OpenReacAmplIOFiles(OpenReacParameters params, Network network, boolean d
this.variableTwoWindingsTransformers = new VariableTwoWindingsTransformers(params.getVariableTwoWindingsTransformers());
this.algorithmParams = new AlgorithmInput(params.getAllAlgorithmParams());
this.voltageLimitsOverride = new VoltageLevelLimitsOverrideInput(params.getSpecificVoltageLimits(), network);
this.configuredBusesWithReactiveSlack = new ConfiguredBusesWithReactiveSlack(params.getConfiguredBusesWithReactiveSlacks());
this.configuredReactiveSlackBuses = new ConfiguredBusesWithReactiveSlack(params.getConfiguredReactiveSlackBuses());

//outputs
this.reactiveSlackOutput = new ReactiveSlackOutput();
Expand All @@ -69,7 +69,7 @@ public NetworkModifications getNetworkModifications() {
@Override
public Collection<AmplInputFile> getInputParameters() {
return List.of(constantQGenerators, variableShuntCompensators, variableTwoWindingsTransformers,
algorithmParams, voltageLimitsOverride, configuredBusesWithReactiveSlack);
algorithmParams, voltageLimitsOverride, configuredReactiveSlackBuses);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class OpenReacParameters {

private final List<String> variableTwoWindingsTransformers = new ArrayList<>();

private final List<String> busesWithReactiveSlack = new ArrayList<>();
private final List<String> configuredReactiveSlackBuses = new ArrayList<>();

// Algo parameters

Expand All @@ -56,7 +56,7 @@ public class OpenReacParameters {

private double maxPlausibleHighVoltageLimit = 1.5; // in pu

private OpenReacBusesWithReactiveSlackConfig busesWithReactiveSlackConfig = OpenReacBusesWithReactiveSlackConfig.NO_GENERATION;
private ReactiveSlackBusesMode reactiveSlackBusesMode = ReactiveSlackBusesMode.NO_GENERATION;

/**
* Override some voltage level limits in the network. This will NOT modify the network object.
Expand Down Expand Up @@ -94,8 +94,8 @@ public OpenReacParameters addVariableTwoWindingsTransformers(List<String> transf
return this;
}

public OpenReacParameters addBusesWithReactiveSlack(List<String> busesIds) {
this.busesWithReactiveSlack.addAll(busesIds);
public OpenReacParameters addConfiguredReactiveSlackBuses(List<String> busesIds) {
this.configuredReactiveSlackBuses.addAll(busesIds);
return this;
}

Expand Down Expand Up @@ -200,12 +200,12 @@ public OpenReacParameters setMaxPlausibleHighVoltageLimit(double maxPlausibleHig
return this;
}

public OpenReacBusesWithReactiveSlackConfig getBusesWithReactiveSlackConfig() {
return busesWithReactiveSlackConfig;
public ReactiveSlackBusesMode getReactiveSlackBusesMode() {
return reactiveSlackBusesMode;
}

public OpenReacParameters setBusesWithReactiveSlackConfig(OpenReacBusesWithReactiveSlackConfig busesWithReactiveSlackConfig) {
this.busesWithReactiveSlackConfig = Objects.requireNonNull(busesWithReactiveSlackConfig);
public OpenReacParameters setReactiveSlackBusesMode(ReactiveSlackBusesMode reactiveSlackBusesMode) {
this.reactiveSlackBusesMode = Objects.requireNonNull(reactiveSlackBusesMode);
return this;
}

Expand All @@ -225,8 +225,8 @@ public List<String> getVariableTwoWindingsTransformers() {
return variableTwoWindingsTransformers;
}

public List<String> getConfiguredBusesWithReactiveSlacks() {
return busesWithReactiveSlack;
public List<String> getConfiguredReactiveSlackBuses() {
return configuredReactiveSlackBuses;
}

public List<OpenReacAlgoParam> getAllAlgorithmParams() {
Expand All @@ -239,7 +239,7 @@ public List<OpenReacAlgoParam> getAllAlgorithmParams() {
allAlgoParams.add(this.logLevelSolver.toParam());
allAlgoParams.add(new OpenReacAlgoParamImpl(MIN_PLAUSIBLE_LOW_VOLTAGE_LIMIT_KEY, Double.toString(minPlausibleLowVoltageLimit)));
allAlgoParams.add(new OpenReacAlgoParamImpl(MAX_PLAUSIBLE_HIGH_VOLTAGE_LIMIT_KEY, Double.toString(maxPlausibleHighVoltageLimit)));
allAlgoParams.add(busesWithReactiveSlackConfig.toParam());
allAlgoParams.add(reactiveSlackBusesMode.toParam());
return allAlgoParams;
}

Expand All @@ -265,7 +265,7 @@ public void checkIntegrity(Network network) throws InvalidParametersException {
throw new InvalidParametersException("Two windings transformer " + transformerId + " not found in the network.");
}
}
for (String busId : getConfiguredBusesWithReactiveSlacks()) {
for (String busId : getConfiguredReactiveSlackBuses()) {
if (network.getBusView().getBus(busId) == null) {
throw new InvalidParametersException("Bus " + busId + " not found in the network.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,24 @@
/**
* @author Pierre Arvy <pierre.arvy at artelys.com>
*/
public enum OpenReacBusesWithReactiveSlackConfig {
SPECIFIED("SPECIFIED"),
public enum ReactiveSlackBusesMode {
CONFIGURED("CONFIGURED"),
NO_GENERATION("NO_GENERATION"),

ALL("ALL");

private static final String BUSES_REACTIVE_SLACKS_KEY = "buses_with_reactive_slacks";
private static final String REACTIVE_SLACK_BUSES_KEY = "buses_with_reactive_slacks";

private final String amplKey;

/**
* @param amplKey value used in param_algo.txt to define the slacks repartition.
*/
OpenReacBusesWithReactiveSlackConfig(String amplKey) {
ReactiveSlackBusesMode(String amplKey) {
this.amplKey = amplKey;
}

public OpenReacAlgoParam toParam() {
return new OpenReacAlgoParamImpl(BUSES_REACTIVE_SLACKS_KEY, amplKey);
return new OpenReacAlgoParamImpl(REACTIVE_SLACK_BUSES_KEY, amplKey);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.powsybl.openreac.parameters.input.OpenReacParameters;
import com.powsybl.openreac.parameters.input.VoltageLimitOverride;
import com.powsybl.openreac.parameters.input.algo.OpenReacAmplLogLevel;
import com.powsybl.openreac.parameters.input.algo.OpenReacBusesWithReactiveSlackConfig;
import com.powsybl.openreac.parameters.input.algo.ReactiveSlackBusesMode;
import com.powsybl.openreac.parameters.input.algo.OpenReacOptimisationObjective;
import com.powsybl.openreac.parameters.input.algo.OpenReacSolverLogLevel;

Expand Down Expand Up @@ -58,9 +58,9 @@ public OpenReacParameters deserialize(JsonParser parser, DeserializationContext
parser.nextToken();
parameters.addVariableTwoWindingsTransformers(parser.readValueAs(new TypeReference<List<String>>() { }));
break;
case "busesWithReactiveSlack":
case "configuredReactiveSlackBuses":
parser.nextToken();
parameters.addBusesWithReactiveSlack(parser.readValueAs(new TypeReference<List<String>>() { }));
parameters.addConfiguredReactiveSlackBuses(parser.readValueAs(new TypeReference<List<String>>() { }));
break;
case "objective":
parser.nextToken();
Expand All @@ -86,9 +86,9 @@ public OpenReacParameters deserialize(JsonParser parser, DeserializationContext
parser.nextToken();
parameters.setMaxPlausibleHighVoltageLimit(parser.readValueAs(Double.class));
break;
case "busesWithReactiveSlackConfig":
case "reactiveSlackBusesMode":
parser.nextToken();
parameters.setBusesWithReactiveSlackConfig(OpenReacBusesWithReactiveSlackConfig.valueOf(parser.getText()));
parameters.setReactiveSlackBusesMode(ReactiveSlackBusesMode.valueOf(parser.getText()));
break;
default:
throw new IllegalStateException("Unexpected field: " + parser.getCurrentName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.powsybl.openreac.parameters.input.OpenReacParameters;
import com.powsybl.openreac.parameters.input.algo.OpenReacBusesWithReactiveSlackConfig;
import com.powsybl.openreac.parameters.input.algo.ReactiveSlackBusesMode;

import java.io.IOException;

Expand All @@ -35,8 +35,8 @@ public void serialize(OpenReacParameters openReacParameters, JsonGenerator jsonG
serializerProvider.defaultSerializeField("constantQGenerators", openReacParameters.getConstantQGenerators(), jsonGenerator);
serializerProvider.defaultSerializeField("variableTwoWindingsTransformers", openReacParameters.getVariableTwoWindingsTransformers(), jsonGenerator);
serializerProvider.defaultSerializeField("variableShuntCompensators", openReacParameters.getVariableShuntCompensators(), jsonGenerator);
if (openReacParameters.getBusesWithReactiveSlackConfig() == OpenReacBusesWithReactiveSlackConfig.SPECIFIED) {
serializerProvider.defaultSerializeField("busesWithReactiveSlack", openReacParameters.getConfiguredBusesWithReactiveSlacks(), jsonGenerator);
if (openReacParameters.getReactiveSlackBusesMode() == ReactiveSlackBusesMode.CONFIGURED) {
serializerProvider.defaultSerializeField("configuredReactiveSlackBuses", openReacParameters.getConfiguredReactiveSlackBuses(), jsonGenerator);
}
serializerProvider.defaultSerializeField("objective", openReacParameters.getObjective().name(), jsonGenerator);
if (openReacParameters.getObjectiveDistance() != null) {
Expand All @@ -46,7 +46,7 @@ public void serialize(OpenReacParameters openReacParameters, JsonGenerator jsonG
serializerProvider.defaultSerializeField("logLevelSolver", openReacParameters.getLogLevelSolver(), jsonGenerator);
serializerProvider.defaultSerializeField("minPlausibleLowVoltageLimit", openReacParameters.getMinPlausibleLowVoltageLimit(), jsonGenerator);
serializerProvider.defaultSerializeField("maxPlausibleHighVoltageLimit", openReacParameters.getMaxPlausibleHighVoltageLimit(), jsonGenerator);
serializerProvider.defaultSerializeField("busesWithReactiveSlackConfig", openReacParameters.getBusesWithReactiveSlackConfig().name(), jsonGenerator);
serializerProvider.defaultSerializeField("reactiveSlackBusesMode", openReacParameters.getReactiveSlackBusesMode().name(), jsonGenerator);
jsonGenerator.writeEndObject();
}
}
14 changes: 7 additions & 7 deletions open-reac/src/main/resources/openreac/reactiveopf.run
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,11 @@ display PARAM_ALGO_VALUES;

# Log level of ampl printing
set LOG_LEVELS ordered = {"ERROR", "WARNING", "INFO", "DEBUG"}; # different values of log level for ampl exec
param log_level_ampl symbolic default "INFO"; # default value of log level
param log_level_ampl symbolic default "INFO"; # default value of log level
if "log_level_ampl" in PARAM_ALGO_KEYS then let log_level_ampl := PARAM_ALGO_VALUES["log_level_ampl"];

# Sets used to print or not. A void set avoid printing
param log_index := ord0(log_level_ampl, LOG_LEVELS);
param log_index := ord0(log_level_ampl, LOG_LEVELS);
set LOG_DEBUG := if log_index >= 4 then{1} else {};
set LOG_INFO := if log_index >= 3 then{1} else {};
set LOG_WARNING := if log_index >= 2 then{1} else {};
Expand Down Expand Up @@ -320,8 +320,8 @@ if "buses_with_reactive_slacks" in PARAM_ALGO_KEYS then let buses_with_reactive_
printf{LOG_INFO} "Parameter: choice for buses with reactive slacks in ACOPF := %Q (%s)\n", buses_with_reactive_slacks,
if buses_with_reactive_slacks == "ALL" then "every bus in connex component."
else if buses_with_reactive_slacks == "NO_GENERATION" then "buses without generation (no generator, svc or vsc)"
else if buses_with_reactive_slacks == "SPECIFIED" then "buses given as parameters in param_buses_with_reactive_slack.txt";
check buses_with_reactive_slacks in {"SPECIFIED", "NO_GENERATION", "ALL"};
else if buses_with_reactive_slacks == "CONFIGURED" then "buses given as parameters in param_buses_with_reactive_slack.txt";
check buses_with_reactive_slacks in {"CONFIGURED", "NO_GENERATION", "ALL"};

# Consistency maximal value for P and Q
# Any Pmax Pmin Qmax Qmin of generating unit with abolute value larger than PQmax is discarded
Expand Down Expand Up @@ -1083,7 +1083,7 @@ for {(qq,m,n) in BRANCHCC: (teta[m]-teta[n])>temp1*0.99 or (teta[m]-teta[n])<tem
# Ouput reactive slack values and voltages
if (sum{n in BUSCC_SLACK} slack1_balance_Q[n])+(sum{n in BUSCC_SLACK} slack2_balance_Q[n]) > Pnull
then {

if 1 in LOG_INFO then
display
sum{n in BUSCC_SLACK} slack1_balance_Q[n],
Expand Down Expand Up @@ -1111,7 +1111,7 @@ include reactiveopfoutput.run;
# Write voltage information in debug file
let fileOut := "debug_bus.csv";
printf{LOG_DEBUG} "#bus_id;Vnom;V;Vlb;Vub;Vmin_mod;Vmax_mod;Vmin_OK;Vmax_OK;Vmin_ori;Vmax_ori;sQ1;sQ2;\n" > (fileOut);
for {n in BUSCC}
for {n in BUSCC}
printf{LOG_DEBUG} "%Q;%i;%.4f;%.4f;%.4f;%.4f;%.4f;%s;%s;%.4f;%.4f;%.2f;%.2f;\n",
bus_id[1,n],substation_Vnomi[1,bus_substation[1,n]],
V[n],V[n].lb,V[n].ub,
Expand All @@ -1128,7 +1128,7 @@ close (fileOut);
# Write units which are not in uniton (debug only)
let fileOut := "reactiveopf_results_generators_Pnull.csv";
printf{LOG_DEBUG} "#variant;num;bus;vRegul;V(pu);targetP(MW);targetQ(Mvar);P(MW);Q(MW);id;bus_id;\n" > (fileOut);
for {(g,n) in UNITCC diff UNITON}
for {(g,n) in UNITCC diff UNITON}
printf{LOG_DEBUG} "%i;%i;%i;%Q;%.3f;%.3f;%.3f;%.3f;%.3f;%Q;%Q;\n",
1,g,n,
unit_vregul[1,g,n],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.powsybl.openreac.parameters.input.algo.OpenReacAmplLogLevel;
import com.powsybl.openreac.parameters.input.algo.OpenReacOptimisationObjective;
import com.powsybl.openreac.parameters.input.algo.OpenReacSolverLogLevel;
import com.powsybl.openreac.parameters.input.algo.OpenReacBusesWithReactiveSlackConfig;
import com.powsybl.openreac.parameters.input.algo.ReactiveSlackBusesMode;
import org.junit.jupiter.api.Test;

import java.util.List;
Expand Down Expand Up @@ -124,7 +124,7 @@ void testAlgorithmParams() {
parameters.setLogLevelSolver(OpenReacSolverLogLevel.NOTHING);
parameters.setMinPlausibleLowVoltageLimit(0.8);
parameters.setMaxPlausibleHighVoltageLimit(1.2);
parameters.setBusesWithReactiveSlackConfig(OpenReacBusesWithReactiveSlackConfig.ALL);
parameters.setReactiveSlackBusesMode(ReactiveSlackBusesMode.ALL);

List<OpenReacAlgoParam> algoParams = parameters.getAllAlgorithmParams();
assertEquals(7, algoParams.size());
Expand All @@ -141,14 +141,14 @@ void testAlgorithmParams() {
void testBusesWithReactiveSlackConfigIntegrity() {
OpenReacParameters parameters = new OpenReacParameters();

assertEquals(OpenReacBusesWithReactiveSlackConfig.NO_GENERATION, parameters.getBusesWithReactiveSlackConfig()); // default value
assertThrows(NullPointerException.class, () -> parameters.setBusesWithReactiveSlackConfig(null));
parameters.setBusesWithReactiveSlackConfig(OpenReacBusesWithReactiveSlackConfig.SPECIFIED);
assertEquals("SPECIFIED", parameters.getBusesWithReactiveSlackConfig().toParam().getValue());
parameters.setBusesWithReactiveSlackConfig(OpenReacBusesWithReactiveSlackConfig.NO_GENERATION);
assertEquals("NO_GENERATION", parameters.getBusesWithReactiveSlackConfig().toParam().getValue());
parameters.setBusesWithReactiveSlackConfig(OpenReacBusesWithReactiveSlackConfig.ALL);
assertEquals("ALL", parameters.getBusesWithReactiveSlackConfig().toParam().getValue());
assertEquals(ReactiveSlackBusesMode.NO_GENERATION, parameters.getReactiveSlackBusesMode()); // default value
assertThrows(NullPointerException.class, () -> parameters.setReactiveSlackBusesMode(null));
parameters.setReactiveSlackBusesMode(ReactiveSlackBusesMode.CONFIGURED);
assertEquals("CONFIGURED", parameters.getReactiveSlackBusesMode().toParam().getValue());
parameters.setReactiveSlackBusesMode(ReactiveSlackBusesMode.NO_GENERATION);
assertEquals("NO_GENERATION", parameters.getReactiveSlackBusesMode().toParam().getValue());
parameters.setReactiveSlackBusesMode(ReactiveSlackBusesMode.ALL);
assertEquals("ALL", parameters.getReactiveSlackBusesMode().toParam().getValue());
}

@Test
Expand All @@ -159,7 +159,7 @@ void testDefaultListsOfParametersIntegrity() {
assertEquals(0, parameters.getSpecificVoltageLimits().size(), "SpecificVoltageLimits should be empty when using default OpenReacParameter constructor.");
assertEquals(0, parameters.getConstantQGenerators().size(), "ConstantQGenerators should be empty when using default OpenReacParameter constructor.");
assertEquals(0, parameters.getVariableShuntCompensators().size(), "VariableShuntCompensators should be empty when using default OpenReacParameter constructor.");
assertEquals(0, parameters.getConfiguredBusesWithReactiveSlacks().size(), "ConfiguredBusesWithReactiveSlack should be empty when using default OpenREacParameter constructor.");
assertEquals(0, parameters.getConfiguredReactiveSlackBuses().size(), "ConfiguredReactiveSlackBuses should be empty when using default OpenREacParameter constructor.");
assertEquals(6, parameters.getAllAlgorithmParams().size());
}

Expand Down Expand Up @@ -207,9 +207,9 @@ void testConstantQGeneratorsParametersIntegrity(Network network, String wrongId)

void testBusesWithReactiveSlacksParametersIntegrity(Network network, String wrongId) {
OpenReacParameters parameters = new OpenReacParameters();
parameters.addBusesWithReactiveSlack(network.getBusView().getBusStream().map(Bus::getId).collect(Collectors.toList()));
parameters.addConfiguredReactiveSlackBuses(network.getBusView().getBusStream().map(Bus::getId).collect(Collectors.toList()));
assertDoesNotThrow(() -> parameters.checkIntegrity(network), "Adding Buses network IDs should not throw.");
parameters.addBusesWithReactiveSlack(List.of(wrongId));
parameters.addConfiguredReactiveSlackBuses(List.of(wrongId));
assertNull(network.getBusView().getBus(wrongId), "Please change wrong ID so it does not match any any element in the network.");
InvalidParametersException e = assertThrows(InvalidParametersException.class, () -> parameters.checkIntegrity(network));
assertEquals("Bus " + wrongId + " not found in the network.", e.getMessage());
Expand Down
Loading

0 comments on commit 80689a8

Please sign in to comment.