Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DcEquationSystem with disabled non impedant branch #663

Merged
merged 5 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public static void initTarget(Equation<DcVariableType, DcEquationType> equation,
break;

case BUS_TARGET_PHI:
case DUMMY_TARGET_P:
targets[equation.getColumn()] = 0;
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,24 @@ public static void createNonImpedantBranch(EquationSystem<DcVariableType, DcEqua
equationSystem.createEquation(branch.getNum(), DcEquationType.ZERO_PHI)
.addTerm(equationSystem.getVariable(bus1.getNum(), DcVariableType.BUS_PHI).createTerm())
.addTerm(equationSystem.getVariable(bus2.getNum(), DcVariableType.BUS_PHI).<DcEquationType>createTerm()
.minus());
.minus()).setActive(!branch.isDisabled());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't understand why but this first setActive is not needed in AcEquationSystem. So I don't know if this fix is the good one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EquationSystem.createEquation has 2 overloads:

  • initial one just take an element num
  • newest one take directly the LfElement and so on is able to internally disable equation according to LfElement status

DcEquationSystem had unfortunately not been migrated to new one


// add a dummy active power variable to both sides of the non impedant branch and with an opposite sign
// to ensure we have the same number of equation and variables
var dummyP = equationSystem.getVariable(branch.getNum(), DcVariableType.DUMMY_P);
equationSystem.getEquation(bus1.getNum(), DcEquationType.BUS_TARGET_P)
.orElseThrow()
.addTerm(equationSystem.getVariable(branch.getNum(), DcVariableType.DUMMY_P)
.createTerm());
.addTerm(dummyP.createTerm());

equationSystem.getEquation(bus2.getNum(), DcEquationType.BUS_TARGET_P)
.orElseThrow()
.addTerm(equationSystem.getVariable(branch.getNum(), DcVariableType.DUMMY_P).<DcEquationType>createTerm()
.minus());
.addTerm(dummyP.<DcEquationType>createTerm().minus());

// create an inactive dummy active power target equation set to zero that could be activated
// on case of switch opening
equationSystem.createEquation(branch, DcEquationType.DUMMY_TARGET_P)
.addTerm(dummyP.createTerm())
.setActive(branch.isDisabled()); // inverted logic
} else {
throw new IllegalStateException("Cannot happen because only there is one slack bus per model");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public enum DcEquationType implements Quantity {
BUS_TARGET_PHI("bus_target_\u03C6", ElementType.BUS), // slack bus voltage angle target
BRANCH_TARGET_P("branch_target_p", ElementType.BRANCH), // phase shifter active flow control
BRANCH_TARGET_ALPHA1("branch_target_\u03B1", ElementType.BRANCH), // phase shifter constant shift
ZERO_PHI("zero_\u03C6", ElementType.BRANCH); // zero impedance branch, voltage angle equality
ZERO_PHI("zero_\u03C6", ElementType.BRANCH), // zero impedance branch, voltage angle equality
DUMMY_TARGET_P("dummy_target_p", ElementType.BRANCH);

private final String symbol;

Expand Down
37 changes: 35 additions & 2 deletions src/test/java/com/powsybl/openloadflow/dc/DcLoadFlowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package com.powsybl.openloadflow.dc;

import com.powsybl.commons.reporter.Reporter;
import com.powsybl.ieeecdf.converter.IeeeCdfNetworkFactory;
import com.powsybl.iidm.network.Line;
import com.powsybl.iidm.network.Network;
Expand All @@ -17,15 +18,20 @@
import com.powsybl.math.matrix.DenseMatrixFactory;
import com.powsybl.openloadflow.OpenLoadFlowParameters;
import com.powsybl.openloadflow.OpenLoadFlowProvider;
import com.powsybl.openloadflow.network.FourBusNetworkFactory;
import com.powsybl.openloadflow.network.SlackBusSelectionMode;
import com.powsybl.openloadflow.dc.equations.DcEquationSystemCreationParameters;
import com.powsybl.openloadflow.network.*;
import com.powsybl.openloadflow.network.impl.LfNetworkList;
import com.powsybl.openloadflow.network.impl.Networks;
import com.powsybl.openloadflow.util.LoadFlowAssert;
import com.powsybl.openloadflow.util.PerUnit;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.usefultoys.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -259,4 +265,31 @@ void shuntCompensatorActivePowerZero() {
loadFlowRunner.run(network, parameters);
LoadFlowAssert.assertActivePowerEquals(0, sc.getTerminal());
}

@Test
void testDisabledNonImpedantBranch() {
Network network = NodeBreakerNetworkFactory.create3Bars();
network.getSwitch("C1").setOpen(true);
LoadFlowParameters parameters = new LoadFlowParameters();
parameters.setDc(true);
LoadFlow.run(network, parameters);
LoadFlowAssert.assertActivePowerEquals(400.0, network.getLine("L1").getTerminal1());
LoadFlowAssert.assertActivePowerEquals(100.0, network.getLine("L2").getTerminal1());
LoadFlowAssert.assertActivePowerEquals(100.0, network.getLine("L3").getTerminal1());

LfNetworkParameters lfNetworkParameters = new LfNetworkParameters().setDc(true).setBreakers(true);
LfNetworkList lfNetworks = Networks.load(network, lfNetworkParameters, Collections.emptySet(), Set.of(network.getSwitch("C1")), Reporter.NO_OP);
LfNetwork largestNetwork = lfNetworks.getLargest().orElseThrow();
largestNetwork.getBranchById("C1").setDisabled(true);
DcLoadFlowParameters dcLoadFlowParameters = new DcLoadFlowParameters(lfNetworkParameters,
new DcEquationSystemCreationParameters(true, true, false, true),
new DenseMatrixFactory(),
true,
parameters.getBalanceType(),
false);
new DcLoadFlowEngine(List.of(largestNetwork), dcLoadFlowParameters).run(Reporter.NO_OP);
assertEquals(400.0, largestNetwork.getBranchById("L1").getP1().eval() * PerUnit.SB, LoadFlowAssert.DELTA_POWER);
assertEquals(100.0, largestNetwork.getBranchById("L2").getP1().eval() * PerUnit.SB, LoadFlowAssert.DELTA_POWER);
assertEquals(100.0, largestNetwork.getBranchById("L3").getP1().eval() * PerUnit.SB, LoadFlowAssert.DELTA_POWER);
}
}