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

Contents of /branches/domexper/dudley/src/Assemble_PDE_Single2_3D.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3137 - (show annotations)
Thu Sep 2 05:03:17 2010 UTC (8 years, 10 months ago) by jfenwick
File MIME type: text/plain
File size: 19513 byte(s)
Removed numSubQuad
1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 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
14
15 /**************************************************************/
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 #ifdef _OPENMP
42 #include <omp.h>
43 #endif
44
45
46 /**************************************************************/
47
48 void Dudley_Assemble_PDE_Single2_3D(Assemble_Parameters p, Dudley_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 __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 double *EM_S, *EM_F, *Vol, *DSDX;
57 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 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 double *F_p=(requireWrite(F), getSampleDataRW(F,0)); /* use comma, to get around the mixed code and declarations thing */
69 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
73 #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)
74 {
75 EM_S=THREAD_MEMALLOC(len_EM_S,double);
76 EM_F=THREAD_MEMALLOC(len_EM_F,double);
77 row_index=THREAD_MEMALLOC(p.row_numShapesTotal,index_t);
78
79 if (!Dudley_checkPtr(EM_S) && !Dudley_checkPtr(EM_F) && !Dudley_checkPtr(row_index) ) {
80
81 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
87 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
94 Vol=&(p.row_jac->volume[INDEX3(0,0,e, p.numQuadTotal,1)]);
95 DSDX=&(p.row_jac->DSDX[INDEX5(0,0,0,0,e,p.row_numShapesTotal,DIM,p.numQuadTotal,1)]);
96 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 if (NULL!=A_p) {
105 add_EM_S=TRUE;
106 if (extendedA) {
107 A_q=&(A_p[INDEX4(0,0,0,0, DIM,DIM,p.numQuadTotal)]);
108 for (s=0;s<p.row_numShapes;s++) {
109 for (r=0;r<p.col_numShapes;r++) {
110 rtmp=0;
111 for (q=0;q<p.numQuadTotal;q++) {
112 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)]
113 + 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)]
114 + 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)]
115 + 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)]
116 + 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)]
117 + 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)]
118 + 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)]
119 + 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)]
120 + 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)]);
121 }
122 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
123 }
124 }
125 } else {
126 for (s=0;s<p.row_numShapes;s++) {
127 for (r=0;r<p.col_numShapes;r++) {
128 rtmp00=0;
129 rtmp01=0;
130 rtmp02=0;
131 rtmp10=0;
132 rtmp11=0;
133 rtmp12=0;
134 rtmp20=0;
135 rtmp21=0;
136 rtmp22=0;
137 for (q=0;q<p.numQuadTotal;q++) {
138
139 rtmp0=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
140 rtmp00+=rtmp0*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
141 rtmp01+=rtmp0*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
142 rtmp02+=rtmp0*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)];
143
144 rtmp1=Vol[q]*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
145 rtmp10+=rtmp1*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
146 rtmp11+=rtmp1*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
147 rtmp12+=rtmp1*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)];
148
149 rtmp2=Vol[q]*DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)];
150 rtmp20+=rtmp2*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
151 rtmp21+=rtmp2*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
152 rtmp22+=rtmp2*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)];
153 }
154 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp00*A_p[INDEX2(0,0,DIM)]
155 +rtmp01*A_p[INDEX2(0,1,DIM)]
156 +rtmp02*A_p[INDEX2(0,2,DIM)]
157 +rtmp10*A_p[INDEX2(1,0,DIM)]
158 +rtmp11*A_p[INDEX2(1,1,DIM)]
159 +rtmp12*A_p[INDEX2(1,2,DIM)]
160 +rtmp20*A_p[INDEX2(2,0,DIM)]
161 +rtmp21*A_p[INDEX2(2,1,DIM)]
162 +rtmp22*A_p[INDEX2(2,2,DIM)];
163 }
164 }
165 }
166 }
167 /**************************************************************/
168 /* process B: */
169 /**************************************************************/
170 if (NULL!=B_p) {
171 add_EM_S=TRUE;
172 if (extendedB) {
173 B_q=&(B_p[INDEX3(0,0,0, DIM,p.numQuadTotal)]);
174 for (s=0;s<p.row_numShapes;s++) {
175 for (r=0;r<p.col_numShapes;r++) {
176 rtmp=0;
177 for (q=0;q<p.numQuadTotal;q++) {
178 rtmp+=Vol[q]*S[INDEX2(r,q,p.row_numShapes)]*
179 ( DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*B_q[INDEX2(0,q,DIM)]
180 + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*B_q[INDEX2(1,q,DIM)]
181 + DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)]*B_q[INDEX2(2,q,DIM)]);
182 }
183 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
184 }
185 }
186 } else {
187 for (s=0;s<p.row_numShapes;s++) {
188 for (r=0;r<p.col_numShapes;r++) {
189 rtmp0=0;
190 rtmp1=0;
191 rtmp2=0;
192 for (q=0;q<p.numQuadTotal;q++) {
193 rtmp=Vol[q]*S[INDEX2(r,q,p.row_numShapes)];
194 rtmp0+=rtmp*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
195 rtmp1+=rtmp*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
196 rtmp2+=rtmp*DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)];
197 }
198 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];
199 }
200 }
201 }
202 }
203 /**************************************************************/
204 /* process C: */
205 /**************************************************************/
206 if (NULL!=C_p) {
207 add_EM_S=TRUE;
208 if (extendedC) {
209 C_q=&(C_p[INDEX3(0,0,0, DIM, p.numQuadTotal)]);
210 for (s=0;s<p.row_numShapes;s++) {
211 for (r=0;r<p.col_numShapes;r++) {
212 rtmp=0;
213 for (q=0;q<p.numQuadTotal;q++) {
214 rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*
215 ( C_q[INDEX2(0,q,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)]
216 + C_q[INDEX2(1,q,DIM)]*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)]
217 + C_q[INDEX2(2,q,DIM)]*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)]);
218 }
219 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
220 }
221 }
222 } else {
223 for (s=0;s<p.row_numShapes;s++) {
224 for (r=0;r<p.col_numShapes;r++) {
225 rtmp0=0;
226 rtmp1=0;
227 rtmp2=0;
228 for (q=0;q<p.numQuadTotal;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 rtmp2+=rtmp*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)];
233 }
234 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];
235 }
236 }
237 }
238 }
239 /************************************************************* */
240 /* process D */
241 /**************************************************************/
242 if (NULL!=D_p) {
243 add_EM_S=TRUE;
244 if (extendedD) {
245 D_q=&(D_p[INDEX2(0,0, p.numQuadTotal)]);
246 for (s=0;s<p.row_numShapes;s++) {
247 for (r=0;r<p.col_numShapes;r++) {
248 rtmp=0;
249 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)];
250 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
251 }
252 }
253 } else {
254 for (s=0;s<p.row_numShapes;s++) {
255 for (r=0;r<p.col_numShapes;r++) {
256 rtmp=0;
257 for (q=0;q<p.numQuadTotal;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(r,q,p.row_numShapes)];
258 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*D_p[0];
259 }
260 }
261 }
262 }
263 /**************************************************************/
264 /* process X: */
265 /**************************************************************/
266 if (NULL!=X_p) {
267 add_EM_F=TRUE;
268 if (extendedX) {
269 X_q=&(X_p[INDEX3(0,0,0, DIM,p.numQuadTotal)]);
270 for (s=0;s<p.row_numShapes;s++) {
271 rtmp=0;
272 for (q=0;q<p.numQuadTotal;q++) {
273 rtmp+=Vol[q]*( DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*X_q[INDEX2(0,q,DIM)]
274 + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*X_q[INDEX2(1,q,DIM)]
275 + DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)]*X_q[INDEX2(2,q,DIM)]);
276 }
277 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
278 }
279 } else {
280 for (s=0;s<p.row_numShapes;s++) {
281 rtmp0=0;
282 rtmp1=0;
283 rtmp2=0;
284 for (q=0;q<p.numQuadTotal;q++) {
285 rtmp0+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
286 rtmp1+=Vol[q]*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
287 rtmp2+=Vol[q]*DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)];
288 }
289 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp0*X_p[0]+rtmp1*X_p[1]+rtmp2*X_p[2];
290 }
291 }
292 }
293 /**************************************************************/
294 /* process Y: */
295 /**************************************************************/
296 if (NULL!=Y_p) {
297 add_EM_F=TRUE;
298 if (extendedY) {
299 Y_q=&(Y_p[INDEX2(0,0, p.numQuadTotal)]);
300 for (s=0;s<p.row_numShapes;s++) {
301 rtmp=0;
302 for (q=0;q<p.numQuadTotal;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*Y_q[q];
303 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
304 }
305 } else {
306 for (s=0;s<p.row_numShapes;s++) {
307 rtmp=0;
308 for (q=0;q<p.numQuadTotal;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
309 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp*Y_p[0];
310 }
311 }
312 }
313 /***********************************************************************************************/
314 /* add the element matrices onto the matrix and right hand side */
315 /***********************************************************************************************/
316
317 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)]];
318
319 if (add_EM_F) Dudley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
320 if (add_EM_S) Dudley_Assemble_addToSystemMatrix(Mat,p.row_numShapesTotal,row_index,p.numEqu,p.col_numShapesTotal,row_index,p.numComp,EM_S);
321
322 } /* end color check */
323 } /* end element loop */
324 } /* end color loop */
325
326 THREAD_MEMFREE(EM_S);
327 THREAD_MEMFREE(EM_F);
328 THREAD_MEMFREE(row_index);
329
330 } /* end of pointer check */
331 } /* end parallel region */
332 }

  ViewVC Help
Powered by ViewVC 1.1.26