Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
S
sparrowzz
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
sgool
sparrowzz
Commits
bcbcf3c8
Commit
bcbcf3c8
authored
Jan 14, 2026
by
Lian-runzhe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
函数多个返回
parent
a2639489
显示空白字符变更
内嵌
并排
正在显示
13 个修改的文件
包含
126 行增加
和
186 行删除
+126
-186
rspower/examples/test_ext2int.txt
+50
-1
rspower/examples/test_make_sdzip.txt
+1
-1
rspower/examples/test_make_ybus.txt
+48
-1
rspower/examples/test_pfsoln.txt
+6
-18
rspower/examples/test_total_load2.txt
+0
-2
rspower/lib/ext2int.txt
+1
-3
rspower/lib/make_jac.txt
+1
-1
rspower/lib/make_y_bus.txt
+2
-1
rspower/lib/make_y_bus_Yf.txt
+0
-75
rspower/lib/make_y_bus_Yt.txt
+0
-75
rspower/lib/pfsoln.txt
+2
-4
rspower/lib/runpf.txt
+1
-1
rustscript/RustScript手册.md
+14
-3
没有找到文件。
rspower/examples/test_ext2int.txt
查看文件 @
bcbcf3c8
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
#include ../lib/idx_brch.txt
#include ../lib/idx_brch.txt
#include ../lib/ext2int.txt
#include ../lib/ext2int.txt
i2e = ext2int(bus, gen, branch, areas
);
[i2e, bus, gen, branch] = ext2int(bus, gen, branch
);
assert_relative_eq(i2e, [
assert_relative_eq(i2e, [
[1],
[1],
...
@@ -22,3 +22,51 @@ assert_relative_eq(i2e, [
...
@@ -22,3 +22,51 @@ assert_relative_eq(i2e, [
[13],
[13],
[14]
[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
rspower/examples/test_make_sdzip.txt
查看文件 @
bcbcf3c8
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
#include ../lib/idx_bus.txt
#include ../lib/idx_bus.txt
#include ../lib/make_sdzip.txt
#include ../lib/make_sdzip.txt
sdzip = make_sdzip(baseMVA, bus
, mpopt
);
sdzip = make_sdzip(baseMVA, bus);
assert_relative_eq(sdzip, [
assert_relative_eq(sdzip, [
[c(0,0), c(0,0), c(0,0)],
[c(0,0), c(0,0), c(0,0)],
...
...
rspower/examples/test_make_ybus.txt
查看文件 @
bcbcf3c8
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
#include ../lib/idx_brch.txt
#include ../lib/idx_brch.txt
#include ../lib/make_y_bus.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, [
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) ],
[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) ],
...
@@ -22,3 +22,49 @@ assert_relative_eq(ybus, [
...
@@ -22,3 +22,49 @@ assert_relative_eq(ybus, [
[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(-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) ]
[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);
],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
rspower/examples/test_pfsoln.txt
查看文件 @
bcbcf3c8
...
@@ -3,8 +3,6 @@
...
@@ -3,8 +3,6 @@
#include ../lib/idx_bus.txt
#include ../lib/idx_bus.txt
#include ../lib/idx_brch.txt
#include ../lib/idx_brch.txt
#include ../lib/make_y_bus.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/dsbus_dv.txt
#include ../lib/make_sdzip.txt
#include ../lib/make_sdzip.txt
#include ../lib/make_sbus.txt
#include ../lib/make_sbus.txt
...
@@ -20,17 +18,13 @@ for i in 0..5 {
...
@@ -20,17 +18,13 @@ for i in 0..5 {
}
}
info(`Run power flow on case14 end`);
info(`Run power flow on case14 end`);
Ybus = make_y_bus(baseMVA, bus, branch);
[Ybus, Yf, Yt] = make_y_bus(baseMVA, bus, branch);
Yf = make_y_bus_Yf(baseMVA, bus, branch);
Yt = make_y_bus_Yt(baseMVA, bus, branch);
V = r;
V = r;
bus_type = slice(bus, [0], [BUS_TYPE-1,BUS_TYPE]);
bus_type = slice(bus, [0], [BUS_TYPE-1,BUS_TYPE]);
ref = find(bus_type == REF) + 1;
ref = find(bus_type == REF) + 1;
pv = find(bus_type == PV) + 1;
pv = find(bus_type == PV) + 1;
pq = find(bus_type == PQ) + 1;
pq = find(bus_type == PQ) + 1;
bus_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, []);
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结果
//bus结果
assert_relative_eq(bus_output, [
assert_relative_eq(bus_output, [
...
@@ -51,16 +45,16 @@ assert_relative_eq(bus_output, [
...
@@ -51,16 +45,16 @@ assert_relative_eq(bus_output, [
],4);
],4);
//gen结果
//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(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(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(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(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)]
[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结果
//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(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(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)],
[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, [
...
@@ -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(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(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)]
[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);*/
],4);
//return bus_output;
//return gen_output;
//return branch_output;
\ No newline at end of file
rspower/examples/test_total_load2.txt
查看文件 @
bcbcf3c8
...
@@ -3,8 +3,6 @@
...
@@ -3,8 +3,6 @@
#include ../lib/idx_bus.txt
#include ../lib/idx_bus.txt
#include ../lib/idx_brch.txt
#include ../lib/idx_brch.txt
#include ../lib/make_y_bus.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/dsbus_dv.txt
#include ../lib/make_sdzip.txt
#include ../lib/make_sdzip.txt
#include ../lib/make_sbus.txt
#include ../lib/make_sbus.txt
...
...
rspower/lib/ext2int.txt
查看文件 @
bcbcf3c8
...
@@ -37,7 +37,5 @@ fn ext2int(bus, gen, branch, areas){
...
@@ -37,7 +37,5 @@ fn ext2int(bus, gen, branch, areas){
e2i_tbus = get_multi(e2i, index_e2i_tbus )';
e2i_tbus = get_multi(e2i, index_e2i_tbus )';
output_branch2 = assign(output_branch1, e2i_tbus, [0], [T_BUS-1, T_BUS] );
output_branch2 = assign(output_branch1, e2i_tbus, [0], [T_BUS-1, T_BUS] );
//return i2e, bus, gen, branch, areas;
return(i2e, bus, gen, branch);
//return output_branch2;
return i2e;
}
}
rspower/lib/make_jac.txt
查看文件 @
bcbcf3c8
fn make_jac(baseMVA, bus, branch, gen, fullJac) {
fn make_jac(baseMVA, bus, branch, gen, fullJac) {
// build Ybus
// build Ybus
Ybus
= make_y_bus(baseMVA, bus, branch);
[Ybus, _, _]
= make_y_bus(baseMVA, bus, branch);
// extract voltage
// extract voltage
V = slice(bus, [0], [VM-1,VM]) .* exp(c(0,1) * pi/180 * slice(bus, [0], [VA-1,VA]));
V = slice(bus, [0], [VM-1,VM]) .* exp(c(0,1) * pi/180 * slice(bus, [0], [VA-1,VA]));
...
...
rspower/lib/make_y_bus.txt
查看文件 @
bcbcf3c8
...
@@ -70,5 +70,5 @@ fn make_y_bus(baseMVA, bus, branch) {
...
@@ -70,5 +70,5 @@ fn make_y_bus(baseMVA, bus, branch) {
full(sparse(j, j, Ysh, nb, nb));
full(sparse(j, j, Ysh, nb, nb));
}
}
return
Ybus
;
return
(Ybus, Yf, Yt)
;
}
}
\ No newline at end of file
rspower/lib/make_y_bus_Yf.txt
deleted
100644 → 0
查看文件 @
a2639489
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
rspower/lib/make_y_bus_Yt.txt
deleted
100644 → 0
查看文件 @
a2639489
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
rspower/lib/pfsoln.txt
查看文件 @
bcbcf3c8
...
@@ -130,9 +130,6 @@ fn pfsoln(baseMVA, bus0, gen0, branch0, Ybus, Yf, Yt, V, ref, pv, pq, mpopt){
...
@@ -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_QT = set(branch_QT, br, imag(St));
branch = horzcat(branch, branch_QT);
branch = horzcat(branch, branch_QT);
//return bus, gen, branch;
return(bus, gen, branch);
return bus;
//return gen;
//return branch;
}
}
\ No newline at end of file
rspower/lib/runpf.txt
查看文件 @
bcbcf3c8
...
@@ -33,7 +33,7 @@ fn runpf() {
...
@@ -33,7 +33,7 @@ fn runpf() {
V_init = set(V0, gbus_k, gen_vg ./ abs(voltage_g) .* voltage_g);
V_init = set(V0, gbus_k, gen_vg ./ abs(voltage_g) .* voltage_g);
// build admittance matrices
// build admittance matrices
Ybus
= make_y_bus(baseMVA, bus, branch);
[Ybus, _, _]
= make_y_bus(baseMVA, bus, branch);
qlim = 0;
qlim = 0;
loop {
loop {
// compute bus power injections
// compute bus power injections
...
...
rustscript/RustScript手册.md
查看文件 @
bcbcf3c8
# Rus
tScript 语言规范
# Rus
tScript 语言规范
...
@@ -1226,9 +1226,20 @@ fn function_name(param1, param2, ...) {
...
@@ -1226,9 +1226,20 @@ fn function_name(param1, param2, ...) {
fn add(a, b) {
fn add(a, b) {
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 函数示例
### 9.2 函数示例
```
rustscript
```
rustscript
...
@@ -1241,7 +1252,7 @@ fn make_y_bus(baseMVA, bus, branch) {
...
@@ -1241,7 +1252,7 @@ fn make_y_bus(baseMVA, bus, branch) {
Ys = stat ./ (slice(branch, [0], [BR_R-1, BR_R])
Ys = stat ./ (slice(branch, [0], [BR_R-1, BR_R])
+ c(0,1) * slice(branch, [0], [BR_X-1, BR_X]));
+ c(0,1) * slice(branch, [0], [BR_X-1, BR_X]));
return Ys;
// 只能返回一个值
return Ys;
}
}
```
```
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论