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

LoadFlowResult management after a DC loadflow #190

Merged
merged 3 commits into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 8 additions & 14 deletions src/main/java/com/powsybl/openloadflow/OpenLoadFlowProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,6 @@ private static ImmutableMap<String, String> createMetrics(AcLoadFlowResult resul
prefix + "status", result.getNewtonRaphsonStatus().name());
}

private static ImmutableMap<String, String> createMetrics(DcLoadFlowResult result) {
Copy link
Member Author

Choose a reason for hiding this comment

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

If you remove that, it means that we have no metrics at the end of the computation using itools or pypowsybl. The number of iterations is not needed as it means nothing but the status is usefull.

Copy link
Member

Choose a reason for hiding this comment

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

Now there is a way to fill status and iteration on component result these metrics are useless ( and this is true also for ac)

Copy link
Member

@geofjamg geofjamg Dec 22, 2020

Choose a reason for hiding this comment

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

Metrics might still be useful for output infos not yet normalized in api output

String prefix = "network_" + result.getNetwork().getNum() + "_";
return ImmutableMap.of(prefix + "iterations", Integer.toString(0),
prefix + "status", result.getStatus().name());
}

private static VoltageInitializer getVoltageInitializer(LoadFlowParameters parameters) {
switch (parameters.getVoltageInitMode()) {
case UNIFORM_VALUES:
Expand Down Expand Up @@ -241,24 +235,24 @@ private CompletableFuture<LoadFlowResult> runDc(Network network, String workingS

Networks.resetState(network);

if (result.isOk() && parameters.isWriteSlackBus()) {
if (result.getStatus() == LoadFlowResult.ComponentResult.Status.CONVERGED && parameters.isWriteSlackBus()) {
SlackTerminal.reset(network);
}

result.getNetwork().updateState(false, parameters.isWriteSlackBus(), parameters.isPhaseShifterRegulationOn(),
parameters.isTransformerVoltageControlOn());

Map<String, String> metrics = new HashMap<>();
metrics.putAll(createMetrics(result));

List<LoadFlowResult.ComponentResult> componentResults = new ArrayList<>();
componentResults.add(new LoadFlowResultImpl.ComponentResultImpl(result.getNetwork().getNum(),
LoadFlowResult.ComponentResult componentResult = new LoadFlowResultImpl.ComponentResultImpl(
result.getNetwork().getNum(),
result.getStatus(),
0,
result.getNetwork().getSlackBus().getId(),
result.getSlackBusActivePowerMismatch() * PerUnit.SB));
result.getSlackBusActivePowerMismatch() * PerUnit.SB);

return new LoadFlowResultImpl(result.isOk(), metrics, null, componentResults);
return new LoadFlowResultImpl(result.getStatus() == LoadFlowResult.ComponentResult.Status.CONVERGED,
Collections.emptyMap(),
null,
Collections.singletonList(componentResult));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package com.powsybl.openloadflow.ac.nr;

import com.powsybl.commons.PowsyblException;
import com.powsybl.loadflow.LoadFlowResult;
import com.powsybl.math.matrix.MatrixFactory;
import com.powsybl.openloadflow.dc.DcLoadFlowEngine;
import com.powsybl.openloadflow.equations.VoltageInitializer;
Expand All @@ -20,7 +21,7 @@ public class DcValueVoltageInitializer implements VoltageInitializer {

@Override
public void prepare(LfNetwork network, MatrixFactory matrixFactory) {
if (!new DcLoadFlowEngine(network, matrixFactory).run().isOk()) {
if (new DcLoadFlowEngine(network, matrixFactory).run().getStatus() != LoadFlowResult.ComponentResult.Status.CONVERGED) {
throw new PowsyblException("DC loadflow failed, impossible to initialize voltage angle from DC values");
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/com/powsybl/openloadflow/dc/DcLoadFlowEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ public DcLoadFlowResult run() {
try {
double[] dx = Arrays.copyOf(targets, targets.length);

boolean ok;
LoadFlowResult.ComponentResult.Status status;
try {
LUDecomposition lu = j.decomposeLU();
lu.solveTransposed(dx);
ok = true;
status = LoadFlowResult.ComponentResult.Status.CONVERGED;
} catch (Exception e) {
ok = false;
status = LoadFlowResult.ComponentResult.Status.FAILED;
LOGGER.error("Failed to solve linear system for DC load flow", e);
}

Expand All @@ -107,10 +107,9 @@ public DcLoadFlowResult run() {
stopwatch.stop();
LOGGER.debug(Markers.PERFORMANCE_MARKER, "Dc loadflow ran in {} ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));

LOGGER.info("Dc loadflow complete (ok={})", ok);
LOGGER.info("Dc loadflow complete (status={})", status);

return new DcLoadFlowResult(network, ok, network.getActivePowerMismatch(),
ok ? LoadFlowResult.ComponentResult.Status.CONVERGED : LoadFlowResult.ComponentResult.Status.FAILED);
return new DcLoadFlowResult(network, network.getActivePowerMismatch(), status);
} finally {
j.cleanLU();
}
Expand Down
15 changes: 5 additions & 10 deletions src/main/java/com/powsybl/openloadflow/dc/DcLoadFlowResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@ public class DcLoadFlowResult {

private final LfNetwork network;

private final boolean ok;

private final double slackBusActivePowerMismatch;

private final LoadFlowResult.ComponentResult.Status status;

public DcLoadFlowResult(LfNetwork network, boolean ok, double slackBusActivePowerMismatch, LoadFlowResult.ComponentResult.Status status) {
public DcLoadFlowResult(LfNetwork network, double slackBusActivePowerMismatch, LoadFlowResult.ComponentResult.Status status) {
this.network = Objects.requireNonNull(network);
this.ok = ok;
this.slackBusActivePowerMismatch = slackBusActivePowerMismatch;
this.status = status;
}
Expand All @@ -35,13 +32,11 @@ public LfNetwork getNetwork() {
return network;
}

public boolean isOk() {
return ok;
}

public double getSlackBusActivePowerMismatch() {
return slackBusActivePowerMismatch; }
return slackBusActivePowerMismatch;
}

public LoadFlowResult.ComponentResult.Status getStatus() {
return status; }
return status;
}
}