/[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 3247 - (hide annotations)
Wed Oct 6 05:53:06 2010 UTC (8 years, 9 months ago) by caltinay
Original Path: branches/domexper/dudley/src/Assemble_PDE_System2_2D.c
File MIME type: text/plain
File size: 14334 byte(s)
Fixed name clashes between dudley and finley so both can be used
simultaneously.

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

  ViewVC Help
Powered by ViewVC 1.1.26