Skip to content

Commit

Permalink
Report instead of warn the failure of application of an action.
Browse files Browse the repository at this point in the history
Signed-off-by: Bertrand Rix <[email protected]>
  • Loading branch information
obrix committed Jan 27, 2025
1 parent 579f2e9 commit 9eb1169
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package com.powsybl.openloadflow.network.action;

import com.powsybl.action.*;
import com.powsybl.commons.report.ReportNode;
import com.powsybl.iidm.network.Network;
import com.powsybl.openloadflow.graph.GraphConnectivity;
import com.powsybl.openloadflow.network.*;
Expand All @@ -28,6 +29,10 @@ public final class LfActionUtils {

private static final Logger LOGGER = LoggerFactory.getLogger(LfActionUtils.class);

private static final String ACTION_ID = "actionId";

private static final String CONTINGENCY_ID = "contingencyId";

private LfActionUtils() {
}

Expand All @@ -54,27 +59,27 @@ public static LfAction createLfAction(Action action, Network network, boolean br
};
}

public static void applyListOfActions(List<LfAction> actions, LfNetwork network, LfContingency contingency, LfNetworkParameters networkParameters) {
public static void applyListOfActions(List<LfAction> actions, LfNetwork network, LfContingency contingency, LfNetworkParameters networkParameters, ReportNode node) {
Objects.requireNonNull(actions);
Objects.requireNonNull(network);

// first apply action modifying connectivity
List<LfAction> branchActions = actions.stream()
.filter(action -> action instanceof AbstractLfBranchAction<?>)
.toList();
updateConnectivity(branchActions, network, contingency);
updateConnectivity(branchActions, network, contingency, node);

// then process remaining changes of actions
actions.stream()
.filter(action -> !(action instanceof AbstractLfBranchAction<?>))
.forEach(action -> {
if (!action.apply(network, contingency, networkParameters)) {
LOGGER.warn("Action {}: may not have been applied successfully.", action.getId());
reportActionApplicationFailure(action.getId(), contingency.getId(), node);
}
});
}

private static void updateConnectivity(List<LfAction> branchActions, LfNetwork network, LfContingency contingency) {
private static void updateConnectivity(List<LfAction> branchActions, LfNetwork network, LfContingency contingency, ReportNode node) {
GraphConnectivity<LfBus, LfBranch> connectivity = network.getConnectivity();

// re-update connectivity according to post contingency state (revert after LfContingency apply)
Expand All @@ -86,7 +91,7 @@ private static void updateConnectivity(List<LfAction> branchActions, LfNetwork n

branchActions.forEach(action -> {
if (!((AbstractLfBranchAction<?>) action).applyOnConnectivity(network, connectivity)) {
LOGGER.warn("Action {}: may not have been applied successfully.", action.getId());
reportActionApplicationFailure(action.getId(), contingency.getId(), node);
}
});

Expand All @@ -97,4 +102,12 @@ private static void updateConnectivity(List<LfAction> branchActions, LfNetwork n
connectivity.undoTemporaryChanges();
}

private static void reportActionApplicationFailure(String actionId, String contingencyId, ReportNode node) {
node.newReportNode()
.withMessageTemplate("LfActionUtils", "Action '${actionId}': may not have been applied successfully on contingency '${contingencyId}'")
.withUntypedValue(ACTION_ID, actionId)
.withUntypedValue(CONTINGENCY_ID, contingencyId)
.add();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ protected OperatorStrategyResult runActionSimulation(LfNetwork network, C contex
.filter(Objects::nonNull)
.toList();

LfActionUtils.applyListOfActions(operatorStrategyLfActions, network, contingency, networkParameters);
LfActionUtils.applyListOfActions(operatorStrategyLfActions, network, contingency, networkParameters, reportNode);

Stopwatch stopwatch = Stopwatch.createStarted();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private OperatorStrategyResult computeOperatorStrategyResultFromPostContingencyA

// apply modifications to compute results
lfContingency.apply(loadFlowContext.getParameters().getBalanceType());
LfActionUtils.applyListOfActions(operatorStrategyLfActions, lfNetwork, lfContingency, loadFlowContext.getParameters().getNetworkParameters());
LfActionUtils.applyListOfActions(operatorStrategyLfActions, lfNetwork, lfContingency, loadFlowContext.getParameters().getNetworkParameters(), reportNode);

// update network result
var postActionsNetworkResult = new PreContingencyNetworkResult(lfNetwork, monitorIndex, createResultExtension);
Expand Down

0 comments on commit 9eb1169

Please sign in to comment.