Dear all,

I am currently integrating ngspice with my finite element time domain electromagnetic(EM) code, in order to address hybrid EM-circuit problems like high speed ICs. I came across several problems in using ngspice and wish to get some help here.

In order to state my problems in ngspice, I need to briefly introduce my method of integration.

The combined EM-ngspice simulation is divided into N time steps with dt. In each time step, say from n to n+1 time period, the EM code and ngspice will run separately from n to n+1, and an interface is established between them. The EM-ngspice interface is written as: 1. The input for ngspice is a voltage source from time period n to n+1, and the output is the current through the voltage source. 2. The voltage source in ngspice and the integration of electric fields along the circuit position in EM should be kept consistent. 3. The current going through the circuits and the integration of magnetic fields along the circuit position in EM should be kept consistent. 4. In each time step, the EM code and ngspice will run for several iterations until conditions 2 and 3 are satisfied.

After 4, the value of voltages (on capacitors), currents (in inductors) in ngspice, electric and magnetic fields in EM simulation at n+1 time are recorded. These values will be used as the initial conditions for the EM code and ngspice for the next time step from n+1 to n+2 time period.

My testing case is a microstrip with nonlinear circuits at one end of it. The voltage source of the microstrip is excited at the other end in the electromagnetic code. The nonlinear circuits are represented in ngspice as follows.

Circuit1

.param V1=

.param V2=

.param V3=

.param IC_L1=

.param IC_L2= * V1,V2,V3,IC_L1,IC_L2 are from previous time step

.param Vm= * Vm represents the integration of electric fields

.param dt= * dt is determined by EM code

.tran {dt/2} {dt} uic

.ic v(1)={V1}

.ic v(2)={V2}

.ic v(3)={V3}

vin 1 0 pwl(0 {V1} {dt} {Vm})

L1 1 2 0.6n IC={IC_L1}

C1 2 3 0.35p

D1 2 3 Diode

L2 3 0 0.6n IC={IC_L2}

.model Diode D (IS=0.5p, N=1.3,VJ=0.5, M=0.235, RS=0.00,IBV=10u, BV=60,TT=30n,FC=0.8)

.probe V(1) V(2) V(3) I(L1) I(L2) I(vin) * I(vin) represents the integration of magnetic fields

.end

Circuit2

.param V1=

.param V2=

.param V3=

.param IC_L1=

.param IC_L2= * V1,V2,V3,IC_L1,IC_L2 are from previous time step

.param Vm= * Vm represents the integration of electric fields

.param dt= * dt is determined by EM code

.tran {dt/2} {dt} uic

.ic v(1)={V1}

.ic v(2)={V2}

.ic v(3)={V3}

vin 1 0 pwl(0 {V1} {dt} {Vm})

L1 1 2 0.6n IC={IC_L1}

L2 2 3 0.6n IC={IC_L2}

C1 3 0 0.35p

D1 3 0 Diode

.model Diode D (IS=0.5p, N=1.3,VJ=0.5, M=0.235, RS=0.00,IBV=10u, BV=60,TT=30n,FC=0.8)

.probe V(1) V(2) V(3) I(L1) I(L2) I(vin) * I(vin) represents the integration of magnetic fields

.end

And My problems are:

1> EM-ngspice (Circuit2) works and EM-ngspice (Circuit1) fails. In EM-ngspice (Circuit1), the EM-ngspice interface fails to converge, namely at a specific time step, the conditions 2 and 3 cannot be satisfied with a acceptable tolerance.

The results, however, seems unacceptable for me. Circuit1 and Circuit2 should have the same output with the same input. The position of L2 should not affect the current go through the voltage source since it is lumped circuits. The only difference I have ever found, is that in Circuit2, I(vin),I(L1) and I(L2) are the same; while in Circuit1, I(vin), I(L1) are the same, but I(L2) are different from I(vin) and I(L1), though the difference is very small. Therefore, I would assume it is the difference cause the interface problem.

Nevertheless, I cannot explain well on how convergence fails because of the difference of the currents. My guess are as follows: (a) the difference of I(L1) and I(L2) will cause the V2-V3 a very small error. This error, however, will be amplified by the small resistance and large diffusion capacitance of diode, when the voltage across the diode exceeds some positive value. The error is reflected in the current going through the circuits, and when it is big, the EM-ngspice interface fails to converge. (b) the v(2)-v(3) error and the I(vin)-I(L2) error do not matter at first. But since the current on the inductor is the integration of voltage, this error would accumulate, and at a specific time, it makes the EM-ngspice interface fails.

But, I compared these two circuits with some parameters in HSPICE and found the results of I(vin), I(L1), and I(L2) are the same in both circuits.

My question then is, is keeping I(L1) and I(L2) different on purpose, or is keeping them the same difficult? The difference between I(L1) and I(L2) may be acceptable in pure circuit design, but it might actually cause the problem for integration.

However, my thinking may be totally wrong and it may not be the difference between I(vin), I(L1) and I(L2) that cause the convergence problem. Any advice is welcomed.

2> My second question is the way to retain the diode conditions from one step to the next. You may see I set RS in the diode model to 0 in ngspice. It is done on purpose because whenever I set a value to RS, say 0.13, the result of the microstrip is not right as compared with a reference (the same EM-circuit configuration in CST Design Studio). I assume the value to determine the equivalent current source and capacitance in the diode model is the voltage across them. So when there is a series resistor in the diode model, it is enough for me to keep track of V(2)-V(3) at one time step and retain the condition of the diode by set IC={V(2)-V(3)} at the next? Or should I save the value of the voltage across the equivalent current source and capacitor but not the total voltage across the diode?

I haven't go to the transistor by now, but I think retain the condition of a transistor may be more difficult.

3> My third question is, ngspice seems to have a minimum number of time step. However, note that in one (EM-ngspice) time step from n to n+1, ngspice will run with multiple time steps. Currently, dt of the EM-ngspice integration is determined by the EM code. But in the EM simulation, the dt may be already very small, as constrained by geometry feature. Is it safe to decrease the minimum number of time steps in ngspice to a smaller value, such as 5?

Any advice for these problems is appreciated. Thanks.

Last edit: jlu 2014-06-17