Skip to content

Commit

Permalink
Add TUs for ACOPF indicators
Browse files Browse the repository at this point in the history
Signed-off-by: p-arvy <[email protected]>
  • Loading branch information
p-arvy committed Nov 27, 2024
1 parent b767132 commit 8da89b0
Show file tree
Hide file tree
Showing 3 changed files with 208 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,7 +38,7 @@
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
* @author Nicolas PIERRE {@literal <nicolas.pierre at artelys.com>}
*/
public class OpenReacOptimizationTest extends AbstractOpenReacRunnerTest {
public class OpenReacOptimizationAndLoadFlowTest extends AbstractOpenReacRunnerTest {

@Test
void testRunAsync() throws IOException {
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <pierre.arvy at artelys.com>}
*/
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"));
}

}

0 comments on commit 8da89b0

Please sign in to comment.