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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6090 - (show annotations)
Wed Mar 23 06:35:54 2016 UTC (3 years ago) by caltinay
File size: 15811 byte(s)
Simplified dudley PDE routines.

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 a single PDE into the stiffness matrix S and right hand side F
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 2D 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 = 2 x 2
29 B = 2
30 C = 2
31 D = scalar
32 X = 2
33 Y = scalar
34
35 *****************************************************************************/
36
37 #include "Assemble.h"
38 #include "Util.h"
39
40 namespace dudley {
41
42 void Assemble_PDE_Single_2D(const AssembleParameters& p,
43 const escript::Data& A, const escript::Data& B,
44 const escript::Data& C, const escript::Data& D,
45 const escript::Data& X, const escript::Data& Y)
46 {
47 const int DIM = 2;
48 bool expandedA = A.actsExpanded();
49 bool expandedB = B.actsExpanded();
50 bool expandedC = C.actsExpanded();
51 bool expandedD = D.actsExpanded();
52 bool expandedX = X.actsExpanded();
53 bool expandedY = Y.actsExpanded();
54 double* F_p = NULL;
55 if (!p.F.isEmpty()) {
56 p.F.requireWrite();
57 F_p = p.F.getSampleDataRW(0);
58 }
59 const double* S = p.shapeFns;
60 const int len_EM_S = p.numShapes * p.numShapes;
61 const int len_EM_F = p.numShapes;
62
63 #pragma omp parallel
64 {
65 std::vector<double> EM_S(len_EM_S);
66 std::vector<double> EM_F(len_EM_F);
67 std::vector<index_t> row_index(len_EM_F);
68
69 for (index_t color = p.elements->minColor; color <= p.elements->maxColor; color++) {
70 // loop over all elements
71 #pragma omp for
72 for (index_t e = 0; e < p.elements->numElements; e++) {
73 if (p.elements->Color[e] == color) {
74 const double vol = p.jac->absD[e] * p.jac->quadweight;
75 const double* DSDX = &p.jac->DSDX[INDEX5(0, 0, 0, 0, e, p.numShapes, DIM, p.numQuad, 1)];
76 std::fill(EM_S.begin(), EM_S.end(), 0);
77 std::fill(EM_F.begin(), EM_F.end(), 0);
78 bool add_EM_F = false;
79 bool add_EM_S = false;
80 /////////////////
81 // process A //
82 /////////////////
83 if (!A.isEmpty()) {
84 const double* A_p = A.getSampleDataRO(e);
85 add_EM_S = true;
86 if (expandedA) {
87 const double* A_q = &A_p[INDEX4(0, 0, 0, 0, DIM, DIM, p.numQuad)];
88 for (int s = 0; s < p.numShapes; s++) {
89 for (int r = 0; r < p.numShapes; r++) {
90 double f = 0.;
91 for (int q = 0; q < p.numQuad; q++) {
92 f += vol *
93 (DSDX[INDEX3(s, 0, q, p.numShapes, DIM)] *
94 A_q[INDEX3(0, 0, q, DIM, DIM)] *
95 DSDX[INDEX3(r, 0, q, p.numShapes, DIM)] +
96 DSDX[INDEX3(s, 0, q, p.numShapes, DIM)] *
97 A_q[INDEX3(0, 1, q, DIM, DIM)] *
98 DSDX[INDEX3(r, 1, q, p.numShapes, DIM)] +
99 DSDX[INDEX3(s, 1, q, p.numShapes, DIM)] *
100 A_q[INDEX3(1, 0, q, DIM, DIM)] *
101 DSDX[INDEX3(r, 0, q, p.numShapes, DIM)] +
102 DSDX[INDEX3(s, 1, q, p.numShapes, DIM)] *
103 A_q[INDEX3(1, 1, q, DIM, DIM)] *
104 DSDX[INDEX3(r, 1, q, p.numShapes, DIM)]);
105 }
106 EM_S[INDEX4(0, 0, s, r, p.numEqu, p.numEqu, p.numShapes)] += f;
107 }
108 }
109 } else {
110 for (int s = 0; s < p.numShapes; s++) {
111 for (int r = 0; r < p.numShapes; r++) {
112 double f00 = 0;
113 double f01 = 0;
114 double f10 = 0;
115 double f11 = 0;
116 for (int q = 0; q < p.numQuad; q++) {
117 const double f0 = vol * DSDX[INDEX3(s, 0, q, p.numShapes, DIM)];
118 const double f1 = vol * DSDX[INDEX3(s, 1, q, p.numShapes, DIM)];
119 f00 += f0 * DSDX[INDEX3(r, 0, q, p.numShapes, DIM)];
120 f01 += f0 * DSDX[INDEX3(r, 1, q, p.numShapes, DIM)];
121 f10 += f1 * DSDX[INDEX3(r, 0, q, p.numShapes, DIM)];
122 f11 += f1 * DSDX[INDEX3(r, 1, q, p.numShapes, DIM)];
123 }
124 EM_S[INDEX4(0, 0, s, r, p.numEqu, p.numEqu, p.numShapes)] +=
125 f00 * A_p[INDEX2(0, 0, DIM)] + f01 * A_p[INDEX2(0, 1, DIM)] +
126 f10 * A_p[INDEX2(1, 0, DIM)] + f11 * A_p[INDEX2(1, 1, DIM)];
127 }
128 }
129 }
130 }
131 ///////////////
132 // process B //
133 ///////////////
134 if (!B.isEmpty()) {
135 const double* B_p = B.getSampleDataRO(e);
136 add_EM_S = true;
137 if (expandedB) {
138 const double* B_q = &B_p[INDEX3(0, 0, 0, DIM, p.numQuad)];
139 for (int s = 0; s < p.numShapes; s++) {
140 for (int r = 0; r < p.numShapes; r++) {
141 double f = 0.;
142 for (int q = 0; q < p.numQuad; q++) {
143 f +=
144 vol * S[INDEX2(r, q, p.numShapes)] *
145 (DSDX[INDEX3(s, 0, q, p.numShapes, DIM)] *
146 B_q[INDEX2(0, q, DIM)] +
147 DSDX[INDEX3(s, 1, q, p.numShapes, DIM)] * B_q[INDEX2(1, q, DIM)]);
148 }
149 EM_S[INDEX4(0, 0, s, r, p.numEqu, p.numEqu, p.numShapes)] += f;
150 }
151 }
152 } else {
153 for (int s = 0; s < p.numShapes; s++) {
154 for (int r = 0; r < p.numShapes; r++) {
155 double f0 = 0;
156 double f1 = 0;
157 for (int q = 0; q < p.numQuad; q++) {
158 const double f = vol * S[INDEX2(r, q, p.numShapes)];
159 f0 += f * DSDX[INDEX3(s, 0, q, p.numShapes, DIM)];
160 f1 += f * DSDX[INDEX3(s, 1, q, p.numShapes, DIM)];
161 }
162 EM_S[INDEX4(0, 0, s, r, p.numEqu, p.numEqu, p.numShapes)] +=
163 f0 * B_p[0] + f1 * B_p[1];
164 }
165 }
166 }
167 }
168 ///////////////
169 // process C //
170 ///////////////
171 if (!C.isEmpty())
172 {
173 const double* C_p = C.getSampleDataRO(e);
174 add_EM_S = true;
175 if (expandedC) {
176 const double* C_q = &C_p[INDEX3(0, 0, 0, DIM, p.numQuad)];
177 for (int s = 0; s < p.numShapes; s++) {
178 for (int r = 0; r < p.numShapes; r++) {
179 double f = 0;
180 for (int q = 0; q < p.numQuad; q++) {
181 f += vol * S[INDEX2(s, q, p.numShapes)]*
182 (C_q[INDEX2(0, q, DIM)] *
183 DSDX[INDEX3(r, 0, q, p.numShapes, DIM)]
184 + C_q[INDEX2(1, q, DIM)] *
185 DSDX[INDEX3(r, 1, q, p.numShapes, DIM)]);
186 }
187 EM_S[INDEX4(0, 0, s, r, p.numEqu, p.numEqu, p.numShapes)] += f;
188 }
189 }
190 } else {
191 for (int s = 0; s < p.numShapes; s++) {
192 for (int r = 0; r < p.numShapes; r++) {
193 double f0 = 0;
194 double f1 = 0;
195 for (int q = 0; q < p.numQuad; q++) {
196 const double f = vol * S[INDEX2(s, q, p.numShapes)];
197 f0 += f * DSDX[INDEX3(r, 0, q, p.numShapes, DIM)];
198 f1 += f * DSDX[INDEX3(r, 1, q, p.numShapes, DIM)];
199 }
200 EM_S[INDEX4(0, 0, s, r, p.numEqu, p.numEqu, p.numShapes)] +=
201 f0 * C_p[0] + f1 * C_p[1];
202 }
203 }
204 }
205 }
206 ///////////////
207 // process D //
208 ///////////////
209 if (!D.isEmpty())
210 {
211 const double* D_p = D.getSampleDataRO(e);
212 add_EM_S = true;
213 if (expandedD) {
214 const double* D_q = &D_p[INDEX2(0, 0, p.numQuad)];
215 for (int s = 0; s < p.numShapes; s++) {
216 for (int r = 0; r < p.numShapes; r++) {
217 double f = 0;
218 for (int q = 0; q < p.numQuad; q++)
219 f +=
220 vol * S[INDEX2(s, q, p.numShapes)] * D_q[q] *
221 S[INDEX2(r, q, p.numShapes)];
222 EM_S[INDEX4(0, 0, s, r, p.numEqu, p.numEqu, p.numShapes)] += f;
223 }
224 }
225 } else {
226 for (int s = 0; s < p.numShapes; s++) {
227 for (int r = 0; r < p.numShapes; r++) {
228 double f = 0;
229 for (int q = 0; q < p.numQuad; q++)
230 f += vol * S[INDEX2(s, q, p.numShapes)] * S[INDEX2(r, q, p.numShapes)];
231 EM_S[INDEX4(0, 0, s, r, p.numEqu, p.numEqu, p.numShapes)] += f * D_p[0];
232 }
233 }
234 }
235 }
236 ///////////////
237 // process X //
238 ///////////////
239 if (!X.isEmpty()) {
240 const double* X_p = X.getSampleDataRO(e);
241 add_EM_F = true;
242 if (expandedX) {
243 const double* X_q = &X_p[INDEX3(0, 0, 0, DIM, p.numQuad)];
244 for (int s = 0; s < p.numShapes; s++) {
245 double f = 0.;
246 for (int q = 0; q < p.numQuad; q++) {
247 f += vol * (DSDX[INDEX3(s, 0, q, p.numShapes, DIM)] *
248 X_q[INDEX2(0, q, DIM)] +
249 DSDX[INDEX3(s, 1, q, p.numShapes, DIM)] * X_q[INDEX2(1, q, DIM)]);
250 }
251 EM_F[INDEX2(0, s, p.numEqu)] += f;
252 }
253 } else {
254 for (int s = 0; s < p.numShapes; s++) {
255 double f0 = 0.;
256 double f1 = 0.;
257 for (int q = 0; q < p.numQuad; q++) {
258 f0 += vol * DSDX[INDEX3(s, 0, q, p.numShapes, DIM)];
259 f1 += vol * DSDX[INDEX3(s, 1, q, p.numShapes, DIM)];
260 }
261 EM_F[INDEX2(0, s, p.numEqu)] += f0*X_p[0] + f1*X_p[1];
262 }
263 }
264 }
265 ///////////////
266 // process Y //
267 ///////////////
268 if (!Y.isEmpty()) {
269 const double* Y_p = Y.getSampleDataRO(e);
270 add_EM_F = true;
271 if (expandedY) {
272 const double* Y_q = &Y_p[INDEX2(0, 0, p.numQuad)];
273 for (int s = 0; s < p.numShapes; s++) {
274 double f = 0;
275 for (int q = 0; q < p.numQuad; q++)
276 f += vol * S[INDEX2(s, q, p.numShapes)] * Y_q[q];
277 EM_F[INDEX2(0, s, p.numEqu)] += f;
278 }
279 } else {
280 for (int s = 0; s < p.numShapes; s++) {
281 double f = 0;
282 for (int q = 0; q < p.numQuad; q++)
283 f += vol * S[INDEX2(s, q, p.numShapes)];
284 EM_F[INDEX2(0, s, p.numEqu)] += f * Y_p[0];
285 }
286 }
287 }
288 // add the element matrices onto the matrix and
289 // right hand side
290 for (int q = 0; q < p.numShapes; q++)
291 row_index[q] = p.DOF[p.elements->Nodes[INDEX2(q, e, p.NN)]];
292 if (add_EM_F)
293 util::addScatter(p.numShapes, &row_index[0],
294 p.numEqu, &EM_F[0], F_p, p.DOF_UpperBound);
295 if (add_EM_S)
296 Assemble_addToSystemMatrix(p.S, row_index, p.numEqu,
297 EM_S);
298 } // end color check
299 } // end element loop
300 } // end color loop
301 } // end parallel region
302 }
303
304 } // namespace dudley
305

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26