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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2748 - (show annotations)
Tue Nov 17 07:32:59 2009 UTC (9 years, 5 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
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2009 by University of Queensland
5 * 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
14
15 /**************************************************************/
16
17 /* assembles the mass matrix in lumped form */
18
19 /* The coefficient D has to be defined on the integration points or not present. */
20
21 /* lumpedMat has to be initialized before the routine is called. */
22
23 /**************************************************************/
24
25 #include "Assemble.h"
26 #include "Util.h"
27 #ifdef _OPENMP
28 #include <omp.h>
29 #endif
30
31
32 /* Disabled until the tests pass */
33 /* #define NEW_LUMPING */ /* */
34
35 /**************************************************************/
36
37 void Finley_Assemble_LumpedSystem(Finley_NodeFile* nodes,Finley_ElementFile* elements, escriptDataC* lumpedMat, escriptDataC* D)
38 {
39
40 bool_t reducedIntegrationOrder=FALSE, expandedD;
41 char error_msg[LenErrorMsg_MAX];
42 Assemble_Parameters p;
43 dim_t dimensions[ESCRIPT_MAX_DATA_RANK], k, e, len_EM_lumpedMat, q, s, isub;
44 type_t funcspace;
45 index_t color,*row_index=NULL;
46 __const double *D_p=NULL;
47 double *S=NULL, *EM_lumpedMat=NULL, *Vol=NULL, *lumpedMat_p=NULL;
48 register double rtmp;
49 size_t len_EM_lumpedMat_size;
50 #if (defined NEW_LUMPING) || (defined _OPENMP)
51 register double m_t=0., diagS=0.;
52 #endif
53
54 Finley_resetError();
55
56 if (nodes==NULL || elements==NULL) return;
57 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 }
62 funcspace=getFunctionSpaceType(D);
63 /* check if all function spaces are the same */
64 if (funcspace==FINLEY_ELEMENTS) {
65 reducedIntegrationOrder=FALSE;
66 } else if (funcspace==FINLEY_FACE_ELEMENTS) {
67 reducedIntegrationOrder=FALSE;
68 } else if (funcspace==FINLEY_REDUCED_ELEMENTS) {
69 reducedIntegrationOrder=TRUE;
70 } else if (funcspace==FINLEY_REDUCED_FACE_ELEMENTS) {
71 reducedIntegrationOrder=TRUE;
72 } else {
73 Finley_setError(TYPE_ERROR,"Assemble_LumpedSystem: assemblage failed because of illegal function space.");
74 }
75 if (! Finley_noError()) return;
76
77 /* set all parameters in p*/
78 Assemble_getAssembleParameters(nodes,elements,NULL,lumpedMat, reducedIntegrationOrder, &p);
79 if (! Finley_noError()) return;
80
81 /* check if all function spaces are the same */
82
83 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 Finley_setError(TYPE_ERROR,error_msg);
86 }
87
88 /* check the dimensions: */
89
90 if (p.numEqu==1) {
91 if (!isEmpty(D)) {
92 if (!isDataPointShapeEqual(D,0,dimensions)) {
93 Finley_setError(TYPE_ERROR,"Assemble_LumpedSystem: coefficient D, rank 0 expected.");
94 }
95
96 }
97 } else {
98 if (!isEmpty(D)) {
99 dimensions[0]=p.numEqu;
100 if (!isDataPointShapeEqual(D,1,dimensions)) {
101 sprintf(error_msg,"Assemble_LumpedSystem: coefficient D, expected shape (%d,)",dimensions[0]);
102 Finley_setError(TYPE_ERROR,error_msg);
103 }
104 }
105 }
106
107 if (Finley_noError()) {
108 void* buffer=allocSampleBuffer(D);
109 requireWrite(lumpedMat);
110 lumpedMat_p=getSampleDataRW(lumpedMat,0);
111 len_EM_lumpedMat=p.row_numShapesTotal*p.numEqu;
112 len_EM_lumpedMat_size=len_EM_lumpedMat*sizeof(double);
113
114 expandedD=isExpanded(D);
115 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 {
119 EM_lumpedMat=THREAD_MEMALLOC(len_EM_lumpedMat,double);
120 row_index=THREAD_MEMALLOC(p.row_numShapesTotal,index_t);
121 if ( !Finley_checkPtr(EM_lumpedMat) && !Finley_checkPtr(row_index) ) {
122 if (p.numEqu == 1) {
123 if (expandedD) {
124
125 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
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 } /* end color check */
162
163 } /* end element loop */
164 } /* end color loop */
165 } else {
166 for (color=elements->minColor;color<=elements->maxColor;color++) {
167 /* 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 } /* end element loop */
207 } /* end color loop */
208
209 }
210 } else {
211 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 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 }
245 }
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 } /* end color check */
251 } /* end element loop */
252 } /* end color loop */
253 } else {
254 for (color=elements->minColor;color<=elements->maxColor;color++) {
255 /* open loop over all elements: */
256 #pragma omp for private(e) schedule(static)
257 for(e=0;e<elements->numElements;e++){
258 if (elements->Color[e]==color) {
259 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 } /* end color check */
294 } /* end element loop */
295 } /* end color loop */
296 }
297 }
298 } /* end of pointer check */
299 THREAD_MEMFREE(EM_lumpedMat);
300 THREAD_MEMFREE(row_index);
301 } /* end parallel region */
302 freeSampleBuffer(buffer);
303 }
304 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26