Skip to content

Commit

Permalink
Proposal.
Browse files Browse the repository at this point in the history
Signed-off-by: Anne Tilloy <anne.tilloy@rte-france.com>
  • Loading branch information
annetill committed Nov 24, 2023
1 parent 5e560d0 commit 7139686
Showing 1 changed file with 27 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
package com.powsybl.openloadflow.ac.outerloop;

import com.powsybl.commons.PowsyblException;
import com.powsybl.commons.reporter.Reporter;
import com.powsybl.math.matrix.DenseMatrix;
import com.powsybl.openloadflow.lf.outerloop.IncrementalContextData;
Expand All @@ -28,6 +27,7 @@
import org.slf4j.LoggerFactory;

import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
Expand All @@ -54,30 +54,17 @@ public String getName() {
return NAME;
}

public static List<LfBus> getControlledBusesOutsideOfDeadband(IncrementalContextData contextData) {
List<LfBus> controlledBuses = IncrementalContextData.getControlledBuses(contextData.getCandidateControlledBuses(), VoltageControl.Type.TRANSFORMER);
return controlledBuses.stream().filter(controlledBus -> {
TransformerVoltageControl voltageControl = controlledBus.getTransformerVoltageControl().orElseThrow();
double diffV = getDiffV(voltageControl);
double halfTargetDeadband = getHalfTargetDeadband(voltageControl);
return Math.abs(diffV) > halfTargetDeadband;
}).collect(Collectors.toList());
public static List<LfBus> getControlledBusesOutOfDeadband(IncrementalContextData contextData) {
return IncrementalContextData.getControlledBuses(contextData.getCandidateControlledBuses(), VoltageControl.Type.TRANSFORMER).stream()
.filter(bus -> isOutOfDeadband(bus.getTransformerVoltageControl().orElseThrow()))
.collect(Collectors.toList());
}

public static List<LfBranch> getControllerElementsOutsideOfDeadband(List<LfBus> controlledBusesOutsideOfDeadband) {
List<LfBranch> controllerBranchesOutsideOfDeadband = new ArrayList<>();
controlledBusesOutsideOfDeadband.forEach(controlledBus -> {
TransformerVoltageControl voltageControl = controlledBus.getTransformerVoltageControl().orElseThrow();
double diffV = getDiffV(voltageControl);
double halfTargetDeadband = getHalfTargetDeadband(voltageControl);
List<LfBranch> controllers = voltageControl.getMergedControllerElements().stream()
.filter(b -> !b.isDisabled())
.collect(Collectors.toList());
LOGGER.trace("Controlled bus '{}' ({} controllers) is outside of its deadband (half is {} kV) and could need a voltage adjustment of {} kV",
controlledBus.getId(), controllers.size(), halfTargetDeadband * controlledBus.getNominalV(), diffV * controlledBus.getNominalV());
controllerBranchesOutsideOfDeadband.addAll(controllers);
});
return controllerBranchesOutsideOfDeadband;
public static List<LfBranch> getControllerElementsOutOfDeadband(List<LfBus> controlledBusesOutOfDeadband) {
return controlledBusesOutOfDeadband.stream()
.flatMap(bus -> bus.getTransformerVoltageControl().orElseThrow().getMergedControllerElements().stream())
.filter(Predicate.not(LfBranch::isDisabled))
.collect(Collectors.toList());
}

public static List<LfBranch> getControllerElements(IncrementalContextData contextData) {
Expand Down Expand Up @@ -219,6 +206,21 @@ private static double getDiffV(TransformerVoltageControl voltageControl) {
return targetV - v;
}

private static boolean isOutOfDeadband(TransformerVoltageControl voltageControl) {
double diffV = getDiffV(voltageControl);
double halfTargetDeadband = getHalfTargetDeadband(voltageControl);
boolean outOfDeadband = Math.abs(diffV) > halfTargetDeadband;
if (outOfDeadband) {
List<LfBranch> controllers = voltageControl.getMergedControllerElements().stream()
.filter(b -> !b.isDisabled())
.collect(Collectors.toList());
LOGGER.trace("Controlled bus '{}' ({} controllers) is outside of its deadband (half is {} kV) and could need a voltage adjustment of {} kV",
voltageControl.getControlledBus().getId(), controllers.size(), halfTargetDeadband * voltageControl.getControlledBus().getNominalV(),
diffV * voltageControl.getControlledBus().getNominalV());
}
return outOfDeadband;
}

@Override
public OuterLoopStatus check(AcOuterLoopContext context, Reporter reporter) {
MutableObject<OuterLoopStatus> status = new MutableObject<>(OuterLoopStatus.STABLE);
Expand All @@ -228,8 +230,8 @@ public OuterLoopStatus check(AcOuterLoopContext context, Reporter reporter) {
var contextData = (IncrementalContextData) context.getData();

// filter out buses/branches which are outside their deadbands
List<LfBus> controlledBusesOutsideOfDeadband = getControlledBusesOutsideOfDeadband(contextData);
List<LfBranch> controllerBranchesOutsideOfDeadband = getControllerElementsOutsideOfDeadband(controlledBusesOutsideOfDeadband);
List<LfBus> controlledBusesOutsideOfDeadband = getControlledBusesOutOfDeadband(contextData);
List<LfBranch> controllerBranchesOutsideOfDeadband = getControllerElementsOutOfDeadband(controlledBusesOutsideOfDeadband);

// all branches are within their deadbands
if (controllerBranchesOutsideOfDeadband.isEmpty()) {
Expand All @@ -247,9 +249,6 @@ public OuterLoopStatus check(AcOuterLoopContext context, Reporter reporter) {
TransformerVoltageControl voltageControl = controlledBus.getTransformerVoltageControl().orElseThrow();
double diffV = getDiffV(voltageControl);
double halfTargetDeadband = getHalfTargetDeadband(voltageControl);
if (Math.abs(diffV) <= halfTargetDeadband) { // buses have already been filtered
throw new PowsyblException("Bus should have been outside of deadband");
}
List<LfBranch> controllers = voltageControl.getMergedControllerElements().stream()
.filter(b -> !b.isDisabled())
.collect(Collectors.toList());
Expand Down

0 comments on commit 7139686

Please sign in to comment.