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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3259 - (show annotations)
Mon Oct 11 01:48:14 2010 UTC (8 years, 11 months ago) by jfenwick
File MIME type: text/plain
File size: 16196 byte(s)
Merging dudley and scons updates from branches

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 by University of Queensland
5 * 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
14
15 /**************************************************************/
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_{k,i,m,j} u_m,j)_i-(B_{k,i,m} u_m)_i+C_{k,m,j} u_m,j-D_{k,m} u_m and -(X_{k,i})_i + Y_k */
22
23 /* u has p.numComp components 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 = p.numEqu x 1 x p.numComp x 1 */
29 /* B = 1 x numEqu x p.numComp */
30 /* C = p.numEqu x 1 x p.numComp */
31 /* D = p.numEqu x p.numComp */
32 /* X = p.numEqu x 1 */
33 /* Y = p.numEqu */
34
35
36 /**************************************************************/
37
38
39 #include "Assemble.h"
40 #include "Util.h"
41 #ifdef _OPENMP
42 #include <omp.h>
43 #endif
44
45
46 /**************************************************************/
47
48 void Finley_Assemble_PDE_System2_1D(Finley_Assemble_Parameters p,
49 Finley_ElementFile* elements,
50 Paso_SystemMatrix* Mat, escriptDataC* F,
51 escriptDataC* A, escriptDataC* B, escriptDataC* C, escriptDataC* D, escriptDataC* X, escriptDataC* Y) {
52
53 #define DIM 1
54 index_t color;
55 dim_t e, isub;
56 __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;
57 double *EM_S, *EM_F, *Vol, *DSDX;
58 index_t *row_index;
59 register dim_t q, s,r,k,m;
60 register double rtmp;
61 bool_t add_EM_F, add_EM_S;
62
63 bool_t extendedA=isExpanded(A);
64 bool_t extendedB=isExpanded(B);
65 bool_t extendedC=isExpanded(C);
66 bool_t extendedD=isExpanded(D);
67 bool_t extendedX=isExpanded(X);
68 bool_t extendedY=isExpanded(Y);
69 double *F_p=(requireWrite(F), getSampleDataRW(F,0)); /* use comma, to get around the mixed code and declarations thing */
70 double *S=p.row_jac->BasisFunctions->S;
71 dim_t len_EM_S=p.row_numShapesTotal*p.col_numShapesTotal*p.numEqu*p.numComp;
72 dim_t len_EM_F=p.row_numShapesTotal*p.numEqu;
73
74 #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,k,m,rtmp,add_EM_F, add_EM_S, isub)
75 {
76 EM_S=THREAD_MEMALLOC(len_EM_S,double);
77 EM_F=THREAD_MEMALLOC(len_EM_F,double);
78 row_index=THREAD_MEMALLOC(p.row_numShapesTotal,index_t);
79
80 if (!Finley_checkPtr(EM_S) && !Finley_checkPtr(EM_F) && !Finley_checkPtr(row_index) ) {
81
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
88 A_p=getSampleDataRO(A,e);
89 B_p=getSampleDataRO(B,e);
90 C_p=getSampleDataRO(C,e);
91 D_p=getSampleDataRO(D,e);
92 X_p=getSampleDataRO(X,e);
93 Y_p=getSampleDataRO(Y,e);
94
95 for (isub=0; isub<p.numSub; isub++) {
96
97 Vol=&(p.row_jac->volume[INDEX3(0,isub,e, p.numQuadSub,p.numSub)]);
98 DSDX=&(p.row_jac->DSDX[INDEX5(0,0,0,isub,e, p.row_numShapesTotal,DIM,p.numQuadSub,p.numSub)]);
99 for (q=0;q<len_EM_S;++q) EM_S[q]=0;
100 for (q=0;q<len_EM_F;++q) EM_F[q]=0;
101 add_EM_F=FALSE;
102 add_EM_S=FALSE;
103
104 /**************************************************************/
105 /* process A: */
106 /**************************************************************/
107
108 if (NULL!=A_p) {
109 add_EM_S=TRUE;
110 if (extendedA) {
111 A_q=&(A_p[INDEX6(0,0,0,0,0,isub, p.numEqu,DIM,p.numComp,DIM,p.numQuadSub)]);
112 for (s=0;s<p.row_numShapes;s++) {
113 for (r=0;r<p.col_numShapes;r++) {
114 for (k=0;k<p.numEqu;k++) {
115 for (m=0;m<p.numComp;m++) {
116 rtmp=0.;
117 for (q=0;q<p.numQuadSub;q++) {
118 rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*
119 A_q[INDEX5(k,0,m,0,q,p.numEqu,DIM,p.numComp,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
120 }
121 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
122 }
123 }
124 }
125 }
126 } else {
127 for (s=0;s<p.row_numShapes;s++) {
128 for (r=0;r<p.col_numShapes;r++) {
129 rtmp=0;
130 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)];
131 for (k=0;k<p.numEqu;k++) {
132 for (m=0;m<p.numComp;m++) {
133 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*A_p[INDEX4(k,0,m,0,p.numEqu,DIM,p.numComp)];
134 }
135 }
136 }
137 }
138 }
139 }
140 /**************************************************************/
141 /* process B: */
142 /**************************************************************/
143
144 if (NULL!=B_p) {
145 add_EM_S=TRUE;
146 if (extendedB) {
147 B_q=&(B_p[INDEX5(0,0,0,0,isub, p.numEqu,DIM,p.numComp,p.numQuadSub)]);
148 for (s=0;s<p.row_numShapes;s++) {
149 for (r=0;r<p.col_numShapes;r++) {
150 for (k=0;k<p.numEqu;k++) {
151 for (m=0;m<p.numComp;m++) {
152 rtmp=0.;
153 for (q=0;q<p.numQuadSub;q++) {
154 rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*
155 B_q[INDEX4(k,0,m,q,p.numEqu,DIM,p.numComp)]*S[INDEX2(r,q,p.row_numShapes)];
156 }
157 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
158 }
159 }
160 }
161 }
162 } else {
163 for (s=0;s<p.row_numShapes;s++) {
164 for (r=0;r<p.col_numShapes;r++) {
165 rtmp=0;
166 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)];
167 for (k=0;k<p.numEqu;k++) {
168 for (m=0;m<p.numComp;m++) {
169 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*B_p[INDEX3(k,0,m,p.numEqu,DIM)];
170 }
171 }
172 }
173 }
174 }
175 }
176 /**************************************************************/
177 /* process C: */
178 /**************************************************************/
179
180 if (NULL!=C_p) {
181 add_EM_S=TRUE;
182 if (extendedC) {
183 C_q=&(C_p[INDEX5(0,0,0,0,isub, p.numEqu,p.numComp,DIM, p.numQuadSub)]);
184 for (s=0;s<p.row_numShapes;s++) {
185 for (r=0;r<p.col_numShapes;r++) {
186 for (k=0;k<p.numEqu;k++) {
187 for (m=0;m<p.numComp;m++) {
188 rtmp=0;
189 for (q=0;q<p.numQuadSub;q++) {
190 rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*C_q[INDEX4(k,m,0,q,p.numEqu,p.numComp,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
191 }
192 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
193 }
194 }
195 }
196 }
197 } else {
198 for (s=0;s<p.row_numShapes;s++) {
199 for (r=0;r<p.col_numShapes;r++) {
200 rtmp=0;
201 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)];
202 for (k=0;k<p.numEqu;k++) {
203 for (m=0;m<p.numComp;m++) {
204 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*C_p[INDEX3(k,m,0,p.numEqu,p.numComp)];
205 }
206 }
207 }
208 }
209 }
210 }
211 /************************************************************* */
212 /* process D */
213 /**************************************************************/
214
215 if (NULL!=D_p) {
216 add_EM_S=TRUE;
217 if (extendedD) {
218 D_q=&(D_p[INDEX4(0,0,0,isub, p.numEqu,p.numComp,p.numQuadSub)]);
219 for (s=0;s<p.row_numShapes;s++) {
220 for (r=0;r<p.col_numShapes;r++) {
221 for (k=0;k<p.numEqu;k++) {
222 for (m=0;m<p.numComp;m++) {
223 rtmp=0;
224 for (q=0;q<p.numQuadSub;q++) {
225 rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*D_q[INDEX3(k,m,q,p.numEqu,p.numComp)]*S[INDEX2(r,q,p.row_numShapes)];
226 }
227 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
228
229 }
230 }
231 }
232 }
233 } else {
234 for (s=0;s<p.row_numShapes;s++) {
235 for (r=0;r<p.col_numShapes;r++) {
236 rtmp=0;
237 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(r,q,p.row_numShapes)];
238 for (k=0;k<p.numEqu;k++) {
239 for (m=0;m<p.numComp;m++) {
240 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*D_p[INDEX2(k,m,p.numEqu)];
241 }
242 }
243 }
244 }
245 }
246 }
247 /**************************************************************/
248 /* process X: */
249 /**************************************************************/
250
251 if (NULL!=X_p) {
252 add_EM_F=TRUE;
253 if (extendedX) {
254 X_q=&(X_p[INDEX4(0,0,0,isub, p.numEqu,DIM,p.numQuadSub)]);
255 for (s=0;s<p.row_numShapes;s++) {
256 for (k=0;k<p.numEqu;k++) {
257 rtmp=0;
258 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*X_q[INDEX3(k,0,q,p.numEqu,DIM)];
259 EM_F[INDEX2(k,s,p.numEqu)]+=rtmp;
260 }
261 }
262 } else {
263 for (s=0;s<p.row_numShapes;s++) {
264 rtmp=0;
265 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
266 for (k=0;k<p.numEqu;k++) EM_F[INDEX2(k,s,p.numEqu)]+=rtmp*X_p[INDEX2(k,0,p.numEqu)];
267 }
268 }
269 }
270 /**************************************************************/
271 /* process Y: */
272 /**************************************************************/
273
274 if (NULL!=Y_p) {
275 add_EM_F=TRUE;
276 if (extendedY) {
277 Y_q=&(Y_p[INDEX3(0,0,isub, p.numEqu,p.numQuadSub)]);
278 for (s=0;s<p.row_numShapes;s++) {
279 for (k=0;k<p.numEqu;k++) {
280 rtmp=0;
281 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*Y_q[INDEX2(k,q,p.numEqu)];
282 EM_F[INDEX2(k,s,p.numEqu)]+=rtmp;
283 }
284 }
285 } else {
286 for (s=0;s<p.row_numShapes;s++) {
287 rtmp=0;
288 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
289 for (k=0;k<p.numEqu;k++) EM_F[INDEX2(k,s,p.numEqu)]+=rtmp*Y_p[k];
290 }
291 }
292 }
293 /***********************************************************************************************/
294 /* add the element matrices onto the matrix and right hand side */
295 /***********************************************************************************************/
296
297 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)]];
298
299 if (add_EM_F) Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
300 if (add_EM_S) Finley_Assemble_addToSystemMatrix(Mat,p.row_numShapesTotal,row_index,p.numEqu,p.col_numShapesTotal,row_index,p.numComp,EM_S);
301
302 } /* end of isub */
303 } /* end color check */
304 } /* end element loop */
305 } /* end color loop */
306
307 THREAD_MEMFREE(EM_S);
308 THREAD_MEMFREE(EM_F);
309 THREAD_MEMFREE(row_index);
310
311 } /* end of pointer check */
312 } /* end parallel region */
313 }
314 /*
315 * $Log$
316 */

  ViewVC Help
Powered by ViewVC 1.1.26