Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into dc_slack_distribution_failure_beh…
Browse files Browse the repository at this point in the history
…avior_fail

# Conflicts:
#	src/main/java/com/powsybl/openloadflow/ac/outerloop/DistributedSlackOuterLoop.java
#	src/main/java/com/powsybl/openloadflow/network/util/ActivePowerDistribution.java
  • Loading branch information
jeandemanged committed Dec 12, 2024
2 parents dac55c1 + 39ca741 commit 5331ad0
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ public double calculateSensi(DenseMatrix dx, int column) {
double dph1 = dx.get(ph1Var.getRow(), column);
double dph2 = dx.get(ph2Var.getRow(), column);
double da1 = a1Var != null ? dx.get(a1Var.getRow(), column) : 0;
return calculateSensi(dph1, dph2, da1);
// - eval(0,0,0) to have an exact epression and remove the constant term of the affine function (wich is 0 in practe because A2 = 0)
return eval(dph1, dph2, da1) - eval(0, 0, 0);
}

protected double ph1(StateVector sv) {
Expand All @@ -116,16 +117,11 @@ protected double ph2() {
return ph2(sv);
}

protected abstract double calculateSensi(double ph1, double ph2, double a1);
protected abstract double eval(double ph1, double ph2, double a1);

@Override
public double eval() {
return calculateSensi(ph1(), ph2(), a1());
}

@Override
public double eval(StateVector sv) {
return calculateSensi(ph1(sv), ph2(sv), a1(sv));
return eval(ph1(), ph2(), a1());
}

protected double a1(StateVector sv) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static ClosedBranchSide1DcFlowEquationTerm create(LfBranch branch, LfBus
}

@Override
protected double calculateSensi(double ph1, double ph2, double a1) {
protected double eval(double ph1, double ph2, double a1) {
double deltaPhase = ph2 - ph1 + A2 - a1;
return -getPower() * deltaPhase;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static ClosedBranchSide2DcFlowEquationTerm create(LfBranch branch, LfBus
}

@Override
protected double calculateSensi(double ph1, double ph2, double a1) {
protected double eval(double ph1, double ph2, double a1) {
double deltaPhase = ph2 - ph1 + A2 - a1;
return getPower() * deltaPhase;
}
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/com/powsybl/openloadflow/equations/Equation.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,16 @@ public double eval() {
for (EquationTerm<V, E> term : terms) {
if (term.isActive()) {
value += term.eval();
if (term.hasRhs()) {
value -= term.rhs();
}
}
}
return value;
}

public double evalLhs() {
double value = 0;
for (EquationTerm<V, E> term : terms) {
if (term.isActive()) {
value += term.evalLhs();
}
}
return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ static <V extends Enum<V> & Quantity, E extends Enum<E> & Quantity> EquationTerm
double eval();

/**
* Evaluate the equation term with an alternative state vector.
* Evaluate equation lhs of the equation term
* @return value of the equation term
*/
default double eval(StateVector sv) {
throw new UnsupportedOperationException("Not implemented");
default double evalLhs() {
return eval() - (hasRhs() ? rhs() : 0);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ protected double[] createArray() {
return array;
}

private void eval(double[] array, List<Equation<V, E>> equations) {
private void evalLhs(double[] array, List<Equation<V, E>> equations) {
Arrays.fill(array, 0); // necessary?
for (Equation<V, E> equation : equations) {
array[equation.getColumn()] = equation.eval();
array[equation.getColumn()] = equation.evalLhs();
}
}

Expand All @@ -59,7 +59,7 @@ protected void updateArray(double[] array) {
throw new IllegalArgumentException("Bad equation vector length: " + array.length);
}

eval(array, equations);
evalLhs(array, equations);

LOGGER.debug(PERFORMANCE_MARKER, "Equation vector updated in {} us", stopwatch.elapsed(TimeUnit.MICROSECONDS));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,4 @@ public boolean isActive() {
return getBranchTermStream().anyMatch(EquationTerm::isActive);
}

@Override
public double eval(StateVector sv) {
// The equation is
// rhs = VariableInjectionPart+ branchPart
// with rhs = - (cte injectionPart) (for ex sum of targetQ)
// -branchPart = variableInjectionPart + cteInjectionPart
return -getBranchTermStream().mapToDouble(t -> t.eval(sv)).sum();
}
}
2 changes: 0 additions & 2 deletions src/main/java/com/powsybl/openloadflow/util/Derivable.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import com.powsybl.math.matrix.DenseMatrix;
import com.powsybl.openloadflow.equations.Quantity;
import com.powsybl.openloadflow.equations.StateVector;
import com.powsybl.openloadflow.equations.Variable;

/**
Expand All @@ -23,5 +22,4 @@ public interface Derivable <V extends Enum<V> & Quantity> extends Evaluable {

boolean isActive();

double eval(StateVector sv);
}
47 changes: 47 additions & 0 deletions src/test/java/com/powsybl/openloadflow/dc/DcLoadFlowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,53 @@ void nonImpedantBranchTest() {
assertEquals(33.3333, network.getLine("L1").getTerminal1().getP(), 0.01);
}

@Test
void nonImpedantBranchAndPhaseShiftingTest() {
Network network = PhaseShifterTestCaseFactory.create();
network.getLine("L2").setX(0).setR(0);
network.getTwoWindingsTransformer("PS1").getPhaseTapChanger().getStep(1).setAlpha(2);
loadFlowRunner.run(network, parameters);

assertEquals(16.5316, network.getLine("L1").getTerminal1().getP(), 0.01);
assertEquals(83.4683, network.getLine("L2").getTerminal1().getP(), 0.01); // Temporary comment : P without fix = 133.87
assertEquals(-83.4683, network.getTwoWindingsTransformer("PS1").getTerminal2().getP(), 0.01);

// With e second zero impedance line and a second load
VoltageLevel vl2 = network.getVoltageLevel("VL2");
vl2.getBusBreakerView().newBus()
.setId("B2Bis")
.add();
vl2.newLoad()
.setId("LD2Bis")
.setConnectableBus("B2Bis")
.setBus("B2Bis")
.setP0(100.0)
.setQ0(50.0)
.add();
network.newLine()
.setId("L2Bis")
.setVoltageLevel1("VL3")
.setConnectableBus1("B3")
.setBus1("B3")
.setVoltageLevel2("VL2")
.setConnectableBus2("B2Bis")
.setBus2("B2Bis")
.setR(0.0)
.setX(0.0)
.setG1(0.0)
.setB1(0.0)
.setG2(0.0)
.setB2(0.0)
.add();
network.getGenerator("G1").setMaxP(500);
LoadFlowResult result = loadFlowRunner.run(network, parameters);
assertTrue(result.isFullyConverged());
assertEquals(49.86, network.getLine("L1").getTerminal1().getP(), 0.01);
assertEquals(150.13, network.getTwoWindingsTransformer("PS1").getTerminal1().getP(), 0.01);
assertEquals(0, network.getTwoWindingsTransformer("PS1").getTerminal2().getP() + network.getLine("L2").getTerminal1().getP() + network.getLine("L2Bis").getTerminal1().getP(), 0.01); // Temporary comment : P without fix = 133.87
assertEquals(-200, network.getGenerator("G1").getTerminal().getP());
}

@Test
void multiCcTest() {
Network network = IeeeCdfNetworkFactory.create14();
Expand Down

0 comments on commit 5331ad0

Please sign in to comment.