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

Remove transformer voltage controls when no PV buses at non controlled side #482

Merged
merged 21 commits into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from 12 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 @@ -10,12 +10,16 @@
import com.powsybl.openloadflow.ac.outerloop.OuterLoopContext;
import com.powsybl.openloadflow.ac.outerloop.OuterLoopStatus;
import com.powsybl.openloadflow.network.LfBranch;
import com.powsybl.openloadflow.network.LfBus;
import com.powsybl.openloadflow.network.LfNetwork;
import com.powsybl.openloadflow.network.PiModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

/**
Expand Down Expand Up @@ -47,4 +51,41 @@ protected OuterLoopStatus roundVoltageRatios(OuterLoopContext context) {
}
return status;
}

public static void checkControl(LfNetwork network) {
var connectivity = network.getConnectivity();
Copy link
Contributor

@flo-dup flo-dup May 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if using the EvenShiloachGraphDecrementalConnectivity here is consistent, as the init is costly.

If we launch a security analysis, that's not a question as the init will be reused.

But if we only launch a loadflow, that's not really appropriate, and the naive approach is 4 times faster.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we keep it this way, the performance issue has been fixed by #537. It was because we get the main connected component many times. And EvenShiloach algorithm recomputes the main connected component each time it is asked (it was first implemented for use cases where only the small components were needed).

Copy link
Member

@geofjamg geofjamg May 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if using the EvenShiloachGraphDecrementalConnectivity here is consistent, as the init is costly.

If we launch a security analysis, that's not a question as the init will be reused.

But if we only launch a loadflow, that's not really appropriate, and the naive approach is 4 times faster.

This piece of code is ran both for a simple LF and a SA. We probably should use naive implementation for the LF and EvenShiloach for the SA but in both cases it has to be fast so it's a good thing that you improved performance for EvenShiloach.

I also think that performance issue was more visible for the SA than simple LF.

List<LfBranch> controllerBranches = new ArrayList<>(1);
for (LfBranch branch : network.getBranches()) {
if (!branch.isDisabled() && branch.isVoltageController() && branch.isVoltageControlEnabled()) {
controllerBranches.add(branch);
}
if (branch.isDisabled()) {
// apply contingency (in case we are inside a security analysis)
connectivity.cut(branch);
}
}
for (LfBranch branch : controllerBranches) {
connectivity.cut(branch);
}
for (LfBranch branch : controllerBranches) {
var voltageControl = branch.getVoltageControl().orElseThrow();
var controlledBus = voltageControl.getControlled();
Set<LfBus> componentOnNotControlledSide = null;
if (controlledBus.equals(branch.getBus1())) {
componentOnNotControlledSide = connectivity.getConnectedComponent(branch.getBus2());
} else if (controlledBus.equals(branch.getBus2())) {
componentOnNotControlledSide = connectivity.getConnectedComponent(branch.getBus1());
} else {
// I don't know.
}
if (componentOnNotControlledSide != null) {
Optional<LfBus> generatorControlledBus = componentOnNotControlledSide.stream().filter(LfBus::isVoltageControlled).findAny();
if (!generatorControlledBus.isPresent()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can replace these two lines by if (componentOnNotControlledSide.stream().noneMatch(LfBus::isVoltageControlled)) {

branch.setVoltageControlEnabled(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not forget to restore it in the outer loop cleanup!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is done as the condition is only to have a voltage control, no?

LOGGER.error("Transformer {} with voltage control on is disabled", branch.getId());
}
}
}
connectivity.reset();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public void initialize(OuterLoopContext context) {
for (LfBranch controllerBranch : getControllerBranches(context.getNetwork())) {
controllerBranch.setVoltageControlEnabled(true);
}
checkControl(context.getNetwork());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public OuterLoopStatus check(OuterLoopContext context, Reporter reporter) {
branch.setVoltageControlEnabled(true);
status = OuterLoopStatus.UNSTABLE;
}
checkControl(context.getNetwork());
}

// At second outer loop iteration, the transformers are rounded. The generator voltage controls that were
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.powsybl.math.matrix.DenseMatrix;
import com.powsybl.math.matrix.MatrixFactory;
import com.powsybl.openloadflow.OpenLoadFlowParameters;
import com.powsybl.openloadflow.ac.AbstractTransformerVoltageControlOuterLoop;
import com.powsybl.openloadflow.ac.equations.AcEquationType;
import com.powsybl.openloadflow.ac.equations.AcVariableType;
import com.powsybl.openloadflow.ac.outerloop.AcLoadFlowContext;
Expand Down Expand Up @@ -133,6 +134,7 @@ private void calculatePostContingencySensitivityValues(List<LfSensitivityFactor<
for (LfBranch branch : lfNetwork.getBranches()) {
branch.getVoltageControl().ifPresent(vc -> branch.setVoltageControlEnabled(true));
}
AbstractTransformerVoltageControlOuterLoop.checkControl(lfNetwork);
}

// we make the assumption that we ran a loadflow before, and thus this jacobian is the right one
Expand Down Expand Up @@ -245,6 +247,7 @@ public void analyse(Network network, List<PropagatedContingency> contingencies,
for (LfBranch branch : lfNetwork.getBranches()) {
branch.getVoltageControl().ifPresent(vc -> branch.setVoltageControlEnabled(true));
}
AbstractTransformerVoltageControlOuterLoop.checkControl(lfNetwork);
}

// we make the assumption that we ran a loadflow before, and thus this jacobian is the right one
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void voltageControlT2wtTest3() {
.setTargetV(135.0);

LoadFlowResult result = loadFlowRunner.run(network, parameters);
assertFalse(result.isOk());
assertTrue(result.isOk());

parametersExt.setTransformerVoltageControlMode(OpenLoadFlowParameters.TransformerVoltageControlMode.AFTER_GENERATOR_VOLTAGE_CONTROL);
LoadFlowResult result2 = loadFlowRunner.run(network, parameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,26 @@ void testBusVoltagePerTargetVTwt() {
assertEquals(0.035205d, result.getBusVoltageSensitivityValue("T2wT", "BUS_2"), LoadFlowAssert.DELTA_V);
assertEquals(1d, result.getBusVoltageSensitivityValue("T2wT", "BUS_3"), LoadFlowAssert.DELTA_V);
assertEquals(1.055117d, result.getBusVoltageSensitivityValue("T2wT", "BUS_4"), LoadFlowAssert.DELTA_V);

t2wt.getRatioTapChanger()
.setTargetDeadband(0)
.setRegulating(true)
.setTapPosition(3)
.setRegulationTerminal(t2wt.getTerminal1()) // control will be disabled.
.setTargetV(135.0);

SensitivityAnalysisResult result2 = sensiRunner.run(network, factors, Collections.emptyList(), Collections.emptyList(), sensiParameters);

assertEquals(4, result2.getValues().size());
assertEquals(0d, result2.getBusVoltageSensitivityValue("T2wT", "BUS_1"), LoadFlowAssert.DELTA_V);
assertEquals(0d, result2.getBusVoltageSensitivityValue("T2wT", "BUS_2"), LoadFlowAssert.DELTA_V);
assertEquals(0d, result2.getBusVoltageSensitivityValue("T2wT", "BUS_3"), LoadFlowAssert.DELTA_V);
assertEquals(0d, result2.getBusVoltageSensitivityValue("T2wT", "BUS_4"), LoadFlowAssert.DELTA_V);

assertEquals(135.0, result2.getBusVoltageFunctionReferenceValue("BUS_1"), LoadFlowAssert.DELTA_V);
assertEquals(133.77, result2.getBusVoltageFunctionReferenceValue("BUS_2"), LoadFlowAssert.DELTA_V);
assertEquals(25.88, result2.getBusVoltageFunctionReferenceValue("BUS_3"), LoadFlowAssert.DELTA_V);
assertEquals(25.16, result2.getBusVoltageFunctionReferenceValue("BUS_4"), LoadFlowAssert.DELTA_V);
}

@Test
Expand Down