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