Skip to content

Commit

Permalink
Adapt to core #3017 (new SA runner parameters)
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Perrin <olivier.perrin@rte-france.com>
  • Loading branch information
olperr1 committed May 29, 2024
1 parent d4fb6cf commit 4edc8dc
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@
package com.powsybl.openloadflow.sa;

import com.google.auto.service.AutoService;
import com.powsybl.action.Action;
import com.powsybl.commons.config.PlatformConfig;
import com.powsybl.commons.extensions.Extension;
import com.powsybl.commons.extensions.ExtensionJsonSerializer;
import com.powsybl.commons.report.ReportNode;
import com.powsybl.computation.ComputationManager;
import com.powsybl.contingency.ContingenciesProvider;
import com.powsybl.iidm.network.Network;
import com.powsybl.loadflow.LoadFlowParameters;
Expand All @@ -27,11 +24,10 @@
import com.powsybl.openloadflow.network.LfBus;
import com.powsybl.openloadflow.util.PowsyblOpenLoadFlowVersion;
import com.powsybl.openloadflow.util.ProviderConstants;
import com.powsybl.security.*;
import com.powsybl.security.interceptors.SecurityAnalysisInterceptor;
import com.powsybl.security.limitreduction.LimitReduction;
import com.powsybl.security.monitor.StateMonitor;
import com.powsybl.security.strategy.OperatorStrategy;
import com.powsybl.security.SecurityAnalysisParameters;
import com.powsybl.security.SecurityAnalysisProvider;
import com.powsybl.security.SecurityAnalysisReport;
import com.powsybl.security.SecurityAnalysisRunParameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -62,29 +58,37 @@ public OpenSecurityAnalysisProvider() {
this(new SparseMatrixFactory(), new EvenShiloachGraphDecrementalConnectivityFactory<>());
}

@Override
public CompletableFuture<SecurityAnalysisReport> run(Network network,
String workingVariantId,
ContingenciesProvider contingenciesProvider,
SecurityAnalysisRunParameters runParameters) {

/* }
@Override
public CompletableFuture<SecurityAnalysisReport> run(Network network, String workingVariantId, LimitViolationDetector limitViolationDetector,
LimitViolationFilter limitViolationFilter, ComputationManager computationManager,
SecurityAnalysisParameters securityAnalysisParameters, ContingenciesProvider contingenciesProvider,
List<SecurityAnalysisInterceptor> interceptors, List<OperatorStrategy> operatorStrategies, List<Action> actions,
List<StateMonitor> stateMonitors, List<LimitReduction> limitReductions, ReportNode reportNode) {
List<StateMonitor> stateMonitors, List<LimitReduction> limitReductions, ReportNode reportNode) {*/
Objects.requireNonNull(network);
Objects.requireNonNull(workingVariantId);
Objects.requireNonNull(computationManager);
Objects.requireNonNull(securityAnalysisParameters);
Objects.requireNonNull(runParameters.getComputationManager());
Objects.requireNonNull(runParameters.getSecurityAnalysisParameters());
Objects.requireNonNull(contingenciesProvider);
Objects.requireNonNull(interceptors);
Objects.requireNonNull(operatorStrategies);
Objects.requireNonNull(actions);
Objects.requireNonNull(stateMonitors);
Objects.requireNonNull(reportNode);
Objects.requireNonNull(runParameters.getInterceptors());
Objects.requireNonNull(runParameters.getOperatorStrategies());
Objects.requireNonNull(runParameters.getActions());
Objects.requireNonNull(runParameters.getMonitors());
Objects.requireNonNull(runParameters.getReportNode());

LoadFlowParameters loadFlowParameters = securityAnalysisParameters.getLoadFlowParameters();
LoadFlowParameters loadFlowParameters = runParameters.getSecurityAnalysisParameters().getLoadFlowParameters();
OpenLoadFlowParameters loadFlowParametersExt = OpenLoadFlowParameters.get(loadFlowParameters);

// FIXME implement a fast incremental connectivity algorithm
GraphConnectivityFactory<LfBus, LfBranch> selectedConnectivityFactory;
if (operatorStrategies.isEmpty() && !loadFlowParametersExt.isSimulateAutomationSystems()) {
if (runParameters.getOperatorStrategies().isEmpty() && !loadFlowParametersExt.isSimulateAutomationSystems()) {
selectedConnectivityFactory = connectivityFactory;
} else {
LOGGER.warn("Naive (and slow!!!) connectivity algorithm has been selected because at least one operator strategy is configured");
Expand All @@ -93,12 +97,13 @@ public CompletableFuture<SecurityAnalysisReport> run(Network network, String wor

AbstractSecurityAnalysis<?, ?, ?, ?, ?> securityAnalysis;
if (loadFlowParameters.isDc()) {
securityAnalysis = new DcSecurityAnalysis(network, matrixFactory, selectedConnectivityFactory, stateMonitors, reportNode);
securityAnalysis = new DcSecurityAnalysis(network, matrixFactory, selectedConnectivityFactory, runParameters.getMonitors(), runParameters.getReportNode());
} else {
securityAnalysis = new AcSecurityAnalysis(network, matrixFactory, selectedConnectivityFactory, stateMonitors, reportNode);
securityAnalysis = new AcSecurityAnalysis(network, matrixFactory, selectedConnectivityFactory, runParameters.getMonitors(), runParameters.getReportNode());
}

return securityAnalysis.run(workingVariantId, securityAnalysisParameters, contingenciesProvider, computationManager, operatorStrategies, actions, limitReductions);
return securityAnalysis.run(workingVariantId, runParameters.getSecurityAnalysisParameters(), contingenciesProvider,
runParameters.getComputationManager(), runParameters.getOperatorStrategies(), runParameters.getActions(), runParameters.getLimitReductions());
}

@Override
Expand Down
29 changes: 13 additions & 16 deletions src/test/java/com/powsybl/openloadflow/NonImpedantBranchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
package com.powsybl.openloadflow;

import com.powsybl.commons.report.ReportNode;
import com.powsybl.computation.local.LocalComputationManager;
import com.powsybl.contingency.BranchContingency;
import com.powsybl.contingency.ContingenciesProvider;
Expand Down Expand Up @@ -365,11 +364,12 @@ void securityAnalysisTest() {

ContingenciesProvider provider = n -> contingencies;
SecurityAnalysisProvider securityAnalysisProvider = new OpenSecurityAnalysisProvider(new DenseMatrixFactory(), new EvenShiloachGraphDecrementalConnectivityFactory<>());
SecurityAnalysisReport report = securityAnalysisProvider.run(network, network.getVariantManager().getWorkingVariantId(), new DefaultLimitViolationDetector(),
new LimitViolationFilter(), LocalComputationManager.getDefault(), new SecurityAnalysisParameters(), provider, Collections.emptyList(),
Collections.emptyList(), Collections.emptyList(),
Collections.emptyList(), Collections.emptyList(),
ReportNode.NO_OP).join();
SecurityAnalysisRunParameters runParameters = new SecurityAnalysisRunParameters()
.setDetector(new DefaultLimitViolationDetector())
.setFilter(new LimitViolationFilter())
.setComputationManager(LocalComputationManager.getDefault())
.setSecurityAnalysisParameters(new SecurityAnalysisParameters());
SecurityAnalysisReport report = securityAnalysisProvider.run(network, network.getVariantManager().getWorkingVariantId(), provider, runParameters).join();
assertEquals(PostContingencyComputationStatus.CONVERGED, report.getResult().getPostContingencyResults().get(0).getStatus());
assertEquals(PostContingencyComputationStatus.CONVERGED, report.getResult().getPostContingencyResults().get(1).getStatus());
}
Expand Down Expand Up @@ -402,19 +402,16 @@ void securityAnalysisNotSameNumberOfVariablesAndEquationsIssueTest() {
Set.of("tr34"),
Set.of("b0_vl", "b1_vl", "b2_vl", "b3_vl", "b4_vl", "b5_vl"),
Collections.emptySet()));
SecurityAnalysisRunParameters runParameters = new SecurityAnalysisRunParameters()
.setDetector(new DefaultLimitViolationDetector())
.setFilter(new LimitViolationFilter())
.setComputationManager(LocalComputationManager.getDefault())
.setSecurityAnalysisParameters(securityAnalysisParameters)
.setMonitors(monitors);
SecurityAnalysisResult result = provider.run(network,
network.getVariantManager().getWorkingVariantId(),
new DefaultLimitViolationDetector(),
new LimitViolationFilter(),
LocalComputationManager.getDefault(),
securityAnalysisParameters,
n -> contingencies,
Collections.emptyList(),
Collections.emptyList(),
Collections.emptyList(),
monitors,
Collections.emptyList(),
ReportNode.NO_OP)
runParameters)
.join()
.getResult();
assertEquals(LoadFlowResult.ComponentResult.Status.CONVERGED, result.getPreContingencyResult().getStatus());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@
import com.powsybl.openloadflow.network.LfBus;
import com.powsybl.openloadflow.network.NodeBreakerNetworkFactory;
import com.powsybl.openloadflow.network.SlackBusSelectionMode;
import com.powsybl.security.LimitViolationFilter;
import com.powsybl.security.SecurityAnalysisParameters;
import com.powsybl.security.SecurityAnalysisReport;
import com.powsybl.security.SecurityAnalysisResult;
import com.powsybl.security.*;
import com.powsybl.security.detectors.DefaultLimitViolationDetector;
import com.powsybl.security.limitreduction.LimitReduction;
import com.powsybl.security.monitor.StateMonitor;
Expand Down Expand Up @@ -138,39 +135,35 @@ protected SecurityAnalysisResult runSecurityAnalysis(Network network, List<Conti
protected SecurityAnalysisResult runSecurityAnalysis(Network network, List<Contingency> contingencies, List<StateMonitor> monitors,
SecurityAnalysisParameters saParameters, ReportNode reportNode) {
ContingenciesProvider provider = n -> contingencies;
SecurityAnalysisRunParameters runParameters = new SecurityAnalysisRunParameters()
.setDetector(new DefaultLimitViolationDetector())
.setFilter(new LimitViolationFilter())
.setComputationManager(computationManager)
.setSecurityAnalysisParameters(saParameters)
.setMonitors(monitors)
.setReportNode(reportNode);
SecurityAnalysisReport report = securityAnalysisProvider.run(network,
network.getVariantManager().getWorkingVariantId(),
new DefaultLimitViolationDetector(),
new LimitViolationFilter(),
computationManager,
saParameters,
provider,
Collections.emptyList(),
Collections.emptyList(),
Collections.emptyList(),
monitors,
Collections.emptyList(),
reportNode)
runParameters)
.join();
return report.getResult();
}

protected SecurityAnalysisResult runSecurityAnalysis(Network network, List<Contingency> contingencies, List<StateMonitor> monitors,
List<LimitReduction> limitReductions, SecurityAnalysisParameters saParameters) {
ContingenciesProvider provider = n -> contingencies;
SecurityAnalysisRunParameters runParameters = new SecurityAnalysisRunParameters()
.setDetector(new DefaultLimitViolationDetector())
.setFilter(new LimitViolationFilter())
.setComputationManager(computationManager)
.setSecurityAnalysisParameters(saParameters)
.setMonitors(monitors)
.setLimitReductions(limitReductions);
SecurityAnalysisReport report = securityAnalysisProvider.run(network,
network.getVariantManager().getWorkingVariantId(),
new DefaultLimitViolationDetector(),
new LimitViolationFilter(),
computationManager,
saParameters,
provider,
Collections.emptyList(),
Collections.emptyList(),
Collections.emptyList(),
monitors,
limitReductions,
ReportNode.NO_OP)
runParameters)
.join();
return report.getResult();
}
Expand All @@ -179,19 +172,19 @@ protected SecurityAnalysisResult runSecurityAnalysis(Network network, List<Conti
SecurityAnalysisParameters saParameters, List<OperatorStrategy> operatorStrategies,
List<Action> actions, ReportNode reportNode) {
ContingenciesProvider provider = n -> contingencies;
SecurityAnalysisRunParameters runParameters = new SecurityAnalysisRunParameters()
.setDetector(new DefaultLimitViolationDetector())
.setFilter(new LimitViolationFilter())
.setComputationManager(computationManager)
.setSecurityAnalysisParameters(saParameters)
.setOperatorStrategies(operatorStrategies)
.setActions(actions)
.setMonitors(monitors)
.setReportNode(reportNode);
SecurityAnalysisReport report = securityAnalysisProvider.run(network,
network.getVariantManager().getWorkingVariantId(),
new DefaultLimitViolationDetector(),
new LimitViolationFilter(),
computationManager,
saParameters,
provider,
Collections.emptyList(),
operatorStrategies,
actions,
monitors,
Collections.emptyList(),
reportNode)
runParameters)
.join();
return report.getResult();
}
Expand Down

0 comments on commit 4edc8dc

Please sign in to comment.