From 3ce07ab48d61fa1e208f95085b9aa96a60d8f660 Mon Sep 17 00:00:00 2001 From: vmouradian Date: Fri, 9 Feb 2024 17:03:13 +0100 Subject: [PATCH] Keep constant power factor only if P0 != 0 Signed-off-by: vmouradian --- .../powsybl/iidm/modification/scalable/LoadScalable.java | 2 +- .../iidm/modification/scalable/LoadScalableTest.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/scalable/LoadScalable.java b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/scalable/LoadScalable.java index 43506e800a5..cf7c67c04cf 100644 --- a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/scalable/LoadScalable.java +++ b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/scalable/LoadScalable.java @@ -150,7 +150,7 @@ public double scale(Network n, double asked, ScalingParameters parameters) { LOGGER.info("Change active power setpoint of {} from {} to {} ", l.getId(), oldP0, l.getP0()); - if (parameters.isConstantPowerFactor()) { + if (parameters.isConstantPowerFactor() && oldP0 != 0) { l.setQ0(l.getP0() * oldQ0 / oldP0); LOGGER.info("Change reactive power setpoint of {} from {} to {} ", l.getId(), oldQ0, l.getQ0()); diff --git a/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/scalable/LoadScalableTest.java b/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/scalable/LoadScalableTest.java index d771452b403..6ca934d78fb 100644 --- a/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/scalable/LoadScalableTest.java +++ b/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/scalable/LoadScalableTest.java @@ -185,6 +185,13 @@ void testConstantPowerFactor() { ls1.scale(network, 20, parameters); assertEquals(60, load.getP0(), 1e-3); assertEquals(7.5, load.getQ0(), 1e-3); + + ls1.reset(network); + assertEquals(0.0, load.getP0(), 1e-3); + assertEquals(7.5, load.getQ0(), 1e-3); + ls1.scale(network, -20, parameters); + assertEquals(20.0, load.getP0(), 1e-3); + assertEquals(7.5, load.getQ0(), 1e-3); } @Test