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

Annotation of /trunk/finley/src/Assemble_PDE_Single2_2D.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 798 - (hide annotations)
Fri Aug 4 01:05:36 2006 UTC (13 years, 2 months ago) by gross
File MIME type: text/plain
File size: 13418 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 gross 798 /*
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    
45     /**************************************************************/
46    
47     void Finley_Assemble_PDE_Single2_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;
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 rtmp00, rtmp01, rtmp10, rtmp11, rtmp, rtmp0, rtmp1;
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     #ifndef PASO_MPI
75     for (color=elements->minColor;color<=elements->maxColor;color++) {
76     /* open loop over all elements: */
77     #pragma omp for private(e) schedule(static)
78     for(e=0;e<elements->numElements;e++){
79     if (elements->Color[e]==color) {
80     #else
81     {
82     for(e=0;e<elements->numElements;e++) {
83     {
84     #endif
85     Vol=&(p.row_jac->volume[INDEX2(0,e,p.numQuad)]);
86     DSDX=&(p.row_jac->DSDX[INDEX4(0,0,0,e,p.row_NN,DIM,p.numQuad)]);
87     for (q=0;q<len_EM_S;++q) EM_S[q]=0;
88     for (q=0;q<len_EM_F;++q) EM_F[q]=0;
89     add_EM_F=FALSE;
90     add_EM_S=FALSE;
91     /**************************************************************/
92     /* process A: */
93     /**************************************************************/
94     A_p=getSampleData(A,e);
95     if (NULL!=A_p) {
96     add_EM_S=TRUE;
97     if (extendedA) {
98     for (s=0;s<p.row_NS;s++) {
99     for (r=0;r<p.col_NS;r++) {
100     rtmp=0;
101     for (q=0;q<p.numQuad;q++) {
102     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)]
103     + 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)]
104     + 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)]
105     + 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)] );
106     }
107     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
108     }
109     }
110     } else {
111     for (s=0;s<p.row_NS;s++) {
112     for (r=0;r<p.col_NS;r++) {
113     rtmp00=0;
114     rtmp01=0;
115     rtmp10=0;
116     rtmp11=0;
117     for (q=0;q<p.numQuad;q++) {
118     rtmp0=Vol[q]*DSDX[INDEX3(s,0,q,p.row_NN,DIM)];
119     rtmp1=Vol[q]*DSDX[INDEX3(s,1,q,p.row_NN,DIM)];
120     rtmp00+=rtmp0*DSDX[INDEX3(r,0,q,p.row_NN,DIM)];
121     rtmp01+=rtmp0*DSDX[INDEX3(r,1,q,p.row_NN,DIM)];
122     rtmp10+=rtmp1*DSDX[INDEX3(r,0,q,p.row_NN,DIM)];
123     rtmp11+=rtmp1*DSDX[INDEX3(r,1,q,p.row_NN,DIM)];
124     }
125     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+= rtmp00*A_p[INDEX2(0,0,DIM)]
126     + rtmp01*A_p[INDEX2(0,1,DIM)]
127     + rtmp10*A_p[INDEX2(1,0,DIM)]
128     + rtmp11*A_p[INDEX2(1,1,DIM)];
129     }
130     }
131     }
132     }
133     /**************************************************************/
134     /* process B: */
135     /**************************************************************/
136     B_p=getSampleData(B,e);
137     if (NULL!=B_p) {
138     add_EM_S=TRUE;
139     if (extendedB) {
140     for (s=0;s<p.row_NS;s++) {
141     for (r=0;r<p.col_NS;r++) {
142     rtmp=0.;
143     for (q=0;q<p.numQuad;q++) {
144     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)]
145     + DSDX[INDEX3(s,1,q,p.row_NN,DIM)]*B_p[INDEX2(1,q,DIM)]);
146     }
147     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
148     }
149     }
150     } else {
151     for (s=0;s<p.row_NS;s++) {
152     for (r=0;r<p.col_NS;r++) {
153     rtmp0=0;
154     rtmp1=0;
155     for (q=0;q<p.numQuad;q++) {
156     rtmp=Vol[q]*S[INDEX2(r,q,p.row_NS)];
157     rtmp0+=rtmp*DSDX[INDEX3(s,0,q,p.row_NN,DIM)];
158     rtmp1+=rtmp*DSDX[INDEX3(s,1,q,p.row_NN,DIM)];
159     }
160     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp0*B_p[0]+rtmp1*B_p[1];
161     }
162     }
163     }
164     }
165     /**************************************************************/
166     /* process C: */
167     /**************************************************************/
168     C_p=getSampleData(C,e);
169     if (NULL!=C_p) {
170     add_EM_S=TRUE;
171     if (extendedC) {
172     for (s=0;s<p.row_NS;s++) {
173     for (r=0;r<p.col_NS;r++) {
174     rtmp=0;
175     for (q=0;q<p.numQuad;q++) {
176     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)]
177     + C_p[INDEX2(1,q,DIM)]*DSDX[INDEX3(r,1,q,p.row_NN,DIM)]);
178     }
179     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
180     }
181     }
182     } else {
183     for (s=0;s<p.row_NS;s++) {
184     for (r=0;r<p.col_NS;r++) {
185     rtmp0=0;
186     rtmp1=0;
187     for (q=0;q<p.numQuad;q++) {
188     rtmp=Vol[q]*S[INDEX2(s,q,p.row_NS)];
189     rtmp0+=rtmp*DSDX[INDEX3(r,0,q,p.row_NN,DIM)];
190     rtmp1+=rtmp*DSDX[INDEX3(r,1,q,p.row_NN,DIM)];
191     }
192     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp0*C_p[0]+rtmp1*C_p[1];
193     }
194     }
195     }
196     }
197     /************************************************************* */
198     /* process D */
199     /**************************************************************/
200     D_p=getSampleData(D,e);
201     if (NULL!=D_p) {
202     add_EM_S=TRUE;
203     if (extendedD) {
204     for (s=0;s<p.row_NS;s++) {
205     for (r=0;r<p.col_NS;r++) {
206     rtmp=0;
207     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)];
208     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp;
209     }
210     }
211     } else {
212     for (s=0;s<p.row_NS;s++) {
213     for (r=0;r<p.col_NS;r++) {
214     rtmp=0;
215     for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*S[INDEX2(r,q,p.row_NS)];
216     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_NN)]+=rtmp*D_p[0];
217     }
218     }
219     }
220     }
221     /**************************************************************/
222     /* process X: */
223     /**************************************************************/
224     X_p=getSampleData(X,e);
225     if (NULL!=X_p) {
226     add_EM_F=TRUE;
227     if (extendedX) {
228     for (s=0;s<p.row_NS;s++) {
229     rtmp=0.;
230     for (q=0;q<p.numQuad;q++) {
231     rtmp+=Vol[q]*( DSDX[INDEX3(s,0,q,p.row_NN,DIM)]*X_p[INDEX2(0,q,DIM)]
232     + DSDX[INDEX3(s,1,q,p.row_NN,DIM)]*X_p[INDEX2(1,q,DIM)]);
233     }
234     EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
235     }
236     } else {
237     for (s=0;s<p.row_NS;s++) {
238     rtmp0=0.;
239     rtmp1=0.;
240     for (q=0;q<p.numQuad;q++) {
241     rtmp0+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_NN,DIM)];
242     rtmp1+=Vol[q]*DSDX[INDEX3(s,1,q,p.row_NN,DIM)];
243     }
244     EM_F[INDEX2(0,s,p.numEqu)]+=rtmp0*X_p[0]+rtmp1*X_p[1];
245     }
246     }
247     }
248     /**************************************************************/
249     /* process Y: */
250     /**************************************************************/
251     Y_p=getSampleData(Y,e);
252     if (NULL!=Y_p) {
253     add_EM_F=TRUE;
254     if (extendedY) {
255     for (s=0;s<p.row_NS;s++) {
256     rtmp=0;
257     for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*Y_p[q];
258     EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
259     }
260     } else {
261     for (s=0;s<p.row_NS;s++) {
262     rtmp=0;
263     for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)];
264     EM_F[INDEX2(0,s,p.numEqu)]+=rtmp*Y_p[0];
265     }
266     }
267     }
268     /***********************************************************************************************/
269     /* add the element matrices onto the matrix and right hand side */
270     /***********************************************************************************************/
271     for (q=0;q<p.row_NN;q++) row_index[q]=p.row_DOF[elements->Nodes[INDEX2(p.row_node[q],e,p.NN)]];
272     if (add_EM_F) Finley_Util_AddScatter(p.row_NN,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
273     if (add_EM_S) Finley_Assemble_addToSystemMatrix(Mat,p.row_NN,row_index,p.numEqu,p.col_NN,row_index,p.numComp,EM_S);
274    
275     } /* end color check */
276     } /* end element loop */
277     } /* end color loop */
278     } /* end parallel region */
279     }
280     /*
281     * $Log$
282     */

  ViewVC Help
Powered by ViewVC 1.1.26