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

Add a utility method to find the optional other side dangling line #2680

Merged
merged 3 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -273,4 +273,15 @@ private static boolean zeroImpedanceLine(BranchAdmittanceMatrix adm) {
return adm.y21().getReal() == 0.0 && adm.y22().getImaginary() == 0.0;
}
}

/**
* <p>Retrieve, if it exists, the dangling line paired to the given one.</p>
*
* @param danglingLine a dangling line
* @return an Optional containing the dangling line paired to the given one
*/
public static Optional<DanglingLine> getPairedDanglingLine(DanglingLine danglingLine) {
return danglingLine.getTieLine().map(t ->
t.getDanglingLine1() == danglingLine ? t.getDanglingLine2() : t.getDanglingLine1());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import com.powsybl.iidm.network.test.NoEquipmentNetworkFactory;
import com.powsybl.iidm.network.util.SV;
import com.powsybl.iidm.network.util.TieLineUtil;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -91,6 +93,10 @@ public void testTieLineAdder() {
assertFalse(network.getDanglingLines(DanglingLineFilter.PAIRED).iterator().hasNext());
assertEquals(List.of(dl1, dl2), network.getDanglingLines());

// test paired dangling line retrieval - For unpaired dangling lines
assertFalse(TieLineUtil.getPairedDanglingLine(dl1).isPresent());
assertFalse(TieLineUtil.getPairedDanglingLine(dl2).isPresent());

TieLineAdder adder = network.newTieLine().setId("testTie")
.setName("testNameTie")
.setDanglingLine1(dl1.getId())
Expand All @@ -116,7 +122,6 @@ public void testTieLineAdder() {
assertEquals(0.0285, tieLine.getB2(), tol);

DanglingLine danglingLine1 = tieLine.getDanglingLine1();

DanglingLine danglingLine2 = tieLine.getDanglingLine2();

// Check notification on DanglingLine changes
Expand Down Expand Up @@ -160,20 +165,28 @@ public void testTieLineAdder() {
double v2 = 380.0;
double angle1 = -1e-4;
double angle2 = -1.7e-3;
tieLine.getDanglingLine1().getTerminal().setP(p1).setQ(q1).getBusView().getBus().setV(v1).setAngle(angle1);
tieLine.getDanglingLine2().getTerminal().setP(p2).setQ(q2).getBusView().getBus().setV(v2).setAngle(angle2);
danglingLine1.getTerminal().setP(p1).setQ(q1).getBusView().getBus().setV(v1).setAngle(angle1);
danglingLine2.getTerminal().setP(p2).setQ(q2).getBusView().getBus().setV(v2).setAngle(angle2);

// test boundaries values
SV expectedSV1 = new SV(p1, q1, v1, angle1, Branch.Side.ONE);
SV expectedSV2 = new SV(p2, q2, v2, angle2, Branch.Side.TWO);
assertEquals(expectedSV1.otherSideP(tieLine.getDanglingLine1(), true), tieLine.getDanglingLine1().getBoundary().getP(), 0.0d);
assertEquals(expectedSV1.otherSideQ(tieLine.getDanglingLine1(), true), tieLine.getDanglingLine1().getBoundary().getQ(), 0.0d);
assertEquals(expectedSV2.otherSideP(tieLine.getDanglingLine2(), true), tieLine.getDanglingLine2().getBoundary().getP(), 0.0d);
assertEquals(expectedSV2.otherSideQ(tieLine.getDanglingLine2(), true), tieLine.getDanglingLine2().getBoundary().getQ(), 0.0d);
assertEquals(expectedSV1.otherSideU(tieLine.getDanglingLine1(), true), tieLine.getDanglingLine1().getBoundary().getV(), 0.0d);
assertEquals(expectedSV1.otherSideA(tieLine.getDanglingLine1(), true), tieLine.getDanglingLine1().getBoundary().getAngle(), 0.0d);
assertEquals(expectedSV2.otherSideU(tieLine.getDanglingLine2(), true), tieLine.getDanglingLine2().getBoundary().getV(), 0.0d);
assertEquals(expectedSV2.otherSideA(tieLine.getDanglingLine2(), true), tieLine.getDanglingLine2().getBoundary().getAngle(), 0.0d);
assertEquals(expectedSV1.otherSideP(danglingLine1, true), danglingLine1.getBoundary().getP(), 0.0d);
assertEquals(expectedSV1.otherSideQ(danglingLine1, true), danglingLine1.getBoundary().getQ(), 0.0d);
assertEquals(expectedSV2.otherSideP(danglingLine2, true), danglingLine2.getBoundary().getP(), 0.0d);
assertEquals(expectedSV2.otherSideQ(danglingLine2, true), danglingLine2.getBoundary().getQ(), 0.0d);
assertEquals(expectedSV1.otherSideU(danglingLine1, true), danglingLine1.getBoundary().getV(), 0.0d);
assertEquals(expectedSV1.otherSideA(danglingLine1, true), danglingLine1.getBoundary().getAngle(), 0.0d);
assertEquals(expectedSV2.otherSideU(danglingLine2, true), danglingLine2.getBoundary().getV(), 0.0d);
assertEquals(expectedSV2.otherSideA(danglingLine2, true), danglingLine2.getBoundary().getAngle(), 0.0d);

// test paired dangling line retrieval - For paired dangling lines
Optional<DanglingLine> otherSide1 = TieLineUtil.getPairedDanglingLine(danglingLine1);
assertTrue(otherSide1.isPresent());
assertEquals(danglingLine2, otherSide1.orElseThrow());
Optional<DanglingLine> otherSide2 = TieLineUtil.getPairedDanglingLine(danglingLine2);
assertTrue(otherSide2.isPresent());
assertEquals(danglingLine1, otherSide2.orElseThrow());
}

@Test
Expand Down