/[escript]/branches/domexper/dudley/src/Assemble_PDE_System2_2D.c
ViewVC logotype

Contents of /branches/domexper/dudley/src/Assemble_PDE_System2_2D.c

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26