Jspice3
niinit.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 #include "spice.h"
9 #include <stdio.h>
10 #include "cktdefs.h"
11 #include "util.h"
12 #include "sperror.h"
13 #include "niext.h"
14 
15 #define CKALLOC(ptr,size,type) if(( ckt->ptr =\
16  (type *) MALLOC((size)*sizeof(type))) == NULL) return(E_NOMEM);
17 
18 
19 int
20 NIinit(ckt)
21 
22 /*
23  * Initialize the numerical iteration package.
24  */
25 CKTcircuit *ckt;
26 {
27  int error;
28 
30  ckt->CKTmatrix = spCreate(0,1,&error);
31  return (error);
32 }
33 
34 
35 void
36 NIprint(ckt)
37 
38 /*
39  * Print the matrix in human readable form.
40  */
41 CKTcircuit *ckt;
42 {
43 
44  if (ckt->CKTmatrix &&
45  spGetSize(ckt->CKTmatrix,1) > 0)
46  spPrint(ckt->CKTmatrix,0,1,1);
47  else
48  printf("Matrix not found.\n");
49 }
50 
51 
52 int
54 
55 /*
56  * Perform reinitialization necessary for the numerical iteration
57  * package - the matrix has now been fully accessed once, so we know
58  * how big it is, so allocate RHS vector
59  */
60 CKTcircuit *ckt;
61 {
62  int size;
63  int i;
64 
65  size = spGetSize(ckt->CKTmatrix,1);
66  FREE(ckt->CKTrhs);
67  FREE(ckt->CKTrhsOld);
68  FREE(ckt->CKTrhsSpare);
69  FREE(ckt->CKTirhs);
70  FREE(ckt->CKTirhsOld);
71  FREE(ckt->CKTirhsSpare);
72  CKALLOC(CKTrhs,size+1,double);
73  CKALLOC(CKTrhsOld,size+1,double);
74  CKALLOC(CKTrhsSpare,size+1,double);
75  CKALLOC(CKTirhs,size+1,double);
76  CKALLOC(CKTirhsOld,size+1,double);
77  CKALLOC(CKTirhsSpare,size+1,double);
78  for (i = 0; i < 8; i++) {
79  FREE(ckt->CKTsols[i]);
80  CKALLOC(CKTsols[i],size+1,double);
81  }
83  return (0);
84 }
85 
86 
87 void
89 
90 /*
91  * delete the data structures allocated for numeric integration.
92  */
93 CKTcircuit *ckt;
94 {
95  spDestroy(ckt->CKTmatrix);
96  ckt->CKTmatrix = NULL;
97  FREE(ckt->CKTrhs);
98  FREE(ckt->CKTrhsOld);
99  FREE(ckt->CKTrhsSpare);
100  FREE(ckt->CKTirhs);
101  FREE(ckt->CKTirhsOld);
102  FREE(ckt->CKTirhsSpare);
103 }
int NIreinit(CKTcircuit *ckt)
Definition: niinit.c:53
#define NIACSHOULDREORDER
Definition: cktdefs.h:123
void spPrint()
#define NIUNINITIALIZED
Definition: cktdefs.h:122
void NIdestroy(CKTcircuit *ckt)
Definition: niinit.c:88
#define NISHOULDREORDER
Definition: cktdefs.h:120
#define FREE(ptr)
Definition: spdefs.h:436
#define CKALLOC(ptr, size, type)
Definition: niinit.c:15
#define NIPZSHOULDREORDER
Definition: cktdefs.h:127
void NIprint(CKTcircuit *ckt)
Definition: niinit.c:36
#define NULL
Definition: spdefs.h:121
int CKTniState
Definition: cktdefs.h:96
int spGetSize()
char * spCreate()
void spDestroy()
int NIinit(CKTcircuit *ckt)
Definition: niinit.c:20