From 2ad97feb3129248c25a600bebe9317ef4bc3050d Mon Sep 17 00:00:00 2001 From: Giles Atkinson <“gatk555@gmail.com”> Date: Fri, 12 Jan 2024 17:14:05 +0000 Subject: [PATCH 1/7] A quick fix for a bug reported in the Help forum by Tom Hajjar on Jan 6 2024. Prevent the TRA device from requesting a breakpoint in the past, as that is a hard error. --- src/spicelib/devices/tra/traacct.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/spicelib/devices/tra/traacct.c b/src/spicelib/devices/tra/traacct.c index 5198df4ac..3e95b3f28 100644 --- a/src/spicelib/devices/tra/traacct.c +++ b/src/spicelib/devices/tra/traacct.c @@ -107,19 +107,16 @@ TRAaccept(CKTcircuit *ckt, GENmodel *inModel) here->TRAabstol) || (fabs(d3-d4) >= here->TRAreltol*MAX(fabs(d3),fabs(d4))+ here->TRAabstol) ) { - /* derivitive changing - need to schedule after delay */ - /*printf("%s: at %g set for %g\n",here->TRAname, - ckt->CKTtime, - *(here->TRAdelays+3*here->TRAsizeDelay-3)+here->TRAtd - );*/ - /*printf("%g, %g, %g -> %g, %g \n",v1,v2,v3,d1,d2);*/ - /*printf("%g, %g, %g -> %g, %g \n",v4,v5,v6,d3,d4);*/ - /* also set for break after PREVIOUS point */ - /*printf("setting break\n");*/ - error = CKTsetBreak(ckt, - *(here->TRAdelays+3*here->TRAsizeDelay -3) + - here->TRAtd); - if(error) return(error); + double when; + + /* Derivative changed - need to schedule after delay */ + + when = *(here->TRAdelays + 3 * here->TRAsizeDelay - 3) + + here->TRAtd; + if (when > ckt->CKTtime) { + error = CKTsetBreak(ckt, when); + if(error) return(error); + } } #endif /*NOTDEF*/ } From d86a0c77cb8aa3fcf9dceb3fd161d945f14165d0 Mon Sep 17 00:00:00 2001 From: Giles Atkinson <“gatk555@gmail.com”> Date: Sat, 13 Jan 2024 18:06:46 +0000 Subject: [PATCH 2/7] Improve scheduling of breakpoints for V-source (PULSE and PWL). This fixes bugs with the TRA delay line reported by Tom Hajjar in the Help forum, Jan 11 2024. --- src/spicelib/devices/vsrc/vsrcacct.c | 33 +++++++++++++++++++++------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/spicelib/devices/vsrc/vsrcacct.c b/src/spicelib/devices/vsrc/vsrcacct.c index 36994a837..df890ed76 100644 --- a/src/spicelib/devices/vsrc/vsrcacct.c +++ b/src/spicelib/devices/vsrc/vsrcacct.c @@ -92,7 +92,7 @@ VSRCaccept(CKTcircuit *ckt, GENmodel *inModel) } if (ckt->CKTtime >= here->VSRCbreak_time) { - double wait; + double wait, atime; if (time >= PER) { /* Repeating signal: where in period are we? */ @@ -101,26 +101,35 @@ VSRCaccept(CKTcircuit *ckt, GENmodel *inModel) time -= basetime; } + /* A request for a breakpoint very close + * to the current time will be ignored. + * Adjust so the next corner will be + * selected. + */ + + atime = time + ckt->CKTminBreak; + /* Set next breakpoint. */ - if (time < 0.0) { + if (atime < 0.0) { /* Await first pulse */ wait = -time; - } else if (time < TR) { + } else if (atime < TR) { /* Wait for end of rise. */ wait = TR - time; - } else if (time < TR + PW) { + } else if (atime < TR + PW) { /* Wait for fall. */ wait = TR + PW - time; - } else if (time < TR + PW + TF) { + } else if (atime < TR + PW + TF) { /* Wait for end of fall. */ wait = TR + PW + TF - time; } else { /* Wait for next pulse. */ + wait = PER - time; } here->VSRCbreak_time = ckt->CKTtime + wait; @@ -160,7 +169,7 @@ VSRCaccept(CKTcircuit *ckt, GENmodel *inModel) case PWL: if (ckt->CKTtime >= here->VSRCbreak_time) { - double time, end, period; + double time, atime, end, period; int i; time = ckt->CKTtime - here->VSRCrdelay; @@ -183,10 +192,18 @@ VSRCaccept(CKTcircuit *ckt, GENmodel *inModel) } } + /* A request for a breakpoint very close + * to the current time will be ignored. + * Adjust so the next corner will be + * selected. + */ + + atime = time + ckt->CKTminBreak; + for (i = 0; i < here->VSRCfunctionOrder; i += 2) { - if (here->VSRCcoeffs[i] > time) { + if (here->VSRCcoeffs[i] > atime) { here->VSRCbreak_time = ckt->CKTtime + here->VSRCcoeffs[i] - time; @@ -257,7 +274,7 @@ VSRCaccept(CKTcircuit *ckt, GENmodel *inModel) if (ckt->CKTtime >= state->RTScapTime - ckt->CKTminBreak && ckt->CKTtime <= - state->RTScapTime + ckt->CKTminBreak) { + state->RTScapTime + ckt->CKTminBreak) { error = CKTsetBreak(ckt, state->RTSemTime); if(error) return(error); From 5266a7c4bc1b8a1d7a863bb371bf348a083e06cd Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sun, 14 Jan 2024 11:16:45 +0100 Subject: [PATCH 3/7] If there is a successful step, but the goal is not yet reached, don't start with the minimum value of 1.00005, as this may last forever. Restart with 3. --- src/spicelib/analysis/cktop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spicelib/analysis/cktop.c b/src/spicelib/analysis/cktop.c index 06983ff6e..ccc1efad9 100644 --- a/src/spicelib/analysis/cktop.c +++ b/src/spicelib/analysis/cktop.c @@ -409,7 +409,7 @@ new_gmin(CKTcircuit* ckt, long int firstmode, } if (iters > (3 * ckt->CKTdcTrcvMaxIter / 4)) - factor = MAX(sqrt(factor), 1.00005); + factor = MAX(sqrt(factor), 3); OldGmin = ckt->CKTgmin; From f541c6fb051869bb3950be551bd9c85e9ed01249 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sun, 14 Jan 2024 14:31:02 +0100 Subject: [PATCH 4/7] C:\Spice64 is again the default install directory for ngspice made by MSVC. --- visualc/make-install-vngspice.bat | 2 +- visualc/make-install-vngspiced.bat | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/visualc/make-install-vngspice.bat b/visualc/make-install-vngspice.bat index 6894d84b2..871abf6d9 100644 --- a/visualc/make-install-vngspice.bat +++ b/visualc/make-install-vngspice.bat @@ -34,7 +34,7 @@ goto end :b64 -set dst=c:\Spice64_KLU +set dst=c:\Spice64 set cmsrc=.\codemodels\x64\Release mkdir %dst%\bin diff --git a/visualc/make-install-vngspiced.bat b/visualc/make-install-vngspiced.bat index 529f324b4..a75f8c705 100644 --- a/visualc/make-install-vngspiced.bat +++ b/visualc/make-install-vngspiced.bat @@ -34,7 +34,7 @@ goto end :b64 -set dst=c:\Spice64d_KLU +set dst=c:\Spice64d set cmsrc=.\codemodels\x64\Debug mkdir %dst%\bin From 0141473aa4020840c1faa91ec1933f8588520545 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sun, 14 Jan 2024 15:12:03 +0100 Subject: [PATCH 5/7] Don't derefence Matrix->SMPkluMatrix->KLUmatrixCommon if it is NULL. Test for NULL moved upwards in front of dereferencing. --- src/maths/KLU/klusmp.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/maths/KLU/klusmp.c b/src/maths/KLU/klusmp.c index 174dee419..d22c36f94 100644 --- a/src/maths/KLU/klusmp.c +++ b/src/maths/KLU/klusmp.c @@ -535,6 +535,10 @@ SMPcLUfac (SMPmatrix *Matrix, double PivTol) if (ret == 0) { + if (Matrix->SMPkluMatrix->KLUmatrixCommon == NULL) { + fprintf(stderr, "Error (ReFactor Complex): KLUcommon object is NULL. A problem occurred\n"); + return 0 ; + } if (Matrix->SMPkluMatrix->KLUmatrixCommon->status == KLU_SINGULAR) { if (ft_ngdebug) { fprintf(stderr, "Warning (ReFactor Complex): KLU Matrix is SINGULAR\n"); @@ -543,9 +547,6 @@ SMPcLUfac (SMPmatrix *Matrix, double PivTol) } return E_SINGULAR ; } - if (Matrix->SMPkluMatrix->KLUmatrixCommon == NULL) { - fprintf (stderr, "Error (ReFactor Complex): KLUcommon object is NULL. A problem occurred\n") ; - } if (Matrix->SMPkluMatrix->KLUmatrixCommon->status == KLU_EMPTY_MATRIX) { fprintf (stderr, "Error (ReFactor Complex): KLU Matrix is empty\n") ; From 79e80dbbab299b19c94a95b06524b0b5c9f90548 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Mon, 15 Jan 2024 09:59:21 +0100 Subject: [PATCH 6/7] Automatically adding diode RS only when variable 'rsdiode' is set to a positive resistance value. --- src/spicelib/devices/dio/diosetup.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/spicelib/devices/dio/diosetup.c b/src/spicelib/devices/dio/diosetup.c index 6bf8e14da..2c549e03d 100644 --- a/src/spicelib/devices/dio/diosetup.c +++ b/src/spicelib/devices/dio/diosetup.c @@ -197,9 +197,14 @@ DIOsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states) if((!model->DIOresistGiven) || (model->DIOresist==0)) { if (newcompat.ps || newcompat.lt) { - model->DIOconductance = 1e4; /* improved convergence */ - if (ft_ngdebug) - fprintf(stderr, "Diode series resistance in model %s set to 100 microOhm\n", model->gen.GENmodName); + double rsdiode = 0.; + if (cp_getvar("rsdiode", CP_REAL, &rsdiode, 0) && rsdiode > 0) { + model->DIOconductance = 1./rsdiode; /* sometimes improves convergence */ + if (ft_ngdebug) + fprintf(stderr, "Diode series resistance in model %s set to 100 microOhm\n", model->gen.GENmodName); + } + else + model->DIOconductance = 0.0; } else model->DIOconductance = 0.0; From a0bddf872d22514cc724f4e6b3ad759085a3fda7 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Mon, 15 Jan 2024 11:10:50 +0100 Subject: [PATCH 7/7] Fix dd7b9ff27 ("Avoid memory crash when reading old VDMOS models. Enable both old and current model format.", 2023-12-30) --- src/frontend/inpcom.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/frontend/inpcom.c b/src/frontend/inpcom.c index 922393c5c..8f96eee84 100644 --- a/src/frontend/inpcom.c +++ b/src/frontend/inpcom.c @@ -8035,7 +8035,6 @@ static int inp_vdmos_model(struct card *deck) wl_append_word(NULL, &wl, token); else { tfree(token); - break; } if (*cut_line == ')' || *cut_line == '\0') { wl_append_word(NULL, &wl, copy(")"));