/[escript]/branches/doubleplusgood/finley/src/Assemble_PDE_Single2_2D.cpp
ViewVC logotype

Annotation of /branches/doubleplusgood/finley/src/Assemble_PDE_Single2_2D.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4327 - (hide annotations)
Wed Mar 20 05:09:11 2013 UTC (6 years, 7 months ago) by jfenwick
File size: 16514 byte(s)
some finley memory
1 gross 798
2 jfenwick 3981 /*****************************************************************************
3 ksteube 1811 *
4 jfenwick 4154 * Copyright (c) 2003-2013 by University of Queensland
5 jfenwick 3981 * http://www.uq.edu.au
6 ksteube 1811 *
7     * Primary Business: Queensland, Australia
8     * Licensed under the Open Software License version 3.0
9     * http://www.opensource.org/licenses/osl-3.0.php
10     *
11 jfenwick 3981 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12     * Development since 2012 by School of Earth Sciences
13     *
14     *****************************************************************************/
15 ksteube 1312
16 ksteube 1811
17 jfenwick 3981 /************************************************************************************/
18 gross 798
19 caltinay 3639 /* assembles the system of numEq PDEs into the stiffness matrix S and right hand side F */
20 gross 798
21     /* -(A_{i,j} u_,j)_i-(B_{i} u)_i+C_{j} u_,j-D u_m and -(X_,i)_i + Y */
22    
23     /* in a 2D domain. The shape functions for test and solution must be identical */
24     /* and row_NS == row_NN */
25    
26     /* Shape of the coefficients: */
27    
28     /* A = 2 x 2 */
29     /* B = 2 */
30     /* C = 2 */
31     /* D = scalar */
32     /* X = 2 */
33     /* Y = scalar */
34    
35    
36 jfenwick 3981 /************************************************************************************/
37 gross 798
38    
39     #include "Assemble.h"
40     #include "Util.h"
41 gross 853 #ifdef _OPENMP
42     #include <omp.h>
43     #endif
44 gross 798
45 jfenwick 3981 /************************************************************************************/
46 gross 798
47 jfenwick 3259 void Finley_Assemble_PDE_Single2_2D(Finley_Assemble_Parameters p,
48     Finley_ElementFile* elements,
49 gross 798 Paso_SystemMatrix* Mat, escriptDataC* F,
50     escriptDataC* A, escriptDataC* B, escriptDataC* C, escriptDataC* D, escriptDataC* X, escriptDataC* Y) {
51    
52     #define DIM 2
53     index_t color;
54 gross 2748 dim_t e,isub;
55     __const double *A_p, *B_p, *C_p, *D_p, *X_p, *Y_p, *A_q, *B_q, *C_q, *D_q, *X_q, *Y_q;
56 jfenwick 2271 double *EM_S, *EM_F, *Vol, *DSDX;
57 gross 853 index_t *row_index;
58     register dim_t q, s,r;
59     register double rtmp00, rtmp01, rtmp10, rtmp11, rtmp, rtmp0, rtmp1;
60     bool_t add_EM_F, add_EM_S;
61    
62 gross 798 bool_t extendedA=isExpanded(A);
63     bool_t extendedB=isExpanded(B);
64     bool_t extendedC=isExpanded(C);
65     bool_t extendedD=isExpanded(D);
66     bool_t extendedX=isExpanded(X);
67     bool_t extendedY=isExpanded(Y);
68 jfenwick 2271 double *F_p=(requireWrite(F), getSampleDataRW(F,0)); /* use comma, to get around the mixed code and declarations thing */
69 gross 2748 double *S=p.row_jac->BasisFunctions->S;
70     dim_t len_EM_S=p.row_numShapesTotal*p.col_numShapesTotal;
71     dim_t len_EM_F=p.row_numShapesTotal;
72 gross 798
73 gross 2748 #pragma omp parallel private(color,EM_S, EM_F, Vol, DSDX, A_p, B_p, C_p, D_p, X_p, Y_p, A_q, B_q, C_q, D_q, X_q, Y_q,row_index,q, s,r,rtmp00, rtmp01, rtmp10, rtmp11, rtmp, rtmp0, rtmp1,add_EM_F, add_EM_S, isub)
74 gross 798 {
75 jfenwick 4327 EM_S=new double[len_EM_S];
76     EM_F=new double[len_EM_F];
77     row_index=new index_t[p.row_numShapesTotal];
78 gross 853
79     if (!Finley_checkPtr(EM_S) && !Finley_checkPtr(EM_F) && !Finley_checkPtr(row_index) ) {
80    
81     for (color=elements->minColor;color<=elements->maxColor;color++) {
82     /* open loop over all elements: */
83     #pragma omp for private(e) schedule(static)
84     for(e=0;e<elements->numElements;e++){
85     if (elements->Color[e]==color) {
86 gross 2748
87 jfenwick 2770 A_p=getSampleDataRO(A,e);
88     B_p=getSampleDataRO(B,e);
89     C_p=getSampleDataRO(C,e);
90     D_p=getSampleDataRO(D,e);
91     X_p=getSampleDataRO(X,e);
92     Y_p=getSampleDataRO(Y,e);
93 gross 2748
94     for (isub=0; isub<p.numSub; isub++) {
95    
96     Vol=&(p.row_jac->volume[INDEX3(0,isub,e, p.numQuadSub,p.numSub)]);
97     DSDX=&(p.row_jac->DSDX[INDEX5(0,0,0,isub,e, p.row_numShapesTotal,DIM,p.numQuadSub,p.numSub)]);
98     for (q=0;q<len_EM_S;++q) EM_S[q]=0;
99     for (q=0;q<len_EM_F;++q) EM_F[q]=0;
100     add_EM_F=FALSE;
101     add_EM_S=FALSE;
102 jfenwick 3981 /************************************************************************************/
103 gross 2748 /* process A: */
104 jfenwick 3981 /************************************************************************************/
105 gross 2748 if (NULL!=A_p) {
106     add_EM_S=TRUE;
107     if (extendedA) {
108     A_q=&(A_p[INDEX4(0,0,0,isub, DIM,DIM,p.numQuadSub)]);
109     for (s=0;s<p.row_numShapes;s++) {
110     for (r=0;r<p.col_numShapes;r++) {
111     rtmp=0;
112     for (q=0;q<p.numQuadSub;q++) {
113     rtmp+=Vol[q]*(DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*A_q[INDEX3(0,0,q,DIM,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)]
114     + DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*A_q[INDEX3(0,1,q,DIM,DIM)]*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)]
115     + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*A_q[INDEX3(1,0,q,DIM,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)]
116     + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*A_q[INDEX3(1,1,q,DIM,DIM)]*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)] );
117     }
118     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
119 gross 853 }
120     }
121 gross 2748 } else {
122     for (s=0;s<p.row_numShapes;s++) {
123     for (r=0;r<p.col_numShapes;r++) {
124     rtmp00=0;
125     rtmp01=0;
126     rtmp10=0;
127     rtmp11=0;
128     for (q=0;q<p.numQuadSub;q++) {
129     rtmp0=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
130     rtmp1=Vol[q]*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
131     rtmp00+=rtmp0*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
132     rtmp01+=rtmp0*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
133     rtmp10+=rtmp1*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
134     rtmp11+=rtmp1*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
135     }
136     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+= rtmp00*A_p[INDEX2(0,0,DIM)]
137     + rtmp01*A_p[INDEX2(0,1,DIM)]
138     + rtmp10*A_p[INDEX2(1,0,DIM)]
139     + rtmp11*A_p[INDEX2(1,1,DIM)];
140     }
141     }
142 gross 853 }
143 gross 2748 }
144 jfenwick 3981 /************************************************************************************/
145 gross 2748 /* process B: */
146 jfenwick 3981 /************************************************************************************/
147 gross 2748 if (NULL!=B_p) {
148     add_EM_S=TRUE;
149     if (extendedB) {
150     B_q=&(B_p[INDEX3(0,0,isub, DIM,p.numQuadSub)]);
151     for (s=0;s<p.row_numShapes;s++) {
152     for (r=0;r<p.col_numShapes;r++) {
153     rtmp=0.;
154     for (q=0;q<p.numQuadSub;q++) {
155     rtmp+=Vol[q]*S[INDEX2(r,q,p.row_numShapes)]*(DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*B_q[INDEX2(0,q,DIM)]
156     + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*B_q[INDEX2(1,q,DIM)]);
157 gross 853 }
158 gross 2748 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
159     }
160 gross 853 }
161 gross 2748 } else {
162     for (s=0;s<p.row_numShapes;s++) {
163     for (r=0;r<p.col_numShapes;r++) {
164     rtmp0=0;
165     rtmp1=0;
166     for (q=0;q<p.numQuadSub;q++) {
167     rtmp=Vol[q]*S[INDEX2(r,q,p.row_numShapes)];
168     rtmp0+=rtmp*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
169     rtmp1+=rtmp*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
170     }
171     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp0*B_p[0]+rtmp1*B_p[1];
172 gross 853 }
173     }
174 gross 2748 }
175     }
176 jfenwick 3981 /************************************************************************************/
177 gross 2748 /* process C: */
178 jfenwick 3981 /************************************************************************************/
179 gross 2748 if (NULL!=C_p) {
180     add_EM_S=TRUE;
181     if (extendedC) {
182     C_q=&(C_p[INDEX3(0,0,isub, DIM, p.numQuadSub)]);
183     for (s=0;s<p.row_numShapes;s++) {
184     for (r=0;r<p.col_numShapes;r++) {
185     rtmp=0;
186     for (q=0;q<p.numQuadSub;q++) {
187     rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*(C_q[INDEX2(0,q,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)]
188     + C_q[INDEX2(1,q,DIM)]*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)]);
189     }
190     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
191 gross 853 }
192     }
193 gross 2748 } else {
194     for (s=0;s<p.row_numShapes;s++) {
195     for (r=0;r<p.col_numShapes;r++) {
196     rtmp0=0;
197     rtmp1=0;
198     for (q=0;q<p.numQuadSub;q++) {
199     rtmp=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
200     rtmp0+=rtmp*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
201     rtmp1+=rtmp*DSDX[INDEX3(r,1,q,p.row_numShapesTotal,DIM)];
202     }
203     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp0*C_p[0]+rtmp1*C_p[1];
204     }
205 gross 853 }
206 gross 2748 }
207 gross 853 }
208 jfenwick 3981 /*********************************************************************************** */
209 gross 2748 /* process D */
210 jfenwick 3981 /************************************************************************************/
211 gross 2748 if (NULL!=D_p) {
212     add_EM_S=TRUE;
213     if (extendedD) {
214     D_q=&(D_p[INDEX2(0,isub, p.numQuadSub)]);
215     for (s=0;s<p.row_numShapes;s++) {
216     for (r=0;r<p.col_numShapes;r++) {
217 gross 853 rtmp=0;
218 gross 2748 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*D_q[q]*S[INDEX2(r,q,p.row_numShapes)];
219     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
220     }
221 gross 853 }
222 gross 2748 } else {
223     for (s=0;s<p.row_numShapes;s++) {
224     for (r=0;r<p.col_numShapes;r++) {
225     rtmp=0;
226     for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(r,q,p.row_numShapes)];
227     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*D_p[0];
228     }
229     }
230     }
231 gross 853 }
232 jfenwick 3981 /************************************************************************************/
233 gross 2748 /* process X: */
234 jfenwick 3981 /************************************************************************************/
235 gross 2748 if (NULL!=X_p) {
236     add_EM_F=TRUE;
237     if (extendedX) {
238     X_q=&(X_p[INDEX3(0,0,isub, DIM,p.numQuadSub)]);
239     for (s=0;s<p.row_numShapes;s++) {
240     rtmp=0.;
241     for (q=0;q<p.numQuadSub;q++) {
242     rtmp+=Vol[q]*( DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*X_q[INDEX2(0,q,DIM)]
243     + DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)]*X_q[INDEX2(1,q,DIM)]);
244     }
245     EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
246     }
247     } else {
248     for (s=0;s<p.row_numShapes;s++) {
249     rtmp0=0.;
250     rtmp1=0.;
251     for (q=0;q<p.numQuadSub;q++) {
252     rtmp0+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
253     rtmp1+=Vol[q]*DSDX[INDEX3(s,1,q,p.row_numShapesTotal,DIM)];
254 gross 853 }
255 gross 2748 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp0*X_p[0]+rtmp1*X_p[1];
256     }
257     }
258     }
259 jfenwick 3981 /************************************************************************************/
260 gross 2748 /* process Y: */
261 jfenwick 3981 /************************************************************************************/
262 gross 2748 if (NULL!=Y_p) {
263     add_EM_F=TRUE;
264     if (extendedY) {
265     Y_q=&(Y_p[INDEX2(0,isub, p.numQuadSub)]);
266     for (s=0;s<p.row_numShapes;s++) {
267     rtmp=0;
268     for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*Y_q[q];
269 gross 853 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
270 gross 2748 }
271     } else {
272     for (s=0;s<p.row_numShapes;s++) {
273     rtmp=0;
274     for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
275     EM_F[INDEX2(0,s,p.numEqu)]+=rtmp*Y_p[0];
276     }
277 gross 798 }
278     }
279 jfenwick 3981 /*********************************************************************************************************************/
280 gross 2748 /* add the element matrices onto the matrix and right hand side */
281 jfenwick 3981 /*********************************************************************************************************************/
282 gross 2748
283     for (q=0;q<p.row_numShapesTotal;q++) row_index[q]=p.row_DOF[elements->Nodes[INDEX2(p.row_node[INDEX2(q,isub,p.row_numShapesTotal)],e,p.NN)]];
284     if (add_EM_F) Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
285     if (add_EM_S) Finley_Assemble_addToSystemMatrix(Mat,p.row_numShapesTotal,row_index,p.numEqu,p.col_numShapesTotal,row_index,p.numComp,EM_S);
286    
287     } /* end of isub */
288 gross 853 } /* end color check */
289     } /* end element loop */
290     } /* end color loop */
291    
292 jfenwick 4327 delete[] EM_S;
293     delete[] EM_F;
294     delete[] row_index;
295 gross 798
296 gross 853 } /* end of pointer check */
297 gross 798 } /* end parallel region */
298     }

  ViewVC Help
Powered by ViewVC 1.1.26