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

Go to the source code of this file.

Functions

int INDsetup (SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states)
 

Function Documentation

int INDsetup ( SMPmatrix matrix,
GENmodel inModel,
CKTcircuit ckt,
int *  states 
)

Definition at line 22 of file indsetup.c.

28 {
29  INDmodel *model = (INDmodel*)inModel;
30  INDinstance *here;
31  int error;
32  CKTnode *tmp;
33 
34 #ifdef MUTUAL
35  MUTmodel *mutmodel;
36  int ktype;
37 #endif /* MUTUAL */
38 
39  /* loop through all the inductor models */
40  for ( ; model != NULL; model = model->INDnextModel) {
41 
42 #ifdef MUTUAL
43  /* save the mutual indutor model head, this is redundant if
44  * there is more than one inductor model
45  */
46  mutmodel = (MUTmodel*)(ckt->CKThead[CKTtypelook("mutual")]);
47  model->INDmutModels = (GENmodel*)mutmodel;
48 #endif
49 
50  /* loop through all the instances of the model */
51  for (here = model->INDinstances; here != NULL;
52  here = here->INDnextInstance) {
53 
54  if (here->INDbrEq == 0) {
55  /* SRW -- used to call this ...#internal, changed for
56  * compatability with voltage sources, i.e. i(l1) maps
57  * to l1#branch.
58  */
59  error = CKTmkCur(ckt,&tmp,here->INDname,"branch");
60  if (error)
61  return (error);
62  here->INDbrEq = tmp->number;
63  }
64 
65  TSTALLOC(INDibrIbrptr,INDbrEq,INDbrEq)
66  TSTALLOC(INDposIbrptr,INDposNode,INDbrEq)
67  TSTALLOC(INDnegIbrptr,INDnegNode,INDbrEq)
68  TSTALLOC(INDibrNegptr,INDbrEq,INDnegNode)
69  TSTALLOC(INDibrPosptr,INDbrEq,INDposNode)
70 
71  here->INDflux = *states;
72  *states += 2 ;
73 
74  if (ckt->CKTpreload) {
75  /* preload constants */
76 
77  if (here->INDposNode) {
78  *(here->INDposIbrptr) += 1;
79  *(here->INDibrPosptr) += 1;
80  }
81  if (here->INDnegNode) {
82  *(here->INDnegIbrptr) -= 1;
83  *(here->INDibrNegptr) -= 1;
84  }
85  }
86  }
87  }
88 
89 #ifdef MUTUAL
90 
91  ktype = CKTtypelook("Inductor");
92 
93  /* loop through all the mutual inductor models */
94  for ( ; mutmodel != NULL; mutmodel = mutmodel->MUTnextModel) {
95 
96  MUTinstance *here;
97 
98  /* loop through all the instances of the model */
99  for (here = mutmodel->MUTinstances; here != NULL;
100  here = here->MUTnextInstance) {
101 
102  error =
103  CKTfndDev((GENERIC*)ckt,&ktype,(GENERIC**)&(here->MUTind1),
104  here->MUTindName1, (GENERIC *)NULL,(char *)NULL);
105  if (error && error != E_NODEV && error != E_NOMOD)
106  return (error);
107  if (error) {
108  IFuid namarray[2];
109  namarray[0] = here->MUTname;
110  namarray[1] = here->MUTindName1;
111  (*(SPfrontEnd->IFerror))(ERR_WARNING,
112  "%s: coupling to non-existant inductor %s.",
113  namarray);
114  }
115  error =
116  CKTfndDev((GENERIC*)ckt,&ktype,(GENERIC**)&(here->MUTind2),
117  here->MUTindName2,(GENERIC *)NULL,(char *)NULL);
118  if (error && error != E_NODEV && error != E_NOMOD)
119  return (error);
120  if (error) {
121  IFuid namarray[2];
122  namarray[0] = here->MUTname;
123  namarray[1] = here->MUTindName2;
124  (*(SPfrontEnd->IFerror))(ERR_WARNING,
125  "%s: coupling to non-existant inductor %s.",
126  namarray);
127  }
128 
129  here->MUTfactor = here->MUTcoupling *
130  sqrt(here->MUTind1->INDinduct *
131  here->MUTind2->INDinduct);
132 
133  TSTALLOC(MUTbr1br2,MUTind1->INDbrEq,MUTind2->INDbrEq)
134  TSTALLOC(MUTbr2br1,MUTind2->INDbrEq,MUTind1->INDbrEq)
135  }
136  }
137 #endif /* MUTUAL */
138 
139  return (OK);
140 }
struct sINDmodel * INDnextModel
Definition: inddefs.h:96
struct sINDinstance * INDnextInstance
Definition: inddefs.h:27
int INDposNode
Definition: inddefs.h:36
double * INDibrNegptr
Definition: inddefs.h:72
#define E_NODEV
Definition: iferrmsg.h:22
if(TDesc==NULL)
Definition: cd.c:1326
double * INDibrPosptr
Definition: inddefs.h:75
IFuid MUTindName1
Definition: inddefs.h:171
GENmodel * INDmutModels
Definition: inddefs.h:106
double * INDnegIbrptr
Definition: inddefs.h:69
IFfrontEnd * SPfrontEnd
Definition: main.c:917
int CKTtypelook()
#define INDflux
Definition: inddefs.h:45
struct sMUTmodel * MUTnextModel
Definition: inddefs.h:200
#define TSTALLOC(ptr, first, second)
Definition: devdefs.h:124
struct sMUTinstance * MUTnextInstance
Definition: inddefs.h:159
#define OK
Definition: iferrmsg.h:17
double * INDposIbrptr
Definition: inddefs.h:66
MUTinstance * MUTinstances
Definition: inddefs.h:203
GENERIC * IFuid
Definition: ifsim.h:72
INDinstance * MUTind1
Definition: inddefs.h:177
#define NULL
Definition: spdefs.h:121
IFuid MUTindName2
Definition: inddefs.h:174
#define E_NOMOD
Definition: iferrmsg.h:23
INDinstance * INDinstances
Definition: inddefs.h:99
int number
Definition: cktdefs.h:39
#define ERR_WARNING
Definition: ifsim.h:517
double MUTfactor
Definition: inddefs.h:168
double MUTcoupling
Definition: inddefs.h:165
int INDnegNode
Definition: inddefs.h:39
int CKTmkCur()
static char model[32]
Definition: subckt.c:76
IFuid INDname
Definition: inddefs.h:30
INDinstance * MUTind2
Definition: inddefs.h:180
int CKTfndDev()
IFuid MUTname
Definition: inddefs.h:162
GENmodel * CKThead[MAXNUMDEVS]
Definition: cktdefs.h:64
int INDbrEq
Definition: inddefs.h:42
double INDinduct
Definition: inddefs.h:51
char GENERIC
Definition: ifsim.h:27