本文整理汇总了Python中pypower.t.t_end.t_end函数的典型用法代码示例。如果您正苦于以下问题:Python t_end函数的具体用法?Python t_end怎么用?Python t_end使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了t_end函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: t_totcost
def t_totcost(quiet=False):
"""Tests for code in C{totcost}.
@author: Ray Zimmerman (PSERC Cornell)
@author: Richard Lincoln
"""
n_tests = 22
t_begin(n_tests, quiet)
## generator cost data
# 1 startup shutdown n x1 y1 ... xn yn
# 2 startup shutdown n c(n-1) ... c0
gencost = array([
[2, 0, 0, 3, 0.01, 0.1, 1, 0, 0, 0, 0, 0],
[2, 0, 0, 5, 0.0006, 0.005, 0.04, 0.3, 2, 0, 0, 0],
[1, 0, 0, 4, 0, 0, 10, 200, 20, 600, 30, 1200],
[1, 0, 0, 4, -30, -2400, -20, -1800, -10, -1000, 0, 0]
])
t = 'totcost - quadratic'
t_is(totcost(gencost, array([0, 0, 0, 0])), [1, 2, 0, 0], 8, t)
t_is(totcost(gencost, array([1, 0, 0, 0])), [1.11, 2, 0, 0], 8, t)
t_is(totcost(gencost, array([2, 0, 0, 0])), [1.24, 2, 0, 0], 8, t)
t = 'totcost - 4th order polynomial'
t_is(totcost(gencost, array([0, 0, 0, 0])), [1, 2, 0, 0], 8, t)
t_is(totcost(gencost, array([0, 1, 0, 0])), [1, 2.3456, 0, 0], 8, t)
t_is(totcost(gencost, array([0, 2, 0, 0])), [1, 2.8096, 0, 0], 8, t)
t = 'totcost - pwl (gen)'
t_is(totcost(gencost, array([0, 0, -10, 0 ])), [1, 2, -200, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 5, 0 ])), [1, 2, 100, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 10, 0])), [1, 2, 200, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 15, 0])), [1, 2, 400, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 20, 0])), [1, 2, 600, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 25, 0])), [1, 2, 900, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 30, 0])), [1, 2, 1200, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 35, 0])), [1, 2, 1500, 0], 8, t)
t = 'totcost - pwl (load)'
t_is(totcost(gencost, array([0, 0, 0, 10 ])), [1, 2, 0, 1000], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -5 ])), [1, 2, 0, -500], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -10])), [1, 2, 0, -1000], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -15])), [1, 2, 0, -1400], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -20])), [1, 2, 0, -1800], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -25])), [1, 2, 0, -2100], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -30])), [1, 2, 0, -2400], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -35])), [1, 2, 0, -2700], 8, t)
t_end()
开发者ID:AdrianBajdiuk,项目名称:PowerGridResillience,代码行数:51,代码来源:t_totcost.py
示例2: t_makeLODF
def t_makeLODF(quiet=False):
"""Tests for C{makeLODF}.
@author: Ray Zimmerman (PSERC Cornell)
@author: Richard Lincoln
"""
ntests = 31
t_begin(ntests, quiet)
tdir = dirname(__file__)
casefile = join(tdir, 't_auction_case')
verbose = 0#not quiet
## load case
ppc = loadcase(casefile)
ppopt = ppoption(VERBOSE=verbose, OUT_ALL=0)
r = rundcopf(ppc, ppopt)
baseMVA, bus, gen, branch = r['baseMVA'], r['bus'], r['gen'], r['branch']
_, bus, gen, branch = ext2int1(bus, gen, branch)
## compute injections and flows
F0 = branch[:, PF]
## create some PTDF matrices
H = makePTDF(baseMVA, bus, branch, 0)
## create some PTDF matrices
try:
LODF = makeLODF(branch, H)
except ZeroDivisionError:
pass
## take out non-essential lines one-by-one and see what happens
ppc['bus'] = bus
ppc['gen'] = gen
branch0 = branch
outages = r_[arange(12), arange(13, 15), arange(16, 18),
[19], arange(26, 33), arange(34, 41)]
for k in outages:
ppc['branch'] = branch0.copy()
ppc['branch'][k, BR_STATUS] = 0
r, _ = rundcpf(ppc, ppopt)
baseMVA, bus, gen, branch = \
r['baseMVA'], r['bus'], r['gen'], r['branch']
F = branch[:, PF]
t_is(LODF[:, k], (F - F0) / F0[k], 6, 'LODF[:, %d]' % k)
t_end()
开发者ID:charlie0389,项目名称:PYPOWER,代码行数:49,代码来源:t_makeLODF.py
示例3: t_hasPQcap
def t_hasPQcap(quiet=False):
"""Tests for C{hasPQcap}.
@author: Ray Zimmerman (PSERC Cornell)
@author: Richard Lincoln
"""
t_begin(4, quiet)
## generator data
# bus Pg Qg Qmax Qmin Vg mBase status Pmax Pmin Pc1 Pc2 Qc1min Qc1max Qc2min Qc2max ramp_agc ramp_10 ramp_30 ramp_q apf
gen = array([
[1, 10, 0, 10, -10, 1, 100, 1, 10, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 10, 0, 10, -10, 1, 100, 1, 10, 2, 0, 20, 0, 12, 0, 2, 0, 0, 0, 0, 0],
[1, 10, 0, 10, -10, 1, 100, 1, 10, 2, 0, 20, -15, 12, -15, 2, 0, 0, 0, 0, 0],
[1, 10, 0, 10, -10, 1, 100, 1, 10, 2, 0, 20, -12, 0, -2, 0, 0, 0, 0, 0, 0],
[1, 10, 0, 10, -10, 1, 100, 1, 10, 2, 0, 20, -12, 15, -2, 15, 0, 0, 0, 0, 0],
[1, 10, 0, 10, -10, 1, 100, 1, 10, 2, 0, 20, -12, 12, -2, 2, 0, 0, 0, 0, 0],
[1, 10, 0, 10, -10, 1, 100, 1, 10, 2, 0, 20, 0, 12, 0, 8, 0, 0, 0, 0, 0],
[1, 10, 0, 10, -10, 1, 100, 1, 10, 2, 0, 20, -15, 12, -15, 8, 0, 0, 0, 0, 0],
[1, 10, 0, 10, -10, 1, 100, 1, 10, 2, 0, 20, -12, 0, -8, 0, 0, 0, 0, 0, 0],
[1, 10, 0, 10, -10, 1, 100, 1, 10, 2, 0, 20, -12, 15, -8, 15, 0, 0, 0, 0, 0],
[1, 10, 0, 10, -10, 1, 100, 1, 10, 2, 0, 20, -12, 12, -8, 8, 0, 0, 0, 0, 0]
])
t = 'hasPQcap(gen)'
t_is(hasPQcap(gen), [0,1,1,1,1,1,1,0,1,0,0], 12, t)
t = 'hasPQcap(gen, \'B\')'
t_is(hasPQcap(gen, 'B'), [0,1,1,1,1,1,1,0,1,0,0], 12, t)
t = 'hasPQcap(gen, \'U\')'
t_is(hasPQcap(gen, 'U'), [0,1,1,1,0,1,0,0,1,0,0], 12, t)
t = 'hasPQcap(gen, \'L\')'
t_is(hasPQcap(gen, 'L'), [0,1,0,1,1,1,1,0,0,0,0], 12, t)
t_end()
开发者ID:charlie0389,项目名称:PYPOWER,代码行数:37,代码来源:t_hasPQcap.py
示例4: t_loadcase
#.........这里部分代码省略.........
ppc1 = loadcase(pfmatfile + '.mat')
t_is(ppc1['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
t_is(ppc1['bus'], bus, 12, [t, 'bus'])
t_is(ppc1['gen'], gen, 12, [t, 'gen'])
t_is(ppc1['branch'], branch, 12, [t, 'branch'])
t = 'ppc = loadcase(pf_PY_file_v2) without .py extension : '
ppc1 = loadcase(pfcasefilev2)
t_is(ppc1['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
t_is(ppc1['bus'], bus, 12, [t, 'bus'])
t_is(ppc1['gen'], gen, 12, [t, 'gen'])
t_is(ppc1['branch'], branch, 12, [t, 'branch'])
t = 'ppc = loadcase(pf_PY_file_v2) with .py extension : '
ppc1 = loadcase(pfcasefilev2 + '.py')
t_is(ppc1['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
t_is(ppc1['bus'], bus, 12, [t, 'bus'])
t_is(ppc1['gen'], gen, 12, [t, 'gen'])
t_is(ppc1['branch'], branch, 12, [t, 'branch'])
t = 'ppc = loadcase(pf_MAT_file_v2) without .mat extension : '
ppc1 = loadcase(pfmatfilev2)
t_is(ppc1['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
t_is(ppc1['bus'], bus, 12, [t, 'bus'])
t_is(ppc1['gen'], gen, 12, [t, 'gen'])
t_is(ppc1['branch'], branch, 12, [t, 'branch'])
t = 'ppc = loadcase(pf_MAT_file_v2) with .mat extension : '
ppc1 = loadcase(pfmatfilev2 + '.mat')
t_is(ppc1['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
t_is(ppc1['bus'], bus, 12, [t, 'bus'])
t_is(ppc1['gen'], gen, 12, [t, 'gen'])
t_is(ppc1['branch'], branch, 12, [t, 'branch'])
t = 'ppc = loadcase(pf_struct_v1) (no version): '
baseMVA1, bus1, gen1, branch1 = t_case9_pf()
c = {}
c['baseMVA'] = baseMVA1
c['bus'] = bus1.copy()
c['gen'] = gen1.copy()
c['branch'] = branch1.copy()
ppc2 = loadcase(c)
t_is(ppc2['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
t_is(ppc2['bus'], bus, 12, [t, 'bus'])
t_is(ppc2['gen'], gen, 12, [t, 'gen'])
t_is(ppc2['branch'], branch, 12, [t, 'branch'])
t = 'ppc = loadcase(pf_struct_v1) (version=''1''): '
c['version'] = '1'
ppc2 = loadcase(c)
t_is(ppc2['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
t_is(ppc2['bus'], bus, 12, [t, 'bus'])
t_is(ppc2['gen'], gen, 12, [t, 'gen'])
t_is(ppc2['branch'], branch, 12, [t, 'branch'])
t = 'ppc = loadcase(pf_struct_v2) : '
c = {}
c['baseMVA'] = baseMVA
c['bus'] = bus.copy()
c['gen'] = gen.copy()
c['branch'] = branch.copy()
c['version'] = '2'
ppc2 = loadcase(c)
t_is(ppc2['baseMVA'], baseMVA, 12, [t, 'baseMVA'])
t_is(ppc2['bus'], bus, 12, [t, 'bus'])
t_is(ppc2['gen'], gen, 12, [t, 'gen'])
t_is(ppc2['branch'], branch, 12, [t, 'branch'])
## cleanup
os.remove(matfile + '.mat')
os.remove(pfmatfile + '.mat')
os.remove(matfilev2 + '.mat')
os.remove(pfmatfilev2 + '.mat')
t = 'runpf(my_PY_file)'
ppopt = ppoption(VERBOSE=0, OUT_ALL=0)
results3, success = runpf(pfcasefile, ppopt)
baseMVA3, bus3, gen3, branch3 = results3['baseMVA'], results3['bus'], \
results3['gen'], results3['branch']
t_ok( success, t )
t = 'runpf(my_object)'
results4, success = runpf(c, ppopt)
baseMVA4, bus4, gen4, branch4 = results4['baseMVA'], results4['bus'], \
results4['gen'], results4['branch']
t_ok( success, t )
t = 'runpf result comparison : '
t_is(baseMVA3, baseMVA4, 12, [t, 'baseMVA'])
t_is(bus3, bus4, 12, [t, 'bus'])
t_is(gen3, gen4, 12, [t, 'gen'])
t_is(branch3, branch4, 12, [t, 'branch'])
t = 'runpf(modified_struct)'
c['gen'][2, 1] = c['gen'][2, 1] + 1 ## increase gen 3 output by 1
results5, success = runpf(c, ppopt)
gen5 = results5['gen']
t_is(gen5[0, 1], gen4[0, 1] - 1, 1, t) ## slack bus output should decrease by 1
t_end()
开发者ID:charlie0389,项目名称:PYPOWER,代码行数:101,代码来源:t_loadcase.py
示例5: t_runopf_w_res
#.........这里部分代码省略.........
casefile = join(tdir, 't_case30_userfcns')
ppopt = ppoption(OPF_VIOLATION=1e-6, PDIPM_GRADTOL=1e-8,
PDIPM_COMPTOL=1e-8, PDIPM_COSTTOL=1e-9)
ppopt = ppoption(ppopt, OUT_ALL=0, VERBOSE=verbose, OPF_ALG=560)
t = 'runopf_w_res(''t_case30_userfcns'') : '
r = runopf_w_res(casefile, ppopt)
t_is(r['reserves']['R'], [25, 15, 0, 0, 19.3906, 0.6094], 4, [t, 'R'])
t_is(r['reserves']['prc'], [2, 2, 2, 2, 5.5, 5.5], 6, [t, 'prc'])
t_is(r['reserves']['mu']['l'], [0, 0, 1, 2, 0, 0], 7, [t, 'mu.l'])
t_is(r['reserves']['mu']['u'], [0.1, 0, 0, 0, 0, 0], 7, [t, 'mu.u'])
t_is(r['reserves']['mu']['Pmax'], [0, 0, 0, 0, 0.5, 0], 7, [t, 'mu.Pmax'])
ppc = loadcase(casefile)
t_is(r['reserves']['cost'], ppc['reserves']['cost'], 12, [t, 'cost'])
t_is(r['reserves']['qty'], ppc['reserves']['qty'], 12, [t, 'qty'])
t_is(r['reserves']['totalcost'], 177.8047, 4, [t, 'totalcost'])
t = 'gen 5 no reserves : ';
ppc = loadcase(casefile)
ppc['reserves']['zones'][:, 4] = 0
ppc['reserves']['cost'] = delete(ppc['reserves']['cost'], 4)
ppc['reserves']['qty'] = delete(ppc['reserves']['qty'], 4)
r = runopf_w_res(ppc, ppopt)
t_is(r['reserves']['R'], [25, 15, 0, 0, 0, 20], 4, [t, 'R'])
t_is(r['reserves']['prc'], [2, 2, 2, 2, 0, 5.5], 6, [t, 'prc'])
t_is(r['reserves']['mu']['l'], [0, 0, 1, 2, 0, 0], 7, [t, 'mu.l'])
t_is(r['reserves']['mu']['u'], [0.1, 0, 0, 0, 0, 0], 6, [t, 'mu.u'])
t_is(r['reserves']['mu']['Pmax'], [0, 0, 0, 0, 0, 0], 7, [t, 'mu.Pmax'])
t_is(r['reserves']['cost'], ppc['reserves']['cost'], 12, [t, 'cost'])
t_is(r['reserves']['qty'], ppc['reserves']['qty'], 12, [t, 'qty'])
t_is(r['reserves']['totalcost'], 187.5, 4, [t, 'totalcost'])
t = 'extra offline gen : ';
ppc = loadcase(casefile)
idx = list(range(3)) + [4] + list(range(3, 6))
ppc['gen'] = ppc['gen'][idx, :]
ppc['gencost'] = ppc['gencost'][idx, :]
ppc['reserves']['zones'] = ppc['reserves']['zones'][:, idx]
ppc['reserves']['cost'] = ppc['reserves']['cost'][idx]
ppc['reserves']['qty'] = ppc['reserves']['qty'][idx]
ppc['gen'][3, GEN_STATUS] = 0
r = runopf_w_res(ppc, ppopt)
t_is(r['reserves']['R'], [25, 15, 0, 0, 0, 19.3906, 0.6094], 4, [t, 'R'])
t_is(r['reserves']['prc'], [2, 2, 2, 5.5, 2, 5.5, 5.5], 6, [t, 'prc'])
t_is(r['reserves']['mu']['l'], [0, 0, 1, 0, 2, 0, 0], 7, [t, 'mu.l'])
t_is(r['reserves']['mu']['u'], [0.1, 0, 0, 0, 0, 0, 0], 7, [t, 'mu.u'])
t_is(r['reserves']['mu']['Pmax'], [0, 0, 0, 0, 0, 0.5, 0], 7, [t, 'mu.Pmax'])
t_is(r['reserves']['cost'], ppc['reserves']['cost'], 12, [t, 'cost'])
t_is(r['reserves']['qty'], ppc['reserves']['qty'], 12, [t, 'qty'])
t_is(r['reserves']['totalcost'], 177.8047, 4, [t, 'totalcost'])
t = 'both extra & gen 6 no res : ';
ppc = loadcase(casefile)
idx = list(range(3)) + [4] + list(range(3, 6))
ppc['gen'] = ppc['gen'][idx, :]
ppc['gencost'] = ppc['gencost'][idx, :]
ppc['reserves']['zones'] = ppc['reserves']['zones'][:, idx]
ppc['reserves']['cost'] = ppc['reserves']['cost'][idx]
ppc['reserves']['qty'] = ppc['reserves']['qty'][idx]
ppc['gen'][3, GEN_STATUS] = 0
ppc['reserves']['zones'][:, 5] = 0
ppc['reserves']['cost'] = delete(ppc['reserves']['cost'], 5)
ppc['reserves']['qty'] = delete(ppc['reserves']['qty'], 5)
r = runopf_w_res(ppc, ppopt)
t_is(r['reserves']['R'], [25, 15, 0, 0, 0, 0, 20], 4, [t, 'R'])
t_is(r['reserves']['prc'], [2, 2, 2, 5.5, 2, 0, 5.5], 6, [t, 'prc'])
t_is(r['reserves']['mu']['l'], [0, 0, 1, 0, 2, 0, 0], 7, [t, 'mu.l'])
t_is(r['reserves']['mu']['u'], [0.1, 0, 0, 0, 0, 0, 0], 6, [t, 'mu.u'])
t_is(r['reserves']['mu']['Pmax'], [0, 0, 0, 0, 0, 0, 0], 7, [t, 'mu.Pmax'])
t_is(r['reserves']['cost'], ppc['reserves']['cost'], 12, [t, 'cost'])
t_is(r['reserves']['qty'], ppc['reserves']['qty'], 12, [t, 'qty'])
t_is(r['reserves']['totalcost'], 187.5, 4, [t, 'totalcost'])
t = 'no qty (Rmax) : '
ppc = loadcase(casefile)
del ppc['reserves']['qty']
r = runopf_w_res(ppc, ppopt)
t_is(r['reserves']['R'], [39.3826, 0.6174, 0, 0, 19.3818, 0.6182], 4, [t, 'R'])
t_is(r['reserves']['prc'], [2, 2, 2, 2, 5.5, 5.5], 5, [t, 'prc'])
t_is(r['reserves']['mu']['l'], [0, 0, 1, 2, 0, 0], 5, [t, 'mu.l'])
t_is(r['reserves']['mu']['u'], [0, 0, 0, 0, 0, 0], 7, [t, 'mu.u'])
t_is(r['reserves']['mu']['Pmax'], [0.1, 0, 0, 0, 0.5, 0], 5, [t, 'mu.Pmax'])
t_is(r['reserves']['cost'], ppc['reserves']['cost'], 12, [t, 'cost'])
t_is(r['reserves']['totalcost'], 176.3708, 4, [t, 'totalcost'])
t = 'RAMP_10, no qty (Rmax) : ';
ppc = loadcase(casefile)
del ppc['reserves']['qty']
ppc['gen'][0, RAMP_10] = 25
r = runopf_w_res(ppc, ppopt)
t_is(r['reserves']['R'], [25, 15, 0, 0, 19.3906, 0.6094], 4, [t, 'R'])
t_is(r['reserves']['prc'], [2, 2, 2, 2, 5.5, 5.5], 6, [t, 'prc'])
t_is(r['reserves']['mu']['l'], [0, 0, 1, 2, 0, 0], 7, [t, 'mu.l'])
t_is(r['reserves']['mu']['u'], [0.1, 0, 0, 0, 0, 0], 7, [t, 'mu.u'])
t_is(r['reserves']['mu']['Pmax'], [0, 0, 0, 0, 0.5, 0], 7, [t, 'mu.Pmax'])
t_is(r['reserves']['cost'], ppc['reserves']['cost'], 12, [t, 'cost'])
t_is(r['reserves']['totalcost'], 177.8047, 4, [t, 'totalcost'])
t_end()
开发者ID:charlie0389,项目名称:PYPOWER,代码行数:101,代码来源:t_runopf_w_res.py
示例6: t_dcline
#.........这里部分代码省略.........
ppc['gen'][0, PMIN] = 10
ppc['branch'][4, RATE_A] = 100
ppc = toggle_dcline(ppc, 'on')
r = rundcopf(ppc, ppopt)
success = r['success']
t_ok(success, [t, 'success'])
expected = array([
[10, 8.9, 0, 0, 1.01, 1],
[2, 2, 0, 0, 1, 1],
[0, 0, 0, 0, 1, 1],
[10, 9.5, 0, 0, 1, 0.98]
])
t_is(r['dcline'][:, c.PF:c.VT + 1], expected, 4, [t, 'P Q V'])
expected = array([
[0, 1.8602, 0, 0, 0, 0],
[1.8507, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0.2681, 0, 0, 0, 0]
])
t_is(r['dcline'][:, c.MU_PMIN:c.MU_QMAXT + 1], expected, 3, [t, 'mu'])
t = ''.join([t0, 'DC PF (with DC lines) : '])
ppc1 = {'baseMVA': r['baseMVA'],
'bus': r['bus'][:, :VMIN + 1].copy(),
'gen': r['gen'][:, :APF + 1].copy(),
'branch': r['branch'][:, :ANGMAX + 1].copy(),
'gencost': r['gencost'].copy(),
'dcline': r['dcline'][:, :c.LOSS1 + 1].copy()}
ppc1 = toggle_dcline(ppc1, 'on')
ppc1['bus'][:, VA] = 0
rp = rundcpf(ppc1, ppopt)
success = rp['success']
t_ok(success, [t, 'success'])
t_is( rp['bus'][:,ib_voltage], r['bus'][:,ib_voltage], 3, [t, 'bus voltage'])
t_is( rp['gen'][:,ig_disp ], r['gen'][:,ig_disp ], 3, [t, 'gen dispatch'])
t_is(rp['branch'][:,ibr_flow ], r['branch'][:,ibr_flow ], 3, [t, 'branch flow'])
## add appropriate P injections and check angles and generation when running PF
t = ''.join([t0, 'DC PF (with equivalent injections) : '])
ppc1 = {'baseMVA': r['baseMVA'],
'bus': r['bus'][:, :VMIN + 1].copy(),
'gen': r['gen'][:, :APF + 1].copy(),
'branch': r['branch'][:, :ANGMAX + 1].copy(),
'gencost': r['gencost'].copy(),
'dcline': r['dcline'][:, :c.LOSS1 + 1].copy()}
ppc1['bus'][:, VA] = 0
for k in range(ndc):
if ppc1['dcline'][k, c.BR_STATUS]:
ff = find(ppc1['bus'][:, BUS_I] == ppc1['dcline'][k, c.F_BUS])
tt = find(ppc1['bus'][:, BUS_I] == ppc1['dcline'][k, c.T_BUS])
ppc1['bus'][ff, PD] = ppc1['bus'][ff, PD] + r['dcline'][k, c.PF]
ppc1['bus'][tt, PD] = ppc1['bus'][tt, PD] - r['dcline'][k, c.PT]
ppc1['bus'][ff, BUS_TYPE] = PV
ppc1['bus'][tt, BUS_TYPE] = PV
rp = rundcpf(ppc1, ppopt)
success = rp['success']
t_ok(success, [t, 'success'])
t_is( rp['bus'][:,ib_voltage], r['bus'][:,ib_voltage], 3, [t, 'bus voltage'])
t_is( rp['gen'][:,ig_disp ], r['gen'][:,ig_disp ], 3, [t, 'gen dispatch'])
t_is(rp['branch'][:,ibr_flow ], r['branch'][:,ibr_flow ], 3, [t, 'branch flow'])
## run with DC lines
t = ''.join([t0, 'AC OPF (with DC lines + poly cost) : '])
ppc = loadcase(casefile)
ppc = toggle_dcline(ppc, 'on')
r = runopf(ppc, ppopt)
success = r['success']
t_ok(success, [t, 'success'])
expected1 = array([
[10, 8.9, -10, 10, 1.0663, 1.0936],
[7.8429, 7.8429, 0, 0, 1.0809, 1.0667],
[0, 0, 0, 0, 1.0000, 1.0000],
[6.0549, 5.7522, -0.5897, -10, 1.0778, 1.0667]
])
t_is(r['dcline'][:, c.PF:c.VT + 1], expected1, 4, [t, 'P Q V'])
expected2 = array([
[0, 0.7605, 0.6226, 0, 0, 0.2980],
[0, 0, 0, 0.4275, 0.0792, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0.0792, 0]
])
t_is(r['dcline'][:, c.MU_PMIN:c.MU_QMAXT + 1], expected2, 3, [t, 'mu'])
ppc['dclinecost'][3, :8] = array([2, 0, 0, 4, 0, 0, 7.3, 0])
r = runopf(ppc, ppopt)
success = r['success']
t_ok(success, [t, 'success'])
t_is(r['dcline'][:, c.PF:c.VT + 1], expected1, 4, [t, 'P Q V'])
t_is(r['dcline'][:, c.MU_PMIN:c.MU_QMAXT + 1], expected2, 3, [t, 'mu'])
t = ''.join([t0, 'AC OPF (with DC lines + pwl cost) : '])
ppc['dclinecost'][3, :8] = array([1, 0, 0, 2, 0, 0, 10, 73])
r = runopf(ppc, ppopt)
success = r['success']
t_ok(success, [t, 'success'])
t_is(r['dcline'][:, c.PF:c.VT + 1], expected1, 4, [t, 'P Q V'])
t_is(r['dcline'][:, c.MU_PMIN:c.MU_QMAXT + 1], expected2, 3, [t, 'mu'])
t_end()
开发者ID:AdrianBajdiuk,项目名称:PowerGridResillience,代码行数:101,代码来源:t_dcline.py
示例7: t_hessian
#.........这里部分代码省略.........
t = ' - d2ASbr_dV2 (squared real power flows)'
lam = 10 * random.rand(nl)
# lam = [1 zeros(nl-1, 1)]
num_Gfaa = zeros((nb, nb), complex)
num_Gfav = zeros((nb, nb), complex)
num_Gfva = zeros((nb, nb), complex)
num_Gfvv = zeros((nb, nb), complex)
num_Gtaa = zeros((nb, nb), complex)
num_Gtav = zeros((nb, nb), complex)
num_Gtva = zeros((nb, nb), complex)
num_Gtvv = zeros((nb, nb), complex)
dSf_dVa, dSf_dVm, dSt_dVa, dSt_dVm, Sf, St = dSbr_dV(branch, Yf, Yt, V)
dAf_dVa, dAf_dVm, dAt_dVa, dAt_dVm = \
dAbr_dV(dSf_dVa.real, dSf_dVm.real, dSt_dVa.real, dSt_dVm.real, Sf.real, St.real)
Gfaa, Gfav, Gfva, Gfvv = d2ASbr_dV2(dSf_dVa.real, dSf_dVm.real, Sf.real, Cf, Yf, V, lam)
Gtaa, Gtav, Gtva, Gtvv = d2ASbr_dV2(dSt_dVa.real, dSt_dVm.real, St.real, Ct, Yt, V, lam)
for i in range(nb):
Vap = V.copy()
Vap[i] = Vm[i] * exp(1j * (Va[i] + pert))
dSf_dVa_ap, dSf_dVm_ap, dSt_dVa_ap, dSt_dVm_ap, Sf_ap, St_ap = \
dSbr_dV(branch, Yf, Yt, Vap)
dAf_dVa_ap, dAf_dVm_ap, dAt_dVa_ap, dAt_dVm_ap = \
dAbr_dV(dSf_dVa_ap.real, dSf_dVm_ap.real, dSt_dVa_ap.real, dSt_dVm_ap.real, Sf_ap.real, St_ap.real)
num_Gfaa[:, i] = (dAf_dVa_ap - dAf_dVa).T * lam / pert
num_Gfva[:, i] = (dAf_dVm_ap - dAf_dVm).T * lam / pert
num_Gtaa[:, i] = (dAt_dVa_ap - dAt_dVa).T * lam / pert
num_Gtva[:, i] = (dAt_dVm_ap - dAt_dVm).T * lam / pert
Vmp = V.copy()
Vmp[i] = (Vm[i] + pert) * exp(1j * Va[i])
dSf_dVa_mp, dSf_dVm_mp, dSt_dVa_mp, dSt_dVm_mp, Sf_mp, St_mp = \
dSbr_dV(branch, Yf, Yt, Vmp)
dAf_dVa_mp, dAf_dVm_mp, dAt_dVa_mp, dAt_dVm_mp = \
dAbr_dV(dSf_dVa_mp.real, dSf_dVm_mp.real, dSt_dVa_mp.real, dSt_dVm_mp.real, Sf_mp.real, St_mp.real)
num_Gfav[:, i] = (dAf_dVa_mp - dAf_dVa).T * lam / pert
num_Gfvv[:, i] = (dAf_dVm_mp - dAf_dVm).T * lam / pert
num_Gtav[:, i] = (dAt_dVa_mp - dAt_dVa).T * lam / pert
num_Gtvv[:, i] = (dAt_dVm_mp - dAt_dVm).T * lam / pert
t_is(Gfaa.todense(), num_Gfaa, 2, ['Gfaa', t])
t_is(Gfav.todense(), num_Gfav, 2, ['Gfav', t])
t_is(Gfva.todense(), num_Gfva, 2, ['Gfva', t])
t_is(Gfvv.todense(), num_Gfvv, 2, ['Gfvv', t])
t_is(Gtaa.todense(), num_Gtaa, 2, ['Gtaa', t])
t_is(Gtav.todense(), num_Gtav, 2, ['Gtav', t])
t_is(Gtva.todense(), num_Gtva, 2, ['Gtva', t])
t_is(Gtvv.todense(), num_Gtvv, 2, ['Gtvv', t])
##----- check d2AIbr_dV2 code -----
t = ' - d2AIbr_dV2 (squared current magnitudes)'
lam = 10 * random.rand(nl)
# lam = [1 zeros(nl-1, 1)]
num_Gfaa = zeros((nb, nb), complex)
num_Gfav = zeros((nb, nb), complex)
num_Gfva = zeros((nb, nb), complex)
num_Gfvv = zeros((nb, nb), complex)
num_Gtaa = zeros((nb, nb), complex)
num_Gtav = zeros((nb, nb), complex)
num_Gtva = zeros((nb, nb), complex)
num_Gtvv = zeros((nb, nb), complex)
dIf_dVa, dIf_dVm, dIt_dVa, dIt_dVm, If, It = dIbr_dV(branch, Yf, Yt, V)
dAf_dVa, dAf_dVm, dAt_dVa, dAt_dVm = \
dAbr_dV(dIf_dVa, dIf_dVm, dIt_dVa, dIt_dVm, If, It)
Gfaa, Gfav, Gfva, Gfvv = d2AIbr_dV2(dIf_dVa, dIf_dVm, If, Yf, V, lam)
Gtaa, Gtav, Gtva, Gtvv = d2AIbr_dV2(dIt_dVa, dIt_dVm, It, Yt, V, lam)
for i in range(nb):
Vap = V.copy()
Vap[i] = Vm[i] * exp(1j * (Va[i] + pert))
dIf_dVa_ap, dIf_dVm_ap, dIt_dVa_ap, dIt_dVm_ap, If_ap, It_ap = \
dIbr_dV(branch, Yf, Yt, Vap)
dAf_dVa_ap, dAf_dVm_ap, dAt_dVa_ap, dAt_dVm_ap = \
dAbr_dV(dIf_dVa_ap, dIf_dVm_ap, dIt_dVa_ap, dIt_dVm_ap, If_ap, It_ap)
num_Gfaa[:, i] = (dAf_dVa_ap - dAf_dVa).T * lam / pert
num_Gfva[:, i] = (dAf_dVm_ap - dAf_dVm).T * lam / pert
num_Gtaa[:, i] = (dAt_dVa_ap - dAt_dVa).T * lam / pert
num_Gtva[:, i] = (dAt_dVm_ap - dAt_dVm).T * lam / pert
Vmp = V.copy()
Vmp[i] = (Vm[i] + pert) * exp(1j * Va[i])
dIf_dVa_mp, dIf_dVm_mp, dIt_dVa_mp, dIt_dVm_mp, If_mp, It_mp = \
dIbr_dV(branch, Yf, Yt, Vmp)
dAf_dVa_mp, dAf_dVm_mp, dAt_dVa_mp, dAt_dVm_mp = \
dAbr_dV(dIf_dVa_mp, dIf_dVm_mp, dIt_dVa_mp, dIt_dVm_mp, If_mp, It_mp)
num_Gfav[:, i] = (dAf_dVa_mp - dAf_dVa).T * lam / pert
num_Gfvv[:, i] = (dAf_dVm_mp - dAf_dVm).T * lam / pert
num_Gtav[:, i] = (dAt_dVa_mp - dAt_dVa).T * lam / pert
num_Gtvv[:, i] = (dAt_dVm_mp - dAt_dVm).T * lam / pert
t_is(Gfaa.todense(), num_Gfaa, 3, ['Gfaa', t])
t_is(Gfav.todense(), num_Gfav, 3, ['Gfav', t])
t_is(Gfva.todense(), num_Gfva, 3, ['Gfva', t])
t_is(Gfvv.todense(), num_Gfvv, 2, ['Gfvv', t])
t_is(Gtaa.todense(), num_Gtaa, 3, ['Gtaa', t])
t_is(Gtav.todense(), num_Gtav, 3, ['Gtav', t])
t_is(Gtva.todense(), num_Gtva, 3, ['Gtva', t])
t_is(Gtvv.todense(), num_Gtvv, 2, ['Gtvv', t])
t_end()
开发者ID:Anastien,项目名称:PYPOWER,代码行数:101,代码来源:t_hessian.py
示例8: t_opf_ipopt
#.........这里部分代码省略.........
t_is(r['var']['val']['z'], 0.025419, 6, [t, 'user variable'])
t_is(r['cost']['usr'], 2.5419, 4, [t, 'user cost'])
##----- test OPF with capability curves -----
ppc = loadcase(join(tdir, 't_case9_opfv2'))
## remove angle diff limits
ppc['branch'][0, ANGMAX] = 360
ppc['branch'][8, ANGMIN] = -360
## get solved AC power flow case from MAT-file
soln9_opf_PQcap = loadmat(join(tdir, 'soln9_opf_PQcap.mat'), struct_as_record=True)
## defines bus_soln, gen_soln, branch_soln, f_soln
bus_soln = soln9_opf_PQcap['bus_soln']
gen_soln = soln9_opf_PQcap['gen_soln']
branch_soln = soln9_opf_PQcap['branch_soln']
f_soln = soln9_opf_PQcap['f_soln'][0]
## run OPF with capability curves
t = ''.join([t0, 'w/capability curves : '])
r = runopf(ppc, ppopt)
bus, gen, branch, f, success = \
r['bus'], r['gen'], r['branch'], r['f'], r['success']
t_ok(success, [t, 'success'])
t_is(f, f_soln, 3, [t, 'f'])
t_is( bus[:, ib_data ], bus_soln[:, ib_data ], 10, [t, 'bus data'])
t_is( bus[:, ib_voltage], bus_soln[:, ib_voltage], 3, [t, 'bus voltage'])
t_is( bus[:, ib_lam ], bus_soln[:, ib_lam ], 3, [t, 'bus lambda'])
t_is( bus[:, ib_mu ], bus_soln[:, ib_mu ], 2, [t, 'bus mu'])
t_is( gen[:, ig_data ], gen_soln[:, ig_data ], 10, [t, 'gen data'])
t_is( gen[:, ig_disp ], gen_soln[:, ig_disp ], 3, [t, 'gen dispatch'])
t_is( gen[:, ig_mu ], gen_soln[:, ig_mu ], 3, [t, 'gen mu'])
t_is(branch[:, ibr_data ], branch_soln[:, ibr_data ], 10, [t, 'branch data'])
t_is(branch[:, ibr_flow ], branch_soln[:, ibr_flow ], 3, [t, 'branch flow'])
t_is(branch[:, ibr_mu ], branch_soln[:, ibr_mu ], 2, [t, 'branch mu'])
##----- test OPF with angle difference limits -----
ppc = loadcase(join(tdir, 't_case9_opfv2'))
## remove capability curves
ppc['gen'][ix_(arange(1, 3),
[PC1, PC2, QC1MIN, QC1MAX, QC2MIN, QC2MAX])] = zeros((2, 6))
## get solved AC power flow case from MAT-file
soln9_opf_ang = loadmat(join(tdir, 'soln9_opf_ang.mat'), struct_as_record=True)
## defines bus_soln, gen_soln, branch_soln, f_soln
bus_soln = soln9_opf_ang['bus_soln']
gen_soln = soln9_opf_ang['gen_soln']
branch_soln = soln9_opf_ang['branch_soln']
f_soln = soln9_opf_ang['f_soln'][0]
## run OPF with angle difference limits
t = ''.join([t0, 'w/angle difference limits : '])
r = runopf(ppc, ppopt)
bus, gen, branch, f, success = \
r['bus'], r['gen'], r['branch'], r['f'], r['success']
t_ok(success, [t, 'success'])
t_is(f, f_soln, 3, [t, 'f'])
t_is( bus[:, ib_data ], bus_soln[:, ib_data ], 10, [t, 'bus data'])
t_is( bus[:, ib_voltage], bus_soln[:, ib_voltage], 3, [t, 'bus voltage'])
t_is( bus[:, ib_lam ], bus_soln[:, ib_lam ], 3, [t, 'bus lambda'])
t_is( bus[:, ib_mu ], bus_soln[:, ib_mu ], 1, [t, 'bus mu'])
t_is( gen[:, ig_data ], gen_soln[:, ig_data ], 10, [t, 'gen data'])
t_is( gen[:, ig_disp ], gen_soln[:, ig_disp ], 3, [t, 'gen dispatch'])
t_is( gen[:, ig_mu ], gen_soln[:, ig_mu ], 3, [t, 'gen mu'])
t_is(branch[:, ibr_data ], branch_soln[:, ibr_data ], 10, [t, 'branch data'])
t_is(branch[:, ibr_flow ], branch_soln[:, ibr_flow ], 3, [t, 'branch flow'])
t_is(branch[:, ibr_mu ], branch_soln[:, ibr_mu ], 2, [t, 'branch mu'])
t_is(branch[:, ibr_angmu ], branch_soln[:, ibr_angmu ], 2, [t, 'branch angle mu'])
##----- test OPF with ignored angle difference limits -----
## get solved AC power flow case from MAT-file
soln9_opf = loadmat(join(tdir, 'soln9_opf.mat'), struct_as_record=True)
## defines bus_soln, gen_soln, branch_soln, f_soln
bus_soln = soln9_opf['bus_soln']
gen_soln = soln9_opf['gen_soln']
branch_soln = soln9_opf['branch_soln']
f_soln = soln9_opf['f_soln'][0]
## run OPF with ignored angle difference limits
t = ''.join([t0, 'w/ignored angle difference limits : '])
ppopt1 = ppoption(ppopt, OPF_IGNORE_ANG_LIM=1)
r = runopf(ppc, ppopt1)
bus, gen, branch, f, success = \
r['bus'], r['gen'], r['branch'], r['f'], r['success']
## ang limits are not in this solution data, so let's remove them
branch[0, ANGMAX] = 360
branch[8, ANGMIN] = -360
t_ok(success, [t, 'success'])
t_is(f, f_soln, 3, [t, 'f'])
t_is( bus[:, ib_data ], bus_soln[:, ib_data ], 10, [t, 'bus data'])
t_is( bus[:, ib_voltage], bus_soln[:, ib_voltage], 3, [t, 'bus voltage'])
t_is( bus[:, ib_lam ], bus_soln[:, ib_lam ], 3, [t, 'bus lambda'])
t_is( bus[:, ib_mu ], bus_soln[:, ib_mu ], 2, [t, 'bus mu'])
t_is( gen[:, ig_data ], gen_soln[:, ig_data ], 10, [t, 'gen data'])
t_is( gen[:, ig_disp ], gen_soln[:, ig_disp ], 3, [t, 'gen dispatch'])
t_is( gen[:, ig_mu ], gen_soln[:, ig_mu ], 3, [t, 'gen mu'])
t_is(branch[:, ibr_data ], branch_soln[:, ibr_data ], 10, [t, 'branch data'])
t_is(branch[:, ibr_flow ], branch_soln[:, ibr_flow ], 3, [t, 'branch flow'])
t_is(branch[:, ibr_mu ], branch_soln[:, ibr_mu ], 2, [t, 'branch mu'])
t_end()
开发者ID:AdrianBajdiuk,项目名称:PowerGridResillience,代码行数:101,代码来源:t_opf_ipopt.py
示例9: t_modcost
#.........这里部分代码省略.........
t_is(totcost(gencost, array([0, 0, 0, -15])) / 5, [1, 2, 0, -1400], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -20])) / 5, [1, 2, 0, -1800], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -25])) / 5, [1, 2, 0, -2100], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -30])) / 5, [1, 2, 0, -2400], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -35])) / 5, [1, 2, 0, -2700], 8, t)
gencost = modcost(gencost0, 2, 'SCALE_X')
t = 'modcost SCALE_X - quadratic'
t_is(totcost(gencost, array([0, 0, 0, 0]) * 2), [1, 2, 0, 0], 8, t)
t_is(totcost(gencost, array([1, 0, 0, 0]) * 2), [1.11, 2, 0, 0], 8, t)
t_is(totcost(gencost, array([2, 0, 0, 0]) * 2), [1.24, 2, 0, 0], 8, t)
t = 'modcost SCALE_X - 4th order polynomial'
t_is(totcost(gencost, array([0, 0, 0, 0]) * 2), [1, 2, 0, 0], 8, t)
t_is(totcost(gencost, array([0, 1, 0, 0]) * 2), [1, 2.3456, 0, 0], 8, t)
t_is(totcost(gencost, array([0, 2, 0, 0]) * 2), [1, 2.8096, 0, 0], 8, t)
t = 'modcost SCALE_X - pwl (gen)'
t_is(totcost(gencost, array([0, 0, 5, 0 ]) * 2), [1, 2, 100, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 10, 0]) * 2), [1, 2, 200, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 15, 0]) * 2), [1, 2, 400, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 20, 0]) * 2), [1, 2, 600, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 25, 0]) * 2), [1, 2, 900, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 30, 0]) * 2), [1, 2, 1200, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 35, 0]) * 2), [1, 2, 1500, 0], 8, t)
t = 'modcost SCALE_X - pwl (load)'
t_is(totcost(gencost, array([0, 0, 0, -5 ]) * 2), [1, 2, 0, -500], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -10]) * 2), [1, 2, 0, -1000], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -15]) * 2), [1, 2, 0, -1400], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -20]) * 2), [1, 2, 0, -1800], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -25]) * 2), [1, 2, 0, -2100], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -30]) * 2), [1, 2, 0, -2400], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -35]) * 2), [1, 2, 0, -2700], 8, t)
gencost = modcost(gencost0, 3, 'SHIFT_F')
t = 'modcost SHIFT_F - quadratic'
t_is(totcost(gencost, array([0, 0, 0, 0])) - 3, [1, 2, 0, 0], 8, t)
t_is(totcost(gencost, array([1, 0, 0, 0])) - 3, [1.11, 2, 0, 0], 8, t)
t_is(totcost(gencost, array([2, 0, 0, 0])) - 3, [1.24, 2, 0, 0], 8, t)
t = 'modcost SHIFT_F - 4th order polynomial'
t_is(totcost(gencost, array([0, 0, 0, 0])) - 3, [1, 2, 0, 0], 8, t)
t_is(totcost(gencost, array([0, 1, 0, 0])) - 3, [1, 2.3456, 0, 0], 8, t)
t_is(totcost(gencost, array([0, 2, 0, 0])) - 3, [1, 2.8096, 0, 0], 8, t)
t = 'modcost SHIFT_F - pwl (gen)'
t_is(totcost(gencost, array([0, 0, 5, 0 ])) - 3, [1, 2, 100, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 10, 0])) - 3, [1, 2, 200, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 15, 0])) - 3, [1, 2, 400, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 20, 0])) - 3, [1, 2, 600, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 25, 0])) - 3, [1, 2, 900, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 30, 0])) - 3, [1, 2, 1200, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 35, 0])) - 3, [1, 2, 1500, 0], 8, t)
t = 'modcost SHIFT_F - pwl (load)'
t_is(totcost(gencost, array([0, 0, 0, -5 ])) - 3, [1, 2, 0, -500], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -10])) - 3, [1, 2, 0, -1000], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -15])) - 3, [1, 2, 0, -1400], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -20])) - 3, [1, 2, 0, -1800], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -25])) - 3, [1, 2, 0, -2100], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -30])) - 3, [1, 2, 0, -2400], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -35])) - 3, [1, 2, 0, -2700], 8, t)
gencost = modcost(gencost0, -4, 'SHIFT_X')
t = 'modcost SHIFT_X - quadratic'
t_is(totcost(gencost, array([0, 0, 0, 0]) - 4), [1, 2, 0, 0], 8, t)
t_is(totcost(gencost, array([1, 0, 0, 0]) - 4), [1.11, 2, 0, 0], 8, t)
t_is(totcost(gencost, array([2, 0, 0, 0]) - 4), [1.24, 2, 0, 0], 8, t)
t = 'modcost SHIFT_X - 4th order polynomial'
t_is(totcost(gencost, array([0, 0, 0, 0]) - 4), [1, 2, 0, 0], 8, t)
t_is(totcost(gencost, array([0, 1, 0, 0]) - 4), [1, 2.3456, 0, 0], 8, t)
t_is(totcost(gencost, array([0, 2, 0, 0]) - 4), [1, 2.8096, 0, 0], 8, t)
t = 'modcost SHIFT_X - pwl (gen)'
t_is(totcost(gencost, array([0, 0, 5, 0 ]) - 4), [1, 2, 100, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 10, 0]) - 4), [1, 2, 200, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 15, 0]) - 4), [1, 2, 400, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 20, 0]) - 4), [1, 2, 600, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 25, 0]) - 4), [1, 2, 900, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 30, 0]) - 4), [1, 2, 1200, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 35, 0]) - 4), [1, 2, 1500, 0], 8, t)
t = 'modcost SHIFT_X - pwl (load)'
t_is(totcost(gencost, array([0, 0, 0, -5 ]) - 4), [1, 2, 0, -500], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -10]) - 4), [1, 2, 0, -1000], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -15]) - 4), [1, 2, 0, -1400], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -20]) - 4), [1, 2, 0, -1800], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -25]) - 4), [1, 2, 0, -2100], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -30]) - 4), [1, 2, 0, -2400], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -35]) - 4), [1, 2, 0, -2700], 8, t)
t_end()
开发者ID:charlie0389,项目名称:PYPOWER,代码行数:101,代码来源:t_modcost.py
示例10: t_pf
#.........这里部分代码省略.........
## run Gauss-Seidel PF
t = 'Gauss-Seidel PF : ';
ppopt = ppoption(ppopt, PF_ALG=4)
results, success = runpf(casefile, ppopt)
bus, gen, branch = results['bus'], results['gen'], results['branch']
t_ok(success, [t, 'success'])
t_is(bus, bus_soln, 5, [t, 'bus'])
t_is(gen, gen_soln, 5, [t, 'gen'])
t_is(branch, branch_soln, 5, [t, 'branch'])
## get solved AC power flow case from MAT-file
## defines bus_soln, gen_soln, branch_soln
soln9_dcpf = loadmat(join(tdir, 'soln9_dcpf.mat'), struct_as_record=False)
bus_soln = soln9_dcpf['bus_soln']
gen_soln = soln9_dcpf['gen_soln']
branch_soln = soln9_dcpf['branch_soln']
## run DC PF
t = 'DC PF : '
results, success = rundcpf(casefile, ppopt)
bus, gen, branch = results['bus'], results['gen'], results['branch']
t_ok(success, [t, 'success'])
t_is(bus, bus_soln, 6, [t, 'bus'])
t_is(gen, gen_soln, 6, [t, 'gen'])
t_is(branch, branch_soln, 6, [t, 'branch'])
## check Qg distribution, when Qmin = Qmax
t = 'check Qg : '
ppopt = ppoption(ppopt, PF_ALG=1, VERBOSE=0)
ppc = loadcase(casefile)
ppc['gen'][0, [QMIN, QMAX]] = [20, 20]
results, success = runpf(ppc, ppopt)
bus, gen, branch = results['bus'], results['gen'], results['branch']
t_is(gen[0, QG], 24.07, 2, [t, 'single gen, Qmin = Qmax'])
ppc['gen'] = r_[array([ ppc['gen'][0, :] ]), ppc['gen']]
ppc['gen'][0, [QMIN, QMAX]] = [10, 10]
ppc['gen'][1, [QMIN, QMAX]] = [ 0, 50]
results, success = runpf(ppc, ppopt)
bus, gen, branch = results['bus'], results['gen'], results['branch']
t_is(gen[0:2, QG], [10, 14.07], 2, [t, '2 gens, Qmin = Qmax for one'])
ppc['gen'][0, [QMIN, QMAX]] = [10, 10]
ppc['gen'][1, [QMIN, QMAX]] = [-50, -50]
results, success = runpf(ppc, ppopt)
bus, gen, branch = results['bus'], results['gen'], results['branch']
t_is(gen[0:2, QG], [12.03, 12.03], 2, [t, '2 gens, Qmin = Qmax for both'])
ppc['gen'][0, [QMIN, QMAX]] = [0, 50]
ppc['gen'][1, [QMIN, QMAX]] = [0, 100]
results, success = runpf(ppc, ppopt)
bus, gen, branch = results['bus'], results['gen'], results['branch']
t_is(gen[0:2, QG], [8.02, 16.05], 2, [t, '2 gens, proportional'])
ppc['gen'][0, [QMIN, QMAX]] = [-50, 0]
ppc['gen'][1, [QMIN, QMAX]] = [50, 150]
results, success = runpf(ppc, ppopt)
bus, gen, branch = results['bus'], results['gen'], results['branch']
t_is(gen[0:2, QG], [-50 + 8.02, 50 + 16.05], 2, [t, '2 gens, proportional'])
## network with islands
t = 'network w/islands : DC PF : '
ppc0 = loadcase(casefile)
ppc0['gen'][0, PG] = 60
ppc0['gen'][0, [PMIN, PMAX, QMIN, QMAX, PG, QG]] = \
ppc0['gen'][0, [PMIN, PMAX, QMIN, QMAX, PG, QG]] / 2
ppc0['gen'] = r_[array([ ppc0['gen'][0, :] ]), ppc0['gen']]
ppc1 = ppc0.copy()
ppc = ppc0.copy()
nb = ppc['bus'].shape[0]
ppc1['bus'][:, BUS_I] = ppc1['bus'][:, BUS_I] + nb
ppc1['branch'][:, F_BUS] = ppc1['branch'][:, F_BUS] + nb
ppc1['branch'][:, T_BUS] = ppc1['branch'][:, T_BUS] + nb
ppc1['gen'][:, GEN_BUS] = ppc1['gen'][:, GEN_BUS] + nb
ppc['bus'] = r_[ppc['bus'], ppc1['bus']]
ppc['branch'] = r_[ppc['branch'], ppc1['branch']]
ppc['gen'] = r_[ppc['gen'], ppc1['gen']]
#ppopt = ppoption(ppopt, OUT_BUS=1, OUT_GEN=1, OUT_ALL=-1, VERBOSE=2)
ppopt = ppoption(ppopt, VERBOSE=verbose)
r = rundcpf(ppc, ppopt)
t_is(r['bus'][ :9, VA], bus_soln[:, VA], 8, [t, 'voltage angles 1'])
t_is(r['bus'][10:18, VA], bus_soln[:, VA], 8, [t, 'voltage angles 2'])
Pg = r_[gen_soln[0, PG] - 30, 30, gen_soln[1:3, PG]]
t_is(r['gen'][ :4, PG], Pg, 8, [t, 'active power generation 1'])
t_is(r['gen'][4:8, PG], Pg, 8, [t, 'active power generation 1'])
t = 'network w/islands : AC PF : '
## get solved AC power flow case from MAT-file
soln9_pf = loadmat(join(tdir, 'soln9_pf.mat'), struct_as_record=False)
bus_soln = soln9_pf['bus_soln']
gen_soln = soln9_pf['gen_soln']
branch_soln = soln9_pf['branch_soln']
r = runpf(ppc, ppopt)
t_is(r['bus'][ :9, VA], bus_soln[:, VA], 8, [t, 'voltage angles 1'])
t_is(r['bus'][9:18, VA], bus_soln[:, VA], 8, [t, 'voltage angles 2'])
Pg = r_[gen_soln[0, PG] - 30, 30, gen_soln[1:3, PG]]
t_is(r['gen'][ :4, PG], Pg, 8, [t, 'active power generation 1'])
t_is(r['gen'][4:8, PG], Pg, 8, [t, 'active power generation 1'])
t_end()
开发者ID:Anastien,项目名称:PYPOWER,代码行数:101,代码来源:t_pf.py
示例11: t_jacobian
#.........这里部分代码省略.........
num_dSbus_dVa = (Vap * conj(Ybus * Vap) - Vc * ones((1, nb)) * conj(Ybus * Vc * ones((1, nb)))) / pert
t_is(dSbus_dVm_sp, num_dSbus_dVm, 5, 'dSbus_dVm (sparse)')
t_is(dSbus_dVa_sp, num_dSbus_dVa, 5, 'dSbus_dVa (sparse)')
t_is(dSbus_dVm_full, num_dSbus_dVm, 5, 'dSbus_dVm (full)')
t_is(dSbus_dVa_full, num_dSbus_dVa, 5, 'dSbus_dVa (full)')
##----- check dSbr_dV code -----
## full matrices
dSf_dVa_full, dSf_dVm_full, dSt_dVa_full, dSt_dVm_full, _, _ = \
dSbr_dV(branch, Yf_full, Yt_full, V)
## sparse matrices
dSf_dVa, dSf_dVm, dSt_dVa, dSt_dVm, Sf, St = dSbr_dV(branch, Yf, Yt, V)
dSf_dVa_sp = dSf_dVa.todense()
dSf_dVm_sp = dSf_dVm.todense()
dSt_dVa_sp = dSt_dVa.todense()
dSt_dVm_sp = dSt_dVm.todense()
## compute numerically to compare
Vmpf = Vmp[f, :]
Vapf = Vap[f, :]
Vmpt = Vmp[t, :]
Vapt = Vap[t, :]
Sf2 = (Vc[f] * ones((1, nb))) * conj(Yf * Vc * ones((1, nb)))
St2 = (Vc[t] * ones((1, nb))) * conj(Yt * Vc * ones((1, nb)))
Smpf = Vmpf * conj(Yf * Vmp)
Sapf = Vapf * conj(Yf * Vap)
Smpt = Vmpt * conj(Yt * Vmp)
Sapt = Vapt * conj(Yt * Vap)
num_dSf_dVm = (Smpf - Sf2) / pert
num_dSf_dVa = (Sapf - Sf2) / pert
num_dSt_dVm = (Smpt - St2) / pert
num_dSt_dVa = (Sapt - St2) / pert
t_is(dSf_dVm_sp, num_dSf_dVm, 5, 'dSf_dVm (sparse)')
t_is(dSf_dVa_sp, num_dSf_dVa, 5, 'dSf_dVa (sparse)')
t_is(dSt_dVm_sp, num_dSt_dVm, 5, 'dSt_dVm (sparse)')
t_is(dSt_dVa_sp, num_dSt_dVa, 5, 'dSt_dVa (sparse)')
t_is(dSf_dVm_full, num_dSf_dVm, 5, 'dSf_dVm (full)')
t_is(dSf_dVa_full, num_dSf_dVa, 5, 'dSf_dVa (full)')
t_is(dSt_dVm_full, num_dSt_dVm, 5, 'dSt_dVm (full)')
t_is(dSt_dVa_full, num_dSt_dVa, 5, 'dSt_dVa (full)')
##----- check dAbr_dV code -----
## full matrices
dAf_dVa_full, dAf_dVm_full, dAt_dVa_full, dAt_dVm_full = \
dAbr_dV(dSf_dVa_full, dSf_dVm_full, dSt_dVa_full, dSt_dVm_full, Sf, St)
## sparse matrices
dAf_dVa, dAf_dVm, dAt_dVa, dAt_dVm = \
dAbr_dV(dSf_dVa, dSf_dVm, dSt_dVa, dSt_dVm, Sf, St)
dAf_dVa_sp = dAf_dVa.todense()
dAf_dVm_sp = dAf_dVm.todense()
dAt_dVa_sp = dAt_dVa.todense()
dAt_dVm_sp = dAt_dVm.todense()
## compute numerically to compare
num_dAf_dVm = (abs(Smpf)**2 - abs(Sf2)**2) / pert
num_dAf_dVa = (abs(Sapf)**2 - abs(Sf2)**2) / pert
num_dAt_dVm = (abs(Smpt)**2 - abs(St2)**2) / pert
num_dAt_dVa = (abs(Sapt)**2 - abs(St2)**2) / pert
t_is(dAf_dVm_sp, num_dAf_dVm, 4, 'dAf_dVm (sparse)')
t_is(dAf_dVa_sp, num_dAf_dVa, 4, 'dAf_dVa (sparse)')
t_is(dAt_dVm_sp, num_dAt_dVm, 4, 'dAt_dVm (sparse)')
t_is(dAt_dVa_sp, num_dAt_dVa, 4, 'dAt_dVa (sparse)')
t_is(dAf_dVm_full, num_dAf_dVm, 4, 'dAf_dVm (full)')
t_is(dAf_dVa_full, num_dAf_dVa, 4, 'dAf_dVa (full)')
t_is(dAt_dVm_full, num_dAt_dVm, 4, 'dAt_dVm (full)')
t_is(dAt_dVa_full, num_dAt_dVa, 4, 'dAt_dVa (full)')
##----- check dIbr_dV code -----
## full matrices
dIf_dVa_full, dIf_dVm_full, dIt_dVa_full, dIt_dVm_full, _, _ = \
dIbr_dV(branch, Yf_full, Yt_full, V)
## sparse matrices
dIf_dVa, dIf_dVm, dIt_dVa, dIt_dVm, _, _ = dIbr_dV(branch, Yf, Yt, V)
dIf_dVa_sp = dIf_dVa.todense()
dIf_dVm_sp = dIf_dVm.todense()
dIt_dVa_sp = dIt_dVa.todense()
dIt_dVm_sp = dIt_dVm.todense()
## compute numerically to compare
num_dIf_dVm = (Yf * Vmp - Yf * Vc * ones((1, nb))) / pert
num_dIf_dVa = (Yf * Vap - Yf * Vc * ones((1, nb))) / pert
num_dIt_dVm = (Yt * Vmp - Yt * Vc * ones((1, nb))) / pert
num_dIt_dVa = (Yt * Vap - Yt * Vc * ones((1, nb))) / pert
t_is(dIf_dVm_sp, num_dIf_dVm, 5, 'dIf_dVm (sparse)')
t_is(dIf_dVa_sp, num_dIf_dVa, 5, 'dIf_dVa (sparse)')
t_is(dIt_dVm_sp, num_dIt_dVm, 5, 'dIt_dVm (sparse)')
t_is(dIt_dVa_sp, num_dIt_dVa, 5, 'dIt_dVa (sparse)')
t_is(dIf_dVm_full, num_dIf_dVm, 5, 'dIf_dVm (full)')
t_is(dIf_dVa_full, num_dIf_dVa, 5, 'dIf_dVa (full)')
t_is(dIt_dVm_full, num_dIt_dVm, 5, 'dIt_dVm (full)')
t_is(dIt_dVa_full, num_dIt_dVa, 5, 'dIt_dVa (full)')
t_end()
开发者ID:Anastien,项目名称:PYPOWER,代码行数:101,代码来源:t_jacobian.py
示例12: t_total_load
#.........这里部分代码省略.........
t_is(Pd, total['disp']['p'], 12, [t, 'Pd'])
t = 'Pd, Qd = total_load(bus, gen, \'all\', \'DISPATCHABLE\') : '
Pd, Qd = total_load(ppc['bus'], ppc['gen'], 'all', 'DISPATCHABLE')
t_is(Pd, total['disp']['p'], 12, [t, 'Pd'])
t_is(Qd, total['disp']['q'], 12, [t, 'Qd'])
t = 'Pd, _ = total_load(bus, gen, None, \'BOTH\') : '
Pd, _ = total_load(ppc['bus'], ppc['gen'], None, 'BOTH')
t_is(Pd, r_[area[0]['both']['p'], area[1]['both']['p'], area[2]['both']['p']], 12, [t, 'Pd'])
t = 'Pd, Qd = total_load(bus, gen, None, \'BOTH\') : '
Pd, Qd = total_load(ppc['bus'], ppc['gen'], None, 'BOTH')
t_is(Pd, [area[0]['both']['p'], area[1]['both']['p'], area[2]['both']['p']], 12, [t, 'Pd'])
t_is(Qd, [area[0]['both']['q'], area[1]['both']['q'], area[2]['both']['q']], 12, [t, 'Qd'])
t = 'Pd, _ = total_load(bus, gen, None, \'FIXED\') : '
Pd, _ = total_load(ppc['bus'], ppc['gen'], None, 'FIXED')
t_is(Pd, [area[0]['fixed']['p'], area[1]['fixed']['p'], area[2]['fixed']['p']], 12, [t, 'Pd'])
t = 'Pd, Qd = total_load(bus, gen, None, \'FIXED\') : '
Pd, Qd = total_load(ppc['bus'], ppc['gen'], None, 'FIXED')
t_is(Pd, [area[0]['fixed']['p'], area[1]['fixed']['p'], area[2]['fixed']['p']], 12, [t, 'Pd'])
t_is(Qd, [area[0]['fixed']['q'], area[1]['fixed']['q'], area[2]['fixed']['q']], 12, [t, 'Qd'])
t = 'Pd, _ = total_load(bus, gen, None, \'DISPATCHABLE\') : '
Pd, _ = total_load(ppc['bus'], ppc['gen'], None, 'DISPATCHABLE')
t_is(Pd, [area[0]['disp']['p'], area[1]['disp']['p'], area[2]['disp']['p']], 12, [t, 'Pd'])
t = 'Pd, Qd = total_load(bus, gen, None, \'DISPATCHABLE\') : '
Pd, Qd = total_load(ppc['bus'], ppc['gen'], None, 'DISPATCHABLE')
t_is(Pd, [area[0]['disp']['p'], area[1]['disp']['p'], area[2]['disp']['p']], 12, [t, 'Pd'])
t_is(Qd, [area[0]['disp']['q'], area[1]['disp']['q'], area[2]['disp']['q']], 12, [t, 'Qd'])
##----- explicit single load zone -----
nb = ppc['bus'].shape[0]
load_zone = zeros(nb, int)
k = find(ppc['bus'][:, BUS_AREA] == 2) ## area 2
load_zone[k] = 1
t = 'Pd, _ = total_load(bus, gen, load_zone1, \'BOTH\') : '
Pd, _ = total_load(ppc['bus'], ppc['gen'], load_zone, 'BOTH')
t_is(Pd, area[1]['both']['p'], 12, [t, 'Pd'])
t = 'Pd, Qd = total_load(bus, gen, load_zone1, \'BOTH\') : '
Pd, Qd = total_load(ppc['bus'], ppc['gen'], load_zone, 'BOTH')
t_is(Pd, area[1]['both']['p'], 12, [t, 'Pd'])
t_is(Qd, area[1]['both']['q'], 12, [t, 'Qd'])
t = 'Pd, _ = total_load(bus, gen, load_zone1, \'FIXED\') : '
Pd, _ = total_load(ppc['bus'], ppc['gen'], load_zone, 'FIXED')
t_is(Pd, area[1]['fixed']['p'], 12, [t, 'Pd'])
t = 'Pd, Qd = total_load(bus, gen, load_zone1, \'FIXED\') : '
Pd, Qd = total_load(ppc['bus'], ppc['gen'], load_zone, 'FIXED')
t_is(Pd, area[1]['fixed']['p'], 12, [t, 'Pd'])
t_is(Qd, area[1]['fixed']['q'], 12, [t, 'Qd'])
t = 'Pd, _ = total_load(bus, gen, load_zone1, \'DISPATCHABLE\') : '
Pd, _ = total_load(ppc['bus'], ppc['gen'], load_zone, 'DISPATCHABLE')
t_is(Pd, area[1]['disp']['p'], 12, [t, 'Pd'])
t = 'Pd, Qd = total_load(bus, gen, load_zone1, \'DISPATCHABLE\') : '
Pd, Qd = total_load(ppc['bus'], ppc['gen'],
|
请发表评论