Skip to content

Commit ae235c9

Browse files
committed
test dc hot start
Signed-off-by: Gautier Bureau <gautier.bureau@rte-france.com>
1 parent 8496811 commit ae235c9

9 files changed

Lines changed: 111 additions & 11 deletions

File tree

src/main/java/com/powsybl/openloadflow/dc/DcLoadFlowEngine.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
import com.powsybl.loadflow.LoadFlowParameters;
1313
import com.powsybl.math.matrix.MatrixException;
1414
import com.powsybl.openloadflow.OpenLoadFlowParameters;
15+
import com.powsybl.openloadflow.dc.equations.DcApproximationType;
1516
import com.powsybl.openloadflow.dc.equations.DcEquationType;
1617
import com.powsybl.openloadflow.dc.equations.DcVariableType;
1718
import com.powsybl.openloadflow.equations.*;
1819
import com.powsybl.openloadflow.lf.LoadFlowEngine;
1920
import com.powsybl.openloadflow.lf.outerloop.OuterLoopResult;
2021
import com.powsybl.openloadflow.lf.outerloop.OuterLoopStatus;
21-
import com.powsybl.openloadflow.network.LfBus;
22-
import com.powsybl.openloadflow.network.LfGenerator;
23-
import com.powsybl.openloadflow.network.LfNetwork;
24-
import com.powsybl.openloadflow.network.LfNetworkLoader;
22+
import com.powsybl.openloadflow.network.*;
23+
import com.powsybl.openloadflow.network.impl.LfBranchImpl;
24+
import com.powsybl.openloadflow.network.impl.LfBusImpl;
2525
import com.powsybl.openloadflow.network.util.ActivePowerDistribution;
2626
import com.powsybl.openloadflow.network.util.UniformValueVoltageInitializer;
2727
import com.powsybl.openloadflow.network.util.VoltageInitializer;
@@ -200,6 +200,32 @@ public DcLoadFlowResult run() {
200200

201201
initStateVector(network, equationSystem, new UniformValueVoltageInitializer());
202202

203+
if (context.getParameters().getEquationSystemCreationParameters().getDcApproximationType() == DcApproximationType.HOT_START) {
204+
double totalLoss = 0.;
205+
for (LfBranch branch : network.getBranches()) {
206+
LfBranchImpl lfbranch = (LfBranchImpl) branch;
207+
double p1 = lfbranch.getBranch().getTerminal1().getP();
208+
double p2 = lfbranch.getBranch().getTerminal2().getP();
209+
double loss = (p1 + p2) / PerUnit.SB;
210+
totalLoss += loss;
211+
System.out.println("Loss " + lfbranch.getId() + ": " + loss);
212+
LfBusImpl lfbus1 = (LfBusImpl) lfbranch.getBus1();
213+
lfbus1.addLossInjectionTargetP(loss / 2.);
214+
LfBusImpl lfbus2 = (LfBusImpl) lfbranch.getBus2();
215+
lfbus2.addLossInjectionTargetP(loss / 2);
216+
}
217+
218+
for (LfHvdc hvdc : network.getHvdcs()) {
219+
double loss = (hvdc.getP10() + hvdc.getP20()) / PerUnit.SB;
220+
System.out.println("Loss " + hvdc.getId() + ": " + loss);
221+
totalLoss += loss;
222+
hvdc.getConverterStation1().getBus().addLossInjectionTargetP(loss / 2.);
223+
hvdc.getConverterStation2().getBus().addLossInjectionTargetP(loss / 2.);
224+
}
225+
226+
System.out.println("Total Loss " + totalLoss);
227+
}
228+
203229
double initialSlackBusActivePowerMismatch = getActivePowerMismatch(network.getBuses());
204230
double distributedActivePower = 0.0;
205231

src/main/java/com/powsybl/openloadflow/dc/equations/AbstractClosedBranchDcFlowEquationTerm.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
import com.powsybl.openloadflow.network.LfBus;
1717
import com.powsybl.openloadflow.network.PiModel;
1818
import com.powsybl.openloadflow.network.PiModelArray;
19+
import com.powsybl.openloadflow.util.PerUnit;
1920

2021
import java.util.List;
2122
import java.util.Objects;
2223

24+
import static com.powsybl.openloadflow.dc.equations.DcApproximationType.HOT_START;
2325
import static com.powsybl.openloadflow.network.PiModel.R2;
2426

2527
/**
@@ -56,7 +58,19 @@ protected AbstractClosedBranchDcFlowEquationTerm(LfBranch branch, LfBus bus1, Lf
5658
this.useTransformerRatio = useTransformerRatio;
5759
this.dcApproximationType = dcApproximationType;
5860
isPowerPreComputed = !(piModel instanceof PiModelArray);
59-
power = isPowerPreComputed ? computePower(useTransformerRatio, dcApproximationType, piModel) : Double.NaN;
61+
double zb = bus1.getNominalV() * bus2.getNominalV() / PerUnit.SB;
62+
double v1 = bus1.getV();
63+
double v2 = bus2.getV();
64+
double angle1 = bus1.getAngle();
65+
double angle2 = bus2.getAngle();
66+
double deltaTheta = angle1 - angle2;
67+
double angular;
68+
if (deltaTheta == 0.) {
69+
angular = 1.;
70+
} else {
71+
angular = Math.sin(deltaTheta) / deltaTheta;
72+
}
73+
power = isPowerPreComputed ? computePower(useTransformerRatio, dcApproximationType, piModel, v1, v2, angular, zb) : Double.NaN;
6074
if (a1Var != null) {
6175
variables = List.of(ph1Var, ph2Var, a1Var);
6276
} else {
@@ -68,17 +82,24 @@ protected AbstractClosedBranchDcFlowEquationTerm(LfBranch branch, LfBus bus1, Lf
6882
* Update power only if the branch is a PiModelArray.
6983
*/
7084
protected double getPower() {
71-
return isPowerPreComputed ? power : computePower(useTransformerRatio, dcApproximationType, element.getPiModel());
85+
return isPowerPreComputed ? power : computePower(useTransformerRatio, dcApproximationType, element.getPiModel(), 1., 1., 1., 1.);
7286
}
7387

74-
public static double computePower(boolean useTransformerRatio, DcApproximationType dcApproximationType, PiModel piModel) {
88+
public static double computePower(boolean useTransformerRatio, DcApproximationType dcApproximationType, PiModel piModel, double v1, double v2, double angular, double zb) {
7589
double b = switch (dcApproximationType) {
7690
case IGNORE_R -> 1d / piModel.getX();
7791
case IGNORE_G -> {
7892
double r = piModel.getR();
7993
double x = piModel.getX();
8094
yield x / (r * r + x * x);
8195
}
96+
case HOT_START -> {
97+
double r = piModel.getR() * zb;
98+
double x = piModel.getX() * zb;
99+
double susceptance = -x / (r * r + x * x);
100+
double admittance = -v1 * v2 * susceptance * angular;
101+
yield admittance * zb;
102+
}
82103
};
83104
return b * (useTransformerRatio ? piModel.getR1() * R2 : 1);
84105
}

src/main/java/com/powsybl/openloadflow/dc/equations/DcApproximationType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
*/
1313
public enum DcApproximationType {
1414
IGNORE_R,
15-
IGNORE_G
15+
IGNORE_G,
16+
HOT_START
1617
}

src/main/java/com/powsybl/openloadflow/dc/fastdc/WoodburyEngine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ private double calculatePower(LfBranch lfBranch) {
151151
}
152152

153153
private double calculatePower(PiModel piModel) {
154-
return AbstractClosedBranchDcFlowEquationTerm.computePower(creationParameters.isUseTransformerRatio(), creationParameters.getDcApproximationType(), piModel);
154+
return AbstractClosedBranchDcFlowEquationTerm.computePower(creationParameters.isUseTransformerRatio(), creationParameters.getDcApproximationType(), piModel, 1, 1, 1, 1);
155155
}
156156

157157
/**

src/main/java/com/powsybl/openloadflow/network/LfBus.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ public boolean isMaxLimit() {
121121
*/
122122
double getFictitiousInjectionTargetQ();
123123

124+
/**
125+
* Returns the part of getLoadTargetP that does not come from a load but from the loss bus injection
126+
*/
127+
double getLossInjectionTargetP();
128+
124129
void invalidateLoadTargetP();
125130

126131
double getLoadTargetP();
@@ -263,4 +268,6 @@ default Optional<Country> getCountry() {
263268
void setArea(LfArea area);
264269

265270
ViolationLocation getViolationLocation();
271+
272+
void addLossInjectionTargetP(double lossInjectionTargetP);
266273
}

src/main/java/com/powsybl/openloadflow/network/LfHvdc.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
package com.powsybl.openloadflow.network;
99

10+
import com.powsybl.iidm.network.HvdcLine;
1011
import com.powsybl.openloadflow.util.Evaluable;
1112

1213
/**
@@ -62,4 +63,10 @@ public interface LfHvdc extends LfElement {
6263

6364
void setAngleDifferenceToFreeze(double angleToFreeze);
6465

66+
HvdcLine.ConvertersMode getConvertersMode();
67+
68+
double getP10();
69+
70+
double getP20();
71+
6572
}

src/main/java/com/powsybl/openloadflow/network/impl/AbstractLfBus.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,15 @@ public abstract class AbstractLfBus extends AbstractElement implements LfBus {
102102

103103
protected boolean forceTargetQInReactiveLimits;
104104

105+
protected double lossInjectionTargetP;
106+
105107
protected AbstractLfBus(LfNetwork network, double v, double angle, LfNetworkParameters parameters) {
106108
super(network);
107109
this.v = v;
108110
this.angle = angle;
109111
this.distributedOnConformLoad = parameters.isDistributedOnConformLoad();
110112
this.forceTargetQInReactiveLimits = parameters.isForceTargetQInReactiveLimits() && parameters.isReactiveLimits();
113+
this.lossInjectionTargetP = 0.;
111114
}
112115

113116
@Override
@@ -477,7 +480,7 @@ public double getLoadTargetP() {
477480
loadTargetP += load.getTargetP() * load.getLoadModel().flatMap(lm -> lm.getExpTermP(0).map(LfLoadModel.ExpTerm::c)).orElse(1d);
478481
}
479482
}
480-
return loadTargetP + getFictitiousInjectionTargetP();
483+
return loadTargetP + getFictitiousInjectionTargetP() + getLossInjectionTargetP();
481484
}
482485

483486
@Override
@@ -929,4 +932,14 @@ public double getFictitiousInjectionTargetQ() {
929932
return 0;
930933
}
931934

935+
@Override
936+
public double getLossInjectionTargetP() {
937+
return this.lossInjectionTargetP;
938+
}
939+
940+
@Override
941+
public void addLossInjectionTargetP(double lossInjectionTargetP) {
942+
this.lossInjectionTargetP += lossInjectionTargetP;
943+
}
944+
932945
}

src/main/java/com/powsybl/openloadflow/network/impl/LfBranchImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public static LfBranchImpl create(Branch<?> branch, LfNetwork network, LfBus bus
188188
return lfBranch;
189189
}
190190

191-
private Branch<?> getBranch() {
191+
public Branch<?> getBranch() {
192192
return branchRef.get();
193193
}
194194

src/main/java/com/powsybl/openloadflow/network/impl/LfHvdcImpl.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ public class LfHvdcImpl extends AbstractElement implements LfHvdc {
5555

5656
private boolean acEmulationFrozen = false;
5757

58+
private HvdcLine.ConvertersMode mode;
59+
60+
private double p10;
61+
62+
private double p20;
63+
5864
public LfHvdcImpl(String id, LfBus bus1, LfBus bus2, LfNetwork network, HvdcLine hvdcLine, boolean acEmulation) {
5965
super(network);
6066
this.id = Objects.requireNonNull(id);
@@ -76,6 +82,9 @@ public LfHvdcImpl(String id, LfBus bus1, LfBus bus2, LfNetwork network, HvdcLine
7682
pMaxFromCS2toCS1 = hvdcLine.getMaxP();
7783
pMaxFromCS1toCS2 = hvdcLine.getMaxP();
7884
}
85+
this.mode = hvdcLine.getConvertersMode();
86+
this.p10 = hvdcLine.getConverterStation1().getTerminal().getP();
87+
this.p20 = hvdcLine.getConverterStation2().getTerminal().getP();
7988
}
8089

8190
@Override
@@ -229,4 +238,20 @@ public double getAngleDifferenceToFreeze() {
229238
public void setAngleDifferenceToFreeze(double frozenP) {
230239
this.angleToFreeze = frozenP;
231240
}
241+
242+
@Override
243+
public HvdcLine.ConvertersMode getConvertersMode() {
244+
return mode;
245+
}
246+
247+
@Override
248+
public double getP10() {
249+
return p10;
250+
}
251+
252+
@Override
253+
public double getP20() {
254+
return p20;
255+
}
256+
232257
}

0 commit comments

Comments
 (0)