Skip to content

Commit

Permalink
Plausible PMax parameter (#212)
Browse files Browse the repository at this point in the history
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
Co-authored-by: Anne Tilloy <48123713+annetill@users.noreply.github.com>
  • Loading branch information
geofjamg and annetill authored Feb 5, 2021
1 parent 40e39dd commit 8367ba3
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 26 deletions.
15 changes: 15 additions & 0 deletions src/main/java/com/powsybl/openloadflow/OpenLoadFlowParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public enum LowImpedanceBranchMode {

private boolean dcUseTransformerRatio = DC_USE_TRANSFORMER_RATIO_DEFAULT_VALUE;

private double plausibleActivePowerLimit = PLAUSIBLE_ACTIVE_POWER_LIMIT_DEFAULT_VALUE;

@Override
public String getName() {
return "OpenLoadFlowParameters";
Expand Down Expand Up @@ -109,6 +111,18 @@ public OpenLoadFlowParameters setDcUseTransformerRatio(boolean dcUseTransformerR
return this;
}

public double getPlausibleActivePowerLimit() {
return plausibleActivePowerLimit;
}

public OpenLoadFlowParameters setPlausibleActivePowerLimit(double plausibleActivePowerLimit) {
if (plausibleActivePowerLimit <= 0) {
throw new IllegalArgumentException("Invalid plausible active power limit: " + plausibleActivePowerLimit);
}
this.plausibleActivePowerLimit = plausibleActivePowerLimit;
return this;
}

public static OpenLoadFlowParameters load() {
return new OpenLoadFlowConfigLoader().load(PlatformConfig.defaultConfig());
}
Expand All @@ -130,6 +144,7 @@ public OpenLoadFlowParameters load(PlatformConfig platformConfig) {
)
.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))
);
return parameters;
}
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/com/powsybl/openloadflow/OpenLoadFlowProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public static AcLoadFlowParameters createAcParameters(Network network, MatrixFac
LOGGER.info("Direct current: {}", parameters.isDc());
LOGGER.info("Transformer voltage control: {}", parameters.isTransformerVoltageControlOn());
LOGGER.info("Load power factor constant: {}", parametersExt.isLoadPowerFactorConstant());
LOGGER.info("Plausible active power limit: {}", parametersExt.getPlausibleActivePowerLimit());

List<OuterLoop> outerLoops = new ArrayList<>();
if (parameters.isDistributedSlack()) {
Expand All @@ -160,7 +161,8 @@ outerLoops, matrixFactory, getObserver(parametersExt),
parameters.isTransformerVoltageControlOn(),
parametersExt.getLowImpedanceBranchMode() == OpenLoadFlowParameters.LowImpedanceBranchMode.REPLACE_BY_MIN_IMPEDANCE_LINE,
parameters.isTwtSplitShuntAdmittance(),
breakers);
breakers,
parametersExt.getPlausibleActivePowerLimit());
}

private CompletableFuture<LoadFlowResult> runAc(Network network, String workingStateId, LoadFlowParameters parameters, OpenLoadFlowParameters parametersExt) {
Expand Down Expand Up @@ -227,9 +229,16 @@ private CompletableFuture<LoadFlowResult> runDc(Network network, String workingS
network.getVariantManager().setWorkingVariant(workingStateId);

SlackBusSelector slackBusSelector = getSlackBusSelector(network, parameters, parametersExt);

LOGGER.info("Slack bus selector: {}", slackBusSelector.getClass().getSimpleName());
LOGGER.info("Use transformer ratio: {}", parametersExt.isDcUseTransformerRatio());
LOGGER.info("Distributed slack: {}", parameters.isDistributedSlack());
LOGGER.info("Balance type: {}", parameters.getBalanceType());
LOGGER.info("Plausible active power limit: {}", parametersExt.getPlausibleActivePowerLimit());

DcLoadFlowParameters dcParameters = new DcLoadFlowParameters(slackBusSelector, matrixFactory, true,
parametersExt.isDcUseTransformerRatio(), parameters.isDistributedSlack(), parameters.getBalanceType(),
forcePhaseControlOffAndAddAngle1Var);
forcePhaseControlOffAndAddAngle1Var, parametersExt.getPlausibleActivePowerLimit());

DcLoadFlowResult result = new DcLoadFlowEngine(network, dcParameters)
.run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ public class AcLoadFlowParameters {

private final boolean breakers;

private double plausibleActivePowerLimit;

public AcLoadFlowParameters(SlackBusSelector slackBusSelector, VoltageInitializer voltageInitializer,
NewtonRaphsonStoppingCriteria stoppingCriteria, List<OuterLoop> outerLoops,
MatrixFactory matrixFactory, AcLoadFlowObserver observer, boolean voltageRemoteControl,
boolean phaseControl, boolean transformerVoltageControlOn, boolean minImpedance,
boolean twtSplitShuntAdmittance, boolean breakers) {
boolean twtSplitShuntAdmittance, boolean breakers, double plausibleActivePowerLimit) {
this.slackBusSelector = Objects.requireNonNull(slackBusSelector);
this.voltageInitializer = Objects.requireNonNull(voltageInitializer);
this.stoppingCriteria = Objects.requireNonNull(stoppingCriteria);
Expand All @@ -61,6 +63,7 @@ public AcLoadFlowParameters(SlackBusSelector slackBusSelector, VoltageInitialize
this.minImpedance = minImpedance;
this.twtSplitShuntAdmittance = twtSplitShuntAdmittance;
this.breakers = breakers;
this.plausibleActivePowerLimit = plausibleActivePowerLimit;
}

public SlackBusSelector getSlackBusSelector() {
Expand Down Expand Up @@ -114,4 +117,8 @@ public boolean isTwtSplitShuntAdmittance() {
public boolean isBreakers() {
return breakers;
}

public double getPlausibleActivePowerLimit() {
return plausibleActivePowerLimit;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static List<LfNetwork> createNetworks(Object network, AcLoadFlowParameter
parameters.getObserver().beforeNetworksCreation();

List<LfNetwork> networks = LfNetwork.load(network, new LfNetworkParameters(parameters.getSlackBusSelector(), parameters.isVoltageRemoteControl(),
parameters.isMinImpedance(), parameters.isTwtSplitShuntAdmittance(), parameters.isBreakers()));
parameters.isMinImpedance(), parameters.isTwtSplitShuntAdmittance(), parameters.isBreakers(), parameters.getPlausibleActivePowerLimit()));

parameters.getObserver().afterNetworksCreation(networks);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.powsybl.openloadflow.network.LfNetworkParameters;
import com.powsybl.openloadflow.network.util.ActivePowerDistribution;
import com.powsybl.openloadflow.util.Markers;
import com.powsybl.openloadflow.util.ParameterConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -45,11 +46,12 @@ public class DcLoadFlowEngine {

public DcLoadFlowEngine(LfNetwork network, MatrixFactory matrixFactory) {
this.networks = Collections.singletonList(network);
parameters = new DcLoadFlowParameters(new FirstSlackBusSelector(), matrixFactory, false, true, false, LoadFlowParameters.BalanceType.PROPORTIONAL_TO_GENERATION_P_MAX, false);
parameters = new DcLoadFlowParameters(new FirstSlackBusSelector(), matrixFactory, false, true, false, LoadFlowParameters.BalanceType.PROPORTIONAL_TO_GENERATION_P_MAX, false,
ParameterConstants.PLAUSIBLE_ACTIVE_POWER_LIMIT_DEFAULT_VALUE);
}

public DcLoadFlowEngine(Object network, DcLoadFlowParameters parameters) {
this.networks = LfNetwork.load(network, new LfNetworkParameters(parameters.getSlackBusSelector(), false, false, false, false));
this.networks = LfNetwork.load(network, new LfNetworkParameters(parameters.getSlackBusSelector(), false, false, false, false, parameters.getPlausibleActivePowerLimit()));
this.parameters = Objects.requireNonNull(parameters);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@ public class DcLoadFlowParameters {

private final boolean forcePhaseControlOffAndAddAngle1Var;

private final double plausibleActivePowerLimit;

public DcLoadFlowParameters(SlackBusSelector slackBusSelector, MatrixFactory matrixFactory, boolean updateFlows,
boolean useTransformerRatio, boolean distributedSlack, LoadFlowParameters.BalanceType balanceType,
boolean forcePhaseControlOffAndAddAngle1Var) {
boolean forcePhaseControlOffAndAddAngle1Var, double plausibleActivePowerLimit) {
this.slackBusSelector = Objects.requireNonNull(slackBusSelector);
this.matrixFactory = Objects.requireNonNull(matrixFactory);
this.updateFlows = updateFlows;
this.useTransformerRatio = useTransformerRatio;
this.distributedSlack = distributedSlack;
this.balanceType = balanceType;
this.forcePhaseControlOffAndAddAngle1Var = forcePhaseControlOffAndAddAngle1Var;
this.plausibleActivePowerLimit = plausibleActivePowerLimit;
}

public SlackBusSelector getSlackBusSelector() {
Expand Down Expand Up @@ -70,4 +73,8 @@ public boolean isUseTransformerRatio() {
public boolean isForcePhaseControlOffAndAddAngle1Var() {
return forcePhaseControlOffAndAddAngle1Var;
}

public double getPlausibleActivePowerLimit() {
return plausibleActivePowerLimit;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.fasterxml.jackson.core.JsonGenerator;
import com.google.common.base.Stopwatch;
import com.powsybl.commons.PowsyblException;
import com.powsybl.openloadflow.util.ParameterConstants;
import net.jafama.FastMath;
import org.jgrapht.Graph;
import org.jgrapht.graph.Pseudograph;
Expand Down Expand Up @@ -400,7 +401,7 @@ private static void validate(LfNetwork network, boolean minImpedance) {
}

public static List<LfNetwork> load(Object network, SlackBusSelector slackBusSelector) {
return load(network, new LfNetworkParameters(slackBusSelector, false, false, false, false));
return load(network, new LfNetworkParameters(slackBusSelector, false, false, false, false, ParameterConstants.PLAUSIBLE_ACTIVE_POWER_LIMIT_DEFAULT_VALUE));
}

public static List<LfNetwork> load(Object network, LfNetworkParameters parameters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
package com.powsybl.openloadflow.network;

import com.powsybl.openloadflow.util.ParameterConstants;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
Expand All @@ -21,13 +23,23 @@ public class LfNetworkParameters {

private final boolean breakers;

private final double plausibleActivePowerLimit;

public LfNetworkParameters(SlackBusSelector slackBusSelector, boolean generatorVoltageRemoteControl,
boolean minImpedance, boolean twtSplitShuntAdmittance, boolean breakers) {
this(slackBusSelector, generatorVoltageRemoteControl, minImpedance, twtSplitShuntAdmittance, breakers,
ParameterConstants.PLAUSIBLE_ACTIVE_POWER_LIMIT_DEFAULT_VALUE);
}

public LfNetworkParameters(SlackBusSelector slackBusSelector, boolean generatorVoltageRemoteControl,
boolean minImpedance, boolean twtSplitShuntAdmittance, boolean breakers,
double plausibleActivePowerLimit) {
this.slackBusSelector = slackBusSelector;
this.generatorVoltageRemoteControl = generatorVoltageRemoteControl;
this.minImpedance = minImpedance;
this.twtSplitShuntAdmittance = twtSplitShuntAdmittance;
this.breakers = breakers;
this.plausibleActivePowerLimit = plausibleActivePowerLimit;
}

public SlackBusSelector getSlackBusSelector() {
Expand All @@ -49,4 +61,8 @@ public boolean isTwtSplitShuntAdmittance() {
public boolean isBreakers() {
return breakers;
}

public double getPlausibleActivePowerLimit() {
return plausibleActivePowerLimit;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ private PlausibleValues() {

public static final double MIN_REACTIVE_RANGE = 1; // MVar
public static final double MAX_REACTIVE_RANGE = 10000; // MVar
public static final int ACTIVE_POWER_LIMIT = 10000; // MW
public static final double MIN_TARGET_VOLTAGE_PU = 0.8; // pu
public static final double MAX_TARGET_VOLTAGE_PU = 1.2; // pu
}
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ private void add(LfGenerator generator, boolean voltageControl, double targetV,
}
}

void addGenerator(Generator generator, double scaleV, LfNetworkLoadingReport report) {
add(LfGeneratorImpl.create(generator, report), generator.isVoltageRegulatorOn(), generator.getTargetV() * scaleV,
void addGenerator(Generator generator, double scaleV, LfNetworkLoadingReport report, double plausibleActivePowerLimit) {
add(LfGeneratorImpl.create(generator, report, plausibleActivePowerLimit), generator.isVoltageRegulatorOn(), generator.getTargetV() * scaleV,
generator.getTargetQ(), report);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.powsybl.iidm.network.extensions.ActivePowerControl;
import com.powsybl.iidm.network.extensions.CoordinatedReactiveControl;
import com.powsybl.openloadflow.network.PerUnit;
import com.powsybl.openloadflow.network.PlausibleValues;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -36,7 +35,7 @@ public final class LfGeneratorImpl extends AbstractLfGenerator {

private double participationFactor;

private LfGeneratorImpl(Generator generator, LfNetworkLoadingReport report) {
private LfGeneratorImpl(Generator generator, LfNetworkLoadingReport report, double plausibleActivePowerLimit) {
super(generator.getTargetP());
this.generator = generator;
participating = true;
Expand All @@ -62,9 +61,9 @@ private LfGeneratorImpl(Generator generator, LfNetworkLoadingReport report) {
report.generatorsDiscardedFromActivePowerControlBecauseTargetPGreaterThenMaxP++;
participating = false;
}
if (generator.getMaxP() > PlausibleValues.ACTIVE_POWER_LIMIT) {
if (generator.getMaxP() > plausibleActivePowerLimit) {
LOGGER.trace("Discard generator '{}' from active power control because maxP ({}) > {}} MW",
generator.getId(), generator.getMaxP(), PlausibleValues.ACTIVE_POWER_LIMIT);
generator.getId(), generator.getMaxP(), plausibleActivePowerLimit);
report.generatorsDiscardedFromActivePowerControlBecauseMaxPNotPlausible++;
participating = false;
}
Expand All @@ -76,10 +75,10 @@ private LfGeneratorImpl(Generator generator, LfNetworkLoadingReport report) {
}
}

public static LfGeneratorImpl create(Generator generator, LfNetworkLoadingReport report) {
public static LfGeneratorImpl create(Generator generator, LfNetworkLoadingReport report, double plausibleActivePowerLimit) {
Objects.requireNonNull(generator);
Objects.requireNonNull(report);
return new LfGeneratorImpl(generator, report);
return new LfGeneratorImpl(generator, report, plausibleActivePowerLimit);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ private static class LoadingContext {
private final Set<ThreeWindingsTransformer> t3wtSet = new LinkedHashSet<>();
}

private static void createBuses(List<Bus> buses, boolean voltageRemoteControl, boolean breakers, LfNetwork lfNetwork,
private static void createBuses(List<Bus> buses, LfNetworkParameters parameters, LfNetwork lfNetwork,
LoadingContext loadingContext, LfNetworkLoadingReport report) {
Map<LfBusImpl, String> controllerBusToControlledBusId = new LinkedHashMap<>();

for (Bus bus : buses) {
LfBusImpl lfBus = createBus(bus, voltageRemoteControl, breakers, loadingContext, report, controllerBusToControlledBusId);
LfBusImpl lfBus = createBus(bus, parameters, loadingContext, report, controllerBusToControlledBusId);
lfNetwork.addBus(lfBus);
}

Expand All @@ -61,7 +61,7 @@ private static Bus getBus(Terminal terminal, boolean breakers) {
return breakers ? terminal.getBusBreakerView().getBus() : terminal.getBusView().getBus();
}

private static LfBusImpl createBus(Bus bus, boolean voltageRemoteControl, boolean breakers, LoadingContext loadingContext,
private static LfBusImpl createBus(Bus bus, LfNetworkParameters parameters, LoadingContext loadingContext,
LfNetworkLoadingReport report, Map<LfBusImpl, String> controllerBusToControlledBusId) {
LfBusImpl lfBus = LfBusImpl.create(bus);

Expand All @@ -88,15 +88,15 @@ public void visitThreeWindingsTransformer(ThreeWindingsTransformer transformer,

private double checkVoltageRemoteControl(Injection injection, Terminal regulatingTerminal, double previousTargetV) {
double scaleV = 1;
Bus controlledBus = getBus(regulatingTerminal, breakers);
Bus connectedBus = getBus(injection.getTerminal(), breakers);
Bus controlledBus = getBus(regulatingTerminal, parameters.isBreakers());
Bus connectedBus = getBus(injection.getTerminal(), parameters.isBreakers());
if (controlledBus == null || connectedBus == null) {
return scaleV;
}
String controlledBusId = controlledBus.getId();
String connectedBusId = connectedBus.getId();
if (!Objects.equals(controlledBusId, connectedBusId)) {
if (voltageRemoteControl) {
if (parameters.isGeneratorVoltageRemoteControl()) {
// controller to controlled bus link will be set later because controlled bus might not have
// been yet created
controllerBusToControlledBusId.put(lfBus, controlledBusId);
Expand All @@ -115,7 +115,7 @@ private double checkVoltageRemoteControl(Injection injection, Terminal regulatin
@Override
public void visitGenerator(Generator generator) {
double scaleV = checkVoltageRemoteControl(generator, generator.getRegulatingTerminal(), generator.getTargetV());
lfBus.addGenerator(generator, scaleV, report);
lfBus.addGenerator(generator, scaleV, report, parameters.getPlausibleActivePowerLimit());
if (generator.isVoltageRegulatorOn()) {
report.voltageControllerCount++;
}
Expand Down Expand Up @@ -395,7 +395,7 @@ private static LfNetwork create(MutableInt num, List<Bus> buses, List<Switch> sw
LoadingContext loadingContext = new LoadingContext();
LfNetworkLoadingReport report = new LfNetworkLoadingReport();

createBuses(buses, parameters.isGeneratorVoltageRemoteControl(), parameters.isBreakers(), lfNetwork, loadingContext, report);
createBuses(buses, parameters, lfNetwork, loadingContext, report);
createBranches(lfNetwork, loadingContext, report, parameters.isTwtSplitShuntAdmittance(), parameters.isBreakers());
createSwitches(switches, lfNetwork);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,8 @@ public DcSensitivityAnalysis(MatrixFactory matrixFactory) {
protected void setFunctionReferenceOnFactors(List<LfNetwork> lfNetworks, List<LfSensitivityFactor> factors,
LoadFlowParameters lfParameters, OpenLoadFlowParameters lfParametersExt) {
DcLoadFlowParameters dcLoadFlowParameters = new DcLoadFlowParameters(lfParametersExt.getSlackBusSelector(), matrixFactory,
true, lfParametersExt.isDcUseTransformerRatio(), lfParameters.isDistributedSlack(), lfParameters.getBalanceType(), true);
true, lfParametersExt.isDcUseTransformerRatio(), lfParameters.isDistributedSlack(), lfParameters.getBalanceType(), true,
lfParametersExt.getPlausibleActivePowerLimit());
DcLoadFlowResult dcLoadFlowResult = new DcLoadFlowEngine(lfNetworks, dcLoadFlowParameters).run();
for (LfSensitivityFactor factor : factors) {
factor.setFunctionReference(dcLoadFlowResult.getNetwork().getBranchById(factor.getFunctionLfBranchId()).getP1() * PerUnit.SB);
Expand Down
Loading

0 comments on commit 8367ba3

Please sign in to comment.