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

Go to the source code of this file.

Functions

int SRCacLoad (GENmodel *inModel, CKTcircuit *ckt)
 

Function Documentation

int SRCacLoad ( GENmodel inModel,
CKTcircuit ckt 
)

Definition at line 17 of file srcacld.c.

21 {
22 
23  /*
24  * Actually load the current voltage value into the
25  * sparse matrix previously provided. The values have
26  * been precomputed and stored with the instance model.
27  */
28 
29  SRCmodel *model = (SRCmodel*)inModel;
30  SRCinstance *here;
31  int i, j;
32  double *derivs;
33  double rhs;
34 
35  /* loop through all the Arbitrary source models */
36  for ( ; model != NULL; model = model->SRCnextModel ) {
37 
38  /* loop through all the instances of the model */
39  for (here = model->SRCinstances; here != NULL;
40  here = here->SRCnextInstance) {
41 
42  /* If SRCtree:
43  * Get the function and its derivatives from the
44  * field in the instance structure. The field is
45  * an array of doubles holding the rhs, and the
46  * entries of the jacobian.
47  */
48 
49  if (here->SRCtype == SRC_V) {
50 
51  if (here->SRCposNode) {
52  *(here->SRCposIbrptr) += 1.0;
53  *(here->SRCibrPosptr) += 1.0;
54  }
55  if (here->SRCnegNode) {
56  *(here->SRCnegIbrptr) -= 1.0;
57  *(here->SRCibrNegptr) -= 1.0;
58  }
59 
60  if (here->SRCacGiven) {
61  *(ckt->CKTrhs + (here->SRCbranch)) += here->SRCacReal;
62  *(ckt->CKTirhs + (here->SRCbranch)) += here->SRCacImag;
63  }
64  else if (here->SRCccCoeffGiven) {
65  *(here->SRCibrContBrptr) += here->SRCcoeff;
66  }
67  if (here->SRCvcCoeffGiven) {
68  *(here->SRCibrContPosptr) -= here->SRCcoeff;
69  *(here->SRCibrContNegptr) += here->SRCcoeff;
70  }
71  else if (here->SRCtree) {
72  derivs = here->SRCacValues;
73  rhs = (here->SRCacValues)[here->SRCtree->numVars];
74  for (i = 0; i < here->SRCtree->numVars; i++) {
75  *(here->SRCposptr[i]) -= derivs[i];
76  }
77  *(ckt->CKTrhs+(here->SRCbranch)) += rhs;
78  }
79  }
80  else {
81 
82  if (here->SRCacGiven) {
83  *(ckt->CKTrhs + (here->SRCposNode)) +=
84  here->SRCacReal;
85  *(ckt->CKTrhs + (here->SRCnegNode)) -=
86  here->SRCacReal;
87  *(ckt->CKTirhs + (here->SRCposNode)) +=
88  here->SRCacImag;
89  *(ckt->CKTirhs + (here->SRCnegNode)) -=
90  here->SRCacImag;
91  }
92  else if (here->SRCccCoeffGiven) {
93  *(here->SRCposContBrptr) += here->SRCcoeff;
94  *(here->SRCnegContBrptr) -= here->SRCcoeff;
95  }
96  else if (here->SRCvcCoeffGiven) {
97  *(here->SRCposContPosptr) += here->SRCcoeff;
98  *(here->SRCposContNegptr) -= here->SRCcoeff;
99  *(here->SRCnegContPosptr) -= here->SRCcoeff;
100  *(here->SRCnegContNegptr) += here->SRCcoeff;
101  }
102  else if (here->SRCtree) {
103  derivs = here->SRCacValues;
104  rhs = (here->SRCacValues)[here->SRCtree->numVars];
105  for (j = 0,i = 0; i < here->SRCtree->numVars; i++) {
106  *(here->SRCposptr[j++]) += derivs[i];
107  *(here->SRCposptr[j++]) -= derivs[i];
108  }
109  *(ckt->CKTrhs+(here->SRCposNode)) -= rhs;
110  *(ckt->CKTrhs+(here->SRCnegNode)) += rhs;
111  }
112  }
113  }
114  }
115  return (OK);
116 }
struct sSRCinstance * SRCnextInstance
Definition: srcdefs.h:26
double * SRCibrContBrptr
Definition: srcdefs.h:157
#define SRC_V
Definition: srcdefs.h:217
double * SRCibrNegptr
Definition: srcdefs.h:173
unsigned SRCccCoeffGiven
Definition: srcdefs.h:187
double * CKTirhs
Definition: cktdefs.h:100
double SRCcoeff
Definition: srcdefs.h:71
int SRCnegNode
Definition: srcdefs.h:38
int SRCposNode
Definition: srcdefs.h:35
double * SRCnegContBrptr
Definition: srcdefs.h:145
double * SRCibrContPosptr
Definition: srcdefs.h:149
#define OK
Definition: iferrmsg.h:17
double SRCacReal
Definition: srcdefs.h:85
int SRCbranch
Definition: srcdefs.h:47
#define NULL
Definition: spdefs.h:121
SRCinstance * SRCinstances
Definition: srcdefs.h:205
double * SRCposContPosptr
Definition: srcdefs.h:125
double * SRCnegIbrptr
Definition: srcdefs.h:165
unsigned SRCvcCoeffGiven
Definition: srcdefs.h:188
double * SRCposContNegptr
Definition: srcdefs.h:129
double * SRCposIbrptr
Definition: srcdefs.h:161
double ** SRCposptr
Definition: srcdefs.h:53
static char model[32]
Definition: subckt.c:76
unsigned SRCacGiven
Definition: srcdefs.h:181
double * SRCacValues
Definition: srcdefs.h:106
int numVars
Definition: ifsim.h:159
double * SRCibrContNegptr
Definition: srcdefs.h:153
double * SRCnegContNegptr
Definition: srcdefs.h:137
double * SRCposContBrptr
Definition: srcdefs.h:141
double * SRCibrPosptr
Definition: srcdefs.h:169
int SRCtype
Definition: srcdefs.h:65
IFparseTree * SRCtree
Definition: srcdefs.h:103
double SRCacImag
Definition: srcdefs.h:88
double * CKTrhs
Definition: cktdefs.h:97
double * SRCnegContPosptr
Definition: srcdefs.h:133
struct sSRCmodel * SRCnextModel
Definition: srcdefs.h:202