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

Auto fixes #719

Merged
merged 9 commits into from
Jan 12, 2023
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 @@ -84,7 +84,7 @@ AutomatonPerimeterResultImpl simulateAutomatonState(State automatonState, State
BUSINESS_WARNS.warn("CRAC has network action automatons with usage method AVAILABLE. These are not supported.");
}
TECHNICAL_LOGS.info("Initial situation:");
RaoLogger.logMostLimitingElementsResults(TECHNICAL_LOGS, prePerimeterSensitivityOutput, Set.of(automatonState, curativeState), raoParameters.getObjectiveFunction(), numberLoggedElementsDuringRao);
RaoLogger.logMostLimitingElementsResults(TECHNICAL_LOGS, prePerimeterSensitivityOutput, Set.of(automatonState), raoParameters.getObjectiveFunction(), numberLoggedElementsDuringRao);

PrePerimeterSensitivityAnalysis preAutoPerimeterSensitivityAnalysis = getPreAutoPerimeterSensitivityAnalysis(automatonState, curativeState);

Expand Down Expand Up @@ -169,7 +169,7 @@ TopoAutomatonSimulationResult simulateTopologicalAutomatons(State automatonState
if (!appliedNetworkActions.isEmpty()) {
TECHNICAL_LOGS.info("Running sensi post application of auto network actions for automaton state {}.", automatonState.getId());
automatonRangeActionOptimizationSensitivityAnalysisOutput = preAutoPerimeterSensitivityAnalysis.runBasedOnInitialResults(network, crac, initialFlowResult, prePerimeterRangeActionSetpointResult, operatorsNotSharingCras, null);
RaoLogger.logMostLimitingElementsResults(TECHNICAL_LOGS, automatonRangeActionOptimizationSensitivityAnalysisOutput, raoParameters.getObjectiveFunction(), numberLoggedElementsDuringRao);
RaoLogger.logMostLimitingElementsResults(TECHNICAL_LOGS, automatonRangeActionOptimizationSensitivityAnalysisOutput, Set.of(automatonState), raoParameters.getObjectiveFunction(), numberLoggedElementsDuringRao);
}

return new TopoAutomatonSimulationResult(automatonRangeActionOptimizationSensitivityAnalysisOutput, appliedNetworkActions);
Expand Down Expand Up @@ -202,8 +202,8 @@ Map<RangeAction<?>, Double> getRangeActionsWithSetpoint() {
}
}

RangeAutomatonSimulationResult simulateRangeAutomatons(State automatonState, State curativeState, Network network, PrePerimeterSensitivityAnalysis preAutoPerimeterSensitivityAnalysis, PrePerimeterResult postAutoResult) {
PrePerimeterResult finalPostAutoResult = postAutoResult;
RangeAutomatonSimulationResult simulateRangeAutomatons(State automatonState, State curativeState, Network network, PrePerimeterSensitivityAnalysis preAutoPerimeterSensitivityAnalysis, PrePerimeterResult postAutoTopoResult) {
PrePerimeterResult finalPostAutoResult = postAutoTopoResult;
// -- Create groups of aligned range actions
List<List<RangeAction<?>>> rangeActionsOnAutomatonState = buildRangeActionsGroupsOrderedBySpeed(finalPostAutoResult, automatonState, network);
// -- Build AutomatonPerimeterResultImpl objects
Expand All @@ -219,10 +219,6 @@ RangeAutomatonSimulationResult simulateRangeAutomatons(State automatonState, Sta
// -- Optimize range-action automatons
for (List<RangeAction<?>> alignedRa : rangeActionsOnAutomatonState) {
RangeAction<?> availableRa = alignedRa.get(0);
// Disable AC emulation for HVDC lines
if (alignedRa.stream().allMatch(HvdcRangeAction.class::isInstance)) {
finalPostAutoResult = disableACEmulation(alignedRa, network, preAutoPerimeterSensitivityAnalysis, finalPostAutoResult);
}
// Define flowCnecs depending on UsageMethod
Set<FlowCnec> flowCnecs = gatherFlowCnecsForAutoRangeAction(availableRa, automatonState, network);
// Shift
Expand All @@ -231,7 +227,8 @@ RangeAutomatonSimulationResult simulateRangeAutomatons(State automatonState, Sta
flowCnecs,
network,
preAutoPerimeterSensitivityAnalysis,
finalPostAutoResult);
finalPostAutoResult,
automatonState);
finalPostAutoResult = postShiftResult.getLeft();
activatedRangeActions.addAll(postShiftResult.getRight().keySet());
rangeActionsWithSetpoint.putAll(postShiftResult.getRight());
Expand Down Expand Up @@ -381,7 +378,7 @@ private PrePerimeterResult runPreCurativeSensitivityComputation(State automatonS
// Run computation
TECHNICAL_LOGS.info("Running pre curative sensi after auto state {}.", automatonState.getId());
PrePerimeterResult postAutomatonSensitivityAnalysisOutput = prePerimeterSensitivityAnalysis.runBasedOnInitialResults(network, crac, initialFlowResult, prePerimeterRangeActionSetpointResult, operatorsNotSharingCras, null);
RaoLogger.logMostLimitingElementsResults(TECHNICAL_LOGS, postAutomatonSensitivityAnalysisOutput, raoParameters.getObjectiveFunction(), numberLoggedElementsDuringRao);
RaoLogger.logMostLimitingElementsResults(TECHNICAL_LOGS, postAutomatonSensitivityAnalysisOutput, Set.of(automatonState), raoParameters.getObjectiveFunction(), numberLoggedElementsDuringRao);
return postAutomatonSensitivityAnalysisOutput;
}

Expand All @@ -392,7 +389,8 @@ private PrePerimeterResult runPreCurativeSensitivityComputation(State automatonS
PrePerimeterResult disableACEmulation(List<RangeAction<?>> alignedRa,
Network network,
PrePerimeterSensitivityAnalysis preAutoPerimeterSensitivityAnalysis,
PrePerimeterResult prePerimeterSensitivityOutput) {
PrePerimeterResult prePerimeterSensitivityOutput,
State automatonState) {
boolean runSensi = false;
for (RangeAction<?> alignedAvailableRa : alignedRa) {
if (alignedAvailableRa instanceof HvdcRangeAction) {
Expand All @@ -408,7 +406,7 @@ PrePerimeterResult disableACEmulation(List<RangeAction<?>> alignedRa,
if (runSensi) {
TECHNICAL_LOGS.info("Running sensi after disabling AC emulation.");
PrePerimeterResult result = preAutoPerimeterSensitivityAnalysis.runBasedOnInitialResults(network, crac, initialFlowResult, prePerimeterRangeActionSetpointResult, operatorsNotSharingCras, null);
RaoLogger.logMostLimitingElementsResults(TECHNICAL_LOGS, result, raoParameters.getObjectiveFunction(), numberLoggedElementsDuringRao);
RaoLogger.logMostLimitingElementsResults(TECHNICAL_LOGS, result, Set.of(automatonState), raoParameters.getObjectiveFunction(), numberLoggedElementsDuringRao);
return result;
} else {
return prePerimeterSensitivityOutput;
Expand All @@ -429,12 +427,20 @@ Pair<PrePerimeterResult, Map<RangeAction<?>, Double>> shiftRangeActionsUntilFlow
Set<FlowCnec> flowCnecs,
Network network,
PrePerimeterSensitivityAnalysis preAutoPerimeterSensitivityAnalysis,
PrePerimeterResult prePerimeterSensitivityOutput) {
PrePerimeterResult prePerimeterSensitivityOutput,
State automatonState) {

Set<Pair<FlowCnec, Side>> flowCnecsToBeExcluded = new HashSet<>();
PrePerimeterResult automatonRangeActionOptimizationSensitivityAnalysisOutput = prePerimeterSensitivityOutput;
Map<RangeAction<?>, Double> activatedRangeActionsWithSetpoint = new HashMap<>();
List<Pair<FlowCnec, Side>> flowCnecsWithNegativeMargin = getCnecsWithNegativeMarginWithoutExcludedCnecs(flowCnecs, flowCnecsToBeExcluded, automatonRangeActionOptimizationSensitivityAnalysisOutput);

if (alignedRangeActions.stream().allMatch(HvdcRangeAction.class::isInstance) && !flowCnecsWithNegativeMargin.isEmpty()) {
// Disable AC emulation for HVDC lines, re-run sensitivity analysis and fetch new negative margins
automatonRangeActionOptimizationSensitivityAnalysisOutput = disableACEmulation(alignedRangeActions, network, preAutoPerimeterSensitivityAnalysis, automatonRangeActionOptimizationSensitivityAnalysisOutput, automatonState);
flowCnecsWithNegativeMargin = getCnecsWithNegativeMarginWithoutExcludedCnecs(flowCnecs, flowCnecsToBeExcluded, automatonRangeActionOptimizationSensitivityAnalysisOutput);
}

// -- Define setpoint bounds
// Aligned range actions have the same setpoint :
double initialSetpoint = alignedRangeActions.get(0).getCurrentSetpoint(network);
Expand Down Expand Up @@ -484,9 +490,9 @@ Pair<PrePerimeterResult, Map<RangeAction<?>, Double>> shiftRangeActionsUntilFlow
rangeAction.apply(network, optimalSetpoint);
activatedRangeActionsWithSetpoint.put(rangeAction, optimalSetpoint);
}
TECHNICAL_LOGS.debug("Shifting setpoint from {} to {} on range action(s) {} to improve margin on cnec {} on side {}} (initial margin : {} MW).", initialSetpoint, optimalSetpoint, alignedRangeActions.stream().map(Identifiable::getId).collect(Collectors.joining(" ,")), toBeShiftedCnec.getId(), side, initialMargin);
TECHNICAL_LOGS.debug("Shifting setpoint from {} to {} on range action(s) {} to improve margin on cnec {} on side {}} (initial margin : {} MW).", initialSetpoint, optimalSetpoint, alignedRangeActions.stream().map(Identifiable::getId).collect(Collectors.joining(", ")), toBeShiftedCnec.getId(), side, initialMargin);
automatonRangeActionOptimizationSensitivityAnalysisOutput = preAutoPerimeterSensitivityAnalysis.runBasedOnInitialResults(network, crac, initialFlowResult, prePerimeterRangeActionSetpointResult, operatorsNotSharingCras, null);
RaoLogger.logMostLimitingElementsResults(TECHNICAL_LOGS, automatonRangeActionOptimizationSensitivityAnalysisOutput, raoParameters.getObjectiveFunction(), numberLoggedElementsDuringRao);
RaoLogger.logMostLimitingElementsResults(TECHNICAL_LOGS, automatonRangeActionOptimizationSensitivityAnalysisOutput, Set.of(automatonState), raoParameters.getObjectiveFunction(), numberLoggedElementsDuringRao);
flowCnecsWithNegativeMargin = getCnecsWithNegativeMarginWithoutExcludedCnecs(flowCnecs, flowCnecsToBeExcluded, automatonRangeActionOptimizationSensitivityAnalysisOutput);

iteration++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ public CompletableFuture<RaoResult> run() {

// compute initial sensitivity on CNECs of the only optimized state
PrePerimeterSensitivityAnalysis prePerimeterSensitivityAnalysis = new PrePerimeterSensitivityAnalysis(
raoInput.getCrac().getFlowCnecs(raoInput.getOptimizedState()),
raoInput.getCrac().getRangeActions(raoInput.getOptimizedState(), UsageMethod.AVAILABLE, UsageMethod.TO_BE_EVALUATED),
raoParameters,
toolProvider);
raoInput.getCrac().getFlowCnecs(raoInput.getOptimizedState()),
raoInput.getCrac().getRangeActions(raoInput.getOptimizedState(), UsageMethod.AVAILABLE, UsageMethod.TO_BE_EVALUATED),
raoParameters,
toolProvider);

PrePerimeterResult initialResults;
try {
Expand Down
Loading