1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
39 if casedata is None:
40 casedata = join(dirname(__file__), 'case9')
41 ppopt = ppoption(ppopt)
42
43
44 r = opf(casedata, ppopt)
45
46
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
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