1 /**********
2 Copyright 1990 Regents of the University of California.  All rights reserved.
3 Author: 1985 Thomas L. Quarles
4 Modified: Alan Gillespie
5 
6 This function is obsolete (was used by an old sensitivity analysis)
7 **********/
8 
9 #include "ngspice/ngspice.h"
10 #include "ngspice/smpdefs.h"
11 #include "ngspice/cktdefs.h"
12 #include "mos9defs.h"
13 #include "ngspice/sperror.h"
14 #include "ngspice/suffix.h"
15 
16 int
MOS9sUpdate(GENmodel * inModel,CKTcircuit * ckt)17 MOS9sUpdate(GENmodel *inModel, CKTcircuit *ckt)
18 {
19     MOS9model *model = (MOS9model *)inModel;
20     MOS9instance *here;
21     int    iparmno;
22     double sb;
23     double sg;
24     double sdprm;
25     double ssprm;
26     double sxpgs;
27     double sxpgd;
28     double sxpbs;
29     double sxpbd;
30     double sxpgb;
31     double dummy1;
32     double dummy2;
33     SENstruct *info;
34 
35 
36     if(ckt->CKTtime == 0) return(OK);
37     info = ckt->CKTsenInfo;
38 
39 #ifdef SENSDEBUG
40     printf("MOS9senupdate\n");
41     printf("CKTtime = %.5e\n",ckt->CKTtime);
42 #endif /* SENSDEBUG */
43 
44     sxpgs = 0;
45     sxpgd = 0;
46     sxpbs = 0;
47     sxpbd = 0;
48     sxpgb = 0;
49     dummy1 = 0;
50     dummy2 = 0;
51 
52     /*  loop through all the MOS9 models */
53     for( ; model != NULL; model = MOS9nextModel(model)) {
54 
55         /* loop through all the instances of the model */
56         for (here = MOS9instances(model); here != NULL ;
57                 here=MOS9nextInstance(here)) {
58 
59 #ifdef SENSDEBUG
60             printf("senupdate instance name %s\n",here->MOS9name);
61             printf("before loading\n");
62             printf("CKTag[0] = %.2e,CKTag[1] = %.2e\n",
63                     ckt->CKTag[0],ckt->CKTag[1]);
64             printf("capgs = %.7e\n",here->MOS9cgs);
65             printf("capgd = %.7e\n",here->MOS9cgd);
66             printf("capgb = %.7e\n",here->MOS9cgb);
67             printf("capbs = %.7e\n",here->MOS9capbs);
68             printf("capbd = %.7e\n",here->MOS9capbd);
69 #endif /* SENSDEBUG */
70 
71             for(iparmno = 1;iparmno<=info->SENparms;iparmno++){
72 
73                 sb = *(info->SEN_Sap[here->MOS9bNode] + iparmno);
74                 sg = *(info->SEN_Sap[here->MOS9gNode] + iparmno);
75                 ssprm = *(info->SEN_Sap[here->MOS9sNodePrime] + iparmno);
76                 sdprm = *(info->SEN_Sap[here->MOS9dNodePrime] + iparmno);
77 #ifdef SENSDEBUG
78                 printf("iparmno = %d\n",iparmno);
79                 printf("sb = %.7e,sg = %.7e\n",sb,sg);
80                 printf("ssprm = %.7e,sdprm = %.7e\n",ssprm,sdprm);
81 #endif /* SENSDEBUG */
82 
83                 sxpgs =  (sg - ssprm) * here->MOS9cgs ;
84                 sxpgd =  (sg - sdprm) * here->MOS9cgd ;
85                 sxpgb =  (sg - sb) * here->MOS9cgb ;
86                 sxpbs =  (sb - ssprm) * here->MOS9capbs ;
87                 sxpbd =  (sb - sdprm) * here->MOS9capbd ;
88 
89                 if(here->MOS9sens_l && (iparmno == here->MOS9senParmNo)){
90                     sxpgs += *(here->MOS9dphigs_dl);
91                     sxpgd += *(here->MOS9dphigd_dl);
92                     sxpbs += *(here->MOS9dphibs_dl);
93                     sxpbd += *(here->MOS9dphibd_dl);
94                     sxpgb += *(here->MOS9dphigb_dl);
95                 }
96                 if(here->MOS9sens_w &&
97                         (iparmno == (here->MOS9senParmNo +
98                             (int) here->MOS9sens_l))){
99                     sxpgs += *(here->MOS9dphigs_dw);
100                     sxpgd += *(here->MOS9dphigd_dw);
101                     sxpbs += *(here->MOS9dphibs_dw);
102                     sxpbd += *(here->MOS9dphibd_dw);
103                     sxpgb += *(here->MOS9dphigb_dw);
104                 }
105                 if(ckt->CKTmode & MODEINITTRAN) {
106                     *(ckt->CKTstate1 + here->MOS9sensxpgs +
107                             10 * (iparmno - 1)) = sxpgs;
108                     *(ckt->CKTstate1 + here->MOS9sensxpgd +
109                             10 * (iparmno - 1)) = sxpgd;
110                     *(ckt->CKTstate1 + here->MOS9sensxpbs +
111                             10 * (iparmno - 1)) = sxpbs;
112                     *(ckt->CKTstate1 + here->MOS9sensxpbd +
113                             10 * (iparmno - 1)) = sxpbd;
114                     *(ckt->CKTstate1 + here->MOS9sensxpgb +
115                             10 * (iparmno - 1)) = sxpgb;
116                     *(ckt->CKTstate1 + here->MOS9sensxpgs +
117                             10 * (iparmno - 1) + 1) = 0;
118                     *(ckt->CKTstate1 + here->MOS9sensxpgd +
119                             10 * (iparmno - 1) + 1) = 0;
120                     *(ckt->CKTstate1 + here->MOS9sensxpbs +
121                             10 * (iparmno - 1) + 1) = 0;
122                     *(ckt->CKTstate1 + here->MOS9sensxpbd +
123                             10 * (iparmno - 1) + 1) = 0;
124                     *(ckt->CKTstate1 + here->MOS9sensxpgb +
125                             10 * (iparmno - 1) + 1) = 0;
126                     goto next;
127                 }
128 
129                 *(ckt->CKTstate0 + here->MOS9sensxpgs +
130                         10 * (iparmno - 1)) = sxpgs;
131                 *(ckt->CKTstate0 + here->MOS9sensxpgd +
132                         10 * (iparmno - 1)) = sxpgd;
133                 *(ckt->CKTstate0 + here->MOS9sensxpbs +
134                         10 * (iparmno - 1)) = sxpbs;
135                 *(ckt->CKTstate0 + here->MOS9sensxpbd +
136                         10 * (iparmno - 1)) = sxpbd;
137                 *(ckt->CKTstate0 + here->MOS9sensxpgb +
138                         10 * (iparmno - 1)) = sxpgb;
139 
140                 NIintegrate(ckt,&dummy1,&dummy2,here->MOS9cgs,
141                         here->MOS9sensxpgs + 10*(iparmno -1));
142                 NIintegrate(ckt,&dummy1,&dummy2,here->MOS9cgd,
143                         here->MOS9sensxpgd + 10*(iparmno -1));
144                 NIintegrate(ckt,&dummy1,&dummy2,here->MOS9cgb,
145                         here->MOS9sensxpgb + 10*(iparmno -1));
146                 NIintegrate(ckt,&dummy1,&dummy2,here->MOS9capbs,
147                         here->MOS9sensxpbs + 10*(iparmno -1));
148                 NIintegrate(ckt,&dummy1,&dummy2,here->MOS9capbd,
149                         here->MOS9sensxpbd + 10*(iparmno -1));
150 
151 
152 next:
153                 ;
154 #ifdef SENSDEBUG
155                 printf("after loading\n");
156                 printf("sxpgs = %.7e,sdotxpgs = %.7e\n",
157                         sxpgs,*(ckt->CKTstate0 + here->MOS9sensxpgs +
158                         10 * (iparmno - 1) + 1));
159                 printf("sxpgd = %.7e,sdotxpgd = %.7e\n",
160                         sxpgd,*(ckt->CKTstate0 + here->MOS9sensxpgd +
161                         10 * (iparmno - 1) + 1));
162                 printf("sxpgb = %.7e,sdotxpgb = %.7e\n",
163                         sxpgb,*(ckt->CKTstate0 + here->MOS9sensxpgb +
164                         10 * (iparmno - 1) + 1));
165                 printf("sxpbs = %.7e,sdotxpbs = %.7e\n",
166                         sxpbs,*(ckt->CKTstate0 + here->MOS9sensxpbs +
167                         10 * (iparmno - 1) + 1));
168                 printf("sxpbd = %.7e,sdotxpbd = %.7e\n",
169                         sxpbd,*(ckt->CKTstate0 + here->MOS9sensxpbd +
170                         10 * (iparmno - 1) + 1));
171 #endif /* SENSDEBUG */
172             }
173         }
174     }
175 #ifdef SENSDEBUG
176     printf("MOS9senupdate end\n");
177 #endif /* SENSDEBUG */
178     return(OK);
179 
180 }
181 
182