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.
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.
Under compat = "spice3":
trtol allowance as is;u()/sgn() in a B source,
flips at whatever timepoint first sees its control past the threshold
(Dune: at the instant it crosses, located to reltol times
the maximum step);Single options still win over the profile:
method = "trap" under the Dune profile integrates with the
trapezoidal rule and keeps everything else.
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.
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.0008558782The 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:
On the 50 us grid of the deck the switch flips up to a step late, and by a different amount every cycle:
compat = "spice3" is the profile Dune’s own test suite uses
against ngspice.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.