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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2748 - (show annotations)
Tue Nov 17 07:32:59 2009 UTC (10 years ago) by gross
File MIME type: text/plain
File size: 23909 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 system of numEq PDEs into the stiffness matrix S right hand side F */
18 /* the shape functions for test and solution must be identical */
19
20
21 /* -(A_{k,i,m,j} u_m,j)_i-(B_{k,i,m} u_m)_i+C_{k,m,j} u_m,j-D_{k,m} u_m and -(X_{k,i})_i + Y_k */
22
23 /* u has p.numComp components in a 3D domain. The shape functions for test and solution must be identical */
24 /* and row_NS == row_NN */
25
26 /* Shape of the coefficients: */
27
28 /* A = p.numEqu x 3 x p.numComp x 3 */
29 /* B = 3 x p.numEqu x p.numComp */
30 /* C = p.numEqu x 3 x p.numComp */
31 /* D = p.numEqu x p.numComp */
32 /* X = p.numEqu x 3 */
33 /* Y = p.numEqu */
34
35
36 /**************************************************************/
37
38
39 #include "Assemble.h"
40 #include "Util.h"
41 #ifdef _OPENMP
42 #include <omp.h>
43 #endif
44
45
46 /**************************************************************/
47
48 void Finley_Assemble_PDE_System2_3D(Assemble_Parameters p, Finley_ElementFile* elements,
49 Paso_SystemMatrix* Mat, escriptDataC* F,
50 escriptDataC* A, escriptDataC* B, escriptDataC* C, escriptDataC* D, escriptDataC* X, escriptDataC* Y) {
51
52 #define DIM 3
53 index_t color;
54 dim_t e, isub;
55 __const double *A_p, *B_p, *C_p, *D_p, *X_p, *Y_p, *A_q, *B_q, *C_q, *D_q, *X_q, *Y_q;
56 double *EM_S, *EM_F, *Vol, *DSDX;
57 index_t *row_index;
58 register dim_t q, s,r,k,m;
59 register double rtmp, rtmp0, rtmp1, rtmp2, rtmp00, rtmp01, rtmp02, rtmp10, rtmp11, rtmp12, rtmp20, rtmp21, rtmp22;
60 bool_t add_EM_F, add_EM_S;
61
62 bool_t extendedA=isExpanded(A);
63 bool_t extendedB=isExpanded(B);
64 bool_t extendedC=isExpanded(C);
65 bool_t extendedD=isExpanded(D);
66 bool_t extendedX=isExpanded(X);
67 bool_t extendedY=isExpanded(Y);
68 double *F_p=(requireWrite(F), getSampleDataRW(F,0)); /* use comma, to get around the mixed code and declarations thing */
69 double *S=p.row_jac->BasisFunctions->S;
70 dim_t len_EM_S=p.row_numShapesTotal*p.col_numShapesTotal*p.numEqu*p.numComp;
71 dim_t len_EM_F=p.row_numShapesTotal*p.numEqu;
72
73 void* ABuff=allocSampleBuffer(A);
74 void* BBuff=allocSampleBuffer(B);
75 void* CBuff=allocSampleBuffer(C);
76 void* DBuff=allocSampleBuffer(D);
77 void* XBuff=allocSampleBuffer(X);
78 void* YBuff=allocSampleBuffer(Y);
79 #pragma omp parallel private(color,EM_S, EM_F, Vol, DSDX, A_p, B_p, C_p, D_p, X_p, Y_p, A_q, B_q, C_q, D_q, X_q, Y_q,row_index,q, s,r,k,m,rtmp, rtmp0, rtmp1, rtmp2, rtmp00, rtmp01, rtmp02, rtmp10, rtmp11, rtmp12, rtmp20, rtmp21, rtmp22,add_EM_F, add_EM_S, isub)
80 {
81 EM_S=THREAD_MEMALLOC(len_EM_S,double);
82 EM_F=THREAD_MEMALLOC(len_EM_F,double);
83 row_index=THREAD_MEMALLOC(p.row_numShapesTotal,index_t);
84
85 if (!Finley_checkPtr(EM_S) && !Finley_checkPtr(EM_F) && !Finley_checkPtr(row_index) ) {
86
87 for (color=elements->minColor;color<=elements->maxColor;color++) {
88 /* open loop over all elements: */
89 #pragma omp for private(e) schedule(static)
90 for(e=0;e<elements->numElements;e++){
91 if (elements->Color[e]==color) {
92
93 A_p=getSampleDataRO(A,e,ABuff);
94 B_p=getSampleDataRO(B,e,BBuff);
95 C_p=getSampleDataRO(C,e,CBuff);
96 D_p=getSampleDataRO(D,e,DBuff);
97 X_p=getSampleDataRO(X,e,XBuff);
98 Y_p=getSampleDataRO(Y,e,YBuff);
99
100 for (isub=0;isub<p.numSub;isub++){
101
102 Vol=&(p.row_jac->volume[INDEX3(0,isub,e, p.numQuadSub,p.numSub)]);
103 DSDX=&(p.row_jac->DSDX[INDEX5(0,0,0,isub,e,p.row_numShapesTotal,DIM,p.numQuadSub,p.numSub)]);
104 for (q=0;q<len_EM_S;++q) EM_S[q]=0;
105 for (q=0;q<len_EM_F;++q) EM_F[q]=0;
106 add_EM_F=FALSE;
107 add_EM_S=FALSE;
108
109 /**************************************************************/
110 /* process A: */
111 /**************************************************************/
112 if (NULL!=A_p) {
113 add_EM_S=TRUE;
114 if (extendedA) {
115 A_q=&(A_p[INDEX6(0,0,0,0,0,isub, p.numEqu,DIM,p.numComp,DIM,p.numQuadSub)]);
116 for (s=0;s<p.row_numShapes;s++) {
117 for (r=0;r<p.col_numShapes;r++) {
118 for (k=0;k<p.numEqu;k++) {
119 for (m=0;m<p.numComp;m++) {
120 rtmp=0;
121 for (q=0;q<p.numQuadSub;q++) {
122 rtmp+=Vol[q]*(
123 DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*A_q[INDEX5(k,0,m,0,q, p.numEqu,DIM,p.numComp,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)]
124 +DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*A_q[INDEX5(k,0,m,1,q, p.numEqu,DIM,p.numComp,DIM)]*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)]
125 +DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*A_q[INDEX5(k,0,m,2,q, p.numEqu,DIM,p.numComp,DIM)]*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)]
126 +DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*A_q[INDEX5(k,1,m,0,q, p.numEqu,DIM,p.numComp,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)]
127 +DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*A_q[INDEX5(k,1,m,1,q, p.numEqu,DIM,p.numComp,DIM)]*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)]
128 +DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*A_q[INDEX5(k,1,m,2,q, p.numEqu,DIM,p.numComp,DIM)]*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)]
129 +DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)]*A_q[INDEX5(k,2,m,0,q, p.numEqu,DIM,p.numComp,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)]
130 +DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)]*A_q[INDEX5(k,2,m,1,q, p.numEqu,DIM,p.numComp,DIM)]*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)]
131 +DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)]*A_q[INDEX5(k,2,m,2,q, p.numEqu,DIM,p.numComp,DIM)]*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)]);
132
133 }
134 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
135 }
136 }
137 }
138 }
139 } else {
140 for (s=0;s<p.row_numShapes;s++) {
141 for (r=0;r<p.col_numShapes;r++) {
142 rtmp00=0;
143 rtmp01=0;
144 rtmp02=0;
145 rtmp10=0;
146 rtmp11=0;
147 rtmp12=0;
148 rtmp20=0;
149 rtmp21=0;
150 rtmp22=0;
151 for (q=0;q<p.numQuadSub;q++) {
152 rtmp0=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
153 rtmp00+=rtmp0*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
154 rtmp01+=rtmp0*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
155 rtmp02+=rtmp0*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)];
156
157 rtmp1=Vol[q]*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
158 rtmp10+=rtmp1*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
159 rtmp11+=rtmp1*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
160 rtmp12+=rtmp1*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)];
161
162 rtmp2=Vol[q]*DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)];
163 rtmp20+=rtmp2*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
164 rtmp21+=rtmp2*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
165 rtmp22+=rtmp2*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)];
166 }
167 for (k=0;k<p.numEqu;k++) {
168 for (m=0;m<p.numComp;m++) {
169 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+= rtmp00*A_p[INDEX4(k,0,m,0, p.numEqu,DIM,p.numComp)]
170 +rtmp01*A_p[INDEX4(k,0,m,1, p.numEqu,DIM,p.numComp)]
171 +rtmp02*A_p[INDEX4(k,0,m,2, p.numEqu,DIM,p.numComp)]
172 +rtmp10*A_p[INDEX4(k,1,m,0, p.numEqu,DIM,p.numComp)]
173 +rtmp11*A_p[INDEX4(k,1,m,1, p.numEqu,DIM,p.numComp)]
174 +rtmp12*A_p[INDEX4(k,1,m,2, p.numEqu,DIM,p.numComp)]
175 +rtmp20*A_p[INDEX4(k,2,m,0, p.numEqu,DIM,p.numComp)]
176 +rtmp21*A_p[INDEX4(k,2,m,1, p.numEqu,DIM,p.numComp)]
177 +rtmp22*A_p[INDEX4(k,2,m,2, p.numEqu,DIM,p.numComp)];
178 }
179 }
180 }
181 }
182 }
183 }
184 /**************************************************************/
185 /* process B: */
186 /**************************************************************/
187 if (NULL!=B_p) {
188 add_EM_S=TRUE;
189 if (extendedB) {
190 B_q=&(B_p[INDEX5(0,0,0,0,isub, p.numEqu,DIM,p.numComp,p.numQuadSub)]);
191 for (s=0;s<p.row_numShapes;s++) {
192 for (r=0;r<p.col_numShapes;r++) {
193 for (k=0;k<p.numEqu;k++) {
194 for (m=0;m<p.numComp;m++) {
195 rtmp=0;
196 for (q=0;q<p.numQuadSub;q++) {
197 rtmp+=Vol[q]*S[INDEX2(r,q,p.row_numShapes)]*(
198 DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*B_q[INDEX4(k,0,m,q,p.numEqu,DIM,p.numComp)]
199 + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*B_q[INDEX4(k,1,m,q,p.numEqu,DIM,p.numComp)]
200 + DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)]*B_q[INDEX4(k,2,m,q,p.numEqu,DIM,p.numComp)] );
201 }
202 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
203 }
204 }
205 }
206 }
207 } else {
208 for (s=0;s<p.row_numShapes;s++) {
209 for (r=0;r<p.col_numShapes;r++) {
210 rtmp0=0;
211 rtmp1=0;
212 rtmp2=0;
213 for (q=0;q<p.numQuadSub;q++) {
214 rtmp=Vol[q]*S[INDEX2(r,q,p.row_numShapes)];
215 rtmp0+=rtmp*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
216 rtmp1+=rtmp*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
217 rtmp2+=rtmp*DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)];
218 }
219 for (k=0;k<p.numEqu;k++) {
220 for (m=0;m<p.numComp;m++) {
221 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp0*B_p[INDEX3(k,0,m,p.numEqu,DIM)]
222 +rtmp1*B_p[INDEX3(k,1,m,p.numEqu,DIM)]
223 +rtmp2*B_p[INDEX3(k,2,m,p.numEqu,DIM)];
224 }
225 }
226 }
227 }
228 }
229 }
230 /**************************************************************/
231 /* process C: */
232 /**************************************************************/
233 if (NULL!=C_p) {
234 add_EM_S=TRUE;
235 if (extendedC) {
236 C_q=&(C_p[INDEX5(0,0,0,0,isub ,p.numEqu,p.numComp,DIM, p.numQuadSub)]);
237 for (s=0;s<p.row_numShapes;s++) {
238 for (r=0;r<p.col_numShapes;r++) {
239 for (k=0;k<p.numEqu;k++) {
240 for (m=0;m<p.numComp;m++) {
241 rtmp=0;
242 for (q=0;q<p.numQuadSub;q++) {
243 rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*(
244 C_q[INDEX4(k,m,0,q,p.numEqu,p.numComp,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)]
245 +C_q[INDEX4(k,m,1,q,p.numEqu,p.numComp,DIM)]*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)]
246 +C_q[INDEX4(k,m,2,q,p.numEqu,p.numComp,DIM)]*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)]);
247 }
248 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
249 }
250 }
251 }
252 }
253 } else {
254 for (s=0;s<p.row_numShapes;s++) {
255 for (r=0;r<p.col_numShapes;r++) {
256 rtmp0=0;
257 rtmp1=0;
258 rtmp2=0;
259 for (q=0;q<p.numQuadSub;q++) {
260 rtmp=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
261 rtmp0+=rtmp*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
262 rtmp1+=rtmp*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
263 rtmp2+=rtmp*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)];
264 }
265 for (k=0;k<p.numEqu;k++) {
266 for (m=0;m<p.numComp;m++) {
267 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp0*C_p[INDEX3(k,m,0,p.numEqu,p.numComp)]
268 +rtmp1*C_p[INDEX3(k,m,1,p.numEqu,p.numComp)]
269 +rtmp2*C_p[INDEX3(k,m,2,p.numEqu,p.numComp)];
270 }
271 }
272 }
273 }
274 }
275 }
276 /************************************************************* */
277 /* process D */
278 /**************************************************************/
279 if (NULL!=D_p) {
280 add_EM_S=TRUE;
281 if (extendedD) {
282 D_q=&(D_p[INDEX4(0,0,0,isub ,p.numEqu,p.numComp, p.numQuadSub)]);
283 for (s=0;s<p.row_numShapes;s++) {
284 for (r=0;r<p.col_numShapes;r++) {
285 for (k=0;k<p.numEqu;k++) {
286 for (m=0;m<p.numComp;m++) {
287 rtmp=0;
288 for (q=0;q<p.numQuadSub;q++) {
289 rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*D_q[INDEX3(k,m,q,p.numEqu,p.numComp)]*S[INDEX2(r,q,p.row_numShapes)];
290 }
291 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
292 }
293 }
294 }
295 }
296 } else {
297 for (s=0;s<p.row_numShapes;s++) {
298 for (r=0;r<p.col_numShapes;r++) {
299 rtmp=0;
300 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(r,q,p.row_numShapes)];
301 for (k=0;k<p.numEqu;k++) {
302 for (m=0;m<p.numComp;m++) {
303 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*D_p[INDEX2(k,m,p.numEqu)];
304 }
305 }
306 }
307 }
308 }
309 }
310 /**************************************************************/
311 /* process X: */
312 /**************************************************************/
313 if (NULL!=X_p) {
314 add_EM_F=TRUE;
315 if (extendedX) {
316 X_q=&(X_p[INDEX4(0,0,0,isub, p.numEqu,DIM,p.numQuadSub)]);
317 for (s=0;s<p.row_numShapes;s++) {
318 for (k=0;k<p.numEqu;k++) {
319 rtmp=0;
320 for (q=0;q<p.numQuadSub;q++) {
321 rtmp+=Vol[q]* ( DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*X_q[INDEX3(k,0,q,p.numEqu,DIM)]
322 + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*X_q[INDEX3(k,1,q,p.numEqu,DIM)]
323 + DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)]*X_q[INDEX3(k,2,q,p.numEqu,DIM)]);
324 }
325 EM_F[INDEX2(k,s,p.numEqu)]+=rtmp;
326 }
327 }
328 } else {
329 for (s=0;s<p.row_numShapes;s++) {
330 rtmp0=0;
331 rtmp1=0;
332 rtmp2=0;
333 for (q=0;q<p.numQuadSub;q++) {
334 rtmp0+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
335 rtmp1+=Vol[q]*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
336 rtmp2+=Vol[q]*DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)];
337 }
338 for (k=0;k<p.numEqu;k++) {
339 EM_F[INDEX2(k,s,p.numEqu)]+=rtmp0*X_p[INDEX2(k,0,p.numEqu)]
340 +rtmp1*X_p[INDEX2(k,1,p.numEqu)]
341 +rtmp2*X_p[INDEX2(k,2,p.numEqu)];
342 }
343 }
344 }
345 }
346 /**************************************************************/
347 /* process Y: */
348 /**************************************************************/
349 if (NULL!=Y_p) {
350 add_EM_F=TRUE;
351 if (extendedY) {
352 Y_q=&(Y_p[INDEX3(0,0,isub, p.numEqu,p.numQuadSub)]);
353 for (s=0;s<p.row_numShapes;s++) {
354 for (k=0;k<p.numEqu;k++) {
355 rtmp=0.;
356 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*Y_q[INDEX2(k,q,p.numEqu)];
357 EM_F[INDEX2(k,s,p.numEqu)]+=rtmp;
358 }
359 }
360 } else {
361 for (s=0;s<p.row_numShapes;s++) {
362 rtmp=0;
363 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
364 for (k=0;k<p.numEqu;k++) EM_F[INDEX2(k,s,p.numEqu)]+=rtmp*Y_p[k];
365 }
366 }
367 }
368
369 /***********************************************************************************************/
370 /* add the element matrices onto the matrix and right hand side */
371 /***********************************************************************************************/
372 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)]];
373
374 if (add_EM_F) Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
375 if (add_EM_S) Finley_Assemble_addToSystemMatrix(Mat,p.row_numShapesTotal,row_index,p.numEqu,p.col_numShapesTotal,row_index,p.numComp,EM_S);
376 } /* end of subn */
377 } /* end color check */
378 } /* end element loop */
379 } /* end color loop */
380
381 THREAD_MEMFREE(EM_S);
382 THREAD_MEMFREE(EM_F);
383 THREAD_MEMFREE(row_index);
384
385 } /* end of pointer check */
386 } /* end parallel region */
387 freeSampleBuffer(ABuff);
388 freeSampleBuffer(BBuff);
389 freeSampleBuffer(CBuff);
390 freeSampleBuffer(DBuff);
391 freeSampleBuffer(XBuff);
392 freeSampleBuffer(YBuff);
393 }

  ViewVC Help
Powered by ViewVC 1.1.26