1 /* basics.c */
2
3 #include "../ILUMtx.h"
4
5 #define MYDEBUG 0
6
7 /*--------------------------------------------------------------------*/
8 /*
9 -----------------------
10 simplest constructor
11
12 created -- 98oct03, cca
13 -----------------------
14 */
15 ILUMtx *
ILUMtx_new(void)16 ILUMtx_new (
17 void
18 ) {
19 ILUMtx *mtx ;
20
21 ALLOCATE(mtx, struct _ILUMtx, 1) ;
22 ILUMtx_setDefaultFields(mtx) ;
23
24 return(mtx) ; }
25
26 /*--------------------------------------------------------------------*/
27 /*
28 -----------------------
29 set the default fields
30
31 return code --
32 1 -- normal return
33 -1 -- mtx is NULL
34
35 created -- 98oct03, cca
36 -----------------------
37 */
38 int
ILUMtx_setDefaultFields(ILUMtx * mtx)39 ILUMtx_setDefaultFields (
40 ILUMtx *mtx
41 ) {
42 if ( mtx == NULL ) {
43 fprintf(stderr, "\n fatal error in ILUMtx_setDefaultFields(%p)"
44 "\n bad input", mtx) ;
45 return(-1) ;
46 }
47 mtx->neqns = 0 ;
48 mtx->type = SPOOLES_REAL ;
49 mtx->symmetryflag = SPOOLES_SYMMETRIC ;
50 mtx->UstorageMode = SPOOLES_BY_ROWS ;
51 mtx->LstorageMode = SPOOLES_BY_COLUMNS ;
52 mtx->sizesL = NULL ;
53 mtx->sizesU = NULL ;
54 mtx->p_indL = NULL ;
55 mtx->p_indU = NULL ;
56 mtx->entD = NULL ;
57 mtx->p_entU = NULL ;
58 mtx->p_entU = NULL ;
59
60 return(1) ; }
61
62 /*--------------------------------------------------------------------*/
63 /*
64 --------------------------------------------------
65 clear the data fields, releasing allocated storage
66
67 return code --
68 1 -- normal return
69 -1 -- mtx is NULL
70
71 created -- 98oct03, cca
72 --------------------------------------------------
73 */
74 int
ILUMtx_clearData(ILUMtx * mtx)75 ILUMtx_clearData (
76 ILUMtx *mtx
77 ) {
78 int ieqn, neqns ;
79 /*
80 ---------------
81 check the input
82 ---------------
83 */
84 if ( mtx == NULL ) {
85 fprintf(stderr, "\n fatal error in ILUMtx_clearData(%p)"
86 "\n bad input\n", mtx) ;
87 return(-1) ;
88 }
89 if ( (neqns = mtx->neqns) < 0 ) {
90 return(1) ;
91 }
92 if ( mtx->entD != NULL ) {
93 DVfree(mtx->entD) ;
94 }
95 IVfree(mtx->sizesU) ;
96 for ( ieqn = 0 ; ieqn < neqns ; ieqn++ ) {
97 if ( mtx->p_indU[ieqn] != NULL ) {
98 IVfree(mtx->p_indU[ieqn]) ;
99 }
100 if ( mtx->p_entU[ieqn] != NULL ) {
101 DVfree(mtx->p_entU[ieqn]) ;
102 }
103 }
104 PIVfree(mtx->p_indU) ;
105 PDVfree(mtx->p_entU) ;
106 if ( mtx->symmetryflag == SPOOLES_NONSYMMETRIC ) {
107 IVfree(mtx->sizesL) ;
108 for ( ieqn = 0 ; ieqn < neqns ; ieqn++ ) {
109 if ( mtx->p_indL[ieqn] != NULL ) {
110 IVfree(mtx->p_indL[ieqn]) ;
111 }
112 if ( mtx->p_entL[ieqn] != NULL ) {
113 DVfree(mtx->p_entL[ieqn]) ;
114 }
115 }
116 PIVfree(mtx->p_indL) ;
117 PDVfree(mtx->p_entL) ;
118 }
119 /*
120 ----------------------
121 set the default fields
122 ----------------------
123 */
124 ILUMtx_setDefaultFields(mtx) ;
125
126 return(-1) ; }
127
128 /*--------------------------------------------------------------------*/
129 /*
130 ------------------------------------------
131 destructor, free's the object and its data
132
133 return code --
134 1 -- normal return
135 -1 -- mtx is NULL
136
137 created -- 98oct03, cca
138 ------------------------------------------
139 */
140 int
ILUMtx_free(ILUMtx * mtx)141 ILUMtx_free (
142 ILUMtx *mtx
143 ) {
144 if ( mtx == NULL ) {
145 fprintf(stderr, "\n fatal error in ILUMtx_free(%p)"
146 "\n bad input\n", mtx) ;
147 return(-1) ;
148 }
149 ILUMtx_clearData(mtx) ;
150 FREE(mtx) ;
151
152 return(1) ; }
153
154 /*--------------------------------------------------------------------*/
155