Jspice3
srcset.c File Reference
#include "spice.h"
#include <stdio.h>
#include "srcdefs.h"
#include "sperror.h"
#include "util.h"
#include "cktext.h"
Include dependency graph for srcset.c:

Go to the source code of this file.

Macros

#define MY_TSTALLOC(ptr, first, second)
 

Functions

static void src_ccvs ()
 
static void src_vcvs ()
 
static void src_cccs ()
 
static void src_vccs ()
 
static void src_dc ()
 
static void src_func0 ()
 
static void src_func1 ()
 
int SRCsetup (SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states)
 
static void src_ccvs (CKTcircuit *ckt, SRCinstance *here)
 
static void src_vcvs (CKTcircuit *ckt, SRCinstance *here)
 
static void src_cccs (CKTcircuit *ckt, SRCinstance *here)
 
static void src_vccs (CKTcircuit *ckt, SRCinstance *here)
 
static void src_dc (CKTcircuit *ckt, SRCinstance *here)
 
static void src_func0 (CKTcircuit *ckt, SRCinstance *here)
 
static void src_func1 (CKTcircuit *ckt, SRCinstance *here)
 

Macro Definition Documentation

#define MY_TSTALLOC (   ptr,
  first,
  second 
)
Value:
if((here->ptr = spGetElement(matrix,here->first,((CKTnode*)(second))->number))\
==(double *)NULL){\
}
#define NULL
Definition: spdefs.h:121
#define E_NOMEM
Definition: iferrmsg.h:27
spREAL * spGetElement()
return(True)

Definition at line 34 of file srcset.c.

Function Documentation

static void src_cccs ( )
static
static void src_cccs ( CKTcircuit ckt,
SRCinstance here 
)
static

Definition at line 302 of file srcset.c.

306 {
307  *(here->SRCposContBrptr) += here->SRCcoeff;
308  *(here->SRCnegContBrptr) -= here->SRCcoeff;
309 }
double SRCcoeff
Definition: srcdefs.h:71
double * SRCnegContBrptr
Definition: srcdefs.h:145
double * SRCposContBrptr
Definition: srcdefs.h:141
static void src_ccvs ( )
static
static void src_ccvs ( CKTcircuit ckt,
SRCinstance here 
)
static

Definition at line 281 of file srcset.c.

285 {
286  *(here->SRCibrContBrptr) += here->SRCcoeff;
287 }
double * SRCibrContBrptr
Definition: srcdefs.h:157
double SRCcoeff
Definition: srcdefs.h:71
static void src_dc ( )
static
static void src_dc ( CKTcircuit ckt,
SRCinstance here 
)
static

Definition at line 326 of file srcset.c.

330 {
331  double rhs = ckt->CKTsrcFact * here->SRCdcValue;
332 
333  if (here->SRCtype == SRC_V) {
334  *(ckt->CKTrhs + here->SRCbranch) = rhs;
335  }
336  else {
337  *(ckt->CKTrhs + (here->SRCposNode)) -= rhs;
338  *(ckt->CKTrhs + (here->SRCnegNode)) += rhs;
339  }
340 }
#define SRC_V
Definition: srcdefs.h:217
int SRCnegNode
Definition: srcdefs.h:38
int SRCposNode
Definition: srcdefs.h:35
double SRCdcValue
Definition: srcdefs.h:77
double CKTsrcFact
Definition: cktdefs.h:199
int SRCbranch
Definition: srcdefs.h:47
int SRCtype
Definition: srcdefs.h:65
double * CKTrhs
Definition: cktdefs.h:97
static void src_func0 ( )
static
static void src_func0 ( CKTcircuit ckt,
SRCinstance here 
)
static

Definition at line 344 of file srcset.c.

348 {
349  double rhs;
350 
351  if (ckt->CKTmode & (MODEINITTRAN|MODEINITPRED|MODEDC)) {
352  rhs = 0;
353 
354  if (ckt->CKTmode & MODEDCTRANCURVE)
355  rhs = ckt->CKTsrcFact * here->SRCdcValue;
356  else if ((*(here->SRCtree->IFeval))
357  (here->SRCtree,ckt->CKTgmin,&rhs,NULL,
358  NULL,&ckt->CKTtime) == OK) {
359  /* !! last arg bogus if ft_sim->specSigs changed !! */
360 
361  here->SRCvalue = rhs;
362 
363  /* Store the rhs for small signal analysis */
364  if (ckt->CKTmode & MODEINITSMSIG) {
365  here->SRCacValues[0] = rhs;
366  }
367  }
368  }
369  else {
370  rhs = here->SRCvalue;
371  }
372 
373  if (here->SRCtype == SRC_V) {
374  *(ckt->CKTrhs + here->SRCbranch) = rhs;
375  }
376  else {
377  *(ckt->CKTrhs + (here->SRCposNode)) -= rhs;
378  *(ckt->CKTrhs + (here->SRCnegNode)) += rhs;
379  }
380 }
double CKTtime
Definition: cktdefs.h:77
#define SRC_V
Definition: srcdefs.h:217
#define MODEINITPRED
Definition: cktdefs.h:161
#define MODEDC
Definition: cktdefs.h:149
#define MODEDCTRANCURVE
Definition: cktdefs.h:152
int SRCnegNode
Definition: srcdefs.h:38
#define MODEINITTRAN
Definition: cktdefs.h:160
int SRCposNode
Definition: srcdefs.h:35
double SRCdcValue
Definition: srcdefs.h:77
double CKTsrcFact
Definition: cktdefs.h:199
#define OK
Definition: iferrmsg.h:17
int SRCbranch
Definition: srcdefs.h:47
#define NULL
Definition: spdefs.h:121
#define MODEINITSMSIG
Definition: cktdefs.h:159
double * SRCacValues
Definition: srcdefs.h:106
double CKTgmin
Definition: cktdefs.h:190
double SRCvalue
Definition: srcdefs.h:112
int SRCtype
Definition: srcdefs.h:65
IFparseTree * SRCtree
Definition: srcdefs.h:103
long CKTmode
Definition: cktdefs.h:139
double * CKTrhs
Definition: cktdefs.h:97
static void src_func1 ( )
static
static void src_func1 ( CKTcircuit ckt,
SRCinstance here 
)
static

Definition at line 384 of file srcset.c.

388 {
389  int i, j;
390  double rhs, deriv;
391 
392  if (ckt->CKTmode & (MODEINITFLOAT|MODEINITFIX)) {
393  for (i = 0; i < here->SRCtree->numVars; i++) {
394  here->SRCvalues[i] =
395  *(ckt->CKTrhsOld + here->SRCeqns[i]);
396  }
397  }
398  else if (ckt->CKTmode & MODEINITPRED) {
399  double *d = ckt->CKTpred;
400  for (i = 0; i < here->SRCtree->numVars; i++) {
401  here->SRCvalues[i] =
402  *(ckt->CKTstate1 + here->SRCstate + i)*d[0] +
403  *(ckt->CKTstate2 + here->SRCstate + i)*d[1] +
404  *(ckt->CKTstate3 + here->SRCstate + i)*d[2] +
405  *(ckt->CKTstate0 + here->SRCstate + i)*d[3];
406  }
407  }
408  else if (ckt->CKTmode & MODEINITJCT) {
409  for (i = 0; i < here->SRCtree->numVars; i++) {
410  here->SRCvalues[i] = 0;
411  }
412  }
413  else {
414  for (i = 0; i < here->SRCtree->numVars; i++) {
415  here->SRCvalues[i] =
416  *(ckt->CKTstate1 + here->SRCstate + i);
417  }
418  }
419 
420  for (i = 0; i < here->SRCtree->numVars; i++) {
421  *(ckt->CKTstate0 + here->SRCstate + i) =
422  here->SRCvalues[i];
423  }
424 
425  rhs = 0;
426  if ((*(here->SRCtree->IFeval))
427  (here->SRCtree,ckt->CKTgmin,&rhs,here->SRCvalues,
428  here->SRCderivs,&ckt->CKTtime) == OK) {
429  /* !! last arg bogus if ft_sim->specSigs changed !! */
430 
431  here->SRCprev = rhs;
432 
433  if (here->SRCtype == SRC_V) {
434  for (i = 0; i < here->SRCtree->numVars; i++) {
435  deriv = here->SRCderivs[i];
436  rhs -= (here->SRCvalues[i] * deriv);
437  *(here->SRCposptr[i]) -= deriv;
438  }
439  *(ckt->CKTrhs + here->SRCbranch) = rhs;
440  }
441  else {
442  for (j = 0,i = 0; i < here->SRCtree->numVars; i++) {
443  deriv = here->SRCderivs[i];
444  rhs -= (here->SRCvalues[i] * deriv);
445  *(here->SRCposptr[j++]) += deriv;
446  *(here->SRCposptr[j++]) -= deriv;
447  }
448  *(ckt->CKTrhs + (here->SRCposNode)) -= rhs;
449  *(ckt->CKTrhs + (here->SRCnegNode)) += rhs;
450  }
451 
452  /* Store the rhs for small signal analysis */
453  if (ckt->CKTmode & MODEINITSMSIG) {
454  for (i = 0; i < here->SRCtree->numVars; i++) {
455  here->SRCacValues[i] = here->SRCderivs[i];
456  }
457  here->SRCacValues[here->SRCtree->numVars] = rhs;
458  }
459  }
460 }
double CKTtime
Definition: cktdefs.h:77
#define SRC_V
Definition: srcdefs.h:217
double * SRCvalues
Definition: srcdefs.h:109
#define MODEINITPRED
Definition: cktdefs.h:161
int * SRCeqns
Definition: srcdefs.h:118
double SRCprev
Definition: srcdefs.h:121
int SRCnegNode
Definition: srcdefs.h:38
#define MODEINITFLOAT
Definition: cktdefs.h:156
int SRCposNode
Definition: srcdefs.h:35
int SRCstate
Definition: srcdefs.h:32
double CKTpred[4]
Definition: cktdefs.h:105
#define OK
Definition: iferrmsg.h:17
double * CKTrhsOld
Definition: cktdefs.h:98
int SRCbranch
Definition: srcdefs.h:47
Definition: cddefs.h:237
#define MODEINITSMSIG
Definition: cktdefs.h:159
double ** SRCposptr
Definition: srcdefs.h:53
#define MODEINITFIX
Definition: cktdefs.h:158
double * SRCacValues
Definition: srcdefs.h:106
int numVars
Definition: ifsim.h:159
double * SRCderivs
Definition: srcdefs.h:115
double CKTgmin
Definition: cktdefs.h:190
int SRCtype
Definition: srcdefs.h:65
IFparseTree * SRCtree
Definition: srcdefs.h:103
long CKTmode
Definition: cktdefs.h:139
#define MODEINITJCT
Definition: cktdefs.h:157
double * CKTrhs
Definition: cktdefs.h:97
static void src_vccs ( )
static
static void src_vccs ( CKTcircuit ckt,
SRCinstance here 
)
static

Definition at line 313 of file srcset.c.

317 {
318  *(here->SRCposContPosptr) += here->SRCcoeff;
319  *(here->SRCposContNegptr) -= here->SRCcoeff;
320  *(here->SRCnegContPosptr) -= here->SRCcoeff;
321  *(here->SRCnegContNegptr) += here->SRCcoeff;
322 }
double SRCcoeff
Definition: srcdefs.h:71
double * SRCposContPosptr
Definition: srcdefs.h:125
double * SRCposContNegptr
Definition: srcdefs.h:129
double * SRCnegContNegptr
Definition: srcdefs.h:137
double * SRCnegContPosptr
Definition: srcdefs.h:133
static void src_vcvs ( )
static
static void src_vcvs ( CKTcircuit ckt,
SRCinstance here 
)
static

Definition at line 291 of file srcset.c.

295 {
296  *(here->SRCibrContPosptr) -= here->SRCcoeff;
297  *(here->SRCibrContNegptr) += here->SRCcoeff;
298 }
double SRCcoeff
Definition: srcdefs.h:71
double * SRCibrContPosptr
Definition: srcdefs.h:149
double * SRCibrContNegptr
Definition: srcdefs.h:153
int SRCsetup ( SMPmatrix matrix,
GENmodel inModel,
CKTcircuit ckt,
int *  states 
)

Definition at line 43 of file srcset.c.

52 {
53  SRCinstance *here;
54  SRCmodel *model = (SRCmodel*)inModel;
55  int error, i, j;
56  CKTnode *tmp;
57  double radians;
58 
59  /* loop through all the user models*/
60  for ( ; model != NULL; model = model->SRCnextModel) {
61 
62  /* loop through all the instances of the model */
63  for (here = model->SRCinstances; here != NULL;
64  here = here->SRCnextInstance) {
65 
66  if (here->SRCtype == SRC_V) {
67  if (here->SRCbranch == 0) {
68  error = CKTmkCur(ckt,&tmp,here->SRCname,"branch");
69  if (error)
70  return (error);
71  here->SRCbranch = tmp->number;
72  }
73  }
74 
75  here->SRCvalue = here->SRCdcValue;
76 
77  if (here->SRCacGiven && !here->SRCacMGiven)
78  here->SRCacMag = 1;
79  if (here->SRCacGiven && !here->SRCacPGiven)
80  here->SRCacPhase = 0;
81  radians = here->SRCacPhase * M_PI / 180.0;
82  here->SRCacReal = here->SRCacMag * cos(radians);
83  here->SRCacImag = here->SRCacMag * sin(radians);
84 
85 #ifdef notdef
86  if (!here->SRCdcGiven) {
87  /* no DC value - either have a transient value, or none */
88  if (here->SRCfuncTGiven) {
89  (*(SPfrontEnd->IFerror))(ERR_WARNING,
90  "%s: no DC value, transient time 0 value used",
91  &(here->SRCname));
92  }
93  else {
94  (*(SPfrontEnd->IFerror))(ERR_WARNING,
95  "%s: has no value, DC 0 assumed",
96  &(here->SRCname));
97  }
98  }
99 #endif
100 
101  here->SRCstate = *states;
102 
103  if (here->SRCtree) {
104  if (here->SRCtree->numVars) {
105  *states += here->SRCtree->numVars;
106  here->SRCvalues = (double *)
107  MALLOC((here->SRCtree->numVars)*sizeof(double));
108  if (here->SRCvalues == NULL)
109  return (E_NOMEM);
110  here->SRCderivs = (double *)
111  MALLOC((here->SRCtree->numVars)*sizeof(double));
112  if (here->SRCderivs == NULL)
113  return (E_NOMEM);
114  here->SRCeqns = (int *)
115  MALLOC((here->SRCtree->numVars)*sizeof(int));
116  if (here->SRCeqns == NULL)
117  return (E_NOMEM);
118  }
119  here->SRCacValues = (double *)
120  MALLOC((here->SRCtree->numVars + 1)*sizeof(double));
121  if (here->SRCacValues == NULL)
122  return (E_NOMEM);
123  }
124  else if (here->SRCccCoeffGiven) {
125  here->SRCcontBranch = CKTfndBranch(ckt,here->SRCcontName);
126  if (here->SRCcontBranch == 0) {
127  IFuid namarray[2];
128  namarray[0] = here->SRCname;
129  namarray[1] = here->SRCcontName;
130  (*(SPfrontEnd->IFerror))(ERR_FATAL,
131  "%s: unknown controlling source %s",namarray);
132  return (E_BADPARM);
133  }
134  }
135 
136  if (here->SRCtype == SRC_V) {
137  TSTALLOC(SRCposIbrptr, SRCposNode, SRCbranch)
138  TSTALLOC(SRCnegIbrptr, SRCnegNode, SRCbranch)
139  TSTALLOC(SRCibrNegptr, SRCbranch, SRCnegNode)
140  TSTALLOC(SRCibrPosptr, SRCbranch, SRCposNode)
141 
142  /* for pz analysis, an ac source is open, ac has precedence
143  * over FUNC
144  */
145  if (here->SRCacGiven)
146  TSTALLOC(SRCibrIbrptr, SRCbranch, SRCbranch)
147 
148  if (ckt->CKTpreload) {
149  /* preload constants */
150 
151  if (here->SRCposNode) {
152  *(here->SRCposIbrptr) += 1.0;
153  *(here->SRCibrPosptr) += 1.0;
154  }
155  if (here->SRCnegNode) {
156  *(here->SRCnegIbrptr) -= 1.0;
157  *(here->SRCibrNegptr) -= 1.0;
158  }
159  }
160 
161  if (here->SRCccCoeffGiven) {
162  TSTALLOC(SRCibrContBrptr, SRCbranch, SRCcontBranch)
163  here->SRCtranFunc = src_ccvs;
164  here->SRCdcFunc = src_ccvs;
165  continue;
166  }
167  else if (here->SRCvcCoeffGiven) {
168  TSTALLOC(SRCibrContPosptr, SRCbranch, SRCcontPosNode)
169  TSTALLOC(SRCibrContNegptr, SRCbranch, SRCcontNegNode)
170  here->SRCtranFunc = src_vcvs;
171  here->SRCdcFunc = src_vcvs;
172  continue;
173  }
174  }
175  else {
176 
177  if (here->SRCccCoeffGiven) {
178  TSTALLOC(SRCposContBrptr,SRCposNode,SRCcontBranch)
179  TSTALLOC(SRCnegContBrptr,SRCnegNode,SRCcontBranch)
180  here->SRCtranFunc = src_cccs;
181  here->SRCdcFunc = src_cccs;
182  continue;
183  }
184  else if (here->SRCvcCoeffGiven) {
185  TSTALLOC(SRCposContPosptr, SRCposNode, SRCcontPosNode)
186  TSTALLOC(SRCposContNegptr, SRCposNode, SRCcontNegNode)
187  TSTALLOC(SRCnegContPosptr, SRCnegNode, SRCcontPosNode)
188  TSTALLOC(SRCnegContNegptr, SRCnegNode, SRCcontNegNode)
189  here->SRCtranFunc = src_vccs;
190  here->SRCdcFunc = src_vccs;
191  continue;
192  }
193  }
194 
195  if (here->SRCtree == NULL) {
196  here->SRCtranFunc = src_dc;
197  here->SRCdcFunc = src_dc;
198  continue;
199  }
200  if (here->SRCtree->numVars == 0) {
201  here->SRCtranFunc = src_func0;
202  if (here->SRCdcGiven)
203  here->SRCdcFunc = src_dc;
204  else
205  here->SRCdcFunc = src_func0;
206  continue;
207  }
208  here->SRCtranFunc = src_func1;
209  if (here->SRCdcGiven)
210  here->SRCdcFunc = src_dc;
211  else
212  here->SRCdcFunc = src_func1;
213 
214  /* For each controlling variable set the entries
215  * in the vector of the positions of the SMP
216  */
217 
218  j = here->SRCtree->numVars;
219  if (here->SRCtype == SRC_I) j *= 2;
220 
221  here->SRCposptr = (double **)MALLOC(j * sizeof(double *));
222 
223  for (j = 0,i = 0; i < here->SRCtree->numVars; i++) {
224  switch (here->SRCtree->varTypes[i]) {
225 
226  case IF_INSTANCE:
227  here->SRCcontBranch = CKTfndBranch(ckt,
228  here->SRCtree->vars[i].uValue);
229  if (here->SRCcontBranch == 0) {
230  IFuid namarray[2];
231  namarray[0] = here->SRCname;
232  namarray[1] = here->SRCtree->vars[i].uValue;
233  (*(SPfrontEnd->IFerror))(ERR_FATAL,
234  "%s: unknown controlling source %s",namarray);
235  return (E_BADPARM);
236  }
237 
238  if (here->SRCtype == SRC_V) {
239  TSTALLOC(SRCposptr[j++],SRCbranch,SRCcontBranch);
240  }
241  else if (here->SRCtype == SRC_I) {
242  TSTALLOC(SRCposptr[j++],SRCposNode,SRCcontBranch);
243  TSTALLOC(SRCposptr[j++],SRCnegNode,SRCcontBranch);
244  }
245  else {
246  return (E_BADPARM);
247  }
248  here->SRCeqns[i] = here->SRCcontBranch;
249  break;
250 
251  case IF_NODE:
252  if (here->SRCtype == SRC_V) {
253  MY_TSTALLOC(SRCposptr[j++],SRCbranch,
254  here->SRCtree->vars[i].nValue);
255  }
256  else if(here->SRCtype == SRC_I) {
257  MY_TSTALLOC(SRCposptr[j++],SRCposNode,
258  here->SRCtree->vars[i].nValue);
259  MY_TSTALLOC(SRCposptr[j++],SRCnegNode,
260  here->SRCtree->vars[i].nValue);
261  }
262  else{
263  return (E_BADPARM);
264  }
265  here->SRCeqns[i] = ((CKTnode *)(here->SRCtree->vars[i].
266  nValue))->number;
267  break;
268 
269  default:
270  break;
271  }
272  }
273  }
274  }
275  return (OK);
276 }
#define SRC_I
Definition: srcdefs.h:216
struct sSRCinstance * SRCnextInstance
Definition: srcdefs.h:26
#define SRC_V
Definition: srcdefs.h:217
double * SRCvalues
Definition: srcdefs.h:109
double * SRCibrNegptr
Definition: srcdefs.h:173
unsigned SRCccCoeffGiven
Definition: srcdefs.h:187
int * varTypes
Definition: ifsim.h:160
IFuid SRCcontName
Definition: srcdefs.h:74
int * SRCeqns
Definition: srcdefs.h:118
void(* SRCdcFunc)()
Definition: srcdefs.h:61
int SRCnegNode
Definition: srcdefs.h:38
if(TDesc==NULL)
Definition: cd.c:1326
#define ERR_FATAL
Definition: ifsim.h:518
static void src_func1()
static void src_vcvs()
#define M_PI
Definition: spice.h:132
static void src_func0()
IFfrontEnd * SPfrontEnd
Definition: main.c:917
int SRCposNode
Definition: srcdefs.h:35
#define E_BADPARM
Definition: iferrmsg.h:26
double SRCdcValue
Definition: srcdefs.h:77
static void src_dc()
#define IF_INSTANCE
Definition: ifsim.h:112
int SRCstate
Definition: srcdefs.h:32
#define TSTALLOC(ptr, first, second)
Definition: devdefs.h:124
#define OK
Definition: iferrmsg.h:17
unsigned SRCdcGiven
Definition: srcdefs.h:180
double SRCacReal
Definition: srcdefs.h:85
GENERIC * IFuid
Definition: ifsim.h:72
int SRCbranch
Definition: srcdefs.h:47
#define MALLOC(x)
Definition: util.h:9
#define NULL
Definition: spdefs.h:121
SRCinstance * SRCinstances
Definition: srcdefs.h:205
#define E_NOMEM
Definition: iferrmsg.h:27
double cos()
IFnode nValue
Definition: ifsim.h:237
int number
Definition: cktdefs.h:39
double * SRCnegIbrptr
Definition: srcdefs.h:165
#define ERR_WARNING
Definition: ifsim.h:517
double sin()
int SRCcontBranch
Definition: srcdefs.h:50
double * SRCposIbrptr
Definition: srcdefs.h:161
int CKTmkCur()
double ** SRCposptr
Definition: srcdefs.h:53
static char model[32]
Definition: subckt.c:76
unsigned SRCacGiven
Definition: srcdefs.h:181
#define MY_TSTALLOC(ptr, first, second)
Definition: srcset.c:34
double * SRCacValues
Definition: srcdefs.h:106
int numVars
Definition: ifsim.h:159
double * SRCderivs
Definition: srcdefs.h:115
static void src_ccvs()
static void src_cccs()
int CKTfndBranch()
unsigned SRCacMGiven
Definition: srcdefs.h:182
double SRCvalue
Definition: srcdefs.h:112
IFuid SRCname
Definition: srcdefs.h:29
double * SRCibrPosptr
Definition: srcdefs.h:169
static void src_vccs()
int SRCtype
Definition: srcdefs.h:65
#define IF_NODE
Definition: ifsim.h:110
IFparseTree * SRCtree
Definition: srcdefs.h:103
void(* SRCtranFunc)()
Definition: srcdefs.h:60
double SRCacImag
Definition: srcdefs.h:88
union uIFvalue * vars
Definition: ifsim.h:162
struct sSRCmodel * SRCnextModel
Definition: srcdefs.h:202
IFuid uValue
Definition: ifsim.h:236
unsigned SRCacPGiven
Definition: srcdefs.h:183