0001 function [Fv, Pv, Qv, Vv] = checklimits(mpc, ac, quiet)
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
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047 define_constants;
0048 tol = 0.001;
0049
0050
0051 if nargin < 2
0052 ac = [];
0053 if nargin < 3
0054 quiet = 0;
0055 end
0056 end
0057
0058
0059 if isempty(ac)
0060 if any(mpc.bus(:, VM) ~= 1)
0061 ac = 1;
0062 else
0063 ac = 0;
0064 end
0065 end
0066
0067
0068
0069 if ac
0070 Ff = sqrt(mpc.branch(:, PF).^2 + mpc.branch(:, QF).^2);
0071 Ft = sqrt(mpc.branch(:, PT).^2 + mpc.branch(:, QT).^2);
0072 F = max(Ff, Ft);
0073 else
0074 F = abs(mpc.branch(:, PF));
0075 end
0076
0077 Fv.i = find(F > mpc.branch(:, RATE_A) + tol & mpc.branch(:, RATE_A) > 0);
0078 Fv.ib = find(F > mpc.branch(:, RATE_B) + tol & mpc.branch(:, RATE_B) > 0);
0079 Fv.ic = find(F > mpc.branch(:, RATE_C) + tol & mpc.branch(:, RATE_C) > 0);
0080
0081 Fv.v = F(Fv.i) - mpc.branch(Fv.i, RATE_A);
0082 Fv.vb = F(Fv.ib) - mpc.branch(Fv.ib, RATE_B);
0083 Fv.vc = F(Fv.ic) - mpc.branch(Fv.ic, RATE_C);
0084
0085 Fv.p = 100 * Fv.v ./ mpc.branch(Fv.i, RATE_A);
0086 Fv.pb = 100 * Fv.vb ./ mpc.branch(Fv.ib, RATE_B);
0087 Fv.pc = 100 * Fv.vc ./ mpc.branch(Fv.ic, RATE_C);
0088
0089 [Fv.p, k] = sort(Fv.p, 'descend');
0090 [Fv.pb, kb] = sort(Fv.pb, 'descend');
0091 [Fv.pc, kc] = sort(Fv.pc, 'descend');
0092
0093 Fv.i = Fv.i(k);
0094 Fv.ib = Fv.ib(kb);
0095 Fv.ic = Fv.ic(kc);
0096 Fv.v = Fv.v(k);
0097 Fv.vb = Fv.vb(kb);
0098 Fv.vc = Fv.vc(kc);
0099
0100
0101 Pg = mpc.gen(:, PG);
0102
0103 Pv.i = find(Pg < mpc.gen(:, PMIN) - tol & mpc.gen(:, GEN_STATUS) > 0);
0104 Pv.I = find(Pg > mpc.gen(:, PMAX) + tol & mpc.gen(:, GEN_STATUS) > 0);
0105
0106 Pv.v = mpc.gen(Pv.i, PMIN) - Pg(Pv.i);
0107 Pv.V = Pg(Pv.I) - mpc.gen(Pv.I, PMAX);
0108
0109 Pv.p = 100 * Pv.v ./ max(abs(mpc.gen(Pv.i, PMIN)), abs(mpc.gen(Pv.i, PMAX)));
0110 Pv.P = 100 * Pv.V ./ max(abs(mpc.gen(Pv.I, PMIN)), abs(mpc.gen(Pv.I, PMAX)));
0111
0112 [Pv.p, k] = sort(Pv.p, 'descend');
0113 [Pv.P, K] = sort(Pv.P, 'descend');
0114
0115 Pv.i = Pv.i(k);
0116 Pv.I = Pv.I(K);
0117 Pv.v = Pv.v(k);
0118 Pv.V = Pv.V(K);
0119
0120 if ~quiet
0121 fprintf('\n');
0122 if isempty(Fv.ic)
0123 fprintf('No Branch Flow Emergency Rating Violations\n');
0124 else
0125 fprintf('Branch Flow Emergency Rating Violations\n');
0126 fprintf(' branch from to flow limit violation %% violation\n');
0127 fprintf('-------- -------- -------- ---------- ---------- ---------- ----------\n');
0128 for k = 1:length(Fv.ic);
0129 fprintf('%7d %8d %8d %10.1f %10.1f %10.2f %10.1f\n', Fv.ic(k), ...
0130 mpc.branch(Fv.ic(k), F_BUS), ...
0131 mpc.branch(Fv.ic(k), T_BUS), ...
0132 F(Fv.ic(k)), ...
0133 mpc.branch(Fv.ic(k), RATE_C), ...
0134 Fv.vc(k), ...
0135 Fv.pc(k) ...
0136 );
0137 end
0138 end
0139 if isempty(Fv.ib)
0140 fprintf('No Branch Flow Short Term Rating Violations\n');
0141 else
0142 fprintf('Branch Flow Short Term Rating Violations\n');
0143 fprintf(' branch from to flow limit violation %% violation\n');
0144 fprintf('-------- -------- -------- ---------- ---------- ---------- ----------\n');
0145 for k = 1:length(Fv.ib);
0146 fprintf('%7d %8d %8d %10.1f %10.1f %10.2f %10.1f\n', Fv.ib(k), ...
0147 mpc.branch(Fv.ib(k), F_BUS), ...
0148 mpc.branch(Fv.ib(k), T_BUS), ...
0149 F(Fv.ib(k)), ...
0150 mpc.branch(Fv.ib(k), RATE_B), ...
0151 Fv.vb(k), ...
0152 Fv.pb(k) ...
0153 );
0154 end
0155 end
0156 if isempty(Fv.i)
0157 fprintf('No Branch Flow Normal Rating Violations\n');
0158 else
0159 fprintf('Branch Flow Normal Rating Violations\n');
0160 fprintf(' branch from to flow limit violation %% violation\n');
0161 fprintf('-------- -------- -------- ---------- ---------- ---------- ----------\n');
0162 for k = 1:length(Fv.i);
0163 fprintf('%7d %8d %8d %10.1f %10.1f %10.2f %10.1f\n', Fv.i(k), ...
0164 mpc.branch(Fv.i(k), F_BUS), ...
0165 mpc.branch(Fv.i(k), T_BUS), ...
0166 F(Fv.i(k)), ...
0167 mpc.branch(Fv.i(k), RATE_A), ...
0168 Fv.v(k), ...
0169 Fv.p(k) ...
0170 );
0171 end
0172 end
0173
0174 fprintf('\n');
0175 fprintf('Generator Limit Violations\n');
0176 if isempty(Pv.i)
0177 fprintf('No Pmin Violations\n');
0178 else
0179 fprintf('Pmin Violations\n');
0180 fprintf(' gen bus Pmin Pg Pmax violation %% violation\n');
0181 fprintf('-------- -------- ---------- ---------- ---------- ---------- ----------\n');
0182 for k = 1:length(Pv.i);
0183 fprintf('%7d %8d %10.1f %10.1f %10.1f %10.2f %10.1f\n', Pv.i(k), ...
0184 mpc.gen(Pv.i(k), GEN_BUS), ...
0185 mpc.gen(Pv.i(k), PMIN), ...
0186 Pg(Pv.i(k)), ...
0187 mpc.gen(Pv.i(k), PMAX), ...
0188 Pv.v(k), ...
0189 Pv.p(k) ...
0190 );
0191 end
0192 end
0193 if isempty(Pv.I)
0194 fprintf('No Pmax Violations\n');
0195 else
0196 fprintf('Pmax Violations\n');
0197 fprintf(' gen bus Pmin Pg Pmax violation %% violation\n');
0198 fprintf('-------- -------- ---------- ---------- ---------- ---------- ----------\n');
0199 for k = 1:length(Pv.I);
0200 fprintf('%7d %8d %10.1f %10.1f %10.1f %10.2f %10.1f\n', Pv.I(k), ...
0201 mpc.gen(Pv.I(k), GEN_BUS), ...
0202 mpc.gen(Pv.I(k), PMIN), ...
0203 Pg(Pv.I(k)), ...
0204 mpc.gen(Pv.I(k), PMAX), ...
0205 Pv.V(k), ...
0206 Pv.P(k) ...
0207 );
0208 end
0209 end
0210 end