8
\$\begingroup\$

I am curious about what numerical methods are used in circuit simulation. Googling around, I did not find many technical descriptions of the actual numerical methods used for example by the variety of SPICE simulators.

I am not curious about using a simulator, or analyzing circuits, but understanding what the actual numerical methods used are, how they are implemented, etc. What are the key resources?

\$\endgroup\$
3
  • \$\begingroup\$ There are (at least) two main considerations: 0. Is the problem linear or non-linear? 1. Are you looking at a steady-state solution or what happens over time? These make a big difference to the methods commonly used. \$\endgroup\$ Nov 27, 2022 at 23:00
  • \$\begingroup\$ In addition to the SPICE2 Thesis document and the "Inside SPICE" textbook mentioned in the answers, take a look at the author of LTspice's SPICE Differentiation article here. Scroll down to the "Implicit Integration" section and also check out footnotes #5 and #6. The jist is that equations involving capacitors and inductors (stiff equations) can result in high instability when not using implicit integration. Therefore, Trap and Gear (and backward Euler) are the only methods used as they are "stiffly stable". \$\endgroup\$
    – Ste Kulov
    Nov 28, 2022 at 7:31
  • \$\begingroup\$ And one more resource is The Designer's Guide to SPICE and Spectre which in Chapter 4 shows the "region of stability" (mentioned in the SPICE2 thesis) for various integration methods applied to a trivial test circuit. \$\endgroup\$
    – Ste Kulov
    Nov 28, 2022 at 7:35

3 Answers 3

25
\$\begingroup\$

For an overview of numerical methods in circuit simulation, I'd suggest reading some of the published SPICE papers, and in particular Laurence Nagel's exemplary PhD thesis:

From the abstract:

The numerical methods that are employed in [versions 1 and 2] of SPICE are presented in detail. These methods are chosen according to guidelines that are presented in the introductory sections of this thesis. Different guidelines probably would result in the implementation of different methods. The widespread use of SPICE, however, indicates that the algorithms that are employed in SPICE are applicable to a wide range of practical circuit simulation problems.

Nagel was the "ad-hoc team leader" of the simulator CANCER, which was an MSc class project at the University of California Berkeley. This was renamed SPICE, released in 1971. It was written in Fortran; Nagel earned his PhD with SPICE v2. Then others took over the program. SPICE was rewritten in C and released as SPICE 3 in 1989. As it was open source, this was the basis of the other SPICE programs.

As a thesis, it is extremely well-written and covers the material clearly, covering the state of the field at that time. As the most influential simulator, it was the starting point for pretty much every subsequent project of this kind. Regarding numerical methods, the conclusions are especially clear about which work well and their performance issues in space, time and the need for stiffness-stability. About a third of the bibliography is about numerical methods.

The numerical methods covered are:

enter image description here

  • If you want to read the original SPICE2 FORTRAN code, it is available at Berkeley with many other historical documents.
  • If you're doing any numerical work, a critical resource is Numerical Recipes: The Art of Scientific Computing, William H.; Teukolsky, Saul A.; Vetterling, William T.; Flannery, Brian P. Cambridge University Press, various editions and versions. Wikipedia article covers versions and alternatives.
\$\endgroup\$
2
  • 3
    \$\begingroup\$ This is the answer, and probably more than what the OP wanted to know lol. \$\endgroup\$
    – DKNguyen
    Nov 26, 2022 at 17:44
  • 3
    \$\begingroup\$ Very possibly too much, but it's probably the definitive overview work on what mathematical models are actually used in circuit simulation. Everything earlier was building up to this; everything after was built on top of this. \$\endgroup\$
    – jonathanjo
    Nov 26, 2022 at 18:42
12
\$\begingroup\$

Because most interesting circuits are non-linear the nodal equations can't be solved directly by straightforward methods (eg. LU decomposition), so Newton-Raphson method is applied to converge to a solution within tolerance criteria. Nonlinear components are linearized about an operating point and a new operating point is calculated, repeating until convergence is achieved.

Once an operating point has been found, for transient analysis a numerical integration (using one of several possible methods) is used to calculate the effect of capacitors and inductors for the next time step and the process repeats. Time steps are dynamically chosen from tolerance criteria.

For AC analysis, the operating point is calculated and linear models are used.


You can refer to documents such as UC Berkeley memorandum ERL-M520 (424 pages) authored by one of the originators of SPICE. For example, he discusses Runge-Kutta and its drawbacks and modifications.

The book Inside SPICE by Ron Kielkowski has a lot of detailed information, concentrating on SPICE 2g.6. The information on the timestep control algorithm variations may be of interest.

From here is a flowchart of the program flow:

enter image description here

Of course you can download the source code for some versions of SPICE (Berkeley has some C code available) and examine it.

\$\endgroup\$
10
\$\begingroup\$

Most of them use either the plain trapezoidal approximation or Gear integration. LTspice specifically also has a proprietary modified trapezoidal method that they claim is less prone to spurious oscillation than standard trap but more accurate than Gear.

It would theoretically be possible to use other differential equation solvers, like the Runge-Kutta method or the Yoshida algorithm, but for one reason or another they don't tend to.

It might be enlightening, if you want to know more, to look at the code of open-source SPICE implementations, as well as non-SPICE simulators like QUCS. Or to just read some books on numerical integration and linear algebra.

\$\endgroup\$
4
  • \$\begingroup\$ Thanks :) . Yes this is actually something I did - had a quick look at ngspice. I come from about of computational background, and I was surprised by a few things. Like, not seeing some RK4, using (though I guess it is for post processing) a custom FFT instead of FFTW, etc. \$\endgroup\$
    – Zorglub29
    Nov 26, 2022 at 15:52
  • 1
    \$\begingroup\$ @Zorglub29 Remember also that much of the codebase of SPICE dates from 1989, with parts that go all the way back to 1973. Computer science wasn't nearly as advanced as it is now. And since it's a de facto standard, it's advantageous to keep most behaviour the same, since you may want to be able to use SPICE models made decades ago and still get the same results. You also want to be able to move models from one simulator to another. \$\endgroup\$
    – Hearth
    Nov 26, 2022 at 17:24
  • 1
    \$\begingroup\$ @Zorglub29 Drastic changes to the numerical algorithms used could render previously-stable models unstable if they were poorly made (and if you're using SPICE, get used to poorly-made models. Some are good, but lots of them are "good enough".). It could also just slow down the simulation speed; I'm already working with simulations that take six hours to run; adding more complexity to the algorithm, even if the results are a fraction more accurate, is not what I want to do there. \$\endgroup\$
    – Hearth
    Nov 26, 2022 at 17:26
  • \$\begingroup\$ Ok, many thanks for the explanations. Interesting to hear that a lot is legacy. Actually, wondering if it is possible to perform some improvements anno 2022... For example, each step of RK4 is more expensive, but also much more accurate than trapezoidal. So to get the same accuracy, it may be much faster to use fewer larger RK4 steps than more shorter trapezoidal steps - at least this is how it is in CFD :) . \$\endgroup\$
    – Zorglub29
    Nov 26, 2022 at 21:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.