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

Adapt openloadflow to new status for security analysis. #638

Merged
merged 9 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from 8 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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<junit-jupiter.version>5.8.2</junit-jupiter.version>
<slf4jtoys.version>1.6.3</slf4jtoys.version>

<powsybl-core.version>4.10.1</powsybl-core.version>
<powsybl-core.version>5.0.0-RC1</powsybl-core.version>
</properties>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
import com.powsybl.computation.ComputationManager;
import com.powsybl.contingency.ContingenciesProvider;
import com.powsybl.iidm.network.Network;
import com.powsybl.loadflow.LoadFlowResult;
import com.powsybl.math.matrix.MatrixFactory;
import com.powsybl.openloadflow.ac.nr.NewtonRaphsonStatus;
import com.powsybl.openloadflow.graph.GraphConnectivityFactory;
import com.powsybl.openloadflow.network.LfBranch;
import com.powsybl.openloadflow.network.LfBus;
import com.powsybl.security.PostContingencyComputationStatus;
import com.powsybl.security.SecurityAnalysisParameters;
import com.powsybl.security.SecurityAnalysisReport;
import com.powsybl.security.action.Action;
Expand Down Expand Up @@ -68,4 +71,34 @@ public CompletableFuture<SecurityAnalysisReport> run(String workingVariantId, Se

abstract SecurityAnalysisReport runSync(String workingVariantId, SecurityAnalysisParameters securityAnalysisParameters, ContingenciesProvider contingenciesProvider,
ComputationManager computationManager, List<OperatorStrategy> operatorStrategies, List<Action> actions);

public static PostContingencyComputationStatus postContingencyStatusFromNRStatus(NewtonRaphsonStatus status) {
switch (status) {
case CONVERGED:
return PostContingencyComputationStatus.CONVERGED;
case MAX_ITERATION_REACHED:
return PostContingencyComputationStatus.MAX_ITERATION_REACHED;
case SOLVER_FAILED:
return PostContingencyComputationStatus.SOLVER_FAILED;
case NO_CALCULATION:
return PostContingencyComputationStatus.NO_IMPACT;
case UNREALISTIC_STATE:
return PostContingencyComputationStatus.FAILED;
default:
return PostContingencyComputationStatus.CONVERGED;
obrix marked this conversation as resolved.
Show resolved Hide resolved
}
}

public static LoadFlowResult.ComponentResult.Status loadFlowResultStatusFromNRStatus(NewtonRaphsonStatus status) {
switch (status) {
case CONVERGED:
return LoadFlowResult.ComponentResult.Status.CONVERGED;
case MAX_ITERATION_REACHED:
return LoadFlowResult.ComponentResult.Status.MAX_ITERATION_REACHED;
case SOLVER_FAILED:
return LoadFlowResult.ComponentResult.Status.SOLVER_FAILED;
default:
return LoadFlowResult.ComponentResult.Status.FAILED;
obrix marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
27 changes: 15 additions & 12 deletions src/main/java/com/powsybl/openloadflow/sa/AcSecurityAnalysis.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.Switch;
import com.powsybl.loadflow.LoadFlowParameters;
import com.powsybl.loadflow.LoadFlowResult;
import com.powsybl.math.matrix.MatrixFactory;
import com.powsybl.openloadflow.OpenLoadFlowParameters;
import com.powsybl.openloadflow.ac.nr.NewtonRaphsonStatus;
Expand All @@ -41,6 +42,7 @@
import com.powsybl.security.results.NetworkResult;
import com.powsybl.security.results.OperatorStrategyResult;
import com.powsybl.security.results.PostContingencyResult;
import com.powsybl.security.results.PreContingencyResult;
import com.powsybl.security.strategy.OperatorStrategy;

import java.util.*;
Expand All @@ -58,7 +60,7 @@ protected AcSecurityAnalysis(Network network, MatrixFactory matrixFactory, Graph
}

private static SecurityAnalysisResult createNoResult() {
return new SecurityAnalysisResult(new LimitViolationsResult(false, Collections.emptyList()), Collections.emptyList());
return new SecurityAnalysisResult(new LimitViolationsResult(Collections.emptyList()), LoadFlowResult.ComponentResult.Status.FAILED, Collections.emptyList());
}

@Override
Expand Down Expand Up @@ -261,12 +263,12 @@ private SecurityAnalysisResult runSimulations(LfNetwork network, List<Propagated
}
}

return new SecurityAnalysisResult(new LimitViolationsResult(preContingencyComputationOk, preContingencyLimitViolationManager.getLimitViolations()),
postContingencyResults,
preContingencyNetworkResult.getBranchResults(),
preContingencyNetworkResult.getBusResults(),
preContingencyNetworkResult.getThreeWindingsTransformerResults(),
operatorStrategyResults);
LoadFlowResult.ComponentResult.Status status = loadFlowResultStatusFromNRStatus(preContingencyLoadFlowResult.getNewtonRaphsonStatus());
return new SecurityAnalysisResult(
new PreContingencyResult(status, new LimitViolationsResult(preContingencyLimitViolationManager.getLimitViolations()),
preContingencyNetworkResult.getBranchResults(), preContingencyNetworkResult.getBusResults(),
preContingencyNetworkResult.getThreeWindingsTransformerResults()),
postContingencyResults, operatorStrategyResults);
}
}

Expand All @@ -287,6 +289,7 @@ private PostContingencyResult runPostContingencySimulation(LfNetwork network, Ac
.run();

boolean postContingencyComputationOk = postContingencyLoadFlowResult.getNewtonRaphsonStatus() == NewtonRaphsonStatus.CONVERGED;
PostContingencyComputationStatus status = postContingencyStatusFromNRStatus(postContingencyLoadFlowResult.getNewtonRaphsonStatus());
var postContingencyLimitViolationManager = new LimitViolationManager(preContingencyLimitViolationManager, violationsParameters);
var postContingencyNetworkResult = new PostContingencyNetworkResult(network, monitorIndex, createResultExtension, preContingencyNetworkResult, contingency);

Expand All @@ -302,8 +305,8 @@ private PostContingencyResult runPostContingencySimulation(LfNetwork network, Ac
LOGGER.info("Post contingency '{}' simulation done on network {} in {} ms", lfContingency.getId(),
network, stopwatch.elapsed(TimeUnit.MILLISECONDS));

return new PostContingencyResult(contingency,
new LimitViolationsResult(postContingencyComputationOk, postContingencyLimitViolationManager.getLimitViolations()),
return new PostContingencyResult(contingency, status,
new LimitViolationsResult(postContingencyLimitViolationManager.getLimitViolations()),
postContingencyNetworkResult.getBranchResults(),
postContingencyNetworkResult.getBusResults(),
postContingencyNetworkResult.getThreeWindingsTransformerResults());
Expand Down Expand Up @@ -340,6 +343,7 @@ private Optional<OperatorStrategyResult> runActionSimulation(LfNetwork network,
.run();

boolean postActionsComputationOk = postActionsLoadFlowResult.getNewtonRaphsonStatus() == NewtonRaphsonStatus.CONVERGED;
PostContingencyComputationStatus status = postContingencyStatusFromNRStatus(postActionsLoadFlowResult.getNewtonRaphsonStatus());
var postActionsViolationManager = new LimitViolationManager(preContingencyLimitViolationManager, violationsParameters);
var postActionsNetworkResult = new PreContingencyNetworkResult(network, monitorIndex, createResultExtension);

Expand All @@ -356,9 +360,8 @@ private Optional<OperatorStrategyResult> runActionSimulation(LfNetwork network,
LOGGER.info("Operator strategy {} after contingency '{}' simulation done on network {} in {} ms", operatorStrategy.getId(),
operatorStrategy.getContingencyId(), network, stopwatch.elapsed(TimeUnit.MILLISECONDS));

operatorStrategyResult = new OperatorStrategyResult(operatorStrategy,
new LimitViolationsResult(postActionsComputationOk,
postActionsViolationManager.getLimitViolations()),
operatorStrategyResult = new OperatorStrategyResult(operatorStrategy, status,
new LimitViolationsResult(postActionsViolationManager.getLimitViolations()),
new NetworkResult(postActionsNetworkResult.getBranchResults(),
postActionsNetworkResult.getBusResults(),
postActionsNetworkResult.getThreeWindingsTransformerResults()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.powsybl.contingency.*;
import com.powsybl.iidm.network.Branch;
import com.powsybl.iidm.network.Network;
import com.powsybl.loadflow.LoadFlowResult;
import com.powsybl.math.matrix.MatrixFactory;
import com.powsybl.openloadflow.OpenLoadFlowParameters;
import com.powsybl.openloadflow.graph.GraphConnectivityFactory;
Expand Down Expand Up @@ -86,7 +87,7 @@ SecurityAnalysisReport runSync(String workingVariantId, SecurityAnalysisParamete
violation -> preContingencyLimitViolationsMap.put(Pair.of(violation.getSubjectId(), violation.getSide()), violation));
}

LimitViolationsResult preContingencyResult = new LimitViolationsResult(true,
LimitViolationsResult preContingencyResult = new LimitViolationsResult(
new ArrayList<>(preContingencyLimitViolationsMap.values()));

List<PostContingencyResult> postContingencyResults = new ArrayList<>();
Expand Down Expand Up @@ -125,11 +126,11 @@ SecurityAnalysisReport runSync(String workingVariantId, SecurityAnalysisParamete
violations.remove(subjectSideId);
}
});
postContingencyResults.add(new PostContingencyResult(contingency, true, new ArrayList<>(violations.values()),
postContingencyResults.add(new PostContingencyResult(contingency, PostContingencyComputationStatus.CONVERGED, new ArrayList<>(violations.values()),
new ArrayList<>(postContingencyBranchResults.values()), Collections.emptyList(), Collections.emptyList()));
}

return new SecurityAnalysisReport(new SecurityAnalysisResult(preContingencyResult, postContingencyResults,
return new SecurityAnalysisReport(new SecurityAnalysisResult(preContingencyResult, LoadFlowResult.ComponentResult.Status.CONVERGED, postContingencyResults,
new ArrayList<>(preContingencyBranchResults.values()), Collections.emptyList(), Collections.emptyList(), Collections.emptyList()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import com.powsybl.computation.ComputationManager;
import com.powsybl.computation.local.LocalComputationManager;
import com.powsybl.contingency.Contingency;
import com.powsybl.contingency.ContingencyList;
import com.powsybl.contingency.DefaultContingencyList;
import com.powsybl.contingency.contingency.list.ContingencyList;
import com.powsybl.contingency.contingency.list.DefaultContingencyList;
import com.powsybl.contingency.json.ContingencyJsonModule;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.Switch;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.powsybl.commons.datasource.ResourceDataSource;
import com.powsybl.commons.datasource.ResourceSet;
import com.powsybl.ieeecdf.converter.IeeeCdfNetworkFactory;
import com.powsybl.iidm.import_.Importers;
import com.powsybl.iidm.network.Importers;
import com.powsybl.iidm.network.Line;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
Expand Down
Loading