Observed on pre-master-47, without any of the patches of this series.
The report is written for maintainers; the loop gain patch of the series
only steps around the problem locally, it does not fix it.
A batch deck with two frequency domain analyses around a real valued one:
klu refactor crash
.option klu
vin in 0 dc 0 ac 1
r1 in out 1k
c1 out 0 159n
.ac dec 4 1 1k
.tran 1u 20u
.ac dec 4 1 1k
.print ac v(out)
.end
Run it in batch mode:
ngspice -b klu.cir
The second .ac crashes in klu_z_refactor(), klu_refactor.c:383.
The same happens on the pause and resume path: pause a transient analysis,
let another analysis run, then resume.
The analyses which work in the frequency domain rebind the matrix of the
KLU solver to complex storage before they start, and back to real storage
when they are done, acan.c:339-352 and acan.c:393-401. The reordering
of the matrix, on the other hand, is asked for once: NIACSHOULDREORDER
and NISHOULDREORDER in ckt->CKTniState are consumed by the first
analysis which sees them, niaciter.c and niiter.c, and the following
analyses call SMPcLUfac(), which refactors the existing symbolic
factorization.
The symbolic factorization which the second .ac inherits belongs to the
real valued analysis which ran in between, so klu_z_refactor() works on
storage which does not match it.
Interactive use hides this: each command re-sets up the circuit and arms
the reorder flags again, so a sequence of ac, tran, ac typed at the
prompt is fine. Only a batch deck, where doAnalyses() walks the job list
without a new setup, and the pause and resume path reach the defect.
Arming NIACSHOULDREORDER when an analysis switches the binding of the
matrix would be the obvious place; the cost is one reordering per analysis.
The loop gain analysis of the accompanying series does this for itself:
/* stban.c, before the sweep */
ckt->CKTniState |= NIACSHOULDREORDER;
It keeps a sequence of a real valued analysis followed by .stb clear of
the crash, and it is commented as hardening against this upstream defect,
not as a part of the analysis.
ngspice pre-master-47, x86_64 Linux, gcc 13.3
../configure --with-x --enable-xspice --enable-cider --enable-openmp \
--with-readline=no CFLAGS="-O1 -g -Wall"