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

Source Code for Module pypower.t.t_pf

  1  # Copyright (C) 2004-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 power flow solvers. 
 18  """ 
 19   
 20  from os.path import dirname, join 
 21   
 22  from numpy import array, r_ 
 23   
 24  from scipy.io import loadmat 
 25   
 26  from pypower.ppoption import ppoption 
 27  from pypower.loadcase import loadcase 
 28  from pypower.runpf import runpf 
 29  from pypower.rundcpf import rundcpf 
 30   
 31  from pypower.idx_gen import QG, QMIN, QMAX 
 32   
 33  from pypower.t.t_begin import t_begin 
 34  from pypower.t.t_is import t_is 
 35  from pypower.t.t_ok import t_ok 
 36  from pypower.t.t_end import t_end 
 37   
 38   
39 -def t_pf(quiet=False):
40 """Tests for power flow solvers. 41 42 @author: Ray Zimmerman (PSERC Cornell) 43 @author: Richard Lincoln 44 """ 45 t_begin(25, quiet) 46 47 tdir = dirname(__file__) 48 casefile = join(tdir, 't_case9_pf') 49 verbose = not quiet 50 51 ppopt = ppoption(VERBOSE=verbose, OUT_ALL=0) 52 53 ## get solved AC power flow case from MAT-file 54 ## defines bus_soln, gen_soln, branch_soln 55 soln9_pf = loadmat(join(tdir, 'soln9_pf.mat'), struct_as_record=False) 56 bus_soln = soln9_pf['bus_soln'] 57 gen_soln = soln9_pf['gen_soln'] 58 branch_soln = soln9_pf['branch_soln'] 59 60 ## run Newton PF 61 t = 'Newton PF : '; 62 ppopt = ppoption(ppopt, PF_ALG=1) 63 results, success = runpf(casefile, ppopt) 64 bus, gen, branch = results['bus'], results['gen'], results['branch'] 65 t_ok(success, [t, 'success']) 66 t_is(bus, bus_soln, 6, [t, 'bus']) 67 t_is(gen, gen_soln, 6, [t, 'gen']) 68 t_is(branch, branch_soln, 6, [t, 'branch']) 69 70 ## run fast-decoupled PF (XB version) 71 t = 'Fast Decoupled (XB) PF : '; 72 ppopt = ppoption(ppopt, PF_ALG=2) 73 results, success = runpf(casefile, ppopt) 74 bus, gen, branch = results['bus'], results['gen'], results['branch'] 75 t_ok(success, [t, 'success']) 76 t_is(bus, bus_soln, 6, [t, 'bus']) 77 t_is(gen, gen_soln, 6, [t, 'gen']) 78 t_is(branch, branch_soln, 6, [t, 'branch']) 79 80 ## run fast-decoupled PF (BX version) 81 t = 'Fast Decoupled (BX) PF : '; 82 ppopt = ppoption(ppopt, PF_ALG=3) 83 results, success = runpf(casefile, ppopt) 84 bus, gen, branch = results['bus'], results['gen'], results['branch'] 85 t_ok(success, [t, 'success']) 86 t_is(bus, bus_soln, 6, [t, 'bus']) 87 t_is(gen, gen_soln, 6, [t, 'gen']) 88 t_is(branch, branch_soln, 6, [t, 'branch']) 89 90 ## run Gauss-Seidel PF 91 t = 'Gauss-Seidel PF : '; 92 ppopt = ppoption(ppopt, PF_ALG=4) 93 results, success = runpf(casefile, ppopt) 94 bus, gen, branch = results['bus'], results['gen'], results['branch'] 95 t_ok(success, [t, 'success']) 96 t_is(bus, bus_soln, 5, [t, 'bus']) 97 t_is(gen, gen_soln, 5, [t, 'gen']) 98 t_is(branch, branch_soln, 5, [t, 'branch']) 99 100 ## get solved AC power flow case from MAT-file 101 ## defines bus_soln, gen_soln, branch_soln 102 soln9_dcpf = loadmat(join(tdir, 'soln9_dcpf.mat'), struct_as_record=False) 103 bus_soln = soln9_dcpf['bus_soln'] 104 gen_soln = soln9_dcpf['gen_soln'] 105 branch_soln = soln9_dcpf['branch_soln'] 106 107 ## run DC PF 108 t = 'DC PF : ' 109 results, success = rundcpf(casefile, ppopt) 110 bus, gen, branch = results['bus'], results['gen'], results['branch'] 111 t_ok(success, [t, 'success']) 112 t_is(bus, bus_soln, 6, [t, 'bus']) 113 t_is(gen, gen_soln, 6, [t, 'gen']) 114 t_is(branch, branch_soln, 6, [t, 'branch']) 115 116 ## check Qg distribution, when Qmin = Qmax 117 t = 'check Qg : ' 118 ppopt = ppoption(ppopt, PF_ALG=1, VERBOSE=0) 119 ppc = loadcase(casefile) 120 ppc['gen'][0, [QMIN, QMAX]] = [20, 20] 121 results, success = runpf(ppc, ppopt) 122 bus, gen, branch = results['bus'], results['gen'], results['branch'] 123 t_is(gen[0, QG], 24.07, 2, [t, 'single gen, Qmin = Qmax']) 124 125 ppc['gen'] = r_[array([ ppc['gen'][0, :] ]), ppc['gen']] 126 ppc['gen'][0, [QMIN, QMAX]] = [10, 10] 127 ppc['gen'][1, [QMIN, QMAX]] = [ 0, 50] 128 results, success = runpf(ppc, ppopt) 129 bus, gen, branch = results['bus'], results['gen'], results['branch'] 130 t_is(gen[0:2, QG], [10, 14.07], 2, [t, '2 gens, Qmin = Qmax for one']) 131 132 ppc['gen'][0, [QMIN, QMAX]] = [10, 10] 133 ppc['gen'][1, [QMIN, QMAX]] = [-50, -50] 134 results, success = runpf(ppc, ppopt) 135 bus, gen, branch = results['bus'], results['gen'], results['branch'] 136 t_is(gen[0:2, QG], [12.03, 12.03], 2, [t, '2 gens, Qmin = Qmax for both']) 137 138 ppc['gen'][0, [QMIN, QMAX]] = [0, 50] 139 ppc['gen'][1, [QMIN, QMAX]] = [0, 100] 140 results, success = runpf(ppc, ppopt) 141 bus, gen, branch = results['bus'], results['gen'], results['branch'] 142 t_is(gen[0:2, QG], [8.02, 16.05], 2, [t, '2 gens, proportional']) 143 144 ppc['gen'][0, [QMIN, QMAX]] = [-50, 0] 145 ppc['gen'][1, [QMIN, QMAX]] = [50, 150] 146 results, success = runpf(ppc, ppopt) 147 bus, gen, branch = results['bus'], results['gen'], results['branch'] 148 t_is(gen[0:2, QG], [-50 + 8.02, 50 + 16.05], 2, [t, '2 gens, proportional']) 149 150 t_end()
151 152 153 if __name__ == '__main__': 154 t_pf(quiet=False) 155