com.powsybl.afs.security.local.LocalSecurityAnalysisRunningService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of powsybl-afs-security-analysis-local Show documentation
Show all versions of powsybl-afs-security-analysis-local Show documentation
Local implementation of security analysis service.
The newest version!
/**
* Copyright (c) 2018, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.afs.security.local;
import com.powsybl.afs.AfsException;
import com.powsybl.afs.AppLogger;
import com.powsybl.afs.ext.base.ProjectCase;
import com.powsybl.afs.security.SecurityAnalysisRunner;
import com.powsybl.afs.security.SecurityAnalysisRunningService;
import com.powsybl.computation.ComputationManager;
import com.powsybl.contingency.ContingenciesProvider;
import com.powsybl.contingency.EmptyContingencyListProvider;
import com.powsybl.iidm.network.Network;
import com.powsybl.security.*;
import com.powsybl.security.interceptors.SecurityAnalysisInterceptor;
import com.powsybl.security.interceptors.SecurityAnalysisInterceptors;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
/**
* @author Geoffroy Jamgotchian {@literal }
*/
public class LocalSecurityAnalysisRunningService implements SecurityAnalysisRunningService {
private final SecurityAnalysis.Runner securityAnalysis;
public LocalSecurityAnalysisRunningService(SecurityAnalysis.Runner securityAnalysis) {
this.securityAnalysis = Objects.requireNonNull(securityAnalysis);
}
@Override
public void run(SecurityAnalysisRunner runner) {
Objects.requireNonNull(runner);
ProjectCase aCase = (ProjectCase) runner.getCase().orElseThrow(() -> new AfsException("Invalid case link"));
ContingenciesProvider contingencyListProvider = runner.getContingencyStore()
.map(store -> (ContingenciesProvider) store)
.orElse(new EmptyContingencyListProvider());
SecurityAnalysisParameters parameters = runner.readParameters();
ComputationManager computationManager = runner.getFileSystem().getData().getLongTimeExecutionComputationManager();
UUID taskId = runner.startTask();
try {
AppLogger logger = runner.createLogger(taskId);
logger.log("Loading network...");
Network network = aCase.getNetwork();
// add all interceptors
List interceptors = new ArrayList<>();
for (String interceptorName : SecurityAnalysisInterceptors.getExtensionNames()) {
interceptors.add(SecurityAnalysisInterceptors.createInterceptor(interceptorName));
}
SecurityAnalysisRunParameters runParameters = new SecurityAnalysisRunParameters()
.setSecurityAnalysisParameters(parameters)
.setComputationManager(computationManager)
.setFilter(new LimitViolationFilter())
.setInterceptors(interceptors);
logger.log("Running security analysis...");
SecurityAnalysisReport securityAnalysisReport = securityAnalysis.run(network,
network.getVariantManager().getWorkingVariantId(),
contingencyListProvider,
runParameters);
runner.writeResult(securityAnalysisReport.getResult());
} finally {
runner.stopTask(taskId);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy