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

Modified exception message when initial LF fails in AC Sensi #1170

Open
wants to merge 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.powsybl.openloadflow.ac.solver.AcSolverStatus;
import com.powsybl.openloadflow.ac.solver.AcSolverUtil;
import com.powsybl.openloadflow.graph.GraphConnectivityFactory;
import com.powsybl.openloadflow.lf.outerloop.OuterLoopStatus;
import com.powsybl.openloadflow.network.*;
import com.powsybl.openloadflow.network.impl.LfNetworkList;
import com.powsybl.openloadflow.network.impl.Networks;
Expand Down Expand Up @@ -152,9 +153,13 @@ private static boolean runLoadFlow(AcLoadFlowContext context, boolean throwsExce
return true;
} else {
if (throwsExceptionIfNoConvergence) {
throw new PowsyblException("Load flow ended with status " + result.getSolverStatus());
if (result.getOuterLoopResult().status() != OuterLoopStatus.STABLE) {
throw new PowsyblException("Load flow ended with outer loop status " + result.getOuterLoopResult().statusText());
} else {
throw new PowsyblException("Load flow ended with solver status " + result.getSolverStatus());
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message can still be improved by specifying that this is the load flow of the N case
(failures for contingencies don't interrupt the analysis)

For this you can also rename the parameter from throwsExceptionIfNoConvergence to something like runBaseSituation (te clarify its meaning since now the message would depend on this param) , and make the message more precise.

} else {
LOGGER.warn("Load flow ended with status {}", result.getSolverStatus());
LOGGER.warn("Load flow failed with result={}", result);
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1515,4 +1515,31 @@ void testUnsupportedVariablesSensiV() {
e = assertThrows(CompletionException.class, () -> sensiRunner.run(network, factors2, contingencies, variableSets, sensiParameters));
assertEquals("Variable type INJECTION_ACTIVE_POWER not supported with function type BUS_VOLTAGE", e.getCause().getMessage());
}

@Test
void testFailingLf() {
Network network = TwoBusNetworkFactory.create();
network.getLoad("l1").setP0(3.0);
List<SensitivityFactor> factors = List.of(new SensitivityFactor(SensitivityFunctionType.BRANCH_ACTIVE_POWER_1,
"l12",
SensitivityVariableType.INJECTION_ACTIVE_POWER,
"g1",
false,
ContingencyContext.all()));
List<Contingency> contingencies = Collections.emptyList();
List<SensitivityVariableSet> variableSets = Collections.emptyList();
SensitivityAnalysisParameters sensiParameters = createParameters(false, "b1_vl_0");
sensiParameters.getLoadFlowParameters().setDistributedSlack(true);

OpenLoadFlowParameters olfParameters = sensiParameters.getLoadFlowParameters().getExtension(OpenLoadFlowParameters.class);
olfParameters.setMaxNewtonRaphsonIterations(1);
CompletionException e = assertThrows(CompletionException.class, () -> sensiRunner.run(network, factors, contingencies, variableSets, sensiParameters));
assertEquals("Load flow ended with solver status MAX_ITERATION_REACHED", e.getCause().getMessage());

olfParameters.setMaxNewtonRaphsonIterations(10)
.setSlackBusPMaxMismatch(0.00001)
.setMaxOuterLoopIterations(1);
e = assertThrows(CompletionException.class, () -> sensiRunner.run(network, factors, contingencies, variableSets, sensiParameters));
assertEquals("Load flow ended with outer loop status UNSTABLE", e.getCause().getMessage());
}
}
Loading