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 :
19 : // Local includes
20 : #include "libmesh/fe.h"
21 : #include "libmesh/elem.h"
22 : #include "libmesh/fe_lagrange_shape_1D.h"
23 : #include "libmesh/enum_to_string.h"
24 : #include "libmesh/face_c0polygon.h"
25 :
26 : // Anonymous namespace for functions shared by LAGRANGE and
27 : // L2_LAGRANGE implementations. Implementations appear at the bottom
28 : // of this file.
29 : namespace
30 : {
31 : using namespace libMesh;
32 :
33 : template <FEFamily T>
34 : Real fe_lagrange_2D_shape(const ElemType,
35 : const Elem * elem,
36 : const Order order,
37 : const unsigned int i,
38 : const Point & p);
39 :
40 : template <FEFamily T>
41 : Real fe_lagrange_2D_shape_deriv(const ElemType type,
42 : const Elem * elem,
43 : const Order order,
44 : const unsigned int i,
45 : const unsigned int j,
46 : const Point & p);
47 :
48 : #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
49 :
50 : template <FEFamily T>
51 : Real fe_lagrange_2D_shape_second_deriv(const ElemType type,
52 : const Elem * elem,
53 : const Order order,
54 : const unsigned int i,
55 : const unsigned int j,
56 : const Point & p);
57 :
58 : #endif // LIBMESH_ENABLE_SECOND_DERIVATIVES
59 :
60 : } // anonymous namespace
61 :
62 :
63 :
64 : namespace libMesh
65 : {
66 :
67 :
68 243596338 : LIBMESH_DEFAULT_VECTORIZED_FE(2,LAGRANGE)
69 1384039 : LIBMESH_DEFAULT_VECTORIZED_FE(2,L2_LAGRANGE)
70 :
71 :
72 : template <>
73 276816722 : Real FE<2,LAGRANGE>::shape(const ElemType type,
74 : const Order order,
75 : const unsigned int i,
76 : const Point & p)
77 : {
78 276816722 : return fe_lagrange_2D_shape<LAGRANGE>(type, nullptr, order, i, p);
79 : }
80 :
81 :
82 :
83 : template <>
84 0 : Real FE<2,L2_LAGRANGE>::shape(const ElemType type,
85 : const Order order,
86 : const unsigned int i,
87 : const Point & p)
88 : {
89 0 : return fe_lagrange_2D_shape<L2_LAGRANGE>(type, nullptr, order, i, p);
90 : }
91 :
92 :
93 : template <>
94 542690563 : Real FE<2,LAGRANGE>::shape(const Elem * elem,
95 : const Order order,
96 : const unsigned int i,
97 : const Point & p,
98 : const bool add_p_level)
99 : {
100 167736014 : libmesh_assert(elem);
101 :
102 : // call the orientation-independent shape functions
103 856856607 : return fe_lagrange_2D_shape<LAGRANGE>(elem->type(), elem, order + add_p_level*elem->p_level(), i, p);
104 : }
105 :
106 :
107 :
108 : template <>
109 2399775 : Real FE<2,L2_LAGRANGE>::shape(const Elem * elem,
110 : const Order order,
111 : const unsigned int i,
112 : const Point & p,
113 : const bool add_p_level)
114 : {
115 616333 : libmesh_assert(elem);
116 :
117 : // call the orientation-independent shape functions
118 3632441 : return fe_lagrange_2D_shape<L2_LAGRANGE>(elem->type(), elem, order + add_p_level*elem->p_level(), i, p);
119 : }
120 :
121 :
122 : template <>
123 427930242 : Real FE<2,LAGRANGE>::shape(const FEType fet,
124 : const Elem * elem,
125 : const unsigned int i,
126 : const Point & p,
127 : const bool add_p_level)
128 : {
129 134680233 : libmesh_assert(elem);
130 649026314 : return fe_lagrange_2D_shape<LAGRANGE>(elem->type(), elem, fet.order + add_p_level*elem->p_level(), i, p);
131 : }
132 :
133 :
134 :
135 : template <>
136 0 : Real FE<2,L2_LAGRANGE>::shape(const FEType fet,
137 : const Elem * elem,
138 : const unsigned int i,
139 : const Point & p,
140 : const bool add_p_level)
141 : {
142 0 : libmesh_assert(elem);
143 0 : return fe_lagrange_2D_shape<L2_LAGRANGE>(elem->type(), elem, fet.order + add_p_level*elem->p_level(), i, p);
144 : }
145 :
146 :
147 : template <>
148 292694936 : Real FE<2,LAGRANGE>::shape_deriv(const ElemType type,
149 : const Order order,
150 : const unsigned int i,
151 : const unsigned int j,
152 : const Point & p)
153 : {
154 292694936 : return fe_lagrange_2D_shape_deriv<LAGRANGE>(type, nullptr, order, i, j, p);
155 : }
156 :
157 :
158 :
159 : template <>
160 0 : Real FE<2,L2_LAGRANGE>::shape_deriv(const ElemType type,
161 : const Order order,
162 : const unsigned int i,
163 : const unsigned int j,
164 : const Point & p)
165 : {
166 0 : return fe_lagrange_2D_shape_deriv<L2_LAGRANGE>(type, nullptr, order, i, j, p);
167 : }
168 :
169 :
170 :
171 : template <>
172 231050380 : Real FE<2,LAGRANGE>::shape_deriv(const Elem * elem,
173 : const Order order,
174 : const unsigned int i,
175 : const unsigned int j,
176 : const Point & p,
177 : const bool add_p_level)
178 : {
179 64802086 : libmesh_assert(elem);
180 :
181 : // call the orientation-independent shape functions
182 360554456 : return fe_lagrange_2D_shape_deriv<LAGRANGE>(elem->type(), elem, order + add_p_level*elem->p_level(), i, j, p);
183 : }
184 :
185 :
186 :
187 : template <>
188 572056 : Real FE<2,L2_LAGRANGE>::shape_deriv(const Elem * elem,
189 : const Order order,
190 : const unsigned int i,
191 : const unsigned int j,
192 : const Point & p,
193 : const bool add_p_level)
194 : {
195 147752 : libmesh_assert(elem);
196 :
197 : // call the orientation-independent shape functions
198 867560 : return fe_lagrange_2D_shape_deriv<L2_LAGRANGE>(elem->type(), elem, order + add_p_level*elem->p_level(), i, j, p);
199 : }
200 :
201 :
202 : template <>
203 4594381294 : Real FE<2,LAGRANGE>::shape_deriv(const FEType fet,
204 : const Elem * elem,
205 : const unsigned int i,
206 : const unsigned int j,
207 : const Point & p,
208 : const bool add_p_level)
209 : {
210 1174275734 : libmesh_assert(elem);
211 6937627514 : return fe_lagrange_2D_shape_deriv<LAGRANGE>(elem->type(), elem, fet.order + add_p_level*elem->p_level(), i, j, p);
212 : }
213 :
214 :
215 :
216 : template <>
217 0 : Real FE<2,L2_LAGRANGE>::shape_deriv(const FEType fet,
218 : const Elem * elem,
219 : const unsigned int i,
220 : const unsigned int j,
221 : const Point & p,
222 : const bool add_p_level)
223 : {
224 0 : libmesh_assert(elem);
225 0 : return fe_lagrange_2D_shape_deriv<L2_LAGRANGE>(elem->type(), elem, fet.order + add_p_level*elem->p_level(), i, j, p);
226 : }
227 :
228 :
229 :
230 : #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
231 :
232 : template <>
233 55352283 : Real FE<2,LAGRANGE>::shape_second_deriv(const ElemType type,
234 : const Order order,
235 : const unsigned int i,
236 : const unsigned int j,
237 : const Point & p)
238 : {
239 55352283 : return fe_lagrange_2D_shape_second_deriv<LAGRANGE>(type, nullptr, order, i, j, p);
240 : }
241 :
242 :
243 :
244 : template <>
245 0 : Real FE<2,L2_LAGRANGE>::shape_second_deriv(const ElemType type,
246 : const Order order,
247 : const unsigned int i,
248 : const unsigned int j,
249 : const Point & p)
250 : {
251 0 : return fe_lagrange_2D_shape_second_deriv<L2_LAGRANGE>(type, nullptr, order, i, j, p);
252 : }
253 :
254 :
255 :
256 : template <>
257 1110087 : Real FE<2,LAGRANGE>::shape_second_deriv(const Elem * elem,
258 : const Order order,
259 : const unsigned int i,
260 : const unsigned int j,
261 : const Point & p,
262 : const bool add_p_level)
263 : {
264 348216 : libmesh_assert(elem);
265 :
266 : // call the orientation-independent shape functions
267 1806519 : return fe_lagrange_2D_shape_second_deriv<LAGRANGE>(elem->type(), elem, order + add_p_level*elem->p_level(), i, j, p);
268 : }
269 :
270 :
271 :
272 : template <>
273 334644 : Real FE<2,L2_LAGRANGE>::shape_second_deriv(const Elem * elem,
274 : const Order order,
275 : const unsigned int i,
276 : const unsigned int j,
277 : const Point & p,
278 : const bool add_p_level)
279 : {
280 90444 : libmesh_assert(elem);
281 :
282 : // call the orientation-independent shape functions
283 515532 : return fe_lagrange_2D_shape_second_deriv<L2_LAGRANGE>(elem->type(), elem, order + add_p_level*elem->p_level(), i, j, p);
284 : }
285 :
286 :
287 : template <>
288 61737204 : Real FE<2,LAGRANGE>::shape_second_deriv(const FEType fet,
289 : const Elem * elem,
290 : const unsigned int i,
291 : const unsigned int j,
292 : const Point & p,
293 : const bool add_p_level)
294 : {
295 15501525 : libmesh_assert(elem);
296 92740254 : return fe_lagrange_2D_shape_second_deriv<LAGRANGE>(elem->type(), elem, fet.order + add_p_level*elem->p_level(), i, j, p);
297 : }
298 :
299 :
300 :
301 : template <>
302 0 : Real FE<2,L2_LAGRANGE>::shape_second_deriv(const FEType fet,
303 : const Elem * elem,
304 : const unsigned int i,
305 : const unsigned int j,
306 : const Point & p,
307 : const bool add_p_level)
308 : {
309 0 : libmesh_assert(elem);
310 0 : return fe_lagrange_2D_shape_second_deriv<L2_LAGRANGE>(elem->type(), elem, fet.order + add_p_level*elem->p_level(), i, j, p);
311 : }
312 :
313 : #endif // LIBMESH_ENABLE_SECOND_DERIVATIVES
314 :
315 : } // namespace libMesh
316 :
317 :
318 :
319 :
320 : // Anonymous namespace function definitions
321 : namespace
322 : {
323 : using namespace libMesh;
324 :
325 : template <FEFamily T>
326 1249837302 : Real fe_lagrange_2D_shape(const ElemType type,
327 : const Elem * elem,
328 : const Order order,
329 : const unsigned int i,
330 : const Point & p)
331 : {
332 : #if LIBMESH_DIM > 1
333 :
334 1249837302 : switch (order)
335 : {
336 : // linear Lagrange shape functions
337 372987502 : case FIRST:
338 : {
339 259387883 : switch (type)
340 : {
341 316536068 : case QUAD4:
342 : case QUADSHELL4:
343 : case QUAD8:
344 : case QUADSHELL8:
345 : case QUAD9:
346 : case QUADSHELL9:
347 : case QUAD16:
348 : {
349 : // Compute quad shape functions as a tensor-product
350 316536068 : const Real xi = p(0);
351 316536068 : const Real eta = p(1);
352 :
353 103054516 : libmesh_assert_less (i, 4);
354 :
355 : // 0 1 2 3
356 : static const unsigned int i0[] = {0, 1, 1, 0};
357 : static const unsigned int i1[] = {0, 0, 1, 1};
358 :
359 316536068 : return (fe_lagrange_1D_linear_shape(i0[i], xi)*
360 530017620 : fe_lagrange_1D_linear_shape(i1[i], eta));
361 : }
362 :
363 56206134 : case TRI3:
364 : case TRISHELL3:
365 : case TRI6:
366 : case TRI7:
367 : {
368 56206134 : const Real zeta1 = p(0);
369 56206134 : const Real zeta2 = p(1);
370 56206134 : const Real zeta0 = 1. - zeta1 - zeta2;
371 :
372 15186405 : libmesh_assert_less (i, 3);
373 :
374 56206134 : switch(i)
375 : {
376 5062135 : case 0:
377 5062135 : return zeta0;
378 :
379 18735378 : case 1:
380 18735378 : return zeta1;
381 :
382 18735378 : case 2:
383 18735378 : return zeta2;
384 :
385 0 : default:
386 0 : libmesh_error_msg("Invalid shape function index i = " << i);
387 : }
388 : }
389 :
390 245300 : case C0POLYGON:
391 : {
392 : // C0Polygon requires using newer FE APIs
393 245300 : if (!elem)
394 0 : libmesh_error_msg("Code (see stack trace) used an outdated FE function overload.\n"
395 : "Shape functions on a C0Polygon are not defined by its ElemType alone.");
396 :
397 68150 : libmesh_assert(elem->type() == C0POLYGON);
398 :
399 68150 : const C0Polygon & poly = *cast_ptr<const C0Polygon *>(elem);
400 :
401 : // We can't use a small tolerance here, because in
402 : // inverse_map() Newton might hand us intermediate
403 : // iterates outside the polygon.
404 245300 : const auto [s, a, b] = poly.subtriangle_coordinates(p, 100);
405 245300 : if (s == invalid_uint)
406 0 : return 0;
407 68150 : libmesh_assert_less(s, poly.n_subtriangles());
408 :
409 245300 : const auto subtri = poly.subtriangle(s);
410 :
411 : // Avoid signed/unsigned comparison warnings
412 245300 : const int nodei = i;
413 245300 : if (nodei == subtri[0])
414 49060 : return 1-a-b;
415 196240 : if (nodei == subtri[1])
416 49060 : return a;
417 147180 : if (nodei == subtri[2])
418 49060 : return b;
419 :
420 : // Basis function i is not supported on p's subtriangle
421 27260 : return 0;
422 : }
423 :
424 0 : default:
425 0 : libmesh_error_msg("ERROR: Unsupported 2D element type: " << Utility::enum_to_string(type));
426 : }
427 : }
428 :
429 :
430 : // quadratic Lagrange shape functions
431 546237368 : case SECOND:
432 : {
433 402149373 : switch (type)
434 : {
435 9605144 : case QUAD8:
436 : case QUADSHELL8:
437 : {
438 9605144 : const Real xi = p(0);
439 9605144 : const Real eta = p(1);
440 :
441 2770328 : libmesh_assert_less (i, 8);
442 :
443 9605144 : switch (i)
444 : {
445 1200643 : case 0:
446 1200643 : return .25*(1. - xi)*(1. - eta)*(-1. - xi - eta);
447 :
448 1200643 : case 1:
449 1200643 : return .25*(1. + xi)*(1. - eta)*(-1. + xi - eta);
450 :
451 1200643 : case 2:
452 1200643 : return .25*(1. + xi)*(1. + eta)*(-1. + xi + eta);
453 :
454 1200643 : case 3:
455 1200643 : return .25*(1. - xi)*(1. + eta)*(-1. - xi + eta);
456 :
457 1200643 : case 4:
458 1200643 : return .5*(1. - xi*xi)*(1. - eta);
459 :
460 1200643 : case 5:
461 1200643 : return .5*(1. + xi)*(1. - eta*eta);
462 :
463 1200643 : case 6:
464 1200643 : return .5*(1. - xi*xi)*(1. + eta);
465 :
466 1200643 : case 7:
467 1200643 : return .5*(1. - xi)*(1. - eta*eta);
468 :
469 0 : default:
470 0 : libmesh_error_msg("Invalid shape function index i = " << i);
471 : }
472 : }
473 :
474 209778588 : case QUAD4:
475 5760 : libmesh_assert_msg(T == L2_LAGRANGE,
476 : "High order on first order elements only supported for L2 families");
477 : libmesh_fallthrough();
478 99944901 : case QUAD9:
479 : case QUADSHELL9:
480 : case QUAD16:
481 : {
482 :
483 : // Compute quad shape functions as a tensor-product
484 309729942 : const Real xi = p(0);
485 309729942 : const Real eta = p(1);
486 :
487 99957114 : libmesh_assert_less (i, 9);
488 :
489 : // 0 1 2 3 4 5 6 7 8
490 : static const unsigned int i0[] = {0, 1, 1, 0, 2, 1, 2, 0, 2};
491 : static const unsigned int i1[] = {0, 0, 1, 1, 0, 2, 1, 2, 2};
492 :
493 309729942 : return (fe_lagrange_1D_quadratic_shape(i0[i], xi)*
494 389855691 : fe_lagrange_1D_quadratic_shape(i1[i], eta));
495 : }
496 :
497 156060582 : case TRI3:
498 4470 : libmesh_assert_msg(T == L2_LAGRANGE,
499 : "High order on first order elements only supported for L2 families");
500 : libmesh_fallthrough();
501 70594164 : case TRI6:
502 : case TRI7:
503 : {
504 226902282 : const Real zeta1 = p(0);
505 226902282 : const Real zeta2 = p(1);
506 226902282 : const Real zeta0 = 1. - zeta1 - zeta2;
507 :
508 70846170 : libmesh_assert_less (i, 6);
509 :
510 226902282 : switch(i)
511 : {
512 37817047 : case 0:
513 37817047 : return 2.*zeta0*(zeta0-0.5);
514 :
515 37817047 : case 1:
516 37817047 : return 2.*zeta1*(zeta1-0.5);
517 :
518 37817047 : case 2:
519 37817047 : return 2.*zeta2*(zeta2-0.5);
520 :
521 37817047 : case 3:
522 37817047 : return 4.*zeta0*zeta1;
523 :
524 37817047 : case 4:
525 37817047 : return 4.*zeta1*zeta2;
526 :
527 37817047 : case 5:
528 37817047 : return 4.*zeta2*zeta0;
529 :
530 0 : default:
531 0 : libmesh_error_msg("Invalid shape function index i = " << i);
532 : }
533 : }
534 :
535 0 : default:
536 0 : libmesh_error_msg("ERROR: Unsupported 2D element type: " << Utility::enum_to_string(type));
537 : }
538 : }
539 :
540 :
541 :
542 : // "cubic" (one cubic bubble) Lagrange shape functions on TRI7
543 330612432 : case THIRD:
544 : {
545 330612432 : switch (type)
546 : {
547 330359408 : case TRI7:
548 : {
549 330359408 : const Real zeta1 = p(0);
550 330359408 : const Real zeta2 = p(1);
551 330359408 : const Real zeta0 = 1. - zeta1 - zeta2;
552 330359408 : const Real bubble_27th = zeta0*zeta1*zeta2;
553 :
554 91319031 : libmesh_assert_less (i, 7);
555 :
556 330359408 : switch(i)
557 : {
558 44924409 : case 0:
559 44924409 : return 2.*zeta0*(zeta0-0.5) + 3.*bubble_27th;
560 :
561 44924409 : case 1:
562 44924409 : return 2.*zeta1*(zeta1-0.5) + 3.*bubble_27th;
563 :
564 44924409 : case 2:
565 44924409 : return 2.*zeta2*(zeta2-0.5) + 3.*bubble_27th;
566 :
567 44924409 : case 3:
568 44924409 : return 4.*zeta0*zeta1 - 12.*bubble_27th;
569 :
570 44924409 : case 4:
571 44924409 : return 4.*zeta1*zeta2 - 12.*bubble_27th;
572 :
573 44924409 : case 5:
574 44924409 : return 4.*zeta2*zeta0 - 12.*bubble_27th;
575 :
576 60812954 : case 6:
577 60812954 : return 27.*bubble_27th;
578 :
579 0 : default:
580 0 : libmesh_error_msg("Invalid shape function index i = " << i);
581 : }
582 : }
583 :
584 253024 : case QUAD16:
585 : {
586 253024 : const Real xi = p(0);
587 253024 : const Real eta = p(1);
588 :
589 : // 1D cubic Lagrange shape functions, nodes at -1, +1, -1/3, +1/3
590 253024 : const Real xi0 = -9./16.*(xi -1.)*(xi +1./3.)*(xi -1./3.); // node at xi=-1
591 253024 : const Real xi1 = 9./16.*(xi +1.)*(xi +1./3.)*(xi -1./3.); // node at xi=+1
592 253024 : const Real xi2 = 27./16.*(xi +1.)*(xi -1.)*(xi -1./3.); // node at xi=-1/3
593 253024 : const Real xi3 = -27./16.*(xi +1.)*(xi -1.)*(xi +1./3.); // node at xi=+1/3
594 :
595 253024 : const Real eta0 = -9./16.*(eta-1.)*(eta+1./3.)*(eta-1./3.); // node at eta=-1
596 253024 : const Real eta1 = 9./16.*(eta+1.)*(eta+1./3.)*(eta-1./3.); // node at eta=+1
597 253024 : const Real eta2 = 27./16.*(eta+1.)*(eta-1.)*(eta-1./3.); // node at eta=-1/3
598 253024 : const Real eta3 = -27./16.*(eta+1.)*(eta-1.)*(eta+1./3.); // node at eta=+1/3
599 :
600 70864 : libmesh_assert_less (i, 16);
601 :
602 253024 : switch(i)
603 : {
604 15814 : case 0:
605 15814 : return xi0*eta0;
606 :
607 15814 : case 1:
608 15814 : return xi1*eta0;
609 :
610 15814 : case 2:
611 15814 : return xi1*eta1;
612 :
613 15814 : case 3:
614 15814 : return xi0*eta1;
615 :
616 15814 : case 4:
617 15814 : return xi2*eta0;
618 :
619 15814 : case 5:
620 15814 : return xi3*eta0;
621 :
622 15814 : case 6:
623 15814 : return xi1*eta2;
624 :
625 15814 : case 7:
626 15814 : return xi1*eta3;
627 :
628 15814 : case 8:
629 15814 : return xi3*eta1;
630 :
631 15814 : case 9:
632 15814 : return xi2*eta1;
633 :
634 15814 : case 10:
635 15814 : return xi0*eta3;
636 :
637 15814 : case 11:
638 15814 : return xi0*eta2;
639 :
640 15814 : case 12:
641 15814 : return xi2*eta2;
642 :
643 15814 : case 13:
644 15814 : return xi3*eta2;
645 :
646 15814 : case 14:
647 15814 : return xi3*eta3;
648 :
649 15814 : case 15:
650 15814 : return xi2*eta3;
651 :
652 0 : default:
653 0 : libmesh_error_msg("Invalid shape function index i = " << i);
654 : }
655 : }
656 :
657 0 : default:
658 0 : libmesh_error_msg("ERROR: Unsupported 2D element type: " << Utility::enum_to_string(type));
659 : }
660 : } // end case THIRD
661 :
662 :
663 :
664 : // unsupported order
665 0 : default:
666 0 : libmesh_error_msg("ERROR: Unsupported 2D FE order: " << order);
667 : }
668 : #else // LIBMESH_DIM > 1
669 : libmesh_ignore(type, order, i, p);
670 : libmesh_not_implemented();
671 : #endif
672 : }
673 :
674 :
675 :
676 : template <FEFamily T>
677 5118698666 : Real fe_lagrange_2D_shape_deriv(const ElemType type,
678 : const Elem * elem,
679 : const Order order,
680 : const unsigned int i,
681 : const unsigned int j,
682 : const Point & p)
683 : {
684 : #if LIBMESH_DIM > 1
685 :
686 1321387328 : libmesh_assert_less (j, 2);
687 :
688 5118698666 : switch (order)
689 : {
690 : // linear Lagrange shape functions
691 149802106 : case FIRST:
692 : {
693 106423114 : switch (type)
694 : {
695 103995728 : case QUAD4:
696 : case QUADSHELL4:
697 : case QUAD8:
698 : case QUADSHELL8:
699 : case QUAD9:
700 : case QUADSHELL9:
701 : case QUAD16:
702 : {
703 : // Compute quad shape functions as a tensor-product
704 103995728 : const Real xi = p(0);
705 103995728 : const Real eta = p(1);
706 :
707 31781760 : libmesh_assert_less (i, 4);
708 :
709 : // 0 1 2 3
710 : static const unsigned int i0[] = {0, 1, 1, 0};
711 : static const unsigned int i1[] = {0, 0, 1, 1};
712 :
713 103995728 : switch (j)
714 : {
715 : // d()/dxi
716 51997864 : case 0:
717 51997864 : return (fe_lagrange_1D_linear_shape_deriv(i0[i], 0, xi)*
718 88104848 : fe_lagrange_1D_linear_shape (i1[i], eta));
719 :
720 : // d()/deta
721 51997864 : case 1:
722 51997864 : return (fe_lagrange_1D_linear_shape (i0[i], xi)*
723 70051356 : fe_lagrange_1D_linear_shape_deriv(i1[i], 0, eta));
724 :
725 0 : default:
726 0 : libmesh_error_msg("ERROR: Invalid derivative index j = " << j);
727 : }
728 : }
729 :
730 45371778 : case TRI3:
731 : case TRISHELL3:
732 : case TRI6:
733 : case TRI7:
734 : {
735 11789196 : libmesh_assert_less (i, 3);
736 :
737 11789196 : const Real dzeta0dxi = -1.;
738 11789196 : const Real dzeta1dxi = 1.;
739 11789196 : const Real dzeta2dxi = 0.;
740 :
741 11789196 : const Real dzeta0deta = -1.;
742 11789196 : const Real dzeta1deta = 0.;
743 11789196 : const Real dzeta2deta = 1.;
744 :
745 45371778 : switch (j)
746 : {
747 : // d()/dxi
748 22685889 : case 0:
749 : {
750 16791357 : switch(i)
751 : {
752 1964866 : case 0:
753 1964866 : return dzeta0dxi;
754 :
755 1964866 : case 1:
756 1964866 : return dzeta1dxi;
757 :
758 1964866 : case 2:
759 1964866 : return dzeta2dxi;
760 :
761 0 : default:
762 0 : libmesh_error_msg("Invalid shape function index i = " << i);
763 : }
764 : }
765 : // d()/deta
766 22685889 : case 1:
767 : {
768 16791357 : switch(i)
769 : {
770 1964866 : case 0:
771 1964866 : return dzeta0deta;
772 :
773 1964866 : case 1:
774 1964866 : return dzeta1deta;
775 :
776 1964866 : case 2:
777 1964866 : return dzeta2deta;
778 :
779 0 : default:
780 0 : libmesh_error_msg("Invalid shape function index i = " << i);
781 : }
782 : }
783 0 : default:
784 0 : libmesh_error_msg("ERROR: Invalid derivative index j = " << j);
785 : }
786 : }
787 :
788 434600 : case C0POLYGON:
789 : {
790 : // C0Polygon requires using newer FE APIs
791 434600 : if (!elem)
792 0 : libmesh_error_msg("Code (see stack trace) used an outdated FE function overload.\n"
793 : "Shape functions on a C0Polygon are not defined by its ElemType alone.");
794 :
795 108760 : libmesh_assert(elem->type() == C0POLYGON);
796 :
797 108760 : const C0Polygon & poly = *cast_ptr<const C0Polygon *>(elem);
798 :
799 : // We can't use a small tolerance here, because in
800 : // inverse_map() Newton might hand us intermediate
801 : // iterates outside the polygon.
802 434600 : const auto [s, a, b] = poly.subtriangle_coordinates(p, 100);
803 434600 : if (s == invalid_uint)
804 0 : return 0;
805 108760 : libmesh_assert_less(s, poly.n_subtriangles());
806 :
807 434600 : const auto subtri = poly.subtriangle(s);
808 :
809 : // Find derivatives w.r.t. subtriangle barycentric
810 : // coordinates
811 108760 : Real du_da = 0, du_db = 0;
812 :
813 : // Avoid signed/unsigned comparison warnings
814 434600 : const int nodei = i;
815 434600 : if (nodei == subtri[0])
816 21752 : du_da = du_db = -1;
817 347680 : else if (nodei == subtri[1])
818 21752 : du_da = 1;
819 260760 : else if (nodei == subtri[2])
820 21752 : du_db = 1;
821 : else
822 : // Basis function i is not supported on p's subtriangle
823 43504 : return 0;
824 :
825 : // We want to return derivatives with respect to xi and
826 : // eta in master space for the polygon, but what we
827 : // calculated above are with respect to xi and eta
828 : // coordinates for a master *triangle*. We need to
829 : // convert from one to the other.
830 :
831 260760 : const auto master_points = poly.master_subtriangle(s);
832 :
833 260760 : const Real dxi_da = master_points[1](0) - master_points[0](0);
834 260760 : const Real dxi_db = master_points[2](0) - master_points[0](0);
835 260760 : const Real deta_da = master_points[1](1) - master_points[0](1);
836 260760 : const Real deta_db = master_points[2](1) - master_points[0](1);
837 260760 : const Real jac = dxi_da*deta_db - dxi_db*deta_da;
838 :
839 260760 : switch (j)
840 : {
841 : // d()/dxi
842 130380 : case 0:
843 : {
844 130380 : const Real da_dxi = deta_db / jac;
845 130380 : const Real db_dxi = -deta_da / jac;
846 130380 : return du_da*da_dxi + du_db*db_dxi;
847 : }
848 : // d()/deta
849 130380 : case 1:
850 : {
851 130380 : const Real da_deta = -dxi_db / jac;
852 130380 : const Real db_deta = dxi_da / jac;
853 130380 : return du_da*da_deta + du_db*db_deta;
854 : }
855 0 : default:
856 0 : libmesh_error_msg("ERROR: Invalid derivative index j = " << j);
857 : }
858 : }
859 :
860 0 : default:
861 0 : libmesh_error_msg("ERROR: Unsupported 2D element type: " << Utility::enum_to_string(type));
862 : }
863 : }
864 :
865 :
866 : // quadratic Lagrange shape functions
867 4467976566 : case SECOND:
868 : {
869 3324818920 : switch (type)
870 : {
871 18418128 : case QUAD8:
872 : case QUADSHELL8:
873 : {
874 18418128 : const Real xi = p(0);
875 18418128 : const Real eta = p(1);
876 :
877 4903392 : libmesh_assert_less (i, 8);
878 :
879 18418128 : switch (j)
880 : {
881 : // d/dxi
882 9209064 : case 0:
883 9209064 : switch (i)
884 : {
885 1151133 : case 0:
886 1764047 : return .25*(1. - eta)*((1. - xi)*(-1.) +
887 1151133 : (-1.)*(-1. - xi - eta));
888 :
889 1151133 : case 1:
890 1764047 : return .25*(1. - eta)*((1. + xi)*(1.) +
891 1151133 : (1.)*(-1. + xi - eta));
892 :
893 1151133 : case 2:
894 1764047 : return .25*(1. + eta)*((1. + xi)*(1.) +
895 1151133 : (1.)*(-1. + xi + eta));
896 :
897 1151133 : case 3:
898 1764047 : return .25*(1. + eta)*((1. - xi)*(-1.) +
899 1151133 : (-1.)*(-1. - xi + eta));
900 :
901 1151133 : case 4:
902 1151133 : return .5*(-2.*xi)*(1. - eta);
903 :
904 1151133 : case 5:
905 1151133 : return .5*(1.)*(1. - eta*eta);
906 :
907 1151133 : case 6:
908 1151133 : return .5*(-2.*xi)*(1. + eta);
909 :
910 1151133 : case 7:
911 1151133 : return .5*(-1.)*(1. - eta*eta);
912 :
913 0 : default:
914 0 : libmesh_error_msg("Invalid shape function index i = " << i);
915 : }
916 :
917 : // d/deta
918 9209064 : case 1:
919 9209064 : switch (i)
920 : {
921 1151133 : case 0:
922 1764047 : return .25*(1. - xi)*((1. - eta)*(-1.) +
923 1151133 : (-1.)*(-1. - xi - eta));
924 :
925 1151133 : case 1:
926 1764047 : return .25*(1. + xi)*((1. - eta)*(-1.) +
927 1151133 : (-1.)*(-1. + xi - eta));
928 :
929 1151133 : case 2:
930 1764047 : return .25*(1. + xi)*((1. + eta)*(1.) +
931 1151133 : (1.)*(-1. + xi + eta));
932 :
933 1151133 : case 3:
934 1764047 : return .25*(1. - xi)*((1. + eta)*(1.) +
935 1151133 : (1.)*(-1. - xi + eta));
936 :
937 1151133 : case 4:
938 1151133 : return .5*(1. - xi*xi)*(-1.);
939 :
940 1151133 : case 5:
941 1151133 : return .5*(1. + xi)*(-2.*eta);
942 :
943 1151133 : case 6:
944 1151133 : return .5*(1. - xi*xi)*(1.);
945 :
946 1151133 : case 7:
947 1151133 : return .5*(1. - xi)*(-2.*eta);
948 :
949 0 : default:
950 0 : libmesh_error_msg("Invalid shape function index i = " << i);
951 : }
952 :
953 0 : default:
954 0 : libmesh_error_msg("ERROR: Invalid derivative index j = " << j);
955 : }
956 : }
957 :
958 433729854 : case QUAD4:
959 9018 : libmesh_assert_msg(T == L2_LAGRANGE,
960 : "High order on first order elements only supported for L2 families");
961 : libmesh_fallthrough();
962 161837010 : case QUAD9:
963 : case QUADSHELL9:
964 : case QUAD16:
965 : {
966 : // Compute quad shape functions as a tensor-product
967 595575882 : const Real xi = p(0);
968 595575882 : const Real eta = p(1);
969 :
970 161855046 : libmesh_assert_less (i, 9);
971 :
972 : // 0 1 2 3 4 5 6 7 8
973 : static const unsigned int i0[] = {0, 1, 1, 0, 2, 1, 2, 0, 2};
974 : static const unsigned int i1[] = {0, 0, 1, 1, 0, 2, 1, 2, 2};
975 :
976 595575882 : switch (j)
977 : {
978 : // d()/dxi
979 297787941 : case 0:
980 297787941 : return (fe_lagrange_1D_quadratic_shape_deriv(i0[i], 0, xi)*
981 377688276 : fe_lagrange_1D_quadratic_shape (i1[i], eta));
982 :
983 : // d()/deta
984 297787941 : case 1:
985 297787941 : return (fe_lagrange_1D_quadratic_shape (i0[i], xi)*
986 514648359 : fe_lagrange_1D_quadratic_shape_deriv(i1[i], 0, eta));
987 :
988 0 : default:
989 0 : libmesh_error_msg("ERROR: Invalid derivative index j = " << j);
990 : }
991 : }
992 :
993 2875232148 : case TRI3:
994 6348 : libmesh_assert_msg(T == L2_LAGRANGE,
995 : "High order on first order elements only supported for L2 families");
996 : libmesh_fallthrough();
997 978650160 : case TRI6:
998 : case TRI7:
999 : {
1000 978756756 : libmesh_assert_less (i, 6);
1001 :
1002 3853982556 : const Real zeta1 = p(0);
1003 3853982556 : const Real zeta2 = p(1);
1004 3853982556 : const Real zeta0 = 1. - zeta1 - zeta2;
1005 :
1006 978756756 : const Real dzeta0dxi = -1.;
1007 978756756 : const Real dzeta1dxi = 1.;
1008 978756756 : const Real dzeta2dxi = 0.;
1009 :
1010 978756756 : const Real dzeta0deta = -1.;
1011 978756756 : const Real dzeta1deta = 0.;
1012 978756756 : const Real dzeta2deta = 1.;
1013 :
1014 3853982556 : switch(j)
1015 : {
1016 1926991278 : case 0:
1017 : {
1018 1926991278 : switch(i)
1019 : {
1020 321165213 : case 0:
1021 321165213 : return (4.*zeta0-1.)*dzeta0dxi;
1022 :
1023 321165213 : case 1:
1024 321165213 : return (4.*zeta1-1.)*dzeta1dxi;
1025 :
1026 321165213 : case 2:
1027 321165213 : return (4.*zeta2-1.)*dzeta2dxi;
1028 :
1029 321165213 : case 3:
1030 321165213 : return 4.*zeta1*dzeta0dxi + 4.*zeta0*dzeta1dxi;
1031 :
1032 321165213 : case 4:
1033 321165213 : return 4.*zeta2*dzeta1dxi + 4.*zeta1*dzeta2dxi;
1034 :
1035 321165213 : case 5:
1036 321165213 : return 4.*zeta2*dzeta0dxi + 4*zeta0*dzeta2dxi;
1037 :
1038 0 : default:
1039 0 : libmesh_error_msg("Invalid shape function index i = " << i);
1040 : }
1041 : }
1042 :
1043 1926991278 : case 1:
1044 : {
1045 1926991278 : switch(i)
1046 : {
1047 321165213 : case 0:
1048 321165213 : return (4.*zeta0-1.)*dzeta0deta;
1049 :
1050 321165213 : case 1:
1051 321165213 : return (4.*zeta1-1.)*dzeta1deta;
1052 :
1053 321165213 : case 2:
1054 321165213 : return (4.*zeta2-1.)*dzeta2deta;
1055 :
1056 321165213 : case 3:
1057 321165213 : return 4.*zeta1*dzeta0deta + 4.*zeta0*dzeta1deta;
1058 :
1059 321165213 : case 4:
1060 321165213 : return 4.*zeta2*dzeta1deta + 4.*zeta1*dzeta2deta;
1061 :
1062 321165213 : case 5:
1063 321165213 : return 4.*zeta2*dzeta0deta + 4*zeta0*dzeta2deta;
1064 :
1065 0 : default:
1066 0 : libmesh_error_msg("Invalid shape function index i = " << i);
1067 : }
1068 : }
1069 0 : default:
1070 0 : libmesh_error_msg("ERROR: Invalid derivative index j = " << j);
1071 : }
1072 : }
1073 :
1074 0 : default:
1075 0 : libmesh_error_msg("ERROR: Unsupported 2D element type: " << Utility::enum_to_string(type));
1076 : }
1077 : }
1078 :
1079 :
1080 :
1081 : // "cubic" (one cubic bubble) Lagrange shape functions on TRI7
1082 500919994 : case THIRD:
1083 : {
1084 500919994 : switch (type)
1085 : {
1086 500165562 : case TRI7:
1087 : {
1088 131985378 : libmesh_assert_less (i, 7);
1089 :
1090 500165562 : const Real zeta1 = p(0);
1091 500165562 : const Real zeta2 = p(1);
1092 500165562 : const Real zeta0 = 1. - zeta1 - zeta2;
1093 : // const Real bubble_27th = zeta0*zeta1*zeta2;
1094 :
1095 131985378 : const Real dzeta0dxi = -1.;
1096 131985378 : const Real dzeta1dxi = 1.;
1097 131985378 : const Real dzeta2dxi = 0.;
1098 500165562 : const Real dbubbledxi = zeta2 * (1. - 2.*zeta1 - zeta2);
1099 :
1100 131985378 : const Real dzeta0deta = -1.;
1101 131985378 : const Real dzeta1deta = 0.;
1102 131985378 : const Real dzeta2deta = 1.;
1103 500165562 : const Real dbubbledeta= zeta1 * (1. - zeta1 - 2.*zeta2);
1104 :
1105 500165562 : switch(j)
1106 : {
1107 250082781 : case 0:
1108 : {
1109 250082781 : switch(i)
1110 : {
1111 34456738 : case 0:
1112 34456738 : return (4.*zeta0-1.)*dzeta0dxi + 3.*dbubbledxi;
1113 :
1114 34456738 : case 1:
1115 34456738 : return (4.*zeta1-1.)*dzeta1dxi + 3.*dbubbledxi;
1116 :
1117 34456738 : case 2:
1118 34456738 : return (4.*zeta2-1.)*dzeta2dxi + 3.*dbubbledxi;
1119 :
1120 34456738 : case 3:
1121 34456738 : return 4.*zeta1*dzeta0dxi + 4.*zeta0*dzeta1dxi - 12.*dbubbledxi;
1122 :
1123 34456738 : case 4:
1124 34456738 : return 4.*zeta2*dzeta1dxi + 4.*zeta1*dzeta2dxi - 12.*dbubbledxi;
1125 :
1126 34456738 : case 5:
1127 34456738 : return 4.*zeta2*dzeta0dxi + 4*zeta0*dzeta2dxi - 12.*dbubbledxi;
1128 :
1129 43342353 : case 6:
1130 43342353 : return 27.*dbubbledxi;
1131 :
1132 0 : default:
1133 0 : libmesh_error_msg("Invalid shape function index i = " << i);
1134 : }
1135 : }
1136 :
1137 250082781 : case 1:
1138 : {
1139 250082781 : switch(i)
1140 : {
1141 34456738 : case 0:
1142 34456738 : return (4.*zeta0-1.)*dzeta0deta + 3.*dbubbledeta;
1143 :
1144 34456738 : case 1:
1145 34456738 : return (4.*zeta1-1.)*dzeta1deta + 3.*dbubbledeta;
1146 :
1147 34456738 : case 2:
1148 34456738 : return (4.*zeta2-1.)*dzeta2deta + 3.*dbubbledeta;
1149 :
1150 34456738 : case 3:
1151 34456738 : return 4.*zeta1*dzeta0deta + 4.*zeta0*dzeta1deta - 12.*dbubbledeta;
1152 :
1153 34456738 : case 4:
1154 34456738 : return 4.*zeta2*dzeta1deta + 4.*zeta1*dzeta2deta - 12.*dbubbledeta;
1155 :
1156 34456738 : case 5:
1157 34456738 : return 4.*zeta2*dzeta0deta + 4*zeta0*dzeta2deta - 12.*dbubbledeta;
1158 :
1159 43342353 : case 6:
1160 43342353 : return 27.*dbubbledeta;
1161 :
1162 0 : default:
1163 0 : libmesh_error_msg("Invalid shape function index i = " << i);
1164 : }
1165 : }
1166 0 : default:
1167 0 : libmesh_error_msg("ERROR: Invalid derivative index j = " << j);
1168 : }
1169 : } //end TRI7
1170 754432 : case QUAD16:
1171 : {
1172 754432 : const Real xi = p(0);
1173 754432 : const Real eta = p(1);
1174 :
1175 : // 1D cubic Lagrange shape functions, nodes at -1, +1, -1/3, +1/3
1176 754432 : const Real xi0 = -9./16.*(xi -1.)*(xi +1./3.)*(xi -1./3.);
1177 754432 : const Real xi1 = 9./16.*(xi +1.)*(xi +1./3.)*(xi -1./3.);
1178 754432 : const Real xi2 = 27./16.*(xi +1.)*(xi -1.)*(xi -1./3.);
1179 754432 : const Real xi3 = -27./16.*(xi +1.)*(xi -1.)*(xi +1./3.);
1180 :
1181 754432 : const Real eta0 = -9./16.*(eta-1.)*(eta+1./3.)*(eta-1./3.);
1182 754432 : const Real eta1 = 9./16.*(eta+1.)*(eta+1./3.)*(eta-1./3.);
1183 754432 : const Real eta2 = 27./16.*(eta+1.)*(eta-1.)*(eta-1./3.);
1184 754432 : const Real eta3 = -27./16.*(eta+1.)*(eta-1.)*(eta+1./3.);
1185 :
1186 : // Derivatives of the above w.r.t. their own argument
1187 754432 : const Real dxi0 = -27./16.*xi*xi + 9./8.*xi + 1./16.;
1188 754432 : const Real dxi1 = 27./16.*xi*xi + 9./8.*xi - 1./16.;
1189 754432 : const Real dxi2 = 81./16.*xi*xi - 9./8.*xi - 27./16.;
1190 754432 : const Real dxi3 = -81./16.*xi*xi - 9./8.*xi + 27./16.;
1191 :
1192 754432 : const Real deta0 = -27./16.*eta*eta + 9./8.*eta + 1./16.;
1193 754432 : const Real deta1 = 27./16.*eta*eta + 9./8.*eta - 1./16.;
1194 754432 : const Real deta2 = 81./16.*eta*eta - 9./8.*eta - 27./16.;
1195 754432 : const Real deta3 = -81./16.*eta*eta - 9./8.*eta + 27./16.;
1196 :
1197 207040 : libmesh_assert_less (i, 16);
1198 :
1199 754432 : switch (j)
1200 : {
1201 377216 : case 0: // d()/dxi
1202 377216 : switch (i)
1203 : {
1204 23576 : case 0: return dxi0*eta0;
1205 23576 : case 1: return dxi1*eta0;
1206 23576 : case 2: return dxi1*eta1;
1207 23576 : case 3: return dxi0*eta1;
1208 23576 : case 4: return dxi2*eta0;
1209 23576 : case 5: return dxi3*eta0;
1210 23576 : case 6: return dxi1*eta2;
1211 23576 : case 7: return dxi1*eta3;
1212 23576 : case 8: return dxi3*eta1;
1213 23576 : case 9: return dxi2*eta1;
1214 23576 : case 10: return dxi0*eta3;
1215 23576 : case 11: return dxi0*eta2;
1216 23576 : case 12: return dxi2*eta2;
1217 23576 : case 13: return dxi3*eta2;
1218 23576 : case 14: return dxi3*eta3;
1219 23576 : case 15: return dxi2*eta3;
1220 :
1221 0 : default:
1222 0 : libmesh_error_msg("Invalid shape function index i = " << i);
1223 : }
1224 :
1225 377216 : case 1: // d()/deta
1226 377216 : switch (i)
1227 : {
1228 23576 : case 0: return xi0*deta0;
1229 23576 : case 1: return xi1*deta0;
1230 23576 : case 2: return xi1*deta1;
1231 23576 : case 3: return xi0*deta1;
1232 23576 : case 4: return xi2*deta0;
1233 23576 : case 5: return xi3*deta0;
1234 23576 : case 6: return xi1*deta2;
1235 23576 : case 7: return xi1*deta3;
1236 23576 : case 8: return xi3*deta1;
1237 23576 : case 9: return xi2*deta1;
1238 23576 : case 10: return xi0*deta3;
1239 23576 : case 11: return xi0*deta2;
1240 23576 : case 12: return xi2*deta2;
1241 23576 : case 13: return xi3*deta2;
1242 23576 : case 14: return xi3*deta3;
1243 23576 : case 15: return xi2*deta3;
1244 :
1245 0 : default:
1246 0 : libmesh_error_msg("Invalid shape function index i = " << i);
1247 : }
1248 :
1249 0 : default:
1250 0 : libmesh_error_msg("Invalid derivative index j = " << j);
1251 : }
1252 : } //end case QUAD16
1253 :
1254 0 : default:
1255 0 : libmesh_error_msg("ERROR: Unsupported 2D element type: " << Utility::enum_to_string(type));
1256 : }
1257 : } // end case THIRD
1258 :
1259 :
1260 :
1261 : // unsupported order
1262 0 : default:
1263 0 : libmesh_error_msg("ERROR: Unsupported 2D FE order: " << order);
1264 : }
1265 : #else // LIBMESH_DIM > 1
1266 : libmesh_ignore(type, order, i, j, p);
1267 : libmesh_not_implemented();
1268 : #endif
1269 : }
1270 :
1271 :
1272 :
1273 : #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
1274 :
1275 : template <FEFamily T>
1276 87510135 : Real fe_lagrange_2D_shape_second_deriv(const ElemType type,
1277 : const Elem *,
1278 : const Order order,
1279 : const unsigned int i,
1280 : const unsigned int j,
1281 : const Point & p)
1282 : {
1283 : #if LIBMESH_DIM > 1
1284 :
1285 : // j = 0 ==> d^2 phi / dxi^2
1286 : // j = 1 ==> d^2 phi / dxi deta
1287 : // j = 2 ==> d^2 phi / deta^2
1288 31024083 : libmesh_assert_less (j, 3);
1289 :
1290 87510135 : switch (order)
1291 : {
1292 : // linear Lagrange shape functions
1293 877455 : case FIRST:
1294 : {
1295 877455 : switch (type)
1296 : {
1297 575820 : case QUAD4:
1298 : case QUADSHELL4:
1299 : case QUAD8:
1300 : case QUADSHELL8:
1301 : case QUAD9:
1302 : case QUADSHELL9:
1303 : {
1304 : // Compute quad shape functions as a tensor-product
1305 196944 : const Real xi = p(0);
1306 196944 : const Real eta = p(1);
1307 :
1308 196944 : libmesh_assert_less (i, 4);
1309 :
1310 : // 0 1 2 3
1311 : static const unsigned int i0[] = {0, 1, 1, 0};
1312 : static const unsigned int i1[] = {0, 0, 1, 1};
1313 :
1314 575820 : switch (j)
1315 : {
1316 : // d^2() / dxi^2
1317 65648 : case 0:
1318 65648 : return 0.;
1319 :
1320 : // d^2() / dxi deta
1321 191940 : case 1:
1322 191940 : return (fe_lagrange_1D_linear_shape_deriv(i0[i], 0, xi)*
1323 255086 : fe_lagrange_1D_linear_shape_deriv(i1[i], 0, eta));
1324 :
1325 : // d^2() / deta^2
1326 65648 : case 2:
1327 65648 : return 0.;
1328 :
1329 0 : default:
1330 0 : libmesh_error_msg("ERROR: Invalid derivative index j = " << j);
1331 : }
1332 : }
1333 :
1334 : // All second derivatives for linear triangles are zero.
1335 112281 : case TRI3:
1336 : case TRISHELL3:
1337 : case TRI6:
1338 : case TRI7:
1339 :
1340 : // All second derivatives for piecewise-linear polygons are
1341 : // zero or dirac-type distributions, but we can't put the
1342 : // latter in a Real, so beware when integrating...
1343 : case C0POLYGON:
1344 : {
1345 112281 : return 0.;
1346 : }
1347 :
1348 0 : default:
1349 0 : libmesh_error_msg("ERROR: Unsupported 2D element type: " << Utility::enum_to_string(type));
1350 :
1351 : } // end switch (type)
1352 : } // end case FIRST
1353 :
1354 :
1355 : // quadratic Lagrange shape functions
1356 40068123 : case SECOND:
1357 : {
1358 40068123 : switch (type)
1359 : {
1360 3291072 : case QUAD8:
1361 : case QUADSHELL8:
1362 : {
1363 3291072 : const Real xi = p(0);
1364 3291072 : const Real eta = p(1);
1365 :
1366 1079016 : libmesh_assert_less (j, 3);
1367 :
1368 3291072 : switch (j)
1369 : {
1370 : // d^2() / dxi^2
1371 1097024 : case 0:
1372 : {
1373 1097024 : switch (i)
1374 : {
1375 274256 : case 0:
1376 : case 1:
1377 274256 : return 0.5*(1.-eta);
1378 :
1379 274256 : case 2:
1380 : case 3:
1381 274256 : return 0.5*(1.+eta);
1382 :
1383 137128 : case 4:
1384 137128 : return eta - 1.;
1385 :
1386 89918 : case 5:
1387 : case 7:
1388 89918 : return 0.0;
1389 :
1390 137128 : case 6:
1391 137128 : return -1. - eta;
1392 :
1393 0 : default:
1394 0 : libmesh_error_msg("Invalid shape function index i = " << i);
1395 : }
1396 : }
1397 :
1398 : // d^2() / dxi deta
1399 1097024 : case 1:
1400 : {
1401 1097024 : switch (i)
1402 : {
1403 137128 : case 0:
1404 137128 : return 0.25*( 1. - 2.*xi - 2.*eta);
1405 :
1406 137128 : case 1:
1407 137128 : return 0.25*(-1. - 2.*xi + 2.*eta);
1408 :
1409 137128 : case 2:
1410 137128 : return 0.25*( 1. + 2.*xi + 2.*eta);
1411 :
1412 137128 : case 3:
1413 137128 : return 0.25*(-1. + 2.*xi - 2.*eta);
1414 :
1415 44959 : case 4:
1416 44959 : return xi;
1417 :
1418 137128 : case 5:
1419 137128 : return -eta;
1420 :
1421 137128 : case 6:
1422 137128 : return -xi;
1423 :
1424 137128 : case 7:
1425 137128 : return eta;
1426 :
1427 0 : default:
1428 0 : libmesh_error_msg("Invalid shape function index i = " << i);
1429 : }
1430 : }
1431 :
1432 : // d^2() / deta^2
1433 1097024 : case 2:
1434 : {
1435 1097024 : switch (i)
1436 : {
1437 274256 : case 0:
1438 : case 3:
1439 274256 : return 0.5*(1.-xi);
1440 :
1441 274256 : case 1:
1442 : case 2:
1443 274256 : return 0.5*(1.+xi);
1444 :
1445 89918 : case 4:
1446 : case 6:
1447 89918 : return 0.0;
1448 :
1449 137128 : case 5:
1450 137128 : return -1.0 - xi;
1451 :
1452 137128 : case 7:
1453 137128 : return xi - 1.0;
1454 :
1455 0 : default:
1456 0 : libmesh_error_msg("Invalid shape function index i = " << i);
1457 : }
1458 : }
1459 :
1460 0 : default:
1461 0 : libmesh_error_msg("ERROR: Invalid derivative index j = " << j);
1462 : } // end switch (j)
1463 : } // end case QUAD8
1464 :
1465 5953662 : case QUAD4:
1466 13527 : libmesh_assert_msg(T == L2_LAGRANGE,
1467 : "High order on first order elements only supported for L2 families");
1468 : libmesh_fallthrough();
1469 3201444 : case QUAD9:
1470 : case QUADSHELL9:
1471 : {
1472 : // Compute QUAD9 second derivatives as tensor product
1473 9168633 : const Real xi = p(0);
1474 9168633 : const Real eta = p(1);
1475 :
1476 3228498 : libmesh_assert_less (i, 9);
1477 :
1478 : // 0 1 2 3 4 5 6 7 8
1479 : static const unsigned int i0[] = {0, 1, 1, 0, 2, 1, 2, 0, 2};
1480 : static const unsigned int i1[] = {0, 0, 1, 1, 0, 2, 1, 2, 2};
1481 :
1482 9168633 : switch (j)
1483 : {
1484 : // d^2() / dxi^2
1485 3056211 : case 0:
1486 3056211 : return (fe_lagrange_1D_quadratic_shape_second_deriv(i0[i], 0, xi)*
1487 3056211 : fe_lagrange_1D_quadratic_shape (i1[i], eta));
1488 :
1489 : // d^2() / dxi deta
1490 3056211 : case 1:
1491 3056211 : return (fe_lagrange_1D_quadratic_shape_deriv(i0[i], 0, xi)*
1492 5036256 : fe_lagrange_1D_quadratic_shape_deriv(i1[i], 0, eta));
1493 :
1494 : // d^2() / deta^2
1495 3056211 : case 2:
1496 3056211 : return (fe_lagrange_1D_quadratic_shape (i0[i], xi)*
1497 3716226 : fe_lagrange_1D_quadratic_shape_second_deriv(i1[i], 0, eta));
1498 :
1499 0 : default:
1500 0 : libmesh_error_msg("ERROR: Invalid derivative index j = " << j);
1501 : } // end switch (j)
1502 : } // end case QUAD9
1503 :
1504 17848314 : case TRI3:
1505 9522 : libmesh_assert_msg(T == L2_LAGRANGE,
1506 : "High order on first order elements only supported for L2 families");
1507 : libmesh_fallthrough();
1508 9739332 : case TRI6:
1509 : case TRI7:
1510 : {
1511 9769626 : const Real dzeta0dxi = -1.;
1512 9769626 : const Real dzeta1dxi = 1.;
1513 9769626 : const Real dzeta2dxi = 0.;
1514 :
1515 9769626 : const Real dzeta0deta = -1.;
1516 9769626 : const Real dzeta1deta = 0.;
1517 9769626 : const Real dzeta2deta = 1.;
1518 :
1519 9769626 : libmesh_assert_less (j, 3);
1520 :
1521 27608418 : switch (j)
1522 : {
1523 : // d^2() / dxi^2
1524 9202806 : case 0:
1525 : {
1526 9202806 : switch (i)
1527 : {
1528 542757 : case 0:
1529 542757 : return 4.*dzeta0dxi*dzeta0dxi;
1530 :
1531 542757 : case 1:
1532 542757 : return 4.*dzeta1dxi*dzeta1dxi;
1533 :
1534 542757 : case 2:
1535 542757 : return 4.*dzeta2dxi*dzeta2dxi;
1536 :
1537 542757 : case 3:
1538 542757 : return 8.*dzeta0dxi*dzeta1dxi;
1539 :
1540 542757 : case 4:
1541 542757 : return 8.*dzeta1dxi*dzeta2dxi;
1542 :
1543 542757 : case 5:
1544 542757 : return 8.*dzeta0dxi*dzeta2dxi;
1545 :
1546 0 : default:
1547 0 : libmesh_error_msg("Invalid shape function index i = " << i);
1548 : }
1549 : }
1550 :
1551 : // d^2() / dxi deta
1552 9202806 : case 1:
1553 : {
1554 9202806 : switch (i)
1555 : {
1556 542757 : case 0:
1557 542757 : return 4.*dzeta0dxi*dzeta0deta;
1558 :
1559 542757 : case 1:
1560 542757 : return 4.*dzeta1dxi*dzeta1deta;
1561 :
1562 542757 : case 2:
1563 542757 : return 4.*dzeta2dxi*dzeta2deta;
1564 :
1565 542757 : case 3:
1566 542757 : return 4.*dzeta1deta*dzeta0dxi + 4.*dzeta0deta*dzeta1dxi;
1567 :
1568 542757 : case 4:
1569 542757 : return 4.*dzeta2deta*dzeta1dxi + 4.*dzeta1deta*dzeta2dxi;
1570 :
1571 542757 : case 5:
1572 542757 : return 4.*dzeta2deta*dzeta0dxi + 4.*dzeta0deta*dzeta2dxi;
1573 :
1574 0 : default:
1575 0 : libmesh_error_msg("Invalid shape function index i = " << i);
1576 : }
1577 : }
1578 :
1579 : // d^2() / deta^2
1580 9202806 : case 2:
1581 : {
1582 9202806 : switch (i)
1583 : {
1584 542757 : case 0:
1585 542757 : return 4.*dzeta0deta*dzeta0deta;
1586 :
1587 542757 : case 1:
1588 542757 : return 4.*dzeta1deta*dzeta1deta;
1589 :
1590 542757 : case 2:
1591 542757 : return 4.*dzeta2deta*dzeta2deta;
1592 :
1593 542757 : case 3:
1594 542757 : return 8.*dzeta0deta*dzeta1deta;
1595 :
1596 542757 : case 4:
1597 542757 : return 8.*dzeta1deta*dzeta2deta;
1598 :
1599 542757 : case 5:
1600 542757 : return 8.*dzeta0deta*dzeta2deta;
1601 :
1602 0 : default:
1603 0 : libmesh_error_msg("Invalid shape function index i = " << i);
1604 : }
1605 : }
1606 :
1607 0 : default:
1608 0 : libmesh_error_msg("ERROR: Invalid derivative index j = " << j);
1609 : } // end switch (j)
1610 : } // end case TRI6+TRI7
1611 :
1612 0 : default:
1613 0 : libmesh_error_msg("ERROR: Unsupported 2D element type: " << Utility::enum_to_string(type));
1614 : }
1615 : } // end case SECOND
1616 :
1617 :
1618 :
1619 : // "cubic" (one cubic bubble) Lagrange shape functions on TRI7
1620 46564557 : case THIRD:
1621 : {
1622 46564557 : switch (type)
1623 : {
1624 29876727 : case TRI3:
1625 0 : libmesh_assert_msg(T == L2_LAGRANGE,
1626 : "High order on first order elements only supported for L2 families");
1627 : libmesh_fallthrough();
1628 16600923 : case TRI6:
1629 : case TRI7:
1630 : {
1631 46489389 : const Real zeta1 = p(0);
1632 46489389 : const Real zeta2 = p(1);
1633 : // const Real zeta0 = 1. - zeta1 - zeta2;
1634 :
1635 16612662 : const Real dzeta0dxi = -1.;
1636 16612662 : const Real dzeta1dxi = 1.;
1637 16612662 : const Real dzeta2dxi = 0.;
1638 : // const Real dbubbledxi = zeta2 * (1. - 2.*zeta1 - zeta2);
1639 46489389 : const Real d2bubbledxi2 = -2. * zeta2;
1640 :
1641 16612662 : const Real dzeta0deta = -1.;
1642 16612662 : const Real dzeta1deta = 0.;
1643 16612662 : const Real dzeta2deta = 1.;
1644 : // const Real dbubbledeta= zeta1 * (1. - zeta1 - 2.*zeta2);
1645 46489389 : const Real d2bubbledeta2 = -2. * zeta1;
1646 :
1647 46489389 : const Real d2bubbledxideta = (1. - 2.*zeta1 - 2.*zeta2);
1648 :
1649 16612662 : libmesh_assert_less (j, 3);
1650 :
1651 46489389 : switch (j)
1652 : {
1653 : // d^2() / dxi^2
1654 15496463 : case 0:
1655 : {
1656 15496463 : switch (i)
1657 : {
1658 2074934 : case 0:
1659 2074934 : return 4.*dzeta0dxi*dzeta0dxi + 3.*d2bubbledxi2;
1660 :
1661 2074934 : case 1:
1662 2074934 : return 4.*dzeta1dxi*dzeta1dxi + 3.*d2bubbledxi2;
1663 :
1664 2074934 : case 2:
1665 2074934 : return 4.*dzeta2dxi*dzeta2dxi + 3.*d2bubbledxi2;
1666 :
1667 2074934 : case 3:
1668 2074934 : return 8.*dzeta0dxi*dzeta1dxi - 12.*d2bubbledxi2;
1669 :
1670 2074934 : case 4:
1671 2074934 : return 8.*dzeta1dxi*dzeta2dxi - 12.*d2bubbledxi2;
1672 :
1673 2074934 : case 5:
1674 2074934 : return 8.*dzeta0dxi*dzeta2dxi - 12.*d2bubbledxi2;
1675 :
1676 3046859 : case 6:
1677 3046859 : return 27.*d2bubbledxi2;
1678 :
1679 0 : default:
1680 0 : libmesh_error_msg("Invalid shape function index i = " << i);
1681 : }
1682 : }
1683 :
1684 : // d^2() / dxi deta
1685 15496463 : case 1:
1686 : {
1687 15496463 : switch (i)
1688 : {
1689 2074934 : case 0:
1690 2074934 : return 4.*dzeta0dxi*dzeta0deta + 3.*d2bubbledxideta;
1691 :
1692 2074934 : case 1:
1693 2074934 : return 4.*dzeta1dxi*dzeta1deta + 3.*d2bubbledxideta;
1694 :
1695 2074934 : case 2:
1696 2074934 : return 4.*dzeta2dxi*dzeta2deta + 3.*d2bubbledxideta;
1697 :
1698 2074934 : case 3:
1699 2074934 : return 4.*dzeta1deta*dzeta0dxi + 4.*dzeta0deta*dzeta1dxi - 12.*d2bubbledxideta;
1700 :
1701 2074934 : case 4:
1702 2074934 : return 4.*dzeta2deta*dzeta1dxi + 4.*dzeta1deta*dzeta2dxi - 12.*d2bubbledxideta;
1703 :
1704 2074934 : case 5:
1705 2074934 : return 4.*dzeta2deta*dzeta0dxi + 4.*dzeta0deta*dzeta2dxi - 12.*d2bubbledxideta;
1706 :
1707 3046859 : case 6:
1708 3046859 : return 27.*d2bubbledxideta;
1709 :
1710 0 : default:
1711 0 : libmesh_error_msg("Invalid shape function index i = " << i);
1712 : }
1713 : }
1714 :
1715 : // d^2() / deta^2
1716 15496463 : case 2:
1717 : {
1718 15496463 : switch (i)
1719 : {
1720 2074934 : case 0:
1721 2074934 : return 4.*dzeta0deta*dzeta0deta + 3.*d2bubbledeta2;
1722 :
1723 2074934 : case 1:
1724 2074934 : return 4.*dzeta1deta*dzeta1deta + 3.*d2bubbledeta2;
1725 :
1726 2074934 : case 2:
1727 2074934 : return 4.*dzeta2deta*dzeta2deta + 3.*d2bubbledeta2;
1728 :
1729 2074934 : case 3:
1730 2074934 : return 8.*dzeta0deta*dzeta1deta - 12.*d2bubbledeta2;
1731 :
1732 2074934 : case 4:
1733 2074934 : return 8.*dzeta1deta*dzeta2deta - 12.*d2bubbledeta2;
1734 :
1735 2074934 : case 5:
1736 2074934 : return 8.*dzeta0deta*dzeta2deta - 12.*d2bubbledeta2;
1737 :
1738 3046859 : case 6:
1739 3046859 : return 27.*d2bubbledeta2;
1740 :
1741 0 : default:
1742 0 : libmesh_error_msg("Invalid shape function index i = " << i);
1743 : }
1744 : }
1745 :
1746 0 : default:
1747 0 : libmesh_error_msg("ERROR: Invalid derivative index j = " << j);
1748 : } // end switch (j)
1749 : } // end case TRI6+TRI7
1750 75168 : case QUAD16:
1751 : {
1752 75168 : const Real xi = p(0);
1753 75168 : const Real eta = p(1);
1754 :
1755 25056 : libmesh_assert_less (i, 16);
1756 :
1757 : static const unsigned int i0[] = {0,1,1,0, 2,3, 1,1, 3,2, 0,0, 2,3,3,2};
1758 : static const unsigned int i1[] = {0,0,1,1, 0,0, 2,3, 1,1, 3,2, 2,2,3,3};
1759 :
1760 75168 : switch (j)
1761 : {
1762 25056 : case 0: // d^2/dxi^2
1763 25056 : return (fe_lagrange_1D_cubic_shape_second_deriv(i0[i], 0, xi)*
1764 25056 : fe_lagrange_1D_cubic_shape(i1[i], eta));
1765 25056 : case 1: // d^2/dxi deta
1766 25056 : return (fe_lagrange_1D_cubic_shape_deriv(i0[i], 0, xi)*
1767 25056 : fe_lagrange_1D_cubic_shape_deriv(i1[i], 0, eta));
1768 25056 : case 2: // d^2/deta^2
1769 25056 : return (fe_lagrange_1D_cubic_shape(i0[i], xi)*
1770 25056 : fe_lagrange_1D_cubic_shape_second_deriv(i1[i], 0, eta));
1771 0 : default:
1772 0 : libmesh_error_msg("Invalid j = " << j);
1773 : }
1774 :
1775 : } // end case QUAD16
1776 :
1777 0 : default:
1778 0 : libmesh_error_msg("ERROR: Unsupported 2D element type: " << Utility::enum_to_string(type));
1779 : }
1780 : } // end case THIRD
1781 :
1782 : // unsupported order
1783 0 : default:
1784 0 : libmesh_error_msg("ERROR: Unsupported 2D FE order: " << order);
1785 :
1786 : } // end switch (order)
1787 :
1788 : #else // LIBMESH_DIM > 1
1789 : libmesh_ignore(type, order, i, j, p);
1790 : libmesh_not_implemented();
1791 : #endif
1792 : }
1793 :
1794 : #endif // LIBMESH_ENABLE_SECOND_DERIVATIVES
1795 :
1796 : } // anonymous namespace
|