From 023995c825dc0dbd2ac0649716c6c4dafa7eb710 Mon Sep 17 00:00:00 2001 From: parvy Date: Wed, 17 Jan 2024 18:20:23 +0100 Subject: [PATCH] add boolean for warm start update and refactor TUs. Signed-off-by: parvy --- .../parameters/output/OpenReacResult.java | 16 ++++-- .../powsybl/openreac/OpenReacRunnerTest.java | 54 +++++++++---------- 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/open-reac/src/main/java/com/powsybl/openreac/parameters/output/OpenReacResult.java b/open-reac/src/main/java/com/powsybl/openreac/parameters/output/OpenReacResult.java index 811c0e66..13907de9 100644 --- a/open-reac/src/main/java/com/powsybl/openreac/parameters/output/OpenReacResult.java +++ b/open-reac/src/main/java/com/powsybl/openreac/parameters/output/OpenReacResult.java @@ -35,6 +35,7 @@ public class OpenReacResult { private final List svcModifications; private final List tapPositionModifications; private final List voltagePlan; + private boolean warmStart = true; /** * @param status the final status of the OpenReac run. @@ -90,6 +91,14 @@ public List getVoltagePlan() { return voltagePlan; } + public boolean getWarmStat() { + return warmStart; + } + + public void setWarmStart(boolean warmStart) { + this.warmStart = warmStart; + } + public List getAllNetworkModifications() { List modifs = new ArrayList<>(getGeneratorModifications().size() + getShuntsModifications().size() + @@ -114,9 +123,10 @@ public void applyAllModifications(Network network) { double v = busResult.getV() * b.getVoltageLevel().getNominalV(); double angle = busResult.getAngle(); - // warm start - b.setV(v); - b.setAngle(angle); + if (getWarmStat()) { + b.setV(v); + b.setAngle(angle); + } // update target of ratio tap changers regulating voltage on b network.getTwoWindingsTransformerStream() 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 3b2d7307..6652f838 100644 --- a/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java +++ b/open-reac/src/test/java/com/powsybl/openreac/OpenReacRunnerTest.java @@ -231,7 +231,8 @@ void testRunAsync() throws IOException { subFolder + "/reactiveopf_results_rtc.csv", subFolder + "/reactiveopf_results_shunts.csv", subFolder + "/reactiveopf_results_static_var_compensators.csv", - subFolder + "/reactiveopf_results_vsc_converter_stations.csv")); + subFolder + "/reactiveopf_results_vsc_converter_stations.csv", + subFolder + "/reactiveopf_results_voltages.csv")); // To really run open reac, use the commented 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), @@ -245,24 +246,7 @@ void testRunAsync() throws IOException { } private void testAllModifAndLoadFlow(Network network, String subFolder, OpenReacParameters parameters) throws IOException { - LocalCommandExecutor localCommandExecutor = new TestLocalCommandExecutor( - List.of(subFolder + "/reactiveopf_results_generators.csv", - subFolder + "/reactiveopf_results_indic.txt", - subFolder + "/reactiveopf_results_rtc.csv", - subFolder + "/reactiveopf_results_shunts.csv", - subFolder + "/reactiveopf_results_static_var_compensators.csv", - 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())) { - OpenReacResult openReacResult = OpenReacRunner.run(network, - network.getVariantManager().getWorkingVariantId(), parameters, new OpenReacConfig(true), - computationManager); - assertEquals(OpenReacStatus.OK, openReacResult.getStatus()); - openReacResult.applyAllModifications(network); - } + runAndApplyAllModifications(network, subFolder, parameters, true); LoadFlowResult loadFlowResult = LoadFlow.run(network); assertTrue(loadFlowResult.isOk()); } @@ -343,6 +327,26 @@ public void testWarmStart() throws IOException { Network network = VoltageControlNetworkFactory.createNetworkWithT2wt(); setDefaultVoltageLimits(network); String subFolder = "openreac-output-warm-start"; + OpenReacParameters parameters = new OpenReacParameters(); + + runAndApplyAllModifications(network, subFolder, parameters, false); // without warm start, no update + assertEquals(Double.NaN, network.getBusBreakerView().getBus("BUS_1").getV()); + assertEquals(Double.NaN, network.getBusBreakerView().getBus("BUS_1").getAngle()); + assertEquals(Double.NaN, network.getBusBreakerView().getBus("BUS_2").getV()); + assertEquals(Double.NaN, network.getBusBreakerView().getBus("BUS_2").getAngle()); + assertEquals(Double.NaN, network.getBusBreakerView().getBus("BUS_3").getV()); + assertEquals(Double.NaN, network.getBusBreakerView().getBus("BUS_3").getAngle()); + + runAndApplyAllModifications(network, subFolder, parameters, true); + assertEquals(119.592, network.getBusBreakerView().getBus("BUS_1").getV()); + assertEquals(0.014, network.getBusBreakerView().getBus("BUS_1").getAngle()); + assertEquals(118.8, network.getBusBreakerView().getBus("BUS_2").getV()); + assertEquals(0, network.getBusBreakerView().getBus("BUS_2").getAngle()); + assertEquals(22.935, network.getBusBreakerView().getBus("BUS_3").getV()); + assertEquals(-0.082, network.getBusBreakerView().getBus("BUS_3").getAngle()); + } + + private void runAndApplyAllModifications(Network network, String subFolder, OpenReacParameters parameters, boolean warmStart) throws IOException { LocalCommandExecutor localCommandExecutor = new TestLocalCommandExecutor( List.of(subFolder + "/reactiveopf_results_generators.csv", subFolder + "/reactiveopf_results_indic.txt", @@ -354,20 +358,14 @@ public void testWarmStart() throws IOException { // 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())) { + localCommandExecutor, ForkJoinPool.commonPool())) { OpenReacResult openReacResult = OpenReacRunner.run(network, - network.getVariantManager().getWorkingVariantId(), new OpenReacParameters(), + network.getVariantManager().getWorkingVariantId(), parameters, new OpenReacConfig(true), computationManager); assertEquals(OpenReacStatus.OK, openReacResult.getStatus()); + openReacResult.setWarmStart(warmStart); openReacResult.applyAllModifications(network); } - - assertEquals(119.592, network.getBusBreakerView().getBus("BUS_1").getV()); - assertEquals(0.014, network.getBusBreakerView().getBus("BUS_1").getAngle()); - assertEquals(118.8, network.getBusBreakerView().getBus("BUS_2").getV()); - assertEquals(0, network.getBusBreakerView().getBus("BUS_2").getAngle()); - assertEquals(22.935, network.getBusBreakerView().getBus("BUS_3").getV()); - assertEquals(-0.082, network.getBusBreakerView().getBus("BUS_3").getAngle()); } public static Network create() {