/[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 117 - (show annotations)
Fri Apr 1 05:48:57 2005 UTC (15 years ago) by jgs
File MIME type: text/plain
File size: 5341 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 Finley_ErrorCode=NO_ERROR;
29 time0=Finley_timer();
30 out=MEMALLOC(1,Finley_SystemMatrix);
31 if (! Finley_checkPtr(out)) {
32 out->pattern=NULL;
33 out->direct=NULL;
34 out->iterative=NULL;
35 out->val=NULL;
36 out->reference_counter=1;
37 /* check the matrix type */
38 switch(type) {
39 case CSC:
40 out->type=CSC;
41 if (row_block_size!=col_block_size || col_block_size>3) {
42 out->row_block_size=1;
43 out->col_block_size=1;
44 out->pattern=Finley_SystemMatrixPattern_unrollBlocks(pattern,col_block_size,row_block_size);
45 } else {
46 out->pattern=Finley_SystemMatrixPattern_reference(pattern);
47 out->row_block_size=row_block_size;
48 out->col_block_size=col_block_size;
49 }
50 break;
51 case CSR:
52 out->type=CSR;
53 if (row_block_size!=col_block_size || col_block_size>3) {
54 out->row_block_size=1;
55 out->col_block_size=1;
56 out->pattern=Finley_SystemMatrixPattern_unrollBlocks(pattern,row_block_size,col_block_size);
57 } else {
58 out->pattern=Finley_SystemMatrixPattern_reference(pattern);
59 out->row_block_size=row_block_size;
60 out->col_block_size=col_block_size;
61 }
62 break;
63 case CSC_BLK1:
64 out->type=CSC;
65 out->row_block_size=1;
66 out->col_block_size=1;
67 if (row_block_size==1 && col_block_size==1) {
68 out->pattern=Finley_SystemMatrixPattern_reference(pattern);
69 } else {
70 out->pattern=Finley_SystemMatrixPattern_unrollBlocks(pattern,col_block_size,row_block_size);
71 }
72 break;
73 case CSR_BLK1:
74 out->type=CSR;
75 out->row_block_size=1;
76 out->col_block_size=1;
77 if (row_block_size==1 && col_block_size==1) {
78 out->pattern=Finley_SystemMatrixPattern_reference(pattern);
79 } else {
80 out->pattern=Finley_SystemMatrixPattern_unrollBlocks(pattern,row_block_size,col_block_size);
81 }
82 break;
83 case CSC_SYM:
84 case CSC_BLK1_SYM:
85 out->type=CSC_SYM;
86 Finley_ErrorCode=TYPE_ERROR;
87 sprintf(Finley_ErrorMsg,"convertion of matrix pattern for symmetric CSC is not implemented yet.");
88 return NULL;
89 default:
90 Finley_ErrorCode=TYPE_ERROR;
91 sprintf(Finley_ErrorMsg,"unknown matrix type identifier %d.",type);
92 return NULL;
93 }
94 if (out->type==CSC || out->type==CSC_SYM ) {
95 out->num_rows=out->pattern->n_index;
96 out->num_cols=out->pattern->n_ptr;
97 } else {
98 out->num_rows=out->pattern->n_ptr;
99 out->num_cols=out->pattern->n_index;
100 }
101 out->logical_row_block_size=row_block_size;
102 out->logical_col_block_size=col_block_size;
103 out->logical_block_size=out->logical_row_block_size*out->logical_block_size;
104 out->row_block_size=out->row_block_size;
105 out->col_block_size=out->col_block_size;
106 out->block_size=out->row_block_size*out->col_block_size;
107 out->len=(size_t)(out->pattern->len)*(size_t)(out->block_size);
108 /* allocate memory for matrix entries */
109 out->val=MEMALLOC(out->len,double);
110 if (! Finley_checkPtr(out->val)) {
111 Finley_SystemMatrix_setValues(out,DBLE(0));
112 }
113 }
114 /* all done: */
115 if (Finley_ErrorCode!=NO_ERROR) {
116 Finley_SystemMatrix_dealloc(out);
117 return NULL;
118 } else {
119 printf("timing: system matrix %.4e sec\n",Finley_timer()-time0);
120 #ifdef Finley_TRACE
121 printf("Finley_SystemMatrix_alloc: %ld x %ld system matrix has been allocated.\n",(long)out->num_rows,(long)out->num_cols);
122 #endif
123 return out;
124 }
125 }
126
127 /* returns a reference to Finley_SystemMatrix in */
128
129 Finley_SystemMatrix* Finley_SystemMatrix_reference(Finley_SystemMatrix* in) {
130 if (in!=NULL) ++(in->reference_counter);
131 return NULL;
132 }
133
134 /* deallocates a SystemMatrix: */
135
136 void Finley_SystemMatrix_dealloc(Finley_SystemMatrix* in) {
137 if (in!=NULL) {
138 in->reference_counter--;
139 if (in->reference_counter<=0) {
140 MEMFREE(in->val);
141 Finley_SystemMatrixPattern_dealloc(in->pattern);
142 Finley_SystemMatrix_solve_free(in);
143 MEMFREE(in);
144 #ifdef Finley_TRACE
145 printf("Finley_SystemMatrix_dealloc: system matrix as been deallocated.\n");
146 #endif
147 }
148 }
149 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26