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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 798 - (show annotations)
Fri Aug 4 01:05:36 2006 UTC (13 years, 1 month ago) by gross
File MIME type: text/plain
File size: 16079 byte(s)
Reimplementation of the assemblage with persistent jacobeans.
There are also a few changes to the tests which has now
dramatically reduced the memory demand.


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
45 /**************************************************************/
46
47 void Finley_Assemble_PDE_System2_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;
54 bool_t extendedA=isExpanded(A);
55 bool_t extendedB=isExpanded(B);
56 bool_t extendedC=isExpanded(C);
57 bool_t extendedD=isExpanded(D);
58 bool_t extendedX=isExpanded(X);
59 bool_t extendedY=isExpanded(Y);
60 double *F_p=getSampleData(F,0);
61 double *S=p.row_jac->ReferenceElement->S;
62 dim_t len_EM_S=p.row_NN*p.col_NN*p.numEqu*p.numComp;
63 dim_t len_EM_F=p.row_NN*p.numEqu;
64
65
66 #pragma omp parallel private(color)
67 {
68 double EM_S[len_EM_S], EM_F[len_EM_F];
69 index_t row_index[p.row_NN];
70 register dim_t q, s,r,k,m;
71 register double rtmp, rtmp0, rtmp1, rtmp00, rtmp10, rtmp01, rtmp11;
72 double *Vol, *DSDX, *A_p, *B_p, *C_p, *D_p, *X_p, *Y_p;
73 bool_t add_EM_F, add_EM_S;
74
75 #ifndef PASO_MPI
76 for (color=elements->minColor;color<=elements->maxColor;color++) {
77 /* open loop over all elements: */
78 #pragma omp for private(e) schedule(static)
79 for(e=0;e<elements->numElements;e++){
80 if (elements->Color[e]==color) {
81 #else
82 {
83 for(e=0;e<elements->numElements;e++) {
84 {
85 #endif
86 Vol=&(p.row_jac->volume[INDEX2(0,e,p.numQuad)]);
87 DSDX=&(p.row_jac->DSDX[INDEX4(0,0,0,e,p.row_NN,DIM,p.numQuad)]);
88 for (q=0;q<len_EM_S;++q) EM_S[q]=0;
89 for (q=0;q<len_EM_F;++q) EM_F[q]=0;
90 add_EM_F=FALSE;
91 add_EM_S=FALSE;
92 /**************************************************************/
93 /* process A: */
94 /**************************************************************/
95 A_p=getSampleData(A,e);
96 if (NULL!=A_p) {
97 add_EM_S=TRUE;
98 if (extendedA) {
99 for (s=0;s<p.row_NS;s++) {
100 for (r=0;r<p.col_NS;r++) {
101 for (k=0;k<p.numEqu;k++) {
102 for (m=0;m<p.numComp;m++) {
103 rtmp=0;
104 for (q=0;q<p.numQuad;q++) {
105 rtmp+=Vol[q]* (
106 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)]
107 +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)]
108 +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)]
109 +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)]);
110 }
111 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
112 }
113 }
114 }
115 }
116 } else {
117 for (s=0;s<p.row_NS;s++) {
118 for (r=0;r<p.col_NS;r++) {
119 rtmp00=0;
120 rtmp01=0;
121 rtmp10=0;
122 rtmp11=0;
123 for (q=0;q<p.numQuad;q++) {
124 rtmp0=Vol[q]*DSDX[INDEX3(s,0,q,p.row_NN,DIM)];
125 rtmp1=Vol[q]*DSDX[INDEX3(s,1,q,p.row_NN,DIM)];
126 rtmp00+=rtmp0*DSDX[INDEX3(r,0,q,p.row_NN,DIM)];
127 rtmp01+=rtmp0*DSDX[INDEX3(r,1,q,p.row_NN,DIM)];
128 rtmp10+=rtmp1*DSDX[INDEX3(r,0,q,p.row_NN,DIM)];
129 rtmp11+=rtmp1*DSDX[INDEX3(r,1,q,p.row_NN,DIM)];
130 }
131 for (k=0;k<p.numEqu;k++) {
132 for (m=0;m<p.numComp;m++) {
133 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_NN)]+=
134 rtmp00*A_p[INDEX4(k,0,m,0,p.numEqu,DIM,p.numComp)]
135 +rtmp01*A_p[INDEX4(k,0,m,1,p.numEqu,DIM,p.numComp)]
136 +rtmp10*A_p[INDEX4(k,1,m,0,p.numEqu,DIM,p.numComp)]
137 +rtmp11*A_p[INDEX4(k,1,m,1,p.numEqu,DIM,p.numComp)];
138 }
139 }
140 }
141 }
142 }
143 }
144 /**************************************************************/
145 /* process B: */
146 /**************************************************************/
147 B_p=getSampleData(B,e);
148 if (NULL!=B_p) {
149 add_EM_S=TRUE;
150 if (extendedB) {
151 for (s=0;s<p.row_NS;s++) {
152 for (r=0;r<p.col_NS;r++) {
153 for (k=0;k<p.numEqu;k++) {
154 for (m=0;m<p.numComp;m++) {
155 rtmp=0;
156 for (q=0;q<p.numQuad;q++) {
157 rtmp+=Vol[q]*S[INDEX2(r,q,p.row_NS)]*
158 ( DSDX[INDEX3(s,0,q,p.row_NN,DIM)]*B_p[INDEX4(k,0,m,q,p.numEqu,DIM,p.numComp)]
159 + DSDX[INDEX3(s,1,q,p.row_NN,DIM)]*B_p[INDEX4(k,1,m,q,p.numEqu,DIM,p.numComp)]);
160 }
161 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
162 }
163 }
164 }
165 }
166 } else {
167 for (s=0;s<p.row_NS;s++) {
168 for (r=0;r<p.col_NS;r++) {
169 rtmp0=0;
170 rtmp1=0;
171 for (q=0;q<p.numQuad;q++) {
172 rtmp=Vol[q]*S[INDEX2(r,q,p.row_NS)];
173 rtmp0+=rtmp*DSDX[INDEX3(s,0,q,p.row_NN,DIM)];
174 rtmp1+=rtmp*DSDX[INDEX3(s,1,q,p.row_NN,DIM)];
175 }
176 for (k=0;k<p.numEqu;k++) {
177 for (m=0;m<p.numComp;m++) {
178 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_NN)]+= rtmp0*B_p[INDEX3(k,0,m,p.numEqu,DIM)]
179 + rtmp1*B_p[INDEX3(k,1,m,p.numEqu,DIM)];
180 }
181 }
182 }
183 }
184 }
185 }
186 /**************************************************************/
187 /* process C: */
188 /**************************************************************/
189 C_p=getSampleData(C,e);
190 if (NULL!=C_p) {
191 add_EM_S=TRUE;
192 if (extendedC) {
193 for (s=0;s<p.row_NS;s++) {
194 for (r=0;r<p.col_NS;r++) {
195 for (k=0;k<p.numEqu;k++) {
196 for (m=0;m<p.numComp;m++) {
197 rtmp=0;
198 for (q=0;q<p.numQuad;q++) {
199 rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*
200 ( C_p[INDEX4(k,m,0,q,p.numEqu,p.numComp,DIM)]*DSDX[INDEX3(r,0,q,p.row_NN,DIM)]
201 + C_p[INDEX4(k,m,1,q,p.numEqu,p.numComp,DIM)]*DSDX[INDEX3(r,1,q,p.row_NN,DIM)]);
202 }
203 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
204 }
205 }
206 }
207 }
208 } else {
209 for (s=0;s<p.row_NS;s++) {
210 for (r=0;r<p.col_NS;r++) {
211 rtmp0=0;
212 rtmp1=0;
213 for (q=0;q<p.numQuad;q++) {
214 rtmp=Vol[q]*S[INDEX2(s,q,p.row_NS)];
215 rtmp0+=rtmp*DSDX[INDEX3(r,0,q,p.row_NN,DIM)];
216 rtmp1+=rtmp*DSDX[INDEX3(r,1,q,p.row_NN,DIM)];
217 }
218 for (k=0;k<p.numEqu;k++) {
219 for (m=0;m<p.numComp;m++) {
220 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)]
221 +rtmp1*C_p[INDEX3(k,m,1,p.numEqu,p.numComp)];
222 }
223 }
224 }
225 }
226 }
227 }
228 /************************************************************* */
229 /* process D */
230 /**************************************************************/
231 D_p=getSampleData(D,e);
232 if (NULL!=D_p) {
233 add_EM_S=TRUE;
234 if (extendedD) {
235 for (s=0;s<p.row_NS;s++) {
236 for (r=0;r<p.col_NS;r++) {
237 for (k=0;k<p.numEqu;k++) {
238 for (m=0;m<p.numComp;m++) {
239 rtmp=0;
240 for (q=0;q<p.numQuad;q++) {
241 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)];
242 }
243 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
244 }
245 }
246 }
247 }
248 } else {
249 for (s=0;s<p.row_NS;s++) {
250 for (r=0;r<p.col_NS;r++) {
251 rtmp=0;
252 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*S[INDEX2(r,q,p.row_NS)];
253 for (k=0;k<p.numEqu;k++) {
254 for (m=0;m<p.numComp;m++) {
255 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp*D_p[INDEX2(k,m,p.numEqu)];
256 }
257 }
258 }
259 }
260 }
261 }
262 /**************************************************************/
263 /* process X: */
264 /**************************************************************/
265 X_p=getSampleData(X,e);
266 if (NULL!=X_p) {
267 add_EM_F=TRUE;
268 if (extendedX) {
269 for (s=0;s<p.row_NS;s++) {
270 for (k=0;k<p.numEqu;k++) {
271 rtmp=0;
272 for (q=0;q<p.numQuad;q++) {
273 rtmp+=Vol[q]*(DSDX[INDEX3(s,0,q,p.row_NN,DIM)]*X_p[INDEX3(k,0,q,p.numEqu,DIM)]
274 +DSDX[INDEX3(s,1,q,p.row_NN,DIM)]*X_p[INDEX3(k,1,q,p.numEqu,DIM)]);
275 }
276 EM_F[INDEX2(k,s,p.numEqu)]+=rtmp;
277 }
278 }
279 } else {
280 for (s=0;s<p.row_NS;s++) {
281 rtmp0=0;
282 rtmp1=0;
283 for (q=0;q<p.numQuad;q++) {
284 rtmp0+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_NN,DIM)];
285 rtmp1+=Vol[q]*DSDX[INDEX3(s,1,q,p.row_NN,DIM)];
286 }
287 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)];
288 }
289 }
290 }
291 /**************************************************************/
292 /* process Y: */
293 /**************************************************************/
294 Y_p=getSampleData(Y,e);
295 if (NULL!=Y_p) {
296 add_EM_F=TRUE;
297 if (extendedY) {
298 for (s=0;s<p.row_NS;s++) {
299 for (k=0;k<p.numEqu;k++) {
300 rtmp=0;
301 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*Y_p[INDEX2(k,q,p.numEqu)];
302 EM_F[INDEX2(k,s,p.numEqu)]+=rtmp;
303 }
304 }
305 } else {
306 for (s=0;s<p.row_NS;s++) {
307 rtmp=0;
308 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)];
309 for (k=0;k<p.numEqu;k++) EM_F[INDEX2(k,s,p.numEqu)]+=rtmp*Y_p[k];
310 }
311 }
312 }
313 /***********************************************************************************************/
314 /* add the element matrices onto the matrix and right hand side */
315 /***********************************************************************************************/
316 for (q=0;q<p.row_NN;q++) row_index[q]=p.row_DOF[elements->Nodes[INDEX2(p.row_node[q],e,p.NN)]];
317 if (add_EM_F) Finley_Util_AddScatter(p.row_NN,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
318 if (add_EM_S) Finley_Assemble_addToSystemMatrix(Mat,p.row_NN,row_index,p.numEqu,p.col_NN,row_index,p.numComp,EM_S);
319
320 } /* end color check */
321 } /* end element loop */
322 } /* end color loop */
323 } /* end parallel region */
324 }
325 /*
326 * $Log$
327 */

  ViewVC Help
Powered by ViewVC 1.1.26