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

Contents of /trunk-mpi-branch/finley/src/Assemble_PDE_Single2_2D.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1253 - (show annotations)
Fri Aug 17 04:09:29 2007 UTC (12 years, 9 months ago) by gross
File MIME type: text/plain
File size: 14595 byte(s)
finally everthing for MPI is in the code. now testing is needed
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_{i,j} u_,j)_i-(B_{i} u)_i+C_{j} u_,j-D u_m and -(X_,i)_i + Y */
20
21 /* 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 = 2 x 2 */
27 /* B = 2 */
28 /* C = 2 */
29 /* D = scalar */
30 /* X = 2 */
31 /* Y = scalar */
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 void Finley_Assemble_PDE_Single2_2D(Assemble_Parameters p, Finley_ElementFile* elements,
51 Paso_SystemMatrix* Mat, escriptDataC* F,
52 escriptDataC* A, escriptDataC* B, escriptDataC* C, escriptDataC* D, escriptDataC* X, escriptDataC* Y) {
53
54 #define DIM 2
55 index_t color;
56 dim_t e;
57 double *EM_S, *EM_F, *Vol, *DSDX, *A_p, *B_p, *C_p, *D_p, *X_p, *Y_p;
58 index_t *row_index;
59 register dim_t q, s,r;
60 register double rtmp00, rtmp01, rtmp10, rtmp11, rtmp, rtmp0, rtmp1;
61 bool_t add_EM_F, add_EM_S;
62
63 bool_t extendedA=isExpanded(A);
64 bool_t extendedB=isExpanded(B);
65 bool_t extendedC=isExpanded(C);
66 bool_t extendedD=isExpanded(D);
67 bool_t extendedX=isExpanded(X);
68 bool_t extendedY=isExpanded(Y);
69 double *F_p=getSampleData(F,0);
70 double *S=p.row_jac->ReferenceElement->S;
71 dim_t len_EM_S=p.row_NN*p.col_NN;
72 dim_t len_EM_F=p.row_NN;
73
74
75 #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,rtmp00, rtmp01, rtmp10, rtmp11, rtmp, rtmp0, rtmp1,add_EM_F, add_EM_S)
76 {
77 EM_S=THREAD_MEMALLOC(len_EM_S,double);
78 EM_F=THREAD_MEMALLOC(len_EM_F,double);
79 row_index=THREAD_MEMALLOC(p.row_NN,index_t);
80
81 if (!Finley_checkPtr(EM_S) && !Finley_checkPtr(EM_F) && !Finley_checkPtr(row_index) ) {
82
83 for (color=elements->minColor;color<=elements->maxColor;color++) {
84 /* open loop over all elements: */
85 #pragma omp for private(e) schedule(static)
86 for(e=0;e<elements->numElements;e++){
87 if (elements->Color[e]==color) {
88 Vol=&(p.row_jac->volume[INDEX2(0,e,p.numQuad)]);
89 DSDX=&(p.row_jac->DSDX[INDEX4(0,0,0,e,p.row_NN,DIM,p.numQuad)]);
90 for (q=0;q<len_EM_S;++q) EM_S[q]=0;
91 for (q=0;q<len_EM_F;++q) EM_F[q]=0;
92 add_EM_F=FALSE;
93 add_EM_S=FALSE;
94 /**************************************************************/
95 /* process A: */
96 /**************************************************************/
97 A_p=getSampleData(A,e);
98 if (NULL!=A_p) {
99 add_EM_S=TRUE;
100 if (extendedA) {
101 for (s=0;s<p.row_NS;s++) {
102 for (r=0;r<p.col_NS;r++) {
103 rtmp=0;
104 for (q=0;q<p.numQuad;q++) {
105 rtmp+=Vol[q]*(DSDX[INDEX3(s,0,q,p.row_NN,DIM)]*A_p[INDEX3(0,0,q,DIM,DIM)]*DSDX[INDEX3(r,0,q,p.row_NN,DIM)]
106 + DSDX[INDEX3(s,0,q,p.row_NN,DIM)]*A_p[INDEX3(0,1,q,DIM,DIM)]*DSDX[INDEX3(r,1,q,p.row_NN,DIM)]
107 + DSDX[INDEX3(s,1,q,p.row_NN,DIM)]*A_p[INDEX3(1,0,q,DIM,DIM)]*DSDX[INDEX3(r,0,q,p.row_NN,DIM)]
108 + DSDX[INDEX3(s,1,q,p.row_NN,DIM)]*A_p[INDEX3(1,1,q,DIM,DIM)]*DSDX[INDEX3(r,1,q,p.row_NN,DIM)] );
109 }
110 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
111 }
112 }
113 } else {
114 for (s=0;s<p.row_NS;s++) {
115 for (r=0;r<p.col_NS;r++) {
116 rtmp00=0;
117 rtmp01=0;
118 rtmp10=0;
119 rtmp11=0;
120 for (q=0;q<p.numQuad;q++) {
121 rtmp0=Vol[q]*DSDX[INDEX3(s,0,q,p.row_NN,DIM)];
122 rtmp1=Vol[q]*DSDX[INDEX3(s,1,q,p.row_NN,DIM)];
123 rtmp00+=rtmp0*DSDX[INDEX3(r,0,q,p.row_NN,DIM)];
124 rtmp01+=rtmp0*DSDX[INDEX3(r,1,q,p.row_NN,DIM)];
125 rtmp10+=rtmp1*DSDX[INDEX3(r,0,q,p.row_NN,DIM)];
126 rtmp11+=rtmp1*DSDX[INDEX3(r,1,q,p.row_NN,DIM)];
127 }
128 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+= rtmp00*A_p[INDEX2(0,0,DIM)]
129 + rtmp01*A_p[INDEX2(0,1,DIM)]
130 + rtmp10*A_p[INDEX2(1,0,DIM)]
131 + rtmp11*A_p[INDEX2(1,1,DIM)];
132 }
133 }
134 }
135 }
136 /**************************************************************/
137 /* process B: */
138 /**************************************************************/
139 B_p=getSampleData(B,e);
140 if (NULL!=B_p) {
141 add_EM_S=TRUE;
142 if (extendedB) {
143 for (s=0;s<p.row_NS;s++) {
144 for (r=0;r<p.col_NS;r++) {
145 rtmp=0.;
146 for (q=0;q<p.numQuad;q++) {
147 rtmp+=Vol[q]*S[INDEX2(r,q,p.row_NS)]*(DSDX[INDEX3(s,0,q,p.row_NN,DIM)]*B_p[INDEX2(0,q,DIM)]
148 + DSDX[INDEX3(s,1,q,p.row_NN,DIM)]*B_p[INDEX2(1,q,DIM)]);
149 }
150 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
151 }
152 }
153 } else {
154 for (s=0;s<p.row_NS;s++) {
155 for (r=0;r<p.col_NS;r++) {
156 rtmp0=0;
157 rtmp1=0;
158 for (q=0;q<p.numQuad;q++) {
159 rtmp=Vol[q]*S[INDEX2(r,q,p.row_NS)];
160 rtmp0+=rtmp*DSDX[INDEX3(s,0,q,p.row_NN,DIM)];
161 rtmp1+=rtmp*DSDX[INDEX3(s,1,q,p.row_NN,DIM)];
162 }
163 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp0*B_p[0]+rtmp1*B_p[1];
164 }
165 }
166 }
167 }
168 /**************************************************************/
169 /* process C: */
170 /**************************************************************/
171 C_p=getSampleData(C,e);
172 if (NULL!=C_p) {
173 add_EM_S=TRUE;
174 if (extendedC) {
175 for (s=0;s<p.row_NS;s++) {
176 for (r=0;r<p.col_NS;r++) {
177 rtmp=0;
178 for (q=0;q<p.numQuad;q++) {
179 rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*(C_p[INDEX2(0,q,DIM)]*DSDX[INDEX3(r,0,q,p.row_NN,DIM)]
180 + C_p[INDEX2(1,q,DIM)]*DSDX[INDEX3(r,1,q,p.row_NN,DIM)]);
181 }
182 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
183 }
184 }
185 } else {
186 for (s=0;s<p.row_NS;s++) {
187 for (r=0;r<p.col_NS;r++) {
188 rtmp0=0;
189 rtmp1=0;
190 for (q=0;q<p.numQuad;q++) {
191 rtmp=Vol[q]*S[INDEX2(s,q,p.row_NS)];
192 rtmp0+=rtmp*DSDX[INDEX3(r,0,q,p.row_NN,DIM)];
193 rtmp1+=rtmp*DSDX[INDEX3(r,1,q,p.row_NN,DIM)];
194 }
195 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp0*C_p[0]+rtmp1*C_p[1];
196 }
197 }
198 }
199 }
200 /************************************************************* */
201 /* process D */
202 /**************************************************************/
203 D_p=getSampleData(D,e);
204 if (NULL!=D_p) {
205 add_EM_S=TRUE;
206 if (extendedD) {
207 for (s=0;s<p.row_NS;s++) {
208 for (r=0;r<p.col_NS;r++) {
209 rtmp=0;
210 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*D_p[q]*S[INDEX2(r,q,p.row_NS)];
211 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
212 }
213 }
214 } else {
215 for (s=0;s<p.row_NS;s++) {
216 for (r=0;r<p.col_NS;r++) {
217 rtmp=0;
218 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*S[INDEX2(r,q,p.row_NS)];
219 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp*D_p[0];
220 }
221 }
222 }
223 }
224 /**************************************************************/
225 /* process X: */
226 /**************************************************************/
227 X_p=getSampleData(X,e);
228 if (NULL!=X_p) {
229 add_EM_F=TRUE;
230 if (extendedX) {
231 for (s=0;s<p.row_NS;s++) {
232 rtmp=0.;
233 for (q=0;q<p.numQuad;q++) {
234 rtmp+=Vol[q]*( DSDX[INDEX3(s,0,q,p.row_NN,DIM)]*X_p[INDEX2(0,q,DIM)]
235 + DSDX[INDEX3(s,1,q,p.row_NN,DIM)]*X_p[INDEX2(1,q,DIM)]);
236 }
237 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
238 }
239 } else {
240 for (s=0;s<p.row_NS;s++) {
241 rtmp0=0.;
242 rtmp1=0.;
243 for (q=0;q<p.numQuad;q++) {
244 rtmp0+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_NN,DIM)];
245 rtmp1+=Vol[q]*DSDX[INDEX3(s,1,q,p.row_NN,DIM)];
246 }
247 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp0*X_p[0]+rtmp1*X_p[1];
248 }
249 }
250 }
251 /**************************************************************/
252 /* process Y: */
253 /**************************************************************/
254 Y_p=getSampleData(Y,e);
255 if (NULL!=Y_p) {
256 add_EM_F=TRUE;
257 if (extendedY) {
258 for (s=0;s<p.row_NS;s++) {
259 rtmp=0;
260 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*Y_p[q];
261 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
262 }
263 } else {
264 for (s=0;s<p.row_NS;s++) {
265 rtmp=0;
266 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)];
267 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp*Y_p[0];
268 }
269 }
270 }
271 /***********************************************************************************************/
272 /* add the element matrices onto the matrix and right hand side */
273 /***********************************************************************************************/
274 for (q=0;q<p.row_NN;q++) row_index[q]=p.row_DOF[elements->Nodes[INDEX2(p.row_node[q],e,p.NN)]];
275 if (add_EM_F) Finley_Util_AddScatter(p.row_NN,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
276 if (add_EM_S) Finley_Assemble_addToSystemMatrix(Mat,p.row_NN,row_index,p.numEqu,p.col_NN,row_index,p.numComp,EM_S);
277
278 } /* end color check */
279 } /* end element loop */
280 } /* end color loop */
281
282 THREAD_MEMFREE(EM_S);
283 THREAD_MEMFREE(EM_F);
284 THREAD_MEMFREE(row_index);
285
286 } /* end of pointer check */
287 } /* end parallel region */
288 }
289 /*
290 * $Log$
291 */

  ViewVC Help
Powered by ViewVC 1.1.26