diff --git a/open-reac/src/test/java/com/powsybl/openreac/optimization/AbstractOpenReacRunnerTest.java b/open-reac/src/test/java/com/powsybl/openreac/optimization/AbstractOpenReacRunnerTest.java index 52dab131..0ef48f70 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/optimization/AbstractOpenReacRunnerTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/optimization/AbstractOpenReacRunnerTest.java @@ -12,7 +12,6 @@ import com.powsybl.commons.test.ComparisonUtils; import com.powsybl.computation.ComputationManager; import com.powsybl.computation.local.LocalCommandExecutor; -import com.powsybl.computation.local.LocalComputationConfig; import com.powsybl.computation.local.LocalComputationManager; import com.powsybl.iidm.network.*; import com.powsybl.loadflow.LoadFlow; @@ -92,6 +91,13 @@ protected void runAndApplyAllModifications(Network network, String subFolder, Op openReacResult.applyAllModifications(network); } + /** + * Runs OpenReac and returns associated result. + */ + protected OpenReacResult runOpenReac(Network network, String subFolder) throws IOException { + return runOpenReac(network, subFolder, new OpenReacParameters(), ReportNode.NO_OP); + } + /** * Runs OpenReac and returns associated result. * Note that OpenReac is not really executed by default. If the execution line is not uncommented, @@ -109,9 +115,9 @@ protected OpenReacResult runOpenReac(Network network, String subFolder, OpenReac subFolder + "/reactiveopf_results_vsc_converter_stations.csv", subFolder + "/reactiveopf_results_voltages.csv")); // To really run open reac, use the commentede line below. Be sure that open-reac/src/test/resources/com/powsybl/config/test/config.yml contains your ampl path -// try (ComputationManager computationManager = new LocalComputationManager()) { - try (ComputationManager computationManager = new LocalComputationManager(new LocalComputationConfig(tmpDir), - localCommandExecutor, ForkJoinPool.commonPool())) { + try (ComputationManager computationManager = new LocalComputationManager()) { +// try (ComputationManager computationManager = new LocalComputationManager(new LocalComputationConfig(tmpDir), +// localCommandExecutor, ForkJoinPool.commonPool())) { return OpenReacRunner.run(network, network.getVariantManager().getWorkingVariantId(), parameters, new OpenReacConfig(true), computationManager, reportNode, null); } diff --git a/open-reac/src/test/java/com/powsybl/openreac/optimization/OpenReacOptimizationTest.java b/open-reac/src/test/java/com/powsybl/openreac/optimization/OpenReacOptimizationAndLoadFlowTest.java similarity index 97% rename from open-reac/src/test/java/com/powsybl/openreac/optimization/OpenReacOptimizationTest.java rename to open-reac/src/test/java/com/powsybl/openreac/optimization/OpenReacOptimizationAndLoadFlowTest.java index b7a2ff18..fa431d9e 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/optimization/OpenReacOptimizationTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/optimization/OpenReacOptimizationAndLoadFlowTest.java @@ -14,6 +14,8 @@ import com.powsybl.computation.local.LocalComputationManager; import com.powsybl.ieeecdf.converter.IeeeCdfNetworkFactory; import com.powsybl.iidm.network.*; +import com.powsybl.loadflow.LoadFlow; +import com.powsybl.loadflow.LoadFlowResult; import com.powsybl.openreac.OpenReacConfig; import com.powsybl.openreac.OpenReacRunner; import com.powsybl.openreac.network.HvdcNetworkFactory; @@ -36,7 +38,7 @@ * @author Geoffroy Jamgotchian {@literal } * @author Nicolas PIERRE {@literal } */ -public class OpenReacOptimizationTest extends AbstractOpenReacRunnerTest { +public class OpenReacOptimizationAndLoadFlowTest extends AbstractOpenReacRunnerTest { @Test void testRunAsync() throws IOException { @@ -187,6 +189,9 @@ void testWarmStart() throws IOException { assertEquals(0, network.getBusBreakerView().getBus("BUS_2").getAngle()); assertEquals(22.935, network.getBusBreakerView().getBus("BUS_3").getV()); assertEquals(-4.698, network.getBusBreakerView().getBus("BUS_3").getAngle(), 0.001); + + LoadFlowResult loadFlowResult = LoadFlow.run(network); + assertTrue(loadFlowResult.isFullyConverged()); } public static Network create() { diff --git a/open-reac/src/test/java/com/powsybl/openreac/optimization/OpenReacOptimizationIndicatorsTest.java b/open-reac/src/test/java/com/powsybl/openreac/optimization/OpenReacOptimizationIndicatorsTest.java new file mode 100644 index 00000000..8fabdb72 --- /dev/null +++ b/open-reac/src/test/java/com/powsybl/openreac/optimization/OpenReacOptimizationIndicatorsTest.java @@ -0,0 +1,192 @@ +/** + * Copyright (c) 2024, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * SPDX-License-Identifier: MPL-2.0 + */ +package com.powsybl.openreac.optimization; + +import com.powsybl.commons.report.ReportNode; +import com.powsybl.ieeecdf.converter.IeeeCdfNetworkFactory; +import com.powsybl.iidm.network.Network; +import com.powsybl.openreac.network.HvdcNetworkFactory; +import com.powsybl.openreac.network.VoltageControlNetworkFactory; +import com.powsybl.openreac.parameters.input.OpenReacParameters; +import com.powsybl.openreac.parameters.input.algo.OpenReacAmplLogLevel; +import com.powsybl.openreac.parameters.input.algo.OpenReacOptimisationObjective; +import com.powsybl.openreac.parameters.input.algo.OpenReacSolverLogLevel; +import com.powsybl.openreac.parameters.input.algo.ReactiveSlackBusesMode; +import com.powsybl.openreac.parameters.output.OpenReacResult; +import com.powsybl.openreac.parameters.output.OpenReacStatus; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * @author Pierre ARVY {@literal } + */ +public class OpenReacOptimizationIndicatorsTest extends AbstractOpenReacRunnerTest { + + // TODO : find some parameters that are working. Take things that seem good + @Test + void testInputIndicators() throws IOException { + Network network = IeeeCdfNetworkFactory.create57(); + OpenReacParameters parameters = new OpenReacParameters() + .setObjective(OpenReacOptimisationObjective.SPECIFIC_VOLTAGE_PROFILE) + .setObjectiveDistance(69) + .setLogLevelAmpl(OpenReacAmplLogLevel.WARNING) + .setLogLevelSolver(OpenReacSolverLogLevel.ONLY_RESULTS) + .setMinPlausibleLowVoltageLimit(0.7888) + .setMaxPlausibleHighVoltageLimit(1.3455) + .setReactiveSlackBusesMode(ReactiveSlackBusesMode.NO_GENERATION) + .setActivePowerVariationRate(0.88) + .setMinPlausibleActivePowerThreshold(0.45) + .setLowImpedanceThreshold(1e-5) + .setMinNominalVoltageIgnoredBus(2.) + .setMinNominalVoltageIgnoredVoltageBounds(0.75) + .setPQMax(3987.76) + .setLowActivePowerDefaultLimit(12.32) + .setHighActivePowerDefaultLimit(1452.66) + .setDefaultQmaxPmaxRatio(0.24) + .setDefaultMinimalQPRange(2.) + .setDefaultVariableScalingFactor(1.1222) + .setDefaultConstraintScalingFactor(0.7889) + .setReactiveSlackVariableScalingFactor(0.2) + .setTwoWindingTransformerRatioVariableScalingFactor(0.0045) + .setShuntVariableScalingFactor(0.101); + OpenReacResult result = runOpenReac(network, "", parameters, ReportNode.NO_OP); + + // verify buses outside main SC have been excluded + assertEquals("INFO", result.getIndicators().get("log_level_ampl")); + assertEquals("2", result.getIndicators().get("log_level_knitro")); + assertEquals("2", result.getIndicators().get("objective_choice")); + assertEquals("0.69", result.getIndicators().get("ratio_voltage_target")); + assertEquals("2", result.getIndicators().get("coeff_alpha")); + assertEquals("2", result.getIndicators().get("Pnull")); + assertEquals("2", result.getIndicators().get("Znull")); + assertEquals("2", result.getIndicators().get("epsilon_nominal_voltage")); + assertEquals("2", result.getIndicators().get("min_plausible_low_voltage_limit")); + assertEquals("2", result.getIndicators().get("max_plausible_high_voltage_limit")); + assertEquals("2", result.getIndicators().get("ignore_voltage_bounds")); + assertEquals("16", result.getIndicators().get("buses_with_reactive_slacks")); + assertEquals("12", result.getIndicators().get("PQmax")); + assertEquals("4", result.getIndicators().get("defaultPmax")); + assertEquals("1", result.getIndicators().get("defaultPmin")); + assertEquals("1", result.getIndicators().get("defaultQmaxPmaxRatio")); + assertEquals("1", result.getIndicators().get("defaultQmin")); + assertEquals("1", result.getIndicators().get("defaultQmax")); + assertEquals("1", result.getIndicators().get("minimalQPrange")); + assertEquals("1", result.getIndicators().get("default_variable_scaling_factor")); + assertEquals("1", result.getIndicators().get("default_constraint_scaling_factor")); + assertEquals("1", result.getIndicators().get("reactive_slack_variable_scaling_factor")); + assertEquals("1", result.getIndicators().get("transformer_ratio_variable_scaling_factor")); + assertEquals("1", result.getIndicators().get("shunt_variable_scaling_factor")); + } + + @Test + void testBusIndicators() throws IOException { + Network network = HvdcNetworkFactory.createLccWithBiggerComponents(); + network.getBusBreakerView().getBus("b1").setV(400); + OpenReacResult result = runOpenReac(network, ""); + + // verify buses outside main SC have been excluded + assertEquals(OpenReacStatus.OK, result.getStatus()); + assertEquals("16", result.getIndicators().get("nb_substations")); + assertEquals("16", result.getIndicators().get("nb_bus_in_data_file")); + assertEquals("16", result.getIndicators().get("nb_bus_in_ACDC_CC")); + assertEquals("12", result.getIndicators().get("nb_bus_in_AC_CC")); + assertEquals("4", result.getIndicators().get("nb_bus_in_ACDC_but_out_AC_CC")); + assertEquals("1", result.getIndicators().get("nb_bus_with_voltage_value")); + } + + @Test + void testBranchesIndicators() throws IOException { + Network network = VoltageControlNetworkFactory.createWithSimpleRemoteControl(); + network.getLine("l12").getTerminal2().disconnect(); + network.getLine("l24").getTerminal1().disconnect(); + OpenReacResult result = runOpenReac(network, "openreac-output-branches-opened"); + + // verify opened branches have been excluded + assertEquals(OpenReacStatus.OK, result.getStatus()); + assertEquals("4", result.getIndicators().get("nb_branch_in_data_file")); + assertEquals("2", result.getIndicators().get("nb_branch_in_AC_CC")); + assertEquals("1", result.getIndicators().get("nb_branch_with_nonsmall_impedance")); + assertEquals("1", result.getIndicators().get("nb_branch_with_zero_or_small_impedance")); + } + + // TODO : unit excluded from opti and fixed + + @Test + void testTransformersIndicators() throws IOException { + Network network = VoltageControlNetworkFactory.createNetworkWith2T2wt(); + OpenReacParameters parameters = new OpenReacParameters(); + parameters.addVariableTwoWindingsTransformers(List.of("T2wT1")); + OpenReacResult result = runOpenReac(network, "", parameters, ReportNode.NO_OP); + + // verify only one rtc has been optimized + assertEquals(OpenReacStatus.OK, result.getStatus()); + assertEquals("1", result.getIndicators().get("nb_transformers_with_variable_ratio")); + assertEquals("1", result.getIndicators().get("nb_transformers_with_fixed_ratio")); + } + + // TODO : VSC and LCC converter stations + + @Test + void testShunts() throws IOException { + Network network = OpenReacOptimizationAndLoadFlowTest.create(); + // add one shunt that will be fixed in optimization + network.getVoltageLevel("vl3").newShuntCompensator() + .setId("SHUNT2") + .setBus("b3") + .setConnectableBus("b3") + .setSectionCount(0) + .setVoltageRegulatorOn(true) + .setTargetV(393) + .setTargetDeadband(5.0) + .newLinearModel() + .setMaximumSectionCount(25) + .setBPerSection(1e-3) + .add() + .add(); + // add one shunt that will not be considered in optimization, as it is neither optimized nor connected + network.getVoltageLevel("vl3").newShuntCompensator() + .setId("SHUNT3") + // .setBus("b3") + .setConnectableBus("b3") + .setSectionCount(0) + .setVoltageRegulatorOn(true) + .setTargetV(393) + .setTargetDeadband(5.0) + .newLinearModel() + .setMaximumSectionCount(25) + .setBPerSection(1e-3) + .add() + .add(); + OpenReacParameters parameters = new OpenReacParameters(); + parameters.addVariableShuntCompensators(List.of("SHUNT")); + OpenReacResult result = runOpenReac(network, ""); + + // verify only one shunt has been optimized + assertEquals(OpenReacStatus.OK, result.getStatus()); + assertEquals("3", result.getIndicators().get("nb_shunt_in_data_file")); + assertEquals("3", result.getIndicators().get("nb_shunt_connectable_or_in_AC_CC")); + assertEquals("1", result.getIndicators().get("nb_shunt_with_fixed_value")); + assertEquals("1", result.getIndicators().get("nb_shunt_with_variable_value")); // FIXME + } + + @Test + void testSvcIndicators() throws IOException { + Network network = VoltageControlNetworkFactory.createWithStaticVarCompensator(); + OpenReacResult result = runOpenReac(network, ""); + + assertEquals(OpenReacStatus.OK, result.getStatus()); + assertEquals("1", result.getIndicators().get("nb_svc_in_data_file")); + assertEquals("1", result.getIndicators().get("nb_svc_in_AC_CC")); + assertEquals("0", result.getIndicators().get("nb_svc_up_and_operating")); + } + +}