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

Contents of /branches/doubleplusgood/finley/src/Assemble_PDE_System2_2D.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26