Home > matpower5.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 %   $Id: checklimits.m 2471 2014-12-16 15:32:35Z ray $
0020 %   by Ray Zimmerman
0021 %   Copyright (c) 2014 by Ray Zimmerman
0022 %
0023 %   This file is part of MATPOWER.
0024 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0025 %
0026 %   MATPOWER is free software: you can redistribute it and/or modify
0027 %   it under the terms of the GNU General Public License as published
0028 %   by the Free Software Foundation, either version 3 of the License,
0029 %   or (at your option) any later version.
0030 %
0031 %   MATPOWER is distributed in the hope that it will be useful,
0032 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0033 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0034 %   GNU General Public License for more details.
0035 %
0036 %   You should have received a copy of the GNU General Public License
0037 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0038 %
0039 %   Additional permission under GNU GPL version 3 section 7
0040 %
0041 %   If you modify MATPOWER, or any covered work, to interface with
0042 %   other modules (such as MATLAB code and MEX-files) available in a
0043 %   MATLAB(R) or comparable environment containing parts covered
0044 %   under other licensing terms, the licensors of MATPOWER grant
0045 %   you additional permission to convey the resulting work.
0046 
0047 define_constants;
0048 tol = 0.001;
0049 
0050 %% input args
0051 if nargin < 2
0052     ac = [];
0053     if nargin < 3
0054         quiet = 0;
0055     end
0056 end
0057 
0058 %% set default
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 %%-----  branch flows  -----
0068 %% get flows
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 %% find branch flow violations
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 %% absolute flow violations
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 %% percentage flow violations
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 %% sort by percentage violation
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 %% reorder indices, absolute violations
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 %%-----  generator real power  -----
0101 Pg = mpc.gen(:, PG);
0102 %% find Pmin and Pmax violations
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 %% absolute gen limit violations
0106 Pv.v = mpc.gen(Pv.i, PMIN) - Pg(Pv.i);
0107 Pv.V = Pg(Pv.I) - mpc.gen(Pv.I, PMAX);
0108 %% percentage gen limit violations
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 %% sort by percentage violation
0112 [Pv.p, k] = sort(Pv.p, 'descend');
0113 [Pv.P, K] = sort(Pv.P, 'descend');
0114 %% reorder indices, absolute violations
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

Generated on Mon 26-Jan-2015 15:21:31 by m2html © 2005