def __init__(self, Lval, i0=0): self.args = (Lval, i0) Lval = cExpr(Lval, positive=True) i0 = cExpr(i0) super(L, self).__init__(Zs.L(Lval), -Vs(i0 * Lval)) self.L = Lval self.i0 = i0
def __init__(self, Cval, v0=0): self.args = (Cval, v0) Cval = cExpr(Cval, positive=True) v0 = cExpr(v0) super(C, self).__init__(Zs.C(Cval), Vs(v0).integrate()) self.C = Cval self.v0 = v0
def __init__(self, Rs, Rp, Cp, Lp): self.args = (Rs, Rp, Cp, Lp) self.Rs = cExpr(Rs, positive=True) self.Rp = cExpr(Rp, positive=True) self.Cp = cExpr(Cp, positive=True) self.Lp = cExpr(Lp, positive=True) N = self.expand() super(Xtal, self).__init__(N.Z, N.V)
def __init__(self, C0, R1, L1, C1): self.C0 = cExpr(C0) self.R1 = cExpr(R1) self.L1 = cExpr(L1) self.C1 = cExpr(C1) N = self.expand() super(Xtal, self).__init__(N.Z, N.V) self.args = (C0, R1, L1, C1)
def __init__(self, I, f, phi=0): self.args = (I, f, phi) I = cExpr(I) f = cExpr(f) phi = cExpr(phi) omega = 2 * sym.pi * f foo = (s * sym.cos(phi) + omega * sym.sin(phi)) / (s**2 + omega**2) super(Iacstep, self).__init__(Is(I * foo))
def __init__(self, Rs, Rp, Cp, Lp): self.Rs = cExpr(Rs) self.Rp = cExpr(Rp) self.Cp = cExpr(Cp) self.Lp = cExpr(Lp) N = self.expand() super(Xtal, self).__init__(N.Z, N.V) self.args = (Rs, Rp, Cp, Lp)
def __init__(self, C0, R1, L1, C1): self.args = (C0, R1, L1, C1) self.C0 = cExpr(C0, positive=True) self.R1 = cExpr(R1, positive=True) self.L1 = cExpr(L1, positive=True) self.C1 = cExpr(C1, positive=True) N = self.expand() super(Xtal, self).__init__(N.Z, N.V)
def __init__(self, V, f, phi=0): self.args = (V, f, phi) V = cExpr(V) f = cExpr(f) phi = cExpr(phi) # Note, cos(-pi / 2) is not quite zero. omega = 2 * sym.pi * f foo = (s * sym.cos(phi) + omega * sym.sin(phi)) / (s**2 + omega**2) super(Vacstep, self).__init__(Vs(V * foo))
def __init__(self, I, phi=0): self.args = (I, phi) I = cExpr(I) phi = cExpr(phi) self.omega = symbol('omega_1', real=True) foo = (s * sym.cos(phi) + self.omega * sym.sin(phi)) / (s**2 + self.omega**2) super(Iac, self).__init__(Is(foo * I, ac=True)) # This is not needed when assumptions propagated. self.Isc.is_ac = True self.i0 = I self.phi = phi
def __init__(self, V, phi=0): self.args = (V, phi) V = cExpr(V) phi = cExpr(phi) # Note, cos(-pi / 2) is not quite zero. self.omega = symbol('omega_1', real=True) foo = (s * sym.cos(phi) + self.omega * sym.sin(phi)) / (s**2 + self.omega**2) super(Vac, self).__init__(Vs(foo * V, ac=True)) # This is not needed when assumptions propagated. self.Voc.is_ac = True self.v0 = V self.phi = phi
def stamp(self, cct): n1, n2, n3, n4 = self.node_indexes m1 = self.cct._branch_index(self.name + 'X') m2 = self.branch_index # m1 is the input branch # m2 is the output branch # GY.I gives the current through the output branch # Could generalise to have different input and output # impedances, Z1 and Z2, but if Z1 != Z2 then the device is # not passive. # V2 = -I1 Z2 V1 = I2 Z1 # where V2 = V[n1] - V[n2] and V1 = V[n3] - V[n4] Z1 = cExpr(self.args[0]).expr Z2 = Z1 if n1 >= 0: cct._B[n1, m2] += 1 cct._C[m1, n1] += 1 if n2 >= 0: cct._B[n2, m2] -= 1 cct._C[m1, n2] -= 1 if n3 >= 0: cct._B[n3, m1] += 1 cct._C[m2, n3] += 1 if n4 >= 0: cct._B[n4, m1] -= 1 cct._C[m2, n4] -= 1 cct._D[m1, m1] += Z2 cct._D[m2, m2] -= Z1
def __init__(self, v): self.args = (v, ) v = cExpr(v) super(Vdc, self).__init__(Vs(v, dc=True) / s) # This is not needed when assumptions propagated. self.Voc.is_dc = True self.v0 = v
def __init__(self, i): self.args = (i, ) i = cExpr(i) super(Idc, self).__init__(Is(i, dc=True) / s) # This is not needed when assumptions propagated. self.Isc.is_dc = True self.i0 = i
def __init__(self, Cval, v0=None): self.hasic = v0 is not None if v0 is None: v0 = 0 if self.hasic: self.args = (Cval, v0) else: self.args = (Cval, ) Cval = cExpr(Cval) v0 = cExpr(v0) self.C = Cval self.v0 = v0 self._Z = Zs.C(Cval) self._Voc = Vsuper(Vs(v0) / s) self.zeroic = self.v0 == 0
def __init__(self, Cval, v0=None): self.hasic = v0 is not None if v0 is None: v0 = 0 if self.hasic: self.args = (Cval, v0) else: self.args = (Cval, ) Cval = cExpr(Cval, positive=True) v0 = cExpr(v0) super(C, self).__init__(Zs.C(Cval), Vs(v0).integrate()) self.C = Cval self.v0 = v0 self.zeroic = self.v0 == 0
def __init__(self, Lval, i0=None): self.hasic = i0 is not None if i0 is None: i0 = 0 if self.hasic: self.args = (Lval, i0) else: self.args = (Lval, ) Lval = cExpr(Lval, positive=True) i0 = cExpr(i0) super(L, self).__init__(Zs.L(Lval), -Vs(i0 * Lval)) self.L = Lval self.i0 = i0 self.zeroic = self.i0 == 0
def stamp(self, cct): n1, n2 = self.node_indexes m = cct._branch_index(self.args[0]) F = cExpr(self.args[1]).expr if n1 >= 0: cct._B[n1, m] -= F if n2 >= 0: cct._B[n2, m] += F
def __init__(self, Lval, i0=None): self.hasic = i0 is not None if i0 is None: i0 = 0 if self.hasic: self.args = (Lval, i0) else: self.args = (Lval, ) Lval = cExpr(Lval) i0 = cExpr(i0) self.L = Lval self.i0 = i0 self._Z = Zs.L(Lval) self._Voc = Vsuper(-Vs(i0 * Lval)) self.zeroic = self.i0 == 0
def Z(self): """Impedance""" kind = self.cct.kind Z1 = self.Zs if kind in ('s', 'ivp', 'super'): return Z1 elif kind in ('dc', 'time'): return cExpr(Z1.jomega(0)) elif isinstance(kind, str) and kind[0] == 'n': return Z1.jomega return Z1.jomega(kind)
def stamp(self, cct): n1, n2 = self.node_indexes m = self.branch_index if n2 >= 0: cct._B[n2, m] += 1 cct._C[m, n2] += 1 A = cExpr(self.args[0]).expr if n1 >= 0: cct._C[m, n1] -= A
def Y(self): """Admittance""" kind = self.cct.kind Y1 = self.Ys if kind in ('s', 'ivp', 'super'): return Y1 elif kind in ('dc', 'time'): return cExpr(Y1.jomega(0)) elif isinstance(kind, str) and kind[0] == 'n': return Y1.jomega return Y1.jomega(kind)
def stamp(self, cct): n1, n2, n3, n4 = self.node_indexes G = cExpr(self.args[0]).expr if n1 >= 0 and n3 >= 0: cct._G[n1, n3] -= G if n1 >= 0 and n4 >= 0: cct._G[n1, n4] += G if n2 >= 0 and n3 >= 0: cct._G[n2, n3] += G if n2 >= 0 and n4 >= 0: cct._G[n2, n4] -= G
def __init__(self, Rd=1e9, Ro=1e-6, A=100000, Rp=1e9, Rm=1e9): # If Ro=0, then Z matrix singular. Rd, Ro, A, Rp, Rm = [cExpr(arg) for arg in (Rd, Ro, A, Rp, Rm)] Ra = Rp * (Rd + Rm) / (Rp + Rd + Rm) Rb = Rm * (Rd + Rp) / (Rp + Rd + Rm) Z = ZMatrix3( ((Rp + Rd, Rd, 0), (Rd, Rm + Rd, 0), (A * Ra, -A * Rb, Ro))) super(Opamp, self).__init__(Z) self.args = (Rd, Ro, A, Rp, Rm)
def stamp(self, cct): n1, n2 = self.node_indexes m = self.branch_index if n1 >= 0: cct._B[n1, m] += 1 cct._C[m, n1] += 1 if n2 >= 0: cct._B[n2, m] -= 1 cct._C[m, n2] -= 1 mc = cct._branch_index(self.args[0]) G = cExpr(self.args[1]).expr cct._D[m, mc] -= G
def __init__(self, Rd=1e9, Ro=1e-6, A=100000, Rp=1e9, Rm=1e9): # If Ro=0, then Z matrix singular. Rd, Ro, A, Rp, Rm = [cExpr(arg) for arg in (Rd, Ro, A, Rp, Rm)] Ra = Rp * (Rd + Rm) / (Rp + Rd + Rm) Rb = Rm * (Rd + Rp) / (Rp + Rd + Rm) Z = ZMatrix3(((Rp + Rd, Rd, 0), (Rd, Rm + Rd, 0), (A * Ra, -A * Rb, Ro))) super(Opamp, self).__init__(Z) self.args = (Rd, Ro, A, Rp, Rm)
def stamp(self, cct): n1, n2, n3, n4 = self.node_indexes m = self.branch_index if n1 >= 0: cct._B[n1, m] += 1 cct._C[m, n1] += 1 if n2 >= 0: cct._B[n2, m] -= 1 cct._C[m, n2] -= 1 A = cExpr(self.args[0]).expr if n3 >= 0: cct._C[m, n3] -= A if n4 >= 0: cct._C[m, n4] += A
def __init__(self, Rval): self.args = (Rval, ) Rval = cExpr(Rval, positive=True) super(R, self).__init__(Zs.R(Rval)) self.R = Rval
def __init__(self, Gval): self.args = (Gval, ) Gval = cExpr(Gval, positive=True) super(G, self).__init__(Ys.G(Gval)) self.G = Gval
def __init__(self, i): self.args = (i, ) i = cExpr(i) super(Istep, self).__init__(Is(i).integrate()) self.i = i
def __init__(self, Rval): self.args = (Rval, ) self.R = cExpr(Rval) self._Z = Zs.R(self.R)
def __init__(self, v): self.args = (v, ) v = cExpr(v) super(Vstep, self).__init__(Vs(v).integrate()) self.v = v
def __init__(self, Gval): self.args = (Gval, ) self.G = cExpr(Gval) self._Z = 1 / Ys.G(self.G)
def __init__(self, v): self.args = (v, ) v = cExpr(v) self._Voc = Vsuper(tExpr(v) * Heaviside(t), causal=True) self.v0 = v
def __init__(self, v): self.args = (v, ) v = cExpr(v) self._Voc = Vsuper(Vconst(v, dc=True)) self.v0 = v
def __init__(self, i): self.args = (i, ) i = cExpr(i) self._Isc = Isuper(tExpr(i) * Heaviside(t), causal=True) self.i0 = i
def __init__(self, i): self.args = (i, ) i = cExpr(i) self._Isc = Isuper(Iconst(i, dc=True)) self.i0 = i