EEVblog Electronics Community Forum

Electronics => Projects, Designs, and Technical Stuff => Topic started by: matthuszagh on February 25, 2024, 02:20:46 am

Title: Increase LTSpice speed for simple circuit
Post by: matthuszagh on February 25, 2024, 02:20:46 am
I'm simulating an AC/DC power supply in LTSpice. I mostly use ngspice, but I'm using some Linear Technology parts and AD doesn't release spice models for a lot of their parts  >:( so I'm using ltspice for this. I'm new to ltspice so I thought I'd run a simple simulation up through the rectifier and filters. This is going extremely slow, though. I'm in the low 10s of ns/s speed range. These sorts of things have always been very fast with ngspice, so I figure I must just be using ltspice incorrectly. Am I (see screenshot)? Would someone mind pointing out my issue. This is running on a modern, fast desktop.
Title: Re: Increase LTSpice speed for simple circuit
Post by: moffy on February 25, 2024, 03:07:07 am
I ran your sim with the generic diodes and ran into the same slow performance when I replaced the diodes with real world diodes (MBR745) the sim was very fast, you might want to replace the generic D diodes.
Title: Re: Increase LTSpice speed for simple circuit
Post by: RoGeorge on February 25, 2024, 03:14:06 am
Try adding a new spice directive, and type in it:
.options method=gear
https://ltwiki.org/LTspiceHelp/LTspiceHelp/_OPTIONS_Set_simulator_options.htm
If not try .options method=trap

Also, attach the .asc file, so others can run the same simulation as you.
Title: Re: Increase LTSpice speed for simple circuit
Post by: matthuszagh on February 25, 2024, 03:16:15 am
Also, attach the .asc file, so others can run the same simulation as you.

My bad - I had this in mind and then forgot. Anyway, here it is.
Title: Re: Increase LTSpice speed for simple circuit
Post by: SiliconWizard on February 25, 2024, 04:50:23 am
Use the alternate solver (in Settings/Spice). The sim runs nearly instant with this, and very slow with the "normal" solver.
I always set it to "alternate" btw. So I didn't notice this was slow, and had to fiddle with options to figure out why.

As moffy pointed out, the real "culprit" here is using generic diodes, which model ideal diodes (that will make very severe non-linearities that are hard on the solver). So even if using the alternate solver makes the sim very fast, I'd still recommend assigning "real" diode models. Otherwise, your sim won't be realistic anyway.
Title: Re: Increase LTSpice speed for simple circuit
Post by: temperance on February 25, 2024, 01:10:10 pm
Adding high value resistor in parallel with diodes performing some switching action in a circuit can also speed up the simulation.
Title: Re: Increase LTSpice speed for simple circuit
Post by: moffy on February 25, 2024, 09:22:34 pm
Yeah and as SiliconWizard mentioned, LTSpice and SPICEs don't like discontinuities, they really don't like ideal switches.
Title: Re: Increase LTSpice speed for simple circuit
Post by: SiliconWizard on February 25, 2024, 09:33:07 pm
Note that, if comparing to ngspice as the OP did, the situation is different regarding the diode models: in ngspice, I bet the OP had defined a diode model with at least some basic parameters. And then, of course, the solvers are different and they can make a big difference in how the simulation converges.

If you just add a generic diode in LTSpice, and do not assign the symbol any specific model, it gets default values, which are listed in LTSpice's help: https://ltwiki.org/LTspiceHelp/LTspiceHelp/D_Diode.htm
As you can see, this will be an idealized diode. Almost never use an idealized diode in a Spice simulation unless you perfectly know why you are.
Title: Re: Increase LTSpice speed for simple circuit
Post by: matthuszagh on February 25, 2024, 09:35:36 pm
Yeah and as SiliconWizard mentioned, LTSpice and SPICEs don't like discontinuities, they really don't like ideal switches.

Makes sense - and I was aware about this with spice. My surprise here was more that the generic diode provides an ideal device. In ngspice, the generic diode is a model of what they deem to be a "typical" diode (it just uses the default model parameters). If you truly wanted an ideal diode you could do such a thing with xspice, which allows you to specify your own transfer functions and that sort of thing, or probably by defining a diode model accordingly. I've found the performance of most xspice models to be fine, but I haven't tried this specific case so I don't know how it would compare.

The choice to make the generic diode ideal seems strange to me. But maybe there's something I'm not considering. Anyway, thanks to the help here my sim is now running quickly and for next time I'll know not to use the generic components.
Title: Re: Increase LTSpice speed for simple circuit
Post by: Ian.M on February 25, 2024, 09:48:25 pm
As moffy pointed out, the real "culprit" here is using generic diodes, which model ideal diodes (that will make very severe non-linearities that are hard on the solver). So even if using the alternate solver makes the sim very fast, I'd still recommend assigning "real" diode models. Otherwise, your sim won't be realistic anyway.
Its worth noting that even 0.1pF in parallel with each offending ideal diode makes this sim run at pretty much full speed.  It gives somewhere for residual current at the discontinuity to go without infinite dV/dt.

A similar result can be achieved in the original sim by adding a tiny capacitance to ground to all nodes with:
Code: [Select]
.opt cshunt=0.1p