/[escript]/branches/doubleplusgood/dudley/src/Assemble_PDE_System2_2D.cpp
ViewVC logotype

Contents of /branches/doubleplusgood/dudley/src/Assemble_PDE_System2_2D.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2881 - (show annotations)
Thu Jan 28 02:03:15 2010 UTC (9 years, 3 months ago) by jfenwick
Original Path: trunk/finley/src/Assemble_PDE_System2_2D.c
File MIME type: text/plain
File size: 19647 byte(s)
Don't panic.
Updating copyright stamps

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(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 2
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,k,m;
59 register double rtmp, rtmp0, rtmp1, rtmp00, rtmp10, rtmp01, rtmp11;
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*p.numEqu*p.numComp;
71 dim_t len_EM_F=p.row_numShapesTotal*p.numEqu;
72
73 #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)
74 {
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 A_p=getSampleDataRO(A,e);
108 if (NULL!=A_p) {
109 add_EM_S=TRUE;
110 if (extendedA) {
111 A_q=&(A_p[INDEX6(0,0,0,0,0,isub, p.numEqu,DIM,p.numComp,DIM,p.numQuadSub)]);
112 for (s=0;s<p.row_numShapes;s++) {
113 for (r=0;r<p.col_numShapes;r++) {
114 for (k=0;k<p.numEqu;k++) {
115 for (m=0;m<p.numComp;m++) {
116 rtmp=0;
117 for (q=0;q<p.numQuadSub;q++) {
118 rtmp+=Vol[q]* (
119 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)]
120 +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)]
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 }
124 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
125 }
126 }
127 }
128 }
129 } else {
130 for (s=0;s<p.row_numShapes;s++) {
131 for (r=0;r<p.col_numShapes;r++) {
132 rtmp00=0;
133 rtmp01=0;
134 rtmp10=0;
135 rtmp11=0;
136 for (q=0;q<p.numQuadSub;q++) {
137 rtmp0=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
138 rtmp1=Vol[q]*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
139 rtmp00+=rtmp0*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
140 rtmp01+=rtmp0*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
141 rtmp10+=rtmp1*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
142 rtmp11+=rtmp1*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
143 }
144 for (k=0;k<p.numEqu;k++) {
145 for (m=0;m<p.numComp;m++) {
146 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=
147 rtmp00*A_p[INDEX4(k,0,m,0,p.numEqu,DIM,p.numComp)]
148 +rtmp01*A_p[INDEX4(k,0,m,1,p.numEqu,DIM,p.numComp)]
149 +rtmp10*A_p[INDEX4(k,1,m,0,p.numEqu,DIM,p.numComp)]
150 +rtmp11*A_p[INDEX4(k,1,m,1,p.numEqu,DIM,p.numComp)];
151 }
152 }
153 }
154 }
155 }
156 }
157 /**************************************************************/
158 /* process B: */
159 /**************************************************************/
160 B_p=getSampleDataRO(B,e);
161 if (NULL!=B_p) {
162 add_EM_S=TRUE;
163 if (extendedB) {
164 B_q=&(B_p[INDEX5(0,0,0,0,isub ,p.numEqu,DIM,p.numComp,p.numQuadSub)]);
165 for (s=0;s<p.row_numShapes;s++) {
166 for (r=0;r<p.col_numShapes;r++) {
167 for (k=0;k<p.numEqu;k++) {
168 for (m=0;m<p.numComp;m++) {
169 rtmp=0;
170 for (q=0;q<p.numQuadSub;q++) {
171 rtmp+=Vol[q]*S[INDEX2(r,q,p.row_numShapes)]*
172 ( DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*B_q[INDEX4(k,0,m,q,p.numEqu,DIM,p.numComp)]
173 + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*B_q[INDEX4(k,1,m,q,p.numEqu,DIM,p.numComp)]);
174 }
175 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
176 }
177 }
178 }
179 }
180 } else {
181 for (s=0;s<p.row_numShapes;s++) {
182 for (r=0;r<p.col_numShapes;r++) {
183 rtmp0=0;
184 rtmp1=0;
185 for (q=0;q<p.numQuadSub;q++) {
186 rtmp=Vol[q]*S[INDEX2(r,q,p.row_numShapes)];
187 rtmp0+=rtmp*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
188 rtmp1+=rtmp*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
189 }
190 for (k=0;k<p.numEqu;k++) {
191 for (m=0;m<p.numComp;m++) {
192 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+= rtmp0*B_p[INDEX3(k,0,m,p.numEqu,DIM)]
193 + rtmp1*B_p[INDEX3(k,1,m,p.numEqu,DIM)];
194 }
195 }
196 }
197 }
198 }
199 }
200 /**************************************************************/
201 /* process C: */
202 /**************************************************************/
203 C_p=getSampleDataRO(C,e);
204 if (NULL!=C_p) {
205 add_EM_S=TRUE;
206 if (extendedC) {
207 C_q=&(C_p[INDEX5(0,0,0,0,isub, p.numEqu,p.numComp,DIM,p.numQuadSub)]);
208 for (s=0;s<p.row_numShapes;s++) {
209 for (r=0;r<p.col_numShapes;r++) {
210 for (k=0;k<p.numEqu;k++) {
211 for (m=0;m<p.numComp;m++) {
212 rtmp=0;
213 for (q=0;q<p.numQuadSub;q++) {
214 rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*
215 ( C_q[INDEX4(k,m,0,q,p.numEqu,p.numComp,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)]
216 + C_q[INDEX4(k,m,1,q,p.numEqu,p.numComp,DIM)]*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)]);
217 }
218 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
219 }
220 }
221 }
222 }
223 } else {
224 for (s=0;s<p.row_numShapes;s++) {
225 for (r=0;r<p.col_numShapes;r++) {
226 rtmp0=0;
227 rtmp1=0;
228 for (q=0;q<p.numQuadSub;q++) {
229 rtmp=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
230 rtmp0+=rtmp*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
231 rtmp1+=rtmp*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
232 }
233 for (k=0;k<p.numEqu;k++) {
234 for (m=0;m<p.numComp;m++) {
235 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)]
236 +rtmp1*C_p[INDEX3(k,m,1,p.numEqu,p.numComp)];
237 }
238 }
239 }
240 }
241 }
242 }
243 /************************************************************* */
244 /* process D */
245 /**************************************************************/
246 D_p=getSampleDataRO(D,e);
247 if (NULL!=D_p) {
248 add_EM_S=TRUE;
249 if (extendedD) {
250 D_q=&(D_p[INDEX4(0,0,0,isub, p.numEqu,p.numComp,p.numQuadSub)]);
251 for (s=0;s<p.row_numShapes;s++) {
252 for (r=0;r<p.col_numShapes;r++) {
253 for (k=0;k<p.numEqu;k++) {
254 for (m=0;m<p.numComp;m++) {
255 rtmp=0;
256 for (q=0;q<p.numQuadSub;q++) {
257 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)];
258 }
259 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
260 }
261 }
262 }
263 }
264 } else {
265 for (s=0;s<p.row_numShapes;s++) {
266 for (r=0;r<p.col_numShapes;r++) {
267 rtmp=0;
268 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(r,q,p.row_numShapes)];
269 for (k=0;k<p.numEqu;k++) {
270 for (m=0;m<p.numComp;m++) {
271 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*D_p[INDEX2(k,m,p.numEqu)];
272 }
273 }
274 }
275 }
276 }
277 }
278 /**************************************************************/
279 /* process X: */
280 /**************************************************************/
281 X_p=getSampleDataRO(X,e);
282 if (NULL!=X_p) {
283 add_EM_F=TRUE;
284 if (extendedX) {
285 X_q=&(X_p[INDEX4(0,0,0,isub, p.numEqu,DIM,p.numQuadSub)]);
286 for (s=0;s<p.row_numShapes;s++) {
287 for (k=0;k<p.numEqu;k++) {
288 rtmp=0;
289 for (q=0;q<p.numQuadSub;q++) {
290 rtmp+=Vol[q]*(DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*X_q[INDEX3(k,0,q,p.numEqu,DIM)]
291 +DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*X_q[INDEX3(k,1,q,p.numEqu,DIM)]);
292 }
293 EM_F[INDEX2(k,s,p.numEqu)]+=rtmp;
294 }
295 }
296 } else {
297 for (s=0;s<p.row_numShapes;s++) {
298 rtmp0=0;
299 rtmp1=0;
300 for (q=0;q<p.numQuadSub;q++) {
301 rtmp0+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
302 rtmp1+=Vol[q]*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
303 }
304 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)];
305 }
306 }
307 }
308 /**************************************************************/
309 /* process Y: */
310 /**************************************************************/
311 Y_p=getSampleDataRO(Y,e);
312 if (NULL!=Y_p) {
313 add_EM_F=TRUE;
314 if (extendedY) {
315 Y_q=&(Y_p[INDEX3(0,0,isub, p.numEqu,p.numQuadSub)]);
316 for (s=0;s<p.row_numShapes;s++) {
317 for (k=0;k<p.numEqu;k++) {
318 rtmp=0;
319 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*Y_q[INDEX2(k,q,p.numEqu)];
320 EM_F[INDEX2(k,s,p.numEqu)]+=rtmp;
321 }
322 }
323 } else {
324 for (s=0;s<p.row_numShapes;s++) {
325 rtmp=0;
326 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
327 for (k=0;k<p.numEqu;k++) EM_F[INDEX2(k,s,p.numEqu)]+=rtmp*Y_p[k];
328 }
329 }
330 }
331 /***********************************************************************************************/
332 /* add the element matrices onto the matrix and right hand side */
333 /***********************************************************************************************/
334 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)]];
335
336 if (add_EM_F) Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
337 if (add_EM_S) Finley_Assemble_addToSystemMatrix(Mat,p.row_numShapesTotal,row_index,p.numEqu,p.col_numShapesTotal,row_index,p.numComp,EM_S);
338
339 } /* end of isub */
340 } /* end color check */
341 } /* end element loop */
342 } /* end color loop */
343
344 THREAD_MEMFREE(EM_S);
345 THREAD_MEMFREE(EM_F);
346 THREAD_MEMFREE(row_index);
347
348 } /* end of pointer check */
349 } /* end parallel region */
350 }
351 /*
352 * $Log$
353 */

  ViewVC Help
Powered by ViewVC 1.1.26