1 /**********
2 Copyright 1990 Regents of the University of California.  All rights reserved.
3 Author: 1985 Thomas L. Quarles
4 Modified: September 2003 Paolo Nenzi
5 **********/
6 /*
7  */
8 
9 /* update the  charge sensitivities and their derivatives */
10 
11 #include "ngspice/ngspice.h"
12 #include "ngspice/cktdefs.h"
13 #include "capdefs.h"
14 #include "ngspice/trandefs.h"
15 #include "ngspice/sperror.h"
16 #include "ngspice/suffix.h"
17 
18 
19 int
CAPsUpdate(GENmodel * inModel,CKTcircuit * ckt)20 CAPsUpdate(GENmodel *inModel, CKTcircuit *ckt)
21 {
22     CAPmodel *model = (CAPmodel*)inModel;
23     CAPinstance *here;
24     int      iparmno;
25     double   s1;
26     double   s2;
27     double   sxp;
28     double   vcap;
29     double   dummy1;
30     double   dummy2;
31     SENstruct *info;
32 
33     info = ckt->CKTsenInfo;
34     if((info->SENmode == TRANSEN) && (ckt->CKTmode & MODEINITTRAN))
35         return(OK);
36 
37 #ifdef SENSDEBUG
38     printf("CAPsenUpdate\n");
39     printf("CKTtime = %.5e\n",ckt->CKTtime);
40 #endif /* SENSDEBUG */
41 
42     /*  loop through all the capacitor models */
43     for( ; model != NULL; model = CAPnextModel(model)) {
44 
45         /* loop through all the instances of the model */
46         for (here = CAPinstances(model); here != NULL ;
47                 here=CAPnextInstance(here)) {
48 
49             vcap = *(ckt->CKTrhsOld+here->CAPposNode) -
50                 *(ckt->CKTrhsOld+here->CAPnegNode) ;
51 
52 
53             for(iparmno=1;iparmno<=info->SENparms;iparmno++){
54 
55                 s1 = *(info->SEN_Sap[here->CAPposNode] + iparmno);
56                 s2 = *(info->SEN_Sap[here->CAPnegNode] + iparmno);
57                 sxp = here->CAPcapac * (s1 - s2);
58 
59                 if(iparmno == here->CAPsenParmNo) sxp += vcap;
60 
61                 *(ckt->CKTstate0 + here->CAPsensxp + 2*(iparmno - 1)) = sxp;
62 
63                 if(ckt->CKTtime == 0){
64                     *(ckt->CKTstate0 + here->CAPsensxp + 2*(iparmno - 1) + 1)=0;
65                 }
66                 else{
67                     NIintegrate(ckt,&dummy1,&dummy2,here->CAPcapac,
68                             (here->CAPsensxp + 2 * (iparmno -1 )));
69                 }
70 #ifdef SENSDEBUG
71                 printf("after loading\n");
72                 printf("iparmno = %d\n",iparmno);
73                 printf("s1 = %.7e,s2 = %.7e\n",s1,s2);
74                 printf("sxp = %.7e,sdotxp = %.7e\n",
75                         sxp,*(ckt->CKTstate0 + here->CAPsensxp +
76                         2*(iparmno - 1) + 1));
77                 printf("\n");
78 #endif /* SENSDEBUG */
79 
80             }
81         }
82     }
83     return(OK);
84 }
85 
86