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

Implements new SecurityAnalysisProvider #348

Merged
merged 4 commits into from
May 30, 2024
Merged
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 @@ -7,21 +7,14 @@
package com.powsybl.dynaflow;

import com.google.auto.service.AutoService;
import com.powsybl.action.Action;
import com.powsybl.commons.report.ReportNode;
import com.powsybl.computation.ComputationManager;
import com.powsybl.contingency.ContingenciesProvider;
import com.powsybl.dynawo.commons.PowsyblDynawoVersion;
import com.powsybl.iidm.network.Network;
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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;
Expand Down Expand Up @@ -49,37 +42,28 @@ public DynaFlowSecurityAnalysisProvider(Supplier<DynaFlowConfig> configSupplier)
@Override
public CompletableFuture<SecurityAnalysisReport> run(Network network,
String workingVariantId,
LimitViolationDetector detector,
LimitViolationFilter filter,
ComputationManager computationManager,
SecurityAnalysisParameters parameters,
ContingenciesProvider contingenciesProvider,
List<SecurityAnalysisInterceptor> interceptors,
List<OperatorStrategy> operatorStrategies,
List<Action> actions,
List<StateMonitor> monitors,
List<LimitReduction> limitReductions,
ReportNode reportNode) {
if (detector != null) {
SecurityAnalysisRunParameters runParameters) {
if (runParameters.getDetector() != null) {
LOG.error("LimitViolationDetector is not used in Dynaflow implementation.");
}
if (monitors != null && !monitors.isEmpty()) {
if (!runParameters.getMonitors().isEmpty()) {
LOG.error("Monitoring is not possible with Dynaflow implementation. There will not be supplementary information about monitored equipment.");
}
if (operatorStrategies != null && !operatorStrategies.isEmpty()) {
if (!runParameters.getOperatorStrategies().isEmpty()) {
LOG.error("Strategies are not implemented in Dynaflow");
}
if (actions != null && !actions.isEmpty()) {
if (!runParameters.getActions().isEmpty()) {
LOG.error("Actions are not implemented in Dynaflow");
}
if (limitReductions != null && !limitReductions.isEmpty()) {
if (!runParameters.getLimitReductions().isEmpty()) {
LOG.error("Limit reductions are not implemented in Dynaflow");
}
DynaFlowSecurityAnalysis securityAnalysis = new DynaFlowSecurityAnalysis(network, filter, computationManager, configSupplier);
interceptors.forEach(securityAnalysis::addInterceptor);
DynaFlowSecurityAnalysis securityAnalysis = new DynaFlowSecurityAnalysis(network, runParameters.getFilter(), runParameters.getComputationManager(), configSupplier);
runParameters.getInterceptors().forEach(securityAnalysis::addInterceptor);

ReportNode dfsaReportNode = DynaflowReports.createDynaFlowSecurityAnalysisReportNode(reportNode, network.getId());
return securityAnalysis.run(workingVariantId, parameters, contingenciesProvider, dfsaReportNode);
ReportNode dfsaReportNode = DynaflowReports.createDynaFlowSecurityAnalysisReportNode(runParameters.getReportNode(), network.getId());
return securityAnalysis.run(workingVariantId, runParameters.getSecurityAnalysisParameters(), contingenciesProvider, dfsaReportNode);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@

import com.powsybl.commons.PowsyblException;
import com.powsybl.commons.test.AbstractSerDeTest;
import com.powsybl.computation.ComputationManager;
import com.powsybl.computation.local.LocalCommandExecutor;
import com.powsybl.computation.local.LocalComputationConfig;
import com.powsybl.computation.local.LocalComputationManager;
import com.powsybl.contingency.ContingenciesProvider;
import com.powsybl.contingency.Contingency;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import com.powsybl.loadflow.LoadFlowResult;
import com.powsybl.security.SecurityAnalysis;
import com.powsybl.security.SecurityAnalysisParameters;
import com.powsybl.security.SecurityAnalysisReport;
import com.powsybl.security.SecurityAnalysisResult;
import com.powsybl.security.*;
import com.powsybl.security.json.SecurityAnalysisResultSerializer;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -120,9 +115,9 @@ void test() throws IOException {
LocalCommandExecutor commandExecutor = new LocalCommandExecutorMock("/dynawo_version.out",
"/SecurityAnalysis/input.xiidm", "/SecurityAnalysis/contingencies.json",
contingencyIds, List.of("/SecurityAnalysis/constraints1.xml", "/SecurityAnalysis/constraints2.xml"));
ComputationManager computationManager = new LocalComputationManager(new LocalComputationConfig(fileSystem.getPath("/working-dir"), 1), commandExecutor, ForkJoinPool.commonPool());

SecurityAnalysisReport report = SecurityAnalysis.run(network, n -> contingencies, SecurityAnalysisParameters.load(), computationManager);
SecurityAnalysisRunParameters runParameters = new SecurityAnalysisRunParameters()
.setComputationManager(new LocalComputationManager(new LocalComputationConfig(fileSystem.getPath("/working-dir"), 1), commandExecutor, ForkJoinPool.commonPool()));
SecurityAnalysisReport report = SecurityAnalysis.run(network, contingencies, runParameters);
SecurityAnalysisResult result = report.getResult();
assertEquals(LoadFlowResult.ComponentResult.Status.CONVERGED, result.getPreContingencyResult().getStatus());

Expand All @@ -134,11 +129,10 @@ void test() throws IOException {
@Test
void testCallingBadVersionDynawo() throws IOException {
Network network = Network.create("test", "test");
ContingenciesProvider contingenciesProvider = n -> List.of();
LocalCommandExecutor commandExecutor = new LocalCommandExecutorMock("/dynawo_bad_version.out", null);
ComputationManager computationManager = new LocalComputationManager(new LocalComputationConfig(fileSystem.getPath("/working-dir"), 1), commandExecutor, ForkJoinPool.commonPool());
SecurityAnalysisParameters sap = SecurityAnalysisParameters.load();
assertThrows(PowsyblException.class, () -> SecurityAnalysis.run(network, contingenciesProvider, sap, computationManager));
SecurityAnalysisRunParameters runParameters = new SecurityAnalysisRunParameters()
.setComputationManager(new LocalComputationManager(new LocalComputationConfig(fileSystem.getPath("/working-dir"), 1), commandExecutor, ForkJoinPool.commonPool()));
assertThrows(PowsyblException.class, () -> SecurityAnalysis.run(network, List.of(), runParameters));
}

private static Network buildNetwork() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
import com.powsybl.iidm.network.test.FourSubstationsNodeBreakerFactory;
import com.powsybl.loadflow.LoadFlowParameters;
import com.powsybl.loadflow.LoadFlowResult;
import com.powsybl.security.LimitViolationFilter;
import com.powsybl.security.SecurityAnalysisParameters;
import com.powsybl.security.SecurityAnalysisResult;
import com.powsybl.security.detectors.DefaultLimitViolationDetector;
import com.powsybl.security.SecurityAnalysisRunParameters;
import com.powsybl.security.json.SecurityAnalysisResultSerializer;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -35,7 +34,6 @@
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -125,9 +123,11 @@ void testSaBb() throws IOException {
.toList();

ReportNode reportNode = ReportNode.newRootReportNode().withMessageTemplate("root", "Root message").build();
SecurityAnalysisResult result = securityAnalysisProvider.run(network, VariantManagerConstants.INITIAL_VARIANT_ID, new DefaultLimitViolationDetector(),
new LimitViolationFilter(), computationManager, securityAnalysisParameters, n -> contingencies, Collections.emptyList(),
Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), reportNode)
SecurityAnalysisRunParameters runParameters = new SecurityAnalysisRunParameters()
.setComputationManager(computationManager)
.setSecurityAnalysisParameters(securityAnalysisParameters)
.setReportNode(reportNode);
SecurityAnalysisResult result = securityAnalysisProvider.run(network, VariantManagerConstants.INITIAL_VARIANT_ID, n -> contingencies, runParameters)
.join()
.getResult();

Expand All @@ -151,9 +151,10 @@ void testSaNb() throws IOException {
List<Contingency> contingencies = network.getGeneratorStream()
.map(g -> Contingency.generator(g.getId()))
.toList();
SecurityAnalysisResult result = securityAnalysisProvider.run(network, VariantManagerConstants.INITIAL_VARIANT_ID, new DefaultLimitViolationDetector(),
new LimitViolationFilter(), computationManager, securityAnalysisParameters, n -> contingencies, Collections.emptyList(),
Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), ReportNode.NO_OP)
SecurityAnalysisRunParameters runParameters = new SecurityAnalysisRunParameters()
.setComputationManager(computationManager)
.setSecurityAnalysisParameters(securityAnalysisParameters);
SecurityAnalysisResult result = securityAnalysisProvider.run(network, VariantManagerConstants.INITIAL_VARIANT_ID, n -> contingencies, runParameters)
.join()
.getResult();

Expand Down
Loading