diff --git a/src/main/java/com/powsybl/openloadflow/OpenLoadFlowProvider.java b/src/main/java/com/powsybl/openloadflow/OpenLoadFlowProvider.java index 104395e7c5..1bd1f78ebf 100644 --- a/src/main/java/com/powsybl/openloadflow/OpenLoadFlowProvider.java +++ b/src/main/java/com/powsybl/openloadflow/OpenLoadFlowProvider.java @@ -145,7 +145,7 @@ private LoadFlowResult runAc(Network network, LoadFlowParameters parameters, Rep result.getNewtonRaphsonIterations(), result.getNetwork().getSlackBus().getId(), result.getSlackBusActivePowerMismatch() * PerUnit.SB, - Double.NaN)); + result.getDistributedActivePower() * PerUnit.SB)); } // zero or low impedance branch flows computation diff --git a/src/main/java/com/powsybl/openloadflow/ac/outerloop/AcLoadFlowResult.java b/src/main/java/com/powsybl/openloadflow/ac/outerloop/AcLoadFlowResult.java index c2820a6586..c0f9aec724 100644 --- a/src/main/java/com/powsybl/openloadflow/ac/outerloop/AcLoadFlowResult.java +++ b/src/main/java/com/powsybl/openloadflow/ac/outerloop/AcLoadFlowResult.java @@ -27,13 +27,16 @@ public class AcLoadFlowResult { private final double slackBusActivePowerMismatch; + private final double distributedActivePower; + public AcLoadFlowResult(LfNetwork network, int outerLoopIterations, int newtonRaphsonIterations, NewtonRaphsonStatus newtonRaphsonStatus, - double slackBusActivePowerMismatch) { + double slackBusActivePowerMismatch, double distributedActivePower) { this.network = Objects.requireNonNull(network); this.outerLoopIterations = outerLoopIterations; this.newtonRaphsonIterations = newtonRaphsonIterations; this.newtonRaphsonStatus = newtonRaphsonStatus; this.slackBusActivePowerMismatch = slackBusActivePowerMismatch; + this.distributedActivePower = distributedActivePower; } public LfNetwork getNetwork() { @@ -56,12 +59,17 @@ public double getSlackBusActivePowerMismatch() { return slackBusActivePowerMismatch; } + public double getDistributedActivePower() { + return distributedActivePower; + } + @Override public String toString() { return "AcLoadFlowResult(outerLoopIterations=" + outerLoopIterations + ", newtonRaphsonIterations=" + newtonRaphsonIterations + ", newtonRaphsonStatus=" + newtonRaphsonStatus + ", slackBusActivePowerMismatch=" + slackBusActivePowerMismatch * PerUnit.SB + + ", distributedActivePower=" + distributedActivePower * PerUnit.SB + ")"; } } diff --git a/src/main/java/com/powsybl/openloadflow/ac/outerloop/AcloadFlowEngine.java b/src/main/java/com/powsybl/openloadflow/ac/outerloop/AcloadFlowEngine.java index 4caf2d7a80..6acf124d4c 100644 --- a/src/main/java/com/powsybl/openloadflow/ac/outerloop/AcloadFlowEngine.java +++ b/src/main/java/com/powsybl/openloadflow/ac/outerloop/AcloadFlowEngine.java @@ -109,6 +109,7 @@ public AcLoadFlowResult run(Reporter reporter) { // run initial Newton-Raphson runningContext.lastNrResult = newtonRaphson.run(voltageInitializer, reporter); + double initialSlackBusActivePowerMismatch = runningContext.lastNrResult.getSlackBusActivePowerMismatch(); // continue with outer loops only if initial Newton-Raphson succeed if (runningContext.lastNrResult.getStatus() == NewtonRaphsonStatus.CONVERGED) { @@ -141,8 +142,12 @@ public AcLoadFlowResult run(Reporter reporter) { int nrIterations = runningContext.lastNrResult.getIteration(); int outerLoopIterations = runningContext.outerLoopIterationByType.values().stream().mapToInt(MutableInt::getValue).sum() + 1; - AcLoadFlowResult result = new AcLoadFlowResult(context.getNetwork(), outerLoopIterations, nrIterations, runningContext.lastNrResult.getStatus(), - runningContext.lastNrResult.getSlackBusActivePowerMismatch()); + AcLoadFlowResult result = new AcLoadFlowResult(context.getNetwork(), + outerLoopIterations, + nrIterations, + runningContext.lastNrResult.getStatus(), + runningContext.lastNrResult.getSlackBusActivePowerMismatch(), + initialSlackBusActivePowerMismatch - runningContext.lastNrResult.getSlackBusActivePowerMismatch()); LOGGER.info("Ac loadflow complete on network {} (result={})", context.getNetwork(), result); @@ -159,7 +164,7 @@ public static List run(T network, LfNetworkLoader netwo .run(reporter); } } - return new AcLoadFlowResult(n, 0, 0, NewtonRaphsonStatus.NO_CALCULATION, Double.NaN); + return new AcLoadFlowResult(n, 0, 0, NewtonRaphsonStatus.NO_CALCULATION, Double.NaN, 0); }) .collect(Collectors.toList()); } diff --git a/src/main/java/com/powsybl/openloadflow/network/util/LoadActivePowerDistributionStep.java b/src/main/java/com/powsybl/openloadflow/network/util/LoadActivePowerDistributionStep.java index 3cbb4482a9..a74728cdef 100644 --- a/src/main/java/com/powsybl/openloadflow/network/util/LoadActivePowerDistributionStep.java +++ b/src/main/java/com/powsybl/openloadflow/network/util/LoadActivePowerDistributionStep.java @@ -79,7 +79,7 @@ public double run(List participatingElements, int iteratio } LOGGER.debug("{} MW / {} MW distributed at iteration {} to {} buses ({} at min consumption)", - done * PerUnit.SB, -remainingMismatch * PerUnit.SB, iteration, modifiedBuses, loadsAtMin); + -done * PerUnit.SB, -remainingMismatch * PerUnit.SB, iteration, modifiedBuses, loadsAtMin); return done; } diff --git a/src/test/java/com/powsybl/openloadflow/ac/DistributedSlackOnGenerationTest.java b/src/test/java/com/powsybl/openloadflow/ac/DistributedSlackOnGenerationTest.java index ebb34b2ed1..71158b076a 100644 --- a/src/test/java/com/powsybl/openloadflow/ac/DistributedSlackOnGenerationTest.java +++ b/src/test/java/com/powsybl/openloadflow/ac/DistributedSlackOnGenerationTest.java @@ -17,6 +17,7 @@ import com.powsybl.openloadflow.OpenLoadFlowProvider; import com.powsybl.openloadflow.network.DistributedSlackNetworkFactory; import com.powsybl.openloadflow.network.SlackBusSelectionMode; +import com.powsybl.openloadflow.util.LoadFlowAssert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -25,8 +26,7 @@ import static com.powsybl.openloadflow.util.LoadFlowAssert.assertActivePowerEquals; import static com.powsybl.openloadflow.util.LoadFlowAssert.assertReactivePowerEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * @author Geoffroy Jamgotchian @@ -60,6 +60,8 @@ void setUp() { void test() { LoadFlowResult result = loadFlowRunner.run(network, parameters); assertTrue(result.isOk()); + assertEquals(1, result.getComponentResults().size()); + assertEquals(120, result.getComponentResults().get(0).getDistributedActivePower(), LoadFlowAssert.DELTA_POWER); assertActivePowerEquals(-115, g1.getTerminal()); assertActivePowerEquals(-245, g2.getTerminal()); assertActivePowerEquals(-105, g3.getTerminal());