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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2748 - (show annotations)
Tue Nov 17 07:32:59 2009 UTC (10 years, 4 months ago) by gross
File MIME type: text/plain
File size: 20054 byte(s)
Macro elements are implemented now. VTK writer for macro elements still needs testing.
1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2009 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 Finley_Assemble_PDE_Single2_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, isub;
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 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, 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, isub)
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_numShapesTotal,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
93 A_p=getSampleDataRO(A,e,ABuff);
94 B_p=getSampleDataRO(B,e,BBuff);
95 C_p=getSampleDataRO(C,e,CBuff);
96 D_p=getSampleDataRO(D,e,DBuff);
97 X_p=getSampleDataRO(X,e,XBuff);
98 Y_p=getSampleDataRO(Y,e,YBuff);
99
100 for (isub=0; isub<p.numSub; isub++) {
101
102 Vol=&(p.row_jac->volume[INDEX3(0,isub,e, p.numQuadSub,p.numSub)]);
103 DSDX=&(p.row_jac->DSDX[INDEX5(0,0,0,isub,e,p.row_numShapesTotal,DIM,p.numQuadSub,p.numSub)]);
104 for (q=0;q<len_EM_S;++q) EM_S[q]=0;
105 for (q=0;q<len_EM_F;++q) EM_F[q]=0;
106 add_EM_F=FALSE;
107 add_EM_S=FALSE;
108
109 /**************************************************************/
110 /* process A: */
111 /**************************************************************/
112 if (NULL!=A_p) {
113 add_EM_S=TRUE;
114 if (extendedA) {
115 A_q=&(A_p[INDEX4(0,0,0,isub, DIM,DIM,p.numQuadSub)]);
116 for (s=0;s<p.row_numShapes;s++) {
117 for (r=0;r<p.col_numShapes;r++) {
118 rtmp=0;
119 for (q=0;q<p.numQuadSub;q++) {
120 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)]
121 + 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)]
122 + 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)]
123 + 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)]
124 + 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)]
125 + 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)]
126 + 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)]
127 + 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)]
128 + 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)]);
129 }
130 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
131 }
132 }
133 } else {
134 for (s=0;s<p.row_numShapes;s++) {
135 for (r=0;r<p.col_numShapes;r++) {
136 rtmp00=0;
137 rtmp01=0;
138 rtmp02=0;
139 rtmp10=0;
140 rtmp11=0;
141 rtmp12=0;
142 rtmp20=0;
143 rtmp21=0;
144 rtmp22=0;
145 for (q=0;q<p.numQuadSub;q++) {
146
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 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp00*A_p[INDEX2(0,0,DIM)]
163 +rtmp01*A_p[INDEX2(0,1,DIM)]
164 +rtmp02*A_p[INDEX2(0,2,DIM)]
165 +rtmp10*A_p[INDEX2(1,0,DIM)]
166 +rtmp11*A_p[INDEX2(1,1,DIM)]
167 +rtmp12*A_p[INDEX2(1,2,DIM)]
168 +rtmp20*A_p[INDEX2(2,0,DIM)]
169 +rtmp21*A_p[INDEX2(2,1,DIM)]
170 +rtmp22*A_p[INDEX2(2,2,DIM)];
171 }
172 }
173 }
174 }
175 /**************************************************************/
176 /* process B: */
177 /**************************************************************/
178 if (NULL!=B_p) {
179 add_EM_S=TRUE;
180 if (extendedB) {
181 B_q=&(B_p[INDEX3(0,0,isub, DIM,p.numQuadSub)]);
182 for (s=0;s<p.row_numShapes;s++) {
183 for (r=0;r<p.col_numShapes;r++) {
184 rtmp=0;
185 for (q=0;q<p.numQuadSub;q++) {
186 rtmp+=Vol[q]*S[INDEX2(r,q,p.row_numShapes)]*
187 ( DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*B_q[INDEX2(0,q,DIM)]
188 + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*B_q[INDEX2(1,q,DIM)]
189 + DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)]*B_q[INDEX2(2,q,DIM)]);
190 }
191 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
192 }
193 }
194 } else {
195 for (s=0;s<p.row_numShapes;s++) {
196 for (r=0;r<p.col_numShapes;r++) {
197 rtmp0=0;
198 rtmp1=0;
199 rtmp2=0;
200 for (q=0;q<p.numQuadSub;q++) {
201 rtmp=Vol[q]*S[INDEX2(r,q,p.row_numShapes)];
202 rtmp0+=rtmp*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
203 rtmp1+=rtmp*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
204 rtmp2+=rtmp*DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)];
205 }
206 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];
207 }
208 }
209 }
210 }
211 /**************************************************************/
212 /* process C: */
213 /**************************************************************/
214 if (NULL!=C_p) {
215 add_EM_S=TRUE;
216 if (extendedC) {
217 C_q=&(C_p[INDEX3(0,0,isub, DIM, p.numQuadSub)]);
218 for (s=0;s<p.row_numShapes;s++) {
219 for (r=0;r<p.col_numShapes;r++) {
220 rtmp=0;
221 for (q=0;q<p.numQuadSub;q++) {
222 rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*
223 ( C_q[INDEX2(0,q,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)]
224 + C_q[INDEX2(1,q,DIM)]*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)]
225 + C_q[INDEX2(2,q,DIM)]*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)]);
226 }
227 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
228 }
229 }
230 } else {
231 for (s=0;s<p.row_numShapes;s++) {
232 for (r=0;r<p.col_numShapes;r++) {
233 rtmp0=0;
234 rtmp1=0;
235 rtmp2=0;
236 for (q=0;q<p.numQuadSub;q++) {
237 rtmp=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
238 rtmp0+=rtmp*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
239 rtmp1+=rtmp*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
240 rtmp2+=rtmp*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)];
241 }
242 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];
243 }
244 }
245 }
246 }
247 /************************************************************* */
248 /* process D */
249 /**************************************************************/
250 if (NULL!=D_p) {
251 add_EM_S=TRUE;
252 if (extendedD) {
253 D_q=&(D_p[INDEX2(0,isub, p.numQuadSub)]);
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.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*D_q[q]*S[INDEX2(r,q,p.row_numShapes)];
258 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
259 }
260 }
261 } else {
262 for (s=0;s<p.row_numShapes;s++) {
263 for (r=0;r<p.col_numShapes;r++) {
264 rtmp=0;
265 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(r,q,p.row_numShapes)];
266 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*D_p[0];
267 }
268 }
269 }
270 }
271 /**************************************************************/
272 /* process X: */
273 /**************************************************************/
274 if (NULL!=X_p) {
275 add_EM_F=TRUE;
276 if (extendedX) {
277 X_q=&(X_p[INDEX3(0,0,isub, DIM,p.numQuadSub)]);
278 for (s=0;s<p.row_numShapes;s++) {
279 rtmp=0;
280 for (q=0;q<p.numQuadSub;q++) {
281 rtmp+=Vol[q]*( DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*X_q[INDEX2(0,q,DIM)]
282 + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*X_q[INDEX2(1,q,DIM)]
283 + DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)]*X_q[INDEX2(2,q,DIM)]);
284 }
285 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
286 }
287 } else {
288 for (s=0;s<p.row_numShapes;s++) {
289 rtmp0=0;
290 rtmp1=0;
291 rtmp2=0;
292 for (q=0;q<p.numQuadSub;q++) {
293 rtmp0+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
294 rtmp1+=Vol[q]*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
295 rtmp2+=Vol[q]*DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)];
296 }
297 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp0*X_p[0]+rtmp1*X_p[1]+rtmp2*X_p[2];
298 }
299 }
300 }
301 /**************************************************************/
302 /* process Y: */
303 /**************************************************************/
304 if (NULL!=Y_p) {
305 add_EM_F=TRUE;
306 if (extendedY) {
307 Y_q=&(Y_p[INDEX2(0,isub, p.numQuadSub)]);
308 for (s=0;s<p.row_numShapes;s++) {
309 rtmp=0;
310 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*Y_q[q];
311 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
312 }
313 } else {
314 for (s=0;s<p.row_numShapes;s++) {
315 rtmp=0;
316 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
317 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp*Y_p[0];
318 }
319 }
320 }
321 /***********************************************************************************************/
322 /* add the element matrices onto the matrix and right hand side */
323 /***********************************************************************************************/
324
325 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)]];
326
327 if (add_EM_F) Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
328 if (add_EM_S) Finley_Assemble_addToSystemMatrix(Mat,p.row_numShapesTotal,row_index,p.numEqu,p.col_numShapesTotal,row_index,p.numComp,EM_S);
329
330 } /* end of isub */
331 } /* end color check */
332 } /* end element loop */
333 } /* end color loop */
334
335 THREAD_MEMFREE(EM_S);
336 THREAD_MEMFREE(EM_F);
337 THREAD_MEMFREE(row_index);
338
339 } /* end of pointer check */
340 } /* end parallel region */
341 freeSampleBuffer(ABuff);
342 freeSampleBuffer(BBuff);
343 freeSampleBuffer(CBuff);
344 freeSampleBuffer(DBuff);
345 freeSampleBuffer(XBuff);
346 freeSampleBuffer(YBuff);
347 }

  ViewVC Help
Powered by ViewVC 1.1.26