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