Skip to content

Commit

Permalink
Add new post-contingency status for security analysis and update to 5…
Browse files Browse the repository at this point in the history
….0.0-RC1 (#638)

Signed-off-by: Bertrand Rix <[email protected]>
  • Loading branch information
obrix authored Nov 7, 2022
1 parent dcdee44 commit b3f1395
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 47 deletions.
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 @@ -6,15 +6,19 @@
*/
package com.powsybl.openloadflow.sa;

import com.powsybl.commons.PowsyblException;
import com.powsybl.commons.reporter.Reporter;
import com.powsybl.computation.CompletableFutureTask;
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 +72,37 @@ 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:
throw new PowsyblException("Unsupported Newton Raphson status : " + status);
}
}

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;
case NO_CALCULATION:
case UNREALISTIC_STATE:
return LoadFlowResult.ComponentResult.Status.FAILED;
default:
throw new PowsyblException("Unsupported Newton Raphson status : " + status);
}
}
}
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 @@ -42,6 +43,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 @@ -59,7 +61,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 @@ -257,12 +259,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 @@ -283,6 +285,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 @@ -298,8 +301,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 @@ -336,6 +339,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 @@ -352,9 +356,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

0 comments on commit b3f1395

Please sign in to comment.