Jspice3
niaciter.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  * NIacIter(ckt)
10  *
11  * This subroutine performs the actual numerical iteration.
12  * It uses the sparse matrix stored in the NIstruct by NIinit,
13  * along with the matrix loading program, the load data, the
14  * convergence test function, and the convergence parameters
15  * - return value is non-zero for convergence failure
16  */
17 
18 
19 #include "spice.h"
20 #include <stdio.h>
21 #include "cktdefs.h"
22 #include "util.h"
23 #include "sperror.h"
24 #include "cktext.h"
25 #include "niext.h"
26 
27 
28 int
30 
31 CKTcircuit * ckt;
32 {
33  int error;
34  int ignore;
35  double *temp;
36 
37  for (;;) {
38  ckt->CKTnoncon = 0;
39 
40  error = CKTacLoad(ckt);
41  if (error) return (error);
42 
43  if (ckt->CKTniState & NIACSHOULDREORDER) {
44  spSetComplex(ckt->CKTmatrix);
45  error = spOrderAndFactor(ckt->CKTmatrix,NULL,
46  ckt->CKTpivotRelTol,ckt->CKTpivotAbsTol,1);
47  ckt->CKTniState &= ~NIACSHOULDREORDER;
48  if (error != 0) {
49  /* either singular equations or no memory, in either case,
50  * let caller handle problem
51  */
52  return (error);
53  }
54  }
55  else {
56  spSetComplex(ckt->CKTmatrix);
57  error = spFactor(ckt->CKTmatrix);
58  if (error != 0) {
59  if (error == E_SINGULAR) {
60  /* the problem is that the matrix can't be solved with
61  * the current LU factorization. Maybe if we reload and
62  * try to reorder again it will help...
63  */
64  ckt->CKTniState |= NIACSHOULDREORDER;
65  continue;
66  }
67  return (error); /* can't handle E_BADMATRIX, so let caller */
68  }
69  }
70  break;
71  }
72  spSolve(ckt->CKTmatrix,ckt->CKTrhs,ckt->CKTrhs,
73  ckt->CKTirhs,ckt->CKTirhs);
74 
75  *ckt->CKTrhs = 0;
76  *ckt->CKTrhsSpare = 0;
77  *ckt->CKTrhsOld = 0;
78  *ckt->CKTirhs = 0;
79  *ckt->CKTirhsSpare = 0;
80  *ckt->CKTirhsOld = 0;
81 
82  temp = ckt->CKTirhsOld;
83  ckt->CKTirhsOld = ckt->CKTirhs;
84  ckt->CKTirhs = temp;
85 
86  temp = ckt->CKTrhsOld;
87  ckt->CKTrhsOld = ckt->CKTrhs;
88  ckt->CKTrhs = temp;
89 
90  return (OK);
91 }
#define NIACSHOULDREORDER
Definition: cktdefs.h:123
int NIacIter(CKTcircuit *ckt)
Definition: niaciter.c:29
#define OK
Definition: iferrmsg.h:17
#define NULL
Definition: spdefs.h:121
int CKTacLoad()
int spFactor()
void spSetComplex()
int spOrderAndFactor()
#define E_SINGULAR
Definition: sperror.h:17
int CKTnoncon
Definition: cktdefs.h:203
void spSolve()