/[escript]/trunk/esys2/finley/src/finleyC/System.c
ViewVC logotype

Contents of /trunk/esys2/finley/src/finleyC/System.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 97 - (show annotations)
Tue Dec 14 05:39:33 2004 UTC (15 years, 1 month ago) by jgs
File MIME type: text/plain
File size: 5449 byte(s)
*** empty log message ***

1 /* $Id$ */
2
3 /**************************************************************/
4
5 /* Finley: SystemMatrix */
6
7 /**************************************************************/
8
9 /* Copyrights by ACcESS Australia 2003, 2004 */
10 /* Author: gross@access.edu.au */
11
12 /**************************************************************/
13
14 #include "Finley.h"
15 #include "System.h"
16
17 /**************************************************************/
18
19 /* allocates a SystemMatrix of type type using the given matrix pattern
20 if type is UNKOWN CSR is used.
21 if CSC or CSC_BLK1 is used pattern has to give the CSC pattern.
22 if CSR or CSR_BLK1 is used pattern has to give the CSR pattern.
23 Values are initialized by zero. */
24
25 Finley_SystemMatrix* Finley_SystemMatrix_alloc(Finley_SystemMatrixType type,Finley_SystemMatrixPattern *pattern, int row_block_size, int col_block_size) {
26 double time0;
27 Finley_SystemMatrix*out=NULL;
28 double *val=NULL;
29 Finley_SystemMatrixType out_type;
30 Finley_ErrorCode=NO_ERROR;
31
32 /* check the matrix type */
33 switch(type) {
34 case CSC:
35 out_type=CSC;
36 break;
37 case CSR:
38 out_type=CSR;
39 break;
40 case CSC_BLK1:
41 out_type=CSC;
42 if (row_block_size!=1 || col_block_size!=1) {
43 Finley_ErrorCode=TYPE_ERROR;
44 sprintf(Finley_ErrorMsg,"convertion of matrix pattern for block size one for logical block size > 1 is not implemented yet");
45 return NULL;
46 }
47 break;
48 case CSR_BLK1:
49 out_type=CSR;
50 if (row_block_size!=1 || col_block_size!=1) {
51 Finley_ErrorCode=TYPE_ERROR;
52 sprintf(Finley_ErrorMsg,"convertion of matrix pattern for block size one for logical block size > 1 is not implemented yet");
53 return NULL;
54 }
55 break;
56 case CSC_SYM:
57 case CSC_BLK1_SYM:
58 out_type=CSC_SYM;
59 Finley_ErrorCode=TYPE_ERROR;
60 sprintf(Finley_ErrorMsg,"convertion of matrix pattern for symmetric CSC is not implemented yet.");
61 return NULL;
62 default:
63 Finley_ErrorCode=TYPE_ERROR;
64 sprintf(Finley_ErrorMsg,"unknown matrix type identifier %d.",type);
65 return NULL;
66 }
67 time0=Finley_timer();
68 /* allocate the return value */
69
70 out=MEMALLOC(1,Finley_SystemMatrix);
71 if (! Finley_checkPtr(out)) {
72
73 /* is block size 1 enforced ? */
74 if (type==CSC_BLK1 || type==CSR_BLK1 || type==CSR_BLK1_SYM || type==CSC_BLK1_SYM) {
75 out->row_block_size=1;
76 out->col_block_size=1;
77 } else {
78 out->row_block_size=row_block_size;
79 out->col_block_size=col_block_size;
80 }
81 if (out_type==CSC || type==CSC_BLK1 || type==CSC_SYM || type==CSC_BLK1_SYM ) {
82 out->num_cols=pattern->n_index;
83 out->num_rows=pattern->n_ptr;
84 } else {
85 out->num_rows=pattern->n_index;
86 out->num_cols=pattern->n_ptr;
87 }
88
89 out->type=out_type;
90 out->logical_row_block_size=row_block_size;
91 out->logical_col_block_size=col_block_size;
92 out->logical_block_size=out->logical_row_block_size*out->logical_block_size;
93 out->block_size=out->row_block_size*out->col_block_size;
94 out->pattern=Finley_SystemMatrixPattern_reference(pattern);
95 out->len=(size_t)(out->pattern->len)*(size_t)(out->block_size);
96 out->reference_counter=1;
97 out->direct=NULL;
98 out->iterative=NULL;
99
100
101 /* allocate memory for matrix entries */
102 val=MEMALLOC(out->len,double);
103 if (! Finley_checkPtr(val)) {
104 out->val=val;
105 Finley_SystemMatrix_setValues(out,DBLE(0));
106 }
107 }
108 /* all done: */
109
110 printf("timing: system matrix %.4e sec\n",Finley_timer()-time0);
111 if (Finley_ErrorCode!=NO_ERROR) {
112 MEMFREE(val);
113 Finley_SystemMatrix_dealloc(out);
114 return NULL;
115 } else {
116 #ifdef Finley_TRACE
117 printf("Finley_SystemMatrix_alloc: %ld x %ld system matrix has been allocated.\n",(long)out->num_rows,(long)out->num_cols);
118 #endif
119 return out;
120 }
121 }
122
123 /* returns a reference to Finley_SystemMatrix in */
124
125 Finley_SystemMatrix* Finley_SystemMatrix_reference(Finley_SystemMatrix* in) {
126 if (in!=NULL) ++(in->reference_counter);
127 return NULL;
128 }
129
130 /* deallocates a SystemMatrix: */
131
132 void Finley_SystemMatrix_dealloc(Finley_SystemMatrix* in) {
133 if (in!=NULL) {
134 in->reference_counter--;
135 if (in->reference_counter<=0) {
136 MEMFREE(in->val);
137 Finley_SystemMatrixPattern_dealloc(in->pattern);
138 Finley_SystemMatrix_solve_free(in);
139 MEMFREE(in);
140 #ifdef Finley_TRACE
141 printf("Finley_SystemMatrix_dealloc: system matrix as been deallocated.\n");
142 #endif
143 }
144 }
145 }
146 /*
147 * $Log$
148 * Revision 1.2 2004/12/14 05:39:30 jgs
149 * *** empty log message ***
150 *
151 * Revision 1.1.1.1.2.3 2004/11/24 01:37:15 gross
152 * some changes dealing with the integer overflow in memory allocation. Finley solves 4M unknowns now
153 *
154 * Revision 1.1.1.1.2.2 2004/11/12 06:58:18 gross
155 * a lot of changes to get the linearPDE class running: most important change is that there is no matrix format exposed to the user anymore. the format is chosen by the Domain according to the solver and symmetry
156 *
157 * Revision 1.1.1.1.2.1 2004/10/28 22:59:24 gross
158 * finley's RecTest.py is running now: problem in SystemMatrixAdapater fixed
159 *
160 * Revision 1.1.1.1 2004/10/26 06:53:57 jgs
161 * initial import of project esys2
162 *
163 * Revision 1.1 2004/07/02 04:21:13 gross
164 * Finley C code has been included
165 *
166 *
167 */

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26