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

[WIP] POC: create security analysis from rao results: add operational limits to use for analysis (instead of limits in network) #1074

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
10 changes: 10 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ jobs:
with:
distribution: 'temurin'
java-version: '17'

- name: Checkout powsybl-core sources
uses: actions/checkout@v1
with:
repository: powsybl/powsybl-core
ref: refs/heads/security_analysis_rewrite_operational_limits

- name: Build and install powsybl-core with Maven
run: mvn --batch-mode -DskipTests=true --file ../powsybl-core/pom.xml install


- name: Build with Maven (Ubuntu / MacOS)
if: matrix.os != 'windows-latest'
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<slf4jtoys.version>1.6.3</slf4jtoys.version>
<asciitable.version>0.3.2</asciitable.version>

<powsybl-core.version>6.4.1</powsybl-core.version>
<powsybl-core.version>6.5.0-SNAPSHOT</powsybl-core.version>
</properties>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.powsybl.computation.ComputationManager;
import com.powsybl.contingency.ContingenciesProvider;
import com.powsybl.contingency.Contingency;
import com.powsybl.contingency.ContingencyContext;
import com.powsybl.iidm.network.Branch;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.Switch;
Expand Down Expand Up @@ -43,6 +44,7 @@
import com.powsybl.security.monitor.StateMonitorIndex;
import com.powsybl.security.results.*;
import com.powsybl.security.strategy.ConditionalActions;
import com.powsybl.security.strategy.OperationalLimitOverride;
import com.powsybl.security.strategy.OperatorStrategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -90,13 +92,14 @@ protected static SecurityAnalysisResult createNoResult() {

public CompletableFuture<SecurityAnalysisReport> run(String workingVariantId, SecurityAnalysisParameters securityAnalysisParameters,
ContingenciesProvider contingenciesProvider, ComputationManager computationManager,
List<OperatorStrategy> operatorStrategies, List<Action> actions, List<LimitReduction> limitReductions) {
List<OperatorStrategy> operatorStrategies, List<Action> actions, List<LimitReduction> limitReductions,
List<OperationalLimitOverride> limitsToOverride) {
Objects.requireNonNull(workingVariantId);
Objects.requireNonNull(securityAnalysisParameters);
Objects.requireNonNull(contingenciesProvider);
return CompletableFutureTask.runAsync(() -> {
network.getVariantManager().setWorkingVariant(workingVariantId);
return runSync(securityAnalysisParameters, contingenciesProvider, operatorStrategies, actions, limitReductions);
return runSync(securityAnalysisParameters, contingenciesProvider, operatorStrategies, actions, limitReductions, limitsToOverride);
}, computationManager.getExecutor());
}

Expand All @@ -107,7 +110,7 @@ public CompletableFuture<SecurityAnalysisReport> run(String workingVariantId, Se
protected abstract P createParameters(LoadFlowParameters lfParameters, OpenLoadFlowParameters lfParametersExt, boolean breakers);

SecurityAnalysisReport runSync(SecurityAnalysisParameters securityAnalysisParameters, ContingenciesProvider contingenciesProvider,
List<OperatorStrategy> operatorStrategies, List<Action> actions, List<LimitReduction> limitReductions) {
List<OperatorStrategy> operatorStrategies, List<Action> actions, List<LimitReduction> limitReductions, List<OperationalLimitOverride> limitsToOverride) {
var saReportNode = createSaRootReportNode();

Stopwatch stopwatch = Stopwatch.createStarted();
Expand Down Expand Up @@ -150,7 +153,7 @@ SecurityAnalysisReport runSync(SecurityAnalysisParameters securityAnalysisParame
try (LfNetworkList lfNetworks = Networks.load(network, parameters.getNetworkParameters(), topoConfig, saReportNode)) {
// run simulation on largest network
SecurityAnalysisResult result = lfNetworks.getLargest().filter(n -> n.getValidity() == LfNetwork.Validity.VALID)
.map(largestNetwork -> runSimulations(largestNetwork, propagatedContingencies, parameters, securityAnalysisParameters, operatorStrategies, actions, limitReductions))
.map(largestNetwork -> runSimulations(largestNetwork, propagatedContingencies, parameters, securityAnalysisParameters, operatorStrategies, actions, limitReductions, limitsToOverride))
.orElse(createNoResult());

stopwatch.stop();
Expand Down Expand Up @@ -396,7 +399,7 @@ protected void afterPreContingencySimulation(P acParameters) {

protected SecurityAnalysisResult runSimulations(LfNetwork lfNetwork, List<PropagatedContingency> propagatedContingencies, P acParameters,
SecurityAnalysisParameters securityAnalysisParameters, List<OperatorStrategy> operatorStrategies,
List<Action> actions, List<LimitReduction> limitReductions) {
List<Action> actions, List<LimitReduction> limitReductions, List<OperationalLimitOverride> limitsToOverride) {
Map<String, Action> actionsById = indexActionsById(actions);
Set<Action> neededActions = new HashSet<>(actionsById.size());
Map<String, List<OperatorStrategy>> operatorStrategiesByContingencyId = indexOperatorStrategiesByContingencyId(propagatedContingencies, operatorStrategies, actionsById, neededActions);
Expand All @@ -417,7 +420,8 @@ protected SecurityAnalysisResult runSimulations(LfNetwork lfNetwork, List<Propag
.run();

boolean preContingencyComputationOk = preContingencyLoadFlowResult.isSuccess();
var preContingencyLimitViolationManager = new LimitViolationManager(limitReductions);
var limitsToOverridePreContingency = limitsToOverride.stream().filter(l -> l.getContingencyContext() == ContingencyContext.none()).toList();
var preContingencyLimitViolationManager = new LimitViolationManager(limitReductions, limitsToOverridePreContingency);
List<PostContingencyResult> postContingencyResults = new ArrayList<>();
var preContingencyNetworkResult = new PreContingencyNetworkResult(lfNetwork, monitorIndex, createResultExtension);
List<OperatorStrategyResult> operatorStrategyResults = new ArrayList<>();
Expand Down Expand Up @@ -451,7 +455,8 @@ protected SecurityAnalysisResult runSimulations(LfNetwork lfNetwork, List<Propag
var postContingencyResult = runPostContingencySimulation(lfNetwork, context, propagatedContingency.getContingency(),
lfContingency, preContingencyLimitViolationManager,
securityAnalysisParameters.getIncreasedViolationsParameters(),
preContingencyNetworkResult, createResultExtension, limitReductions);
preContingencyNetworkResult, createResultExtension, limitReductions,
limitsToOverride);
postContingencyResults.add(postContingencyResult);

List<OperatorStrategy> operatorStrategiesForThisContingency = operatorStrategiesByContingencyId.get(lfContingency.getId());
Expand All @@ -468,7 +473,7 @@ protected SecurityAnalysisResult runSimulations(LfNetwork lfNetwork, List<Propag
operatorStrategy, preContingencyLimitViolationManager,
securityAnalysisParameters.getIncreasedViolationsParameters(), lfActionById,
createResultExtension, lfContingency, postContingencyResult.getLimitViolationsResult(),
acParameters.getNetworkParameters(), limitReductions)
acParameters.getNetworkParameters(), limitReductions, limitsToOverride)
.ifPresent(operatorStrategyResults::add);
} else {
// multiple operator strategies, save post contingency state for later restoration after action
Expand All @@ -480,7 +485,7 @@ protected SecurityAnalysisResult runSimulations(LfNetwork lfNetwork, List<Propag
operatorStrategy, preContingencyLimitViolationManager,
securityAnalysisParameters.getIncreasedViolationsParameters(), lfActionById,
createResultExtension, lfContingency, postContingencyResult.getLimitViolationsResult(),
acParameters.getNetworkParameters(), limitReductions)
acParameters.getNetworkParameters(), limitReductions, limitsToOverride)
.ifPresent(result -> {
operatorStrategyResults.add(result);
postContingencyNetworkState.restore();
Expand Down Expand Up @@ -512,13 +517,13 @@ private Optional<OperatorStrategyResult> runActionSimulation(LfNetwork network,
SecurityAnalysisParameters.IncreasedViolationsParameters violationsParameters,
Map<String, LfAction> lfActionById, boolean createResultExtension, LfContingency contingency,
LimitViolationsResult postContingencyLimitViolations, LfNetworkParameters networkParameters,
List<LimitReduction> limitReductions) {
List<LimitReduction> limitReductions, List<OperationalLimitOverride> limitsToOverride) {
OperatorStrategyResult operatorStrategyResult = null;

List<String> actionIds = checkCondition(operatorStrategy, postContingencyLimitViolations);
if (!actionIds.isEmpty()) {
operatorStrategyResult = runActionSimulation(network, context, operatorStrategy, actionIds, preContingencyLimitViolationManager,
violationsParameters, lfActionById, createResultExtension, contingency, networkParameters, limitReductions);
violationsParameters, lfActionById, createResultExtension, contingency, networkParameters, limitReductions, limitsToOverride);
}

return Optional.ofNullable(operatorStrategyResult);
Expand All @@ -528,7 +533,7 @@ protected PostContingencyResult runPostContingencySimulation(LfNetwork network,
LimitViolationManager preContingencyLimitViolationManager,
SecurityAnalysisParameters.IncreasedViolationsParameters violationsParameters,
PreContingencyNetworkResult preContingencyNetworkResult, boolean createResultExtension,
List<LimitReduction> limitReductions) {
List<LimitReduction> limitReductions, List<OperationalLimitOverride> limitsToOverride) {
LOGGER.info("Start post contingency '{}' simulation on network {}", lfContingency.getId(), network);
LOGGER.debug("Contingency '{}' impact on network {}: remove {} buses, remove {} branches, remove {} generators, shift {} shunts, shift {} loads",
lfContingency.getId(), network, lfContingency.getDisabledNetwork().getBuses(), lfContingency.getDisabledNetwork().getBranchesStatus(),
Expand All @@ -538,7 +543,8 @@ protected PostContingencyResult runPostContingencySimulation(LfNetwork network,

// restart LF on post contingency equation system
PostContingencyComputationStatus status = runActionLoadFlow(context); // FIXME: change name.
var postContingencyLimitViolationManager = new LimitViolationManager(preContingencyLimitViolationManager, limitReductions, violationsParameters);
var limitsToOverridePostContingency = limitsToOverride.stream().filter(l -> Objects.equals(l.getContingencyContext(), ContingencyContext.specificContingency(contingency.getId())) && l.getConditionalActionsId().isEmpty()).toList();
var postContingencyLimitViolationManager = new LimitViolationManager(preContingencyLimitViolationManager, limitReductions, limitsToOverridePostContingency, violationsParameters);
var postContingencyNetworkResult = new PostContingencyNetworkResult(network, monitorIndex, createResultExtension, preContingencyNetworkResult, contingency);

if (status.equals(PostContingencyComputationStatus.CONVERGED)) {
Expand Down Expand Up @@ -571,7 +577,8 @@ protected OperatorStrategyResult runActionSimulation(LfNetwork network, C contex
LimitViolationManager preContingencyLimitViolationManager,
SecurityAnalysisParameters.IncreasedViolationsParameters violationsParameters,
Map<String, LfAction> lfActionById, boolean createResultExtension, LfContingency contingency,
LfNetworkParameters networkParameters, List<LimitReduction> limitReductions) {
LfNetworkParameters networkParameters, List<LimitReduction> limitReductions,
List<OperationalLimitOverride> limitsToOverride) {
LOGGER.info("Start operator strategy {} after contingency '{}' simulation on network {}", operatorStrategy.getId(),
operatorStrategy.getContingencyContext().getContingencyId(), network);

Expand All @@ -589,7 +596,8 @@ protected OperatorStrategyResult runActionSimulation(LfNetwork network, C contex

// restart LF on post contingency and post actions equation system
PostContingencyComputationStatus status = runActionLoadFlow(context);
var postActionsViolationManager = new LimitViolationManager(preContingencyLimitViolationManager, limitReductions, violationsParameters);
var limitsToOverridePostActions = limitsToOverride.stream().filter(l -> Objects.equals(l.getContingencyContext(), ContingencyContext.specificContingency(contingency.getId())) && l.getConditionalActionsId().isPresent()).toList();
var postActionsViolationManager = new LimitViolationManager(preContingencyLimitViolationManager, limitReductions, limitsToOverridePostActions, violationsParameters);
var postActionsNetworkResult = new PreContingencyNetworkResult(network, monitorIndex, createResultExtension);

if (status.equals(PostContingencyComputationStatus.CONVERGED)) {
Expand Down
Loading