BUSTYPES Builds index lists for each type of bus (REF, PV, PQ). [REF, PV, PQ] = BUSTYPES(BUS, GEN) Generators with "out-of-service" status are treated as PQ buses with zero generation (regardless of Pg/Qg values in gen). Expects BUS and GEN have been converted to use internal consecutive bus numbering.
0001 function [ref, pv, pq] = bustypes(bus, gen) 0002 %BUSTYPES Builds index lists for each type of bus (REF, PV, PQ). 0003 % [REF, PV, PQ] = BUSTYPES(BUS, GEN) 0004 % Generators with "out-of-service" status are treated as PQ buses with 0005 % zero generation (regardless of Pg/Qg values in gen). Expects BUS and 0006 % GEN have been converted to use internal consecutive bus numbering. 0007 0008 % MATPOWER 0009 % $Id: bustypes.m 1635 2010-04-26 19:45:26Z ray $ 0010 % by Ray Zimmerman, PSERC Cornell 0011 % Copyright (c) 1996-2010 by Power System Engineering Research Center (PSERC) 0012 % 0013 % This file is part of MATPOWER. 0014 % See http://www.pserc.cornell.edu/matpower/ for more info. 0015 % 0016 % MATPOWER is free software: you can redistribute it and/or modify 0017 % it under the terms of the GNU General Public License as published 0018 % by the Free Software Foundation, either version 3 of the License, 0019 % or (at your option) any later version. 0020 % 0021 % MATPOWER is distributed in the hope that it will be useful, 0022 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0023 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0024 % GNU General Public License for more details. 0025 % 0026 % You should have received a copy of the GNU General Public License 0027 % along with MATPOWER. If not, see <http://www.gnu.org/licenses/>. 0028 % 0029 % Additional permission under GNU GPL version 3 section 7 0030 % 0031 % If you modify MATPOWER, or any covered work, to interface with 0032 % other modules (such as MATLAB code and MEX-files) available in a 0033 % MATLAB(R) or comparable environment containing parts covered 0034 % under other licensing terms, the licensors of MATPOWER grant 0035 % you additional permission to convey the resulting work. 0036 0037 %% constants 0038 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ... 0039 VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus; 0040 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ... 0041 MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ... 0042 QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen; 0043 0044 %% get generator status 0045 % bus_gen_status = zeros(size(bus, 1), 1); 0046 % bus_gen_status(gen(:, GEN_BUS)) = gen(:, GEN_STATUS) > 0; 0047 nb = size(bus, 1); 0048 ng = size(gen, 1); 0049 Cg = sparse(gen(:, GEN_BUS), (1:ng)', gen(:, GEN_STATUS) > 0, nb, ng); %% gen connection matrix 0050 %% element i, j is 1 if, generator j at bus i is ON 0051 bus_gen_status = Cg * ones(ng, 1); %% number of generators at each bus that are ON 0052 0053 0054 %% form index lists for slack, PV, and PQ buses 0055 ref = find(bus(:, BUS_TYPE) == REF & bus_gen_status); %% reference bus index 0056 pv = find(bus(:, BUS_TYPE) == PV & bus_gen_status); %% PV bus indices 0057 pq = find(bus(:, BUS_TYPE) == PQ | ~bus_gen_status); %% PQ bus indices 0058 0059 %% pick a new reference bus if for some reason there is none (may have been shut down) 0060 if isempty(ref) 0061 ref = pv(1); %% use the first PV bus 0062 pv = pv(2:length(pv)); %% take it off PV list 0063 end