Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report buses out of realistic voltage range in sub reports #1105

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/main/java/com/powsybl/openloadflow/util/Reports.java
Original file line number Diff line number Diff line change
Expand Up @@ -606,14 +606,20 @@ public static void reportMaxVoltageChangeStateVectorScaling(ReportNode reportNod
}

public static void reportNewtonRaphsonBusesOutOfRealisticVoltageRange(ReportNode reportNode, Map<String, Double> 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("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)
.withUntypedValue("busesOutOfRealisticVoltageRange", busesOutOfRealisticVoltageRange.toString())
.withSeverity(TypedValue.ERROR_SEVERITY)
.add();

busesOutOfRealisticVoltageRange.forEach((id, voltage) -> voltageOutOfRangeReport.newReportNode()
.withMessageTemplate("newtonRaphsonBusesOutOfRealisticVoltageRangeDetails", "Bus ${busId} has an unrealistic voltage magnitude: ${voltage} p.u.")
.withUntypedValue(BUS_ID, id)
.withUntypedValue("voltage", voltage)
.withSeverity(TypedValue.TRACE_SEVERITY)
.add());
}

public static void reportAngleReferenceBusAndSlackBuses(ReportNode reportNode, String referenceBus, List<String> slackBuses) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <bertrand.rix at artelys.com>}
Expand Down Expand Up @@ -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] 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}