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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3136 - (show annotations)
Thu Sep 2 03:48:29 2010 UTC (8 years, 9 months ago) by jfenwick
File MIME type: text/plain
File size: 23330 byte(s)
Removed numSubElements
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_{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 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 = p.numEqu x 3 x p.numComp x 3 */
29 /* B = 3 x p.numEqu x p.numComp */
30 /* C = p.numEqu x 3 x p.numComp */
31 /* D = p.numEqu x p.numComp */
32 /* X = p.numEqu x 3 */
33 /* Y = p.numEqu */
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_System2_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,k,m;
59 register double rtmp, rtmp0, rtmp1, rtmp2, rtmp00, rtmp01, rtmp02, rtmp10, rtmp11, rtmp12, rtmp20, rtmp21, rtmp22;
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*p.numEqu*p.numComp;
71 dim_t len_EM_F=p.row_numShapesTotal*p.numEqu;
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,k,m,rtmp, rtmp0, rtmp1, rtmp2, rtmp00, rtmp01, rtmp02, rtmp10, rtmp11, rtmp12, rtmp20, rtmp21, rtmp22,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.numQuadSub,1)]);
95 DSDX=&(p.row_jac->DSDX[INDEX5(0,0,0,0,e,p.row_numShapesTotal,DIM,p.numQuadSub,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[INDEX6(0,0,0,0,0,0, p.numEqu,DIM,p.numComp,DIM,p.numQuadSub)]);
108 for (s=0;s<p.row_numShapes;s++) {
109 for (r=0;r<p.col_numShapes;r++) {
110 for (k=0;k<p.numEqu;k++) {
111 for (m=0;m<p.numComp;m++) {
112 rtmp=0;
113 for (q=0;q<p.numQuadSub;q++) {
114 rtmp+=Vol[q]*(
115 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)]
116 +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)]
117 +DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*A_q[INDEX5(k,0,m,2,q, p.numEqu,DIM,p.numComp,DIM)]*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)]
118 +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)]
119 +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)]
120 +DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*A_q[INDEX5(k,1,m,2,q, p.numEqu,DIM,p.numComp,DIM)]*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)]
121 +DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)]*A_q[INDEX5(k,2,m,0,q, p.numEqu,DIM,p.numComp,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)]
122 +DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)]*A_q[INDEX5(k,2,m,1,q, p.numEqu,DIM,p.numComp,DIM)]*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)]
123 +DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)]*A_q[INDEX5(k,2,m,2,q, p.numEqu,DIM,p.numComp,DIM)]*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)]);
124
125 }
126 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
127 }
128 }
129 }
130 }
131 } else {
132 for (s=0;s<p.row_numShapes;s++) {
133 for (r=0;r<p.col_numShapes;r++) {
134 rtmp00=0;
135 rtmp01=0;
136 rtmp02=0;
137 rtmp10=0;
138 rtmp11=0;
139 rtmp12=0;
140 rtmp20=0;
141 rtmp21=0;
142 rtmp22=0;
143 for (q=0;q<p.numQuadSub;q++) {
144 rtmp0=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
145 rtmp00+=rtmp0*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
146 rtmp01+=rtmp0*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
147 rtmp02+=rtmp0*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)];
148
149 rtmp1=Vol[q]*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
150 rtmp10+=rtmp1*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
151 rtmp11+=rtmp1*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
152 rtmp12+=rtmp1*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)];
153
154 rtmp2=Vol[q]*DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)];
155 rtmp20+=rtmp2*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
156 rtmp21+=rtmp2*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
157 rtmp22+=rtmp2*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)];
158 }
159 for (k=0;k<p.numEqu;k++) {
160 for (m=0;m<p.numComp;m++) {
161 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+= rtmp00*A_p[INDEX4(k,0,m,0, p.numEqu,DIM,p.numComp)]
162 +rtmp01*A_p[INDEX4(k,0,m,1, p.numEqu,DIM,p.numComp)]
163 +rtmp02*A_p[INDEX4(k,0,m,2, p.numEqu,DIM,p.numComp)]
164 +rtmp10*A_p[INDEX4(k,1,m,0, p.numEqu,DIM,p.numComp)]
165 +rtmp11*A_p[INDEX4(k,1,m,1, p.numEqu,DIM,p.numComp)]
166 +rtmp12*A_p[INDEX4(k,1,m,2, p.numEqu,DIM,p.numComp)]
167 +rtmp20*A_p[INDEX4(k,2,m,0, p.numEqu,DIM,p.numComp)]
168 +rtmp21*A_p[INDEX4(k,2,m,1, p.numEqu,DIM,p.numComp)]
169 +rtmp22*A_p[INDEX4(k,2,m,2, p.numEqu,DIM,p.numComp)];
170 }
171 }
172 }
173 }
174 }
175 }
176 /**************************************************************/
177 /* process B: */
178 /**************************************************************/
179 if (NULL!=B_p) {
180 add_EM_S=TRUE;
181 if (extendedB) {
182 B_q=&(B_p[INDEX5(0,0,0,0,0, p.numEqu,DIM,p.numComp,p.numQuadSub)]);
183 for (s=0;s<p.row_numShapes;s++) {
184 for (r=0;r<p.col_numShapes;r++) {
185 for (k=0;k<p.numEqu;k++) {
186 for (m=0;m<p.numComp;m++) {
187 rtmp=0;
188 for (q=0;q<p.numQuadSub;q++) {
189 rtmp+=Vol[q]*S[INDEX2(r,q,p.row_numShapes)]*(
190 DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*B_q[INDEX4(k,0,m,q,p.numEqu,DIM,p.numComp)]
191 + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*B_q[INDEX4(k,1,m,q,p.numEqu,DIM,p.numComp)]
192 + DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)]*B_q[INDEX4(k,2,m,q,p.numEqu,DIM,p.numComp)] );
193 }
194 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
195 }
196 }
197 }
198 }
199 } else {
200 for (s=0;s<p.row_numShapes;s++) {
201 for (r=0;r<p.col_numShapes;r++) {
202 rtmp0=0;
203 rtmp1=0;
204 rtmp2=0;
205 for (q=0;q<p.numQuadSub;q++) {
206 rtmp=Vol[q]*S[INDEX2(r,q,p.row_numShapes)];
207 rtmp0+=rtmp*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
208 rtmp1+=rtmp*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
209 rtmp2+=rtmp*DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)];
210 }
211 for (k=0;k<p.numEqu;k++) {
212 for (m=0;m<p.numComp;m++) {
213 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp0*B_p[INDEX3(k,0,m,p.numEqu,DIM)]
214 +rtmp1*B_p[INDEX3(k,1,m,p.numEqu,DIM)]
215 +rtmp2*B_p[INDEX3(k,2,m,p.numEqu,DIM)];
216 }
217 }
218 }
219 }
220 }
221 }
222 /**************************************************************/
223 /* process C: */
224 /**************************************************************/
225 if (NULL!=C_p) {
226 add_EM_S=TRUE;
227 if (extendedC) {
228 C_q=&(C_p[INDEX5(0,0,0,0,0 ,p.numEqu,p.numComp,DIM, p.numQuadSub)]);
229 for (s=0;s<p.row_numShapes;s++) {
230 for (r=0;r<p.col_numShapes;r++) {
231 for (k=0;k<p.numEqu;k++) {
232 for (m=0;m<p.numComp;m++) {
233 rtmp=0;
234 for (q=0;q<p.numQuadSub;q++) {
235 rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*(
236 C_q[INDEX4(k,m,0,q,p.numEqu,p.numComp,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)]
237 +C_q[INDEX4(k,m,1,q,p.numEqu,p.numComp,DIM)]*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)]
238 +C_q[INDEX4(k,m,2,q,p.numEqu,p.numComp,DIM)]*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)]);
239 }
240 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
241 }
242 }
243 }
244 }
245 } else {
246 for (s=0;s<p.row_numShapes;s++) {
247 for (r=0;r<p.col_numShapes;r++) {
248 rtmp0=0;
249 rtmp1=0;
250 rtmp2=0;
251 for (q=0;q<p.numQuadSub;q++) {
252 rtmp=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
253 rtmp0+=rtmp*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
254 rtmp1+=rtmp*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
255 rtmp2+=rtmp*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)];
256 }
257 for (k=0;k<p.numEqu;k++) {
258 for (m=0;m<p.numComp;m++) {
259 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)]
260 +rtmp1*C_p[INDEX3(k,m,1,p.numEqu,p.numComp)]
261 +rtmp2*C_p[INDEX3(k,m,2,p.numEqu,p.numComp)];
262 }
263 }
264 }
265 }
266 }
267 }
268 /************************************************************* */
269 /* process D */
270 /**************************************************************/
271 if (NULL!=D_p) {
272 add_EM_S=TRUE;
273 if (extendedD) {
274 D_q=&(D_p[INDEX4(0,0,0,0 ,p.numEqu,p.numComp, p.numQuadSub)]);
275 for (s=0;s<p.row_numShapes;s++) {
276 for (r=0;r<p.col_numShapes;r++) {
277 for (k=0;k<p.numEqu;k++) {
278 for (m=0;m<p.numComp;m++) {
279 rtmp=0;
280 for (q=0;q<p.numQuadSub;q++) {
281 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)];
282 }
283 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
284 }
285 }
286 }
287 }
288 } else {
289 for (s=0;s<p.row_numShapes;s++) {
290 for (r=0;r<p.col_numShapes;r++) {
291 rtmp=0;
292 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(r,q,p.row_numShapes)];
293 for (k=0;k<p.numEqu;k++) {
294 for (m=0;m<p.numComp;m++) {
295 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*D_p[INDEX2(k,m,p.numEqu)];
296 }
297 }
298 }
299 }
300 }
301 }
302 /**************************************************************/
303 /* process X: */
304 /**************************************************************/
305 if (NULL!=X_p) {
306 add_EM_F=TRUE;
307 if (extendedX) {
308 X_q=&(X_p[INDEX4(0,0,0,0, p.numEqu,DIM,p.numQuadSub)]);
309 for (s=0;s<p.row_numShapes;s++) {
310 for (k=0;k<p.numEqu;k++) {
311 rtmp=0;
312 for (q=0;q<p.numQuadSub;q++) {
313 rtmp+=Vol[q]* ( DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*X_q[INDEX3(k,0,q,p.numEqu,DIM)]
314 + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*X_q[INDEX3(k,1,q,p.numEqu,DIM)]
315 + DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)]*X_q[INDEX3(k,2,q,p.numEqu,DIM)]);
316 }
317 EM_F[INDEX2(k,s,p.numEqu)]+=rtmp;
318 }
319 }
320 } else {
321 for (s=0;s<p.row_numShapes;s++) {
322 rtmp0=0;
323 rtmp1=0;
324 rtmp2=0;
325 for (q=0;q<p.numQuadSub;q++) {
326 rtmp0+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
327 rtmp1+=Vol[q]*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
328 rtmp2+=Vol[q]*DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)];
329 }
330 for (k=0;k<p.numEqu;k++) {
331 EM_F[INDEX2(k,s,p.numEqu)]+=rtmp0*X_p[INDEX2(k,0,p.numEqu)]
332 +rtmp1*X_p[INDEX2(k,1,p.numEqu)]
333 +rtmp2*X_p[INDEX2(k,2,p.numEqu)];
334 }
335 }
336 }
337 }
338 /**************************************************************/
339 /* process Y: */
340 /**************************************************************/
341 if (NULL!=Y_p) {
342 add_EM_F=TRUE;
343 if (extendedY) {
344 Y_q=&(Y_p[INDEX3(0,0,0, p.numEqu,p.numQuadSub)]);
345 for (s=0;s<p.row_numShapes;s++) {
346 for (k=0;k<p.numEqu;k++) {
347 rtmp=0.;
348 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*Y_q[INDEX2(k,q,p.numEqu)];
349 EM_F[INDEX2(k,s,p.numEqu)]+=rtmp;
350 }
351 }
352 } else {
353 for (s=0;s<p.row_numShapes;s++) {
354 rtmp=0;
355 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
356 for (k=0;k<p.numEqu;k++) EM_F[INDEX2(k,s,p.numEqu)]+=rtmp*Y_p[k];
357 }
358 }
359 }
360
361 /***********************************************************************************************/
362 /* add the element matrices onto the matrix and right hand side */
363 /***********************************************************************************************/
364 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)]];
365
366 if (add_EM_F) Dudley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
367 if (add_EM_S) Dudley_Assemble_addToSystemMatrix(Mat,p.row_numShapesTotal,row_index,p.numEqu,p.col_numShapesTotal,row_index,p.numComp,EM_S);
368 } /* end color check */
369 } /* end element loop */
370 } /* end color loop */
371
372 THREAD_MEMFREE(EM_S);
373 THREAD_MEMFREE(EM_F);
374 THREAD_MEMFREE(row_index);
375
376 } /* end of pointer check */
377 } /* end parallel region */
378 }

  ViewVC Help
Powered by ViewVC 1.1.26