Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def build_b(self):
"""build Bp and Bpp for fast decoupled method"""
if not self.n:
return
method = self.system.pflow.config.method.lower()
# Build B prime matrix
y1 = mul(
self.u, self.g1
) # y1 neglects line charging shunt, and g1 is usually 0 in HV lines
y2 = mul(
self.u, self.g2
) # y2 neglects line charging shunt, and g2 is usually 0 in HV lines
m = polar(1.0, self.phi * deg2rad) # neglected tap ratio
self.mconj = conj(m)
m2 = matrix(1.0, (self.n, 1), 'z')
if method in ('fdxb', 'dcpf'):
# neglect line resistance in Bp in XB method
y12 = div(self.u, self.x * 1j)
else:
y12 = div(self.u, self.r + self.x * 1j)
self.Bp = spmatrix(
div(y12 + y1, m2), self.a1, self.a1, (self.nb, self.nb), 'z')
self.Bp -= spmatrix(
div(y12, conj(m)), self.a1, self.a2, (self.nb, self.nb), 'z')
self.Bp -= spmatrix(
div(y12, m), self.a2, self.a1, (self.nb, self.nb), 'z')
self.Bp += spmatrix(y12 + y2, self.a2, self.a2, (self.nb, self.nb),
'z')
self.Bp = self.Bp.imag()
def init0(self, dae):
# behind-transformer AC theta_sh and V_sh - must assign first
dae.y[self.ash] = dae.y[self.a] + 1e-6
dae.y[self.vsh] = mul(self.v0, 1 - self.vV) + mul(self.vref0,
self.vV) + 1e-6
Vm = polar(dae.y[self.v], dae.y[self.a])
Vsh = polar(dae.y[self.vsh], dae.y[self.ash]) # Initial value for Vsh
IshC = conj(div(Vsh - Vm, self.Zsh))
# PQ PV and V control initials on converters
dae.y[self.psh] = mul(self.pref0, self.PQ + self.PV)
dae.y[self.qsh] = mul(self.qref0, self.PQ)
dae.y[self.v1] = dae.y[self.v2] + mul(dae.y[self.v1], 1 - self.vV) + mul(self.vdcref0, self.vV)
# PV and V control on AC buses
dae.y[self.v] = mul(dae.y[self.v], 1 - self.PV - self.vV) + mul(self.vref0, self.PV + self.vV)
# Converter current initial
dae.y[self.Ish] = abs(IshC)
# Converter dc power output
dae.y[self.pdc] = mul(Vsh, IshC).real() + \
(self.k0 + mul(self.k1, dae.y[self.Ish]) + mul(self.k2, mul(dae.y[self.Ish], dae.y[self.Ish])))
) # y1 neglected line charging shunt, and g1 is usually 0 in HV lines
y2 = mul(
self.u, self.g2 + self.b2 * 1j
) # y2 neglected line charging shunt, and g2 is usually 0 in HV lines
m = self.tap + 0j # neglected phase shifter
m2 = abs(m)**2 + 0j
if method in ('fdbx', 'fdpf', 'dcpf'):
# neglect line resistance in Bpp in BX method
y12 = div(self.u, self.x * 1j)
else:
y12 = div(self.u, self.r + self.x * 1j)
self.Bpp = spmatrix(
div(y12 + y1, m2), self.a1, self.a1, (self.nb, self.nb), 'z')
self.Bpp -= spmatrix(
div(y12, conj(m)), self.a1, self.a2, (self.nb, self.nb), 'z')
self.Bpp -= spmatrix(
div(y12, m), self.a2, self.a1, (self.nb, self.nb), 'z')
self.Bpp += spmatrix(y12 + y2, self.a2, self.a2, (self.nb, self.nb),
'z')
self.Bpp = self.Bpp.imag()
for item in range(self.nb):
if abs(self.Bp[item, item]) == 0:
self.Bp[item, item] = 1e-6 + 0j
if abs(self.Bpp[item, item]) == 0:
self.Bpp[item, item] = 1e-6 + 0j
"""Build line Jacobian matrix"""
if not self.n:
idx = range(dae.m)
dae.set_jac(Gy, 1e-6, idx, idx)
return
Vn = polar(1.0, dae.y[self.a])
Vc = mul(dae.y[self.v], Vn)
Ic = self.Y * Vc
diagVn = spdiag(Vn)
diagVc = spdiag(Vc)
diagIc = spdiag(Ic)
dS = self.Y * diagVn
dS = diagVc * conj(dS)
dS += conj(diagIc) * diagVn
dR = diagIc
dR -= self.Y * diagVc
dR = diagVc.H.T * dR
self.gy_store = sparse([[dR.imag(), dR.real()], [dS.real(),
dS.imag()]])
return self.gy_store
if not self.n:
idx = range(dae.m)
dae.set_jac(Gy, 1e-6, idx, idx)
return
Vn = polar(1.0, dae.y[self.a])
Vc = mul(dae.y[self.v], Vn)
Ic = self.Y * Vc
diagVn = spdiag(Vn)
diagVc = spdiag(Vc)
diagIc = spdiag(Ic)
dS = self.Y * diagVn
dS = diagVc * conj(dS)
dS += conj(diagIc) * diagVn
dR = diagIc
dR -= self.Y * diagVc
dR = diagVc.H.T * dR
self.gy_store = sparse([[dR.imag(), dR.real()], [dS.real(),
dS.imag()]])
return self.gy_store
def gcall(self, dae):
if sum(self.u) == 0:
return
Vm = polar(dae.y[self.v], dae.y[self.a])
Vsh = polar(dae.y[self.vsh], dae.y[self.ash])
Ish = mul(self.Ysh, Vsh - Vm)
IshC = conj(Ish)
Ssh = mul(Vm, IshC)
# check the Vsh and Ish limits during PF iterations
vupper = list(abs(Vsh) - self.vshmax)
vlower = list(abs(Vsh) - self.vshmin)
iupper = list(abs(IshC) - self.Ishmax)
# check for Vsh and Ish limit violations
if self.system.pflow.niter >= self.system.pflow.config.ipv2pq:
for i in range(self.n):
if self.u[i] and (vupper[i] > 0 or vlower[i] < 0 or iupper[i] > 0):
if i not in self.vio.keys():
self.vio[i] = list()
if vupper[i] > 0:
if 'vmax' not in self.vio[i]:
self.vio[i].append('vmax')
logger.debug(' * Vmax reached for VSC_{0}'.format(i))
) # y1 neglects line charging shunt, and g1 is usually 0 in HV lines
y2 = mul(
self.u, self.g2
) # y2 neglects line charging shunt, and g2 is usually 0 in HV lines
m = polar(1.0, self.phi * deg2rad) # neglected tap ratio
self.mconj = conj(m)
m2 = matrix(1.0, (self.n, 1), 'z')
if method in ('fdxb', 'dcpf'):
# neglect line resistance in Bp in XB method
y12 = div(self.u, self.x * 1j)
else:
y12 = div(self.u, self.r + self.x * 1j)
self.Bp = spmatrix(
div(y12 + y1, m2), self.a1, self.a1, (self.nb, self.nb), 'z')
self.Bp -= spmatrix(
div(y12, conj(m)), self.a1, self.a2, (self.nb, self.nb), 'z')
self.Bp -= spmatrix(
div(y12, m), self.a2, self.a1, (self.nb, self.nb), 'z')
self.Bp += spmatrix(y12 + y2, self.a2, self.a2, (self.nb, self.nb),
'z')
self.Bp = self.Bp.imag()
# Build B double prime matrix
y1 = mul(
self.u, self.g1 + self.b1 * 1j
) # y1 neglected line charging shunt, and g1 is usually 0 in HV lines
y2 = mul(
self.u, self.g2 + self.b2 * 1j
) # y2 neglected line charging shunt, and g2 is usually 0 in HV lines
m = self.tap + 0j # neglected phase shifter
m2 = abs(m)**2 + 0j