/[escript]/branches/doubleplusgood/finley/src/Assemble_PDE_Single2_3D.cpp
ViewVC logotype

Contents of /branches/doubleplusgood/finley/src/Assemble_PDE_Single2_3D.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4327 - (show annotations)
Wed Mar 20 05:09:11 2013 UTC (6 years, 7 months ago) by jfenwick
File size: 20036 byte(s)
some finley memory
1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2013 by University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development since 2012 by School of Earth Sciences
13 *
14 *****************************************************************************/
15
16
17 /************************************************************************************/
18
19 /* assembles the system of numEq PDEs into the stiffness matrix S and right hand side F */
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(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;
60 register double rtmp, rtmp00, rtmp01, rtmp02, rtmp10, rtmp11, rtmp12, rtmp20, rtmp21, rtmp22, rtmp0, rtmp1, rtmp2;
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;
72 dim_t len_EM_F=p.row_numShapesTotal;
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,rtmp, rtmp00, rtmp01, rtmp02, rtmp10, rtmp11, rtmp12, rtmp20, rtmp21, rtmp22, rtmp0, rtmp1, rtmp2,add_EM_F, add_EM_S, isub)
75 {
76 EM_S=new double[len_EM_S];
77 EM_F=new double[len_EM_F];
78 row_index=new index_t[p.row_numShapesTotal];
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[INDEX4(0,0,0,isub, DIM,DIM,p.numQuadSub)]);
111 for (s=0;s<p.row_numShapes;s++) {
112 for (r=0;r<p.col_numShapes;r++) {
113 rtmp=0;
114 for (q=0;q<p.numQuadSub;q++) {
115 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)]
116 + 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)]
117 + 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)]
118 + 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)]
119 + 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)]
120 + 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)]
121 + 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)]
122 + 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)]
123 + 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)]);
124 }
125 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
126 }
127 }
128 } else {
129 for (s=0;s<p.row_numShapes;s++) {
130 for (r=0;r<p.col_numShapes;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.numQuadSub;q++) {
141
142 rtmp0=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
143 rtmp00+=rtmp0*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
144 rtmp01+=rtmp0*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
145 rtmp02+=rtmp0*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)];
146
147 rtmp1=Vol[q]*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
148 rtmp10+=rtmp1*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
149 rtmp11+=rtmp1*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
150 rtmp12+=rtmp1*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)];
151
152 rtmp2=Vol[q]*DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)];
153 rtmp20+=rtmp2*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
154 rtmp21+=rtmp2*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
155 rtmp22+=rtmp2*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)];
156 }
157 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp00*A_p[INDEX2(0,0,DIM)]
158 +rtmp01*A_p[INDEX2(0,1,DIM)]
159 +rtmp02*A_p[INDEX2(0,2,DIM)]
160 +rtmp10*A_p[INDEX2(1,0,DIM)]
161 +rtmp11*A_p[INDEX2(1,1,DIM)]
162 +rtmp12*A_p[INDEX2(1,2,DIM)]
163 +rtmp20*A_p[INDEX2(2,0,DIM)]
164 +rtmp21*A_p[INDEX2(2,1,DIM)]
165 +rtmp22*A_p[INDEX2(2,2,DIM)];
166 }
167 }
168 }
169 }
170 /************************************************************************************/
171 /* process B: */
172 /************************************************************************************/
173 if (NULL!=B_p) {
174 add_EM_S=TRUE;
175 if (extendedB) {
176 B_q=&(B_p[INDEX3(0,0,isub, DIM,p.numQuadSub)]);
177 for (s=0;s<p.row_numShapes;s++) {
178 for (r=0;r<p.col_numShapes;r++) {
179 rtmp=0;
180 for (q=0;q<p.numQuadSub;q++) {
181 rtmp+=Vol[q]*S[INDEX2(r,q,p.row_numShapes)]*
182 ( DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*B_q[INDEX2(0,q,DIM)]
183 + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*B_q[INDEX2(1,q,DIM)]
184 + DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)]*B_q[INDEX2(2,q,DIM)]);
185 }
186 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
187 }
188 }
189 } else {
190 for (s=0;s<p.row_numShapes;s++) {
191 for (r=0;r<p.col_numShapes;r++) {
192 rtmp0=0;
193 rtmp1=0;
194 rtmp2=0;
195 for (q=0;q<p.numQuadSub;q++) {
196 rtmp=Vol[q]*S[INDEX2(r,q,p.row_numShapes)];
197 rtmp0+=rtmp*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
198 rtmp1+=rtmp*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
199 rtmp2+=rtmp*DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)];
200 }
201 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];
202 }
203 }
204 }
205 }
206 /************************************************************************************/
207 /* process C: */
208 /************************************************************************************/
209 if (NULL!=C_p) {
210 add_EM_S=TRUE;
211 if (extendedC) {
212 C_q=&(C_p[INDEX3(0,0,isub, DIM, p.numQuadSub)]);
213 for (s=0;s<p.row_numShapes;s++) {
214 for (r=0;r<p.col_numShapes;r++) {
215 rtmp=0;
216 for (q=0;q<p.numQuadSub;q++) {
217 rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*
218 ( C_q[INDEX2(0,q,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)]
219 + C_q[INDEX2(1,q,DIM)]*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)]
220 + C_q[INDEX2(2,q,DIM)]*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)]);
221 }
222 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
223 }
224 }
225 } else {
226 for (s=0;s<p.row_numShapes;s++) {
227 for (r=0;r<p.col_numShapes;r++) {
228 rtmp0=0;
229 rtmp1=0;
230 rtmp2=0;
231 for (q=0;q<p.numQuadSub;q++) {
232 rtmp=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
233 rtmp0+=rtmp*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
234 rtmp1+=rtmp*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
235 rtmp2+=rtmp*DSDX[INDEX3(r,2,q,p.row_numShapesTotal,DIM)];
236 }
237 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];
238 }
239 }
240 }
241 }
242 /*********************************************************************************** */
243 /* process D */
244 /************************************************************************************/
245 if (NULL!=D_p) {
246 add_EM_S=TRUE;
247 if (extendedD) {
248 D_q=&(D_p[INDEX2(0,isub, p.numQuadSub)]);
249 for (s=0;s<p.row_numShapes;s++) {
250 for (r=0;r<p.col_numShapes;r++) {
251 rtmp=0;
252 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)];
253 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
254 }
255 }
256 } else {
257 for (s=0;s<p.row_numShapes;s++) {
258 for (r=0;r<p.col_numShapes;r++) {
259 rtmp=0;
260 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(r,q,p.row_numShapes)];
261 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*D_p[0];
262 }
263 }
264 }
265 }
266 /************************************************************************************/
267 /* process X: */
268 /************************************************************************************/
269 if (NULL!=X_p) {
270 add_EM_F=TRUE;
271 if (extendedX) {
272 X_q=&(X_p[INDEX3(0,0,isub, DIM,p.numQuadSub)]);
273 for (s=0;s<p.row_numShapes;s++) {
274 rtmp=0;
275 for (q=0;q<p.numQuadSub;q++) {
276 rtmp+=Vol[q]*( DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*X_q[INDEX2(0,q,DIM)]
277 + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*X_q[INDEX2(1,q,DIM)]
278 + DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)]*X_q[INDEX2(2,q,DIM)]);
279 }
280 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
281 }
282 } else {
283 for (s=0;s<p.row_numShapes;s++) {
284 rtmp0=0;
285 rtmp1=0;
286 rtmp2=0;
287 for (q=0;q<p.numQuadSub;q++) {
288 rtmp0+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
289 rtmp1+=Vol[q]*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
290 rtmp2+=Vol[q]*DSDX[INDEX3(s,2,q,p.row_numShapesTotal,DIM)];
291 }
292 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp0*X_p[0]+rtmp1*X_p[1]+rtmp2*X_p[2];
293 }
294 }
295 }
296 /************************************************************************************/
297 /* process Y: */
298 /************************************************************************************/
299 if (NULL!=Y_p) {
300 add_EM_F=TRUE;
301 if (extendedY) {
302 Y_q=&(Y_p[INDEX2(0,isub, p.numQuadSub)]);
303 for (s=0;s<p.row_numShapes;s++) {
304 rtmp=0;
305 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*Y_q[q];
306 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
307 }
308 } else {
309 for (s=0;s<p.row_numShapes;s++) {
310 rtmp=0;
311 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
312 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp*Y_p[0];
313 }
314 }
315 }
316 /*********************************************************************************************************************/
317 /* add the element matrices onto the matrix and right hand side */
318 /*********************************************************************************************************************/
319
320 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)]];
321
322 if (add_EM_F) Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
323 if (add_EM_S) Finley_Assemble_addToSystemMatrix(Mat,p.row_numShapesTotal,row_index,p.numEqu,p.col_numShapesTotal,row_index,p.numComp,EM_S);
324
325 } /* end of isub */
326 } /* end color check */
327 } /* end element loop */
328 } /* end color loop */
329
330 delete[] EM_S;
331 delete[] EM_F;
332 delete[] row_index;
333
334 } /* end of pointer check */
335 } /* end parallel region */
336 }

  ViewVC Help
Powered by ViewVC 1.1.26