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

Clean phase control outer loop code #527

Merged
merged 3 commits into from
May 4, 2022
Merged
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 @@ -23,7 +23,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -95,16 +94,15 @@ public OuterLoopStatus check(OuterLoopContext context, Reporter reporter) {
}

private OuterLoopStatus firstIteration(OuterLoopContext context) {

List<DiscretePhaseControl> phaseControlsOn = context.getNetwork().getBranches().stream()
.map(branch -> branch.getDiscretePhaseControl().filter(dpc -> branch.isPhaseControlled()))
.filter(Optional::isPresent)
.map(Optional::get)
.filter(dpc -> dpc.getMode() == DiscretePhaseControl.Mode.CONTROLLER || dpc.getMode() == DiscretePhaseControl.Mode.LIMITER)
.filter(LfBranch::isPhaseControlled)
.flatMap(branch -> branch.getDiscretePhaseControl().stream())
.collect(Collectors.toList());

// all branches with active power control are switched off
phaseControlsOn.stream().filter(dpc -> dpc.getMode() == DiscretePhaseControl.Mode.CONTROLLER).forEach(this::switchOffPhaseControl);
phaseControlsOn.stream()
.filter(dpc -> dpc.getMode() == DiscretePhaseControl.Mode.CONTROLLER)
.forEach(this::switchOffPhaseControl);

// if at least one phase shifter has been switched off we need to continue
return phaseControlsOn.isEmpty() ? OuterLoopStatus.STABLE : OuterLoopStatus.UNSTABLE;
Expand All @@ -115,11 +113,10 @@ private OuterLoopStatus nextIteration(OuterLoopContext context) {
// and a current greater than the limit
// phase control consists in increasing or decreasing tap position to limit the current
List<DiscretePhaseControl> unstablePhaseControls = context.getNetwork().getBranches().stream()
.map(branch -> branch.getDiscretePhaseControl().filter(dpc -> branch.isPhaseControlled()))
.filter(Optional::isPresent)
.map(Optional::get)
.filter(dpc -> dpc.getMode() == DiscretePhaseControl.Mode.LIMITER)
.filter(dpc -> changeTapPositions(dpc) == OuterLoopStatus.UNSTABLE)
.filter(LfBranch::isPhaseControlled)
.flatMap(branch -> branch.getDiscretePhaseControl().stream())
.filter(phaseControl -> phaseControl.getMode() == DiscretePhaseControl.Mode.LIMITER)
.filter(this::changeTapPositions)
.collect(Collectors.toList());

return unstablePhaseControls.isEmpty() ? OuterLoopStatus.STABLE : OuterLoopStatus.UNSTABLE;
Expand All @@ -138,21 +135,19 @@ private void switchOffPhaseControl(DiscretePhaseControl phaseControl) {
LOGGER.info("Round phase shift of '{}': {} -> {}", controllerBranch.getId(), a1Value, roundedA1Value);
}

private OuterLoopStatus changeTapPositions(DiscretePhaseControl phaseControl) {
private boolean changeTapPositions(DiscretePhaseControl phaseControl) {
// only local control supported: controlled branch is controller branch.
double currentLimit = phaseControl.getTargetValue();
LfBranch controllerBranch = phaseControl.getController();
PiModel piModel = controllerBranch.getPiModel();
boolean isSensibilityPositive;
boolean success = false;
if (phaseControl.getControlledSide() == DiscretePhaseControl.ControlledSide.ONE && currentLimit < controllerBranch.getI1().eval()) {
isSensibilityPositive = isSensitivityCurrentPerA1Positive(controllerBranch, DiscretePhaseControl.ControlledSide.ONE);
success = isSensibilityPositive ? piModel.updateTapPosition(PiModel.Direction.DECREASE) : piModel.updateTapPosition(PiModel.Direction.INCREASE);
boolean isSensibilityPositive = isSensitivityCurrentPerA1Positive(controllerBranch, DiscretePhaseControl.ControlledSide.ONE);
return isSensibilityPositive ? piModel.updateTapPosition(PiModel.Direction.DECREASE) : piModel.updateTapPosition(PiModel.Direction.INCREASE);
} else if (phaseControl.getControlledSide() == DiscretePhaseControl.ControlledSide.TWO && currentLimit < controllerBranch.getI2().eval()) {
isSensibilityPositive = isSensitivityCurrentPerA1Positive(controllerBranch, DiscretePhaseControl.ControlledSide.TWO);
success = isSensibilityPositive ? piModel.updateTapPosition(PiModel.Direction.DECREASE) : piModel.updateTapPosition(PiModel.Direction.INCREASE);
boolean isSensibilityPositive = isSensitivityCurrentPerA1Positive(controllerBranch, DiscretePhaseControl.ControlledSide.TWO);
return isSensibilityPositive ? piModel.updateTapPosition(PiModel.Direction.DECREASE) : piModel.updateTapPosition(PiModel.Direction.INCREASE);
}
return success ? OuterLoopStatus.UNSTABLE : OuterLoopStatus.STABLE;
return false;
}

boolean isSensitivityCurrentPerA1Positive(LfBranch controllerBranch, DiscretePhaseControl.ControlledSide controlledSide) {
Expand Down