From bba7463865784a25db697d15c591ad28e668b424 Mon Sep 17 00:00:00 2001 From: Anne Tilloy Date: Thu, 5 Oct 2023 10:06:08 +0200 Subject: [PATCH] Add log during merging. Signed-off-by: Anne Tilloy --- .../iidm/network/util/TieLineUtil.java | 4 ++ .../network/tck/AbstractMergeNetworkTest.java | 38 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/util/TieLineUtil.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/util/TieLineUtil.java index e230f460707..85f7d32cfab 100644 --- a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/util/TieLineUtil.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/util/TieLineUtil.java @@ -188,6 +188,10 @@ public static void findAndAssociateDanglingLines(DanglingLine candidateDanglingL List connectedDls = dls.stream().filter(dl -> dl.getTerminal().isConnected()).collect(Collectors.toList()); if (connectedDls.size() == 1) { // if there is exactly one connected dangling line in the merging network, merge it. Otherwise, do nothing associateDanglingLines.accept(connectedDls.get(0), candidateDanglingLine); + } else { + LOGGER.warn("Several connected dangling lines {} of the same subnetwork are candidate for merging for pairing key '{}'. " + + "No tie line automatically created, tie lines must be created by hand.", + connectedDls.stream().map(DanglingLine::getId).collect(Collectors.toList()), connectedDls.get(0).getPairingKey()); } } } diff --git a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractMergeNetworkTest.java b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractMergeNetworkTest.java index 180f9ef6fbb..a94ccc5617c 100644 --- a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractMergeNetworkTest.java +++ b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractMergeNetworkTest.java @@ -619,23 +619,61 @@ public void mergeThenCloneVariantBug() { @Test public void multipleDanglingLinesInMergedNetwork() { + // The code is not the same if the dangling line with the duplicate pairing key is in the current network + // or in the network we are adding when we try to associate dangling lines. + // + // This test covers the case where the duplicate pairing key is in the CURRENT network. addCommonSubstationsAndVoltageLevels(); addCommonDanglingLines("dl1", "code", "dl2", "code"); addDanglingLine(n2, "vl2", "dl3", "code", "b2", null); Network merge = Network.merge(n1, n2); + // Since n2 has ONLY ONE connected dangling line with the pairing key, the tie line is created assertNotNull(merge.getTieLine("dl1 + dl2")); assertEquals("dl1_name + dl2_name", merge.getTieLine("dl1 + dl2").getOptionalName().orElse(null)); assertEquals("dl1_name + dl2_name", merge.getTieLine("dl1 + dl2").getNameOrId()); } + @Test + public void multipleConnectedDanglingLinesInMergedNetwork() { + // The code is not the same if the dangling line with the duplicate pairing key is in the current network + // or in the network we are adding when we try to associate dangling lines. + // + // This test covers the case where the duplicate pairing key is in the CURRENT network. + addCommonSubstationsAndVoltageLevels(); + addCommonDanglingLines("dl1", "code", "dl2", "code"); + addDanglingLine(n2, "vl2", "dl3", "code", "b2", "b2"); + Network merge = Network.merge(n1, n2); + // Since n2 has SEVERAL connected dangling lines with the pairing key, we don't create the tie line + assertEquals(0, merge.getTieLineCount()); + } + @Test public void multipleDanglingLinesInMergingNetwork() { + // The code is not the same if the dangling line with the duplicate pairing key is in the current network + // or in the network we are adding when we try to associate dangling lines. + // + // This test covers the case where the duplicate pairing key is in the ADDED network. addCommonSubstationsAndVoltageLevels(); addCommonDanglingLines("dl1", "code", "dl2", "code"); addDanglingLine(n1, "vl1", "dl3", "code", "b1", null); Network merge = Network.merge(n1, n2); + // Since n1 has ONLY ONE connected dangling line with the pairing key, the tie line is created assertNotNull(merge.getTieLine("dl1 + dl2")); assertEquals("dl1_name + dl2_name", merge.getTieLine("dl1 + dl2").getOptionalName().orElse(null)); assertEquals("dl1_name + dl2_name", merge.getTieLine("dl1 + dl2").getNameOrId()); } + + @Test + public void multipleConnectedDanglingLinesWithSamePairingKey() { + // The code is not the same if the dangling line with the duplicate pairing key is in the current network + // or in the network we are adding when we try to associate dangling lines. + // + // This test covers the case where the duplicate pairing key is in the ADDED network. + addCommonSubstationsAndVoltageLevels(); + addCommonDanglingLines("dl1", "code", "dl2", "code"); + addDanglingLine(n1, "vl1", "dl3", "code", "b1", "b1"); + Network merge = Network.merge(n1, n2); + // Since n1 has SEVERAL connected dangling lines with the pairing key, we don't create the tie line + assertEquals(0, merge.getTieLineCount()); + } }