def test_geteqsys(): var('R1 V0 Isat T') k = symbolic.kboltzmann qelectron = symbolic.qelectron c = SubCircuit(toolkit=symbolic) c['V0'] = VS('net1', gnd, v=V0, toolkit=symbolic) c['R1'] = R('net1', 'net2', r=R1) c['D1'] = Diode('net2', gnd, IS=Isat, toolkit=symbolic) dc = SymbolicDC(c) dc.epar.T = T eqsys, x = dc.get_eqsys() x0, x2, x3 = x eqsys_ref = np.array([x3 + x0/R1 - x2/R1, -Isat*(1 - sympy.exp(qelectron*x2/(T*k))) + x2/R1 - x0/R1, x0 - V0]) assert sympy.simplify(eqsys_ref[0] - eqsys_ref[0]) == 0 assert sympy.simplify(eqsys_ref[0] - eqsys_ref[0]) == 0 assert sympy.simplify(eqsys_ref[0] - eqsys_ref[0]) == 0
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_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.'
def test_linear(): var('R1 R2 V0') c = SubCircuit(toolkit=symbolic) c['V0'] = VS(1, gnd, v=V0, vac=1, toolkit=symbolic) c['L'] = L(1,2, L=1e-3) c['R1'] = R(2, 3, r = Symbol('R1')) c['R2'] = R(3, gnd, r = Symbol('R2')) dc = SymbolicDC(c) res = dc.solve() assert_equal(sympy.simplify(res.v(3, gnd) - V0*R2/(R1+R2)), 0)
def test_nonlinear(): var('k qelectron I0 Isat qelectron T', positive=True, real=True) c = SubCircuit(toolkit=symbolic) c['I0'] = IS(gnd, 'net1', i=I0, toolkit=symbolic) c['D'] = Diode('net1', gnd, IS=Isat, toolkit=symbolic) dc = SymbolicDC(c) dc.epar.T = T res = dc.solve() assert_equal(sympy.simplify(res.v('net1') - k * T / qelectron * log(I0/Isat+1)), 0)
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_geteqsys(): var('k qelectron R1 V0 Isat q T qelectron') c = SubCircuit(toolkit=symbolic) c['V0'] = VS('net1', gnd, v=V0, toolkit=symbolic) c['R1'] = R('net1', 'net2', r=R1) c['D1'] = Diode('net2', gnd, IS=Isat, toolkit=symbolic) dc = SymbolicDC(c) dc.epar.T = Symbol('T') eqsys, x = dc.get_eqsys() x0, x2, x3 = x assert_array_equal(eqsys, [x3 + x0/R1 - x2/R1, -Isat*(1 - sympy.exp(qelectron*x2/(T*k))) + x2/R1 - x0/R1, x0 - V0])