Jspice3
niconv.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  1993 Stephen R. Whiteley
6 ****************************************************************************/
7 
8 /*
9  * NIconvTest(ckt)
10  * perform the convergence test - returns 1 if any of the
11  * values in the old and new arrays have changed by more
12  * than absTol + relTol*(max(old,new)), otherwise returns 0
13  */
14 
15 #include "spice.h"
16 #include <stdio.h>
17 #include <math.h>
18 #include "cktdefs.h"
19 #include "util.h"
20 #include "cktext.h"
21 #include "niext.h"
22 
23 int
25 
26 CKTcircuit *ckt;
27 {
28  int i; /* generic loop variable */
29  int size; /* size of the matrix */
30  CKTnode *node; /* current matrix entry */
31  double old, aold;
32  double new, anew;
33  double dd, tol;
34 
35  node = ckt->CKTnodes;
36  size = spGetSize(ckt->CKTmatrix,1);
37  for (i = 1; i <= size; i++) {
38 
39  node = node->next;
40 
41  new = *((ckt->CKTrhs) + i);
42  old = *((ckt->CKTrhsOld) + i);
43 
44  if (new > 0)
45  anew = new;
46  else
47  anew = -new;
48 
49  if (old > 0)
50  aold = old;
51  else
52  aold = -old;
53 
54  dd = new - old;
55  if (dd < 0)
56  dd = -dd;
57 
58  if (node->type == 3) {
59  tol = ckt->CKTreltol*MAX(aold,anew) + ckt->CKTvoltTol;
60  if (dd > tol) {
61 #ifdef STEPDEBUG
62  printf(" non-convergence at node %s\n",CKTnodName(ckt,i));
63 #endif /* STEPDEBUG */
64  ckt->CKTtroubleNode = i;
65  return (1);
66  }
67  }
68  else {
69  tol = ckt->CKTreltol*MAX(aold,anew) + ckt->CKTabstol;
70  if (dd > tol) {
71 #ifdef STEPDEBUG
72  printf(" non-convergence at node %s\n",CKTnodName(ckt,i));
73 #endif /* STEPDEBUG */
74  return (1);
75  }
76  }
77  }
78  return (CKTconvTest(ckt));
79 }
#define MAX(a, b)
Definition: spdefs.h:135
int CKTconvTest(CKTcircuit *ckt)
Definition: dcoan.c:177
IFuid CKTnodName()
int type
Definition: cktdefs.h:32
int NIconvTest(CKTcircuit *ckt)
Definition: niconv.c:24
struct sCKTnode * next
Definition: cktdefs.h:43
int spGetSize()