/[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 1811 - (hide annotations)
Thu Sep 25 23:11:13 2008 UTC (10 years, 9 months ago) by ksteube
File MIME type: text/plain
File size: 17265 byte(s)
Copyright updated in all files

1 gross 798
2 ksteube 1312 /*******************************************************
3 ksteube 1811 *
4     * Copyright (c) 2003-2008 by University of Queensland
5     * 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     dim_t e;
55 gross 853 double *EM_S, *EM_F, *Vol, *DSDX, *A_p, *B_p, *C_p, *D_p, *X_p, *Y_p;
56     index_t *row_index;
57     register dim_t q, s,r;
58     register double rtmp, rtmp00, rtmp01, rtmp02, rtmp10, rtmp11, rtmp12, rtmp20, rtmp21, rtmp22, rtmp0, rtmp1, rtmp2;
59     bool_t add_EM_F, add_EM_S;
60    
61 gross 798 bool_t extendedA=isExpanded(A);
62     bool_t extendedB=isExpanded(B);
63     bool_t extendedC=isExpanded(C);
64     bool_t extendedD=isExpanded(D);
65     bool_t extendedX=isExpanded(X);
66     bool_t extendedY=isExpanded(Y);
67     double *F_p=getSampleData(F,0);
68     double *S=p.row_jac->ReferenceElement->S;
69     dim_t len_EM_S=p.row_NN*p.col_NN;
70     dim_t len_EM_F=p.row_NN;
71    
72    
73 gross 853 #pragma omp parallel private(color,EM_S, EM_F, Vol, DSDX, A_p, B_p, C_p, D_p, X_p, Y_p,row_index,q, s,r,rtmp, rtmp00, rtmp01, rtmp02, rtmp10, rtmp11, rtmp12, rtmp20, rtmp21, rtmp22, rtmp0, rtmp1, rtmp2,add_EM_F, add_EM_S)
74 gross 798 {
75 gross 853 EM_S=THREAD_MEMALLOC(len_EM_S,double);
76     EM_F=THREAD_MEMALLOC(len_EM_F,double);
77     row_index=THREAD_MEMALLOC(p.row_NN,index_t);
78    
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     Vol=&(p.row_jac->volume[INDEX2(0,e,p.numQuad)]);
87     DSDX=&(p.row_jac->DSDX[INDEX4(0,0,0,e,p.row_NN,DIM,p.numQuad)]);
88     for (q=0;q<len_EM_S;++q) EM_S[q]=0;
89     for (q=0;q<len_EM_F;++q) EM_F[q]=0;
90     add_EM_F=FALSE;
91     add_EM_S=FALSE;
92     /**************************************************************/
93     /* process A: */
94     /**************************************************************/
95     A_p=getSampleData(A,e);
96     if (NULL!=A_p) {
97     add_EM_S=TRUE;
98     if (extendedA) {
99     for (s=0;s<p.row_NS;s++) {
100     for (r=0;r<p.col_NS;r++) {
101     rtmp=0;
102     for (q=0;q<p.numQuad;q++) {
103     rtmp+=Vol[q]*( DSDX[INDEX3(s,0,q,p.row_NN,DIM)]*A_p[INDEX3(0,0,q,DIM,DIM)]*DSDX[INDEX3(r,0,q,p.row_NN,DIM)]
104     + DSDX[INDEX3(s,0,q,p.row_NN,DIM)]*A_p[INDEX3(0,1,q,DIM,DIM)]*DSDX[INDEX3(r,1,q,p.row_NN,DIM)]
105     + DSDX[INDEX3(s,0,q,p.row_NN,DIM)]*A_p[INDEX3(0,2,q,DIM,DIM)]*DSDX[INDEX3(r,2,q,p.row_NN,DIM)]
106     + DSDX[INDEX3(s,1,q,p.row_NN,DIM)]*A_p[INDEX3(1,0,q,DIM,DIM)]*DSDX[INDEX3(r,0,q,p.row_NN,DIM)]
107     + DSDX[INDEX3(s,1,q,p.row_NN,DIM)]*A_p[INDEX3(1,1,q,DIM,DIM)]*DSDX[INDEX3(r,1,q,p.row_NN,DIM)]
108     + DSDX[INDEX3(s,1,q,p.row_NN,DIM)]*A_p[INDEX3(1,2,q,DIM,DIM)]*DSDX[INDEX3(r,2,q,p.row_NN,DIM)]
109     + DSDX[INDEX3(s,2,q,p.row_NN,DIM)]*A_p[INDEX3(2,0,q,DIM,DIM)]*DSDX[INDEX3(r,0,q,p.row_NN,DIM)]
110     + DSDX[INDEX3(s,2,q,p.row_NN,DIM)]*A_p[INDEX3(2,1,q,DIM,DIM)]*DSDX[INDEX3(r,1,q,p.row_NN,DIM)]
111     + DSDX[INDEX3(s,2,q,p.row_NN,DIM)]*A_p[INDEX3(2,2,q,DIM,DIM)]*DSDX[INDEX3(r,2,q,p.row_NN,DIM)]);
112     }
113     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
114     }
115     }
116     } else {
117     for (s=0;s<p.row_NS;s++) {
118     for (r=0;r<p.col_NS;r++) {
119     rtmp00=0;
120     rtmp01=0;
121     rtmp02=0;
122     rtmp10=0;
123     rtmp11=0;
124     rtmp12=0;
125     rtmp20=0;
126     rtmp21=0;
127     rtmp22=0;
128     for (q=0;q<p.numQuad;q++) {
129    
130     rtmp0=Vol[q]*DSDX[INDEX3(s,0,q,p.row_NN,DIM)];
131     rtmp00+=rtmp0*DSDX[INDEX3(r,0,q,p.row_NN,DIM)];
132     rtmp01+=rtmp0*DSDX[INDEX3(r,1,q,p.row_NN,DIM)];
133     rtmp02+=rtmp0*DSDX[INDEX3(r,2,q,p.row_NN,DIM)];
134    
135     rtmp1=Vol[q]*DSDX[INDEX3(s,1,q,p.row_NN,DIM)];
136     rtmp10+=rtmp1*DSDX[INDEX3(r,0,q,p.row_NN,DIM)];
137     rtmp11+=rtmp1*DSDX[INDEX3(r,1,q,p.row_NN,DIM)];
138     rtmp12+=rtmp1*DSDX[INDEX3(r,2,q,p.row_NN,DIM)];
139    
140     rtmp2=Vol[q]*DSDX[INDEX3(s,2,q,p.row_NN,DIM)];
141     rtmp20+=rtmp2*DSDX[INDEX3(r,0,q,p.row_NN,DIM)];
142     rtmp21+=rtmp2*DSDX[INDEX3(r,1,q,p.row_NN,DIM)];
143     rtmp22+=rtmp2*DSDX[INDEX3(r,2,q,p.row_NN,DIM)];
144     }
145     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp00*A_p[INDEX2(0,0,DIM)]
146     +rtmp01*A_p[INDEX2(0,1,DIM)]
147     +rtmp02*A_p[INDEX2(0,2,DIM)]
148     +rtmp10*A_p[INDEX2(1,0,DIM)]
149     +rtmp11*A_p[INDEX2(1,1,DIM)]
150     +rtmp12*A_p[INDEX2(1,2,DIM)]
151     +rtmp20*A_p[INDEX2(2,0,DIM)]
152     +rtmp21*A_p[INDEX2(2,1,DIM)]
153     +rtmp22*A_p[INDEX2(2,2,DIM)];
154     }
155     }
156     }
157     }
158     /**************************************************************/
159     /* process B: */
160     /**************************************************************/
161     B_p=getSampleData(B,e);
162     if (NULL!=B_p) {
163     add_EM_S=TRUE;
164     if (extendedB) {
165     for (s=0;s<p.row_NS;s++) {
166     for (r=0;r<p.col_NS;r++) {
167     rtmp=0;
168     for (q=0;q<p.numQuad;q++) {
169     rtmp+=Vol[q]*S[INDEX2(r,q,p.row_NS)]*
170     ( DSDX[INDEX3(s,0,q,p.row_NN,DIM)]*B_p[INDEX2(0,q,DIM)]
171     + DSDX[INDEX3(s,1,q,p.row_NN,DIM)]*B_p[INDEX2(1,q,DIM)]
172     + DSDX[INDEX3(s,2,q,p.row_NN,DIM)]*B_p[INDEX2(2,q,DIM)]);
173     }
174     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
175     }
176     }
177     } else {
178     for (s=0;s<p.row_NS;s++) {
179     for (r=0;r<p.col_NS;r++) {
180     rtmp0=0;
181     rtmp1=0;
182     rtmp2=0;
183     for (q=0;q<p.numQuad;q++) {
184     rtmp=Vol[q]*S[INDEX2(r,q,p.row_NS)];
185     rtmp0+=rtmp*DSDX[INDEX3(s,0,q,p.row_NN,DIM)];
186     rtmp1+=rtmp*DSDX[INDEX3(s,1,q,p.row_NN,DIM)];
187     rtmp2+=rtmp*DSDX[INDEX3(s,2,q,p.row_NN,DIM)];
188     }
189     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp0*B_p[0]+rtmp1*B_p[1]+rtmp2*B_p[2];
190     }
191     }
192 gross 798 }
193     }
194 gross 853 /**************************************************************/
195     /* process C: */
196     /**************************************************************/
197     C_p=getSampleData(C,e);
198     if (NULL!=C_p) {
199     add_EM_S=TRUE;
200     if (extendedC) {
201     for (s=0;s<p.row_NS;s++) {
202     for (r=0;r<p.col_NS;r++) {
203     rtmp=0;
204     for (q=0;q<p.numQuad;q++) {
205     rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*
206     ( C_p[INDEX2(0,q,DIM)]*DSDX[INDEX3(r,0,q,p.row_NN,DIM)]
207     + C_p[INDEX2(1,q,DIM)]*DSDX[INDEX3(r,1,q,p.row_NN,DIM)]
208     + C_p[INDEX2(2,q,DIM)]*DSDX[INDEX3(r,2,q,p.row_NN,DIM)]);
209     }
210     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
211     }
212     }
213     } else {
214     for (s=0;s<p.row_NS;s++) {
215     for (r=0;r<p.col_NS;r++) {
216     rtmp0=0;
217     rtmp1=0;
218     rtmp2=0;
219     for (q=0;q<p.numQuad;q++) {
220     rtmp=Vol[q]*S[INDEX2(s,q,p.row_NS)];
221     rtmp0+=rtmp*DSDX[INDEX3(r,0,q,p.row_NN,DIM)];
222     rtmp1+=rtmp*DSDX[INDEX3(r,1,q,p.row_NN,DIM)];
223     rtmp2+=rtmp*DSDX[INDEX3(r,2,q,p.row_NN,DIM)];
224     }
225     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp0*C_p[0]+rtmp1*C_p[1]+rtmp2*C_p[2];
226     }
227     }
228     }
229     }
230     /************************************************************* */
231     /* process D */
232     /**************************************************************/
233     D_p=getSampleData(D,e);
234     if (NULL!=D_p) {
235     add_EM_S=TRUE;
236     if (extendedD) {
237     for (s=0;s<p.row_NS;s++) {
238     for (r=0;r<p.col_NS;r++) {
239     rtmp=0;
240     for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*D_p[q]*S[INDEX2(r,q,p.row_NS)];
241     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
242     }
243     }
244     } else {
245     for (s=0;s<p.row_NS;s++) {
246     for (r=0;r<p.col_NS;r++) {
247     rtmp=0;
248     for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*S[INDEX2(r,q,p.row_NS)];
249     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp*D_p[0];
250     }
251     }
252     }
253     }
254     /**************************************************************/
255     /* process X: */
256     /**************************************************************/
257     X_p=getSampleData(X,e);
258     if (NULL!=X_p) {
259     add_EM_F=TRUE;
260     if (extendedX) {
261     for (s=0;s<p.row_NS;s++) {
262     rtmp=0;
263     for (q=0;q<p.numQuad;q++) {
264     rtmp+=Vol[q]*( DSDX[INDEX3(s,0,q,p.row_NN,DIM)]*X_p[INDEX2(0,q,DIM)]
265     + DSDX[INDEX3(s,1,q,p.row_NN,DIM)]*X_p[INDEX2(1,q,DIM)]
266     + DSDX[INDEX3(s,2,q,p.row_NN,DIM)]*X_p[INDEX2(2,q,DIM)]);
267     }
268     EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
269 gross 798 }
270 gross 853 } else {
271     for (s=0;s<p.row_NS;s++) {
272     rtmp0=0;
273     rtmp1=0;
274     rtmp2=0;
275     for (q=0;q<p.numQuad;q++) {
276     rtmp0+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_NN,DIM)];
277     rtmp1+=Vol[q]*DSDX[INDEX3(s,1,q,p.row_NN,DIM)];
278     rtmp2+=Vol[q]*DSDX[INDEX3(s,2,q,p.row_NN,DIM)];
279     }
280     EM_F[INDEX2(0,s,p.numEqu)]+=rtmp0*X_p[0]+rtmp1*X_p[1]+rtmp2*X_p[2];
281 gross 798 }
282 gross 853 }
283 gross 798 }
284 gross 853 /**************************************************************/
285     /* process Y: */
286     /**************************************************************/
287     Y_p=getSampleData(Y,e);
288     if (NULL!=Y_p) {
289     add_EM_F=TRUE;
290     if (extendedY) {
291     for (s=0;s<p.row_NS;s++) {
292     rtmp=0;
293     for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*Y_p[q];
294     EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
295 gross 798 }
296 gross 853 } else {
297     for (s=0;s<p.row_NS;s++) {
298 gross 798 rtmp=0;
299 gross 853 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)];
300     EM_F[INDEX2(0,s,p.numEqu)]+=rtmp*Y_p[0];
301 gross 798 }
302     }
303 gross 853 }
304     /***********************************************************************************************/
305     /* add the element matrices onto the matrix and right hand side */
306     /***********************************************************************************************/
307     for (q=0;q<p.row_NN;q++) row_index[q]=p.row_DOF[elements->Nodes[INDEX2(p.row_node[q],e,p.NN)]];
308     if (add_EM_F) Finley_Util_AddScatter(p.row_NN,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
309     if (add_EM_S) Finley_Assemble_addToSystemMatrix(Mat,p.row_NN,row_index,p.numEqu,p.col_NN,row_index,p.numComp,EM_S);
310    
311     } /* end color check */
312     } /* end element loop */
313     } /* end color loop */
314    
315     THREAD_MEMFREE(EM_S);
316     THREAD_MEMFREE(EM_F);
317     THREAD_MEMFREE(row_index);
318 gross 798
319 gross 853 } /* end of pointer check */
320 gross 798 } /* end parallel region */
321     }
322     /*
323     * $Log$
324     */

  ViewVC Help
Powered by ViewVC 1.1.26