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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2748 - (show annotations)
Tue Nov 17 07:32:59 2009 UTC (10 years ago) by gross
File MIME type: text/plain
File size: 16532 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 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 = 2 x 2 */
29 /* B = 2 */
30 /* C = 2 */
31 /* D = scalar */
32 /* X = 2 */
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 void Finley_Assemble_PDE_Single2_2D(Assemble_Parameters p, Finley_ElementFile* elements,
48 Paso_SystemMatrix* Mat, escriptDataC* F,
49 escriptDataC* A, escriptDataC* B, escriptDataC* C, escriptDataC* D, escriptDataC* X, escriptDataC* Y) {
50
51 #define DIM 2
52 index_t color;
53 dim_t e,isub;
54 __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;
55 double *EM_S, *EM_F, *Vol, *DSDX;
56 index_t *row_index;
57 register dim_t q, s,r;
58 register double rtmp00, rtmp01, rtmp10, rtmp11, rtmp, rtmp0, rtmp1;
59 bool_t add_EM_F, add_EM_S;
60
61 bool_t extendedA=isExpanded(A);
62 bool_t extendedB=isExpanded(B);
63 bool_t extendedC=isExpanded(C);
64 bool_t extendedD=isExpanded(D);
65 bool_t extendedX=isExpanded(X);
66 bool_t extendedY=isExpanded(Y);
67 double *F_p=(requireWrite(F), getSampleDataRW(F,0)); /* use comma, to get around the mixed code and declarations thing */
68 double *S=p.row_jac->BasisFunctions->S;
69 dim_t len_EM_S=p.row_numShapesTotal*p.col_numShapesTotal;
70 dim_t len_EM_F=p.row_numShapesTotal;
71
72 void* ABuff=allocSampleBuffer(A);
73 void* BBuff=allocSampleBuffer(B);
74 void* CBuff=allocSampleBuffer(C);
75 void* DBuff=allocSampleBuffer(D);
76 void* XBuff=allocSampleBuffer(X);
77 void* YBuff=allocSampleBuffer(Y);
78 #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,rtmp00, rtmp01, rtmp10, rtmp11, rtmp, rtmp0, rtmp1,add_EM_F, add_EM_S, isub)
79 {
80 EM_S=THREAD_MEMALLOC(len_EM_S,double);
81 EM_F=THREAD_MEMALLOC(len_EM_F,double);
82 row_index=THREAD_MEMALLOC(p.row_numShapesTotal,index_t);
83
84 if (!Finley_checkPtr(EM_S) && !Finley_checkPtr(EM_F) && !Finley_checkPtr(row_index) ) {
85
86 for (color=elements->minColor;color<=elements->maxColor;color++) {
87 /* open loop over all elements: */
88 #pragma omp for private(e) schedule(static)
89 for(e=0;e<elements->numElements;e++){
90 if (elements->Color[e]==color) {
91
92 A_p=getSampleDataRO(A,e,ABuff);
93 B_p=getSampleDataRO(B,e,BBuff);
94 C_p=getSampleDataRO(C,e,CBuff);
95 D_p=getSampleDataRO(D,e,DBuff);
96 X_p=getSampleDataRO(X,e,XBuff);
97 Y_p=getSampleDataRO(Y,e,YBuff);
98
99 for (isub=0; isub<p.numSub; isub++) {
100
101 Vol=&(p.row_jac->volume[INDEX3(0,isub,e, p.numQuadSub,p.numSub)]);
102 DSDX=&(p.row_jac->DSDX[INDEX5(0,0,0,isub,e, p.row_numShapesTotal,DIM,p.numQuadSub,p.numSub)]);
103 for (q=0;q<len_EM_S;++q) EM_S[q]=0;
104 for (q=0;q<len_EM_F;++q) EM_F[q]=0;
105 add_EM_F=FALSE;
106 add_EM_S=FALSE;
107 /**************************************************************/
108 /* process A: */
109 /**************************************************************/
110 if (NULL!=A_p) {
111 add_EM_S=TRUE;
112 if (extendedA) {
113 A_q=&(A_p[INDEX4(0,0,0,isub, DIM,DIM,p.numQuadSub)]);
114 for (s=0;s<p.row_numShapes;s++) {
115 for (r=0;r<p.col_numShapes;r++) {
116 rtmp=0;
117 for (q=0;q<p.numQuadSub;q++) {
118 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)]
119 + 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)]
120 + 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)]
121 + 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)] );
122 }
123 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
124 }
125 }
126 } else {
127 for (s=0;s<p.row_numShapes;s++) {
128 for (r=0;r<p.col_numShapes;r++) {
129 rtmp00=0;
130 rtmp01=0;
131 rtmp10=0;
132 rtmp11=0;
133 for (q=0;q<p.numQuadSub;q++) {
134 rtmp0=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
135 rtmp1=Vol[q]*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
136 rtmp00+=rtmp0*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
137 rtmp01+=rtmp0*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
138 rtmp10+=rtmp1*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
139 rtmp11+=rtmp1*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
140 }
141 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+= rtmp00*A_p[INDEX2(0,0,DIM)]
142 + rtmp01*A_p[INDEX2(0,1,DIM)]
143 + rtmp10*A_p[INDEX2(1,0,DIM)]
144 + rtmp11*A_p[INDEX2(1,1,DIM)];
145 }
146 }
147 }
148 }
149 /**************************************************************/
150 /* process B: */
151 /**************************************************************/
152 if (NULL!=B_p) {
153 add_EM_S=TRUE;
154 if (extendedB) {
155 B_q=&(B_p[INDEX3(0,0,isub, DIM,p.numQuadSub)]);
156 for (s=0;s<p.row_numShapes;s++) {
157 for (r=0;r<p.col_numShapes;r++) {
158 rtmp=0.;
159 for (q=0;q<p.numQuadSub;q++) {
160 rtmp+=Vol[q]*S[INDEX2(r,q,p.row_numShapes)]*(DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*B_q[INDEX2(0,q,DIM)]
161 + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*B_q[INDEX2(1,q,DIM)]);
162 }
163 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
164 }
165 }
166 } else {
167 for (s=0;s<p.row_numShapes;s++) {
168 for (r=0;r<p.col_numShapes;r++) {
169 rtmp0=0;
170 rtmp1=0;
171 for (q=0;q<p.numQuadSub;q++) {
172 rtmp=Vol[q]*S[INDEX2(r,q,p.row_numShapes)];
173 rtmp0+=rtmp*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
174 rtmp1+=rtmp*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
175 }
176 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp0*B_p[0]+rtmp1*B_p[1];
177 }
178 }
179 }
180 }
181 /**************************************************************/
182 /* process C: */
183 /**************************************************************/
184 if (NULL!=C_p) {
185 add_EM_S=TRUE;
186 if (extendedC) {
187 C_q=&(C_p[INDEX3(0,0,isub, DIM, p.numQuadSub)]);
188 for (s=0;s<p.row_numShapes;s++) {
189 for (r=0;r<p.col_numShapes;r++) {
190 rtmp=0;
191 for (q=0;q<p.numQuadSub;q++) {
192 rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*(C_q[INDEX2(0,q,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)]
193 + C_q[INDEX2(1,q,DIM)]*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)]);
194 }
195 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
196 }
197 }
198 } else {
199 for (s=0;s<p.row_numShapes;s++) {
200 for (r=0;r<p.col_numShapes;r++) {
201 rtmp0=0;
202 rtmp1=0;
203 for (q=0;q<p.numQuadSub;q++) {
204 rtmp=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
205 rtmp0+=rtmp*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
206 rtmp1+=rtmp*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
207 }
208 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp0*C_p[0]+rtmp1*C_p[1];
209 }
210 }
211 }
212 }
213 /************************************************************* */
214 /* process D */
215 /**************************************************************/
216 if (NULL!=D_p) {
217 add_EM_S=TRUE;
218 if (extendedD) {
219 D_q=&(D_p[INDEX2(0,isub, p.numQuadSub)]);
220 for (s=0;s<p.row_numShapes;s++) {
221 for (r=0;r<p.col_numShapes;r++) {
222 rtmp=0;
223 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)];
224 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
225 }
226 }
227 } else {
228 for (s=0;s<p.row_numShapes;s++) {
229 for (r=0;r<p.col_numShapes;r++) {
230 rtmp=0;
231 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(r,q,p.row_numShapes)];
232 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*D_p[0];
233 }
234 }
235 }
236 }
237 /**************************************************************/
238 /* process X: */
239 /**************************************************************/
240 if (NULL!=X_p) {
241 add_EM_F=TRUE;
242 if (extendedX) {
243 X_q=&(X_p[INDEX3(0,0,isub, DIM,p.numQuadSub)]);
244 for (s=0;s<p.row_numShapes;s++) {
245 rtmp=0.;
246 for (q=0;q<p.numQuadSub;q++) {
247 rtmp+=Vol[q]*( DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*X_q[INDEX2(0,q,DIM)]
248 + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*X_q[INDEX2(1,q,DIM)]);
249 }
250 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
251 }
252 } else {
253 for (s=0;s<p.row_numShapes;s++) {
254 rtmp0=0.;
255 rtmp1=0.;
256 for (q=0;q<p.numQuadSub;q++) {
257 rtmp0+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
258 rtmp1+=Vol[q]*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
259 }
260 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp0*X_p[0]+rtmp1*X_p[1];
261 }
262 }
263 }
264 /**************************************************************/
265 /* process Y: */
266 /**************************************************************/
267 if (NULL!=Y_p) {
268 add_EM_F=TRUE;
269 if (extendedY) {
270 Y_q=&(Y_p[INDEX2(0,isub, p.numQuadSub)]);
271 for (s=0;s<p.row_numShapes;s++) {
272 rtmp=0;
273 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*Y_q[q];
274 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
275 }
276 } else {
277 for (s=0;s<p.row_numShapes;s++) {
278 rtmp=0;
279 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
280 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp*Y_p[0];
281 }
282 }
283 }
284 /***********************************************************************************************/
285 /* add the element matrices onto the matrix and right hand side */
286 /***********************************************************************************************/
287
288 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)]];
289 if (add_EM_F) Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
290 if (add_EM_S) Finley_Assemble_addToSystemMatrix(Mat,p.row_numShapesTotal,row_index,p.numEqu,p.col_numShapesTotal,row_index,p.numComp,EM_S);
291
292 } /* end of isub */
293 } /* end color check */
294 } /* end element loop */
295 } /* end color loop */
296
297 THREAD_MEMFREE(EM_S);
298 THREAD_MEMFREE(EM_F);
299 THREAD_MEMFREE(row_index);
300
301 } /* end of pointer check */
302 } /* end parallel region */
303 freeSampleBuffer(ABuff);
304 freeSampleBuffer(BBuff);
305 freeSampleBuffer(CBuff);
306 freeSampleBuffer(DBuff);
307 freeSampleBuffer(XBuff);
308 freeSampleBuffer(YBuff);
309 }

  ViewVC Help
Powered by ViewVC 1.1.26