1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """Tests C{runopf_w_res} and the associated callbacks.
18 """
19
20 from os.path import dirname, join
21
22 from numpy import delete
23
24 from pypower.ppoption import ppoption
25 from pypower.loadcase import loadcase
26 from pypower.runopf_w_res import runopf_w_res
27
28 from pypower.idx_gen import GEN_STATUS, RAMP_10
29
30 from pypower.t.t_begin import t_begin
31 from pypower.t.t_is import t_is
32 from pypower.t.t_end import t_end
33
34
36 """Tests C{runopf_w_res} and the associated callbacks.
37
38 @author: Ray Zimmerman (PSERC Cornell)
39 @author: Richard Lincoln
40 """
41 t_begin(46, quiet)
42
43 verbose = 0
44
45 tdir = dirname(__file__)
46 casefile = join(tdir, 't_case30_userfcns')
47
48 ppopt = ppoption(OPF_VIOLATION=1e-6, PDIPM_GRADTOL=1e-8,
49 PDIPM_COMPTOL=1e-8, PDIPM_COSTTOL=1e-9)
50 ppopt = ppoption(ppopt, OUT_ALL=0, VERBOSE=verbose, OPF_ALG=560)
51
52 t = 'runopf_w_res(''t_case30_userfcns'') : '
53 r = runopf_w_res(casefile, ppopt)
54 t_is(r['reserves']['R'], [25, 15, 0, 0, 19.3906, 0.6094], 4, [t, 'R'])
55 t_is(r['reserves']['prc'], [2, 2, 2, 2, 3.5, 3.5], 6, [t, 'prc'])
56 t_is(r['reserves']['mu']['l'], [0, 0, 1, 2, 0, 0], 7, [t, 'mu.l'])
57 t_is(r['reserves']['mu']['u'], [0.1, 0, 0, 0, 0, 0], 7, [t, 'mu.u'])
58 t_is(r['reserves']['mu']['Pmax'], [0, 0, 0, 0, 0.5, 0], 7, [t, 'mu.Pmax'])
59 ppc = loadcase(casefile)
60 t_is(r['reserves']['cost'], ppc['reserves']['cost'], 12, [t, 'cost'])
61 t_is(r['reserves']['qty'], ppc['reserves']['qty'], 12, [t, 'qty'])
62 t_is(r['reserves']['totalcost'], 177.8047, 4, [t, 'totalcost'])
63
64 t = 'gen 5 no reserves : ';
65 ppc = loadcase(casefile)
66 ppc['reserves']['zones'][:, 4] = 0
67 ppc['reserves']['cost'] = delete(ppc['reserves']['cost'], 4)
68 ppc['reserves']['qty'] = delete(ppc['reserves']['qty'], 4)
69 r = runopf_w_res(ppc, ppopt)
70 t_is(r['reserves']['R'], [25, 15, 0, 0, 0, 20], 4, [t, 'R'])
71 t_is(r['reserves']['prc'], [2, 2, 2, 2, 0, 3.5], 6, [t, 'prc'])
72 t_is(r['reserves']['mu']['l'], [0, 0, 1, 2, 0, 0], 7, [t, 'mu.l'])
73 t_is(r['reserves']['mu']['u'], [0.1, 0, 0, 0, 0, 0], 6, [t, 'mu.u'])
74 t_is(r['reserves']['mu']['Pmax'], [0, 0, 0, 0, 0, 0], 7, [t, 'mu.Pmax'])
75 t_is(r['reserves']['cost'], ppc['reserves']['cost'], 12, [t, 'cost'])
76 t_is(r['reserves']['qty'], ppc['reserves']['qty'], 12, [t, 'qty'])
77 t_is(r['reserves']['totalcost'], 187.5, 4, [t, 'totalcost'])
78
79 t = 'extra offline gen : ';
80 ppc = loadcase(casefile)
81 idx = range(3) +[4]+ range(3, 6)
82 ppc['gen'] = ppc['gen'][idx, :]
83 ppc['gencost'] = ppc['gencost'][idx, :]
84 ppc['reserves']['zones'] = ppc['reserves']['zones'][:, idx]
85 ppc['reserves']['cost'] = ppc['reserves']['cost'][idx]
86 ppc['reserves']['qty'] = ppc['reserves']['qty'][idx]
87 ppc['gen'][3, GEN_STATUS] = 0
88 r = runopf_w_res(ppc, ppopt)
89 t_is(r['reserves']['R'], [25, 15, 0, 0, 0, 19.3906, 0.6094], 4, [t, 'R'])
90 t_is(r['reserves']['prc'], [2, 2, 2, 3.5, 2, 3.5, 3.5], 6, [t, 'prc'])
91 t_is(r['reserves']['mu']['l'], [0, 0, 1, 0, 2, 0, 0], 7, [t, 'mu.l'])
92 t_is(r['reserves']['mu']['u'], [0.1, 0, 0, 0, 0, 0, 0], 7, [t, 'mu.u'])
93 t_is(r['reserves']['mu']['Pmax'], [0, 0, 0, 0, 0, 0.5, 0], 7, [t, 'mu.Pmax'])
94 t_is(r['reserves']['cost'], ppc['reserves']['cost'], 12, [t, 'cost'])
95 t_is(r['reserves']['qty'], ppc['reserves']['qty'], 12, [t, 'qty'])
96 t_is(r['reserves']['totalcost'], 177.8047, 4, [t, 'totalcost'])
97
98 t = 'both extra & gen 6 no res : ';
99 ppc = loadcase(casefile)
100 idx = range(3) +[4]+ range(3, 6)
101 ppc['gen'] = ppc['gen'][idx, :]
102 ppc['gencost'] = ppc['gencost'][idx, :]
103 ppc['reserves']['zones'] = ppc['reserves']['zones'][:, idx]
104 ppc['reserves']['cost'] = ppc['reserves']['cost'][idx]
105 ppc['reserves']['qty'] = ppc['reserves']['qty'][idx]
106 ppc['gen'][3, GEN_STATUS] = 0
107 ppc['reserves']['zones'][:, 5] = 0
108 ppc['reserves']['cost'] = delete(ppc['reserves']['cost'], 5)
109 ppc['reserves']['qty'] = delete(ppc['reserves']['qty'], 5)
110 r = runopf_w_res(ppc, ppopt)
111 t_is(r['reserves']['R'], [25, 15, 0, 0, 0, 0, 20], 4, [t, 'R'])
112 t_is(r['reserves']['prc'], [2, 2, 2, 3.5, 2, 0, 3.5], 6, [t, 'prc'])
113 t_is(r['reserves']['mu']['l'], [0, 0, 1, 0, 2, 0, 0], 7, [t, 'mu.l'])
114 t_is(r['reserves']['mu']['u'], [0.1, 0, 0, 0, 0, 0, 0], 6, [t, 'mu.u'])
115 t_is(r['reserves']['mu']['Pmax'], [0, 0, 0, 0, 0, 0, 0], 7, [t, 'mu.Pmax'])
116 t_is(r['reserves']['cost'], ppc['reserves']['cost'], 12, [t, 'cost'])
117 t_is(r['reserves']['qty'], ppc['reserves']['qty'], 12, [t, 'qty'])
118 t_is(r['reserves']['totalcost'], 187.5, 4, [t, 'totalcost'])
119
120 t = 'no qty (Rmax) : '
121 ppc = loadcase(casefile)
122 del ppc['reserves']['qty']
123 r = runopf_w_res(ppc, ppopt)
124 t_is(r['reserves']['R'], [39.3826, 0.6174, 0, 0, 19.3818, 0.6182], 4, [t, 'R'])
125 t_is(r['reserves']['prc'], [2, 2, 2, 2, 3.5, 3.5], 5, [t, 'prc'])
126 t_is(r['reserves']['mu']['l'], [0, 0, 1, 2, 0, 0], 5, [t, 'mu.l'])
127 t_is(r['reserves']['mu']['u'], [0, 0, 0, 0, 0, 0], 7, [t, 'mu.u'])
128 t_is(r['reserves']['mu']['Pmax'], [0.1, 0, 0, 0, 0.5, 0], 5, [t, 'mu.Pmax'])
129 t_is(r['reserves']['cost'], ppc['reserves']['cost'], 12, [t, 'cost'])
130 t_is(r['reserves']['totalcost'], 176.3708, 4, [t, 'totalcost'])
131
132 t = 'RAMP_10, no qty (Rmax) : ';
133 ppc = loadcase(casefile)
134 del ppc['reserves']['qty']
135 ppc['gen'][0, RAMP_10] = 25
136 r = runopf_w_res(ppc, ppopt)
137 t_is(r['reserves']['R'], [25, 15, 0, 0, 19.3906, 0.6094], 4, [t, 'R'])
138 t_is(r['reserves']['prc'], [2, 2, 2, 2, 3.5, 3.5], 6, [t, 'prc'])
139 t_is(r['reserves']['mu']['l'], [0, 0, 1, 2, 0, 0], 7, [t, 'mu.l'])
140 t_is(r['reserves']['mu']['u'], [0.1, 0, 0, 0, 0, 0], 7, [t, 'mu.u'])
141 t_is(r['reserves']['mu']['Pmax'], [0, 0, 0, 0, 0.5, 0], 7, [t, 'mu.Pmax'])
142 t_is(r['reserves']['cost'], ppc['reserves']['cost'], 12, [t, 'cost'])
143 t_is(r['reserves']['totalcost'], 177.8047, 4, [t, 'totalcost'])
144
145 t_end()
146
147
148 if __name__ == '__main__':
149 t_runopf_w_res(quiet=False)
150