1 /**** BSIM3v3.2.4, Released by Xuemei Xi 12/21/2001 ****/
2 
3 /**********
4  * Copyright 2001 Regents of the University of California. All rights reserved.
5  * File: b3set.c of BSIM3v3.2.4
6  * Author: 1995 Min-Chie Jeng and Mansun Chan.
7  * Author: 1997-1999 Weidong Liu.
8  * Author: 2001  Xuemei Xi
9  **********/
10 
11 #include "ngspice/ngspice.h"
12 #include "ngspice/smpdefs.h"
13 #include "ngspice/cktdefs.h"
14 #include "bsim3v32def.h"
15 #include "ngspice/const.h"
16 #include "ngspice/sperror.h"
17 #include "ngspice/devdefs.h"
18 #include "ngspice/suffix.h"
19 
20 #define MAX_EXP 5.834617425e14
21 #define MIN_EXP 1.713908431e-15
22 #define EXP_THRESHOLD 34.0
23 #define SMOOTHFACTOR 0.1
24 #define EPSOX 3.453133e-11
25 #define EPSSI 1.03594e-10
26 #define PI 3.141592654
27 #define Charge_q 1.60219e-19
28 #define Meter2Micron 1.0e6
29 
30 int
BSIM3v32setup(SMPmatrix * matrix,GENmodel * inModel,CKTcircuit * ckt,int * states)31 BSIM3v32setup (SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt,
32             int *states)
33 {
34 BSIM3v32model *model = (BSIM3v32model*)inModel;
35 BSIM3v32instance *here;
36 int error;
37 CKTnode *tmp;
38 
39 CKTnode *tmpNode;
40 IFuid tmpName;
41 
42 #ifdef USE_OMP
43 int idx, InstCount;
44 BSIM3v32instance **InstArray;
45 #endif
46 
47     /*  loop through all the BSIM3v32 device models */
48     for( ; model != NULL; model = BSIM3v32nextModel(model))
49     {
50 /* Default value Processing for BSIM3v32 MOSFET Models */
51         if (!model->BSIM3v32typeGiven)
52             model->BSIM3v32type = NMOS;
53         if (!model->BSIM3v32mobModGiven)
54             model->BSIM3v32mobMod = 1;
55         if (!model->BSIM3v32binUnitGiven)
56             model->BSIM3v32binUnit = 1;
57         if (!model->BSIM3v32paramChkGiven)
58             model->BSIM3v32paramChk = 0;
59         if (!model->BSIM3v32capModGiven)
60             model->BSIM3v32capMod = 3;
61         if (!model->BSIM3v32acmModGiven)
62             model->BSIM3v32acmMod = 0;
63         if (!model->BSIM3v32calcacmGiven)
64             model->BSIM3v32calcacm = 0;
65         if (!model->BSIM3v32noiModGiven)
66             model->BSIM3v32noiMod = 1;
67         if (!model->BSIM3v32nqsModGiven)
68             model->BSIM3v32nqsMod = 0;
69         else if ((model->BSIM3v32nqsMod != 0) && (model->BSIM3v32nqsMod != 1))
70         {   model->BSIM3v32nqsMod = 0;
71             printf("Warning: nqsMod has been set to its default value: 0.\n");
72         }
73 
74         /* If the user does not provide the model revision,
75          * we always choose the most recent.
76          */
77         if (!model->BSIM3v32versionGiven)
78                 model->BSIM3v32version = copy("3.2.4");
79 
80         /* I have added below the code that translate model string
81          * into an integer. This trick is meant to speed up the
82          * revision testing instruction, since comparing integer
83          * is faster than comparing strings.
84          * Paolo Nenzi 2002
85          */
86         if ((!strcmp(model->BSIM3v32version, "3.2.4"))||(!strncmp(model->BSIM3v32version, "3.24", 4)))
87                 model->BSIM3v32intVersion = BSIM3v32V324;
88         else if ((!strcmp(model->BSIM3v32version, "3.2.3"))||(!strncmp(model->BSIM3v32version, "3.23", 4)))
89                 model->BSIM3v32intVersion = BSIM3v32V323;
90         else if ((!strcmp(model->BSIM3v32version, "3.2.2"))||(!strncmp(model->BSIM3v32version, "3.22", 4)))
91                 model->BSIM3v32intVersion = BSIM3v32V322;
92         else if ((!strncmp(model->BSIM3v32version, "3.2", 3))||(!strncmp(model->BSIM3v32version, "3.20", 4)))
93                 model->BSIM3v32intVersion = BSIM3v32V32;
94         else
95                 model->BSIM3v32intVersion = BSIM3v32V3OLD;
96         /* BSIM3v32V3OLD is a placeholder for pre 3.2 revision
97          * This model should not be used for pre 3.2 models.
98          */
99 
100         if (!model->BSIM3v32toxGiven)
101             model->BSIM3v32tox = 150.0e-10;
102         model->BSIM3v32cox = 3.453133e-11 / model->BSIM3v32tox;
103         if (!model->BSIM3v32toxmGiven)
104             model->BSIM3v32toxm = model->BSIM3v32tox;
105 
106         if (!model->BSIM3v32cdscGiven)
107             model->BSIM3v32cdsc = 2.4e-4;   /* unit Q/V/m^2  */
108         if (!model->BSIM3v32cdscbGiven)
109             model->BSIM3v32cdscb = 0.0;   /* unit Q/V/m^2  */
110         if (!model->BSIM3v32cdscdGiven)
111             model->BSIM3v32cdscd = 0.0;   /* unit Q/V/m^2  */
112         if (!model->BSIM3v32citGiven)
113             model->BSIM3v32cit = 0.0;   /* unit Q/V/m^2  */
114         if (!model->BSIM3v32nfactorGiven)
115             model->BSIM3v32nfactor = 1;
116         if (!model->BSIM3v32xjGiven)
117             model->BSIM3v32xj = .15e-6;
118         if (!model->BSIM3v32vsatGiven)
119             model->BSIM3v32vsat = 8.0e4;    /* unit m/s */
120         if (!model->BSIM3v32atGiven)
121             model->BSIM3v32at = 3.3e4;    /* unit m/s */
122         if (!model->BSIM3v32a0Given)
123             model->BSIM3v32a0 = 1.0;
124         if (!model->BSIM3v32agsGiven)
125             model->BSIM3v32ags = 0.0;
126         if (!model->BSIM3v32a1Given)
127             model->BSIM3v32a1 = 0.0;
128         if (!model->BSIM3v32a2Given)
129             model->BSIM3v32a2 = 1.0;
130         if (!model->BSIM3v32ketaGiven)
131             model->BSIM3v32keta = -0.047;    /* unit  / V */
132         if (!model->BSIM3v32nsubGiven)
133             model->BSIM3v32nsub = 6.0e16;   /* unit 1/cm3 */
134         if (!model->BSIM3v32npeakGiven)
135             model->BSIM3v32npeak = 1.7e17;   /* unit 1/cm3 */
136         if (!model->BSIM3v32ngateGiven)
137             model->BSIM3v32ngate = 0;   /* unit 1/cm3 */
138         if (!model->BSIM3v32vbmGiven)
139             model->BSIM3v32vbm = -3.0;
140         if (!model->BSIM3v32xtGiven)
141             model->BSIM3v32xt = 1.55e-7;
142         if (!model->BSIM3v32kt1Given)
143             model->BSIM3v32kt1 = -0.11;      /* unit V */
144         if (!model->BSIM3v32kt1lGiven)
145             model->BSIM3v32kt1l = 0.0;      /* unit V*m */
146         if (!model->BSIM3v32kt2Given)
147             model->BSIM3v32kt2 = 0.022;      /* No unit */
148         if (!model->BSIM3v32k3Given)
149             model->BSIM3v32k3 = 80.0;
150         if (!model->BSIM3v32k3bGiven)
151             model->BSIM3v32k3b = 0.0;
152         if (!model->BSIM3v32w0Given)
153             model->BSIM3v32w0 = 2.5e-6;
154         if (!model->BSIM3v32nlxGiven)
155             model->BSIM3v32nlx = 1.74e-7;
156         if (!model->BSIM3v32dvt0Given)
157             model->BSIM3v32dvt0 = 2.2;
158         if (!model->BSIM3v32dvt1Given)
159             model->BSIM3v32dvt1 = 0.53;
160         if (!model->BSIM3v32dvt2Given)
161             model->BSIM3v32dvt2 = -0.032;   /* unit 1 / V */
162 
163         if (!model->BSIM3v32dvt0wGiven)
164             model->BSIM3v32dvt0w = 0.0;
165         if (!model->BSIM3v32dvt1wGiven)
166             model->BSIM3v32dvt1w = 5.3e6;
167         if (!model->BSIM3v32dvt2wGiven)
168             model->BSIM3v32dvt2w = -0.032;
169 
170         if (!model->BSIM3v32droutGiven)
171             model->BSIM3v32drout = 0.56;
172         if (!model->BSIM3v32dsubGiven)
173             model->BSIM3v32dsub = model->BSIM3v32drout;
174         if (!model->BSIM3v32vth0Given)
175             model->BSIM3v32vth0 = (model->BSIM3v32type == NMOS) ? 0.7 : -0.7;
176         if (!model->BSIM3v32uaGiven)
177             model->BSIM3v32ua = 2.25e-9;      /* unit m/V */
178         if (!model->BSIM3v32ua1Given)
179             model->BSIM3v32ua1 = 4.31e-9;      /* unit m/V */
180         if (!model->BSIM3v32ubGiven)
181             model->BSIM3v32ub = 5.87e-19;     /* unit (m/V)**2 */
182         if (!model->BSIM3v32ub1Given)
183             model->BSIM3v32ub1 = -7.61e-18;     /* unit (m/V)**2 */
184         if (!model->BSIM3v32ucGiven)
185             model->BSIM3v32uc = (model->BSIM3v32mobMod == 3) ? -0.0465 : -0.0465e-9;
186         if (!model->BSIM3v32uc1Given)
187             model->BSIM3v32uc1 = (model->BSIM3v32mobMod == 3) ? -0.056 : -0.056e-9;
188         if (!model->BSIM3v32u0Given)
189             model->BSIM3v32u0 = (model->BSIM3v32type == NMOS) ? 0.067 : 0.025;
190         if (!model->BSIM3v32uteGiven)
191             model->BSIM3v32ute = -1.5;
192         if (!model->BSIM3v32voffGiven)
193             model->BSIM3v32voff = -0.08;
194         if (!model->BSIM3v32deltaGiven)
195            model->BSIM3v32delta = 0.01;
196         if (!model->BSIM3v32rdswGiven)
197             model->BSIM3v32rdsw = 0;
198         if (!model->BSIM3v32prwgGiven)
199             model->BSIM3v32prwg = 0.0;      /* unit 1/V */
200         if (!model->BSIM3v32prwbGiven)
201             model->BSIM3v32prwb = 0.0;
202         if (!model->BSIM3v32prtGiven)
203             model->BSIM3v32prt = 0.0;
204         if (!model->BSIM3v32eta0Given)
205             model->BSIM3v32eta0 = 0.08;      /* no unit  */
206         if (!model->BSIM3v32etabGiven)
207             model->BSIM3v32etab = -0.07;      /* unit  1/V */
208         if (!model->BSIM3v32pclmGiven)
209             model->BSIM3v32pclm = 1.3;      /* no unit  */
210         if (!model->BSIM3v32pdibl1Given)
211             model->BSIM3v32pdibl1 = .39;    /* no unit  */
212         if (!model->BSIM3v32pdibl2Given)
213             model->BSIM3v32pdibl2 = 0.0086;    /* no unit  */
214         if (!model->BSIM3v32pdiblbGiven)
215             model->BSIM3v32pdiblb = 0.0;    /* 1/V  */
216         if (!model->BSIM3v32pscbe1Given)
217             model->BSIM3v32pscbe1 = 4.24e8;
218         if (!model->BSIM3v32pscbe2Given)
219             model->BSIM3v32pscbe2 = 1.0e-5;
220         if (!model->BSIM3v32pvagGiven)
221             model->BSIM3v32pvag = 0.0;
222         if (!model->BSIM3v32wrGiven)
223             model->BSIM3v32wr = 1.0;
224         if (!model->BSIM3v32dwgGiven)
225             model->BSIM3v32dwg = 0.0;
226         if (!model->BSIM3v32dwbGiven)
227             model->BSIM3v32dwb = 0.0;
228         if (!model->BSIM3v32b0Given)
229             model->BSIM3v32b0 = 0.0;
230         if (!model->BSIM3v32b1Given)
231             model->BSIM3v32b1 = 0.0;
232         if (!model->BSIM3v32alpha0Given)
233             model->BSIM3v32alpha0 = 0.0;
234         if (!model->BSIM3v32alpha1Given)
235             model->BSIM3v32alpha1 = 0.0;
236         if (!model->BSIM3v32beta0Given)
237             model->BSIM3v32beta0 = 30.0;
238         if (!model->BSIM3v32ijthGiven)
239             model->BSIM3v32ijth = 0.1; /* unit A */
240 
241         if (!model->BSIM3v32elmGiven)
242             model->BSIM3v32elm = 5.0;
243         if (!model->BSIM3v32cgslGiven)
244             model->BSIM3v32cgsl = 0.0;
245         if (!model->BSIM3v32cgdlGiven)
246             model->BSIM3v32cgdl = 0.0;
247         if (!model->BSIM3v32ckappaGiven)
248             model->BSIM3v32ckappa = 0.6;
249         if (!model->BSIM3v32clcGiven)
250             model->BSIM3v32clc = 0.1e-6;
251         if (!model->BSIM3v32cleGiven)
252             model->BSIM3v32cle = 0.6;
253         if (!model->BSIM3v32vfbcvGiven)
254             model->BSIM3v32vfbcv = -1.0;
255         if (!model->BSIM3v32acdeGiven)
256             model->BSIM3v32acde = 1.0;
257         if (!model->BSIM3v32moinGiven)
258             model->BSIM3v32moin = 15.0;
259         if (!model->BSIM3v32noffGiven)
260             model->BSIM3v32noff = 1.0;
261         if (!model->BSIM3v32voffcvGiven)
262             model->BSIM3v32voffcv = 0.0;
263         if (!model->BSIM3v32tcjGiven)
264             model->BSIM3v32tcj = 0.0;
265         if (!model->BSIM3v32tpbGiven)
266             model->BSIM3v32tpb = 0.0;
267         if (!model->BSIM3v32tcjswGiven)
268             model->BSIM3v32tcjsw = 0.0;
269         if (!model->BSIM3v32tpbswGiven)
270             model->BSIM3v32tpbsw = 0.0;
271         if (!model->BSIM3v32tcjswgGiven)
272             model->BSIM3v32tcjswg = 0.0;
273         if (!model->BSIM3v32tpbswgGiven)
274             model->BSIM3v32tpbswg = 0.0;
275 
276         /* ACM model */
277         if (!model->BSIM3v32hdifGiven)
278           model->BSIM3v32hdif = 0.0;
279         if (!model->BSIM3v32ldifGiven)
280           model->BSIM3v32ldif = 0.0;
281         if (!model->BSIM3v32ldGiven)
282           model->BSIM3v32ld = 0.0;
283         if (!model->BSIM3v32rdGiven)
284           model->BSIM3v32rd = 0.0;
285         if (!model->BSIM3v32rsGiven)
286           model->BSIM3v32rs = 0.0;
287         if (!model->BSIM3v32rdcGiven)
288           model->BSIM3v32rdc = 0.0;
289         if (!model->BSIM3v32rscGiven)
290           model->BSIM3v32rsc = 0.0;
291         if (!model->BSIM3v32wmltGiven)
292           model->BSIM3v32wmlt = 1.0;
293 
294         if (!model->BSIM3v32lmltGiven)
295           model->BSIM3v32lmlt = 1.0;
296 
297         /* Length dependence */
298         if (!model->BSIM3v32lcdscGiven)
299             model->BSIM3v32lcdsc = 0.0;
300         if (!model->BSIM3v32lcdscbGiven)
301             model->BSIM3v32lcdscb = 0.0;
302         if (!model->BSIM3v32lcdscdGiven)
303             model->BSIM3v32lcdscd = 0.0;
304         if (!model->BSIM3v32lcitGiven)
305             model->BSIM3v32lcit = 0.0;
306         if (!model->BSIM3v32lnfactorGiven)
307             model->BSIM3v32lnfactor = 0.0;
308         if (!model->BSIM3v32lxjGiven)
309             model->BSIM3v32lxj = 0.0;
310         if (!model->BSIM3v32lvsatGiven)
311             model->BSIM3v32lvsat = 0.0;
312         if (!model->BSIM3v32latGiven)
313             model->BSIM3v32lat = 0.0;
314         if (!model->BSIM3v32la0Given)
315             model->BSIM3v32la0 = 0.0;
316         if (!model->BSIM3v32lagsGiven)
317             model->BSIM3v32lags = 0.0;
318         if (!model->BSIM3v32la1Given)
319             model->BSIM3v32la1 = 0.0;
320         if (!model->BSIM3v32la2Given)
321             model->BSIM3v32la2 = 0.0;
322         if (!model->BSIM3v32lketaGiven)
323             model->BSIM3v32lketa = 0.0;
324         if (!model->BSIM3v32lnsubGiven)
325             model->BSIM3v32lnsub = 0.0;
326         if (!model->BSIM3v32lnpeakGiven)
327             model->BSIM3v32lnpeak = 0.0;
328         if (!model->BSIM3v32lngateGiven)
329             model->BSIM3v32lngate = 0.0;
330         if (!model->BSIM3v32lvbmGiven)
331             model->BSIM3v32lvbm = 0.0;
332         if (!model->BSIM3v32lxtGiven)
333             model->BSIM3v32lxt = 0.0;
334         if (!model->BSIM3v32lkt1Given)
335             model->BSIM3v32lkt1 = 0.0;
336         if (!model->BSIM3v32lkt1lGiven)
337             model->BSIM3v32lkt1l = 0.0;
338         if (!model->BSIM3v32lkt2Given)
339             model->BSIM3v32lkt2 = 0.0;
340         if (!model->BSIM3v32lk3Given)
341             model->BSIM3v32lk3 = 0.0;
342         if (!model->BSIM3v32lk3bGiven)
343             model->BSIM3v32lk3b = 0.0;
344         if (!model->BSIM3v32lw0Given)
345             model->BSIM3v32lw0 = 0.0;
346         if (!model->BSIM3v32lnlxGiven)
347             model->BSIM3v32lnlx = 0.0;
348         if (!model->BSIM3v32ldvt0Given)
349             model->BSIM3v32ldvt0 = 0.0;
350         if (!model->BSIM3v32ldvt1Given)
351             model->BSIM3v32ldvt1 = 0.0;
352         if (!model->BSIM3v32ldvt2Given)
353             model->BSIM3v32ldvt2 = 0.0;
354         if (!model->BSIM3v32ldvt0wGiven)
355             model->BSIM3v32ldvt0w = 0.0;
356         if (!model->BSIM3v32ldvt1wGiven)
357             model->BSIM3v32ldvt1w = 0.0;
358         if (!model->BSIM3v32ldvt2wGiven)
359             model->BSIM3v32ldvt2w = 0.0;
360         if (!model->BSIM3v32ldroutGiven)
361             model->BSIM3v32ldrout = 0.0;
362         if (!model->BSIM3v32ldsubGiven)
363             model->BSIM3v32ldsub = 0.0;
364         if (!model->BSIM3v32lvth0Given)
365            model->BSIM3v32lvth0 = 0.0;
366         if (!model->BSIM3v32luaGiven)
367             model->BSIM3v32lua = 0.0;
368         if (!model->BSIM3v32lua1Given)
369             model->BSIM3v32lua1 = 0.0;
370         if (!model->BSIM3v32lubGiven)
371             model->BSIM3v32lub = 0.0;
372         if (!model->BSIM3v32lub1Given)
373             model->BSIM3v32lub1 = 0.0;
374         if (!model->BSIM3v32lucGiven)
375             model->BSIM3v32luc = 0.0;
376         if (!model->BSIM3v32luc1Given)
377             model->BSIM3v32luc1 = 0.0;
378         if (!model->BSIM3v32lu0Given)
379             model->BSIM3v32lu0 = 0.0;
380         if (!model->BSIM3v32luteGiven)
381             model->BSIM3v32lute = 0.0;
382         if (!model->BSIM3v32lvoffGiven)
383             model->BSIM3v32lvoff = 0.0;
384         if (!model->BSIM3v32ldeltaGiven)
385             model->BSIM3v32ldelta = 0.0;
386         if (!model->BSIM3v32lrdswGiven)
387             model->BSIM3v32lrdsw = 0.0;
388         if (!model->BSIM3v32lprwbGiven)
389             model->BSIM3v32lprwb = 0.0;
390         if (!model->BSIM3v32lprwgGiven)
391             model->BSIM3v32lprwg = 0.0;
392         if (!model->BSIM3v32lprtGiven)
393             model->BSIM3v32lprt = 0.0;
394         if (!model->BSIM3v32leta0Given)
395             model->BSIM3v32leta0 = 0.0;
396         if (!model->BSIM3v32letabGiven)
397             model->BSIM3v32letab = -0.0;
398         if (!model->BSIM3v32lpclmGiven)
399             model->BSIM3v32lpclm = 0.0;
400         if (!model->BSIM3v32lpdibl1Given)
401             model->BSIM3v32lpdibl1 = 0.0;
402         if (!model->BSIM3v32lpdibl2Given)
403             model->BSIM3v32lpdibl2 = 0.0;
404         if (!model->BSIM3v32lpdiblbGiven)
405             model->BSIM3v32lpdiblb = 0.0;
406         if (!model->BSIM3v32lpscbe1Given)
407             model->BSIM3v32lpscbe1 = 0.0;
408         if (!model->BSIM3v32lpscbe2Given)
409             model->BSIM3v32lpscbe2 = 0.0;
410         if (!model->BSIM3v32lpvagGiven)
411             model->BSIM3v32lpvag = 0.0;
412         if (!model->BSIM3v32lwrGiven)
413             model->BSIM3v32lwr = 0.0;
414         if (!model->BSIM3v32ldwgGiven)
415             model->BSIM3v32ldwg = 0.0;
416         if (!model->BSIM3v32ldwbGiven)
417             model->BSIM3v32ldwb = 0.0;
418         if (!model->BSIM3v32lb0Given)
419             model->BSIM3v32lb0 = 0.0;
420         if (!model->BSIM3v32lb1Given)
421             model->BSIM3v32lb1 = 0.0;
422         if (!model->BSIM3v32lalpha0Given)
423             model->BSIM3v32lalpha0 = 0.0;
424         if (!model->BSIM3v32lalpha1Given)
425             model->BSIM3v32lalpha1 = 0.0;
426         if (!model->BSIM3v32lbeta0Given)
427             model->BSIM3v32lbeta0 = 0.0;
428         if (!model->BSIM3v32lvfbGiven)
429             model->BSIM3v32lvfb = 0.0;
430 
431         if (!model->BSIM3v32lelmGiven)
432             model->BSIM3v32lelm = 0.0;
433         if (!model->BSIM3v32lcgslGiven)
434             model->BSIM3v32lcgsl = 0.0;
435         if (!model->BSIM3v32lcgdlGiven)
436             model->BSIM3v32lcgdl = 0.0;
437         if (!model->BSIM3v32lckappaGiven)
438             model->BSIM3v32lckappa = 0.0;
439         if (!model->BSIM3v32lclcGiven)
440             model->BSIM3v32lclc = 0.0;
441         if (!model->BSIM3v32lcleGiven)
442             model->BSIM3v32lcle = 0.0;
443         if (!model->BSIM3v32lcfGiven)
444             model->BSIM3v32lcf = 0.0;
445         if (!model->BSIM3v32lvfbcvGiven)
446             model->BSIM3v32lvfbcv = 0.0;
447         if (!model->BSIM3v32lacdeGiven)
448             model->BSIM3v32lacde = 0.0;
449         if (!model->BSIM3v32lmoinGiven)
450             model->BSIM3v32lmoin = 0.0;
451         if (!model->BSIM3v32lnoffGiven)
452             model->BSIM3v32lnoff = 0.0;
453         if (!model->BSIM3v32lvoffcvGiven)
454             model->BSIM3v32lvoffcv = 0.0;
455 
456         /* Width dependence */
457         if (!model->BSIM3v32wcdscGiven)
458             model->BSIM3v32wcdsc = 0.0;
459         if (!model->BSIM3v32wcdscbGiven)
460             model->BSIM3v32wcdscb = 0.0;
461         if (!model->BSIM3v32wcdscdGiven)
462             model->BSIM3v32wcdscd = 0.0;
463         if (!model->BSIM3v32wcitGiven)
464             model->BSIM3v32wcit = 0.0;
465         if (!model->BSIM3v32wnfactorGiven)
466             model->BSIM3v32wnfactor = 0.0;
467         if (!model->BSIM3v32wxjGiven)
468             model->BSIM3v32wxj = 0.0;
469         if (!model->BSIM3v32wvsatGiven)
470             model->BSIM3v32wvsat = 0.0;
471         if (!model->BSIM3v32watGiven)
472             model->BSIM3v32wat = 0.0;
473         if (!model->BSIM3v32wa0Given)
474             model->BSIM3v32wa0 = 0.0;
475         if (!model->BSIM3v32wagsGiven)
476             model->BSIM3v32wags = 0.0;
477         if (!model->BSIM3v32wa1Given)
478             model->BSIM3v32wa1 = 0.0;
479         if (!model->BSIM3v32wa2Given)
480             model->BSIM3v32wa2 = 0.0;
481         if (!model->BSIM3v32wketaGiven)
482             model->BSIM3v32wketa = 0.0;
483         if (!model->BSIM3v32wnsubGiven)
484             model->BSIM3v32wnsub = 0.0;
485         if (!model->BSIM3v32wnpeakGiven)
486             model->BSIM3v32wnpeak = 0.0;
487         if (!model->BSIM3v32wngateGiven)
488             model->BSIM3v32wngate = 0.0;
489         if (!model->BSIM3v32wvbmGiven)
490             model->BSIM3v32wvbm = 0.0;
491         if (!model->BSIM3v32wxtGiven)
492             model->BSIM3v32wxt = 0.0;
493         if (!model->BSIM3v32wkt1Given)
494             model->BSIM3v32wkt1 = 0.0;
495         if (!model->BSIM3v32wkt1lGiven)
496             model->BSIM3v32wkt1l = 0.0;
497         if (!model->BSIM3v32wkt2Given)
498             model->BSIM3v32wkt2 = 0.0;
499         if (!model->BSIM3v32wk3Given)
500             model->BSIM3v32wk3 = 0.0;
501         if (!model->BSIM3v32wk3bGiven)
502             model->BSIM3v32wk3b = 0.0;
503         if (!model->BSIM3v32ww0Given)
504             model->BSIM3v32ww0 = 0.0;
505         if (!model->BSIM3v32wnlxGiven)
506             model->BSIM3v32wnlx = 0.0;
507         if (!model->BSIM3v32wdvt0Given)
508             model->BSIM3v32wdvt0 = 0.0;
509         if (!model->BSIM3v32wdvt1Given)
510             model->BSIM3v32wdvt1 = 0.0;
511         if (!model->BSIM3v32wdvt2Given)
512             model->BSIM3v32wdvt2 = 0.0;
513         if (!model->BSIM3v32wdvt0wGiven)
514             model->BSIM3v32wdvt0w = 0.0;
515         if (!model->BSIM3v32wdvt1wGiven)
516             model->BSIM3v32wdvt1w = 0.0;
517         if (!model->BSIM3v32wdvt2wGiven)
518             model->BSIM3v32wdvt2w = 0.0;
519         if (!model->BSIM3v32wdroutGiven)
520             model->BSIM3v32wdrout = 0.0;
521         if (!model->BSIM3v32wdsubGiven)
522             model->BSIM3v32wdsub = 0.0;
523         if (!model->BSIM3v32wvth0Given)
524            model->BSIM3v32wvth0 = 0.0;
525         if (!model->BSIM3v32wuaGiven)
526             model->BSIM3v32wua = 0.0;
527         if (!model->BSIM3v32wua1Given)
528             model->BSIM3v32wua1 = 0.0;
529         if (!model->BSIM3v32wubGiven)
530             model->BSIM3v32wub = 0.0;
531         if (!model->BSIM3v32wub1Given)
532             model->BSIM3v32wub1 = 0.0;
533         if (!model->BSIM3v32wucGiven)
534             model->BSIM3v32wuc = 0.0;
535         if (!model->BSIM3v32wuc1Given)
536             model->BSIM3v32wuc1 = 0.0;
537         if (!model->BSIM3v32wu0Given)
538             model->BSIM3v32wu0 = 0.0;
539         if (!model->BSIM3v32wuteGiven)
540             model->BSIM3v32wute = 0.0;
541         if (!model->BSIM3v32wvoffGiven)
542             model->BSIM3v32wvoff = 0.0;
543         if (!model->BSIM3v32wdeltaGiven)
544             model->BSIM3v32wdelta = 0.0;
545         if (!model->BSIM3v32wrdswGiven)
546             model->BSIM3v32wrdsw = 0.0;
547         if (!model->BSIM3v32wprwbGiven)
548             model->BSIM3v32wprwb = 0.0;
549         if (!model->BSIM3v32wprwgGiven)
550             model->BSIM3v32wprwg = 0.0;
551         if (!model->BSIM3v32wprtGiven)
552             model->BSIM3v32wprt = 0.0;
553         if (!model->BSIM3v32weta0Given)
554             model->BSIM3v32weta0 = 0.0;
555         if (!model->BSIM3v32wetabGiven)
556             model->BSIM3v32wetab = 0.0;
557         if (!model->BSIM3v32wpclmGiven)
558             model->BSIM3v32wpclm = 0.0;
559         if (!model->BSIM3v32wpdibl1Given)
560             model->BSIM3v32wpdibl1 = 0.0;
561         if (!model->BSIM3v32wpdibl2Given)
562             model->BSIM3v32wpdibl2 = 0.0;
563         if (!model->BSIM3v32wpdiblbGiven)
564             model->BSIM3v32wpdiblb = 0.0;
565         if (!model->BSIM3v32wpscbe1Given)
566             model->BSIM3v32wpscbe1 = 0.0;
567         if (!model->BSIM3v32wpscbe2Given)
568             model->BSIM3v32wpscbe2 = 0.0;
569         if (!model->BSIM3v32wpvagGiven)
570             model->BSIM3v32wpvag = 0.0;
571         if (!model->BSIM3v32wwrGiven)
572             model->BSIM3v32wwr = 0.0;
573         if (!model->BSIM3v32wdwgGiven)
574             model->BSIM3v32wdwg = 0.0;
575         if (!model->BSIM3v32wdwbGiven)
576             model->BSIM3v32wdwb = 0.0;
577         if (!model->BSIM3v32wb0Given)
578             model->BSIM3v32wb0 = 0.0;
579         if (!model->BSIM3v32wb1Given)
580             model->BSIM3v32wb1 = 0.0;
581         if (!model->BSIM3v32walpha0Given)
582             model->BSIM3v32walpha0 = 0.0;
583         if (!model->BSIM3v32walpha1Given)
584             model->BSIM3v32walpha1 = 0.0;
585         if (!model->BSIM3v32wbeta0Given)
586             model->BSIM3v32wbeta0 = 0.0;
587         if (!model->BSIM3v32wvfbGiven)
588             model->BSIM3v32wvfb = 0.0;
589 
590         if (!model->BSIM3v32welmGiven)
591             model->BSIM3v32welm = 0.0;
592         if (!model->BSIM3v32wcgslGiven)
593             model->BSIM3v32wcgsl = 0.0;
594         if (!model->BSIM3v32wcgdlGiven)
595             model->BSIM3v32wcgdl = 0.0;
596         if (!model->BSIM3v32wckappaGiven)
597             model->BSIM3v32wckappa = 0.0;
598         if (!model->BSIM3v32wcfGiven)
599             model->BSIM3v32wcf = 0.0;
600         if (!model->BSIM3v32wclcGiven)
601             model->BSIM3v32wclc = 0.0;
602         if (!model->BSIM3v32wcleGiven)
603             model->BSIM3v32wcle = 0.0;
604         if (!model->BSIM3v32wvfbcvGiven)
605             model->BSIM3v32wvfbcv = 0.0;
606         if (!model->BSIM3v32wacdeGiven)
607             model->BSIM3v32wacde = 0.0;
608         if (!model->BSIM3v32wmoinGiven)
609             model->BSIM3v32wmoin = 0.0;
610         if (!model->BSIM3v32wnoffGiven)
611             model->BSIM3v32wnoff = 0.0;
612         if (!model->BSIM3v32wvoffcvGiven)
613             model->BSIM3v32wvoffcv = 0.0;
614 
615         /* Cross-term dependence */
616         if (!model->BSIM3v32pcdscGiven)
617             model->BSIM3v32pcdsc = 0.0;
618         if (!model->BSIM3v32pcdscbGiven)
619             model->BSIM3v32pcdscb = 0.0;
620         if (!model->BSIM3v32pcdscdGiven)
621             model->BSIM3v32pcdscd = 0.0;
622         if (!model->BSIM3v32pcitGiven)
623             model->BSIM3v32pcit = 0.0;
624         if (!model->BSIM3v32pnfactorGiven)
625             model->BSIM3v32pnfactor = 0.0;
626         if (!model->BSIM3v32pxjGiven)
627             model->BSIM3v32pxj = 0.0;
628         if (!model->BSIM3v32pvsatGiven)
629             model->BSIM3v32pvsat = 0.0;
630         if (!model->BSIM3v32patGiven)
631             model->BSIM3v32pat = 0.0;
632         if (!model->BSIM3v32pa0Given)
633             model->BSIM3v32pa0 = 0.0;
634 
635         if (!model->BSIM3v32pagsGiven)
636             model->BSIM3v32pags = 0.0;
637         if (!model->BSIM3v32pa1Given)
638             model->BSIM3v32pa1 = 0.0;
639         if (!model->BSIM3v32pa2Given)
640             model->BSIM3v32pa2 = 0.0;
641         if (!model->BSIM3v32pketaGiven)
642             model->BSIM3v32pketa = 0.0;
643         if (!model->BSIM3v32pnsubGiven)
644             model->BSIM3v32pnsub = 0.0;
645         if (!model->BSIM3v32pnpeakGiven)
646             model->BSIM3v32pnpeak = 0.0;
647         if (!model->BSIM3v32pngateGiven)
648             model->BSIM3v32pngate = 0.0;
649         if (!model->BSIM3v32pvbmGiven)
650             model->BSIM3v32pvbm = 0.0;
651         if (!model->BSIM3v32pxtGiven)
652             model->BSIM3v32pxt = 0.0;
653         if (!model->BSIM3v32pkt1Given)
654             model->BSIM3v32pkt1 = 0.0;
655         if (!model->BSIM3v32pkt1lGiven)
656             model->BSIM3v32pkt1l = 0.0;
657         if (!model->BSIM3v32pkt2Given)
658             model->BSIM3v32pkt2 = 0.0;
659         if (!model->BSIM3v32pk3Given)
660             model->BSIM3v32pk3 = 0.0;
661         if (!model->BSIM3v32pk3bGiven)
662             model->BSIM3v32pk3b = 0.0;
663         if (!model->BSIM3v32pw0Given)
664             model->BSIM3v32pw0 = 0.0;
665         if (!model->BSIM3v32pnlxGiven)
666             model->BSIM3v32pnlx = 0.0;
667         if (!model->BSIM3v32pdvt0Given)
668             model->BSIM3v32pdvt0 = 0.0;
669         if (!model->BSIM3v32pdvt1Given)
670             model->BSIM3v32pdvt1 = 0.0;
671         if (!model->BSIM3v32pdvt2Given)
672             model->BSIM3v32pdvt2 = 0.0;
673         if (!model->BSIM3v32pdvt0wGiven)
674             model->BSIM3v32pdvt0w = 0.0;
675         if (!model->BSIM3v32pdvt1wGiven)
676             model->BSIM3v32pdvt1w = 0.0;
677         if (!model->BSIM3v32pdvt2wGiven)
678             model->BSIM3v32pdvt2w = 0.0;
679         if (!model->BSIM3v32pdroutGiven)
680             model->BSIM3v32pdrout = 0.0;
681         if (!model->BSIM3v32pdsubGiven)
682             model->BSIM3v32pdsub = 0.0;
683         if (!model->BSIM3v32pvth0Given)
684            model->BSIM3v32pvth0 = 0.0;
685         if (!model->BSIM3v32puaGiven)
686             model->BSIM3v32pua = 0.0;
687         if (!model->BSIM3v32pua1Given)
688             model->BSIM3v32pua1 = 0.0;
689         if (!model->BSIM3v32pubGiven)
690             model->BSIM3v32pub = 0.0;
691         if (!model->BSIM3v32pub1Given)
692             model->BSIM3v32pub1 = 0.0;
693         if (!model->BSIM3v32pucGiven)
694             model->BSIM3v32puc = 0.0;
695         if (!model->BSIM3v32puc1Given)
696             model->BSIM3v32puc1 = 0.0;
697         if (!model->BSIM3v32pu0Given)
698             model->BSIM3v32pu0 = 0.0;
699         if (!model->BSIM3v32puteGiven)
700             model->BSIM3v32pute = 0.0;
701         if (!model->BSIM3v32pvoffGiven)
702             model->BSIM3v32pvoff = 0.0;
703         if (!model->BSIM3v32pdeltaGiven)
704             model->BSIM3v32pdelta = 0.0;
705         if (!model->BSIM3v32prdswGiven)
706             model->BSIM3v32prdsw = 0.0;
707         if (!model->BSIM3v32pprwbGiven)
708             model->BSIM3v32pprwb = 0.0;
709         if (!model->BSIM3v32pprwgGiven)
710             model->BSIM3v32pprwg = 0.0;
711         if (!model->BSIM3v32pprtGiven)
712             model->BSIM3v32pprt = 0.0;
713         if (!model->BSIM3v32peta0Given)
714             model->BSIM3v32peta0 = 0.0;
715         if (!model->BSIM3v32petabGiven)
716             model->BSIM3v32petab = 0.0;
717         if (!model->BSIM3v32ppclmGiven)
718             model->BSIM3v32ppclm = 0.0;
719         if (!model->BSIM3v32ppdibl1Given)
720             model->BSIM3v32ppdibl1 = 0.0;
721         if (!model->BSIM3v32ppdibl2Given)
722             model->BSIM3v32ppdibl2 = 0.0;
723         if (!model->BSIM3v32ppdiblbGiven)
724             model->BSIM3v32ppdiblb = 0.0;
725         if (!model->BSIM3v32ppscbe1Given)
726             model->BSIM3v32ppscbe1 = 0.0;
727         if (!model->BSIM3v32ppscbe2Given)
728             model->BSIM3v32ppscbe2 = 0.0;
729         if (!model->BSIM3v32ppvagGiven)
730             model->BSIM3v32ppvag = 0.0;
731         if (!model->BSIM3v32pwrGiven)
732             model->BSIM3v32pwr = 0.0;
733         if (!model->BSIM3v32pdwgGiven)
734             model->BSIM3v32pdwg = 0.0;
735         if (!model->BSIM3v32pdwbGiven)
736             model->BSIM3v32pdwb = 0.0;
737         if (!model->BSIM3v32pb0Given)
738             model->BSIM3v32pb0 = 0.0;
739         if (!model->BSIM3v32pb1Given)
740             model->BSIM3v32pb1 = 0.0;
741         if (!model->BSIM3v32palpha0Given)
742             model->BSIM3v32palpha0 = 0.0;
743         if (!model->BSIM3v32palpha1Given)
744             model->BSIM3v32palpha1 = 0.0;
745         if (!model->BSIM3v32pbeta0Given)
746             model->BSIM3v32pbeta0 = 0.0;
747         if (!model->BSIM3v32pvfbGiven)
748             model->BSIM3v32pvfb = 0.0;
749 
750         if (!model->BSIM3v32pelmGiven)
751             model->BSIM3v32pelm = 0.0;
752         if (!model->BSIM3v32pcgslGiven)
753             model->BSIM3v32pcgsl = 0.0;
754         if (!model->BSIM3v32pcgdlGiven)
755             model->BSIM3v32pcgdl = 0.0;
756         if (!model->BSIM3v32pckappaGiven)
757             model->BSIM3v32pckappa = 0.0;
758         if (!model->BSIM3v32pcfGiven)
759             model->BSIM3v32pcf = 0.0;
760         if (!model->BSIM3v32pclcGiven)
761             model->BSIM3v32pclc = 0.0;
762         if (!model->BSIM3v32pcleGiven)
763             model->BSIM3v32pcle = 0.0;
764         if (!model->BSIM3v32pvfbcvGiven)
765             model->BSIM3v32pvfbcv = 0.0;
766         if (!model->BSIM3v32pacdeGiven)
767             model->BSIM3v32pacde = 0.0;
768         if (!model->BSIM3v32pmoinGiven)
769             model->BSIM3v32pmoin = 0.0;
770         if (!model->BSIM3v32pnoffGiven)
771             model->BSIM3v32pnoff = 0.0;
772         if (!model->BSIM3v32pvoffcvGiven)
773             model->BSIM3v32pvoffcv = 0.0;
774 
775         /* unit degree celcius */
776         if (!model->BSIM3v32tnomGiven)
777             model->BSIM3v32tnom = ckt->CKTnomTemp;
778 /*        else
779             model->BSIM3v32tnom = model->BSIM3v32tnom + 273.15; we make this transform in b3v32mpar.c in the first run */
780         if (!model->BSIM3v32LintGiven)
781            model->BSIM3v32Lint = 0.0;
782         if (!model->BSIM3v32LlGiven)
783            model->BSIM3v32Ll = 0.0;
784         if (!model->BSIM3v32LlcGiven)
785            model->BSIM3v32Llc = model->BSIM3v32Ll;
786         if (!model->BSIM3v32LlnGiven)
787            model->BSIM3v32Lln = 1.0;
788         if (!model->BSIM3v32LwGiven)
789            model->BSIM3v32Lw = 0.0;
790         if (!model->BSIM3v32LwcGiven)
791            model->BSIM3v32Lwc = model->BSIM3v32Lw;
792         if (!model->BSIM3v32LwnGiven)
793            model->BSIM3v32Lwn = 1.0;
794         if (!model->BSIM3v32LwlGiven)
795            model->BSIM3v32Lwl = 0.0;
796         if (!model->BSIM3v32LwlcGiven)
797            model->BSIM3v32Lwlc = model->BSIM3v32Lwl;
798         if (!model->BSIM3v32LminGiven)
799            model->BSIM3v32Lmin = 0.0;
800         if (!model->BSIM3v32LmaxGiven)
801            model->BSIM3v32Lmax = 1.0;
802         if (!model->BSIM3v32WintGiven)
803            model->BSIM3v32Wint = 0.0;
804         if (!model->BSIM3v32WlGiven)
805            model->BSIM3v32Wl = 0.0;
806         if (!model->BSIM3v32WlcGiven)
807            model->BSIM3v32Wlc = model->BSIM3v32Wl;
808         if (!model->BSIM3v32WlnGiven)
809            model->BSIM3v32Wln = 1.0;
810         if (!model->BSIM3v32WwGiven)
811            model->BSIM3v32Ww = 0.0;
812         if (!model->BSIM3v32WwcGiven)
813            model->BSIM3v32Wwc = model->BSIM3v32Ww;
814         if (!model->BSIM3v32WwnGiven)
815            model->BSIM3v32Wwn = 1.0;
816         if (!model->BSIM3v32WwlGiven)
817            model->BSIM3v32Wwl = 0.0;
818         if (!model->BSIM3v32WwlcGiven)
819            model->BSIM3v32Wwlc = model->BSIM3v32Wwl;
820         if (!model->BSIM3v32WminGiven)
821            model->BSIM3v32Wmin = 0.0;
822         if (!model->BSIM3v32WmaxGiven)
823            model->BSIM3v32Wmax = 1.0;
824         if (!model->BSIM3v32dwcGiven)
825            model->BSIM3v32dwc = model->BSIM3v32Wint;
826         if (!model->BSIM3v32dlcGiven)
827            model->BSIM3v32dlc = model->BSIM3v32Lint;
828 
829         if (!model->BSIM3v32xlGiven)
830            model->BSIM3v32xl = 0.0;
831         if (!model->BSIM3v32xwGiven)
832            model->BSIM3v32xw = 0.0;
833 
834         if (!model->BSIM3v32cfGiven)
835             model->BSIM3v32cf = 2.0 * EPSOX / PI
836                            * log(1.0 + 0.4e-6 / model->BSIM3v32tox);
837         if (!model->BSIM3v32cgdoGiven)
838         {   if (model->BSIM3v32dlcGiven && (model->BSIM3v32dlc > 0.0))
839             {   model->BSIM3v32cgdo = model->BSIM3v32dlc * model->BSIM3v32cox
840                                  - model->BSIM3v32cgdl ;
841             }
842             else
843                 model->BSIM3v32cgdo = 0.6 * model->BSIM3v32xj * model->BSIM3v32cox;
844         }
845         if (!model->BSIM3v32cgsoGiven)
846         {   if (model->BSIM3v32dlcGiven && (model->BSIM3v32dlc > 0.0))
847             {   model->BSIM3v32cgso = model->BSIM3v32dlc * model->BSIM3v32cox
848                                  - model->BSIM3v32cgsl ;
849             }
850             else
851                 model->BSIM3v32cgso = 0.6 * model->BSIM3v32xj * model->BSIM3v32cox;
852         }
853 
854         if (!model->BSIM3v32cgboGiven)
855         {   model->BSIM3v32cgbo = 2.0 * model->BSIM3v32dwc * model->BSIM3v32cox;
856         }
857         if (!model->BSIM3v32xpartGiven)
858             model->BSIM3v32xpart = 0.0;
859         if (!model->BSIM3v32sheetResistanceGiven)
860             model->BSIM3v32sheetResistance = 0.0;
861         if (!model->BSIM3v32unitAreaJctCapGiven)
862             model->BSIM3v32unitAreaJctCap = 5.0E-4;
863         if (!model->BSIM3v32unitLengthSidewallJctCapGiven)
864             model->BSIM3v32unitLengthSidewallJctCap = 5.0E-10;
865         if (!model->BSIM3v32unitLengthGateSidewallJctCapGiven)
866             model->BSIM3v32unitLengthGateSidewallJctCap = model->BSIM3v32unitLengthSidewallJctCap ;
867         if (!model->BSIM3v32jctSatCurDensityGiven)
868             model->BSIM3v32jctSatCurDensity = 1.0E-4;
869         if (!model->BSIM3v32jctSidewallSatCurDensityGiven)
870             model->BSIM3v32jctSidewallSatCurDensity = 0.0;
871         if (!model->BSIM3v32bulkJctPotentialGiven)
872             model->BSIM3v32bulkJctPotential = 1.0;
873         if (!model->BSIM3v32sidewallJctPotentialGiven)
874             model->BSIM3v32sidewallJctPotential = 1.0;
875         if (!model->BSIM3v32GatesidewallJctPotentialGiven)
876             model->BSIM3v32GatesidewallJctPotential = model->BSIM3v32sidewallJctPotential;
877         if (!model->BSIM3v32bulkJctBotGradingCoeffGiven)
878             model->BSIM3v32bulkJctBotGradingCoeff = 0.5;
879         if (!model->BSIM3v32bulkJctSideGradingCoeffGiven)
880             model->BSIM3v32bulkJctSideGradingCoeff = 0.33;
881         if (!model->BSIM3v32bulkJctGateSideGradingCoeffGiven)
882             model->BSIM3v32bulkJctGateSideGradingCoeff = model->BSIM3v32bulkJctSideGradingCoeff;
883         if (!model->BSIM3v32jctEmissionCoeffGiven)
884             model->BSIM3v32jctEmissionCoeff = 1.0;
885         if (!model->BSIM3v32jctTempExponentGiven)
886             model->BSIM3v32jctTempExponent = 3.0;
887         if (!model->BSIM3v32oxideTrapDensityAGiven)
888         {   if (model->BSIM3v32type == NMOS)
889                 model->BSIM3v32oxideTrapDensityA = 1e20;
890             else
891                 model->BSIM3v32oxideTrapDensityA=9.9e18;
892         }
893         if (!model->BSIM3v32oxideTrapDensityBGiven)
894         {   if (model->BSIM3v32type == NMOS)
895                 model->BSIM3v32oxideTrapDensityB = 5e4;
896             else
897                 model->BSIM3v32oxideTrapDensityB = 2.4e3;
898         }
899         if (!model->BSIM3v32oxideTrapDensityCGiven)
900         {   if (model->BSIM3v32type == NMOS)
901                 model->BSIM3v32oxideTrapDensityC = -1.4e-12;
902             else
903                 model->BSIM3v32oxideTrapDensityC = 1.4e-12;
904 
905         }
906         if (!model->BSIM3v32emGiven)
907             model->BSIM3v32em = 4.1e7; /* V/m */
908         if (!model->BSIM3v32efGiven)
909             model->BSIM3v32ef = 1.0;
910         if (!model->BSIM3v32afGiven)
911             model->BSIM3v32af = 1.0;
912         if (!model->BSIM3v32kfGiven)
913             model->BSIM3v32kf = 0.0;
914 
915         if (!model->BSIM3v32vgsMaxGiven)
916             model->BSIM3v32vgsMax = 1e99;
917         if (!model->BSIM3v32vgdMaxGiven)
918             model->BSIM3v32vgdMax = 1e99;
919         if (!model->BSIM3v32vgbMaxGiven)
920             model->BSIM3v32vgbMax = 1e99;
921         if (!model->BSIM3v32vdsMaxGiven)
922             model->BSIM3v32vdsMax = 1e99;
923         if (!model->BSIM3v32vbsMaxGiven)
924             model->BSIM3v32vbsMax = 1e99;
925         if (!model->BSIM3v32vbdMaxGiven)
926             model->BSIM3v32vbdMax = 1e99;
927         if (!model->BSIM3v32vgsrMaxGiven)
928             model->BSIM3v32vgsrMax = 1e99;
929         if (!model->BSIM3v32vgdrMaxGiven)
930             model->BSIM3v32vgdrMax = 1e99;
931         if (!model->BSIM3v32vgbrMaxGiven)
932             model->BSIM3v32vgbrMax = 1e99;
933         if (!model->BSIM3v32vbsrMaxGiven)
934             model->BSIM3v32vbsrMax = 1e99;
935         if (!model->BSIM3v32vbdrMaxGiven)
936             model->BSIM3v32vbdrMax = 1e99;
937 
938         /* loop through all the instances of the model */
939         for (here = BSIM3v32instances(model); here != NULL ;
940              here=BSIM3v32nextInstance(here))
941         {
942             /* allocate a chunk of the state vector */
943             here->BSIM3v32states = *states;
944             *states += BSIM3v32numStates;
945 
946             /* perform the parameter defaulting */
947             if (!here->BSIM3v32drainAreaGiven)
948                 here->BSIM3v32drainArea = 0.0;
949             if (!here->BSIM3v32drainPerimeterGiven)
950                 here->BSIM3v32drainPerimeter = 0.0;
951             if (!here->BSIM3v32drainSquaresGiven)
952             {
953                 if (model->BSIM3v32acmMod == 0)
954                   here->BSIM3v32drainSquares = 1.0;
955                 else
956                   here->BSIM3v32drainSquares = 0.0;
957             }
958             if (!here->BSIM3v32delvtoGiven)
959                 here->BSIM3v32delvto = 0.0;
960             if (!here->BSIM3v32mulu0Given)
961                 here->BSIM3v32mulu0 = 1.0;
962             if (!here->BSIM3v32icVBSGiven)
963                 here->BSIM3v32icVBS = 0.0;
964             if (!here->BSIM3v32icVDSGiven)
965                 here->BSIM3v32icVDS = 0.0;
966             if (!here->BSIM3v32icVGSGiven)
967                 here->BSIM3v32icVGS = 0.0;
968             if (!here->BSIM3v32lGiven)
969                 here->BSIM3v32l = 5.0e-6;
970             if (!here->BSIM3v32sourceAreaGiven)
971                 here->BSIM3v32sourceArea = 0.0;
972             if (!here->BSIM3v32sourcePerimeterGiven)
973                 here->BSIM3v32sourcePerimeter = 0.0;
974             if (!here->BSIM3v32sourceSquaresGiven)
975             {
976                 if (model->BSIM3v32acmMod == 0)
977                   here->BSIM3v32sourceSquares = 1.0;
978                 else
979                   here->BSIM3v32sourceSquares = 0.0;
980             }
981             if (!here->BSIM3v32wGiven)
982                 here->BSIM3v32w = 5.0e-6;
983             if (!here->BSIM3v32nqsModGiven)
984                 here->BSIM3v32nqsMod = model->BSIM3v32nqsMod;
985             else if ((here->BSIM3v32nqsMod != 0) && (here->BSIM3v32nqsMod != 1))
986             {   here->BSIM3v32nqsMod = model->BSIM3v32nqsMod;
987                 printf("Warning: nqsMod has been set to its global value %d.\n",
988                 model->BSIM3v32nqsMod);
989             }
990             if (!here->BSIM3v32geoGiven)
991                 here->BSIM3v32geo = 0;
992 
993             if (!here->BSIM3v32mGiven)
994                 here->BSIM3v32m = 1;
995 
996             /* process source/drain series resistance */
997             /* ACM model */
998 
999             double DrainResistance, SourceResistance;
1000 
1001             if (model->BSIM3v32acmMod == 0)
1002             {
1003                 DrainResistance = model->BSIM3v32sheetResistance
1004                     * here->BSIM3v32drainSquares;
1005                 SourceResistance = model->BSIM3v32sheetResistance
1006                     * here->BSIM3v32sourceSquares;
1007             }
1008             else /* ACM > 0 */
1009             {
1010                 error = ACM_SourceDrainResistances(
1011                     model->BSIM3v32acmMod,
1012                     model->BSIM3v32ld,
1013                     model->BSIM3v32ldif,
1014                     model->BSIM3v32hdif,
1015                     model->BSIM3v32wmlt,
1016                     here->BSIM3v32w,
1017                     model->BSIM3v32xw,
1018                     model->BSIM3v32sheetResistance,
1019                     here->BSIM3v32drainSquaresGiven,
1020                     model->BSIM3v32rd,
1021                     model->BSIM3v32rdc,
1022                     here->BSIM3v32drainSquares,
1023                     here->BSIM3v32sourceSquaresGiven,
1024                     model->BSIM3v32rs,
1025                     model->BSIM3v32rsc,
1026                     here->BSIM3v32sourceSquares,
1027                     &DrainResistance,
1028                     &SourceResistance
1029                     );
1030                 if (error)
1031                     return(error);
1032             }
1033 
1034             /* process drain series resistance */
1035             if (DrainResistance != 0)
1036             {
1037                if(here->BSIM3v32dNodePrime == 0) {
1038                  error = CKTmkVolt(ckt,&tmp,here->BSIM3v32name,"drain");
1039                  if(error) return(error);
1040                  here->BSIM3v32dNodePrime = tmp->number;
1041                  if (ckt->CKTcopyNodesets) {
1042                    if (CKTinst2Node(ckt,here,1,&tmpNode,&tmpName)==OK) {
1043                       if (tmpNode->nsGiven) {
1044                         tmp->nodeset=tmpNode->nodeset;
1045                         tmp->nsGiven=tmpNode->nsGiven;
1046                       }
1047                    }
1048                  }
1049                }
1050             }
1051             else
1052             {  here->BSIM3v32dNodePrime = here->BSIM3v32dNode;
1053             }
1054 
1055             /* process source series resistance */
1056             if (SourceResistance != 0)
1057             {
1058                if(here->BSIM3v32sNodePrime == 0) {
1059                  error = CKTmkVolt(ckt,&tmp,here->BSIM3v32name,"source");
1060                  if(error) return(error);
1061                  here->BSIM3v32sNodePrime = tmp->number;
1062                  if (ckt->CKTcopyNodesets) {
1063                    if (CKTinst2Node(ckt,here,3,&tmpNode,&tmpName)==OK) {
1064                       if (tmpNode->nsGiven) {
1065                         tmp->nodeset=tmpNode->nodeset;
1066                         tmp->nsGiven=tmpNode->nsGiven;
1067                       }
1068                    }
1069                  }
1070                }
1071             }
1072             else
1073             {  here->BSIM3v32sNodePrime = here->BSIM3v32sNode;
1074             }
1075 
1076             /* internal charge node */
1077 
1078             if (here->BSIM3v32nqsMod)
1079             {   if(here->BSIM3v32qNode == 0)
1080                 {   error = CKTmkVolt(ckt,&tmp,here->BSIM3v32name,"charge");
1081                     if(error) return(error);
1082                     here->BSIM3v32qNode = tmp->number;
1083                 }
1084             }
1085             else
1086             {   here->BSIM3v32qNode = 0;
1087             }
1088 
1089             /* Channel length scaling with lmlt model parameter */
1090 
1091             if (model->BSIM3v32lmltGiven)
1092                 here->BSIM3v32l *= model->BSIM3v32lmlt;
1093 
1094         /* set Sparse Matrix Pointers */
1095 
1096 /* macro to make elements with built in test for out of memory */
1097 #define TSTALLOC(ptr,first,second) \
1098 do { if((here->ptr = SMPmakeElt(matrix, here->first, here->second)) == NULL){\
1099     return(E_NOMEM);\
1100 } } while(0)
1101 
1102             TSTALLOC(BSIM3v32DdPtr, BSIM3v32dNode, BSIM3v32dNode);
1103             TSTALLOC(BSIM3v32GgPtr, BSIM3v32gNode, BSIM3v32gNode);
1104             TSTALLOC(BSIM3v32SsPtr, BSIM3v32sNode, BSIM3v32sNode);
1105             TSTALLOC(BSIM3v32BbPtr, BSIM3v32bNode, BSIM3v32bNode);
1106             TSTALLOC(BSIM3v32DPdpPtr, BSIM3v32dNodePrime, BSIM3v32dNodePrime);
1107             TSTALLOC(BSIM3v32SPspPtr, BSIM3v32sNodePrime, BSIM3v32sNodePrime);
1108             TSTALLOC(BSIM3v32DdpPtr, BSIM3v32dNode, BSIM3v32dNodePrime);
1109             TSTALLOC(BSIM3v32GbPtr, BSIM3v32gNode, BSIM3v32bNode);
1110             TSTALLOC(BSIM3v32GdpPtr, BSIM3v32gNode, BSIM3v32dNodePrime);
1111             TSTALLOC(BSIM3v32GspPtr, BSIM3v32gNode, BSIM3v32sNodePrime);
1112             TSTALLOC(BSIM3v32SspPtr, BSIM3v32sNode, BSIM3v32sNodePrime);
1113             TSTALLOC(BSIM3v32BdpPtr, BSIM3v32bNode, BSIM3v32dNodePrime);
1114             TSTALLOC(BSIM3v32BspPtr, BSIM3v32bNode, BSIM3v32sNodePrime);
1115             TSTALLOC(BSIM3v32DPspPtr, BSIM3v32dNodePrime, BSIM3v32sNodePrime);
1116             TSTALLOC(BSIM3v32DPdPtr, BSIM3v32dNodePrime, BSIM3v32dNode);
1117             TSTALLOC(BSIM3v32BgPtr, BSIM3v32bNode, BSIM3v32gNode);
1118             TSTALLOC(BSIM3v32DPgPtr, BSIM3v32dNodePrime, BSIM3v32gNode);
1119             TSTALLOC(BSIM3v32SPgPtr, BSIM3v32sNodePrime, BSIM3v32gNode);
1120             TSTALLOC(BSIM3v32SPsPtr, BSIM3v32sNodePrime, BSIM3v32sNode);
1121             TSTALLOC(BSIM3v32DPbPtr, BSIM3v32dNodePrime, BSIM3v32bNode);
1122             TSTALLOC(BSIM3v32SPbPtr, BSIM3v32sNodePrime, BSIM3v32bNode);
1123             TSTALLOC(BSIM3v32SPdpPtr, BSIM3v32sNodePrime, BSIM3v32dNodePrime);
1124 
1125             TSTALLOC(BSIM3v32QqPtr, BSIM3v32qNode, BSIM3v32qNode);
1126 
1127             TSTALLOC(BSIM3v32QdpPtr, BSIM3v32qNode, BSIM3v32dNodePrime);
1128             TSTALLOC(BSIM3v32QspPtr, BSIM3v32qNode, BSIM3v32sNodePrime);
1129             TSTALLOC(BSIM3v32QgPtr, BSIM3v32qNode, BSIM3v32gNode);
1130             TSTALLOC(BSIM3v32QbPtr, BSIM3v32qNode, BSIM3v32bNode);
1131             TSTALLOC(BSIM3v32DPqPtr, BSIM3v32dNodePrime, BSIM3v32qNode);
1132             TSTALLOC(BSIM3v32SPqPtr, BSIM3v32sNodePrime, BSIM3v32qNode);
1133             TSTALLOC(BSIM3v32GqPtr, BSIM3v32gNode, BSIM3v32qNode);
1134             TSTALLOC(BSIM3v32BqPtr, BSIM3v32bNode, BSIM3v32qNode);
1135 
1136         }
1137     }
1138 #ifdef USE_OMP
1139     InstCount = 0;
1140     model = (BSIM3v32model*)inModel;
1141     /* loop through all the BSIM3 device models
1142     to count the number of instances */
1143 
1144     for (; model != NULL; model = BSIM3v32nextModel(model))
1145     {
1146         /* loop through all the instances of the model */
1147         for (here = BSIM3v32instances(model); here != NULL;
1148              here = BSIM3v32nextInstance(here))
1149         {
1150             InstCount++;
1151         }
1152         model->BSIM3v32InstCount = 0;
1153         model->BSIM3v32InstanceArray = NULL;
1154     }
1155     InstArray = TMALLOC(BSIM3v32instance*, InstCount);
1156     model = (BSIM3v32model*)inModel;
1157     /* store this in the first model only */
1158     model->BSIM3v32InstCount = InstCount;
1159     model->BSIM3v32InstanceArray = InstArray;
1160     idx = 0;
1161     for (; model != NULL; model = BSIM3v32nextModel(model))
1162     {
1163         /* loop through all the instances of the model */
1164         for (here = BSIM3v32instances(model); here != NULL;
1165              here = BSIM3v32nextInstance(here))
1166         {
1167             InstArray[idx] = here;
1168             idx++;
1169         }
1170     }
1171 
1172 #endif
1173     return(OK);
1174 }
1175 
1176 int
BSIM3v32unsetup(GENmodel * inModel,CKTcircuit * ckt)1177 BSIM3v32unsetup(
1178     GENmodel *inModel,
1179     CKTcircuit *ckt)
1180 {
1181     BSIM3v32model *model;
1182     BSIM3v32instance *here;
1183 
1184 #ifdef USE_OMP
1185     model = (BSIM3v32model*)inModel;
1186     tfree(model->BSIM3v32InstanceArray);
1187 #endif
1188 
1189     for (model = (BSIM3v32model *)inModel; model != NULL;
1190             model = BSIM3v32nextModel(model))
1191     {
1192         for (here = BSIM3v32instances(model); here != NULL;
1193                 here=BSIM3v32nextInstance(here))
1194         {
1195             if (here->BSIM3v32qNode > 0)
1196                 CKTdltNNum(ckt, here->BSIM3v32qNode);
1197             here->BSIM3v32qNode = 0;
1198 
1199             if (here->BSIM3v32sNodePrime > 0
1200                     && here->BSIM3v32sNodePrime != here->BSIM3v32sNode)
1201                 CKTdltNNum(ckt, here->BSIM3v32sNodePrime);
1202             here->BSIM3v32sNodePrime = 0;
1203 
1204             if (here->BSIM3v32dNodePrime > 0
1205                     && here->BSIM3v32dNodePrime != here->BSIM3v32dNode)
1206                 CKTdltNNum(ckt, here->BSIM3v32dNodePrime);
1207             here->BSIM3v32dNodePrime = 0;
1208         }
1209     }
1210     return OK;
1211 }
1212 
1213 
1214 
1215 
1216 
1217 
1218