/[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 2881 - (show annotations)
Thu Jan 28 02:03:15 2010 UTC (9 years, 10 months ago) by jfenwick
File MIME type: text/plain
File size: 16100 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_{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 #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)
73 {
74 EM_S=THREAD_MEMALLOC(len_EM_S,double);
75 EM_F=THREAD_MEMALLOC(len_EM_F,double);
76 row_index=THREAD_MEMALLOC(p.row_numShapesTotal,index_t);
77
78 if (!Finley_checkPtr(EM_S) && !Finley_checkPtr(EM_F) && !Finley_checkPtr(row_index) ) {
79
80 for (color=elements->minColor;color<=elements->maxColor;color++) {
81 /* open loop over all elements: */
82 #pragma omp for private(e) schedule(static)
83 for(e=0;e<elements->numElements;e++){
84 if (elements->Color[e]==color) {
85
86 A_p=getSampleDataRO(A,e);
87 B_p=getSampleDataRO(B,e);
88 C_p=getSampleDataRO(C,e);
89 D_p=getSampleDataRO(D,e);
90 X_p=getSampleDataRO(X,e);
91 Y_p=getSampleDataRO(Y,e);
92
93 for (isub=0; isub<p.numSub; isub++) {
94
95 Vol=&(p.row_jac->volume[INDEX3(0,isub,e, p.numQuadSub,p.numSub)]);
96 DSDX=&(p.row_jac->DSDX[INDEX5(0,0,0,isub,e, p.row_numShapesTotal,DIM,p.numQuadSub,p.numSub)]);
97 for (q=0;q<len_EM_S;++q) EM_S[q]=0;
98 for (q=0;q<len_EM_F;++q) EM_F[q]=0;
99 add_EM_F=FALSE;
100 add_EM_S=FALSE;
101 /**************************************************************/
102 /* process A: */
103 /**************************************************************/
104 if (NULL!=A_p) {
105 add_EM_S=TRUE;
106 if (extendedA) {
107 A_q=&(A_p[INDEX4(0,0,0,isub, DIM,DIM,p.numQuadSub)]);
108 for (s=0;s<p.row_numShapes;s++) {
109 for (r=0;r<p.col_numShapes;r++) {
110 rtmp=0;
111 for (q=0;q<p.numQuadSub;q++) {
112 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)]
113 + 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)]
114 + 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)]
115 + 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)] );
116 }
117 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
118 }
119 }
120 } else {
121 for (s=0;s<p.row_numShapes;s++) {
122 for (r=0;r<p.col_numShapes;r++) {
123 rtmp00=0;
124 rtmp01=0;
125 rtmp10=0;
126 rtmp11=0;
127 for (q=0;q<p.numQuadSub;q++) {
128 rtmp0=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
129 rtmp1=Vol[q]*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
130 rtmp00+=rtmp0*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
131 rtmp01+=rtmp0*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
132 rtmp10+=rtmp1*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
133 rtmp11+=rtmp1*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
134 }
135 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+= rtmp00*A_p[INDEX2(0,0,DIM)]
136 + rtmp01*A_p[INDEX2(0,1,DIM)]
137 + rtmp10*A_p[INDEX2(1,0,DIM)]
138 + rtmp11*A_p[INDEX2(1,1,DIM)];
139 }
140 }
141 }
142 }
143 /**************************************************************/
144 /* process B: */
145 /**************************************************************/
146 if (NULL!=B_p) {
147 add_EM_S=TRUE;
148 if (extendedB) {
149 B_q=&(B_p[INDEX3(0,0,isub, DIM,p.numQuadSub)]);
150 for (s=0;s<p.row_numShapes;s++) {
151 for (r=0;r<p.col_numShapes;r++) {
152 rtmp=0.;
153 for (q=0;q<p.numQuadSub;q++) {
154 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)]
155 + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*B_q[INDEX2(1,q,DIM)]);
156 }
157 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
158 }
159 }
160 } else {
161 for (s=0;s<p.row_numShapes;s++) {
162 for (r=0;r<p.col_numShapes;r++) {
163 rtmp0=0;
164 rtmp1=0;
165 for (q=0;q<p.numQuadSub;q++) {
166 rtmp=Vol[q]*S[INDEX2(r,q,p.row_numShapes)];
167 rtmp0+=rtmp*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
168 rtmp1+=rtmp*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
169 }
170 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp0*B_p[0]+rtmp1*B_p[1];
171 }
172 }
173 }
174 }
175 /**************************************************************/
176 /* process C: */
177 /**************************************************************/
178 if (NULL!=C_p) {
179 add_EM_S=TRUE;
180 if (extendedC) {
181 C_q=&(C_p[INDEX3(0,0,isub, DIM, p.numQuadSub)]);
182 for (s=0;s<p.row_numShapes;s++) {
183 for (r=0;r<p.col_numShapes;r++) {
184 rtmp=0;
185 for (q=0;q<p.numQuadSub;q++) {
186 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)]
187 + C_q[INDEX2(1,q,DIM)]*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)]);
188 }
189 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
190 }
191 }
192 } else {
193 for (s=0;s<p.row_numShapes;s++) {
194 for (r=0;r<p.col_numShapes;r++) {
195 rtmp0=0;
196 rtmp1=0;
197 for (q=0;q<p.numQuadSub;q++) {
198 rtmp=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
199 rtmp0+=rtmp*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
200 rtmp1+=rtmp*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
201 }
202 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp0*C_p[0]+rtmp1*C_p[1];
203 }
204 }
205 }
206 }
207 /************************************************************* */
208 /* process D */
209 /**************************************************************/
210 if (NULL!=D_p) {
211 add_EM_S=TRUE;
212 if (extendedD) {
213 D_q=&(D_p[INDEX2(0,isub, p.numQuadSub)]);
214 for (s=0;s<p.row_numShapes;s++) {
215 for (r=0;r<p.col_numShapes;r++) {
216 rtmp=0;
217 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)];
218 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
219 }
220 }
221 } else {
222 for (s=0;s<p.row_numShapes;s++) {
223 for (r=0;r<p.col_numShapes;r++) {
224 rtmp=0;
225 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(r,q,p.row_numShapes)];
226 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*D_p[0];
227 }
228 }
229 }
230 }
231 /**************************************************************/
232 /* process X: */
233 /**************************************************************/
234 if (NULL!=X_p) {
235 add_EM_F=TRUE;
236 if (extendedX) {
237 X_q=&(X_p[INDEX3(0,0,isub, DIM,p.numQuadSub)]);
238 for (s=0;s<p.row_numShapes;s++) {
239 rtmp=0.;
240 for (q=0;q<p.numQuadSub;q++) {
241 rtmp+=Vol[q]*( DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*X_q[INDEX2(0,q,DIM)]
242 + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*X_q[INDEX2(1,q,DIM)]);
243 }
244 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
245 }
246 } else {
247 for (s=0;s<p.row_numShapes;s++) {
248 rtmp0=0.;
249 rtmp1=0.;
250 for (q=0;q<p.numQuadSub;q++) {
251 rtmp0+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
252 rtmp1+=Vol[q]*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
253 }
254 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp0*X_p[0]+rtmp1*X_p[1];
255 }
256 }
257 }
258 /**************************************************************/
259 /* process Y: */
260 /**************************************************************/
261 if (NULL!=Y_p) {
262 add_EM_F=TRUE;
263 if (extendedY) {
264 Y_q=&(Y_p[INDEX2(0,isub, p.numQuadSub)]);
265 for (s=0;s<p.row_numShapes;s++) {
266 rtmp=0;
267 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*Y_q[q];
268 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
269 }
270 } else {
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)];
274 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp*Y_p[0];
275 }
276 }
277 }
278 /***********************************************************************************************/
279 /* add the element matrices onto the matrix and right hand side */
280 /***********************************************************************************************/
281
282 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)]];
283 if (add_EM_F) Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
284 if (add_EM_S) Finley_Assemble_addToSystemMatrix(Mat,p.row_numShapesTotal,row_index,p.numEqu,p.col_numShapesTotal,row_index,p.numComp,EM_S);
285
286 } /* end of isub */
287 } /* end color check */
288 } /* end element loop */
289 } /* end color loop */
290
291 THREAD_MEMFREE(EM_S);
292 THREAD_MEMFREE(EM_F);
293 THREAD_MEMFREE(row_index);
294
295 } /* end of pointer check */
296 } /* end parallel region */
297 }

  ViewVC Help
Powered by ViewVC 1.1.26