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

Use new parameters isDcUseTransformerRatio and countriesToBalance #308

Merged
merged 8 commits into from
May 21, 2021
13 changes: 0 additions & 13 deletions src/main/java/com/powsybl/openloadflow/OpenLoadFlowParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ public enum LowImpedanceBranchMode {

private boolean loadPowerFactorConstant = LOAD_POWER_FACTOR_CONSTANT_DEFAULT_VALUE;

private boolean dcUseTransformerRatio = DC_USE_TRANSFORMER_RATIO_DEFAULT_VALUE;

private double plausibleActivePowerLimit = PLAUSIBLE_ACTIVE_POWER_LIMIT_DEFAULT_VALUE;

private boolean addRatioToLinesWithDifferentNominalVoltageAtBothEnds = ADD_RATIO_TO_LINES_WITH_DIFFERENT_NOMINAL_VOLTAGE_AT_BOTH_ENDS_DEFAULT_VALUE;
Expand Down Expand Up @@ -105,15 +103,6 @@ public OpenLoadFlowParameters setLoadPowerFactorConstant(boolean loadPowerFactor
return this;
}

public boolean isDcUseTransformerRatio() {
return dcUseTransformerRatio;
}

public OpenLoadFlowParameters setDcUseTransformerRatio(boolean dcUseTransformerRatio) {
this.dcUseTransformerRatio = dcUseTransformerRatio;
return this;
}

public double getPlausibleActivePowerLimit() {
return plausibleActivePowerLimit;
}
Expand Down Expand Up @@ -157,7 +146,6 @@ public String toString() {
", voltageRemoteControl=" + voltageRemoteControl +
", lowImpedanceBranchMode=" + lowImpedanceBranchMode +
", loadPowerFactorConstant=" + loadPowerFactorConstant +
", dcUseTransformerRatio=" + dcUseTransformerRatio +
", plausibleActivePowerLimit=" + plausibleActivePowerLimit +
", addRatioToLinesWithDifferentNominalVoltageAtBothEnds=" + addRatioToLinesWithDifferentNominalVoltageAtBothEnds +
", slackBusPMaxMismatch=" + slackBusPMaxMismatch +
Expand All @@ -181,7 +169,6 @@ public OpenLoadFlowParameters load(PlatformConfig platformConfig) {
config.getBooleanProperty(THROWS_EXCEPTION_IN_CASE_OF_SLACK_DISTRIBUTION_FAILURE_PARAM_NAME, THROWS_EXCEPTION_IN_CASE_OF_SLACK_DISTRIBUTION_FAILURE_DEFAULT_VALUE)
)
.setLoadPowerFactorConstant(config.getBooleanProperty(LOAD_POWER_FACTOR_CONSTANT_PARAM_NAME, LOAD_POWER_FACTOR_CONSTANT_DEFAULT_VALUE))
.setDcUseTransformerRatio(config.getBooleanProperty(DC_USE_TRANSFORMER_RATIO_PARAM_NAME, DC_USE_TRANSFORMER_RATIO_DEFAULT_VALUE))
.setPlausibleActivePowerLimit(config.getDoubleProperty(PLAUSIBLE_ACTIVE_POWER_LIMIT_PARAM_NAME, PLAUSIBLE_ACTIVE_POWER_LIMIT_DEFAULT_VALUE))
.setAddRatioToLinesWithDifferentNominalVoltageAtBothEnds(config.getBooleanProperty(ADD_RATIO_TO_LINES_WITH_DIFFERENT_NOMINAL_VOLTAGE_AT_BOTH_ENDS_NAME, ADD_RATIO_TO_LINES_WITH_DIFFERENT_NOMINAL_VOLTAGE_AT_BOTH_ENDS_DEFAULT_VALUE))
.setSlackBusPMaxMismatch(config.getDoubleProperty(SLACK_BUS_P_MAX_MISMATCH_NAME, SLACK_BUS_P_MAX_MISMATCH_DEFAULT_VALUE))
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/powsybl/openloadflow/OpenLoadFlowProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ public static AcLoadFlowParameters createAcParameters(Network network, MatrixFac
forceA1Var,
parametersExt.isAddRatioToLinesWithDifferentNominalVoltageAtBothEnds(),
branchesWithCurrent,
parameters.getConnectedComponentMode() == LoadFlowParameters.ConnectedComponentMode.MAIN);
parameters.getConnectedComponentMode() == LoadFlowParameters.ConnectedComponentMode.MAIN,
parameters.getCountriesToBalance());
}

private LoadFlowResult runAc(Network network, LoadFlowParameters parameters, OpenLoadFlowParameters parametersExt, Reporter reporter) {
Expand Down Expand Up @@ -247,7 +248,7 @@ private LoadFlowResult runDc(Network network, LoadFlowParameters parameters, Ope
SlackBusSelector slackBusSelector = getSlackBusSelector(network, parameters, parametersExt);

LOGGER.info("Slack bus selector: {}", slackBusSelector.getClass().getSimpleName());
LOGGER.info("Use transformer ratio: {}", parametersExt.isDcUseTransformerRatio());
LOGGER.info("Use transformer ratio: {}", parameters.isDcUseTransformerRatio());
LOGGER.info("Distributed slack: {}", parameters.isDistributedSlack());
LOGGER.info("Balance type: {}", parameters.getBalanceType());
LOGGER.info("Plausible active power limit: {}", parametersExt.getPlausibleActivePowerLimit());
Expand All @@ -257,14 +258,15 @@ private LoadFlowResult runDc(Network network, LoadFlowParameters parameters, Ope
DcLoadFlowParameters dcParameters = new DcLoadFlowParameters(slackBusSelector,
matrixFactory,
true,
parametersExt.isDcUseTransformerRatio(),
parameters.isDcUseTransformerRatio(),
parameters.isDistributedSlack(),
parameters.getBalanceType(),
forcePhaseControlOffAndAddAngle1Var,
parametersExt.getPlausibleActivePowerLimit(),
parametersExt.isAddRatioToLinesWithDifferentNominalVoltageAtBothEnds(),
true,
parameters.getConnectedComponentMode() == LoadFlowParameters.ConnectedComponentMode.MAIN);
parameters.getConnectedComponentMode() == LoadFlowParameters.ConnectedComponentMode.MAIN,
parameters.getCountriesToBalance());

List<DcLoadFlowResult> results = new DcLoadFlowEngine(network, dcParameters, reporter)
.run(reporter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
*/
package com.powsybl.openloadflow.ac.outerloop;

import com.powsybl.iidm.network.Country;
import com.powsybl.math.matrix.MatrixFactory;
import com.powsybl.openloadflow.ac.nr.NewtonRaphsonStoppingCriteria;
import com.powsybl.openloadflow.equations.VoltageInitializer;
import com.powsybl.openloadflow.network.SlackBusSelector;

import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -52,13 +54,16 @@ public class AcLoadFlowParameters {

private final boolean computeMainConnectedComponentOnly;

private final Set<Country> countriesToBalance;

public AcLoadFlowParameters(SlackBusSelector slackBusSelector, VoltageInitializer voltageInitializer,
NewtonRaphsonStoppingCriteria stoppingCriteria, List<OuterLoop> outerLoops,
MatrixFactory matrixFactory, boolean voltageRemoteControl,
boolean phaseControl, boolean transformerVoltageControlOn, boolean minImpedance,
boolean twtSplitShuntAdmittance, boolean breakers, double plausibleActivePowerLimit,
boolean forceA1Var, boolean addRatioToLinesWithDifferentNominalVoltageAtBothEnds,
Set<String> branchesWithCurrent, boolean computeMainConnectedComponentOnly) {
Set<String> branchesWithCurrent, boolean computeMainConnectedComponentOnly,
Set<Country> countriesToBalance) {
this.slackBusSelector = Objects.requireNonNull(slackBusSelector);
this.voltageInitializer = Objects.requireNonNull(voltageInitializer);
this.stoppingCriteria = Objects.requireNonNull(stoppingCriteria);
Expand All @@ -75,6 +80,7 @@ public AcLoadFlowParameters(SlackBusSelector slackBusSelector, VoltageInitialize
this.addRatioToLinesWithDifferentNominalVoltageAtBothEnds = addRatioToLinesWithDifferentNominalVoltageAtBothEnds;
this.branchesWithCurrent = branchesWithCurrent;
this.computeMainConnectedComponentOnly = computeMainConnectedComponentOnly;
this.countriesToBalance = countriesToBalance;
}

public SlackBusSelector getSlackBusSelector() {
Expand Down Expand Up @@ -145,4 +151,8 @@ public boolean isComputeMainConnectedComponentOnly() {
return computeMainConnectedComponentOnly;
}

public Set<Country> getCountriesToBalance() {
return Collections.unmodifiableSet(countriesToBalance);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -59,7 +56,8 @@ public static List<LfNetwork> createNetworks(Object network, AcLoadFlowParameter
parameters.isBreakers(),
parameters.getPlausibleActivePowerLimit(),
parameters.isAddRatioToLinesWithDifferentNominalVoltageAtBothEnds(),
parameters.isComputeMainConnectedComponentOnly());
parameters.isComputeMainConnectedComponentOnly(),
parameters.getCountriesToBalance());
return LfNetwork.load(network, networkParameters, reporter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public DcLoadFlowEngine(LfNetwork network, MatrixFactory matrixFactory, boolean

public DcLoadFlowEngine(Object network, DcLoadFlowParameters parameters, Reporter reporter) {
LfNetworkParameters lfNetworkParameters = new LfNetworkParameters(parameters.getSlackBusSelector(), false, false, false, false,
parameters.getPlausibleActivePowerLimit(), false, parameters.isComputeMainConnectedComponentOnly());
parameters.getPlausibleActivePowerLimit(), false, parameters.isComputeMainConnectedComponentOnly(), parameters.getCountriesToBalance());
this.networks = LfNetwork.load(network, lfNetworkParameters, reporter);
this.parameters = Objects.requireNonNull(parameters);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
*/
package com.powsybl.openloadflow.dc;

import com.powsybl.iidm.network.Country;
import com.powsybl.loadflow.LoadFlowParameters;
import com.powsybl.math.matrix.MatrixFactory;
import com.powsybl.openloadflow.network.SlackBusSelector;
import com.powsybl.openloadflow.util.ParameterConstants;

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

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
Expand Down Expand Up @@ -40,15 +43,18 @@ public class DcLoadFlowParameters {

private final boolean computeMainConnectedComponentOnly;

private final Set<Country> countriesToBalance;

public DcLoadFlowParameters(SlackBusSelector slackBusSelector, MatrixFactory matrixFactory, boolean setVToNan) {
this(slackBusSelector, matrixFactory, false, true, false, LoadFlowParameters.BalanceType.PROPORTIONAL_TO_GENERATION_P_MAX, false,
ParameterConstants.PLAUSIBLE_ACTIVE_POWER_LIMIT_DEFAULT_VALUE, false, setVToNan, true);
ParameterConstants.PLAUSIBLE_ACTIVE_POWER_LIMIT_DEFAULT_VALUE, false, setVToNan, true, LoadFlowParameters.DEFAULT_COUNTRIES_TO_BALANCE);
}

public DcLoadFlowParameters(SlackBusSelector slackBusSelector, MatrixFactory matrixFactory, boolean updateFlows,
boolean useTransformerRatio, boolean distributedSlack, LoadFlowParameters.BalanceType balanceType,
boolean forcePhaseControlOffAndAddAngle1Var, double plausibleActivePowerLimit,
boolean addRatioToLinesWithDifferentNominalVoltageAtBothEnds, boolean setVToNan, boolean computeMainConnectedComponentOnly) {
boolean addRatioToLinesWithDifferentNominalVoltageAtBothEnds, boolean setVToNan, boolean computeMainConnectedComponentOnly,
Set<Country> countriesToBalance) {
this.slackBusSelector = Objects.requireNonNull(slackBusSelector);
this.matrixFactory = Objects.requireNonNull(matrixFactory);
this.updateFlows = updateFlows;
Expand All @@ -60,6 +66,7 @@ public DcLoadFlowParameters(SlackBusSelector slackBusSelector, MatrixFactory mat
this.addRatioToLinesWithDifferentNominalVoltageAtBothEnds = addRatioToLinesWithDifferentNominalVoltageAtBothEnds;
this.setVToNan = setVToNan;
this.computeMainConnectedComponentOnly = computeMainConnectedComponentOnly;
this.countriesToBalance = countriesToBalance;
}

public SlackBusSelector getSlackBusSelector() {
Expand Down Expand Up @@ -106,4 +113,8 @@ public boolean isComputeMainConnectedComponentOnly() {
return computeMainConnectedComponentOnly;
}

public Set<Country> getCountriesToBalance() {
return Collections.unmodifiableSet(countriesToBalance);
}

}
2 changes: 2 additions & 0 deletions src/main/java/com/powsybl/openloadflow/network/LfBus.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,6 @@ public interface LfBus extends LfElement {
void setQ(Evaluable q);

Evaluable getQ();

boolean isParticipating();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
*/
package com.powsybl.openloadflow.network;

import com.powsybl.iidm.network.Country;
import com.powsybl.openloadflow.util.ParameterConstants;

import java.util.Collections;
import java.util.Set;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
Expand All @@ -29,16 +33,18 @@ public class LfNetworkParameters {

private final boolean computeMainConnectedComponentOnly;

private final Set<Country> countriesToBalance;

public LfNetworkParameters(SlackBusSelector slackBusSelector) {
this(slackBusSelector, false, false, false, false,
ParameterConstants.PLAUSIBLE_ACTIVE_POWER_LIMIT_DEFAULT_VALUE, false,
true);
true, Collections.emptySet());
}

public LfNetworkParameters(SlackBusSelector slackBusSelector, boolean generatorVoltageRemoteControl,
boolean minImpedance, boolean twtSplitShuntAdmittance, boolean breakers,
double plausibleActivePowerLimit, boolean addRatioToLinesWithDifferentNominalVoltageAtBothEnds,
boolean computeMainConnectedComponentOnly) {
boolean computeMainConnectedComponentOnly, Set<Country> countriesToBalance) {
this.slackBusSelector = slackBusSelector;
this.generatorVoltageRemoteControl = generatorVoltageRemoteControl;
this.minImpedance = minImpedance;
Expand All @@ -47,6 +53,7 @@ public LfNetworkParameters(SlackBusSelector slackBusSelector, boolean generatorV
this.plausibleActivePowerLimit = plausibleActivePowerLimit;
this.addRatioToLinesWithDifferentNominalVoltageAtBothEnds = addRatioToLinesWithDifferentNominalVoltageAtBothEnds;
this.computeMainConnectedComponentOnly = computeMainConnectedComponentOnly;
this.countriesToBalance = countriesToBalance;
}

public SlackBusSelector getSlackBusSelector() {
Expand Down Expand Up @@ -80,4 +87,8 @@ public boolean isAddRatioToLinesWithDifferentNominalVoltageAtBothEnds() {
public boolean isComputeMainConnectedComponentOnly() {
return computeMainConnectedComponentOnly;
}

public Set<Country> getCountriesToBalance() {
return Collections.unmodifiableSet(countriesToBalance);
}
}
14 changes: 11 additions & 3 deletions src/main/java/com/powsybl/openloadflow/network/impl/LfBusImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,20 @@ public class LfBusImpl extends AbstractLfBus {

private final double highVoltageLimit;

protected LfBusImpl(Bus bus, LfNetwork network, double v, double angle) {
private final boolean participating;

protected LfBusImpl(Bus bus, LfNetwork network, double v, double angle, boolean participating) {
super(network, v, angle);
this.bus = bus;
nominalV = bus.getVoltageLevel().getNominalV();
lowVoltageLimit = bus.getVoltageLevel().getLowVoltageLimit();
highVoltageLimit = bus.getVoltageLevel().getHighVoltageLimit();
this.participating = participating;
}

public static LfBusImpl create(Bus bus, LfNetwork network) {
public static LfBusImpl create(Bus bus, LfNetwork network, boolean participating) {
Objects.requireNonNull(bus);
return new LfBusImpl(bus, network, bus.getV(), bus.getAngle());
return new LfBusImpl(bus, network, bus.getV(), bus.getAngle(), participating);
}

@Override
Expand Down Expand Up @@ -79,4 +82,9 @@ public void updateState(boolean reactiveLimits, boolean writeSlackBus) {

super.updateState(reactiveLimits, writeSlackBus);
}

@Override
public boolean isParticipating() {
return participating;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,9 @@ public void updateState(boolean reactiveLimits, boolean writeSlackBus) {

super.updateState(reactiveLimits, writeSlackBus);
}

@Override
public boolean isParticipating() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private static Bus getBus(Terminal terminal, boolean breakers) {

private static LfBusImpl createBus(Bus bus, LfNetworkParameters parameters, LfNetwork lfNetwork, LoadingContext loadingContext,
LfNetworkLoadingReport report) {
LfBusImpl lfBus = LfBusImpl.create(bus, lfNetwork);
LfBusImpl lfBus = LfBusImpl.create(bus, lfNetwork, participateToSlackDistribution(parameters, bus));

bus.visitConnectedEquipments(new DefaultTopologyVisitor() {

Expand Down Expand Up @@ -566,4 +566,11 @@ public Optional<List<LfNetwork>> load(Object network, LfNetworkParameters parame

return Optional.empty();
}

static boolean participateToSlackDistribution(LfNetworkParameters parameters, Bus b) {
return parameters.getCountriesToBalance().isEmpty()
|| b.getVoltageLevel().getSubstation().getCountry()
.map(country -> parameters.getCountriesToBalance().contains(country))
.orElse(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,9 @@ public void updateState(boolean reactiveLimits, boolean writeSlackBus) {

super.updateState(reactiveLimits, writeSlackBus);
}

@Override
public boolean isParticipating() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public String getElementType() {
@Override
public List<ParticipatingElement> getParticipatingElements(Collection<LfBus> buses) {
return buses.stream()
.filter(bus -> !(bus.isDisabled() || bus.isFictitious()))
.filter(bus -> bus.isParticipating() && !bus.isDisabled() && !bus.isFictitious())
.flatMap(bus -> bus.getGenerators().stream())
.filter(generator -> generator.isParticipating() && getParticipationFactor(generator) != 0)
.map(generator -> new ParticipatingElement(generator, getParticipationFactor(generator)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public String getElementType() {
@Override
public List<ParticipatingElement> getParticipatingElements(Collection<LfBus> buses) {
return buses.stream()
.filter(bus -> bus.getPositiveLoadCount() > 0 && getVariableLoadTargetP(bus) > 0 && !(bus.isFictitious() || bus.isDisabled()))
.filter(bus -> bus.getPositiveLoadCount() > 0 && getVariableLoadTargetP(bus) > 0 && bus.isParticipating() && !bus.isDisabled() && !bus.isFictitious())
.map(bus -> new ParticipatingElement(bus, getVariableLoadTargetP(bus)))
.collect(Collectors.toList());
}
Expand Down
Loading