def Z(self): if self._Z is not None: return self._Z if self._Y is not None: return Zs(1 / self._Y) if self._Voc is not None: return Zs(0) if self._Isc is not None: return Zs(1 / Ys(0)) raise ValueError('_Isc, _Voc, _Y, or _Z undefined for %s' % self)
def __init__(self, Zval=Zs(0), Vval=Vs(0)): # print('<T> Z:', Zval, 'V:', Vval) if not isinstance(Zval, Zs): raise ValueError('Zval not Zs') if not isinstance(Vval, Vs): raise ValueError('Vval not Vs') self.Z = Zval self.Voc = Vval super(Thevenin, self).__init__()
def impedance(self, Np, Nm): """Return s-domain impedance between nodes Np and Nm with independent sources killed. """ new = self.kill() # Connect 1 A s-domain current source between nodes and # measure voltage. new._add('Iin_ %d %d {DiracDelta(t)}' % (Np, Nm)) Vf = new.Voc(Np, Nm) new.remove('Iin_') return Zs(Vf.laplace())
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, 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 __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 Amatrix(self, N1p, N1m, N2p, N2m): """Create A matrix from network, where: I1 is the current flowing into N1p and out of N1m I2 is the current flowing into N2p and out of N2m V1 is V[N1p] - V[N1m] V2 is V[N2p] - V[N2m] """ from lcapy.twoport import AMatrix if self.Voc(N1p, N1m) != 0 or self.Voc(N2p, N2m) != 0: raise ValueError('Network contains independent sources') try: self.add('V1_ %d %d {DiracDelta(t)}' % (N1p, N1m)) # A11 = V1 / V2 with I2 = 0 # Apply V1 and measure V2 with port 2 open-circuit A11 = Hs(self.V1_.V.laplace() / self.Voc(N2p, N2m).laplace()) # A12 = V1 / I2 with V2 = 0 # Apply V1 and measure I2 with port 2 short-circuit A12 = Zs(self.V1_.V.laplace() / self.Isc(N2p, N2m).laplace()) self.remove('V1_') self.add('I1_ %d %d {DiracDelta(t)}' % (N1p, N1m)) # A21 = I1 / V2 with I2 = 0 # Apply I1 and measure I2 with port 2 open-circuit A21 = Ys(-self.I1_.I.laplace() / self.Voc(N2p, N2m).laplace()) # A22 = I1 / I2 with V2 = 0 # Apply I1 and measure I2 with port 2 short-circuit A22 = Hs(-self.I1_.I.laplace() / self.Isc(N2p, N2m).laplace()) self.remove('I1_') A = AMatrix(A11, A12, A21, A22) return A except ValueError: raise ValueError('Cannot create A matrix')
def __init__(self, Zval): self.args = (Zval, ) Zval = Zs(Zval) self._Z = Zval
def __init__(self, Rval): self.args = (Rval, ) self.R = cExpr(Rval) self._Z = Zs.R(self.R)
def __init__(self, Vval): super(VoltageSource, self).__init__(Zs(0), Vs(Vval))
def __init__(self, Zval): self.args = (Zval, ) Zval = Zs(Zval) super(Z, self).__init__(Zval)
def __init__(self, Rval): self.args = (Rval, ) Rval = cExpr(Rval, positive=True) super(R, self).__init__(Zs.R(Rval)) self.R = Rval
def Z(self): return Zs(1 / self.Y)
def __init__(self, vval): self.args = (vval, ) Vval = tExpr(vval) super(V, self).__init__(Zs(0), Vs(Vval).laplace()) self.assumptions_infer(Vval)