/[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 2989 - (hide annotations)
Thu Mar 18 01:45:55 2010 UTC (9 years ago) by gross
File MIME type: text/plain
File size: 14867 byte(s)
- bug in error handling in the case of lumped mass matrix fixed.
- switched back to rowsum lumping as there are problems with HRZ lumping for order 2 


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 2989 /* #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 2989
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 gross 2989
81 gross 798 /* check if all function spaces are the same */
82 gross 2989 if (! numSamplesEqual(D,p.numQuadTotal,elements->numElements) ) {
83 gross 2748 sprintf(error_msg,"Assemble_LumpedSystem: sample points of coefficient D don't match (%d,%d)",p.numQuadSub,elements->numElements);
84 jgs 150 Finley_setError(TYPE_ERROR,error_msg);
85 jgs 82 }
86    
87     /* check the dimensions: */
88 gross 1204 if (p.numEqu==1) {
89 jgs 82 if (!isEmpty(D)) {
90     if (!isDataPointShapeEqual(D,0,dimensions)) {
91 gross 1204 Finley_setError(TYPE_ERROR,"Assemble_LumpedSystem: coefficient D, rank 0 expected.");
92 jgs 82 }
93 gross 1204
94 jgs 82 }
95     } else {
96     if (!isEmpty(D)) {
97     dimensions[0]=p.numEqu;
98 gross 1204 if (!isDataPointShapeEqual(D,1,dimensions)) {
99     sprintf(error_msg,"Assemble_LumpedSystem: coefficient D, expected shape (%d,)",dimensions[0]);
100 jgs 150 Finley_setError(TYPE_ERROR,error_msg);
101 jgs 82 }
102     }
103     }
104 jgs 150 if (Finley_noError()) {
105 gross 2989 printf("SADSADSADAS 2\n");
106 jfenwick 2271 requireWrite(lumpedMat);
107     lumpedMat_p=getSampleDataRW(lumpedMat,0);
108 gross 2748 len_EM_lumpedMat=p.row_numShapesTotal*p.numEqu;
109 gross 1204 len_EM_lumpedMat_size=len_EM_lumpedMat*sizeof(double);
110 gross 2748
111 gross 1204 expandedD=isExpanded(D);
112 gross 2748 S=p.row_jac->BasisFunctions->S;
113 gross 2989
114 caltinay 2750 #ifdef NEW_LUMPING
115 gross 2748 #pragma omp parallel private(color, EM_lumpedMat, row_index, Vol, D_p, s, q, k, rtmp, diagS, m_t)
116 caltinay 2750 #else
117     #pragma omp parallel private(color, EM_lumpedMat, row_index, Vol, D_p, s, q, k, rtmp)
118     #endif
119 gross 1204 {
120     EM_lumpedMat=THREAD_MEMALLOC(len_EM_lumpedMat,double);
121 gross 2748 row_index=THREAD_MEMALLOC(p.row_numShapesTotal,index_t);
122 gross 1204 if ( !Finley_checkPtr(EM_lumpedMat) && !Finley_checkPtr(row_index) ) {
123 gross 2988 if (p.numEqu == 1) { /* single equation */
124     if (expandedD) { /* with expanded D */
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 gross 2988 for(e=0;e<elements->numElements;e++){
129     if (elements->Color[e]==color) {
130 gross 2748 for (isub=0; isub<p.numSub; isub++) {
131 gross 2989 Vol=&(p.row_jac->volume[INDEX3(0,isub,e, p.numQuadSub,p.numSub)]);
132 jfenwick 2770 D_p=getSampleDataRO(D,e);
133 gross 2988 #ifdef NEW_LUMPING /* HRZ lumping */
134    
135 gross 2748 m_t=0; /* mass of the element: m_t */
136     for (q=0;q<p.numQuadSub;q++) m_t+=Vol[q]*D_p[INDEX2(q, isub,p.numQuadSub) ];
137 gross 2988
138 gross 2748 diagS=0; /* diagonal sum: S */
139     for (s=0;s<p.row_numShapes;s++) {
140     rtmp=0;
141     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)];
142     EM_lumpedMat[INDEX2(0,s,p.numEqu)]=rtmp;
143     diagS+=rtmp;
144     }
145     /* rescale diagonals by m_t/diagS to ensure consistent mass over element */
146 gross 2988 rtmp=m_t/diagS;
147 gross 2748 for (s=0;s<p.row_numShapes;s++) EM_lumpedMat[INDEX2(0,s,p.numEqu)]*=rtmp;
148    
149     #else /* row-sum lumping */
150     for (s=0;s<p.row_numShapes;s++) {
151     rtmp=0;
152     for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*D_p[INDEX2(q, isub,p.numQuadSub)];
153 gross 2989 EM_lumpedMat[INDEX2(0,s,p.numEqu)]=rtmp;
154 gross 2748 }
155 gross 2989
156 gross 2748 #endif
157     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)]];
158     Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_lumpedMat,lumpedMat_p, p.row_DOF_UpperBound);
159     } /* end of isub loop */
160 gross 2988 } /* end color check */
161 gross 1204 } /* end element loop */
162     } /* end color loop */
163 gross 2988 } else { /* with constant D */
164 gross 2989 printf("SADSADSADAS\n");
165 gross 1204 for (color=elements->minColor;color<=elements->maxColor;color++) {
166 gross 2748 /* open loop over all elements: */
167     #pragma omp for private(e) schedule(static)
168     for(e=0;e<elements->numElements;e++){
169 gross 2988 if (elements->Color[e]==color) {
170 gross 2748 for (isub=0; isub<p.numSub; isub++) {
171 gross 2988 Vol=&(p.row_jac->volume[INDEX3(0,isub,e, p.numQuadSub,p.numSub)]);
172 jfenwick 2770 D_p=getSampleDataRO(D,e);
173 gross 2988 #ifdef NEW_LUMPING /* HRZ lumping */
174 gross 2748 m_t=0; /* mass of the element: m_t */
175     for (q=0;q<p.numQuadSub;q++) m_t+=Vol[q];
176     diagS=0; /* diagonal sum: S */
177     for (s=0;s<p.row_numShapes;s++) {
178     rtmp=0;
179     for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(s,q,p.row_numShapes)];
180     EM_lumpedMat[INDEX2(0,s,p.numEqu)]=rtmp;
181     diagS+=rtmp;
182     }
183     /* rescale diagonals by m_t/diagS to ensure consistent mass over element */
184 gross 2988 rtmp=m_t/diagS*D_p[0];
185 gross 2748 for (s=0;s<p.row_numShapes;s++) EM_lumpedMat[INDEX2(0,s,p.numEqu)]*=rtmp;
186     #else /* row-sum lumping */
187     for (s=0;s<p.row_numShapes;s++) {
188     rtmp=0;
189     for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
190 gross 2988 EM_lumpedMat[INDEX2(0,s,p.numEqu)]=rtmp*D_p[0];
191 gross 2748 }
192 gross 2989 for (s=0;s<p.row_numShapes;s++) printf(" %d %d : %e\n",isub,s,EM_lumpedMat[INDEX2(0,s,p.numEqu)]);
193 gross 2748 #endif
194     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)]];
195     Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_lumpedMat,lumpedMat_p, p.row_DOF_UpperBound);
196     } /* end of isub loop */
197     } /* end color check */
198 gross 1204 } /* end element loop */
199 gross 2748 } /* end color loop */
200    
201 gross 1204 }
202 gross 2988 } else { /* system of equation */
203     if (expandedD) { /* with expanded D */
204 gross 1204 for (color=elements->minColor;color<=elements->maxColor;color++) {
205     /* open loop over all elements: */
206     #pragma omp for private(e) schedule(static)
207     for(e=0;e<elements->numElements;e++){
208     if (elements->Color[e]==color) {
209 gross 2988 for (isub=0; isub<p.numSub; isub++) {
210 gross 2748 Vol=&(p.row_jac->volume[INDEX3(0,isub,e, p.numQuadSub,p.numSub)]);
211 gross 2988 D_p=getSampleDataRO(D,e);
212    
213 gross 2748 #ifdef NEW_LUMPING /* HRZ lumping */
214     for (k=0;k<p.numEqu;k++) {
215     m_t=0; /* mass of the element: m_t */
216     for (q=0;q<p.numQuadSub;q++) m_t+=Vol[q]*D_p[INDEX3(k,q,isub,p.numEqu,p.numQuadSub)];
217    
218     diagS=0; /* diagonal sum: S */
219     for (s=0;s<p.row_numShapes;s++) {
220     rtmp=0;
221     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)];
222     EM_lumpedMat[INDEX2(k,s,p.numEqu)]=rtmp;
223     diagS+=rtmp;
224 gross 2988 }
225     /* rescale diagonals by m_t/diagS to ensure consistent mass over element */
226     rtmp=m_t/diagS;
227     for (s=0;s<p.row_numShapes;s++) EM_lumpedMat[INDEX2(k,s,p.numEqu)]*=rtmp;
228     }
229     #else /* row-sum lumping */
230     for (s=0;s<p.row_numShapes;s++) {
231     for (k=0;k<p.numEqu;k++) {
232     rtmp=0.;
233     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)];
234     EM_lumpedMat[INDEX2(k,s,p.numEqu)]=rtmp;
235     }
236     }
237     #endif
238     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)]];
239     Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_lumpedMat,lumpedMat_p, p.row_DOF_UpperBound);
240     } /* end of isub loop */
241 gross 1204 } /* end color check */
242     } /* end element loop */
243     } /* end color loop */
244 gross 2988 } else { /* with constant D */
245 gross 1204 for (color=elements->minColor;color<=elements->maxColor;color++) {
246 gross 2748 /* open loop over all elements: */
247 gross 1204 #pragma omp for private(e) schedule(static)
248     for(e=0;e<elements->numElements;e++){
249     if (elements->Color[e]==color) {
250 gross 2988 for (isub=0; isub<p.numSub; isub++) {
251 gross 2748 Vol=&(p.row_jac->volume[INDEX3(0,isub,e, p.numQuadSub,p.numSub)]);
252 jfenwick 2770 D_p=getSampleDataRO(D,e);
253 gross 2748
254     #ifdef NEW_LUMPING /* HRZ lumping */
255     m_t=0; /* mass of the element: m_t */
256 gross 2988 for (q=0;q<p.numQuadSub;q++) m_t+=Vol[q];
257 gross 2748 diagS=0; /* diagonal sum: S */
258     for (s=0;s<p.row_numShapes;s++) {
259     rtmp=0;
260     for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(s,q,p.row_numShapes)];
261 gross 2988 for (k=0;k<p.numEqu;k++) EM_lumpedMat[INDEX2(k,s,p.numEqu)]=rtmp;
262 gross 2748 diagS+=rtmp;
263     }
264 gross 2988 /* rescale diagonals by m_t/diagS to ensure consistent mass over element */
265     rtmp=m_t/diagS;
266     for (s=0;s<p.row_numShapes;s++) {
267     for (k=0;k<p.numEqu;k++) EM_lumpedMat[INDEX2(k,s,p.numEqu)]*=rtmp*D_p[k];
268     }
269     #else /* row-sum lumping */
270 gross 2748 for (s=0;s<p.row_numShapes;s++) {
271 gross 2988 for (k=0;k<p.numEqu;k++) {
272 gross 2748 rtmp=0.;
273     for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
274 gross 2989 EM_lumpedMat[INDEX2(k,s,p.numEqu)]=rtmp*D_p[k];
275 gross 2748 }
276 gross 2988 }
277     #endif
278     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)]];
279     Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_lumpedMat,lumpedMat_p, p.row_DOF_UpperBound);
280     } /* end of isub loop */
281 gross 1204 } /* end color check */
282     } /* end element loop */
283     } /* end color loop */
284     }
285 gross 798 }
286 gross 1204 } /* end of pointer check */
287     THREAD_MEMFREE(EM_lumpedMat);
288     THREAD_MEMFREE(row_index);
289     } /* end parallel region */
290 jgs 82 }
291     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26