MAKEAPQ Construct linear constraints for generator capability curves. [APQH, UBPQH, APQL, UBPQL, DATA] = MAKEAPQ(BASEMVA, GEN) Constructs the parameters for the following linear constraints implementing trapezoidal generator capability curves, where Pg and Qg are the real and reactive generator injections. APQH * [Pg; Qg] <= UBPQH APQL * [Pg; Qg] <= UBPQL DATA constains additional information as shown below. Example: [Apqh, ubpqh, Apql, ubpql, data] = makeApq(baseMVA, gen); data.h [QC1MAX-QC2MAX, PC2-PC1] data.l [QC2MIN-QC1MIN, PC1-PC2] data.ipqh indices of gens with general PQ cap curves (upper) data.ipql indices of gens with general PQ cap curves (lower)
0001 function [Apqh, ubpqh, Apql, ubpql, data] = makeApq(baseMVA, gen) 0002 %MAKEAPQ Construct linear constraints for generator capability curves. 0003 % [APQH, UBPQH, APQL, UBPQL, DATA] = MAKEAPQ(BASEMVA, GEN) 0004 % 0005 % Constructs the parameters for the following linear constraints 0006 % implementing trapezoidal generator capability curves, where 0007 % Pg and Qg are the real and reactive generator injections. 0008 % 0009 % APQH * [Pg; Qg] <= UBPQH 0010 % APQL * [Pg; Qg] <= UBPQL 0011 % 0012 % DATA constains additional information as shown below. 0013 % 0014 % Example: 0015 % [Apqh, ubpqh, Apql, ubpql, data] = makeApq(baseMVA, gen); 0016 % 0017 % data.h [QC1MAX-QC2MAX, PC2-PC1] 0018 % data.l [QC2MIN-QC1MIN, PC1-PC2] 0019 % data.ipqh indices of gens with general PQ cap curves (upper) 0020 % data.ipql indices of gens with general PQ cap curves (lower) 0021 0022 % MATPOWER 0023 % Copyright (c) 1996-2016, Power Systems Engineering Research Center (PSERC) 0024 % by Ray Zimmerman, PSERC Cornell 0025 % and Carlos E. Murillo-Sanchez, PSERC Cornell & Universidad Nacional de Colombia 0026 % 0027 % This file is part of MATPOWER. 0028 % Covered by the 3-clause BSD License (see LICENSE file for details). 0029 % See http://www.pserc.cornell.edu/matpower/ for more info. 0030 0031 %% define named indices into data matrices 0032 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ... 0033 MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ... 0034 QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen; 0035 0036 %% data dimensions 0037 ng = size(gen, 1); %% number of dispatchable injections 0038 0039 %% which generators require additional linear constraints 0040 %% (in addition to simple box constraints) on (Pg,Qg) to correctly 0041 %% model their PQ capability curves 0042 ipqh = find( hasPQcap(gen, 'U') ); 0043 ipql = find( hasPQcap(gen, 'L') ); 0044 npqh = size(ipqh, 1); %% number of general PQ capability curves (upper) 0045 npql = size(ipql, 1); %% number of general PQ capability curves (lower) 0046 0047 %% make Apqh if there is a need to add general PQ capability curves; 0048 %% use normalized coefficient rows so multipliers have right scaling 0049 %% in $$/pu 0050 if npqh > 0 0051 data.h = [gen(ipqh,QC1MAX)-gen(ipqh,QC2MAX), gen(ipqh,PC2)-gen(ipqh,PC1)]; 0052 ubpqh = data.h(:, 1) .* gen(ipqh,PC1) + data.h(:, 2) .* gen(ipqh,QC1MAX); 0053 for i=1:npqh, 0054 tmp = norm(data.h(i,:)); 0055 data.h(i,:) = data.h(i, :) / tmp; 0056 ubpqh(i) = ubpqh(i) / tmp; 0057 end 0058 Apqh = sparse([1:npqh, 1:npqh]', [ipqh; ipqh+ng], ... 0059 data.h(:), npqh, 2*ng); 0060 ubpqh = ubpqh / baseMVA; 0061 else 0062 data.h = []; 0063 Apqh = sparse(0, 2*ng); 0064 ubpqh = []; 0065 end 0066 0067 %% similarly Apql 0068 if npql > 0 0069 data.l = [gen(ipql,QC2MIN)-gen(ipql,QC1MIN), gen(ipql,PC1)-gen(ipql,PC2)]; 0070 ubpql= data.l(:, 1) .* gen(ipql,PC1) + data.l(:, 2) .* gen(ipql,QC1MIN) ; 0071 for i=1:npql, 0072 tmp = norm(data.l(i, : )); 0073 data.l(i, :) = data.l(i, :) / tmp; 0074 ubpql(i) = ubpql(i) / tmp; 0075 end 0076 Apql = sparse([1:npql, 1:npql]', [ipql; ipql+ng], ... 0077 data.l(:), npql, 2*ng); 0078 ubpql = ubpql / baseMVA; 0079 else 0080 data.l = []; 0081 Apql = sparse(0, 2*ng); 0082 ubpql = []; 0083 end 0084 0085 data.ipql = ipql; 0086 data.ipqh = ipqh;