/[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 3144 - (hide annotations)
Fri Sep 3 00:49:02 2010 UTC (8 years, 7 months ago) by jfenwick
Original Path: branches/domexper/dudley/src/Assemble_PDE_Single2_1D.c
File MIME type: text/plain
File size: 13331 byte(s)
row_node, col_node (Assemble params), node_selection 
removed
1 gross 798
2 ksteube 1312 /*******************************************************
3 ksteube 1811 *
4 jfenwick 2881 * Copyright (c) 2003-2010 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 jfenwick 3086 void Dudley_Assemble_PDE_Single2_1D(Assemble_Parameters p, Dudley_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 1
53     index_t color;
54 jfenwick 3136 dim_t e;
55 gross 2748 __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 3136 #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)
74 gross 798 {
75 gross 853 EM_S=THREAD_MEMALLOC(len_EM_S,double);
76     EM_F=THREAD_MEMALLOC(len_EM_F,double);
77 gross 2748 row_index=THREAD_MEMALLOC(p.row_numShapesTotal,index_t);
78 gross 853
79 jfenwick 2271
80 jfenwick 3086 if (!Dudley_checkPtr(EM_S) && !Dudley_checkPtr(EM_F) && !Dudley_checkPtr(row_index) ) {
81 gross 853
82     for (color=elements->minColor;color<=elements->maxColor;color++) {
83     /* open loop over all elements: */
84     #pragma omp for private(e) schedule(static)
85     for(e=0;e<elements->numElements;e++){
86     if (elements->Color[e]==color) {
87 gross 2748
88 jfenwick 2770 A_p=getSampleDataRO(A,e);
89     C_p=getSampleDataRO(C,e);
90     B_p=getSampleDataRO(B,e);
91     D_p=getSampleDataRO(D,e);
92     X_p=getSampleDataRO(X,e);
93     Y_p=getSampleDataRO(Y,e);
94 gross 2748
95 jfenwick 3137 Vol=&(p.row_jac->volume[INDEX3(0,0,e, p.numQuadTotal,1)]);
96     DSDX=&(p.row_jac->DSDX[INDEX5(0,0,0,0,e, p.row_numShapesTotal,DIM,p.numQuadTotal,1)]);
97 gross 2748 for (q=0;q<len_EM_S;++q) EM_S[q]=0;
98     for (q=0;q<len_EM_F;++q) EM_F[q]=0;
99     add_EM_F=FALSE;
100     add_EM_S=FALSE;
101     /**************************************************************/
102     /* process A: */
103     /**************************************************************/
104     if (NULL!=A_p) {
105     add_EM_S=TRUE;
106     if (extendedA) {
107 jfenwick 3137 A_q=&(A_p[INDEX4(0,0,0,0, DIM,DIM,p.numQuadTotal)]);
108 gross 2748 for (s=0;s<p.row_numShapes;s++) {
109     for (r=0;r<p.col_numShapes;r++) {
110     rtmp=0;
111 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) {
112 gross 2748 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)];
113     }
114     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
115     }
116     }
117     } else {
118     for (s=0;s<p.row_numShapes;s++) {
119     for (r=0;r<p.col_numShapes;r++) {
120     rtmp=0;
121 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
122 gross 2748 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*A_p[INDEX2(0,0,DIM)];
123     }
124     }
125     }
126     }
127     /**************************************************************/
128     /* process B: */
129     /**************************************************************/
130     if (NULL!=B_p) {
131     add_EM_S=TRUE;
132     if (extendedB) {
133 jfenwick 3137 B_q=&(B_p[INDEX3(0,0,0, DIM, p.numQuadTotal)]);
134 gross 2748 for (s=0;s<p.row_numShapes;s++) {
135     for (r=0;r<p.col_numShapes;r++) {
136     rtmp=0;
137 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) {
138 gross 2748 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)];
139     }
140     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
141     }
142     }
143     } else {
144     for (s=0;s<p.row_numShapes;s++) {
145     for (r=0;r<p.col_numShapes;r++) {
146     rtmp=0;
147 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*S[INDEX2(r,q,p.row_numShapes)];
148 gross 2748 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*B_p[0];
149     }
150     }
151 gross 853 }
152 gross 2748 }
153     /**************************************************************/
154     /* process C: */
155     /**************************************************************/
156     if (NULL!=C_p) {
157     add_EM_S=TRUE;
158     if (extendedC) {
159 jfenwick 3137 C_q=&(C_p[INDEX3(0,0,0, DIM, p.numQuadTotal)]);
160 gross 2748 for (s=0;s<p.row_numShapes;s++) {
161     for (r=0;r<p.col_numShapes;r++) {
162     rtmp=0;
163 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) {
164 gross 2748 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)];
165     }
166     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
167     }
168     }
169     } else {
170     for (s=0;s<p.row_numShapes;s++) {
171     for (r=0;r<p.col_numShapes;r++) {
172     rtmp=0;
173 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
174 gross 2748 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*C_p[0];
175     }
176     }
177     }
178     }
179     /************************************************************* */
180     /* process D */
181     /**************************************************************/
182     if (NULL!=D_p) {
183     add_EM_S=TRUE;
184     if (extendedD) {
185 jfenwick 3137 D_q=&(D_p[INDEX2(0,0, p.numQuadTotal)]);
186 gross 2748 for (s=0;s<p.row_numShapes;s++) {
187     for (r=0;r<p.col_numShapes;r++) {
188     rtmp=0;
189 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) {
190 gross 2748 rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*D_q[q]*S[INDEX2(r,q,p.row_numShapes)];
191     }
192     EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
193     }
194     }
195     } else {
196     for (s=0;s<p.row_numShapes;s++) {
197     for (r=0;r<p.col_numShapes;r++) {
198     rtmp=0;
199 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(r,q,p.row_numShapes)];
200 gross 2748 EM_S[INDEX4(0,0,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*D_p[0];
201     }
202     }
203     }
204     }
205     /**************************************************************/
206     /* process X: */
207     /**************************************************************/
208     if (NULL!=X_p) {
209     add_EM_F=TRUE;
210     if (extendedX) {
211 jfenwick 3137 X_q=&(X_p[INDEX3(0,0,0, DIM,p.numQuadTotal)]);
212 gross 2748 for (s=0;s<p.row_numShapes;s++) {
213 gross 853 rtmp=0;
214 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*X_q[INDEX2(0,q,DIM)];
215 gross 2748 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
216 gross 853 }
217 gross 2748 } else {
218     for (s=0;s<p.row_numShapes;s++) {
219 gross 853 rtmp=0;
220 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) rtmp+=Vol[q]*DSDX[INDEX3(s,0,q, p.row_numShapesTotal,DIM)];
221 gross 2748 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp*X_p[0];
222 gross 853 }
223 gross 2748 }
224 gross 853 }
225 gross 2748 /**************************************************************/
226     /* process Y: */
227     /**************************************************************/
228     if (NULL!=Y_p) {
229     add_EM_F=TRUE;
230     if (extendedY) {
231 jfenwick 3137 Y_q=&(Y_p[INDEX2(0,0, p.numQuadTotal)]);
232 gross 2748 for (s=0;s<p.row_numShapes;s++) {
233 gross 853 rtmp=0;
234 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*Y_q[q];
235 gross 2748 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp;
236 gross 853 }
237 gross 2748 } else {
238     for (s=0;s<p.row_numShapes;s++) {
239 gross 853 rtmp=0;
240 jfenwick 3137 for (q=0;q<p.numQuadTotal;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
241 gross 2748 EM_F[INDEX2(0,s,p.numEqu)]+=rtmp*Y_p[0];
242 gross 853 }
243     }
244 gross 2748 }
245     /***********************************************************************************************/
246     /* add the element matrices onto the matrix and right hand side */
247     /***********************************************************************************************/
248 jfenwick 3144 for (q=0;q<p.row_numShapesTotal;q++) row_index[q]=p.row_DOF[elements->Nodes[INDEX2(q,e,p.NN)]];
249 gross 2748
250 jfenwick 3086 if (add_EM_F) Dudley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
251     if (add_EM_S) Dudley_Assemble_addToSystemMatrix(Mat,p.row_numShapesTotal,row_index,p.numEqu,p.col_numShapesTotal,row_index,p.numComp,EM_S);
252 gross 853
253     } /* end color check */
254     } /* end element loop */
255     } /* end color loop */
256    
257 jfenwick 2271 THREAD_MEMFREE(EM_S); /* these FREEs appear to be inside the if because if any of the allocs */
258     THREAD_MEMFREE(EM_F); /* failed it means an out of memory (which is not recoverable anyway) */
259 gross 853 THREAD_MEMFREE(row_index);
260 gross 798
261 gross 853 } /* end of pointer check */
262 gross 798 } /* end parallel region */
263     }
264     /*
265     * $Log$
266     */

  ViewVC Help
Powered by ViewVC 1.1.26