Line data Source code
1 : // The libMesh Finite Element Library.
2 : // Copyright (C) 2002-2026 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 :
4 : // This library is free software; you can redistribute it and/or
5 : // modify it under the terms of the GNU Lesser General Public
6 : // License as published by the Free Software Foundation; either
7 : // version 2.1 of the License, or (at your option) any later version.
8 :
9 : // This library is distributed in the hope that it will be useful,
10 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 : // Lesser General Public License for more details.
13 :
14 : // You should have received a copy of the GNU Lesser General Public
15 : // License along with this library; if not, write to the Free Software
16 : // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 :
18 : #ifndef LIBMESH_FE_SIMPLEX_LAGRANGE_H
19 : #define LIBMESH_FE_SIMPLEX_LAGRANGE_H
20 :
21 : // Lagrange shape functions and their derivatives for the simplex
22 : // topologies, in one place rather than spelled out per element order in
23 : // fe_lagrange_shape_2D.C and fe_lagrange_shape_3D.C.
24 : //
25 : // They are inline and call nothing but each other and the 1D shapes,
26 : // which is what the Kokkos work needs in order to evaluate the same
27 : // expressions on a device. The assertions are the exception: those are
28 : // ours, host-only, and a device build will have to say what it wants
29 : // done with them.
30 : //
31 : // Everything here is expressed in the barycentric coordinates of the
32 : // reference simplex -- zeta_0 = 1 - xi - eta (- zeta) and the remaining
33 : // zeta_i the reference coordinates themselves -- because that is the
34 : // form in which the higher-order members stay readable: each is the
35 : // order below it plus a correction, rather than a fresh set of
36 : // polynomials.
37 :
38 : #include "libmesh/libmesh_device.h"
39 : #include "libmesh/point.h"
40 :
41 : namespace libMesh
42 : {
43 : namespace detail
44 : {
45 :
46 : /**
47 : * \returns The derivative of barycentric coordinate \p i with respect
48 : * to reference coordinate \p j on the triangle; a constant, since the
49 : * coordinates are affine in xi and eta.
50 : */
51 : LIBMESH_DEVICE_INLINE
52 1509234396 : Real tri_dzeta(const unsigned int i,
53 : const unsigned int j)
54 : {
55 1509234396 : libmesh_assert_less(i, 3);
56 1509234396 : libmesh_assert_less(j, 2);
57 :
58 1579344804 : switch (i)
59 : {
60 503078132 : case 0:
61 503078132 : return -1.;
62 1979494740 : case 1:
63 1979494740 : return j == 0 ? 1. : 0.;
64 1979494740 : default:
65 1979494740 : return j == 0 ? 0. : 1.;
66 : }
67 : }
68 :
69 : /**
70 : * \returns Which barycentric coordinate the \p j th factor of Tri6
71 : * shape \p i uses: a vertex shape uses its own coordinate twice, and a
72 : * mid-edge shape the two coordinates of the vertices it lies between.
73 : */
74 : LIBMESH_DEVICE_INLINE
75 6109641438 : unsigned short tri6_zeta_index(const unsigned int i,
76 : const unsigned int j)
77 : {
78 2108978286 : libmesh_assert_less(i, 6);
79 2108978286 : libmesh_assert_less(j, 2);
80 :
81 6114526251 : switch (i)
82 : {
83 349868110 : case 0: return 0;
84 349868110 : case 1: return 1;
85 349868110 : case 2: return 2;
86 1022874976 : case 3: return j == 0 ? 0 : 1;
87 1022874976 : case 4: return j == 0 ? 1 : 2;
88 1022874976 : default: return j == 0 ? 2 : 0;
89 : }
90 : }
91 :
92 : LIBMESH_DEVICE_INLINE
93 565578060 : Real tet_dzeta(const unsigned int i,
94 : const unsigned int j)
95 : {
96 191808444 : libmesh_assert_less(i, 4);
97 191808444 : libmesh_assert_less(j, 3);
98 :
99 590518740 : switch (i)
100 : {
101 47952111 : case 0:
102 47952111 : return -1.;
103 189346866 : case 1:
104 189346866 : return j == 0 ? 1. : 0.;
105 189346866 : case 2:
106 189346866 : return j == 1 ? 1. : 0.;
107 189346866 : default:
108 189346866 : return j == 2 ? 1. : 0.;
109 : }
110 : }
111 :
112 : LIBMESH_DEVICE_INLINE
113 569083032 : unsigned short tet10_zeta_index(const unsigned int i,
114 : const unsigned int j)
115 : {
116 151691696 : libmesh_assert_less(i, 10);
117 151691696 : libmesh_assert_less(j, 2);
118 :
119 569083032 : switch (i)
120 : {
121 10249388 : case 0: return 0;
122 20488744 : case 1: return 1;
123 20488744 : case 2: return 2;
124 20488744 : case 3: return 3;
125 70444356 : case 4: return j == 0 ? 0 : 1;
126 70444356 : case 5: return j == 0 ? 1 : 2;
127 70444356 : case 6: return j == 0 ? 2 : 0;
128 70444356 : case 7: return j == 0 ? 0 : 3;
129 70444356 : case 8: return j == 0 ? 1 : 3;
130 70444356 : default: return j == 0 ? 2 : 3;
131 : }
132 : }
133 :
134 : #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
135 : LIBMESH_DEVICE_INLINE
136 256404960 : unsigned short tet_second_deriv_index(const unsigned int i,
137 : const unsigned int j)
138 : {
139 81996360 : libmesh_assert_less(i, 6);
140 81996360 : libmesh_assert_less(j, 2);
141 :
142 256404960 : switch (i)
143 : {
144 13666060 : case 0: return 0;
145 42734160 : case 1: return static_cast<unsigned short>(j);
146 13666060 : case 2: return 1;
147 42734160 : case 3: return j == 0 ? 0 : 2;
148 42734160 : case 4: return j == 0 ? 1 : 2;
149 13666060 : default: return 2;
150 : }
151 : }
152 : #endif
153 :
154 : LIBMESH_DEVICE_INLINE
155 : /**
156 : * The linear triangle's shape functions are its barycentric
157 : * coordinates.
158 : */
159 15186264 : Real fe_lagrange_tri3_shape(const unsigned int i,
160 : const Real xi,
161 : const Real eta)
162 : {
163 15186264 : libmesh_assert_less(i, 3);
164 :
165 56205966 : switch (i)
166 : {
167 18735322 : case 0: return 1. - xi - eta;
168 5062088 : case 1: return xi;
169 18735322 : default: return eta;
170 : }
171 : }
172 :
173 : LIBMESH_DEVICE_INLINE
174 11788980 : Real fe_lagrange_tri3_shape_deriv(const unsigned int i,
175 : const unsigned int j)
176 : {
177 11788980 : libmesh_assert_less(i, 3);
178 11788980 : libmesh_assert_less(j, 2);
179 :
180 11788980 : return tri_dzeta(i, j);
181 : }
182 :
183 : LIBMESH_DEVICE_INLINE
184 : /**
185 : * Quadratic on the triangle: zeta*(2*zeta - 1) at a vertex, and
186 : * 4*zeta_a*zeta_b at the node between vertices a and b, which
187 : * tri6_zeta_index() names.
188 : */
189 226904862 : Real fe_lagrange_tri6_shape(const unsigned int i,
190 : const Real xi,
191 : const Real eta)
192 : {
193 70846638 : libmesh_assert_less(i, 6);
194 :
195 226904862 : const Real bary[3] = {1. - xi - eta, xi, eta};
196 165486690 : const unsigned short m = tri6_zeta_index(i, 0);
197 165486690 : const unsigned short n = tri6_zeta_index(i, 1);
198 :
199 226904862 : if (i < 3)
200 113452431 : return bary[m] * (2. * bary[m] - 1.);
201 :
202 113452431 : return 4. * bary[m] * bary[n];
203 : }
204 :
205 : LIBMESH_DEVICE_INLINE
206 3853985676 : Real fe_lagrange_tri6_shape_deriv(const unsigned int i,
207 : const unsigned int j,
208 : const Real xi,
209 : const Real eta)
210 : {
211 978757692 : libmesh_assert_less(i, 6);
212 978757692 : libmesh_assert_less(j, 2);
213 :
214 3853985676 : const Real bary[3] = {1. - xi - eta, xi, eta};
215 2875529820 : const unsigned short m = tri6_zeta_index(i, 0);
216 2875529820 : const unsigned short n = tri6_zeta_index(i, 1);
217 :
218 3853985676 : if (i < 3)
219 2885402166 : return (4. * bary[m] - 1.) * tri_dzeta(m, j);
220 :
221 3843811494 : return 4. * bary[n] * tri_dzeta(m, j) + 4. * bary[m] * tri_dzeta(n, j);
222 : }
223 :
224 : LIBMESH_DEVICE_INLINE
225 : /**
226 : * Tri6 plus the interior bubble 27*zeta_0*zeta_1*zeta_2, with the vertex
227 : * and edge shapes corrected by three and minus twelve bubbles so that
228 : * each still vanishes at every node but its own. The Tri6 halves are
229 : * written out rather than obtained from fe_lagrange_tri6_shape() so that
230 : * the arithmetic, and so the rounding, is the same as the .C file this
231 : * came from.
232 : */
233 330358652 : Real fe_lagrange_tri7_shape(const unsigned int i,
234 : const Real xi,
235 : const Real eta)
236 : {
237 91318674 : libmesh_assert_less(i, 7);
238 :
239 91318674 : const Real zeta1 = xi;
240 91318674 : const Real zeta2 = eta;
241 330358652 : const Real zeta0 = 1. - zeta1 - zeta2;
242 330358652 : const Real bubble_27th = zeta0*zeta1*zeta2;
243 :
244 330358652 : switch (i)
245 : {
246 44924301 : case 0: return 2.*zeta0*(zeta0-0.5) + 3.*bubble_27th;
247 44924301 : case 1: return 2.*zeta1*(zeta1-0.5) + 3.*bubble_27th;
248 44924301 : case 2: return 2.*zeta2*(zeta2-0.5) + 3.*bubble_27th;
249 44924301 : case 3: return 4.*zeta0*zeta1 - 12.*bubble_27th;
250 44924301 : case 4: return 4.*zeta1*zeta2 - 12.*bubble_27th;
251 44924301 : case 5: return 4.*zeta2*zeta0 - 12.*bubble_27th;
252 60812846 : default: return 27.*bubble_27th;
253 : }
254 : }
255 :
256 : LIBMESH_DEVICE_INLINE
257 : /**
258 : * Differentiating zeta_0*zeta_1*zeta_2 and substituting zeta_0 = 1 - xi -
259 : * eta, zeta_1 = xi, zeta_2 = eta collapses the product rule to one term
260 : * per direction.
261 : */
262 500164834 : Real fe_lagrange_tri7_shape_deriv(const unsigned int i,
263 : const unsigned int j,
264 : const Real xi,
265 : const Real eta)
266 : {
267 131984986 : libmesh_assert_less(i, 7);
268 131984986 : libmesh_assert_less(j, 2);
269 :
270 131984986 : const Real zeta1 = xi;
271 131984986 : const Real zeta2 = eta;
272 500164834 : const Real zeta0 = 1. - zeta1 - zeta2;
273 :
274 131984986 : const Real dzeta0dxi = -1.;
275 131984986 : const Real dzeta1dxi = 1.;
276 131984986 : const Real dzeta2dxi = 0.;
277 500164834 : const Real dbubbledxi = zeta2 * (1. - 2.*zeta1 - zeta2);
278 :
279 131984986 : const Real dzeta0deta = -1.;
280 131984986 : const Real dzeta1deta = 0.;
281 131984986 : const Real dzeta2deta = 1.;
282 500164834 : const Real dbubbledeta= zeta1 * (1. - zeta1 - 2.*zeta2);
283 :
284 500164834 : if (j == 0)
285 250082417 : switch (i)
286 : {
287 34456686 : case 0: return (4.*zeta0-1.)*dzeta0dxi + 3.*dbubbledxi;
288 34456686 : case 1: return (4.*zeta1-1.)*dzeta1dxi + 3.*dbubbledxi;
289 34456686 : case 2: return (4.*zeta2-1.)*dzeta2dxi + 3.*dbubbledxi;
290 34456686 : case 3: return 4.*zeta1*dzeta0dxi + 4.*zeta0*dzeta1dxi - 12.*dbubbledxi;
291 34456686 : case 4: return 4.*zeta2*dzeta1dxi + 4.*zeta1*dzeta2dxi - 12.*dbubbledxi;
292 34456686 : case 5: return 4.*zeta2*dzeta0dxi + 4*zeta0*dzeta2dxi - 12.*dbubbledxi;
293 43342301 : default: return 27.*dbubbledxi;
294 : }
295 :
296 250082417 : switch (i)
297 : {
298 34456686 : case 0: return (4.*zeta0-1.)*dzeta0deta + 3.*dbubbledeta;
299 34456686 : case 1: return (4.*zeta1-1.)*dzeta1deta + 3.*dbubbledeta;
300 34456686 : case 2: return (4.*zeta2-1.)*dzeta2deta + 3.*dbubbledeta;
301 34456686 : case 3: return 4.*zeta1*dzeta0deta + 4.*zeta0*dzeta1deta - 12.*dbubbledeta;
302 34456686 : case 4: return 4.*zeta2*dzeta1deta + 4.*zeta1*dzeta2deta - 12.*dbubbledeta;
303 34456686 : case 5: return 4.*zeta2*dzeta0deta + 4*zeta0*dzeta2deta - 12.*dbubbledeta;
304 43342301 : default: return 27.*dbubbledeta;
305 : }
306 : }
307 :
308 : #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
309 : LIBMESH_DEVICE_INLINE
310 37378044 : Real fe_lagrange_tri6_shape_second_deriv(const unsigned int i,
311 : const unsigned int j)
312 : {
313 9769626 : libmesh_assert_less(i, 6);
314 9769626 : libmesh_assert_less(j, 3);
315 :
316 37378044 : const unsigned short my_j = j == 2 ? 1 : 0;
317 9769626 : const unsigned short my_k = j == 0 ? 0 : 1;
318 :
319 37378044 : if (i < 3)
320 31148370 : return 4. * tri_dzeta(i, my_j) * tri_dzeta(i, my_k);
321 :
322 13804209 : const unsigned short m = tri6_zeta_index(i, 0);
323 13804209 : const unsigned short n = tri6_zeta_index(i, 1);
324 :
325 17060751 : return 4. * (tri_dzeta(n, my_j) * tri_dzeta(m, my_k) +
326 23573835 : tri_dzeta(m, my_j) * tri_dzeta(n, my_k));
327 : }
328 :
329 : LIBMESH_DEVICE_INLINE
330 : /**
331 : * The bubble is quadratic in each direction at most, so its second
332 : * derivatives are linear: -2*eta in xi, -2*xi in eta, and 1 - 2*xi -
333 : * 2*eta mixed. The Tri6 halves are constants, since a quadratic's
334 : * second derivative does not depend on the point.
335 : */
336 63102051 : Real fe_lagrange_tri7_shape_second_deriv(const unsigned int i,
337 : const unsigned int j,
338 : const Real xi,
339 : const Real eta)
340 : {
341 16612662 : libmesh_assert_less(i, 7);
342 16612662 : libmesh_assert_less(j, 3);
343 :
344 16612662 : const Real zeta1 = xi;
345 16612662 : const Real zeta2 = eta;
346 :
347 16612662 : const Real dzeta0dxi = -1.;
348 16612662 : const Real dzeta1dxi = 1.;
349 16612662 : const Real dzeta2dxi = 0.;
350 63102051 : const Real d2bubbledxi2 = -2. * zeta2;
351 :
352 16612662 : const Real dzeta0deta = -1.;
353 16612662 : const Real dzeta1deta = 0.;
354 16612662 : const Real dzeta2deta = 1.;
355 63102051 : const Real d2bubbledeta2 = -2. * zeta1;
356 :
357 63102051 : const Real d2bubbledxideta = (1. - 2.*zeta1 - 2.*zeta2);
358 :
359 63102051 : if (j == 0)
360 21034017 : switch (i)
361 : {
362 2814736 : case 0: return 4.*dzeta0dxi*dzeta0dxi + 3.*d2bubbledxi2;
363 2814736 : case 1: return 4.*dzeta1dxi*dzeta1dxi + 3.*d2bubbledxi2;
364 2814736 : case 2: return 4.*dzeta2dxi*dzeta2dxi + 3.*d2bubbledxi2;
365 2814736 : case 3: return 8.*dzeta0dxi*dzeta1dxi - 12.*d2bubbledxi2;
366 2814736 : case 4: return 8.*dzeta1dxi*dzeta2dxi - 12.*d2bubbledxi2;
367 2814736 : case 5: return 8.*dzeta0dxi*dzeta2dxi - 12.*d2bubbledxi2;
368 4145601 : default: return 27.*d2bubbledxi2;
369 : }
370 :
371 42068034 : if (j == 1)
372 21034017 : switch (i)
373 : {
374 2814736 : case 0: return 4.*dzeta0dxi*dzeta0deta + 3.*d2bubbledxideta;
375 2814736 : case 1: return 4.*dzeta1dxi*dzeta1deta + 3.*d2bubbledxideta;
376 2814736 : case 2: return 4.*dzeta2dxi*dzeta2deta + 3.*d2bubbledxideta;
377 2814736 : case 3: return 4.*dzeta1deta*dzeta0dxi + 4.*dzeta0deta*dzeta1dxi - 12.*d2bubbledxideta;
378 2814736 : case 4: return 4.*dzeta2deta*dzeta1dxi + 4.*dzeta1deta*dzeta2dxi - 12.*d2bubbledxideta;
379 2814736 : case 5: return 4.*dzeta2deta*dzeta0dxi + 4.*dzeta0deta*dzeta2dxi - 12.*d2bubbledxideta;
380 4145601 : default: return 27.*d2bubbledxideta;
381 : }
382 :
383 21034017 : switch (i)
384 : {
385 2814736 : case 0: return 4.*dzeta0deta*dzeta0deta + 3.*d2bubbledeta2;
386 2814736 : case 1: return 4.*dzeta1deta*dzeta1deta + 3.*d2bubbledeta2;
387 2814736 : case 2: return 4.*dzeta2deta*dzeta2deta + 3.*d2bubbledeta2;
388 2814736 : case 3: return 8.*dzeta0deta*dzeta1deta - 12.*d2bubbledeta2;
389 2814736 : case 4: return 8.*dzeta1deta*dzeta2deta - 12.*d2bubbledeta2;
390 2814736 : case 5: return 8.*dzeta0deta*dzeta2deta - 12.*d2bubbledeta2;
391 4145601 : default: return 27.*d2bubbledeta2;
392 : }
393 : }
394 :
395 : #endif
396 :
397 : LIBMESH_DEVICE_INLINE
398 : /**
399 : * The linear tet's shape functions are its barycentric coordinates,
400 : * as for the triangle.
401 : */
402 15737976 : Real fe_lagrange_tet4_shape(const unsigned int i,
403 : const Real xi,
404 : const Real eta,
405 : const Real zeta)
406 : {
407 15737976 : libmesh_assert_less(i, 4);
408 :
409 62092164 : switch (i)
410 : {
411 15523041 : case 0: return 1. - xi - eta - zeta;
412 3934494 : case 1: return xi;
413 15523041 : case 2: return eta;
414 15523041 : default: return zeta;
415 : }
416 : }
417 :
418 : LIBMESH_DEVICE_INLINE
419 341676 : Real fe_lagrange_tet4_shape_deriv(const unsigned int i,
420 : const unsigned int j)
421 : {
422 341676 : libmesh_assert_less(i, 4);
423 341676 : libmesh_assert_less(j, 3);
424 :
425 714204 : return tet_dzeta(i, j);
426 : }
427 :
428 : LIBMESH_DEVICE_INLINE
429 : /**
430 : * Quadratic on the tet, in the same two forms as Tri6:
431 : * zeta*(2*zeta - 1) at a vertex and 4*zeta_a*zeta_b at a mid-edge node.
432 : */
433 48715260 : Real fe_lagrange_tet10_shape(const unsigned int i,
434 : const Real xi,
435 : const Real eta,
436 : const Real zeta)
437 : {
438 13576570 : libmesh_assert_less(i, 10);
439 :
440 48715260 : const Real bary[4] = {1. - xi - eta - zeta, xi, eta, zeta};
441 48715260 : const unsigned short m = tet10_zeta_index(i, 0);
442 48715260 : const unsigned short n = tet10_zeta_index(i, 1);
443 :
444 48715260 : if (i < 4)
445 19486104 : return bary[m] * (2. * bary[m] - 1.);
446 :
447 29229156 : return 4. * bary[m] * bary[n];
448 : }
449 :
450 : LIBMESH_DEVICE_INLINE
451 134305860 : Real fe_lagrange_tet10_shape_deriv(const unsigned int i,
452 : const unsigned int j,
453 : const Real xi,
454 : const Real eta,
455 : const Real zeta)
456 : {
457 37670370 : libmesh_assert_less(i, 10);
458 37670370 : libmesh_assert_less(j, 3);
459 :
460 134305860 : const Real bary[4] = {1. - xi - eta - zeta, xi, eta, zeta};
461 134305860 : const unsigned short m = tet10_zeta_index(i, 0);
462 134305860 : const unsigned short n = tet10_zeta_index(i, 1);
463 :
464 134305860 : if (i < 4)
465 65023617 : return (4. * bary[m] - 1.) * tet_dzeta(m, j);
466 :
467 114487335 : return 4. * bary[n] * tet_dzeta(m, j) + 4. * bary[m] * tet_dzeta(n, j);
468 : }
469 :
470 : LIBMESH_DEVICE_INLINE
471 : /**
472 : * Tet10 plus one bubble per face, zeta_a*zeta_b*zeta_c over the face's
473 : * three vertices. A vertex shape picks up the three bubbles of the faces
474 : * it touches, an edge shape loses twelve of each bubble on the two faces
475 : * sharing that edge, and each face node is 27 times its own bubble. The
476 : * Tet10 halves are written out rather than obtained from
477 : * fe_lagrange_tet10_shape() so that the arithmetic, and so the rounding,
478 : * is the same as the .C file this came from.
479 : */
480 376871110 : Real fe_lagrange_tet14_shape(const unsigned int i,
481 : const Real xi,
482 : const Real eta,
483 : const Real zeta)
484 : {
485 97469764 : libmesh_assert_less(i, 14);
486 :
487 : // Area coordinates, pg. 205, Vol. I, Carey, Oden, Becker FEM
488 97469764 : const Real zeta1 = xi;
489 97469764 : const Real zeta2 = eta;
490 97469764 : const Real zeta3 = zeta;
491 376871110 : const Real zeta0 = 1. - zeta1 - zeta2 - zeta3;
492 :
493 : // Bubble functions (not yet scaled) on side nodes
494 376871110 : const Real bubble_012 = zeta0*zeta1*zeta2;
495 376871110 : const Real bubble_013 = zeta0*zeta1*zeta3;
496 376871110 : const Real bubble_123 = zeta1*zeta2*zeta3;
497 376871110 : const Real bubble_023 = zeta0*zeta2*zeta3;
498 :
499 376871110 : switch (i)
500 : {
501 26919365 : case 0: return zeta0*(2.*zeta0 - 1.) + 3.*(bubble_012+bubble_013+bubble_023);
502 26919365 : case 1: return zeta1*(2.*zeta1 - 1.) + 3.*(bubble_012+bubble_013+bubble_123);
503 26919365 : case 2: return zeta2*(2.*zeta2 - 1.) + 3.*(bubble_012+bubble_023+bubble_123);
504 26919365 : case 3: return zeta3*(2.*zeta3 - 1.) + 3.*(bubble_013+bubble_023+bubble_123);
505 26919365 : case 4: return 4.*zeta0*zeta1 - 12.*(bubble_012+bubble_013);
506 26919365 : case 5: return 4.*zeta1*zeta2 - 12.*(bubble_012+bubble_123);
507 26919365 : case 6: return 4.*zeta2*zeta0 - 12.*(bubble_012+bubble_023);
508 26919365 : case 7: return 4.*zeta0*zeta3 - 12.*(bubble_013+bubble_023);
509 26919365 : case 8: return 4.*zeta1*zeta3 - 12.*(bubble_013+bubble_123);
510 26919365 : case 9: return 4.*zeta2*zeta3 - 12.*(bubble_023+bubble_123);
511 26919365 : case 10: return 27.*bubble_012;
512 26919365 : case 11: return 27.*bubble_013;
513 26919365 : case 12: return 27.*bubble_123;
514 26919365 : default: return 27.*bubble_023;
515 : }
516 : }
517 :
518 : LIBMESH_DEVICE_INLINE
519 : /**
520 : * Tet10 plus one cubic bubble per face, each bubble differentiated in
521 : * place: substituting zeta_0 = 1 - xi - eta - zeta leaves a single
522 : * product per face and direction, so the face opposite the direction's
523 : * vertex loses a factor outright while the faces containing it pick up
524 : * the difference of the two coordinates that vary.
525 : */
526 1216857054 : Real fe_lagrange_tet14_shape_deriv(const unsigned int i,
527 : const unsigned int j,
528 : const Real xi,
529 : const Real eta,
530 : const Real zeta)
531 : {
532 315331128 : libmesh_assert_less(i, 14);
533 315331128 : libmesh_assert_less(j, 3);
534 :
535 315331128 : const Real zeta1 = xi;
536 315331128 : const Real zeta2 = eta;
537 315331128 : const Real zeta3 = zeta;
538 1216857054 : const Real zeta0 = 1. - zeta1 - zeta2 - zeta3;
539 :
540 315331128 : const Real dzeta0dxi = -1.;
541 315331128 : const Real dzeta1dxi = 1.;
542 315331128 : const Real dzeta2dxi = 0.;
543 315331128 : const Real dzeta3dxi = 0.;
544 1216857054 : const Real dbubble012dxi = (zeta0-zeta1)*zeta2;
545 1216857054 : const Real dbubble013dxi = (zeta0-zeta1)*zeta3;
546 1216857054 : const Real dbubble123dxi = zeta2*zeta3;
547 620493804 : const Real dbubble023dxi = -zeta2*zeta3;
548 :
549 315331128 : const Real dzeta0deta = -1.;
550 315331128 : const Real dzeta1deta = 0.;
551 315331128 : const Real dzeta2deta = 1.;
552 315331128 : const Real dzeta3deta = 0.;
553 1216857054 : const Real dbubble012deta = (zeta0-zeta2)*zeta1;
554 1216857054 : const Real dbubble013deta = -zeta1*zeta3;
555 620493804 : const Real dbubble123deta = zeta1*zeta3;
556 1216857054 : const Real dbubble023deta = (zeta0-zeta2)*zeta3;
557 :
558 315331128 : const Real dzeta0dzeta = -1.;
559 315331128 : const Real dzeta1dzeta = 0.;
560 315331128 : const Real dzeta2dzeta = 0.;
561 315331128 : const Real dzeta3dzeta = 1.;
562 1216857054 : const Real dbubble012dzeta = -zeta1*zeta2;
563 1216857054 : const Real dbubble013dzeta = (zeta0-zeta3)*zeta1;
564 620493804 : const Real dbubble123dzeta = zeta1*zeta2;
565 1216857054 : const Real dbubble023dzeta = (zeta0-zeta3)*zeta2;
566 :
567 1216857054 : if (j == 0)
568 405619018 : switch (i)
569 : {
570 28972787 : case 0: return (4.*zeta0 - 1.)*dzeta0dxi + 3.*(dbubble012dxi+dbubble013dxi+dbubble023dxi);
571 28972787 : case 1: return (4.*zeta1 - 1.)*dzeta1dxi + 3.*(dbubble012dxi+dbubble013dxi+dbubble123dxi);
572 28972787 : case 2: return (4.*zeta2 - 1.)*dzeta2dxi + 3.*(dbubble012dxi+dbubble023dxi+dbubble123dxi);
573 28972787 : case 3: return (4.*zeta3 - 1.)*dzeta3dxi + 3.*(dbubble013dxi+dbubble023dxi+dbubble123dxi);
574 28972787 : case 4: return 4.*(zeta0*dzeta1dxi + dzeta0dxi*zeta1) - 12.*(dbubble012dxi+dbubble013dxi);
575 28972787 : case 5: return 4.*(zeta1*dzeta2dxi + dzeta1dxi*zeta2) - 12.*(dbubble012dxi+dbubble123dxi);
576 28972787 : case 6: return 4.*(zeta0*dzeta2dxi + dzeta0dxi*zeta2) - 12.*(dbubble012dxi+dbubble023dxi);
577 28972787 : case 7: return 4.*(zeta0*dzeta3dxi + dzeta0dxi*zeta3) - 12.*(dbubble013dxi+dbubble023dxi);
578 28972787 : case 8: return 4.*(zeta1*dzeta3dxi + dzeta1dxi*zeta3) - 12.*(dbubble013dxi+dbubble123dxi);
579 28972787 : case 9: return 4.*(zeta2*dzeta3dxi + dzeta2dxi*zeta3) - 12.*(dbubble023dxi+dbubble123dxi);
580 28972787 : case 10: return 27.*dbubble012dxi;
581 28972787 : case 11: return 27.*dbubble013dxi;
582 28972787 : case 12: return 27.*dbubble123dxi;
583 28972787 : default: return 27.*dbubble023dxi;
584 : }
585 :
586 811238036 : if (j == 1)
587 405619018 : switch (i)
588 : {
589 28972787 : case 0: return (4.*zeta0 - 1.)*dzeta0deta + 3.*(dbubble012deta+dbubble013deta+dbubble023deta);
590 28972787 : case 1: return (4.*zeta1 - 1.)*dzeta1deta + 3.*(dbubble012deta+dbubble013deta+dbubble123deta);
591 28972787 : case 2: return (4.*zeta2 - 1.)*dzeta2deta + 3.*(dbubble012deta+dbubble023deta+dbubble123deta);
592 28972787 : case 3: return (4.*zeta3 - 1.)*dzeta3deta + 3.*(dbubble013deta+dbubble023deta+dbubble123deta);
593 28972787 : case 4: return 4.*(zeta0*dzeta1deta + dzeta0deta*zeta1) - 12.*(dbubble012deta+dbubble013deta);
594 28972787 : case 5: return 4.*(zeta1*dzeta2deta + dzeta1deta*zeta2) - 12.*(dbubble012deta+dbubble123deta);
595 28972787 : case 6: return 4.*(zeta0*dzeta2deta + dzeta0deta*zeta2) - 12.*(dbubble012deta+dbubble023deta);
596 28972787 : case 7: return 4.*(zeta0*dzeta3deta + dzeta0deta*zeta3) - 12.*(dbubble013deta+dbubble023deta);
597 28972787 : case 8: return 4.*(zeta1*dzeta3deta + dzeta1deta*zeta3) - 12.*(dbubble013deta+dbubble123deta);
598 28972787 : case 9: return 4.*(zeta2*dzeta3deta + dzeta2deta*zeta3) - 12.*(dbubble023deta+dbubble123deta);
599 28972787 : case 10: return 27.*dbubble012deta;
600 28972787 : case 11: return 27.*dbubble013deta;
601 28972787 : case 12: return 27.*dbubble123deta;
602 28972787 : default: return 27.*dbubble023deta;
603 : }
604 :
605 405619018 : switch (i)
606 : {
607 28972787 : case 0: return (4.*zeta0 - 1.)*dzeta0dzeta + 3.*(dbubble012dzeta+dbubble013dzeta+dbubble023dzeta);
608 28972787 : case 1: return (4.*zeta1 - 1.)*dzeta1dzeta + 3.*(dbubble012dzeta+dbubble013dzeta+dbubble123dzeta);
609 28972787 : case 2: return (4.*zeta2 - 1.)*dzeta2dzeta + 3.*(dbubble012dzeta+dbubble023dzeta+dbubble123dzeta);
610 28972787 : case 3: return (4.*zeta3 - 1.)*dzeta3dzeta + 3.*(dbubble013dzeta+dbubble023dzeta+dbubble123dzeta);
611 28972787 : case 4: return 4.*(zeta0*dzeta1dzeta + dzeta0dzeta*zeta1) - 12.*(dbubble012dzeta+dbubble013dzeta);
612 28972787 : case 5: return 4.*(zeta1*dzeta2dzeta + dzeta1dzeta*zeta2) - 12.*(dbubble012dzeta+dbubble123dzeta);
613 28972787 : case 6: return 4.*(zeta0*dzeta2dzeta + dzeta0dzeta*zeta2) - 12.*(dbubble012dzeta+dbubble023dzeta);
614 28972787 : case 7: return 4.*(zeta0*dzeta3dzeta + dzeta0dzeta*zeta3) - 12.*(dbubble013dzeta+dbubble023dzeta);
615 28972787 : case 8: return 4.*(zeta1*dzeta3dzeta + dzeta1dzeta*zeta3) - 12.*(dbubble013dzeta+dbubble123dzeta);
616 28972787 : case 9: return 4.*(zeta2*dzeta3dzeta + dzeta2dzeta*zeta3) - 12.*(dbubble023dzeta+dbubble123dzeta);
617 28972787 : case 10: return 27.*dbubble012dzeta;
618 28972787 : case 11: return 27.*dbubble013dzeta;
619 28972787 : case 12: return 27.*dbubble123dzeta;
620 28972787 : default: return 27.*dbubble023dzeta;
621 : }
622 : }
623 :
624 : #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
625 : LIBMESH_DEVICE_INLINE
626 169200660 : Real fe_lagrange_tet10_shape_second_deriv(const unsigned int i,
627 : const unsigned int j)
628 : {
629 40998180 : libmesh_assert_less(i, 10);
630 40998180 : libmesh_assert_less(j, 6);
631 :
632 128202480 : const unsigned short my_j = tet_second_deriv_index(j, 0);
633 128202480 : const unsigned short my_k = tet_second_deriv_index(j, 1);
634 :
635 169200660 : if (i < 4)
636 92279172 : return 4. * tet_dzeta(i, my_j) * tet_dzeta(i, my_k);
637 :
638 101520396 : const unsigned short m = tet10_zeta_index(i, 0);
639 101520396 : const unsigned short n = tet10_zeta_index(i, 1);
640 :
641 138418758 : return 4. * (tet_dzeta(n, my_j) * tet_dzeta(m, my_k) +
642 101520396 : tet_dzeta(m, my_j) * tet_dzeta(n, my_k));
643 : }
644 :
645 : LIBMESH_DEVICE_INLINE
646 : /**
647 : * The Tet10 half of each second derivative is a constant, so it comes
648 : * from fe_lagrange_tet10_shape_second_deriv(); the face nodes have no
649 : * Tet10 half at all. Each bubble is trilinear in the barycentric
650 : * coordinates, so its second derivatives are linear in the point.
651 : */
652 233856588 : Real fe_lagrange_tet14_shape_second_deriv(const unsigned int i,
653 : const unsigned int j,
654 : const Real xi,
655 : const Real eta,
656 : const Real zeta)
657 : {
658 56532336 : libmesh_assert_less(i, 14);
659 56532336 : libmesh_assert_less(j, 6);
660 :
661 233856588 : const Real returnval = (i < 10) ? fe_lagrange_tet10_shape_second_deriv(i, j) : 0.;
662 :
663 56532336 : const Real zeta1 = xi;
664 56532336 : const Real zeta2 = eta;
665 56532336 : const Real zeta3 = zeta;
666 233856588 : const Real zeta0 = 1. - zeta1 - zeta2 - zeta3;
667 :
668 : // Fill these with whichever derivative we're concerned with
669 : Real d2bubble012, d2bubble013, d2bubble023, d2bubble123;
670 233856588 : switch (j)
671 : {
672 : // d^2()/dxi^2
673 38976098 : case 0:
674 38976098 : d2bubble012 = -2.*zeta2;
675 38976098 : d2bubble013 = -2.*zeta3;
676 9422056 : d2bubble023 = 0.;
677 9422056 : d2bubble123 = 0.;
678 38976098 : break;
679 :
680 : // d^2()/dxideta
681 38976098 : case 1:
682 38976098 : d2bubble012 = (zeta0-zeta1)-zeta2;
683 38976098 : d2bubble013 = -zeta3;
684 9422056 : d2bubble123 = zeta3;
685 9422056 : d2bubble023 = -zeta3;
686 38976098 : break;
687 :
688 : // d^2()/deta^2
689 38976098 : case 2:
690 38976098 : d2bubble012 = -2.*zeta1;
691 9422056 : d2bubble013 = 0.;
692 9422056 : d2bubble123 = 0.;
693 38976098 : d2bubble023 = -2.*zeta3;
694 38976098 : break;
695 :
696 : // d^2()/dxi dzeta
697 38976098 : case 3:
698 38976098 : d2bubble012 = -zeta2;
699 38976098 : d2bubble013 = (zeta0-zeta3)-zeta1;
700 9422056 : d2bubble123 = zeta2;
701 9422056 : d2bubble023 = -zeta2;
702 38976098 : break;
703 :
704 : // d^2()/deta dzeta
705 38976098 : case 4:
706 38976098 : d2bubble012 = -zeta1;
707 9422056 : d2bubble013 = -zeta1;
708 9422056 : d2bubble123 = zeta1;
709 38976098 : d2bubble023 = (zeta0-zeta3)-zeta2;
710 38976098 : break;
711 :
712 : // d^2()/dzeta^2
713 38976098 : default:
714 9422056 : d2bubble012 = 0.;
715 38976098 : d2bubble013 = -2.*zeta1;
716 9422056 : d2bubble123 = 0.;
717 38976098 : d2bubble023 = -2.*zeta2;
718 38976098 : break;
719 : }
720 :
721 233856588 : switch (i)
722 : {
723 16704042 : case 0: return returnval + 3.*(d2bubble012+d2bubble013+d2bubble023);
724 16704042 : case 1: return returnval + 3.*(d2bubble012+d2bubble013+d2bubble123);
725 16704042 : case 2: return returnval + 3.*(d2bubble012+d2bubble023+d2bubble123);
726 16704042 : case 3: return returnval + 3.*(d2bubble013+d2bubble023+d2bubble123);
727 16704042 : case 4: return returnval - 12.*(d2bubble012+d2bubble013);
728 16704042 : case 5: return returnval - 12.*(d2bubble012+d2bubble123);
729 16704042 : case 6: return returnval - 12.*(d2bubble012+d2bubble023);
730 16704042 : case 7: return returnval - 12.*(d2bubble013+d2bubble023);
731 16704042 : case 8: return returnval - 12.*(d2bubble013+d2bubble123);
732 16704042 : case 9: return returnval - 12.*(d2bubble023+d2bubble123);
733 16704042 : case 10: return 27.*d2bubble012;
734 16704042 : case 11: return 27.*d2bubble013;
735 16704042 : case 12: return 27.*d2bubble123;
736 16704042 : default: return 27.*d2bubble023;
737 : }
738 : }
739 :
740 : #endif
741 :
742 : } // namespace detail
743 : } // namespace libMesh
744 :
745 : #endif // LIBMESH_FE_SIMPLEX_LAGRANGE_H
|