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