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

Go to the source code of this file.

Functions

int TRAload (GENmodel *inModel, CKTcircuit *ckt)
 

Function Documentation

int TRAload ( GENmodel inModel,
CKTcircuit ckt 
)

Definition at line 15 of file traload.c.

22 {
23  TRAmodel *model = (TRAmodel *)inModel;
24  TRAinstance *here;
25  double t1,t2,t3;
26  double f1,f2,f3;
27  register int i;
28 
29  /* loop through all the transmission line models */
30  for( ; model != NULL; model = model->TRAnextModel ) {
31 
32  /* loop through all the instances of the model */
33  for (here = model->TRAinstances; here != NULL ;
34  here=here->TRAnextInstance) {
35 
36  *(here->TRApos1Pos1Ptr) += here->TRAconduct;
37  *(here->TRApos1Int1Ptr) -= here->TRAconduct;
38  *(here->TRAneg1Ibr1Ptr) -= 1;
39  *(here->TRApos2Pos2Ptr) += here->TRAconduct;
40  *(here->TRAneg2Ibr2Ptr) -= 1;
41  *(here->TRAint1Pos1Ptr) -= here->TRAconduct;
42  *(here->TRAint1Int1Ptr) += here->TRAconduct;
43  *(here->TRAint1Ibr1Ptr) += 1;
44  *(here->TRAint2Int2Ptr) += here->TRAconduct;
45  *(here->TRAint2Ibr2Ptr) += 1;
46  *(here->TRAibr1Neg1Ptr) -= 1;
47  *(here->TRAibr1Int1Ptr) += 1;
48  *(here->TRAibr2Neg2Ptr) -= 1;
49  *(here->TRAibr2Int2Ptr) += 1;
50  *(here->TRApos2Int2Ptr) -= here->TRAconduct;
51  *(here->TRAint2Pos2Ptr) -= here->TRAconduct;
52 
53  if(ckt->CKTmode & MODEDC) {
54  *(here->TRAibr1Pos2Ptr) -= 1;
55  *(here->TRAibr1Neg2Ptr) += 1;
56  *(here->TRAibr1Ibr2Ptr) -= (1-ckt->CKTgmin)*here->TRAimped;
57  *(here->TRAibr2Pos1Ptr) -= 1;
58  *(here->TRAibr2Neg1Ptr) += 1;
59  *(here->TRAibr2Ibr1Ptr) -= (1-ckt->CKTgmin)*here->TRAimped;
60  } else {
61  if (ckt->CKTmode & MODEINITTRAN) {
62  if(ckt->CKTmode & MODEUIC) {
63  here->TRAinput1 = here->TRAinitVolt2 + here->TRAinitCur2
64  * here->TRAimped;
65  here->TRAinput2 = here->TRAinitVolt1 + here->TRAinitCur1
66  * here->TRAimped;
67  } else {
68  here->TRAinput1 =
69  ( *(ckt->CKTrhsOld+here->TRAposNode2)
70  - *(ckt->CKTrhsOld+here->TRAnegNode2) )
71  + ( *(ckt->CKTrhsOld+here->TRAbrEq2)
72  *here->TRAimped);
73  here->TRAinput2 =
74  ( *(ckt->CKTrhsOld+here->TRAposNode1)
75  - *(ckt->CKTrhsOld+here->TRAnegNode1) )
76  + ( *(ckt->CKTrhsOld+here->TRAbrEq1)
77  *here->TRAimped);
78  }
79  *(here->TRAdelays ) = -2*here->TRAtd;
80  *(here->TRAdelays +3) = -here->TRAtd;
81  *(here->TRAdelays+6) = 0;
82  *(here->TRAdelays+1) = *(here->TRAdelays +4) =
83  *(here->TRAdelays+7) = here->TRAinput1;
84  *(here->TRAdelays+2) = *(here->TRAdelays +5) =
85  *(here->TRAdelays+8) = here->TRAinput2;
86  here->TRAsizeDelay = 2;
87  } else {
88  if(ckt->CKTmode & MODEINITPRED) {
89  for(i=2;(i<here->TRAsizeDelay) &&
90  (*(here->TRAdelays +3*i) <=
91  (ckt->CKTtime-here->TRAtd));i++) {;/*loop does it*/}
92  t1 = *(here->TRAdelays + (3*(i-2)));
93  t2 = *(here->TRAdelays + (3*(i-1)));
94  t3 = *(here->TRAdelays + (3*(i )));
95  if( (t2-t1)==0 || (t3-t2) == 0) continue;
96  f1 = (ckt->CKTtime - here->TRAtd - t2) *
97  (ckt->CKTtime - here->TRAtd - t3) ;
98  f2 = (ckt->CKTtime - here->TRAtd - t1) *
99  (ckt->CKTtime - here->TRAtd - t3) ;
100  f3 = (ckt->CKTtime - here->TRAtd - t1) *
101  (ckt->CKTtime - here->TRAtd - t2) ;
102  if((t2-t1)==0) { /* should never happen, but don't want
103  * to divide by zero, EVER... */
104  f1=0;
105  f2=0;
106  } else {
107  f1 /= (t1-t2);
108  f2 /= (t2-t1);
109  }
110  if((t3-t2)==0) { /* should never happen, but don't want
111  * to divide by zero, EVER... */
112  f2=0;
113  f3=0;
114  } else {
115  f2 /= (t2-t3);
116  f3 /= (t2-t3);
117  }
118  if((t3-t1)==0) { /* should never happen, but don't want
119  * to divide by zero, EVER... */
120  f1=0;
121  f2=0;
122  } else {
123  f1 /= (t1-t3);
124  f3 /= (t1-t3);
125  }
126  /*printf("at time %g, using %g, %g, %g\n",ckt->CKTtime,
127  t1,t2,t3);
128  printf("values %g, %g, %g \n",
129  *(here->TRAdelays + (3*(i-2))+1),
130  *(here->TRAdelays + (3*(i-1))+1),
131  *(here->TRAdelays + (3*(i ))+1) );
132  printf("and %g, %g, %g \n",
133  *(here->TRAdelays + (3*(i-2))+2),
134  *(here->TRAdelays + (3*(i-1))+2),
135  *(here->TRAdelays + (3*(i ))+2) );*/
136  here->TRAinput1 = f1 * *(here->TRAdelays + (3*(i-2))+1)
137  + f2 * *(here->TRAdelays + (3*(i-1))+1)
138  + f3 * *(here->TRAdelays + (3*(i ))+1);
139  here->TRAinput2 = f1 * *(here->TRAdelays + (3*(i-2))+2)
140  + f2 * *(here->TRAdelays + (3*(i-1))+2)
141  + f3 * *(here->TRAdelays + (3*(i ))+2);
142  }
143  }
144  *(ckt->CKTrhs + here->TRAbrEq1) += here->TRAinput1;
145  *(ckt->CKTrhs + here->TRAbrEq2) += here->TRAinput2;
146  }
147  }
148  }
149  return(OK);
150 }
double * TRAibr1Neg1Ptr
Definition: tradefs.h:50
double CKTtime
Definition: cktdefs.h:77
struct sTRAinstance * TRAnextInstance
Definition: tradefs.h:20
TRAinstance * TRAinstances
Definition: tradefs.h:89
double * TRAint1Pos1Ptr
Definition: tradefs.h:60
double TRAinitVolt2
Definition: tradefs.h:39
int TRAbrEq1
Definition: tradefs.h:46
struct sTRAmodel * TRAnextModel
Definition: tradefs.h:87
#define MODEINITPRED
Definition: cktdefs.h:161
#define MODEDC
Definition: cktdefs.h:149
double TRAimped
Definition: tradefs.h:30
double TRAinitCur1
Definition: tradefs.h:38
#define MODEINITTRAN
Definition: cktdefs.h:160
double * TRApos2Pos2Ptr
Definition: tradefs.h:69
double TRAtd
Definition: tradefs.h:32
int TRAsizeDelay
Definition: tradefs.h:44
double * TRApos1Pos1Ptr
Definition: tradefs.h:67
int TRAnegNode1
Definition: tradefs.h:25
double * TRAint2Pos2Ptr
Definition: tradefs.h:63
int TRAposNode1
Definition: tradefs.h:24
double * TRAint1Int1Ptr
Definition: tradefs.h:59
#define OK
Definition: iferrmsg.h:17
double * TRAibr2Ibr1Ptr
Definition: tradefs.h:53
double * TRAibr2Neg2Ptr
Definition: tradefs.h:56
double * CKTrhsOld
Definition: cktdefs.h:98
int TRAnegNode2
Definition: tradefs.h:27
double TRAinitVolt1
Definition: tradefs.h:37
double * TRAibr1Pos2Ptr
Definition: tradefs.h:52
#define NULL
Definition: spdefs.h:121
double * TRAibr2Pos1Ptr
Definition: tradefs.h:57
double * TRAibr1Ibr2Ptr
Definition: tradefs.h:48
double TRAinput2
Definition: tradefs.h:36
double * TRAibr1Int1Ptr
Definition: tradefs.h:49
double * TRAibr2Neg1Ptr
Definition: tradefs.h:55
static char model[32]
Definition: subckt.c:76
double * TRAneg1Ibr1Ptr
Definition: tradefs.h:64
double TRAconduct
Definition: tradefs.h:31
double TRAinitCur2
Definition: tradefs.h:40
double TRAinput1
Definition: tradefs.h:35
double * TRAibr1Neg2Ptr
Definition: tradefs.h:51
double * TRAint2Ibr2Ptr
Definition: tradefs.h:61
double CKTgmin
Definition: cktdefs.h:190
double * TRApos1Int1Ptr
Definition: tradefs.h:66
double * TRAint2Int2Ptr
Definition: tradefs.h:62
double * TRAint1Ibr1Ptr
Definition: tradefs.h:58
double * TRAneg2Ibr2Ptr
Definition: tradefs.h:65
double * TRApos2Int2Ptr
Definition: tradefs.h:68
double * TRAdelays
Definition: tradefs.h:43
int TRAbrEq2
Definition: tradefs.h:47
long CKTmode
Definition: cktdefs.h:139
int TRAposNode2
Definition: tradefs.h:26
double * CKTrhs
Definition: cktdefs.h:97
#define MODEUIC
Definition: cktdefs.h:166
double * TRAibr2Int2Ptr
Definition: tradefs.h:54