/[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 2748 - (show annotations)
Tue Nov 17 07:32:59 2009 UTC (9 years, 8 months ago) by gross
File MIME type: text/plain
File size: 16584 byte(s)
Macro elements are implemented now. VTK writer for macro elements still needs testing.
1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2009 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(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 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 double *EM_S, *EM_F, *Vol, *DSDX;
57 index_t *row_index;
58 register dim_t q, s,r,k,m;
59 register double rtmp;
60 bool_t add_EM_F, add_EM_S;
61
62 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 double *F_p=(requireWrite(F), getSampleDataRW(F,0)); /* use comma, to get around the mixed code and declarations thing */
69 double *S=p.row_jac->BasisFunctions->S;
70 dim_t len_EM_S=p.row_numShapesTotal*p.col_numShapesTotal*p.numEqu*p.numComp;
71 dim_t len_EM_F=p.row_numShapesTotal*p.numEqu;
72
73 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 #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)
80 {
81 EM_S=THREAD_MEMALLOC(len_EM_S,double);
82 EM_F=THREAD_MEMALLOC(len_EM_F,double);
83 row_index=THREAD_MEMALLOC(p.row_numShapesTotal,index_t);
84
85 if (!Finley_checkPtr(EM_S) && !Finley_checkPtr(EM_F) && !Finley_checkPtr(row_index) ) {
86
87 for (color=elements->minColor;color<=elements->maxColor;color++) {
88 /* open loop over all elements: */
89 #pragma omp for private(e) schedule(static)
90 for(e=0;e<elements->numElements;e++){
91 if (elements->Color[e]==color) {
92
93 A_p=getSampleDataRO(A,e,ABuff);
94 B_p=getSampleDataRO(B,e,BBuff);
95 C_p=getSampleDataRO(C,e,CBuff);
96 D_p=getSampleDataRO(D,e,DBuff);
97 X_p=getSampleDataRO(X,e,XBuff);
98 Y_p=getSampleDataRO(Y,e,YBuff);
99
100 for (isub=0; isub<p.numSub; isub++) {
101
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 /**************************************************************/
110 /* process A: */
111 /**************************************************************/
112
113 if (NULL!=A_p) {
114 add_EM_S=TRUE;
115 if (extendedA) {
116 A_q=&(A_p[INDEX6(0,0,0,0,0,isub, p.numEqu,DIM,p.numComp,DIM,p.numQuadSub)]);
117 for (s=0;s<p.row_numShapes;s++) {
118 for (r=0;r<p.col_numShapes;r++) {
119 for (k=0;k<p.numEqu;k++) {
120 for (m=0;m<p.numComp;m++) {
121 rtmp=0.;
122 for (q=0;q<p.numQuadSub;q++) {
123 rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*
124 A_q[INDEX5(k,0,m,0,q,p.numEqu,DIM,p.numComp,DIM)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
125 }
126 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
127 }
128 }
129 }
130 }
131 } else {
132 for (s=0;s<p.row_numShapes;s++) {
133 for (r=0;r<p.col_numShapes;r++) {
134 rtmp=0;
135 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)];
136 for (k=0;k<p.numEqu;k++) {
137 for (m=0;m<p.numComp;m++) {
138 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)];
139 }
140 }
141 }
142 }
143 }
144 }
145 /**************************************************************/
146 /* process B: */
147 /**************************************************************/
148
149 if (NULL!=B_p) {
150 add_EM_S=TRUE;
151 if (extendedB) {
152 B_q=&(B_p[INDEX5(0,0,0,0,isub, p.numEqu,DIM,p.numComp,p.numQuadSub)]);
153 for (s=0;s<p.row_numShapes;s++) {
154 for (r=0;r<p.col_numShapes;r++) {
155 for (k=0;k<p.numEqu;k++) {
156 for (m=0;m<p.numComp;m++) {
157 rtmp=0.;
158 for (q=0;q<p.numQuadSub;q++) {
159 rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)]*
160 B_q[INDEX4(k,0,m,q,p.numEqu,DIM,p.numComp)]*S[INDEX2(r,q,p.row_numShapes)];
161 }
162 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
163 }
164 }
165 }
166 }
167 } else {
168 for (s=0;s<p.row_numShapes;s++) {
169 for (r=0;r<p.col_numShapes;r++) {
170 rtmp=0;
171 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)];
172 for (k=0;k<p.numEqu;k++) {
173 for (m=0;m<p.numComp;m++) {
174 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*B_p[INDEX3(k,0,m,p.numEqu,DIM)];
175 }
176 }
177 }
178 }
179 }
180 }
181 /**************************************************************/
182 /* process C: */
183 /**************************************************************/
184
185 if (NULL!=C_p) {
186 add_EM_S=TRUE;
187 if (extendedC) {
188 C_q=&(C_p[INDEX5(0,0,0,0,isub, p.numEqu,p.numComp,DIM, p.numQuadSub)]);
189 for (s=0;s<p.row_numShapes;s++) {
190 for (r=0;r<p.col_numShapes;r++) {
191 for (k=0;k<p.numEqu;k++) {
192 for (m=0;m<p.numComp;m++) {
193 rtmp=0;
194 for (q=0;q<p.numQuadSub;q++) {
195 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)];
196 }
197 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
198 }
199 }
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)]*DSDX[INDEX3(r,0,q,p.row_numShapesTotal,DIM)];
207 for (k=0;k<p.numEqu;k++) {
208 for (m=0;m<p.numComp;m++) {
209 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)];
210 }
211 }
212 }
213 }
214 }
215 }
216 /************************************************************* */
217 /* process D */
218 /**************************************************************/
219
220 if (NULL!=D_p) {
221 add_EM_S=TRUE;
222 if (extendedD) {
223 D_q=&(D_p[INDEX4(0,0,0,isub, p.numEqu,p.numComp,p.numQuadSub)]);
224 for (s=0;s<p.row_numShapes;s++) {
225 for (r=0;r<p.col_numShapes;r++) {
226 for (k=0;k<p.numEqu;k++) {
227 for (m=0;m<p.numComp;m++) {
228 rtmp=0;
229 for (q=0;q<p.numQuadSub;q++) {
230 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)];
231 }
232 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp;
233
234 }
235 }
236 }
237 }
238 } else {
239 for (s=0;s<p.row_numShapes;s++) {
240 for (r=0;r<p.col_numShapes;r++) {
241 rtmp=0;
242 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*S[INDEX2(r,q,p.row_numShapes)];
243 for (k=0;k<p.numEqu;k++) {
244 for (m=0;m<p.numComp;m++) {
245 EM_S[INDEX4(k,m,s,r,p.numEqu,p.numComp,p.row_numShapesTotal)]+=rtmp*D_p[INDEX2(k,m,p.numEqu)];
246 }
247 }
248 }
249 }
250 }
251 }
252 /**************************************************************/
253 /* process X: */
254 /**************************************************************/
255
256 if (NULL!=X_p) {
257 add_EM_F=TRUE;
258 if (extendedX) {
259 X_q=&(X_p[INDEX4(0,0,0,isub, p.numEqu,DIM,p.numQuadSub)]);
260 for (s=0;s<p.row_numShapes;s++) {
261 for (k=0;k<p.numEqu;k++) {
262 rtmp=0;
263 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)];
264 EM_F[INDEX2(k,s,p.numEqu)]+=rtmp;
265 }
266 }
267 } else {
268 for (s=0;s<p.row_numShapes;s++) {
269 rtmp=0;
270 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*DSDX[INDEX3(s,0,q,p.row_numShapesTotal,DIM)];
271 for (k=0;k<p.numEqu;k++) EM_F[INDEX2(k,s,p.numEqu)]+=rtmp*X_p[INDEX2(k,0,p.numEqu)];
272 }
273 }
274 }
275 /**************************************************************/
276 /* process Y: */
277 /**************************************************************/
278
279 if (NULL!=Y_p) {
280 add_EM_F=TRUE;
281 if (extendedY) {
282 Y_q=&(Y_p[INDEX3(0,0,isub, p.numEqu,p.numQuadSub)]);
283 for (s=0;s<p.row_numShapes;s++) {
284 for (k=0;k<p.numEqu;k++) {
285 rtmp=0;
286 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)]*Y_q[INDEX2(k,q,p.numEqu)];
287 EM_F[INDEX2(k,s,p.numEqu)]+=rtmp;
288 }
289 }
290 } else {
291 for (s=0;s<p.row_numShapes;s++) {
292 rtmp=0;
293 for (q=0;q<p.numQuadSub;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_numShapes)];
294 for (k=0;k<p.numEqu;k++) EM_F[INDEX2(k,s,p.numEqu)]+=rtmp*Y_p[k];
295 }
296 }
297 }
298 /***********************************************************************************************/
299 /* add the element matrices onto the matrix and right hand side */
300 /***********************************************************************************************/
301
302 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)]];
303
304 if (add_EM_F) Finley_Util_AddScatter(p.row_numShapesTotal,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
305 if (add_EM_S) Finley_Assemble_addToSystemMatrix(Mat,p.row_numShapesTotal,row_index,p.numEqu,p.col_numShapesTotal,row_index,p.numComp,EM_S);
306
307 } /* end of isub */
308 } /* end color check */
309 } /* end element loop */
310 } /* end color loop */
311
312 THREAD_MEMFREE(EM_S);
313 THREAD_MEMFREE(EM_F);
314 THREAD_MEMFREE(row_index);
315
316 } /* end of pointer check */
317 } /* end parallel region */
318 freeSampleBuffer(ABuff);
319 freeSampleBuffer(BBuff);
320 freeSampleBuffer(CBuff);
321 freeSampleBuffer(DBuff);
322 freeSampleBuffer(XBuff);
323 freeSampleBuffer(YBuff);
324 }
325 /*
326 * $Log$
327 */

  ViewVC Help
Powered by ViewVC 1.1.26