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/fix phase control parameter in DC computations #833

Merged
merged 2 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
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 @@ -1276,8 +1276,7 @@ public static DcLoadFlowParameters createDcParameters(LoadFlowParameters paramet

var equationSystemCreationParameters = new DcEquationSystemCreationParameters(true,
forcePhaseControlOffAndAddAngle1Var,
parameters.isDcUseTransformerRatio(),
parameters.isPhaseShifterRegulationOn());
parameters.isDcUseTransformerRatio());

return new DcLoadFlowParameters(networkParameters,
equationSystemCreationParameters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ public void prepare(LfNetwork network) {
// modified by slack distribution, so that AC load flow can restart from original state
List<BusDcState> busStates = distributedSlack ? ElementState.save(network.getBuses(), BusDcState::save) : null;

DcLoadFlowParameters parameters = new DcLoadFlowParameters(networkParameters,
new DcEquationSystemCreationParameters(false, false, useTransformerRatio, false),
LfNetworkParameters networkParametersDcInit = new LfNetworkParameters(networkParameters)
.setPhaseControl(false); // not supported yet.

DcLoadFlowParameters parameters = new DcLoadFlowParameters(networkParametersDcInit,
new DcEquationSystemCreationParameters(false, false, useTransformerRatio),
matrixFactory,
distributedSlack,
balanceType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@ public class DcEquationSystemCreationParameters {

private final boolean useTransformerRatio;

private final boolean phaseShifterRegulationOn;

public DcEquationSystemCreationParameters(boolean updateFlows, boolean forcePhaseControlOffAndAddAngle1Var,
boolean useTransformerRatio, boolean phaseShifterRegulationOn) {
boolean useTransformerRatio) {
this.updateFlows = updateFlows;
this.forcePhaseControlOffAndAddAngle1Var = forcePhaseControlOffAndAddAngle1Var;
this.useTransformerRatio = useTransformerRatio;
this.phaseShifterRegulationOn = phaseShifterRegulationOn;
}

public boolean isUpdateFlows() {
Expand All @@ -43,10 +40,6 @@ public boolean isUseTransformerRatio() {
return useTransformerRatio;
}

public boolean isPhaseShifterRegulationOn() {
return phaseShifterRegulationOn;
}

@Override
public String toString() {
return "DcEquationSystemCreationParameters(" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private static void createImpedantBranch(EquationSystem<DcVariableType, DcEquati
DcEquationSystemCreationParameters creationParameters, LfBranch branch,
LfBus bus1, LfBus bus2) {
if (bus1 != null && bus2 != null) {
boolean deriveA1 = (creationParameters.isForcePhaseControlOffAndAddAngle1Var() || creationParameters.isPhaseShifterRegulationOn()) && branch.hasPhaseControllerCapability();
boolean deriveA1 = isDeriveA1(branch, creationParameters);
ClosedBranchSide1DcFlowEquationTerm p1 = ClosedBranchSide1DcFlowEquationTerm.create(branch, bus1, bus2, equationSystem.getVariableSet(), deriveA1, creationParameters.isUseTransformerRatio());
ClosedBranchSide2DcFlowEquationTerm p2 = ClosedBranchSide2DcFlowEquationTerm.create(branch, bus1, bus2, equationSystem.getVariableSet(), deriveA1, creationParameters.isUseTransformerRatio());
equationSystem.getEquation(bus1.getNum(), DcEquationType.BUS_TARGET_P)
Expand All @@ -107,6 +107,11 @@ private static void createImpedantBranch(EquationSystem<DcVariableType, DcEquati
}
}

protected static boolean isDeriveA1(LfBranch branch, DcEquationSystemCreationParameters creationParameters) {
return branch.isPhaseController()
|| creationParameters.isForcePhaseControlOffAndAddAngle1Var() && branch.hasPhaseControllerCapability() && branch.isConnectedAtBothSides();
}

private void createBranches(EquationSystem<DcVariableType, DcEquationType> equationSystem) {
for (LfBranch branch : network.getBranches()) {
LfBus bus1 = branch.getBus1();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.powsybl.openloadflow.graph.GraphConnectivityFactory;

import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

Expand Down Expand Up @@ -108,6 +109,43 @@ public class LfNetworkParameters {

private boolean asymmetrical = ASYMMETRICAL_DEFAULT_VALUE;

public LfNetworkParameters() {
}

public LfNetworkParameters(LfNetworkParameters other) {
Objects.requireNonNull(other);
this.slackBusSelector = other.slackBusSelector;
this.connectivityFactory = other.connectivityFactory;
this.generatorVoltageRemoteControl = other.generatorVoltageRemoteControl;
this.minImpedance = other.minImpedance;
this.twtSplitShuntAdmittance = other.twtSplitShuntAdmittance;
this.breakers = other.breakers;
this.plausibleActivePowerLimit = other.plausibleActivePowerLimit;
this.computeMainConnectedComponentOnly = other.computeMainConnectedComponentOnly;
this.countriesToBalance = new HashSet<>(other.countriesToBalance);
this.distributedOnConformLoad = other.distributedOnConformLoad;
this.phaseControl = other.phaseControl;
this.transformerVoltageControl = other.transformerVoltageControl;
this.voltagePerReactivePowerControl = other.voltagePerReactivePowerControl;
this.reactivePowerRemoteControl = other.reactivePowerRemoteControl;
this.loadFlowModel = other.loadFlowModel;
this.shuntVoltageControl = other.shuntVoltageControl;
this.reactiveLimits = other.reactiveLimits;
this.hvdcAcEmulation = other.hvdcAcEmulation;
this.minPlausibleTargetVoltage = other.minPlausibleTargetVoltage;
this.maxPlausibleTargetVoltage = other.maxPlausibleTargetVoltage;
this.minNominalVoltageTargetVoltageCheck = other.minNominalVoltageTargetVoltageCheck;
this.loaderPostProcessorSelection = new HashSet<>(other.loaderPostProcessorSelection);
this.reactiveRangeCheckMode = other.reactiveRangeCheckMode;
this.lowImpedanceThreshold = other.lowImpedanceThreshold;
this.svcVoltageMonitoring = other.svcVoltageMonitoring;
this.maxSlackBusCount = other.maxSlackBusCount;
this.debugDir = other.debugDir;
this.secondaryVoltageControl = other.secondaryVoltageControl;
this.cacheEnabled = other.cacheEnabled;
this.asymmetrical = other.asymmetrical;
}

public SlackBusSelector getSlackBusSelector() {
return slackBusSelector;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ private static DcLoadFlowParameters createDcLoadFlowParameters(LfNetworkParamete
LoadFlowParameters lfParameters, OpenLoadFlowParameters parametersExt) {
var equationSystemCreationParameters = new DcEquationSystemCreationParameters(true,
true,
lfParameters.isDcUseTransformerRatio(),
false);
lfParameters.isDcUseTransformerRatio());

return new DcLoadFlowParameters(networkParameters,
equationSystemCreationParameters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void buildDcMatrix() {
List<LfNetwork> lfNetworks = Networks.load(network, new FirstSlackBusSelector());
LfNetwork mainNetwork = lfNetworks.get(0);

DcEquationSystemCreationParameters creationParameters = new DcEquationSystemCreationParameters(true, false, true, false);
DcEquationSystemCreationParameters creationParameters = new DcEquationSystemCreationParameters(true, false, true);
EquationSystem<DcVariableType, DcEquationType> equationSystem = new DcEquationSystemCreator(mainNetwork, creationParameters).create(false);

for (LfBus b : mainNetwork.getBuses()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ void testDisabledNonImpedantBranch() {
.setLoadFlowModel(LoadFlowModel.DC)
.setBreakers(true);
DcLoadFlowParameters dcLoadFlowParameters = new DcLoadFlowParameters(lfNetworkParameters,
new DcEquationSystemCreationParameters(true, false, true, false),
new DcEquationSystemCreationParameters(true, false, true),
new DenseMatrixFactory(),
true,
parameters.getBalanceType(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void writeDcSystemTest() {
List<LfNetwork> lfNetworks = Networks.load(EurostagTutorialExample1Factory.create(), new FirstSlackBusSelector());
LfNetwork network = lfNetworks.get(0);

EquationSystem<DcVariableType, DcEquationType> equationSystem = new DcEquationSystemCreator(network, new DcEquationSystemCreationParameters(true, false, true, false)).create(false);
EquationSystem<DcVariableType, DcEquationType> equationSystem = new DcEquationSystemCreator(network, new DcEquationSystemCreationParameters(true, false, true)).create(false);
String ref = String.join(System.lineSeparator(),
"bus_target_φ0 = φ0",
"bus_target_p1 = dc_p_2(φ0, φ1) + dc_p_1(φ1, φ2) + dc_p_1(φ1, φ2)",
Expand Down