0001 function [V, converged, i] = fdpf(Ybus, Sbus, V0, Bp, Bpp, ref, pv, pq, mpopt)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 if nargin < 7
0030 mpopt = mpoption;
0031 end
0032
0033
0034 tol = mpopt.pf.tol;
0035 max_it = mpopt.pf.fd.max_it;
0036 if have_fcn('matlab') && have_fcn('matlab', 'vnum') < 7.3
0037 lu_vec = 0;
0038 else
0039 lu_vec = 1;
0040 end
0041
0042
0043 converged = 0;
0044 i = 0;
0045 V = V0;
0046 Va = angle(V);
0047 Vm = abs(V);
0048
0049
0050 npv = length(pv);
0051 npq = length(pq);
0052
0053
0054 mis = (V .* conj(Ybus * V) - Sbus(Vm)) ./ Vm;
0055 P = real(mis([pv; pq]));
0056 Q = imag(mis(pq));
0057
0058
0059 normP = norm(P, inf);
0060 normQ = norm(Q, inf);
0061 if mpopt.verbose > 1
0062 fprintf('\niteration max mismatch (p.u.) ');
0063 fprintf('\ntype # P Q ');
0064 fprintf('\n---- ---- ----------- -----------');
0065 fprintf('\n - %3d %10.3e %10.3e', i, normP, normQ);
0066 end
0067 if normP < tol && normQ < tol
0068 converged = 1;
0069 if mpopt.verbose > 1
0070 fprintf('\nConverged!\n');
0071 end
0072 end
0073
0074
0075 Bp = Bp([pv; pq], [pv; pq]);
0076 Bpp = Bpp(pq, pq);
0077
0078
0079 if lu_vec
0080 [Lp, Up, pp, qp ] = lu(Bp, 'vector');
0081 [Lpp, Upp, ppp, qpp] = lu(Bpp, 'vector');
0082 [junk, iqp ] = sort(qp);
0083 [junk, iqpp] = sort(qpp);
0084
0085
0086 else
0087 [Lp, Up, Pp] = lu(Bp);
0088 [Lpp, Upp, Ppp] = lu(Bpp);
0089 end
0090
0091
0092 while (~converged && i < max_it)
0093
0094 i = i + 1;
0095
0096
0097 if lu_vec
0098 dVa = -( Up \ (Lp \ P(pp)) );
0099 dVa = dVa(iqp);
0100 else
0101 dVa = -( Up \ (Lp \ (Pp * P)));
0102 end
0103
0104
0105 Va([pv; pq]) = Va([pv; pq]) + dVa;
0106 V = Vm .* exp(1j * Va);
0107
0108
0109 mis = (V .* conj(Ybus * V) - Sbus(Vm)) ./ Vm;
0110 P = real(mis([pv; pq]));
0111 Q = imag(mis(pq));
0112
0113
0114 normP = norm(P, inf);
0115 normQ = norm(Q, inf);
0116 if mpopt.verbose > 1
0117 fprintf('\n P %3d %10.3e %10.3e', i, normP, normQ);
0118 end
0119 if normP < tol && normQ < tol
0120 converged = 1;
0121 if mpopt.verbose
0122 fprintf('\nFast-decoupled power flow converged in %d P-iterations and %d Q-iterations.\n', i, i-1);
0123 end
0124 break;
0125 end
0126
0127
0128 if lu_vec
0129 dVm = -( Upp \ (Lpp \ Q(ppp)) );
0130 dVm = dVm(iqpp);
0131 else
0132 dVm = -( Upp \ (Lpp \ (Ppp * Q)) );
0133 end
0134
0135
0136 Vm(pq) = Vm(pq) + dVm;
0137 V = Vm .* exp(1j * Va);
0138
0139
0140 mis = (V .* conj(Ybus * V) - Sbus(Vm)) ./ Vm;
0141 P = real(mis([pv; pq]));
0142 Q = imag(mis(pq));
0143
0144
0145 normP = norm(P, inf);
0146 normQ = norm(Q, inf);
0147 if mpopt.verbose > 1
0148 fprintf('\n Q %3d %10.3e %10.3e', i, normP, normQ);
0149 end
0150 if normP < tol && normQ < tol
0151 converged = 1;
0152 if mpopt.verbose
0153 fprintf('\nFast-decoupled power flow converged in %d P-iterations and %d Q-iterations.\n', i, i);
0154 end
0155 break;
0156 end
0157 end
0158
0159 if mpopt.verbose
0160 if ~converged
0161 fprintf('\nFast-decoupled power flow did not converge in %d iterations.\n', i);
0162 end
0163 end