Skip to content

Commit

Permalink
Low impedance threshold into OLF parameters (#656)
Browse files Browse the repository at this point in the history
Signed-off-by: cluke <caio.luke@artelys.com>
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@gmail.com>
  • Loading branch information
caioluke authored Nov 29, 2022
1 parent 83e92cd commit ac51bf0
Show file tree
Hide file tree
Showing 24 changed files with 188 additions and 110 deletions.
35 changes: 29 additions & 6 deletions src/main/java/com/powsybl/openloadflow/OpenLoadFlowParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public class OpenLoadFlowParameters extends AbstractExtension<LoadFlowParameters

public static final String REACTIVE_RANGE_CHECK_MODE_NAME = "reactiveRangeCheckMode";

public static final String LOW_IMPEDANCE_THRESHOLD_NAME = "lowImpedanceThreshold";

public static final List<String> SPECIFIC_PARAMETERS_NAMES = List.of(SLACK_BUS_SELECTION_PARAM_NAME,
SLACK_BUSES_IDS_PARAM_NAME,
LOW_IMPEDANCE_BRANCH_MODE_PARAM_NAME,
Expand All @@ -120,7 +122,8 @@ public class OpenLoadFlowParameters extends AbstractExtension<LoadFlowParameters
MAX_PLAUSIBLE_TARGET_VOLTAGE_NAME,
MIN_REALISTIC_VOLTAGE_NAME,
MAX_REALISTIC_VOLTAGE_NAME,
REACTIVE_RANGE_CHECK_MODE_NAME);
REACTIVE_RANGE_CHECK_MODE_NAME,
LOW_IMPEDANCE_THRESHOLD_NAME);

public enum VoltageInitModeOverride {
NONE,
Expand Down Expand Up @@ -181,6 +184,8 @@ public enum LowImpedanceBranchMode {

private double maxRealisticVoltage = NewtonRaphsonParameters.DEFAULT_MAX_REALISTIC_VOLTAGE;

private double lowImpedanceThreshold = LfNetworkParameters.LOW_IMPEDANCE_THRESHOLD_DEFAULT_VALUE;

public enum ReactiveRangeCheckMode {
MIN_MAX,
MAX,
Expand Down Expand Up @@ -382,6 +387,18 @@ public OpenLoadFlowParameters setReactiveRangeCheckMode(ReactiveRangeCheckMode r
return this;
}

public double getLowImpedanceThreshold() {
return lowImpedanceThreshold;
}

public OpenLoadFlowParameters setLowImpedanceThreshold(double lowImpedanceThreshold) {
if (lowImpedanceThreshold <= 0) {
throw new PowsyblException("lowImpedanceThreshold must be greater than 0");
}
this.lowImpedanceThreshold = lowImpedanceThreshold;
return this;
}

public static OpenLoadFlowParameters load() {
return load(PlatformConfig.defaultConfig());
}
Expand Down Expand Up @@ -411,7 +428,8 @@ public static OpenLoadFlowParameters load(PlatformConfig platformConfig) {
.setMaxPlausibleTargetVoltage(config.getDoubleProperty(MAX_PLAUSIBLE_TARGET_VOLTAGE_NAME, LfNetworkParameters.MAX_PLAUSIBLE_TARGET_VOLTAGE_DEFAULT_VALUE))
.setMinRealisticVoltage(config.getDoubleProperty(MIN_REALISTIC_VOLTAGE_NAME, NewtonRaphsonParameters.DEFAULT_MIN_REALISTIC_VOLTAGE))
.setMaxRealisticVoltage(config.getDoubleProperty(MAX_REALISTIC_VOLTAGE_NAME, NewtonRaphsonParameters.DEFAULT_MAX_REALISTIC_VOLTAGE))
.setReactiveRangeCheckMode(config.getEnumProperty(REACTIVE_RANGE_CHECK_MODE_NAME, ReactiveRangeCheckMode.class, LfNetworkParameters.REACTIVE_RANGE_CHECK_MODE_DEFAULT_VALUE)));
.setReactiveRangeCheckMode(config.getEnumProperty(REACTIVE_RANGE_CHECK_MODE_NAME, ReactiveRangeCheckMode.class, LfNetworkParameters.REACTIVE_RANGE_CHECK_MODE_DEFAULT_VALUE))
.setLowImpedanceThreshold(config.getDoubleProperty(LOW_IMPEDANCE_THRESHOLD_NAME, LfNetworkParameters.LOW_IMPEDANCE_THRESHOLD_DEFAULT_VALUE)));
return parameters;
}

Expand Down Expand Up @@ -460,6 +478,8 @@ public OpenLoadFlowParameters update(Map<String, String> properties) {
.ifPresent(prop -> this.setMaxRealisticVoltage(Double.parseDouble(prop)));
Optional.ofNullable(properties.get(REACTIVE_RANGE_CHECK_MODE_NAME))
.ifPresent(prop -> this.setReactiveRangeCheckMode(ReactiveRangeCheckMode.valueOf(prop)));
Optional.ofNullable(properties.get(LOW_IMPEDANCE_THRESHOLD_NAME))
.ifPresent(prop -> this.setLowImpedanceThreshold(Double.parseDouble(prop)));
return this;
}

Expand All @@ -486,6 +506,7 @@ public String toString() {
", minRealisticVoltage=" + minRealisticVoltage +
", maxRealisticVoltage=" + maxRealisticVoltage +
", reactiveRangeCheckMode=" + reactiveRangeCheckMode +
", lowImpedanceThreshold=" + lowImpedanceThreshold +
')';
}

Expand Down Expand Up @@ -573,10 +594,10 @@ static VoltageInitializer getExtendedVoltageInitializer(LoadFlowParameters param
return getVoltageInitializer(parameters, networkParameters, matrixFactory, reporter);

case VOLTAGE_MAGNITUDE:
return new VoltageMagnitudeInitializer(parameters.isTransformerVoltageControlOn(), matrixFactory);
return new VoltageMagnitudeInitializer(parameters.isTransformerVoltageControlOn(), matrixFactory, networkParameters.getLowImpedanceThreshold());

case FULL_VOLTAGE:
return new FullVoltageInitializer(new VoltageMagnitudeInitializer(parameters.isTransformerVoltageControlOn(), matrixFactory),
return new FullVoltageInitializer(new VoltageMagnitudeInitializer(parameters.isTransformerVoltageControlOn(), matrixFactory, networkParameters.getLowImpedanceThreshold()),
new DcValueVoltageInitializer(networkParameters,
parameters.isDistributedSlack(),
parameters.getBalanceType(),
Expand Down Expand Up @@ -613,7 +634,8 @@ static LfNetworkParameters getNetworkParameters(LoadFlowParameters parameters, O
.setHvdcAcEmulation(parameters.isHvdcAcEmulation())
.setMinPlausibleTargetVoltage(parametersExt.getMinPlausibleTargetVoltage())
.setMaxPlausibleTargetVoltage(parametersExt.getMaxPlausibleTargetVoltage())
.setReactiveRangeCheckMode(parametersExt.getReactiveRangeCheckMode());
.setReactiveRangeCheckMode(parametersExt.getReactiveRangeCheckMode())
.setLowImpedanceThreshold(parametersExt.getLowImpedanceThreshold());
}

public static AcLoadFlowParameters createAcParameters(Network network, LoadFlowParameters parameters, OpenLoadFlowParameters parametersExt,
Expand Down Expand Up @@ -696,7 +718,8 @@ public static DcLoadFlowParameters createDcParameters(LoadFlowParameters paramet
.setHvdcAcEmulation(false) // FIXME
.setMinPlausibleTargetVoltage(parametersExt.getMinPlausibleTargetVoltage())
.setMaxPlausibleTargetVoltage(parametersExt.getMaxPlausibleTargetVoltage())
.setReactiveRangeCheckMode(ReactiveRangeCheckMode.MAX); // not useful for DC.
.setReactiveRangeCheckMode(ReactiveRangeCheckMode.MAX) // not useful for DC.
.setLowImpedanceThreshold(parametersExt.getLowImpedanceThreshold());

var equationSystemCreationParameters = new DcEquationSystemCreationParameters(true,
false,
Expand Down
32 changes: 17 additions & 15 deletions src/main/java/com/powsybl/openloadflow/OpenLoadFlowProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.powsybl.openloadflow.network.LfBranch;
import com.powsybl.openloadflow.network.LfBus;
import com.powsybl.openloadflow.network.LfNetwork;
import com.powsybl.openloadflow.network.LfNetworkParameters;
import com.powsybl.openloadflow.network.impl.LfNetworkLoaderImpl;
import com.powsybl.openloadflow.network.impl.Networks;
import com.powsybl.openloadflow.util.*;
Expand Down Expand Up @@ -127,7 +128,7 @@ private LoadFlowResult runAc(Network network, LoadFlowParameters parameters, Rep
parameters.isDistributedSlack() && (parameters.getBalanceType() == LoadFlowParameters.BalanceType.PROPORTIONAL_TO_LOAD || parameters.getBalanceType() == LoadFlowParameters.BalanceType.PROPORTIONAL_TO_CONFORM_LOAD) && parametersExt.isLoadPowerFactorConstant(), parameters.isDc());

// zero or low impedance branch flows computation
computeZeroImpedanceFlows(result.getNetwork(), parameters.isDc());
computeZeroImpedanceFlows(result.getNetwork(), parameters.isDc(), parametersExt.getLowImpedanceThreshold());
}

LoadFlowResult.ComponentResult.Status status;
Expand Down Expand Up @@ -159,11 +160,11 @@ private LoadFlowResult runAc(Network network, LoadFlowParameters parameters, Rep
return new LoadFlowResultImpl(ok, Collections.emptyMap(), null, componentResults);
}

private void computeZeroImpedanceFlows(LfNetwork network, boolean dc) {
Graph<LfBus, LfBranch> zeroImpedanceSubGraph = network.createZeroImpedanceSubGraph(dc);
private void computeZeroImpedanceFlows(LfNetwork network, boolean dc, double lowImpedanceThreshold) {
Graph<LfBus, LfBranch> zeroImpedanceSubGraph = network.createZeroImpedanceSubGraph(dc, lowImpedanceThreshold);
if (!zeroImpedanceSubGraph.vertexSet().isEmpty()) {
SpanningTreeAlgorithm.SpanningTree<LfBranch> spanningTree = new KruskalMinimumSpanningTree<>(zeroImpedanceSubGraph).getSpanningTree();
new ZeroImpedanceFlows(zeroImpedanceSubGraph, spanningTree).compute(dc);
new ZeroImpedanceFlows(zeroImpedanceSubGraph, spanningTree).compute(dc, lowImpedanceThreshold);
}
}

Expand All @@ -178,35 +179,36 @@ private LoadFlowResult runDc(Network network, LoadFlowParameters parameters, Rep

Networks.resetState(network);

List<LoadFlowResult.ComponentResult> componentsResult = results.stream().map(r -> processResult(network, r, parameters)).collect(Collectors.toList());
List<LoadFlowResult.ComponentResult> componentsResult = results.stream().map(r -> processResult(network, r, parameters, dcParameters.getNetworkParameters())).collect(Collectors.toList());
boolean ok = results.stream().anyMatch(r -> r.getStatus() == LoadFlowResult.ComponentResult.Status.CONVERGED);
return new LoadFlowResultImpl(ok, Collections.emptyMap(), null, componentsResult);
}

private LoadFlowResult.ComponentResult processResult(Network network, DcLoadFlowResult pResult, LoadFlowParameters parameters) {
if (pResult.getStatus() == LoadFlowResult.ComponentResult.Status.CONVERGED && parameters.isWriteSlackBus()) {
private LoadFlowResult.ComponentResult processResult(Network network, DcLoadFlowResult result, LoadFlowParameters parameters,
LfNetworkParameters networkParameters) {
if (result.getStatus() == LoadFlowResult.ComponentResult.Status.CONVERGED && parameters.isWriteSlackBus()) {
SlackTerminal.reset(network);
}

if (pResult.getStatus() == LoadFlowResult.ComponentResult.Status.CONVERGED) {
pResult.getNetwork().updateState(false,
if (result.getStatus() == LoadFlowResult.ComponentResult.Status.CONVERGED) {
result.getNetwork().updateState(false,
parameters.isWriteSlackBus(),
parameters.isPhaseShifterRegulationOn(),
parameters.isTransformerVoltageControlOn(),
parameters.isDistributedSlack() && parameters.getBalanceType() == LoadFlowParameters.BalanceType.PROPORTIONAL_TO_CONFORM_LOAD,
false, true);

// zero or low impedance branch flows computation
computeZeroImpedanceFlows(pResult.getNetwork(), true);
computeZeroImpedanceFlows(result.getNetwork(), true, networkParameters.getLowImpedanceThreshold());
}

return new LoadFlowResultImpl.ComponentResultImpl(
pResult.getNetwork().getNumCC(),
pResult.getNetwork().getNumSC(),
pResult.getStatus(),
result.getNetwork().getNumCC(),
result.getNetwork().getNumSC(),
result.getStatus(),
0,
pResult.getNetwork().getSlackBus().getId(),
pResult.getSlackBusActivePowerMismatch() * PerUnit.SB,
result.getNetwork().getSlackBus().getId(),
result.getSlackBusActivePowerMismatch() * PerUnit.SB,
Double.NaN);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class VoltageMagnitudeInitializer implements VoltageInitializer {

private static final Logger LOGGER = LoggerFactory.getLogger(VoltageMagnitudeInitializer.class);

private final double lowImpedanceThreshold;

public enum InitVmEquationType implements Quantity {
BUS_TARGET_V("v", ElementType.BUS),
BUS_ZERO("bus_z", ElementType.BUS);
Expand Down Expand Up @@ -87,7 +89,7 @@ public static final class InitVmBusEquationTerm extends AbstractBusEquationTerm<

private final TDoubleArrayList der;

public InitVmBusEquationTerm(LfBus bus, VariableSet<InitVmVariableType> variableSet) {
public InitVmBusEquationTerm(LfBus bus, VariableSet<InitVmVariableType> variableSet, double lowImpedanceThreshold) {
super(bus);

Map<LfBus, List<LfBranch>> neighbors = bus.findNeighbors();
Expand All @@ -108,7 +110,7 @@ public InitVmBusEquationTerm(LfBus bus, VariableSet<InitVmVariableType> variable
double r = 0;
for (LfBranch neighborBranch : neighborBranches) {
PiModel piModel = neighborBranch.getPiModel();
double x = Math.max(Math.abs(piModel.getX()), LfBranch.LOW_IMPEDANCE_THRESHOLD); // to void issue with negative reactances
double x = Math.max(Math.abs(piModel.getX()), lowImpedanceThreshold); // to avoid issues with negative reactances
b += 1 / x;
r += neighborBranch.getBus1() == bus ? 1 / piModel.getR1() : piModel.getR1();
}
Expand Down Expand Up @@ -157,9 +159,10 @@ protected String getName() {

private final MatrixFactory matrixFactory;

public VoltageMagnitudeInitializer(boolean transformerVoltageControlOn, MatrixFactory matrixFactory) {
public VoltageMagnitudeInitializer(boolean transformerVoltageControlOn, MatrixFactory matrixFactory, double lowImpedanceThreshold) {
this.transformerVoltageControlOn = transformerVoltageControlOn;
this.matrixFactory = Objects.requireNonNull(matrixFactory);
this.lowImpedanceThreshold = lowImpedanceThreshold;
}

private static void initTarget(Equation<InitVmVariableType, InitVmEquationType> equation, LfNetwork network, double[] targets) {
Expand Down Expand Up @@ -202,7 +205,7 @@ public void prepare(LfNetwork network) {
.addTerm(v);
} else {
equationSystem.createEquation(bus.getNum(), InitVmEquationType.BUS_ZERO)
.addTerm(new InitVmBusEquationTerm(bus, equationSystem.getVariableSet()))
.addTerm(new InitVmBusEquationTerm(bus, equationSystem.getVariableSet(), lowImpedanceThreshold))
.addTerm(v.minus());
}
}
Expand Down
Loading

0 comments on commit ac51bf0

Please sign in to comment.