/[escript]/trunk/finley/src/Assemble_LumpedSystem.c
ViewVC logotype

Annotation of /trunk/finley/src/Assemble_LumpedSystem.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2748 - (hide annotations)
Tue Nov 17 07:32:59 2009 UTC (9 years, 4 months ago) by gross
File MIME type: text/plain
File size: 15192 byte(s)
Macro elements are implemented now. VTK writer for macro elements still needs testing.
1 jgs 82
2 ksteube 1312 /*******************************************************
3 ksteube 1811 *
4 jfenwick 2548 * Copyright (c) 2003-2009 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 ksteube 1312
14 ksteube 1811
15 jgs 82 /**************************************************************/
16    
17 gross 1204 /* assembles the mass matrix in lumped form */
18 jgs 82
19 gross 1204 /* The coefficient D has to be defined on the integration points or not present. */
20 jgs 82
21 gross 1204 /* lumpedMat has to be initialized before the routine is called. */
22 jgs 82
23     /**************************************************************/
24    
25     #include "Assemble.h"
26     #include "Util.h"
27     #ifdef _OPENMP
28     #include <omp.h>
29     #endif
30    
31    
32 ksteube 1221 /* Disabled until the tests pass */
33     /* #define NEW_LUMPING */ /* */
34 btully 1220
35 jgs 82 /**************************************************************/
36    
37 gross 1204 void Finley_Assemble_LumpedSystem(Finley_NodeFile* nodes,Finley_ElementFile* elements, escriptDataC* lumpedMat, escriptDataC* D)
38     {
39 jgs 82
40 gross 1204 bool_t reducedIntegrationOrder=FALSE, expandedD;
41 jgs 150 char error_msg[LenErrorMsg_MAX];
42 gross 798 Assemble_Parameters p;
43 gross 2748 dim_t dimensions[ESCRIPT_MAX_DATA_RANK], k, e, len_EM_lumpedMat, q, s, isub;
44 gross 1028 type_t funcspace;
45 gross 1204 index_t color,*row_index=NULL;
46 jfenwick 2271 __const double *D_p=NULL;
47     double *S=NULL, *EM_lumpedMat=NULL, *Vol=NULL, *lumpedMat_p=NULL;
48 phornby 1628 register double rtmp;
49 gross 1204 size_t len_EM_lumpedMat_size;
50 gross 2748 #if (defined NEW_LUMPING) || (defined _OPENMP)
51     register double m_t=0., diagS=0.;
52     #endif
53    
54 jgs 150 Finley_resetError();
55 jgs 82
56     if (nodes==NULL || elements==NULL) return;
57 gross 1204 if (isEmpty(lumpedMat) || isEmpty(D)) return;
58     if (isEmpty(lumpedMat) && !isEmpty(D)) {
59     Finley_setError(TYPE_ERROR,"Assemble_LumpedSystem: coefficients are non-zero but no lumped matrix is given.");
60     return;
61 gross 798 }
62 gross 1204 funcspace=getFunctionSpaceType(D);
63 jgs 82 /* check if all function spaces are the same */
64 gross 798 if (funcspace==FINLEY_ELEMENTS) {
65     reducedIntegrationOrder=FALSE;
66     } else if (funcspace==FINLEY_FACE_ELEMENTS) {
67     reducedIntegrationOrder=FALSE;
68 gross 1072 } else if (funcspace==FINLEY_REDUCED_ELEMENTS) {
69     reducedIntegrationOrder=TRUE;
70     } else if (funcspace==FINLEY_REDUCED_FACE_ELEMENTS) {
71     reducedIntegrationOrder=TRUE;
72 gross 798 } else {
73 gross 1204 Finley_setError(TYPE_ERROR,"Assemble_LumpedSystem: assemblage failed because of illegal function space.");
74 gross 798 }
75     if (! Finley_noError()) return;
76 jgs 82
77 gross 798 /* set all parameters in p*/
78 gross 1204 Assemble_getAssembleParameters(nodes,elements,NULL,lumpedMat, reducedIntegrationOrder, &p);
79 gross 798 if (! Finley_noError()) return;
80    
81     /* check if all function spaces are the same */
82    
83 gross 2748 if (! numSamplesEqual(D,p.numQuadSub,elements->numElements) ) {
84     sprintf(error_msg,"Assemble_LumpedSystem: sample points of coefficient D don't match (%d,%d)",p.numQuadSub,elements->numElements);
85 jgs 150 Finley_setError(TYPE_ERROR,error_msg);
86 jgs 82 }
87    
88     /* check the dimensions: */
89    
90 gross 1204 if (p.numEqu==1) {
91 jgs 82 if (!isEmpty(D)) {
92     if (!isDataPointShapeEqual(D,0,dimensions)) {
93 gross 1204 Finley_setError(TYPE_ERROR,"Assemble_LumpedSystem: coefficient D, rank 0 expected.");
94 jgs 82 }
95 gross 1204
96 jgs 82 }
97     } else {
98     if (!isEmpty(D)) {
99     dimensions[0]=p.numEqu;
100 gross 1204 if (!isDataPointShapeEqual(D,1,dimensions)) {
101     sprintf(error_msg,"Assemble_LumpedSystem: coefficient D, expected shape (%d,)",dimensions[0]);
102 jgs 150 Finley_setError(TYPE_ERROR,error_msg);
103 jgs 82 }
104     }
105     }
106 gross 1204
107 jgs 150 if (Finley_noError()) {
108 jfenwick 2271 void* buffer=allocSampleBuffer(D);
109     requireWrite(lumpedMat);
110     lumpedMat_p=getSampleDataRW(lumpedMat,0);
111 gross 2748 len_EM_lumpedMat=p.row_numShapesTotal*p.numEqu;
112 gross 1204 len_EM_lumpedMat_size=len_EM_lumpedMat*sizeof(double);
113 gross 2748
114 gross 1204 expandedD=isExpanded(D);
115 gross 2748 S=p.row_jac->BasisFunctions->S;
116    
117     #pragma omp parallel private(color, EM_lumpedMat, row_index, Vol, D_p, s, q, k, rtmp, diagS, m_t)
118 gross 1204 {
119     EM_lumpedMat=THREAD_MEMALLOC(len_EM_lumpedMat,double);
120 gross 2748 row_index=THREAD_MEMALLOC(p.row_numShapesTotal,index_t);
121 gross 1204 if ( !Finley_checkPtr(EM_lumpedMat) && !Finley_checkPtr(row_index) ) {
122     if (p.numEqu == 1) {
123     if (expandedD) {
124 gross 2748
125 gross 1204 for (color=elements->minColor;color<=elements->maxColor;color++) {
126     /* open loop over all elements: */
127     #pragma omp for private(e) schedule(static)
128     for(e=0;e<elements->numElements;e++){
129 gross 2748
130     if (elements->Color[e]==color) {
131     for (isub=0; isub<p.numSub; isub++) {
132     Vol=&(p.row_jac->volume[INDEX3(0,isub,e, p.numQuadSub,p.numSub)]);
133     memset(EM_lumpedMat,0,len_EM_lumpedMat_size);
134    
135     D_p=getSampleDataRO(D,e,buffer);
136     #ifdef NEW_LUMPING /* HRZ lumping */
137     m_t=0; /* mass of the element: m_t */
138     for (q=0;q<p.numQuadSub;q++) m_t+=Vol[q]*D_p[INDEX2(q, isub,p.numQuadSub) ];
139    
140     diagS=0; /* diagonal sum: S */
141     for (s=0;s<p.row_numShapes;s++) {
142     rtmp=0;
143     for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*D_p[INDEX2(q, isub,p.numQuadSub)]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(s,q,p.row_numShapes)];
144     EM_lumpedMat[INDEX2(0,s,p.numEqu)]=rtmp;
145     diagS+=rtmp;
146     }
147     /* rescale diagonals by m_t/diagS to ensure consistent mass over element */
148     rtmp=m_t/diagS;
149     for (s=0;s<p.row_numShapes;s++) EM_lumpedMat[INDEX2(0,s,p.numEqu)]*=rtmp;
150    
151     #else /* row-sum lumping */
152     for (s=0;s<p.row_numShapes;s++) {
153     rtmp=0;
154     for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*D_p[INDEX2(q, isub,p.numQuadSub)];
155     EM_lumpedMat[INDEX2(0,s,p.numEqu)]+=rtmp;
156     }
157     #endif
158     for (q=0;q<p.row_numShapesTotal;q++) row_index[q]=p.row_DOF[elements->Nodes[INDEX2(p.row_node[INDEX2(q,isub,p.row_numShapesTotal)],e,p.NN)]];
159     Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_lumpedMat,lumpedMat_p, p.row_DOF_UpperBound);
160     } /* end of isub loop */
161 gross 1204 } /* end color check */
162 gross 2748
163 gross 1204 } /* end element loop */
164     } /* end color loop */
165 gross 2748 } else {
166 gross 1204 for (color=elements->minColor;color<=elements->maxColor;color++) {
167 gross 2748 /* open loop over all elements: */
168     #pragma omp for private(e) schedule(static)
169     for(e=0;e<elements->numElements;e++){
170    
171     if (elements->Color[e]==color) {
172     for (isub=0; isub<p.numSub; isub++) {
173    
174     Vol=&(p.row_jac->volume[INDEX3(0,isub,e, p.numQuadSub,p.numSub)]);
175     memset(EM_lumpedMat,0,len_EM_lumpedMat_size);
176    
177     D_p=getSampleDataRO(D,e,buffer);
178     #ifdef NEW_LUMPING /* HRZ lumping */
179     m_t=0; /* mass of the element: m_t */
180     for (q=0;q<p.numQuadSub;q++) m_t+=Vol[q];
181     m_t*=D_p[0];
182    
183     diagS=0; /* diagonal sum: S */
184     for (s=0;s<p.row_numShapes;s++) {
185     rtmp=0;
186     for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(s,q,p.row_numShapes)];
187     rtmp*=D_p[0];
188     EM_lumpedMat[INDEX2(0,s,p.numEqu)]=rtmp;
189     diagS+=rtmp;
190     }
191     /* rescale diagonals by m_t/diagS to ensure consistent mass over element */
192     rtmp=m_t/diagS;
193     for (s=0;s<p.row_numShapes;s++) EM_lumpedMat[INDEX2(0,s,p.numEqu)]*=rtmp;
194    
195     #else /* row-sum lumping */
196     for (s=0;s<p.row_numShapes;s++) {
197     rtmp=0;
198     for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
199     EM_lumpedMat[INDEX2(0,s,p.numEqu)]+=rtmp*D_p[0];
200     }
201     #endif
202     for (q=0;q<p.row_numShapesTotal;q++) row_index[q]=p.row_DOF[elements->Nodes[INDEX2(p.row_node[INDEX2(q,isub,p.row_numShapesTotal)],e,p.NN)]];
203     Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_lumpedMat,lumpedMat_p, p.row_DOF_UpperBound);
204     } /* end of isub loop */
205     } /* end color check */
206 gross 1204 } /* end element loop */
207 gross 2748 } /* end color loop */
208    
209 gross 1204 }
210 gross 798 } else {
211 gross 1204 if (expandedD) {
212     for (color=elements->minColor;color<=elements->maxColor;color++) {
213     /* open loop over all elements: */
214     #pragma omp for private(e) schedule(static)
215     for(e=0;e<elements->numElements;e++){
216     if (elements->Color[e]==color) {
217 gross 2748 for (isub=0; isub<p.numSub; isub++) {
218     Vol=&(p.row_jac->volume[INDEX3(0,isub,e, p.numQuadSub,p.numSub)]);
219     memset(EM_lumpedMat,0,len_EM_lumpedMat_size);
220     D_p=getSampleDataRO(D,e,buffer);
221    
222     #ifdef NEW_LUMPING /* HRZ lumping */
223     for (k=0;k<p.numEqu;k++) {
224     m_t=0; /* mass of the element: m_t */
225     for (q=0;q<p.numQuadSub;q++) m_t+=Vol[q]*D_p[INDEX3(k,q,isub,p.numEqu,p.numQuadSub)];
226    
227     diagS=0; /* diagonal sum: S */
228     for (s=0;s<p.row_numShapes;s++) {
229     rtmp=0;
230     for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*D_p[INDEX3(k,q,isub,p.numEqu,p.numQuadSub)]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(s,q,p.row_numShapes)];
231     EM_lumpedMat[INDEX2(k,s,p.numEqu)]=rtmp;
232     diagS+=rtmp;
233     }
234     /* rescale diagonals by m_t/diagS to ensure consistent mass over element */
235     rtmp=m_t/diagS;
236     for (s=0;s<p.row_numShapes;s++) EM_lumpedMat[INDEX2(k,s,p.numEqu)]*=rtmp;
237     }
238     #else /* row-sum lumping */
239     for (s=0;s<p.row_numShapes;s++) {
240     for (k=0;k<p.numEqu;k++) {
241     rtmp=0.;
242     for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*D_p[INDEX3(k,q,isub,p.numEqu,p.numQuadSub)];
243     EM_lumpedMat[INDEX2(k,s,p.numEqu)]+=rtmp;
244 btully 1220 }
245 gross 2748 }
246     #endif
247     for (q=0;q<p.row_numShapesTotal;q++) row_index[q]=p.row_DOF[elements->Nodes[INDEX2(p.row_node[INDEX2(q,isub,p.row_numShapesTotal)],e,p.NN)]];
248     Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_lumpedMat,lumpedMat_p, p.row_DOF_UpperBound);
249     } /* end of isub loop */
250 gross 1204 } /* end color check */
251     } /* end element loop */
252     } /* end color loop */
253     } else {
254     for (color=elements->minColor;color<=elements->maxColor;color++) {
255 gross 2748 /* open loop over all elements: */
256 gross 1204 #pragma omp for private(e) schedule(static)
257     for(e=0;e<elements->numElements;e++){
258     if (elements->Color[e]==color) {
259 gross 2748 for (isub=0; isub<p.numSub; isub++) {
260     Vol=&(p.row_jac->volume[INDEX3(0,isub,e, p.numQuadSub,p.numSub)]);
261     memset(EM_lumpedMat,0,len_EM_lumpedMat_size);
262     D_p=getSampleDataRO(D,e,buffer);
263    
264     #ifdef NEW_LUMPING /* HRZ lumping */
265     for (k=0;k<p.numEqu;k++) {
266     m_t=0; /* mass of the element: m_t */
267     for (q=0;q<p.numQuadSub;q++) m_t+=Vol[q]*D_p[INDEX3(k,q,isub,p.numEqu,p.numQuadSub)];
268     m_t*=D_p[k];
269     diagS=0; /* diagonal sum: S */
270     for (s=0;s<p.row_numShapes;s++) {
271     rtmp=0;
272     for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(s,q,p.row_numShapes)];
273     rtmp*=D_p[k];
274     EM_lumpedMat[INDEX2(k,s,p.numEqu)]=rtmp;
275     diagS+=rtmp;
276     }
277     /* rescale diagonals by m_t/diagS to ensure consistent mass over element */
278     rtmp=m_t/diagS;
279     for (s=0;s<p.row_numShapes;s++) EM_lumpedMat[INDEX2(k,s,p.numEqu)]*=rtmp;
280     }
281     #else /* row-sum lumping */
282     for (s=0;s<p.row_numShapes;s++) {
283     for (k=0;k<p.numEqu;k++) {
284     rtmp=0.;
285     for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
286     EM_lumpedMat[INDEX2(k,s,p.numEqu)]+=rtmp*D_p[k];
287     }
288     }
289     #endif
290     for (q=0;q<p.row_numShapesTotal;q++) row_index[q]=p.row_DOF[elements->Nodes[INDEX2(p.row_node[INDEX2(q,isub,p.row_numShapesTotal)],e,p.NN)]];
291     Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_lumpedMat,lumpedMat_p, p.row_DOF_UpperBound);
292     } /* end of isub loop */
293 gross 1204 } /* end color check */
294     } /* end element loop */
295     } /* end color loop */
296     }
297 gross 798 }
298 gross 1204 } /* end of pointer check */
299     THREAD_MEMFREE(EM_lumpedMat);
300     THREAD_MEMFREE(row_index);
301     } /* end parallel region */
302 jfenwick 2271 freeSampleBuffer(buffer);
303 jgs 82 }
304     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26