From b207d4c90b96bb33b0a95aeea6c4025de09346b7 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Wed, 2 Oct 2024 18:42:06 +0200 Subject: [PATCH 01/10] /openmp:llvm removed from additional options for the 'Release' builds (however keep it in the 'ReleaseOMP' builds). --- visualc/sharedspice.vcxproj | 2 +- visualc/vngspice.vcxproj | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/visualc/sharedspice.vcxproj b/visualc/sharedspice.vcxproj index bce301c2a..c18f68813 100644 --- a/visualc/sharedspice.vcxproj +++ b/visualc/sharedspice.vcxproj @@ -407,7 +407,7 @@ lib /machine:x64 /def:..\..\fftw-3.3-dll64\libfftw3-3.def /out:$(IntDir)libfftw3 Default true stdcpp14 - /openmp:llvm %(AdditionalOptions) + %(AdditionalOptions) psapi.lib;KLU_COMPLEX.lib;%(AdditionalDependencies) diff --git a/visualc/vngspice.vcxproj b/visualc/vngspice.vcxproj index 476250aa7..5281546d0 100644 --- a/visualc/vngspice.vcxproj +++ b/visualc/vngspice.vcxproj @@ -383,7 +383,7 @@ Default true stdcpp14 - /openmp:llvm %(AdditionalOptions) + %(AdditionalOptions) psapi.lib;KLU_COMPLEX.lib;%(AdditionalDependencies) @@ -2896,4 +2896,4 @@ - + \ No newline at end of file From 5ff96c51dd992edf2acad6487a98d4035af516b4 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Wed, 2 Oct 2024 18:56:47 +0200 Subject: [PATCH 02/10] Don't compile with OpenMP support, as it is not used in KLU. --- visualc/KLU/KLU_COMPLEX.vcxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/visualc/KLU/KLU_COMPLEX.vcxproj b/visualc/KLU/KLU_COMPLEX.vcxproj index e4222f58e..e1af1f11b 100644 --- a/visualc/KLU/KLU_COMPLEX.vcxproj +++ b/visualc/KLU/KLU_COMPLEX.vcxproj @@ -236,7 +236,7 @@ MultiThreaded - true + false Level3 @@ -257,7 +257,7 @@ MultiThreaded - true + false Level3 From 8422c1caa18b040670ec12caf1c13e24dd267274 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sat, 5 Oct 2024 19:59:43 +0200 Subject: [PATCH 03/10] Revert the sign of ac_gain.real Fix bug no 697, reported by Matthieu Guerquin-Kern --- src/xspice/icm/xtradev/potentiometer/cfunc.mod | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/xspice/icm/xtradev/potentiometer/cfunc.mod b/src/xspice/icm/xtradev/potentiometer/cfunc.mod index 8b9448c2d..f352a06ec 100644 --- a/src/xspice/icm/xtradev/potentiometer/cfunc.mod +++ b/src/xspice/icm/xtradev/potentiometer/cfunc.mod @@ -194,31 +194,31 @@ void cm_potentiometer (ARGS) ac_gain.imag= 0.0; - ac_gain.real = -1.0 / r_lower; + ac_gain.real = 1.0 / r_lower; AC_GAIN(r0,r0) = ac_gain; ac_gain.real = 0.0; AC_GAIN(r0,r1) = ac_gain; - ac_gain.real = 1.0 / r_lower; + ac_gain.real = -1.0 / r_lower; AC_GAIN(r0,wiper) = ac_gain; ac_gain.real = 0.0; AC_GAIN(r1,r0) = ac_gain; - ac_gain.real = -1.0 / r_upper; + ac_gain.real = 1.0 / r_upper; AC_GAIN(r1,r1) = ac_gain; - ac_gain.real = 1.0 / r_upper; + ac_gain.real = -1.0 / r_upper; AC_GAIN(r1,wiper) = ac_gain; - ac_gain.real = 1.0 / r_lower; + ac_gain.real = -1.0 / r_lower; AC_GAIN(wiper,r0) = ac_gain; - ac_gain.real = 1.0 / r_upper; + ac_gain.real = -1.0 / r_upper; AC_GAIN(wiper,r1) = ac_gain; - ac_gain.real = -(1.0/r_lower) - (1.0/r_upper); + ac_gain.real = (1.0/r_lower) + (1.0/r_upper); AC_GAIN(wiper,wiper) = ac_gain; } From 5493862a1d0466f8798bbf145921ff5959071ba8 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sat, 5 Oct 2024 20:05:54 +0200 Subject: [PATCH 04/10] Some cosmetics --- .../icm/xtradev/potentiometer/cfunc.mod | 68 ++++++------------- 1 file changed, 21 insertions(+), 47 deletions(-) diff --git a/src/xspice/icm/xtradev/potentiometer/cfunc.mod b/src/xspice/icm/xtradev/potentiometer/cfunc.mod index f352a06ec..c7d0a8c36 100644 --- a/src/xspice/icm/xtradev/potentiometer/cfunc.mod +++ b/src/xspice/icm/xtradev/potentiometer/cfunc.mod @@ -8,9 +8,8 @@ Public Domain Georgia Tech Research Corporation Atlanta, Georgia 30332 PROJECT A-8503-405 - -AUTHORS +AUTHORS 19 June 1992 Jeffrey P. Murray @@ -19,7 +18,7 @@ MODIFICATIONS 19 June 1992 Jeffrey P. Murray 22 October 2022 Holger Vogt - + 05 October 2024 Holger Vogt SUMMARY @@ -27,17 +26,16 @@ SUMMARY code model. -INTERFACES +INTERFACES - FILE ROUTINE CALLED + FILE ROUTINE CALLED - CMmacros.h cm_message_send(); + CMmacros.h cm_message_send(); REFERENCED FILES Inputs from and outputs to ARGS structure. - NON-STANDARD FEATURES @@ -49,36 +47,24 @@ NON-STANDARD FEATURES #include - - /*=== CONSTANTS ========================*/ - - /*=== MACROS ===========================*/ - - /*=== LOCAL VARIABLES & TYPEDEFS =======*/ - - /*=== FUNCTION PROTOTYPE DEFINITIONS ===*/ - - - - /*============================================================================== FUNCTION cm_potentiometer() -AUTHORS +AUTHORS 19 June 1992 Jeffrey P. Murray @@ -90,11 +76,11 @@ SUMMARY This function implements the potentiometer code model. -INTERFACES +INTERFACES - FILE ROUTINE CALLED + FILE ROUTINE CALLED - CMmacros.h cm_message_send(); + CMmacros.h cm_message_send(); RETURNED VALUE @@ -123,11 +109,7 @@ void cm_potentiometer (ARGS) double vr1; /* voltage at r1 */ double vwiper; /* voltage at wiper */ - - Mif_Complex_t ac_gain; - - /* Retrieve frequently used parameters... */ @@ -148,29 +130,25 @@ void cm_potentiometer (ARGS) vr1 = INPUT(r1); - if ( PARAM(log) == FALSE ) { + if ( PARAM(log) == FALSE ) { /* Linear Variation in resistance w.r.t. position */ r_lower = position * resistance; r_upper = resistance - r_lower; } - else { + else { /* Logarithmic Variation in resistance w.r.t. position */ - r_lower = resistance / + r_lower = resistance / pow(10.0,(position * PARAM(log_multiplier))); r_upper = resistance - r_lower; } - - - - /* Output DC & Transient Values */ - if(ANALYSIS != MIF_AC) { + if(ANALYSIS != MIF_AC) { OUTPUT(r0) = (vr0 - vwiper) / r_lower; OUTPUT(r1) = (vr1 - vwiper) / r_upper; OUTPUT(wiper) = ((vwiper - vr0)/r_lower) + ((vwiper - vr1)/r_upper); @@ -188,43 +166,39 @@ void cm_potentiometer (ARGS) PARTIAL(wiper,wiper) = (1.0/r_lower) + (1.0/r_upper); } - else { + else { /* Output AC Gain Values */ - ac_gain.imag= 0.0; + ac_gain.imag= 0.0; ac_gain.real = 1.0 / r_lower; AC_GAIN(r0,r0) = ac_gain; - ac_gain.real = 0.0; + ac_gain.real = 0.0; AC_GAIN(r0,r1) = ac_gain; - ac_gain.real = -1.0 / r_lower; + ac_gain.real = -1.0 / r_lower; AC_GAIN(r0,wiper) = ac_gain; ac_gain.real = 0.0; AC_GAIN(r1,r0) = ac_gain; - ac_gain.real = 1.0 / r_upper; + ac_gain.real = 1.0 / r_upper; AC_GAIN(r1,r1) = ac_gain; - ac_gain.real = -1.0 / r_upper; + ac_gain.real = -1.0 / r_upper; AC_GAIN(r1,wiper) = ac_gain; ac_gain.real = -1.0 / r_lower; AC_GAIN(wiper,r0) = ac_gain; - ac_gain.real = -1.0 / r_upper; + ac_gain.real = -1.0 / r_upper; AC_GAIN(wiper,r1) = ac_gain; - ac_gain.real = (1.0/r_lower) + (1.0/r_upper); + ac_gain.real = (1.0/r_lower) + (1.0/r_upper); AC_GAIN(wiper,wiper) = ac_gain; } } - - - - From 5b3b48b913d520e171353b2db7d33eb0d34a9db6 Mon Sep 17 00:00:00 2001 From: briantofleeds Date: Sun, 29 Sep 2024 14:30:52 -0700 Subject: [PATCH 05/10] This does not fix noise analysis with klu. It does add missing { and } when event-driven instances are not present. Without this change CKTop will always be called again directly in NOISEan even if CKTop was previously called by EVTop. This matches the intended behavior before #ifdef KLU was added. --- src/spicelib/analysis/noisean.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/spicelib/analysis/noisean.c b/src/spicelib/analysis/noisean.c index 9c22da199..99e0a393b 100644 --- a/src/spicelib/analysis/noisean.c +++ b/src/spicelib/analysis/noisean.c @@ -189,6 +189,7 @@ NOISEan(CKTcircuit* ckt, int restart) EVTop_save(ckt, MIF_TRUE, 0.0); } else + { // start of no XSPICE event-driven instances #endif #ifdef KLU @@ -216,10 +217,13 @@ NOISEan(CKTcircuit* ckt, int restart) return(error); } } - else + else { fprintf(stdout, "\n Linear circuit, option noopac given: no OP analysis\n"); + } #ifdef XSPICE + } // end of no XSPICE event-driven instances + /* gtri - add - wbk - 12/19/90 - Add IPC stuff */ /* Send the operating point results for Mspice compatibility */ From 223226921799cd5ecda77f77ddf8d801902aa177 Mon Sep 17 00:00:00 2001 From: Brian Taylor Date: Fri, 4 Oct 2024 17:06:54 -0700 Subject: [PATCH 06/10] Added: Error: Pole/zero analysis is not (yet) supported with 'option KLU'. Use 'option sparse' instead. --- src/spicelib/analysis/pzan.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/spicelib/analysis/pzan.c b/src/spicelib/analysis/pzan.c index 9c975889e..faceb6563 100644 --- a/src/spicelib/analysis/pzan.c +++ b/src/spicelib/analysis/pzan.c @@ -26,6 +26,14 @@ PZan(CKTcircuit *ckt, int reset) NG_IGNORE(reset); +#ifdef KLU + if (ckt->CKTkluMODE) { + fprintf(stderr, "Error: Pole/zero analysis is not (yet) supported with 'option KLU'.\n"); + fprintf(stderr, " Use 'option sparse' instead.\n"); + return(E_UNSUPP); + } +#endif + error = PZinit(ckt); if (error != OK) return error; From e658a0942b446d943353dee8c64934dc8180945b Mon Sep 17 00:00:00 2001 From: Giles Atkinson <“gatk555@gmail.com”> Date: Tue, 1 Oct 2024 15:51:11 +0100 Subject: [PATCH 07/10] Try to clarify the mechanism of parameter substitution and add an example of substituting an XSPICE vector parameter. --- examples/numparam/vector_param.cir | 33 ++++++++++++++++++++++++++++++ src/frontend/numparam/numparam.h | 5 +++++ src/frontend/numparam/spicenum.c | 5 +++-- src/frontend/numparam/xpressn.c | 8 +++----- 4 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 examples/numparam/vector_param.cir diff --git a/examples/numparam/vector_param.cir b/examples/numparam/vector_param.cir new file mode 100644 index 000000000..ce79093a9 --- /dev/null +++ b/examples/numparam/vector_param.cir @@ -0,0 +1,33 @@ +.TITLE SUBCKT VECTOR PARAM TEST +* Example of passing a vector parameter to a sub-circuit. +* Modified from https://sourceforge.net/p/ngspice/feature-requests/55/ + +* An AND gate impmented as a LUT in a subcircuit. + +.param default_vec="[1e-12 2e-12]" + *--vector parameter-- +.subckt testcir in0 in1 outlut testpar = {default_vec} + +A_genlut [in0 in1] [outlut] genlut +.model genlut d_genlut ( ++ input_delay = {testpar} ++ table_values = "0001") + +.ends testcir + +V_Vss vss 0 DC 3.3 +V_pulse sine 0 DC 0 SIN(0 1 1000) + +.param actual_vec="[1.3e-3 2e-3]" + *--vector parameter-- +X_subckt no1 dss node3 testcir testpar={actual_vec} + +A_ADC [sine vss] [no1 dss] ADC +.model ADC adc_bridge(in_low=0.7 in_high=0.71) + +.control + tran 20u 4m + plot sine node3 +.endc + +.end diff --git a/src/frontend/numparam/numparam.h b/src/frontend/numparam/numparam.h index 890bf8299..148311149 100644 --- a/src/frontend/numparam/numparam.h +++ b/src/frontend/numparam/numparam.h @@ -20,6 +20,11 @@ extern const struct nupa_type S_nupa_string; extern const struct nupa_type S_nupa_subckt; extern const struct nupa_type S_nupa_unknown; +/* Length of "numparam____ ..." string to be inserted and replaced. */ + +#define ACT_CHARACTS 25 +#define MARKER "numparm__________" + #define NUPA_REAL (&S_nupa_real) #define NUPA_STRING (&S_nupa_string) #define NUPA_SUBCKT (&S_nupa_subckt) diff --git a/src/frontend/numparam/spicenum.c b/src/frontend/numparam/spicenum.c index fc1454759..bd7690e08 100644 --- a/src/frontend/numparam/spicenum.c +++ b/src/frontend/numparam/spicenum.c @@ -121,8 +121,9 @@ stripbraces(DSTRINGPTR dstr_p) cadd(&tstr, ' '); { - char buf[25+1]; - sprintf(buf, "numparm__________%08lx", ++placeholder); + char buf[ACT_CHARACTS + 1]; + + sprintf(buf, MARKER "%08lx", ++placeholder); sadd(&tstr, buf); } cadd(&tstr, ' '); diff --git a/src/frontend/numparam/xpressn.c b/src/frontend/numparam/xpressn.c index a3c049d73..c1bb96208 100644 --- a/src/frontend/numparam/xpressn.c +++ b/src/frontend/numparam/xpressn.c @@ -23,8 +23,6 @@ extern long dynsubst; /* see inpcom.c */ -#define ACT_CHARACTS 25 /* actual string length to be inserted and replaced */ - #define S_init 0 #define S_atom 1 #define S_binop 2 @@ -1165,7 +1163,7 @@ static char *string_expr(dico_t *dico, DSTRINGPTR qstr_p, /* stupid, produce a string representation of a given double * to be spliced back into the circuit deck - * we want *exactly* 25 chars, we have + * we want *exactly* 25 (ACT_CHARACTS) chars, we have * sign, leading digit, '.', 'e', sign, upto 3 digits exponent * ==> 8 chars, thus we have 17 left for precision * don't print a leading '+', something choked @@ -1214,10 +1212,10 @@ insertnumber(dico_t *dico, char **lp, DSTRINGPTR ustr_p) long id = 0; int n; - char *p = strstr(s, "numparm__________"); + char *p = strstr(s, MARKER); if (p && - (1 == sscanf(p, "numparm__________%8lx%n", &id, &n)) && + (1 == sscanf(p, MARKER "%8lx%n", &id, &n)) && (n == ACT_CHARACTS) && (id > 0) && (id < dynsubst + 1)) { /* Found a target for substitution. */ From e0079e1cd56aed4cd4fda8fab9de671d98b883d9 Mon Sep 17 00:00:00 2001 From: Giles Atkinson <“gatk555@gmail.com”> Date: Thu, 3 Oct 2024 18:04:47 +0100 Subject: [PATCH 08/10] Improve an error message. --- src/frontend/evaluate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontend/evaluate.c b/src/frontend/evaluate.c index ee9bec045..42fc4540b 100644 --- a/src/frontend/evaluate.c +++ b/src/frontend/evaluate.c @@ -721,7 +721,7 @@ op_ind(struct pnode *arg1, struct pnode *arg2) v->v_numdims = 1; v->v_dims[0] = v->v_length; if (v->v_length <= 1) { - fprintf(cp_err, "Error: nostrchring on a scalar (%s)\n", + fprintf(cp_err, "Error: indexing a scalar (%s)\n", v->v_name); return (NULL); } From 7c9ac42fd1e9fc2830ee952f5fdea902b7bb431f Mon Sep 17 00:00:00 2001 From: Giles Atkinson <“gatk555@gmail.com”> Date: Tue, 8 Oct 2024 08:53:03 +0100 Subject: [PATCH 09/10] Fix Bug #698 - "Initial transient solution assumes voltage source=0 even if it is not." Cause was another error in ad5bb9eb8d, fix for Bug #607, which uncovered an earlier latent bug. --- src/spicelib/devices/vsrc/vsrcload.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/spicelib/devices/vsrc/vsrcload.c b/src/spicelib/devices/vsrc/vsrcload.c index 54183aaa5..c74c9a756 100644 --- a/src/spicelib/devices/vsrc/vsrcload.c +++ b/src/spicelib/devices/vsrc/vsrcload.c @@ -320,9 +320,8 @@ VSRCload(GENmodel *inModel, CKTcircuit *ckt) double end_time, itime; time -= here->VSRCrdelay; - if (time < here->VSRCcoeffs[0]) { + if (time <= here->VSRCcoeffs[0]) { value = here->VSRCcoeffs[1]; - value = value; break; } From 878ac0076a98e52c73d7cb04744aee838b7ac55b Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Wed, 9 Oct 2024 16:58:20 +0200 Subject: [PATCH 10/10] Allow plotting a single point in an ascii plot (command .asciiplot) --- src/frontend/plotting/agraf.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/frontend/plotting/agraf.c b/src/frontend/plotting/agraf.c index de750a973..464cb0ac1 100644 --- a/src/frontend/plotting/agraf.c +++ b/src/frontend/plotting/agraf.c @@ -86,12 +86,6 @@ ft_agraf(double *xlims, double *ylims, struct dvec *xscale, struct plot *plot, s yrange[0] = ylims[0]; yrange[1] = ylims[1]; - if (maxx < 2) { - fprintf(cp_err, - "Error: asciiplot can't handle scale with length < 2\n"); - return; - } - if (maxx <= 0) { fprintf(cp_err, "Note: no points to plot\n"); return; @@ -294,12 +288,18 @@ ft_agraf(double *xlims, double *ylims, struct dvec *xscale, struct plot *plot, s for (i = 0; i < maxx; i++) { if (nointerp) x = isreal(xscale) ? xscale->v_realdata[i] : - realpart(xscale->v_compdata[i]); + realpart(xscale->v_compdata[i]); else if (xlog && xrange[0] > 0.0 && xrange[1] > 0.0) - x = xrange[0] * pow(10.0, mylog10(xrange[1]/xrange[0]) - * i / (maxx - 1)); + if (maxx == 1) + x = (xrange[0] + xrange[1]) / 2.; + else + x = xrange[0] * pow(10.0, mylog10(xrange[1] / xrange[0]) + * i / (maxx - 1)); else - x = xrange[0] + (xrange[1] - xrange[0]) * i / (maxx - 1); + if (maxx == 1) + x = (xrange[0] + xrange[1]) / 2.; + else + x = xrange[0] + (xrange[1] - xrange[0]) * i / (maxx - 1); if (x < 0.0) out_printf("%.3e ", x);