1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """Tests for C{makeLODF}.
18 """
19
20 from os.path import dirname, join
21
22 from numpy import arange, r_
23
24 from pypower.loadcase import loadcase
25 from pypower.ppoption import ppoption
26 from pypower.rundcopf import rundcopf
27 from pypower.ext2int import ext2int1
28 from pypower.makePTDF import makePTDF
29 from pypower.makeLODF import makeLODF
30 from pypower.rundcpf import rundcpf
31
32 from pypower.idx_brch import BR_STATUS, PF
33
34 from pypower.t.t_begin import t_begin
35 from pypower.t.t_is import t_is
36 from pypower.t.t_end import t_end
37
38
40 """Tests for C{makeLODF}.
41
42 @author: Ray Zimmerman (PSERC Cornell)
43 @author: Richard Lincoln
44 """
45 ntests = 31
46 t_begin(ntests, quiet)
47
48 tdir = dirname(__file__)
49 casefile = join(tdir, 't_auction_case')
50 verbose = 0
51
52
53 ppc = loadcase(casefile)
54 ppopt = ppoption(VERBOSE=verbose, OUT_ALL=0)
55 r = rundcopf(ppc, ppopt)
56 baseMVA, bus, gen, branch = r['baseMVA'], r['bus'], r['gen'], r['branch']
57 _, bus, gen, branch = ext2int1(bus, gen, branch)
58
59
60 F0 = branch[:, PF]
61
62
63 H = makePTDF(baseMVA, bus, branch, 0)
64
65
66 try:
67 LODF = makeLODF(branch, H)
68 except ZeroDivisionError:
69 pass
70
71
72 ppc['bus'] = bus
73 ppc['gen'] = gen
74 branch0 = branch
75 outages = r_[arange(12), arange(13, 15), arange(16, 18),
76 [19], arange(26, 33), arange(34, 41)]
77 for k in outages:
78 ppc['branch'] = branch0.copy()
79 ppc['branch'][k, BR_STATUS] = 0
80 r, _ = rundcpf(ppc, ppopt)
81 baseMVA, bus, gen, branch = \
82 r['baseMVA'], r['bus'], r['gen'], r['branch']
83 F = branch[:, PF]
84
85 t_is(LODF[:, k], (F - F0) / F0[k], 6, 'LODF[:, %d]' % k)
86
87 t_end()
88
89
90 if __name__ == '__main__':
91 t_makeLODF(quiet=False)
92