/[escript]/branches/doubleplusgood/dudley/src/Assemble_PDE_Single2_1D.cpp
ViewVC logotype

Annotation of /branches/doubleplusgood/dudley/src/Assemble_PDE_Single2_1D.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2748 - (hide annotations)
Tue Nov 17 07:32:59 2009 UTC (9 years, 4 months ago) by gross
Original Path: trunk/finley/src/Assemble_PDE_Single2_1D.c
File MIME type: text/plain
File size: 13913 byte(s)
Macro elements are implemented now. VTK writer for macro elements still needs testing.
1 gross 798
2 ksteube 1312 /*******************************************************
3 ksteube 1811 *
4 jfenwick 2548 * Copyright (c) 2003-2009 by University of Queensland
5 ksteube 1811 * Earth Systems Science Computational Center (ESSCC)
6     * http://www.uq.edu.au/esscc
7     *
8     * Primary Business: Queensland, Australia
9     * Licensed under the Open Software License version 3.0
10     * http://www.opensource.org/licenses/osl-3.0.php
11     *
12     *******************************************************/
13 ksteube 1312
14 ksteube 1811
15 gross 798 /**************************************************************/
16    
17     /* assembles the system of numEq PDEs into the stiffness matrix S right hand side F */
18     /* the shape functions for test and solution must be identical */
19    
20    
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 1D 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 = 1 x 1 */
29     /* B = 1 */
30     /* C = 1 */
31     /* D = scalar */
32     /* X = 1 */
33     /* Y = scalar */
34    
35    
36     /**************************************************************/
37    
38    
39     #include "Assemble.h"
40     #include "Util.h"
41 gross 853 #ifdef _OPENMP
42     #include <omp.h>
43     #endif
44 gross 798
45 gross 853
46 gross 798 /**************************************************************/
47    
48     void Finley_Assemble_PDE_Single2_1D(Assemble_Parameters p, Finley_ElementFile* elements,
49     Paso_SystemMatrix* Mat, escriptDataC* F,
50     escriptDataC* A, escriptDataC* B, escriptDataC* C, escriptDataC* D, escriptDataC* X, escriptDataC* Y) {
51    
52     #define DIM 1
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 rtmp;
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 jfenwick 2271 void* ABuff=allocSampleBuffer(A);
74     void* BBuff=allocSampleBuffer(B);
75     void* CBuff=allocSampleBuffer(C);
76     void* DBuff=allocSampleBuffer(D);
77     void* XBuff=allocSampleBuffer(X);
78     void* YBuff=allocSampleBuffer(Y);
79 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,rtmp,add_EM_F, add_EM_S, isub)
80 gross 798 {
81 gross 853 EM_S=THREAD_MEMALLOC(len_EM_S,double);
82     EM_F=THREAD_MEMALLOC(len_EM_F,double);
83 gross 2748 row_index=THREAD_MEMALLOC(p.row_numShapesTotal,index_t);
84 gross 853
85 jfenwick 2271
86 gross 853 if (!Finley_checkPtr(EM_S) && !Finley_checkPtr(EM_F) && !Finley_checkPtr(row_index) ) {
87    
88     for (color=elements->minColor;color<=elements->maxColor;color++) {
89     /* open loop over all elements: */
90     #pragma omp for private(e) schedule(static)
91     for(e=0;e<elements->numElements;e++){
92     if (elements->Color[e]==color) {
93 gross 2748
94     A_p=getSampleDataRO(A,e,ABuff);
95     C_p=getSampleDataRO(C,e,CBuff);
96     B_p=getSampleDataRO(B,e,BBuff);
97     D_p=getSampleDataRO(D,e,DBuff);
98     X_p=getSampleDataRO(X,e,XBuff);
99     Y_p=getSampleDataRO(Y,e,YBuff);
100    
101     for (isub=0; isub<p.numSub; isub++) {
102     Vol=&(p.row_jac->volume[INDEX3(0,isub,e, p.numQuadSub,p.numSub)]);
103     DSDX=&(p.row_jac->DSDX[INDEX5(0,0,0,isub,e, p.row_numShapesTotal,DIM,p.numQuadSub,p.numSub)]);
104     for (q=0;q<len_EM_S;++q) EM_S[q]=0;
105     for (q=0;q<len_EM_F;++q) EM_F[q]=0;
106     add_EM_F=FALSE;
107     add_EM_S=FALSE;
108     /**************************************************************/
109     /* process A: */
110     /**************************************************************/
111     if (NULL!=A_p) {
112     add_EM_S=TRUE;
113     if (extendedA) {
114     A_q=&(A_p[INDEX4(0,0,0,isub, DIM,DIM,p.numQuadSub)]);
115     for (s=0;s<p.row_numShapes;s++) {
116     for (r=0;r<p.col_numShapes;r++) {
117     rtmp=0;
118     for (q=0;q<p.numQuadSub;q++) {
119     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)];
120     }
121     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
122     }
123     }
124     } else {
125     for (s=0;s<p.row_numShapes;s++) {
126     for (r=0;r<p.col_numShapes;r++) {
127     rtmp=0;
128     for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
129     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*A_p[INDEX2(0,0,DIM)];
130     }
131     }
132     }
133     }
134     /**************************************************************/
135     /* process B: */
136     /**************************************************************/
137     if (NULL!=B_p) {
138     add_EM_S=TRUE;
139     if (extendedB) {
140     B_q=&(B_p[INDEX3(0,0,isub, DIM, p.numQuadSub)]);
141     for (s=0;s<p.row_numShapes;s++) {
142     for (r=0;r<p.col_numShapes;r++) {
143     rtmp=0;
144     for (q=0;q<p.numQuadSub;q++) {
145     rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*B_q[INDEX2(0,q,DIM)]*S[INDEX2(r,q,p.row_numShapes)];
146     }
147     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
148     }
149     }
150     } else {
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++) rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*S[INDEX2(r,q,p.row_numShapes)];
155     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*B_p[0];
156     }
157     }
158 gross 853 }
159 gross 2748 }
160     /**************************************************************/
161     /* process C: */
162     /**************************************************************/
163     if (NULL!=C_p) {
164     add_EM_S=TRUE;
165     if (extendedC) {
166     C_q=&(C_p[INDEX3(0,0,isub, DIM, p.numQuadSub)]);
167     for (s=0;s<p.row_numShapes;s++) {
168     for (r=0;r<p.col_numShapes;r++) {
169     rtmp=0;
170     for (q=0;q<p.numQuadSub;q++) {
171     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)];
172     }
173     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
174     }
175     }
176     } else {
177     for (s=0;s<p.row_numShapes;s++) {
178     for (r=0;r<p.col_numShapes;r++) {
179     rtmp=0;
180     for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
181     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*C_p[0];
182     }
183     }
184     }
185     }
186     /************************************************************* */
187     /* process D */
188     /**************************************************************/
189     if (NULL!=D_p) {
190     add_EM_S=TRUE;
191     if (extendedD) {
192     D_q=&(D_p[INDEX2(0,isub, p.numQuadSub)]);
193     for (s=0;s<p.row_numShapes;s++) {
194     for (r=0;r<p.col_numShapes;r++) {
195     rtmp=0;
196     for (q=0;q<p.numQuadSub;q++) {
197     rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*D_q[q]*S[INDEX2(r,q,p.row_numShapes)];
198     }
199     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
200     }
201     }
202     } else {
203     for (s=0;s<p.row_numShapes;s++) {
204     for (r=0;r<p.col_numShapes;r++) {
205     rtmp=0;
206     for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(r,q,p.row_numShapes)];
207     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*D_p[0];
208     }
209     }
210     }
211     }
212     /**************************************************************/
213     /* process X: */
214     /**************************************************************/
215     if (NULL!=X_p) {
216     add_EM_F=TRUE;
217     if (extendedX) {
218     X_q=&(X_p[INDEX3(0,0,isub, DIM,p.numQuadSub)]);
219     for (s=0;s<p.row_numShapes;s++) {
220 gross 853 rtmp=0;
221 gross 2748 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*X_q[INDEX2(0,q,DIM)];
222     EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
223 gross 853 }
224 gross 2748 } else {
225     for (s=0;s<p.row_numShapes;s++) {
226 gross 853 rtmp=0;
227 gross 2748 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*DSDX[INDEX3(s,0,q, p.row_numShapesTotal,DIM)];
228     EM_F[INDEX2(0,s,p.numEqu)]+=rtmp*X_p[0];
229 gross 853 }
230 gross 2748 }
231 gross 853 }
232 gross 2748 /**************************************************************/
233     /* process Y: */
234     /**************************************************************/
235     if (NULL!=Y_p) {
236     add_EM_F=TRUE;
237     if (extendedY) {
238     Y_q=&(Y_p[INDEX2(0,isub, p.numQuadSub)]);
239     for (s=0;s<p.row_numShapes;s++) {
240 gross 853 rtmp=0;
241 gross 2748 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*Y_q[q];
242     EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
243 gross 853 }
244 gross 2748 } else {
245     for (s=0;s<p.row_numShapes;s++) {
246 gross 853 rtmp=0;
247 gross 2748 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
248     EM_F[INDEX2(0,s,p.numEqu)]+=rtmp*Y_p[0];
249 gross 853 }
250     }
251 gross 2748 }
252     /***********************************************************************************************/
253     /* add the element matrices onto the matrix and right hand side */
254     /***********************************************************************************************/
255     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)]];
256    
257     if (add_EM_F) Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
258     if (add_EM_S) Finley_Assemble_addToSystemMatrix(Mat,p.row_numShapesTotal,row_index,p.numEqu,p.col_numShapesTotal,row_index,p.numComp,EM_S);
259     } /* end of isub */
260 gross 853
261     } /* end color check */
262     } /* end element loop */
263     } /* end color loop */
264    
265 jfenwick 2271 THREAD_MEMFREE(EM_S); /* these FREEs appear to be inside the if because if any of the allocs */
266     THREAD_MEMFREE(EM_F); /* failed it means an out of memory (which is not recoverable anyway) */
267 gross 853 THREAD_MEMFREE(row_index);
268 gross 798
269 gross 853 } /* end of pointer check */
270 gross 798 } /* end parallel region */
271 jfenwick 2271 freeSampleBuffer(ABuff);
272     freeSampleBuffer(BBuff);
273     freeSampleBuffer(CBuff);
274     freeSampleBuffer(DBuff);
275     freeSampleBuffer(XBuff);
276     freeSampleBuffer(YBuff);
277 gross 798 }
278     /*
279     * $Log$
280     */

  ViewVC Help
Powered by ViewVC 1.1.26