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 659e3744d9..1b23c8e208 100644 --- a/src/main/java/com/powsybl/openloadflow/network/impl/LfLoadImpl.java +++ b/src/main/java/com/powsybl/openloadflow/network/impl/LfLoadImpl.java @@ -96,8 +96,9 @@ void updateState(double diffLoadTargetP, boolean loadPowerFactorConstant) { init(); for (int i = 0; i < loadsRefs.size(); i++) { Load load = loadsRefs.get(i).get(); - double updatedP0 = (load.getP0() / PerUnit.SB + diffLoadTargetP * participationFactors[i]) * PerUnit.SB; - double updatedQ0 = loadPowerFactorConstant ? getPowerFactor(load) * updatedP0 : load.getQ0(); + double diffP0 = diffLoadTargetP * participationFactors[i] * PerUnit.SB; + double updatedP0 = load.getP0() + diffP0; + double updatedQ0 = load.getQ0() + (loadPowerFactorConstant ? getPowerFactor(load) * diffP0 : 0.0); load.getTerminal().setP(updatedP0); load.getTerminal().setQ(updatedQ0); } diff --git a/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowTwoBusNetworkTest.java b/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowTwoBusNetworkTest.java index fd4a9f21af..1c7b3e24a1 100644 --- a/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowTwoBusNetworkTest.java +++ b/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowTwoBusNetworkTest.java @@ -6,9 +6,7 @@ */ package com.powsybl.openloadflow.ac; -import com.powsybl.iidm.network.Bus; -import com.powsybl.iidm.network.Line; -import com.powsybl.iidm.network.Network; +import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.extensions.ActivePowerControlAdder; import com.powsybl.loadflow.LoadFlow; import com.powsybl.loadflow.LoadFlowParameters; @@ -162,4 +160,37 @@ void zeroImpedanceToShuntCompensator() { assertReactivePowerEquals(0.9038788263615884, network.getLine("l23").getTerminal1()); assertActivePowerEquals(0.0, network.getLine("l23").getTerminal1()); } + + @Test + void modifiedLoadCaseTest() { + // previous value : l1 (P0, Q0) = (2, 1) + // new values : l1 (P0, Q0) = (0, 1) and + // l2 (P0, Q0) = (2, 0) + network.getLoad("l1").setP0(0); + Load l2 = bus2.getVoltageLevel().newLoad() + .setId("l2") + .setBus("b2") + .setConnectableBus("b2") + .setP0(2) + .setQ0(0) + .add(); + l2.getTerminal().setP(2).setQ(0); + + parameters = new LoadFlowParameters() + .setReadSlackBus(false) + .setDistributedSlack(true) + .setBalanceType(LoadFlowParameters.BalanceType.PROPORTIONAL_TO_LOAD); + OpenLoadFlowParameters.create(parameters) + .setSlackBusSelectionMode(SlackBusSelectionMode.MOST_MESHED) + .setLoadPowerFactorConstant(true); + + LoadFlowResult result = loadFlowRunner.run(network, parameters); + assertTrue(result.isOk()); + + Double bus2BalanceQ = bus2.getConnectedTerminalStream().map(Terminal::getQ) + .filter(d -> !Double.isNaN(d)) + .reduce(0.0, Double::sum); + + assertEquals(0.0, bus2BalanceQ, DELTA_POWER); + } }