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

Source Code for Module pypower.t.t_opf_userfcns

  1  # Copyright (C) 2009-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 userfcn callbacks (reserves/iflims) w/OPF. 
 18  """ 
 19   
 20  from os.path import dirname, join 
 21   
 22  from pypower.ppoption import ppoption 
 23  from pypower.loadcase import loadcase 
 24  from pypower.toggle_reserves import toggle_reserves 
 25  from pypower.toggle_iflims import toggle_iflims 
 26  from pypower.runopf import runopf 
 27  from pypower.rundcopf import rundcopf 
 28   
 29  from pypower.idx_brch import PF, BR_STATUS 
 30   
 31  from pypower.t.t_begin import t_begin 
 32  from pypower.t.t_is import t_is 
 33  from pypower.t.t_ok import t_ok 
 34  from pypower.t.t_end import t_end 
 35   
 36   
37 -def t_opf_userfcns(quiet=False):
38 """Tests for userfcn callbacks (reserves/iflims) w/OPF. 39 40 Includes high-level tests of reserves and iflims implementations. 41 42 @author: Ray Zimmerman (PSERC Cornell) 43 @author: Richard Lincoln 44 """ 45 t_begin(38, quiet) 46 47 tdir = dirname(__file__) 48 casefile = join(tdir, 't_case30_userfcns') 49 verbose = 0#not quiet 50 51 ppopt = ppoption(OPF_VIOLATION=1e-6, PDIPM_GRADTOL=1e-8, 52 PDIPM_COMPTOL=1e-8, PDIPM_COSTTOL=1e-9) 53 ppopt = ppoption(ppopt, OUT_ALL=0, VERBOSE=verbose, 54 OPF_ALG=560, OPF_ALG_DC=200) 55 #ppopt = ppoption(ppopt, OUT_ALL=-1, VERBOSE=2, OUT_GEN=1) 56 57 ## run the OPF with fixed reserves 58 t = 'fixed reserves : ' 59 ppc = loadcase(casefile) 60 ppc = toggle_reserves(ppc, 'on') 61 r = runopf(ppc, ppopt) 62 t_ok(r['success'], [t, 'success']) 63 t_is(r['reserves']['R'], [25, 15, 0, 0, 19.3906, 0.6094], 4, [t, 'reserves.R']) 64 t_is(r['reserves']['prc'], [2, 2, 2, 2, 3.5, 3.5], 4, [t, 'reserves.prc']) 65 t_is(r['reserves']['mu']['Pmax'], [0, 0, 0, 0, 0.5, 0], 4, [t, 'reserves.mu.Pmax']) 66 t_is(r['reserves']['mu']['l'], [0, 0, 1, 2, 0, 0], 4, [t, 'reserves.mu.l']) 67 t_is(r['reserves']['mu']['u'], [0.1, 0, 0, 0, 0, 0], 4, [t, 'reserves.mu.u']) 68 t_ok('P' not in r['if'], [t, 'no iflims']) 69 t_is(r['reserves']['totalcost'], 177.8047, 4, [t, 'totalcost']) 70 71 t = 'toggle_reserves(ppc, \'off\') : '; 72 ppc = toggle_reserves(ppc, 'off') 73 r = runopf(ppc, ppopt) 74 t_ok(r['success'], [t, 'success']) 75 t_ok('R' not in r['reserves'], [t, 'no reserves']) 76 t_ok('P' not in r['if'], [t, 'no iflims']) 77 78 t = 'interface flow lims (DC) : ' 79 ppc = loadcase(casefile) 80 ppc = toggle_iflims(ppc, 'on') 81 r = rundcopf(ppc, ppopt) 82 t_ok(r['success'], [t, 'success']) 83 t_is(r['if']['P'], [-15, 20], 4, [t, 'if.P']) 84 t_is(r['if']['mu']['l'], [4.8427, 0], 4, [t, 'if.mu.l']) 85 t_is(r['if']['mu']['u'], [0, 13.2573], 4, [t, 'if.mu.u']) 86 t_is(r['branch'][13, PF], 8.244, 3, [t, 'flow in branch 14']) 87 t_ok('R' not in r['reserves'], [t, 'no reserves']) 88 89 t = 'reserves + interface flow lims (DC) : ' 90 ppc = loadcase(casefile) 91 ppc = toggle_reserves(ppc, 'on') 92 ppc = toggle_iflims(ppc, 'on') 93 r = rundcopf(ppc, ppopt) 94 t_ok(r['success'], [t, 'success']) 95 t_is(r['if']['P'], [-15, 20], 4, [t, 'if.P']) 96 t_is(r['if']['mu']['l'], [4.8427, 0], 4, [t, 'if.mu.l']) 97 t_is(r['if']['mu']['u'], [0, 38.2573], 4, [t, 'if.mu.u']) 98 t_is(r['reserves']['R'], [25, 15, 0, 0, 16.9, 3.1], 4, [t, 'reserves.R']) 99 t_is(r['reserves']['prc'], [2, 2, 2, 2, 3.5, 3.5], 4, [t, 'reserves.prc']) 100 t_is(r['reserves']['mu']['Pmax'], [0, 0, 0, 0, 0.5, 0], 4, [t, 'reserves.mu.Pmax']) 101 t_is(r['reserves']['mu']['l'], [0, 0, 1, 2, 0, 0], 4, [t, 'reserves.mu.l']) 102 t_is(r['reserves']['mu']['u'], [0.1, 0, 0, 0, 0, 0], 4, [t, 'reserves.mu.u']) 103 t_is(r['reserves']['totalcost'], 179.05, 4, [t, 'totalcost']) 104 105 t = 'interface flow lims (AC) : ' 106 ppc = toggle_reserves(ppc, 'off') 107 r = runopf(ppc, ppopt) 108 t_ok(r['success'], [t, 'success']) 109 t_is(r['if']['P'], [-9.101, 21.432], 3, [t, 'if.P']) 110 t_is(r['if']['mu']['l'], [0, 0], 4, [t, 'if.mu.l']) 111 t_is(r['if']['mu']['u'], [0, 10.198], 3, [t, 'if.mu.u']) 112 t_ok('R' not in r['reserves'], [t, 'no reserves']) 113 114 t = 'interface flow lims (line out) : ' 115 ppc = loadcase(casefile) 116 ppc = toggle_iflims(ppc, 'on') 117 ppc['branch'][11, BR_STATUS] = 0 ## take out line 6-10 118 r = rundcopf(ppc, ppopt) 119 t_ok(r['success'], [t, 'success']) 120 t_is(r['if']['P'], [-15, 20], 4, [t, 'if.P']) 121 t_is(r['if']['mu']['l'], [4.8427, 0], 4, [t, 'if.mu.l']) 122 t_is(r['if']['mu']['u'], [0, 13.2573], 4, [t, 'if.mu.u']) 123 t_is(r['branch'][13, PF], 10.814, 3, [t, 'flow in branch 14']) 124 t_ok('R' not in r['reserves'], [t, 'no reserves']) 125 126 # r['reserves']['R'] 127 # r['reserves']['prc'] 128 # r['reserves']['mu.Pmax'] 129 # r['reserves']['mu']['l'] 130 # r['reserves']['mu']['u'] 131 # r['reserves']['totalcost'] 132 # 133 # r['if']['P'] 134 # r['if']['mu']['l'] 135 # r['if']['mu']['u'] 136 137 t_end()
138 139 140 if __name__ == '__main__': 141 t_opf_userfcns(quiet=False) 142