1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
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
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
56
57
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
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
127
128
129
130
131
132
133
134
135
136
137 t_end()
138
139
140 if __name__ == '__main__':
141 t_opf_userfcns(quiet=False)
142