Commit 4e187859 by Lian-runzhe

状态估计修改

parent b9e0c8f9
#include ../data/case3bus_P6_6.txt
#include ../lib/checkDataIntegrity.txt
//函数输入的自变量“measure, idx, sigma”matpower中为结构体类型,拆分的话变量太多了,故先不作为函数输入自变量
//该测试的“measure, idx, sigma”是测试错误情况
// which measurements are available
idx_zPF = [[1],[2]];
idx_zPT = [3];
idx_zPG = [[1],[2],[3]];
idx_zVa = [];
idx_zQF = [];
idx_zQT = [];
idx_zQG = [];
idx_zVm = [[2]];
// specify measurements
measure_PF = [[0.12],[0.10]];
measure_PT = [-0.04];
measure_PG = [[0.58],[0.30]];
measure_Va = [];
measure_QF = [];
measure_QT = [];
measure_QG = [];
measure_Vm = [[1.04],[0.98]];
// specify measurement variances
sigma_PF = 0.02;
sigma_PT = [];
sigma_PG = [[1.04],[0.98]];
sigma_Va = [[1.04],[0.98]];
sigma_QF = [[1.04],[0.98]];
sigma_QT = [[1.04],[0.98]];
sigma_QG = [[1.04],[0.98]];
sigma_Vm = 0.01;
nbus = 3;
success = checkDataIntegrity(nbus);
return success;
\ No newline at end of file
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include ../lib/make_sbus.txt #include ../lib/make_sbus.txt
#include ../lib/pfsoln.txt #include ../lib/pfsoln.txt
#include ../lib/total_load.txt #include ../lib/total_load.txt
#include ../lib/checkDataIntegrity.txt
//输入观测值 //输入观测值
// which measurements are available // which measurements are available
...@@ -48,6 +49,13 @@ sigma_QT = []; ...@@ -48,6 +49,13 @@ sigma_QT = [];
sigma_QG = []; sigma_QG = [];
sigma_Vm = 0.01; sigma_Vm = 0.01;
// check input data integrity
nbus = 3;
success = checkDataIntegrity(nbus);
if ~~success{
println('State Estimation input data are not complete or sufficient!');
}
type_initialguess = 2; type_initialguess = 2;
V0 = [[1], [1.02], [1.02]]; V0 = [[1], [1.02], [1.02]];
......
//CHECKDATAINTEGRITY Check state estimation input data integrity.
// returns 1 if the data is complete, 0 otherwise.
// NOTE: for each type of measurements, the measurement vector and index
// vector should have the same length. If not, the longer vector will be
// truncated to have the same length as the shorter vector.
fn checkDataIntegrity(nbus) {
success = 1; // pass integrity check?
nowarning = 1; // no warning found?
// check input data consistency
// for PF
len_PF_measure = length(measure_PF);
len_PF_idx = length(idx_zPF);
if len_PF_measure != len_PF_idx {
println(`Warning: measurement vector and index vector for PF do not have the same length.`);
nowarning = 0;
}
if ~~is_empty(idx_zPF) && length(sigma_PF) <= 0 { // no sigma defined
println(`Error: Sigma for PF is not specified.`);
success = 0;
}
if length(sigma_PF) > 1 {
println(`Warning: Sigma for PF is assigned multiple values.`);
nowarning = 0;
}
// for PT
len_PT_measure = length(measure_PT);
len_PT_idx = length(idx_zPT);
if len_PT_measure != len_PT_idx {
println(`Warning: measurement vector and index vector for PT do not have the same length.`);
nowarning = 0;
}
if ~~is_empty(idx_zPT) && length(sigma_PT) <= 0 { // no sigma defined
println(`Error: Sigma for PT is not specified.`);
success = 0;
}
if length(sigma_PT) > 1 {
println(`Warning: Sigma for PT is assigned multiple values.`);
nowarning = 0;
}
// for PG
len_PG_measure = length(measure_PG);
len_PG_idx = length(idx_zPG);
if len_PG_measure != len_PG_idx {
println(`Warning: measurement vector and index vector for PG do not have the same length.`);
nowarning = 0;
}
if ~~is_empty(idx_zPG) && length(sigma_PG) <= 0 { // no sigma defined
println(`Error: Sigma for PG is not specified.`);
success = 0;
}
if length(sigma_PG) > 1 {
println(`Warning: Sigma for PG is assigned multiple values.`);
nowarning = 0;
}
// for Va
len_Va_measure = length(measure_Va);
len_Va_idx = length(idx_zVa);
if len_Va_measure != len_Va_idx {
println(`Warning: measurement vector and index vector for Va do not have the same length.`);
nowarning = 0;
}
if ~~is_empty(idx_zVa) && length(sigma_Va) <= 0 { // no sigma defined
println(`Error: Sigma for Va is not specified.`);
success = 0;
}
if length(sigma_Va) > 1 {
println(`Warning: Sigma for Va is assigned multiple values.`);
nowarning = 0;
}
// for QF
len_QF_measure = length(measure_QF);
len_QF_idx = length(idx_zQF);
if len_QF_measure != len_QF_idx {
println(`Warning: measurement vector and index vector for QF do not have the same length.`);
nowarning = 0;
}
if ~~is_empty(idx_zQF) && length(sigma_QF) <= 0 { // no sigma defined
println(`Error: Sigma for QF is not specified.`);
success = 0;
}
if length(sigma_QF) > 1 {
println(`Warning: Sigma for QF is assigned multiple values.`);
nowarning = 0;
}
// for QT
len_QT_measure = length(measure_QT);
len_QT_idx = length(idx_zQT);
if len_QT_measure != len_QT_idx {
println(`Warning: measurement vector and index vector for QT do not have the same length.`);
nowarning = 0;
}
if ~~is_empty(idx_zQT) && length(sigma_QT) <= 0 { // no sigma defined
println(`Error: Sigma for QT is not specified.`);
success = 0;
}
if length(sigma_QT) > 1 {
println(`Warning: Sigma for QT is assigned multiple values.`);
nowarning = 0;
}
// for QG
len_QG_measure = length(measure_QG);
len_QG_idx = length(idx_zQG);
if len_QG_measure != len_QG_idx {
println(`Warning: measurement vector and index vector for QG do not have the same length.`);
nowarning = 0;
}
if ~~is_empty(idx_zQG) && length(sigma_QG) <= 0 { // no sigma defined
println(`Error: Sigma for QG is not specified.`);
success = 0;
}
if length(sigma_QG) > 1 {
println(`Warning: Sigma for QG is assigned multiple values.`);
nowarning = 0;
}
// for Vm
len_Vm_measure = length(measure_Vm);
len_Vm_idx = length(idx_zVm);
if len_Vm_measure != len_Vm_idx {
println(`Warning: measurement vector and index vector for Vm do not have the same length.`);
nowarning = 0;
}
if ~~is_empty(idx_zVm) && length(sigma_Vm) <= 0 { // no sigma defined
println(`Error: Sigma for Vm is not specified.`);
success = 0;
}
if length(sigma_Vm) > 1 {
println(`Warning: Sigma for Vm is assigned multiple values.`);
nowarning = 0;
}
// check if total number of measurements is no less than total number of
// variables to be estimated
num_allMeasure = len_PF_measure + len_PT_measure + len_PG_measure + len_Va_measure + len_QF_measure + len_QT_measure + len_QG_measure + len_Vm_measure;
num_variables = 2 * (nbus - 1);
if num_allMeasure < num_variables {
println(`Error: There are less measurements than number of variables to be estimated.`);
success = 0;
}
return success;
}
\ No newline at end of file
...@@ -135,36 +135,5 @@ fn dSbr_dV(branch, Yf, Yt, V, vcart) { ...@@ -135,36 +135,5 @@ fn dSbr_dV(branch, Yf, Yt, V, vcart) {
Sf = get_multi(V, f)' .* Ifc; Sf = get_multi(V, f)' .* Ifc;
St = get_multi(V, t)' .* Itc; St = get_multi(V, t)' .* Itc;
/*if is_sparse(Yf) { // 稀疏矩阵版本 (如果Yf是稀疏矩阵)
diagVf = sparse(range(0, nl), range(0, nl), get_multi(V, f), nl, nl);
diagVt = sparse(range(0, nl), range(0, nl), get_multi(V, t), nl, nl);
diagIfc = sparse(range(0, nl), range(0, nl), Ifc, nl, nl);
diagItc = sparse(range(0, nl), range(0, nl), Itc, nl, nl);
if vcart == 0 { // 极坐标
Vnorm = V ./ abs(V);
diagVc = sparse(range(0, nb), range(0, nb), Vc, nb, nb);
diagVnorm = sparse(range(0, nb), range(0, nb), Vnorm, nb, nb);
CVf = sparse(range(0, nl), f, get_multi(V, f), nl, nb);
CVnf = sparse(range(0, nl), f, get_multi(get_multi(Vnorm, f), range(0, size(f, 0))), nl, nb);
CVt = sparse(range(0, nl), t, get_multi(V, t), nl, nb);
CVnt = sparse(range(0, nl), t, get_multi(get_multi(Vnorm, t), range(0, size(t, 0))), nl, nb);
}
} else { // 稠密矩阵版本
diagVf = diag(get_multi(V, f));
diagVt = diag(get_multi(V, t));
diagIfc = diag(Ifc);
diagItc = diag(Itc);
if vcart == 0 { // 极坐标
Vnorm = V ./ abs(V);
diagVc = diag(Vc);
diagVnorm = diag(Vnorm);
CVf = full(sparse(range(0, nl), f, get_multi(V, f), nl, nb));
CVnf = full(sparse(range(0, nl), f, get_multi(Vnorm, f), nl, nb));
CVt = full(sparse(range(0, nl), t, get_multi(V, t), nl, nb));
CVnt = full(sparse(range(0, nl), t, get_multi(Vnorm, t), nl, nb));
}
}
*/
return (dSf_dV1, dSf_dV2, dSt_dV1, dSt_dV2, Sf, St); return (dSf_dV1, dSf_dV2, dSt_dV1, dSt_dV2, Sf, St);
} }
...@@ -186,7 +186,7 @@ fn doSE(baseMVA, bus, gen, branch, Ybus, Yf, Yt, V0, ref, pv, pq) { ...@@ -186,7 +186,7 @@ fn doSE(baseMVA, bus, gen, branch, Ybus, Yf, Yt, V0, ref, pv, pq) {
// ---------------------- 收敛判断 ---------------------- // ---------------------- 收敛判断 ----------------------
normF = max(abs(F)); // 残差无穷范数 normF = max(abs(F)); // 残差无穷范数
if verbose > 1 { if verbose > 1 {
println("\niteration [%3d]\t\tnorm of mismatch: %10.3e", iter_num, normF); //println("\niteration [%3d]\t\tnorm of mismatch: %10.3e", iter_num, normF);
} }
if normF < tol { if normF < tol {
converged = 1; converged = 1;
......
...@@ -34,7 +34,7 @@ fn getV0(bus, gen, type_initialguess, V0_in) { ...@@ -34,7 +34,7 @@ fn getV0(bus, gen, type_initialguess, V0_in) {
// 使用给定的初始电压 // 使用给定的初始电压
V0 = V0_in; V0 = V0_in;
} else { } else {
//info(`Error: unknown 'type_initialguess'`); //println(`Error: unknown 'type_initialguess`);
return []; return [];
} }
......
...@@ -60,10 +60,6 @@ fn run_se(type_initialguess, V0) { ...@@ -60,10 +60,6 @@ fn run_se(type_initialguess, V0) {
// 转换回原始母线编号 // 转换回原始母线编号
[output_bus, output_gen, output_branch] = int2ext(se_i2e, new_bus, new_gen, new_branch, areas); [output_bus, output_gen, output_branch] = int2ext(se_i2e, new_bus, new_gen, new_branch, areas);
// 输出结果
//outputpfsoln(baseMVA, bus, gen, branch, success, et, 1, iterNum);
//outputsesoln(idx, sigma, z, z_est, error_sqrsum);
return (baseMVA, output_bus, output_gen, output_branch, success, z, z_est, error_sqrsum); return (baseMVA, output_bus, output_gen, output_branch, success, z, z_est, error_sqrsum);
} }
\ No newline at end of file
# RustScript 语言规范 # RustScript 语言规范
...@@ -1256,7 +1256,7 @@ for i in 0..b { ...@@ -1256,7 +1256,7 @@ for i in 0..b {
max_num = 10; max_num = 10;
a = 0; a = 0;
converged = 0; converged = 0;
while (!converged && a < max_num) { while (~~converged && a < max_num) {
a = a + 1; a = a + 1;
} }
``` ```
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论