Package pypower :: Package t :: Module t_total_load
[hide private]
[frames] | no frames]

Source Code for Module pypower.t.t_total_load

  1  # Copyright (C) 2008-2011 Power System Engineering Research Center (PSERC) 
  2  # Copyright (C) 2011 Richard Lincoln 
  3  # 
  4  # PYPOWER is free software: you can redistribute it and/or modify 
  5  # it under the terms of the GNU General Public License as published 
  6  # by the Free Software Foundation, either version 3 of the License, 
  7  # or (at your option) any later version. 
  8  # 
  9  # PYPOWER is distributed in the hope that it will be useful, 
 10  # but WITHOUT ANY WARRANTY], without even the implied warranty of 
 11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
 12  # GNU General Public License for more details. 
 13  # 
 14  # You should have received a copy of the GNU General Public License 
 15  # along with PYPOWER. If not, see <http://www.gnu.org/licenses/>. 
 16   
 17  """Tests for code in C{total_load}. 
 18  """ 
 19   
 20  from os.path import dirname, join 
 21   
 22  from numpy import array, zeros, r_, in1d, vstack, flatnonzero as find 
 23   
 24  from pypower.loadcase import loadcase 
 25  from pypower.isload import isload 
 26  from pypower.total_load import total_load 
 27   
 28  from pypower.idx_bus import PD, QD, BUS_AREA 
 29  from pypower.idx_gen import GEN_BUS, QG, PMIN, QMIN, QMAX 
 30   
 31  from pypower.t.t_begin import t_begin 
 32  from pypower.t.t_is import t_is 
 33  from pypower.t.t_end import t_end 
 34   
 35   
36 -def t_total_load(quiet=False):
37 """Tests for code in C{total_load}. 38 39 @author: Ray Zimmerman (PSERC Cornell) 40 @author: Richard Lincoln 41 """ 42 n_tests = 48 43 44 t_begin(n_tests, quiet) 45 46 ppc = loadcase(join(dirname(__file__), 't_auction_case')) 47 ppc['gen'][7, GEN_BUS] = 2 ## multiple d. loads per area, same bus as gen 48 ppc['gen'][7, [QG, QMIN, QMAX]] = array([3, 0, 3]) 49 ## put it load before gen in matrix 50 51 ppc['gen'] = vstack([ppc['gen'][7, :], ppc['gen'][:7, :], ppc['gen'][8, :]]) 52 ld = find(isload(ppc['gen'])) 53 a = [None] * 3 54 lda = [None] * 3 55 for k in range(3): 56 a[k] = find(ppc['bus'][:, BUS_AREA] == k + 1) ## buses in area k 57 tmp = find( in1d(ppc['gen'][ld, GEN_BUS] - 1, a[k]) ) 58 lda[k] = ld[tmp] ## disp loads in area k 59 60 area = [None] * 3 61 for k in range(3): 62 area[k] = {'fixed': {}, 'disp': {}, 'both': {}} 63 area[k]['fixed']['p'] = sum(ppc['bus'][a[k], PD]) 64 area[k]['fixed']['q'] = sum(ppc['bus'][a[k], QD]) 65 area[k]['disp']['p'] = -sum(ppc['gen'][lda[k], PMIN]) 66 area[k]['disp']['qmin'] = -sum(ppc['gen'][lda[k], QMIN]) 67 area[k]['disp']['qmax'] = -sum(ppc['gen'][lda[k], QMAX]) 68 area[k]['disp']['q'] = area[k]['disp']['qmin'] + area[k]['disp']['qmax'] 69 area[k]['both']['p'] = area[k]['fixed']['p'] + area[k]['disp']['p'] 70 area[k]['both']['q'] = area[k]['fixed']['q'] + area[k]['disp']['q'] 71 72 total = {'fixed': {}, 'disp': {}, 'both': {}} 73 total['fixed']['p'] = sum(ppc['bus'][:, PD]) 74 total['fixed']['q'] = sum(ppc['bus'][:, QD]) 75 total['disp']['p'] = -sum(ppc['gen'][ld, PMIN]) 76 total['disp']['qmin'] = -sum(ppc['gen'][ld, QMIN]) 77 total['disp']['qmax'] = -sum(ppc['gen'][ld, QMAX]) 78 total['disp']['q'] = total['disp']['qmin'] + total['disp']['qmax'] 79 total['both']['p'] = total['fixed']['p'] + total['disp']['p'] 80 total['both']['q'] = total['fixed']['q'] + total['disp']['q'] 81 82 ##----- all load ----- 83 t = 'Pd, _ = total_load(bus) : ' 84 Pd, _ = total_load(ppc['bus']) 85 t_is(Pd, [area[0]['fixed']['p'], area[1]['fixed']['p'], area[2]['fixed']['p']], 12, [t, 'Pd']) 86 87 t = 'Pd, Qd = total_load(bus) : ' 88 Pd, Qd = total_load(ppc['bus']) 89 t_is(Pd, [area[0]['fixed']['p'], area[1]['fixed']['p'], area[2]['fixed']['p']], 12, [t, 'Pd']) 90 t_is(Qd, [area[0]['fixed']['q'], area[1]['fixed']['q'], area[2]['fixed']['q']], 12, [t, 'Qd']) 91 92 t = 'Pd, _ = total_load(bus, gen) : ' 93 Pd, _ = total_load(ppc['bus'], ppc['gen']) 94 t_is(Pd, [area[0]['both']['p'], area[1]['both']['p'], area[2]['both']['p']], 12, [t, 'Pd']) 95 96 t = 'Pd, Qd = total_load(bus, gen) : ' 97 Pd, Qd = total_load(ppc['bus'], ppc['gen']) 98 t_is(Pd, [area[0]['both']['p'], area[1]['both']['p'], area[2]['both']['p']], 12, [t, 'Pd']) 99 t_is(Qd, [area[0]['both']['q'], area[1]['both']['q'], area[2]['both']['q']], 12, [t, 'Qd']) 100 101 t = 'Pd, _ = total_load(bus, None, \'all\') : ' 102 Pd, _ = total_load(ppc['bus'], None, 'all') 103 t_is(Pd, total['fixed']['p'], 12, [t, 'Pd']) 104 105 t = 'Pd, Qd = total_load(bus, None, \'all\') : ' 106 Pd, Qd = total_load(ppc['bus'], None, 'all') 107 t_is(Pd, total['fixed']['p'], 12, [t, 'Pd']) 108 t_is(Qd, total['fixed']['q'], 12, [t, 'Qd']) 109 110 t = 'Pd, _ = total_load(bus, gen, \'all\') : ' 111 Pd, _ = total_load(ppc['bus'], ppc['gen'], 'all') 112 t_is(Pd, total['both']['p'], 12, [t, 'Pd']) 113 114 t = 'Pd, Qd = total_load(bus, gen, \'all\') : ' 115 Pd, Qd = total_load(ppc['bus'], ppc['gen'], 'all') 116 t_is(Pd, total['both']['p'], 12, [t, 'Pd']) 117 t_is(Qd, total['both']['q'], 12, [t, 'Qd']) 118 119 t = 'Pd, _ = total_load(bus, gen, \'all\', \'BOTH\') : ' 120 Pd, _ = total_load(ppc['bus'], ppc['gen'], 'all', 'BOTH') 121 t_is(Pd, total['both']['p'], 12, [t, 'Pd']) 122 123 t = 'Pd, Qd = total_load(bus, gen, \'all\', \'BOTH\') : ' 124 Pd, Qd = total_load(ppc['bus'], ppc['gen'], 'all', 'BOTH') 125 t_is(Pd, total['both']['p'], 12, [t, 'Pd']) 126 t_is(Qd, total['both']['q'], 12, [t, 'Qd']) 127 128 t = 'Pd, _ = total_load(bus, gen, \'all\', \'FIXED\') : ' 129 Pd, _ = total_load(ppc['bus'], ppc['gen'], 'all', 'FIXED') 130 t_is(Pd, total['fixed']['p'], 12, [t, 'Pd']) 131 132 t = 'Pd, Qd = total_load(bus, gen, \'all\', \'FIXED\') : ' 133 Pd, Qd = total_load(ppc['bus'], ppc['gen'], 'all', 'FIXED') 134 t_is(Pd, total['fixed']['p'], 12, [t, 'Pd']) 135 t_is(Qd, total['fixed']['q'], 12, [t, 'Qd']) 136 137 t = 'Pd, _ = total_load(bus, gen, \'all\', \'DISPATCHABLE\') : ' 138 Pd, _ = total_load(ppc['bus'], ppc['gen'], 'all', 'DISPATCHABLE') 139 t_is(Pd, total['disp']['p'], 12, [t, 'Pd']) 140 141 t = 'Pd, Qd = total_load(bus, gen, \'all\', \'DISPATCHABLE\') : ' 142 Pd, Qd = total_load(ppc['bus'], ppc['gen'], 'all', 'DISPATCHABLE') 143 t_is(Pd, total['disp']['p'], 12, [t, 'Pd']) 144 t_is(Qd, total['disp']['q'], 12, [t, 'Qd']) 145 146 t = 'Pd, _ = total_load(bus, gen, None, \'BOTH\') : ' 147 Pd, _ = total_load(ppc['bus'], ppc['gen'], None, 'BOTH') 148 t_is(Pd, r_[area[0]['both']['p'], area[1]['both']['p'], area[2]['both']['p']], 12, [t, 'Pd']) 149 150 t = 'Pd, Qd = total_load(bus, gen, None, \'BOTH\') : ' 151 Pd, Qd = total_load(ppc['bus'], ppc['gen'], None, 'BOTH') 152 t_is(Pd, [area[0]['both']['p'], area[1]['both']['p'], area[2]['both']['p']], 12, [t, 'Pd']) 153 t_is(Qd, [area[0]['both']['q'], area[1]['both']['q'], area[2]['both']['q']], 12, [t, 'Qd']) 154 155 t = 'Pd, _ = total_load(bus, gen, None, \'FIXED\') : ' 156 Pd, _ = total_load(ppc['bus'], ppc['gen'], None, 'FIXED') 157 t_is(Pd, [area[0]['fixed']['p'], area[1]['fixed']['p'], area[2]['fixed']['p']], 12, [t, 'Pd']) 158 159 t = 'Pd, Qd = total_load(bus, gen, None, \'FIXED\') : ' 160 Pd, Qd = total_load(ppc['bus'], ppc['gen'], None, 'FIXED') 161 t_is(Pd, [area[0]['fixed']['p'], area[1]['fixed']['p'], area[2]['fixed']['p']], 12, [t, 'Pd']) 162 t_is(Qd, [area[0]['fixed']['q'], area[1]['fixed']['q'], area[2]['fixed']['q']], 12, [t, 'Qd']) 163 164 t = 'Pd, _ = total_load(bus, gen, None, \'DISPATCHABLE\') : ' 165 Pd, _ = total_load(ppc['bus'], ppc['gen'], None, 'DISPATCHABLE') 166 t_is(Pd, [area[0]['disp']['p'], area[1]['disp']['p'], area[2]['disp']['p']], 12, [t, 'Pd']) 167 168 t = 'Pd, Qd = total_load(bus, gen, None, \'DISPATCHABLE\') : ' 169 Pd, Qd = total_load(ppc['bus'], ppc['gen'], None, 'DISPATCHABLE') 170 t_is(Pd, [area[0]['disp']['p'], area[1]['disp']['p'], area[2]['disp']['p']], 12, [t, 'Pd']) 171 t_is(Qd, [area[0]['disp']['q'], area[1]['disp']['q'], area[2]['disp']['q']], 12, [t, 'Qd']) 172 173 ##----- explicit single load zone ----- 174 nb = ppc['bus'].shape[0] 175 load_zone = zeros(nb, int) 176 k = find(ppc['bus'][:, BUS_AREA] == 2) ## area 2 177 load_zone[k] = 1 178 t = 'Pd, _ = total_load(bus, gen, load_zone1, \'BOTH\') : ' 179 Pd, _ = total_load(ppc['bus'], ppc['gen'], load_zone, 'BOTH') 180 t_is(Pd, area[1]['both']['p'], 12, [t, 'Pd']) 181 182 t = 'Pd, Qd = total_load(bus, gen, load_zone1, \'BOTH\') : ' 183 Pd, Qd = total_load(ppc['bus'], ppc['gen'], load_zone, 'BOTH') 184 t_is(Pd, area[1]['both']['p'], 12, [t, 'Pd']) 185 t_is(Qd, area[1]['both']['q'], 12, [t, 'Qd']) 186 187 t = 'Pd, _ = total_load(bus, gen, load_zone1, \'FIXED\') : ' 188 Pd, _ = total_load(ppc['bus'], ppc['gen'], load_zone, 'FIXED') 189 t_is(Pd, area[1]['fixed']['p'], 12, [t, 'Pd']) 190 191 t = 'Pd, Qd = total_load(bus, gen, load_zone1, \'FIXED\') : ' 192 Pd, Qd = total_load(ppc['bus'], ppc['gen'], load_zone, 'FIXED') 193 t_is(Pd, area[1]['fixed']['p'], 12, [t, 'Pd']) 194 t_is(Qd, area[1]['fixed']['q'], 12, [t, 'Qd']) 195 196 t = 'Pd, _ = total_load(bus, gen, load_zone1, \'DISPATCHABLE\') : ' 197 Pd, _ = total_load(ppc['bus'], ppc['gen'], load_zone, 'DISPATCHABLE') 198 t_is(Pd, area[1]['disp']['p'], 12, [t, 'Pd']) 199 200 t = 'Pd, Qd = total_load(bus, gen, load_zone1, \'DISPATCHABLE\') : ' 201 Pd, Qd = total_load(ppc['bus'], ppc['gen'], load_zone, 'DISPATCHABLE') 202 t_is(Pd, area[1]['disp']['p'], 12, [t, 'Pd']) 203 t_is(Qd, area[1]['disp']['q'], 12, [t, 'Qd']) 204 205 ##----- explicit multiple load zone ----- 206 load_zone = zeros(nb, int) 207 k = find(ppc['bus'][:, BUS_AREA] == 3) ## area 3 208 load_zone[k] = 1 209 k = find(ppc['bus'][:, BUS_AREA] == 1) ## area 1 210 load_zone[k] = 2 211 t = 'Pd, _ = total_load(bus, gen, load_zone2, \'BOTH\') : ' 212 Pd, _ = total_load(ppc['bus'], ppc['gen'], load_zone, 'BOTH') 213 t_is(Pd, [area[2]['both']['p'], area[0]['both']['p']], 12, [t, 'Pd']) 214 215 t = 'Pd, Qd = total_load(bus, gen, load_zone2, \'BOTH\') : ' 216 Pd, Qd = total_load(ppc['bus'], ppc['gen'], load_zone, 'BOTH') 217 t_is(Pd, [area[2]['both']['p'], area[0]['both']['p']], 12, [t, 'Pd']) 218 t_is(Qd, [area[2]['both']['q'], area[0]['both']['q']], 12, [t, 'Qd']) 219 220 t = 'Pd, _ = total_load(bus, gen, load_zone2, \'FIXED\') : ' 221 Pd, _ = total_load(ppc['bus'], ppc['gen'], load_zone, 'FIXED') 222 t_is(Pd, [area[2]['fixed']['p'], area[0]['fixed']['p']], 12, [t, 'Pd']) 223 224 t = 'Pd, Qd = total_load(bus, gen, load_zone2, \'FIXED\') : ' 225 Pd, Qd = total_load(ppc['bus'], ppc['gen'], load_zone, 'FIXED') 226 t_is(Pd, [area[2]['fixed']['p'], area[0]['fixed']['p']], 12, [t, 'Pd']) 227 t_is(Qd, [area[2]['fixed']['q'], area[0]['fixed']['q']], 12, [t, 'Qd']) 228 229 t = 'Pd, _ = total_load(bus, gen, load_zone2, \'DISPATCHABLE\') : ' 230 Pd, _ = total_load(ppc['bus'], ppc['gen'], load_zone, 'DISPATCHABLE') 231 t_is(Pd, [area[2]['disp']['p'], area[0]['disp']['p']], 12, [t, 'Pd']) 232 233 t = 'Pd, Qd = total_load(bus, gen, load_zone2, \'DISPATCHABLE\') : ' 234 Pd, Qd = total_load(ppc['bus'], ppc['gen'], load_zone, 'DISPATCHABLE') 235 t_is(Pd, [area[2]['disp']['p'], area[0]['disp']['p']], 12, [t, 'Pd']) 236 t_is(Qd, [area[2]['disp']['q'], area[0]['disp']['q']], 12, [t, 'Qd']) 237 238 t_end()
239 240 241 if __name__ == '__main__': 242 t_total_load(quiet=False) 243