Skip to content

Active Power Distribution: better reports severities when residual mismatch remains #1215

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

Merged
merged 7 commits into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,12 @@ public OuterLoopResult check(AcOuterLoopContext context, ReportNode reportNode)
);
double remainingMismatch = resultWbh.remainingMismatch();
double distributedActivePower = slackBusActivePowerMismatch - remainingMismatch;
if (Math.abs(remainingMismatch) > ActivePowerDistribution.P_RESIDUE_EPS) {
if (Math.abs(remainingMismatch) > slackBusPMaxMismatch / PerUnit.SB) {
Reports.reportMismatchDistributionFailure(iterationReportNode, remainingMismatch * PerUnit.SB);
} else {
if (Math.abs(remainingMismatch) > ActivePowerDistribution.P_RESIDUE_EPS) {
Reports.reportResidualDistributionMismatch(reportNode, remainingMismatch * PerUnit.SB);
}
ActivePowerDistribution.reportAndLogSuccess(iterationReportNode, slackBusActivePowerMismatch, resultWbh);
}
DistributedSlackContextData contextData = (DistributedSlackContextData) context.getData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,12 @@ public DcLoadFlowResult run() {
);
double remainingMismatch = resultWbh.remainingMismatch();
distributedActivePower = initialSlackBusActivePowerMismatch - remainingMismatch;
if (Math.abs(remainingMismatch) > ActivePowerDistribution.P_RESIDUE_EPS) {
if (Math.abs(remainingMismatch) > context.getParameters().getSlackBusPMaxMismatch() / PerUnit.SB) {
Reports.reportMismatchDistributionFailure(reportNode, remainingMismatch * PerUnit.SB);
} else {
if (Math.abs(remainingMismatch) > ActivePowerDistribution.P_RESIDUE_EPS) {
Reports.reportResidualDistributionMismatch(reportNode, remainingMismatch * PerUnit.SB);
}
ActivePowerDistribution.reportAndLogSuccess(reportNode, initialSlackBusActivePowerMismatch, resultWbh);
}
if (resultWbh.failed()) {
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/powsybl/openloadflow/util/Reports.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,15 @@ public static void reportMismatchDistributionFailure(ReportNode reportNode, doub
reportNode.newReportNode()
.withMessageTemplate("mismatchDistributionFailure", "Failed to distribute slack bus active power mismatch, ${mismatch} MW remains")
.withTypedValue(MISMATCH, remainingMismatch, OpenLoadFlowReportConstants.MISMATCH_TYPED_VALUE)
.withSeverity(TypedValue.ERROR_SEVERITY)
.withSeverity(TypedValue.WARN_SEVERITY)
.add();
}

public static void reportResidualDistributionMismatch(ReportNode reportNode, double remainingMismatch) {
reportNode.newReportNode()
.withMessageTemplate("residualDistributionMismatch", "Remaining residual slack bus active power mismatch after active power distribution, ${mismatch} MW remains")
.withTypedValue(MISMATCH, remainingMismatch, OpenLoadFlowReportConstants.MISMATCH_TYPED_VALUE)
.withSeverity(TypedValue.DEBUG_SEVERITY)
.add();
}

Expand Down
11 changes: 11 additions & 0 deletions src/test/java/com/powsybl/openloadflow/dc/DcLoadFlowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,17 @@ void testDcApproxIgnoreG() {
assertEquals(-307.436, line2.getTerminal2().getP(), 0.01);
}

@Test
void testDcResidualMismatchRemaining() {
Network network = IeeeCdfNetworkFactory.create9();
network.getGenerator("B1-G").setTargetP(67.99); // Setting target P to have an initially almost balanced network
ReportNode reportNode = ReportNode.newRootReportNode().withMessageTemplate("test", "test").build();
System.out.println(network.getGenerator("B1-G").getId() + " has P = " + network.getGenerator("B1-G").getTargetP());
loadFlowRunner.run(network, network.getVariantManager().getWorkingVariantId(), LocalComputationManager.getDefault(), parameters, reportNode);
// DC loadflow succeeds but the initial residual mismatch still remains
assertReportContains("Remaining residual slack bus active power mismatch after active power distribution, [-+]?0\\.\\d* MW remains", reportNode);
}

@Test
void testDcSlackDistributionFailureBehavior() {
Network network = IeeeCdfNetworkFactory.create57();
Expand Down