From 7c201cd9170a9f017bd06c5a4beda3bd9fb815dc Mon Sep 17 00:00:00 2001 From: parvy Date: Fri, 3 Nov 2023 16:10:28 +0100 Subject: [PATCH 01/26] Add two params to control consistency of voltage limits. Signed-off-by: parvy --- .../main/resources/openreac/reactiveopf.mod | 33 ++++++++++--------- .../main/resources/openreac/reactiveopf.run | 20 +++++++---- .../resources/openreac/reactiveopfexit.run | 3 +- .../resources/openreac/reactiveopfoutput.run | 3 +- 4 files changed, 35 insertions(+), 24 deletions(-) diff --git a/open-reac/src/main/resources/openreac/reactiveopf.mod b/open-reac/src/main/resources/openreac/reactiveopf.mod index 0edb53ff..511cfe56 100644 --- a/open-reac/src/main/resources/openreac/reactiveopf.mod +++ b/open-reac/src/main/resources/openreac/reactiveopf.mod @@ -42,20 +42,20 @@ check 1 in TIME; check card({(t,s) in SUBSTATIONS: substation_Vnomi[t,s] >= epsilon_nominal_voltage}) > 1; # Voltage bounds -check{(t,s) in SUBSTATIONS: substation_Vmin[t,s] >= epsilon_min_voltage and substation_Vmax[t,s] >= epsilon_min_voltage}: - substation_Vmin[t,s] < substation_Vmax[t,s]; -# Parameter below will be used to force voltage to be in interval [epsilon;2-epsilon]. -# Typical value is 0.5 although academics would use 0.9 or 0.95 -check epsilon_min_voltage > 0 and epsilon_min_voltage < 1; -# Bounds below will be used for substations without bounds or with bad bounds (eg 0.01pu or 20pu are bad values) +check{(t,s) in SUBSTATIONS: substation_Vmin[t,s] >= consistent_min_voltage and substation_Vmax[t,s] >= consistent_min_voltage}: +substation_Vmin[t,s] < substation_Vmax[t,s]; + +# Parameters consistent_min_voltage and consistent_max_voltage are used to force voltage to be in interval [consistent_min_voltage;consistent_max_voltage]. +# Default value is [0.5;1.5] although academics would use low limit equals to 0.9 or 0.95 +# Bounds below will be used for substations without bounds or with bad bounds param minimal_voltage_lower_bound := - if card({(t,s) in SUBSTATIONS: substation_Vmin[t,s] > 0}) > 0 - then max(epsilon_min_voltage,min{(t,s) in SUBSTATIONS: substation_Vmin[t,s] > 0} substation_Vmin[t,s]) - else epsilon_min_voltage; +if card({(t,s) in SUBSTATIONS: substation_Vmin[t,s] > 0}) > 0 +then max(consistent_min_voltage,min{(t,s) in SUBSTATIONS: substation_Vmin[t,s] > 0} substation_Vmin[t,s]) +else consistent_min_voltage; param maximal_voltage_upper_bound := - if card({(t,s) in SUBSTATIONS: substation_Vmin[t,s] > 0}) > 0 - then min(2-epsilon_min_voltage,max{(t,s) in SUBSTATIONS: substation_Vmax[t,s] > 0} substation_Vmax[t,s]) - else 2-epsilon_min_voltage; +if card({(t,s) in SUBSTATIONS: substation_Vmin[t,s] > 0}) > 0 +then min(consistent_max_voltage,max{(t,s) in SUBSTATIONS: substation_Vmax[t,s] > 0} substation_Vmax[t,s]) +else consistent_max_voltage; check minimal_voltage_lower_bound > 0; check maximal_voltage_upper_bound > minimal_voltage_lower_bound; @@ -84,6 +84,9 @@ check {(t,s) in SUBSTATIONS: s in BOUND_OVERRIDES}: substation_new_Vmin[s] < sub # Negative value for substation_Vmin or substation_Vmax means that the value is undefined # In that case, minimal_voltage_lower_bound or maximal_voltage_upper_bound is used instead +# Note that low and high override are taken into account only if +# substation_new_Vmin > minimal_voltage_lower_bound and substation_new_Vmax < maximal_voltage_upper_bound + param voltage_lower_bound{(t,s) in SUBSTATIONS} := max( minimal_voltage_lower_bound, if s in BOUND_OVERRIDES then substation_new_Vmin[s] else substation_Vmin[t,s] @@ -546,7 +549,7 @@ set UNITCC := setof {(1,g,n) in UNIT : n in BUSCC} (g,n); set BATTERYCC := setof {(1,b,n) in BATTERY : n in BUSCC} (b,n); # Busses with valid voltage value -set BUSVV := {n in BUSCC : bus_V0[1,n] >= epsilon_min_voltage}; +set BUSVV := {n in BUSCC : bus_V0[1,n] >= consistent_min_voltage}; # Units up and generating: # Warning: units with Ptarget=0 are considered as out of order @@ -814,10 +817,10 @@ subject to ctr_null_phase_bus{PROBLEM_ACOPF}: teta[null_phase_bus] = 0; # Modulus of voltage var V{n in BUSCC} <= - if substation_Vnomi[1,bus_substation[1,n]] <= ignore_voltage_bounds then 2-epsilon_min_voltage else + if substation_Vnomi[1,bus_substation[1,n]] <= ignore_voltage_bounds then consistent_max_voltage else voltage_upper_bound[1,bus_substation[1,n]], >= - if substation_Vnomi[1,bus_substation[1,n]] <= ignore_voltage_bounds then epsilon_min_voltage else + if substation_Vnomi[1,bus_substation[1,n]] <= ignore_voltage_bounds then consistent_min_voltage else voltage_lower_bound[1,bus_substation[1,n]]; diff --git a/open-reac/src/main/resources/openreac/reactiveopf.run b/open-reac/src/main/resources/openreac/reactiveopf.run index 6450c795..de22c565 100644 --- a/open-reac/src/main/resources/openreac/reactiveopf.run +++ b/open-reac/src/main/resources/openreac/reactiveopf.run @@ -292,19 +292,25 @@ printf{LOG_INFO} "Parameter: for consistency checks of minimum nominal voltages check epsilon_nominal_voltage > 0; # Minimum consistency value for voltage in PU -# This value has to be >0 and <1 -param epsilon_min_voltage default 0.5; -if "epsilon_min_voltage" in PARAM_ALGO_KEYS then let epsilon_min_voltage := num(PARAM_ALGO_VALUES["epsilon_min_voltage"]); -printf{LOG_INFO} "Parameter: for consistency checks of voltage bounds eps<=Vmin 0 and epsilon_min_voltage < 1; +# This value should be < 1 +param consistent_min_voltage default 0.5; +if "consistent_min_voltage" in PARAM_ALGO_KEYS then let consistent_min_voltage := num(PARAM_ALGO_VALUES["consistent_min_voltage"]); +printf{LOG_INFO} "Parameter: for consistency of voltage bounds, consistent_min_voltage:= %Q pu\n",consistent_min_voltage; +check consistent_min_voltage > 0; + +# Maximum consistency value for voltage in PU +param consistent_max_voltage default 1.5; +if "consistent_max_voltage" in PARAM_ALGO_KEYS then let consistent_max_voltage := num(PARAM_ALGO_VALUES["consistent_max_voltage"]); +printf{LOG_INFO} "Parameter: for consistency of voltage bounds, consistent_max_voltage:= %Q pu\n",consistent_max_voltage; +check consistent_max_voltage > consistent_min_voltage; # Ignore voltage bounds for buses with nominal voltage lower than this parameter # For all busses with nominal voltage lower than ignore_voltage_bounds, voltage bonds will be ignored -# and replaced by [epsilon_min_voltage ; 2 - epsilon_min_voltage] +# and replaced by [consistent_min_voltage ; consistent_max_voltage] param ignore_voltage_bounds default 0; if "ignore_voltage_bounds" in PARAM_ALGO_KEYS then let ignore_voltage_bounds := num(PARAM_ALGO_VALUES["ignore_voltage_bounds"]); if ignore_voltage_bounds >= epsilon_nominal_voltage -then printf{LOG_INFO} "Parameter: for all busses with nominal voltage <= ignore_voltage_bounds=%.1f, voltage bounds are ignored and replaced by [%.3f;%.3f]\n",ignore_voltage_bounds,epsilon_min_voltage,2-epsilon_min_voltage; +then printf{LOG_INFO} "Parameter: for all busses with nominal voltage <= ignore_voltage_bounds=%.1f, voltage bounds are ignored and replaced by [%.3f;%.3f]\n",ignore_voltage_bounds,consistent_min_voltage,consistent_max_voltage; check ignore_voltage_bounds >= 0; # Consistency maximal value for P and Q diff --git a/open-reac/src/main/resources/openreac/reactiveopfexit.run b/open-reac/src/main/resources/openreac/reactiveopfexit.run index de40f41d..14b468e7 100644 --- a/open-reac/src/main/resources/openreac/reactiveopfexit.run +++ b/open-reac/src/main/resources/openreac/reactiveopfexit.run @@ -53,7 +53,8 @@ printf "\n" > (fileOut); printf "%s %f\n","Pnull",Pnull > (fileOut); printf "%s %f\n","Znull",Znull > (fileOut); printf "%s %f\n","epsilon_nominal_voltage",epsilon_nominal_voltage > (fileOut); -printf "%s %f\n","epsilon_min_voltage",epsilon_min_voltage > (fileOut); +printf "%s %f\n","consistent_min_voltage",consistent_min_voltage > (fileOut); +printf "%s %f\n","consistent_max_voltage",consistent_max_voltage > (fileOut); printf "%s %f\n","ignore_voltage_bounds",ignore_voltage_bounds > (fileOut); printf "%s %f\n","PQmax",PQmax > (fileOut); printf "%s %f\n","defaultPmax",defaultPmax > (fileOut); diff --git a/open-reac/src/main/resources/openreac/reactiveopfoutput.run b/open-reac/src/main/resources/openreac/reactiveopfoutput.run index f640ac28..1c1ffc08 100644 --- a/open-reac/src/main/resources/openreac/reactiveopfoutput.run +++ b/open-reac/src/main/resources/openreac/reactiveopfoutput.run @@ -237,7 +237,8 @@ printf "%s %f\n","coeff_alpha",coeff_alpha > (fileOut); printf "%s %f\n","Pnull",Pnull > (fileOut); printf "%s %f\n","Znull",Znull > (fileOut); printf "%s %f\n","epsilon_nominal_voltage",epsilon_nominal_voltage > (fileOut); -printf "%s %f\n","epsilon_min_voltage",epsilon_min_voltage > (fileOut); +printf "%s %f\n","consistent_min_voltage",consistent_min_voltage > (fileOut); +printf "%s %f\n","consistent_max_voltage",consistent_max_voltage > (fileOut); printf "%s %f\n","ignore_voltage_bounds",ignore_voltage_bounds > (fileOut); printf "%s %f\n","PQmax",PQmax > (fileOut); printf "%s %f\n","defaultPmax",defaultPmax > (fileOut); From 34fbc8e85e48567487aa2bbb18dc52cf6965c28b Mon Sep 17 00:00:00 2001 From: parvy Date: Fri, 10 Nov 2023 12:18:08 +0100 Subject: [PATCH 02/26] Add interface for min/max voltage limit parameters. Signed-off-by: parvy --- .../parameters/input/OpenReacParameters.java | 77 +++++++++++++++++-- .../openreac/OpenReacParametersTest.java | 47 +++++++++++ 2 files changed, 119 insertions(+), 5 deletions(-) diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java index f46a6480..1bc53a16 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java @@ -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 specificVoltageLimits = new ArrayList<>(); private final List variableShuntCompensators = new ArrayList<>(); @@ -39,10 +37,22 @@ public class OpenReacParameters { private final List 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. *

@@ -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 getVariableShuntCompensators() { return variableShuntCompensators; } @@ -154,7 +194,7 @@ public List getVariableTwoWindingsTransformers() { } public List getAllAlgorithmParams() { - ArrayList allAlgoParams = new ArrayList<>(algorithmParams.size() + 2); + ArrayList allAlgoParams = new ArrayList<>(algorithmParams.size() + 4); allAlgoParams.addAll(algorithmParams); if (objective != null) { allAlgoParams.add(objective.toParam()); @@ -162,6 +202,12 @@ public List getAllAlgorithmParams() { 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; } @@ -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; } /** diff --git a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java index 22ae95e5..31840687 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java @@ -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; @@ -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 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(); From d440d7a6e3898934f23128c9afa089b5a5034959 Mon Sep 17 00:00:00 2001 From: parvy Date: Fri, 10 Nov 2023 12:21:27 +0100 Subject: [PATCH 03/26] Fix codesmell. Signed-off-by: parvy --- .../java/com/powsybl/openreac/OpenReacParametersTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java index 31840687..148fbad9 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java @@ -41,7 +41,7 @@ public void testObjectiveIntegrityChecks() { } @Test - public void testMinMaxVoltageLimitIntegrityChecks() { + void testMinMaxVoltageLimitIntegrityChecks() { OpenReacParameters parameters = new OpenReacParameters(); assertNull(parameters.getMinVoltageLimitConsistency()); assertNull(parameters.getMaxVoltageLimitConsistency()); @@ -61,6 +61,8 @@ public void testMinMaxVoltageLimitIntegrityChecks() { assertFalse(parameters.checkAlgorithmParametersIntegrity()); parameters.setMaxVoltageLimitConsistency(1.2); assertTrue(parameters.checkAlgorithmParametersIntegrity()); + + parameters. } @Test From efdf25fcfead684c0784d87d520e0ba6f1d51781 Mon Sep 17 00:00:00 2001 From: parvy Date: Fri, 10 Nov 2023 12:24:04 +0100 Subject: [PATCH 04/26] Fix. Signed-off-by: parvy --- .../test/java/com/powsybl/openreac/OpenReacParametersTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java index 148fbad9..9fb85d1c 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java @@ -61,8 +61,6 @@ void testMinMaxVoltageLimitIntegrityChecks() { assertFalse(parameters.checkAlgorithmParametersIntegrity()); parameters.setMaxVoltageLimitConsistency(1.2); assertTrue(parameters.checkAlgorithmParametersIntegrity()); - - parameters. } @Test From 72cacc18caed4fa78510800a97805534d12a7611 Mon Sep 17 00:00:00 2001 From: parvy Date: Fri, 10 Nov 2023 13:55:02 +0100 Subject: [PATCH 05/26] Add unit test with comparison of input file exported. Signed-off-by: parvy --- .../powsybl/openreac/OpenReacRunnerTest.java | 37 +++++++++++++++++++ .../consistent_voltage_limits.txt | 4 ++ .../test/resources/openreac-input/default.txt | 2 + 3 files changed, 43 insertions(+) create mode 100644 open-reac/src/test/resources/openreac-input/consistent_voltage_limits.txt create mode 100644 open-reac/src/test/resources/openreac-input/default.txt diff --git a/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java b/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java index 61c5c42d..69ad8962 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java @@ -73,6 +73,43 @@ private Path getAmplExecPath() throws IOException { return execFolder; } + @Test + void testDefaultParamAlgoExport() throws IOException { + Network network = IeeeCdfNetworkFactory.create118(); + setDefaultVoltageLimits(network); // set default voltage limits to every voltage levels of the network + OpenReacParameters parameters = new OpenReacParameters(); + + LocalCommandExecutor localCommandExecutor = new TestLocalCommandExecutor( + List.of("empty_case/reactiveopf_results_indic.txt")); + try (ComputationManager computationManager = new LocalComputationManager(new LocalComputationConfig(tmpDir), + localCommandExecutor, ForkJoinPool.commonPool())) { + OpenReacRunner.run(network, network.getVariantManager().getWorkingVariantId(), parameters, + new OpenReacConfig(true), computationManager); + Path execFolder = getAmplExecPath(); + assertEqualsToRef(execFolder.resolve("param_algo.txt"), "/openreac-input/default.txt"); + } + } + + @Test + void testConsistentVoltageLimitsParamAlgoExport() throws IOException { + Network network = IeeeCdfNetworkFactory.create118(); + setDefaultVoltageLimits(network); // set default voltage limits to every voltage levels of the network + OpenReacParameters parameters = new OpenReacParameters() + .setMinVoltageLimitConsistency(0.7888) + .setMaxVoltageLimitConsistency(1.3455); + + LocalCommandExecutor localCommandExecutor = new TestLocalCommandExecutor( + List.of("empty_case/reactiveopf_results_indic.txt")); + try (ComputationManager computationManager = new LocalComputationManager(new LocalComputationConfig(tmpDir), + localCommandExecutor, ForkJoinPool.commonPool())) { + OpenReacRunner.run(network, network.getVariantManager().getWorkingVariantId(), parameters, + new OpenReacConfig(true), computationManager); + Path execFolder = getAmplExecPath(); + assertEqualsToRef(execFolder.resolve("param_algo.txt"), "/openreac-input/consistent_voltage_limits.txt"); + } + + } + @Test void testInputFile() throws IOException { Network network = IeeeCdfNetworkFactory.create118(); diff --git a/open-reac/src/test/resources/openreac-input/consistent_voltage_limits.txt b/open-reac/src/test/resources/openreac-input/consistent_voltage_limits.txt new file mode 100644 index 00000000..f5c94c70 --- /dev/null +++ b/open-reac/src/test/resources/openreac-input/consistent_voltage_limits.txt @@ -0,0 +1,4 @@ +objective_choice 0 +consistent_min_voltage 0.7888 +consistent_max_voltage 1.3455 + diff --git a/open-reac/src/test/resources/openreac-input/default.txt b/open-reac/src/test/resources/openreac-input/default.txt new file mode 100644 index 00000000..745bf608 --- /dev/null +++ b/open-reac/src/test/resources/openreac-input/default.txt @@ -0,0 +1,2 @@ +objective_choice 0 + From b5421e8bdbb22fc1178dc29407aff0e1781e6e20 Mon Sep 17 00:00:00 2001 From: parvy Date: Fri, 10 Nov 2023 14:03:37 +0100 Subject: [PATCH 06/26] Refactor java code. Signed-off-by: parvy --- .../parameters/input/OpenReacParameters.java | 52 +++++++++---------- .../openreac/OpenReacParametersTest.java | 28 +++++----- .../powsybl/openreac/OpenReacRunnerTest.java | 8 +-- .../default.txt | 0 .../minmax_plausible_voltage_limits.txt} | 0 5 files changed, 44 insertions(+), 44 deletions(-) rename open-reac/src/test/resources/{openreac-input => openreac-input-algo-parameters}/default.txt (100%) rename open-reac/src/test/resources/{openreac-input/consistent_voltage_limits.txt => openreac-input-algo-parameters/minmax_plausible_voltage_limits.txt} (100%) diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java index 1bc53a16..c83849d9 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java @@ -45,13 +45,13 @@ public class OpenReacParameters { private Double objectiveDistance; - private static final String MIN_VOLTAGE_LIMIT_CONSISTENCY_KEY = "consistent_min_voltage"; + private static final String MIN_PLAUSIBLE_LOW_VOLTAGE_LIMIT_KEY = "consistent_min_voltage"; - private Double minVoltageLimitConsistency; // in pu + private Double minPlausibleLowVoltageLimit; // in pu - private static final String MAX_VOLTAGE_LIMIT_CONSISTENCY_KEY = "consistent_max_voltage"; + private static final String MAX_PLAUSIBLE_HIGH_VOLTAGE_LIMIT_KEY = "consistent_max_voltage"; - private Double maxVoltageLimitConsistency; // in pu + private Double maxPlausibleHighVoltageLimit; // in pu /** * Override some voltage level limits in the network. This will NOT modify the network object. @@ -148,32 +148,32 @@ public OpenReacParameters setObjectiveDistance(double objectiveDistance) { } /** - * @return the minimal voltage limit consistency value in p.u. + * @return the minimal plausible value for low voltage limits in p.u. */ - public Double getMinVoltageLimitConsistency() { - return minVoltageLimitConsistency; + public Double getMinPlausibleLowVoltageLimit() { + return minPlausibleLowVoltageLimit; } - public OpenReacParameters setMinVoltageLimitConsistency(double minVoltageLimitConsistency) { - if (minVoltageLimitConsistency < 0) { - throw new InvalidParametersException("Minimal voltage limit must be >= 0 to be consistent."); + public OpenReacParameters setMinPlausibleLowVoltageLimit(double minPlausibleLowVoltageLimit) { + if (minPlausibleLowVoltageLimit < 0) { + throw new InvalidParametersException("Min plausible low voltage limit must be >= 0 to be consistent."); } - this.minVoltageLimitConsistency = minVoltageLimitConsistency; + this.minPlausibleLowVoltageLimit = minPlausibleLowVoltageLimit; return this; } /** - * @return the maximal voltage limit consistency value in p.u. + * @return the maximal plausible value for high voltage limits in p.u. */ - public Double getMaxVoltageLimitConsistency() { - return maxVoltageLimitConsistency; + public Double getMaxPlausibleHighVoltageLimit() { + return maxPlausibleHighVoltageLimit; } - public OpenReacParameters setMaxVoltageLimitConsistency(double maxVoltageLimitConsistency) { - if (maxVoltageLimitConsistency <= 0) { - throw new InvalidParametersException("Maximal voltage limit must be > 0 to be consistent."); + public OpenReacParameters setMaxPlausibleHighVoltageLimit(double maxPlausibleHighVoltageLimit) { + if (maxPlausibleHighVoltageLimit <= 0) { + throw new InvalidParametersException("Max plausible high voltage limit must be > 0 to be consistent."); } - this.maxVoltageLimitConsistency = maxVoltageLimitConsistency; + this.maxPlausibleHighVoltageLimit = maxPlausibleHighVoltageLimit; return this; } @@ -202,11 +202,11 @@ public List getAllAlgorithmParams() { 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 (minPlausibleLowVoltageLimit != null) { + allAlgoParams.add(new OpenReacAlgoParamImpl(MIN_PLAUSIBLE_LOW_VOLTAGE_LIMIT_KEY, Double.toString(minPlausibleLowVoltageLimit))); } - if (maxVoltageLimitConsistency != null) { - allAlgoParams.add(new OpenReacAlgoParamImpl(MAX_VOLTAGE_LIMIT_CONSISTENCY_KEY, Double.toString(maxVoltageLimitConsistency))); + if (maxPlausibleHighVoltageLimit != null) { + allAlgoParams.add(new OpenReacAlgoParamImpl(MAX_PLAUSIBLE_HIGH_VOLTAGE_LIMIT_KEY, Double.toString(maxPlausibleHighVoltageLimit))); } return allAlgoParams; } @@ -265,10 +265,10 @@ public boolean checkAlgorithmParametersIntegrity() { 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."); + // Check integrity of min/max plausible voltage limits + if (minPlausibleLowVoltageLimit != null && maxPlausibleHighVoltageLimit != null + && minPlausibleLowVoltageLimit > maxPlausibleHighVoltageLimit) { + LOGGER.warn("Min plausible low voltage limit must be lower than max plausible high voltage limit."); integrityAlgorithmParameters = false; } diff --git a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java index 9fb85d1c..9153db05 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java @@ -43,23 +43,23 @@ public void testObjectiveIntegrityChecks() { @Test void testMinMaxVoltageLimitIntegrityChecks() { OpenReacParameters parameters = new OpenReacParameters(); - assertNull(parameters.getMinVoltageLimitConsistency()); - assertNull(parameters.getMaxVoltageLimitConsistency()); + assertNull(parameters.getMinPlausibleLowVoltageLimit()); + assertNull(parameters.getMaxPlausibleHighVoltageLimit()); - // Consistency of min voltage limit (>= 0) - assertThrows(InvalidParametersException.class, () -> parameters.setMinVoltageLimitConsistency(-0.25)); - parameters.setMinVoltageLimitConsistency(0.8); - assertEquals(0.8, parameters.getMinVoltageLimitConsistency()); + // Consistency of min plausible low voltage limit (>= 0) + assertThrows(InvalidParametersException.class, () -> parameters.setMinPlausibleLowVoltageLimit(-0.25)); + parameters.setMinPlausibleLowVoltageLimit(0.8); + assertEquals(0.8, parameters.getMinPlausibleLowVoltageLimit()); - // 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()); + // Consistency of max plausible high voltage limit (> 0) + assertThrows(InvalidParametersException.class, () -> parameters.setMaxPlausibleHighVoltageLimit(-0.15)); + assertThrows(InvalidParametersException.class, () -> parameters.setMaxPlausibleHighVoltageLimit(0)); + parameters.setMaxPlausibleHighVoltageLimit(0.75); + assertEquals(0.75, parameters.getMaxPlausibleHighVoltageLimit()); // Check min < max assertFalse(parameters.checkAlgorithmParametersIntegrity()); - parameters.setMaxVoltageLimitConsistency(1.2); + parameters.setMaxPlausibleHighVoltageLimit(1.2); assertTrue(parameters.checkAlgorithmParametersIntegrity()); } @@ -69,8 +69,8 @@ void testAlgorithmParams() { parameters.addAlgorithmParam("myParam", "myValue"); parameters.setObjective(OpenReacOptimisationObjective.SPECIFIC_VOLTAGE_PROFILE); parameters.setObjectiveDistance(0.4); - parameters.setMinVoltageLimitConsistency(0.8); - parameters.setMaxVoltageLimitConsistency(1.2); + parameters.setMinPlausibleLowVoltageLimit(0.8); + parameters.setMaxPlausibleHighVoltageLimit(1.2); List algoParams = parameters.getAllAlgorithmParams(); assertEquals(5, algoParams.size()); diff --git a/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java b/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java index 69ad8962..52cb0894 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java @@ -86,7 +86,7 @@ void testDefaultParamAlgoExport() throws IOException { OpenReacRunner.run(network, network.getVariantManager().getWorkingVariantId(), parameters, new OpenReacConfig(true), computationManager); Path execFolder = getAmplExecPath(); - assertEqualsToRef(execFolder.resolve("param_algo.txt"), "/openreac-input/default.txt"); + assertEqualsToRef(execFolder.resolve("param_algo.txt"), "/openreac-input-algo-parameters/default.txt"); } } @@ -95,8 +95,8 @@ void testConsistentVoltageLimitsParamAlgoExport() throws IOException { Network network = IeeeCdfNetworkFactory.create118(); setDefaultVoltageLimits(network); // set default voltage limits to every voltage levels of the network OpenReacParameters parameters = new OpenReacParameters() - .setMinVoltageLimitConsistency(0.7888) - .setMaxVoltageLimitConsistency(1.3455); + .setMinPlausibleLowVoltageLimit(0.7888) + .setMaxPlausibleHighVoltageLimit(1.3455); LocalCommandExecutor localCommandExecutor = new TestLocalCommandExecutor( List.of("empty_case/reactiveopf_results_indic.txt")); @@ -105,7 +105,7 @@ void testConsistentVoltageLimitsParamAlgoExport() throws IOException { OpenReacRunner.run(network, network.getVariantManager().getWorkingVariantId(), parameters, new OpenReacConfig(true), computationManager); Path execFolder = getAmplExecPath(); - assertEqualsToRef(execFolder.resolve("param_algo.txt"), "/openreac-input/consistent_voltage_limits.txt"); + assertEqualsToRef(execFolder.resolve("param_algo.txt"), "/openreac-input-algo-parameters/minmax_plausible_voltage_limits.txt"); } } diff --git a/open-reac/src/test/resources/openreac-input/default.txt b/open-reac/src/test/resources/openreac-input-algo-parameters/default.txt similarity index 100% rename from open-reac/src/test/resources/openreac-input/default.txt rename to open-reac/src/test/resources/openreac-input-algo-parameters/default.txt diff --git a/open-reac/src/test/resources/openreac-input/consistent_voltage_limits.txt b/open-reac/src/test/resources/openreac-input-algo-parameters/minmax_plausible_voltage_limits.txt similarity index 100% rename from open-reac/src/test/resources/openreac-input/consistent_voltage_limits.txt rename to open-reac/src/test/resources/openreac-input-algo-parameters/minmax_plausible_voltage_limits.txt From 3ce751b244400f7c4e0cb002f004516e3ed7f573 Mon Sep 17 00:00:00 2001 From: parvy Date: Fri, 10 Nov 2023 14:10:57 +0100 Subject: [PATCH 07/26] Refactor ampl code. Signed-off-by: parvy --- .../parameters/input/OpenReacParameters.java | 4 ++-- .../main/resources/openreac/reactiveopf.mod | 18 +++++++------- .../main/resources/openreac/reactiveopf.run | 24 +++++++++---------- .../resources/openreac/reactiveopfexit.run | 4 ++-- .../resources/openreac/reactiveopfoutput.run | 4 ++-- .../openreac/OpenReacParametersTest.java | 4 ++-- .../minmax_plausible_voltage_limits.txt | 4 ++-- 7 files changed, 31 insertions(+), 31 deletions(-) diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java index c83849d9..8f27f3c9 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java @@ -45,11 +45,11 @@ public class OpenReacParameters { private Double objectiveDistance; - private static final String MIN_PLAUSIBLE_LOW_VOLTAGE_LIMIT_KEY = "consistent_min_voltage"; + private static final String MIN_PLAUSIBLE_LOW_VOLTAGE_LIMIT_KEY = "min_plausible_low_voltage_limit"; private Double minPlausibleLowVoltageLimit; // in pu - private static final String MAX_PLAUSIBLE_HIGH_VOLTAGE_LIMIT_KEY = "consistent_max_voltage"; + private static final String MAX_PLAUSIBLE_HIGH_VOLTAGE_LIMIT_KEY = "max_plausible_high_voltage_limit"; private Double maxPlausibleHighVoltageLimit; // in pu diff --git a/open-reac/src/main/resources/openreac/reactiveopf.mod b/open-reac/src/main/resources/openreac/reactiveopf.mod index 511cfe56..aa975cd0 100644 --- a/open-reac/src/main/resources/openreac/reactiveopf.mod +++ b/open-reac/src/main/resources/openreac/reactiveopf.mod @@ -42,20 +42,20 @@ check 1 in TIME; check card({(t,s) in SUBSTATIONS: substation_Vnomi[t,s] >= epsilon_nominal_voltage}) > 1; # Voltage bounds -check{(t,s) in SUBSTATIONS: substation_Vmin[t,s] >= consistent_min_voltage and substation_Vmax[t,s] >= consistent_min_voltage}: +check{(t,s) in SUBSTATIONS: substation_Vmin[t,s] >= min_plausible_low_voltage_limit and substation_Vmax[t,s] >= min_plausible_low_voltage_limit}: substation_Vmin[t,s] < substation_Vmax[t,s]; -# Parameters consistent_min_voltage and consistent_max_voltage are used to force voltage to be in interval [consistent_min_voltage;consistent_max_voltage]. +# Parameters min_plausible_low_voltage_limit and max_plausible_high_voltage_limit are used to force voltage to be in interval [min_plausible_low_voltage_limit;max_plausible_high_voltage_limit]. # Default value is [0.5;1.5] although academics would use low limit equals to 0.9 or 0.95 # Bounds below will be used for substations without bounds or with bad bounds param minimal_voltage_lower_bound := if card({(t,s) in SUBSTATIONS: substation_Vmin[t,s] > 0}) > 0 -then max(consistent_min_voltage,min{(t,s) in SUBSTATIONS: substation_Vmin[t,s] > 0} substation_Vmin[t,s]) -else consistent_min_voltage; +then max(min_plausible_low_voltage_limit,min{(t,s) in SUBSTATIONS: substation_Vmin[t,s] > 0} substation_Vmin[t,s]) +else min_plausible_low_voltage_limit; param maximal_voltage_upper_bound := if card({(t,s) in SUBSTATIONS: substation_Vmin[t,s] > 0}) > 0 -then min(consistent_max_voltage,max{(t,s) in SUBSTATIONS: substation_Vmax[t,s] > 0} substation_Vmax[t,s]) -else consistent_max_voltage; +then min(max_plausible_high_voltage_limit,max{(t,s) in SUBSTATIONS: substation_Vmax[t,s] > 0} substation_Vmax[t,s]) +else max_plausible_high_voltage_limit; check minimal_voltage_lower_bound > 0; check maximal_voltage_upper_bound > minimal_voltage_lower_bound; @@ -549,7 +549,7 @@ set UNITCC := setof {(1,g,n) in UNIT : n in BUSCC} (g,n); set BATTERYCC := setof {(1,b,n) in BATTERY : n in BUSCC} (b,n); # Busses with valid voltage value -set BUSVV := {n in BUSCC : bus_V0[1,n] >= consistent_min_voltage}; +set BUSVV := {n in BUSCC : bus_V0[1,n] >= min_plausible_low_voltage_limit}; # Units up and generating: # Warning: units with Ptarget=0 are considered as out of order @@ -817,10 +817,10 @@ subject to ctr_null_phase_bus{PROBLEM_ACOPF}: teta[null_phase_bus] = 0; # Modulus of voltage var V{n in BUSCC} <= - if substation_Vnomi[1,bus_substation[1,n]] <= ignore_voltage_bounds then consistent_max_voltage else + if substation_Vnomi[1,bus_substation[1,n]] <= ignore_voltage_bounds then max_plausible_high_voltage_limit else voltage_upper_bound[1,bus_substation[1,n]], >= - if substation_Vnomi[1,bus_substation[1,n]] <= ignore_voltage_bounds then consistent_min_voltage else + if substation_Vnomi[1,bus_substation[1,n]] <= ignore_voltage_bounds then min_plausible_low_voltage_limit else voltage_lower_bound[1,bus_substation[1,n]]; diff --git a/open-reac/src/main/resources/openreac/reactiveopf.run b/open-reac/src/main/resources/openreac/reactiveopf.run index de22c565..5575a906 100644 --- a/open-reac/src/main/resources/openreac/reactiveopf.run +++ b/open-reac/src/main/resources/openreac/reactiveopf.run @@ -291,26 +291,26 @@ if "epsilon_nominal_voltage" in PARAM_ALGO_KEYS then let epsilon_nominal_voltage printf{LOG_INFO} "Parameter: for consistency checks of minimum nominal voltages epsilon_nominal_voltage:= %Q kV\n",epsilon_nominal_voltage; check epsilon_nominal_voltage > 0; -# Minimum consistency value for voltage in PU +# Minimum plausible value for voltage low limits in PU # This value should be < 1 -param consistent_min_voltage default 0.5; -if "consistent_min_voltage" in PARAM_ALGO_KEYS then let consistent_min_voltage := num(PARAM_ALGO_VALUES["consistent_min_voltage"]); -printf{LOG_INFO} "Parameter: for consistency of voltage bounds, consistent_min_voltage:= %Q pu\n",consistent_min_voltage; -check consistent_min_voltage > 0; +param min_plausible_low_voltage_limit default 0.5; +if "min_plausible_low_voltage_limit" in PARAM_ALGO_KEYS then let min_plausible_low_voltage_limit := num(PARAM_ALGO_VALUES["min_plausible_low_voltage_limit"]); +printf{LOG_INFO} "Parameter: for consistency of voltage bounds, min_plausible_low_voltage_limit:= %Q pu\n",min_plausible_low_voltage_limit; +check min_plausible_low_voltage_limit > 0; -# Maximum consistency value for voltage in PU -param consistent_max_voltage default 1.5; -if "consistent_max_voltage" in PARAM_ALGO_KEYS then let consistent_max_voltage := num(PARAM_ALGO_VALUES["consistent_max_voltage"]); -printf{LOG_INFO} "Parameter: for consistency of voltage bounds, consistent_max_voltage:= %Q pu\n",consistent_max_voltage; -check consistent_max_voltage > consistent_min_voltage; +# Maximum plausible value for voltage high limits in PU +param max_plausible_high_voltage_limit default 1.5; +if "max_plausible_high_voltage_limit" in PARAM_ALGO_KEYS then let max_plausible_high_voltage_limit := num(PARAM_ALGO_VALUES["max_plausible_high_voltage_limit"]); +printf{LOG_INFO} "Parameter: for consistency of voltage bounds, max_plausible_high_voltage_limit:= %Q pu\n",max_plausible_high_voltage_limit; +check max_plausible_high_voltage_limit > min_plausible_low_voltage_limit; # Ignore voltage bounds for buses with nominal voltage lower than this parameter # For all busses with nominal voltage lower than ignore_voltage_bounds, voltage bonds will be ignored -# and replaced by [consistent_min_voltage ; consistent_max_voltage] +# and replaced by [min_plausible_low_voltage_limit ; max_plausible_high_voltage_limit] param ignore_voltage_bounds default 0; if "ignore_voltage_bounds" in PARAM_ALGO_KEYS then let ignore_voltage_bounds := num(PARAM_ALGO_VALUES["ignore_voltage_bounds"]); if ignore_voltage_bounds >= epsilon_nominal_voltage -then printf{LOG_INFO} "Parameter: for all busses with nominal voltage <= ignore_voltage_bounds=%.1f, voltage bounds are ignored and replaced by [%.3f;%.3f]\n",ignore_voltage_bounds,consistent_min_voltage,consistent_max_voltage; +then printf{LOG_INFO} "Parameter: for all busses with nominal voltage <= ignore_voltage_bounds=%.1f, voltage bounds are ignored and replaced by [%.3f;%.3f]\n",ignore_voltage_bounds,min_plausible_low_voltage_limit,max_plausible_high_voltage_limit; check ignore_voltage_bounds >= 0; # Consistency maximal value for P and Q diff --git a/open-reac/src/main/resources/openreac/reactiveopfexit.run b/open-reac/src/main/resources/openreac/reactiveopfexit.run index 14b468e7..0c0a1189 100644 --- a/open-reac/src/main/resources/openreac/reactiveopfexit.run +++ b/open-reac/src/main/resources/openreac/reactiveopfexit.run @@ -53,8 +53,8 @@ printf "\n" > (fileOut); printf "%s %f\n","Pnull",Pnull > (fileOut); printf "%s %f\n","Znull",Znull > (fileOut); printf "%s %f\n","epsilon_nominal_voltage",epsilon_nominal_voltage > (fileOut); -printf "%s %f\n","consistent_min_voltage",consistent_min_voltage > (fileOut); -printf "%s %f\n","consistent_max_voltage",consistent_max_voltage > (fileOut); +printf "%s %f\n","min_plausible_low_voltage_limit",min_plausible_low_voltage_limit > (fileOut); +printf "%s %f\n","max_plausible_high_voltage_limit",max_plausible_high_voltage_limit > (fileOut); printf "%s %f\n","ignore_voltage_bounds",ignore_voltage_bounds > (fileOut); printf "%s %f\n","PQmax",PQmax > (fileOut); printf "%s %f\n","defaultPmax",defaultPmax > (fileOut); diff --git a/open-reac/src/main/resources/openreac/reactiveopfoutput.run b/open-reac/src/main/resources/openreac/reactiveopfoutput.run index 1c1ffc08..b1553df4 100644 --- a/open-reac/src/main/resources/openreac/reactiveopfoutput.run +++ b/open-reac/src/main/resources/openreac/reactiveopfoutput.run @@ -237,8 +237,8 @@ printf "%s %f\n","coeff_alpha",coeff_alpha > (fileOut); printf "%s %f\n","Pnull",Pnull > (fileOut); printf "%s %f\n","Znull",Znull > (fileOut); printf "%s %f\n","epsilon_nominal_voltage",epsilon_nominal_voltage > (fileOut); -printf "%s %f\n","consistent_min_voltage",consistent_min_voltage > (fileOut); -printf "%s %f\n","consistent_max_voltage",consistent_max_voltage > (fileOut); +printf "%s %f\n","min_plausible_low_voltage_limit",min_plausible_low_voltage_limit > (fileOut); +printf "%s %f\n","max_plausible_high_voltage_limit",max_plausible_high_voltage_limit > (fileOut); printf "%s %f\n","ignore_voltage_bounds",ignore_voltage_bounds > (fileOut); printf "%s %f\n","PQmax",PQmax > (fileOut); printf "%s %f\n","defaultPmax",defaultPmax > (fileOut); diff --git a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java index 9153db05..50243a18 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java @@ -80,9 +80,9 @@ void testAlgorithmParams() { 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("min_plausible_low_voltage_limit", algoParams.get(3).getName()); assertEquals("0.8", algoParams.get(3).getValue()); - assertEquals("consistent_max_voltage", algoParams.get(4).getName()); + assertEquals("max_plausible_high_voltage_limit", algoParams.get(4).getName()); assertEquals("1.2", algoParams.get(4).getValue()); } diff --git a/open-reac/src/test/resources/openreac-input-algo-parameters/minmax_plausible_voltage_limits.txt b/open-reac/src/test/resources/openreac-input-algo-parameters/minmax_plausible_voltage_limits.txt index f5c94c70..35e1f7fd 100644 --- a/open-reac/src/test/resources/openreac-input-algo-parameters/minmax_plausible_voltage_limits.txt +++ b/open-reac/src/test/resources/openreac-input-algo-parameters/minmax_plausible_voltage_limits.txt @@ -1,4 +1,4 @@ objective_choice 0 -consistent_min_voltage 0.7888 -consistent_max_voltage 1.3455 +min_plausible_low_voltage_limit 0.7888 +max_plausible_high_voltage_limit 1.3455 From 12593684bed4a401e0bb26515f1c741bfc38b5e3 Mon Sep 17 00:00:00 2001 From: parvy Date: Fri, 10 Nov 2023 14:21:12 +0100 Subject: [PATCH 08/26] Refactor unit test. Signed-off-by: parvy --- .../src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java b/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java index 52cb0894..d7aab5b9 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java @@ -91,7 +91,7 @@ void testDefaultParamAlgoExport() throws IOException { } @Test - void testConsistentVoltageLimitsParamAlgoExport() throws IOException { + void testMinMaxPlausibleVoltageLimitsParamAlgoExport() throws IOException { Network network = IeeeCdfNetworkFactory.create118(); setDefaultVoltageLimits(network); // set default voltage limits to every voltage levels of the network OpenReacParameters parameters = new OpenReacParameters() From 0ac46c9e4891ed1ab631ccc0000db088684cb516 Mon Sep 17 00:00:00 2001 From: parvy Date: Mon, 13 Nov 2023 15:43:15 +0100 Subject: [PATCH 09/26] Add openreac parameters in OpenReacParameters. Signed-off-by: parvy --- .../parameters/input/OpenReacParameters.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java index 8f27f3c9..0c34ea9a 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java @@ -53,6 +53,28 @@ public class OpenReacParameters { private Double maxPlausibleHighVoltageLimit; // in pu + private static final String ALPHA_COEFFICIENT_KEY = "coeff_alpha"; + + private Double alphaCoefficient; // in [0;1]. If 1, minimizes sum of generation. If 0, minimizes sum of differences between target and value + + private static final String ZERO_POWER_THRESHOLD_KEY = "Pnull"; + + private Double zeroPowerThreshold; // in MW, for detecting zero value for power + + private static final String ZERO_IMPEDANCE_KEY = "Znull"; + + private Double zeroImpedance; // in p.u., for detecting null impedance branches + + private static final String LOW_IGNORED_NOMINAL_VOLTAGE_KEY = "epsilon_nominal_voltage"; + + private Double lowIgnoredNominalVoltage; // in kV, to ignore buses with Vnom lower than this value + + private static final String LOW_IGNORED_VOLTAGE_BOUNDS_KEY = "ignore_voltage_bounds"; + + private Double lowIgnoredVoltageBounds; // in kV, to ignore voltage bounds of buses with Vnom lower than this value + + + /** * Override some voltage level limits in the network. This will NOT modify the network object. *

From dac3c188aaa8f7acec312768fdd809bdc50468aa Mon Sep 17 00:00:00 2001 From: parvy Date: Wed, 15 Nov 2023 10:00:49 +0100 Subject: [PATCH 10/26] Add methods to access/set OpenReac parameters. Signed-off-by: parvy --- .../parameters/input/OpenReacParameters.java | 108 +++++++++++++++--- 1 file changed, 95 insertions(+), 13 deletions(-) diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java index 0c34ea9a..c9a0cd20 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java @@ -55,23 +55,23 @@ public class OpenReacParameters { private static final String ALPHA_COEFFICIENT_KEY = "coeff_alpha"; - private Double alphaCoefficient; // in [0;1]. If 1, minimizes sum of generation. If 0, minimizes sum of differences between target and value + private Double alphaCoefficient = 1.; // in [0;1] private static final String ZERO_POWER_THRESHOLD_KEY = "Pnull"; - private Double zeroPowerThreshold; // in MW, for detecting zero value for power + private Double zeroPowerThreshold = 0.01; // in MW, for detecting zero value for power - private static final String ZERO_IMPEDANCE_KEY = "Znull"; + private static final String ZERO_IMPEDANCE_THRESHOLD_KEY = "Znull"; - private Double zeroImpedance; // in p.u., for detecting null impedance branches + private Double zeroImpedanceThreshold = 1e-4; // in p.u., for detecting null impedance branches - private static final String LOW_IGNORED_NOMINAL_VOLTAGE_KEY = "epsilon_nominal_voltage"; + private static final String NOMINAL_THRESHOLD_IGNORED_BUS_KEY = "epsilon_nominal_voltage"; - private Double lowIgnoredNominalVoltage; // in kV, to ignore buses with Vnom lower than this value + private Double nominalThresholdIgnoredBuses = 1.; // in kV, to ignore buses with Vnom lower than this value - private static final String LOW_IGNORED_VOLTAGE_BOUNDS_KEY = "ignore_voltage_bounds"; + private static final String NOMINAL_THRESHOLD_IGNORED_VOLTAGE_BOUNDS_KEY = "ignore_voltage_bounds"; - private Double lowIgnoredVoltageBounds; // in kV, to ignore voltage bounds of buses with Vnom lower than this value + private Double nominalThresholdIgnoredVoltageBounds = 0.; // in kV, to ignore voltage bounds of buses with Vnom lower than this value @@ -165,6 +165,9 @@ public Double getObjectiveDistance() { * @param objectiveDistance is in % */ public OpenReacParameters setObjectiveDistance(double objectiveDistance) { + if (Double.isNaN(objectiveDistance) || objectiveDistance > 1 || objectiveDistance < 0) { + throw new IllegalArgumentException("Objective distance must be defined and >= 0 and <= 1 to be consistent"); + } this.objectiveDistance = objectiveDistance; return this; } @@ -177,8 +180,8 @@ public Double getMinPlausibleLowVoltageLimit() { } public OpenReacParameters setMinPlausibleLowVoltageLimit(double minPlausibleLowVoltageLimit) { - if (minPlausibleLowVoltageLimit < 0) { - throw new InvalidParametersException("Min plausible low voltage limit must be >= 0 to be consistent."); + if (Double.isNaN(minPlausibleLowVoltageLimit) || minPlausibleLowVoltageLimit < 0) { + throw new InvalidParametersException("Min plausible low voltage limit must be defined and >= 0 to be consistent."); } this.minPlausibleLowVoltageLimit = minPlausibleLowVoltageLimit; return this; @@ -192,13 +195,73 @@ public Double getMaxPlausibleHighVoltageLimit() { } public OpenReacParameters setMaxPlausibleHighVoltageLimit(double maxPlausibleHighVoltageLimit) { - if (maxPlausibleHighVoltageLimit <= 0) { - throw new InvalidParametersException("Max plausible high voltage limit must be > 0 to be consistent."); + if (Double.isNaN(maxPlausibleHighVoltageLimit) || maxPlausibleHighVoltageLimit <= 0) { + throw new InvalidParametersException("Max plausible high voltage limit must be defined and > 0 to be consistent."); } this.maxPlausibleHighVoltageLimit = maxPlausibleHighVoltageLimit; return this; } + public Double getAlphaCoefficient() { + return alphaCoefficient; + } + + public OpenReacParameters setAlphaCoefficient(Double alphaCoefficient) { + if (Double.isNaN(alphaCoefficient) || alphaCoefficient < 0 || alphaCoefficient > 1) { + throw new InvalidParametersException("Coefficient alpha parameter must be defined and between 0 and 1 to be consistent."); + } + this.alphaCoefficient = alphaCoefficient; + return this; + } + + public Double getZeroPowerThreshold() { + return zeroPowerThreshold; + } + + public OpenReacParameters setZeroPowerThreshold(Double zeroPowerThreshold) { + if (Double.isNaN(zeroPowerThreshold) || zeroPowerThreshold < 0) { + throw new InvalidParametersException("Zero power threshold must be defined and >= 0 to be consistent."); + } + this.zeroPowerThreshold = zeroPowerThreshold; + return this; + } + + public Double getZeroImpedanceThreshold() { + return zeroImpedanceThreshold; + } + + public OpenReacParameters setZeroImpedanceThreshold(Double zeroImpedanceThreshold) { + if (Double.isNaN(zeroImpedanceThreshold) || zeroImpedanceThreshold < 0) { + throw new InvalidParametersException("Zero impedance threshold must be defined and >= 0 to be consistent."); + } + this.zeroImpedanceThreshold = zeroImpedanceThreshold; + return this; + } + + public Double getNominalThresholdIgnoredBuses() { + return nominalThresholdIgnoredBuses; + } + + public OpenReacParameters setNominalThresholdIgnoredBuses(Double nominalThresholdIgnoredBuses) { + if (Double.isNaN(nominalThresholdIgnoredBuses) || nominalThresholdIgnoredBuses < 0) { + throw new InvalidParametersException("Nominal threshold for ignored buses must be defined and >= 0 to be consistent."); + } + this.nominalThresholdIgnoredBuses = nominalThresholdIgnoredBuses; + return this; + } + + public Double getNominalThresholdIgnoredVoltageBounds() { + return nominalThresholdIgnoredVoltageBounds; + } + + public OpenReacParameters setNominalThresholdIgnoredVoltageBounds(Double nominalThresholdIgnoredVoltageBounds) { + if (Double.isNaN(nominalThresholdIgnoredVoltageBounds) || nominalThresholdIgnoredVoltageBounds < 0) { + throw new InvalidParametersException("Nominal threshold for ignored voltage bounds must be defined and >= 0 to be consistent"); + } + this.nominalThresholdIgnoredVoltageBounds = nominalThresholdIgnoredVoltageBounds; + return this; + } + public List getVariableShuntCompensators() { return variableShuntCompensators; } @@ -216,7 +279,7 @@ public List getVariableTwoWindingsTransformers() { } public List getAllAlgorithmParams() { - ArrayList allAlgoParams = new ArrayList<>(algorithmParams.size() + 4); + ArrayList allAlgoParams = new ArrayList<>(algorithmParams.size() + 9); allAlgoParams.addAll(algorithmParams); if (objective != null) { allAlgoParams.add(objective.toParam()); @@ -230,6 +293,21 @@ public List getAllAlgorithmParams() { if (maxPlausibleHighVoltageLimit != null) { allAlgoParams.add(new OpenReacAlgoParamImpl(MAX_PLAUSIBLE_HIGH_VOLTAGE_LIMIT_KEY, Double.toString(maxPlausibleHighVoltageLimit))); } + if (alphaCoefficient != null) { + allAlgoParams.add(new OpenReacAlgoParamImpl(ALPHA_COEFFICIENT_KEY, Double.toString(alphaCoefficient))); + } + if (zeroPowerThreshold != null) { + allAlgoParams.add(new OpenReacAlgoParamImpl(ZERO_POWER_THRESHOLD_KEY, Double.toString(zeroPowerThreshold))); + } + if (zeroImpedanceThreshold != null) { + allAlgoParams.add(new OpenReacAlgoParamImpl(ZERO_IMPEDANCE_THRESHOLD_KEY, Double.toString(zeroImpedanceThreshold))); + } + if (nominalThresholdIgnoredBuses != null) { + allAlgoParams.add(new OpenReacAlgoParamImpl(NOMINAL_THRESHOLD_IGNORED_BUS_KEY, Double.toString(nominalThresholdIgnoredBuses))); + } + if (nominalThresholdIgnoredVoltageBounds != null) { + allAlgoParams.add(new OpenReacAlgoParamImpl(NOMINAL_THRESHOLD_IGNORED_VOLTAGE_BOUNDS_KEY, Double.toString(nominalThresholdIgnoredVoltageBounds))); + } return allAlgoParams; } @@ -294,6 +372,10 @@ public boolean checkAlgorithmParametersIntegrity() { integrityAlgorithmParameters = false; } + if (nominalThresholdIgnoredBuses > nominalThresholdIgnoredVoltageBounds) { + LOGGER.warn("Some buses with ignored voltage bounds will be ignored in calculations."); + } + return integrityAlgorithmParameters; } From 7bd8d98b4a0a923369db23cdb05b1a9cbd70d98d Mon Sep 17 00:00:00 2001 From: parvy Date: Thu, 16 Nov 2023 18:42:45 +0100 Subject: [PATCH 11/26] Remove algoParam map and replace with OpenReac interfaces. Signed-off-by: parvy --- .../parameters/input/OpenReacParameters.java | 103 +++++------------- .../json/OpenReacParametersDeserializer.java | 33 +++++- .../json/OpenReacParametersSerializer.java | 13 ++- .../openreac/OpenReacParametersTest.java | 60 ++++------ .../powsybl/openreac/OpenReacRunnerTest.java | 15 ++- .../input/json/OpenReacJsonModuleTest.java | 30 +++-- .../resources/expected_inputs/param_algo.txt | 7 ++ .../default.txt | 8 ++ .../minmax_plausible_voltage_limits.txt | 4 - .../modified_param_algo.txt | 10 ++ open-reac/src/test/resources/parameters.json | 16 +-- 11 files changed, 152 insertions(+), 147 deletions(-) delete mode 100644 open-reac/src/test/resources/openreac-input-algo-parameters/minmax_plausible_voltage_limits.txt create mode 100644 open-reac/src/test/resources/openreac-input-algo-parameters/modified_param_algo.txt diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java index c9a0cd20..cf8a5b04 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java @@ -35,23 +35,21 @@ public class OpenReacParameters { private final List variableTwoWindingsTransformers = new ArrayList<>(); - private final List 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 Double objectiveDistance = 0.5; private static final String MIN_PLAUSIBLE_LOW_VOLTAGE_LIMIT_KEY = "min_plausible_low_voltage_limit"; - private Double minPlausibleLowVoltageLimit; // in pu + private Double minPlausibleLowVoltageLimit = 0.5; // in pu private static final String MAX_PLAUSIBLE_HIGH_VOLTAGE_LIMIT_KEY = "max_plausible_high_voltage_limit"; - private Double maxPlausibleHighVoltageLimit; // in pu + private Double maxPlausibleHighVoltageLimit = 1.5; // in pu private static final String ALPHA_COEFFICIENT_KEY = "coeff_alpha"; @@ -73,8 +71,6 @@ public class OpenReacParameters { private Double nominalThresholdIgnoredVoltageBounds = 0.; // in kV, to ignore voltage bounds of buses with Vnom lower than this value - - /** * Override some voltage level limits in the network. This will NOT modify the network object. *

@@ -86,6 +82,10 @@ public OpenReacParameters addSpecificVoltageLimits(List sp return this; } + public List getSpecificVoltageLimits() { + return specificVoltageLimits; + } + /** * A list of shunt compensators, which susceptance will be considered as variable by the optimizer. * The optimizer computes a continuous value that is rounded when results are stored in {@link com.powsybl.openreac.parameters.output.OpenReacResult}. @@ -95,6 +95,10 @@ public OpenReacParameters addVariableShuntCompensators(List shuntsIds) { return this; } + public List getVariableShuntCompensators() { + return variableShuntCompensators; + } + /** * The reactive power produced by every generator in the list will be constant and equal to `targetQ`. */ @@ -103,6 +107,10 @@ public OpenReacParameters addConstantQGenerators(List generatorsIds) { return this; } + public List getConstantQGenerators() { + return constantQGenerators; + } + /** * A list of two windings transformers, which ratio will be considered as variable by the optimizer. */ @@ -111,24 +119,8 @@ public OpenReacParameters addVariableTwoWindingsTransformers(List transf return this; } - /** - * Add a parameter to the optimization engine - */ - public OpenReacParameters addAlgorithmParam(List algorithmParams) { - this.algorithmParams.addAll(algorithmParams); - return this; - } - - /** - * Add a parameter to the optimization engine - */ - public OpenReacParameters addAlgorithmParam(String name, String value) { - algorithmParams.add(new OpenReacAlgoParamImpl(name, value)); - return this; - } - - public List getAlgorithmParams() { - return algorithmParams; + public List getVariableTwoWindingsTransformers() { + return variableTwoWindingsTransformers; } /** @@ -262,52 +254,17 @@ public OpenReacParameters setNominalThresholdIgnoredVoltageBounds(Double nominal return this; } - public List getVariableShuntCompensators() { - return variableShuntCompensators; - } - - public List getSpecificVoltageLimits() { - return specificVoltageLimits; - } - - public List getConstantQGenerators() { - return constantQGenerators; - } - - public List getVariableTwoWindingsTransformers() { - return variableTwoWindingsTransformers; - } - public List getAllAlgorithmParams() { - ArrayList allAlgoParams = new ArrayList<>(algorithmParams.size() + 9); - 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 (minPlausibleLowVoltageLimit != null) { - allAlgoParams.add(new OpenReacAlgoParamImpl(MIN_PLAUSIBLE_LOW_VOLTAGE_LIMIT_KEY, Double.toString(minPlausibleLowVoltageLimit))); - } - if (maxPlausibleHighVoltageLimit != null) { - allAlgoParams.add(new OpenReacAlgoParamImpl(MAX_PLAUSIBLE_HIGH_VOLTAGE_LIMIT_KEY, Double.toString(maxPlausibleHighVoltageLimit))); - } - if (alphaCoefficient != null) { - allAlgoParams.add(new OpenReacAlgoParamImpl(ALPHA_COEFFICIENT_KEY, Double.toString(alphaCoefficient))); - } - if (zeroPowerThreshold != null) { - allAlgoParams.add(new OpenReacAlgoParamImpl(ZERO_POWER_THRESHOLD_KEY, Double.toString(zeroPowerThreshold))); - } - if (zeroImpedanceThreshold != null) { - allAlgoParams.add(new OpenReacAlgoParamImpl(ZERO_IMPEDANCE_THRESHOLD_KEY, Double.toString(zeroImpedanceThreshold))); - } - if (nominalThresholdIgnoredBuses != null) { - allAlgoParams.add(new OpenReacAlgoParamImpl(NOMINAL_THRESHOLD_IGNORED_BUS_KEY, Double.toString(nominalThresholdIgnoredBuses))); - } - if (nominalThresholdIgnoredVoltageBounds != null) { - allAlgoParams.add(new OpenReacAlgoParamImpl(NOMINAL_THRESHOLD_IGNORED_VOLTAGE_BOUNDS_KEY, Double.toString(nominalThresholdIgnoredVoltageBounds))); - } + ArrayList allAlgoParams = new ArrayList<>(); + allAlgoParams.add(objective.toParam()); + allAlgoParams.add(new OpenReacAlgoParamImpl(OBJECTIVE_DISTANCE_KEY, Double.toString(objectiveDistance))); + 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(new OpenReacAlgoParamImpl(ALPHA_COEFFICIENT_KEY, Double.toString(alphaCoefficient))); + allAlgoParams.add(new OpenReacAlgoParamImpl(ZERO_POWER_THRESHOLD_KEY, Double.toString(zeroPowerThreshold))); + allAlgoParams.add(new OpenReacAlgoParamImpl(ZERO_IMPEDANCE_THRESHOLD_KEY, Double.toString(zeroImpedanceThreshold))); + allAlgoParams.add(new OpenReacAlgoParamImpl(NOMINAL_THRESHOLD_IGNORED_BUS_KEY, Double.toString(nominalThresholdIgnoredBuses))); + allAlgoParams.add(new OpenReacAlgoParamImpl(NOMINAL_THRESHOLD_IGNORED_VOLTAGE_BOUNDS_KEY, Double.toString(nominalThresholdIgnoredVoltageBounds))); return allAlgoParams; } @@ -359,12 +316,6 @@ public void checkIntegrity(Network network) throws InvalidParametersException { public boolean checkAlgorithmParametersIntegrity() { boolean integrityAlgorithmParameters = true; - // Check integrity of objective function - if (objective.equals(OpenReacOptimisationObjective.BETWEEN_HIGH_AND_LOW_VOLTAGE_LIMIT) && objectiveDistance == null) { - 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 plausible voltage limits if (minPlausibleLowVoltageLimit != null && maxPlausibleHighVoltageLimit != null && minPlausibleLowVoltageLimit > maxPlausibleHighVoltageLimit) { diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersDeserializer.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersDeserializer.java index 905d457b..3a7cf2da 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersDeserializer.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersDeserializer.java @@ -13,7 +13,6 @@ import com.fasterxml.jackson.databind.deser.std.StdDeserializer; import com.powsybl.openreac.parameters.input.OpenReacParameters; import com.powsybl.openreac.parameters.input.VoltageLimitOverride; -import com.powsybl.openreac.parameters.input.algo.OpenReacAlgoParam; import com.powsybl.openreac.parameters.input.algo.OpenReacOptimisationObjective; import java.io.IOException; @@ -56,10 +55,6 @@ public OpenReacParameters deserialize(JsonParser parser, DeserializationContext parser.nextToken(); parameters.addVariableTwoWindingsTransformers(parser.readValueAs(new TypeReference>() { })); break; - case "algorithmParams": - parser.nextToken(); - parameters.addAlgorithmParam(parser.readValueAs(new TypeReference>() { })); - break; case "objective": parser.nextToken(); parameters.setObjective(OpenReacOptimisationObjective.valueOf(parser.getText())); @@ -68,6 +63,34 @@ public OpenReacParameters deserialize(JsonParser parser, DeserializationContext parser.nextToken(); parameters.setObjectiveDistance(parser.getValueAsDouble()); break; + case "minPlausibleLowVoltageLimit": + parser.nextToken(); + parameters.setMinPlausibleLowVoltageLimit(parser.getValueAsDouble()); + break; + case "maxPlausibleHighVoltageLimit": + parser.nextToken(); + parameters.setMaxPlausibleHighVoltageLimit(parser.getValueAsDouble()); + break; + case "alphaCoefficient": + parser.nextToken(); + parameters.setAlphaCoefficient(parser.getValueAsDouble()); + break; + case "zeroPowerThreshold": + parser.nextToken(); + parameters.setZeroPowerThreshold(parser.getValueAsDouble()); + break; + case "zeroImpedanceThreshold": + parser.nextToken(); + parameters.setZeroImpedanceThreshold(parser.getValueAsDouble()); + break; + case "nominalThresholdIgnoredBuses": + parser.nextToken(); + parameters.setNominalThresholdIgnoredBuses(parser.getValueAsDouble()); + break; + case "nominalThresholdIgnoredVoltageBounds": + parser.nextToken(); + parameters.setNominalThresholdIgnoredVoltageBounds(parser.getValueAsDouble()); + break; default: throw new IllegalStateException("Unexpected field: " + parser.getCurrentName()); } diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersSerializer.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersSerializer.java index b15a5e98..00cb21b2 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersSerializer.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersSerializer.java @@ -34,11 +34,16 @@ 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); - serializerProvider.defaultSerializeField("algorithmParams", openReacParameters.getAlgorithmParams(), jsonGenerator); serializerProvider.defaultSerializeField("objective", openReacParameters.getObjective().name(), jsonGenerator); - if (openReacParameters.getObjectiveDistance() != null) { - serializerProvider.defaultSerializeField("objectiveDistance", openReacParameters.getObjectiveDistance(), jsonGenerator); - } + serializerProvider.defaultSerializeField("objectiveDistance", openReacParameters.getObjectiveDistance(), jsonGenerator); + serializerProvider.defaultSerializeField("minPlausibleLowVoltageLimit", openReacParameters.getMinPlausibleLowVoltageLimit(), jsonGenerator); + serializerProvider.defaultSerializeField("maxPlausibleHighVoltageLimit", openReacParameters.getMaxPlausibleHighVoltageLimit(), jsonGenerator); + serializerProvider.defaultSerializeField("alphaCoefficient", openReacParameters.getAlphaCoefficient(), jsonGenerator); + serializerProvider.defaultSerializeField("zeroPowerThreshold", openReacParameters.getZeroPowerThreshold(), jsonGenerator); + serializerProvider.defaultSerializeField("zeroImpedanceThreshold", openReacParameters.getZeroImpedanceThreshold(), jsonGenerator); + serializerProvider.defaultSerializeField("nominalThresholdIgnoredBuses", openReacParameters.getNominalThresholdIgnoredBuses(), jsonGenerator); + serializerProvider.defaultSerializeField("nominalThresholdIgnoredVoltageBounds", openReacParameters.getNominalThresholdIgnoredVoltageBounds(), jsonGenerator); + jsonGenerator.writeEndObject(); } } diff --git a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java index 50243a18..105aebb6 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java @@ -10,7 +10,6 @@ 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; @@ -28,28 +27,38 @@ public class OpenReacParametersTest { public void testObjectiveIntegrityChecks() { Network network = IeeeCdfNetworkFactory.create118(); setDefaultVoltageLimits(network); // set default voltage limits to every voltage levels of the network - OpenReacParameters parameters = new OpenReacParameters(); - assertEquals(parameters.getObjective(), OpenReacOptimisationObjective.MIN_GENERATION); - assertThrows(NullPointerException.class, () -> parameters.setObjective(null), "We can't unset objective function."); - parameters.setObjective(OpenReacOptimisationObjective.MIN_GENERATION); - assertDoesNotThrow(() -> parameters.checkIntegrity(network), "Default configuration with only objective should be ok."); + // Objective choice + OpenReacParameters parameters = new OpenReacParameters(); + assertEquals(OpenReacOptimisationObjective.MIN_GENERATION, parameters.getObjective()); parameters.setObjective(OpenReacOptimisationObjective.BETWEEN_HIGH_AND_LOW_VOLTAGE_LIMIT); - assertThrows(InvalidParametersException.class, () -> parameters.checkIntegrity(network), "BETWEEN_HIGH_AND_LOW_VOLTAGE_LIMIT without ratio voltage set should throw"); - parameters.setObjectiveDistance(1); - assertDoesNotThrow(() -> parameters.checkIntegrity(network), "Default configuration with BETWEEN_HIGH_AND_LOW_VOLTAGE_LIMIT and ratio voltage set should not throw"); + assertEquals(OpenReacOptimisationObjective.BETWEEN_HIGH_AND_LOW_VOLTAGE_LIMIT, parameters.getObjective()); + parameters.setObjective(OpenReacOptimisationObjective.SPECIFIC_VOLTAGE_PROFILE); + assertEquals(OpenReacOptimisationObjective.SPECIFIC_VOLTAGE_PROFILE, parameters.getObjective()); + assertThrows(NullPointerException.class, () -> parameters.setObjective(null), "We can't unset objective function."); + + // Objective distance for BETWEEN_HIGH_AND_LOW_VOLTAGE_LIMIT objective + assertEquals(0.5, parameters.getObjectiveDistance()); // default value + parameters.setObjectiveDistance(0.); // min value + assertEquals(0., parameters.getObjectiveDistance()); + parameters.setObjectiveDistance(1.); // max value + assertEquals(1., parameters.getObjectiveDistance()); + assertThrows(IllegalArgumentException.class, () -> parameters.setObjectiveDistance(-2.)); + assertThrows(IllegalArgumentException.class, () -> parameters.setObjectiveDistance(1.2)); + assertThrows(IllegalArgumentException.class, () -> parameters.setObjectiveDistance(Double.NaN), "Objective distance must be defined."); + + assertDoesNotThrow(() -> parameters.checkIntegrity(network)); + parameters.setObjectiveDistance(0.15); } @Test void testMinMaxVoltageLimitIntegrityChecks() { OpenReacParameters parameters = new OpenReacParameters(); - assertNull(parameters.getMinPlausibleLowVoltageLimit()); - assertNull(parameters.getMaxPlausibleHighVoltageLimit()); // Consistency of min plausible low voltage limit (>= 0) assertThrows(InvalidParametersException.class, () -> parameters.setMinPlausibleLowVoltageLimit(-0.25)); - parameters.setMinPlausibleLowVoltageLimit(0.8); - assertEquals(0.8, parameters.getMinPlausibleLowVoltageLimit()); + parameters.setMinPlausibleLowVoltageLimit(0.8211); + assertEquals(0.8211, parameters.getMinPlausibleLowVoltageLimit()); // Consistency of max plausible high voltage limit (> 0) assertThrows(InvalidParametersException.class, () -> parameters.setMaxPlausibleHighVoltageLimit(-0.15)); @@ -63,29 +72,6 @@ void testMinMaxVoltageLimitIntegrityChecks() { 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.setMinPlausibleLowVoltageLimit(0.8); - parameters.setMaxPlausibleHighVoltageLimit(1.2); - List 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("min_plausible_low_voltage_limit", algoParams.get(3).getName()); - assertEquals("0.8", algoParams.get(3).getValue()); - assertEquals("max_plausible_high_voltage_limit", algoParams.get(4).getName()); - assertEquals("1.2", algoParams.get(4).getValue()); - } - @Test public void testParametersIntegrityChecks() { Network network = IeeeCdfNetworkFactory.create118(); @@ -97,7 +83,7 @@ public void testParametersIntegrityChecks() { 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(1, parameters.getAllAlgorithmParams().size()); + assertEquals(9, parameters.getAllAlgorithmParams().size()); // adding an objective, to have a valid OpenReacParameter object parameters.setObjective(OpenReacOptimisationObjective.MIN_GENERATION); diff --git a/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java b/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java index d7aab5b9..e8b7eab7 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java @@ -91,12 +91,19 @@ void testDefaultParamAlgoExport() throws IOException { } @Test - void testMinMaxPlausibleVoltageLimitsParamAlgoExport() throws IOException { + void testParamAlgoExport() throws IOException { Network network = IeeeCdfNetworkFactory.create118(); setDefaultVoltageLimits(network); // set default voltage limits to every voltage levels of the network OpenReacParameters parameters = new OpenReacParameters() + .setObjective(OpenReacOptimisationObjective.SPECIFIC_VOLTAGE_PROFILE) + .setObjectiveDistance(0.69) .setMinPlausibleLowVoltageLimit(0.7888) - .setMaxPlausibleHighVoltageLimit(1.3455); + .setMaxPlausibleHighVoltageLimit(1.3455) + .setAlphaCoefficient(0.88) + .setZeroPowerThreshold(0.45) + .setZeroImpedanceThreshold(1e-5) + .setNominalThresholdIgnoredBuses(2.) + .setNominalThresholdIgnoredVoltageBounds(0.75); LocalCommandExecutor localCommandExecutor = new TestLocalCommandExecutor( List.of("empty_case/reactiveopf_results_indic.txt")); @@ -105,7 +112,7 @@ void testMinMaxPlausibleVoltageLimitsParamAlgoExport() throws IOException { OpenReacRunner.run(network, network.getVariantManager().getWorkingVariantId(), parameters, new OpenReacConfig(true), computationManager); Path execFolder = getAmplExecPath(); - assertEqualsToRef(execFolder.resolve("param_algo.txt"), "/openreac-input-algo-parameters/minmax_plausible_voltage_limits.txt"); + assertEqualsToRef(execFolder.resolve("param_algo.txt"), "/openreac-input-algo-parameters/modified_param_algo.txt"); } } @@ -116,7 +123,7 @@ void testInputFile() throws IOException { setDefaultVoltageLimits(network); // set default voltage limits to every voltage levels of the network OpenReacParameters parameters = new OpenReacParameters().setObjective( OpenReacOptimisationObjective.BETWEEN_HIGH_AND_LOW_VOLTAGE_LIMIT) - .setObjectiveDistance(70) + .setObjectiveDistance(0.70) .addVariableTwoWindingsTransformers(network.getTwoWindingsTransformerStream() .limit(1) .map(TwoWindingsTransformer::getId) diff --git a/open-reac/src/test/java/com/powsybl/openreac/parameters/input/json/OpenReacJsonModuleTest.java b/open-reac/src/test/java/com/powsybl/openreac/parameters/input/json/OpenReacJsonModuleTest.java index 26c0c8ca..5caa55de 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/parameters/input/json/OpenReacJsonModuleTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/parameters/input/json/OpenReacJsonModuleTest.java @@ -11,6 +11,7 @@ import com.powsybl.commons.test.ComparisonUtils; import com.powsybl.openreac.parameters.input.OpenReacParameters; import com.powsybl.openreac.parameters.input.VoltageLimitOverride; +import com.powsybl.openreac.parameters.input.algo.OpenReacOptimisationObjective; import org.junit.jupiter.api.Test; import java.io.IOException; @@ -38,13 +39,20 @@ void test() throws IOException { vloList1.add(new VoltageLimitOverride("bar", VoltageLimitOverride.VoltageLimitType.LOW_VOLTAGE_LIMIT, false, 20)); vloList1.add(new VoltageLimitOverride("bar", VoltageLimitOverride.VoltageLimitType.HIGH_VOLTAGE_LIMIT, false, 26)); + // modify open reac parameters parameters.addSpecificVoltageLimits(vloList1); parameters.addConstantQGenerators(List.of("g1", "g2")); parameters.addVariableTwoWindingsTransformers(List.of("tr1")); parameters.addVariableShuntCompensators(List.of("sc1", "sc2")); - parameters.addAlgorithmParam("p1", "v1"); - parameters.addAlgorithmParam("p2", "v2"); - parameters.setObjectiveDistance(5); + parameters.setObjectiveDistance(0.6665); + parameters.setMinPlausibleLowVoltageLimit(0.712); + parameters.setMaxPlausibleHighVoltageLimit(1.2222); + parameters.setAlphaCoefficient(0.56); + parameters.setZeroPowerThreshold(0.5); + parameters.setZeroImpedanceThreshold(1e-5); + parameters.setNominalThresholdIgnoredBuses(10.); + parameters.setNominalThresholdIgnoredVoltageBounds(5.); + String json = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(parameters); ComparisonUtils.compareTxt(Objects.requireNonNull(getClass().getResourceAsStream("/parameters.json")), json); @@ -59,11 +67,15 @@ void test() throws IOException { assertEquals(vloList2, parameters2.getSpecificVoltageLimits()); assertEquals(List.of("g1", "g2"), parameters2.getConstantQGenerators()); assertEquals(List.of("tr1"), parameters2.getVariableTwoWindingsTransformers()); - assertEquals(2, parameters2.getAlgorithmParams().size()); - assertEquals("p1", parameters2.getAlgorithmParams().get(0).getName()); - assertEquals("v1", parameters2.getAlgorithmParams().get(0).getValue()); - assertEquals("p2", parameters2.getAlgorithmParams().get(1).getName()); - assertEquals("v2", parameters2.getAlgorithmParams().get(1).getValue()); - assertEquals(5, parameters2.getObjectiveDistance()); + assertEquals(List.of("sc1", "sc2"), parameters2.getVariableShuntCompensators()); + assertEquals(OpenReacOptimisationObjective.MIN_GENERATION, parameters2.getObjective()); + assertEquals(0.6665, parameters2.getObjectiveDistance()); + assertEquals(0.712, parameters2.getMinPlausibleLowVoltageLimit()); + assertEquals(1.2222, parameters2.getMaxPlausibleHighVoltageLimit()); + assertEquals(0.56, parameters2.getAlphaCoefficient()); + assertEquals(0.5, parameters2.getZeroPowerThreshold()); + assertEquals(1e-5, parameters2.getZeroImpedanceThreshold()); + assertEquals(10., parameters2.getNominalThresholdIgnoredBuses()); + assertEquals(5., parameters2.getNominalThresholdIgnoredVoltageBounds()); } } diff --git a/open-reac/src/test/resources/expected_inputs/param_algo.txt b/open-reac/src/test/resources/expected_inputs/param_algo.txt index 3e2e6a46..032696cb 100644 --- a/open-reac/src/test/resources/expected_inputs/param_algo.txt +++ b/open-reac/src/test/resources/expected_inputs/param_algo.txt @@ -1,3 +1,10 @@ objective_choice 1 ratio_voltage_target 0.7 +min_plausible_low_voltage_limit 0.5 +max_plausible_high_voltage_limit 1.5 +coeff_alpha 1.0 +Pnull 0.01 +Znull 1.0E-4 +epsilon_nominal_voltage 1.0 +ignore_voltage_bounds 0.0 diff --git a/open-reac/src/test/resources/openreac-input-algo-parameters/default.txt b/open-reac/src/test/resources/openreac-input-algo-parameters/default.txt index 745bf608..84e00d9a 100644 --- a/open-reac/src/test/resources/openreac-input-algo-parameters/default.txt +++ b/open-reac/src/test/resources/openreac-input-algo-parameters/default.txt @@ -1,2 +1,10 @@ objective_choice 0 +ratio_voltage_target 0.5 +min_plausible_low_voltage_limit 0.5 +max_plausible_high_voltage_limit 1.5 +coeff_alpha 1.0 +Pnull 0.01 +Znull 1.0E-4 +epsilon_nominal_voltage 1.0 +ignore_voltage_bounds 0.0 diff --git a/open-reac/src/test/resources/openreac-input-algo-parameters/minmax_plausible_voltage_limits.txt b/open-reac/src/test/resources/openreac-input-algo-parameters/minmax_plausible_voltage_limits.txt deleted file mode 100644 index 35e1f7fd..00000000 --- a/open-reac/src/test/resources/openreac-input-algo-parameters/minmax_plausible_voltage_limits.txt +++ /dev/null @@ -1,4 +0,0 @@ -objective_choice 0 -min_plausible_low_voltage_limit 0.7888 -max_plausible_high_voltage_limit 1.3455 - diff --git a/open-reac/src/test/resources/openreac-input-algo-parameters/modified_param_algo.txt b/open-reac/src/test/resources/openreac-input-algo-parameters/modified_param_algo.txt new file mode 100644 index 00000000..5d8a912d --- /dev/null +++ b/open-reac/src/test/resources/openreac-input-algo-parameters/modified_param_algo.txt @@ -0,0 +1,10 @@ +objective_choice 2 +ratio_voltage_target 0.69 +min_plausible_low_voltage_limit 0.7888 +max_plausible_high_voltage_limit 1.3455 +coeff_alpha 0.88 +Pnull 0.45 +Znull 1.0E-5 +epsilon_nominal_voltage 2.0 +ignore_voltage_bounds 0.75 + diff --git a/open-reac/src/test/resources/parameters.json b/open-reac/src/test/resources/parameters.json index 5aee589c..ea21a83d 100644 --- a/open-reac/src/test/resources/parameters.json +++ b/open-reac/src/test/resources/parameters.json @@ -24,13 +24,13 @@ "constantQGenerators" : [ "g1", "g2" ], "variableTwoWindingsTransformers" : [ "tr1" ], "variableShuntCompensators" : [ "sc1", "sc2" ], - "algorithmParams" : [ { - "name" : "p1", - "value" : "v1" - }, { - "name" : "p2", - "value" : "v2" - } ], "objective" : "MIN_GENERATION", - "objectiveDistance" : 5.0 + "objectiveDistance" : 0.6665, + "minPlausibleLowVoltageLimit" : 0.712, + "maxPlausibleHighVoltageLimit" : 1.2222, + "alphaCoefficient" : 0.56, + "zeroPowerThreshold" : 0.5, + "zeroImpedanceThreshold" : 1.0E-5, + "nominalThresholdIgnoredBuses" : 10.0, + "nominalThresholdIgnoredVoltageBounds" : 5.0 } \ No newline at end of file From faebf3bba776c3a862d6983e06dd5b9461770dbb Mon Sep 17 00:00:00 2001 From: parvy Date: Thu, 16 Nov 2023 19:27:04 +0100 Subject: [PATCH 12/26] Improve unit tests. Signed-off-by: parvy --- .../openreac/OpenReacParametersTest.java | 103 ++++++++++++++++-- 1 file changed, 93 insertions(+), 10 deletions(-) diff --git a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java index 105aebb6..76698022 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java @@ -20,11 +20,12 @@ /** * @author Nicolas PIERRE + * @author Pierre ARVY */ public class OpenReacParametersTest { @Test - public void testObjectiveIntegrityChecks() { + public void testObjectiveIntegrity() { Network network = IeeeCdfNetworkFactory.create118(); setDefaultVoltageLimits(network); // set default voltage limits to every voltage levels of the network @@ -35,7 +36,7 @@ public void testObjectiveIntegrityChecks() { assertEquals(OpenReacOptimisationObjective.BETWEEN_HIGH_AND_LOW_VOLTAGE_LIMIT, parameters.getObjective()); parameters.setObjective(OpenReacOptimisationObjective.SPECIFIC_VOLTAGE_PROFILE); assertEquals(OpenReacOptimisationObjective.SPECIFIC_VOLTAGE_PROFILE, parameters.getObjective()); - assertThrows(NullPointerException.class, () -> parameters.setObjective(null), "We can't unset objective function."); + assertThrows(NullPointerException.class, () -> parameters.setObjective(null), "Can't unset objective function."); // Objective distance for BETWEEN_HIGH_AND_LOW_VOLTAGE_LIMIT objective assertEquals(0.5, parameters.getObjectiveDistance()); // default value @@ -43,28 +44,36 @@ public void testObjectiveIntegrityChecks() { assertEquals(0., parameters.getObjectiveDistance()); parameters.setObjectiveDistance(1.); // max value assertEquals(1., parameters.getObjectiveDistance()); - assertThrows(IllegalArgumentException.class, () -> parameters.setObjectiveDistance(-2.)); - assertThrows(IllegalArgumentException.class, () -> parameters.setObjectiveDistance(1.2)); + assertThrows(IllegalArgumentException.class, () -> parameters.setObjectiveDistance(-2.), "Objective distance must be > 0"); + assertThrows(IllegalArgumentException.class, () -> parameters.setObjectiveDistance(1.2), "Objective distance must be < 1"); assertThrows(IllegalArgumentException.class, () -> parameters.setObjectiveDistance(Double.NaN), "Objective distance must be defined."); - assertDoesNotThrow(() -> parameters.checkIntegrity(network)); - parameters.setObjectiveDistance(0.15); + assertTrue(parameters.checkAlgorithmParametersIntegrity()); } @Test - void testMinMaxVoltageLimitIntegrityChecks() { + void testMinMaxVoltageLimitIntegrity() { + Network network = IeeeCdfNetworkFactory.create118(); + setDefaultVoltageLimits(network); // set default voltage limits to every voltage levels of the network + OpenReacParameters parameters = new OpenReacParameters(); // Consistency of min plausible low voltage limit (>= 0) - assertThrows(InvalidParametersException.class, () -> parameters.setMinPlausibleLowVoltageLimit(-0.25)); + assertEquals(0.5, parameters.getMinPlausibleLowVoltageLimit()); // default value + parameters.setMinPlausibleLowVoltageLimit(0.); + assertEquals(0., parameters.getMinPlausibleLowVoltageLimit()); // min value parameters.setMinPlausibleLowVoltageLimit(0.8211); assertEquals(0.8211, parameters.getMinPlausibleLowVoltageLimit()); + assertThrows(InvalidParametersException.class, () -> parameters.setMinPlausibleLowVoltageLimit(-0.25), "minPlausibleLowVoltageLimit must be > 0."); + assertThrows(InvalidParametersException.class, () -> parameters.setMinPlausibleLowVoltageLimit(Double.NaN), "minPlausibleLowVoltageLimit must be defined."); // Consistency of max plausible high voltage limit (> 0) - assertThrows(InvalidParametersException.class, () -> parameters.setMaxPlausibleHighVoltageLimit(-0.15)); - assertThrows(InvalidParametersException.class, () -> parameters.setMaxPlausibleHighVoltageLimit(0)); + assertEquals(1.5, parameters.getMaxPlausibleHighVoltageLimit()); // default value parameters.setMaxPlausibleHighVoltageLimit(0.75); assertEquals(0.75, parameters.getMaxPlausibleHighVoltageLimit()); + assertThrows(InvalidParametersException.class, () -> parameters.setMaxPlausibleHighVoltageLimit(-0.15), "maxPlausibleHighVoltageLimit must be > 0."); + assertThrows(InvalidParametersException.class, () -> parameters.setMaxPlausibleHighVoltageLimit(0), "maxPlausibleHighVoltageLimit must be > 0"); + assertThrows(InvalidParametersException.class, () -> parameters.setMaxPlausibleHighVoltageLimit(Double.NaN), "maxPlausibleHighVoltageLimit must be defined."); // Check min < max assertFalse(parameters.checkAlgorithmParametersIntegrity()); @@ -72,6 +81,80 @@ void testMinMaxVoltageLimitIntegrityChecks() { assertTrue(parameters.checkAlgorithmParametersIntegrity()); } + @Test + void testAlphaCoefficientIntegrity() { + Network network = IeeeCdfNetworkFactory.create118(); + setDefaultVoltageLimits(network); // set default voltage limits to every voltage levels of the network + + OpenReacParameters parameters = new OpenReacParameters(); + assertEquals(1., parameters.getAlphaCoefficient()); // default/max value + parameters.setAlphaCoefficient(0.); // min value + assertEquals(0., parameters.getAlphaCoefficient()); + parameters.setAlphaCoefficient(0.445556); + assertEquals(0.445556, parameters.getAlphaCoefficient()); + + assertThrows(InvalidParametersException.class, () -> parameters.setAlphaCoefficient(-1.2), "alphaCoefficient must be > 0."); + assertThrows(InvalidParametersException.class, () -> parameters.setAlphaCoefficient(42.), "alphaCoefficient must be < 1."); + assertThrows(InvalidParametersException.class, () -> parameters.setAlphaCoefficient(Double.NaN), "alphaCoefficient must be defined."); + assertTrue(parameters.checkAlgorithmParametersIntegrity()); + } + + @Test + void testZeroPowerThresholdIntegrity() { + Network network = IeeeCdfNetworkFactory.create118(); + setDefaultVoltageLimits(network); // set default voltage limits to every voltage levels of the network + + OpenReacParameters parameters = new OpenReacParameters(); + assertEquals(0.01, parameters.getZeroPowerThreshold()); // default value + parameters.setZeroPowerThreshold(0.); + assertEquals(0., parameters.getZeroPowerThreshold()); // min value + parameters.setZeroPowerThreshold(2.365); + assertEquals(2.365, parameters.getZeroPowerThreshold()); + + assertThrows(InvalidParametersException.class, () -> parameters.setZeroPowerThreshold(-1.2), "zeroPowerThreshold must be > 0."); + assertThrows(InvalidParametersException.class, () -> parameters.setZeroPowerThreshold(Double.NaN), "zeroPowerThreshold must be defined."); + assertTrue(parameters.checkAlgorithmParametersIntegrity()); + } + + @Test + void testZeroImpedanceThresholdIntegrity() { + Network network = IeeeCdfNetworkFactory.create118(); + setDefaultVoltageLimits(network); // set default voltage limits to every voltage levels of the network + + OpenReacParameters parameters = new OpenReacParameters(); + assertEquals(1e-4, parameters.getZeroImpedanceThreshold()); // default value + parameters.setZeroImpedanceThreshold(0.); + assertEquals(0., parameters.getZeroImpedanceThreshold()); // min value + parameters.setZeroImpedanceThreshold(1e-5); + assertEquals(1e-5, parameters.getZeroImpedanceThreshold()); + + assertThrows(InvalidParametersException.class, () -> parameters.setZeroImpedanceThreshold(-1.2), "zeroImpedanceThreshold must be > 0."); + assertThrows(InvalidParametersException.class, () -> parameters.setZeroImpedanceThreshold(Double.NaN), "zeroImpedanceThreshold must be defined."); + } + + @Test + void testNominalThresholdsIntegrity() { + Network network = IeeeCdfNetworkFactory.create118(); + setDefaultVoltageLimits(network); // set default voltage limits to every voltage levels of the network + + OpenReacParameters parameters = new OpenReacParameters(); + assertEquals(1., parameters.getNominalThresholdIgnoredBuses()); // default value + parameters.setNominalThresholdIgnoredBuses(0.); // min value + assertEquals(0., parameters.getNominalThresholdIgnoredBuses()); + parameters.setNominalThresholdIgnoredBuses(45.); + assertEquals(45., parameters.getNominalThresholdIgnoredBuses()); + assertThrows(InvalidParametersException.class, () -> parameters.setNominalThresholdIgnoredBuses(-1.2), "nominalThresholdIgnoredBuses must be > 0."); + assertThrows(InvalidParametersException.class, () -> parameters.setNominalThresholdIgnoredBuses(Double.NaN), "nominalThresholdIgnoredBuses must be defined."); + + assertEquals(0., parameters.getNominalThresholdIgnoredVoltageBounds()); // default/min value + parameters.setNominalThresholdIgnoredVoltageBounds(200.); + assertEquals(200., parameters.getNominalThresholdIgnoredVoltageBounds()); + assertThrows(InvalidParametersException.class, () -> parameters.setNominalThresholdIgnoredVoltageBounds(-1.2), "nominalThresholdIgnoredVoltageBounds must be > 0."); + assertThrows(InvalidParametersException.class, () -> parameters.setNominalThresholdIgnoredVoltageBounds(Double.NaN), "nominalThresholdIgnoredVoltageBounds must be defined."); + + assertTrue(parameters.checkAlgorithmParametersIntegrity()); + } + @Test public void testParametersIntegrityChecks() { Network network = IeeeCdfNetworkFactory.create118(); From 7819ec6b69cb2a9ae882b0e3547dd594d25b97b3 Mon Sep 17 00:00:00 2001 From: parvy Date: Thu, 16 Nov 2023 19:34:13 +0100 Subject: [PATCH 13/26] Add last OpenReac parameters in Java. Signed-off-by: parvy --- .../parameters/input/OpenReacParameters.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java index cf8a5b04..42578558 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java @@ -71,6 +71,26 @@ public class OpenReacParameters { private Double nominalThresholdIgnoredVoltageBounds = 0.; // in kV, to ignore voltage bounds of buses with Vnom lower than this value + private static final String PQ_MAX_KEY = "PQmax"; + + private Double PQMax = 9000.; // MW + + private static final String DEFAULT_PMAX_KEY = "defaultPmax"; + + private Double defaultPMax = 1000.; // MW + + private static final String DEFAULT_PMIN_KEY = "defaultPmin"; + + private Double defaultPMin = 0.; // MW + + private static final String DEFAULT_QMAX_PMAX_RATIO_KEY = "defaultQmaxPmaxRatio"; + + private Double defaultQmaxPmaxRatio = 0.3; + + private static final String DEFAULT_MINIMAL_Q_P_RANGE_KEY = "minimalQPrange"; + + private Double defaultMinimalQPRange = 1.; + /** * Override some voltage level limits in the network. This will NOT modify the network object. *

From e4ee12c2afa61880fb7af9bdb40aa28bca7b7f69 Mon Sep 17 00:00:00 2001 From: parvy Date: Fri, 17 Nov 2023 15:07:43 +0100 Subject: [PATCH 14/26] Add methods and unit tests. Signed-off-by: parvy --- .../parameters/input/OpenReacParameters.java | 96 +++++++++++++++++-- .../json/OpenReacParametersDeserializer.java | 20 ++++ .../json/OpenReacParametersSerializer.java | 5 + .../openreac/OpenReacParametersTest.java | 2 +- .../powsybl/openreac/OpenReacRunnerTest.java | 7 +- .../input/json/OpenReacJsonModuleTest.java | 10 ++ .../resources/expected_inputs/param_algo.txt | 5 + .../default.txt | 5 + .../modified_param_algo.txt | 5 + open-reac/src/test/resources/parameters.json | 7 +- 10 files changed, 153 insertions(+), 9 deletions(-) diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java index 42578558..1968e5b8 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java @@ -71,9 +71,9 @@ public class OpenReacParameters { private Double nominalThresholdIgnoredVoltageBounds = 0.; // in kV, to ignore voltage bounds of buses with Vnom lower than this value - private static final String PQ_MAX_KEY = "PQmax"; + private static final String PQMAX_KEY = "PQmax"; - private Double PQMax = 9000.; // MW + private Double pQMax = 9000.; // MW private static final String DEFAULT_PMAX_KEY = "defaultPmax"; @@ -87,7 +87,7 @@ public class OpenReacParameters { private Double defaultQmaxPmaxRatio = 0.3; - private static final String DEFAULT_MINIMAL_Q_P_RANGE_KEY = "minimalQPrange"; + private static final String DEFAULT_MINIMAL_QP_RANGE_KEY = "minimalQPrange"; private Double defaultMinimalQPRange = 1.; @@ -274,6 +274,67 @@ public OpenReacParameters setNominalThresholdIgnoredVoltageBounds(Double nominal return this; } + public Double getPQMax() { + return pQMax; + } + + public OpenReacParameters setPQMax(Double pQMax) { + if (Double.isNaN(pQMax) || pQMax <= 0) { + throw new InvalidParametersException("Maximal consistency value for P and Q must be defined and > 0 to be consistent"); + } + this.pQMax = pQMax; + return this; + } + + public Double getDefaultPMax() { + return defaultPMax; + } + + public OpenReacParameters setDefaultPMax(Double defaultPMax) { + if (Double.isNaN(defaultPMax) || defaultPMax <= 0) { + throw new InvalidParametersException("Default P max value must be defined and > 0 to be consistent."); + } + this.defaultPMax = defaultPMax; + return this; + } + + public Double getDefaultPMin() { + return defaultPMin; + } + + public OpenReacParameters setDefaultPMin(Double defaultPMin) { + if (Double.isNaN(defaultPMin) || defaultPMin < 0) { + throw new InvalidParametersException("Default P min value must be defined and >= 0 to be consistent."); + } + this.defaultPMin = defaultPMin; + return this; + } + + public Double getDefaultQmaxPmaxRatio() { + return defaultQmaxPmaxRatio; + } + + public OpenReacParameters setDefaultQmaxPmaxRatio(Double defaultQmaxPmaxRatio) { + // Qmin/Qmax are computed with this value in OpenReac, can not be zero + if (Double.isNaN(defaultQmaxPmaxRatio) || defaultQmaxPmaxRatio <= 0) { + throw new InvalidParametersException("Default Qmax and Pmax ratio must be defined and > 0 to be consistent."); + } + this.defaultQmaxPmaxRatio = defaultQmaxPmaxRatio; + return this; + } + + public Double getDefaultMinimalQPRange() { + return defaultMinimalQPRange; + } + + public OpenReacParameters setDefaultMinimalQPRange(Double defaultMinimalQPRange) { + if (Double.isNaN(defaultMinimalQPRange) || defaultMinimalQPRange < 0) { + throw new InvalidParametersException("Default minimal QP range must be defined and >= 0 to be consistent."); + } + this.defaultMinimalQPRange = defaultMinimalQPRange; + return this; + } + public List getAllAlgorithmParams() { ArrayList allAlgoParams = new ArrayList<>(); allAlgoParams.add(objective.toParam()); @@ -285,6 +346,11 @@ public List getAllAlgorithmParams() { allAlgoParams.add(new OpenReacAlgoParamImpl(ZERO_IMPEDANCE_THRESHOLD_KEY, Double.toString(zeroImpedanceThreshold))); allAlgoParams.add(new OpenReacAlgoParamImpl(NOMINAL_THRESHOLD_IGNORED_BUS_KEY, Double.toString(nominalThresholdIgnoredBuses))); allAlgoParams.add(new OpenReacAlgoParamImpl(NOMINAL_THRESHOLD_IGNORED_VOLTAGE_BOUNDS_KEY, Double.toString(nominalThresholdIgnoredVoltageBounds))); + allAlgoParams.add(new OpenReacAlgoParamImpl(PQMAX_KEY, Double.toString(pQMax))); + allAlgoParams.add(new OpenReacAlgoParamImpl(DEFAULT_PMIN_KEY, Double.toString(defaultPMin))); + allAlgoParams.add(new OpenReacAlgoParamImpl(DEFAULT_PMAX_KEY, Double.toString(defaultPMax))); + allAlgoParams.add(new OpenReacAlgoParamImpl(DEFAULT_QMAX_PMAX_RATIO_KEY, Double.toString(defaultQmaxPmaxRatio))); + allAlgoParams.add(new OpenReacAlgoParamImpl(DEFAULT_MINIMAL_QP_RANGE_KEY, Double.toString(defaultMinimalQPRange))); return allAlgoParams; } @@ -337,9 +403,27 @@ public boolean checkAlgorithmParametersIntegrity() { boolean integrityAlgorithmParameters = true; // Check integrity of min/max plausible voltage limits - if (minPlausibleLowVoltageLimit != null && maxPlausibleHighVoltageLimit != null - && minPlausibleLowVoltageLimit > maxPlausibleHighVoltageLimit) { - LOGGER.warn("Min plausible low voltage limit must be lower than max plausible high voltage limit."); + if (minPlausibleLowVoltageLimit > maxPlausibleHighVoltageLimit) { + LOGGER.warn("Min plausible low voltage limit = {} must be lower than max plausible high voltage limit = {} to be consistent.", + minPlausibleLowVoltageLimit, maxPlausibleHighVoltageLimit); + integrityAlgorithmParameters = false; + } + + if (defaultPMin > defaultPMax) { + LOGGER.warn("Default P min = {} must be lower than default P max = {} to be consistent.", + defaultPMin, defaultPMax); + integrityAlgorithmParameters = false; + } + + if (defaultPMin > pQMax || defaultPMax > pQMax) { + LOGGER.warn("Default P min = {} and default P max = {} must be lower than PQmax value = {} to be consistent.", + defaultPMin, defaultPMax, pQMax); + integrityAlgorithmParameters = false; + } + + if (defaultPMax * defaultQmaxPmaxRatio > pQMax) { + LOGGER.warn("Default Q max value = {} value must be lower than PQmax value to be consistent.", + defaultPMax * defaultQmaxPmaxRatio); integrityAlgorithmParameters = false; } diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersDeserializer.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersDeserializer.java index 3a7cf2da..3e5d4f8f 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersDeserializer.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersDeserializer.java @@ -91,6 +91,26 @@ public OpenReacParameters deserialize(JsonParser parser, DeserializationContext parser.nextToken(); parameters.setNominalThresholdIgnoredVoltageBounds(parser.getValueAsDouble()); break; + case "pQmax": + parser.nextToken(); + parameters.setPQMax(parser.getValueAsDouble()); + break; + case "defaultPMin": + parser.nextToken(); + parameters.setDefaultPMin(parser.getValueAsDouble()); + break; + case "defaultPMax": + parser.nextToken(); + parameters.setDefaultPMax(parser.getValueAsDouble()); + break; + case "defaultQmaxPmaxRatio": + parser.nextToken(); + parameters.setDefaultQmaxPmaxRatio(parser.getValueAsDouble()); + break; + case "defaultMinimalQPRange": + parser.nextToken(); + parameters.setDefaultMinimalQPRange(parser.getValueAsDouble()); + break; default: throw new IllegalStateException("Unexpected field: " + parser.getCurrentName()); } diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersSerializer.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersSerializer.java index 00cb21b2..2e75b7f0 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersSerializer.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersSerializer.java @@ -43,6 +43,11 @@ public void serialize(OpenReacParameters openReacParameters, JsonGenerator jsonG serializerProvider.defaultSerializeField("zeroImpedanceThreshold", openReacParameters.getZeroImpedanceThreshold(), jsonGenerator); serializerProvider.defaultSerializeField("nominalThresholdIgnoredBuses", openReacParameters.getNominalThresholdIgnoredBuses(), jsonGenerator); serializerProvider.defaultSerializeField("nominalThresholdIgnoredVoltageBounds", openReacParameters.getNominalThresholdIgnoredVoltageBounds(), jsonGenerator); + serializerProvider.defaultSerializeField("pQmax", openReacParameters.getPQMax(), jsonGenerator); + serializerProvider.defaultSerializeField("defaultPMin", openReacParameters.getDefaultPMin(), jsonGenerator); + serializerProvider.defaultSerializeField("defaultPMax", openReacParameters.getDefaultPMax(), jsonGenerator); + serializerProvider.defaultSerializeField("defaultQmaxPmaxRatio", openReacParameters.getDefaultQmaxPmaxRatio(), jsonGenerator); + serializerProvider.defaultSerializeField("defaultMinimalQPRange", openReacParameters.getDefaultMinimalQPRange(), jsonGenerator); jsonGenerator.writeEndObject(); } diff --git a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java index 76698022..c8934e8b 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java @@ -166,7 +166,7 @@ public void testParametersIntegrityChecks() { 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(9, parameters.getAllAlgorithmParams().size()); + assertEquals(14, parameters.getAllAlgorithmParams().size()); // adding an objective, to have a valid OpenReacParameter object parameters.setObjective(OpenReacOptimisationObjective.MIN_GENERATION); diff --git a/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java b/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java index e8b7eab7..cedb39a8 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java @@ -103,7 +103,12 @@ void testParamAlgoExport() throws IOException { .setZeroPowerThreshold(0.45) .setZeroImpedanceThreshold(1e-5) .setNominalThresholdIgnoredBuses(2.) - .setNominalThresholdIgnoredVoltageBounds(0.75); + .setNominalThresholdIgnoredVoltageBounds(0.75) + .setPQMax(3987.76) + .setDefaultPMin(12.32) + .setDefaultPMax(1452.66) + .setDefaultQmaxPmaxRatio(0.24) + .setDefaultMinimalQPRange(2.); LocalCommandExecutor localCommandExecutor = new TestLocalCommandExecutor( List.of("empty_case/reactiveopf_results_indic.txt")); diff --git a/open-reac/src/test/java/com/powsybl/openreac/parameters/input/json/OpenReacJsonModuleTest.java b/open-reac/src/test/java/com/powsybl/openreac/parameters/input/json/OpenReacJsonModuleTest.java index 5caa55de..83c259f6 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/parameters/input/json/OpenReacJsonModuleTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/parameters/input/json/OpenReacJsonModuleTest.java @@ -52,6 +52,11 @@ void test() throws IOException { parameters.setZeroImpedanceThreshold(1e-5); parameters.setNominalThresholdIgnoredBuses(10.); parameters.setNominalThresholdIgnoredVoltageBounds(5.); + parameters.setPQMax(8555.3); + parameters.setDefaultPMin(99.2); + parameters.setDefaultPMax(1144.); + parameters.setDefaultQmaxPmaxRatio(0.4); + parameters.setDefaultMinimalQPRange(1.1); String json = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(parameters); ComparisonUtils.compareTxt(Objects.requireNonNull(getClass().getResourceAsStream("/parameters.json")), json); @@ -77,5 +82,10 @@ void test() throws IOException { assertEquals(1e-5, parameters2.getZeroImpedanceThreshold()); assertEquals(10., parameters2.getNominalThresholdIgnoredBuses()); assertEquals(5., parameters2.getNominalThresholdIgnoredVoltageBounds()); + assertEquals(8555.3, parameters2.getPQMax()); + assertEquals(99.2, parameters2.getDefaultPMin()); + assertEquals(1144., parameters2.getDefaultPMax()); + assertEquals(0.4, parameters2.getDefaultQmaxPmaxRatio()); + assertEquals(1.1, parameters2.getDefaultMinimalQPRange()); } } diff --git a/open-reac/src/test/resources/expected_inputs/param_algo.txt b/open-reac/src/test/resources/expected_inputs/param_algo.txt index 032696cb..f3634222 100644 --- a/open-reac/src/test/resources/expected_inputs/param_algo.txt +++ b/open-reac/src/test/resources/expected_inputs/param_algo.txt @@ -7,4 +7,9 @@ Pnull 0.01 Znull 1.0E-4 epsilon_nominal_voltage 1.0 ignore_voltage_bounds 0.0 +PQmax 9000.0 +defaultPmin 0.0 +defaultPmax 1000.0 +defaultQmaxPmaxRatio 0.3 +minimalQPrange 1.0 diff --git a/open-reac/src/test/resources/openreac-input-algo-parameters/default.txt b/open-reac/src/test/resources/openreac-input-algo-parameters/default.txt index 84e00d9a..4d66adc8 100644 --- a/open-reac/src/test/resources/openreac-input-algo-parameters/default.txt +++ b/open-reac/src/test/resources/openreac-input-algo-parameters/default.txt @@ -7,4 +7,9 @@ Pnull 0.01 Znull 1.0E-4 epsilon_nominal_voltage 1.0 ignore_voltage_bounds 0.0 +PQmax 9000.0 +defaultPmin 0.0 +defaultPmax 1000.0 +defaultQmaxPmaxRatio 0.3 +minimalQPrange 1.0 diff --git a/open-reac/src/test/resources/openreac-input-algo-parameters/modified_param_algo.txt b/open-reac/src/test/resources/openreac-input-algo-parameters/modified_param_algo.txt index 5d8a912d..4575b0c7 100644 --- a/open-reac/src/test/resources/openreac-input-algo-parameters/modified_param_algo.txt +++ b/open-reac/src/test/resources/openreac-input-algo-parameters/modified_param_algo.txt @@ -7,4 +7,9 @@ Pnull 0.45 Znull 1.0E-5 epsilon_nominal_voltage 2.0 ignore_voltage_bounds 0.75 +PQmax 3987.76 +defaultPmin 12.32 +defaultPmax 1452.66 +defaultQmaxPmaxRatio 0.24 +minimalQPrange 2.0 diff --git a/open-reac/src/test/resources/parameters.json b/open-reac/src/test/resources/parameters.json index ea21a83d..7734e488 100644 --- a/open-reac/src/test/resources/parameters.json +++ b/open-reac/src/test/resources/parameters.json @@ -32,5 +32,10 @@ "zeroPowerThreshold" : 0.5, "zeroImpedanceThreshold" : 1.0E-5, "nominalThresholdIgnoredBuses" : 10.0, - "nominalThresholdIgnoredVoltageBounds" : 5.0 + "nominalThresholdIgnoredVoltageBounds" : 5.0, + "pQmax" : 8555.3, + "defaultPMin" : 99.2, + "defaultPMax" : 1144.0, + "defaultQmaxPmaxRatio" : 0.4, + "defaultMinimalQPRange" : 1.1 } \ No newline at end of file From 1e005362f4c60c1a9be6f6aa5c581b28b3c36cdb Mon Sep 17 00:00:00 2001 From: parvy Date: Fri, 17 Nov 2023 15:54:42 +0100 Subject: [PATCH 15/26] Add unit tests and default_param_algo.txt file to OpenReac resources. Signed-off-by: parvy --- .../parameters/input/OpenReacParameters.java | 2 +- .../resources/openreac/default_param_algo.txt | 15 +++ .../openreac/OpenReacParametersTest.java | 103 +++++++++++++----- 3 files changed, 90 insertions(+), 30 deletions(-) create mode 100644 open-reac/src/main/resources/openreac/default_param_algo.txt diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java index 1968e5b8..4c3c8f66 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java @@ -415,7 +415,7 @@ public boolean checkAlgorithmParametersIntegrity() { integrityAlgorithmParameters = false; } - if (defaultPMin > pQMax || defaultPMax > pQMax) { + if (defaultPMax > pQMax) { LOGGER.warn("Default P min = {} and default P max = {} must be lower than PQmax value = {} to be consistent.", defaultPMin, defaultPMax, pQMax); integrityAlgorithmParameters = false; diff --git a/open-reac/src/main/resources/openreac/default_param_algo.txt b/open-reac/src/main/resources/openreac/default_param_algo.txt new file mode 100644 index 00000000..f3634222 --- /dev/null +++ b/open-reac/src/main/resources/openreac/default_param_algo.txt @@ -0,0 +1,15 @@ +objective_choice 1 +ratio_voltage_target 0.7 +min_plausible_low_voltage_limit 0.5 +max_plausible_high_voltage_limit 1.5 +coeff_alpha 1.0 +Pnull 0.01 +Znull 1.0E-4 +epsilon_nominal_voltage 1.0 +ignore_voltage_bounds 0.0 +PQmax 9000.0 +defaultPmin 0.0 +defaultPmax 1000.0 +defaultQmaxPmaxRatio 0.3 +minimalQPrange 1.0 + diff --git a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java index c8934e8b..704b9369 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java @@ -25,13 +25,9 @@ public class OpenReacParametersTest { @Test - public void testObjectiveIntegrity() { - Network network = IeeeCdfNetworkFactory.create118(); - setDefaultVoltageLimits(network); // set default voltage limits to every voltage levels of the network - + void testObjectiveIntegrity() { // Objective choice OpenReacParameters parameters = new OpenReacParameters(); - assertEquals(OpenReacOptimisationObjective.MIN_GENERATION, parameters.getObjective()); parameters.setObjective(OpenReacOptimisationObjective.BETWEEN_HIGH_AND_LOW_VOLTAGE_LIMIT); assertEquals(OpenReacOptimisationObjective.BETWEEN_HIGH_AND_LOW_VOLTAGE_LIMIT, parameters.getObjective()); parameters.setObjective(OpenReacOptimisationObjective.SPECIFIC_VOLTAGE_PROFILE); @@ -39,7 +35,6 @@ public void testObjectiveIntegrity() { assertThrows(NullPointerException.class, () -> parameters.setObjective(null), "Can't unset objective function."); // Objective distance for BETWEEN_HIGH_AND_LOW_VOLTAGE_LIMIT objective - assertEquals(0.5, parameters.getObjectiveDistance()); // default value parameters.setObjectiveDistance(0.); // min value assertEquals(0., parameters.getObjectiveDistance()); parameters.setObjectiveDistance(1.); // max value @@ -53,13 +48,9 @@ public void testObjectiveIntegrity() { @Test void testMinMaxVoltageLimitIntegrity() { - Network network = IeeeCdfNetworkFactory.create118(); - setDefaultVoltageLimits(network); // set default voltage limits to every voltage levels of the network - OpenReacParameters parameters = new OpenReacParameters(); // Consistency of min plausible low voltage limit (>= 0) - assertEquals(0.5, parameters.getMinPlausibleLowVoltageLimit()); // default value parameters.setMinPlausibleLowVoltageLimit(0.); assertEquals(0., parameters.getMinPlausibleLowVoltageLimit()); // min value parameters.setMinPlausibleLowVoltageLimit(0.8211); @@ -68,7 +59,6 @@ void testMinMaxVoltageLimitIntegrity() { assertThrows(InvalidParametersException.class, () -> parameters.setMinPlausibleLowVoltageLimit(Double.NaN), "minPlausibleLowVoltageLimit must be defined."); // Consistency of max plausible high voltage limit (> 0) - assertEquals(1.5, parameters.getMaxPlausibleHighVoltageLimit()); // default value parameters.setMaxPlausibleHighVoltageLimit(0.75); assertEquals(0.75, parameters.getMaxPlausibleHighVoltageLimit()); assertThrows(InvalidParametersException.class, () -> parameters.setMaxPlausibleHighVoltageLimit(-0.15), "maxPlausibleHighVoltageLimit must be > 0."); @@ -83,11 +73,7 @@ void testMinMaxVoltageLimitIntegrity() { @Test void testAlphaCoefficientIntegrity() { - Network network = IeeeCdfNetworkFactory.create118(); - setDefaultVoltageLimits(network); // set default voltage limits to every voltage levels of the network - OpenReacParameters parameters = new OpenReacParameters(); - assertEquals(1., parameters.getAlphaCoefficient()); // default/max value parameters.setAlphaCoefficient(0.); // min value assertEquals(0., parameters.getAlphaCoefficient()); parameters.setAlphaCoefficient(0.445556); @@ -101,11 +87,7 @@ void testAlphaCoefficientIntegrity() { @Test void testZeroPowerThresholdIntegrity() { - Network network = IeeeCdfNetworkFactory.create118(); - setDefaultVoltageLimits(network); // set default voltage limits to every voltage levels of the network - OpenReacParameters parameters = new OpenReacParameters(); - assertEquals(0.01, parameters.getZeroPowerThreshold()); // default value parameters.setZeroPowerThreshold(0.); assertEquals(0., parameters.getZeroPowerThreshold()); // min value parameters.setZeroPowerThreshold(2.365); @@ -118,11 +100,7 @@ void testZeroPowerThresholdIntegrity() { @Test void testZeroImpedanceThresholdIntegrity() { - Network network = IeeeCdfNetworkFactory.create118(); - setDefaultVoltageLimits(network); // set default voltage limits to every voltage levels of the network - OpenReacParameters parameters = new OpenReacParameters(); - assertEquals(1e-4, parameters.getZeroImpedanceThreshold()); // default value parameters.setZeroImpedanceThreshold(0.); assertEquals(0., parameters.getZeroImpedanceThreshold()); // min value parameters.setZeroImpedanceThreshold(1e-5); @@ -134,11 +112,7 @@ void testZeroImpedanceThresholdIntegrity() { @Test void testNominalThresholdsIntegrity() { - Network network = IeeeCdfNetworkFactory.create118(); - setDefaultVoltageLimits(network); // set default voltage limits to every voltage levels of the network - OpenReacParameters parameters = new OpenReacParameters(); - assertEquals(1., parameters.getNominalThresholdIgnoredBuses()); // default value parameters.setNominalThresholdIgnoredBuses(0.); // min value assertEquals(0., parameters.getNominalThresholdIgnoredBuses()); parameters.setNominalThresholdIgnoredBuses(45.); @@ -146,7 +120,6 @@ void testNominalThresholdsIntegrity() { assertThrows(InvalidParametersException.class, () -> parameters.setNominalThresholdIgnoredBuses(-1.2), "nominalThresholdIgnoredBuses must be > 0."); assertThrows(InvalidParametersException.class, () -> parameters.setNominalThresholdIgnoredBuses(Double.NaN), "nominalThresholdIgnoredBuses must be defined."); - assertEquals(0., parameters.getNominalThresholdIgnoredVoltageBounds()); // default/min value parameters.setNominalThresholdIgnoredVoltageBounds(200.); assertEquals(200., parameters.getNominalThresholdIgnoredVoltageBounds()); assertThrows(InvalidParametersException.class, () -> parameters.setNominalThresholdIgnoredVoltageBounds(-1.2), "nominalThresholdIgnoredVoltageBounds must be > 0."); @@ -156,7 +129,79 @@ void testNominalThresholdsIntegrity() { } @Test - public void testParametersIntegrityChecks() { + void testPMinMaxIntegrity() { + OpenReacParameters parameters = new OpenReacParameters(); + parameters.setPQMax(5775.); + assertEquals(5775., parameters.getPQMax()); + assertThrows(InvalidParametersException.class, () -> parameters.setPQMax(0.), "pQmax must be > 0."); // min value + assertThrows(InvalidParametersException.class, () -> parameters.setPQMax(-2.1), "pQmax must be > 0."); + assertThrows(InvalidParametersException.class, () -> parameters.setPQMax(Double.NaN)); + + parameters.setDefaultPMin(1500.); + assertEquals(1500., parameters.getDefaultPMin()); + assertThrows(InvalidParametersException.class, () -> parameters.setDefaultPMin(-100.), "defaultPmin must be >= 0"); + assertThrows(InvalidParametersException.class, () -> parameters.setDefaultPMin(Double.NaN)); + + parameters.setDefaultPMax(1250.); + assertEquals(1250., parameters.getDefaultPMax()); + assertThrows(InvalidParametersException.class, () -> parameters.setDefaultPMax(0.), "defaultPmax must be > 0."); + assertThrows(InvalidParametersException.class, () -> parameters.setDefaultPMax(-100.), "defaultPmax must be > 0."); + assertThrows(InvalidParametersException.class, () -> parameters.setDefaultPMax(Double.NaN)); + + assertFalse(parameters.checkAlgorithmParametersIntegrity()); // case defaultPmin > defaultPmax + parameters.setDefaultPMax(10000.); + assertFalse(parameters.checkAlgorithmParametersIntegrity()); // case defaultPmax > pQmax + parameters.setDefaultPMin(50.).setDefaultPMax(1000.); + assertTrue(parameters.checkAlgorithmParametersIntegrity()); + } + + @Test + void testDefaultQmaxPmaxRatioIntegrity() { + OpenReacParameters parameters = new OpenReacParameters(); + parameters.setDefaultQmaxPmaxRatio(0.778); + assertEquals(0.778, parameters.getDefaultQmaxPmaxRatio()); + assertThrows(InvalidParametersException.class, () -> parameters.setDefaultQmaxPmaxRatio(0.), "defaultQmaxPmaxRatio must be > 0"); + assertThrows(InvalidParametersException.class, () -> parameters.setDefaultQmaxPmaxRatio(-0.3), "defaultQmaxPmaxRatio must be > 0."); + assertThrows(InvalidParametersException.class, () -> parameters.setDefaultQmaxPmaxRatio(Double.NaN), "defaultQmaxPmaxRatio must be defined."); + + parameters.setDefaultQmaxPmaxRatio(500.); + assertFalse(parameters.checkAlgorithmParametersIntegrity()); + } + + @Test + void testDefault() { + OpenReacParameters parameters = new OpenReacParameters(); + parameters.setDefaultMinimalQPRange(10.); + assertEquals(10., parameters.getDefaultMinimalQPRange()); + parameters.setDefaultMinimalQPRange(0.); + assertEquals(0., parameters.getDefaultMinimalQPRange()); + + assertThrows(InvalidParametersException.class, () -> parameters.setDefaultMinimalQPRange(-1.5)); + assertThrows(InvalidParametersException.class, () -> parameters.setDefaultMinimalQPRange(Double.NaN)); + } + + @Test + void testDefaultValuesIntegrity() { + OpenReacParameters parameters = new OpenReacParameters(); + assertEquals(OpenReacOptimisationObjective.MIN_GENERATION, parameters.getObjective()); + assertEquals(0.5, parameters.getObjectiveDistance()); + assertEquals(0.5, parameters.getMinPlausibleLowVoltageLimit()); + assertEquals(1.5, parameters.getMaxPlausibleHighVoltageLimit()); + assertEquals(1., parameters.getAlphaCoefficient()); + assertEquals(0.01, parameters.getZeroPowerThreshold()); + assertEquals(1e-4, parameters.getZeroImpedanceThreshold()); + assertEquals(1., parameters.getNominalThresholdIgnoredBuses()); + assertEquals(0., parameters.getNominalThresholdIgnoredVoltageBounds()); + assertEquals(9000., parameters.getPQMax()); + assertEquals(0, parameters.getDefaultPMin()); + assertEquals(1000., parameters.getDefaultPMax()); + assertEquals(0.3, parameters.getDefaultQmaxPmaxRatio()); + assertEquals(1., parameters.getDefaultMinimalQPRange()); + assertTrue(parameters.checkAlgorithmParametersIntegrity()); + } + + @Test + void testParametersIntegrityChecks() { Network network = IeeeCdfNetworkFactory.create118(); setDefaultVoltageLimits(network); // set default voltage limits to every voltage levels of the network String wrongId = "An id not in 118 cdf network."; From 28fe3f288b75a3c6c8be9760e28f1d8b58f8f919 Mon Sep 17 00:00:00 2001 From: parvy Date: Mon, 20 Nov 2023 10:11:38 +0100 Subject: [PATCH 16/26] Refactor. Signed-off-by: parvy --- .../test/java/com/powsybl/openreac/OpenReacParametersTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java index 704b9369..a49ec2aa 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java @@ -169,7 +169,7 @@ void testDefaultQmaxPmaxRatioIntegrity() { } @Test - void testDefault() { + void testDefaultMinimalQPRangeIntegrity() { OpenReacParameters parameters = new OpenReacParameters(); parameters.setDefaultMinimalQPRange(10.); assertEquals(10., parameters.getDefaultMinimalQPRange()); From 54210a89fcf8f3af920c43c87b9564e5674fa227 Mon Sep 17 00:00:00 2001 From: parvy Date: Tue, 28 Nov 2023 18:48:30 +0100 Subject: [PATCH 17/26] Refactor TU. Signed-off-by: parvy --- .../parameters/input/OpenReacParameters.java | 61 ++++++++++--------- .../openreac/OpenReacParametersTest.java | 24 +++++++- 2 files changed, 53 insertions(+), 32 deletions(-) diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java index 5aa6a9cd..f6c2d246 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java @@ -60,43 +60,43 @@ public class OpenReacParameters { private static final String ALPHA_COEFFICIENT_KEY = "coeff_alpha"; - private Double alphaCoefficient = 1.; // in [0;1] + private double alphaCoefficient = 1.; // in [0;1] private static final String ZERO_POWER_THRESHOLD_KEY = "Pnull"; - private Double zeroPowerThreshold = 0.01; // in MW, for detecting zero value for power + private double zeroPowerThreshold = 0.01; // in MW, for detecting zero value for power private static final String ZERO_IMPEDANCE_THRESHOLD_KEY = "Znull"; - private Double zeroImpedanceThreshold = 1e-4; // in p.u., for detecting null impedance branches + private double zeroImpedanceThreshold = 1e-4; // in p.u., for detecting null impedance branches private static final String NOMINAL_THRESHOLD_IGNORED_BUS_KEY = "epsilon_nominal_voltage"; - private Double nominalThresholdIgnoredBuses = 1.; // in kV, to ignore buses with Vnom lower than this value + private double nominalThresholdIgnoredBuses = 1.; // in kV, to ignore buses with Vnom lower than this value private static final String NOMINAL_THRESHOLD_IGNORED_VOLTAGE_BOUNDS_KEY = "ignore_voltage_bounds"; - private Double nominalThresholdIgnoredVoltageBounds = 0.; // in kV, to ignore voltage bounds of buses with Vnom lower than this value + private double nominalThresholdIgnoredVoltageBounds = 0.; // in kV, to ignore voltage bounds of buses with Vnom lower than this value private static final String PQMAX_KEY = "PQmax"; - private Double pQMax = 9000.; // MW + private double pQMax = 9000.; // MW private static final String DEFAULT_PMAX_KEY = "defaultPmax"; - private Double defaultPMax = 1000.; // MW + private double defaultPMax = 1000.; // MW private static final String DEFAULT_PMIN_KEY = "defaultPmin"; - private Double defaultPMin = 0.; // MW + private double defaultPMin = 0.; // MW private static final String DEFAULT_QMAX_PMAX_RATIO_KEY = "defaultQmaxPmaxRatio"; - private Double defaultQmaxPmaxRatio = 0.3; + private double defaultQmaxPmaxRatio = 0.3; private static final String DEFAULT_MINIMAL_QP_RANGE_KEY = "minimalQPrange"; - private Double defaultMinimalQPRange = 1.; + private double defaultMinimalQPRange = 1.; /** * Override some voltage level limits in the network. This will NOT modify the network object. @@ -202,6 +202,7 @@ public OpenReacParameters setObjectiveDistance(double objectiveDistance) { this.objectiveDistance = objectiveDistance; return this; } + /** * @return log level of ampl printings. */ @@ -275,11 +276,11 @@ public OpenReacParameters setReactiveSlackBusesMode(ReactiveSlackBusesMode react return this; } - public Double getAlphaCoefficient() { + public double getAlphaCoefficient() { return alphaCoefficient; } - public OpenReacParameters setAlphaCoefficient(Double alphaCoefficient) { + public OpenReacParameters setAlphaCoefficient(double alphaCoefficient) { if (Double.isNaN(alphaCoefficient) || alphaCoefficient < 0 || alphaCoefficient > 1) { throw new InvalidParametersException("Coefficient alpha parameter must be defined and between 0 and 1 to be consistent."); } @@ -287,11 +288,11 @@ public OpenReacParameters setAlphaCoefficient(Double alphaCoefficient) { return this; } - public Double getZeroPowerThreshold() { + public double getZeroPowerThreshold() { return zeroPowerThreshold; } - public OpenReacParameters setZeroPowerThreshold(Double zeroPowerThreshold) { + public OpenReacParameters setZeroPowerThreshold(double zeroPowerThreshold) { if (Double.isNaN(zeroPowerThreshold) || zeroPowerThreshold < 0) { throw new InvalidParametersException("Zero power threshold must be defined and >= 0 to be consistent."); } @@ -299,11 +300,11 @@ public OpenReacParameters setZeroPowerThreshold(Double zeroPowerThreshold) { return this; } - public Double getZeroImpedanceThreshold() { + public double getZeroImpedanceThreshold() { return zeroImpedanceThreshold; } - public OpenReacParameters setZeroImpedanceThreshold(Double zeroImpedanceThreshold) { + public OpenReacParameters setZeroImpedanceThreshold(double zeroImpedanceThreshold) { if (Double.isNaN(zeroImpedanceThreshold) || zeroImpedanceThreshold < 0) { throw new InvalidParametersException("Zero impedance threshold must be defined and >= 0 to be consistent."); } @@ -311,11 +312,11 @@ public OpenReacParameters setZeroImpedanceThreshold(Double zeroImpedanceThreshol return this; } - public Double getNominalThresholdIgnoredBuses() { + public double getNominalThresholdIgnoredBuses() { return nominalThresholdIgnoredBuses; } - public OpenReacParameters setNominalThresholdIgnoredBuses(Double nominalThresholdIgnoredBuses) { + public OpenReacParameters setNominalThresholdIgnoredBuses(double nominalThresholdIgnoredBuses) { if (Double.isNaN(nominalThresholdIgnoredBuses) || nominalThresholdIgnoredBuses < 0) { throw new InvalidParametersException("Nominal threshold for ignored buses must be defined and >= 0 to be consistent."); } @@ -323,11 +324,11 @@ public OpenReacParameters setNominalThresholdIgnoredBuses(Double nominalThreshol return this; } - public Double getNominalThresholdIgnoredVoltageBounds() { + public double getNominalThresholdIgnoredVoltageBounds() { return nominalThresholdIgnoredVoltageBounds; } - public OpenReacParameters setNominalThresholdIgnoredVoltageBounds(Double nominalThresholdIgnoredVoltageBounds) { + public OpenReacParameters setNominalThresholdIgnoredVoltageBounds(double nominalThresholdIgnoredVoltageBounds) { if (Double.isNaN(nominalThresholdIgnoredVoltageBounds) || nominalThresholdIgnoredVoltageBounds < 0) { throw new InvalidParametersException("Nominal threshold for ignored voltage bounds must be defined and >= 0 to be consistent"); } @@ -335,11 +336,11 @@ public OpenReacParameters setNominalThresholdIgnoredVoltageBounds(Double nominal return this; } - public Double getPQMax() { + public double getPQMax() { return pQMax; } - public OpenReacParameters setPQMax(Double pQMax) { + public OpenReacParameters setPQMax(double pQMax) { if (Double.isNaN(pQMax) || pQMax <= 0) { throw new InvalidParametersException("Maximal consistency value for P and Q must be defined and > 0 to be consistent"); } @@ -347,11 +348,11 @@ public OpenReacParameters setPQMax(Double pQMax) { return this; } - public Double getDefaultPMax() { + public double getDefaultPMax() { return defaultPMax; } - public OpenReacParameters setDefaultPMax(Double defaultPMax) { + public OpenReacParameters setDefaultPMax(double defaultPMax) { if (Double.isNaN(defaultPMax) || defaultPMax <= 0) { throw new InvalidParametersException("Default P max value must be defined and > 0 to be consistent."); } @@ -359,11 +360,11 @@ public OpenReacParameters setDefaultPMax(Double defaultPMax) { return this; } - public Double getDefaultPMin() { + public double getDefaultPMin() { return defaultPMin; } - public OpenReacParameters setDefaultPMin(Double defaultPMin) { + public OpenReacParameters setDefaultPMin(double defaultPMin) { if (Double.isNaN(defaultPMin) || defaultPMin < 0) { throw new InvalidParametersException("Default P min value must be defined and >= 0 to be consistent."); } @@ -371,11 +372,11 @@ public OpenReacParameters setDefaultPMin(Double defaultPMin) { return this; } - public Double getDefaultQmaxPmaxRatio() { + public double getDefaultQmaxPmaxRatio() { return defaultQmaxPmaxRatio; } - public OpenReacParameters setDefaultQmaxPmaxRatio(Double defaultQmaxPmaxRatio) { + public OpenReacParameters setDefaultQmaxPmaxRatio(double defaultQmaxPmaxRatio) { // Qmin/Qmax are computed with this value in OpenReac, can not be zero if (Double.isNaN(defaultQmaxPmaxRatio) || defaultQmaxPmaxRatio <= 0) { throw new InvalidParametersException("Default Qmax and Pmax ratio must be defined and > 0 to be consistent."); @@ -384,11 +385,11 @@ public OpenReacParameters setDefaultQmaxPmaxRatio(Double defaultQmaxPmaxRatio) { return this; } - public Double getDefaultMinimalQPRange() { + public double getDefaultMinimalQPRange() { return defaultMinimalQPRange; } - public OpenReacParameters setDefaultMinimalQPRange(Double defaultMinimalQPRange) { + public OpenReacParameters setDefaultMinimalQPRange(double defaultMinimalQPRange) { if (Double.isNaN(defaultMinimalQPRange) || defaultMinimalQPRange < 0) { throw new InvalidParametersException("Default minimal QP range must be defined and >= 0 to be consistent."); } diff --git a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java index 7bbff24d..63de2ce8 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java @@ -234,9 +234,19 @@ void testAlgorithmParams() { parameters.setMinPlausibleLowVoltageLimit(0.8); parameters.setMaxPlausibleHighVoltageLimit(1.2); parameters.setReactiveSlackBusesMode(ReactiveSlackBusesMode.ALL); + parameters.setAlphaCoefficient(0.56); + parameters.setZeroPowerThreshold(0.5); + parameters.setZeroImpedanceThreshold(1e-5); + parameters.setNominalThresholdIgnoredBuses(10); + parameters.setNominalThresholdIgnoredVoltageBounds(5); + parameters.setPQMax(8555.3); + parameters.setDefaultPMin(99.2); + parameters.setDefaultPMax(1144); + parameters.setDefaultQmaxPmaxRatio(0.4); + parameters.setDefaultMinimalQPRange(1.1); List algoParams = parameters.getAllAlgorithmParams(); - assertEquals(7, algoParams.size()); + assertEquals(17, algoParams.size()); assertEquals("2", algoParams.get(0).getValue()); assertEquals("0.4", algoParams.get(1).getValue()); assertEquals("DEBUG", algoParams.get(2).getValue()); @@ -244,6 +254,16 @@ void testAlgorithmParams() { assertEquals("0.8", algoParams.get(4).getValue()); assertEquals("1.2", algoParams.get(5).getValue()); assertEquals("ALL", algoParams.get(6).getValue()); + assertEquals("0.56", algoParams.get(7).getValue()); + assertEquals("0.5", algoParams.get(8).getValue()); + assertEquals("1.0E-5", algoParams.get(9).getValue()); + assertEquals("10.0", algoParams.get(10).getValue()); + assertEquals("5.0", algoParams.get(11).getValue()); + assertEquals("8555.3", algoParams.get(12).getValue()); + assertEquals("99.2", algoParams.get(13).getValue()); + assertEquals("1144.0", algoParams.get(14).getValue()); + assertEquals("0.4", algoParams.get(15).getValue()); + assertEquals("1.1", algoParams.get(16).getValue()); } @Test @@ -269,7 +289,7 @@ void testDefaultListsOfParametersIntegrity() { 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.getConfiguredReactiveSlackBuses().size(), "ConfiguredReactiveSlackBuses should be empty when using default OpenREacParameter constructor."); - assertEquals(6, parameters.getAllAlgorithmParams().size()); + assertEquals(16, parameters.getAllAlgorithmParams().size()); } @Test From e330673a59a3f408cf6e0d738f303a95ecb5ca78 Mon Sep 17 00:00:00 2001 From: parvy Date: Wed, 29 Nov 2023 16:46:54 +0100 Subject: [PATCH 18/26] Refactor. Signed-off-by: parvy --- .../parameters/input/OpenReacParameters.java | 20 +-- .../openreac/OpenReacParametersTest.java | 151 ++++++++++++------ 2 files changed, 109 insertions(+), 62 deletions(-) diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java index f6c2d246..42fe2315 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java @@ -282,7 +282,7 @@ public double getAlphaCoefficient() { public OpenReacParameters setAlphaCoefficient(double alphaCoefficient) { if (Double.isNaN(alphaCoefficient) || alphaCoefficient < 0 || alphaCoefficient > 1) { - throw new InvalidParametersException("Coefficient alpha parameter must be defined and between 0 and 1 to be consistent."); + throw new IllegalArgumentException("Coefficient alpha parameter must be defined and between 0 and 1 to be consistent."); } this.alphaCoefficient = alphaCoefficient; return this; @@ -294,7 +294,7 @@ public double getZeroPowerThreshold() { public OpenReacParameters setZeroPowerThreshold(double zeroPowerThreshold) { if (Double.isNaN(zeroPowerThreshold) || zeroPowerThreshold < 0) { - throw new InvalidParametersException("Zero power threshold must be defined and >= 0 to be consistent."); + throw new IllegalArgumentException("Zero power threshold must be defined and >= 0 to be consistent."); } this.zeroPowerThreshold = zeroPowerThreshold; return this; @@ -306,7 +306,7 @@ public double getZeroImpedanceThreshold() { public OpenReacParameters setZeroImpedanceThreshold(double zeroImpedanceThreshold) { if (Double.isNaN(zeroImpedanceThreshold) || zeroImpedanceThreshold < 0) { - throw new InvalidParametersException("Zero impedance threshold must be defined and >= 0 to be consistent."); + throw new IllegalArgumentException("Zero impedance threshold must be defined and >= 0 to be consistent."); } this.zeroImpedanceThreshold = zeroImpedanceThreshold; return this; @@ -318,7 +318,7 @@ public double getNominalThresholdIgnoredBuses() { public OpenReacParameters setNominalThresholdIgnoredBuses(double nominalThresholdIgnoredBuses) { if (Double.isNaN(nominalThresholdIgnoredBuses) || nominalThresholdIgnoredBuses < 0) { - throw new InvalidParametersException("Nominal threshold for ignored buses must be defined and >= 0 to be consistent."); + throw new IllegalArgumentException("Nominal threshold for ignored buses must be defined and >= 0 to be consistent."); } this.nominalThresholdIgnoredBuses = nominalThresholdIgnoredBuses; return this; @@ -330,7 +330,7 @@ public double getNominalThresholdIgnoredVoltageBounds() { public OpenReacParameters setNominalThresholdIgnoredVoltageBounds(double nominalThresholdIgnoredVoltageBounds) { if (Double.isNaN(nominalThresholdIgnoredVoltageBounds) || nominalThresholdIgnoredVoltageBounds < 0) { - throw new InvalidParametersException("Nominal threshold for ignored voltage bounds must be defined and >= 0 to be consistent"); + throw new IllegalArgumentException("Nominal threshold for ignored voltage bounds must be defined and >= 0 to be consistent"); } this.nominalThresholdIgnoredVoltageBounds = nominalThresholdIgnoredVoltageBounds; return this; @@ -342,7 +342,7 @@ public double getPQMax() { public OpenReacParameters setPQMax(double pQMax) { if (Double.isNaN(pQMax) || pQMax <= 0) { - throw new InvalidParametersException("Maximal consistency value for P and Q must be defined and > 0 to be consistent"); + throw new IllegalArgumentException("Maximal consistency value for P and Q must be defined and > 0 to be consistent"); } this.pQMax = pQMax; return this; @@ -354,7 +354,7 @@ public double getDefaultPMax() { public OpenReacParameters setDefaultPMax(double defaultPMax) { if (Double.isNaN(defaultPMax) || defaultPMax <= 0) { - throw new InvalidParametersException("Default P max value must be defined and > 0 to be consistent."); + throw new IllegalArgumentException("Default P max value must be defined and > 0 to be consistent."); } this.defaultPMax = defaultPMax; return this; @@ -366,7 +366,7 @@ public double getDefaultPMin() { public OpenReacParameters setDefaultPMin(double defaultPMin) { if (Double.isNaN(defaultPMin) || defaultPMin < 0) { - throw new InvalidParametersException("Default P min value must be defined and >= 0 to be consistent."); + throw new IllegalArgumentException("Default P min value must be defined and >= 0 to be consistent."); } this.defaultPMin = defaultPMin; return this; @@ -379,7 +379,7 @@ public double getDefaultQmaxPmaxRatio() { public OpenReacParameters setDefaultQmaxPmaxRatio(double defaultQmaxPmaxRatio) { // Qmin/Qmax are computed with this value in OpenReac, can not be zero if (Double.isNaN(defaultQmaxPmaxRatio) || defaultQmaxPmaxRatio <= 0) { - throw new InvalidParametersException("Default Qmax and Pmax ratio must be defined and > 0 to be consistent."); + throw new IllegalArgumentException("Default Qmax and Pmax ratio must be defined and > 0 to be consistent."); } this.defaultQmaxPmaxRatio = defaultQmaxPmaxRatio; return this; @@ -391,7 +391,7 @@ public double getDefaultMinimalQPRange() { public OpenReacParameters setDefaultMinimalQPRange(double defaultMinimalQPRange) { if (Double.isNaN(defaultMinimalQPRange) || defaultMinimalQPRange < 0) { - throw new InvalidParametersException("Default minimal QP range must be defined and >= 0 to be consistent."); + throw new IllegalArgumentException("Default minimal QP range must be defined and >= 0 to be consistent."); } this.defaultMinimalQPRange = defaultMinimalQPRange; return this; diff --git a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java index 63de2ce8..c9b5ff0d 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java @@ -118,56 +118,67 @@ void testMinMaxVoltageLimitIntegrity() { @Test void testAlphaCoefficientIntegrity() { OpenReacParameters parameters = new OpenReacParameters(); - parameters.setAlphaCoefficient(0.); // min value + parameters.setAlphaCoefficient(0); // min value assertEquals(0., parameters.getAlphaCoefficient()); parameters.setAlphaCoefficient(0.445556); assertEquals(0.445556, parameters.getAlphaCoefficient()); - assertThrows(InvalidParametersException.class, () -> parameters.setAlphaCoefficient(-1.2), "alphaCoefficient must be > 0."); - assertThrows(InvalidParametersException.class, () -> parameters.setAlphaCoefficient(42.), "alphaCoefficient must be < 1."); - assertThrows(InvalidParametersException.class, () -> parameters.setAlphaCoefficient(Double.NaN), "alphaCoefficient must be defined."); + IllegalArgumentException e1 = assertThrows(IllegalArgumentException.class, () -> parameters.setAlphaCoefficient(-1.2)); + assertEquals("Coefficient alpha parameter must be defined and between 0 and 1 to be consistent.", e1.getMessage()); + IllegalArgumentException e2 = assertThrows(IllegalArgumentException.class, () -> parameters.setAlphaCoefficient(42)); + assertEquals("Coefficient alpha parameter must be defined and between 0 and 1 to be consistent.", e2.getMessage()); + IllegalArgumentException e3 = assertThrows(IllegalArgumentException.class, () -> parameters.setAlphaCoefficient(Double.NaN)); + assertEquals("Coefficient alpha parameter must be defined and between 0 and 1 to be consistent.", e3.getMessage()); assertTrue(parameters.checkAlgorithmParametersIntegrity()); } @Test void testZeroPowerThresholdIntegrity() { OpenReacParameters parameters = new OpenReacParameters(); - parameters.setZeroPowerThreshold(0.); + parameters.setZeroPowerThreshold(0); assertEquals(0., parameters.getZeroPowerThreshold()); // min value parameters.setZeroPowerThreshold(2.365); assertEquals(2.365, parameters.getZeroPowerThreshold()); - assertThrows(InvalidParametersException.class, () -> parameters.setZeroPowerThreshold(-1.2), "zeroPowerThreshold must be > 0."); - assertThrows(InvalidParametersException.class, () -> parameters.setZeroPowerThreshold(Double.NaN), "zeroPowerThreshold must be defined."); + IllegalArgumentException e1 = assertThrows(IllegalArgumentException.class, () -> parameters.setZeroPowerThreshold(-1.2)); + assertEquals("Zero power threshold must be defined and >= 0 to be consistent.", e1.getMessage()); + IllegalArgumentException e2 = assertThrows(IllegalArgumentException.class, () -> parameters.setZeroPowerThreshold(Double.NaN)); + assertEquals("Zero power threshold must be defined and >= 0 to be consistent.", e2.getMessage()); assertTrue(parameters.checkAlgorithmParametersIntegrity()); } @Test void testZeroImpedanceThresholdIntegrity() { OpenReacParameters parameters = new OpenReacParameters(); - parameters.setZeroImpedanceThreshold(0.); + parameters.setZeroImpedanceThreshold(0); assertEquals(0., parameters.getZeroImpedanceThreshold()); // min value parameters.setZeroImpedanceThreshold(1e-5); assertEquals(1e-5, parameters.getZeroImpedanceThreshold()); - assertThrows(InvalidParametersException.class, () -> parameters.setZeroImpedanceThreshold(-1.2), "zeroImpedanceThreshold must be > 0."); - assertThrows(InvalidParametersException.class, () -> parameters.setZeroImpedanceThreshold(Double.NaN), "zeroImpedanceThreshold must be defined."); + IllegalArgumentException e1 = assertThrows(IllegalArgumentException.class, () -> parameters.setZeroImpedanceThreshold(-1.2)); + assertEquals("Zero impedance threshold must be defined and >= 0 to be consistent.", e1.getMessage()); + IllegalArgumentException e2 = assertThrows(IllegalArgumentException.class, () -> parameters.setZeroImpedanceThreshold(Double.NaN)); + assertEquals("Zero impedance threshold must be defined and >= 0 to be consistent.", e2.getMessage()); } @Test void testNominalThresholdsIntegrity() { OpenReacParameters parameters = new OpenReacParameters(); - parameters.setNominalThresholdIgnoredBuses(0.); // min value - assertEquals(0., parameters.getNominalThresholdIgnoredBuses()); - parameters.setNominalThresholdIgnoredBuses(45.); - assertEquals(45., parameters.getNominalThresholdIgnoredBuses()); - assertThrows(InvalidParametersException.class, () -> parameters.setNominalThresholdIgnoredBuses(-1.2), "nominalThresholdIgnoredBuses must be > 0."); - assertThrows(InvalidParametersException.class, () -> parameters.setNominalThresholdIgnoredBuses(Double.NaN), "nominalThresholdIgnoredBuses must be defined."); - - parameters.setNominalThresholdIgnoredVoltageBounds(200.); - assertEquals(200., parameters.getNominalThresholdIgnoredVoltageBounds()); - assertThrows(InvalidParametersException.class, () -> parameters.setNominalThresholdIgnoredVoltageBounds(-1.2), "nominalThresholdIgnoredVoltageBounds must be > 0."); - assertThrows(InvalidParametersException.class, () -> parameters.setNominalThresholdIgnoredVoltageBounds(Double.NaN), "nominalThresholdIgnoredVoltageBounds must be defined."); + parameters.setNominalThresholdIgnoredBuses(0); // min value + assertEquals(0, parameters.getNominalThresholdIgnoredBuses()); + parameters.setNominalThresholdIgnoredBuses(45); + assertEquals(45, parameters.getNominalThresholdIgnoredBuses()); + IllegalArgumentException e1 = assertThrows(IllegalArgumentException.class, () -> parameters.setNominalThresholdIgnoredBuses(-1.2)); + assertEquals("Nominal threshold for ignored buses must be defined and >= 0 to be consistent.", e1.getMessage()); + IllegalArgumentException e2 = assertThrows(IllegalArgumentException.class, () -> parameters.setNominalThresholdIgnoredBuses(Double.NaN)); + assertEquals("Nominal threshold for ignored buses must be defined and >= 0 to be consistent.", e2.getMessage()); + + parameters.setNominalThresholdIgnoredVoltageBounds(200); + assertEquals(200, parameters.getNominalThresholdIgnoredVoltageBounds()); + IllegalArgumentException e3 = assertThrows(IllegalArgumentException.class, () -> parameters.setNominalThresholdIgnoredVoltageBounds(-1.2)); + assertEquals("Nominal threshold for ignored voltage bounds must be defined and >= 0 to be consistent", e3.getMessage()); + IllegalArgumentException e4 = assertThrows(IllegalArgumentException.class, () -> parameters.setNominalThresholdIgnoredVoltageBounds(Double.NaN)); + assertEquals("Nominal threshold for ignored voltage bounds must be defined and >= 0 to be consistent", e4.getMessage()); assertTrue(parameters.checkAlgorithmParametersIntegrity()); } @@ -175,27 +186,35 @@ void testNominalThresholdsIntegrity() { @Test void testPMinMaxIntegrity() { OpenReacParameters parameters = new OpenReacParameters(); - parameters.setPQMax(5775.); - assertEquals(5775., parameters.getPQMax()); - assertThrows(InvalidParametersException.class, () -> parameters.setPQMax(0.), "pQmax must be > 0."); // min value - assertThrows(InvalidParametersException.class, () -> parameters.setPQMax(-2.1), "pQmax must be > 0."); - assertThrows(InvalidParametersException.class, () -> parameters.setPQMax(Double.NaN)); - - parameters.setDefaultPMin(1500.); - assertEquals(1500., parameters.getDefaultPMin()); - assertThrows(InvalidParametersException.class, () -> parameters.setDefaultPMin(-100.), "defaultPmin must be >= 0"); - assertThrows(InvalidParametersException.class, () -> parameters.setDefaultPMin(Double.NaN)); - - parameters.setDefaultPMax(1250.); - assertEquals(1250., parameters.getDefaultPMax()); - assertThrows(InvalidParametersException.class, () -> parameters.setDefaultPMax(0.), "defaultPmax must be > 0."); - assertThrows(InvalidParametersException.class, () -> parameters.setDefaultPMax(-100.), "defaultPmax must be > 0."); - assertThrows(InvalidParametersException.class, () -> parameters.setDefaultPMax(Double.NaN)); + parameters.setPQMax(5775); + assertEquals(5775, parameters.getPQMax()); + IllegalArgumentException e1 = assertThrows(IllegalArgumentException.class, () -> parameters.setPQMax(0)); // min value + assertEquals("Maximal consistency value for P and Q must be defined and > 0 to be consistent", e1.getMessage()); + IllegalArgumentException e2 = assertThrows(IllegalArgumentException.class, () -> parameters.setPQMax(-2.1)); + assertEquals("Maximal consistency value for P and Q must be defined and > 0 to be consistent", e2.getMessage()); + IllegalArgumentException e3 = assertThrows(IllegalArgumentException.class, () -> parameters.setPQMax(Double.NaN)); + assertEquals("Maximal consistency value for P and Q must be defined and > 0 to be consistent", e3.getMessage()); + + parameters.setDefaultPMin(1500); + assertEquals(1500, parameters.getDefaultPMin()); + IllegalArgumentException e4 = assertThrows(IllegalArgumentException.class, () -> parameters.setDefaultPMin(-100)); + assertEquals("Default P min value must be defined and >= 0 to be consistent.", e4.getMessage()); + IllegalArgumentException e5 = assertThrows(IllegalArgumentException.class, () -> parameters.setDefaultPMin(Double.NaN)); + assertEquals("Default P min value must be defined and >= 0 to be consistent.", e5.getMessage()); + + parameters.setDefaultPMax(1250); + assertEquals(1250, parameters.getDefaultPMax()); + IllegalArgumentException e6 = assertThrows(IllegalArgumentException.class, () -> parameters.setDefaultPMax(0)); + assertEquals("Default P max value must be defined and > 0 to be consistent.", e6.getMessage()); + IllegalArgumentException e7 = assertThrows(IllegalArgumentException.class, () -> parameters.setDefaultPMax(-100)); + assertEquals("Default P max value must be defined and > 0 to be consistent.", e7.getMessage()); + IllegalArgumentException e8 = assertThrows(IllegalArgumentException.class, () -> parameters.setDefaultPMax(Double.NaN)); + assertEquals("Default P max value must be defined and > 0 to be consistent.", e8.getMessage()); assertFalse(parameters.checkAlgorithmParametersIntegrity()); // case defaultPmin > defaultPmax - parameters.setDefaultPMax(10000.); + parameters.setDefaultPMax(10000); assertFalse(parameters.checkAlgorithmParametersIntegrity()); // case defaultPmax > pQmax - parameters.setDefaultPMin(50.).setDefaultPMax(1000.); + parameters.setDefaultPMin(50).setDefaultPMax(1000); assertTrue(parameters.checkAlgorithmParametersIntegrity()); } @@ -204,24 +223,29 @@ void testDefaultQmaxPmaxRatioIntegrity() { OpenReacParameters parameters = new OpenReacParameters(); parameters.setDefaultQmaxPmaxRatio(0.778); assertEquals(0.778, parameters.getDefaultQmaxPmaxRatio()); - assertThrows(InvalidParametersException.class, () -> parameters.setDefaultQmaxPmaxRatio(0.), "defaultQmaxPmaxRatio must be > 0"); - assertThrows(InvalidParametersException.class, () -> parameters.setDefaultQmaxPmaxRatio(-0.3), "defaultQmaxPmaxRatio must be > 0."); - assertThrows(InvalidParametersException.class, () -> parameters.setDefaultQmaxPmaxRatio(Double.NaN), "defaultQmaxPmaxRatio must be defined."); - - parameters.setDefaultQmaxPmaxRatio(500.); + IllegalArgumentException e1 = assertThrows(IllegalArgumentException.class, () -> parameters.setDefaultQmaxPmaxRatio(0)); + assertEquals("Default Qmax and Pmax ratio must be defined and > 0 to be consistent.", e1.getMessage()); + IllegalArgumentException e2 = assertThrows(IllegalArgumentException.class, () -> parameters.setDefaultQmaxPmaxRatio(-0.3)); + assertEquals("Default Qmax and Pmax ratio must be defined and > 0 to be consistent.", e2.getMessage()); + IllegalArgumentException e3 = assertThrows(IllegalArgumentException.class, () -> parameters.setDefaultQmaxPmaxRatio(Double.NaN)); + assertEquals("Default Qmax and Pmax ratio must be defined and > 0 to be consistent.", e3.getMessage()); + + parameters.setDefaultQmaxPmaxRatio(500); assertFalse(parameters.checkAlgorithmParametersIntegrity()); } @Test void testDefaultMinimalQPRangeIntegrity() { OpenReacParameters parameters = new OpenReacParameters(); - parameters.setDefaultMinimalQPRange(10.); - assertEquals(10., parameters.getDefaultMinimalQPRange()); - parameters.setDefaultMinimalQPRange(0.); - assertEquals(0., parameters.getDefaultMinimalQPRange()); - - assertThrows(InvalidParametersException.class, () -> parameters.setDefaultMinimalQPRange(-1.5)); - assertThrows(InvalidParametersException.class, () -> parameters.setDefaultMinimalQPRange(Double.NaN)); + parameters.setDefaultMinimalQPRange(10); + assertEquals(10, parameters.getDefaultMinimalQPRange()); + parameters.setDefaultMinimalQPRange(0); + assertEquals(0, parameters.getDefaultMinimalQPRange()); + + IllegalArgumentException e1 = assertThrows(IllegalArgumentException.class, () -> parameters.setDefaultMinimalQPRange(-1.5)); + assertEquals("Default minimal QP range must be defined and >= 0 to be consistent.", e1.getMessage()); + IllegalArgumentException e2 = assertThrows(IllegalArgumentException.class, () -> parameters.setDefaultMinimalQPRange(Double.NaN)); + assertEquals("Default minimal QP range must be defined and >= 0 to be consistent.", e2.getMessage()); } @Test @@ -281,7 +305,30 @@ void testBusesWithReactiveSlackConfigIntegrity() { } @Test - void testDefaultListsOfParametersIntegrity() { + void testDefaultParametersValuesIntegrity() { + OpenReacParameters parameters = new OpenReacParameters(); + assertEquals(OpenReacOptimisationObjective.MIN_GENERATION, parameters.getObjective()); + assertNull(parameters.getObjectiveDistance()); + assertEquals(OpenReacAmplLogLevel.INFO, parameters.getLogLevelAmpl()); + assertEquals(OpenReacSolverLogLevel.EVERYTHING, parameters.getLogLevelSolver()); + assertEquals(0.5, parameters.getMinPlausibleLowVoltageLimit()); + assertEquals(1.5, parameters.getMaxPlausibleHighVoltageLimit()); + assertEquals(ReactiveSlackBusesMode.NO_GENERATION, parameters.getReactiveSlackBusesMode()); + assertEquals(1., parameters.getAlphaCoefficient()); + assertEquals(0.01, parameters.getZeroPowerThreshold()); + assertEquals(1e-4, parameters.getZeroImpedanceThreshold()); + assertEquals(1., parameters.getNominalThresholdIgnoredBuses()); + assertEquals(0., parameters.getNominalThresholdIgnoredVoltageBounds()); + assertEquals(9000., parameters.getPQMax()); + assertEquals(0, parameters.getDefaultPMin()); + assertEquals(1000., parameters.getDefaultPMax()); + assertEquals(0.3, parameters.getDefaultQmaxPmaxRatio()); + assertEquals(1., parameters.getDefaultMinimalQPRange()); + assertTrue(parameters.checkAlgorithmParametersIntegrity()); + } + + @Test + void testDefaultParametersListsIntegrity() { // testing default lists of parameters OpenReacParameters parameters = new OpenReacParameters(); assertEquals(0, parameters.getVariableTwoWindingsTransformers().size(), "VariableTwoWindingsTransformers should be empty when using default OpenReacParameter constructor."); From 6747d379ae6b22a28b847178b4cc188aeb2cd30d Mon Sep 17 00:00:00 2001 From: parvy Date: Wed, 29 Nov 2023 18:46:00 +0100 Subject: [PATCH 19/26] Refactor. Signed-off-by: parvy --- .../src/main/resources/openreac/default_param_algo.txt | 6 ++++-- .../test/java/com/powsybl/openreac/OpenReacRunnerTest.java | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/open-reac/src/main/resources/openreac/default_param_algo.txt b/open-reac/src/main/resources/openreac/default_param_algo.txt index f3634222..bd596362 100644 --- a/open-reac/src/main/resources/openreac/default_param_algo.txt +++ b/open-reac/src/main/resources/openreac/default_param_algo.txt @@ -1,7 +1,9 @@ -objective_choice 1 -ratio_voltage_target 0.7 +objective_choice 0 +log_level_ampl INFO +log_level_knitro 2 min_plausible_low_voltage_limit 0.5 max_plausible_high_voltage_limit 1.5 +buses_with_reactive_slacks NO_GENERATION coeff_alpha 1.0 Pnull 0.01 Znull 1.0E-4 diff --git a/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java b/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java index cc1e8bbb..a0660ef5 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java @@ -46,6 +46,7 @@ /** * @author Geoffroy Jamgotchian * @author Nicolas PIERRE + * @author Pierre ARVY */ class OpenReacRunnerTest { protected FileSystem fileSystem; @@ -94,7 +95,7 @@ void testDefaultParamAlgoExport() throws IOException { } @Test - void testParamAlgoExport() throws IOException { + void testModifiedParamAlgoExport() throws IOException { Network network = IeeeCdfNetworkFactory.create57(); setDefaultVoltageLimits(network); // set default voltage limits to every voltage levels of the network OpenReacParameters parameters = new OpenReacParameters() From 2dcef614f9deab14c5ec42083001ae675c12eabd Mon Sep 17 00:00:00 2001 From: parvy Date: Wed, 7 Feb 2024 10:46:45 +0100 Subject: [PATCH 20/26] refactor. Signed-off-by: parvy --- .../parameters/input/OpenReacParameters.java | 60 +++++++++---------- .../json/OpenReacParametersDeserializer.java | 8 +-- .../json/OpenReacParametersSerializer.java | 4 +- .../openreac/OpenReacParametersTest.java | 32 +++++----- .../powsybl/openreac/OpenReacRunnerTest.java | 5 +- .../input/json/OpenReacJsonModuleTest.java | 8 +-- open-reac/src/test/resources/parameters.json | 4 +- 7 files changed, 60 insertions(+), 61 deletions(-) diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java index 42fe2315..3bd4e895 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java @@ -60,35 +60,35 @@ public class OpenReacParameters { private static final String ALPHA_COEFFICIENT_KEY = "coeff_alpha"; - private double alphaCoefficient = 1.; // in [0;1] + private double alphaCoefficient = 1; // in [0;1] - private static final String ZERO_POWER_THRESHOLD_KEY = "Pnull"; + private static final String MIN_PLAUSIBLE_ACTIVE_POWER_THRESHOLD_KEY = "Pnull"; - private double zeroPowerThreshold = 0.01; // in MW, for detecting zero value for power + private double minPlausibleActivePowerThreshold = 0.01; // in MW, for detecting zero value for power - private static final String ZERO_IMPEDANCE_THRESHOLD_KEY = "Znull"; + private static final String LOW_IMPEDANCE_THRESHOLD_KEY = "Znull"; - private double zeroImpedanceThreshold = 1e-4; // in p.u., for detecting null impedance branches + private double lowImpedanceThreshold = 1e-4; // in p.u., for detecting null impedance branches private static final String NOMINAL_THRESHOLD_IGNORED_BUS_KEY = "epsilon_nominal_voltage"; - private double nominalThresholdIgnoredBuses = 1.; // in kV, to ignore buses with Vnom lower than this value + private double nominalThresholdIgnoredBuses = 1; // in kV, to ignore buses with Vnom lower than this value private static final String NOMINAL_THRESHOLD_IGNORED_VOLTAGE_BOUNDS_KEY = "ignore_voltage_bounds"; - private double nominalThresholdIgnoredVoltageBounds = 0.; // in kV, to ignore voltage bounds of buses with Vnom lower than this value + private double nominalThresholdIgnoredVoltageBounds = 0; // in kV, to ignore voltage bounds of buses with Vnom lower than this value - private static final String PQMAX_KEY = "PQmax"; + private static final String PLAUSIBLE_POWER_LIMIT_KEY = "PQmax"; - private double pQMax = 9000.; // MW + private double plausiblePowerLimit = 9000; // MW private static final String DEFAULT_PMAX_KEY = "defaultPmax"; - private double defaultPMax = 1000.; // MW + private double defaultPMax = 1000; // MW private static final String DEFAULT_PMIN_KEY = "defaultPmin"; - private double defaultPMin = 0.; // MW + private double defaultPMin = 0; // MW private static final String DEFAULT_QMAX_PMAX_RATIO_KEY = "defaultQmaxPmaxRatio"; @@ -96,7 +96,7 @@ public class OpenReacParameters { private static final String DEFAULT_MINIMAL_QP_RANGE_KEY = "minimalQPrange"; - private double defaultMinimalQPRange = 1.; + private double defaultMinimalQPRange = 1; /** * Override some voltage level limits in the network. This will NOT modify the network object. @@ -288,27 +288,27 @@ public OpenReacParameters setAlphaCoefficient(double alphaCoefficient) { return this; } - public double getZeroPowerThreshold() { - return zeroPowerThreshold; + public double getMinPlausibleActivePowerThreshold() { + return minPlausibleActivePowerThreshold; } - public OpenReacParameters setZeroPowerThreshold(double zeroPowerThreshold) { - if (Double.isNaN(zeroPowerThreshold) || zeroPowerThreshold < 0) { + public OpenReacParameters setMinPlausibleActivePowerThreshold(double minPlausibleActivePowerThreshold) { + if (Double.isNaN(minPlausibleActivePowerThreshold) || minPlausibleActivePowerThreshold < 0) { throw new IllegalArgumentException("Zero power threshold must be defined and >= 0 to be consistent."); } - this.zeroPowerThreshold = zeroPowerThreshold; + this.minPlausibleActivePowerThreshold = minPlausibleActivePowerThreshold; return this; } - public double getZeroImpedanceThreshold() { - return zeroImpedanceThreshold; + public double getLowImpedanceThreshold() { + return lowImpedanceThreshold; } - public OpenReacParameters setZeroImpedanceThreshold(double zeroImpedanceThreshold) { - if (Double.isNaN(zeroImpedanceThreshold) || zeroImpedanceThreshold < 0) { + public OpenReacParameters setLowImpedanceThreshold(double lowImpedanceThreshold) { + if (Double.isNaN(lowImpedanceThreshold) || lowImpedanceThreshold < 0) { throw new IllegalArgumentException("Zero impedance threshold must be defined and >= 0 to be consistent."); } - this.zeroImpedanceThreshold = zeroImpedanceThreshold; + this.lowImpedanceThreshold = lowImpedanceThreshold; return this; } @@ -337,14 +337,14 @@ public OpenReacParameters setNominalThresholdIgnoredVoltageBounds(double nominal } public double getPQMax() { - return pQMax; + return plausiblePowerLimit; } public OpenReacParameters setPQMax(double pQMax) { if (Double.isNaN(pQMax) || pQMax <= 0) { throw new IllegalArgumentException("Maximal consistency value for P and Q must be defined and > 0 to be consistent"); } - this.pQMax = pQMax; + this.plausiblePowerLimit = pQMax; return this; } @@ -409,11 +409,11 @@ public List getAllAlgorithmParams() { allAlgoParams.add(new OpenReacAlgoParamImpl(MAX_PLAUSIBLE_HIGH_VOLTAGE_LIMIT_KEY, Double.toString(maxPlausibleHighVoltageLimit))); allAlgoParams.add(reactiveSlackBusesMode.toParam()); allAlgoParams.add(new OpenReacAlgoParamImpl(ALPHA_COEFFICIENT_KEY, Double.toString(alphaCoefficient))); - allAlgoParams.add(new OpenReacAlgoParamImpl(ZERO_POWER_THRESHOLD_KEY, Double.toString(zeroPowerThreshold))); - allAlgoParams.add(new OpenReacAlgoParamImpl(ZERO_IMPEDANCE_THRESHOLD_KEY, Double.toString(zeroImpedanceThreshold))); + allAlgoParams.add(new OpenReacAlgoParamImpl(MIN_PLAUSIBLE_ACTIVE_POWER_THRESHOLD_KEY, Double.toString(minPlausibleActivePowerThreshold))); + allAlgoParams.add(new OpenReacAlgoParamImpl(LOW_IMPEDANCE_THRESHOLD_KEY, Double.toString(lowImpedanceThreshold))); allAlgoParams.add(new OpenReacAlgoParamImpl(NOMINAL_THRESHOLD_IGNORED_BUS_KEY, Double.toString(nominalThresholdIgnoredBuses))); allAlgoParams.add(new OpenReacAlgoParamImpl(NOMINAL_THRESHOLD_IGNORED_VOLTAGE_BOUNDS_KEY, Double.toString(nominalThresholdIgnoredVoltageBounds))); - allAlgoParams.add(new OpenReacAlgoParamImpl(PQMAX_KEY, Double.toString(pQMax))); + allAlgoParams.add(new OpenReacAlgoParamImpl(PLAUSIBLE_POWER_LIMIT_KEY, Double.toString(plausiblePowerLimit))); allAlgoParams.add(new OpenReacAlgoParamImpl(DEFAULT_PMIN_KEY, Double.toString(defaultPMin))); allAlgoParams.add(new OpenReacAlgoParamImpl(DEFAULT_PMAX_KEY, Double.toString(defaultPMax))); allAlgoParams.add(new OpenReacAlgoParamImpl(DEFAULT_QMAX_PMAX_RATIO_KEY, Double.toString(defaultQmaxPmaxRatio))); @@ -493,13 +493,13 @@ public boolean checkAlgorithmParametersIntegrity() { integrityAlgorithmParameters = false; } - if (defaultPMax > pQMax) { + if (defaultPMax > plausiblePowerLimit) { LOGGER.warn("Default P min = {} and default P max = {} must be lower than PQmax value = {} to be consistent.", - defaultPMin, defaultPMax, pQMax); + defaultPMin, defaultPMax, plausiblePowerLimit); integrityAlgorithmParameters = false; } - if (defaultPMax * defaultQmaxPmaxRatio > pQMax) { + if (defaultPMax * defaultQmaxPmaxRatio > plausiblePowerLimit) { LOGGER.warn("Default Q max value = {} value must be lower than PQmax value to be consistent.", defaultPMax * defaultQmaxPmaxRatio); integrityAlgorithmParameters = false; diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersDeserializer.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersDeserializer.java index 91b92628..333f3ac4 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersDeserializer.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersDeserializer.java @@ -94,13 +94,13 @@ public OpenReacParameters deserialize(JsonParser parser, DeserializationContext parser.nextToken(); parameters.setAlphaCoefficient(parser.getValueAsDouble()); break; - case "zeroPowerThreshold": + case "minPlausibleActivePowerThreshold": parser.nextToken(); - parameters.setZeroPowerThreshold(parser.getValueAsDouble()); + parameters.setMinPlausibleActivePowerThreshold(parser.getValueAsDouble()); break; - case "zeroImpedanceThreshold": + case "lowImpedanceThreshold": parser.nextToken(); - parameters.setZeroImpedanceThreshold(parser.getValueAsDouble()); + parameters.setLowImpedanceThreshold(parser.getValueAsDouble()); break; case "nominalThresholdIgnoredBuses": parser.nextToken(); diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersSerializer.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersSerializer.java index 765474fa..0f1c4367 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersSerializer.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersSerializer.java @@ -48,8 +48,8 @@ public void serialize(OpenReacParameters openReacParameters, JsonGenerator jsonG serializerProvider.defaultSerializeField("maxPlausibleHighVoltageLimit", openReacParameters.getMaxPlausibleHighVoltageLimit(), jsonGenerator); serializerProvider.defaultSerializeField("reactiveSlackBusesMode", openReacParameters.getReactiveSlackBusesMode().name(), jsonGenerator); serializerProvider.defaultSerializeField("alphaCoefficient", openReacParameters.getAlphaCoefficient(), jsonGenerator); - serializerProvider.defaultSerializeField("zeroPowerThreshold", openReacParameters.getZeroPowerThreshold(), jsonGenerator); - serializerProvider.defaultSerializeField("zeroImpedanceThreshold", openReacParameters.getZeroImpedanceThreshold(), jsonGenerator); + serializerProvider.defaultSerializeField("minPlausibleActivePowerThreshold", openReacParameters.getMinPlausibleActivePowerThreshold(), jsonGenerator); + serializerProvider.defaultSerializeField("lowImpedanceThreshold", openReacParameters.getLowImpedanceThreshold(), jsonGenerator); serializerProvider.defaultSerializeField("nominalThresholdIgnoredBuses", openReacParameters.getNominalThresholdIgnoredBuses(), jsonGenerator); serializerProvider.defaultSerializeField("nominalThresholdIgnoredVoltageBounds", openReacParameters.getNominalThresholdIgnoredVoltageBounds(), jsonGenerator); serializerProvider.defaultSerializeField("pQmax", openReacParameters.getPQMax(), jsonGenerator); diff --git a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java index c9b5ff0d..401acfc3 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java @@ -135,14 +135,14 @@ void testAlphaCoefficientIntegrity() { @Test void testZeroPowerThresholdIntegrity() { OpenReacParameters parameters = new OpenReacParameters(); - parameters.setZeroPowerThreshold(0); - assertEquals(0., parameters.getZeroPowerThreshold()); // min value - parameters.setZeroPowerThreshold(2.365); - assertEquals(2.365, parameters.getZeroPowerThreshold()); + parameters.setMinPlausibleActivePowerThreshold(0); + assertEquals(0., parameters.getMinPlausibleActivePowerThreshold()); // min value + parameters.setMinPlausibleActivePowerThreshold(2.365); + assertEquals(2.365, parameters.getMinPlausibleActivePowerThreshold()); - IllegalArgumentException e1 = assertThrows(IllegalArgumentException.class, () -> parameters.setZeroPowerThreshold(-1.2)); + IllegalArgumentException e1 = assertThrows(IllegalArgumentException.class, () -> parameters.setMinPlausibleActivePowerThreshold(-1.2)); assertEquals("Zero power threshold must be defined and >= 0 to be consistent.", e1.getMessage()); - IllegalArgumentException e2 = assertThrows(IllegalArgumentException.class, () -> parameters.setZeroPowerThreshold(Double.NaN)); + IllegalArgumentException e2 = assertThrows(IllegalArgumentException.class, () -> parameters.setMinPlausibleActivePowerThreshold(Double.NaN)); assertEquals("Zero power threshold must be defined and >= 0 to be consistent.", e2.getMessage()); assertTrue(parameters.checkAlgorithmParametersIntegrity()); } @@ -150,14 +150,14 @@ void testZeroPowerThresholdIntegrity() { @Test void testZeroImpedanceThresholdIntegrity() { OpenReacParameters parameters = new OpenReacParameters(); - parameters.setZeroImpedanceThreshold(0); - assertEquals(0., parameters.getZeroImpedanceThreshold()); // min value - parameters.setZeroImpedanceThreshold(1e-5); - assertEquals(1e-5, parameters.getZeroImpedanceThreshold()); + parameters.setLowImpedanceThreshold(0); + assertEquals(0., parameters.getLowImpedanceThreshold()); // min value + parameters.setLowImpedanceThreshold(1e-5); + assertEquals(1e-5, parameters.getLowImpedanceThreshold()); - IllegalArgumentException e1 = assertThrows(IllegalArgumentException.class, () -> parameters.setZeroImpedanceThreshold(-1.2)); + IllegalArgumentException e1 = assertThrows(IllegalArgumentException.class, () -> parameters.setLowImpedanceThreshold(-1.2)); assertEquals("Zero impedance threshold must be defined and >= 0 to be consistent.", e1.getMessage()); - IllegalArgumentException e2 = assertThrows(IllegalArgumentException.class, () -> parameters.setZeroImpedanceThreshold(Double.NaN)); + IllegalArgumentException e2 = assertThrows(IllegalArgumentException.class, () -> parameters.setLowImpedanceThreshold(Double.NaN)); assertEquals("Zero impedance threshold must be defined and >= 0 to be consistent.", e2.getMessage()); } @@ -259,8 +259,8 @@ void testAlgorithmParams() { parameters.setMaxPlausibleHighVoltageLimit(1.2); parameters.setReactiveSlackBusesMode(ReactiveSlackBusesMode.ALL); parameters.setAlphaCoefficient(0.56); - parameters.setZeroPowerThreshold(0.5); - parameters.setZeroImpedanceThreshold(1e-5); + parameters.setMinPlausibleActivePowerThreshold(0.5); + parameters.setLowImpedanceThreshold(1e-5); parameters.setNominalThresholdIgnoredBuses(10); parameters.setNominalThresholdIgnoredVoltageBounds(5); parameters.setPQMax(8555.3); @@ -315,8 +315,8 @@ void testDefaultParametersValuesIntegrity() { assertEquals(1.5, parameters.getMaxPlausibleHighVoltageLimit()); assertEquals(ReactiveSlackBusesMode.NO_GENERATION, parameters.getReactiveSlackBusesMode()); assertEquals(1., parameters.getAlphaCoefficient()); - assertEquals(0.01, parameters.getZeroPowerThreshold()); - assertEquals(1e-4, parameters.getZeroImpedanceThreshold()); + assertEquals(0.01, parameters.getMinPlausibleActivePowerThreshold()); + assertEquals(1e-4, parameters.getLowImpedanceThreshold()); assertEquals(1., parameters.getNominalThresholdIgnoredBuses()); assertEquals(0., parameters.getNominalThresholdIgnoredVoltageBounds()); assertEquals(9000., parameters.getPQMax()); diff --git a/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java b/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java index c8a646ae..5f1f194a 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java @@ -46,7 +46,6 @@ /** * @author Geoffroy Jamgotchian * @author Nicolas PIERRE - * @author Pierre ARVY */ class OpenReacRunnerTest { protected FileSystem fileSystem; @@ -107,8 +106,8 @@ void testModifiedParamAlgoExport() throws IOException { .setMaxPlausibleHighVoltageLimit(1.3455) .setReactiveSlackBusesMode(ReactiveSlackBusesMode.ALL) .setAlphaCoefficient(0.88) - .setZeroPowerThreshold(0.45) - .setZeroImpedanceThreshold(1e-5) + .setMinPlausibleActivePowerThreshold(0.45) + .setLowImpedanceThreshold(1e-5) .setNominalThresholdIgnoredBuses(2.) .setNominalThresholdIgnoredVoltageBounds(0.75) .setPQMax(3987.76) diff --git a/open-reac/src/test/java/com/powsybl/openreac/parameters/input/json/OpenReacJsonModuleTest.java b/open-reac/src/test/java/com/powsybl/openreac/parameters/input/json/OpenReacJsonModuleTest.java index abc7964d..f7848486 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/parameters/input/json/OpenReacJsonModuleTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/parameters/input/json/OpenReacJsonModuleTest.java @@ -55,8 +55,8 @@ void test() throws IOException { parameters.setReactiveSlackBusesMode(ReactiveSlackBusesMode.CONFIGURED); parameters.addConfiguredReactiveSlackBuses(List.of("bus1", "bus2")); parameters.setAlphaCoefficient(0.56); - parameters.setZeroPowerThreshold(0.5); - parameters.setZeroImpedanceThreshold(1e-5); + parameters.setMinPlausibleActivePowerThreshold(0.5); + parameters.setLowImpedanceThreshold(1e-5); parameters.setNominalThresholdIgnoredBuses(10.); parameters.setNominalThresholdIgnoredVoltageBounds(5.); parameters.setPQMax(8555.3); @@ -89,8 +89,8 @@ void test() throws IOException { assertEquals(ReactiveSlackBusesMode.CONFIGURED, parameters2.getReactiveSlackBusesMode()); assertEquals(OpenReacOptimisationObjective.MIN_GENERATION, parameters2.getObjective()); assertEquals(0.56, parameters2.getAlphaCoefficient()); - assertEquals(0.5, parameters2.getZeroPowerThreshold()); - assertEquals(1e-5, parameters2.getZeroImpedanceThreshold()); + assertEquals(0.5, parameters2.getMinPlausibleActivePowerThreshold()); + assertEquals(1e-5, parameters2.getLowImpedanceThreshold()); assertEquals(10., parameters2.getNominalThresholdIgnoredBuses()); assertEquals(5., parameters2.getNominalThresholdIgnoredVoltageBounds()); assertEquals(8555.3, parameters2.getPQMax()); diff --git a/open-reac/src/test/resources/parameters.json b/open-reac/src/test/resources/parameters.json index 507f0b16..bea6fc9d 100644 --- a/open-reac/src/test/resources/parameters.json +++ b/open-reac/src/test/resources/parameters.json @@ -33,8 +33,8 @@ "maxPlausibleHighVoltageLimit" : 1.236, "reactiveSlackBusesMode" : "CONFIGURED", "alphaCoefficient" : 0.56, - "zeroPowerThreshold" : 0.5, - "zeroImpedanceThreshold" : 1.0E-5, + "minPlausibleActivePowerThreshold" : 0.5, + "lowImpedanceThreshold" : 1.0E-5, "nominalThresholdIgnoredBuses" : 10.0, "nominalThresholdIgnoredVoltageBounds" : 5.0, "pQmax" : 8555.3, From bc7158eefd44e5a755aaec178322c7b8bfc8bede Mon Sep 17 00:00:00 2001 From: parvy Date: Mon, 8 Apr 2024 17:34:03 +0200 Subject: [PATCH 21/26] add comments. Signed-off-by: parvy --- .../parameters/input/OpenReacParameters.java | 33 ++++++++++++++++++- .../resources/openreac/default_param_algo.txt | 17 ---------- 2 files changed, 32 insertions(+), 18 deletions(-) delete mode 100644 open-reac/src/main/resources/openreac/default_param_algo.txt diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java index 3bd4e895..24458aae 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java @@ -276,6 +276,9 @@ public OpenReacParameters setReactiveSlackBusesMode(ReactiveSlackBusesMode react return this; } + /** + * @return the weight to favor more/less minimization of active power produced by generators. + */ public double getAlphaCoefficient() { return alphaCoefficient; } @@ -288,6 +291,9 @@ public OpenReacParameters setAlphaCoefficient(double alphaCoefficient) { return this; } + /** + * @return the threshold of active and reactive power considered as null. + */ public double getMinPlausibleActivePowerThreshold() { return minPlausibleActivePowerThreshold; } @@ -300,6 +306,9 @@ public OpenReacParameters setMinPlausibleActivePowerThreshold(double minPlausibl return this; } + /** + * @return the threshold of impedance considered as null. + */ public double getLowImpedanceThreshold() { return lowImpedanceThreshold; } @@ -312,6 +321,9 @@ public OpenReacParameters setLowImpedanceThreshold(double lowImpedanceThreshold) return this; } + /** + * @return the threshold to ignore voltage levels with nominal voltager lower than it. + */ public double getNominalThresholdIgnoredBuses() { return nominalThresholdIgnoredBuses; } @@ -324,6 +336,10 @@ public OpenReacParameters setNominalThresholdIgnoredBuses(double nominalThreshol return this; } + /** + * @return the threshold used to replace voltage limits of voltage levels with nominal voltage + * than it. + */ public double getNominalThresholdIgnoredVoltageBounds() { return nominalThresholdIgnoredVoltageBounds; } @@ -336,6 +352,9 @@ public OpenReacParameters setNominalThresholdIgnoredVoltageBounds(double nominal return this; } + /** + * @return the threshold for maximum active and reactive power considered in correction of generator limits. + */ public double getPQMax() { return plausiblePowerLimit; } @@ -348,6 +367,9 @@ public OpenReacParameters setPQMax(double pQMax) { return this; } + /** + * @return the threshold for correction of high active power limit produced by generators. + */ public double getDefaultPMax() { return defaultPMax; } @@ -360,6 +382,9 @@ public OpenReacParameters setDefaultPMax(double defaultPMax) { return this; } + /** + * @return the threshold for correction of low active power limit produced by generators. + */ public double getDefaultPMin() { return defaultPMin; } @@ -372,6 +397,9 @@ public OpenReacParameters setDefaultPMin(double defaultPMin) { return this; } + /** + * @return the ratio used to calculate threshold for corrections of high/low reactive power limits. + */ public double getDefaultQmaxPmaxRatio() { return defaultQmaxPmaxRatio; } @@ -385,6 +413,10 @@ public OpenReacParameters setDefaultQmaxPmaxRatio(double defaultQmaxPmaxRatio) { return this; } + /** + * @return the threshold to fix active (resp. reactive) power of generators with + * active (resp. reactive) power limits that are closer than it. + */ public double getDefaultMinimalQPRange() { return defaultMinimalQPRange; } @@ -466,7 +498,6 @@ public void checkIntegrity(Network network) throws InvalidParametersException { if (!integrityAlgorithmParameters) { throw new InvalidParametersException("At least one algorithm parameter is inconsistent."); } - } /** diff --git a/open-reac/src/main/resources/openreac/default_param_algo.txt b/open-reac/src/main/resources/openreac/default_param_algo.txt deleted file mode 100644 index bd596362..00000000 --- a/open-reac/src/main/resources/openreac/default_param_algo.txt +++ /dev/null @@ -1,17 +0,0 @@ -objective_choice 0 -log_level_ampl INFO -log_level_knitro 2 -min_plausible_low_voltage_limit 0.5 -max_plausible_high_voltage_limit 1.5 -buses_with_reactive_slacks NO_GENERATION -coeff_alpha 1.0 -Pnull 0.01 -Znull 1.0E-4 -epsilon_nominal_voltage 1.0 -ignore_voltage_bounds 0.0 -PQmax 9000.0 -defaultPmin 0.0 -defaultPmax 1000.0 -defaultQmaxPmaxRatio 0.3 -minimalQPrange 1.0 - From 78ca8148aa6abeb0222d69ef80508e13956ba77e Mon Sep 17 00:00:00 2001 From: parvy Date: Mon, 8 Apr 2024 18:04:30 +0200 Subject: [PATCH 22/26] rename parameters. Signed-off-by: parvy --- .../parameters/input/OpenReacParameters.java | 88 +++++++++---------- .../json/OpenReacParametersDeserializer.java | 18 ++-- .../json/OpenReacParametersSerializer.java | 10 +-- .../openreac/OpenReacParametersTest.java | 58 ++++++------ .../powsybl/openreac/OpenReacRunnerTest.java | 8 +- .../input/json/OpenReacJsonModuleTest.java | 16 ++-- open-reac/src/test/resources/parameters.json | 10 +-- 7 files changed, 104 insertions(+), 104 deletions(-) diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java index 24458aae..94608d43 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java @@ -70,25 +70,25 @@ public class OpenReacParameters { private double lowImpedanceThreshold = 1e-4; // in p.u., for detecting null impedance branches - private static final String NOMINAL_THRESHOLD_IGNORED_BUS_KEY = "epsilon_nominal_voltage"; + private static final String MIN_NOMINAL_VOLTAGE_IGNORED_BUS_KEY = "epsilon_nominal_voltage"; - private double nominalThresholdIgnoredBuses = 1; // in kV, to ignore buses with Vnom lower than this value + private double minNominalVoltageIgnoredBus = 1; // in kV, to ignore buses with Vnom lower than this value - private static final String NOMINAL_THRESHOLD_IGNORED_VOLTAGE_BOUNDS_KEY = "ignore_voltage_bounds"; + private static final String MIN_NOMINAL_VOLTAGE_IGNORED_VOLTAGE_BOUNDS_KEY = "ignore_voltage_bounds"; - private double nominalThresholdIgnoredVoltageBounds = 0; // in kV, to ignore voltage bounds of buses with Vnom lower than this value + private double minNominalVoltageIgnoredVoltageBounds = 0; // in kV, to ignore voltage bounds of buses with Vnom lower than this value - private static final String PLAUSIBLE_POWER_LIMIT_KEY = "PQmax"; + private static final String MAX_PLAUSIBLE_POWER_LIMIT_KEY = "PQmax"; - private double plausiblePowerLimit = 9000; // MW + private double maxPlausiblePowerLimit = 9000; // MW - private static final String DEFAULT_PMAX_KEY = "defaultPmax"; + private static final String HIGH_ACTIVE_POWER_DEFAULT_LIMIT_KEY = "defaultPmax"; - private double defaultPMax = 1000; // MW + private double highActivePowerDefaultLimit = 1000; // MW - private static final String DEFAULT_PMIN_KEY = "defaultPmin"; + private static final String LOW_ACTIVE_POWER_DEFAULT_LIMIT_KEY = "defaultPmin"; - private double defaultPMin = 0; // MW + private double lowActivePowerDefaultLimit = 0; // MW private static final String DEFAULT_QMAX_PMAX_RATIO_KEY = "defaultQmaxPmaxRatio"; @@ -324,15 +324,15 @@ public OpenReacParameters setLowImpedanceThreshold(double lowImpedanceThreshold) /** * @return the threshold to ignore voltage levels with nominal voltager lower than it. */ - public double getNominalThresholdIgnoredBuses() { - return nominalThresholdIgnoredBuses; + public double getMinNominalVoltageIgnoredBus() { + return minNominalVoltageIgnoredBus; } - public OpenReacParameters setNominalThresholdIgnoredBuses(double nominalThresholdIgnoredBuses) { - if (Double.isNaN(nominalThresholdIgnoredBuses) || nominalThresholdIgnoredBuses < 0) { + public OpenReacParameters setMinNominalVoltageIgnoredBus(double minNominalVoltageIgnoredBus) { + if (Double.isNaN(minNominalVoltageIgnoredBus) || minNominalVoltageIgnoredBus < 0) { throw new IllegalArgumentException("Nominal threshold for ignored buses must be defined and >= 0 to be consistent."); } - this.nominalThresholdIgnoredBuses = nominalThresholdIgnoredBuses; + this.minNominalVoltageIgnoredBus = minNominalVoltageIgnoredBus; return this; } @@ -340,15 +340,15 @@ public OpenReacParameters setNominalThresholdIgnoredBuses(double nominalThreshol * @return the threshold used to replace voltage limits of voltage levels with nominal voltage * than it. */ - public double getNominalThresholdIgnoredVoltageBounds() { - return nominalThresholdIgnoredVoltageBounds; + public double getMinNominalVoltageIgnoredVoltageBounds() { + return minNominalVoltageIgnoredVoltageBounds; } - public OpenReacParameters setNominalThresholdIgnoredVoltageBounds(double nominalThresholdIgnoredVoltageBounds) { - if (Double.isNaN(nominalThresholdIgnoredVoltageBounds) || nominalThresholdIgnoredVoltageBounds < 0) { + public OpenReacParameters setMinNominalVoltageIgnoredVoltageBounds(double minNominalVoltageIgnoredVoltageBounds) { + if (Double.isNaN(minNominalVoltageIgnoredVoltageBounds) || minNominalVoltageIgnoredVoltageBounds < 0) { throw new IllegalArgumentException("Nominal threshold for ignored voltage bounds must be defined and >= 0 to be consistent"); } - this.nominalThresholdIgnoredVoltageBounds = nominalThresholdIgnoredVoltageBounds; + this.minNominalVoltageIgnoredVoltageBounds = minNominalVoltageIgnoredVoltageBounds; return this; } @@ -356,44 +356,44 @@ public OpenReacParameters setNominalThresholdIgnoredVoltageBounds(double nominal * @return the threshold for maximum active and reactive power considered in correction of generator limits. */ public double getPQMax() { - return plausiblePowerLimit; + return maxPlausiblePowerLimit; } public OpenReacParameters setPQMax(double pQMax) { if (Double.isNaN(pQMax) || pQMax <= 0) { throw new IllegalArgumentException("Maximal consistency value for P and Q must be defined and > 0 to be consistent"); } - this.plausiblePowerLimit = pQMax; + this.maxPlausiblePowerLimit = pQMax; return this; } /** * @return the threshold for correction of high active power limit produced by generators. */ - public double getDefaultPMax() { - return defaultPMax; + public double getHighActivePowerDefaultLimit() { + return highActivePowerDefaultLimit; } - public OpenReacParameters setDefaultPMax(double defaultPMax) { - if (Double.isNaN(defaultPMax) || defaultPMax <= 0) { + public OpenReacParameters setHighActivePowerDefaultLimit(double highActivePowerDefaultLimit) { + if (Double.isNaN(highActivePowerDefaultLimit) || highActivePowerDefaultLimit <= 0) { throw new IllegalArgumentException("Default P max value must be defined and > 0 to be consistent."); } - this.defaultPMax = defaultPMax; + this.highActivePowerDefaultLimit = highActivePowerDefaultLimit; return this; } /** * @return the threshold for correction of low active power limit produced by generators. */ - public double getDefaultPMin() { - return defaultPMin; + public double getLowActivePowerDefaultLimit() { + return lowActivePowerDefaultLimit; } - public OpenReacParameters setDefaultPMin(double defaultPMin) { - if (Double.isNaN(defaultPMin) || defaultPMin < 0) { + public OpenReacParameters setLowActivePowerDefaultLimit(double lowActivePowerDefaultLimit) { + if (Double.isNaN(lowActivePowerDefaultLimit) || lowActivePowerDefaultLimit < 0) { throw new IllegalArgumentException("Default P min value must be defined and >= 0 to be consistent."); } - this.defaultPMin = defaultPMin; + this.lowActivePowerDefaultLimit = lowActivePowerDefaultLimit; return this; } @@ -443,11 +443,11 @@ public List getAllAlgorithmParams() { allAlgoParams.add(new OpenReacAlgoParamImpl(ALPHA_COEFFICIENT_KEY, Double.toString(alphaCoefficient))); allAlgoParams.add(new OpenReacAlgoParamImpl(MIN_PLAUSIBLE_ACTIVE_POWER_THRESHOLD_KEY, Double.toString(minPlausibleActivePowerThreshold))); allAlgoParams.add(new OpenReacAlgoParamImpl(LOW_IMPEDANCE_THRESHOLD_KEY, Double.toString(lowImpedanceThreshold))); - allAlgoParams.add(new OpenReacAlgoParamImpl(NOMINAL_THRESHOLD_IGNORED_BUS_KEY, Double.toString(nominalThresholdIgnoredBuses))); - allAlgoParams.add(new OpenReacAlgoParamImpl(NOMINAL_THRESHOLD_IGNORED_VOLTAGE_BOUNDS_KEY, Double.toString(nominalThresholdIgnoredVoltageBounds))); - allAlgoParams.add(new OpenReacAlgoParamImpl(PLAUSIBLE_POWER_LIMIT_KEY, Double.toString(plausiblePowerLimit))); - allAlgoParams.add(new OpenReacAlgoParamImpl(DEFAULT_PMIN_KEY, Double.toString(defaultPMin))); - allAlgoParams.add(new OpenReacAlgoParamImpl(DEFAULT_PMAX_KEY, Double.toString(defaultPMax))); + allAlgoParams.add(new OpenReacAlgoParamImpl(MIN_NOMINAL_VOLTAGE_IGNORED_BUS_KEY, Double.toString(minNominalVoltageIgnoredBus))); + allAlgoParams.add(new OpenReacAlgoParamImpl(MIN_NOMINAL_VOLTAGE_IGNORED_VOLTAGE_BOUNDS_KEY, Double.toString(minNominalVoltageIgnoredVoltageBounds))); + allAlgoParams.add(new OpenReacAlgoParamImpl(MAX_PLAUSIBLE_POWER_LIMIT_KEY, Double.toString(maxPlausiblePowerLimit))); + allAlgoParams.add(new OpenReacAlgoParamImpl(LOW_ACTIVE_POWER_DEFAULT_LIMIT_KEY, Double.toString(lowActivePowerDefaultLimit))); + allAlgoParams.add(new OpenReacAlgoParamImpl(HIGH_ACTIVE_POWER_DEFAULT_LIMIT_KEY, Double.toString(highActivePowerDefaultLimit))); allAlgoParams.add(new OpenReacAlgoParamImpl(DEFAULT_QMAX_PMAX_RATIO_KEY, Double.toString(defaultQmaxPmaxRatio))); allAlgoParams.add(new OpenReacAlgoParamImpl(DEFAULT_MINIMAL_QP_RANGE_KEY, Double.toString(defaultMinimalQPRange))); return allAlgoParams; @@ -518,25 +518,25 @@ public boolean checkAlgorithmParametersIntegrity() { integrityAlgorithmParameters = false; } - if (defaultPMin > defaultPMax) { + if (lowActivePowerDefaultLimit > highActivePowerDefaultLimit) { LOGGER.warn("Default P min = {} must be lower than default P max = {} to be consistent.", - defaultPMin, defaultPMax); + lowActivePowerDefaultLimit, highActivePowerDefaultLimit); integrityAlgorithmParameters = false; } - if (defaultPMax > plausiblePowerLimit) { + if (highActivePowerDefaultLimit > maxPlausiblePowerLimit) { LOGGER.warn("Default P min = {} and default P max = {} must be lower than PQmax value = {} to be consistent.", - defaultPMin, defaultPMax, plausiblePowerLimit); + lowActivePowerDefaultLimit, highActivePowerDefaultLimit, maxPlausiblePowerLimit); integrityAlgorithmParameters = false; } - if (defaultPMax * defaultQmaxPmaxRatio > plausiblePowerLimit) { + if (highActivePowerDefaultLimit * defaultQmaxPmaxRatio > maxPlausiblePowerLimit) { LOGGER.warn("Default Q max value = {} value must be lower than PQmax value to be consistent.", - defaultPMax * defaultQmaxPmaxRatio); + highActivePowerDefaultLimit * defaultQmaxPmaxRatio); integrityAlgorithmParameters = false; } - if (nominalThresholdIgnoredBuses > nominalThresholdIgnoredVoltageBounds) { + if (minNominalVoltageIgnoredBus > minNominalVoltageIgnoredVoltageBounds) { LOGGER.warn("Some buses with ignored voltage bounds will be ignored in calculations."); } diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersDeserializer.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersDeserializer.java index 333f3ac4..bbe9ee79 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersDeserializer.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersDeserializer.java @@ -102,25 +102,25 @@ public OpenReacParameters deserialize(JsonParser parser, DeserializationContext parser.nextToken(); parameters.setLowImpedanceThreshold(parser.getValueAsDouble()); break; - case "nominalThresholdIgnoredBuses": + case "minNominalVoltageIgnoredBus": parser.nextToken(); - parameters.setNominalThresholdIgnoredBuses(parser.getValueAsDouble()); + parameters.setMinNominalVoltageIgnoredBus(parser.getValueAsDouble()); break; - case "nominalThresholdIgnoredVoltageBounds": + case "minNominalVoltageIgnoredVoltageBounds": parser.nextToken(); - parameters.setNominalThresholdIgnoredVoltageBounds(parser.getValueAsDouble()); + parameters.setMinNominalVoltageIgnoredVoltageBounds(parser.getValueAsDouble()); break; - case "pQmax": + case "maxPlausiblePowerLimit": parser.nextToken(); parameters.setPQMax(parser.getValueAsDouble()); break; - case "defaultPMin": + case "lowActivePowerDefaultLimit": parser.nextToken(); - parameters.setDefaultPMin(parser.getValueAsDouble()); + parameters.setLowActivePowerDefaultLimit(parser.getValueAsDouble()); break; - case "defaultPMax": + case "highActivePowerDefaultLimit": parser.nextToken(); - parameters.setDefaultPMax(parser.getValueAsDouble()); + parameters.setHighActivePowerDefaultLimit(parser.getValueAsDouble()); break; case "defaultQmaxPmaxRatio": parser.nextToken(); diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersSerializer.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersSerializer.java index 0f1c4367..795c1bac 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersSerializer.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersSerializer.java @@ -50,11 +50,11 @@ public void serialize(OpenReacParameters openReacParameters, JsonGenerator jsonG serializerProvider.defaultSerializeField("alphaCoefficient", openReacParameters.getAlphaCoefficient(), jsonGenerator); serializerProvider.defaultSerializeField("minPlausibleActivePowerThreshold", openReacParameters.getMinPlausibleActivePowerThreshold(), jsonGenerator); serializerProvider.defaultSerializeField("lowImpedanceThreshold", openReacParameters.getLowImpedanceThreshold(), jsonGenerator); - serializerProvider.defaultSerializeField("nominalThresholdIgnoredBuses", openReacParameters.getNominalThresholdIgnoredBuses(), jsonGenerator); - serializerProvider.defaultSerializeField("nominalThresholdIgnoredVoltageBounds", openReacParameters.getNominalThresholdIgnoredVoltageBounds(), jsonGenerator); - serializerProvider.defaultSerializeField("pQmax", openReacParameters.getPQMax(), jsonGenerator); - serializerProvider.defaultSerializeField("defaultPMin", openReacParameters.getDefaultPMin(), jsonGenerator); - serializerProvider.defaultSerializeField("defaultPMax", openReacParameters.getDefaultPMax(), jsonGenerator); + serializerProvider.defaultSerializeField("minNominalVoltageIgnoredBus", openReacParameters.getMinNominalVoltageIgnoredBus(), jsonGenerator); + serializerProvider.defaultSerializeField("minNominalVoltageIgnoredVoltageBounds", openReacParameters.getMinNominalVoltageIgnoredVoltageBounds(), jsonGenerator); + serializerProvider.defaultSerializeField("maxPlausiblePowerLimit", openReacParameters.getPQMax(), jsonGenerator); + serializerProvider.defaultSerializeField("lowActivePowerDefaultLimit", openReacParameters.getLowActivePowerDefaultLimit(), jsonGenerator); + serializerProvider.defaultSerializeField("highActivePowerDefaultLimit", openReacParameters.getHighActivePowerDefaultLimit(), jsonGenerator); serializerProvider.defaultSerializeField("defaultQmaxPmaxRatio", openReacParameters.getDefaultQmaxPmaxRatio(), jsonGenerator); serializerProvider.defaultSerializeField("defaultMinimalQPRange", openReacParameters.getDefaultMinimalQPRange(), jsonGenerator); diff --git a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java index 401acfc3..04181463 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java @@ -164,20 +164,20 @@ void testZeroImpedanceThresholdIntegrity() { @Test void testNominalThresholdsIntegrity() { OpenReacParameters parameters = new OpenReacParameters(); - parameters.setNominalThresholdIgnoredBuses(0); // min value - assertEquals(0, parameters.getNominalThresholdIgnoredBuses()); - parameters.setNominalThresholdIgnoredBuses(45); - assertEquals(45, parameters.getNominalThresholdIgnoredBuses()); - IllegalArgumentException e1 = assertThrows(IllegalArgumentException.class, () -> parameters.setNominalThresholdIgnoredBuses(-1.2)); + parameters.setMinNominalVoltageIgnoredBus(0); // min value + assertEquals(0, parameters.getMinNominalVoltageIgnoredBus()); + parameters.setMinNominalVoltageIgnoredBus(45); + assertEquals(45, parameters.getMinNominalVoltageIgnoredBus()); + IllegalArgumentException e1 = assertThrows(IllegalArgumentException.class, () -> parameters.setMinNominalVoltageIgnoredBus(-1.2)); assertEquals("Nominal threshold for ignored buses must be defined and >= 0 to be consistent.", e1.getMessage()); - IllegalArgumentException e2 = assertThrows(IllegalArgumentException.class, () -> parameters.setNominalThresholdIgnoredBuses(Double.NaN)); + IllegalArgumentException e2 = assertThrows(IllegalArgumentException.class, () -> parameters.setMinNominalVoltageIgnoredBus(Double.NaN)); assertEquals("Nominal threshold for ignored buses must be defined and >= 0 to be consistent.", e2.getMessage()); - parameters.setNominalThresholdIgnoredVoltageBounds(200); - assertEquals(200, parameters.getNominalThresholdIgnoredVoltageBounds()); - IllegalArgumentException e3 = assertThrows(IllegalArgumentException.class, () -> parameters.setNominalThresholdIgnoredVoltageBounds(-1.2)); + parameters.setMinNominalVoltageIgnoredVoltageBounds(200); + assertEquals(200, parameters.getMinNominalVoltageIgnoredVoltageBounds()); + IllegalArgumentException e3 = assertThrows(IllegalArgumentException.class, () -> parameters.setMinNominalVoltageIgnoredVoltageBounds(-1.2)); assertEquals("Nominal threshold for ignored voltage bounds must be defined and >= 0 to be consistent", e3.getMessage()); - IllegalArgumentException e4 = assertThrows(IllegalArgumentException.class, () -> parameters.setNominalThresholdIgnoredVoltageBounds(Double.NaN)); + IllegalArgumentException e4 = assertThrows(IllegalArgumentException.class, () -> parameters.setMinNominalVoltageIgnoredVoltageBounds(Double.NaN)); assertEquals("Nominal threshold for ignored voltage bounds must be defined and >= 0 to be consistent", e4.getMessage()); assertTrue(parameters.checkAlgorithmParametersIntegrity()); @@ -195,26 +195,26 @@ void testPMinMaxIntegrity() { IllegalArgumentException e3 = assertThrows(IllegalArgumentException.class, () -> parameters.setPQMax(Double.NaN)); assertEquals("Maximal consistency value for P and Q must be defined and > 0 to be consistent", e3.getMessage()); - parameters.setDefaultPMin(1500); - assertEquals(1500, parameters.getDefaultPMin()); - IllegalArgumentException e4 = assertThrows(IllegalArgumentException.class, () -> parameters.setDefaultPMin(-100)); + parameters.setLowActivePowerDefaultLimit(1500); + assertEquals(1500, parameters.getLowActivePowerDefaultLimit()); + IllegalArgumentException e4 = assertThrows(IllegalArgumentException.class, () -> parameters.setLowActivePowerDefaultLimit(-100)); assertEquals("Default P min value must be defined and >= 0 to be consistent.", e4.getMessage()); - IllegalArgumentException e5 = assertThrows(IllegalArgumentException.class, () -> parameters.setDefaultPMin(Double.NaN)); + IllegalArgumentException e5 = assertThrows(IllegalArgumentException.class, () -> parameters.setLowActivePowerDefaultLimit(Double.NaN)); assertEquals("Default P min value must be defined and >= 0 to be consistent.", e5.getMessage()); - parameters.setDefaultPMax(1250); - assertEquals(1250, parameters.getDefaultPMax()); - IllegalArgumentException e6 = assertThrows(IllegalArgumentException.class, () -> parameters.setDefaultPMax(0)); + parameters.setHighActivePowerDefaultLimit(1250); + assertEquals(1250, parameters.getHighActivePowerDefaultLimit()); + IllegalArgumentException e6 = assertThrows(IllegalArgumentException.class, () -> parameters.setHighActivePowerDefaultLimit(0)); assertEquals("Default P max value must be defined and > 0 to be consistent.", e6.getMessage()); - IllegalArgumentException e7 = assertThrows(IllegalArgumentException.class, () -> parameters.setDefaultPMax(-100)); + IllegalArgumentException e7 = assertThrows(IllegalArgumentException.class, () -> parameters.setHighActivePowerDefaultLimit(-100)); assertEquals("Default P max value must be defined and > 0 to be consistent.", e7.getMessage()); - IllegalArgumentException e8 = assertThrows(IllegalArgumentException.class, () -> parameters.setDefaultPMax(Double.NaN)); + IllegalArgumentException e8 = assertThrows(IllegalArgumentException.class, () -> parameters.setHighActivePowerDefaultLimit(Double.NaN)); assertEquals("Default P max value must be defined and > 0 to be consistent.", e8.getMessage()); assertFalse(parameters.checkAlgorithmParametersIntegrity()); // case defaultPmin > defaultPmax - parameters.setDefaultPMax(10000); + parameters.setHighActivePowerDefaultLimit(10000); assertFalse(parameters.checkAlgorithmParametersIntegrity()); // case defaultPmax > pQmax - parameters.setDefaultPMin(50).setDefaultPMax(1000); + parameters.setLowActivePowerDefaultLimit(50).setHighActivePowerDefaultLimit(1000); assertTrue(parameters.checkAlgorithmParametersIntegrity()); } @@ -261,11 +261,11 @@ void testAlgorithmParams() { parameters.setAlphaCoefficient(0.56); parameters.setMinPlausibleActivePowerThreshold(0.5); parameters.setLowImpedanceThreshold(1e-5); - parameters.setNominalThresholdIgnoredBuses(10); - parameters.setNominalThresholdIgnoredVoltageBounds(5); + parameters.setMinNominalVoltageIgnoredBus(10); + parameters.setMinNominalVoltageIgnoredVoltageBounds(5); parameters.setPQMax(8555.3); - parameters.setDefaultPMin(99.2); - parameters.setDefaultPMax(1144); + parameters.setLowActivePowerDefaultLimit(99.2); + parameters.setHighActivePowerDefaultLimit(1144); parameters.setDefaultQmaxPmaxRatio(0.4); parameters.setDefaultMinimalQPRange(1.1); @@ -317,11 +317,11 @@ void testDefaultParametersValuesIntegrity() { assertEquals(1., parameters.getAlphaCoefficient()); assertEquals(0.01, parameters.getMinPlausibleActivePowerThreshold()); assertEquals(1e-4, parameters.getLowImpedanceThreshold()); - assertEquals(1., parameters.getNominalThresholdIgnoredBuses()); - assertEquals(0., parameters.getNominalThresholdIgnoredVoltageBounds()); + assertEquals(1., parameters.getMinNominalVoltageIgnoredBus()); + assertEquals(0., parameters.getMinNominalVoltageIgnoredVoltageBounds()); assertEquals(9000., parameters.getPQMax()); - assertEquals(0, parameters.getDefaultPMin()); - assertEquals(1000., parameters.getDefaultPMax()); + assertEquals(0, parameters.getLowActivePowerDefaultLimit()); + assertEquals(1000., parameters.getHighActivePowerDefaultLimit()); assertEquals(0.3, parameters.getDefaultQmaxPmaxRatio()); assertEquals(1., parameters.getDefaultMinimalQPRange()); assertTrue(parameters.checkAlgorithmParametersIntegrity()); diff --git a/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java b/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java index 5f1f194a..c17a1332 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java @@ -108,11 +108,11 @@ void testModifiedParamAlgoExport() throws IOException { .setAlphaCoefficient(0.88) .setMinPlausibleActivePowerThreshold(0.45) .setLowImpedanceThreshold(1e-5) - .setNominalThresholdIgnoredBuses(2.) - .setNominalThresholdIgnoredVoltageBounds(0.75) + .setMinNominalVoltageIgnoredBus(2.) + .setMinNominalVoltageIgnoredVoltageBounds(0.75) .setPQMax(3987.76) - .setDefaultPMin(12.32) - .setDefaultPMax(1452.66) + .setLowActivePowerDefaultLimit(12.32) + .setHighActivePowerDefaultLimit(1452.66) .setDefaultQmaxPmaxRatio(0.24) .setDefaultMinimalQPRange(2.); diff --git a/open-reac/src/test/java/com/powsybl/openreac/parameters/input/json/OpenReacJsonModuleTest.java b/open-reac/src/test/java/com/powsybl/openreac/parameters/input/json/OpenReacJsonModuleTest.java index f7848486..ecaec185 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/parameters/input/json/OpenReacJsonModuleTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/parameters/input/json/OpenReacJsonModuleTest.java @@ -57,11 +57,11 @@ void test() throws IOException { parameters.setAlphaCoefficient(0.56); parameters.setMinPlausibleActivePowerThreshold(0.5); parameters.setLowImpedanceThreshold(1e-5); - parameters.setNominalThresholdIgnoredBuses(10.); - parameters.setNominalThresholdIgnoredVoltageBounds(5.); + parameters.setMinNominalVoltageIgnoredBus(10.); + parameters.setMinNominalVoltageIgnoredVoltageBounds(5.); parameters.setPQMax(8555.3); - parameters.setDefaultPMin(99.2); - parameters.setDefaultPMax(1144.); + parameters.setLowActivePowerDefaultLimit(99.2); + parameters.setHighActivePowerDefaultLimit(1144.); parameters.setDefaultQmaxPmaxRatio(0.4); parameters.setDefaultMinimalQPRange(1.1); @@ -91,11 +91,11 @@ void test() throws IOException { assertEquals(0.56, parameters2.getAlphaCoefficient()); assertEquals(0.5, parameters2.getMinPlausibleActivePowerThreshold()); assertEquals(1e-5, parameters2.getLowImpedanceThreshold()); - assertEquals(10., parameters2.getNominalThresholdIgnoredBuses()); - assertEquals(5., parameters2.getNominalThresholdIgnoredVoltageBounds()); + assertEquals(10., parameters2.getMinNominalVoltageIgnoredBus()); + assertEquals(5., parameters2.getMinNominalVoltageIgnoredVoltageBounds()); assertEquals(8555.3, parameters2.getPQMax()); - assertEquals(99.2, parameters2.getDefaultPMin()); - assertEquals(1144., parameters2.getDefaultPMax()); + assertEquals(99.2, parameters2.getLowActivePowerDefaultLimit()); + assertEquals(1144., parameters2.getHighActivePowerDefaultLimit()); assertEquals(0.4, parameters2.getDefaultQmaxPmaxRatio()); assertEquals(1.1, parameters2.getDefaultMinimalQPRange()); } diff --git a/open-reac/src/test/resources/parameters.json b/open-reac/src/test/resources/parameters.json index bea6fc9d..5eae794b 100644 --- a/open-reac/src/test/resources/parameters.json +++ b/open-reac/src/test/resources/parameters.json @@ -35,11 +35,11 @@ "alphaCoefficient" : 0.56, "minPlausibleActivePowerThreshold" : 0.5, "lowImpedanceThreshold" : 1.0E-5, - "nominalThresholdIgnoredBuses" : 10.0, - "nominalThresholdIgnoredVoltageBounds" : 5.0, - "pQmax" : 8555.3, - "defaultPMin" : 99.2, - "defaultPMax" : 1144.0, + "minNominalVoltageIgnoredBus" : 10.0, + "minNominalVoltageIgnoredVoltageBounds" : 5.0, + "maxPlausiblePowerLimit" : 8555.3, + "lowActivePowerDefaultLimit" : 99.2, + "highActivePowerDefaultLimit" : 1144.0, "defaultQmaxPmaxRatio" : 0.4, "defaultMinimalQPRange" : 1.1 } \ No newline at end of file From d94cd78a3fb3e7136d700941c8ad17ff62c923be Mon Sep 17 00:00:00 2001 From: parvy Date: Wed, 17 Apr 2024 11:22:18 +0200 Subject: [PATCH 23/26] Update merge. Signed-off-by: parvy --- .../parameters/input/OpenReacParameters.java | 86 +++++++++---------- .../json/OpenReacAlgoParamDeserializer.java | 11 ++- .../json/OpenReacParametersDeserializer.java | 43 +++++----- .../openreac/OpenReacParametersTest.java | 13 +-- 4 files changed, 74 insertions(+), 79 deletions(-) diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java index 9d051be6..bbe2546d 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java @@ -403,6 +403,48 @@ public OpenReacParameters setHighActivePowerDefaultLimit(double highActivePowerD */ public double getLowActivePowerDefaultLimit() { return lowActivePowerDefaultLimit; + } + + public OpenReacParameters setLowActivePowerDefaultLimit(double lowActivePowerDefaultLimit) { + if (Double.isNaN(lowActivePowerDefaultLimit) || lowActivePowerDefaultLimit < 0) { + throw new IllegalArgumentException("Default P min value must be defined and >= 0 to be consistent."); + } + this.lowActivePowerDefaultLimit = lowActivePowerDefaultLimit; + return this; + } + + /** + * @return the ratio used to calculate threshold for corrections of high/low reactive power limits. + */ + public double getDefaultQmaxPmaxRatio() { + return defaultQmaxPmaxRatio; + } + + public OpenReacParameters setDefaultQmaxPmaxRatio(double defaultQmaxPmaxRatio) { + // Qmin/Qmax are computed with this value in OpenReac, can not be zero + if (Double.isNaN(defaultQmaxPmaxRatio) || defaultQmaxPmaxRatio <= 0) { + throw new IllegalArgumentException("Default Qmax and Pmax ratio must be defined and > 0 to be consistent."); + } + this.defaultQmaxPmaxRatio = defaultQmaxPmaxRatio; + return this; + } + + /** + * @return the threshold to fix active (resp. reactive) power of generators with + * active (resp. reactive) power limits that are closer than it. + */ + public double getDefaultMinimalQPRange() { + return defaultMinimalQPRange; + } + + public OpenReacParameters setDefaultMinimalQPRange(double defaultMinimalQPRange) { + if (Double.isNaN(defaultMinimalQPRange) || defaultMinimalQPRange < 0) { + throw new IllegalArgumentException("Default minimal QP range must be defined and >= 0 to be consistent."); + } + this.defaultMinimalQPRange = defaultMinimalQPRange; + return this; + } + /** * @return the default scaling value of all the variables in ACOPF solving. */ @@ -463,50 +505,6 @@ public OpenReacParameters setTwoWindingTransformerRatioVariableScalingFactor(dou return this; } - public List getVariableShuntCompensators() { - return variableShuntCompensators; - } - - public OpenReacParameters setLowActivePowerDefaultLimit(double lowActivePowerDefaultLimit) { - if (Double.isNaN(lowActivePowerDefaultLimit) || lowActivePowerDefaultLimit < 0) { - throw new IllegalArgumentException("Default P min value must be defined and >= 0 to be consistent."); - } - this.lowActivePowerDefaultLimit = lowActivePowerDefaultLimit; - return this; - } - - /** - * @return the ratio used to calculate threshold for corrections of high/low reactive power limits. - */ - public double getDefaultQmaxPmaxRatio() { - return defaultQmaxPmaxRatio; - } - - public OpenReacParameters setDefaultQmaxPmaxRatio(double defaultQmaxPmaxRatio) { - // Qmin/Qmax are computed with this value in OpenReac, can not be zero - if (Double.isNaN(defaultQmaxPmaxRatio) || defaultQmaxPmaxRatio <= 0) { - throw new IllegalArgumentException("Default Qmax and Pmax ratio must be defined and > 0 to be consistent."); - } - this.defaultQmaxPmaxRatio = defaultQmaxPmaxRatio; - return this; - } - - /** - * @return the threshold to fix active (resp. reactive) power of generators with - * active (resp. reactive) power limits that are closer than it. - */ - public double getDefaultMinimalQPRange() { - return defaultMinimalQPRange; - } - - public OpenReacParameters setDefaultMinimalQPRange(double defaultMinimalQPRange) { - if (Double.isNaN(defaultMinimalQPRange) || defaultMinimalQPRange < 0) { - throw new IllegalArgumentException("Default minimal QP range must be defined and >= 0 to be consistent."); - } - this.defaultMinimalQPRange = defaultMinimalQPRange; - return this; - } - public List getAllAlgorithmParams() { ArrayList allAlgoParams = new ArrayList<>(); allAlgoParams.add(objective.toParam()); diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacAlgoParamDeserializer.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacAlgoParamDeserializer.java index 53d7c8a7..4a91d551 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacAlgoParamDeserializer.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacAlgoParamDeserializer.java @@ -30,16 +30,15 @@ public OpenReacAlgoParam deserialize(JsonParser parser, DeserializationContext d String value = null; while (parser.nextToken() != JsonToken.END_OBJECT) { switch (parser.getCurrentName()) { - case "name": + case "name" -> { parser.nextToken(); name = parser.getText(); - break; - case "value": + } + case "value" -> { parser.nextToken(); value = parser.getText(); - break; - default: - throw new IllegalStateException("Unexpected field: " + parser.getCurrentName()); + } + default -> throw new IllegalStateException("Unexpected field: " + parser.getCurrentName()); } } return new OpenReacAlgoParamImpl(name, value); diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersDeserializer.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersDeserializer.java index 5ffe0e36..718bc6df 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersDeserializer.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersDeserializer.java @@ -90,49 +90,46 @@ public OpenReacParameters deserialize(JsonParser parser, DeserializationContext case "reactiveSlackBusesMode" -> { parser.nextToken(); parameters.setReactiveSlackBusesMode(ReactiveSlackBusesMode.valueOf(parser.getText())); - break; - case "alphaCoefficient": + } + case "alphaCoefficient" -> { parser.nextToken(); parameters.setAlphaCoefficient(parser.getValueAsDouble()); - break; - case "minPlausibleActivePowerThreshold": + } + case "minPlausibleActivePowerThreshold" -> { parser.nextToken(); parameters.setMinPlausibleActivePowerThreshold(parser.getValueAsDouble()); - break; - case "lowImpedanceThreshold": + } + case "lowImpedanceThreshold" -> { parser.nextToken(); parameters.setLowImpedanceThreshold(parser.getValueAsDouble()); - break; - case "minNominalVoltageIgnoredBus": + } + case "minNominalVoltageIgnoredBus" -> { parser.nextToken(); parameters.setMinNominalVoltageIgnoredBus(parser.getValueAsDouble()); - break; - case "minNominalVoltageIgnoredVoltageBounds": + } + case "minNominalVoltageIgnoredVoltageBounds" -> { parser.nextToken(); parameters.setMinNominalVoltageIgnoredVoltageBounds(parser.getValueAsDouble()); - break; - case "maxPlausiblePowerLimit": + } + case "maxPlausiblePowerLimit" -> { parser.nextToken(); parameters.setPQMax(parser.getValueAsDouble()); - break; - case "lowActivePowerDefaultLimit": + } + case "lowActivePowerDefaultLimit" -> { parser.nextToken(); parameters.setLowActivePowerDefaultLimit(parser.getValueAsDouble()); - break; - case "highActivePowerDefaultLimit": + } + case "highActivePowerDefaultLimit" -> { parser.nextToken(); parameters.setHighActivePowerDefaultLimit(parser.getValueAsDouble()); - break; - case "defaultQmaxPmaxRatio": + } + case "defaultQmaxPmaxRatio" -> { parser.nextToken(); parameters.setDefaultQmaxPmaxRatio(parser.getValueAsDouble()); - break; - case "defaultMinimalQPRange": + } + case "defaultMinimalQPRange" -> { parser.nextToken(); parameters.setDefaultMinimalQPRange(parser.getValueAsDouble()); - break; - default: - throw new IllegalStateException("Unexpected field: " + parser.getCurrentName()); } case "defaultVariableScalingFactor" -> { parser.nextToken(); diff --git a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java index 47286f66..c3685e99 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java @@ -326,7 +326,7 @@ void testAlgorithmParams() { parameters.setTwoWindingTransformerRatioVariableScalingFactor(0.0001); List algoParams = parameters.getAllAlgorithmParams(); - assertEquals(17, algoParams.size()); + assertEquals(21, algoParams.size()); assertEquals("2", algoParams.get(0).getValue()); assertEquals("0.4", algoParams.get(1).getValue()); assertEquals("DEBUG", algoParams.get(2).getValue()); @@ -344,10 +344,10 @@ void testAlgorithmParams() { assertEquals("1144.0", algoParams.get(14).getValue()); assertEquals("0.4", algoParams.get(15).getValue()); assertEquals("1.1", algoParams.get(16).getValue()); - assertEquals("0.5", algoParams.get(7).getValue()); - assertEquals("0.75", algoParams.get(8).getValue()); - assertEquals("0.01", algoParams.get(9).getValue()); - assertEquals("1.0E-4", algoParams.get(10).getValue()); + assertEquals("0.5", algoParams.get(17).getValue()); + assertEquals("0.75", algoParams.get(18).getValue()); + assertEquals("0.01", algoParams.get(19).getValue()); + assertEquals("1.0E-4", algoParams.get(20).getValue()); } @Test @@ -384,6 +384,7 @@ void testDefaultParametersValuesIntegrity() { assertEquals(1000., parameters.getHighActivePowerDefaultLimit()); assertEquals(0.3, parameters.getDefaultQmaxPmaxRatio()); assertEquals(1., parameters.getDefaultMinimalQPRange()); + // TODO : add cases for scaling values assertTrue(parameters.checkAlgorithmParametersIntegrity()); } @@ -396,7 +397,7 @@ void testDefaultParametersListsIntegrity() { 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.getConfiguredReactiveSlackBuses().size(), "ConfiguredReactiveSlackBuses should be empty when using default OpenREacParameter constructor."); - assertEquals(16, parameters.getAllAlgorithmParams().size()); + assertEquals(20, parameters.getAllAlgorithmParams().size()); } @Test From 599e59d41328eff5f0f7734b7d1b2576ce44dd68 Mon Sep 17 00:00:00 2001 From: parvy Date: Wed, 17 Apr 2024 11:28:23 +0200 Subject: [PATCH 24/26] Revert modifications on ParamAlgoDeserializer. Signed-off-by: parvy --- .../input/json/OpenReacAlgoParamDeserializer.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacAlgoParamDeserializer.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacAlgoParamDeserializer.java index 4a91d551..53d7c8a7 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacAlgoParamDeserializer.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacAlgoParamDeserializer.java @@ -30,15 +30,16 @@ public OpenReacAlgoParam deserialize(JsonParser parser, DeserializationContext d String value = null; while (parser.nextToken() != JsonToken.END_OBJECT) { switch (parser.getCurrentName()) { - case "name" -> { + case "name": parser.nextToken(); name = parser.getText(); - } - case "value" -> { + break; + case "value": parser.nextToken(); value = parser.getText(); - } - default -> throw new IllegalStateException("Unexpected field: " + parser.getCurrentName()); + break; + default: + throw new IllegalStateException("Unexpected field: " + parser.getCurrentName()); } } return new OpenReacAlgoParamImpl(name, value); From b49014d9699967d84cbf32f87198eb9653cfbbde Mon Sep 17 00:00:00 2001 From: parvy Date: Wed, 17 Apr 2024 11:38:47 +0200 Subject: [PATCH 25/26] Refactor json tests to fix code smell. Signed-off-by: parvy --- .../input/json/OpenReacJsonModuleTest.java | 58 ++++++++++++------- .../{parameters.json => parametersLists.json} | 37 ++++++------ .../test/resources/parametersThresholds.json | 28 +++++++++ 3 files changed, 83 insertions(+), 40 deletions(-) rename open-reac/src/test/resources/{parameters.json => parametersLists.json} (52%) create mode 100644 open-reac/src/test/resources/parametersThresholds.json diff --git a/open-reac/src/test/java/com/powsybl/openreac/parameters/input/json/OpenReacJsonModuleTest.java b/open-reac/src/test/java/com/powsybl/openreac/parameters/input/json/OpenReacJsonModuleTest.java index ed9e0b92..bc6e5fc7 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/parameters/input/json/OpenReacJsonModuleTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/parameters/input/json/OpenReacJsonModuleTest.java @@ -30,7 +30,7 @@ class OpenReacJsonModuleTest { @Test - void test() throws IOException { + void testOpenReacParametersLists() throws IOException { ObjectMapper objectMapper = JsonUtil.createObjectMapper() .registerModule(new OpenReactJsonModule()); OpenReacParameters parameters = new OpenReacParameters(); @@ -47,17 +47,41 @@ void test() throws IOException { parameters.addConstantQGenerators(List.of("g1", "g2")); parameters.addVariableTwoWindingsTransformers(List.of("tr1")); parameters.addVariableShuntCompensators(List.of("sc1", "sc2")); + parameters.setReactiveSlackBusesMode(ReactiveSlackBusesMode.CONFIGURED); + parameters.addConfiguredReactiveSlackBuses(List.of("bus1", "bus2")); + + String json = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(parameters); + ComparisonUtils.compareTxt(Objects.requireNonNull(getClass().getResourceAsStream("/parametersLists.json")), json); + + OpenReacParameters parameters2 = objectMapper.readValue(json, OpenReacParameters.class); + // List of voltage limit overrides + List vloList2 = new ArrayList<>(); + vloList2.add(new VoltageLimitOverride("foo", VoltageLimitOverride.VoltageLimitType.LOW_VOLTAGE_LIMIT, true, -1)); + vloList2.add(new VoltageLimitOverride("foo", VoltageLimitOverride.VoltageLimitType.HIGH_VOLTAGE_LIMIT, true, 2)); + vloList2.add(new VoltageLimitOverride("bar", VoltageLimitOverride.VoltageLimitType.LOW_VOLTAGE_LIMIT, false, 20)); + vloList2.add(new VoltageLimitOverride("bar", VoltageLimitOverride.VoltageLimitType.HIGH_VOLTAGE_LIMIT, false, 26)); + + assertEquals(vloList2, parameters2.getSpecificVoltageLimits()); + assertEquals(List.of("g1", "g2"), parameters2.getConstantQGenerators()); + assertEquals(List.of("tr1"), parameters2.getVariableTwoWindingsTransformers()); + assertEquals(List.of("sc1", "sc2"), parameters2.getVariableShuntCompensators()); + assertEquals(ReactiveSlackBusesMode.CONFIGURED, parameters2.getReactiveSlackBusesMode()); + assertEquals(List.of("bus1", "bus2"), parameters2.getConfiguredReactiveSlackBuses()); + } + + @Test + void testOpenReacParametersThresholds() throws IOException { + ObjectMapper objectMapper = JsonUtil.createObjectMapper() + .registerModule(new OpenReactJsonModule()); + OpenReacParameters parameters = new OpenReacParameters(); + + // modify open reac parameters parameters.setObjectiveDistance(5); parameters.setLogLevelAmpl(OpenReacAmplLogLevel.WARNING); parameters.setLogLevelSolver(OpenReacSolverLogLevel.NOTHING); parameters.setMinPlausibleLowVoltageLimit(0.755); parameters.setMaxPlausibleHighVoltageLimit(1.236); - parameters.setReactiveSlackBusesMode(ReactiveSlackBusesMode.CONFIGURED); - parameters.setDefaultVariableScalingFactor(0.756); - parameters.setDefaultConstraintScalingFactor(0.888); - parameters.setReactiveSlackVariableScalingFactor(1e-2); - parameters.setTwoWindingTransformerRatioVariableScalingFactor(0.005); - parameters.addConfiguredReactiveSlackBuses(List.of("bus1", "bus2")); + parameters.setReactiveSlackBusesMode(ReactiveSlackBusesMode.ALL); parameters.setAlphaCoefficient(0.56); parameters.setMinPlausibleActivePowerThreshold(0.5); parameters.setLowImpedanceThreshold(1e-5); @@ -68,29 +92,21 @@ void test() throws IOException { parameters.setHighActivePowerDefaultLimit(1144.); parameters.setDefaultQmaxPmaxRatio(0.4); parameters.setDefaultMinimalQPRange(1.1); + parameters.setDefaultVariableScalingFactor(0.756); + parameters.setDefaultConstraintScalingFactor(0.888); + parameters.setReactiveSlackVariableScalingFactor(1e-2); + parameters.setTwoWindingTransformerRatioVariableScalingFactor(0.005); String json = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(parameters); - ComparisonUtils.compareTxt(Objects.requireNonNull(getClass().getResourceAsStream("/parameters.json")), json); - + ComparisonUtils.compareTxt(Objects.requireNonNull(getClass().getResourceAsStream("/parametersThresholds.json")), json); OpenReacParameters parameters2 = objectMapper.readValue(json, OpenReacParameters.class); - // List of voltage limit overrides - List vloList2 = new ArrayList<>(); - vloList2.add(new VoltageLimitOverride("foo", VoltageLimitOverride.VoltageLimitType.LOW_VOLTAGE_LIMIT, true, -1)); - vloList2.add(new VoltageLimitOverride("foo", VoltageLimitOverride.VoltageLimitType.HIGH_VOLTAGE_LIMIT, true, 2)); - vloList2.add(new VoltageLimitOverride("bar", VoltageLimitOverride.VoltageLimitType.LOW_VOLTAGE_LIMIT, false, 20)); - vloList2.add(new VoltageLimitOverride("bar", VoltageLimitOverride.VoltageLimitType.HIGH_VOLTAGE_LIMIT, false, 26)); - assertEquals(vloList2, parameters2.getSpecificVoltageLimits()); - assertEquals(List.of("g1", "g2"), parameters2.getConstantQGenerators()); - assertEquals(List.of("tr1"), parameters2.getVariableTwoWindingsTransformers()); - assertEquals(List.of("bus1", "bus2"), parameters2.getConfiguredReactiveSlackBuses()); - assertEquals(List.of("sc1", "sc2"), parameters2.getVariableShuntCompensators()); assertEquals(5, parameters2.getObjectiveDistance()); assertEquals(OpenReacAmplLogLevel.WARNING, parameters2.getLogLevelAmpl()); assertEquals(OpenReacSolverLogLevel.NOTHING, parameters2.getLogLevelSolver()); assertEquals(0.755, parameters2.getMinPlausibleLowVoltageLimit()); assertEquals(1.236, parameters2.getMaxPlausibleHighVoltageLimit()); - assertEquals(ReactiveSlackBusesMode.CONFIGURED, parameters2.getReactiveSlackBusesMode()); + assertEquals(ReactiveSlackBusesMode.ALL, parameters2.getReactiveSlackBusesMode()); assertEquals(OpenReacOptimisationObjective.MIN_GENERATION, parameters2.getObjective()); assertEquals(0.56, parameters2.getAlphaCoefficient()); assertEquals(0.5, parameters2.getMinPlausibleActivePowerThreshold()); diff --git a/open-reac/src/test/resources/parameters.json b/open-reac/src/test/resources/parametersLists.json similarity index 52% rename from open-reac/src/test/resources/parameters.json rename to open-reac/src/test/resources/parametersLists.json index d58ba0b2..6f52029d 100644 --- a/open-reac/src/test/resources/parameters.json +++ b/open-reac/src/test/resources/parametersLists.json @@ -26,24 +26,23 @@ "variableShuntCompensators" : [ "sc1", "sc2" ], "configuredReactiveSlackBuses" : [ "bus1", "bus2" ], "objective" : "MIN_GENERATION", - "objectiveDistance" : 5.0, - "logLevelAmpl" : "WARNING", - "logLevelSolver" : "NOTHING", - "minPlausibleLowVoltageLimit" : 0.755, - "maxPlausibleHighVoltageLimit" : 1.236, + "logLevelAmpl" : "INFO", + "logLevelSolver" : "EVERYTHING", + "minPlausibleLowVoltageLimit" : 0.5, + "maxPlausibleHighVoltageLimit" : 1.5, "reactiveSlackBusesMode" : "CONFIGURED", - "alphaCoefficient" : 0.56, - "minPlausibleActivePowerThreshold" : 0.5, - "lowImpedanceThreshold" : 1.0E-5, - "minNominalVoltageIgnoredBus" : 10.0, - "minNominalVoltageIgnoredVoltageBounds" : 5.0, - "maxPlausiblePowerLimit" : 8555.3, - "lowActivePowerDefaultLimit" : 99.2, - "highActivePowerDefaultLimit" : 1144.0, - "defaultQmaxPmaxRatio" : 0.4, - "defaultMinimalQPRange" : 1.1, - "defaultVariableScalingFactor" : 0.756, - "defaultConstraintScalingFactor" : 0.888, - "reactiveSlackVariableScalingFactor" : 0.01, - "twoWindingTransformerRatioVariableScalingFactor" : 0.005 + "alphaCoefficient" : 1.0, + "minPlausibleActivePowerThreshold" : 0.01, + "lowImpedanceThreshold" : 1.0E-4, + "minNominalVoltageIgnoredBus" : 1.0, + "minNominalVoltageIgnoredVoltageBounds" : 0.0, + "maxPlausiblePowerLimit" : 9000.0, + "lowActivePowerDefaultLimit" : 0.0, + "highActivePowerDefaultLimit" : 1000.0, + "defaultQmaxPmaxRatio" : 0.3, + "defaultMinimalQPRange" : 1.0, + "defaultVariableScalingFactor" : 1.0, + "defaultConstraintScalingFactor" : 1.0, + "reactiveSlackVariableScalingFactor" : 0.1, + "twoWindingTransformerRatioVariableScalingFactor" : 0.001 } \ No newline at end of file diff --git a/open-reac/src/test/resources/parametersThresholds.json b/open-reac/src/test/resources/parametersThresholds.json new file mode 100644 index 00000000..2b198078 --- /dev/null +++ b/open-reac/src/test/resources/parametersThresholds.json @@ -0,0 +1,28 @@ +{ + "version" : "1.0", + "specificVoltageLimits" : [ ], + "constantQGenerators" : [ ], + "variableTwoWindingsTransformers" : [ ], + "variableShuntCompensators" : [ ], + "objective" : "MIN_GENERATION", + "objectiveDistance" : 5.0, + "logLevelAmpl" : "WARNING", + "logLevelSolver" : "NOTHING", + "minPlausibleLowVoltageLimit" : 0.755, + "maxPlausibleHighVoltageLimit" : 1.236, + "reactiveSlackBusesMode" : "ALL", + "alphaCoefficient" : 0.56, + "minPlausibleActivePowerThreshold" : 0.5, + "lowImpedanceThreshold" : 1.0E-5, + "minNominalVoltageIgnoredBus" : 10.0, + "minNominalVoltageIgnoredVoltageBounds" : 5.0, + "maxPlausiblePowerLimit" : 8555.3, + "lowActivePowerDefaultLimit" : 99.2, + "highActivePowerDefaultLimit" : 1144.0, + "defaultQmaxPmaxRatio" : 0.4, + "defaultMinimalQPRange" : 1.1, + "defaultVariableScalingFactor" : 0.756, + "defaultConstraintScalingFactor" : 0.888, + "reactiveSlackVariableScalingFactor" : 0.01, + "twoWindingTransformerRatioVariableScalingFactor" : 0.005 +} \ No newline at end of file From 325c6fe83a03c7732c37ae81becdccd917c60358 Mon Sep 17 00:00:00 2001 From: parvy Date: Thu, 18 Apr 2024 11:32:59 +0200 Subject: [PATCH 26/26] Refactor alphaCoefficient parameter into activePowerVariationRate. Signed-off-by: parvy --- .../parameters/input/OpenReacParameters.java | 18 ++++++------ .../json/OpenReacParametersDeserializer.java | 4 +-- .../json/OpenReacParametersSerializer.java | 2 +- .../openreac/OpenReacParametersTest.java | 28 +++++++++---------- .../powsybl/openreac/OpenReacRunnerTest.java | 2 +- .../input/json/OpenReacJsonModuleTest.java | 4 +-- .../src/test/resources/parametersLists.json | 2 +- .../test/resources/parametersThresholds.json | 2 +- 8 files changed, 31 insertions(+), 31 deletions(-) diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java index bbe2546d..dda19ae1 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/OpenReacParameters.java @@ -58,9 +58,9 @@ public class OpenReacParameters { private ReactiveSlackBusesMode reactiveSlackBusesMode = ReactiveSlackBusesMode.NO_GENERATION; - private static final String ALPHA_COEFFICIENT_KEY = "coeff_alpha"; + private static final String ACTIVE_POWER_VARIATION_RATE_KEY = "coeff_alpha"; - private double alphaCoefficient = 1; // in [0;1] + private double activePowerVariationRate = 1; // in [0;1] private static final String MIN_PLAUSIBLE_ACTIVE_POWER_THRESHOLD_KEY = "Pnull"; @@ -295,15 +295,15 @@ public OpenReacParameters setReactiveSlackBusesMode(ReactiveSlackBusesMode react /** * @return the weight to favor more/less minimization of active power produced by generators. */ - public double getAlphaCoefficient() { - return alphaCoefficient; + public double getActivePowerVariationRate() { + return activePowerVariationRate; } - public OpenReacParameters setAlphaCoefficient(double alphaCoefficient) { - if (Double.isNaN(alphaCoefficient) || alphaCoefficient < 0 || alphaCoefficient > 1) { - throw new IllegalArgumentException("Coefficient alpha parameter must be defined and between 0 and 1 to be consistent."); + public OpenReacParameters setActivePowerVariationRate(double activePowerVariationRate) { + if (Double.isNaN(activePowerVariationRate) || activePowerVariationRate < 0 || activePowerVariationRate > 1) { + throw new IllegalArgumentException("Active power variation rate must be defined and between 0 and 1 to be consistent."); } - this.alphaCoefficient = alphaCoefficient; + this.activePowerVariationRate = activePowerVariationRate; return this; } @@ -516,7 +516,7 @@ public List getAllAlgorithmParams() { 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(reactiveSlackBusesMode.toParam()); - allAlgoParams.add(new OpenReacAlgoParamImpl(ALPHA_COEFFICIENT_KEY, Double.toString(alphaCoefficient))); + allAlgoParams.add(new OpenReacAlgoParamImpl(ACTIVE_POWER_VARIATION_RATE_KEY, Double.toString(activePowerVariationRate))); allAlgoParams.add(new OpenReacAlgoParamImpl(MIN_PLAUSIBLE_ACTIVE_POWER_THRESHOLD_KEY, Double.toString(minPlausibleActivePowerThreshold))); allAlgoParams.add(new OpenReacAlgoParamImpl(LOW_IMPEDANCE_THRESHOLD_KEY, Double.toString(lowImpedanceThreshold))); allAlgoParams.add(new OpenReacAlgoParamImpl(MIN_NOMINAL_VOLTAGE_IGNORED_BUS_KEY, Double.toString(minNominalVoltageIgnoredBus))); diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersDeserializer.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersDeserializer.java index 718bc6df..cc98a602 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersDeserializer.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersDeserializer.java @@ -91,9 +91,9 @@ public OpenReacParameters deserialize(JsonParser parser, DeserializationContext parser.nextToken(); parameters.setReactiveSlackBusesMode(ReactiveSlackBusesMode.valueOf(parser.getText())); } - case "alphaCoefficient" -> { + case "activePowerVariationRate" -> { parser.nextToken(); - parameters.setAlphaCoefficient(parser.getValueAsDouble()); + parameters.setActivePowerVariationRate(parser.getValueAsDouble()); } case "minPlausibleActivePowerThreshold" -> { parser.nextToken(); diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersSerializer.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersSerializer.java index d99f388a..a92fad26 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersSerializer.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/input/json/OpenReacParametersSerializer.java @@ -47,7 +47,7 @@ public void serialize(OpenReacParameters openReacParameters, JsonGenerator jsonG serializerProvider.defaultSerializeField("minPlausibleLowVoltageLimit", openReacParameters.getMinPlausibleLowVoltageLimit(), jsonGenerator); serializerProvider.defaultSerializeField("maxPlausibleHighVoltageLimit", openReacParameters.getMaxPlausibleHighVoltageLimit(), jsonGenerator); serializerProvider.defaultSerializeField("reactiveSlackBusesMode", openReacParameters.getReactiveSlackBusesMode().name(), jsonGenerator); - serializerProvider.defaultSerializeField("alphaCoefficient", openReacParameters.getAlphaCoefficient(), jsonGenerator); + serializerProvider.defaultSerializeField("activePowerVariationRate", openReacParameters.getActivePowerVariationRate(), jsonGenerator); serializerProvider.defaultSerializeField("minPlausibleActivePowerThreshold", openReacParameters.getMinPlausibleActivePowerThreshold(), jsonGenerator); serializerProvider.defaultSerializeField("lowImpedanceThreshold", openReacParameters.getLowImpedanceThreshold(), jsonGenerator); serializerProvider.defaultSerializeField("minNominalVoltageIgnoredBus", openReacParameters.getMinNominalVoltageIgnoredBus(), jsonGenerator); diff --git a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java index c3685e99..f4ac0859 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/OpenReacParametersTest.java @@ -116,19 +116,19 @@ void testMinMaxVoltageLimitIntegrity() { } @Test - void testAlphaCoefficientIntegrity() { + void testActivePowerVariationRateIntegrity() { OpenReacParameters parameters = new OpenReacParameters(); - parameters.setAlphaCoefficient(0); // min value - assertEquals(0., parameters.getAlphaCoefficient()); - parameters.setAlphaCoefficient(0.445556); - assertEquals(0.445556, parameters.getAlphaCoefficient()); - - IllegalArgumentException e1 = assertThrows(IllegalArgumentException.class, () -> parameters.setAlphaCoefficient(-1.2)); - assertEquals("Coefficient alpha parameter must be defined and between 0 and 1 to be consistent.", e1.getMessage()); - IllegalArgumentException e2 = assertThrows(IllegalArgumentException.class, () -> parameters.setAlphaCoefficient(42)); - assertEquals("Coefficient alpha parameter must be defined and between 0 and 1 to be consistent.", e2.getMessage()); - IllegalArgumentException e3 = assertThrows(IllegalArgumentException.class, () -> parameters.setAlphaCoefficient(Double.NaN)); - assertEquals("Coefficient alpha parameter must be defined and between 0 and 1 to be consistent.", e3.getMessage()); + parameters.setActivePowerVariationRate(0); // min value + assertEquals(0., parameters.getActivePowerVariationRate()); + parameters.setActivePowerVariationRate(0.445556); + assertEquals(0.445556, parameters.getActivePowerVariationRate()); + + IllegalArgumentException e1 = assertThrows(IllegalArgumentException.class, () -> parameters.setActivePowerVariationRate(-1.2)); + assertEquals("Active power variation rate must be defined and between 0 and 1 to be consistent.", e1.getMessage()); + IllegalArgumentException e2 = assertThrows(IllegalArgumentException.class, () -> parameters.setActivePowerVariationRate(42)); + assertEquals("Active power variation rate must be defined and between 0 and 1 to be consistent.", e2.getMessage()); + IllegalArgumentException e3 = assertThrows(IllegalArgumentException.class, () -> parameters.setActivePowerVariationRate(Double.NaN)); + assertEquals("Active power variation rate must be defined and between 0 and 1 to be consistent.", e3.getMessage()); assertTrue(parameters.checkAlgorithmParametersIntegrity()); } @@ -310,7 +310,7 @@ void testAlgorithmParams() { parameters.setMinPlausibleLowVoltageLimit(0.8); parameters.setMaxPlausibleHighVoltageLimit(1.2); parameters.setReactiveSlackBusesMode(ReactiveSlackBusesMode.ALL); - parameters.setAlphaCoefficient(0.56); + parameters.setActivePowerVariationRate(0.56); parameters.setMinPlausibleActivePowerThreshold(0.5); parameters.setLowImpedanceThreshold(1e-5); parameters.setMinNominalVoltageIgnoredBus(10); @@ -374,7 +374,7 @@ void testDefaultParametersValuesIntegrity() { assertEquals(0.5, parameters.getMinPlausibleLowVoltageLimit()); assertEquals(1.5, parameters.getMaxPlausibleHighVoltageLimit()); assertEquals(ReactiveSlackBusesMode.NO_GENERATION, parameters.getReactiveSlackBusesMode()); - assertEquals(1., parameters.getAlphaCoefficient()); + assertEquals(1., parameters.getActivePowerVariationRate()); assertEquals(0.01, parameters.getMinPlausibleActivePowerThreshold()); assertEquals(1e-4, parameters.getLowImpedanceThreshold()); assertEquals(1., parameters.getMinNominalVoltageIgnoredBus()); diff --git a/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java b/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java index ad3537e2..dc6c43a5 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java @@ -105,7 +105,7 @@ void testModifiedParamAlgoExport() throws IOException { .setMinPlausibleLowVoltageLimit(0.7888) .setMaxPlausibleHighVoltageLimit(1.3455) .setReactiveSlackBusesMode(ReactiveSlackBusesMode.ALL) - .setAlphaCoefficient(0.88) + .setActivePowerVariationRate(0.88) .setMinPlausibleActivePowerThreshold(0.45) .setLowImpedanceThreshold(1e-5) .setMinNominalVoltageIgnoredBus(2.) diff --git a/open-reac/src/test/java/com/powsybl/openreac/parameters/input/json/OpenReacJsonModuleTest.java b/open-reac/src/test/java/com/powsybl/openreac/parameters/input/json/OpenReacJsonModuleTest.java index bc6e5fc7..eeb19c96 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/parameters/input/json/OpenReacJsonModuleTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/parameters/input/json/OpenReacJsonModuleTest.java @@ -82,7 +82,7 @@ void testOpenReacParametersThresholds() throws IOException { parameters.setMinPlausibleLowVoltageLimit(0.755); parameters.setMaxPlausibleHighVoltageLimit(1.236); parameters.setReactiveSlackBusesMode(ReactiveSlackBusesMode.ALL); - parameters.setAlphaCoefficient(0.56); + parameters.setActivePowerVariationRate(0.56); parameters.setMinPlausibleActivePowerThreshold(0.5); parameters.setLowImpedanceThreshold(1e-5); parameters.setMinNominalVoltageIgnoredBus(10.); @@ -108,7 +108,7 @@ void testOpenReacParametersThresholds() throws IOException { assertEquals(1.236, parameters2.getMaxPlausibleHighVoltageLimit()); assertEquals(ReactiveSlackBusesMode.ALL, parameters2.getReactiveSlackBusesMode()); assertEquals(OpenReacOptimisationObjective.MIN_GENERATION, parameters2.getObjective()); - assertEquals(0.56, parameters2.getAlphaCoefficient()); + assertEquals(0.56, parameters2.getActivePowerVariationRate()); assertEquals(0.5, parameters2.getMinPlausibleActivePowerThreshold()); assertEquals(1e-5, parameters2.getLowImpedanceThreshold()); assertEquals(10., parameters2.getMinNominalVoltageIgnoredBus()); diff --git a/open-reac/src/test/resources/parametersLists.json b/open-reac/src/test/resources/parametersLists.json index 6f52029d..79ffbc86 100644 --- a/open-reac/src/test/resources/parametersLists.json +++ b/open-reac/src/test/resources/parametersLists.json @@ -31,7 +31,7 @@ "minPlausibleLowVoltageLimit" : 0.5, "maxPlausibleHighVoltageLimit" : 1.5, "reactiveSlackBusesMode" : "CONFIGURED", - "alphaCoefficient" : 1.0, + "activePowerVariationRate" : 1.0, "minPlausibleActivePowerThreshold" : 0.01, "lowImpedanceThreshold" : 1.0E-4, "minNominalVoltageIgnoredBus" : 1.0, diff --git a/open-reac/src/test/resources/parametersThresholds.json b/open-reac/src/test/resources/parametersThresholds.json index 2b198078..1fcece0c 100644 --- a/open-reac/src/test/resources/parametersThresholds.json +++ b/open-reac/src/test/resources/parametersThresholds.json @@ -11,7 +11,7 @@ "minPlausibleLowVoltageLimit" : 0.755, "maxPlausibleHighVoltageLimit" : 1.236, "reactiveSlackBusesMode" : "ALL", - "alphaCoefficient" : 0.56, + "activePowerVariationRate" : 0.56, "minPlausibleActivePowerThreshold" : 0.5, "lowImpedanceThreshold" : 1.0E-5, "minNominalVoltageIgnoredBus" : 10.0,