From 6466b2ad55b5c6c88f27fa6bca1aab965212f77e Mon Sep 17 00:00:00 2001 From: Caio Luke Date: Mon, 17 Jul 2023 15:37:32 +0200 Subject: [PATCH 1/2] add test of bug in constant power factor Signed-off-by: Caio Luke --- .../ac/DistributedSlackOnLoadTest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/test/java/com/powsybl/openloadflow/ac/DistributedSlackOnLoadTest.java b/src/test/java/com/powsybl/openloadflow/ac/DistributedSlackOnLoadTest.java index 3682f1c710..9787fb6768 100644 --- a/src/test/java/com/powsybl/openloadflow/ac/DistributedSlackOnLoadTest.java +++ b/src/test/java/com/powsybl/openloadflow/ac/DistributedSlackOnLoadTest.java @@ -214,4 +214,27 @@ void testPowerFactorConstant2() { assertEquals(0.0, sumBus, 10E-6); assertPowerFactor(network); } + + @Test + void testPowerFactorConstant3() { + Network network = DistributedSlackNetworkFactory.createNetworkWithLoads2(); + parameters.setBalanceType(LoadFlowParameters.BalanceType.PROPORTIONAL_TO_LOAD); + parametersExt.setLoadPowerFactorConstant(true); + network.getLoad("l4").newExtension(LoadDetailAdder.class) + .withFixedActivePower(0) + .withFixedReactivePower(0) + .withVariableActivePower(0) + .withVariableReactivePower(50) + .add(); + LoadFlowResult result = loadFlowRunner.run(network, parameters); + assertTrue(result.isOk()); + double sumBus = 0.0; + sumBus += network.getLine("l14").getTerminal2().getQ(); + sumBus += network.getLine("l24").getTerminal2().getQ(); + sumBus += network.getLine("l34").getTerminal2().getQ(); + sumBus += network.getLoad("l4").getTerminal().getQ(); + sumBus += network.getLoad("l5").getTerminal().getQ(); + assertEquals(0.0, sumBus, 10E-6); + assertPowerFactor(network); + } } From 5e4b0243bf261ad0269f675da6bee3fcb8a9d458 Mon Sep 17 00:00:00 2001 From: Anne Tilloy Date: Mon, 17 Jul 2023 20:06:02 +0200 Subject: [PATCH 2/2] Improve unit test and fix proposal. Signed-off-by: Anne Tilloy --- .../openloadflow/network/impl/LfLoadImpl.java | 4 ++-- .../ac/DistributedSlackOnLoadTest.java | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/powsybl/openloadflow/network/impl/LfLoadImpl.java b/src/main/java/com/powsybl/openloadflow/network/impl/LfLoadImpl.java index ea78ba33a6..48dbd4890e 100644 --- a/src/main/java/com/powsybl/openloadflow/network/impl/LfLoadImpl.java +++ b/src/main/java/com/powsybl/openloadflow/network/impl/LfLoadImpl.java @@ -99,8 +99,8 @@ public double calculateNewTargetQ(double diffTargetP) { double newLoadTargetQ = 0; for (int i = 0; i < loadsRefs.size(); i++) { Load load = loadsRefs.get(i).get(); - double updatedP0 = load.getP0() / PerUnit.SB + diffTargetP * getParticipationFactor(i); - newLoadTargetQ += getPowerFactor(load) * updatedP0; + double updatedQ0 = load.getQ0() / PerUnit.SB + getPowerFactor(load) * diffTargetP * getParticipationFactor(i); + newLoadTargetQ += updatedQ0; } return newLoadTargetQ; } diff --git a/src/test/java/com/powsybl/openloadflow/ac/DistributedSlackOnLoadTest.java b/src/test/java/com/powsybl/openloadflow/ac/DistributedSlackOnLoadTest.java index 9787fb6768..ba0134d5c2 100644 --- a/src/test/java/com/powsybl/openloadflow/ac/DistributedSlackOnLoadTest.java +++ b/src/test/java/com/powsybl/openloadflow/ac/DistributedSlackOnLoadTest.java @@ -220,11 +220,22 @@ void testPowerFactorConstant3() { Network network = DistributedSlackNetworkFactory.createNetworkWithLoads2(); parameters.setBalanceType(LoadFlowParameters.BalanceType.PROPORTIONAL_TO_LOAD); parametersExt.setLoadPowerFactorConstant(true); - network.getLoad("l4").newExtension(LoadDetailAdder.class) + network.getGenerator("g1").setTargetP(-208); + Load l4 = network.getLoad("l4"); + l4.setP0(0.0).setQ0(-50); + l4.newExtension(LoadDetailAdder.class) .withFixedActivePower(0) .withFixedReactivePower(0) .withVariableActivePower(0) - .withVariableReactivePower(50) + .withVariableReactivePower(-50) + .add(); + Load l5 = network.getLoad("l5"); + l5.setP0(-10.0).setQ0(0.0); + l5.newExtension(LoadDetailAdder.class) + .withFixedActivePower(-10) + .withFixedReactivePower(0) + .withVariableActivePower(0) + .withVariableReactivePower(0.0) .add(); LoadFlowResult result = loadFlowRunner.run(network, parameters); assertTrue(result.isOk()); @@ -234,7 +245,7 @@ void testPowerFactorConstant3() { sumBus += network.getLine("l34").getTerminal2().getQ(); sumBus += network.getLoad("l4").getTerminal().getQ(); sumBus += network.getLoad("l5").getTerminal().getQ(); - assertEquals(0.0, sumBus, 10E-6); + assertEquals(0.0, sumBus, 10E-3); assertPowerFactor(network); } }