Jspice3
indload.c
Go to the documentation of this file.
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  1992 Stephen R. Whiteley
6 ****************************************************************************/
7 
8 /* actually load the current inductance value into the
9  * sparse matrix previously provided
10  */
11 
12 #include "spice.h"
13 #include <stdio.h>
14 #include <math.h>
15 #include "inddefs.h"
16 #include "util.h"
17 #include "sperror.h"
18 #include "niext.h"
19 
20 
21 int
22 INDload(inModel,ckt)
23 
24 GENmodel *inModel;
25 CKTcircuit *ckt;
26 {
27  INDmodel *model = (INDmodel*)inModel;
28  INDinstance *here;
29  double factor;
30  int error;
31 #ifdef MUTUAL
32  MUTinstance *muthere;
33  MUTmodel *mutmodel;
34 #endif
35 
36  if (ckt->CKTmode & MODEDC)
37  return (OK);
38 
39  if (ckt->CKTmode & MODEINITFLOAT) {
40 
41 #ifdef MUTUAL
42  mutmodel = (MUTmodel *)model->INDmutModels;
43 
44  /* loop through all the mutual inductor models */
45  for ( ; mutmodel != NULL; mutmodel = mutmodel->MUTnextModel) {
46 
47  /* loop through all the instances of the model */
48  for (muthere = mutmodel->MUTinstances; muthere != NULL;
49  muthere = muthere->MUTnextInstance) {
50 
51  factor = muthere->MUTfactor;
52  *(ckt->CKTstate0 + muthere->MUTind1->INDflux) +=
53  factor * *(ckt->CKTrhsOld +
54  muthere->MUTind2->INDbrEq);
55 
56  *(ckt->CKTstate0 + muthere->MUTind2->INDflux) +=
57  factor * *(ckt->CKTrhsOld +
58  muthere->MUTind1->INDbrEq);
59 
60  factor *= ckt->CKTag[0];
61  *(muthere->MUTbr1br2) -= factor;
62  *(muthere->MUTbr2br1) -= factor;
63  }
64  }
65 #endif
66  /* loop through all the inductor models */
67  for ( ; model != NULL; model = model->INDnextModel) {
68 
69  /* loop through all the instances of the model */
70  for (here = model->INDinstances; here != NULL;
71  here = here->INDnextInstance) {
72 
73  *(ckt->CKTstate0 + here->INDflux) +=
74  here->INDinduct * *(ckt->CKTrhsOld + here->INDbrEq) -
75  here->INDprevFlux;
76 
77  here->INDprevFlux = *(ckt->CKTstate0 + here->INDflux);
78 
79  *(ckt->CKTstate0 + here->INDvolt) =
80  ckt->CKTag[0] * *(ckt->CKTstate0 + here->INDflux) +
81  here->INDveq;
82 
83  *(ckt->CKTrhs + here->INDbrEq) += here->INDveq;
84  *(here->INDibrIbrptr) -= here->INDreq;
85  }
86  }
87  return (OK);
88  }
89 
90  if (ckt->CKTmode & MODEINITPRED) {
91 
92 #ifdef MUTUAL
93  mutmodel = (MUTmodel *)model->INDmutModels;
94 
95  /* loop through all the mutual inductor models */
96  for ( ; mutmodel != NULL; mutmodel = mutmodel->MUTnextModel) {
97 
98  /* loop through all the instances of the model */
99  for (muthere = mutmodel->MUTinstances; muthere != NULL;
100  muthere = muthere->MUTnextInstance) {
101 
102  factor = muthere->MUTfactor*ckt->CKTag[0];
103  *(muthere->MUTbr1br2) -= factor;
104  *(muthere->MUTbr2br1) -= factor;
105  }
106  }
107 #endif /* MUTUAL */
108 
109  /* loop through all the inductor models */
110  for ( ; model != NULL; model = model->INDnextModel) {
111 
112  /* loop through all the instances of the model */
113  for (here = model->INDinstances; here != NULL;
114  here = here->INDnextInstance) {
115 
116  here->INDreq = ckt->CKTag[0] * here->INDinduct;
117 
118  NI_SUM(ckt,here->INDveq,here->INDflux);
119 
120  *(ckt->CKTrhs + here->INDbrEq) += here->INDveq;
121  *(here->INDibrIbrptr) -= here->INDreq;
122 
123  here->INDprevFlux = 0;
124  *(ckt->CKTstate0 + here->INDflux) = 0;
125  }
126  }
127  return (OK);
128  }
129 
130  if (ckt->CKTmode & MODEINITTRAN) {
131 
132 #ifdef MUTUAL
133  mutmodel = (MUTmodel *)model->INDmutModels;
134 
135  /* loop through all the mutual inductor models */
136  for ( ; mutmodel != NULL; mutmodel = mutmodel->MUTnextModel) {
137 
138  /* loop through all the instances of the model */
139  for (muthere = mutmodel->MUTinstances; muthere != NULL;
140  muthere = muthere->MUTnextInstance) {
141 
142  factor = muthere->MUTfactor;
143  if (ckt->CKTmode & MODEUIC) {
144 
145  *(ckt->CKTstate1 + muthere->MUTind1->INDflux) +=
146  factor * muthere->MUTind2->INDinitCond;
147 
148  *(ckt->CKTstate1 + muthere->MUTind2->INDflux) +=
149  factor * muthere->MUTind1->INDinitCond;
150  }
151  else {
152  *(ckt->CKTstate1 + muthere->MUTind1->INDflux) +=
153  factor * *(ckt->CKTrhsOld +
154  muthere->MUTind2->INDbrEq);
155 
156  *(ckt->CKTstate1 + muthere->MUTind2->INDflux) +=
157  factor * *(ckt->CKTrhsOld +
158  muthere->MUTind1->INDbrEq);
159  }
160  factor *= ckt->CKTag[0];
161  *(muthere->MUTbr1br2) -= factor;
162  *(muthere->MUTbr2br1) -= factor;
163  }
164  }
165 #endif /* MUTUAL */
166 
167  /* loop through all the inductor models */
168  for ( ; model != NULL; model = model->INDnextModel) {
169 
170  /* loop through all the instances of the model */
171  for (here = model->INDinstances; here != NULL;
172  here = here->INDnextInstance) {
173 
174  if (ckt->CKTmode & MODEUIC) {
175  *(ckt->CKTstate1 + here->INDflux) += here->INDinduct *
176  here->INDinitCond;
177  }
178  else {
179  *(ckt->CKTstate1 + here->INDflux) += here->INDinduct *
180  *(ckt->CKTrhsOld + here->INDbrEq);
181  }
182  here->INDprevFlux = 0;
183  *(ckt->CKTstate0 + here->INDflux) = 0;
184 
185  here->INDreq = ckt->CKTag[0] * here->INDinduct;
186 
187  NI_SUM(ckt,here->INDveq,here->INDflux);
188 
189  *(ckt->CKTrhs + here->INDbrEq) += here->INDveq;
190  *(here->INDibrIbrptr) -= here->INDreq;
191  }
192  }
193  }
194  return (OK);
195 }
struct sINDmodel * INDnextModel
Definition: inddefs.h:96
struct sINDinstance * INDnextInstance
Definition: inddefs.h:27
#define MODEINITPRED
Definition: cktdefs.h:161
#define MODEDC
Definition: cktdefs.h:149
#define MODEINITFLOAT
Definition: cktdefs.h:156
#define MODEINITTRAN
Definition: cktdefs.h:160
GENmodel * INDmutModels
Definition: inddefs.h:106
#define NI_SUM(ckt, ceq, qcap)
Definition: devdefs.h:130
int INDload(GENmodel *inModel, CKTcircuit *ckt)
Definition: indload.c:22
struct sMUTmodel * MUTnextModel
Definition: inddefs.h:200
struct sMUTinstance * MUTnextInstance
Definition: inddefs.h:159
#define OK
Definition: iferrmsg.h:17
double * CKTrhsOld
Definition: cktdefs.h:98
double * MUTbr1br2
Definition: inddefs.h:182
MUTinstance * MUTinstances
Definition: inddefs.h:203
double INDveq
Definition: inddefs.h:57
INDinstance * MUTind1
Definition: inddefs.h:177
#define NULL
Definition: spdefs.h:121
INDinstance * INDinstances
Definition: inddefs.h:99
double * INDibrIbrptr
Definition: inddefs.h:78
double CKTag[7]
Definition: cktdefs.h:83
double MUTfactor
Definition: inddefs.h:168
double INDreq
Definition: inddefs.h:60
static char model[32]
Definition: subckt.c:76
INDinstance * MUTind2
Definition: inddefs.h:180
double INDprevFlux
Definition: inddefs.h:63
double * MUTbr2br1
Definition: inddefs.h:183
double INDinitCond
Definition: inddefs.h:54
int INDbrEq
Definition: inddefs.h:42
long CKTmode
Definition: cktdefs.h:139
double INDinduct
Definition: inddefs.h:51
double * CKTrhs
Definition: cktdefs.h:97
#define MODEUIC
Definition: cktdefs.h:166