Skip to content

Commit

Permalink
Fix Breaking change
Browse files Browse the repository at this point in the history
Signed-off-by: lisrte <[email protected]>
  • Loading branch information
Lisrte committed May 17, 2024
1 parent c669ccc commit 7abb2b5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 46 deletions.
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,29 @@ 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,
SecurityAnalysisRunParameters runParameters,
ReportNode reportNode) {
if (detector != null) {
if (runParameters.getDetector() != null) {
LOG.error("LimitViolationDetector is not used in Dynaflow implementation.");
}
if (monitors != null && !monitors.isEmpty()) {
if (runParameters.getMonitors() != null && !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() != null && !runParameters.getOperatorStrategies().isEmpty()) {
LOG.error("Strategies are not implemented in Dynaflow");
}
if (actions != null && !actions.isEmpty()) {
if (runParameters.getActions() != null && !runParameters.getActions().isEmpty()) {
LOG.error("Actions are not implemented in Dynaflow");
}
if (limitReductions != null && !limitReductions.isEmpty()) {
if (runParameters.getLimitReductions() != null && !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);
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,10 @@ 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);
SecurityAnalysisResult result = securityAnalysisProvider.run(network, VariantManagerConstants.INITIAL_VARIANT_ID, n -> contingencies, runParameters, reportNode)
.join()
.getResult();

Expand All @@ -151,9 +150,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, ReportNode.NO_OP)
.join()
.getResult();

Expand Down

0 comments on commit 7abb2b5

Please sign in to comment.