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

Zero impedance flows. Specific solution for open Loadflow #573

Merged
merged 9 commits into from
Jul 18, 2022
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
40 changes: 25 additions & 15 deletions src/main/java/com/powsybl/openloadflow/OpenLoadFlowProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.powsybl.loadflow.LoadFlowProvider;
import com.powsybl.loadflow.LoadFlowResult;
import com.powsybl.loadflow.LoadFlowResultImpl;
import com.powsybl.loadflow.resultscompletion.z0flows.Z0FlowsCompletion;
import com.powsybl.math.matrix.MatrixFactory;
import com.powsybl.math.matrix.SparseMatrixFactory;
import com.powsybl.openloadflow.ac.nr.NewtonRaphsonStatus;
Expand All @@ -33,11 +32,20 @@
import com.powsybl.openloadflow.graph.GraphDecrementalConnectivityFactory;
import com.powsybl.openloadflow.network.LfBranch;
import com.powsybl.openloadflow.network.LfBus;
import com.powsybl.openloadflow.network.LfNetwork;
import com.powsybl.openloadflow.network.impl.LfNetworkLoaderImpl;
import com.powsybl.openloadflow.network.impl.Networks;
import com.powsybl.openloadflow.util.*;
import com.powsybl.openloadflow.network.util.ZeroImpedanceFlows;
import com.powsybl.openloadflow.util.Markers;
import com.powsybl.openloadflow.util.PerUnit;
import com.powsybl.openloadflow.util.PowsyblOpenLoadFlowVersion;
import com.powsybl.openloadflow.util.ProviderConstants;
import com.powsybl.tools.PowsyblCoreVersion;
import net.jafama.FastMath;

import org.jgrapht.Graph;
import org.jgrapht.alg.interfaces.SpanningTreeAlgorithm;
import org.jgrapht.alg.spanning.KruskalMinimumSpanningTree;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -116,8 +124,10 @@ private LoadFlowResult runAc(Network network, LoadFlowParameters parameters, Rep
parameters.isPhaseShifterRegulationOn(),
parameters.isTransformerVoltageControlOn(),
parameters.isDistributedSlack() && parameters.getBalanceType() == LoadFlowParameters.BalanceType.PROPORTIONAL_TO_CONFORM_LOAD,
parameters.isDistributedSlack() && (parameters.getBalanceType() == LoadFlowParameters.BalanceType.PROPORTIONAL_TO_LOAD ||
parameters.getBalanceType() == LoadFlowParameters.BalanceType.PROPORTIONAL_TO_CONFORM_LOAD) && parametersExt.isLoadPowerFactorConstant(), parameters.isDc());
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());
}

LoadFlowResult.ComponentResult.Status status;
Expand All @@ -144,20 +154,17 @@ private LoadFlowResult runAc(Network network, LoadFlowParameters parameters, Rep
result.getDistributedActivePower() * PerUnit.SB));
}

// zero or low impedance branch flows computation
if (ok) {
new Z0FlowsCompletion(network, line -> {
// to be consistent with low impedance criteria used in DcEquationSystem and AcEquationSystem
double nominalV = line.getTerminal1().getVoltageLevel().getNominalV();
double zb = nominalV * nominalV / PerUnit.SB;
double z = FastMath.hypot(line.getR(), line.getX());
return z / zb <= LfBranch.LOW_IMPEDANCE_THRESHOLD;
}).complete();
}

return new LoadFlowResultImpl(ok, Collections.emptyMap(), null, componentResults);
}

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

private LoadFlowResult runDc(Network network, LoadFlowParameters parameters, Reporter reporter) {
OpenLoadFlowParameters parametersExt = OpenLoadFlowParameters.get(parameters);
OpenLoadFlowParameters.logDc(parameters, parametersExt);
Expand Down Expand Up @@ -186,6 +193,9 @@ private LoadFlowResult.ComponentResult processResult(Network network, DcLoadFlow
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);
}

return new LoadFlowResultImpl.ComponentResultImpl(
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/powsybl/openloadflow/network/LfBranch.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ default List<LfLimit> getLimits2(LimitType type) {

void updateState(boolean phaseShifterRegulationOn, boolean isTransformerVoltageControlOn, boolean dc);

void updateFlows(double p1, double q1, double p2, double q2);

boolean isPhaseController();

boolean isPhaseControlled();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2021, RTE (http://www.rte-france.com)
* Copyright (c) 2022, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
Expand All @@ -18,76 +18,81 @@
/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public abstract class AbstractFictitiousLfBranch extends AbstractLfBranch {
public abstract class AbstractImpedantLfBranch extends AbstractLfBranch {

protected Evaluable p = NAN;
protected Evaluable p1 = NAN;

protected Evaluable q = NAN;
protected Evaluable q1 = NAN;

protected Evaluable i = NAN;
protected Evaluable i1 = NAN;

protected AbstractFictitiousLfBranch(LfNetwork network, LfBus bus1, LfBus bus2, PiModel piModel) {
protected Evaluable p2 = NAN;

protected Evaluable q2 = NAN;

protected Evaluable i2 = NAN;

protected AbstractImpedantLfBranch(LfNetwork network, LfBus bus1, LfBus bus2, PiModel piModel) {
super(network, bus1, bus2, piModel);
}

@Override
public void setP1(Evaluable p1) {
this.p = Objects.requireNonNull(p1);
this.p1 = Objects.requireNonNull(p1);
}

@Override
public Evaluable getP1() {
return p;
return p1;
}

@Override
public void setP2(Evaluable p2) {
// nothing to do
this.p2 = Objects.requireNonNull(p2);
}

@Override
public Evaluable getP2() {
return NAN;
return p2;
}

@Override
public void setQ1(Evaluable q1) {
this.q = Objects.requireNonNull(q1);
this.q1 = Objects.requireNonNull(q1);
}

@Override
public Evaluable getQ1() {
return q;
return q1;
}

@Override
public void setQ2(Evaluable q2) {
// nothing to do
this.q2 = Objects.requireNonNull(q2);
}

@Override
public Evaluable getQ2() {
return NAN;
return q2;
}

@Override
public void setI1(Evaluable i1) {
this.i = Objects.requireNonNull(i1);
this.i1 = Objects.requireNonNull(i1);
}

@Override
public Evaluable getI1() {
return i;
return i1;
}

@Override
public void setI2(Evaluable i2) {
// nothing to do
this.i2 = Objects.requireNonNull(i2);
}

@Override
public Evaluable getI2() {
return NAN;
return i2;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.powsybl.commons.PowsyblException;
import com.powsybl.iidm.network.*;
import com.powsybl.openloadflow.network.*;
import com.powsybl.openloadflow.util.Evaluable;
import com.powsybl.openloadflow.util.PerUnit;
import com.powsybl.security.results.BranchResult;
import org.slf4j.Logger;
Expand All @@ -19,29 +18,15 @@
import java.util.List;
import java.util.Objects;

import static com.powsybl.openloadflow.util.EvaluableConstants.NAN;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public class LfBranchImpl extends AbstractLfBranch {
public class LfBranchImpl extends AbstractImpedantLfBranch {

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

private final Branch<?> branch;

private Evaluable p1 = NAN;

private Evaluable p2 = NAN;

private Evaluable q1 = NAN;

private Evaluable q2 = NAN;

private Evaluable i1 = NAN;

private Evaluable i2 = NAN;

protected LfBranchImpl(LfNetwork network, LfBus bus1, LfBus bus2, PiModel piModel, Branch<?> branch) {
super(network, bus1, bus2, piModel);
this.branch = branch;
Expand Down Expand Up @@ -147,66 +132,6 @@ public boolean hasPhaseControlCapability() {
&& ((TwoWindingsTransformer) branch).getPhaseTapChanger() != null;
}

@Override
public void setP1(Evaluable p1) {
this.p1 = Objects.requireNonNull(p1);
}

@Override
public Evaluable getP1() {
return p1;
}

@Override
public void setP2(Evaluable p2) {
this.p2 = Objects.requireNonNull(p2);
}

@Override
public Evaluable getP2() {
return p2;
}

@Override
public void setQ1(Evaluable q1) {
this.q1 = Objects.requireNonNull(q1);
}

@Override
public Evaluable getQ1() {
return q1;
}

@Override
public void setQ2(Evaluable q2) {
this.q2 = Objects.requireNonNull(q2);
}

@Override
public Evaluable getQ2() {
return q2;
}

@Override
public void setI1(Evaluable i1) {
this.i1 = Objects.requireNonNull(i1);
}

@Override
public Evaluable getI1() {
return i1;
}

@Override
public void setI2(Evaluable i2) {
this.i2 = Objects.requireNonNull(i2);
}

@Override
public Evaluable getI2() {
return i2;
}

@Override
public BranchResult createBranchResult(double preContingencyBranchP1, double preContingencyBranchOfContingencyP1, boolean createExtension) {
double flowTransfer = Double.NaN;
Expand Down Expand Up @@ -255,10 +180,7 @@ public List<LfLimit> getLimits2(final LimitType type) {

@Override
public void updateState(boolean phaseShifterRegulationOn, boolean isTransformerVoltageControlOn, boolean dc) {
branch.getTerminal1().setP(p1.eval() * PerUnit.SB);
branch.getTerminal1().setQ(q1.eval() * PerUnit.SB);
branch.getTerminal2().setP(p2.eval() * PerUnit.SB);
branch.getTerminal2().setQ(q2.eval() * PerUnit.SB);
updateFlows(p1.eval(), q1.eval(), p2.eval(), q2.eval());

if (phaseShifterRegulationOn && isPhaseController()) {
// it means there is a regulating phase tap changer located on that branch
Expand All @@ -277,4 +199,12 @@ public void updateState(boolean phaseShifterRegulationOn, boolean isTransformerV
checkTargetDeadband(rtc);
}
}

@Override
public void updateFlows(double p1, double q1, double p2, double q2) {
branch.getTerminal1().setP(p1 * PerUnit.SB)
.setQ(q1 * PerUnit.SB);
branch.getTerminal2().setP(p2 * PerUnit.SB)
.setQ(q2 * PerUnit.SB);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public class LfDanglingLineBranch extends AbstractFictitiousLfBranch {
public class LfDanglingLineBranch extends AbstractImpedantLfBranch {

private final DanglingLine danglingLine;

Expand Down Expand Up @@ -81,12 +81,13 @@ public List<LfLimit> getLimits1(final LimitType type) {

@Override
public void updateState(boolean phaseShifterRegulationOn, boolean isTransformerVoltageControlOn, boolean dc) {
if (this.isZeroImpedanceBranch(dc)) {
danglingLine.getTerminal().setP(-getBus2().getP().eval() * PerUnit.SB);
danglingLine.getTerminal().setQ(-getBus2().getQ().eval() * PerUnit.SB);
} else {
danglingLine.getTerminal().setP(p.eval() * PerUnit.SB);
danglingLine.getTerminal().setQ(q.eval() * PerUnit.SB);
}
updateFlows(p1.eval(), q1.eval(), Double.NaN, Double.NaN);
}

@Override
public void updateFlows(double p1, double q1, double p2, double q2) {
// Network side is always on side 1.
danglingLine.getTerminal().setP(p1 * PerUnit.SB)
.setQ(q1 * PerUnit.SB);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public class LfLegBranch extends AbstractFictitiousLfBranch {
public class LfLegBranch extends AbstractImpedantLfBranch {

private final ThreeWindingsTransformer twt;

Expand Down Expand Up @@ -147,8 +147,7 @@ public List<LfLimit> getLimits1(final LimitType type) {

@Override
public void updateState(boolean phaseShifterRegulationOn, boolean isTransformerVoltageControlOn, boolean dc) {
leg.getTerminal().setP(p.eval() * PerUnit.SB);
leg.getTerminal().setQ(q.eval() * PerUnit.SB);
updateFlows(p1.eval(), q1.eval(), Double.NaN, Double.NaN);

if (phaseShifterRegulationOn && isPhaseController()) {
// it means there is a regulating phase tap changer located on that leg
Expand All @@ -157,7 +156,7 @@ public void updateState(boolean phaseShifterRegulationOn, boolean isTransformerV

if (phaseShifterRegulationOn && isPhaseControlled() && discretePhaseControl.getControlledSide() == DiscretePhaseControl.ControlledSide.ONE) {
// check if the target value deadband is respected
checkTargetDeadband(p.eval());
checkTargetDeadband(p1.eval());
}

if (isTransformerVoltageControlOn && isVoltageController()) { // it means there is a regulating ratio tap changer
Expand All @@ -169,4 +168,11 @@ public void updateState(boolean phaseShifterRegulationOn, boolean isTransformerV
checkTargetDeadband(rtc);
}
}

@Override
public void updateFlows(double p1, double q1, double p2, double q2) {
// Star bus is always on side 2.
leg.getTerminal().setP(p1 * PerUnit.SB)
.setQ(q1 * PerUnit.SB);
}
}
Loading