/[escript]/branches/trilinos_from_5897/dudley/src/Assemble_PDE_System2_2D.cpp
ViewVC logotype

Annotation of /branches/trilinos_from_5897/dudley/src/Assemble_PDE_System2_2D.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3205 - (hide annotations)
Fri Sep 24 00:30:43 2010 UTC (8 years, 9 months ago) by jfenwick
Original Path: branches/domexper/dudley/src/Assemble_PDE_System2_2D.c
File MIME type: text/plain
File size: 14406 byte(s)
Removing -total from field names

1 gross 798
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 gross 798 /**************************************************************/
15    
16     /* assembles the system of numEq PDEs into the stiffness matrix S right hand side F */
17     /* the shape functions for test and solution must be identical */
18    
19     /* -(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 */
20    
21     /* u has p.numComp components in a 2D domain. The shape functions for test and solution must be identical */
22     /* and row_NS == row_NN */
23    
24     /* Shape of the coefficients: */
25    
26     /* A = p.numEqu x 2 x p.numComp x 2 */
27     /* B = 2 x p.numEqu x p.numComp */
28     /* C = p.numEqu x 2 x p.numComp */
29     /* D = p.numEqu x p.numComp */
30     /* X = p.numEqu x 2 */
31     /* Y = p.numEqu */
32    
33     /**************************************************************/
34    
35     #include "Assemble.h"
36     #include "Util.h"
37 gross 853 #ifdef _OPENMP
38     #include <omp.h>
39     #endif
40 gross 798
41     /**************************************************************/
42    
43 jfenwick 3187 void Dudley_Assemble_PDE_System2_2D(Assemble_Parameters p, Dudley_ElementFile * elements,
44     Paso_SystemMatrix * Mat, escriptDataC * F,
45     escriptDataC * A, escriptDataC * B, escriptDataC * C, escriptDataC * D,
46     escriptDataC * X, escriptDataC * Y)
47     {
48 gross 798
49 jfenwick 3187 #define DIM 2
50 gross 798 index_t color;
51 jfenwick 3136 dim_t e;
52 gross 2748 __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;
53 jfenwick 3187 double *EM_S, *EM_F, *DSDX;
54 gross 853 index_t *row_index;
55 jfenwick 3187 register dim_t q, s, r, k, m;
56 gross 853 register double rtmp, rtmp0, rtmp1, rtmp00, rtmp10, rtmp01, rtmp11;
57     bool_t add_EM_F, add_EM_S;
58    
59 jfenwick 3187 bool_t extendedA = isExpanded(A);
60     bool_t extendedB = isExpanded(B);
61     bool_t extendedC = isExpanded(C);
62     bool_t extendedD = isExpanded(D);
63     bool_t extendedX = isExpanded(X);
64     bool_t extendedY = isExpanded(Y);
65     double *F_p = (requireWrite(F), getSampleDataRW(F, 0)); /* use comma, to get around the mixed code and declarations thing */
66 jfenwick 3202 // double *S = p.row_jac->BasisFunctions->S;
67     const double* S = p.shapeFns;
68 jfenwick 3204 dim_t len_EM_S = p.numShapes * p.numShapes * p.numEqu * p.numComp;
69     dim_t len_EM_F = p.numShapes * p.numEqu;
70 gross 798
71 jfenwick 3187 #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, rtmp00, rtmp10, rtmp01, rtmp11,add_EM_F, add_EM_S)
72 gross 798 {
73 jfenwick 2271
74 jfenwick 3187 EM_S = THREAD_MEMALLOC(len_EM_S, double);
75     EM_F = THREAD_MEMALLOC(len_EM_F, double);
76 jfenwick 3204 row_index = THREAD_MEMALLOC(p.numShapes, index_t);
77 gross 798
78 jfenwick 3187 if (!Dudley_checkPtr(EM_S) && !Dudley_checkPtr(EM_F) && !Dudley_checkPtr(row_index))
79     {
80 gross 2748
81 jfenwick 3187 for (color = elements->minColor; color <= elements->maxColor; color++)
82     {
83     /* open loop over all elements: */
84     #pragma omp for private(e) schedule(static)
85     for (e = 0; e < elements->numElements; e++)
86     {
87     if (elements->Color[e] == color)
88     {
89 gross 2748
90 jfenwick 3187 A_p = getSampleDataRO(A, e);
91     B_p = getSampleDataRO(B, e);
92     C_p = getSampleDataRO(C, e);
93     D_p = getSampleDataRO(D, e);
94     X_p = getSampleDataRO(X, e);
95     Y_p = getSampleDataRO(Y, e);
96     double vol = p.row_jac->absD[e] * p.row_jac->quadweight;
97 jfenwick 3205 DSDX = &(p.row_jac->DSDX[INDEX5(0, 0, 0, 0, e, p.numShapes, DIM, p.numQuad, 1)]);
98 jfenwick 3187 for (q = 0; q < len_EM_S; ++q)
99     EM_S[q] = 0;
100     for (q = 0; q < len_EM_F; ++q)
101     EM_F[q] = 0;
102     add_EM_F = FALSE;
103     add_EM_S = FALSE;
104 gross 2748
105 jfenwick 3187 /**************************************************************/
106     /* process A: */
107     /**************************************************************/
108     A_p = getSampleDataRO(A, e);
109     if (NULL != A_p)
110     {
111     add_EM_S = TRUE;
112     if (extendedA)
113     {
114 jfenwick 3205 A_q = &(A_p[INDEX6(0, 0, 0, 0, 0, 0, p.numEqu, DIM, p.numComp, DIM, p.numQuad)]);
115 jfenwick 3204 for (s = 0; s < p.numShapes; s++)
116 jfenwick 3187 {
117 jfenwick 3204 for (r = 0; r < p.numShapes; r++)
118 jfenwick 3187 {
119     for (k = 0; k < p.numEqu; k++)
120     {
121     for (m = 0; m < p.numComp; m++)
122     {
123     rtmp = 0;
124 jfenwick 3205 for (q = 0; q < p.numQuad; q++)
125 jfenwick 3187 {
126     rtmp +=
127 jfenwick 3204 vol * (DSDX[INDEX3(s, 0, q, p.numShapes, DIM)] *
128 jfenwick 3187 A_q[INDEX5(k, 0, m, 0, q, p.numEqu, DIM, p.numComp, DIM)]
129 jfenwick 3204 * DSDX[INDEX3(r, 0, q, p.numShapes, DIM)] +
130     DSDX[INDEX3(s, 0, q, p.numShapes, DIM)] *
131 jfenwick 3187 A_q[INDEX5(k, 0, m, 1, q, p.numEqu, DIM, p.numComp, DIM)]
132 jfenwick 3204 * DSDX[INDEX3(r, 1, q, p.numShapes, DIM)] +
133     DSDX[INDEX3(s, 1, q, p.numShapes, DIM)] *
134 jfenwick 3187 A_q[INDEX5(k, 1, m, 0, q, p.numEqu, DIM, p.numComp, DIM)]
135 jfenwick 3204 * DSDX[INDEX3(r, 0, q, p.numShapes, DIM)] +
136     DSDX[INDEX3(s, 1, q, p.numShapes, DIM)] *
137 jfenwick 3187 A_q[INDEX5(k, 1, m, 1, q, p.numEqu, DIM, p.numComp, DIM)]
138 jfenwick 3204 * DSDX[INDEX3(r, 1, q, p.numShapes, DIM)]);
139 jfenwick 3187 }
140 jfenwick 3204 EM_S[INDEX4(k, m, s, r, p.numEqu, p.numComp, p.numShapes)] +=
141 jfenwick 3187 rtmp;
142     }
143     }
144     }
145     }
146     } else
147     {
148 jfenwick 3204 for (s = 0; s < p.numShapes; s++)
149 jfenwick 3187 {
150 jfenwick 3204 for (r = 0; r < p.numShapes; r++)
151 jfenwick 3187 {
152     rtmp00 = 0;
153     rtmp01 = 0;
154     rtmp10 = 0;
155     rtmp11 = 0;
156 jfenwick 3205 for (q = 0; q < p.numQuad; q++)
157 jfenwick 3187 {
158 jfenwick 3204 rtmp0 = vol * DSDX[INDEX3(s, 0, q, p.numShapes, DIM)];
159     rtmp1 = vol * DSDX[INDEX3(s, 1, q, p.numShapes, DIM)];
160     rtmp00 += rtmp0 * DSDX[INDEX3(r, 0, q, p.numShapes, DIM)];
161     rtmp01 += rtmp0 * DSDX[INDEX3(r, 1, q, p.numShapes, DIM)];
162     rtmp10 += rtmp1 * DSDX[INDEX3(r, 0, q, p.numShapes, DIM)];
163     rtmp11 += rtmp1 * DSDX[INDEX3(r, 1, q, p.numShapes, DIM)];
164 jfenwick 3187 }
165     for (k = 0; k < p.numEqu; k++)
166     {
167     for (m = 0; m < p.numComp; m++)
168     {
169 jfenwick 3204 EM_S[INDEX4(k, m, s, r, p.numEqu, p.numComp, p.numShapes)] +=
170 jfenwick 3187 rtmp00 * A_p[INDEX4(k, 0, m, 0, p.numEqu, DIM, p.numComp)]
171     + rtmp01 * A_p[INDEX4(k, 0, m, 1, 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     }
175     }
176     }
177     }
178     }
179     }
180     /**************************************************************/
181     /* process B: */
182     /**************************************************************/
183     B_p = getSampleDataRO(B, e);
184     if (NULL != B_p)
185     {
186     add_EM_S = TRUE;
187     if (extendedB)
188     {
189 jfenwick 3205 B_q = &(B_p[INDEX5(0, 0, 0, 0, 0, p.numEqu, DIM, p.numComp, p.numQuad)]);
190 jfenwick 3204 for (s = 0; s < p.numShapes; s++)
191 jfenwick 3187 {
192 jfenwick 3204 for (r = 0; r < p.numShapes; r++)
193 jfenwick 3187 {
194     for (k = 0; k < p.numEqu; k++)
195     {
196     for (m = 0; m < p.numComp; m++)
197     {
198     rtmp = 0;
199 jfenwick 3205 for (q = 0; q < p.numQuad; q++)
200 jfenwick 3187 {
201 jfenwick 3204 rtmp += vol * S[INDEX2(r, q, p.numShapes)] *
202     (DSDX[INDEX3(s, 0, q, p.numShapes, DIM)] *
203 jfenwick 3187 B_q[INDEX4(k, 0, m, q, p.numEqu, DIM, p.numComp)] +
204 jfenwick 3204 DSDX[INDEX3(s, 1, q, p.numShapes, DIM)] *
205 jfenwick 3187 B_q[INDEX4(k, 1, m, q, p.numEqu, DIM, p.numComp)]);
206     }
207 jfenwick 3204 EM_S[INDEX4(k, m, s, r, p.numEqu, p.numComp, p.numShapes)] +=
208 jfenwick 3187 rtmp;
209     }
210     }
211     }
212     }
213     } else
214     {
215 jfenwick 3204 for (s = 0; s < p.numShapes; s++)
216 jfenwick 3187 {
217 jfenwick 3204 for (r = 0; r < p.numShapes; r++)
218 jfenwick 3187 {
219     rtmp0 = 0;
220     rtmp1 = 0;
221 jfenwick 3205 for (q = 0; q < p.numQuad; q++)
222 jfenwick 3187 {
223 jfenwick 3204 rtmp = vol * S[INDEX2(r, q, p.numShapes)];
224     rtmp0 += rtmp * DSDX[INDEX3(s, 0, q, p.numShapes, DIM)];
225     rtmp1 += rtmp * DSDX[INDEX3(s, 1, q, p.numShapes, DIM)];
226 jfenwick 3187 }
227     for (k = 0; k < p.numEqu; k++)
228     {
229     for (m = 0; m < p.numComp; m++)
230     {
231 jfenwick 3204 EM_S[INDEX4(k, m, s, r, p.numEqu, p.numComp, p.numShapes)] +=
232 jfenwick 3187 rtmp0 * B_p[INDEX3(k, 0, m, p.numEqu, DIM)] +
233     rtmp1 * B_p[INDEX3(k, 1, m, p.numEqu, DIM)];
234     }
235     }
236     }
237     }
238     }
239     }
240     /**************************************************************/
241     /* process C: */
242     /**************************************************************/
243     C_p = getSampleDataRO(C, e);
244     if (NULL != C_p)
245     {
246     add_EM_S = TRUE;
247     if (extendedC)
248     {
249 jfenwick 3205 C_q = &(C_p[INDEX5(0, 0, 0, 0, 0, p.numEqu, p.numComp, DIM, p.numQuad)]);
250 jfenwick 3204 for (s = 0; s < p.numShapes; s++)
251 jfenwick 3187 {
252 jfenwick 3204 for (r = 0; r < p.numShapes; r++)
253 jfenwick 3187 {
254     for (k = 0; k < p.numEqu; k++)
255     {
256     for (m = 0; m < p.numComp; m++)
257     {
258     rtmp = 0;
259 jfenwick 3205 for (q = 0; q < p.numQuad; q++)
260 jfenwick 3187 {
261 jfenwick 3204 rtmp += vol * S[INDEX2(s, q, p.numShapes)] *
262 jfenwick 3187 (C_q[INDEX4(k, m, 0, q, p.numEqu, p.numComp, DIM)] *
263 jfenwick 3204 DSDX[INDEX3(r, 0, q, p.numShapes, DIM)] +
264 jfenwick 3187 C_q[INDEX4(k, m, 1, q, p.numEqu, p.numComp, DIM)] *
265 jfenwick 3204 DSDX[INDEX3(r, 1, q, p.numShapes, DIM)]);
266 jfenwick 3187 }
267 jfenwick 3204 EM_S[INDEX4(k, m, s, r, p.numEqu, p.numComp, p.numShapes)] +=
268 jfenwick 3187 rtmp;
269     }
270     }
271     }
272     }
273     } else
274     {
275 jfenwick 3204 for (s = 0; s < p.numShapes; s++)
276 jfenwick 3187 {
277 jfenwick 3204 for (r = 0; r < p.numShapes; r++)
278 jfenwick 3187 {
279     rtmp0 = 0;
280     rtmp1 = 0;
281 jfenwick 3205 for (q = 0; q < p.numQuad; q++)
282 jfenwick 3187 {
283 jfenwick 3204 rtmp = vol * S[INDEX2(s, q, p.numShapes)];
284     rtmp0 += rtmp * DSDX[INDEX3(r, 0, q, p.numShapes, DIM)];
285     rtmp1 += rtmp * DSDX[INDEX3(r, 1, q, p.numShapes, DIM)];
286 jfenwick 3187 }
287     for (k = 0; k < p.numEqu; k++)
288     {
289     for (m = 0; m < p.numComp; m++)
290     {
291 jfenwick 3204 EM_S[INDEX4(k, m, s, r, p.numEqu, p.numComp, p.numShapes)] +=
292 jfenwick 3187 rtmp0 * C_p[INDEX3(k, m, 0, p.numEqu, p.numComp)] +
293     rtmp1 * C_p[INDEX3(k, m, 1, p.numEqu, p.numComp)];
294     }
295     }
296     }
297     }
298     }
299     }
300     /************************************************************* */
301     /* process D */
302     /**************************************************************/
303     D_p = getSampleDataRO(D, e);
304     if (NULL != D_p)
305     {
306     add_EM_S = TRUE;
307     if (extendedD)
308     {
309 jfenwick 3205 D_q = &(D_p[INDEX4(0, 0, 0, 0, p.numEqu, p.numComp, p.numQuad)]);
310 jfenwick 3204 for (s = 0; s < p.numShapes; s++)
311 jfenwick 3187 {
312 jfenwick 3204 for (r = 0; r < p.numShapes; r++)
313 jfenwick 3187 {
314     for (k = 0; k < p.numEqu; k++)
315     {
316     for (m = 0; m < p.numComp; m++)
317     {
318     rtmp = 0;
319 jfenwick 3205 for (q = 0; q < p.numQuad; q++)
320 jfenwick 3187 {
321     rtmp +=
322 jfenwick 3204 vol * S[INDEX2(s, q, p.numShapes)] *
323 jfenwick 3187 D_q[INDEX3(k, m, q, p.numEqu, p.numComp)] *
324 jfenwick 3204 S[INDEX2(r, q, p.numShapes)];
325 jfenwick 3187 }
326 jfenwick 3204 EM_S[INDEX4(k, m, s, r, p.numEqu, p.numComp, p.numShapes)] +=
327 jfenwick 3187 rtmp;
328     }
329     }
330     }
331     }
332     } else
333     {
334 jfenwick 3204 for (s = 0; s < p.numShapes; s++)
335 jfenwick 3187 {
336 jfenwick 3204 for (r = 0; r < p.numShapes; r++)
337 jfenwick 3187 {
338     rtmp = 0;
339 jfenwick 3205 for (q = 0; q < p.numQuad; q++)
340 jfenwick 3187 rtmp +=
341 jfenwick 3204 vol * S[INDEX2(s, q, p.numShapes)] *
342     S[INDEX2(r, q, p.numShapes)];
343 jfenwick 3187 for (k = 0; k < p.numEqu; k++)
344     {
345     for (m = 0; m < p.numComp; m++)
346     {
347 jfenwick 3204 EM_S[INDEX4(k, m, s, r, p.numEqu, p.numComp, p.numShapes)] +=
348 jfenwick 3187 rtmp * D_p[INDEX2(k, m, p.numEqu)];
349     }
350     }
351     }
352     }
353     }
354     }
355     /**************************************************************/
356     /* process X: */
357     /**************************************************************/
358     X_p = getSampleDataRO(X, e);
359     if (NULL != X_p)
360     {
361     add_EM_F = TRUE;
362     if (extendedX)
363     {
364 jfenwick 3205 X_q = &(X_p[INDEX4(0, 0, 0, 0, p.numEqu, DIM, p.numQuad)]);
365 jfenwick 3204 for (s = 0; s < p.numShapes; s++)
366 jfenwick 3187 {
367     for (k = 0; k < p.numEqu; k++)
368     {
369     rtmp = 0;
370 jfenwick 3205 for (q = 0; q < p.numQuad; q++)
371 jfenwick 3187 {
372     rtmp +=
373 jfenwick 3204 vol * (DSDX[INDEX3(s, 0, q, p.numShapes, DIM)] *
374 jfenwick 3187 X_q[INDEX3(k, 0, q, p.numEqu, DIM)] +
375 jfenwick 3204 DSDX[INDEX3(s, 1, q, p.numShapes, DIM)] *
376 jfenwick 3187 X_q[INDEX3(k, 1, q, p.numEqu, DIM)]);
377     }
378     EM_F[INDEX2(k, s, p.numEqu)] += rtmp;
379     }
380     }
381     } else
382     {
383 jfenwick 3204 for (s = 0; s < p.numShapes; s++)
384 jfenwick 3187 {
385     rtmp0 = 0;
386     rtmp1 = 0;
387 jfenwick 3205 for (q = 0; q < p.numQuad; q++)
388 jfenwick 3187 {
389 jfenwick 3204 rtmp0 += vol * DSDX[INDEX3(s, 0, q, p.numShapes, DIM)];
390     rtmp1 += vol * DSDX[INDEX3(s, 1, q, p.numShapes, DIM)];
391 jfenwick 3187 }
392     for (k = 0; k < p.numEqu; k++)
393     EM_F[INDEX2(k, s, p.numEqu)] +=
394     rtmp0 * X_p[INDEX2(k, 0, p.numEqu)] + rtmp1 * X_p[INDEX2(k, 1, p.numEqu)];
395     }
396     }
397     }
398     /**************************************************************/
399     /* process Y: */
400     /**************************************************************/
401     Y_p = getSampleDataRO(Y, e);
402     if (NULL != Y_p)
403     {
404     add_EM_F = TRUE;
405     if (extendedY)
406     {
407 jfenwick 3205 Y_q = &(Y_p[INDEX3(0, 0, 0, p.numEqu, p.numQuad)]);
408 jfenwick 3204 for (s = 0; s < p.numShapes; s++)
409 jfenwick 3187 {
410     for (k = 0; k < p.numEqu; k++)
411     {
412     rtmp = 0;
413 jfenwick 3205 for (q = 0; q < p.numQuad; q++)
414 jfenwick 3187 rtmp +=
415 jfenwick 3204 vol * S[INDEX2(s, q, p.numShapes)] * Y_q[INDEX2(k, q, p.numEqu)];
416 jfenwick 3187 EM_F[INDEX2(k, s, p.numEqu)] += rtmp;
417     }
418     }
419     } else
420     {
421 jfenwick 3204 for (s = 0; s < p.numShapes; s++)
422 jfenwick 3187 {
423     rtmp = 0;
424 jfenwick 3205 for (q = 0; q < p.numQuad; q++)
425 jfenwick 3204 rtmp += vol * S[INDEX2(s, q, p.numShapes)];
426 jfenwick 3187 for (k = 0; k < p.numEqu; k++)
427     EM_F[INDEX2(k, s, p.numEqu)] += rtmp * Y_p[k];
428     }
429     }
430     }
431     /***********************************************************************************************/
432     /* add the element matrices onto the matrix and right hand side */
433     /***********************************************************************************************/
434 jfenwick 3204 for (q = 0; q < p.numShapes; q++)
435 jfenwick 3187 row_index[q] = p.row_DOF[elements->Nodes[INDEX2(q, e, p.NN)]];
436 gross 798
437 jfenwick 3187 if (add_EM_F)
438 jfenwick 3204 Dudley_Util_AddScatter(p.numShapes, row_index, p.numEqu, EM_F, F_p,
439 jfenwick 3187 p.row_DOF_UpperBound);
440     if (add_EM_S)
441 jfenwick 3204 Dudley_Assemble_addToSystemMatrix(Mat, p.numShapes, row_index, p.numEqu,
442     p.numShapes, row_index, p.numComp, EM_S);
443 jfenwick 3187
444     } /* end color check */
445     } /* end element loop */
446     } /* end color loop */
447    
448     THREAD_MEMFREE(EM_S);
449     THREAD_MEMFREE(EM_F);
450     THREAD_MEMFREE(row_index);
451    
452     } /* end of pointer check */
453     } /* end parallel region */
454 gross 798 }
455 jfenwick 3187
456 gross 798 /*
457     * $Log$
458     */

  ViewVC Help
Powered by ViewVC 1.1.26