/[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 2988 - (hide annotations)
Tue Mar 16 06:14:30 2010 UTC (9 years, 1 month ago) by gross
File MIME type: text/plain
File size: 14831 byte(s)
C-level lumping switched on
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 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 gross 2988 #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 caltinay 2750 #ifdef NEW_LUMPING
51 gross 2748 register double m_t=0., diagS=0.;
52 caltinay 2750 #endif
53 gross 2748
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 requireWrite(lumpedMat);
109     lumpedMat_p=getSampleDataRW(lumpedMat,0);
110 gross 2748 len_EM_lumpedMat=p.row_numShapesTotal*p.numEqu;
111 gross 1204 len_EM_lumpedMat_size=len_EM_lumpedMat*sizeof(double);
112 gross 2748
113 gross 1204 expandedD=isExpanded(D);
114 gross 2748 S=p.row_jac->BasisFunctions->S;
115 caltinay 2750
116     #ifdef NEW_LUMPING
117 gross 2748 #pragma omp parallel private(color, EM_lumpedMat, row_index, Vol, D_p, s, q, k, rtmp, diagS, m_t)
118 caltinay 2750 #else
119     #pragma omp parallel private(color, EM_lumpedMat, row_index, Vol, D_p, s, q, k, rtmp)
120     #endif
121 gross 1204 {
122     EM_lumpedMat=THREAD_MEMALLOC(len_EM_lumpedMat,double);
123 gross 2748 row_index=THREAD_MEMALLOC(p.row_numShapesTotal,index_t);
124 gross 1204 if ( !Finley_checkPtr(EM_lumpedMat) && !Finley_checkPtr(row_index) ) {
125 gross 2988 if (p.numEqu == 1) { /* single equation */
126     if (expandedD) { /* with expanded D */
127 gross 1204 for (color=elements->minColor;color<=elements->maxColor;color++) {
128     /* open loop over all elements: */
129     #pragma omp for private(e) schedule(static)
130 gross 2988 for(e=0;e<elements->numElements;e++){
131     if (elements->Color[e]==color) {
132 gross 2748 for (isub=0; isub<p.numSub; isub++) {
133 gross 2988 Vol=&(p.row_jac->volume[INDEX3(0,isub,e, p.numQuadSub,p.numSub)]);;
134 gross 2748
135 jfenwick 2770 D_p=getSampleDataRO(D,e);
136 gross 2988 #ifdef NEW_LUMPING /* HRZ lumping */
137    
138 gross 2748 m_t=0; /* mass of the element: m_t */
139     for (q=0;q<p.numQuadSub;q++) m_t+=Vol[q]*D_p[INDEX2(q, isub,p.numQuadSub) ];
140 gross 2988
141 gross 2748 diagS=0; /* diagonal sum: S */
142     for (s=0;s<p.row_numShapes;s++) {
143     rtmp=0;
144     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)];
145     EM_lumpedMat[INDEX2(0,s,p.numEqu)]=rtmp;
146     diagS+=rtmp;
147     }
148     /* rescale diagonals by m_t/diagS to ensure consistent mass over element */
149 gross 2988 rtmp=m_t/diagS;
150 gross 2748 for (s=0;s<p.row_numShapes;s++) EM_lumpedMat[INDEX2(0,s,p.numEqu)]*=rtmp;
151    
152     #else /* row-sum lumping */
153     for (s=0;s<p.row_numShapes;s++) {
154     rtmp=0;
155     for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*D_p[INDEX2(q, isub,p.numQuadSub)];
156     EM_lumpedMat[INDEX2(0,s,p.numEqu)]+=rtmp;
157     }
158     #endif
159     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)]];
160     Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_lumpedMat,lumpedMat_p, p.row_DOF_UpperBound);
161     } /* end of isub loop */
162 gross 2988 } /* end color check */
163 gross 1204 } /* end element loop */
164     } /* end color loop */
165 gross 2988 } else { /* with constant D */
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 gross 2988 if (elements->Color[e]==color) {
171 gross 2748 for (isub=0; isub<p.numSub; isub++) {
172 gross 2988 Vol=&(p.row_jac->volume[INDEX3(0,isub,e, p.numQuadSub,p.numSub)]);
173 jfenwick 2770 D_p=getSampleDataRO(D,e);
174 gross 2988 #ifdef NEW_LUMPING /* HRZ lumping */
175 gross 2748 m_t=0; /* mass of the element: m_t */
176     for (q=0;q<p.numQuadSub;q++) m_t+=Vol[q];
177    
178     diagS=0; /* diagonal sum: S */
179     for (s=0;s<p.row_numShapes;s++) {
180     rtmp=0;
181     for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(s,q,p.row_numShapes)];
182     EM_lumpedMat[INDEX2(0,s,p.numEqu)]=rtmp;
183     diagS+=rtmp;
184     }
185     /* rescale diagonals by m_t/diagS to ensure consistent mass over element */
186 gross 2988 rtmp=m_t/diagS*D_p[0];
187 gross 2748 for (s=0;s<p.row_numShapes;s++) EM_lumpedMat[INDEX2(0,s,p.numEqu)]*=rtmp;
188    
189     #else /* row-sum lumping */
190     for (s=0;s<p.row_numShapes;s++) {
191     rtmp=0;
192     for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
193 gross 2988 EM_lumpedMat[INDEX2(0,s,p.numEqu)]=rtmp*D_p[0];
194 gross 2748 }
195     #endif
196     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)]];
197     Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_lumpedMat,lumpedMat_p, p.row_DOF_UpperBound);
198     } /* end of isub loop */
199     } /* end color check */
200 gross 1204 } /* end element loop */
201 gross 2748 } /* end color loop */
202    
203 gross 1204 }
204 gross 2988 } else { /* system of equation */
205     if (expandedD) { /* with expanded D */
206 gross 1204 for (color=elements->minColor;color<=elements->maxColor;color++) {
207     /* open loop over all elements: */
208     #pragma omp for private(e) schedule(static)
209     for(e=0;e<elements->numElements;e++){
210     if (elements->Color[e]==color) {
211 gross 2988 for (isub=0; isub<p.numSub; isub++) {
212 gross 2748 Vol=&(p.row_jac->volume[INDEX3(0,isub,e, p.numQuadSub,p.numSub)]);
213 gross 2988 D_p=getSampleDataRO(D,e);
214    
215 gross 2748 #ifdef NEW_LUMPING /* HRZ lumping */
216     for (k=0;k<p.numEqu;k++) {
217     m_t=0; /* mass of the element: m_t */
218     for (q=0;q<p.numQuadSub;q++) m_t+=Vol[q]*D_p[INDEX3(k,q,isub,p.numEqu,p.numQuadSub)];
219    
220     diagS=0; /* diagonal sum: S */
221     for (s=0;s<p.row_numShapes;s++) {
222     rtmp=0;
223     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)];
224     EM_lumpedMat[INDEX2(k,s,p.numEqu)]=rtmp;
225     diagS+=rtmp;
226 gross 2988 }
227     /* rescale diagonals by m_t/diagS to ensure consistent mass over element */
228     rtmp=m_t/diagS;
229     for (s=0;s<p.row_numShapes;s++) EM_lumpedMat[INDEX2(k,s,p.numEqu)]*=rtmp;
230     }
231     #else /* row-sum lumping */
232     for (s=0;s<p.row_numShapes;s++) {
233     for (k=0;k<p.numEqu;k++) {
234     rtmp=0.;
235     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)];
236     EM_lumpedMat[INDEX2(k,s,p.numEqu)]=rtmp;
237     }
238     }
239     #endif
240     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)]];
241     Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_lumpedMat,lumpedMat_p, p.row_DOF_UpperBound);
242     } /* end of isub loop */
243 gross 1204 } /* end color check */
244     } /* end element loop */
245     } /* end color loop */
246 gross 2988 } else { /* with constant D */
247 gross 1204 for (color=elements->minColor;color<=elements->maxColor;color++) {
248 gross 2748 /* open loop over all elements: */
249 gross 1204 #pragma omp for private(e) schedule(static)
250     for(e=0;e<elements->numElements;e++){
251     if (elements->Color[e]==color) {
252 gross 2988 for (isub=0; isub<p.numSub; isub++) {
253 gross 2748 Vol=&(p.row_jac->volume[INDEX3(0,isub,e, p.numQuadSub,p.numSub)]);
254     memset(EM_lumpedMat,0,len_EM_lumpedMat_size);
255 jfenwick 2770 D_p=getSampleDataRO(D,e);
256 gross 2748
257     #ifdef NEW_LUMPING /* HRZ lumping */
258     m_t=0; /* mass of the element: m_t */
259 gross 2988 for (q=0;q<p.numQuadSub;q++) m_t+=Vol[q];
260 gross 2748 diagS=0; /* diagonal sum: S */
261     for (s=0;s<p.row_numShapes;s++) {
262     rtmp=0;
263     for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(s,q,p.row_numShapes)];
264 gross 2988 for (k=0;k<p.numEqu;k++) EM_lumpedMat[INDEX2(k,s,p.numEqu)]=rtmp;
265 gross 2748 diagS+=rtmp;
266     }
267 gross 2988 /* rescale diagonals by m_t/diagS to ensure consistent mass over element */
268     rtmp=m_t/diagS;
269     for (s=0;s<p.row_numShapes;s++) {
270     for (k=0;k<p.numEqu;k++) EM_lumpedMat[INDEX2(k,s,p.numEqu)]*=rtmp*D_p[k];
271     }
272     #else /* row-sum lumping */
273 gross 2748 for (s=0;s<p.row_numShapes;s++) {
274 gross 2988 for (k=0;k<p.numEqu;k++) {
275 gross 2748 rtmp=0.;
276     for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
277     EM_lumpedMat[INDEX2(k,s,p.numEqu)]+=rtmp*D_p[k];
278     }
279 gross 2988 }
280     #endif
281     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)]];
282     Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_lumpedMat,lumpedMat_p, p.row_DOF_UpperBound);
283     } /* end of isub loop */
284 gross 1204 } /* end color check */
285     } /* end element loop */
286     } /* end color loop */
287     }
288 gross 798 }
289 gross 1204 } /* end of pointer check */
290     THREAD_MEMFREE(EM_lumpedMat);
291     THREAD_MEMFREE(row_index);
292     } /* end parallel region */
293 jgs 82 }
294     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26