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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3184 - (hide annotations)
Wed Sep 15 00:23:42 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: 19421 byte(s)
Removed volume from ElementFile_Jacobeans

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 ksteube 1811
15 gross 798 /**************************************************************/
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 2D 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 2 x p.numComp x 2 */
29     /* B = 2 x p.numEqu x p.numComp */
30     /* C = p.numEqu x 2 x p.numComp */
31     /* D = p.numEqu x p.numComp */
32     /* X = p.numEqu x 2 */
33     /* Y = p.numEqu */
34    
35    
36     /**************************************************************/
37    
38    
39     #include "Assemble.h"
40     #include "Util.h"
41 gross 853 #ifdef _OPENMP
42     #include <omp.h>
43     #endif
44 gross 798
45 gross 853
46 gross 798 /**************************************************************/
47    
48 jfenwick 3086 void Dudley_Assemble_PDE_System2_2D(Assemble_Parameters p, Dudley_ElementFile* elements,
49 gross 798 Paso_SystemMatrix* Mat, escriptDataC* F,
50     escriptDataC* A, escriptDataC* B, escriptDataC* C, escriptDataC* D, escriptDataC* X, escriptDataC* Y) {
51    
52     #define DIM 2
53     index_t color;
54 jfenwick 3136 dim_t e;
55 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;
56 jfenwick 3184 double *EM_S, *EM_F, *DSDX;
57 gross 853 index_t *row_index;
58     register dim_t q, s,r,k,m;
59     register double rtmp, rtmp0, rtmp1, rtmp00, rtmp10, rtmp01, rtmp11;
60     bool_t add_EM_F, add_EM_S;
61    
62 gross 798 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 jfenwick 2271 double *F_p=(requireWrite(F), getSampleDataRW(F,0)); /* use comma, to get around the mixed code and declarations thing */
69 gross 2748 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 gross 798
73 jfenwick 3136 #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)
74 gross 798 {
75 jfenwick 2271
76 gross 853 EM_S=THREAD_MEMALLOC(len_EM_S,double);
77     EM_F=THREAD_MEMALLOC(len_EM_F,double);
78 gross 2748 row_index=THREAD_MEMALLOC(p.row_numShapesTotal,index_t);
79 gross 853
80 jfenwick 3086 if (!Dudley_checkPtr(EM_S) && !Dudley_checkPtr(EM_F) && !Dudley_checkPtr(row_index) ) {
81 gross 798
82 gross 853 for (color=elements->minColor;color<=elements->maxColor;color++) {
83     /* open loop over all elements: */
84     #pragma omp for private(e) schedule(static)
85     for(e=0;e<elements->numElements;e++){
86     if (elements->Color[e]==color) {
87 gross 2748
88 jfenwick 2770 A_p=getSampleDataRO(A,e);
89     B_p=getSampleDataRO(B,e);
90     C_p=getSampleDataRO(C,e);
91     D_p=getSampleDataRO(D,e);
92     X_p=getSampleDataRO(X,e);
93     Y_p=getSampleDataRO(Y,e);
94 jfenwick 3184 double vol=p.row_jac->absD[e]*p.row_jac->quadweight;
95 jfenwick 3137 DSDX=&(p.row_jac->DSDX[INDEX5(0,0,0,0,e,p.row_numShapesTotal,DIM,p.numQuadTotal,1)]);
96 gross 2748 for (q=0;q<len_EM_S;++q) EM_S[q]=0;
97     for (q=0;q<len_EM_F;++q) EM_F[q]=0;
98     add_EM_F=FALSE;
99     add_EM_S=FALSE;
100    
101     /**************************************************************/
102     /* process A: */
103     /**************************************************************/
104 jfenwick 2770 A_p=getSampleDataRO(A,e);
105 gross 2748 if (NULL!=A_p) {
106     add_EM_S=TRUE;
107     if (extendedA) {
108 jfenwick 3137 A_q=&(A_p[INDEX6(0,0,0,0,0,0, p.numEqu,DIM,p.numComp,DIM,p.numQuadTotal)]);
109 gross 2748 for (s=0;s<p.row_numShapes;s++) {
110     for (r=0;r<p.col_numShapes;r++) {
111     for (k=0;k<p.numEqu;k++) {
112     for (m=0;m<p.numComp;m++) {
113     rtmp=0;
114 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) {
115 jfenwick 3184 rtmp+=vol* (
116 gross 2748 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)]
117     +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)]
118     +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)]
119     +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)]);
120     }
121     EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
122     }
123     }
124     }
125     }
126     } else {
127     for (s=0;s<p.row_numShapes;s++) {
128     for (r=0;r<p.col_numShapes;r++) {
129     rtmp00=0;
130     rtmp01=0;
131     rtmp10=0;
132     rtmp11=0;
133 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) {
134 jfenwick 3184 rtmp0=vol*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
135     rtmp1=vol*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
136 gross 2748 rtmp00+=rtmp0*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
137     rtmp01+=rtmp0*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
138     rtmp10+=rtmp1*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
139     rtmp11+=rtmp1*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
140 gross 853 }
141 gross 2748 for (k=0;k<p.numEqu;k++) {
142     for (m=0;m<p.numComp;m++) {
143     EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=
144     rtmp00*A_p[INDEX4(k,0,m,0,p.numEqu,DIM,p.numComp)]
145     +rtmp01*A_p[INDEX4(k,0,m,1,p.numEqu,DIM,p.numComp)]
146     +rtmp10*A_p[INDEX4(k,1,m,0,p.numEqu,DIM,p.numComp)]
147     +rtmp11*A_p[INDEX4(k,1,m,1,p.numEqu,DIM,p.numComp)];
148     }
149     }
150 gross 798 }
151 gross 2748 }
152     }
153     }
154     /**************************************************************/
155     /* process B: */
156     /**************************************************************/
157 jfenwick 2770 B_p=getSampleDataRO(B,e);
158 gross 2748 if (NULL!=B_p) {
159     add_EM_S=TRUE;
160     if (extendedB) {
161 jfenwick 3137 B_q=&(B_p[INDEX5(0,0,0,0,0 ,p.numEqu,DIM,p.numComp,p.numQuadTotal)]);
162 gross 2748 for (s=0;s<p.row_numShapes;s++) {
163     for (r=0;r<p.col_numShapes;r++) {
164     for (k=0;k<p.numEqu;k++) {
165 gross 853 for (m=0;m<p.numComp;m++) {
166 gross 2748 rtmp=0;
167 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) {
168 jfenwick 3184 rtmp+=vol*S[INDEX2(r,q,p.row_numShapes)]*
169 gross 2748 ( DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*B_q[INDEX4(k,0,m,q,p.numEqu,DIM,p.numComp)]
170     + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*B_q[INDEX4(k,1,m,q,p.numEqu,DIM,p.numComp)]);
171     }
172     EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
173 gross 853 }
174 gross 2748 }
175 gross 853 }
176 gross 2748 }
177     } else {
178     for (s=0;s<p.row_numShapes;s++) {
179     for (r=0;r<p.col_numShapes;r++) {
180     rtmp0=0;
181     rtmp1=0;
182 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) {
183 jfenwick 3184 rtmp=vol*S[INDEX2(r,q,p.row_numShapes)];
184 gross 2748 rtmp0+=rtmp*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
185     rtmp1+=rtmp*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
186 gross 853 }
187 gross 2748 for (k=0;k<p.numEqu;k++) {
188     for (m=0;m<p.numComp;m++) {
189     EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+= rtmp0*B_p[INDEX3(k,0,m,p.numEqu,DIM)]
190     + rtmp1*B_p[INDEX3(k,1,m,p.numEqu,DIM)];
191     }
192     }
193     }
194     }
195 gross 853 }
196 gross 2748 }
197     /**************************************************************/
198     /* process C: */
199     /**************************************************************/
200 jfenwick 2770 C_p=getSampleDataRO(C,e);
201 gross 2748 if (NULL!=C_p) {
202     add_EM_S=TRUE;
203     if (extendedC) {
204 jfenwick 3137 C_q=&(C_p[INDEX5(0,0,0,0,0, p.numEqu,p.numComp,DIM,p.numQuadTotal)]);
205 gross 2748 for (s=0;s<p.row_numShapes;s++) {
206     for (r=0;r<p.col_numShapes;r++) {
207     for (k=0;k<p.numEqu;k++) {
208 gross 853 for (m=0;m<p.numComp;m++) {
209 gross 2748 rtmp=0;
210 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) {
211 jfenwick 3184 rtmp+=vol*S[INDEX2(s,q,p.row_numShapes)]*
212 gross 2748 ( C_q[INDEX4(k,m,0,q,p.numEqu,p.numComp,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)]
213     + C_q[INDEX4(k,m,1,q,p.numEqu,p.numComp,DIM)]*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)]);
214     }
215     EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
216 gross 853 }
217 gross 2748 }
218     }
219     }
220     } else {
221     for (s=0;s<p.row_numShapes;s++) {
222     for (r=0;r<p.col_numShapes;r++) {
223     rtmp0=0;
224     rtmp1=0;
225 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) {
226 jfenwick 3184 rtmp=vol*S[INDEX2(s,q,p.row_numShapes)];
227 gross 2748 rtmp0+=rtmp*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
228     rtmp1+=rtmp*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
229     }
230     for (k=0;k<p.numEqu;k++) {
231     for (m=0;m<p.numComp;m++) {
232     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)]
233     +rtmp1*C_p[INDEX3(k,m,1,p.numEqu,p.numComp)];
234     }
235     }
236     }
237     }
238     }
239 gross 798 }
240 gross 2748 /************************************************************* */
241     /* process D */
242     /**************************************************************/
243 jfenwick 2770 D_p=getSampleDataRO(D,e);
244 gross 2748 if (NULL!=D_p) {
245     add_EM_S=TRUE;
246     if (extendedD) {
247 jfenwick 3137 D_q=&(D_p[INDEX4(0,0,0,0, p.numEqu,p.numComp,p.numQuadTotal)]);
248 gross 2748 for (s=0;s<p.row_numShapes;s++) {
249     for (r=0;r<p.col_numShapes;r++) {
250     for (k=0;k<p.numEqu;k++) {
251     for (m=0;m<p.numComp;m++) {
252     rtmp=0;
253 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) {
254 jfenwick 3184 rtmp+=vol*S[INDEX2(s,q,p.row_numShapes)]*D_q[INDEX3(k,m,q,p.numEqu,p.numComp)]*S[INDEX2(r,q,p.row_numShapes)];
255 gross 2748 }
256     EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
257     }
258     }
259     }
260     }
261     } else {
262     for (s=0;s<p.row_numShapes;s++) {
263     for (r=0;r<p.col_numShapes;r++) {
264 gross 853 rtmp=0;
265 jfenwick 3184 for (q=0;q<p.numQuadTotal;q++) rtmp+=vol*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(r,q,p.row_numShapes)];
266 gross 2748 for (k=0;k<p.numEqu;k++) {
267     for (m=0;m<p.numComp;m++) {
268     EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*D_p[INDEX2(k,m,p.numEqu)];
269     }
270 gross 853 }
271     }
272 gross 2748 }
273     }
274     }
275     /**************************************************************/
276     /* process X: */
277     /**************************************************************/
278 jfenwick 2770 X_p=getSampleDataRO(X,e);
279 gross 2748 if (NULL!=X_p) {
280     add_EM_F=TRUE;
281     if (extendedX) {
282 jfenwick 3137 X_q=&(X_p[INDEX4(0,0,0,0, p.numEqu,DIM,p.numQuadTotal)]);
283 gross 2748 for (s=0;s<p.row_numShapes;s++) {
284 gross 853 for (k=0;k<p.numEqu;k++) {
285 gross 2748 rtmp=0;
286 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) {
287 jfenwick 3184 rtmp+=vol*(DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*X_q[INDEX3(k,0,q,p.numEqu,DIM)]
288 gross 2748 +DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*X_q[INDEX3(k,1,q,p.numEqu,DIM)]);
289     }
290     EM_F[INDEX2(k,s,p.numEqu)]+=rtmp;
291 gross 853 }
292     }
293 gross 2748 } else {
294     for (s=0;s<p.row_numShapes;s++) {
295     rtmp0=0;
296     rtmp1=0;
297 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) {
298 jfenwick 3184 rtmp0+=vol*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
299     rtmp1+=vol*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
300 gross 2748 }
301     for (k=0;k<p.numEqu;k++) EM_F[INDEX2(k,s,p.numEqu)]+=rtmp0*X_p[INDEX2(k,0,p.numEqu)]+rtmp1*X_p[INDEX2(k,1,p.numEqu)];
302     }
303     }
304 gross 853 }
305 gross 2748 /**************************************************************/
306     /* process Y: */
307     /**************************************************************/
308 jfenwick 2770 Y_p=getSampleDataRO(Y,e);
309 gross 2748 if (NULL!=Y_p) {
310     add_EM_F=TRUE;
311     if (extendedY) {
312 jfenwick 3137 Y_q=&(Y_p[INDEX3(0,0,0, p.numEqu,p.numQuadTotal)]);
313 gross 2748 for (s=0;s<p.row_numShapes;s++) {
314     for (k=0;k<p.numEqu;k++) {
315 gross 853 rtmp=0;
316 jfenwick 3184 for (q=0;q<p.numQuadTotal;q++) rtmp+=vol*S[INDEX2(s,q,p.row_numShapes)]*Y_q[INDEX2(k,q,p.numEqu)];
317 gross 2748 EM_F[INDEX2(k,s,p.numEqu)]+=rtmp;
318     }
319 gross 853 }
320 gross 2748 } else {
321     for (s=0;s<p.row_numShapes;s++) {
322 gross 798 rtmp=0;
323 jfenwick 3184 for (q=0;q<p.numQuadTotal;q++) rtmp+=vol*S[INDEX2(s,q,p.row_numShapes)];
324 gross 2748 for (k=0;k<p.numEqu;k++) EM_F[INDEX2(k,s,p.numEqu)]+=rtmp*Y_p[k];
325 gross 798 }
326 gross 853 }
327 gross 2748 }
328     /***********************************************************************************************/
329     /* add the element matrices onto the matrix and right hand side */
330     /***********************************************************************************************/
331 jfenwick 3144 for (q=0;q<p.row_numShapesTotal;q++) row_index[q]=p.row_DOF[elements->Nodes[INDEX2(q,e,p.NN)]];
332 gross 2748
333 jfenwick 3086 if (add_EM_F) Dudley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
334     if (add_EM_S) Dudley_Assemble_addToSystemMatrix(Mat,p.row_numShapesTotal,row_index,p.numEqu,p.col_numShapesTotal,row_index,p.numComp,EM_S);
335 gross 2748
336 gross 853 } /* end color check */
337     } /* end element loop */
338     } /* end color loop */
339    
340     THREAD_MEMFREE(EM_S);
341     THREAD_MEMFREE(EM_F);
342     THREAD_MEMFREE(row_index);
343 gross 798
344 gross 853 } /* end of pointer check */
345 gross 798 } /* end parallel region */
346     }
347     /*
348     * $Log$
349     */

  ViewVC Help
Powered by ViewVC 1.1.26