MAKEAVL Construct linear constraints for constant power factor var loads. [AVL, LVL, UVL, IVL] = MAKEAVL(BASEMVA, GEN) Constructs parameters for the following linear constraint enforcing a constant power factor constraint for dispatchable loads. LVL <= AVL * [Pg; Qg] <= UVL IVL is the vector of indices of generators representing variable loads. Example: [Avl, lvl, uvl, ivl] = makeAvl(baseMVA, gen);
0001 function [Avl, lvl, uvl, ivl] = makeAvl(baseMVA, gen) 0002 %MAKEAVL Construct linear constraints for constant power factor var loads. 0003 % [AVL, LVL, UVL, IVL] = MAKEAVL(BASEMVA, GEN) 0004 % 0005 % Constructs parameters for the following linear constraint enforcing a 0006 % constant power factor constraint for dispatchable loads. 0007 % 0008 % LVL <= AVL * [Pg; Qg] <= UVL 0009 % 0010 % IVL is the vector of indices of generators representing variable loads. 0011 % 0012 % Example: 0013 % [Avl, lvl, uvl, ivl] = makeAvl(baseMVA, gen); 0014 0015 % MATPOWER 0016 % Copyright (c) 1996-2016, Power Systems Engineering Research Center (PSERC) 0017 % by Ray Zimmerman, PSERC Cornell 0018 % and Carlos E. Murillo-Sanchez, PSERC Cornell & Universidad Nacional de Colombia 0019 % 0020 % This file is part of MATPOWER. 0021 % Covered by the 3-clause BSD License (see LICENSE file for details). 0022 % See http://www.pserc.cornell.edu/matpower/ for more info. 0023 0024 %% define named indices into data matrices 0025 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ... 0026 MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ... 0027 QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen; 0028 0029 %% data dimensions 0030 ng = size(gen, 1); %% number of dispatchable injections 0031 Pg = gen(:, PG) / baseMVA; 0032 Qg = gen(:, QG) / baseMVA; 0033 Pmin = gen(:, PMIN) / baseMVA; 0034 Qmin = gen(:, QMIN) / baseMVA; 0035 Qmax = gen(:, QMAX) / baseMVA; 0036 0037 0038 % Find out if any of these "generators" are actually dispatchable loads. 0039 % (see 'help isload' for details on what constitutes a dispatchable load) 0040 % Dispatchable loads are modeled as generators with an added constant 0041 % power factor constraint. The power factor is derived from the original 0042 % value of Pmin and either Qmin (for inductive loads) or Qmax (for capacitive 0043 % loads). If both Qmin and Qmax are zero, this implies a unity power factor 0044 % without the need for an additional constraint. 0045 0046 0047 ivl = find( isload(gen) & (Qmin ~= 0 | Qmax ~= 0) ); 0048 nvl = size(ivl, 1); %% number of dispatchable loads 0049 0050 %% at least one of the Q limits must be zero (corresponding to Pmax == 0) 0051 if any( Qmin(ivl) ~= 0 & Qmax(ivl) ~= 0 ) 0052 error('makeAvl: either Qmin or Qmax must be equal to zero for each dispatchable load.'); 0053 end 0054 0055 % Initial values of PG and QG must be consistent with specified power factor 0056 % This is to prevent a user from unknowingly using a case file which would 0057 % have defined a different power factor constraint under a previous version 0058 % which used PG and QG to define the power factor. 0059 Qlim = (Qmin(ivl) == 0) .* Qmax(ivl) + ... 0060 (Qmax(ivl) == 0) .* Qmin(ivl); 0061 if any( abs( Qg(ivl) - Pg(ivl) .* Qlim ./ Pmin(ivl) ) > 1e-6 ) 0062 error('makeAvl: %s\n %s\n', ... 0063 'For a dispatchable load, PG and QG must be consistent', ... 0064 'with the power factor defined by PMIN and the Q limits.'); 0065 end 0066 0067 % make Avl, lvl, uvl, for lvl <= Avl * [Pg; Qg] <= uvl 0068 if nvl > 0 0069 xx = Pmin(ivl); 0070 yy = Qlim; 0071 pftheta = atan2(yy, xx); 0072 pc = sin(pftheta); 0073 qc = -cos(pftheta); 0074 ii = [ (1:nvl)'; (1:nvl)' ]; 0075 jj = [ ivl; ivl+ng ]; 0076 Avl = sparse(ii, jj, [pc; qc], nvl, 2*ng); 0077 lvl = zeros(nvl, 1); 0078 uvl = lvl; 0079 else 0080 Avl = sparse(0, 2*ng); 0081 lvl =[]; 0082 uvl =[]; 0083 end