diff --git a/pypower/opf_costfcn.py b/pypower/opf_costfcn.py index ab58406..823b274 100644 --- a/pypower/opf_costfcn.py +++ b/pypower/opf_costfcn.py @@ -102,7 +102,8 @@ def opf_costfcn(x, om, return_hessian=False): ## polynomial cost of P and Q df_dPgQg = zeros(2 * ng) ## w.r.t p.u. Pg and Qg - df_dPgQg[ipol] = baseMVA * polycost(gencost[ipol, :], xx[ipol], 1) + if len(ipol): + df_dPgQg[ipol] = baseMVA * polycost(gencost[ipol, :], xx[ipol], 1) df = zeros(nxyz) df[iPg] = df_dPgQg[:ng] df[iQg] = df_dPgQg[ng:ng + ng] diff --git a/pypower/opf_hessfcn.py b/pypower/opf_hessfcn.py index de842f5..5177817 100644 --- a/pypower/opf_hessfcn.py +++ b/pypower/opf_hessfcn.py @@ -101,9 +101,10 @@ def opf_hessfcn(x, lmbda, om, Ybus, Yf, Yt, ppopt, il=None, cost_mult=1.0): d2f_dPg2 = zeros(ng)#sparse((ng, 1)) ## w.r.t. p.u. Pg d2f_dQg2 = zeros(ng)#sparse((ng, 1)) ## w.r.t. p.u. Qg ipolp = find(pcost[:, MODEL] == POLYNOMIAL) - d2f_dPg2[ipolp] = \ + if len(ipol): + d2f_dPg2[ipolp] = \ baseMVA**2 * polycost(pcost[ipolp, :], Pg[ipolp] * baseMVA, 2) - if any(qcost): ## Qg is not free + if qcost.any(): ## Qg is not free ipolq = find(qcost[:, MODEL] == POLYNOMIAL) d2f_dQg2[ipolq] = \ baseMVA**2 * polycost(qcost[ipolq, :], Qg[ipolq] * baseMVA, 2)