Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_basic_complex(self):
import cvxopt
a = cvxopt.matrix([1,-2,3])
b = cvxopt.matrix([1.0,-2.0,3.0])
c = cvxopt.matrix([1.0+2j,1-2j,0+1j])
d = cvxopt.spmatrix([complex(1.0,0.0), complex(0.0,1.0), complex(2.0,-1.0)],[0,1,3],[0,2,3],(4,4))
e = cvxopt.spmatrix([complex(1.0,0.0), complex(0.0,1.0), complex(2.0,-1.0)],[2,3,3],[1,2,3],(4,4))
self.assertAlmostEqualLists(list(cvxopt.div(b,c)),[0.2-0.4j,-0.4-0.8j,-3j])
self.assertAlmostEqualLists(list(cvxopt.div(b,2.0j)),[-0.5j,1j,-1.5j])
self.assertAlmostEqualLists(list(cvxopt.div(a,c)),[0.2-0.4j,-0.4-0.8j,-3j])
self.assertAlmostEqualLists(list(cvxopt.div(c,a)),[(1+2j),(-0.5+1j),0.3333333333333333j])
self.assertAlmostEqualLists(list(cvxopt.div(c,c)),[1.0,1.0,1.0])
self.assertAlmostEqualLists(list(cvxopt.div(a,2.0j)),[-0.5j,1j,-1.5j])
self.assertAlmostEqualLists(list(cvxopt.div(c,1.0j)),[2-1j,-2-1j,1+0j])
self.assertAlmostEqualLists(list(cvxopt.div(1j,c)),[0.4+0.2j,-0.4+0.2j,1+0j])
self.assertTrue(len(d)+len(e)==len(cvxopt.sparse([d,e])))
self.assertTrue(len(d)+len(e)==len(cvxopt.sparse([[d],[e]])))
def fxcall(self, dae):
Turbine.jac0(self, dae)
dae.add_jac(Gx, -dae.y[self.vsd], self.isd, self.isq)
dae.add_jac(Gx, mul(dae.x[self.isq], self.xq), self.vsd, self.omega_m)
dae.add_jac(Gx, mul(dae.x[self.omega_m], self.xq), self.vsd, self.isq)
dae.add_jac(Gx, self.psip - mul(dae.y[self.isd], self.xd), self.vsq,
self.omega_m)
dae.add_jac(Gx, dae.y[self.vsq], self.ps, self.isq)
dae.add_jac(Gx, self.psip + mul(dae.y[self.isd], self.xq - self.xd),
self.te, self.isq)
dae.add_jac(
Fx,
mul(-0.5, dae.y[self.pw], div(1, self.H), (dae.x[self.omega_m])
** -2), self.omega_m, self.omega_m)
dae.add_jac(
Fx, -mul(
div(1, self.Teq), (dae.x[self.omega_m])**-2,
div(1, self.psip - mul(dae.y[self.isd], self.xd)),
dae.y[self.pwa] - mul(self.Kcoi, dae.y[self.dwdt_coi]) - mul(
self.Kdc, dae.y[self.v1] - dae.y[self.v2]) - mul(
self.Ki, dae.y[self.dwdt])), self.isq, self.omega_m)
dae.add_jac(Fy, mul(0.5, div(1, self.H), div(1, dae.x[self.omega_m])),
self.omega_m, self.pw)
dae.add_jac(
Fy,
mul(self.Kdc, div(1, self.Teq), div(1, dae.x[self.omega_m]),
div(1, self.psip - mul(dae.y[self.isd], self.xd))), self.isq,
return
if self._flags['sysbase']:
logger.debug('Model <{}> is not in sysbase. data_to_elem_base() aborted.'.format(self._name))
return
Sb = self.system.mva
Vb = matrix([])
if 'bus' in self._ac.keys():
Vb = self.read_data_ext('Bus', 'Vn', idx=self.bus)
elif 'bus1' in self._ac.keys():
Vb = self.read_data_ext('Bus', 'Vn', idx=self.bus1)
for var in self._voltages:
self._store[var] = self.__dict__[var]
self.__dict__[var] = mul(self.__dict__[var], self.Vn)
self.__dict__[var] = div(self.__dict__[var], Vb)
for var in self._powers:
self._store[var] = self.__dict__[var]
self.__dict__[var] = mul(self.__dict__[var], self.Sn)
self.__dict__[var] /= Sb
for var in self._currents:
self._store[var] = self.__dict__[var]
self.__dict__[var] = mul(self.__dict__[var], self.Sn)
self.__dict__[var] = div(self.__dict__[var], self.Vn)
self.__dict__[var] = mul(self.__dict__[var], Vb)
self.__dict__[var] /= Sb
if len(self._z) or len(self._y):
Zn = div(self.Vn**2, self.Sn)
Zb = (Vb**2) / Sb
for var in self._z:
self._store[var] = self.__dict__[var]
self.__dict__[var] = mul(self.__dict__[var], Zn)
-mul(self.iTe, self.K0, self.T1T2,
1 + mul(self.s0, -1 + mul(dae.y[self.v], div(1, self.v0)))),
self.vfout, self.vm)
dae.add_jac(
Fx, self.iTe + mul(self.iTe, self.s0,
-1 + mul(dae.y[self.v], div(1, self.v0))),
self.vfout, self.vr)
dae.add_jac(
Fy,
mul(self.iTe, self.K0, self.T1T2,
1 + mul(self.s0, -1 + mul(dae.y[self.v], div(1, self.v0)))),
self.vfout, self.vref)
dae.add_jac(
Fy,
mul(
self.iTe, self.s0, div(1, self.v0),
self.vf0 + dae.x[self.vr] + mul(
self.K0, self.T1T2, dae.y[self.vref] - dae.x[self.vm])),
self.vfout, self.v)
def init1(self, dae):
self.servcall(dae)
dae.x[self.vfout] = dae.y[self.vf]
self.vref0 = dae.y[self.v] + mul(dae.y[self.vf], div(1, self.K0),
1 + self.Se)
dae.y[self.vref] = self.vref0
dae.x[self.vm] = dae.y[self.v]
dae.x[self.vr1] = mul(self.K0, 1 - self.T21,
self.vref0 - dae.y[self.v])
dae.y[self.vr] = mul(dae.y[self.vf], 1 + self.Se)
dae.x[self.vr2] = mul(
div(1, self.K0), 1 - self.T43, dae.x[self.vr1] + mul(
self.K0, self.T21, dae.y[self.vref] - dae.x[self.vm]))
vrd[i] = x[4]
vrq[i] = x[5]
dae.x[self.ird] = mul(self.u0, ird)
dae.x[self.irq] = mul(self.u0, irq)
dae.y[self.isd] = isd
dae.y[self.isq] = isq
dae.y[self.vrd] = vrd
dae.y[self.vrq] = vrq
dae.x[self.omega_m] = mul(self.u0, omega)
dae.x[self.theta_p] = mul(self.u0, theta)
dae.y[self.pwa] = mmax(mmin(2 * dae.x[self.omega_m] - 1, 1), 0)
self.vref0 = mul(
aneb(self.KV, 0), Vc - div(ird + div(Vc, xmu), self.KV))
dae.y[self.vref] = self.vref0
k = mul(div(x1, Vc, xmu, omega), toSb)
self.irq_off = -mul(k, mmax(mmin(2 * omega - 1, 1), 0)) - irq
# electrical torque in pu
te = mul(
xmu,
mul(dae.x[self.irq], dae.y[self.isd]) - mul(
dae.x[self.ird], dae.y[self.isq]))
for i in range(self.n):
if te[i] < 0:
logger.error(
'Pe < 0 on bus <{}>. Wind speed initialize failed.'.
format(self.bus[i]))
mul((div(1, dae.y[self.lamb] + mul(0.08, dae.x[self.theta_p])) +
mul(-0.035, div(1, 1 + (dae.x[self.theta_p]) ** 3))) ** -2,
mul(0.08, (dae.y[self.lamb] + mul(0.08, dae.x[self.theta_p]))
** -2) + mul(-0.105, (dae.x[self.theta_p]) ** 2,
(1 + (dae.x[self.theta_p]) ** 3) ** -2)),
self.ilamb,
self.theta_p)
dae.add_jac(Gx, -mul(self.u0, dae.y[self.vrq]), self.a, self.irq)
dae.add_jac(Gx, -mul(self.u0, dae.y[self.vrd]), self.a, self.ird)
dae.add_jac(Gx, mul(self.u0, dae.y[self.v], self.xmu, div(1, self.x0)),
self.v, self.ird)
dae.add_jac(
Fx,
mul(dae.y[self.pwa], self.x0, toSb, div(1, self.Te),
(dae.x[self.omega_m])**-2, div(1, dae.y[self.v]),
div(1, self.xmu)), self.irq, self.omega_m)
dae.add_jac(
Fy,
mul(dae.y[self.pwa], self.x0, toSb, div(1, self.Te), div(1, omega),
(dae.y[self.v])**-2, div(1, self.xmu)), self.irq, self.v)
dae.add_jac(
Fy, -mul(self.x0, toSb, div(1, self.Te), div(1, omega),
div(1, dae.y[self.v]), div(1, self.xmu)), self.irq,
self.pwa)
dae.add_jac(Fx, mul(0.5, dae.y[self.isq], self.xmu, div(1, self.H)),
self.omega_m, self.ird)
dae.add_jac(
Fx,
mul(-0.5, dae.y[self.pw], div(1, self.H), (dae.x[self.omega_m])
** -2), self.omega_m, self.omega_m)
dae.add_jac(Gx0, mul(self.Ic12, self.u0), self.In1, self.w)
dae.add_jac(Gx0, mul(self.Ic21, self.u0), self.In2, self.omega)
dae.add_jac(Gx0, mul(self.Ic22, self.u0), self.In2, self.w)
dae.add_jac(Gx0, -self.u0, self.x3, self.u3)
dae.add_jac(Gx0, self.u0, self.x4, self.u4)
dae.add_jac(Gx0, self.u0, self.x5, self.u5)
dae.add_jac(Gx0, self.u0, self.x6, self.u6)
dae.add_jac(Fx0, -mul(self.u0, div(1, self.T1)), self.x1, self.x1)
dae.add_jac(Fx0, -mul(self.u0, div(1, self.T2)), self.x2, self.x2)
dae.add_jac(Fx0, -mul(self.u0, div(1, self.T4)), self.u3, self.u3)
dae.add_jac(Fx0, -mul(self.u0, div(1, self.T6)), self.u4, self.u4)
dae.add_jac(Fx0, -mul(self.u0, div(1, self.T8)), self.u5, self.u5)
dae.add_jac(Fx0, -mul(self.u0, div(1, self.T10)), self.u6, self.u6)
dae.add_jac(Fy0, mul(self.K1, self.u0, div(1, self.T1)), self.x1,
self.In1)
dae.add_jac(Fy0, mul(self.K2, self.u0, div(1, self.T2)), self.x2,
self.In2)
dae.add_jac(Fy0, mul(self.T34, self.u0, div(1, self.T4)), self.u3,
self.In)
dae.add_jac(Fy0, mul(self.u0, div(1, self.T6), 1 - self.T56), self.u4,
self.x3)
dae.add_jac(Fy0, mul(self.u0, div(1, self.T8), 1 - self.T78), self.u5,
self.x4)
dae.add_jac(Fy0, mul(self.u0, div(1, self.T10), 1 - self.T910),
self.u6, self.x5)
dae.add_jac(Gy0, 1e-6, self.In1, self.In1)
dae.add_jac(Gy0, 1e-6, self.In2, self.In2)
dae.add_jac(Gy0, 1e-6, self.In, self.In)
dae.add_jac(Gy0, 1e-6, self.x3, self.x3)
dae.add_jac(Gy0, 1e-6, self.x4, self.x4)
dae.add_jac(Gy0, 1e-6, self.x5, self.x5)
dae.add_jac(Gy0, 1e-6, self.x6, self.x6)
def voltage_init1(self, dae):
dae.y[self.Idref] = mul(self.pref0, div(1, dae.y[self.vd]))
dae.y[self.Iqref] = mul(self.qref0, div(1, dae.y[self.vd]))
dae.x[self.Nd] = dae.y[self.Idref]
dae.x[self.Nq] = dae.y[self.Iqref]
dae.y[self.ref2] = dae.y[self.v]
def gycall(self, dae):
if sum(self.u) == 0:
return
Zsh = self.rsh + 1j * self.xsh
iZsh = div(self.u, abs(Zsh))
Vh = polar(dae.y[self.v], dae.y[self.a] * 1j)
Vsh = polar(dae.y[self.vsh], dae.y[self.ash] * 1j)
Ish = div(Vsh - Vh + 1e-6, Zsh)
iIsh = div(self.u, Ish)
gsh = div(self.u, Zsh).real()
bsh = div(self.u, Zsh).imag()
V = dae.y[self.v]
theta = dae.y[self.a]
Vsh = dae.y[self.vsh]
thetash = dae.y[self.ash]
Vdc = dae.y[self.v1] - dae.y[self.v2]
iVdc2 = div(self.u, Vdc**2)
dae.add_jac(Gy, div(self.u, Vdc), self.v1, self.pdc)
dae.add_jac(Gy, -mul(self.u, dae.y[self.pdc], iVdc2), self.v1, self.v1)
dae.add_jac(Gy, mul(self.u, dae.y[self.pdc], iVdc2), self.v1, self.v2)
dae.add_jac(Gy, -div(self.u, Vdc), self.v2, self.pdc)
dae.add_jac(Gy, mul(self.u, dae.y[self.pdc], iVdc2), self.v2, self.v1)
dae.add_jac(Gy, -mul(self.u, dae.y[self.pdc], iVdc2), self.v2, self.v2)