Jspice3
dioconv.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 #include <stdio.h>
9 #include "spice.h"
10 #include "diodefs.h"
11 #include "const.h"
12 #include "util.h"
13 #include "sperror.h"
14 
15 int
16 DIOconvTest(inModel,ckt)
17 
18 /* Check the devices for convergence
19  */
20 GENmodel *inModel;
21 CKTcircuit *ckt;
22 {
23  DIOmodel *model = (DIOmodel*)inModel;
24  DIOinstance *here;
25  double delvd, vd, cdhat, cd;
26  double tol, A1, A2;
27 
28  /* loop through all the diode models */
29  for ( ; model != NULL; model = model->DIOnextModel) {
30 
31  /* loop through all the instances of the model */
32  for (here = model->DIOinstances; here != NULL;
33  here = here->DIOnextInstance) {
34 
35  /*
36  * initialization
37  */
38 
39  vd = *(ckt->CKTrhsOld + here->DIOposPrimeNode) -
40  *(ckt->CKTrhsOld + here->DIOnegNode);
41 
42  delvd = vd - *(ckt->CKTstate0 + here->DIOvoltage);
43  cd = here->DIOcd;
44  cdhat = cd + here->DIOgd*delvd;
45 
46  /*
47  * check convergence
48  */
49  A1 = FABS(cdhat);
50  A2 = FABS(cd);
51  tol = ckt->CKTreltol*MAX(A1,A2) + ckt->CKTabstol;
52  A1 = cdhat - cd;
53  if (FABS(A1) > tol) {
54  ckt->CKTnoncon++;
55  ckt->CKTtroubleElt = (GENinstance *) here;
56  return (OK);
57  }
58  }
59  }
60  return (OK);
61 }
double DIOgd
Definition: diodefs.h:61
GENinstance * CKTtroubleElt
Definition: cktdefs.h:229
#define MAX(a, b)
Definition: spdefs.h:135
struct sDIOinstance * DIOnextInstance
Definition: diodefs.h:20
double DIOcd
Definition: diodefs.h:60
double CKTreltol
Definition: cktdefs.h:183
double CKTabstol
Definition: cktdefs.h:180
#define OK
Definition: iferrmsg.h:17
double * CKTrhsOld
Definition: cktdefs.h:98
DIOinstance * DIOinstances
Definition: diodefs.h:121
#define NULL
Definition: spdefs.h:121
int DIOposPrimeNode
Definition: diodefs.h:26
struct sDIOmodel * DIOnextModel
Definition: diodefs.h:119
int DIOconvTest(GENmodel *inModel, CKTcircuit *ckt)
Definition: dioconv.c:16
static char model[32]
Definition: subckt.c:76
#define FABS(a)
Definition: util.h:41
int DIOnegNode
Definition: diodefs.h:25
int CKTnoncon
Definition: cktdefs.h:203