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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 115 - (hide annotations)
Fri Mar 4 07:12:47 2005 UTC (14 years, 2 months ago) by jgs
File MIME type: text/plain
File size: 4633 byte(s)
*** empty log message ***

1 jgs 82 /* $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 jgs 102 /* 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 jgs 82
25 jgs 102 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 jgs 82 Finley_ErrorCode=NO_ERROR;
31    
32 jgs 102 /* 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 jgs 82 time0=Finley_timer();
68     /* allocate the return value */
69    
70 jgs 102 out=MEMALLOC(1,Finley_SystemMatrix);
71     if (! Finley_checkPtr(out)) {
72 jgs 82
73 jgs 102 /* 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 jgs 82 }
81 jgs 102 if (out_type==CSC || type==CSC_BLK1 || type==CSC_SYM || type==CSC_BLK1_SYM ) {
82     out->num_rows=pattern->n_index;
83     out->num_cols=pattern->n_ptr;
84 jgs 115 } else {
85     out->num_rows=pattern->n_ptr;
86     out->num_cols=pattern->n_index;
87 jgs 102 }
88 jgs 82
89 jgs 102 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 jgs 82
100    
101 jgs 102 /* 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 jgs 82 }
107 jgs 102 }
108 jgs 82 /* all done: */
109    
110 jgs 102 printf("timing: system matrix %.4e sec\n",Finley_timer()-time0);
111 jgs 82 if (Finley_ErrorCode!=NO_ERROR) {
112 jgs 102 MEMFREE(val);
113     Finley_SystemMatrix_dealloc(out);
114 jgs 82 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 jgs 102 /* 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 jgs 82 /* 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 jgs 102 Finley_SystemMatrixPattern_dealloc(in->pattern);
138     Finley_SystemMatrix_solve_free(in);
139 jgs 82 MEMFREE(in);
140     #ifdef Finley_TRACE
141     printf("Finley_SystemMatrix_dealloc: system matrix as been deallocated.\n");
142     #endif
143     }
144     }
145     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26