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

  ViewVC Help
Powered by ViewVC 1.1.26