Skip to content

Commit

Permalink
Allow Xnodes connected to more than 2 Nodes to be imported correctly …
Browse files Browse the repository at this point in the history
…if the number of connected branches s lower or equal than two. (#1780)

Signed-off-by: Sébastien Murgey <[email protected]>
  • Loading branch information
murgeyseb authored and miovd committed Jul 7, 2021
1 parent 71f7200 commit 95fadc4
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.io.*;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import static com.powsybl.ucte.converter.util.UcteConstants.*;

Expand Down Expand Up @@ -799,28 +800,34 @@ private static String getBusId(Bus bus) {
}

private static DanglingLine getMatchingDanglingLine(DanglingLine dl1, Multimap<String, DanglingLine> danglingLinesByXnodeCode) {
DanglingLine dl2 = null;
Xnode xnodExtension = dl1.getExtension(Xnode.class);
if (xnodExtension == null) {
throw new UcteException("Dangling line " + dl1.getNameOrId() + " doesn't have the Xnode extension");
}
String otherXnodeCode = xnodExtension.getCode();
Iterator<DanglingLine> it = danglingLinesByXnodeCode.get(otherXnodeCode).iterator();
DanglingLine first = it.next();
if (it.hasNext()) {
DanglingLine second = it.next();
if (dl1 == first) {
dl2 = second;
} else if (dl1 == second) {
dl2 = first;
} else {
throw new AssertionError("Inconsistent XNODE index");
List<DanglingLine> matchingDanglingLines = danglingLinesByXnodeCode.get(otherXnodeCode)
.stream().filter(dl -> dl != dl1)
.collect(Collectors.toList());
if (matchingDanglingLines.isEmpty()) {
return null;
} else if (matchingDanglingLines.size() == 1) {
return matchingDanglingLines.get(0);
} else {
if (!dl1.getTerminal().isConnected()) {
return null;
}
if (it.hasNext()) {
throw new UcteException("More that 2 dangling lines have the same XNODE " + dl1.getUcteXnodeCode());
List<DanglingLine> connectedMatchingDanglingLines = matchingDanglingLines.stream()
.filter(dl -> dl.getTerminal().isConnected())
.collect(Collectors.toList());
if (connectedMatchingDanglingLines.isEmpty()) {
return null;
}
if (connectedMatchingDanglingLines.size() == 1) {
return connectedMatchingDanglingLines.get(0);
} else {
throw new UcteException("More that 2 connected dangling lines have the same XNODE " + dl1.getUcteXnodeCode());
}
}
return dl2;
}

private static void addElementNameProperty(TieLine tieLine, DanglingLine dl1, DanglingLine dl2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,16 @@ public void testValidationUtil() throws IOException {
testExporter(network, "/invalidVoltageReference.uct");
}

@Test
public void roundTripOfNetworkWithXnodesConnectedToOneClosedLineMustSucceed() throws IOException {
Network network = loadNetworkFromResourceFile("/xnodeOneClosedLine.uct");
testExporter(network, "/xnodeOneClosedLine.uct");
}

@Test
public void roundTripOfNetworkWithXnodesConnectedToTwoClosedLineMustSucceed() throws IOException {
Network network = loadNetworkFromResourceFile("/xnodeTwoClosedLine.uct");
testExporter(network, "/xnodeTwoClosedLine.uct");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void countryAssociationIssueTest() {
}

@Test
public void germanTsosImport() throws Exception {
public void germanTsosImport() {
ReadOnlyDataSource dataSource = new ResourceDataSource("germanTsos", new ResourceSet("/", "germanTsos.uct"));

Network network = new UcteImporter().importData(dataSource, null);
Expand Down Expand Up @@ -223,5 +223,27 @@ public void checkTapPositionsRangeIsExtended() {
assertEquals(-8, network.getTwoWindingsTransformer("ZABCD221 ZEFGH221 1").getPhaseTapChanger().getLowTapPosition());
assertEquals(8, network.getTwoWindingsTransformer("ZABCD221 ZEFGH221 1").getPhaseTapChanger().getHighTapPosition());
}

@Test
public void importOfNetworkWithXnodesConnectedToOneClosedLineMustSucceed() {
ResourceDataSource dataSource = new ResourceDataSource("xnodeOneClosedLine", new ResourceSet("/", "xnodeOneClosedLine.uct"));
Network network = new UcteImporter().importData(dataSource, new NetworkFactoryImpl(), null);
assertNotNull(network.getDanglingLine("FFFFFF12 XXXXXX11 1"));
}

@Test
public void importOfNetworkWithXnodesConnectedToTwoClosedLineMustSucceed() {
ResourceDataSource dataSource = new ResourceDataSource("xnodeTwoClosedLine", new ResourceSet("/", "xnodeTwoClosedLine.uct"));
Network network = new UcteImporter().importData(dataSource, new NetworkFactoryImpl(), null);
assertNotNull(network.getLine("BEBBBB11 XXXXXX11 1 + FFFFFF12 XXXXXX11 1"));
assertNotNull(network.getDanglingLine("FFFFFF11 XXXXXX11 1"));
assertNotNull(network.getDanglingLine("BEBBBB12 XXXXXX11 1"));
}

@Test
public void importOfNetworkWithXnodesConnectedToMoreThanTwoClosedLineMustFail() {
ResourceDataSource dataSource = new ResourceDataSource("xnodeThreeClosedLine", new ResourceSet("/", "xnodeTwoClosedLine.uct"));
assertThrows(UcteException.class, () -> new UcteImporter().importData(dataSource, new NetworkFactoryImpl(), null));
}
}

19 changes: 19 additions & 0 deletions ucte/ucte-converter/src/test/resources/xnodeOneClosedLine.uct
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
##C 2007.05.01
Generated by powsybl, 2019.09.23 17:47
Case date: 2019.09.24 19:30
##N
##ZBE
BEBBBB11 0 0 3.96708 0.00000 0.00000 0.00000
BEBBBB12 0 0 3.96708 0.00000 0.00000 0.00000
##ZFR
FFFFFF11 0 0 3.96708 0.00000 0.00000 0.00000
FFFFFF12 0 0 3.96708 0.00000 0.00000 0.00000
##ZXX
XXXXXX11 1 0 3.96708 0.00000 0.00000 0.00000
##L
BEBBBB11 XXXXXX11 1 8 0.0000 0.2000 0.000000 8080 ABCDE
BEBBBB12 XXXXXX11 1 8 0.0000 0.2000 0.000000 8080 ABCDE
FFFFFF11 XXXXXX11 1 8 0.0000 0.2000 0.000000 8080 ABCDE
FFFFFF12 XXXXXX11 1 0 0.0000 0.2000 0.000000 8080 ABCDE
##T
##R
19 changes: 19 additions & 0 deletions ucte/ucte-converter/src/test/resources/xnodeThreeClosedLine.uct
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
##C 2007.05.01
Generated by powsybl, 2019.09.23 17:47
Case date: 2019.09.24 19:30
##N
##ZBE
BEBBBB11 0 0 3.96708 0.00000 0.00000 0.00000
BEBBBB12 0 0 3.96708 0.00000 0.00000 0.00000
##ZFR
FFFFFF11 0 0 3.96708 0.00000 0.00000 0.00000
FFFFFF12 0 0 3.96708 0.00000 0.00000 0.00000
##ZXX
XXXXXX11 1 0 3.96708 0.00000 0.00000 0.00000
##L
BEBBBB11 XXXXXX11 1 0 0.0000 0.2000 0.000000 8080 ABCDE
BEBBBB12 XXXXXX11 1 8 0.0000 0.2000 0.000000 8080 ABCDE
FFFFFF11 XXXXXX11 1 0 0.0000 0.2000 0.000000 8080 ABCDE
FFFFFF12 XXXXXX11 1 0 0.0000 0.2000 0.000000 8080 ABCDE
##T
##R
19 changes: 19 additions & 0 deletions ucte/ucte-converter/src/test/resources/xnodeTwoClosedLine.uct
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
##C 2007.05.01
Generated by powsybl, 2019.09.23 17:47
Case date: 2019.09.24 19:30
##N
##ZBE
BEBBBB11 0 0 3.96708 0.00000 0.00000 0.00000
BEBBBB12 0 0 3.96708 0.00000 0.00000 0.00000
##ZFR
FFFFFF11 0 0 3.96708 0.00000 0.00000 0.00000
FFFFFF12 0 0 3.96708 0.00000 0.00000 0.00000
##ZXX
XXXXXX11 1 0 0.00000 0.00000 0.00000 0.00000
##L
BEBBBB11 XXXXXX11 1 0 0.0000 0.2000 0.000000 8080 ABCDE
BEBBBB12 XXXXXX11 1 8 0.0000 0.2000 0.000000 8080 ABCDE
FFFFFF11 XXXXXX11 1 8 0.0000 0.2000 0.000000 8080 ABCDE
FFFFFF12 XXXXXX11 1 0 0.0000 0.2000 0.000000 8080 ABCDE
##T
##R

0 comments on commit 95fadc4

Please sign in to comment.