Skip to content

Commit

Permalink
Fix injections ignored on slack buses when using multi slacks (#1116)
Browse files Browse the repository at this point in the history
Fix injections ignored on slack buses when using multi slacks (#1116)
Signed-off-by: vmouradian <valentin.mouradian@artelys.com>
Signed-off-by: Damien Jeandemange <damien.jeandemange@artelys.com>
Co-authored-by: Damien Jeandemange <damien.jeandemange@artelys.com>
  • Loading branch information
vmouradian authored Nov 15, 2024
1 parent d96584a commit 305fa38
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private static double getReactivePowerControlTarget(LfBranch branch) {

public static void init(Equation<AcVariableType, AcEquationType> equation, LfNetwork network, double[] targets) {
switch (equation.getType()) {
case BUS_TARGET_P:
case BUS_TARGET_P, BUS_DISTR_SLACK_P:
targets[equation.getColumn()] = network.getBus(equation.getElementNum()).getTargetP();
break;

Expand Down Expand Up @@ -118,7 +118,6 @@ public static void init(Equation<AcVariableType, AcEquationType> equation, LfNet
DISTR_SHUNT_B,
DUMMY_TARGET_P,
DUMMY_TARGET_Q,
BUS_DISTR_SLACK_P,
BUS_TARGET_IX_ZERO,
BUS_TARGET_IY_ZERO,
BUS_TARGET_IX_NEGATIVE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1036,14 +1036,14 @@ private void createMultipleSlackBusesEquations(EquationSystem<AcVariableType, Ac
LfBus firstSlackBus = slackBuses.get(0);
for (int i = 1; i < slackBuses.size(); i++) {
LfBus slackBus = slackBuses.get(i);
// example for 2 slack buses
// 0 = slack_p1 - slack_p2
// 0 = slack_p1 - slack_p3
// example for 3 slack buses
// target_p2 = slack_p2 - slack_p1
// target_p3 = slack_p3 - slack_p1
equationSystem.createEquation(slackBus, AcEquationType.BUS_DISTR_SLACK_P)
.addTerms(createActiveInjectionTerms(firstSlackBus, equationSystem.getVariableSet()))
.addTerms(createActiveInjectionTerms(slackBus, equationSystem.getVariableSet()).stream()
.addTerms(createActiveInjectionTerms(firstSlackBus, equationSystem.getVariableSet()).stream()
.map(EquationTerm::minus)
.collect(Collectors.toList()));
.toList())
.addTerms(createActiveInjectionTerms(slackBus, equationSystem.getVariableSet()));
// to update open/close terms activation
for (LfBranch branch : slackBus.getBranches()) {
updateBranchEquations(branch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
*/
package com.powsybl.openloadflow.ac;

import com.powsybl.iidm.network.Load;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.TwoWindingsTransformer;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import com.powsybl.loadflow.LoadFlow;
import com.powsybl.loadflow.LoadFlowParameters;
Expand All @@ -17,6 +19,7 @@
import com.powsybl.openloadflow.OpenLoadFlowProvider;
import com.powsybl.openloadflow.ac.solver.NewtonRaphsonStoppingCriteriaType;
import com.powsybl.openloadflow.network.EurostagFactory;
import com.powsybl.openloadflow.network.SlackBusSelectionMode;
import com.powsybl.openloadflow.util.LoadFlowAssert;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -30,6 +33,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static com.powsybl.openloadflow.util.LoadFlowAssert.assertActivePowerEquals;

/**
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
Expand Down Expand Up @@ -107,4 +111,26 @@ void nonImpedantBranchTest() {
assertEquals(-0.005, slackBusResults.get(0).getActivePowerMismatch(), LoadFlowAssert.DELTA_POWER);
assertEquals(-0.005, slackBusResults.get(1).getActivePowerMismatch(), LoadFlowAssert.DELTA_POWER);
}

@Test
void testSlackBusWithInjection() {
parametersExt
.setSlackBusSelectionMode(SlackBusSelectionMode.NAME)
.setSlackBusesIds(List.of("VLHV2", "VLLOAD"))
.setNewtonRaphsonConvEpsPerEq(1e-6);
LoadFlowResult result = loadFlowRunner.run(network, parameters);
assertTrue(result.isFullyConverged());
LoadFlowResult.ComponentResult componentResult = result.getComponentResults().get(0);
List<LoadFlowResult.SlackBusResult> slackBusResults = componentResult.getSlackBusResults();

TwoWindingsTransformer t2wtLoad = network.getTwoWindingsTransformer("NHV2_NLOAD");
Load load = network.getLoad("LOAD");

assertActivePowerEquals(-600.710, t2wtLoad.getTerminal2());
assertActivePowerEquals(600.0, load.getTerminal());

assertEquals(2, slackBusResults.size());
assertEquals(-0.710, slackBusResults.get(0).getActivePowerMismatch(), LoadFlowAssert.DELTA_POWER);
assertEquals(-0.710, slackBusResults.get(1).getActivePowerMismatch(), LoadFlowAssert.DELTA_POWER);
}
}

0 comments on commit 305fa38

Please sign in to comment.