1 /***************************************************************************
2 JSPICE3 adaptation of Spice3f2 - Copyright (c) Stephen R. Whiteley 1992
3 Copyright 1990 Regents of the University of California.  All rights reserved.
4 Authors: 1985 Thomas L. Quarles
5          1987 Kanwar Jit Singh
6          1993 Stephen R. Whiteley
7 ****************************************************************************/
8 
9 #ifndef SRC
10 #define SRC
11 
12 #include "devdefs.h"
13 
14 /*
15  * structures to describe Arbitrary sources
16  */
17 
18 /* information to describe a single instance */
19 
20 typedef struct sSRCinstance {
21 
22     /* backpointer to model */
23     struct sSRCmodel *SRCmodPtr;
24 
25     /* pointer to next instance of current model */
26     struct sSRCinstance *SRCnextInstance;
27 
28     /* pointer to character string naming this instance */
29     IFuid SRCname;
30 
31     /* state info */
32     int SRCstate;
33 
34     /* number of positive node of source */
35     int SRCposNode;
36 
37     /* number of negative node of source */
38     int SRCnegNode;
39 
40     /* number of positive node of linear controlling voltage source */
41     int SRCcontPosNode;
42 
43     /* number of negative node of linear controlling voltage source */
44     int SRCcontNegNode;
45 
46     /* number of branch equation added for voltage source */
47     int SRCbranch;
48 
49     /* number of branch eq of controlling current source */
50     int SRCcontBranch;
51 
52     /* pointer to pointers of the elements in the sparse matrix */
53     double **SRCposptr;
54 
55     /* functions to call to obtain source output */
56 #ifdef __STDC__
57     void (*SRCtranFunc)(CKTcircuit*,struct sSRCinstance*);
58     void (*SRCdcFunc)(CKTcircuit*,struct sSRCinstance*);
59 #else
60     void (*SRCtranFunc)();
61     void (*SRCdcFunc)();
62 #endif
63 
64     /* whether source is voltage or current */
65     int SRCtype;
66 
67     /* whether the source is a linear dependent source and what kind */
68     int SRCdep;
69 
70     /* linear gain coefficient */
71     double SRCcoeff;
72 
73     /* pointer to name of controlling instance */
74     IFuid SRCcontName;
75 
76     /* DC and TRANSIENT value of source */
77     double SRCdcValue;
78 
79     /* AC magnitude and phase */
80     double SRCacVec[2];
81 #define SRCacMag SRCacVec[0]
82 #define SRCacPhase SRCacVec[1]
83 
84     /* AC real component */
85     double SRCacReal;
86 
87     /* AC imaginary component */
88     double SRCacImag;
89 
90     /* distortion f1 magnitude */
91     double SRCdF1mag;
92 
93     /* distortion f2 magnitude */
94     double SRCdF2mag;
95 
96     /* distortion f1 phase */
97     double SRCdF1phase;
98 
99     /* distortion f2 phase */
100     double SRCdF2phase;
101 
102     /* the parse tree */
103     IFparseTree *SRCtree;
104 
105     /* store rhs and derivatives for ac anal */
106     double *SRCacValues;
107 
108     /* store input values to function */
109     double *SRCvalues;
110 
111     /* present source value */
112     double SRCvalue;
113 
114     /* store partial derivatives */
115     double *SRCderivs;
116 
117     /* store equation numbers of input values */
118     int *SRCeqns;
119 
120     /* previous value for the convergence test */
121     double SRCprev;
122 
123     /* pointer to sparse matrix element at
124       (positive node, control positive node) */
125     double *SRCposContPosptr;
126 
127     /* pointer to sparse matrix element at
128       (positive node, control negative node) */
129     double *SRCposContNegptr;
130 
131     /* pointer to sparse matrix element at
132       (negative node, control positive node) */
133     double *SRCnegContPosptr;
134 
135     /* pointer to sparse matrix element at
136       (negative node, control negative node) */
137     double *SRCnegContNegptr;
138 
139     /* pointer to sparse matrix element at
140       (positive node, control branch eq) */
141     double *SRCposContBrptr;
142 
143     /* pointer to sparse matrix element at
144       (negative node, control branch eq) */
145     double *SRCnegContBrptr;
146 
147     /* pointer to sparse matrix element at
148       (branch equation, control positive node) */
149     double *SRCibrContPosptr;
150 
151     /* pointer to sparse matrix element at
152       (branch equation, control negative node) */
153     double *SRCibrContNegptr;
154 
155     /* pointer to sparse matrix element at
156       (branch equation, control branch eq) */
157     double *SRCibrContBrptr;
158 
159     /* pointer to sparse matrix element at
160        (positive node, branch equation) */
161     double *SRCposIbrptr;
162 
163     /* pointer to sparse matrix element at
164        (negative node, branch equation) */
165     double *SRCnegIbrptr;
166 
167     /* pointer to sparse matrix element at
168        (branch equation, positive node) */
169     double *SRCibrPosptr;
170 
171     /* pointer to sparse matrix element at
172        (branch equation, negative node) */
173     double *SRCibrNegptr;
174 
175     /* pointer to sparse matrix element at
176        (branch equation, branch equation) */
177     double *SRCibrIbrptr;
178 
179     /* flags to indicate: */
180     unsigned SRCdcGiven      :1; /* dc value given */
181     unsigned SRCacGiven      :1; /* ac keyword given */
182     unsigned SRCacMGiven     :1; /* ac magnitude given */
183     unsigned SRCacPGiven     :1; /* ac phase given */
184     unsigned SRCdGiven       :1; /* source is a disto input */
185     unsigned SRCdF1given     :1; /* source is an f1 dist input */
186     unsigned SRCdF2given     :1; /* source is an f2 dist input */
187     unsigned SRCccCoeffGiven :1; /* current controlled gain coeff given */
188     unsigned SRCvcCoeffGiven :1; /* voltage controlled gain coeff given */
189 
190 } SRCinstance;
191 
192 
193 /* per model data */
194 
195 /* model structure for a source */
196 typedef struct sSRCmodel {
197 
198     /* type index of this device */
199     int SRCmodType;
200 
201     /* pointer to next possible model in linked list */
202     struct sSRCmodel *SRCnextModel;
203 
204     /* pointer to list of instances that have this model */
205     SRCinstance *SRCinstances;
206 
207     /* pointer to character string naming this model */
208     IFuid SRCmodName;
209 
210 } SRCmodel;
211 
212 #define SRC_CC 1
213 #define SRC_VC 2
214 
215 /* device parameters */
216 #define SRC_I            1
217 #define SRC_V            2
218 #define SRC_DEP          3
219 #define SRC_DC           4
220 #define SRC_AC           5
221 #define SRC_AC_MAG       6
222 #define SRC_AC_PHASE     7
223 #define SRC_FUNC         8
224 #define SRC_D_F1         9
225 #define SRC_D_F2         10
226 #define SRC_GAIN         11
227 #define SRC_CONTROL      12
228 #define SRC_POS_NODE     13
229 #define SRC_NEG_NODE     14
230 #define SRC_AC_REAL      15
231 #define SRC_AC_IMAG      16
232 #define SRC_CURRENT      17
233 #define SRC_POWER        18
234 #define SRC_CONT_P_NODE  19
235 #define SRC_CONT_N_NODE  20
236 
237 #ifdef __STDC__
238 
239 extern int  SRCacLoad(GENmodel*,CKTcircuit*);
240 extern int  SRCask(CKTcircuit*,GENinstance *,int,IFvalue *,IFvalue*);
241 extern int  SRCconvTest(GENmodel *,CKTcircuit*);
242 extern int  SRCdelete(GENmodel *,IFuid,GENinstance **);
243 extern void SRCdestroy(GENmodel**);
244 extern int  SRCfindBr(CKTcircuit *,GENmodel *,IFuid);
245 extern int  SRCload(GENmodel *,CKTcircuit*);
246 extern int  SRCmDelete(GENmodel**,IFuid,GENmodel*);
247 extern int  SRCparam(CKTcircuit*,int,IFvalue*,GENinstance*,IFvalue*);
248 extern void SRCparse(int,GENERIC*,GENERIC*,GENERIC*);
249 extern int  SRCpzLoad(GENmodel*,CKTcircuit*,SPcomplex*);
250 extern int  SRCsetup(SMPmatrix*,GENmodel*,CKTcircuit*,int*);
251 
252 #else /* stdc */
253 
254 extern int  SRCacLoad();
255 extern int  SRCask();
256 extern int  SRCconvTest();
257 extern int  SRCdelete();
258 extern void SRCdestroy();
259 extern int  SRCfindBr();
260 extern int  SRCload();
261 extern int  SRCmDelete();
262 extern int  SRCparam();
263 extern void SRCparse();
264 extern int  SRCpzLoad();
265 extern int  SRCsetup();
266 
267 #endif /* stdc */
268 
269 
270 #endif /* SRC */
271