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

Annotation of /trunk/finley/src/Assemble_PDE_Single2_3D.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2881 - (hide annotations)
Thu Jan 28 02:03:15 2010 UTC (9 years, 7 months ago) by jfenwick
File MIME type: text/plain
File size: 19622 byte(s)
Don't panic.
Updating copyright stamps

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_{i,j} u_,j)_i-(B_{i} u)_i+C_{j} u_,j-D u_m and -(X_,i)_i + Y */
22    
23     /* 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 = 3 x 3 */
29     /* B = 3 */
30     /* C = 3 */
31     /* D = scalar */
32     /* X = 3 */
33     /* Y = scalar */
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_Single2_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 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;
59     register double rtmp, rtmp00, rtmp01, rtmp02, rtmp10, rtmp11, rtmp12, rtmp20, rtmp21, rtmp22, rtmp0, rtmp1, rtmp2;
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;
71     dim_t len_EM_F=p.row_numShapesTotal;
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,rtmp, rtmp00, rtmp01, rtmp02, rtmp10, rtmp11, rtmp12, rtmp20, rtmp21, rtmp22, rtmp0, rtmp1, rtmp2,add_EM_F, add_EM_S, isub)
74 gross 798 {
75 gross 853 EM_S=THREAD_MEMALLOC(len_EM_S,double);
76     EM_F=THREAD_MEMALLOC(len_EM_F,double);
77 gross 2748 row_index=THREAD_MEMALLOC(p.row_numShapesTotal,index_t);
78 gross 853
79     if (!Finley_checkPtr(EM_S) && !Finley_checkPtr(EM_F) && !Finley_checkPtr(row_index) ) {
80 gross 798
81 gross 853 for (color=elements->minColor;color<=elements->maxColor;color++) {
82     /* open loop over all elements: */
83     #pragma omp for private(e) schedule(static)
84     for(e=0;e<elements->numElements;e++){
85     if (elements->Color[e]==color) {
86 gross 2748
87 jfenwick 2770 A_p=getSampleDataRO(A,e);
88     B_p=getSampleDataRO(B,e);
89     C_p=getSampleDataRO(C,e);
90     D_p=getSampleDataRO(D,e);
91     X_p=getSampleDataRO(X,e);
92     Y_p=getSampleDataRO(Y,e);
93 gross 2748
94     for (isub=0; isub<p.numSub; isub++) {
95    
96     Vol=&(p.row_jac->volume[INDEX3(0,isub,e, p.numQuadSub,p.numSub)]);
97     DSDX=&(p.row_jac->DSDX[INDEX5(0,0,0,isub,e,p.row_numShapesTotal,DIM,p.numQuadSub,p.numSub)]);
98     for (q=0;q<len_EM_S;++q) EM_S[q]=0;
99     for (q=0;q<len_EM_F;++q) EM_F[q]=0;
100     add_EM_F=FALSE;
101     add_EM_S=FALSE;
102    
103     /**************************************************************/
104     /* process A: */
105     /**************************************************************/
106     if (NULL!=A_p) {
107     add_EM_S=TRUE;
108     if (extendedA) {
109     A_q=&(A_p[INDEX4(0,0,0,isub, DIM,DIM,p.numQuadSub)]);
110     for (s=0;s<p.row_numShapes;s++) {
111     for (r=0;r<p.col_numShapes;r++) {
112     rtmp=0;
113     for (q=0;q<p.numQuadSub;q++) {
114     rtmp+=Vol[q]*( DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*A_q[INDEX3(0,0,q,DIM,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)]
115     + DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*A_q[INDEX3(0,1,q,DIM,DIM)]*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)]
116     + DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*A_q[INDEX3(0,2,q,DIM,DIM)]*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)]
117     + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*A_q[INDEX3(1,0,q,DIM,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)]
118     + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*A_q[INDEX3(1,1,q,DIM,DIM)]*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)]
119     + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*A_q[INDEX3(1,2,q,DIM,DIM)]*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)]
120     + DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)]*A_q[INDEX3(2,0,q,DIM,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)]
121     + DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)]*A_q[INDEX3(2,1,q,DIM,DIM)]*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)]
122     + DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)]*A_q[INDEX3(2,2,q,DIM,DIM)]*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)]);
123     }
124     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
125     }
126     }
127     } else {
128     for (s=0;s<p.row_numShapes;s++) {
129     for (r=0;r<p.col_numShapes;r++) {
130     rtmp00=0;
131     rtmp01=0;
132     rtmp02=0;
133     rtmp10=0;
134     rtmp11=0;
135     rtmp12=0;
136     rtmp20=0;
137     rtmp21=0;
138     rtmp22=0;
139     for (q=0;q<p.numQuadSub;q++) {
140    
141     rtmp0=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
142     rtmp00+=rtmp0*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
143     rtmp01+=rtmp0*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
144     rtmp02+=rtmp0*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)];
145    
146     rtmp1=Vol[q]*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
147     rtmp10+=rtmp1*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
148     rtmp11+=rtmp1*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
149     rtmp12+=rtmp1*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)];
150    
151     rtmp2=Vol[q]*DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)];
152     rtmp20+=rtmp2*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
153     rtmp21+=rtmp2*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
154     rtmp22+=rtmp2*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)];
155     }
156     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp00*A_p[INDEX2(0,0,DIM)]
157     +rtmp01*A_p[INDEX2(0,1,DIM)]
158     +rtmp02*A_p[INDEX2(0,2,DIM)]
159     +rtmp10*A_p[INDEX2(1,0,DIM)]
160     +rtmp11*A_p[INDEX2(1,1,DIM)]
161     +rtmp12*A_p[INDEX2(1,2,DIM)]
162     +rtmp20*A_p[INDEX2(2,0,DIM)]
163     +rtmp21*A_p[INDEX2(2,1,DIM)]
164     +rtmp22*A_p[INDEX2(2,2,DIM)];
165     }
166     }
167     }
168     }
169     /**************************************************************/
170     /* process B: */
171     /**************************************************************/
172     if (NULL!=B_p) {
173     add_EM_S=TRUE;
174     if (extendedB) {
175     B_q=&(B_p[INDEX3(0,0,isub, DIM,p.numQuadSub)]);
176     for (s=0;s<p.row_numShapes;s++) {
177     for (r=0;r<p.col_numShapes;r++) {
178     rtmp=0;
179     for (q=0;q<p.numQuadSub;q++) {
180     rtmp+=Vol[q]*S[INDEX2(r,q,p.row_numShapes)]*
181     ( DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*B_q[INDEX2(0,q,DIM)]
182     + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*B_q[INDEX2(1,q,DIM)]
183     + DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)]*B_q[INDEX2(2,q,DIM)]);
184     }
185     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
186     }
187     }
188     } else {
189     for (s=0;s<p.row_numShapes;s++) {
190     for (r=0;r<p.col_numShapes;r++) {
191     rtmp0=0;
192     rtmp1=0;
193     rtmp2=0;
194     for (q=0;q<p.numQuadSub;q++) {
195     rtmp=Vol[q]*S[INDEX2(r,q,p.row_numShapes)];
196     rtmp0+=rtmp*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
197     rtmp1+=rtmp*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
198     rtmp2+=rtmp*DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)];
199     }
200     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp0*B_p[0]+rtmp1*B_p[1]+rtmp2*B_p[2];
201     }
202     }
203 gross 853 }
204 gross 798 }
205 gross 2748 /**************************************************************/
206     /* process C: */
207     /**************************************************************/
208     if (NULL!=C_p) {
209     add_EM_S=TRUE;
210     if (extendedC) {
211     C_q=&(C_p[INDEX3(0,0,isub, DIM, p.numQuadSub)]);
212     for (s=0;s<p.row_numShapes;s++) {
213     for (r=0;r<p.col_numShapes;r++) {
214     rtmp=0;
215     for (q=0;q<p.numQuadSub;q++) {
216     rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*
217     ( C_q[INDEX2(0,q,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)]
218     + C_q[INDEX2(1,q,DIM)]*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)]
219     + C_q[INDEX2(2,q,DIM)]*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)]);
220     }
221     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
222     }
223     }
224     } else {
225     for (s=0;s<p.row_numShapes;s++) {
226     for (r=0;r<p.col_numShapes;r++) {
227     rtmp0=0;
228     rtmp1=0;
229     rtmp2=0;
230     for (q=0;q<p.numQuadSub;q++) {
231     rtmp=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
232     rtmp0+=rtmp*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
233     rtmp1+=rtmp*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
234     rtmp2+=rtmp*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)];
235     }
236     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp0*C_p[0]+rtmp1*C_p[1]+rtmp2*C_p[2];
237     }
238     }
239     }
240     }
241     /************************************************************* */
242     /* process D */
243     /**************************************************************/
244     if (NULL!=D_p) {
245     add_EM_S=TRUE;
246     if (extendedD) {
247     D_q=&(D_p[INDEX2(0,isub, p.numQuadSub)]);
248     for (s=0;s<p.row_numShapes;s++) {
249     for (r=0;r<p.col_numShapes;r++) {
250     rtmp=0;
251     for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*D_q[q]*S[INDEX2(r,q,p.row_numShapes)];
252     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
253     }
254     }
255     } else {
256     for (s=0;s<p.row_numShapes;s++) {
257     for (r=0;r<p.col_numShapes;r++) {
258     rtmp=0;
259     for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(r,q,p.row_numShapes)];
260     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*D_p[0];
261     }
262     }
263     }
264     }
265     /**************************************************************/
266     /* process X: */
267     /**************************************************************/
268     if (NULL!=X_p) {
269     add_EM_F=TRUE;
270     if (extendedX) {
271     X_q=&(X_p[INDEX3(0,0,isub, DIM,p.numQuadSub)]);
272     for (s=0;s<p.row_numShapes;s++) {
273     rtmp=0;
274     for (q=0;q<p.numQuadSub;q++) {
275     rtmp+=Vol[q]*( DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*X_q[INDEX2(0,q,DIM)]
276     + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*X_q[INDEX2(1,q,DIM)]
277     + DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)]*X_q[INDEX2(2,q,DIM)]);
278     }
279     EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
280 gross 853 }
281 gross 2748 } else {
282     for (s=0;s<p.row_numShapes;s++) {
283     rtmp0=0;
284     rtmp1=0;
285     rtmp2=0;
286     for (q=0;q<p.numQuadSub;q++) {
287     rtmp0+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
288     rtmp1+=Vol[q]*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
289     rtmp2+=Vol[q]*DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)];
290     }
291     EM_F[INDEX2(0,s,p.numEqu)]+=rtmp0*X_p[0]+rtmp1*X_p[1]+rtmp2*X_p[2];
292 gross 853 }
293 gross 2748 }
294 gross 853 }
295 gross 2748 /**************************************************************/
296     /* process Y: */
297     /**************************************************************/
298     if (NULL!=Y_p) {
299     add_EM_F=TRUE;
300     if (extendedY) {
301     Y_q=&(Y_p[INDEX2(0,isub, p.numQuadSub)]);
302     for (s=0;s<p.row_numShapes;s++) {
303     rtmp=0;
304     for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*Y_q[q];
305     EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
306 gross 853 }
307 gross 2748 } else {
308     for (s=0;s<p.row_numShapes;s++) {
309 gross 853 rtmp=0;
310 gross 2748 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
311     EM_F[INDEX2(0,s,p.numEqu)]+=rtmp*Y_p[0];
312 gross 853 }
313     }
314 gross 2748 }
315     /***********************************************************************************************/
316     /* add the element matrices onto the matrix and right hand side */
317     /***********************************************************************************************/
318    
319     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)]];
320    
321     if (add_EM_F) Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
322     if (add_EM_S) Finley_Assemble_addToSystemMatrix(Mat,p.row_numShapesTotal,row_index,p.numEqu,p.col_numShapesTotal,row_index,p.numComp,EM_S);
323    
324     } /* end of isub */
325 gross 853 } /* end color check */
326     } /* end element loop */
327     } /* end color loop */
328    
329     THREAD_MEMFREE(EM_S);
330     THREAD_MEMFREE(EM_F);
331     THREAD_MEMFREE(row_index);
332 gross 798
333 gross 853 } /* end of pointer check */
334 gross 798 } /* end parallel region */
335     }

  ViewVC Help
Powered by ViewVC 1.1.26