From 0638aaa1604c3f94221f0a3e489f956ed870043a Mon Sep 17 00:00:00 2001 From: Keith OHara Date: Mon, 6 Apr 2026 00:01:12 +0200 Subject: [PATCH] Continue Newton iteration until currents settle. For each type of device, a *convTest function determines if the current through that device is converged within tolerance, and sets CKTnoncon if the current is not yet converged. ASCRconvTest() erroneously subtracted old current from old, rather than old from new, when evaluating convergence. Also, since at least 3f5, the calling function NIconvTest assumed that the worker functions indicated non-convergence through their return value, so was ignoring the reports of current nonconvergence. --- src/maths/ni/niconv.c | 9 +++++++++ src/spicelib/devices/asrc/asrcconv.c | 2 +- tests/regression/misc/Makefile.am | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/maths/ni/niconv.c b/src/maths/ni/niconv.c index 5d24a23bf..355fa5bd8 100644 --- a/src/maths/ni/niconv.c +++ b/src/maths/ni/niconv.c @@ -81,6 +81,15 @@ NIconvTest(CKTcircuit *ckt) #ifdef NEWCONV i = CKTconvTest(ckt); + /* The individual testers, called by CKTconvTest, set + * ckt->CKTnoncon and ckt->CKTtroubleElt appropriately. */ + if (ckt->CKTnoncon != 0) { + ckt->CKTtroubleNode = 0; + return(1); + } + /* CKTconvTest early-returns nonzero 'i' on the first error + * in evaluating convergence (such as parameter out of range) so + * there may be untested devices that have not yet converged */ if (i) ckt->CKTtroubleNode = 0; return(i); diff --git a/src/spicelib/devices/asrc/asrcconv.c b/src/spicelib/devices/asrc/asrcconv.c index 4fa584a74..459838797 100644 --- a/src/spicelib/devices/asrc/asrcconv.c +++ b/src/spicelib/devices/asrc/asrcconv.c @@ -32,7 +32,7 @@ ASRCconvTest(GENmodel *inModel, CKTcircuit *ckt) } for (i = 0; i < here->ASRCtree->numVars; i++) - asrc_vals[i] = ckt->CKTrhsOld[here->ASRCvars[i]]; + asrc_vals[i] = ckt->CKTrhs[here->ASRCvars[i]]; if (here->ASRCtree->IFeval(here->ASRCtree, ckt->CKTgmin, &rhs, asrc_vals, asrc_derivs) != OK) diff --git a/tests/regression/misc/Makefile.am b/tests/regression/misc/Makefile.am index 5c9ac9d80..d485a8f10 100644 --- a/tests/regression/misc/Makefile.am +++ b/tests/regression/misc/Makefile.am @@ -1,7 +1,7 @@ ## Process this file with automake to produce Makefile.in -TESTS = bugs-1.cir bugs-2.cir dollar-1.cir empty-1.cir resume-1.cir log-functions-1.cir alter-vec.cir test-noise-2.cir test-noise-3.cir ac-zero.cir asrc-tc-1.cir asrc-tc-2.cir if-elseif.cir +TESTS = bugs-1.cir bugs-2.cir dollar-1.cir empty-1.cir resume-1.cir log-functions-1.cir alter-vec.cir test-noise-2.cir test-noise-3.cir ac-zero.cir asrc-tc-1.cir asrc-tc-2.cir if-elseif.cir convergence.cir TESTS_ENVIRONMENT = ngspice_vpath=$(srcdir) $(SHELL) $(top_srcdir)/tests/bin/check.sh $(top_builddir)/src/ngspice