From f3615ad7d5b27025fc8aab99974ce7d78f60fb38 Mon Sep 17 00:00:00 2001 From: Joris Mancini Date: Fri, 18 Oct 2024 11:34:38 +0200 Subject: [PATCH 1/5] fix: split in sub-reports for a list of elements that could be too big Signed-off-by: Joris Mancini --- .../com/powsybl/openloadflow/util/Reports.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/powsybl/openloadflow/util/Reports.java b/src/main/java/com/powsybl/openloadflow/util/Reports.java index b35dcdf485..6a7421edf0 100644 --- a/src/main/java/com/powsybl/openloadflow/util/Reports.java +++ b/src/main/java/com/powsybl/openloadflow/util/Reports.java @@ -606,14 +606,25 @@ public static void reportMaxVoltageChangeStateVectorScaling(ReportNode reportNod } public static void reportNewtonRaphsonBusesOutOfRealisticVoltageRange(ReportNode reportNode, Map busesOutOfRealisticVoltageRange, double minRealisticVoltage, double maxRealisticVoltage) { - reportNode.newReportNode() - .withMessageTemplate("newtonRaphsonBusesOutOfRealisticVoltageRange", "${busCountOutOfRealisticVoltageRange} buses have a voltage magnitude out of the configured realistic range [${minRealisticVoltage}, ${maxRealisticVoltage}] p.u.: ${busesOutOfRealisticVoltageRange}") + ReportNode voltageOutOfRangeReport = reportNode.newReportNode() + .withMessageTemplate("busesOutOfVoltageRealisticRange", "Buses have a voltage magnitude out of the configured realistic range") + .add(); + + voltageOutOfRangeReport.newReportNode() + .withMessageTemplate("busesOutOfVoltageRealisticRangeSummary", "${busCountOutOfRealisticVoltageRange} buses have a voltage magnitude out of the configured realistic range [${minRealisticVoltage}, ${maxRealisticVoltage}]") .withUntypedValue("busCountOutOfRealisticVoltageRange", busesOutOfRealisticVoltageRange.size()) .withUntypedValue("minRealisticVoltage", minRealisticVoltage) .withUntypedValue("maxRealisticVoltage", maxRealisticVoltage) .withUntypedValue("busesOutOfRealisticVoltageRange", busesOutOfRealisticVoltageRange.toString()) .withSeverity(TypedValue.ERROR_SEVERITY) .add(); + + busesOutOfRealisticVoltageRange.forEach((id, voltage) -> voltageOutOfRangeReport.newReportNode() + .withMessageTemplate("busesOutOfVoltageRealisticRangeDetail", "Bus ${id} has an unrealistic voltage magnitude: ${voltage} pu") + .withUntypedValue("id", id) + .withUntypedValue("voltage", voltage) + .withSeverity(TypedValue.TRACE_SEVERITY) + .add()); } public static void reportAngleReferenceBusAndSlackBuses(ReportNode reportNode, String referenceBus, List slackBuses) { From 1b6b732d339b561de3490383ddcd875c990ffd64 Mon Sep 17 00:00:00 2001 From: Joris Mancini Date: Wed, 13 Nov 2024 10:17:04 +0100 Subject: [PATCH 2/5] fix: remove unused value in report Signed-off-by: Joris Mancini --- src/main/java/com/powsybl/openloadflow/util/Reports.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/powsybl/openloadflow/util/Reports.java b/src/main/java/com/powsybl/openloadflow/util/Reports.java index 6a7421edf0..8c021e068c 100644 --- a/src/main/java/com/powsybl/openloadflow/util/Reports.java +++ b/src/main/java/com/powsybl/openloadflow/util/Reports.java @@ -615,7 +615,6 @@ public static void reportNewtonRaphsonBusesOutOfRealisticVoltageRange(ReportNode .withUntypedValue("busCountOutOfRealisticVoltageRange", busesOutOfRealisticVoltageRange.size()) .withUntypedValue("minRealisticVoltage", minRealisticVoltage) .withUntypedValue("maxRealisticVoltage", maxRealisticVoltage) - .withUntypedValue("busesOutOfRealisticVoltageRange", busesOutOfRealisticVoltageRange.toString()) .withSeverity(TypedValue.ERROR_SEVERITY) .add(); From 418b53fa44c299ffc340028e4e5f9860c81e39f1 Mon Sep 17 00:00:00 2001 From: Damien Jeandemange Date: Wed, 13 Nov 2024 13:53:32 +0100 Subject: [PATCH 3/5] proposal Signed-off-by: Damien Jeandemange --- .../powsybl/openloadflow/util/Reports.java | 4 --- .../openloadflow/ac/AcLoadFlowReportTest.java | 35 +++++++++++++++++++ .../openloadflow/util/LoadFlowAssert.java | 9 +++++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/powsybl/openloadflow/util/Reports.java b/src/main/java/com/powsybl/openloadflow/util/Reports.java index 8c021e068c..f4378ab515 100644 --- a/src/main/java/com/powsybl/openloadflow/util/Reports.java +++ b/src/main/java/com/powsybl/openloadflow/util/Reports.java @@ -607,10 +607,6 @@ public static void reportMaxVoltageChangeStateVectorScaling(ReportNode reportNod public static void reportNewtonRaphsonBusesOutOfRealisticVoltageRange(ReportNode reportNode, Map busesOutOfRealisticVoltageRange, double minRealisticVoltage, double maxRealisticVoltage) { ReportNode voltageOutOfRangeReport = reportNode.newReportNode() - .withMessageTemplate("busesOutOfVoltageRealisticRange", "Buses have a voltage magnitude out of the configured realistic range") - .add(); - - voltageOutOfRangeReport.newReportNode() .withMessageTemplate("busesOutOfVoltageRealisticRangeSummary", "${busCountOutOfRealisticVoltageRange} buses have a voltage magnitude out of the configured realistic range [${minRealisticVoltage}, ${maxRealisticVoltage}]") .withUntypedValue("busCountOutOfRealisticVoltageRange", busesOutOfRealisticVoltageRange.size()) .withUntypedValue("minRealisticVoltage", minRealisticVoltage) diff --git a/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowReportTest.java b/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowReportTest.java index c887fb15b8..9d14a3acf1 100644 --- a/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowReportTest.java +++ b/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowReportTest.java @@ -31,6 +31,7 @@ import java.util.Set; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Bertrand Rix {@literal } @@ -256,4 +257,38 @@ void areaInterchangeControl() throws IOException { assertEquals(LoadFlowResult.ComponentResult.Status.CONVERGED, result.getComponentResults().get(0).getStatus()); LoadFlowAssert.assertReportEquals("/areaInterchangeControlOuterloop.txt", reportNode); } + + @Test + void busesOutOfRealisticVoltageRangeTest() throws IOException { + Network network = EurostagTutorialExample1Factory.create(); + ReportNode reportNode = ReportNode.newRootReportNode() + .withMessageTemplate("testReport", "Test Report") + .build(); + var lfParameters = new LoadFlowParameters(); + OpenLoadFlowParameters.create(lfParameters) + .setMinRealisticVoltage(0.99) + .setMaxRealisticVoltage(1.01); + + LoadFlowProvider provider = new OpenLoadFlowProvider(new DenseMatrixFactory(), new NaiveGraphConnectivityFactory<>(LfBus::getNum)); + LoadFlow.Runner runner = new LoadFlow.Runner(provider); + LoadFlowResult result = runner.run(network, network.getVariantManager().getWorkingVariantId(), LocalComputationManager.getDefault(), lfParameters, reportNode); + + assertTrue(result.isFailed()); + LoadFlowAssert.assertTxtReportEquals(""" + + Test Report + + Load flow on network 'sim1' + + Network CC0 SC0 + + Network info + Network has 4 buses and 4 branches + Network balance: active generation=607.0 MW, active load=600.0 MW, reactive generation=0.0 MVar, reactive load=200.0 MVar + Angle reference bus: VLHV1_0 + Slack bus: VLHV1_0 + + 4 buses have a voltage magnitude out of the configured realistic range [0.99, 1.01] + Bus VLGEN_0 has an unrealistic voltage magnitude: 1.0208333333333333 pu + Bus VLHV1_0 has an unrealistic voltage magnitude: 1.0582636574158686 pu + Bus VLHV2_0 has an unrealistic voltage magnitude: 1.0261840057810543 pu + Bus VLLOAD_0 has an unrealistic voltage magnitude: 0.9838500227734096 pu + AC load flow completed with error (solverStatus=UNREALISTIC_STATE, outerloopStatus=STABLE) + """, reportNode); + } } diff --git a/src/test/java/com/powsybl/openloadflow/util/LoadFlowAssert.java b/src/test/java/com/powsybl/openloadflow/util/LoadFlowAssert.java index 911474f1e3..70ee3d913b 100644 --- a/src/test/java/com/powsybl/openloadflow/util/LoadFlowAssert.java +++ b/src/test/java/com/powsybl/openloadflow/util/LoadFlowAssert.java @@ -108,4 +108,13 @@ public static void assertReportEquals(InputStream ref, ReportNode reportNode) th String logExport = normalizeLineSeparator(sw.toString()); assertEquals(refLogExport, logExport); } + + public static void assertTxtReportEquals(String reportTxt, ReportNode reportNode) throws IOException { + StringWriter sw = new StringWriter(); + reportNode.print(sw); + + String refLogExport = normalizeLineSeparator(reportTxt); + String logExport = normalizeLineSeparator(sw.toString()); + assertEquals(refLogExport, logExport); + } } From 96551330cc128aafca999e471fc6fe65ceacb874 Mon Sep 17 00:00:00 2001 From: Damien Jeandemange Date: Wed, 13 Nov 2024 14:02:07 +0100 Subject: [PATCH 4/5] do not change the existing report key Signed-off-by: Damien Jeandemange --- src/main/java/com/powsybl/openloadflow/util/Reports.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/powsybl/openloadflow/util/Reports.java b/src/main/java/com/powsybl/openloadflow/util/Reports.java index f4378ab515..ebad647c9e 100644 --- a/src/main/java/com/powsybl/openloadflow/util/Reports.java +++ b/src/main/java/com/powsybl/openloadflow/util/Reports.java @@ -607,7 +607,7 @@ public static void reportMaxVoltageChangeStateVectorScaling(ReportNode reportNod public static void reportNewtonRaphsonBusesOutOfRealisticVoltageRange(ReportNode reportNode, Map busesOutOfRealisticVoltageRange, double minRealisticVoltage, double maxRealisticVoltage) { ReportNode voltageOutOfRangeReport = reportNode.newReportNode() - .withMessageTemplate("busesOutOfVoltageRealisticRangeSummary", "${busCountOutOfRealisticVoltageRange} buses have a voltage magnitude out of the configured realistic range [${minRealisticVoltage}, ${maxRealisticVoltage}]") + .withMessageTemplate("newtonRaphsonBusesOutOfRealisticVoltageRange", "${busCountOutOfRealisticVoltageRange} buses have a voltage magnitude out of the configured realistic range [${minRealisticVoltage}, ${maxRealisticVoltage}]") .withUntypedValue("busCountOutOfRealisticVoltageRange", busesOutOfRealisticVoltageRange.size()) .withUntypedValue("minRealisticVoltage", minRealisticVoltage) .withUntypedValue("maxRealisticVoltage", maxRealisticVoltage) From f811d0fa1f84692bffd0ee500e9a96d3d26da406 Mon Sep 17 00:00:00 2001 From: Damien Jeandemange Date: Wed, 13 Nov 2024 14:07:17 +0100 Subject: [PATCH 5/5] consistency / fix Signed-off-by: Damien Jeandemange --- .../java/com/powsybl/openloadflow/util/Reports.java | 6 +++--- .../powsybl/openloadflow/ac/AcLoadFlowReportTest.java | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/powsybl/openloadflow/util/Reports.java b/src/main/java/com/powsybl/openloadflow/util/Reports.java index ebad647c9e..ee88766866 100644 --- a/src/main/java/com/powsybl/openloadflow/util/Reports.java +++ b/src/main/java/com/powsybl/openloadflow/util/Reports.java @@ -607,7 +607,7 @@ public static void reportMaxVoltageChangeStateVectorScaling(ReportNode reportNod public static void reportNewtonRaphsonBusesOutOfRealisticVoltageRange(ReportNode reportNode, Map busesOutOfRealisticVoltageRange, double minRealisticVoltage, double maxRealisticVoltage) { ReportNode voltageOutOfRangeReport = reportNode.newReportNode() - .withMessageTemplate("newtonRaphsonBusesOutOfRealisticVoltageRange", "${busCountOutOfRealisticVoltageRange} buses have a voltage magnitude out of the configured realistic range [${minRealisticVoltage}, ${maxRealisticVoltage}]") + .withMessageTemplate("newtonRaphsonBusesOutOfRealisticVoltageRange", "${busCountOutOfRealisticVoltageRange} buses have a voltage magnitude out of the configured realistic range [${minRealisticVoltage}, ${maxRealisticVoltage}] p.u.") .withUntypedValue("busCountOutOfRealisticVoltageRange", busesOutOfRealisticVoltageRange.size()) .withUntypedValue("minRealisticVoltage", minRealisticVoltage) .withUntypedValue("maxRealisticVoltage", maxRealisticVoltage) @@ -615,8 +615,8 @@ public static void reportNewtonRaphsonBusesOutOfRealisticVoltageRange(ReportNode .add(); busesOutOfRealisticVoltageRange.forEach((id, voltage) -> voltageOutOfRangeReport.newReportNode() - .withMessageTemplate("busesOutOfVoltageRealisticRangeDetail", "Bus ${id} has an unrealistic voltage magnitude: ${voltage} pu") - .withUntypedValue("id", id) + .withMessageTemplate("newtonRaphsonBusesOutOfRealisticVoltageRangeDetails", "Bus ${busId} has an unrealistic voltage magnitude: ${voltage} p.u.") + .withUntypedValue(BUS_ID, id) .withUntypedValue("voltage", voltage) .withSeverity(TypedValue.TRACE_SEVERITY) .add()); diff --git a/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowReportTest.java b/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowReportTest.java index 9d14a3acf1..3e67ebfe3b 100644 --- a/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowReportTest.java +++ b/src/test/java/com/powsybl/openloadflow/ac/AcLoadFlowReportTest.java @@ -283,11 +283,11 @@ void busesOutOfRealisticVoltageRangeTest() throws IOException { Network balance: active generation=607.0 MW, active load=600.0 MW, reactive generation=0.0 MVar, reactive load=200.0 MVar Angle reference bus: VLHV1_0 Slack bus: VLHV1_0 - + 4 buses have a voltage magnitude out of the configured realistic range [0.99, 1.01] - Bus VLGEN_0 has an unrealistic voltage magnitude: 1.0208333333333333 pu - Bus VLHV1_0 has an unrealistic voltage magnitude: 1.0582636574158686 pu - Bus VLHV2_0 has an unrealistic voltage magnitude: 1.0261840057810543 pu - Bus VLLOAD_0 has an unrealistic voltage magnitude: 0.9838500227734096 pu + + 4 buses have a voltage magnitude out of the configured realistic range [0.99, 1.01] p.u. + Bus VLGEN_0 has an unrealistic voltage magnitude: 1.0208333333333333 p.u. + Bus VLHV1_0 has an unrealistic voltage magnitude: 1.0582636574158686 p.u. + Bus VLHV2_0 has an unrealistic voltage magnitude: 1.0261840057810543 p.u. + Bus VLLOAD_0 has an unrealistic voltage magnitude: 0.9838500227734096 p.u. AC load flow completed with error (solverStatus=UNREALISTIC_STATE, outerloopStatus=STABLE) """, reportNode); }