def test_transient_plot(): vvec = np.linspace(-2, 2, 100) ivec = np.tanh(vvec) nvec = ivec * 0 # no noise c = SubCircuit() n1, n2 = c.add_nodes('1', '2') c['vsin'] = VSin(n1, gnd, freq=2e3, va=1, vo=1.) c['vccs'] = myVCCS(n1, gnd, n2, gnd, ivec=ivec, vvec=vvec, nvec=nvec) c['mycap'] = myC(n2, gnd) c['rl'] = R(n2, gnd, r=2.0) tran = Transient(c) res = tran.solve(tend=1e-3, timestep=1e-5) plotall(res.v(n1), res.v(n2)) pylab.show()
def test_transient_plot(): vvec=np.linspace(-2,2,100) ivec=np.tanh(vvec) nvec=ivec*0 # no noise c = SubCircuit() n1,n2 = c.add_nodes('1', '2') c['vsin'] = VSin(n1, gnd, freq=2e3, va=1, vo=1.) c['vccs'] = myVCCS(n1, gnd, n2, gnd, ivec=ivec, vvec=vvec, nvec=nvec) c['mycap'] = myC(n2, gnd) c['rl'] = R(n2, gnd, r=2.0) tran = Transient(c) res = tran.solve(tend=1e-3, timestep=1e-5) plotall(res.v(n1),res.v(n2)) pylab.show()
def test_transient_RLC(): """Test of transient simulation of RLC-circuit """ circuit.default_toolkit = circuit.numeric c = SubCircuit() c['VSin'] = VSin(gnd, 1, va=10, freq=50e3) c['R1'] = R(1, 2, r=1e6) c['C'] = C(2, gnd, c=1e-12) #c['L'] = L(2,gnd, L=1e-3) tran_imp = Transient(c) res_imp = tran_imp.solve(tend=40e-6,timestep=1e-6) expected = 2.58 assert abs(res_imp.v(2,gnd)[-1] - expected) < 1e-2*expected,\ 'Does not match QUCS result.'
def test_transient_get_diff(): """Test of differentiation method """ circuit.default_toolkit = circuit.numeric c = SubCircuit() c['VSin'] = VSin(gnd, 1, va=10, freq=50e3) c['R1'] = R(1, 2, r=1e6) c['C'] = C(2, gnd, c=1e-12) tran = Transient(c) tran._dt=1e-6 x0=np.ones(c.n) q=c.q(x0) Cmatrix=c.C(x0) print tran.parameters a,b,b_=tran._method[tran.par.method] tran._qlast=np.zeros((len(a),tran.cir.n))#initialize q-history vector iq,geq = tran.get_diff(q,Cmatrix) print iq,geq
def test_Idtmod_modulo(): """Test modulo integrator element in transient""" pycircuit.circuit.circuit.default_toolkit = numeric c = SubCircuit() nin = c.add_node('in') nout = c.add_node('out') c['vin'] = VS(nin, gnd, v=1.0) c['R1'] = R(nout, gnd, r=1e3) c['Idtmod'] = Idtmod(nin, gnd, nout, gnd, modulus = 1., offset = -0.) tran = Transient(c, toolkit=numeric) result = tran.solve(tend=2.0,timestep=1e-2) y = result.v(nout).y x = result.v(nout).x[0] # vout = vin * t with constant input => test that v(nout) = t assert_array_equal(y[1:]/(x[1:]%1.0), np.ones(y[1:].size)) #avoid divide by t=0.0
def test_transient_RC(): """Test of the of transient simulation of RC-circuit """ circuit.default_toolkit = circuit.numeric c = SubCircuit() n1 = c.add_node('net1') n2 = c.add_node('net2') c['ISin'] = ISin(gnd, n1, ia=10, freq=500) c['R1'] = R(n1, gnd, r=1) c['R2'] = R(n1, n2, r=1e3) c['R3'] = R(n2, gnd, r=100e3) c['C'] = C(n2, gnd, c=1e-5) tran = Transient(c) res = tran.solve(tend=10e-3,timestep=1e-4) expected = 6.3 assert abs(res.v(n2,gnd)[-1] - expected) < 1e-2*expected,\ 'Does not match QUCS result.'