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

Contents of /trunk/finley/src/Assemble_PDE_System2_3D.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3259 - (show annotations)
Mon Oct 11 01:48:14 2010 UTC (8 years, 10 months ago) by jfenwick
File MIME type: text/plain
File size: 23521 byte(s)
Merging dudley and scons updates from branches

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 Finley_Assemble_PDE_System2_3D(Finley_Assemble_Parameters p,
49 Finley_ElementFile* elements,
50 Paso_SystemMatrix* Mat, escriptDataC* F,
51 escriptDataC* A, escriptDataC* B, escriptDataC* C, escriptDataC* D, escriptDataC* X, escriptDataC* Y) {
52
53 #define DIM 3
54 index_t color;
55 dim_t e, isub;
56 __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;
57 double *EM_S, *EM_F, *Vol, *DSDX;
58 index_t *row_index;
59 register dim_t q, s,r,k,m;
60 register double rtmp, rtmp0, rtmp1, rtmp2, rtmp00, rtmp01, rtmp02, rtmp10, rtmp11, rtmp12, rtmp20, rtmp21, rtmp22;
61 bool_t add_EM_F, add_EM_S;
62
63 bool_t extendedA=isExpanded(A);
64 bool_t extendedB=isExpanded(B);
65 bool_t extendedC=isExpanded(C);
66 bool_t extendedD=isExpanded(D);
67 bool_t extendedX=isExpanded(X);
68 bool_t extendedY=isExpanded(Y);
69 double *F_p=(requireWrite(F), getSampleDataRW(F,0)); /* use comma, to get around the mixed code and declarations thing */
70 double *S=p.row_jac->BasisFunctions->S;
71 dim_t len_EM_S=p.row_numShapesTotal*p.col_numShapesTotal*p.numEqu*p.numComp;
72 dim_t len_EM_F=p.row_numShapesTotal*p.numEqu;
73
74 #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, isub)
75 {
76 EM_S=THREAD_MEMALLOC(len_EM_S,double);
77 EM_F=THREAD_MEMALLOC(len_EM_F,double);
78 row_index=THREAD_MEMALLOC(p.row_numShapesTotal,index_t);
79
80 if (!Finley_checkPtr(EM_S) && !Finley_checkPtr(EM_F) && !Finley_checkPtr(row_index) ) {
81
82 for (color=elements->minColor;color<=elements->maxColor;color++) {
83 /* open loop over all elements: */
84 #pragma omp for private(e) schedule(static)
85 for(e=0;e<elements->numElements;e++){
86 if (elements->Color[e]==color) {
87
88 A_p=getSampleDataRO(A,e);
89 B_p=getSampleDataRO(B,e);
90 C_p=getSampleDataRO(C,e);
91 D_p=getSampleDataRO(D,e);
92 X_p=getSampleDataRO(X,e);
93 Y_p=getSampleDataRO(Y,e);
94
95 for (isub=0;isub<p.numSub;isub++){
96
97 Vol=&(p.row_jac->volume[INDEX3(0,isub,e, p.numQuadSub,p.numSub)]);
98 DSDX=&(p.row_jac->DSDX[INDEX5(0,0,0,isub,e,p.row_numShapesTotal,DIM,p.numQuadSub,p.numSub)]);
99 for (q=0;q<len_EM_S;++q) EM_S[q]=0;
100 for (q=0;q<len_EM_F;++q) EM_F[q]=0;
101 add_EM_F=FALSE;
102 add_EM_S=FALSE;
103
104 /**************************************************************/
105 /* process A: */
106 /**************************************************************/
107 if (NULL!=A_p) {
108 add_EM_S=TRUE;
109 if (extendedA) {
110 A_q=&(A_p[INDEX6(0,0,0,0,0,isub, p.numEqu,DIM,p.numComp,DIM,p.numQuadSub)]);
111 for (s=0;s<p.row_numShapes;s++) {
112 for (r=0;r<p.col_numShapes;r++) {
113 for (k=0;k<p.numEqu;k++) {
114 for (m=0;m<p.numComp;m++) {
115 rtmp=0;
116 for (q=0;q<p.numQuadSub;q++) {
117 rtmp+=Vol[q]*(
118 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)]
119 +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)]
120 +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)]
121 +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)]
122 +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)]
123 +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)]
124 +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)]
125 +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)]
126 +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)]);
127
128 }
129 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
130 }
131 }
132 }
133 }
134 } else {
135 for (s=0;s<p.row_numShapes;s++) {
136 for (r=0;r<p.col_numShapes;r++) {
137 rtmp00=0;
138 rtmp01=0;
139 rtmp02=0;
140 rtmp10=0;
141 rtmp11=0;
142 rtmp12=0;
143 rtmp20=0;
144 rtmp21=0;
145 rtmp22=0;
146 for (q=0;q<p.numQuadSub;q++) {
147 rtmp0=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
148 rtmp00+=rtmp0*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
149 rtmp01+=rtmp0*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
150 rtmp02+=rtmp0*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)];
151
152 rtmp1=Vol[q]*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
153 rtmp10+=rtmp1*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
154 rtmp11+=rtmp1*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
155 rtmp12+=rtmp1*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)];
156
157 rtmp2=Vol[q]*DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)];
158 rtmp20+=rtmp2*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
159 rtmp21+=rtmp2*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
160 rtmp22+=rtmp2*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)];
161 }
162 for (k=0;k<p.numEqu;k++) {
163 for (m=0;m<p.numComp;m++) {
164 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)]
165 +rtmp01*A_p[INDEX4(k,0,m,1, p.numEqu,DIM,p.numComp)]
166 +rtmp02*A_p[INDEX4(k,0,m,2, p.numEqu,DIM,p.numComp)]
167 +rtmp10*A_p[INDEX4(k,1,m,0, p.numEqu,DIM,p.numComp)]
168 +rtmp11*A_p[INDEX4(k,1,m,1, p.numEqu,DIM,p.numComp)]
169 +rtmp12*A_p[INDEX4(k,1,m,2, p.numEqu,DIM,p.numComp)]
170 +rtmp20*A_p[INDEX4(k,2,m,0, p.numEqu,DIM,p.numComp)]
171 +rtmp21*A_p[INDEX4(k,2,m,1, p.numEqu,DIM,p.numComp)]
172 +rtmp22*A_p[INDEX4(k,2,m,2, p.numEqu,DIM,p.numComp)];
173 }
174 }
175 }
176 }
177 }
178 }
179 /**************************************************************/
180 /* process B: */
181 /**************************************************************/
182 if (NULL!=B_p) {
183 add_EM_S=TRUE;
184 if (extendedB) {
185 B_q=&(B_p[INDEX5(0,0,0,0,isub, p.numEqu,DIM,p.numComp,p.numQuadSub)]);
186 for (s=0;s<p.row_numShapes;s++) {
187 for (r=0;r<p.col_numShapes;r++) {
188 for (k=0;k<p.numEqu;k++) {
189 for (m=0;m<p.numComp;m++) {
190 rtmp=0;
191 for (q=0;q<p.numQuadSub;q++) {
192 rtmp+=Vol[q]*S[INDEX2(r,q,p.row_numShapes)]*(
193 DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*B_q[INDEX4(k,0,m,q,p.numEqu,DIM,p.numComp)]
194 + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*B_q[INDEX4(k,1,m,q,p.numEqu,DIM,p.numComp)]
195 + DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)]*B_q[INDEX4(k,2,m,q,p.numEqu,DIM,p.numComp)] );
196 }
197 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
198 }
199 }
200 }
201 }
202 } else {
203 for (s=0;s<p.row_numShapes;s++) {
204 for (r=0;r<p.col_numShapes;r++) {
205 rtmp0=0;
206 rtmp1=0;
207 rtmp2=0;
208 for (q=0;q<p.numQuadSub;q++) {
209 rtmp=Vol[q]*S[INDEX2(r,q,p.row_numShapes)];
210 rtmp0+=rtmp*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
211 rtmp1+=rtmp*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
212 rtmp2+=rtmp*DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)];
213 }
214 for (k=0;k<p.numEqu;k++) {
215 for (m=0;m<p.numComp;m++) {
216 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp0*B_p[INDEX3(k,0,m,p.numEqu,DIM)]
217 +rtmp1*B_p[INDEX3(k,1,m,p.numEqu,DIM)]
218 +rtmp2*B_p[INDEX3(k,2,m,p.numEqu,DIM)];
219 }
220 }
221 }
222 }
223 }
224 }
225 /**************************************************************/
226 /* process C: */
227 /**************************************************************/
228 if (NULL!=C_p) {
229 add_EM_S=TRUE;
230 if (extendedC) {
231 C_q=&(C_p[INDEX5(0,0,0,0,isub ,p.numEqu,p.numComp,DIM, p.numQuadSub)]);
232 for (s=0;s<p.row_numShapes;s++) {
233 for (r=0;r<p.col_numShapes;r++) {
234 for (k=0;k<p.numEqu;k++) {
235 for (m=0;m<p.numComp;m++) {
236 rtmp=0;
237 for (q=0;q<p.numQuadSub;q++) {
238 rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*(
239 C_q[INDEX4(k,m,0,q,p.numEqu,p.numComp,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)]
240 +C_q[INDEX4(k,m,1,q,p.numEqu,p.numComp,DIM)]*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)]
241 +C_q[INDEX4(k,m,2,q,p.numEqu,p.numComp,DIM)]*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)]);
242 }
243 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
244 }
245 }
246 }
247 }
248 } else {
249 for (s=0;s<p.row_numShapes;s++) {
250 for (r=0;r<p.col_numShapes;r++) {
251 rtmp0=0;
252 rtmp1=0;
253 rtmp2=0;
254 for (q=0;q<p.numQuadSub;q++) {
255 rtmp=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
256 rtmp0+=rtmp*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
257 rtmp1+=rtmp*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
258 rtmp2+=rtmp*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)];
259 }
260 for (k=0;k<p.numEqu;k++) {
261 for (m=0;m<p.numComp;m++) {
262 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)]
263 +rtmp1*C_p[INDEX3(k,m,1,p.numEqu,p.numComp)]
264 +rtmp2*C_p[INDEX3(k,m,2,p.numEqu,p.numComp)];
265 }
266 }
267 }
268 }
269 }
270 }
271 /************************************************************* */
272 /* process D */
273 /**************************************************************/
274 if (NULL!=D_p) {
275 add_EM_S=TRUE;
276 if (extendedD) {
277 D_q=&(D_p[INDEX4(0,0,0,isub ,p.numEqu,p.numComp, p.numQuadSub)]);
278 for (s=0;s<p.row_numShapes;s++) {
279 for (r=0;r<p.col_numShapes;r++) {
280 for (k=0;k<p.numEqu;k++) {
281 for (m=0;m<p.numComp;m++) {
282 rtmp=0;
283 for (q=0;q<p.numQuadSub;q++) {
284 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)];
285 }
286 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
287 }
288 }
289 }
290 }
291 } else {
292 for (s=0;s<p.row_numShapes;s++) {
293 for (r=0;r<p.col_numShapes;r++) {
294 rtmp=0;
295 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(r,q,p.row_numShapes)];
296 for (k=0;k<p.numEqu;k++) {
297 for (m=0;m<p.numComp;m++) {
298 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*D_p[INDEX2(k,m,p.numEqu)];
299 }
300 }
301 }
302 }
303 }
304 }
305 /**************************************************************/
306 /* process X: */
307 /**************************************************************/
308 if (NULL!=X_p) {
309 add_EM_F=TRUE;
310 if (extendedX) {
311 X_q=&(X_p[INDEX4(0,0,0,isub, p.numEqu,DIM,p.numQuadSub)]);
312 for (s=0;s<p.row_numShapes;s++) {
313 for (k=0;k<p.numEqu;k++) {
314 rtmp=0;
315 for (q=0;q<p.numQuadSub;q++) {
316 rtmp+=Vol[q]* ( DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*X_q[INDEX3(k,0,q,p.numEqu,DIM)]
317 + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*X_q[INDEX3(k,1,q,p.numEqu,DIM)]
318 + DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)]*X_q[INDEX3(k,2,q,p.numEqu,DIM)]);
319 }
320 EM_F[INDEX2(k,s,p.numEqu)]+=rtmp;
321 }
322 }
323 } else {
324 for (s=0;s<p.row_numShapes;s++) {
325 rtmp0=0;
326 rtmp1=0;
327 rtmp2=0;
328 for (q=0;q<p.numQuadSub;q++) {
329 rtmp0+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
330 rtmp1+=Vol[q]*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
331 rtmp2+=Vol[q]*DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)];
332 }
333 for (k=0;k<p.numEqu;k++) {
334 EM_F[INDEX2(k,s,p.numEqu)]+=rtmp0*X_p[INDEX2(k,0,p.numEqu)]
335 +rtmp1*X_p[INDEX2(k,1,p.numEqu)]
336 +rtmp2*X_p[INDEX2(k,2,p.numEqu)];
337 }
338 }
339 }
340 }
341 /**************************************************************/
342 /* process Y: */
343 /**************************************************************/
344 if (NULL!=Y_p) {
345 add_EM_F=TRUE;
346 if (extendedY) {
347 Y_q=&(Y_p[INDEX3(0,0,isub, p.numEqu,p.numQuadSub)]);
348 for (s=0;s<p.row_numShapes;s++) {
349 for (k=0;k<p.numEqu;k++) {
350 rtmp=0.;
351 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*Y_q[INDEX2(k,q,p.numEqu)];
352 EM_F[INDEX2(k,s,p.numEqu)]+=rtmp;
353 }
354 }
355 } else {
356 for (s=0;s<p.row_numShapes;s++) {
357 rtmp=0;
358 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
359 for (k=0;k<p.numEqu;k++) EM_F[INDEX2(k,s,p.numEqu)]+=rtmp*Y_p[k];
360 }
361 }
362 }
363
364 /***********************************************************************************************/
365 /* add the element matrices onto the matrix and right hand side */
366 /***********************************************************************************************/
367 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)]];
368
369 if (add_EM_F) Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
370 if (add_EM_S) Finley_Assemble_addToSystemMatrix(Mat,p.row_numShapesTotal,row_index,p.numEqu,p.col_numShapesTotal,row_index,p.numComp,EM_S);
371 } /* end of subn */
372 } /* end color check */
373 } /* end element loop */
374 } /* end color loop */
375
376 THREAD_MEMFREE(EM_S);
377 THREAD_MEMFREE(EM_F);
378 THREAD_MEMFREE(row_index);
379
380 } /* end of pointer check */
381 } /* end parallel region */
382 }

  ViewVC Help
Powered by ViewVC 1.1.26