From ac0208538d81ab3e2fc8ff34b4e9432e3c49b523 Mon Sep 17 00:00:00 2001 From: Naledi EL CHEIKH Date: Wed, 13 Nov 2024 11:33:59 +0100 Subject: [PATCH 1/9] successful copy of lines element Signed-off-by: Naledi EL CHEIKH --- .../com/powsybl/iidm/network/Network.java | 15 +++++++ .../iidm/network/impl/NetworkImpl.java | 2 +- .../tck/AbstractIdenticalLinesTest.java | 25 ++++++++++++ .../iidm/network/tck/AbstractLineTest.java | 39 ++++++++++++++++++- 4 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractIdenticalLinesTest.java diff --git a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Network.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Network.java index 8197882ca70..c8830b69af0 100644 --- a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Network.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Network.java @@ -761,6 +761,21 @@ default VoltageLevelAdder newVoltageLevel() { */ LineAdder newLine(); + /** + * Get a builder to create a new AC line by copying an existing one. + * @return a builder to create a new line + */ + default LineAdder newLine(Line line) { + return newLine().setR(line.getR()) + .setX(line.getX()) + .setG1(line.getG1()) + .setG2(line.getG2()) + .setB1(line.getB1()) + .setB2(line.getB2()) + .setVoltageLevel1(line.getTerminal1().getVoltageLevel().getId()) + .setVoltageLevel2(line.getTerminal2().getVoltageLevel().getId()); + } + /** * Get all AC lines. */ diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NetworkImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NetworkImpl.java index abfe43b0d34..c53dc5cfea0 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NetworkImpl.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NetworkImpl.java @@ -359,7 +359,7 @@ public VoltageLevelExt getVoltageLevel(String id) { @Override public LineAdderImpl newLine() { - return newLine(null); + return newLine((String) null); } LineAdderImpl newLine(String subnetwork) { diff --git a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractIdenticalLinesTest.java b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractIdenticalLinesTest.java new file mode 100644 index 00000000000..0b057014ad2 --- /dev/null +++ b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractIdenticalLinesTest.java @@ -0,0 +1,25 @@ +package com.powsybl.iidm.network.tck; + +import com.powsybl.iidm.network.Line; + +import java.util.Objects; + +public abstract class AbstractIdenticalLinesTest { + public boolean areLinesIdentical(Line line1, Line line2) { + boolean areIdentical = false; + + if (line1 != null && line2 != null) { + areIdentical = line1.getR() == line2.getR() + && line1.getX() == line2.getX() + && line1.getG1() == line2.getG1() + && line1.getG2() == line2.getG2() + && line1.getB1() == line2.getB1() + && line1.getB2() == line2.getB2() + && Objects.equals(line1.getTerminal1().getVoltageLevel().getId(), line2.getTerminal1().getVoltageLevel().getId()) + && Objects.equals(line1.getTerminal2().getVoltageLevel().getId(), line2.getTerminal2().getVoltageLevel().getId()); + } + return areIdentical; + } +} + + diff --git a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractLineTest.java b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractLineTest.java index 1e9873332fa..5607098b7b7 100644 --- a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractLineTest.java +++ b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractLineTest.java @@ -27,7 +27,7 @@ import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; -public abstract class AbstractLineTest { +public abstract class AbstractLineTest extends AbstractIdenticalLinesTest { private static final String INVALID = "invalid"; @@ -181,6 +181,43 @@ public void testDefaultLine() { assertSame(voltageLevelB, acLine.getTerminal2().getVoltageLevel()); } + @Test + public void testLineCopier() { + // First limit normally created + LineAdder acLineAdder1 = network.newLine() + .setId("line1") + .setName(LINE_NAME) + .setR(1.0) + .setX(2.0) + .setG1(3.0) + .setG2(3.5) + .setB1(4.0) + .setB2(4.5) + .setVoltageLevel1("vl1") + .setVoltageLevel2("vl2") + .setBus1("busA") + .setBus2("busB") + .setConnectableBus1("busA") + .setConnectableBus2("busB"); + acLineAdder1.add(); + Line acLine1 = network.getLine("line1"); + + // Second limit created by copy + LineAdder acLineAdder2 = network.newLine(acLine1); + acLineAdder2 + .setId("line2") + .setName(LINE_NAME) + .setBus1("busA") + .setBus2("busB") + .setConnectableBus1("busA") + .setConnectableBus2("busB"); + acLineAdder2.add(); + Line acLine2 = network.getLine("line2"); + + assertNotNull(acLine2); + assertTrue(areLinesIdentical(acLine1, acLine2)); + } + @Test public void testMove1Bb() { Line line = createLineBetweenVoltageAB("line", LINE_NAME, 1.0, 2.0, 3.0, 3.5, 4.0, 4.5); From f20738743e7b056b4a4ce2ff8945523d510a055f Mon Sep 17 00:00:00 2001 From: Naledi EL CHEIKH Date: Thu, 14 Nov 2024 17:42:00 +0100 Subject: [PATCH 2/9] add: details on operational limits groups and extensions duplication while copy of line Signed-off-by: Naledi EL CHEIKH --- .../java/com/powsybl/iidm/network/Branch.java | 2 +- .../com/powsybl/iidm/network/Network.java | 11 +----- .../iidm/network/OperationalLimitsGroup.java | 17 +++++++++ .../iidm/network/util/LoadingLimitsUtil.java | 5 ++- .../iidm/network/impl/LineAdderImpl.java | 38 +++++++++++++++++-- .../iidm/network/impl/NetworkImpl.java | 14 +++++++ .../iidm/network/impl/SubnetworkImpl.java | 5 +++ .../iidm/network/tck/AbstractLineTest.java | 1 + 8 files changed, 77 insertions(+), 16 deletions(-) diff --git a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Branch.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Branch.java index 20107ac6326..2fb120979ac 100644 --- a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Branch.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Branch.java @@ -97,7 +97,7 @@ * * * - * + * @author Geoffroy Jamgotchian {@literal } */ public interface Branch> extends Identifiable { diff --git a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Network.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Network.java index c8830b69af0..cd19d73ec72 100644 --- a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Network.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Network.java @@ -765,16 +765,7 @@ default VoltageLevelAdder newVoltageLevel() { * Get a builder to create a new AC line by copying an existing one. * @return a builder to create a new line */ - default LineAdder newLine(Line line) { - return newLine().setR(line.getR()) - .setX(line.getX()) - .setG1(line.getG1()) - .setG2(line.getG2()) - .setB1(line.getB1()) - .setB2(line.getB2()) - .setVoltageLevel1(line.getTerminal1().getVoltageLevel().getId()) - .setVoltageLevel2(line.getTerminal2().getVoltageLevel().getId()); - } + LineAdder newLine(Line line); /** * Get all AC lines. diff --git a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/OperationalLimitsGroup.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/OperationalLimitsGroup.java index 027d4072e36..c34a20cce89 100644 --- a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/OperationalLimitsGroup.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/OperationalLimitsGroup.java @@ -9,6 +9,8 @@ package com.powsybl.iidm.network; import java.util.Optional; +import static com.powsybl.iidm.network.util.LoadingLimitsUtil.initializeFromLoadingLimits; + /** * @author Pauline Jean-Marie {@literal } */ @@ -28,6 +30,21 @@ public interface OperationalLimitsGroup { ApparentPowerLimitsAdder newApparentPowerLimits(); + default CurrentLimitsAdder newCurrentLimits(CurrentLimits currentLimits) { + CurrentLimitsAdder currentLimitsAdder = newCurrentLimits(); + return initializeFromLoadingLimits(currentLimitsAdder, currentLimits); + } + + default ActivePowerLimitsAdder newActivePowerLimits(ActivePowerLimits activePowerLimits) { + ActivePowerLimitsAdder activePowerLimitsAdder = newActivePowerLimits(); + return initializeFromLoadingLimits(activePowerLimitsAdder, activePowerLimits); + } + + default ApparentPowerLimitsAdder newApparentPowerLimits(ApparentPowerLimits apparentPowerLimits) { + ApparentPowerLimitsAdder apparentPowerLimitsAdder = newApparentPowerLimits(); + return initializeFromLoadingLimits(apparentPowerLimitsAdder, apparentPowerLimits); + } + void removeCurrentLimits(); void removeActivePowerLimits(); diff --git a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/util/LoadingLimitsUtil.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/util/LoadingLimitsUtil.java index 62e9c4cf9d3..8f482e69f66 100644 --- a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/util/LoadingLimitsUtil.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/util/LoadingLimitsUtil.java @@ -7,10 +7,11 @@ */ package com.powsybl.iidm.network.util; -import com.powsybl.iidm.network.LoadingLimits; -import com.powsybl.iidm.network.LoadingLimitsAdder; +import com.powsybl.iidm.network.*; +import com.sun.source.tree.UsesTree; import java.util.Comparator; +import java.util.Optional; import static java.lang.Integer.MAX_VALUE; diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/LineAdderImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/LineAdderImpl.java index e9701b6b432..6c31824682e 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/LineAdderImpl.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/LineAdderImpl.java @@ -7,11 +7,12 @@ */ package com.powsybl.iidm.network.impl; -import com.powsybl.iidm.network.LineAdder; -import com.powsybl.iidm.network.ValidationException; -import com.powsybl.iidm.network.ValidationUtil; +import com.powsybl.commons.extensions.Extension; +import com.powsybl.iidm.network.*; import com.powsybl.commons.ref.Ref; +import java.util.Collection; + /** * * @author Geoffroy Jamgotchian {@literal } @@ -20,6 +21,8 @@ class LineAdderImpl extends AbstractBranchAdder implements LineAd private final NetworkImpl network; private final String subnetwork; + private final Line copiedLine; + private double r = Double.NaN; @@ -36,8 +39,17 @@ class LineAdderImpl extends AbstractBranchAdder implements LineAd LineAdderImpl(NetworkImpl network, String subnetwork) { this.network = network; this.subnetwork = subnetwork; + this.copiedLine = null; + } + + LineAdderImpl(NetworkImpl network, String subnetwork, Line copiedLine) { + this.network = network; + this.subnetwork = subnetwork; + this.copiedLine = copiedLine; } + + @Override protected NetworkImpl getNetwork() { return network; @@ -110,6 +122,26 @@ public LineImpl add() { line.addTerminal(terminal1); line.addTerminal(terminal2); + if (copiedLine != null) { + Collection> extensions = copiedLine.getExtensions(); + extensions.forEach(lineExtension -> + line.addExtension((Class>) lineExtension.getClass(), lineExtension)); + + copiedLine.getOperationalLimitsGroups1().forEach(operationalLimitsGroup -> { + OperationalLimitsGroup copiedGroup = line.newOperationalLimitsGroup1(operationalLimitsGroup.getId()); + copiedGroup.newCurrentLimits(line.getCurrentLimits1().orElse(null)).add(); + copiedGroup.newActivePowerLimits(line.getActivePowerLimits1().orElse(null)).add(); + copiedGroup.newApparentPowerLimits(line.getApparentPowerLimits1().orElse(null)).add(); + }); + + copiedLine.getOperationalLimitsGroups2().forEach(operationalLimitsGroup -> { + OperationalLimitsGroup copiedGroup = line.newOperationalLimitsGroup1(operationalLimitsGroup.getId()); + copiedGroup.newCurrentLimits(line.getCurrentLimits2().orElse(null)).add(); + copiedGroup.newActivePowerLimits(line.getActivePowerLimits2().orElse(null)).add(); + copiedGroup.newApparentPowerLimits(line.getApparentPowerLimits2().orElse(null)).add(); + }); + } + // check that the line is attachable on both side voltageLevel1.attach(terminal1, true); voltageLevel2.attach(terminal2, true); diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NetworkImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NetworkImpl.java index c53dc5cfea0..495d0222995 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NetworkImpl.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NetworkImpl.java @@ -366,6 +366,20 @@ LineAdderImpl newLine(String subnetwork) { return new LineAdderImpl(this, subnetwork); } + @Override + public LineAdderImpl newLine(Line line) { + return newLine().setR(line.getR()) + .setX(line.getX()) + .setG1(line.getG1()) + .setG2(line.getG2()) + .setB1(line.getB1()) + .setB2(line.getB2()) + .setVoltageLevel1(line.getTerminal1().getVoltageLevel().getId()) + .setVoltageLevel2(line.getTerminal2().getVoltageLevel().getId()); + } + + LineAdderImpl newLine(String subnetwork, Line line) { return new LineAdderImpl(this, subnetwork, line); } + @Override public Iterable getLines() { return Collections.unmodifiableCollection(index.getAll(LineImpl.class)); diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/SubnetworkImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/SubnetworkImpl.java index 04dad01f24b..25e4f1a04db 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/SubnetworkImpl.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/SubnetworkImpl.java @@ -232,6 +232,11 @@ public LineAdder newLine() { return getNetwork().newLine(id); } + @Override + public LineAdder newLine(Line line) { + return getNetwork().newLine(line.getId()); + } + @Override public Iterable getLines() { return getLineStream().toList(); diff --git a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractLineTest.java b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractLineTest.java index 5607098b7b7..de9e50ca792 100644 --- a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractLineTest.java +++ b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractLineTest.java @@ -199,6 +199,7 @@ public void testLineCopier() { .setBus2("busB") .setConnectableBus1("busA") .setConnectableBus2("busB"); + acLineAdder1.add(); Line acLine1 = network.getLine("line1"); From c6a7463e6f3bf87936dc12b6f533a365c7557b05 Mon Sep 17 00:00:00 2001 From: Naledi EL CHEIKH Date: Wed, 20 Nov 2024 16:46:02 +0100 Subject: [PATCH 3/9] update : lines adder impl updated by adding operational limit groups, and tests Signed-off-by: Naledi EL CHEIKH --- .../iidm/network/util/LoadingLimitsUtil.java | 4 +++ .../iidm/network/impl/LineAdderImpl.java | 30 ++++++++----------- .../iidm/network/impl/NetworkImpl.java | 2 +- .../iidm/network/tck/AbstractLineTest.java | 16 +++++++++- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/util/LoadingLimitsUtil.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/util/LoadingLimitsUtil.java index 8f482e69f66..7e56a045afb 100644 --- a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/util/LoadingLimitsUtil.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/util/LoadingLimitsUtil.java @@ -7,6 +7,7 @@ */ package com.powsybl.iidm.network.util; +import com.powsybl.commons.PowsyblException; import com.powsybl.iidm.network.*; import com.sun.source.tree.UsesTree; @@ -97,6 +98,9 @@ public static > void * @param limits the limits to copy */ public static > A initializeFromLoadingLimits(A adder, L limits) { + if (limits == null) { + throw new PowsyblException("Cannot initialize new limits from null limits"); + } adder.setPermanentLimit(limits.getPermanentLimit()); limits.getTemporaryLimits().forEach(limit -> adder.beginTemporaryLimit() diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/LineAdderImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/LineAdderImpl.java index 6c31824682e..d9d930ca6b1 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/LineAdderImpl.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/LineAdderImpl.java @@ -7,12 +7,9 @@ */ package com.powsybl.iidm.network.impl; -import com.powsybl.commons.extensions.Extension; import com.powsybl.iidm.network.*; import com.powsybl.commons.ref.Ref; -import java.util.Collection; - /** * * @author Geoffroy Jamgotchian {@literal } @@ -123,23 +120,22 @@ public LineImpl add() { line.addTerminal(terminal2); if (copiedLine != null) { - Collection> extensions = copiedLine.getExtensions(); - extensions.forEach(lineExtension -> - line.addExtension((Class>) lineExtension.getClass(), lineExtension)); - - copiedLine.getOperationalLimitsGroups1().forEach(operationalLimitsGroup -> { - OperationalLimitsGroup copiedGroup = line.newOperationalLimitsGroup1(operationalLimitsGroup.getId()); - copiedGroup.newCurrentLimits(line.getCurrentLimits1().orElse(null)).add(); - copiedGroup.newActivePowerLimits(line.getActivePowerLimits1().orElse(null)).add(); - copiedGroup.newApparentPowerLimits(line.getApparentPowerLimits1().orElse(null)).add(); + copiedLine.getOperationalLimitsGroups1().forEach(groupToCopy -> { + OperationalLimitsGroup copy1 = line.newOperationalLimitsGroup1(groupToCopy.getId()); + groupToCopy.getCurrentLimits().ifPresent(limit -> copy1.newCurrentLimits(limit).add()); + groupToCopy.getActivePowerLimits().ifPresent(limit -> copy1.newActivePowerLimits(limit).add()); + groupToCopy.getApparentPowerLimits().ifPresent(limit -> copy1.newApparentPowerLimits(limit).add()); }); - copiedLine.getOperationalLimitsGroups2().forEach(operationalLimitsGroup -> { - OperationalLimitsGroup copiedGroup = line.newOperationalLimitsGroup1(operationalLimitsGroup.getId()); - copiedGroup.newCurrentLimits(line.getCurrentLimits2().orElse(null)).add(); - copiedGroup.newActivePowerLimits(line.getActivePowerLimits2().orElse(null)).add(); - copiedGroup.newApparentPowerLimits(line.getApparentPowerLimits2().orElse(null)).add(); + copiedLine.getOperationalLimitsGroups2().forEach(groupToCopy -> { + OperationalLimitsGroup copy2 = line.newOperationalLimitsGroup2(groupToCopy.getId()); + groupToCopy.getCurrentLimits().ifPresent(limit -> copy2.newCurrentLimits(limit).add()); + groupToCopy.getActivePowerLimits().ifPresent(limit -> copy2.newActivePowerLimits(limit).add()); + groupToCopy.getApparentPowerLimits().ifPresent(limit -> copy2.newApparentPowerLimits(limit).add()); }); + + copiedLine.getSelectedOperationalLimitsGroupId1().ifPresent(line::setSelectedOperationalLimitsGroup1); + copiedLine.getSelectedOperationalLimitsGroupId2().ifPresent(line::setSelectedOperationalLimitsGroup2); } // check that the line is attachable on both side diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NetworkImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NetworkImpl.java index 495d0222995..29450569176 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NetworkImpl.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NetworkImpl.java @@ -368,7 +368,7 @@ LineAdderImpl newLine(String subnetwork) { @Override public LineAdderImpl newLine(Line line) { - return newLine().setR(line.getR()) + return newLine(null, line).setR(line.getR()) .setX(line.getX()) .setG1(line.getG1()) .setG2(line.getG2()) diff --git a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractLineTest.java b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractLineTest.java index de9e50ca792..b14a3c19125 100644 --- a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractLineTest.java +++ b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractLineTest.java @@ -199,9 +199,15 @@ public void testLineCopier() { .setBus2("busB") .setConnectableBus1("busA") .setConnectableBus2("busB"); - acLineAdder1.add(); Line acLine1 = network.getLine("line1"); + // Group and limits creation + acLine1.newOperationalLimitsGroup1("group1").newCurrentLimits().setPermanentLimit(220.0).add(); + acLine1.setSelectedOperationalLimitsGroup1("group1"); + Optional optionalLimits1 = acLine1.getCurrentLimits1(); + assertTrue(optionalLimits1.isPresent()); + CurrentLimits limits1 = optionalLimits1.get(); + // Second limit created by copy LineAdder acLineAdder2 = network.newLine(acLine1); @@ -214,9 +220,17 @@ public void testLineCopier() { .setConnectableBus2("busB"); acLineAdder2.add(); Line acLine2 = network.getLine("line2"); + // Limits check to set up test + Optional optionalLimits2 = acLine2.getCurrentLimits1(); + assertTrue(optionalLimits2.isPresent()); + CurrentLimits limits2 = optionalLimits2.get(); + // Tests assertNotNull(acLine2); assertTrue(areLinesIdentical(acLine1, acLine2)); + assertEquals(limits1.getPermanentLimit(), limits2.getPermanentLimit()); + assertSame(acLine1.getSelectedOperationalLimitsGroupId2(), acLine2.getSelectedOperationalLimitsGroupId2()); + } @Test From 87d4e226467036cbbde6b6cd3699e0c15fb9bbaa Mon Sep 17 00:00:00 2001 From: Naledi EL CHEIKH Date: Wed, 20 Nov 2024 17:31:17 +0100 Subject: [PATCH 4/9] update : lines adder impl updated by adding operational limit groups, and tests Signed-off-by: Naledi EL CHEIKH --- .../iidm/network/util/LoadingLimitsUtil.java | 2 -- .../iidm/network/impl/LineAdderImpl.java | 3 --- .../iidm/network/impl/NetworkImpl.java | 20 ++++++++++--------- .../iidm/network/tck/AbstractLineTest.java | 1 - 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/util/LoadingLimitsUtil.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/util/LoadingLimitsUtil.java index 7e56a045afb..7a4874636c9 100644 --- a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/util/LoadingLimitsUtil.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/util/LoadingLimitsUtil.java @@ -9,10 +9,8 @@ import com.powsybl.commons.PowsyblException; import com.powsybl.iidm.network.*; -import com.sun.source.tree.UsesTree; import java.util.Comparator; -import java.util.Optional; import static java.lang.Integer.MAX_VALUE; diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/LineAdderImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/LineAdderImpl.java index d9d930ca6b1..3a910826812 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/LineAdderImpl.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/LineAdderImpl.java @@ -19,7 +19,6 @@ class LineAdderImpl extends AbstractBranchAdder implements LineAd private final NetworkImpl network; private final String subnetwork; private final Line copiedLine; - private double r = Double.NaN; @@ -45,8 +44,6 @@ class LineAdderImpl extends AbstractBranchAdder implements LineAd this.copiedLine = copiedLine; } - - @Override protected NetworkImpl getNetwork() { return network; diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NetworkImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NetworkImpl.java index 29450569176..cb59468f3a4 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NetworkImpl.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/NetworkImpl.java @@ -368,17 +368,19 @@ LineAdderImpl newLine(String subnetwork) { @Override public LineAdderImpl newLine(Line line) { - return newLine(null, line).setR(line.getR()) - .setX(line.getX()) - .setG1(line.getG1()) - .setG2(line.getG2()) - .setB1(line.getB1()) - .setB2(line.getB2()) - .setVoltageLevel1(line.getTerminal1().getVoltageLevel().getId()) - .setVoltageLevel2(line.getTerminal2().getVoltageLevel().getId()); + return newLine(null, line).setR(line.getR()) + .setX(line.getX()) + .setG1(line.getG1()) + .setG2(line.getG2()) + .setB1(line.getB1()) + .setB2(line.getB2()) + .setVoltageLevel1(line.getTerminal1().getVoltageLevel().getId()) + .setVoltageLevel2(line.getTerminal2().getVoltageLevel().getId()); } - LineAdderImpl newLine(String subnetwork, Line line) { return new LineAdderImpl(this, subnetwork, line); } + LineAdderImpl newLine(String subnetwork, Line line) { + return new LineAdderImpl(this, subnetwork, line); + } @Override public Iterable getLines() { diff --git a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractLineTest.java b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractLineTest.java index b14a3c19125..ec8d5e2b52a 100644 --- a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractLineTest.java +++ b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractLineTest.java @@ -208,7 +208,6 @@ public void testLineCopier() { assertTrue(optionalLimits1.isPresent()); CurrentLimits limits1 = optionalLimits1.get(); - // Second limit created by copy LineAdder acLineAdder2 = network.newLine(acLine1); acLineAdder2 From 67fcd206af723d0b5e6565c8287fcb20554bca11 Mon Sep 17 00:00:00 2001 From: Naledi EL CHEIKH Date: Mon, 25 Nov 2024 14:12:11 +0100 Subject: [PATCH 5/9] update : added tests on lines copy for operational limit groups Signed-off-by: Naledi EL CHEIKH --- .../iidm/network/tck/AbstractLineTest.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractLineTest.java b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractLineTest.java index ec8d5e2b52a..2337f086780 100644 --- a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractLineTest.java +++ b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractLineTest.java @@ -201,12 +201,20 @@ public void testLineCopier() { .setConnectableBus2("busB"); acLineAdder1.add(); Line acLine1 = network.getLine("line1"); - // Group and limits creation + // Group and limits creation 1 acLine1.newOperationalLimitsGroup1("group1").newCurrentLimits().setPermanentLimit(220.0).add(); acLine1.setSelectedOperationalLimitsGroup1("group1"); Optional optionalLimits1 = acLine1.getCurrentLimits1(); assertTrue(optionalLimits1.isPresent()); CurrentLimits limits1 = optionalLimits1.get(); + // Group and limit creation 2 + acLine1.newOperationalLimitsGroup2("group2").newCurrentLimits().setPermanentLimit(80.0).add(); + acLine1.setSelectedOperationalLimitsGroup2("group2"); + Optional optionalLimits2 = acLine1.getCurrentLimits2(); + assertTrue(optionalLimits2.isPresent()); + CurrentLimits limits2 = optionalLimits2.get(); + + assertNotNull(limits2); // Second limit created by copy LineAdder acLineAdder2 = network.newLine(acLine1); @@ -220,15 +228,16 @@ public void testLineCopier() { acLineAdder2.add(); Line acLine2 = network.getLine("line2"); // Limits check to set up test - Optional optionalLimits2 = acLine2.getCurrentLimits1(); - assertTrue(optionalLimits2.isPresent()); - CurrentLimits limits2 = optionalLimits2.get(); + Optional optionalLimits3 = acLine2.getCurrentLimits1(); + assertTrue(optionalLimits3.isPresent()); + CurrentLimits limits3 = optionalLimits3.get(); // Tests assertNotNull(acLine2); assertTrue(areLinesIdentical(acLine1, acLine2)); - assertEquals(limits1.getPermanentLimit(), limits2.getPermanentLimit()); - assertSame(acLine1.getSelectedOperationalLimitsGroupId2(), acLine2.getSelectedOperationalLimitsGroupId2()); + assertEquals(limits1.getPermanentLimit(), limits3.getPermanentLimit()); + assertNotNull(acLine2.getOperationalLimitsGroup2("group2")); + assertEquals(acLine1.getSelectedOperationalLimitsGroupId2(), acLine2.getSelectedOperationalLimitsGroupId2()); } From f57a6ed54b9e614d2c9ce4dbbf9d23d3aeb38ca5 Mon Sep 17 00:00:00 2001 From: Naledi EL CHEIKH Date: Mon, 25 Nov 2024 14:16:15 +0100 Subject: [PATCH 6/9] update : added tests on limits adder by copy Signed-off-by: Naledi EL CHEIKH --- .../com/powsybl/iidm/network/tck/AbstractCurrentLimitsTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractCurrentLimitsTest.java b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractCurrentLimitsTest.java index 88bdb4f4dc1..5bc9220e292 100644 --- a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractCurrentLimitsTest.java +++ b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractCurrentLimitsTest.java @@ -7,6 +7,7 @@ */ package com.powsybl.iidm.network.tck; +import com.powsybl.commons.PowsyblException; import com.powsybl.iidm.network.*; import org.junit.jupiter.api.Test; @@ -738,6 +739,7 @@ public void testAdderByCopy() { adder.add(); assertTrue(areLimitsIdentical(limits1, limits2)); + assertThrows(PowsyblException.class, () -> line.newCurrentLimits1(null)); } @Test From 9a1a21adfe86a3144d640f4838e5487e90c22780 Mon Sep 17 00:00:00 2001 From: Naledi EL CHEIKH Date: Mon, 25 Nov 2024 14:26:35 +0100 Subject: [PATCH 7/9] update : added tests on lines copy for active and apparent power limits Signed-off-by: Naledi EL CHEIKH --- .../iidm/network/tck/AbstractLineTest.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractLineTest.java b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractLineTest.java index 2337f086780..c76660932fc 100644 --- a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractLineTest.java +++ b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractLineTest.java @@ -207,13 +207,28 @@ public void testLineCopier() { Optional optionalLimits1 = acLine1.getCurrentLimits1(); assertTrue(optionalLimits1.isPresent()); CurrentLimits limits1 = optionalLimits1.get(); + assertNotNull(limits1); + + acLine1.getOperationalLimitsGroup1("group1").get().newActivePowerLimits().setPermanentLimit(220.0).add(); + acLine1.setSelectedOperationalLimitsGroup1("group1"); + Optional optionalActivePowerLimits1 = acLine1.getActivePowerLimits1(); + assertTrue(optionalActivePowerLimits1.isPresent()); + ActivePowerLimits activePowerLimits1 = optionalActivePowerLimits1.get(); + assertNotNull(activePowerLimits1); + + acLine1.getOperationalLimitsGroup1("group1").get().newApparentPowerLimits().setPermanentLimit(220.0).add(); + acLine1.setSelectedOperationalLimitsGroup1("group1"); + Optional optionalApparentPowerLimits1 = acLine1.getApparentPowerLimits1(); + assertTrue(optionalApparentPowerLimits1.isPresent()); + ApparentPowerLimits apparentPowerLimits1 = optionalApparentPowerLimits1.get(); + assertNotNull(apparentPowerLimits1); + // Group and limit creation 2 acLine1.newOperationalLimitsGroup2("group2").newCurrentLimits().setPermanentLimit(80.0).add(); acLine1.setSelectedOperationalLimitsGroup2("group2"); Optional optionalLimits2 = acLine1.getCurrentLimits2(); assertTrue(optionalLimits2.isPresent()); CurrentLimits limits2 = optionalLimits2.get(); - assertNotNull(limits2); // Second limit created by copy From eccf723d92571ea38edee84fae6932c561c72046 Mon Sep 17 00:00:00 2001 From: Naledi EL CHEIKH Date: Tue, 10 Dec 2024 13:24:09 +0100 Subject: [PATCH 8/9] update : corrected limits adder test Signed-off-by: Naledi EL CHEIKH --- .../java/com/powsybl/iidm/network/Branch.java | 1 - .../iidm/network/util/LoadingLimitsUtil.java | 9 +++++-- .../iidm/network/impl/SubnetworkImpl.java | 2 +- .../tck/AbstractCurrentLimitsTest.java | 2 +- .../tck/AbstractIdenticalLinesTest.java | 25 ------------------- .../iidm/network/tck/AbstractLineTest.java | 19 +++++++++++++- 6 files changed, 27 insertions(+), 31 deletions(-) delete mode 100644 iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractIdenticalLinesTest.java diff --git a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Branch.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Branch.java index 2fb120979ac..d24186fdc80 100644 --- a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Branch.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/Branch.java @@ -97,7 +97,6 @@ * * * - * @author Geoffroy Jamgotchian {@literal } */ public interface Branch> extends Identifiable { diff --git a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/util/LoadingLimitsUtil.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/util/LoadingLimitsUtil.java index 7a4874636c9..156349064ab 100644 --- a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/util/LoadingLimitsUtil.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/util/LoadingLimitsUtil.java @@ -7,8 +7,9 @@ */ package com.powsybl.iidm.network.util; -import com.powsybl.commons.PowsyblException; import com.powsybl.iidm.network.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.Comparator; @@ -22,6 +23,9 @@ public final class LoadingLimitsUtil { private LoadingLimitsUtil() { } + private static final Logger LOGGER = LoggerFactory.getLogger(LoadingLimitsUtil.class); + + /** * Interface for objects used to report the performed operation on limits when fixed by * {@link #fixMissingPermanentLimit(LoadingLimitsAdder, double, String, LimitFixLogger)}. @@ -97,7 +101,8 @@ public static > void */ public static > A initializeFromLoadingLimits(A adder, L limits) { if (limits == null) { - throw new PowsyblException("Cannot initialize new limits from null limits"); + LOGGER.warn("Created adder is empty"); + return adder; } adder.setPermanentLimit(limits.getPermanentLimit()); limits.getTemporaryLimits().forEach(limit -> diff --git a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/SubnetworkImpl.java b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/SubnetworkImpl.java index 827d78567fb..afd91472ec6 100644 --- a/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/SubnetworkImpl.java +++ b/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/SubnetworkImpl.java @@ -234,7 +234,7 @@ public LineAdder newLine() { @Override public LineAdder newLine(Line line) { - return getNetwork().newLine(line.getId()); + return getNetwork().newLine(id, line); } @Override diff --git a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractCurrentLimitsTest.java b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractCurrentLimitsTest.java index 5bc9220e292..b3b296fba38 100644 --- a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractCurrentLimitsTest.java +++ b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractCurrentLimitsTest.java @@ -739,7 +739,7 @@ public void testAdderByCopy() { adder.add(); assertTrue(areLimitsIdentical(limits1, limits2)); - assertThrows(PowsyblException.class, () -> line.newCurrentLimits1(null)); + assertFalse(line.newCurrentLimits1(null).hasTemporaryLimits()); } @Test diff --git a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractIdenticalLinesTest.java b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractIdenticalLinesTest.java deleted file mode 100644 index 0b057014ad2..00000000000 --- a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractIdenticalLinesTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.powsybl.iidm.network.tck; - -import com.powsybl.iidm.network.Line; - -import java.util.Objects; - -public abstract class AbstractIdenticalLinesTest { - public boolean areLinesIdentical(Line line1, Line line2) { - boolean areIdentical = false; - - if (line1 != null && line2 != null) { - areIdentical = line1.getR() == line2.getR() - && line1.getX() == line2.getX() - && line1.getG1() == line2.getG1() - && line1.getG2() == line2.getG2() - && line1.getB1() == line2.getB1() - && line1.getB2() == line2.getB2() - && Objects.equals(line1.getTerminal1().getVoltageLevel().getId(), line2.getTerminal1().getVoltageLevel().getId()) - && Objects.equals(line1.getTerminal2().getVoltageLevel().getId(), line2.getTerminal2().getVoltageLevel().getId()); - } - return areIdentical; - } -} - - diff --git a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractLineTest.java b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractLineTest.java index 25389676c63..322764fb084 100644 --- a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractLineTest.java +++ b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractLineTest.java @@ -20,6 +20,7 @@ import org.mockito.Mockito; import java.util.Collection; +import java.util.Objects; import java.util.Optional; import java.util.stream.Stream; @@ -27,7 +28,7 @@ import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; -public abstract class AbstractLineTest extends AbstractIdenticalLinesTest { +public abstract class AbstractLineTest { private static final String INVALID = "invalid"; @@ -41,6 +42,22 @@ public abstract class AbstractLineTest extends AbstractIdenticalLinesTest { private VoltageLevel voltageLevelA; private VoltageLevel voltageLevelB; + public boolean areLinesIdentical(Line line1, Line line2) { + boolean areIdentical = false; + + if (line1 != null && line2 != null) { + areIdentical = line1.getR() == line2.getR() + && line1.getX() == line2.getX() + && line1.getG1() == line2.getG1() + && line1.getG2() == line2.getG2() + && line1.getB1() == line2.getB1() + && line1.getB2() == line2.getB2() + && Objects.equals(line1.getTerminal1().getVoltageLevel().getId(), line2.getTerminal1().getVoltageLevel().getId()) + && Objects.equals(line1.getTerminal2().getVoltageLevel().getId(), line2.getTerminal2().getVoltageLevel().getId()); + } + return areIdentical; + } + @BeforeEach public void setUp() { network = NoEquipmentNetworkFactory.create(); From a13e13c2c199bb2a2528174078c9a2dafb7edde2 Mon Sep 17 00:00:00 2001 From: Naledi EL CHEIKH Date: Tue, 10 Dec 2024 15:19:26 +0100 Subject: [PATCH 9/9] update : corrected limits adder test Signed-off-by: Naledi EL CHEIKH --- .../java/com/powsybl/iidm/network/util/LoadingLimitsUtil.java | 1 - .../com/powsybl/iidm/network/tck/AbstractCurrentLimitsTest.java | 1 - 2 files changed, 2 deletions(-) diff --git a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/util/LoadingLimitsUtil.java b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/util/LoadingLimitsUtil.java index 156349064ab..ca75d5a8621 100644 --- a/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/util/LoadingLimitsUtil.java +++ b/iidm/iidm-api/src/main/java/com/powsybl/iidm/network/util/LoadingLimitsUtil.java @@ -25,7 +25,6 @@ private LoadingLimitsUtil() { private static final Logger LOGGER = LoggerFactory.getLogger(LoadingLimitsUtil.class); - /** * Interface for objects used to report the performed operation on limits when fixed by * {@link #fixMissingPermanentLimit(LoadingLimitsAdder, double, String, LimitFixLogger)}. diff --git a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractCurrentLimitsTest.java b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractCurrentLimitsTest.java index b3b296fba38..dfa8444a8c6 100644 --- a/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractCurrentLimitsTest.java +++ b/iidm/iidm-tck/src/test/java/com/powsybl/iidm/network/tck/AbstractCurrentLimitsTest.java @@ -7,7 +7,6 @@ */ package com.powsybl.iidm.network.tck; -import com.powsybl.commons.PowsyblException; import com.powsybl.iidm.network.*; import org.junit.jupiter.api.Test;