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

Contents of /branches/trilinos_from_5897/dudley/src/Assemble_PDE_Single2_1D.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5963 - (show annotations)
Mon Feb 22 06:59:27 2016 UTC (3 years, 3 months ago) by caltinay
File size: 11429 byte(s)
sync and fix.

1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2016 by The 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 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16
17 /************************************************************************************/
18
19 /* assembles the system of numEq PDEs into the stiffness matrix S right hand side F */
20 /* the shape functions for test and solution must be identical */
21
22 /* -(A_{i,j} u_,j)_i-(B_{i} u)_i+C_{j} u_,j-D u_m and -(X_,i)_i + Y */
23
24 /* in a 1D domain. The shape functions for test and solution must be identical */
25 /* and row_NS == row_NN */
26
27 /* Shape of the coefficients: */
28
29 /* A = 1 x 1 */
30 /* B = 1 */
31 /* C = 1 */
32 /* D = scalar */
33 /* X = 1 */
34 /* Y = scalar */
35
36 /************************************************************************************/
37
38 #include "Assemble.h"
39 #include "Util.h"
40 #ifdef _OPENMP
41 #include <omp.h>
42 #endif
43
44 /************************************************************************************/
45
46 void Dudley_Assemble_PDE_Single2_1D(Dudley_Assemble_Parameters p, Dudley_ElementFile * elements,
47 escript::ASM_ptr mat, escriptDataC * F,
48 escriptDataC * A, escriptDataC * B, escriptDataC * C, escriptDataC * D,
49 escriptDataC * X, escriptDataC * Y)
50 {
51
52 #define DIM 1
53 index_t color;
54 dim_t e;
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, *DSDX;
57 index_t *row_index;
58 dim_t q, s, r;
59 double rtmp;
60 bool add_EM_F, add_EM_S;
61
62 bool extendedA = isExpanded(A);
63 bool extendedB = isExpanded(B);
64 bool extendedC = isExpanded(C);
65 bool extendedD = isExpanded(D);
66 bool extendedX = isExpanded(X);
67 bool 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.row_numShapesTotal;
71 dim_t len_EM_F = p.row_numShapesTotal;
72
73 #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 {
75 EM_S = new double[len_EM_S];
76 EM_F = new double[len_EM_F];
77 row_index = new index_t[p.row_numShapesTotal];
78
79 if (!Dudley_checkPtr(EM_S) && !Dudley_checkPtr(EM_F) && !Dudley_checkPtr(row_index))
80 {
81
82 for (color = elements->minColor; color <= elements->maxColor; color++)
83 {
84 /* open loop over all elements: */
85 #pragma omp for private(e) schedule(static)
86 for (e = 0; e < elements->numElements; e++)
87 {
88 if (elements->Color[e] == color)
89 {
90
91 A_p = getSampleDataRO(A, e);
92 C_p = getSampleDataRO(C, e);
93 B_p = getSampleDataRO(B, e);
94 D_p = getSampleDataRO(D, e);
95 X_p = getSampleDataRO(X, e);
96 Y_p = getSampleDataRO(Y, e);
97
98 double vol = p.row_jac->absD[e] * p.row_jac->quadweight;
99 DSDX = &(p.row_jac->DSDX[INDEX5(0, 0, 0, 0, e, p.row_numShapesTotal, DIM, p.numQuadTotal, 1)]);
100 for (q = 0; q < len_EM_S; ++q)
101 EM_S[q] = 0;
102 for (q = 0; q < len_EM_F; ++q)
103 EM_F[q] = 0;
104 add_EM_F = FALSE;
105 add_EM_S = FALSE;
106 /************************************************************************************/
107 /* process A: */
108 /************************************************************************************/
109 if (NULL != A_p)
110 {
111 add_EM_S = TRUE;
112 if (extendedA)
113 {
114 A_q = &(A_p[INDEX4(0, 0, 0, 0, DIM, DIM, p.numQuadTotal)]);
115 for (s = 0; s < p.row_numShapes; s++)
116 {
117 for (r = 0; r < p.row_numShapes; r++)
118 {
119 rtmp = 0;
120 for (q = 0; q < p.numQuadTotal; q++)
121 {
122 rtmp +=
123 vol * DSDX[INDEX3(s, 0, q, p.row_numShapesTotal, DIM)] *
124 A_q[INDEX3(0, 0, q, DIM, DIM)] *
125 DSDX[INDEX3(r, 0, q, p.row_numShapesTotal, DIM)];
126 }
127 EM_S[INDEX4(0, 0, s, r, p.numEqu, p.numComp, p.row_numShapesTotal)] += rtmp;
128 }
129 }
130 }
131 else
132 {
133 for (s = 0; s < p.row_numShapes; s++)
134 {
135 for (r = 0; r < p.row_numShapes; r++)
136 {
137 rtmp = 0;
138 for (q = 0; q < p.numQuadTotal; q++)
139 rtmp +=
140 vol * DSDX[INDEX3(s, 0, q, p.row_numShapesTotal, DIM)] *
141 DSDX[INDEX3(r, 0, q, p.row_numShapesTotal, DIM)];
142 EM_S[INDEX4(0, 0, s, r, p.numEqu, p.numComp, p.row_numShapesTotal)] +=
143 rtmp * A_p[INDEX2(0, 0, DIM)];
144 }
145 }
146 }
147 }
148 /************************************************************************************/
149 /* process B: */
150 /************************************************************************************/
151 if (NULL != B_p)
152 {
153 add_EM_S = TRUE;
154 if (extendedB)
155 {
156 B_q = &(B_p[INDEX3(0, 0, 0, DIM, p.numQuadTotal)]);
157 for (s = 0; s < p.row_numShapes; s++)
158 {
159 for (r = 0; r < p.row_numShapes; r++)
160 {
161 rtmp = 0;
162 for (q = 0; q < p.numQuadTotal; q++)
163 {
164 rtmp +=
165 vol * DSDX[INDEX3(s, 0, q, p.row_numShapesTotal, DIM)] *
166 B_q[INDEX2(0, q, DIM)] * S[INDEX2(r, q, p.row_numShapes)];
167 }
168 EM_S[INDEX4(0, 0, s, r, p.numEqu, p.numComp, p.row_numShapesTotal)] += rtmp;
169 }
170 }
171 }
172 else
173 {
174 for (s = 0; s < p.row_numShapes; s++)
175 {
176 for (r = 0; r < p.row_numShapes; r++)
177 {
178 rtmp = 0;
179 for (q = 0; q < p.numQuadTotal; q++)
180 rtmp +=
181 vol * DSDX[INDEX3(s, 0, q, p.row_numShapesTotal, DIM)] *
182 S[INDEX2(r, q, p.row_numShapes)];
183 EM_S[INDEX4(0, 0, s, r, p.numEqu, p.numComp, p.row_numShapesTotal)] +=
184 rtmp * B_p[0];
185 }
186 }
187 }
188 }
189 /************************************************************************************/
190 /* process C: */
191 /************************************************************************************/
192 if (NULL != C_p)
193 {
194 add_EM_S = TRUE;
195 if (extendedC)
196 {
197 C_q = &(C_p[INDEX3(0, 0, 0, DIM, p.numQuadTotal)]);
198 for (s = 0; s < p.row_numShapes; s++)
199 {
200 for (r = 0; r < p.row_numShapes; r++)
201 {
202 rtmp = 0;
203 for (q = 0; q < p.numQuadTotal; q++)
204 {
205 rtmp +=
206 vol * S[INDEX2(s, q, p.row_numShapes)] * C_q[INDEX2(0, q, DIM)] *
207 DSDX[INDEX3(r, 0, q, p.row_numShapesTotal, DIM)];
208 }
209 EM_S[INDEX4(0, 0, s, r, p.numEqu, p.numComp, p.row_numShapesTotal)] += rtmp;
210 }
211 }
212 }
213 else
214 {
215 for (s = 0; s < p.row_numShapes; s++)
216 {
217 for (r = 0; r < p.row_numShapes; r++)
218 {
219 rtmp = 0;
220 for (q = 0; q < p.numQuadTotal; q++)
221 rtmp +=
222 vol * S[INDEX2(s, q, p.row_numShapes)] *
223 DSDX[INDEX3(r, 0, q, p.row_numShapesTotal, DIM)];
224 EM_S[INDEX4(0, 0, s, r, p.numEqu, p.numComp, p.row_numShapesTotal)] +=
225 rtmp * C_p[0];
226 }
227 }
228 }
229 }
230 /*********************************************************************************** */
231 /* process D */
232 /************************************************************************************/
233 if (NULL != D_p)
234 {
235 add_EM_S = TRUE;
236 if (extendedD)
237 {
238 D_q = &(D_p[INDEX2(0, 0, p.numQuadTotal)]);
239 for (s = 0; s < p.row_numShapes; s++)
240 {
241 for (r = 0; r < p.row_numShapes; r++)
242 {
243 rtmp = 0;
244 for (q = 0; q < p.numQuadTotal; q++)
245 {
246 rtmp +=
247 vol * S[INDEX2(s, q, p.row_numShapes)] * D_q[q] *
248 S[INDEX2(r, q, p.row_numShapes)];
249 }
250 EM_S[INDEX4(0, 0, s, r, p.numEqu, p.numComp, p.row_numShapesTotal)] += rtmp;
251 }
252 }
253 }
254 else
255 {
256 for (s = 0; s < p.row_numShapes; s++)
257 {
258 for (r = 0; r < p.row_numShapes; r++)
259 {
260 rtmp = 0;
261 for (q = 0; q < p.numQuadTotal; q++)
262 rtmp +=
263 vol * S[INDEX2(s, q, p.row_numShapes)] *
264 S[INDEX2(r, q, p.row_numShapes)];
265 EM_S[INDEX4(0, 0, s, r, p.numEqu, p.numComp, p.row_numShapesTotal)] +=
266 rtmp * D_p[0];
267 }
268 }
269 }
270 }
271 /************************************************************************************/
272 /* process X: */
273 /************************************************************************************/
274 if (NULL != X_p)
275 {
276 add_EM_F = TRUE;
277 if (extendedX)
278 {
279 X_q = &(X_p[INDEX3(0, 0, 0, DIM, p.numQuadTotal)]);
280 for (s = 0; s < p.row_numShapes; s++)
281 {
282 rtmp = 0;
283 for (q = 0; q < p.numQuadTotal; q++)
284 rtmp +=
285 vol * DSDX[INDEX3(s, 0, q, p.row_numShapesTotal, DIM)] *
286 X_q[INDEX2(0, q, DIM)];
287 EM_F[INDEX2(0, s, p.numEqu)] += rtmp;
288 }
289 }
290 else
291 {
292 for (s = 0; s < p.row_numShapes; s++)
293 {
294 rtmp = 0;
295 for (q = 0; q < p.numQuadTotal; q++)
296 rtmp += vol * DSDX[INDEX3(s, 0, q, p.row_numShapesTotal, DIM)];
297 EM_F[INDEX2(0, s, p.numEqu)] += rtmp * X_p[0];
298 }
299 }
300 }
301 /************************************************************************************/
302 /* process Y: */
303 /************************************************************************************/
304 if (NULL != Y_p)
305 {
306 add_EM_F = TRUE;
307 if (extendedY)
308 {
309 Y_q = &(Y_p[INDEX2(0, 0, p.numQuadTotal)]);
310 for (s = 0; s < p.row_numShapes; s++)
311 {
312 rtmp = 0;
313 for (q = 0; q < p.numQuadTotal; q++)
314 rtmp += vol * S[INDEX2(s, q, p.row_numShapes)] * Y_q[q];
315 EM_F[INDEX2(0, s, p.numEqu)] += rtmp;
316 }
317 }
318 else
319 {
320 for (s = 0; s < p.row_numShapes; s++)
321 {
322 rtmp = 0;
323 for (q = 0; q < p.numQuadTotal; q++)
324 rtmp += vol * S[INDEX2(s, q, p.row_numShapes)];
325 EM_F[INDEX2(0, s, p.numEqu)] += rtmp * Y_p[0];
326 }
327 }
328 }
329 /*********************************************************************************************************************/
330 /* add the element matrices onto the matrix and right hand side */
331 /*********************************************************************************************************************/
332 for (q = 0; q < p.row_numShapesTotal; q++)
333 row_index[q] = p.row_DOF[elements->Nodes[INDEX2(q, e, p.NN)]];
334
335 if (add_EM_F)
336 Dudley_Util_AddScatter(p.row_numShapesTotal, row_index, p.numEqu, EM_F, F_p,
337 p.row_DOF_UpperBound);
338 if (add_EM_S)
339 Dudley_Assemble_addToSystemMatrix(mat, p.row_numShapesTotal, row_index, p.numEqu,
340 p.row_numShapesTotal, row_index, p.numComp, EM_S);
341
342 } /* end color check */
343 } /* end element loop */
344 } /* end color loop */
345
346 delete[] EM_S; /* these FREEs appear to be inside the if because if any of the allocs */
347 delete[] EM_F; /* failed it means an out of memory (which is not recoverable anyway) */
348 delete[] row_index;
349
350 } /* end of pointer check */
351 } /* end parallel region */
352 }
353
354 /*
355 * $Log$
356 */

Properties

Name Value
svn:mergeinfo /branches/4.0fordebian/dudley/src/Assemble_PDE_Single2_1D.cpp:5567-5588 /branches/complex/dudley/src/Assemble_PDE_Single2_1D.cpp:5866-5937 /branches/lapack2681/finley/src/Assemble_PDE_Single2_1D.cpp:2682-2741 /branches/pasowrap/dudley/src/Assemble_PDE_Single2_1D.cpp:3661-3674 /branches/py3_attempt2/dudley/src/Assemble_PDE_Single2_1D.cpp:3871-3891 /branches/restext/finley/src/Assemble_PDE_Single2_1D.cpp:2610-2624 /branches/ripleygmg_from_3668/dudley/src/Assemble_PDE_Single2_1D.cpp:3669-3791 /branches/stage3.0/finley/src/Assemble_PDE_Single2_1D.cpp:2569-2590 /branches/symbolic_from_3470/dudley/src/Assemble_PDE_Single2_1D.cpp:3471-3974 /branches/symbolic_from_3470/ripley/test/python/dudley/src/Assemble_PDE_Single2_1D.cpp:3517-3974 /release/3.0/finley/src/Assemble_PDE_Single2_1D.cpp:2591-2601 /release/4.0/dudley/src/Assemble_PDE_Single2_1D.cpp:5380-5406 /trunk/dudley/src/Assemble_PDE_Single2_1D.cpp:4257-4344,5898-5962 /trunk/ripley/test/python/dudley/src/Assemble_PDE_Single2_1D.cpp:3480-3515

  ViewVC Help
Powered by ViewVC 1.1.26