Home > matpower6.0 > 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-2016, Power Systems Engineering Research Center (PSERC)
0020 %   by Ray Zimmerman, PSERC Cornell
0021 %
0022 %   This file is part of MATPOWER.
0023 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0024 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0025 
0026 define_constants;
0027 tol = 0.001;
0028 
0029 %% input args
0030 if nargin < 2
0031     ac = [];
0032     if nargin < 3
0033         quiet = 0;
0034     end
0035 end
0036 
0037 %% set default
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 %%-----  branch flows  -----
0047 %% get flows
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 %% find branch flow violations
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 %% absolute flow violations
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 %% percentage flow violations
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 %% sort by percentage violation
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 %% reorder indices, absolute violations
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 %%-----  generator real power  -----
0080 Pg = mpc.gen(:, PG);
0081 %% find Pmin and Pmax violations
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 %% absolute gen limit violations
0085 Pv.v = mpc.gen(Pv.i, PMIN) - Pg(Pv.i);
0086 Pv.V = Pg(Pv.I) - mpc.gen(Pv.I, PMAX);
0087 %% percentage gen limit violations
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 %% sort by percentage violation
0091 [Pv.p, k] = sort(Pv.p, 'descend');
0092 [Pv.P, K] = sort(Pv.P, 'descend');
0093 %% reorder indices, absolute violations
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

Generated on Fri 16-Dec-2016 12:45:37 by m2html © 2005