From a2c865866c0020cad67efc5e3e42e5981ab202d4 Mon Sep 17 00:00:00 2001 From: Damien Jeandemange Date: Tue, 18 Jul 2023 09:33:27 +0200 Subject: [PATCH 1/8] reproduce issue Signed-off-by: Damien Jeandemange --- .../ac/AcLoadFlowPhaseShifterTest.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowPhaseShifterTest.java b/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowPhaseShifterTest.java index e898eb9c76..4fdf060e0c 100644 --- a/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowPhaseShifterTest.java +++ b/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowPhaseShifterTest.java @@ -157,6 +157,35 @@ void remoteFlowControlT2wtTest() { assertEquals(0, t2wt.getPhaseTapChanger().getTapPosition()); } + @Test + void remoteFlowControlOnZeroImpedanceBranch() { + selectNetwork(PhaseControlFactory.createNetworkWithT2wt()); + parameters.setPhaseShifterRegulationOn(true); + t2wt.getPhaseTapChanger().setRegulationMode(PhaseTapChanger.RegulationMode.ACTIVE_POWER_CONTROL) + .setTargetDeadband(1) + .setRegulating(true) + .setTapPosition(2) + .setRegulationTerminal(line1.getTerminal1()) + .setRegulationValue(83); + line1.setR(0).setX(0).setG1(0).setG2(0).setB1(0).setB2(0); + + // FIXME: throws + // Caused by: java.util.NoSuchElementException: No value present + // at java.base/java.util.Optional.orElseThrow(Optional.java:382) + // at com.powsybl.openloadflow.ac.equations.AcEquationSystemCreator.updateTransformerPhaseControlEquations(AcEquationSystemCreator.java:474) + // at com.powsybl.openloadflow.ac.equations.AcEquationSystemUpdater.onTransformerPhaseControlChange(AcEquationSystemUpdater.java:43) + // at com.powsybl.openloadflow.network.LfNetworkListenerTracer.onTransformerPhaseControlChange(LfNetworkListenerTracer.java:54) + // at com.powsybl.openloadflow.network.impl.AbstractLfBranch.setPhaseControlEnabled(AbstractLfBranch.java:163) + // at com.powsybl.openloadflow.ac.outerloop.PhaseControlOuterLoop.initialize(PhaseControlOuterLoop.java:39) + // at com.powsybl.openloadflow.ac.outerloop.PhaseControlOuterLoop.initialize(PhaseControlOuterLoop.java:24) + // at com.powsybl.openloadflow.ac.AcloadFlowEngine.run(AcloadFlowEngine.java:130) + LoadFlowResult result = loadFlowRunner.run(network, parameters); + assertTrue(result.isOk()); + // TODO will be different values: assertActivePowerEquals(83.688, line1.getTerminal1()); + // TODO will be different values: assertActivePowerEquals(16.527, line2.getTerminal1()); + // TODO will be different values: assertEquals(0, t2wt.getPhaseTapChanger().getTapPosition()); + } + @Test void currentLimiterT2wtTest() { selectNetwork(PhaseControlFactory.createNetworkWithT2wt()); From 1207750a31bbbb97a49abacf5d9b838a4088ddfd Mon Sep 17 00:00:00 2001 From: Anne Tilloy Date: Tue, 18 Jul 2023 13:16:44 +0200 Subject: [PATCH 2/8] Fix proposal. Signed-off-by: Anne Tilloy --- .../openloadflow/network/LfNetwork.java | 3 +- .../network/impl/AbstractLfBranch.java | 4 +++ .../ac/AcLoadFlowPhaseShifterTest.java | 28 ++++++------------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/powsybl/openloadflow/network/LfNetwork.java b/src/main/java/com/powsybl/openloadflow/network/LfNetwork.java index f64eb6f07a..3dd3a90eb5 100644 --- a/src/main/java/com/powsybl/openloadflow/network/LfNetwork.java +++ b/src/main/java/com/powsybl/openloadflow/network/LfNetwork.java @@ -482,8 +482,9 @@ public void fix(boolean minImpedance, double lowImpedanceThreshold) { } } else { // zero impedance controller phase shifter is not supported + // zero impedance controlled branch is not supported branches.stream() - .filter(LfBranch::isPhaseController) + .filter(b -> b.isPhaseController() || b.isPhaseControlled()) .forEach(branch -> branch.setMinZ(lowImpedanceThreshold)); } } diff --git a/src/main/java/com/powsybl/openloadflow/network/impl/AbstractLfBranch.java b/src/main/java/com/powsybl/openloadflow/network/impl/AbstractLfBranch.java index dd5622f8b6..f273ac3c13 100644 --- a/src/main/java/com/powsybl/openloadflow/network/impl/AbstractLfBranch.java +++ b/src/main/java/com/powsybl/openloadflow/network/impl/AbstractLfBranch.java @@ -281,6 +281,10 @@ public void setMinZ(double lowImpedanceThreshold) { if (piModel.setMinZ(lowImpedanceThreshold, loadFlowModel)) { LOGGER.trace("Branch {} has a low impedance in {}, set to min {}", getId(), loadFlowModel, lowImpedanceThreshold); zeroImpedanceContextByModel.get(loadFlowModel).zeroImpedance = false; + } else if (isZeroImpedance(loadFlowModel)) { + // For DC load flow model, the min impedance has already been set by AC load flow model but + // the zero impedance field was not updated. + zeroImpedanceContextByModel.get(loadFlowModel).zeroImpedance = false; } } } diff --git a/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowPhaseShifterTest.java b/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowPhaseShifterTest.java index 4fdf060e0c..6f14b20633 100644 --- a/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowPhaseShifterTest.java +++ b/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowPhaseShifterTest.java @@ -168,22 +168,11 @@ void remoteFlowControlOnZeroImpedanceBranch() { .setRegulationTerminal(line1.getTerminal1()) .setRegulationValue(83); line1.setR(0).setX(0).setG1(0).setG2(0).setB1(0).setB2(0); - - // FIXME: throws - // Caused by: java.util.NoSuchElementException: No value present - // at java.base/java.util.Optional.orElseThrow(Optional.java:382) - // at com.powsybl.openloadflow.ac.equations.AcEquationSystemCreator.updateTransformerPhaseControlEquations(AcEquationSystemCreator.java:474) - // at com.powsybl.openloadflow.ac.equations.AcEquationSystemUpdater.onTransformerPhaseControlChange(AcEquationSystemUpdater.java:43) - // at com.powsybl.openloadflow.network.LfNetworkListenerTracer.onTransformerPhaseControlChange(LfNetworkListenerTracer.java:54) - // at com.powsybl.openloadflow.network.impl.AbstractLfBranch.setPhaseControlEnabled(AbstractLfBranch.java:163) - // at com.powsybl.openloadflow.ac.outerloop.PhaseControlOuterLoop.initialize(PhaseControlOuterLoop.java:39) - // at com.powsybl.openloadflow.ac.outerloop.PhaseControlOuterLoop.initialize(PhaseControlOuterLoop.java:24) - // at com.powsybl.openloadflow.ac.AcloadFlowEngine.run(AcloadFlowEngine.java:130) LoadFlowResult result = loadFlowRunner.run(network, parameters); assertTrue(result.isOk()); - // TODO will be different values: assertActivePowerEquals(83.688, line1.getTerminal1()); - // TODO will be different values: assertActivePowerEquals(16.527, line2.getTerminal1()); - // TODO will be different values: assertEquals(0, t2wt.getPhaseTapChanger().getTapPosition()); + assertActivePowerEquals(100.0, line1.getTerminal1()); + assertActivePowerEquals(0.0, line2.getTerminal1()); + assertEquals(1, t2wt.getPhaseTapChanger().getTapPosition()); } @Test @@ -650,15 +639,16 @@ void activePowerflowControlAndNonImpedantPhaseShifterTest() { assertActivePowerEquals(-112.019, line2.getTerminal2()); assertEquals(2, t2wt.getPhaseTapChanger().getTapPosition()); - line1.setR(0).setX(0); + line1.setR(0.0).setX(0.0); t2wt.setR(2.0).setX(100.0); t2wt.getPhaseTapChanger() .setRegulationTerminal(line1.getTerminal1()) .setTapPosition(0); + LoadFlowResult result2 = loadFlowRunner.run(network, parameters); - assertTrue(result.isOk()); - assertActivePowerEquals(-12.006, line1.getTerminal1()); - assertActivePowerEquals(112.197, line2.getTerminal1()); - assertEquals(0, t2wt.getPhaseTapChanger().getTapPosition()); + assertTrue(result2.isOk()); + assertActivePowerEquals(100.0, line1.getTerminal1()); + assertActivePowerEquals(0.0, line2.getTerminal1()); + assertEquals(1, t2wt.getPhaseTapChanger().getTapPosition()); } } From 8b93ea538cdecc855aac50b90f169e8291ae0d6c Mon Sep 17 00:00:00 2001 From: Anne Tilloy Date: Tue, 18 Jul 2023 13:39:20 +0200 Subject: [PATCH 3/8] Add unit test. Signed-off-by: Anne Tilloy --- .../network/impl/LfNetworkLoaderImplTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/test/java/com/powsybl/openloadflow/network/impl/LfNetworkLoaderImplTest.java b/src/test/java/com/powsybl/openloadflow/network/impl/LfNetworkLoaderImplTest.java index a6b0d7e851..493212eced 100644 --- a/src/test/java/com/powsybl/openloadflow/network/impl/LfNetworkLoaderImplTest.java +++ b/src/test/java/com/powsybl/openloadflow/network/impl/LfNetworkLoaderImplTest.java @@ -204,4 +204,17 @@ void validationLevelTest5() { PowsyblException e = assertThrows(PowsyblException.class, () -> Networks.load(network, new FirstSlackBusSelector())); assertEquals("Only STEADY STATE HYPOTHESIS validation level of the network is supported", e.getMessage()); } + + @Test + void testMinImpedance() { + network = EurostagTutorialExample1Factory.create(); + network.getLine("NHV1_NHV2_1").setR(0.0).setX(0.0).setB1(0.0).setB2(0.0).setG1(0.0).setG2(0.0); + List lfNetworks = Networks.load(network, new FirstSlackBusSelector()); + LfBranch line = lfNetworks.get(0).getBranchById("NHV1_NHV2_1"); + assertTrue(line.isZeroImpedance(LoadFlowModel.AC)); + assertTrue(line.isZeroImpedance(LoadFlowModel.DC)); + line.setMinZ(10); // for both AC and DL load flow model + assertFalse(line.isZeroImpedance(LoadFlowModel.AC)); + assertFalse(line.isZeroImpedance(LoadFlowModel.DC)); + } } From cf1acc29d50a9481d3b3f4a5da6c893877799a4a Mon Sep 17 00:00:00 2001 From: Anne Tilloy Date: Tue, 18 Jul 2023 13:42:56 +0200 Subject: [PATCH 4/8] Fix comments. Signed-off-by: Anne Tilloy --- .../com/powsybl/openloadflow/network/impl/AbstractLfBranch.java | 2 +- .../openloadflow/network/impl/LfNetworkLoaderImplTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/powsybl/openloadflow/network/impl/AbstractLfBranch.java b/src/main/java/com/powsybl/openloadflow/network/impl/AbstractLfBranch.java index f273ac3c13..1e0b9b4862 100644 --- a/src/main/java/com/powsybl/openloadflow/network/impl/AbstractLfBranch.java +++ b/src/main/java/com/powsybl/openloadflow/network/impl/AbstractLfBranch.java @@ -283,7 +283,7 @@ public void setMinZ(double lowImpedanceThreshold) { zeroImpedanceContextByModel.get(loadFlowModel).zeroImpedance = false; } else if (isZeroImpedance(loadFlowModel)) { // For DC load flow model, the min impedance has already been set by AC load flow model but - // the zero impedance field was not updated. + // the zero impedance field must still be updated. zeroImpedanceContextByModel.get(loadFlowModel).zeroImpedance = false; } } diff --git a/src/test/java/com/powsybl/openloadflow/network/impl/LfNetworkLoaderImplTest.java b/src/test/java/com/powsybl/openloadflow/network/impl/LfNetworkLoaderImplTest.java index 493212eced..633cec96fe 100644 --- a/src/test/java/com/powsybl/openloadflow/network/impl/LfNetworkLoaderImplTest.java +++ b/src/test/java/com/powsybl/openloadflow/network/impl/LfNetworkLoaderImplTest.java @@ -213,7 +213,7 @@ void testMinImpedance() { LfBranch line = lfNetworks.get(0).getBranchById("NHV1_NHV2_1"); assertTrue(line.isZeroImpedance(LoadFlowModel.AC)); assertTrue(line.isZeroImpedance(LoadFlowModel.DC)); - line.setMinZ(10); // for both AC and DL load flow model + line.setMinZ(10); // for both AC and DC load flow model assertFalse(line.isZeroImpedance(LoadFlowModel.AC)); assertFalse(line.isZeroImpedance(LoadFlowModel.DC)); } From c7c7d6a9c50c53203fa7ca0b59e93a37a115eb88 Mon Sep 17 00:00:00 2001 From: Anne Tilloy Date: Tue, 18 Jul 2023 13:50:04 +0200 Subject: [PATCH 5/8] Clean unit test. Signed-off-by: Anne Tilloy --- .../ac/AcLoadFlowPhaseShifterTest.java | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowPhaseShifterTest.java b/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowPhaseShifterTest.java index 6f14b20633..06170a643f 100644 --- a/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowPhaseShifterTest.java +++ b/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowPhaseShifterTest.java @@ -157,24 +157,6 @@ void remoteFlowControlT2wtTest() { assertEquals(0, t2wt.getPhaseTapChanger().getTapPosition()); } - @Test - void remoteFlowControlOnZeroImpedanceBranch() { - selectNetwork(PhaseControlFactory.createNetworkWithT2wt()); - parameters.setPhaseShifterRegulationOn(true); - t2wt.getPhaseTapChanger().setRegulationMode(PhaseTapChanger.RegulationMode.ACTIVE_POWER_CONTROL) - .setTargetDeadband(1) - .setRegulating(true) - .setTapPosition(2) - .setRegulationTerminal(line1.getTerminal1()) - .setRegulationValue(83); - line1.setR(0).setX(0).setG1(0).setG2(0).setB1(0).setB2(0); - LoadFlowResult result = loadFlowRunner.run(network, parameters); - assertTrue(result.isOk()); - assertActivePowerEquals(100.0, line1.getTerminal1()); - assertActivePowerEquals(0.0, line2.getTerminal1()); - assertEquals(1, t2wt.getPhaseTapChanger().getTapPosition()); - } - @Test void currentLimiterT2wtTest() { selectNetwork(PhaseControlFactory.createNetworkWithT2wt()); From d17479f5641199ff5507aa527a78eef69bdc56c6 Mon Sep 17 00:00:00 2001 From: Anne Tilloy Date: Tue, 18 Jul 2023 13:53:05 +0200 Subject: [PATCH 6/8] Add log. Signed-off-by: Anne Tilloy --- .../com/powsybl/openloadflow/network/impl/AbstractLfBranch.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/powsybl/openloadflow/network/impl/AbstractLfBranch.java b/src/main/java/com/powsybl/openloadflow/network/impl/AbstractLfBranch.java index 1e0b9b4862..4ad959bc42 100644 --- a/src/main/java/com/powsybl/openloadflow/network/impl/AbstractLfBranch.java +++ b/src/main/java/com/powsybl/openloadflow/network/impl/AbstractLfBranch.java @@ -284,6 +284,7 @@ public void setMinZ(double lowImpedanceThreshold) { } else if (isZeroImpedance(loadFlowModel)) { // For DC load flow model, the min impedance has already been set by AC load flow model but // the zero impedance field must still be updated. + LOGGER.trace("Branch {} has a low impedance in {}, set to min {}", getId(), loadFlowModel, lowImpedanceThreshold); zeroImpedanceContextByModel.get(loadFlowModel).zeroImpedance = false; } } From 40ee1e54346f66baf20cf95d3dc58bb223c7d276 Mon Sep 17 00:00:00 2001 From: Damien Jeandemange Date: Tue, 18 Jul 2023 15:37:57 +0200 Subject: [PATCH 7/8] fix code smell Signed-off-by: Damien Jeandemange --- .../com/powsybl/openloadflow/network/LfNetwork.java | 3 +-- .../openloadflow/network/impl/AbstractLfBranch.java | 10 ++++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/powsybl/openloadflow/network/LfNetwork.java b/src/main/java/com/powsybl/openloadflow/network/LfNetwork.java index 3dd3a90eb5..c02688368f 100644 --- a/src/main/java/com/powsybl/openloadflow/network/LfNetwork.java +++ b/src/main/java/com/powsybl/openloadflow/network/LfNetwork.java @@ -481,8 +481,7 @@ public void fix(boolean minImpedance, double lowImpedanceThreshold) { branch.setMinZ(lowImpedanceThreshold); } } else { - // zero impedance controller phase shifter is not supported - // zero impedance controlled branch is not supported + // zero impedance controller phase shifter or controller branch is not supported branches.stream() .filter(b -> b.isPhaseController() || b.isPhaseControlled()) .forEach(branch -> branch.setMinZ(lowImpedanceThreshold)); diff --git a/src/main/java/com/powsybl/openloadflow/network/impl/AbstractLfBranch.java b/src/main/java/com/powsybl/openloadflow/network/impl/AbstractLfBranch.java index 4ad959bc42..843ae4709b 100644 --- a/src/main/java/com/powsybl/openloadflow/network/impl/AbstractLfBranch.java +++ b/src/main/java/com/powsybl/openloadflow/network/impl/AbstractLfBranch.java @@ -278,12 +278,10 @@ public boolean isConnectedAtBothSides() { @Override public void setMinZ(double lowImpedanceThreshold) { for (LoadFlowModel loadFlowModel : List.of(LoadFlowModel.AC, LoadFlowModel.DC)) { - if (piModel.setMinZ(lowImpedanceThreshold, loadFlowModel)) { - LOGGER.trace("Branch {} has a low impedance in {}, set to min {}", getId(), loadFlowModel, lowImpedanceThreshold); - zeroImpedanceContextByModel.get(loadFlowModel).zeroImpedance = false; - } else if (isZeroImpedance(loadFlowModel)) { - // For DC load flow model, the min impedance has already been set by AC load flow model but - // the zero impedance field must still be updated. + if (piModel.setMinZ(lowImpedanceThreshold, loadFlowModel) || + (LoadFlowModel.DC.equals(loadFlowModel) && isZeroImpedance(loadFlowModel))) { + // Note: For DC load flow model, the min impedance has already been set by AC load flow model but + // the zero impedance field must still be updated. LOGGER.trace("Branch {} has a low impedance in {}, set to min {}", getId(), loadFlowModel, lowImpedanceThreshold); zeroImpedanceContextByModel.get(loadFlowModel).zeroImpedance = false; } From 11f7dae99992eefb542959d946fd1b1c865fa7e0 Mon Sep 17 00:00:00 2001 From: Damien Jeandemange Date: Tue, 18 Jul 2023 15:40:21 +0200 Subject: [PATCH 8/8] typo Signed-off-by: Damien Jeandemange --- src/main/java/com/powsybl/openloadflow/network/LfNetwork.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/powsybl/openloadflow/network/LfNetwork.java b/src/main/java/com/powsybl/openloadflow/network/LfNetwork.java index c02688368f..413b9efb47 100644 --- a/src/main/java/com/powsybl/openloadflow/network/LfNetwork.java +++ b/src/main/java/com/powsybl/openloadflow/network/LfNetwork.java @@ -481,7 +481,7 @@ public void fix(boolean minImpedance, double lowImpedanceThreshold) { branch.setMinZ(lowImpedanceThreshold); } } else { - // zero impedance controller phase shifter or controller branch is not supported + // zero impedance phase shifter controller or controlled branch is not supported branches.stream() .filter(b -> b.isPhaseController() || b.isPhaseControlled()) .forEach(branch -> branch.setMinZ(lowImpedanceThreshold));