/[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 2271 - (show annotations)
Mon Feb 16 05:08:29 2009 UTC (10 years, 4 months ago) by jfenwick
Original Path: trunk/finley/src/Assemble_PDE_System2_3D.c
File MIME type: text/plain
File size: 21366 byte(s)
Merging version 2269 to trunk

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

  ViewVC Help
Powered by ViewVC 1.1.26