/[escript]/branches/domexper/dudley/src/Assemble_PDE_Single2_2D.c
ViewVC logotype

Annotation of /branches/domexper/dudley/src/Assemble_PDE_Single2_2D.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3137 - (hide annotations)
Thu Sep 2 05:03:17 2010 UTC (9 years, 4 months ago) by jfenwick
File MIME type: text/plain
File size: 15991 byte(s)
Removed numSubQuad
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 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 = 2 x 2 */
29     /* B = 2 */
30     /* C = 2 */
31     /* D = scalar */
32     /* X = 2 */
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     /**************************************************************/
46    
47 jfenwick 3086 void Dudley_Assemble_PDE_Single2_2D(Assemble_Parameters p, Dudley_ElementFile* elements,
48 gross 798 Paso_SystemMatrix* Mat, escriptDataC* F,
49     escriptDataC* A, escriptDataC* B, escriptDataC* C, escriptDataC* D, escriptDataC* X, escriptDataC* Y) {
50    
51     #define DIM 2
52     index_t color;
53 jfenwick 3136 dim_t e;
54 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;
55 jfenwick 2271 double *EM_S, *EM_F, *Vol, *DSDX;
56 gross 853 index_t *row_index;
57     register dim_t q, s,r;
58     register double rtmp00, rtmp01, rtmp10, rtmp11, rtmp, rtmp0, rtmp1;
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 jfenwick 2271 double *F_p=(requireWrite(F), getSampleDataRW(F,0)); /* use comma, to get around the mixed code and declarations thing */
68 gross 2748 double *S=p.row_jac->BasisFunctions->S;
69     dim_t len_EM_S=p.row_numShapesTotal*p.col_numShapesTotal;
70     dim_t len_EM_F=p.row_numShapesTotal;
71 gross 798
72 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,rtmp00, rtmp01, rtmp10, rtmp11, rtmp, rtmp0, rtmp1,add_EM_F, add_EM_S)
73 gross 798 {
74 gross 853 EM_S=THREAD_MEMALLOC(len_EM_S,double);
75     EM_F=THREAD_MEMALLOC(len_EM_F,double);
76 gross 2748 row_index=THREAD_MEMALLOC(p.row_numShapesTotal,index_t);
77 gross 853
78 jfenwick 3086 if (!Dudley_checkPtr(EM_S) && !Dudley_checkPtr(EM_F) && !Dudley_checkPtr(row_index) ) {
79 gross 853
80     for (color=elements->minColor;color<=elements->maxColor;color++) {
81     /* open loop over all elements: */
82     #pragma omp for private(e) schedule(static)
83     for(e=0;e<elements->numElements;e++){
84     if (elements->Color[e]==color) {
85 gross 2748
86 jfenwick 2770 A_p=getSampleDataRO(A,e);
87     B_p=getSampleDataRO(B,e);
88     C_p=getSampleDataRO(C,e);
89     D_p=getSampleDataRO(D,e);
90     X_p=getSampleDataRO(X,e);
91     Y_p=getSampleDataRO(Y,e);
92 gross 2748
93 jfenwick 3137 Vol=&(p.row_jac->volume[INDEX3(0,0,e, p.numQuadTotal,1)]);
94     DSDX=&(p.row_jac->DSDX[INDEX5(0,0,0,0,e, p.row_numShapesTotal,DIM,p.numQuadTotal,1)]);
95 gross 2748 for (q=0;q<len_EM_S;++q) EM_S[q]=0;
96     for (q=0;q<len_EM_F;++q) EM_F[q]=0;
97     add_EM_F=FALSE;
98     add_EM_S=FALSE;
99     /**************************************************************/
100     /* process A: */
101     /**************************************************************/
102     if (NULL!=A_p) {
103     add_EM_S=TRUE;
104     if (extendedA) {
105 jfenwick 3137 A_q=&(A_p[INDEX4(0,0,0,0, DIM,DIM,p.numQuadTotal)]);
106 gross 2748 for (s=0;s<p.row_numShapes;s++) {
107     for (r=0;r<p.col_numShapes;r++) {
108     rtmp=0;
109 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) {
110 gross 2748 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)]
111     + 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)]
112     + 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)]
113     + 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)] );
114     }
115     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
116 gross 853 }
117     }
118 gross 2748 } else {
119     for (s=0;s<p.row_numShapes;s++) {
120     for (r=0;r<p.col_numShapes;r++) {
121     rtmp00=0;
122     rtmp01=0;
123     rtmp10=0;
124     rtmp11=0;
125 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) {
126 gross 2748 rtmp0=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
127     rtmp1=Vol[q]*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
128     rtmp00+=rtmp0*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
129     rtmp01+=rtmp0*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
130     rtmp10+=rtmp1*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
131     rtmp11+=rtmp1*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
132     }
133     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+= rtmp00*A_p[INDEX2(0,0,DIM)]
134     + rtmp01*A_p[INDEX2(0,1,DIM)]
135     + rtmp10*A_p[INDEX2(1,0,DIM)]
136     + rtmp11*A_p[INDEX2(1,1,DIM)];
137     }
138     }
139 gross 853 }
140 gross 2748 }
141     /**************************************************************/
142     /* process B: */
143     /**************************************************************/
144     if (NULL!=B_p) {
145     add_EM_S=TRUE;
146     if (extendedB) {
147 jfenwick 3137 B_q=&(B_p[INDEX3(0,0,0, DIM,p.numQuadTotal)]);
148 gross 2748 for (s=0;s<p.row_numShapes;s++) {
149     for (r=0;r<p.col_numShapes;r++) {
150     rtmp=0.;
151 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) {
152 gross 2748 rtmp+=Vol[q]*S[INDEX2(r,q,p.row_numShapes)]*(DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*B_q[INDEX2(0,q,DIM)]
153     + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*B_q[INDEX2(1,q,DIM)]);
154 gross 853 }
155 gross 2748 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
156     }
157 gross 853 }
158 gross 2748 } else {
159     for (s=0;s<p.row_numShapes;s++) {
160     for (r=0;r<p.col_numShapes;r++) {
161     rtmp0=0;
162     rtmp1=0;
163 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) {
164 gross 2748 rtmp=Vol[q]*S[INDEX2(r,q,p.row_numShapes)];
165     rtmp0+=rtmp*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
166     rtmp1+=rtmp*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
167     }
168     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp0*B_p[0]+rtmp1*B_p[1];
169 gross 853 }
170     }
171 gross 2748 }
172     }
173     /**************************************************************/
174     /* process C: */
175     /**************************************************************/
176     if (NULL!=C_p) {
177     add_EM_S=TRUE;
178     if (extendedC) {
179 jfenwick 3137 C_q=&(C_p[INDEX3(0,0,0, DIM, p.numQuadTotal)]);
180 gross 2748 for (s=0;s<p.row_numShapes;s++) {
181     for (r=0;r<p.col_numShapes;r++) {
182     rtmp=0;
183 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) {
184 gross 2748 rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*(C_q[INDEX2(0,q,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)]
185     + C_q[INDEX2(1,q,DIM)]*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)]);
186     }
187     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
188 gross 853 }
189     }
190 gross 2748 } else {
191     for (s=0;s<p.row_numShapes;s++) {
192     for (r=0;r<p.col_numShapes;r++) {
193     rtmp0=0;
194     rtmp1=0;
195 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) {
196 gross 2748 rtmp=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
197     rtmp0+=rtmp*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
198     rtmp1+=rtmp*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
199     }
200     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp0*C_p[0]+rtmp1*C_p[1];
201     }
202 gross 853 }
203 gross 2748 }
204 gross 853 }
205 gross 2748 /************************************************************* */
206     /* process D */
207     /**************************************************************/
208     if (NULL!=D_p) {
209     add_EM_S=TRUE;
210     if (extendedD) {
211 jfenwick 3137 D_q=&(D_p[INDEX2(0,0, p.numQuadTotal)]);
212 gross 2748 for (s=0;s<p.row_numShapes;s++) {
213     for (r=0;r<p.col_numShapes;r++) {
214 gross 853 rtmp=0;
215 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*D_q[q]*S[INDEX2(r,q,p.row_numShapes)];
216 gross 2748 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
217     }
218 gross 853 }
219 gross 2748 } else {
220     for (s=0;s<p.row_numShapes;s++) {
221     for (r=0;r<p.col_numShapes;r++) {
222     rtmp=0;
223 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(r,q,p.row_numShapes)];
224 gross 2748 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*D_p[0];
225     }
226     }
227     }
228 gross 853 }
229 gross 2748 /**************************************************************/
230     /* process X: */
231     /**************************************************************/
232     if (NULL!=X_p) {
233     add_EM_F=TRUE;
234     if (extendedX) {
235 jfenwick 3137 X_q=&(X_p[INDEX3(0,0,0, DIM,p.numQuadTotal)]);
236 gross 2748 for (s=0;s<p.row_numShapes;s++) {
237     rtmp=0.;
238 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) {
239 gross 2748 rtmp+=Vol[q]*( DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*X_q[INDEX2(0,q,DIM)]
240     + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*X_q[INDEX2(1,q,DIM)]);
241     }
242     EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
243     }
244     } else {
245     for (s=0;s<p.row_numShapes;s++) {
246     rtmp0=0.;
247     rtmp1=0.;
248 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) {
249 gross 2748 rtmp0+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
250     rtmp1+=Vol[q]*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
251 gross 853 }
252 gross 2748 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp0*X_p[0]+rtmp1*X_p[1];
253     }
254     }
255     }
256     /**************************************************************/
257     /* process Y: */
258     /**************************************************************/
259     if (NULL!=Y_p) {
260     add_EM_F=TRUE;
261     if (extendedY) {
262 jfenwick 3137 Y_q=&(Y_p[INDEX2(0,0, p.numQuadTotal)]);
263 gross 2748 for (s=0;s<p.row_numShapes;s++) {
264     rtmp=0;
265 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*Y_q[q];
266 gross 853 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
267 gross 2748 }
268     } else {
269     for (s=0;s<p.row_numShapes;s++) {
270     rtmp=0;
271 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
272 gross 2748 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp*Y_p[0];
273     }
274 gross 798 }
275     }
276 gross 2748 /***********************************************************************************************/
277     /* add the element matrices onto the matrix and right hand side */
278     /***********************************************************************************************/
279    
280 jfenwick 3136 for (q=0;q<p.row_numShapesTotal;q++) row_index[q]=p.row_DOF[elements->Nodes[INDEX2(p.row_node[INDEX2(q,0,p.row_numShapesTotal)],e,p.NN)]];
281 jfenwick 3086 if (add_EM_F) Dudley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
282     if (add_EM_S) Dudley_Assemble_addToSystemMatrix(Mat,p.row_numShapesTotal,row_index,p.numEqu,p.col_numShapesTotal,row_index,p.numComp,EM_S);
283 gross 853 } /* end color check */
284     } /* end element loop */
285     } /* end color loop */
286    
287     THREAD_MEMFREE(EM_S);
288     THREAD_MEMFREE(EM_F);
289     THREAD_MEMFREE(row_index);
290 gross 798
291 gross 853 } /* end of pointer check */
292 gross 798 } /* end parallel region */
293     }

  ViewVC Help
Powered by ViewVC 1.1.26