/[escript]/branches/domexper/dudley/src/IndexList.c
ViewVC logotype

Annotation of /branches/domexper/dudley/src/IndexList.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3216 - (hide annotations)
Tue Sep 28 05:13:17 2010 UTC (9 years, 1 month ago) by jfenwick
File MIME type: text/plain
File size: 7855 byte(s)
ElementFile does not use ReferenceElements anymore

1 jgs 82
2 ksteube 1312 /*******************************************************
3 ksteube 1811 *
4 jfenwick 2881 * Copyright (c) 2003-2010 by University of Queensland
5 ksteube 1811 * Earth Systems Science Computational Center (ESSCC)
6     * http://www.uq.edu.au/esscc
7     *
8     * Primary Business: Queensland, Australia
9     * Licensed under the Open Software License version 3.0
10     * http://www.opensource.org/licenses/osl-3.0.php
11     *
12     *******************************************************/
13 jgs 82
14 ksteube 1811
15 jgs 82 /**************************************************************/
16    
17 jfenwick 3086 /* Dudley: Converting an element list into a matrix shape */
18 jgs 82
19     /**************************************************************/
20    
21     #include "IndexList.h"
22    
23 ksteube 1312 /* Translate from distributed/local array indices to global indices */
24    
25 jgs 82 /**************************************************************/
26     /* inserts the contributions from the element matrices of elements
27     into the row index col. If symmetric is set, only the upper
28     triangle of the matrix is stored. */
29    
30 jfenwick 3086 void Dudley_IndexList_insertElements(Dudley_IndexList* index_list, Dudley_ElementFile* elements,
31 ksteube 1312 bool_t reduce_row_order, index_t* row_map,
32 jfenwick 3141 bool_t reduce_col_order, index_t* col_map)
33     {
34 ksteube 1312 /* index_list is an array of linked lists. Each entry is a row (DOF) and contains the indices to the non-zero columns */
35 gross 2748 index_t color;
36 jfenwick 3216 // Dudley_ReferenceElement*refElement;
37 jfenwick 3145 dim_t e, kr, kc, NN_row, NN_col, icol, irow, NN;
38 jfenwick 3141 if (elements!=NULL)
39     {
40 ksteube 1312 NN=elements->numNodes;
41 jfenwick 3216 // refElement= Dudley_ReferenceElementSet_borrowReferenceElement(elements->referenceElementSet, FALSE);
42     NN_col=(elements->numShapes);
43     NN_row=(elements->numShapes) ;
44 gross 2748
45 jfenwick 3141 for (color=elements->minColor;color<=elements->maxColor;color++)
46     {
47 jfenwick 3161 #pragma omp for private(e,irow,kr,kc,icol) schedule(static)
48 jfenwick 3141 for (e=0;e<elements->numElements;e++)
49     {
50     if (elements->Color[e]==color)
51     {
52     for (kr=0;kr<NN_row;kr++)
53     {
54 jfenwick 3145 irow=row_map[elements->Nodes[INDEX2(kr,e,NN)]];
55 jfenwick 3141 for (kc=0;kc<NN_col;kc++)
56     {
57 jfenwick 3145 icol=col_map[elements->Nodes[INDEX2(kc,e,NN)]];
58 jfenwick 3141 Dudley_IndexList_insertIndex(&(index_list[irow]),icol);
59     }
60     }
61     }
62 gross 2748 }
63 jfenwick 3144 }
64 jgs 82 }
65     return;
66     }
67    
68 gross 2748
69 jfenwick 3086 void Dudley_IndexList_insertElementsWithRowRange(Dudley_IndexList* index_list, index_t firstRow, index_t lastRow,
70     Dudley_ElementFile* elements, index_t* row_map, index_t* col_map)
71 ksteube 1312 {
72 gross 2748 /* this does not resolve macro elements */
73     index_t color;
74 phornby 1628 dim_t e,kr,kc,icol,irow, NN;
75 ksteube 1312 if (elements!=NULL) {
76     NN=elements->numNodes;
77     for (color=elements->minColor;color<=elements->maxColor;color++) {
78     #pragma omp for private(e,irow,kr,kc,icol) schedule(static)
79     for (e=0;e<elements->numElements;e++) {
80     if (elements->Color[e]==color) {
81     for (kr=0;kr<NN;kr++) {
82     irow=row_map[elements->Nodes[INDEX2(kr,e,NN)]];
83     if ((firstRow<=irow) && (irow < lastRow)) {
84     irow-=firstRow;
85     for (kc=0;kc<NN;kc++) {
86     icol=col_map[elements->Nodes[INDEX2(kc,e,NN)]];
87 jfenwick 3086 Dudley_IndexList_insertIndex(&(index_list[irow]),icol);
88 ksteube 1312 }
89     }
90     }
91     }
92     }
93     }
94     }
95     }
96 jfenwick 3086 void Dudley_IndexList_insertElementsWithRowRangeNoMainDiagonal(Dudley_IndexList* index_list, index_t firstRow, index_t lastRow,
97     Dudley_ElementFile* elements, index_t* row_map, index_t* col_map)
98 gross 1722 {
99 gross 2748 /* this does not resolve macro elements */
100 gross 1722 index_t color;
101     dim_t e,kr,kc,icol,irow, NN,irow_loc;
102     if (elements!=NULL) {
103     NN=elements->numNodes;
104     for (color=elements->minColor;color<=elements->maxColor;color++) {
105     #pragma omp for private(e,irow,kr,kc,icol,irow_loc) schedule(static)
106     for (e=0;e<elements->numElements;e++) {
107     if (elements->Color[e]==color) {
108     for (kr=0;kr<NN;kr++) {
109     irow=row_map[elements->Nodes[INDEX2(kr,e,NN)]];
110     if ((firstRow<=irow) && (irow < lastRow)) {
111     irow_loc=irow-firstRow;
112     for (kc=0;kc<NN;kc++) {
113     icol=col_map[elements->Nodes[INDEX2(kc,e,NN)]];
114 jfenwick 3086 if (icol != irow) Dudley_IndexList_insertIndex(&(index_list[irow_loc]),icol);
115 gross 1722 }
116     }
117     }
118     }
119     }
120     }
121     }
122     }
123 ksteube 1312
124 jfenwick 3086 /* inserts row index row into the Dudley_IndexList in if it does not exist */
125 jgs 82
126 jfenwick 3086 void Dudley_IndexList_insertIndex(Dudley_IndexList* in, index_t index) {
127 jgs 123 dim_t i;
128 jgs 82 /* is index in in? */
129     for (i=0;i<in->n;i++) {
130 jgs 102 if (in->index[i]==index) return;
131 jgs 82 }
132     /* index could not be found */
133     if (in->n==INDEXLIST_LENGTH) {
134     /* if in->index is full check the extension */
135     if (in->extension==NULL) {
136 jfenwick 3086 in->extension=TMPMEMALLOC(1,Dudley_IndexList);
137     if (Dudley_checkPtr(in->extension)) return;
138 jgs 82 in->extension->n=0;
139     in->extension->extension=NULL;
140     }
141 jfenwick 3086 Dudley_IndexList_insertIndex(in->extension,index);
142 jgs 82 } else {
143     /* insert index into in->index*/
144     in->index[in->n]=index;
145     in->n++;
146     }
147     }
148    
149 jfenwick 3086 /* counts the number of row indices in the Dudley_IndexList in */
150 jgs 82
151 jfenwick 3086 dim_t Dudley_IndexList_count(Dudley_IndexList* in, index_t range_min,index_t range_max) {
152 ksteube 1312 dim_t i;
153     dim_t out=0;
154     register index_t itmp;
155 jgs 82 if (in==NULL) {
156     return 0;
157     } else {
158 ksteube 1312 for (i=0;i<in->n;i++) {
159     itmp=in->index[i];
160     if ((itmp>=range_min) && (range_max>itmp)) ++out;
161     }
162 jfenwick 3086 return out+Dudley_IndexList_count(in->extension, range_min,range_max);
163 jgs 82 }
164     }
165    
166 jfenwick 3086 /* count the number of row indices in the Dudley_IndexList in */
167 jgs 82
168 jfenwick 3086 void Dudley_IndexList_toArray(Dudley_IndexList* in, index_t* array, index_t range_min,index_t range_max, index_t index_offset) {
169 ksteube 1312 dim_t i, ptr;
170     register index_t itmp;
171 jgs 82 if (in!=NULL) {
172 ksteube 1312 ptr=0;
173     for (i=0;i<in->n;i++) {
174     itmp=in->index[i];
175     if ((itmp>=range_min) && (range_max>itmp)) {
176     array[ptr]=itmp+index_offset;
177     ptr++;
178     }
179    
180     }
181 jfenwick 3086 Dudley_IndexList_toArray(in->extension,&(array[ptr]), range_min, range_max, index_offset);
182 jgs 82 }
183     }
184    
185 jfenwick 3086 /* deallocates the Dudley_IndexList in by recursive calls */
186 jgs 82
187 jfenwick 3086 void Dudley_IndexList_free(Dudley_IndexList* in) {
188 jgs 82 if (in!=NULL) {
189 jfenwick 3086 Dudley_IndexList_free(in->extension);
190 jgs 82 TMPMEMFREE(in);
191     }
192     }
193    
194 ksteube 1312 /* creates a Paso_pattern from a range of indices */
195 jfenwick 3086 Paso_Pattern* Dudley_IndexList_createPattern(dim_t n0, dim_t n,Dudley_IndexList* index_list,index_t range_min,index_t range_max,index_t index_offset)
196 ksteube 1312 {
197     dim_t *ptr=NULL;
198     register dim_t s,i,itmp;
199     index_t *index=NULL;
200     Paso_Pattern* out=NULL;
201    
202 gross 1552 ptr=MEMALLOC(n+1-n0,index_t);
203 jfenwick 3086 if (! Dudley_checkPtr(ptr) ) {
204 ksteube 1312 /* get the number of connections per row */
205     #pragma omp parallel for schedule(static) private(i)
206 gross 1552 for(i=n0;i<n;++i) {
207 jfenwick 3086 ptr[i-n0]=Dudley_IndexList_count(&index_list[i],range_min,range_max);
208 ksteube 1312 }
209     /* accumulate ptr */
210     s=0;
211 gross 1552 for(i=n0;i<n;++i) {
212     itmp=ptr[i-n0];
213     ptr[i-n0]=s;
214 ksteube 1312 s+=itmp;
215     }
216 gross 1552 ptr[n-n0]=s;
217 ksteube 1312 /* fill index */
218 gross 1552 index=MEMALLOC(ptr[n-n0],index_t);
219 jfenwick 3086 if (! Dudley_checkPtr(index)) {
220 ksteube 1312 #pragma omp parallel for schedule(static)
221 gross 1552 for(i=n0;i<n;++i) {
222 jfenwick 3086 Dudley_IndexList_toArray(&index_list[i],&index[ptr[i-n0]],range_min,range_max,index_offset);
223 ksteube 1312 }
224 gross 2551 out=Paso_Pattern_alloc(PATTERN_FORMAT_DEFAULT,n-n0,range_max+index_offset,ptr,index);
225 ksteube 1312 }
226     }
227 jfenwick 3086 if (! Dudley_noError()) {
228 ksteube 1312 MEMFREE(ptr);
229     MEMFREE(index);
230     Paso_Pattern_free(out);
231     }
232     return out;
233     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26