Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Caio Luke <caioluke97@gmail.com>
  • Loading branch information
caioluke committed Nov 24, 2023
1 parent 7139686 commit 121c9f8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static com.powsybl.openloadflow.lf.outerloop.IncrementalContextData.getControlledBusesOutOfDeadband;
import static com.powsybl.openloadflow.lf.outerloop.IncrementalContextData.getDiffV;

/**
* @author Anne Tilloy {@literal <anne.tilloy at rte-france.com>}
*/
Expand All @@ -54,10 +57,8 @@ public String getName() {
return NAME;
}

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> getControllerElements(IncrementalContextData contextData) {
return IncrementalContextData.getControllerElements(contextData.getCandidateControlledBuses(), VoltageControl.Type.TRANSFORMER);
}

public static List<LfBranch> getControllerElementsOutOfDeadband(List<LfBus> controlledBusesOutOfDeadband) {
Expand All @@ -67,10 +68,6 @@ public static List<LfBranch> getControllerElementsOutOfDeadband(List<LfBus> cont
.collect(Collectors.toList());
}

public static List<LfBranch> getControllerElements(IncrementalContextData contextData) {
return IncrementalContextData.getControllerElements(contextData.getCandidateControlledBuses(), VoltageControl.Type.TRANSFORMER);
}

@Override
public void initialize(AcOuterLoopContext context) {
var contextData = new IncrementalContextData(context.getNetwork(), VoltageControl.Type.TRANSFORMER);
Expand Down Expand Up @@ -200,27 +197,6 @@ private boolean adjustWithSeveralControllers(List<LfBranch> controllerBranches,
return adjusted.booleanValue();
}

private static double getDiffV(TransformerVoltageControl voltageControl) {
double targetV = voltageControl.getTargetValue();
double v = voltageControl.getControlledBus().getV();
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 @@ -230,7 +206,7 @@ public OuterLoopStatus check(AcOuterLoopContext context, Reporter reporter) {
var contextData = (IncrementalContextData) context.getData();

// filter out buses/branches which are outside their deadbands
List<LfBus> controlledBusesOutsideOfDeadband = getControlledBusesOutOfDeadband(contextData);
List<LfBus> controlledBusesOutsideOfDeadband = getControlledBusesOutOfDeadband(contextData, VoltageControl.Type.TRANSFORMER);
List<LfBranch> controllerBranchesOutsideOfDeadband = getControllerElementsOutOfDeadband(controlledBusesOutsideOfDeadband);

// all branches are within their deadbands
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
*/
package com.powsybl.openloadflow.lf.outerloop;

import com.powsybl.openloadflow.ac.outerloop.IncrementalTransformerVoltageControlOuterLoop;
import com.powsybl.openloadflow.network.*;
import org.apache.commons.lang3.mutable.MutableInt;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.HashMap;
Expand All @@ -21,6 +24,8 @@
*/
public class IncrementalContextData {

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

public static final class ControllerContext {

private final int maxDirectionChange;
Expand Down Expand Up @@ -86,4 +91,36 @@ public static <E extends LfElement> List<E> getControllerElements(List<LfBus> ca
.map(element -> (E) element)
.collect(Collectors.toList());
}

public static List<LfBus> getControlledBusesOutOfDeadband(IncrementalContextData contextData, VoltageControl.Type type) {
return IncrementalContextData.getControlledBuses(contextData.getCandidateControlledBuses(), type).stream()
.filter(bus -> isOutOfDeadband((TransformerVoltageControl) bus.getVoltageControl(type).orElseThrow()))
.collect(Collectors.toList());
}

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;
}

public static double getDiffV(TransformerVoltageControl voltageControl) {
double targetV = voltageControl.getTargetValue();
double v = voltageControl.getControlledBus().getV();
return targetV - v;
}

// TODO fix min deadband
protected static double getHalfTargetDeadband(TransformerVoltageControl voltageControl) {
return voltageControl.getTargetDeadband().orElse(0.1 / voltageControl.getControlledBus().getNominalV()) / 2;
}
}

0 comments on commit 121c9f8

Please sign in to comment.