Skip to content

Commit

Permalink
Boundary P, Q, angle and voltage with zero impedance (#3048)
Browse files Browse the repository at this point in the history
* Manage zero impedance dangling line.
* Extend zero impedance to dangling lines without generation and paired dangling lines

Signed-off-by: Anne Tilloy <[email protected]>
Signed-off-by: José Antonio Marqués <[email protected]>
(cherry picked from commit be4c1cc)
  • Loading branch information
annetill authored and olperr1 committed Jun 11, 2024
1 parent 41bb687 commit edd5369
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import java.util.Objects;

import static com.powsybl.iidm.network.util.DanglingLineData.zeroImpedance;

/**
* @author Miora Ralambotiana {@literal <miora.ralambotiana at rte-france.com>}
*/
Expand All @@ -33,7 +35,11 @@ public double getV() {

Terminal t = parent.getTerminal();
Bus b = t.getBusView().getBus();
return new SV(t.getP(), t.getQ(), getV(b), getAngle(b), TwoSides.ONE).otherSideU(parent, true);
if (zeroImpedance(parent)) {
return getV(b);
} else {
return new SV(t.getP(), t.getQ(), getV(b), getAngle(b), TwoSides.ONE).otherSideU(parent, true);
}
}

@Override
Expand All @@ -44,7 +50,11 @@ public double getAngle() {
}
Terminal t = parent.getTerminal();
Bus b = t.getBusView().getBus();
return new SV(t.getP(), t.getQ(), getV(b), getAngle(b), TwoSides.ONE).otherSideA(parent, true);
if (zeroImpedance(parent)) {
return getAngle(b);
} else {
return new SV(t.getP(), t.getQ(), getV(b), getAngle(b), TwoSides.ONE).otherSideA(parent, true);
}
}

@Override
Expand All @@ -54,7 +64,11 @@ public double getP() {
}
Terminal t = parent.getTerminal();
Bus b = t.getBusView().getBus();
return new SV(t.getP(), t.getQ(), getV(b), getAngle(b), TwoSides.ONE).otherSideP(parent, true);
if (zeroImpedance(parent)) {
return -t.getP();
} else {
return new SV(t.getP(), t.getQ(), getV(b), getAngle(b), TwoSides.ONE).otherSideP(parent, true);
}
}

@Override
Expand All @@ -64,7 +78,11 @@ public double getQ() {
}
Terminal t = parent.getTerminal();
Bus b = t.getBusView().getBus();
return new SV(t.getP(), t.getQ(), getV(b), getAngle(b), TwoSides.ONE).otherSideQ(parent, true);
if (zeroImpedance(parent)) {
return -t.getQ();
} else {
return new SV(t.getP(), t.getQ(), getV(b), getAngle(b), TwoSides.ONE).otherSideQ(parent, true);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ public DanglingLineData(DanglingLine danglingLine) {
public DanglingLineData(DanglingLine danglingLine, boolean splitShuntAdmittance) {
this.danglingLine = Objects.requireNonNull(danglingLine);

double g1 = splitShuntAdmittance ? danglingLine.getG() * 0.5 : danglingLine.getG();
double b1 = splitShuntAdmittance ? danglingLine.getB() * 0.5 : danglingLine.getB();
double g2 = splitShuntAdmittance ? danglingLine.getG() * 0.5 : 0.0;
double b2 = splitShuntAdmittance ? danglingLine.getB() * 0.5 : 0.0;

double u1 = getV(danglingLine);
double theta1 = getTheta(danglingLine);

Expand All @@ -46,6 +41,17 @@ public DanglingLineData(DanglingLine danglingLine, boolean splitShuntAdmittance)
return;
}

if (zeroImpedance(danglingLine)) {
boundaryBusU = u1;
boundaryBusTheta = theta1;
return;
}

double g1 = splitShuntAdmittance ? danglingLine.getG() * 0.5 : danglingLine.getG();
double b1 = splitShuntAdmittance ? danglingLine.getB() * 0.5 : danglingLine.getB();
double g2 = splitShuntAdmittance ? danglingLine.getG() * 0.5 : 0.0;
double b2 = splitShuntAdmittance ? danglingLine.getB() * 0.5 : 0.0;

Complex v1 = ComplexUtils.polar2Complex(u1, theta1);

Complex vBoundaryBus = new Complex(Double.NaN, Double.NaN);
Expand Down Expand Up @@ -103,5 +109,10 @@ public double getBoundaryBusU() {
public double getBoundaryBusTheta() {
return boundaryBusTheta;
}

public static boolean zeroImpedance(DanglingLine parent) {
// Simple way to deal with zero impedance dangling line.
return parent.getR() == 0.0 && parent.getX() == 0.0;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,13 @@ public static void findAndAssociateDanglingLines(DanglingLine candidateDanglingL
public static double getR(DanglingLine dl1, DanglingLine dl2) {
LinkData.BranchAdmittanceMatrix adm = TieLineUtil.equivalentBranchAdmittanceMatrix(dl1, dl2);
// Add 0.0 to avoid negative zero, tests where the R value is compared as text, fail
return adm.y12().negate().reciprocal().getReal() + 0.0;
return zeroImpedanceLine(adm) ? 0.0 : adm.y12().negate().reciprocal().getReal() + 0.0;
}

public static double getX(DanglingLine dl1, DanglingLine dl2) {
LinkData.BranchAdmittanceMatrix adm = TieLineUtil.equivalentBranchAdmittanceMatrix(dl1, dl2);
// Add 0.0 to avoid negative zero, tests where the X value is compared as text, fail
return adm.y12().negate().reciprocal().getImaginary() + 0.0;
return zeroImpedanceLine(adm) ? 0.0 : adm.y12().negate().reciprocal().getImaginary() + 0.0;
}

public static double getG1(DanglingLine dl1, DanglingLine dl2) {
Expand Down Expand Up @@ -318,7 +318,9 @@ private static LinkData.BranchAdmittanceMatrix equivalentBranchAdmittanceMatrix(
BranchAdmittanceMatrix adm2 = LinkData.calculateBranchAdmittance(dl2.getR(), dl2.getX(), 1.0, 0.0, 1.0, 0.0,
new Complex(0.0, 0.0), new Complex(dl2.getG(), dl2.getB()));

if (zeroImpedanceLine(adm1)) {
if (zeroImpedanceLine(adm1) && zeroImpedanceLine(adm2)) {
return adm1;
} else if (zeroImpedanceLine(adm1)) {
return adm2;
} else if (zeroImpedanceLine(adm2)) {
return adm1;
Expand All @@ -345,7 +347,15 @@ private static Complex voltageAtTheBoundaryNode(DanglingLine dl1, DanglingLine d
BranchAdmittanceMatrix adm2 = LinkData.calculateBranchAdmittance(dl2.getR(), dl2.getX(), 1.0, 0.0, 1.0, 0.0,
new Complex(0.0, 0.0), new Complex(dl2.getG(), dl2.getB()));

return adm1.y21().multiply(v1).add(adm2.y12().multiply(v2)).negate().divide(adm1.y22().add(adm2.y11()));
if (zeroImpedanceLine(adm1) && zeroImpedanceLine(adm2)) {
return v1;
} else if (zeroImpedanceLine(adm1)) {
return v1;
} else if (zeroImpedanceLine(adm2)) {
return v2;
} else {
return adm1.y21().multiply(v1).add(adm2.y12().multiply(v2)).negate().divide(adm1.y22().add(adm2.y11()));
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.test.NoEquipmentNetworkFactory;
import java.time.ZonedDateTime;

import com.powsybl.iidm.network.util.TieLineUtil;
import org.junit.jupiter.api.Test;

import com.powsybl.iidm.network.util.LinkData;
Expand Down Expand Up @@ -273,6 +275,76 @@ void testDefaultValuesTieLine() {
assertSame(s2vl1, tieLine.getDanglingLine2().getTerminal().getVoltageLevel());
}

@Test
void tieLineTestZeroImpedanceDl1() {
// Line1 from node1 to boundaryNode, Line2 from node2 to boundaryNode
CaseSv caseSv0 = createCase0();
Network n = createNetworkWithTieLine(NetworkFactory.findDefault(), TwoSides.TWO, TwoSides.TWO, caseSv0);
Branch<?> branch = n.getBranch("TWO + TWO");
assertTrue(branch instanceof TieLine);

TieLine tieLine = (TieLine) branch;
tieLine.getDanglingLine1().setR(0.0).setX(0.0).setG(0.0).setB(0.0);

double tol = 1.0e-6;
assertEquals(tieLine.getDanglingLine2().getR(), tieLine.getR(), tol);
assertEquals(tieLine.getDanglingLine2().getX(), tieLine.getX(), tol);
assertEquals(tieLine.getDanglingLine2().getG(), tieLine.getG2(), tol);
assertEquals(tieLine.getDanglingLine2().getB(), tieLine.getB2(), tol);
assertEquals(0.0, tieLine.getG1(), tol);
assertEquals(0.0, tieLine.getB1(), tol);

assertEquals(tieLine.getDanglingLine1().getTerminal().getBusView().getBus().getV(), TieLineUtil.getBoundaryV(tieLine.getDanglingLine1(), tieLine.getDanglingLine2()), tol);
assertEquals(tieLine.getDanglingLine1().getTerminal().getBusView().getBus().getAngle(), TieLineUtil.getBoundaryAngle(tieLine.getDanglingLine1(), tieLine.getDanglingLine2()), tol);
}

@Test
void tieLineTestZeroImpedanceDl2() {
// Line1 from node1 to boundaryNode, Line2 from node2 to boundaryNode
CaseSv caseSv0 = createCase0();
Network n = createNetworkWithTieLine(NetworkFactory.findDefault(), TwoSides.TWO, TwoSides.TWO, caseSv0);
Branch<?> branch = n.getBranch("TWO + TWO");
assertTrue(branch instanceof TieLine);

TieLine tieLine = (TieLine) branch;
tieLine.getDanglingLine2().setR(0.0).setX(0.0).setG(0.0).setB(0.0);

double tol = 1.0e-6;
assertEquals(tieLine.getDanglingLine1().getR(), tieLine.getR(), tol);
assertEquals(tieLine.getDanglingLine1().getX(), tieLine.getX(), tol);
assertEquals(tieLine.getDanglingLine1().getG(), tieLine.getG1(), tol);
assertEquals(tieLine.getDanglingLine1().getB(), tieLine.getB1(), tol);
assertEquals(0.0, tieLine.getG2(), tol);
assertEquals(0.0, tieLine.getB2(), tol);

assertEquals(tieLine.getDanglingLine2().getTerminal().getBusView().getBus().getV(), TieLineUtil.getBoundaryV(tieLine.getDanglingLine1(), tieLine.getDanglingLine2()), tol);
assertEquals(tieLine.getDanglingLine2().getTerminal().getBusView().getBus().getAngle(), TieLineUtil.getBoundaryAngle(tieLine.getDanglingLine1(), tieLine.getDanglingLine2()), tol);
}

@Test
void tieLineTestZeroImpedanceDl1AndDl2() {
// Line1 from node1 to boundaryNode, Line2 from node2 to boundaryNode
CaseSv caseSv0 = createCase0();
Network n = createNetworkWithTieLine(NetworkFactory.findDefault(), TwoSides.TWO, TwoSides.TWO, caseSv0);
Branch<?> branch = n.getBranch("TWO + TWO");
assertTrue(branch instanceof TieLine);

TieLine tieLine = (TieLine) branch;
tieLine.getDanglingLine1().setR(0.0).setX(0.0).setG(0.0).setB(0.0);
tieLine.getDanglingLine2().setR(0.0).setX(0.0).setG(0.0).setB(0.0);

double tol = 1.0e-6;
assertEquals(0.0, tieLine.getR(), tol);
assertEquals(0.0, tieLine.getX(), tol);
assertEquals(0.0, tieLine.getG1(), tol);
assertEquals(0.0, tieLine.getB1(), tol);
assertEquals(0.0, tieLine.getG2(), tol);
assertEquals(0.0, tieLine.getB2(), tol);

assertEquals(tieLine.getDanglingLine1().getTerminal().getBusView().getBus().getV(), TieLineUtil.getBoundaryV(tieLine.getDanglingLine1(), tieLine.getDanglingLine2()), tol);
assertEquals(tieLine.getDanglingLine1().getTerminal().getBusView().getBus().getAngle(), TieLineUtil.getBoundaryAngle(tieLine.getDanglingLine1(), tieLine.getDanglingLine2()), tol);
}

private static Network createNetworkWithTieLine(NetworkFactory networkFactory,
TwoSides boundarySide1, TwoSides boundarySide2, CaseSv caseSv) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,36 @@ void testWithGeneration() {
assertEquals(130.037, danglingLine.getBoundary().getV(), tol);
assertEquals(0.995, danglingLine.getBoundary().getAngle(), tol);
}

@Test
void testWithZeroImpedanceDanglingLineWithGeneration() {
double tol = 0.001;
Network network = DanglingLineNetworkFactory.createWithGeneration();
DanglingLine danglingLine = network.getDanglingLine("DL");
danglingLine.setR(0.0).setX(0.0);
danglingLine.getTerminal().setP(-298.937);
danglingLine.getTerminal().setQ(-7.413);
danglingLine.getTerminal().getBusView().getBus().setAngle(0.0);
danglingLine.getTerminal().getBusView().getBus().setV(100.0);
assertEquals(298.937, danglingLine.getBoundary().getP(), tol);
assertEquals(7.413, danglingLine.getBoundary().getQ(), tol);
assertEquals(100.0, danglingLine.getBoundary().getV(), tol);
assertEquals(0.0, danglingLine.getBoundary().getAngle(), tol);
}

@Test
void testWithZeroImpedanceDanglingLineWithoutGeneration() {
double tol = 0.001;
Network network = DanglingLineNetworkFactory.create();
DanglingLine danglingLine = network.getDanglingLine("DL");
danglingLine.setR(0.0).setX(0.0);
danglingLine.getTerminal().setP(50.0);
danglingLine.getTerminal().setQ(30.0);
danglingLine.getTerminal().getBusView().getBus().setAngle(0.0);
danglingLine.getTerminal().getBusView().getBus().setV(100.0);
assertEquals(-50.0, danglingLine.getBoundary().getP(), tol);
assertEquals(-30.0, danglingLine.getBoundary().getQ(), tol);
assertEquals(100.0, danglingLine.getBoundary().getV(), tol);
assertEquals(0.0, danglingLine.getBoundary().getAngle(), tol);
}
}

0 comments on commit edd5369

Please sign in to comment.