Commit bcbcf3c8 by Lian-runzhe

函数多个返回

parent a2639489
......@@ -4,7 +4,7 @@
#include ../lib/idx_brch.txt
#include ../lib/ext2int.txt
i2e = ext2int(bus, gen, branch, areas);
[i2e, bus, gen, branch] = ext2int(bus, gen, branch);
assert_relative_eq(i2e, [
[1],
......@@ -21,4 +21,52 @@ assert_relative_eq(i2e, [
[12],
[13],
[14]
]);
assert_relative_eq(bus, [
[1, 3, 0, 0, 0, 0, 1, 1.06, 0, 0, 1, 1.06, 0.94],
[2, 2, 21.7, 12.7, 0, 0, 1, 1.045, -4.98, 0, 1, 1.06, 0.94],
[3, 2, 94.2, 19, 0, 0, 1, 1.01, -12.72, 0, 1, 1.06, 0.94],
[4, 1, 47.8, -3.9, 0, 0, 1, 1.019, -10.33, 0, 1, 1.06, 0.94],
[5, 1, 7.6, 1.6, 0, 0, 1, 1.02, -8.78, 0, 1, 1.06, 0.94],
[6, 2, 11.2, 7.5, 0, 0, 1, 1.07, -14.22, 0, 1, 1.06, 0.94],
[7, 1, 0, 0, 0, 0, 1, 1.062, -13.37, 0, 1, 1.06, 0.94],
[8, 2, 0, 0, 0, 0, 1, 1.09, -13.36, 0, 1, 1.06, 0.94],
[9, 1, 29.5, 16.6, 0, 19, 1, 1.056, -14.94, 0, 1, 1.06, 0.94],
[10, 1, 9, 5.8, 0, 0, 1, 1.051, -15.1, 0, 1, 1.06, 0.94],
[11, 1, 3.5, 1.8, 0, 0, 1, 1.057, -14.79, 0, 1, 1.06, 0.94],
[12, 1, 6.1, 1.6, 0, 0, 1, 1.055, -15.07, 0, 1, 1.06, 0.94],
[13, 1, 13.5, 5.8, 0, 0, 1, 1.05, -15.16, 0, 1, 1.06, 0.94],
[14, 1, 14.9, 5, 0, 0, 1, 1.036, -16.04, 0, 1, 1.06, 0.94]
]);
assert_relative_eq(gen, [
[1, 232.4, -16.9, 10, 0, 1.06, 100, 1, 332.4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[2, 40, 42.4, 50, -40, 1.045, 100, 1, 140, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[3, 0, 23.4, 40, 0, 1.01, 100, 1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[6, 0, 12.2, 24, -6, 1.07, 100, 1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[8, 0, 17.4, 24, -6, 1.09, 100, 1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
]);
assert_relative_eq(branch, [
[1, 2, 0.01938, 0.05917, 0.0528, 0, 0, 0, 0, 0, 1, -360, 360],
[1, 5, 0.05403, 0.22304, 0.0492, 0, 0, 0, 0, 0, 1, -360, 360],
[2, 3, 0.04699, 0.19797, 0.0438, 0, 0, 0, 0, 0, 1, -360, 360],
[2, 4, 0.05811, 0.17632, 0.034, 0, 0, 0, 0, 0, 1, -360, 360],
[2, 5, 0.05695, 0.17388, 0.0346, 0, 0, 0, 0, 0, 1, -360, 360],
[3, 4, 0.06701, 0.17103, 0.0128, 0, 0, 0, 0, 0, 1, -360, 360],
[4, 5, 0.01335, 0.04211, 0, 0, 0, 0, 0, 0, 1, -360, 360],
[4, 7, 0, 0.20912, 0, 0, 0, 0, 0.978, 0, 1, -360, 360],
[4, 9, 0, 0.55618, 0, 0, 0, 0, 0.969, 0, 1, -360, 360],
[5, 6, 0, 0.25202, 0, 0, 0, 0, 0.932, 0, 1, -360, 360],
[6, 11, 0.09498, 0.1989, 0, 0, 0, 0, 0, 0, 1, -360, 360],
[6, 12, 0.12291, 0.25581, 0, 0, 0, 0, 0, 0, 1, -360, 360],
[6, 13, 0.06615, 0.13027, 0, 0, 0, 0, 0, 0, 1, -360, 360],
[7, 8, 0, 0.17615, 0, 0, 0, 0, 0, 0, 1, -360, 360],
[7, 9, 0, 0.11001, 0, 0, 0, 0, 0, 0, 1, -360, 360],
[9, 10, 0.03181, 0.0845, 0, 0, 0, 0, 0, 0, 1, -360, 360],
[9, 14, 0.12711, 0.27038, 0, 0, 0, 0, 0, 0, 1, -360, 360],
[10, 11, 0.08205, 0.19207, 0, 0, 0, 0, 0, 0, 1, -360, 360],
[12, 13, 0.22092, 0.19988, 0, 0, 0, 0, 0, 0, 1, -360, 360],
[13, 14, 0.17093, 0.34802, 0, 0, 0, 0, 0, 0, 1, -360, 360]
]);
\ No newline at end of file
......@@ -3,7 +3,7 @@
#include ../lib/idx_bus.txt
#include ../lib/make_sdzip.txt
sdzip = make_sdzip(baseMVA, bus, mpopt);
sdzip = make_sdzip(baseMVA, bus);
assert_relative_eq(sdzip, [
[c(0,0), c(0,0), c(0,0)],
......
......@@ -4,7 +4,7 @@
#include ../lib/idx_brch.txt
#include ../lib/make_y_bus.txt
ybus = make_y_bus(baseMVA, bus, branch);
[ybus, yf, yt] = make_y_bus(baseMVA, bus, branch);
assert_relative_eq(ybus, [
[c(6.0250,-19.4471), c(-4.9991,15.2631), c(0,0), c(0,0), c(-1.0259,4.2350), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0) ],
......@@ -21,4 +21,50 @@ assert_relative_eq(ybus, [
[c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(-1.5260,3.1760), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(4.0150,-5.4279), c(-2.4890,2.2520), c(0,0) ],
[c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(-3.0989,6.1028), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(-2.4890,2.2520), c(6.7249,-10.6697), c(-1.1370,2.3150) ],
[c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(-1.4240,3.0291), c(0,0), c(0,0), c(0,0), c(-1.1370,2.3150), c(2.5610,-5.3440) ]
],4);
assert_relative_eq(yf, [
[c(4.9991,-15.2367), c(-4.9991,15.2631), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0)],
[c(1.0259,-4.2103), c(0,0), c(0,0), c(0,0.0), c(-1.0259,4.2350), c(0,0.0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0)],
[c(0,0), c(1.1350,-4.7600), c(-1.1350,4.7819), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0)],
[c(0,0), c(1.6860,-5.0988), c(0,0), c(-1.6860,5.1158), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0)],
[c(0,0), c(1.7011,-5.1766), c(0,0), c(0,0), c(-1.7011,5.1939), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0)],
[c(0,0), c(0,0), c(1.9860,-5.0624), c(-1.9860,5.0688), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0)],
[c(0,0), c(0,0), c(0,0), c(6.8410,-21.5786), c(-6.8410,21.5786), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0)],
[c(0,0), c(0,0), c(0,0), c(0.0,-4.9995), c(0,0), c(0,0), c(-0.0,4.8895), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0)],
[c(0,0), c(0,0), c(0,0), c(0.0,-1.9149), c(0,0), c(0,0), c(0,0), c(0,0), c(-0.0,1.8555), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0)],
[c(0,0), c(0,0), c(0,0), c(0,0), c(0.0,-4.5681), c(-0.0,4.2574), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0)],
[c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(1.9550,-4.0941), c(0,0), c(0,0), c(0,0), c(0,0), c(-1.9550,4.0941), c(0,0), c(0,0), c(0,0)],
[c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(1.5260,-3.1760), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(-1.5260,3.1760), c(0,0), c(0,0)],
[c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(3.0989,-6.1028), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(-3.0989,6.1028), c(0,0)],
[c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0.0,-5.6770), c(-0.0,5.6770), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0)],
[c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0.0,-9.0901), c(0,0), c(-0.0,9.0901), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0)],
[c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(3.9020,-10.3653), c(-3.9020,10.3654), c(0,0), c(0,0), c(0,0), c(0,0)],
[c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(1.4240,-3.0290), c(0,0), c(0,0), c(0,0), c(0,0), c(-1.4240,3.0291)],
[c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(1.8809,-4.4029), c(-1.8809,4.4029), c(0,0), c(0,0), c(0,0)],
[c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(2.4890,-2.2520), c(-2.4890,2.2520), c(0,0)],
[c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(1.1370,-2.3150), c(-1.1370,2.3150)]
],4);
assert_relative_eq(yt, [
[c(-4.9991,15.2631), c(4.9991,-15.2367), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0)],
[c(-1.0259,4.2350), c(0,0), c(0,0), c(0,0), c(1.0259,-4.2104), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0)],
[c(0,0), c(-1.1350,4.7819), c(1.1350,-4.7600), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0)],
[c(0,0), c(-1.6860,5.1158), c(0,0), c(1.6860,-5.0988), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0)],
[c(0,0), c(-1.7011,5.1939), c(0,0), c(0,0), c(1.7011,-5.1766), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0)],
[c(0,0), c(0,0), c(-1.9860,5.0688), c(1.9860,-5.0624), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0)],
[c(0,0), c(0,0), c(0,0), c(-6.8410,21.578553981691588), c(6.8410,-21.5786), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0)],
[c(0,0), c(0,0), c(0,0), c(0.0,4.8895), c(0,0), c(0,0), c(0.0,-4.7819), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0)],
[c(0,0), c(0,0), c(0,0), c(0.0,1.8555), c(0,0), c(0,0), c(0,0), c(0,0), c(0.0,-1.7980), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0)],
[c(0,0), c(0,0), c(0,0), c(0,0), c(0.0,4.2574), c(0.0,-3.9679), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0)],
[c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(-1.9550,4.0940), c(0,0), c(0,0), c(0,0), c(0,0), c(1.9550,-4.0941), c(0,0), c(0,0), c(0,0)],
[c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(-1.5260,3.1760), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(1.5260,-3.1760), c(0,0), c(0,0)],
[c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(-3.0989,6.1028), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(3.0989,-6.1028), c(0,0)],
[c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0.0,5.6770), c(0.0,-5.6770), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0)],
[c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0.0,9.0901), c(0,0), c(0.0,-9.0901), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0)],
[c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(-3.90208,10.3654), c(3.9020,-10.3654), c(0,0), c(0,0), c(0,0), c(0,0)],
[c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(-1.4240,3.0291), c(0,0), c(0,0), c(0,0), c(0,0), c(1.4240,-3.0291)],
[c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(-1.8809,4.4029), c(1.8809,-4.4029), c(0,0), c(0,0), c(0,0)],
[c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(-2.4890,2.2520), c(2.4890,-2.2520), c(0,0)],
[c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(0,0), c(-1.1370,2.3150), c(1.1370,-2.3150)]
],4);
\ No newline at end of file
......@@ -3,8 +3,6 @@
#include ../lib/idx_bus.txt
#include ../lib/idx_brch.txt
#include ../lib/make_y_bus.txt
#include ../lib/make_y_bus_Yf.txt
#include ../lib/make_y_bus_Yt.txt
#include ../lib/dsbus_dv.txt
#include ../lib/make_sdzip.txt
#include ../lib/make_sbus.txt
......@@ -20,17 +18,13 @@ for i in 0..5 {
}
info(`Run power flow on case14 end`);
Ybus = make_y_bus(baseMVA, bus, branch);
Yf = make_y_bus_Yf(baseMVA, bus, branch);
Yt = make_y_bus_Yt(baseMVA, bus, branch);
[Ybus, Yf, Yt] = make_y_bus(baseMVA, bus, branch);
V = r;
bus_type = slice(bus, [0], [BUS_TYPE-1,BUS_TYPE]);
ref = find(bus_type == REF) + 1;
pv = find(bus_type == PV) + 1;
pq = find(bus_type == PQ) + 1;
bus_output = pfsoln(baseMVA, bus, gen, branch, Ybus, Yf, Yt, V, ref, pv, pq, []);
gen_output = pfsoln(baseMVA, bus, gen, branch, Ybus, Yf, Yt, V, ref, pv, pq, []);
branch_output = pfsoln(baseMVA, bus, gen, branch, Ybus, Yf, Yt, V, ref, pv, pq, []);
[bus_output, gen_output, branch_output] = pfsoln(baseMVA, bus, gen, branch, Ybus, Yf, Yt, V, ref, pv, pq, []);
//bus结果
assert_relative_eq(bus_output, [
......@@ -51,16 +45,16 @@ assert_relative_eq(bus_output, [
],4);
//gen结果
/*assert_relative_eq(gen_output, [
assert_relative_eq(gen_output, [
[c(1.0,0.0), c(232.3933,0.0), c(-16.5493,0.0), c(10.0,0.0), c(0.0,0.0), c(1.0600,0.0), c(100.0,0.0), c(1.0,0.0), c(332.4,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0)],
[c(2.0,0.0), c(40.0,0.0), c(43.5571,0.0), c(50.0,0.0), c(-40.0,-0.0), c(1.0450,0.0), c(100.0,0.0), c(1.0,0.0), c(140.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0)],
[c(3.0,0.0), c(0.0,0.0), c(25.0753,0.0), c(40.0,0.0), c(0.0,0.0), c(1.0100,0.0), c(100.0,0.0), c(1.0,0.0), c(100.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0)],
[c(6.0,0.0), c(0.0,0.0), c(12.7309,0.0), c(24.0,0.0), c(-6.0,-0.0), c(1.0700,0.0), c(100.0,0.0), c(1.0,0.0), c(100.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0)],
[c(8.0,0.0), c(0.0,0.0), c(17.6235,0.0), c(24.0,0.0), c(-6.0,-0.0), c(1.0900,0.0), c(100.0,0.0), c(1.0,0.0), c(100.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0), c(0.0,0.0)]
],4);*/
],4);
//branch结果
/*assert_relative_eq(branch_output, [
assert_relative_eq(branch_output, [
[c(1.0, 0.0), c(2.0, 0.0), c(0.0194, 0.0), c(0.0592, 0.0), c(0.0528, 0.0), c(0.0, 0.0), c(0.0, 0.0), c(0.0, 0.0), c(0.0, 0.0), c(0.0, 0.0), c(1.0, 0.0), c(-360.0, -0.0), c(360.0, 0.0), c(156.8829, 0.0), c(-20.4043, 0.0), c(-152.5853, 0.0), c(27.6762, 0.0)],
[c(1.0, 0.0), c(5.0, 0.0), c(0.0540, 0.0), c(0.2230, 0.0), c(0.0492, 0.0), c(0.0, 0.0), c(0.0, 0.0), c(0.0, 0.0), c(0.0, 0.0), c(0.0, 0.0), c(1.0, 0.0), c(-360.0, -0.0), c(360.0, 0.0), c(75.5104, 0.0), c(3.8550, 0.0), c(-72.7475, 0.0), c(2.2294, 0.0)],
[c(2.0, 0.0), c(3.0, 0.0), c(0.0470, 0.0), c(0.1980, 0.0), c(0.0438, 0.0), c(0.0, 0.0), c(0.0, 0.0), c(0.0, 0.0), c(0.0, 0.0), c(0.0, 0.0), c(1.0, 0.0), c(-360.0, -0.0), c(360.0, 0.0), c(73.2376, 0.0), c(3.5602, 0.0), c(-70.9143, 0.0), c(1.6022, 0.0)],
......@@ -81,9 +75,4 @@ assert_relative_eq(bus_output, [
[c(10.0, 0.0), c(11.0, 0.0), c(0.0821, 0.0), c(0.1921, 0.0), c(0.0, 0.0), c(0.0, 0.0), c(0.0, 0.0), c(0.0, 0.0), c(0.0, 0.0), c(0.0, 0.0), c(1.0, 0.0), c(-360.0, -0.0), c(360.0, 0.0), c(-3.7853, 0.0), c(-1.6151, 0.0), c(3.7979, 0.0), c(1.6445, 0.0)],
[c(12.0, 0.0), c(13.0, 0.0), c(0.2209, 0.0), c(0.1999, 0.0), c(0.0, 0.0), c(0.0, 0.0), c(0.0, 0.0), c(0.0, 0.0), c(0.0, 0.0), c(0.0, 0.0), c(1.0, 0.0), c(-360.0, -0.0), c(360.0, 0.0), c(1.6143, 0.0), c(0.7540, 0.0), c(-1.6080, 0.0), c(-0.7483, 0.0)],
[c(13.0, 0.0), c(14.0, 0.0), c(0.1709, 0.0), c(0.3480, 0.0), c(0.0, 0.0), c(0.0, 0.0), c(0.0, 0.0), c(0.0, 0.0), c(0.0, 0.0), c(0.0, 0.0), c(1.0, 0.0), c(-360.0, -0.0), c(360.0, 0.0), c(5.6439, 0.0), c(1.7472, 0.0), c(-5.5898, 0.0), c(-1.6371, 0.0)]
],4);*/
//return bus_output;
//return gen_output;
//return branch_output;
\ No newline at end of file
],4);
......@@ -3,8 +3,6 @@
#include ../lib/idx_bus.txt
#include ../lib/idx_brch.txt
#include ../lib/make_y_bus.txt
#include ../lib/make_y_bus_Yf.txt
#include ../lib/make_y_bus_Yt.txt
#include ../lib/dsbus_dv.txt
#include ../lib/make_sdzip.txt
#include ../lib/make_sbus.txt
......
......@@ -37,7 +37,5 @@ fn ext2int(bus, gen, branch, areas){
e2i_tbus = get_multi(e2i, index_e2i_tbus )';
output_branch2 = assign(output_branch1, e2i_tbus, [0], [T_BUS-1, T_BUS] );
//return i2e, bus, gen, branch, areas;
//return output_branch2;
return i2e;
return(i2e, bus, gen, branch);
}
fn make_jac(baseMVA, bus, branch, gen, fullJac) {
// build Ybus
Ybus = make_y_bus(baseMVA, bus, branch);
[Ybus, _, _] = make_y_bus(baseMVA, bus, branch);
// extract voltage
V = slice(bus, [0], [VM-1,VM]) .* exp(c(0,1) * pi/180 * slice(bus, [0], [VA-1,VA]));
......
......@@ -70,5 +70,5 @@ fn make_y_bus(baseMVA, bus, branch) {
full(sparse(j, j, Ysh, nb, nb));
}
return Ybus;
return(Ybus, Yf, Yt);
}
\ No newline at end of file
fn make_y_bus_Yf(baseMVA, bus, branch) {
// constants
nb = size(bus, 0); // number of buses
nl = size(branch, 0); // number of lines
// for each branch, compute the elements of the branch admittance matrix where
//
// | If | | Yff Yft | | Vf |
// | | = | | * | |
// | It | | Ytf Ytt | | Vt |
//
stat = slice(branch, [0], [BR_STATUS-1,BR_STATUS]); // ones at in-service branches
Ys = stat ./ (slice(branch, [0], [BR_R-1,BR_R])
+ c(0,1) * slice(branch, [0], [BR_X-1,BR_X])); // series admittance
Bc = stat .* slice(branch, [0], [BR_B-1,BR_B]); // line charging susceptance
tap_col = slice(branch, [0], [TAP-1,TAP]); // tap ratio column
index = find(tap_col); // indices of non-zero tap ratios
tap_init = set(ones(nl, 1), index, get_multi(tap_col, index)); // assign non-zero tap ratios
tap = tap_init .* exp(c(0,1)*pi/180 * slice(branch, [0], [SHIFT-1,SHIFT])); // add phase shifters
Ytt = Ys + c(0,1) * Bc/2;
Yff = Ytt ./ (tap .* conj(tap));
Yft = - Ys ./ conj(tap);
Ytf = - Ys ./ tap;
// compute shunt admittance
// if Psh is the real power consumed by the shunt at V = 1.0 p.u.
// and Qsh is the reactive power injected by the shunt at V = 1.0 p.u.
// then Psh - j Qsh = V * conj(Ysh * V) = conj(Ysh) = Gs - j Bs,
// i.e. Ysh = Psh + j Qsh, so ...
// vector of shunt admittances
Ysh = (slice(bus, [0], [GS-1,GS]) + c(0,1) * slice(bus, [0], [BS-1,BS])) / baseMVA;
// bus indices
f = slice(branch, [0], F_BUS-1) - 1; // list of "from" buses
t = slice(branch, [0], T_BUS-1) - 1; // list of "to" buses
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(0, nl),range(0, nl)); // double set of row indices
j = range(0,nb);
upper = horzcat(Yff', Yft');
lower = horzcat(Ytf', Ytt');
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 = 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 = 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 = 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 +
full(sparse(j, j, Ysh, nb, nb));
}
return Yf;
}
\ No newline at end of file
fn make_y_bus_Yt(baseMVA, bus, branch) {
// constants
nb = size(bus, 0); // number of buses
nl = size(branch, 0); // number of lines
// for each branch, compute the elements of the branch admittance matrix where
//
// | If | | Yff Yft | | Vf |
// | | = | | * | |
// | It | | Ytf Ytt | | Vt |
//
stat = slice(branch, [0], [BR_STATUS-1,BR_STATUS]); // ones at in-service branches
Ys = stat ./ (slice(branch, [0], [BR_R-1,BR_R])
+ c(0,1) * slice(branch, [0], [BR_X-1,BR_X])); // series admittance
Bc = stat .* slice(branch, [0], [BR_B-1,BR_B]); // line charging susceptance
tap_col = slice(branch, [0], [TAP-1,TAP]); // tap ratio column
index = find(tap_col); // indices of non-zero tap ratios
tap_init = set(ones(nl, 1), index, get_multi(tap_col, index)); // assign non-zero tap ratios
tap = tap_init .* exp(c(0,1)*pi/180 * slice(branch, [0], [SHIFT-1,SHIFT])); // add phase shifters
Ytt = Ys + c(0,1) * Bc/2;
Yff = Ytt ./ (tap .* conj(tap));
Yft = - Ys ./ conj(tap);
Ytf = - Ys ./ tap;
// compute shunt admittance
// if Psh is the real power consumed by the shunt at V = 1.0 p.u.
// and Qsh is the reactive power injected by the shunt at V = 1.0 p.u.
// then Psh - j Qsh = V * conj(Ysh * V) = conj(Ysh) = Gs - j Bs,
// i.e. Ysh = Psh + j Qsh, so ...
// vector of shunt admittances
Ysh = (slice(bus, [0], [GS-1,GS]) + c(0,1) * slice(bus, [0], [BS-1,BS])) / baseMVA;
// bus indices
f = slice(branch, [0], F_BUS-1) - 1; // list of "from" buses
t = slice(branch, [0], T_BUS-1) - 1; // list of "to" buses
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(0, nl),range(0, nl)); // double set of row indices
j = range(0,nb);
upper = horzcat(Yff', Yft');
lower = horzcat(Ytf', Ytt');
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 = 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 = 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 = 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 +
full(sparse(j, j, Ysh, nb, nb));
}
return Yt;
}
\ No newline at end of file
......@@ -130,9 +130,6 @@ fn pfsoln(baseMVA, bus0, gen0, branch0, Ybus, Yf, Yt, V, ref, pv, pq, mpopt){
branch_QT = set(branch_QT, br, imag(St));
branch = horzcat(branch, branch_QT);
//return bus, gen, branch;
return bus;
//return gen;
//return branch;
return(bus, gen, branch);
}
\ No newline at end of file
......@@ -33,7 +33,7 @@ fn runpf() {
V_init = set(V0, gbus_k, gen_vg ./ abs(voltage_g) .* voltage_g);
// build admittance matrices
Ybus = make_y_bus(baseMVA, bus, branch);
[Ybus, _, _] = make_y_bus(baseMVA, bus, branch);
qlim = 0;
loop {
// compute bus power injections
......
# RustScript 语言规范
# RustScript 语言规范
......@@ -1226,9 +1226,20 @@ fn function_name(param1, param2, ...) {
fn add(a, b) {
a + b
}
//函数支持多个返回
fn two_return_fn(input) {
return(input, input+1);
}
fn three_return_fn(input) {
return(input, input+1, input+2);
}
a = 0;
b = 1.0;
[a, b] = two_return_fn(a);
[_, b, _] = three_return_fn(a); //返回值若无目标变量可用“_”空置
```
**重要限制:RustScript函数只能返回一个变量,不支持多返回值。**
### 9.2 函数示例
```rustscript
......@@ -1241,7 +1252,7 @@ fn make_y_bus(baseMVA, bus, branch) {
Ys = stat ./ (slice(branch, [0], [BR_R-1, BR_R])
+ c(0,1) * slice(branch, [0], [BR_X-1, BR_X]));
return Ys; // 只能返回一个值
return Ys;
}
```
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论