1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
54
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
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
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
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
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
101
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
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
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