Trunc() bug - simulator occasionally ignores trunc() timestep

I might be quibbling or misunderstanding but the above is not quite right.

After QSpice does some initialization, the simulation cycle works like this:

  1. Call MaxExtStepSize(). QSpice selects a next timepoint/step not greater than the returned step size.
  2. [If Trunc() present] Call Trunc() with the next hypothetical timestep values. Keep calling Trunc() until the value returned in *timestep would no longer reduce the next timestep.
  3. Call the evaluation function with the final timepoint value. Commit the results to the simulation data.
  4. If not finished, goto 1.

So, if Trunc() is not present, calculations in (1) and (3) are executed only once per simulation data point. There is no speed advantage to doing a calculation in MaxExtStepSize() vs the evaluation function.

On the other hand, if Trunc() is present, things change. The canonical Trunc() function calls the evaluation function with a hypothetical timepoint/step. The eval code is executed at least twice (at least once in (2) and exactly once in (3)). So the calculations are done multiple times. If you are choosing between putting code in MaxExtStepSize() vs the eval function, the former guarantees the calculation is done only once per timestep whether or not Trunc() is implemented.

Alternatively (and more generally), if you have eval function code that you don’t want executed when called from Trunc(), you can test the ForKeeps flag. QSpice clears the flag before (2) and sets it before (3).

Hope the quibbling was helpful.

–robert

1 Like