Home > matpower5.1 > extras > misc > checklimits.m

checklimits

PURPOSE ^

CHECKLIMITS Checks a solved power flow case for limit violations.

SYNOPSIS ^

function [Fv, Pv, Qv, Vv] = checklimits(mpc, ac, quiet)

DESCRIPTION ^

CHECKLIMITS   Checks a solved power flow case for limit violations.

   [FV, PV] = CHECKLIMITS(MPC)
   [FV, PV, QV, VV] = CHECKLIMITS(MPC, AC)
   [FV, PV, QV, VV] = CHECKLIMITS(MPC, AC, QUIET)

   Inputs:
       MPC : MATPOWER case struct
       AC :  0 = check DC limits, real power flows, Pg limits
             1 = check AC limits (includes |V|, Qg lims, MVA flows)
       QUIET : 1 doesn't print anything, 0 prints results

   Work-in-progress:   Currently only flow and real power generation limit
                       checks are implemented.
                       At this point, the code *is* the documentation.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [Fv, Pv, Qv, Vv] = checklimits(mpc, ac, quiet)
0002 %CHECKLIMITS   Checks a solved power flow case for limit violations.
0003 %
0004 %   [FV, PV] = CHECKLIMITS(MPC)
0005 %   [FV, PV, QV, VV] = CHECKLIMITS(MPC, AC)
0006 %   [FV, PV, QV, VV] = CHECKLIMITS(MPC, AC, QUIET)
0007 %
0008 %   Inputs:
0009 %       MPC : MATPOWER case struct
0010 %       AC :  0 = check DC limits, real power flows, Pg limits
0011 %             1 = check AC limits (includes |V|, Qg lims, MVA flows)
0012 %       QUIET : 1 doesn't print anything, 0 prints results
0013 %
0014 %   Work-in-progress:   Currently only flow and real power generation limit
0015 %                       checks are implemented.
0016 %                       At this point, the code *is* the documentation.
0017 
0018 %   MATPOWER
0019 %   Copyright (c) 2014-2015 by Power System Engineering Research Center (PSERC)
0020 %   by Ray Zimmerman, PSERC Cornell
0021 %
0022 %   $Id: checklimits.m 2644 2015-03-11 19:34:22Z ray $
0023 %
0024 %   This file is part of MATPOWER.
0025 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0026 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0027 
0028 define_constants;
0029 tol = 0.001;
0030 
0031 %% input args
0032 if nargin < 2
0033     ac = [];
0034     if nargin < 3
0035         quiet = 0;
0036     end
0037 end
0038 
0039 %% set default
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 %%-----  branch flows  -----
0049 %% get flows
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 %% find branch flow violations
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 %% absolute flow violations
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 %% percentage flow violations
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 %% sort by percentage violation
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 %% reorder indices, absolute violations
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 %%-----  generator real power  -----
0082 Pg = mpc.gen(:, PG);
0083 %% find Pmin and Pmax violations
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 %% absolute gen limit violations
0087 Pv.v = mpc.gen(Pv.i, PMIN) - Pg(Pv.i);
0088 Pv.V = Pg(Pv.I) - mpc.gen(Pv.I, PMAX);
0089 %% percentage gen limit violations
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 %% sort by percentage violation
0093 [Pv.p, k] = sort(Pv.p, 'descend');
0094 [Pv.P, K] = sort(Pv.P, 'descend');
0095 %% reorder indices, absolute violations
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

Generated on Fri 20-Mar-2015 18:23:34 by m2html © 2005