/[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 3080 - (hide annotations)
Tue Aug 3 04:28:03 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: 19647 byte(s)
inital rename
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     void Finley_Assemble_PDE_System2_2D(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 2
53     index_t color;
54 gross 2748 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 jfenwick 2271 double *EM_S, *EM_F, *Vol, *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 gross 2748 #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, isub)
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     if (!Finley_checkPtr(EM_S) && !Finley_checkPtr(EM_F) && !Finley_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 gross 2748
95     for (isub=0; isub<p.numSub; isub++) {
96    
97     Vol=&(p.row_jac->volume[INDEX3(0,isub,e, p.numQuadSub,p.numSub)]);
98     DSDX=&(p.row_jac->DSDX[INDEX5(0,0,0,isub,e,p.row_numShapesTotal,DIM,p.numQuadSub,p.numSub)]);
99     for (q=0;q<len_EM_S;++q) EM_S[q]=0;
100     for (q=0;q<len_EM_F;++q) EM_F[q]=0;
101     add_EM_F=FALSE;
102     add_EM_S=FALSE;
103    
104     /**************************************************************/
105     /* process A: */
106     /**************************************************************/
107 jfenwick 2770 A_p=getSampleDataRO(A,e);
108 gross 2748 if (NULL!=A_p) {
109     add_EM_S=TRUE;
110     if (extendedA) {
111     A_q=&(A_p[INDEX6(0,0,0,0,0,isub, p.numEqu,DIM,p.numComp,DIM,p.numQuadSub)]);
112     for (s=0;s<p.row_numShapes;s++) {
113     for (r=0;r<p.col_numShapes;r++) {
114     for (k=0;k<p.numEqu;k++) {
115     for (m=0;m<p.numComp;m++) {
116     rtmp=0;
117     for (q=0;q<p.numQuadSub;q++) {
118     rtmp+=Vol[q]* (
119     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)]
120     +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)]
121     +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)]
122     +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)]);
123     }
124     EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
125     }
126     }
127     }
128     }
129     } else {
130     for (s=0;s<p.row_numShapes;s++) {
131     for (r=0;r<p.col_numShapes;r++) {
132     rtmp00=0;
133     rtmp01=0;
134     rtmp10=0;
135     rtmp11=0;
136     for (q=0;q<p.numQuadSub;q++) {
137     rtmp0=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
138     rtmp1=Vol[q]*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
139     rtmp00+=rtmp0*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
140     rtmp01+=rtmp0*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
141     rtmp10+=rtmp1*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
142     rtmp11+=rtmp1*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
143 gross 853 }
144 gross 2748 for (k=0;k<p.numEqu;k++) {
145     for (m=0;m<p.numComp;m++) {
146     EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=
147     rtmp00*A_p[INDEX4(k,0,m,0,p.numEqu,DIM,p.numComp)]
148     +rtmp01*A_p[INDEX4(k,0,m,1,p.numEqu,DIM,p.numComp)]
149     +rtmp10*A_p[INDEX4(k,1,m,0,p.numEqu,DIM,p.numComp)]
150     +rtmp11*A_p[INDEX4(k,1,m,1,p.numEqu,DIM,p.numComp)];
151     }
152     }
153 gross 798 }
154 gross 2748 }
155     }
156     }
157     /**************************************************************/
158     /* process B: */
159     /**************************************************************/
160 jfenwick 2770 B_p=getSampleDataRO(B,e);
161 gross 2748 if (NULL!=B_p) {
162     add_EM_S=TRUE;
163     if (extendedB) {
164     B_q=&(B_p[INDEX5(0,0,0,0,isub ,p.numEqu,DIM,p.numComp,p.numQuadSub)]);
165     for (s=0;s<p.row_numShapes;s++) {
166     for (r=0;r<p.col_numShapes;r++) {
167     for (k=0;k<p.numEqu;k++) {
168 gross 853 for (m=0;m<p.numComp;m++) {
169 gross 2748 rtmp=0;
170     for (q=0;q<p.numQuadSub;q++) {
171     rtmp+=Vol[q]*S[INDEX2(r,q,p.row_numShapes)]*
172     ( DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*B_q[INDEX4(k,0,m,q,p.numEqu,DIM,p.numComp)]
173     + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*B_q[INDEX4(k,1,m,q,p.numEqu,DIM,p.numComp)]);
174     }
175     EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
176 gross 853 }
177 gross 2748 }
178 gross 853 }
179 gross 2748 }
180     } else {
181     for (s=0;s<p.row_numShapes;s++) {
182     for (r=0;r<p.col_numShapes;r++) {
183     rtmp0=0;
184     rtmp1=0;
185     for (q=0;q<p.numQuadSub;q++) {
186     rtmp=Vol[q]*S[INDEX2(r,q,p.row_numShapes)];
187     rtmp0+=rtmp*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
188     rtmp1+=rtmp*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
189 gross 853 }
190 gross 2748 for (k=0;k<p.numEqu;k++) {
191     for (m=0;m<p.numComp;m++) {
192     EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+= rtmp0*B_p[INDEX3(k,0,m,p.numEqu,DIM)]
193     + rtmp1*B_p[INDEX3(k,1,m,p.numEqu,DIM)];
194     }
195     }
196     }
197     }
198 gross 853 }
199 gross 2748 }
200     /**************************************************************/
201     /* process C: */
202     /**************************************************************/
203 jfenwick 2770 C_p=getSampleDataRO(C,e);
204 gross 2748 if (NULL!=C_p) {
205     add_EM_S=TRUE;
206     if (extendedC) {
207     C_q=&(C_p[INDEX5(0,0,0,0,isub, p.numEqu,p.numComp,DIM,p.numQuadSub)]);
208     for (s=0;s<p.row_numShapes;s++) {
209     for (r=0;r<p.col_numShapes;r++) {
210     for (k=0;k<p.numEqu;k++) {
211 gross 853 for (m=0;m<p.numComp;m++) {
212 gross 2748 rtmp=0;
213     for (q=0;q<p.numQuadSub;q++) {
214     rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*
215     ( C_q[INDEX4(k,m,0,q,p.numEqu,p.numComp,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)]
216     + C_q[INDEX4(k,m,1,q,p.numEqu,p.numComp,DIM)]*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)]);
217     }
218     EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
219 gross 853 }
220 gross 2748 }
221     }
222     }
223     } else {
224     for (s=0;s<p.row_numShapes;s++) {
225     for (r=0;r<p.col_numShapes;r++) {
226     rtmp0=0;
227     rtmp1=0;
228     for (q=0;q<p.numQuadSub;q++) {
229     rtmp=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
230     rtmp0+=rtmp*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
231     rtmp1+=rtmp*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
232     }
233     for (k=0;k<p.numEqu;k++) {
234     for (m=0;m<p.numComp;m++) {
235     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)]
236     +rtmp1*C_p[INDEX3(k,m,1,p.numEqu,p.numComp)];
237     }
238     }
239     }
240     }
241     }
242 gross 798 }
243 gross 2748 /************************************************************* */
244     /* process D */
245     /**************************************************************/
246 jfenwick 2770 D_p=getSampleDataRO(D,e);
247 gross 2748 if (NULL!=D_p) {
248     add_EM_S=TRUE;
249     if (extendedD) {
250     D_q=&(D_p[INDEX4(0,0,0,isub, p.numEqu,p.numComp,p.numQuadSub)]);
251     for (s=0;s<p.row_numShapes;s++) {
252     for (r=0;r<p.col_numShapes;r++) {
253     for (k=0;k<p.numEqu;k++) {
254     for (m=0;m<p.numComp;m++) {
255     rtmp=0;
256     for (q=0;q<p.numQuadSub;q++) {
257     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)];
258     }
259     EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
260     }
261     }
262     }
263     }
264     } else {
265     for (s=0;s<p.row_numShapes;s++) {
266     for (r=0;r<p.col_numShapes;r++) {
267 gross 853 rtmp=0;
268 gross 2748 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(r,q,p.row_numShapes)];
269     for (k=0;k<p.numEqu;k++) {
270     for (m=0;m<p.numComp;m++) {
271     EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*D_p[INDEX2(k,m,p.numEqu)];
272     }
273 gross 853 }
274     }
275 gross 2748 }
276     }
277     }
278     /**************************************************************/
279     /* process X: */
280     /**************************************************************/
281 jfenwick 2770 X_p=getSampleDataRO(X,e);
282 gross 2748 if (NULL!=X_p) {
283     add_EM_F=TRUE;
284     if (extendedX) {
285     X_q=&(X_p[INDEX4(0,0,0,isub, p.numEqu,DIM,p.numQuadSub)]);
286     for (s=0;s<p.row_numShapes;s++) {
287 gross 853 for (k=0;k<p.numEqu;k++) {
288 gross 2748 rtmp=0;
289     for (q=0;q<p.numQuadSub;q++) {
290     rtmp+=Vol[q]*(DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*X_q[INDEX3(k,0,q,p.numEqu,DIM)]
291     +DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*X_q[INDEX3(k,1,q,p.numEqu,DIM)]);
292     }
293     EM_F[INDEX2(k,s,p.numEqu)]+=rtmp;
294 gross 853 }
295     }
296 gross 2748 } else {
297     for (s=0;s<p.row_numShapes;s++) {
298     rtmp0=0;
299     rtmp1=0;
300     for (q=0;q<p.numQuadSub;q++) {
301     rtmp0+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
302     rtmp1+=Vol[q]*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
303     }
304     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)];
305     }
306     }
307 gross 853 }
308 gross 2748 /**************************************************************/
309     /* process Y: */
310     /**************************************************************/
311 jfenwick 2770 Y_p=getSampleDataRO(Y,e);
312 gross 2748 if (NULL!=Y_p) {
313     add_EM_F=TRUE;
314     if (extendedY) {
315     Y_q=&(Y_p[INDEX3(0,0,isub, p.numEqu,p.numQuadSub)]);
316     for (s=0;s<p.row_numShapes;s++) {
317     for (k=0;k<p.numEqu;k++) {
318 gross 853 rtmp=0;
319 gross 2748 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*Y_q[INDEX2(k,q,p.numEqu)];
320     EM_F[INDEX2(k,s,p.numEqu)]+=rtmp;
321     }
322 gross 853 }
323 gross 2748 } else {
324     for (s=0;s<p.row_numShapes;s++) {
325 gross 798 rtmp=0;
326 gross 2748 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
327     for (k=0;k<p.numEqu;k++) EM_F[INDEX2(k,s,p.numEqu)]+=rtmp*Y_p[k];
328 gross 798 }
329 gross 853 }
330 gross 2748 }
331     /***********************************************************************************************/
332     /* add the element matrices onto the matrix and right hand side */
333     /***********************************************************************************************/
334     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)]];
335    
336     if (add_EM_F) Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
337     if (add_EM_S) Finley_Assemble_addToSystemMatrix(Mat,p.row_numShapesTotal,row_index,p.numEqu,p.col_numShapesTotal,row_index,p.numComp,EM_S);
338    
339     } /* end of isub */
340 gross 853 } /* end color check */
341     } /* end element loop */
342     } /* end color loop */
343    
344     THREAD_MEMFREE(EM_S);
345     THREAD_MEMFREE(EM_F);
346     THREAD_MEMFREE(row_index);
347 gross 798
348 gross 853 } /* end of pointer check */
349 gross 798 } /* end parallel region */
350     }
351     /*
352     * $Log$
353     */

  ViewVC Help
Powered by ViewVC 1.1.26