Commit 68590573 by dongshufeng

refactor: change pf alg

parent 9205c828
......@@ -7,6 +7,7 @@
#include ../lib/make_jac.txt
#include ../lib/make_sdzip.txt
#include ../lib/make_sbus.txt
#include ../lib/newtonpf.txt
#include ../lib/runpf.txt
return runpf();
\ No newline at end of file
......@@ -53,5 +53,6 @@ fn newtonpf(Ybus, Sbus, V0, ref, pv, pq, mpopt) {
j5 = j4 + 1; j6 = j4 + npq; // j5:j6 - V mag of pq buses
// evaluate F(x0)
mis = V .* conj(Ybus * V) - Sbus(Vm);
mis = V .* cosnj(Ybus * V) - Sbus(Vm);
return V;
}
\ No newline at end of file
......@@ -31,13 +31,20 @@ fn runpf() {
voltage_g = get_multi(V0, gbus_k);
V_init = set(V0, gbus_k, gen_vg ./ abs(voltage_g) .* voltage_g);
// build admittance matrices
Ybus = make_y_bus(baseMVA, bus, branch);
repeat = 1;
while repeat {
qlim = 0;
loop {
// compute bus power injections
Sbus = make_sbus(baseMVA, bus, gen, 1, 1, 1);
repeat = 0;
V = newtonpf(Ybus, Sbus, V_init, ref, pv, pq, [1e-8, 100, 0]);
if ~~is_empty(V) && qlim {
// if V is empty, it means the power flow did not converge
break;
} else {
break;
}
}
return V_init;
return V;
}
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论