Commit 7d97f2a0 by dongshufeng

refactor: make y bus work

parent 8f878fae
......@@ -30,28 +30,29 @@ fn make_y_bus(baseMVA, bus, branch) {
Ysh = (slice(bus, [0], [GS-1,GS]) + c(0,1) * slice(bus, [0], [BS-1,BS])) / baseMVA; // vector of shunt admittances
// bus indices
f = slice(branch, [0], F_BUS-1); // list of "from" buses
t = slice(branch, [0], T_BUS-1); // list of "to" buses
f = slice(branch, [0], F_BUS-1) - 1; // list of "from" buses
t = slice(branch, [0], T_BUS-1) - 1; // list of "to" buses
Ybus = [0];
if nb < 300 {
// small case
// build Yf and Yt such that Yf * V is the vector of complex branch currents injected
// at each branch's "from" bus, and Yt is the same for the "to" bus end
i = horzcat(range(1,nl),range(1,nl)); // double set of row indices
i = horzcat(range(1,nl),range(1,nl)) - 1; // double set of row indices
j = range(0,nb - 1);
upper = horzcat(Yff, Yft);
lower = horzcat(Ytf, Ytt);
Yf = sparse(i - 1, horzcat(f, t) - 1, upper, nl, nb);
Yt = sparse(i - 1, horzcat(f, t) - 1, lower, nl, nb);
Yf = sparse(i, horzcat(f, t), upper, nl, nb);
Yt = sparse(i, horzcat(f, t), lower, nl, nb);
// build Ybus
// branch admittances + shunt admittance
Ybus = sparse(horzcat(f,f,t,t) - 1, horzcat(f,t,f,t) - 1, vertcat(upper,lower), nb, nb) +
sparse(range(1,nb) - 1, range(1,nb) - 1, Ysh, nb, nb);
Ybus = sparse(horzcat(f,f,t,t), horzcat(f,t,f,t), vertcat(upper,lower), nb, nb) +
sparse(j, j, Ysh, nb, nb);
} else {
// large case running on MATLAB
// build connection matrices
i = range(1,nl);
j = range(1,nb);
i = range(0,nl-1);
j = range(0,nb-1);
Cf = sparse(i, f, ones(nl, 1), nl, nb); // connection matrix for line & from buses
Ct = sparse(i, t, ones(nl, 1), nl, nb); // connection matrix for line & to buses
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论