Commit 172a4d27 by dongshufeng

refactor: change sparse funciton logic, add full function to use dense matrix

parent f34c0dac
......@@ -19,7 +19,7 @@ fn bustypes_ref(bus, gen) {
nb = size(bus, 0);
ng = size(gen, 0);
g_i = slice(gen, [0], [GEN_BUS-1,GEN_BUS]) - 1; // generator bus indices
Cg = sparse(g_i, range(0, ng), slice(gen, [0], [GEN_STATUS-1,GEN_STATUS]) > 0, nb, ng); // gen connection matrix
Cg = full(sparse(g_i, range(0, ng), slice(gen, [0], [GEN_STATUS-1,GEN_STATUS]) > 0, nb, ng)); // gen connection matrix
// element i, j is 1 if, generator j at bus i is ON
bus_gen_status = Cg * ones(ng, 1); // number of generators at each bus that are ON
......@@ -37,7 +37,7 @@ fn bustypes_pv(bus, gen) {
nb = size(bus, 0);
ng = size(gen, 0);
g_i = slice(gen, [0], [GEN_BUS-1,GEN_BUS]) - 1; // generator bus indices
Cg = sparse(g_i, range(0, ng), slice(gen, [0], [GEN_STATUS-1,GEN_STATUS]) > 0, nb, ng); // gen connection matrix
Cg = full(sparse(g_i, range(0, ng), slice(gen, [0], [GEN_STATUS-1,GEN_STATUS]) > 0, nb, ng); // gen connection matrix
// element i, j is 1 if, generator j at bus i is ON
bus_gen_status = Cg * ones(ng, 1); // number of generators at each bus that are ON
......@@ -55,7 +55,7 @@ fn bustypes_pq(bus, gen) {
nb = size(bus, 0);
ng = size(gen, 0);
g_i = slice(gen, [0], [GEN_BUS-1,GEN_BUS]) - 1; // generator bus indices
Cg = sparse(g_i, range(0, ng), slice(gen, [0], [GEN_STATUS-1,GEN_STATUS]) > 0, nb, ng); // gen connection matrix
Cg = full(sparse(g_i, range(0, ng), slice(gen, [0], [GEN_STATUS-1,GEN_STATUS]) > 0, nb, ng); // gen connection matrix
// element i, j is 1 if, generator j at bus i is ON
bus_gen_status = Cg * ones(ng, 1); // number of generators at each bus that are ON
......
......@@ -16,7 +16,7 @@ fn ext2int(bus, gen, branch, areas){
// create map of external bus numbers to bus indices
i2e = slice(bus, [0], [BUS_I-1,BUS_I] ); //得到bus矩阵的母线序号所在列
e2i = sparse(range(0,max(i2e))', zeros(max(i2e),1), zeros(max(i2e),1), max(i2e), 1); //创建(原bus矩阵母线最大序号值*1)的e2i全零稀疏矩阵
e2i = full(sparse(range(0,max(i2e))', zeros(max(i2e),1), zeros(max(i2e),1), max(i2e), 1)); //创建(原bus矩阵母线最大序号值*1)的e2i全零稀疏矩阵
index_e2i = i2e - 1; //索引值=母线序号-1
e2i = set(e2i, index_e2i, range(1, size(bus, 0) + 1 )' ); //建立母线序号的映射,对应位置进行从1重新编号
......
......@@ -34,7 +34,7 @@ fn make_sbus(baseMVA, bus, gen) {
on = find(slice(gen, [0], [GEN_STATUS-1, GEN_STATUS]) > 0); // which generators are on?
gbus = get_multi(slice(gen, [0], [GEN_BUS-1, GEN_BUS]), on) - 1; // what buses are they at?
ngon = size(on, 0);
Cg = sparse(gbus, range(0, ngon), 1, nb, ngon);
Cg = full(sparse(gbus, range(0, ngon), 1, nb, ngon));
Gp = slice(gen, [0], [PG-1, PG]);
Gq = slice(gen, [0], [PG-1, PG]);
Sbusg = Cg * (get_multi(Gp, on) + c(0,1) * get_multi(Gq, on)) / baseMVA;
......
......@@ -41,31 +41,31 @@ fn make_y_bus(baseMVA, bus, branch) {
// at each branch's "from" bus, and Yt is the same for the "to" bus end
i = horzcat(range(0, nl),range(0, nl)) - 1; // double set of row indices
j = range(0,nb);
Yf = sparse(i, horzcat(f, t), upper, nl, nb);
Yt = sparse(i, horzcat(f, t), lower, nl, nb);
Yf = full(sparse(i, horzcat(f, t), upper, nl, nb));
Yt = full(sparse(i, horzcat(f, t), lower, nl, nb));
// build Ybus
// branch admittances + shunt admittance
Ybus = sparse(horzcat(f,f,t,t), horzcat(f,t,f,t), vertcat(Yff,Yft,Ytf,Ytt), nb, nb) +
sparse(j, j, Ysh, nb, nb);
Ybus = full(sparse(horzcat(f,f,t,t), horzcat(f,t,f,t), vertcat(Yff,Yft,Ytf,Ytt), nb, nb)) +
full(sparse(j, j, Ysh, nb, nb));
} else {
// large case running on MATLAB
// build connection matrices
i = range(0, nl);
j = range(0, nb);
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
Cf = full(sparse(i, f, ones(nl, 1), nl, nb)); // connection matrix for line & from buses
Ct = full(sparse(i, t, ones(nl, 1), nl, nb)); // connection matrix for line & to buses
// 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
Yf = sparse(i, i, Yff, nl, nl) * Cf + sparse(i, i, Yft, nl, nl) * Ct;
Yt = sparse(i, i, Ytf, nl, nl) * Cf + sparse(i, i, Ytt, nl, nl) * Ct;
Yf = full(sparse(i, i, Yff, nl, nl)) * Cf + full(sparse(i, i, Yft, nl, nl)) * Ct;
Yt = full(sparse(i, i, Ytf, nl, nl)) * Cf + full(sparse(i, i, Ytt, nl, nl)) * Ct;
// build Ybus
// branch admittances + shunt admittance
Ybus = Cf' * Yf + Ct' * Yt +
sparse(j, j, Ysh, nb, nb);
full(sparse(j, j, Ysh, nb, nb));
}
return Ybus;
......
......@@ -6,7 +6,7 @@ fn runpf() {
nb = size(bus, 0);
ng = size(gen, 0);
g_i = slice(gen, [0], [GEN_BUS-1,GEN_BUS]) - 1; // generator bus indices
Cg = sparse(g_i, range(0, ng), slice(gen, [0], [GEN_STATUS-1,GEN_STATUS]) > 0, nb, ng); // gen connection matrix
Cg = full(sparse(g_i, range(0, ng), slice(gen, [0], [GEN_STATUS-1,GEN_STATUS]) > 0, nb, ng)); // gen connection matrix
// element i, j is 1 if, generator j at bus i is ON
bus_gen_status = Cg * ones(ng, 1); // number of generators at each bus that are ON
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论