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

Go to the source code of this file.

Functions

int DIOconvTest (GENmodel *inModel, CKTcircuit *ckt)
 

Function Documentation

int DIOconvTest ( GENmodel inModel,
CKTcircuit ckt 
)

Definition at line 16 of file dioconv.c.

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
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