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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3259 - (show annotations)
Mon Oct 11 01:48:14 2010 UTC (8 years, 11 months ago) by jfenwick
File MIME type: text/plain
File size: 19691 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 2D 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 2 x p.numComp x 2 */
29 /* B = 2 x p.numEqu x p.numComp */
30 /* C = p.numEqu x 2 x p.numComp */
31 /* D = p.numEqu x p.numComp */
32 /* X = p.numEqu x 2 */
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_2D(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 2
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, rtmp00, rtmp10, rtmp01, rtmp11;
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, rtmp00, rtmp10, rtmp01, rtmp11,add_EM_F, add_EM_S, isub)
75 {
76
77 EM_S=THREAD_MEMALLOC(len_EM_S,double);
78 EM_F=THREAD_MEMALLOC(len_EM_F,double);
79 row_index=THREAD_MEMALLOC(p.row_numShapesTotal,index_t);
80
81 if (!Finley_checkPtr(EM_S) && !Finley_checkPtr(EM_F) && !Finley_checkPtr(row_index) ) {
82
83 for (color=elements->minColor;color<=elements->maxColor;color++) {
84 /* open loop over all elements: */
85 #pragma omp for private(e) schedule(static)
86 for(e=0;e<elements->numElements;e++){
87 if (elements->Color[e]==color) {
88
89 A_p=getSampleDataRO(A,e);
90 B_p=getSampleDataRO(B,e);
91 C_p=getSampleDataRO(C,e);
92 D_p=getSampleDataRO(D,e);
93 X_p=getSampleDataRO(X,e);
94 Y_p=getSampleDataRO(Y,e);
95
96 for (isub=0; isub<p.numSub; isub++) {
97
98 Vol=&(p.row_jac->volume[INDEX3(0,isub,e, p.numQuadSub,p.numSub)]);
99 DSDX=&(p.row_jac->DSDX[INDEX5(0,0,0,isub,e,p.row_numShapesTotal,DIM,p.numQuadSub,p.numSub)]);
100 for (q=0;q<len_EM_S;++q) EM_S[q]=0;
101 for (q=0;q<len_EM_F;++q) EM_F[q]=0;
102 add_EM_F=FALSE;
103 add_EM_S=FALSE;
104
105 /**************************************************************/
106 /* process A: */
107 /**************************************************************/
108 A_p=getSampleDataRO(A,e);
109 if (NULL!=A_p) {
110 add_EM_S=TRUE;
111 if (extendedA) {
112 A_q=&(A_p[INDEX6(0,0,0,0,0,isub, p.numEqu,DIM,p.numComp,DIM,p.numQuadSub)]);
113 for (s=0;s<p.row_numShapes;s++) {
114 for (r=0;r<p.col_numShapes;r++) {
115 for (k=0;k<p.numEqu;k++) {
116 for (m=0;m<p.numComp;m++) {
117 rtmp=0;
118 for (q=0;q<p.numQuadSub;q++) {
119 rtmp+=Vol[q]* (
120 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)]
121 +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)]
122 +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)]
123 +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)]);
124 }
125 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
126 }
127 }
128 }
129 }
130 } else {
131 for (s=0;s<p.row_numShapes;s++) {
132 for (r=0;r<p.col_numShapes;r++) {
133 rtmp00=0;
134 rtmp01=0;
135 rtmp10=0;
136 rtmp11=0;
137 for (q=0;q<p.numQuadSub;q++) {
138 rtmp0=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
139 rtmp1=Vol[q]*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
140 rtmp00+=rtmp0*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
141 rtmp01+=rtmp0*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
142 rtmp10+=rtmp1*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
143 rtmp11+=rtmp1*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
144 }
145 for (k=0;k<p.numEqu;k++) {
146 for (m=0;m<p.numComp;m++) {
147 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=
148 rtmp00*A_p[INDEX4(k,0,m,0,p.numEqu,DIM,p.numComp)]
149 +rtmp01*A_p[INDEX4(k,0,m,1,p.numEqu,DIM,p.numComp)]
150 +rtmp10*A_p[INDEX4(k,1,m,0,p.numEqu,DIM,p.numComp)]
151 +rtmp11*A_p[INDEX4(k,1,m,1,p.numEqu,DIM,p.numComp)];
152 }
153 }
154 }
155 }
156 }
157 }
158 /**************************************************************/
159 /* process B: */
160 /**************************************************************/
161 B_p=getSampleDataRO(B,e);
162 if (NULL!=B_p) {
163 add_EM_S=TRUE;
164 if (extendedB) {
165 B_q=&(B_p[INDEX5(0,0,0,0,isub ,p.numEqu,DIM,p.numComp,p.numQuadSub)]);
166 for (s=0;s<p.row_numShapes;s++) {
167 for (r=0;r<p.col_numShapes;r++) {
168 for (k=0;k<p.numEqu;k++) {
169 for (m=0;m<p.numComp;m++) {
170 rtmp=0;
171 for (q=0;q<p.numQuadSub;q++) {
172 rtmp+=Vol[q]*S[INDEX2(r,q,p.row_numShapes)]*
173 ( DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*B_q[INDEX4(k,0,m,q,p.numEqu,DIM,p.numComp)]
174 + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*B_q[INDEX4(k,1,m,q,p.numEqu,DIM,p.numComp)]);
175 }
176 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
177 }
178 }
179 }
180 }
181 } else {
182 for (s=0;s<p.row_numShapes;s++) {
183 for (r=0;r<p.col_numShapes;r++) {
184 rtmp0=0;
185 rtmp1=0;
186 for (q=0;q<p.numQuadSub;q++) {
187 rtmp=Vol[q]*S[INDEX2(r,q,p.row_numShapes)];
188 rtmp0+=rtmp*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
189 rtmp1+=rtmp*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
190 }
191 for (k=0;k<p.numEqu;k++) {
192 for (m=0;m<p.numComp;m++) {
193 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+= rtmp0*B_p[INDEX3(k,0,m,p.numEqu,DIM)]
194 + rtmp1*B_p[INDEX3(k,1,m,p.numEqu,DIM)];
195 }
196 }
197 }
198 }
199 }
200 }
201 /**************************************************************/
202 /* process C: */
203 /**************************************************************/
204 C_p=getSampleDataRO(C,e);
205 if (NULL!=C_p) {
206 add_EM_S=TRUE;
207 if (extendedC) {
208 C_q=&(C_p[INDEX5(0,0,0,0,isub, p.numEqu,p.numComp,DIM,p.numQuadSub)]);
209 for (s=0;s<p.row_numShapes;s++) {
210 for (r=0;r<p.col_numShapes;r++) {
211 for (k=0;k<p.numEqu;k++) {
212 for (m=0;m<p.numComp;m++) {
213 rtmp=0;
214 for (q=0;q<p.numQuadSub;q++) {
215 rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*
216 ( C_q[INDEX4(k,m,0,q,p.numEqu,p.numComp,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)]
217 + C_q[INDEX4(k,m,1,q,p.numEqu,p.numComp,DIM)]*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)]);
218 }
219 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
220 }
221 }
222 }
223 }
224 } else {
225 for (s=0;s<p.row_numShapes;s++) {
226 for (r=0;r<p.col_numShapes;r++) {
227 rtmp0=0;
228 rtmp1=0;
229 for (q=0;q<p.numQuadSub;q++) {
230 rtmp=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
231 rtmp0+=rtmp*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
232 rtmp1+=rtmp*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
233 }
234 for (k=0;k<p.numEqu;k++) {
235 for (m=0;m<p.numComp;m++) {
236 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)]
237 +rtmp1*C_p[INDEX3(k,m,1,p.numEqu,p.numComp)];
238 }
239 }
240 }
241 }
242 }
243 }
244 /************************************************************* */
245 /* process D */
246 /**************************************************************/
247 D_p=getSampleDataRO(D,e);
248 if (NULL!=D_p) {
249 add_EM_S=TRUE;
250 if (extendedD) {
251 D_q=&(D_p[INDEX4(0,0,0,isub, p.numEqu,p.numComp,p.numQuadSub)]);
252 for (s=0;s<p.row_numShapes;s++) {
253 for (r=0;r<p.col_numShapes;r++) {
254 for (k=0;k<p.numEqu;k++) {
255 for (m=0;m<p.numComp;m++) {
256 rtmp=0;
257 for (q=0;q<p.numQuadSub;q++) {
258 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)];
259 }
260 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
261 }
262 }
263 }
264 }
265 } else {
266 for (s=0;s<p.row_numShapes;s++) {
267 for (r=0;r<p.col_numShapes;r++) {
268 rtmp=0;
269 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(r,q,p.row_numShapes)];
270 for (k=0;k<p.numEqu;k++) {
271 for (m=0;m<p.numComp;m++) {
272 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*D_p[INDEX2(k,m,p.numEqu)];
273 }
274 }
275 }
276 }
277 }
278 }
279 /**************************************************************/
280 /* process X: */
281 /**************************************************************/
282 X_p=getSampleDataRO(X,e);
283 if (NULL!=X_p) {
284 add_EM_F=TRUE;
285 if (extendedX) {
286 X_q=&(X_p[INDEX4(0,0,0,isub, p.numEqu,DIM,p.numQuadSub)]);
287 for (s=0;s<p.row_numShapes;s++) {
288 for (k=0;k<p.numEqu;k++) {
289 rtmp=0;
290 for (q=0;q<p.numQuadSub;q++) {
291 rtmp+=Vol[q]*(DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*X_q[INDEX3(k,0,q,p.numEqu,DIM)]
292 +DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*X_q[INDEX3(k,1,q,p.numEqu,DIM)]);
293 }
294 EM_F[INDEX2(k,s,p.numEqu)]+=rtmp;
295 }
296 }
297 } else {
298 for (s=0;s<p.row_numShapes;s++) {
299 rtmp0=0;
300 rtmp1=0;
301 for (q=0;q<p.numQuadSub;q++) {
302 rtmp0+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
303 rtmp1+=Vol[q]*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
304 }
305 for (k=0;k<p.numEqu;k++) EM_F[INDEX2(k,s,p.numEqu)]+=rtmp0*X_p[INDEX2(k,0,p.numEqu)]+rtmp1*X_p[INDEX2(k,1,p.numEqu)];
306 }
307 }
308 }
309 /**************************************************************/
310 /* process Y: */
311 /**************************************************************/
312 Y_p=getSampleDataRO(Y,e);
313 if (NULL!=Y_p) {
314 add_EM_F=TRUE;
315 if (extendedY) {
316 Y_q=&(Y_p[INDEX3(0,0,isub, p.numEqu,p.numQuadSub)]);
317 for (s=0;s<p.row_numShapes;s++) {
318 for (k=0;k<p.numEqu;k++) {
319 rtmp=0;
320 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*Y_q[INDEX2(k,q,p.numEqu)];
321 EM_F[INDEX2(k,s,p.numEqu)]+=rtmp;
322 }
323 }
324 } else {
325 for (s=0;s<p.row_numShapes;s++) {
326 rtmp=0;
327 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
328 for (k=0;k<p.numEqu;k++) EM_F[INDEX2(k,s,p.numEqu)]+=rtmp*Y_p[k];
329 }
330 }
331 }
332 /***********************************************************************************************/
333 /* add the element matrices onto the matrix and right hand side */
334 /***********************************************************************************************/
335 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)]];
336
337 if (add_EM_F) Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
338 if (add_EM_S) Finley_Assemble_addToSystemMatrix(Mat,p.row_numShapesTotal,row_index,p.numEqu,p.col_numShapesTotal,row_index,p.numComp,EM_S);
339
340 } /* end of isub */
341 } /* end color check */
342 } /* end element loop */
343 } /* end color loop */
344
345 THREAD_MEMFREE(EM_S);
346 THREAD_MEMFREE(EM_F);
347 THREAD_MEMFREE(row_index);
348
349 } /* end of pointer check */
350 } /* end parallel region */
351 }
352 /*
353 * $Log$
354 */

  ViewVC Help
Powered by ViewVC 1.1.26