Package pypower :: Module runopf
[hide private]
[frames] | no frames]

Source Code for Module pypower.runopf

 1  # Copyright (C) 1996-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  """Runs an optimal power flow. 
18  """ 
19   
20  from sys import stdout, stderr 
21   
22  from os.path import dirname, join 
23   
24  from pypower.ppoption import ppoption 
25  from pypower.opf import opf 
26  from pypower.printpf import printpf 
27  from pypower.savecase import savecase 
28   
29   
30 -def runopf(casedata=None, ppopt=None, fname='', solvedcase=''):
31 """Runs an optimal power flow. 32 33 @see: L{rundcopf}, L{runuopf} 34 35 @author: Ray Zimmerman (PSERC Cornell) 36 @author: Richard Lincoln 37 """ 38 ## default arguments 39 if casedata is None: 40 casedata = join(dirname(__file__), 'case9') 41 ppopt = ppoption(ppopt) 42 43 ##----- run the optimal power flow ----- 44 r = opf(casedata, ppopt) 45 46 ##----- output results ----- 47 if fname: 48 fd = None 49 try: 50 fd = open(fname, "wb") 51 except IOError, detail: 52 stderr.write("Error opening %s: %s.\n" % (fname, detail)) 53 finally: 54 if fd is not None: 55 printpf(r, fd, ppopt) 56 fd.close() 57 58 printpf(r, stdout, ppopt) 59 60 ## save solved case 61 if solvedcase: 62 savecase(solvedcase, r) 63 64 return r
65 66 67 if __name__ == '__main__': 68 ppopt = ppoption(OPF_ALG=580) 69 runopf(None, ppopt) 70