Jspice3
jjacct.c
Go to the documentation of this file.
1 /***************************************************************************
2 JSPICE3 adaptation of Spice3e2 - Copyright (c) Stephen R. Whiteley 1992
3 Author: 1992 Stephen R. Whiteley
4 ****************************************************************************/
5 
6 #include "spice.h"
7 #include <stdio.h>
8 #include "jjdefs.h"
9 #include "sperror.h"
10 #include "util.h"
11 
12 int
13 JJaccept(ckt,inModel)
14 
15 CKTcircuit *ckt;
16 GENmodel *inModel;
17 {
18  JJmodel *model = (JJmodel *)inModel;
19  JJinstance *here;
20  double phi,ag0;
21  double vj,vmax = 0;
22  int pint;
23 
24  ag0 = ckt->CKTag[0];
25 
26  for ( ; model != NULL; model = model->JJnextModel) {
27 
28  if (model->JJictype != 0 && vmax < model->JJvdpbak)
29  vmax = model->JJvdpbak;
30 
31  for (here = model->JJinstances; here != NULL;
32  here = here->JJnextInstance) {
33 
34  vj = *(ckt->CKTstate0 + here->JJvoltage);
35 
36  /* update */
37  *(ckt->CKTstate0 + here->JJdvdt) = here->JJdelVdelT + ag0*vj;
38 
39  /* keep phase > -2*PI and < 2*PI */
40  phi = *(ckt->CKTstate0 + here->JJphase);
41  pint = *(int *)(ckt->CKTstate1 + here->JJphsInt);
42  if (phi > 2*M_PI) {
43  phi -= 2*M_PI;
44  pint++;
45  }
46  else if (phi < -2*M_PI) {
47  phi += 2*M_PI;
48  pint--;
49  }
50  *(ckt->CKTstate0 + here->JJphase) = phi;
51  *(int *)(ckt->CKTstate0 + here->JJphsInt) = pint;
52 
53  /* find max vj for time step */
54  if (model->JJictype != 0 && here->JJcriti > 0) {
55  if (vj < 0)
56  vj = -vj;
57  if (vmax < vj) vmax = vj;
58  }
59 
60  if (here->JJphsNode)
61  *(ckt->CKTrhsOld + here->JJphsNode) = phi + (2*M_PI)*pint;
62  }
63  }
64  /* set next time step */
65  if (ckt->CKTjjPresent) /* not set if jj's have cct=0 */
66  ckt->CKTdelta = JJdphi/vmax;
67  return (OK);
68 }
double phi()
double JJdphi
Definition: options.c:21
#define M_PI
Definition: spice.h:132
int JJphsNode
Definition: jjdefs.h:25
JJinstance * JJinstances
Definition: jjdefs.h:84
#define OK
Definition: iferrmsg.h:17
double JJcriti
Definition: jjdefs.h:39
double JJdelVdelT
Definition: jjdefs.h:36
int JJaccept(CKTcircuit *ckt, GENmodel *inModel)
Definition: jjacct.c:13
#define NULL
Definition: spdefs.h:121
double JJvdpbak
Definition: jjdefs.h:99
static char model[32]
Definition: subckt.c:76
int JJictype
Definition: jjdefs.h:89
struct sJJmodel * JJnextModel
Definition: jjdefs.h:82
struct sJJinstance * JJnextInstance
Definition: jjdefs.h:17