Dune’s defaults and SPICE compatibility

spice reads SPICE3 netlists and runs SPICE3f5’s device models and analyses. In a few places its engine, Dune, does something else by default than SPICE3 does — only where the result is measurably closer to the converged answer at the same timestep. This vignette shows what changes, and the one option that turns it all back.

library(spice)

The option

compat selects the profile of defaults: "dune" (the default) or "spice3". It can be given from R or on a .options card of the deck.

spice_run(deck, options = list(compat = "spice3"))

Under compat = "spice3":

Single options still win over the profile: method = "trap" under the Dune profile integrates with the trapezoidal rule and keeps everything else.

A switch that is late

A relaxation oscillator: 10 V charges 100 nF through 10 kOhm, and a switch across the capacitor closes at 7 V and opens again at 3 V. Its period has a closed form.

Schematic of the relaxation oscillator: Vdd charges C1 through R1, and a switch across C1 is controlled by the voltage of C1 itself.

deck <- "relaxation oscillator
vdd 1 0 10
r1 1 2 10k
c1 2 0 100n ic=0
s1 2 0 2 0 sdis
.model sdis sw vt=5 vh=2 ron=100 roff=1e9
.tran 50u 20m uic
.end"

rp <- 1e4 * 100 / 1.01e4
vinf <- 10 * 100 / 1.01e4
exact <- 1e4 * 100e-9 * log(7 / 3) +
  rp * 100e-9 * log((7 - vinf) / (3 - vinf))
exact
#> [1] 0.0008558782

The periods of a run are the spacings of the peaks of the capacitor voltage:

periods <- function(res) {
  v <- res |> spice_tidy("tran", "v(2)")
  i <- seq(2, nrow(v) - 1)
  peak <- i[v$value[i] >= v$value[i - 1] & v$value[i] > v$value[i + 1] &
    v$value[i] > 6]
  diff(v$scale[peak])
}

dune <- periods(spice_run(deck))
spice3 <- periods(spice_run(deck, options = list(compat = "spice3")))

With the flip located, every cycle is the same and matches the closed form:

range(dune / exact - 1)
#> [1] 0.0002553887 0.0003282992

On the 50 us grid of the deck the switch flips up to a step late, and by a different amount every cycle:

range(spice3 / exact - 1)
#> [1] -0.148936536 -0.004992686

When to ask for SPICE3

Otherwise the defaults are the better answer at the same cost: over the engine’s corpus of transient decks, the error at the deck’s own step is several times smaller for a few percent more timepoints.