1 /*
2  * Copyright (c) 1985 Thomas L. Quarles
3  * Modified 1999 Paolo Nenzi - Removed non STDC definitions
4  * Modified 2000 AlansFixes
5  */
6 #ifndef ngspice_CKTDEFS_H
7 #define ngspice_CKTDEFS_H
8 
9 #include "ngspice/typedefs.h"
10 
11 
12 /* gtri - evt - wbk - 5/20/91 - add event-driven and enhancements data */
13 #ifdef XSPICE
14 #include "ngspice/evttypes.h"
15 #include "ngspice/enhtypes.h"
16 #endif
17 /* gtri - evt - wbk - 5/20/91 - add event-driven and enhancements data */
18 
19 
20 #define MAXNUMDEVS 64   /* Max number of possible devices PN:XXX may cause toubles*/
21 #define MAXNUMDEVNODES 4        /* Max No. of nodes per device */
22                          /* Need to change for SOI devs ? */
23 
24 #include "ngspice/smpdefs.h"
25 #include "ngspice/ifsim.h"
26 #include "ngspice/acdefs.h"
27 #include "ngspice/gendefs.h"
28 #include "ngspice/trcvdefs.h"
29 #include "ngspice/optdefs.h"
30 #include "ngspice/sen2defs.h"
31 #include "ngspice/pzdefs.h"
32 #include "ngspice/noisedef.h"
33 #include "ngspice/hash.h"
34 
35 
36 
37 struct CKTnode {
38     IFuid name;
39     int type;
40 
41 #define SP_VOLTAGE 3
42 #define SP_CURRENT 4
43 #define NODE_VOLTAGE SP_VOLTAGE
44 #define NODE_CURRENT SP_CURRENT
45 
46     int number;                 /* Number of the node */
47     double ic;                  /* Value of the initial condition */
48     double nodeset;             /* Value of the .nodeset option */
49     double *ptr;                /* ??? */
50     CKTnode *next;              /* pointer to the next node */
51     unsigned int icGiven:1;     /* FLAG ic given */
52     unsigned int nsGiven:1;     /* FLAG nodeset given */
53 };
54 
55 /* defines for node parameters */
56 enum {
57     PARM_NS = 1,
58     PARM_IC,
59     PARM_NODETYPE,
60 };
61 
62 struct CKTcircuit {
63 
64 /* gtri - begin - wbk - change declaration to allow dynamic sizing */
65 
66 /* An associated change is made in CKTinit.c to alloc the space */
67 /* required for the pointers.  No changes are needed to the source */
68 /* code at the 3C1 level, although the compiler will generate */
69 /* slightly different code for references to this data. */
70 
71 /*  GENmodel *CKThead[MAXNUMDEVS]; The max number of loadable devices */
72     GENmodel **CKThead;
73 
74 /* gtri - end   - wbk - change declaration to allow dynamic sizing */
75 
76 /*    GENmodel *CKThead[MAXNUMDEVS];  maschmann : deleted */
77 
78 
79     STATistics *CKTstat;        /* The STATistics structure */
80     double *CKTstates[8];       /* Used as memory of past steps ??? */
81 
82     /* Some shortcut for CKTstates */
83 #define CKTstate0 CKTstates[0]
84 #define CKTstate1 CKTstates[1]
85 #define CKTstate2 CKTstates[2]
86 #define CKTstate3 CKTstates[3]
87 #define CKTstate4 CKTstates[4]
88 #define CKTstate5 CKTstates[5]
89 #define CKTstate6 CKTstates[6]
90 #define CKTstate7 CKTstates[7]
91     double CKTtime;             /* Current transient simulation time */
92     double CKTdelta;            /* next time step in transient simulation */
93     double CKTdeltaOld[7];      /* Memory for the 7 most recent CKTdelta */
94     double CKTtemp;             /* Actual temperature of CKT, initialzed to 300.15 K in cktinit.c*/
95     double CKTnomTemp;          /* Reference temperature 300.15 K set in cktinit.c */
96     double CKTvt;               /* Thernmal voltage at CKTtemp */
97     double CKTag[7];            /* the gear variable coefficient matrix */
98 #ifdef PREDICTOR
99     double CKTagp[7];           /* the gear predictor variable
100                                    coefficient matrix */
101 #endif /*PREDICTOR*/
102     int CKTorder;               /* the integration method order */
103     int CKTmaxOrder;            /* maximum integration method order */
104     int CKTintegrateMethod;     /* the integration method to be used */
105     double CKTxmu;              /* for trapezoidal method */
106     int CKTindverbosity;        /* control check of inductive couplings */
107 
108 /* known integration methods */
109 #define TRAPEZOIDAL 1
110 #define GEAR 2
111 
112     SMPmatrix *CKTmatrix;       /* pointer to sparse matrix */
113     int CKTniState;             /* internal state */
114     double *CKTrhs;             /* current rhs value - being loaded */
115     double *CKTrhsOld;          /* previous rhs value for convergence
116                                    testing */
117     double *CKTrhsSpare;        /* spare rhs value for reordering */
118     double *CKTirhs;            /* current rhs value - being loaded
119                                    (imag) */
120     double *CKTirhsOld;         /* previous rhs value (imaginary)*/
121     double *CKTirhsSpare;       /* spare rhs value (imaginary)*/
122 #ifdef PREDICTOR
123     double *CKTpred;            /* predicted solution vector */
124     double *CKTsols[8];         /* previous 8 solutions */
125 #endif /* PREDICTOR */
126 
127     double *CKTrhsOp;           /* opearating point values */
128     double *CKTsenRhs;          /* current sensitivity rhs values */
129     double *CKTseniRhs;         /* current sensitivity rhs values
130                                    (imag)*/
131 
132 
133 /*
134  *  symbolic constants for CKTniState
135  *      Note that they are bitwise disjoint
136  *  What is their meaning ????
137  */
138 
139 #define NISHOULDREORDER       0x1
140 #define NIREORDERED           0x2
141 #define NIUNINITIALIZED       0x4
142 #define NIACSHOULDREORDER    0x10
143 #define NIACREORDERED        0x20
144 #define NIACUNINITIALIZED    0x40
145 #define NIDIDPREORDER       0x100
146 #define NIPZSHOULDREORDER   0x200
147 
148     int CKTmaxEqNum;            /* And this ? */
149     int CKTcurrentAnalysis;     /* the analysis in progress (if any) */
150 
151 /* defines for the value of  CKTcurrentAnalysis */
152 /* are in TSKdefs.h */
153 
154     CKTnode *CKTnodes;          /* ??? */
155     CKTnode *CKTlastNode;       /* ??? */
156     CKTnode *prev_CKTlastNode;  /* just before model setup */
157 
158     /* This define should be somewhere else ??? */
159 #define NODENAME(ckt,nodenum) CKTnodName(ckt,nodenum)
160     int CKTnumStates;           /* Number of sates effectively valid
161                                    ??? */
162     long CKTmode;               /* Mode of operation of the circuit
163                                    ??? */
164 
165 /* defines for CKTmode */
166 
167 /* old 'mode' parameters */
168 #define MODE               0x3
169 #define MODETRAN           0x1
170 #define MODEAC             0x2
171 
172 /* for noise analysis */
173 #define MODEACNOISE        0x8
174 
175 /* old 'modedc' parameters */
176 #define MODEDC            0x70
177 #define MODEDCOP          0x10
178 #define MODETRANOP        0x20
179 #define MODEDCTRANCURVE   0x40
180 
181 /* old 'initf' parameters */
182 #define INITF           0x3f00
183 #define MODEINITFLOAT    0x100
184 #define MODEINITJCT      0x200
185 #define MODEINITFIX      0x400
186 #define MODEINITSMSIG    0x800
187 #define MODEINITTRAN    0x1000
188 #define MODEINITPRED    0x2000
189 
190 /* old 'nosolv' paramater */
191 #define MODEUIC 0x10000l
192 
193     int CKTbypass;              /* bypass option, how does it work ?  */
194     int CKTdcMaxIter;           /* iteration limit for dc op.  (itl1) */
195     int CKTdcTrcvMaxIter;       /* iteration limit for dc tran. curv
196                                    (itl2) */
197     int CKTtranMaxIter;         /* iteration limit for each timepoint
198                                    for tran*/
199     /* (itl4) */
200     int CKTbreakSize;           /* ??? */
201     int CKTbreak;               /* ??? */
202     double CKTsaveDelta;        /* ??? */
203     double CKTminBreak;         /* ??? */
204     double *CKTbreaks;          /* List of breakpoints ??? */
205     double CKTabstol;           /* --- */
206     double CKTpivotAbsTol;      /* --- */
207     double CKTpivotRelTol;      /* --- */
208     double CKTreltol;           /* --- */
209     double CKTchgtol;           /* --- */
210     double CKTvoltTol;          /* --- */
211     /* What is this define for  ? */
212 #ifdef NEWTRUNC
213     double CKTlteReltol;
214     double CKTlteAbstol;
215 #endif /* NEWTRUNC */
216     double CKTgmin;             /* .options GMIN */
217     double CKTgshunt;           /* .options RSHUNT */
218     double CKTcshunt;           /* .options CSHUNT */
219     double CKTdelmin;           /* minimum time step for tran analysis */
220     double CKTtrtol;            /* .options TRTOL */
221     double CKTfinalTime;        /* TSTOP */
222     double CKTstep;             /* TSTEP */
223     double CKTmaxStep;          /* TMAX */
224     double CKTinitTime;         /* TSTART */
225     double CKTomega;            /* actual angular frequency for ac analysis */
226     double CKTsrcFact;          /* source stepping scaling factor */
227     double CKTdiagGmin;         /* actual value during gmin stepping */
228     int CKTnumSrcSteps;         /* .options SRCSTEPS */
229     int CKTnumGminSteps;        /* .options GMINSTEPS */
230     double CKTgminFactor;       /* gmin stepping scaling factor */
231     int CKTnoncon;              /* used by devices (and few other places)
232                                    to announce non-convergence */
233     double CKTdefaultMosM;      /* Default MOS multiplier parameter m */
234     double CKTdefaultMosL;      /* Default Channel Lenght of MOS devices */
235     double CKTdefaultMosW;      /* Default Channel Width of MOS devics */
236     double CKTdefaultMosAD;     /* Default Drain Area of MOS */
237     double CKTdefaultMosAS;     /* Default Source Area of MOS */
238     unsigned int CKThadNodeset:1; /* flag to show that nodes have been set up */
239     unsigned int CKTfixLimit:1; /* flag to indicate that the limiting
240                                    of MOSFETs should be done as in
241                                    SPICE2 */
242     unsigned int CKTnoOpIter:1; /* flag to indicate not to try the operating
243                                    point brute force, but to use gmin stepping
244                                    first */
245     unsigned int CKTisSetup:1;  /* flag to indicate if CKTsetup done */
246 #ifdef XSPICE
247     unsigned int CKTadevFlag:1; /* flag indicates 'A' devices in the circuit */
248 #endif
249     JOB *CKTcurJob;             /* Next analysis to be performed ??? */
250 
251     SENstruct *CKTsenInfo;      /* the sensitivity information */
252     double *CKTtimePoints;      /* list of all accepted timepoints in
253                                    the current transient simulation */
254     double *CKTdeltaList;       /* list of all timesteps in the
255                                    current transient simulation */
256     int CKTtimeListSize;        /* size of above lists */
257     int CKTtimeIndex;           /* current position in above lists */
258     int CKTsizeIncr;            /* amount to increment size of above
259                                    arrays when you run out of space */
260     unsigned int CKTtryToCompact:1; /* try to compact past history for LTRA
261                                        lines */
262     unsigned int CKTbadMos3:1;  /* Use old, unfixed MOS3 equations */
263     unsigned int CKTkeepOpInfo:1; /* flag for small signal analyses */
264     unsigned int CKTcopyNodesets:1; /* NodesetFIX */
265     unsigned int CKTnodeDamping:1; /* flag for node damping fix */
266     double CKTabsDv;            /* abs limit for iter-iter voltage change */
267     double CKTrelDv;            /* rel limit for iter-iter voltage change */
268     int CKTtroubleNode;         /* Non-convergent node number */
269     GENinstance *CKTtroubleElt; /* Non-convergent device instance */
270     int CKTvarHertz;            /* variable HERTZ in B source */
271 /* gtri - evt - wbk - 5/20/91 - add event-driven and enhancements data */
272 #ifdef XSPICE
273     Evt_Ckt_Data_t *evt;        /* all data about event driven stuff */
274     Enh_Ckt_Data_t *enh;        /* data used by general enhancements */
275 #endif
276 /* gtri - evt - wbk - 5/20/91 - add event-driven and enhancements data */
277 
278 #ifdef WITH_PSS
279 /* SP: Periodic Steady State Analysis - 100609 */
280     double CKTstabTime;		/* PSS stab time */
281     double CKTguessedFreq;	/* PSS guessed frequency */
282     int CKTharms;		/* PSS harmonics */
283     long int CKTpsspoints;	/* PSS number of samples */
284     char *CKToscNode;       	/* PSS oscnode */
285     double CKTsteady_coeff;	/* PSS Steady Coefficient */
286     int CKTsc_iter;        	/* PSS Maximum Number of Shooting Iterations */
287 /* SP: 100609 */
288 #endif
289 
290     unsigned int CKTisLinear:1; /* flag to indicate that the circuit
291                                    contains only linear elements */
292     unsigned int CKTnoopac:1; /* flag to indicate that OP will not be evaluated
293                                  during AC simulation */
294     int CKTsoaCheck;    /* flag to indicate that in certain device models
295                            a safe operating area (SOA) check is executed */
296     int CKTsoaMaxWarns; /* specifies the maximum number of SOA warnings */
297 
298     double CKTepsmin; /* minimum argument value for some log functions, e.g. diode saturation current*/
299 
300     NGHASHPTR DEVnameHash;
301     NGHASHPTR MODnameHash;
302 
303     GENinstance *noise_input;   /* identify the input vsrc/isrc during noise analysis */
304 };
305 
306 
307 /* Now function prottypes */
308 
309 extern int ACan(CKTcircuit *, int);
310 extern int ACaskQuest(CKTcircuit *, JOB *, int , IFvalue *);
311 extern int ACsetParm(CKTcircuit *, JOB *, int , IFvalue *);
312 extern int CKTacDump(CKTcircuit *, double , runDesc *);
313 extern int CKTacLoad(CKTcircuit *);
314 extern int CKTaccept(CKTcircuit *);
315 extern int CKTacct(CKTcircuit *, JOB *, int , IFvalue *);
316 extern int CKTask(CKTcircuit *, GENinstance *, int , IFvalue *, IFvalue *);
317 extern int CKTaskAnalQ(CKTcircuit *, JOB *, int , IFvalue *, IFvalue *);
318 extern int CKTaskNodQst(CKTcircuit *, CKTnode *, int , IFvalue *, IFvalue *);
319 extern int CKTbindNode(CKTcircuit *, GENinstance *, int , CKTnode *);
320 extern void CKTbreakDump(CKTcircuit *);
321 extern int CKTclrBreak(CKTcircuit *);
322 extern int CKTconvTest(CKTcircuit *);
323 extern int CKTcrtElt(CKTcircuit *, GENmodel *, GENinstance **, IFuid);
324 extern int CKTdelTask(CKTcircuit *, TSKtask *);
325 extern int CKTdestroy(CKTcircuit *);
326 extern int CKTdltAnal(void *, void *, void *);
327 extern int CKTdltInst(CKTcircuit *, void *);
328 extern int CKTdltMod(CKTcircuit *, GENmodel *);
329 extern int CKTdltNNum(CKTcircuit *, int);
330 extern int CKTdltNod(CKTcircuit *, CKTnode *);
331 extern int CKTdoJob(CKTcircuit *, int , TSKtask *);
332 extern void CKTdump(CKTcircuit *, double, runDesc *);
333 extern int CKTsoaInit(void);
334 extern int CKTsoaCheck(CKTcircuit *);
335 #ifdef CIDER
336 extern void NDEVacct(CKTcircuit *ckt, FILE *file);
337 #endif /* CIDER */
338 extern void CKTncDump(CKTcircuit *);
339 extern int CKTfndAnal(CKTcircuit *, int *, JOB **, IFuid , TSKtask *, IFuid);
340 extern int CKTfndBranch(CKTcircuit *, IFuid);
341 extern GENinstance *CKTfndDev(CKTcircuit *, IFuid);
342 extern GENmodel *CKTfndMod(CKTcircuit *, IFuid);
343 extern int CKTfndNode(CKTcircuit *, CKTnode **, IFuid);
344 extern int CKTfndTask(CKTcircuit *, TSKtask **, IFuid );
345 extern int CKTground(CKTcircuit *, CKTnode **, IFuid);
346 extern int CKTic(CKTcircuit *);
347 extern int CKTinit(CKTcircuit **);
348 extern int CKTinst2Node(CKTcircuit *, void *, int , CKTnode **, IFuid *);
349 extern int CKTlinkEq(CKTcircuit *, CKTnode *);
350 extern int CKTload(CKTcircuit *);
351 extern int CKTmapNode(CKTcircuit *, CKTnode **, IFuid);
352 extern int CKTmkCur(CKTcircuit  *, CKTnode **, IFuid , char *);
353 extern int CKTmkNode(CKTcircuit *, CKTnode **);
354 extern int CKTmkVolt(CKTcircuit  *, CKTnode **, IFuid , char *);
355 extern int CKTmodAsk(CKTcircuit *, GENmodel *, int , IFvalue *, IFvalue *);
356 extern int CKTmodCrt(CKTcircuit *, int , GENmodel **, IFuid);
357 extern int CKTmodParam(CKTcircuit *, GENmodel *, int , IFvalue *, IFvalue *);
358 extern int CKTnames(CKTcircuit *, int *, IFuid **);
359 extern int CKTdnames(CKTcircuit *);
360 extern int CKTnewAnal(CKTcircuit *, int , IFuid , JOB **, TSKtask *);
361 extern int CKTnewEq(CKTcircuit *, CKTnode **, IFuid);
362 extern int CKTnewNode(CKTcircuit *, CKTnode **, IFuid);
363 extern int CKTnewTask(CKTcircuit *, TSKtask **, IFuid, TSKtask **);
364 extern int CKTnoise (CKTcircuit *ckt, int mode, int operation, Ndata *data);
365 extern IFuid CKTnodName(CKTcircuit *, int);
366 extern void CKTnodOut(CKTcircuit *);
367 extern CKTnode * CKTnum2nod(CKTcircuit *, int);
368 extern int CKTop(CKTcircuit *, long, long, int);
369 extern int CKTpModName(char *, IFvalue *, CKTcircuit *, int , IFuid , GENmodel **);
370 extern int CKTpName(char *, IFvalue *, CKTcircuit *, int , char *, GENinstance **);
371 extern int CKTparam(CKTcircuit *, GENinstance *, int , IFvalue *, IFvalue *);
372 extern int CKTpzFindZeros(CKTcircuit *, PZtrial **, int *);
373 extern int CKTpzLoad(CKTcircuit *, SPcomplex *);
374 extern int CKTpzSetup(CKTcircuit *, int);
375 extern int CKTsenAC(CKTcircuit *);
376 extern int CKTsenComp(CKTcircuit *);
377 extern int CKTsenDCtran(CKTcircuit *);
378 extern int CKTsenLoad(CKTcircuit *);
379 extern void CKTsenPrint(CKTcircuit *);
380 extern int CKTsenSetup(CKTcircuit *);
381 extern int CKTsenUpdate(CKTcircuit *);
382 extern int CKTsetAnalPm(CKTcircuit *, JOB *, int , IFvalue *, IFvalue *);
383 extern int CKTsetBreak(CKTcircuit *, double);
384 extern int CKTsetNodPm(CKTcircuit *, CKTnode *, int , IFvalue *, IFvalue *);
385 extern int CKTsetOpt(CKTcircuit *, JOB *, int , IFvalue *);
386 extern int CKTsetup(CKTcircuit *);
387 extern int CKTunsetup(CKTcircuit *);
388 extern int CKTtemp(CKTcircuit *);
389 extern char *CKTtrouble(CKTcircuit *, char *);
390 extern void CKTterr(int , CKTcircuit *, double *);
391 extern int CKTtrunc(CKTcircuit *, double *);
392 extern int CKTtypelook(char *);
393 extern int DCOaskQuest(CKTcircuit *, JOB *, int , IFvalue *);
394 extern int DCOsetParm(CKTcircuit  *, JOB *, int , IFvalue *);
395 extern int DCTaskQuest(CKTcircuit *, JOB *, int , IFvalue *);
396 extern int DCTsetParm(CKTcircuit  *, JOB *, int , IFvalue *);
397 extern int DCop(CKTcircuit *ckt, int notused); /* va: notused avoids "init from incompatible pointer type" */
398 extern int DCtrCurv(CKTcircuit *, int);
399 extern int DCtran(CKTcircuit *, int);
400 extern int DISTOan(CKTcircuit *, int);
401 extern int NOISEan(CKTcircuit *, int);
402 extern int PZan(CKTcircuit *, int);
403 extern int PZinit(CKTcircuit *);
404 extern int PZpost(CKTcircuit *);
405 extern int PZaskQuest(CKTcircuit *, JOB *, int , IFvalue *);
406 extern int PZsetParm(CKTcircuit *, JOB *, int , IFvalue *);
407 
408 #ifdef WANT_SENSE2
409 extern int SENaskQuest(CKTcircuit *, JOB *, int , IFvalue *);
410 extern void SENdestroy(SENstruct *);
411 extern int SENsetParm(CKTcircuit *, JOB *, int , IFvalue *);
412 extern int SENstartup(CKTcircuit *, int);
413 #endif
414 
415 extern int SPIinit(IFfrontEnd *, IFsimulator **);
416 extern int TFanal(CKTcircuit *, int);
417 extern int TFaskQuest(CKTcircuit *, JOB *, int , IFvalue *);
418 extern int TFsetParm(CKTcircuit *, JOB *, int , IFvalue *);
419 extern int TRANaskQuest(CKTcircuit *, JOB *, int , IFvalue *);
420 extern int TRANsetParm(CKTcircuit *, JOB *, int , IFvalue *);
421 extern int TRANinit(CKTcircuit *, JOB *);
422 
423 #ifdef WITH_PSS
424 /* SP: Steady State Analysis */
425 extern int PSSaskQuest(CKTcircuit *, JOB *, int , IFvalue *);
426 extern int PSSsetParm(CKTcircuit *, JOB *, int , IFvalue *);
427 extern int PSSinit(CKTcircuit *, JOB *);
428 extern int DCpss(CKTcircuit *, int);
429 /* SP */
430 #endif
431 
432 #ifdef __cplusplus
433 extern "C"
434 {
435 #endif
436 extern int NaskQuest(CKTcircuit *, JOB *, int, IFvalue *);
437 extern int NsetParm(CKTcircuit *, JOB *, int, IFvalue *);
438 extern int NIacIter(CKTcircuit *);
439 extern int NIcomCof(CKTcircuit *);
440 extern int NIconvTest(CKTcircuit *);
441 extern void NIdestroy(CKTcircuit *);
442 extern int NIinit(CKTcircuit  *);
443 extern int NIintegrate(CKTcircuit *, double *, double *, double , int);
444 extern int NIiter(CKTcircuit * , int);
445 extern int NIpzMuller(PZtrial **, PZtrial *);
446 extern int NIpzComplex(PZtrial **, PZtrial *);
447 extern int NIpzSym(PZtrial **, PZtrial *);
448 extern int NIpzSym2(PZtrial **, PZtrial *);
449 extern int NIreinit(CKTcircuit *);
450 extern int NIsenReinit(CKTcircuit *);
451 extern int NIdIter (CKTcircuit *);
452 extern void NInzIter(CKTcircuit *, int, int);
453 #ifdef __cplusplus
454 }
455 #endif
456 
457 #ifdef PREDICTOR
458 extern int NIpred(CKTcircuit *ckt);
459 #endif
460 
461 extern IFfrontEnd *SPfrontEnd;
462 
463 struct circ;
464 extern void inp_evaluate_temper(struct circ *ckt);
465 
466 #endif
467