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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 853 - (show annotations)
Wed Sep 20 05:56:36 2006 UTC (12 years, 10 months ago) by gross
Original Path: trunk/finley/src/Assemble_PDE_System2_2D.c
File MIME type: text/plain
File size: 17534 byte(s)
some performance problems wit openmp fixed.
1 /*
2 ************************************************************
3 * Copyright 2006 by ACcESS MNRF *
4 * *
5 * http://www.access.edu.au *
6 * Primary Business: Queensland, Australia *
7 * Licensed under the Open Software License version 3.0 *
8 * http://www.opensource.org/licenses/osl-3.0.php *
9 * *
10 ************************************************************
11 */
12
13 /**************************************************************/
14
15 /* assembles the system of numEq PDEs into the stiffness matrix S right hand side F */
16 /* the shape functions for test and solution must be identical */
17
18
19 /* -(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 */
20
21 /* u has p.numComp components in a 2D domain. The shape functions for test and solution must be identical */
22 /* and row_NS == row_NN */
23
24 /* Shape of the coefficients: */
25
26 /* A = p.numEqu x 2 x p.numComp x 2 */
27 /* B = 2 x p.numEqu x p.numComp */
28 /* C = p.numEqu x 2 x p.numComp */
29 /* D = p.numEqu x p.numComp */
30 /* X = p.numEqu x 2 */
31 /* Y = p.numEqu */
32
33
34 /**************************************************************/
35
36 /* Author: gross@access.edu.au */
37 /* Version: $Id:$ */
38
39 /**************************************************************/
40
41
42 #include "Assemble.h"
43 #include "Util.h"
44 #ifdef _OPENMP
45 #include <omp.h>
46 #endif
47
48
49 /**************************************************************/
50
51 void Finley_Assemble_PDE_System2_2D(Assemble_Parameters p, Finley_ElementFile* elements,
52 Paso_SystemMatrix* Mat, escriptDataC* F,
53 escriptDataC* A, escriptDataC* B, escriptDataC* C, escriptDataC* D, escriptDataC* X, escriptDataC* Y) {
54
55 #define DIM 2
56 index_t color;
57 dim_t e;
58 double *EM_S, *EM_F, *Vol, *DSDX, *A_p, *B_p, *C_p, *D_p, *X_p, *Y_p;
59 index_t *row_index;
60 register dim_t q, s,r,k,m;
61 register double rtmp, rtmp0, rtmp1, rtmp00, rtmp10, rtmp01, rtmp11;
62 bool_t add_EM_F, add_EM_S;
63
64 bool_t extendedA=isExpanded(A);
65 bool_t extendedB=isExpanded(B);
66 bool_t extendedC=isExpanded(C);
67 bool_t extendedD=isExpanded(D);
68 bool_t extendedX=isExpanded(X);
69 bool_t extendedY=isExpanded(Y);
70 double *F_p=getSampleData(F,0);
71 double *S=p.row_jac->ReferenceElement->S;
72 dim_t len_EM_S=p.row_NN*p.col_NN*p.numEqu*p.numComp;
73 dim_t len_EM_F=p.row_NN*p.numEqu;
74
75
76 #pragma omp parallel private(color,EM_S, EM_F, Vol, DSDX, A_p, B_p, C_p, D_p, X_p, Y_p,row_index,q, s,r,k,m,rtmp, rtmp0, rtmp1, rtmp00, rtmp10, rtmp01, rtmp11,add_EM_F, add_EM_S)
77 {
78 EM_S=THREAD_MEMALLOC(len_EM_S,double);
79 EM_F=THREAD_MEMALLOC(len_EM_F,double);
80 row_index=THREAD_MEMALLOC(p.row_NN,index_t);
81
82 if (!Finley_checkPtr(EM_S) && !Finley_checkPtr(EM_F) && !Finley_checkPtr(row_index) ) {
83
84 #ifndef PASO_MPI
85 for (color=elements->minColor;color<=elements->maxColor;color++) {
86 /* open loop over all elements: */
87 #pragma omp for private(e) schedule(static)
88 for(e=0;e<elements->numElements;e++){
89 if (elements->Color[e]==color) {
90 #else
91 {
92 for(e=0;e<elements->numElements;e++) {
93 {
94 #endif
95 Vol=&(p.row_jac->volume[INDEX2(0,e,p.numQuad)]);
96 DSDX=&(p.row_jac->DSDX[INDEX4(0,0,0,e,p.row_NN,DIM,p.numQuad)]);
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 A_p=getSampleData(A,e);
105 if (NULL!=A_p) {
106 add_EM_S=TRUE;
107 if (extendedA) {
108 for (s=0;s<p.row_NS;s++) {
109 for (r=0;r<p.col_NS;r++) {
110 for (k=0;k<p.numEqu;k++) {
111 for (m=0;m<p.numComp;m++) {
112 rtmp=0;
113 for (q=0;q<p.numQuad;q++) {
114 rtmp+=Vol[q]* (
115 DSDX[INDEX3(s,0,q,p.row_NN,DIM)]*A_p[INDEX5(k,0,m,0,q,p.numEqu,DIM,p.numComp,DIM)]*DSDX[INDEX3(r,0,q,p.row_NN,DIM)]
116 +DSDX[INDEX3(s,0,q,p.row_NN,DIM)]*A_p[INDEX5(k,0,m,1,q,p.numEqu,DIM,p.numComp,DIM)]*DSDX[INDEX3(r,1,q,p.row_NN,DIM)]
117 +DSDX[INDEX3(s,1,q,p.row_NN,DIM)]*A_p[INDEX5(k,1,m,0,q,p.numEqu,DIM,p.numComp,DIM)]*DSDX[INDEX3(r,0,q,p.row_NN,DIM)]
118 +DSDX[INDEX3(s,1,q,p.row_NN,DIM)]*A_p[INDEX5(k,1,m,1,q,p.numEqu,DIM,p.numComp,DIM)]*DSDX[INDEX3(r,1,q,p.row_NN,DIM)]);
119 }
120 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
121 }
122 }
123 }
124 }
125 } else {
126 for (s=0;s<p.row_NS;s++) {
127 for (r=0;r<p.col_NS;r++) {
128 rtmp00=0;
129 rtmp01=0;
130 rtmp10=0;
131 rtmp11=0;
132 for (q=0;q<p.numQuad;q++) {
133 rtmp0=Vol[q]*DSDX[INDEX3(s,0,q,p.row_NN,DIM)];
134 rtmp1=Vol[q]*DSDX[INDEX3(s,1,q,p.row_NN,DIM)];
135 rtmp00+=rtmp0*DSDX[INDEX3(r,0,q,p.row_NN,DIM)];
136 rtmp01+=rtmp0*DSDX[INDEX3(r,1,q,p.row_NN,DIM)];
137 rtmp10+=rtmp1*DSDX[INDEX3(r,0,q,p.row_NN,DIM)];
138 rtmp11+=rtmp1*DSDX[INDEX3(r,1,q,p.row_NN,DIM)];
139 }
140 for (k=0;k<p.numEqu;k++) {
141 for (m=0;m<p.numComp;m++) {
142 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_NN)]+=
143 rtmp00*A_p[INDEX4(k,0,m,0,p.numEqu,DIM,p.numComp)]
144 +rtmp01*A_p[INDEX4(k,0,m,1,p.numEqu,DIM,p.numComp)]
145 +rtmp10*A_p[INDEX4(k,1,m,0,p.numEqu,DIM,p.numComp)]
146 +rtmp11*A_p[INDEX4(k,1,m,1,p.numEqu,DIM,p.numComp)];
147 }
148 }
149 }
150 }
151 }
152 }
153 /**************************************************************/
154 /* process B: */
155 /**************************************************************/
156 B_p=getSampleData(B,e);
157 if (NULL!=B_p) {
158 add_EM_S=TRUE;
159 if (extendedB) {
160 for (s=0;s<p.row_NS;s++) {
161 for (r=0;r<p.col_NS;r++) {
162 for (k=0;k<p.numEqu;k++) {
163 for (m=0;m<p.numComp;m++) {
164 rtmp=0;
165 for (q=0;q<p.numQuad;q++) {
166 rtmp+=Vol[q]*S[INDEX2(r,q,p.row_NS)]*
167 ( DSDX[INDEX3(s,0,q,p.row_NN,DIM)]*B_p[INDEX4(k,0,m,q,p.numEqu,DIM,p.numComp)]
168 + DSDX[INDEX3(s,1,q,p.row_NN,DIM)]*B_p[INDEX4(k,1,m,q,p.numEqu,DIM,p.numComp)]);
169 }
170 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
171 }
172 }
173 }
174 }
175 } else {
176 for (s=0;s<p.row_NS;s++) {
177 for (r=0;r<p.col_NS;r++) {
178 rtmp0=0;
179 rtmp1=0;
180 for (q=0;q<p.numQuad;q++) {
181 rtmp=Vol[q]*S[INDEX2(r,q,p.row_NS)];
182 rtmp0+=rtmp*DSDX[INDEX3(s,0,q,p.row_NN,DIM)];
183 rtmp1+=rtmp*DSDX[INDEX3(s,1,q,p.row_NN,DIM)];
184 }
185 for (k=0;k<p.numEqu;k++) {
186 for (m=0;m<p.numComp;m++) {
187 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_NN)]+= rtmp0*B_p[INDEX3(k,0,m,p.numEqu,DIM)]
188 + rtmp1*B_p[INDEX3(k,1,m,p.numEqu,DIM)];
189 }
190 }
191 }
192 }
193 }
194 }
195 /**************************************************************/
196 /* process C: */
197 /**************************************************************/
198 C_p=getSampleData(C,e);
199 if (NULL!=C_p) {
200 add_EM_S=TRUE;
201 if (extendedC) {
202 for (s=0;s<p.row_NS;s++) {
203 for (r=0;r<p.col_NS;r++) {
204 for (k=0;k<p.numEqu;k++) {
205 for (m=0;m<p.numComp;m++) {
206 rtmp=0;
207 for (q=0;q<p.numQuad;q++) {
208 rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*
209 ( C_p[INDEX4(k,m,0,q,p.numEqu,p.numComp,DIM)]*DSDX[INDEX3(r,0,q,p.row_NN,DIM)]
210 + C_p[INDEX4(k,m,1,q,p.numEqu,p.numComp,DIM)]*DSDX[INDEX3(r,1,q,p.row_NN,DIM)]);
211 }
212 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
213 }
214 }
215 }
216 }
217 } else {
218 for (s=0;s<p.row_NS;s++) {
219 for (r=0;r<p.col_NS;r++) {
220 rtmp0=0;
221 rtmp1=0;
222 for (q=0;q<p.numQuad;q++) {
223 rtmp=Vol[q]*S[INDEX2(s,q,p.row_NS)];
224 rtmp0+=rtmp*DSDX[INDEX3(r,0,q,p.row_NN,DIM)];
225 rtmp1+=rtmp*DSDX[INDEX3(r,1,q,p.row_NN,DIM)];
226 }
227 for (k=0;k<p.numEqu;k++) {
228 for (m=0;m<p.numComp;m++) {
229 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp0*C_p[INDEX3(k,m,0,p.numEqu,p.numComp)]
230 +rtmp1*C_p[INDEX3(k,m,1,p.numEqu,p.numComp)];
231 }
232 }
233 }
234 }
235 }
236 }
237 /************************************************************* */
238 /* process D */
239 /**************************************************************/
240 D_p=getSampleData(D,e);
241 if (NULL!=D_p) {
242 add_EM_S=TRUE;
243 if (extendedD) {
244 for (s=0;s<p.row_NS;s++) {
245 for (r=0;r<p.col_NS;r++) {
246 for (k=0;k<p.numEqu;k++) {
247 for (m=0;m<p.numComp;m++) {
248 rtmp=0;
249 for (q=0;q<p.numQuad;q++) {
250 rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*D_p[INDEX3(k,m,q,p.numEqu,p.numComp)]*S[INDEX2(r,q,p.row_NS)];
251 }
252 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
253 }
254 }
255 }
256 }
257 } else {
258 for (s=0;s<p.row_NS;s++) {
259 for (r=0;r<p.col_NS;r++) {
260 rtmp=0;
261 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*S[INDEX2(r,q,p.row_NS)];
262 for (k=0;k<p.numEqu;k++) {
263 for (m=0;m<p.numComp;m++) {
264 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp*D_p[INDEX2(k,m,p.numEqu)];
265 }
266 }
267 }
268 }
269 }
270 }
271 /**************************************************************/
272 /* process X: */
273 /**************************************************************/
274 X_p=getSampleData(X,e);
275 if (NULL!=X_p) {
276 add_EM_F=TRUE;
277 if (extendedX) {
278 for (s=0;s<p.row_NS;s++) {
279 for (k=0;k<p.numEqu;k++) {
280 rtmp=0;
281 for (q=0;q<p.numQuad;q++) {
282 rtmp+=Vol[q]*(DSDX[INDEX3(s,0,q,p.row_NN,DIM)]*X_p[INDEX3(k,0,q,p.numEqu,DIM)]
283 +DSDX[INDEX3(s,1,q,p.row_NN,DIM)]*X_p[INDEX3(k,1,q,p.numEqu,DIM)]);
284 }
285 EM_F[INDEX2(k,s,p.numEqu)]+=rtmp;
286 }
287 }
288 } else {
289 for (s=0;s<p.row_NS;s++) {
290 rtmp0=0;
291 rtmp1=0;
292 for (q=0;q<p.numQuad;q++) {
293 rtmp0+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_NN,DIM)];
294 rtmp1+=Vol[q]*DSDX[INDEX3(s,1,q,p.row_NN,DIM)];
295 }
296 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)];
297 }
298 }
299 }
300 /**************************************************************/
301 /* process Y: */
302 /**************************************************************/
303 Y_p=getSampleData(Y,e);
304 if (NULL!=Y_p) {
305 add_EM_F=TRUE;
306 if (extendedY) {
307 for (s=0;s<p.row_NS;s++) {
308 for (k=0;k<p.numEqu;k++) {
309 rtmp=0;
310 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*Y_p[INDEX2(k,q,p.numEqu)];
311 EM_F[INDEX2(k,s,p.numEqu)]+=rtmp;
312 }
313 }
314 } else {
315 for (s=0;s<p.row_NS;s++) {
316 rtmp=0;
317 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)];
318 for (k=0;k<p.numEqu;k++) EM_F[INDEX2(k,s,p.numEqu)]+=rtmp*Y_p[k];
319 }
320 }
321 }
322 /***********************************************************************************************/
323 /* add the element matrices onto the matrix and right hand side */
324 /***********************************************************************************************/
325 for (q=0;q<p.row_NN;q++) row_index[q]=p.row_DOF[elements->Nodes[INDEX2(p.row_node[q],e,p.NN)]];
326 if (add_EM_F) Finley_Util_AddScatter(p.row_NN,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
327 if (add_EM_S) Finley_Assemble_addToSystemMatrix(Mat,p.row_NN,row_index,p.numEqu,p.col_NN,row_index,p.numComp,EM_S);
328
329 } /* end color check */
330 } /* end element loop */
331 } /* end color loop */
332
333 THREAD_MEMFREE(EM_S);
334 THREAD_MEMFREE(EM_F);
335 THREAD_MEMFREE(row_index);
336
337 } /* end of pointer check */
338 } /* end parallel region */
339 }
340 /*
341 * $Log$
342 */

  ViewVC Help
Powered by ViewVC 1.1.26