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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 798 - (show annotations)
Fri Aug 4 01:05:36 2006 UTC (12 years, 11 months ago) by gross
File MIME type: text/plain
File size: 16219 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_{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 3D 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 = 3 x 3 */
27 /* B = 3 */
28 /* C = 3 */
29 /* D = scalar */
30 /* X = 3 */
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
45 /**************************************************************/
46
47 void Finley_Assemble_PDE_Single2_3D(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 3
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;
63 dim_t len_EM_F=p.row_NN;
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;
71 register double rtmp, rtmp00, rtmp01, rtmp02, rtmp10, rtmp11, rtmp12, rtmp20, rtmp21, rtmp22, rtmp0, rtmp1, rtmp2;
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 rtmp=0;
102 for (q=0;q<p.numQuad;q++) {
103 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)]
104 + 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)]
105 + DSDX[INDEX3(s,0,q,p.row_NN,DIM)]*A_p[INDEX3(0,2,q,DIM,DIM)]*DSDX[INDEX3(r,2,q,p.row_NN,DIM)]
106 + 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)]
107 + 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)]
108 + DSDX[INDEX3(s,1,q,p.row_NN,DIM)]*A_p[INDEX3(1,2,q,DIM,DIM)]*DSDX[INDEX3(r,2,q,p.row_NN,DIM)]
109 + DSDX[INDEX3(s,2,q,p.row_NN,DIM)]*A_p[INDEX3(2,0,q,DIM,DIM)]*DSDX[INDEX3(r,0,q,p.row_NN,DIM)]
110 + DSDX[INDEX3(s,2,q,p.row_NN,DIM)]*A_p[INDEX3(2,1,q,DIM,DIM)]*DSDX[INDEX3(r,1,q,p.row_NN,DIM)]
111 + DSDX[INDEX3(s,2,q,p.row_NN,DIM)]*A_p[INDEX3(2,2,q,DIM,DIM)]*DSDX[INDEX3(r,2,q,p.row_NN,DIM)]);
112 }
113 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
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 rtmp02=0;
122 rtmp10=0;
123 rtmp11=0;
124 rtmp12=0;
125 rtmp20=0;
126 rtmp21=0;
127 rtmp22=0;
128 for (q=0;q<p.numQuad;q++) {
129
130 rtmp0=Vol[q]*DSDX[INDEX3(s,0,q,p.row_NN,DIM)];
131 rtmp00+=rtmp0*DSDX[INDEX3(r,0,q,p.row_NN,DIM)];
132 rtmp01+=rtmp0*DSDX[INDEX3(r,1,q,p.row_NN,DIM)];
133 rtmp02+=rtmp0*DSDX[INDEX3(r,2,q,p.row_NN,DIM)];
134
135 rtmp1=Vol[q]*DSDX[INDEX3(s,1,q,p.row_NN,DIM)];
136 rtmp10+=rtmp1*DSDX[INDEX3(r,0,q,p.row_NN,DIM)];
137 rtmp11+=rtmp1*DSDX[INDEX3(r,1,q,p.row_NN,DIM)];
138 rtmp12+=rtmp1*DSDX[INDEX3(r,2,q,p.row_NN,DIM)];
139
140 rtmp2=Vol[q]*DSDX[INDEX3(s,2,q,p.row_NN,DIM)];
141 rtmp20+=rtmp2*DSDX[INDEX3(r,0,q,p.row_NN,DIM)];
142 rtmp21+=rtmp2*DSDX[INDEX3(r,1,q,p.row_NN,DIM)];
143 rtmp22+=rtmp2*DSDX[INDEX3(r,2,q,p.row_NN,DIM)];
144 }
145 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp00*A_p[INDEX2(0,0,DIM)]
146 +rtmp01*A_p[INDEX2(0,1,DIM)]
147 +rtmp02*A_p[INDEX2(0,2,DIM)]
148 +rtmp10*A_p[INDEX2(1,0,DIM)]
149 +rtmp11*A_p[INDEX2(1,1,DIM)]
150 +rtmp12*A_p[INDEX2(1,2,DIM)]
151 +rtmp20*A_p[INDEX2(2,0,DIM)]
152 +rtmp21*A_p[INDEX2(2,1,DIM)]
153 +rtmp22*A_p[INDEX2(2,2,DIM)];
154 }
155 }
156 }
157 }
158 /**************************************************************/
159 /* process B: */
160 /**************************************************************/
161 B_p=getSampleData(B,e);
162 if (NULL!=B_p) {
163 add_EM_S=TRUE;
164 if (extendedB) {
165 for (s=0;s<p.row_NS;s++) {
166 for (r=0;r<p.col_NS;r++) {
167 rtmp=0;
168 for (q=0;q<p.numQuad;q++) {
169 rtmp+=Vol[q]*S[INDEX2(r,q,p.row_NS)]*
170 ( DSDX[INDEX3(s,0,q,p.row_NN,DIM)]*B_p[INDEX2(0,q,DIM)]
171 + DSDX[INDEX3(s,1,q,p.row_NN,DIM)]*B_p[INDEX2(1,q,DIM)]
172 + DSDX[INDEX3(s,2,q,p.row_NN,DIM)]*B_p[INDEX2(2,q,DIM)]);
173 }
174 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
175 }
176 }
177 } else {
178 for (s=0;s<p.row_NS;s++) {
179 for (r=0;r<p.col_NS;r++) {
180 rtmp0=0;
181 rtmp1=0;
182 rtmp2=0;
183 for (q=0;q<p.numQuad;q++) {
184 rtmp=Vol[q]*S[INDEX2(r,q,p.row_NS)];
185 rtmp0+=rtmp*DSDX[INDEX3(s,0,q,p.row_NN,DIM)];
186 rtmp1+=rtmp*DSDX[INDEX3(s,1,q,p.row_NN,DIM)];
187 rtmp2+=rtmp*DSDX[INDEX3(s,2,q,p.row_NN,DIM)];
188 }
189 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp0*B_p[0]+rtmp1*B_p[1]+rtmp2*B_p[2];
190 }
191 }
192 }
193 }
194 /**************************************************************/
195 /* process C: */
196 /**************************************************************/
197 C_p=getSampleData(C,e);
198 if (NULL!=C_p) {
199 add_EM_S=TRUE;
200 if (extendedC) {
201 for (s=0;s<p.row_NS;s++) {
202 for (r=0;r<p.col_NS;r++) {
203 rtmp=0;
204 for (q=0;q<p.numQuad;q++) {
205 rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*
206 ( C_p[INDEX2(0,q,DIM)]*DSDX[INDEX3(r,0,q,p.row_NN,DIM)]
207 + C_p[INDEX2(1,q,DIM)]*DSDX[INDEX3(r,1,q,p.row_NN,DIM)]
208 + C_p[INDEX2(2,q,DIM)]*DSDX[INDEX3(r,2,q,p.row_NN,DIM)]);
209 }
210 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
211 }
212 }
213 } else {
214 for (s=0;s<p.row_NS;s++) {
215 for (r=0;r<p.col_NS;r++) {
216 rtmp0=0;
217 rtmp1=0;
218 rtmp2=0;
219 for (q=0;q<p.numQuad;q++) {
220 rtmp=Vol[q]*S[INDEX2(s,q,p.row_NS)];
221 rtmp0+=rtmp*DSDX[INDEX3(r,0,q,p.row_NN,DIM)];
222 rtmp1+=rtmp*DSDX[INDEX3(r,1,q,p.row_NN,DIM)];
223 rtmp2+=rtmp*DSDX[INDEX3(r,2,q,p.row_NN,DIM)];
224 }
225 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp0*C_p[0]+rtmp1*C_p[1]+rtmp2*C_p[2];
226 }
227 }
228 }
229 }
230 /************************************************************* */
231 /* process D */
232 /**************************************************************/
233 D_p=getSampleData(D,e);
234 if (NULL!=D_p) {
235 add_EM_S=TRUE;
236 if (extendedD) {
237 for (s=0;s<p.row_NS;s++) {
238 for (r=0;r<p.col_NS;r++) {
239 rtmp=0;
240 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)];
241 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
242 }
243 }
244 } else {
245 for (s=0;s<p.row_NS;s++) {
246 for (r=0;r<p.col_NS;r++) {
247 rtmp=0;
248 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*S[INDEX2(r,q,p.row_NS)];
249 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp*D_p[0];
250 }
251 }
252 }
253 }
254 /**************************************************************/
255 /* process X: */
256 /**************************************************************/
257 X_p=getSampleData(X,e);
258 if (NULL!=X_p) {
259 add_EM_F=TRUE;
260 if (extendedX) {
261 for (s=0;s<p.row_NS;s++) {
262 rtmp=0;
263 for (q=0;q<p.numQuad;q++) {
264 rtmp+=Vol[q]*( DSDX[INDEX3(s,0,q,p.row_NN,DIM)]*X_p[INDEX2(0,q,DIM)]
265 + DSDX[INDEX3(s,1,q,p.row_NN,DIM)]*X_p[INDEX2(1,q,DIM)]
266 + DSDX[INDEX3(s,2,q,p.row_NN,DIM)]*X_p[INDEX2(2,q,DIM)]);
267 }
268 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
269 }
270 } else {
271 for (s=0;s<p.row_NS;s++) {
272 rtmp0=0;
273 rtmp1=0;
274 rtmp2=0;
275 for (q=0;q<p.numQuad;q++) {
276 rtmp0+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_NN,DIM)];
277 rtmp1+=Vol[q]*DSDX[INDEX3(s,1,q,p.row_NN,DIM)];
278 rtmp2+=Vol[q]*DSDX[INDEX3(s,2,q,p.row_NN,DIM)];
279 }
280 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp0*X_p[0]+rtmp1*X_p[1]+rtmp2*X_p[2];
281 }
282 }
283 }
284 /**************************************************************/
285 /* process Y: */
286 /**************************************************************/
287 Y_p=getSampleData(Y,e);
288 if (NULL!=Y_p) {
289 add_EM_F=TRUE;
290 if (extendedY) {
291 for (s=0;s<p.row_NS;s++) {
292 rtmp=0;
293 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*Y_p[q];
294 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
295 }
296 } else {
297 for (s=0;s<p.row_NS;s++) {
298 rtmp=0;
299 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)];
300 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp*Y_p[0];
301 }
302 }
303 }
304 /***********************************************************************************************/
305 /* add the element matrices onto the matrix and right hand side */
306 /***********************************************************************************************/
307 for (q=0;q<p.row_NN;q++) row_index[q]=p.row_DOF[elements->Nodes[INDEX2(p.row_node[q],e,p.NN)]];
308 if (add_EM_F) Finley_Util_AddScatter(p.row_NN,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
309 if (add_EM_S) Finley_Assemble_addToSystemMatrix(Mat,p.row_NN,row_index,p.numEqu,p.col_NN,row_index,p.numComp,EM_S);
310
311 } /* end color check */
312 } /* end element loop */
313 } /* end color loop */
314 } /* end parallel region */
315 }
316 /*
317 * $Log$
318 */

  ViewVC Help
Powered by ViewVC 1.1.26