libMesh
Loading...
Searching...
No Matches
fe_lagrange.C
Go to the documentation of this file.
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
20// Local includes
21#include "libmesh/dof_map.h"
22#include "libmesh/elem.h"
23#include "libmesh/enum_to_string.h"
24#include "libmesh/fe.h"
25#include "libmesh/fe_interface.h"
26#include "libmesh/fe_macro.h"
27#include "libmesh/remote_elem.h"
28#include "libmesh/threads.h"
29
30
31#ifdef LIBMESH_ENABLE_AMR
32#ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
33// to have the macro 'inf_fe_switch' available.
34#include "libmesh/fe_interface_macros.h"
35#include "libmesh/inf_fe.h"
36#endif
37#endif
38
39namespace libMesh
40{
41
42// global helper function
43void lagrange_nodal_soln(const Elem * elem,
44 const Order order,
45 const std::vector<Number> & elem_soln,
46 std::vector<Number> & nodal_soln,
47 const bool add_p_level)
48{
49 const unsigned int n_nodes = elem->n_nodes();
50 const ElemType type = elem->type();
51
52 const Order totalorder = order + add_p_level*elem->p_level();
53
54 nodal_soln.resize(n_nodes);
55
56
57
58 switch (totalorder)
59 {
60 // linear Lagrange shape functions
61 case FIRST:
62 {
63 switch (type)
64 {
65 case EDGE3:
66 {
67 libmesh_assert_equal_to (elem_soln.size(), 2);
68 libmesh_assert_equal_to (nodal_soln.size(), 3);
69
70 nodal_soln[0] = elem_soln[0];
71 nodal_soln[1] = elem_soln[1];
72 nodal_soln[2] = .5*(elem_soln[0] + elem_soln[1]);
73
74 return;
75 }
76
77 case EDGE4:
78 {
79 libmesh_assert_equal_to (elem_soln.size(), 2);
80 libmesh_assert_equal_to (nodal_soln.size(), 4);
81
82 nodal_soln[0] = elem_soln[0];
83 nodal_soln[1] = elem_soln[1];
84 nodal_soln[2] = (2.*elem_soln[0] + elem_soln[1])/3.;
85 nodal_soln[3] = (elem_soln[0] + 2.*elem_soln[1])/3.;
86
87 return;
88 }
89
90
91 case TRI7:
92 libmesh_assert_equal_to (nodal_soln.size(), 7);
93 nodal_soln[6] = (elem_soln[0] + elem_soln[1] + elem_soln[2])/3.;
94 libmesh_fallthrough();
95 case TRI6:
96 {
97 libmesh_assert (type == TRI7 || nodal_soln.size() == 6);
98 libmesh_assert_equal_to (elem_soln.size(), 3);
99
100 nodal_soln[0] = elem_soln[0];
101 nodal_soln[1] = elem_soln[1];
102 nodal_soln[2] = elem_soln[2];
103 nodal_soln[3] = .5*(elem_soln[0] + elem_soln[1]);
104 nodal_soln[4] = .5*(elem_soln[1] + elem_soln[2]);
105 nodal_soln[5] = .5*(elem_soln[2] + elem_soln[0]);
106
107 return;
108 }
109
110
111 case QUAD8:
112 case QUAD9:
113 {
114 libmesh_assert_equal_to (elem_soln.size(), 4);
115
116 if (type == QUAD8)
117 libmesh_assert_equal_to (nodal_soln.size(), 8);
118 else
119 libmesh_assert_equal_to (nodal_soln.size(), 9);
120
121
122 nodal_soln[0] = elem_soln[0];
123 nodal_soln[1] = elem_soln[1];
124 nodal_soln[2] = elem_soln[2];
125 nodal_soln[3] = elem_soln[3];
126 nodal_soln[4] = .5*(elem_soln[0] + elem_soln[1]);
127 nodal_soln[5] = .5*(elem_soln[1] + elem_soln[2]);
128 nodal_soln[6] = .5*(elem_soln[2] + elem_soln[3]);
129 nodal_soln[7] = .5*(elem_soln[3] + elem_soln[0]);
130
131 if (type == QUAD9)
132 nodal_soln[8] = .25*(elem_soln[0] + elem_soln[1] + elem_soln[2] + elem_soln[3]);
133
134 return;
135 }
136
137
138 case TET14:
139 libmesh_assert_equal_to (nodal_soln.size(), 14);
140 nodal_soln[10] = (elem_soln[0] + elem_soln[1] + elem_soln[2])/3.;
141 nodal_soln[11] = (elem_soln[0] + elem_soln[1] + elem_soln[3])/3.;
142 nodal_soln[12] = (elem_soln[1] + elem_soln[2] + elem_soln[3])/3.;
143 nodal_soln[13] = (elem_soln[0] + elem_soln[2] + elem_soln[3])/3.;
144 libmesh_fallthrough();
145 case TET10:
146 {
147 libmesh_assert_equal_to (elem_soln.size(), 4);
148 libmesh_assert (type == TET14 || nodal_soln.size() == 10);
149
150 nodal_soln[0] = elem_soln[0];
151 nodal_soln[1] = elem_soln[1];
152 nodal_soln[2] = elem_soln[2];
153 nodal_soln[3] = elem_soln[3];
154 nodal_soln[4] = .5*(elem_soln[0] + elem_soln[1]);
155 nodal_soln[5] = .5*(elem_soln[1] + elem_soln[2]);
156 nodal_soln[6] = .5*(elem_soln[2] + elem_soln[0]);
157 nodal_soln[7] = .5*(elem_soln[3] + elem_soln[0]);
158 nodal_soln[8] = .5*(elem_soln[3] + elem_soln[1]);
159 nodal_soln[9] = .5*(elem_soln[3] + elem_soln[2]);
160
161 return;
162 }
163
164
165 case HEX20:
166 case HEX27:
167 {
168 libmesh_assert_equal_to (elem_soln.size(), 8);
169
170 if (type == HEX20)
171 libmesh_assert_equal_to (nodal_soln.size(), 20);
172 else
173 libmesh_assert_equal_to (nodal_soln.size(), 27);
174
175 nodal_soln[0] = elem_soln[0];
176 nodal_soln[1] = elem_soln[1];
177 nodal_soln[2] = elem_soln[2];
178 nodal_soln[3] = elem_soln[3];
179 nodal_soln[4] = elem_soln[4];
180 nodal_soln[5] = elem_soln[5];
181 nodal_soln[6] = elem_soln[6];
182 nodal_soln[7] = elem_soln[7];
183 nodal_soln[8] = .5*(elem_soln[0] + elem_soln[1]);
184 nodal_soln[9] = .5*(elem_soln[1] + elem_soln[2]);
185 nodal_soln[10] = .5*(elem_soln[2] + elem_soln[3]);
186 nodal_soln[11] = .5*(elem_soln[3] + elem_soln[0]);
187 nodal_soln[12] = .5*(elem_soln[0] + elem_soln[4]);
188 nodal_soln[13] = .5*(elem_soln[1] + elem_soln[5]);
189 nodal_soln[14] = .5*(elem_soln[2] + elem_soln[6]);
190 nodal_soln[15] = .5*(elem_soln[3] + elem_soln[7]);
191 nodal_soln[16] = .5*(elem_soln[4] + elem_soln[5]);
192 nodal_soln[17] = .5*(elem_soln[5] + elem_soln[6]);
193 nodal_soln[18] = .5*(elem_soln[6] + elem_soln[7]);
194 nodal_soln[19] = .5*(elem_soln[4] + elem_soln[7]);
195
196 if (type == HEX27)
197 {
198 nodal_soln[20] = .25*(elem_soln[0] + elem_soln[1] + elem_soln[2] + elem_soln[3]);
199 nodal_soln[21] = .25*(elem_soln[0] + elem_soln[1] + elem_soln[4] + elem_soln[5]);
200 nodal_soln[22] = .25*(elem_soln[1] + elem_soln[2] + elem_soln[5] + elem_soln[6]);
201 nodal_soln[23] = .25*(elem_soln[2] + elem_soln[3] + elem_soln[6] + elem_soln[7]);
202 nodal_soln[24] = .25*(elem_soln[3] + elem_soln[0] + elem_soln[7] + elem_soln[4]);
203 nodal_soln[25] = .25*(elem_soln[4] + elem_soln[5] + elem_soln[6] + elem_soln[7]);
204
205 nodal_soln[26] = .125*(elem_soln[0] + elem_soln[1] + elem_soln[2] + elem_soln[3] +
206 elem_soln[4] + elem_soln[5] + elem_soln[6] + elem_soln[7]);
207 }
208
209 return;
210 }
211
212
213 case PRISM21:
214 nodal_soln[20] = (elem_soln[0] + elem_soln[1] + elem_soln[2] +
215 elem_soln[3] + elem_soln[4] + elem_soln[5])/Real(6);
216 libmesh_fallthrough();
217 case PRISM20:
218 if (type == PRISM20)
219 libmesh_assert_equal_to (nodal_soln.size(), 20);
220 nodal_soln[18] = (elem_soln[0] + elem_soln[1] + elem_soln[2])/Real(3);
221 nodal_soln[19] = (elem_soln[3] + elem_soln[4] + elem_soln[5])/Real(3);
222 libmesh_fallthrough();
223 case PRISM18:
224 if (type == PRISM18)
225 libmesh_assert_equal_to (nodal_soln.size(), 18);
226 nodal_soln[15] = .25*(elem_soln[0] + elem_soln[1] + elem_soln[4] + elem_soln[3]);
227 nodal_soln[16] = .25*(elem_soln[1] + elem_soln[2] + elem_soln[5] + elem_soln[4]);
228 nodal_soln[17] = .25*(elem_soln[2] + elem_soln[0] + elem_soln[3] + elem_soln[5]);
229 libmesh_fallthrough();
230 case PRISM15:
231 {
232 libmesh_assert_equal_to (elem_soln.size(), 6);
233
234 if (type == PRISM15)
235 libmesh_assert_equal_to (nodal_soln.size(), 15);
236
237 nodal_soln[0] = elem_soln[0];
238 nodal_soln[1] = elem_soln[1];
239 nodal_soln[2] = elem_soln[2];
240 nodal_soln[3] = elem_soln[3];
241 nodal_soln[4] = elem_soln[4];
242 nodal_soln[5] = elem_soln[5];
243 nodal_soln[6] = .5*(elem_soln[0] + elem_soln[1]);
244 nodal_soln[7] = .5*(elem_soln[1] + elem_soln[2]);
245 nodal_soln[8] = .5*(elem_soln[0] + elem_soln[2]);
246 nodal_soln[9] = .5*(elem_soln[0] + elem_soln[3]);
247 nodal_soln[10] = .5*(elem_soln[1] + elem_soln[4]);
248 nodal_soln[11] = .5*(elem_soln[2] + elem_soln[5]);
249 nodal_soln[12] = .5*(elem_soln[3] + elem_soln[4]);
250 nodal_soln[13] = .5*(elem_soln[4] + elem_soln[5]);
251 nodal_soln[14] = .5*(elem_soln[3] + elem_soln[5]);
252
253 return;
254 }
255
256 case PYRAMID18:
257 {
258 libmesh_assert_equal_to (nodal_soln.size(), 18);
259
260 nodal_soln[14] = (elem_soln[0] + elem_soln[1] + elem_soln[4])/Real(3);
261 nodal_soln[15] = (elem_soln[1] + elem_soln[2] + elem_soln[4])/Real(3);
262 nodal_soln[16] = (elem_soln[2] + elem_soln[3] + elem_soln[4])/Real(3);
263 nodal_soln[17] = (elem_soln[0] + elem_soln[3] + elem_soln[4])/Real(3);
264
265 libmesh_fallthrough();
266 }
267
268 case PYRAMID14:
269 {
270 if (type == PYRAMID14)
271 libmesh_assert_equal_to (nodal_soln.size(), 14);
272
273 nodal_soln[13] = .25*(elem_soln[0] + elem_soln[1] + elem_soln[2] + elem_soln[3]);
274
275 libmesh_fallthrough();
276 }
277
278 case PYRAMID13:
279 {
280 libmesh_assert_equal_to (elem_soln.size(), 5);
281
282 if (type == PYRAMID13)
283 libmesh_assert_equal_to (nodal_soln.size(), 13);
284
285 nodal_soln[0] = elem_soln[0];
286 nodal_soln[1] = elem_soln[1];
287 nodal_soln[2] = elem_soln[2];
288 nodal_soln[3] = elem_soln[3];
289 nodal_soln[4] = elem_soln[4];
290 nodal_soln[5] = .5*(elem_soln[0] + elem_soln[1]);
291 nodal_soln[6] = .5*(elem_soln[1] + elem_soln[2]);
292 nodal_soln[7] = .5*(elem_soln[2] + elem_soln[3]);
293 nodal_soln[8] = .5*(elem_soln[3] + elem_soln[0]);
294 nodal_soln[9] = .5*(elem_soln[0] + elem_soln[4]);
295 nodal_soln[10] = .5*(elem_soln[1] + elem_soln[4]);
296 nodal_soln[11] = .5*(elem_soln[2] + elem_soln[4]);
297 nodal_soln[12] = .5*(elem_soln[3] + elem_soln[4]);
298
299 return;
300 }
301 default:
302 {
303 // By default the element solution _is_ nodal,
304 // so just copy it.
305 nodal_soln = elem_soln;
306
307 return;
308 }
309 }
310 }
311
312 case SECOND:
313 {
314 switch (type)
315 {
316 case EDGE4:
317 {
318 libmesh_assert_equal_to (elem_soln.size(), 3);
319 libmesh_assert_equal_to (nodal_soln.size(), 4);
320
321 // Project quadratic solution onto cubic element nodes
322 nodal_soln[0] = elem_soln[0];
323 nodal_soln[1] = elem_soln[1];
324 nodal_soln[2] = (2.*elem_soln[0] - elem_soln[1] +
325 8.*elem_soln[2])/9.;
326 nodal_soln[3] = (-elem_soln[0] + 2.*elem_soln[1] +
327 8.*elem_soln[2])/9.;
328 return;
329 }
330
331 case TRI7:
332 {
333 libmesh_assert_equal_to (elem_soln.size(), 6);
334 libmesh_assert_equal_to (nodal_soln.size(), 7);
335
336 for (int i=0; i != 6; ++i)
337 nodal_soln[i] = elem_soln[i];
338
339 nodal_soln[6] = -1./9. * (elem_soln[0] + elem_soln[1] + elem_soln[2])
340 +4./9. * (elem_soln[3] + elem_soln[4] + elem_soln[5]);
341
342 return;
343 }
344
345 case TET14:
346 {
347 libmesh_assert_equal_to (elem_soln.size(), 10);
348 libmesh_assert_equal_to (nodal_soln.size(), 14);
349
350 for (int i=0; i != 10; ++i)
351 nodal_soln[i] = elem_soln[i];
352
353 nodal_soln[10] = -1./9. * (elem_soln[0] + elem_soln[1] + elem_soln[2])
354 +4./9. * (elem_soln[4] + elem_soln[5] + elem_soln[6]);
355 nodal_soln[11] = -1./9. * (elem_soln[0] + elem_soln[1] + elem_soln[3])
356 +4./9. * (elem_soln[4] + elem_soln[7] + elem_soln[8]);
357 nodal_soln[12] = -1./9. * (elem_soln[1] + elem_soln[2] + elem_soln[3])
358 +4./9. * (elem_soln[5] + elem_soln[8] + elem_soln[9]);
359 nodal_soln[13] = -1./9. * (elem_soln[0] + elem_soln[2] + elem_soln[3])
360 +4./9. * (elem_soln[6] + elem_soln[7] + elem_soln[9]);
361
362 return;
363 }
364
365 case PRISM21:
366 {
367 nodal_soln[20] = -1./9. * (elem_soln[9] + elem_soln[10] + elem_soln[11])
368 +4./9. * (elem_soln[15] + elem_soln[16] + elem_soln[17]);
369 libmesh_fallthrough();
370 }
371 case PRISM20:
372 {
373 libmesh_assert_equal_to (elem_soln.size(), 18);
374 if (type == PRISM20)
375 libmesh_assert_equal_to (nodal_soln.size(), 20);
376
377 for (int i=0; i != 18; ++i)
378 nodal_soln[i] = elem_soln[i];
379
380 nodal_soln[18] = -1./9. * (elem_soln[0] + elem_soln[1] + elem_soln[2])
381 +4./9. * (elem_soln[6] + elem_soln[7] + elem_soln[8]);
382 nodal_soln[19] = -1./9. * (elem_soln[3] + elem_soln[4] + elem_soln[5])
383 +4./9. * (elem_soln[12] + elem_soln[13] + elem_soln[14]);
384 return;
385 }
386
387 case PYRAMID18:
388 {
389 libmesh_assert_equal_to (elem_soln.size(), 14);
390 libmesh_assert_equal_to (nodal_soln.size(), 18);
391
392 for (int i=0; i != 14; ++i)
393 nodal_soln[i] = elem_soln[i];
394
395 nodal_soln[14] = -1./9. * (elem_soln[0] + elem_soln[1] + elem_soln[4])
396 +4./9. * (elem_soln[5] + elem_soln[9] + elem_soln[10]);
397 nodal_soln[15] = -1./9. * (elem_soln[1] + elem_soln[2] + elem_soln[4])
398 +4./9. * (elem_soln[6] + elem_soln[10] + elem_soln[11]);
399 nodal_soln[16] = -1./9. * (elem_soln[2] + elem_soln[3] + elem_soln[4])
400 +4./9. * (elem_soln[7] + elem_soln[11] + elem_soln[12]);
401 nodal_soln[17] = -1./9. * (elem_soln[0] + elem_soln[3] + elem_soln[4])
402 +4./9. * (elem_soln[8] + elem_soln[9] + elem_soln[12]);
403
404 return;
405 }
406
407 default:
408 {
409 // By default the element solution _is_ nodal, so just
410 // copy the portion relevant to the nodal solution.
411 // (this is the whole nodal solution for true Lagrange
412 // elements, but a smaller part for "L2 Lagrange"
413 libmesh_assert_less_equal(nodal_soln.size(), elem_soln.size());
414 for (const auto i : index_range(nodal_soln))
415 nodal_soln[i] = elem_soln[i];
416
417 return;
418 }
419 }
420 }
421
422
423
424
425 default:
426 {
427 // By default the element solution _is_ nodal, so just copy
428 // the portion relevant to the nodal solution. (this is the
429 // whole nodal solution for true Lagrange elements, but a
430 // smaller part for "L2 Lagrange"
431 libmesh_assert_less_equal(nodal_soln.size(), elem_soln.size());
432 for (const auto i : index_range(nodal_soln))
433 nodal_soln[i] = elem_soln[i];
434
435 return;
436 }
437 }
438}
439
440
441// Anonymous namespace for local helper functions
442namespace {
443unsigned int lagrange_n_dofs(const ElemType t, const Elem * e, const Order o)
444{
445 libmesh_assert(!e || e->type() == t);
446
447 switch (o)
448 {
449 // lagrange can only be constant on a single node
450 case CONSTANT:
451 {
452 switch (t)
453 {
454 case NODEELEM:
455 return 1;
456
457 default:
458 libmesh_error_msg("ERROR: Bad ElemType = " << Utility::enum_to_string(t) << " for " << Utility::enum_to_string(o) << " order approximation!");
459 }
460 }
461
462 // linear Lagrange shape functions
463 case FIRST:
464 {
465 switch (t)
466 {
467 case NODEELEM:
468 return 1;
469
470 case EDGE2:
471 case EDGE3:
472 case EDGE4:
473 return 2;
474
475 case TRI3:
476 case TRISHELL3:
477 case TRI3SUBDIVISION:
478 case TRI6:
479 case TRI7:
480 return 3;
481
482 case QUAD4:
483 case QUADSHELL4:
484 case QUAD8:
485 case QUADSHELL8:
486 case QUAD9:
487 case QUADSHELL9:
488 return 4;
489
490 case TET4:
491 case TET10:
492 case TET14:
493 return 4;
494
495 case HEX8:
496 case HEX20:
497 case HEX27:
498 return 8;
499
500 case PRISM6:
501 case PRISM15:
502 case PRISM18:
503 case PRISM20:
504 case PRISM21:
505 return 6;
506
507 case PYRAMID5:
508 case PYRAMID13:
509 case PYRAMID14:
510 case PYRAMID18:
511 return 5;
512
513 case INVALID_ELEM:
514 return 0;
515
516 case C0POLYGON:
517 case C0POLYHEDRON:
518 // Polygons and polyhedra require using newer FE APIs
519 if (!e)
520 libmesh_error_msg("Code (see stack trace) used an outdated FE function overload.\n"
521 "n_dofs() on a polygon or polyhedron is not defined by ElemType alone.");
522 return e->n_nodes();
523
524 default:
525 libmesh_error_msg("ERROR: Bad ElemType = " << Utility::enum_to_string(t) << " for " << Utility::enum_to_string(o) << " order approximation!");
526 }
527 }
528
529
530 // quadratic Lagrange shape functions
531 case SECOND:
532 {
533 switch (t)
534 {
535 case NODEELEM:
536 return 1;
537
538 case EDGE3:
539 return 3;
540
541 case TRI6:
542 case TRI7:
543 return 6;
544
545 case QUAD8:
546 case QUADSHELL8:
547 return 8;
548
549 case QUAD9:
550 case QUADSHELL9:
551 return 9;
552
553 case TET10:
554 case TET14:
555 return 10;
556
557 case HEX20:
558 return 20;
559
560 case HEX27:
561 return 27;
562
563 case PRISM15:
564 return 15;
565
566 case PRISM18:
567 case PRISM20:
568 case PRISM21:
569 return 18;
570
571 case PYRAMID13:
572 return 13;
573
574 case PYRAMID14:
575 case PYRAMID18:
576 return 14;
577
578 case INVALID_ELEM:
579 return 0;
580
581 default:
582 libmesh_error_msg("ERROR: Bad ElemType = " << Utility::enum_to_string(t) << " for " << Utility::enum_to_string(o) << " order approximation!");
583 }
584 }
585
586 case THIRD:
587 {
588 switch (t)
589 {
590 case NODEELEM:
591 return 1;
592
593 case EDGE4:
594 return 4;
595
596 case PRISM20:
597 return 20;
598
599 case PRISM21:
600 return 21;
601
602 case PYRAMID18:
603 return 18;
604
605 case TRI7:
606 return 7;
607
608 case TET14:
609 return 14;
610
611 case INVALID_ELEM:
612 return 0;
613
614 default:
615 libmesh_error_msg("ERROR: Bad ElemType = " << Utility::enum_to_string(t) << " for " << Utility::enum_to_string(o) << " order approximation!");
616 }
617 }
618
619 default:
620 libmesh_error_msg("ERROR: Invalid Order " << Utility::enum_to_string(o) << " selected for LAGRANGE FE family!");
621 }
622}
623
624
625
626unsigned int lagrange_n_dofs_at_node(const ElemType t,
627 const Order o,
628 const unsigned int n)
629{
630 switch (o)
631 {
632 // lagrange can only be constant on a single node
633 case CONSTANT:
634 {
635 switch (t)
636 {
637 case NODEELEM:
638 return 1;
639
640 default:
641 libmesh_error_msg("ERROR: Bad ElemType = " << Utility::enum_to_string(t) << " for " << Utility::enum_to_string(o) << " order approximation!");
642 }
643 }
644
645 // linear Lagrange shape functions
646 case FIRST:
647 {
648 switch (t)
649 {
650 case NODEELEM:
651 return 1;
652
653 case EDGE2:
654 case EDGE3:
655 case EDGE4:
656 {
657 switch (n)
658 {
659 case 0:
660 case 1:
661 return 1;
662
663 default:
664 return 0;
665 }
666 }
667
668 case TRI3:
669 case TRISHELL3:
670 case TRI3SUBDIVISION:
671 case TRI6:
672 case TRI7:
673 {
674 switch (n)
675 {
676 case 0:
677 case 1:
678 case 2:
679 return 1;
680
681 default:
682 return 0;
683 }
684 }
685
686 case QUAD4:
687 case QUADSHELL4:
688 case QUAD8:
689 case QUADSHELL8:
690 case QUAD9:
691 case QUADSHELL9:
692 {
693 switch (n)
694 {
695 case 0:
696 case 1:
697 case 2:
698 case 3:
699 return 1;
700
701 default:
702 return 0;
703 }
704 }
705
706 case C0POLYGON:
707 case C0POLYHEDRON:
708 return 1;
709
710
711 case TET4:
712 case TET10:
713 case TET14:
714 {
715 switch (n)
716 {
717 case 0:
718 case 1:
719 case 2:
720 case 3:
721 return 1;
722
723 default:
724 return 0;
725 }
726 }
727
728 case HEX8:
729 case HEX20:
730 case HEX27:
731 {
732 switch (n)
733 {
734 case 0:
735 case 1:
736 case 2:
737 case 3:
738 case 4:
739 case 5:
740 case 6:
741 case 7:
742 return 1;
743
744 default:
745 return 0;
746 }
747 }
748
749 case PRISM6:
750 case PRISM15:
751 case PRISM18:
752 case PRISM20:
753 case PRISM21:
754 {
755 switch (n)
756 {
757 case 0:
758 case 1:
759 case 2:
760 case 3:
761 case 4:
762 case 5:
763 return 1;
764
765 default:
766 return 0;
767 }
768 }
769
770 case PYRAMID5:
771 case PYRAMID13:
772 case PYRAMID14:
773 case PYRAMID18:
774 {
775 switch (n)
776 {
777 case 0:
778 case 1:
779 case 2:
780 case 3:
781 case 4:
782 return 1;
783
784 default:
785 return 0;
786 }
787 }
788
789 case INVALID_ELEM:
790 return 0;
791
792 default:
793 libmesh_error_msg("ERROR: Bad ElemType = " << Utility::enum_to_string(t) << " for " << Utility::enum_to_string(o) << " order approximation!");
794 }
795 }
796
797 // quadratic Lagrange shape functions
798 case SECOND:
799 {
800 switch (t)
801 {
802 // quadratic lagrange has one dof at each node
803 case NODEELEM:
804 case EDGE3:
805 case TRI6:
806 case QUAD8:
807 case QUADSHELL8:
808 case QUAD9:
809 case QUADSHELL9:
810 case TET10:
811 case HEX20:
812 case HEX27:
813 case PRISM15:
814 case PRISM18:
815 case PYRAMID13:
816 case PYRAMID14:
817 return 1;
818
819 case PRISM20:
820 case PRISM21:
821 return (n < 18);
822
823 case PYRAMID18:
824 return (n < 14);
825
826 case TRI7:
827 return (n < 6);
828
829 case TET14:
830 return (n < 10);
831
832 case INVALID_ELEM:
833 return 0;
834
835 default:
836 libmesh_error_msg("ERROR: Bad ElemType = " << Utility::enum_to_string(t) << " for " << Utility::enum_to_string(o) << " order approximation!");
837 }
838 }
839
840 case THIRD:
841 {
842 switch (t)
843 {
844 case NODEELEM:
845 case EDGE4:
846 case PRISM20:
847 case PRISM21:
848 case PYRAMID18:
849 case TRI7:
850 case TET14:
851 return 1;
852
853 case INVALID_ELEM:
854 return 0;
855
856 default:
857 libmesh_error_msg("ERROR: Bad ElemType = " << Utility::enum_to_string(t) << " for " << Utility::enum_to_string(o) << " order approximation!");
858 }
859 }
860
861 default:
862 libmesh_error_msg("Unsupported order: " << o );
863 }
864}
865
866
867
868unsigned int lagrange_n_dofs_at_node(const Elem & e,
869 const Order o,
870 const unsigned int n)
871{
872 return lagrange_n_dofs_at_node(e.type(), o, n);
873}
874
875
876#ifdef LIBMESH_ENABLE_AMR
877void lagrange_compute_constraints (DofConstraints & constraints,
878 DofMap & dof_map,
879 const unsigned int variable_number,
880 const Elem * elem,
881 const unsigned Dim)
882{
883 // Only constrain elements in 2,3D.
884 if (Dim == 1)
885 return;
886
887 libmesh_assert(elem);
888
889 // Only constrain active and ancestor elements
890 if (elem->subactive())
891 return;
892
893#ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
894 if (elem->infinite())
895 {
896 const FEType fe_t = dof_map.variable_type(variable_number);
897
898 // expand the infinite_compute_constraint in its template-arguments.
899 switch(Dim)
900 {
901 case 2:
902 {
903 inf_fe_family_mapping_switch(2, inf_compute_constraints (constraints, dof_map, variable_number, elem) , ,; break;);
904 break;
905 }
906 case 3:
907 {
908 inf_fe_family_mapping_switch(3, inf_compute_constraints (constraints, dof_map, variable_number, elem) , ,; break;);
909 break;
910 }
911 default:
912 libmesh_error_msg("Invalid dim = " << Dim);
913 }
914 return;
915 }
916#endif
917
918 const Variable & var = dof_map.variable(variable_number);
919 const FEType fe_type = var.type();
920 const bool add_p_level = fe_type.p_refinement;
921
922 // Pull objects out of the loop to reduce heap operations
923 std::vector<dof_id_type> my_dof_indices, parent_dof_indices;
924 std::unique_ptr<const Elem> my_side, parent_side;
925
926 // Look at the element faces. Check to see if we need to
927 // build constraints.
928 for (auto s : elem->side_index_range())
929 if (const Elem * const neigh = elem->neighbor_ptr(s);
930 neigh && neigh != remote_elem)
931 {
932 // constrain dofs shared between this element and ones coarser
933 if (neigh->level() < elem->level() &&
934 var.active_on_subdomain(neigh->subdomain_id()))
935 {
936 // than this element.
937 // Get pointers to the elements of interest and its parent.
938 const Elem * parent = elem->parent();
939
940 // This can't happen... Only level-0 elements have nullptr
941 // parents, and no level-0 elements can be at a higher
942 // level than their neighbors!
943 libmesh_assert(parent);
944
945 elem->build_side_ptr(my_side, s);
946 parent->build_side_ptr(parent_side, s);
947
948 // We have some elements with interior bubble function bases
949 // and lower-order sides. We need to only ask for the lower
950 // order in those cases.
951 FEType side_fe_type = fe_type;
952 int extra_order = 0;
953 if (my_side->default_order() < fe_type.order)
954 {
955 side_fe_type.order = my_side->default_order();
956 extra_order = (int)(side_fe_type.order) -
957 (int)(fe_type.order);
958 }
959
960 // This function gets called element-by-element, so there
961 // will be a lot of memory allocation going on. We can
962 // at least minimize this for the case of the dof indices
963 // by efficiently preallocating the requisite storage.
964 my_dof_indices.reserve (my_side->n_nodes());
965 parent_dof_indices.reserve (parent_side->n_nodes());
966
967 dof_map.dof_indices (my_side.get(), my_dof_indices,
968 variable_number, extra_order);
969 dof_map.dof_indices (parent_side.get(), parent_dof_indices,
970 variable_number, extra_order);
971
972 const unsigned int n_side_dofs =
973 FEInterface::n_dofs(side_fe_type, my_side.get());
974 const unsigned int n_parent_side_dofs =
975 FEInterface::n_dofs(side_fe_type, parent_side.get());
976 for (unsigned int my_dof=0; my_dof != n_side_dofs; my_dof++)
977 {
978 libmesh_assert_less (my_dof, my_side->n_nodes());
979
980 // My global dof index.
981 const dof_id_type my_dof_g = my_dof_indices[my_dof];
982
983 // Hunt for "constraining against myself" cases before
984 // we bother creating a constraint row
985 bool self_constraint = false;
986 for (unsigned int their_dof=0;
987 their_dof != n_parent_side_dofs; their_dof++)
988 {
989 libmesh_assert_less (their_dof, parent_side->n_nodes());
990
991 // Their global dof index.
992 const dof_id_type their_dof_g =
993 parent_dof_indices[their_dof];
994
995 if (their_dof_g == my_dof_g)
996 {
997 self_constraint = true;
998 break;
999 }
1000 }
1001
1002 if (self_constraint)
1003 continue;
1004
1005 DofConstraintRow * constraint_row;
1006
1007 // we may be running constraint methods concurrently
1008 // on multiple threads, so we need a lock to
1009 // ensure that this constraint is "ours"
1010 {
1011 Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
1012
1013 if (dof_map.is_constrained_dof(my_dof_g))
1014 continue;
1015
1016 constraint_row = &(constraints[my_dof_g]);
1017 libmesh_assert(constraint_row->empty());
1018 }
1019
1020 // The support point of the DOF
1021 const Point & support_point = my_side->point(my_dof);
1022
1023 // Figure out where my node lies on their reference element.
1024 const Point mapped_point = FEMap::inverse_map(Dim-1,
1025 parent_side.get(),
1026 support_point);
1027
1028 // Compute the parent's side shape function values.
1029 for (unsigned int their_dof=0;
1030 their_dof != n_parent_side_dofs; their_dof++)
1031 {
1032 libmesh_assert_less (their_dof, parent_side->n_nodes());
1033
1034 // Their global dof index.
1035 const dof_id_type their_dof_g =
1036 parent_dof_indices[their_dof];
1037
1038 const Real their_dof_value = FEInterface::shape(side_fe_type,
1039 parent_side.get(),
1040 their_dof,
1041 mapped_point);
1042
1043 // Only add non-zero and non-identity values
1044 // for Lagrange basis functions.
1045 if ((std::abs(their_dof_value) > 1.e-5) &&
1046 (std::abs(their_dof_value) < .999))
1047 {
1048 constraint_row->emplace(their_dof_g, their_dof_value);
1049 }
1050 #ifdef DEBUG
1051 // Protect for the case u_i = 0.999 u_j,
1052 // in which case i better equal j.
1053 else if (their_dof_value >= .999)
1054 libmesh_assert_equal_to (my_dof_g, their_dof_g);
1055 #endif
1056 }
1057 }
1058 }
1059
1060 if (elem->active() && add_p_level)
1061 {
1062 // p refinement constraints:
1063 // constrain dofs shared between
1064 // active elements and neighbors with
1065 // lower polynomial degrees
1066 const unsigned int min_p_level =
1067 neigh->min_p_level_by_neighbor(elem, elem->p_level());
1068 if (min_p_level < elem->p_level())
1069 libmesh_error_msg(
1070 "Mismatched p-refinement levels for LAGRANGE is not currently supported");
1071 }
1072 }
1073} // lagrange_compute_constraints()
1074#endif // #ifdef LIBMESH_ENABLE_AMR
1075
1076} // anonymous namespace
1077
1078
1079// Instantiate (side_) nodal_soln() function for every dimension
1082
1083
1084// Do full-specialization for every dimension, instead
1085// of explicit instantiation at the end of this function.
1086// This could be macro-ified.
1087template <> unsigned int FE<0,LAGRANGE>::n_dofs(const ElemType t, const Order o) { return lagrange_n_dofs(t, nullptr, o); }
1088template <> unsigned int FE<1,LAGRANGE>::n_dofs(const ElemType t, const Order o) { return lagrange_n_dofs(t, nullptr, o); }
1089template <> unsigned int FE<2,LAGRANGE>::n_dofs(const ElemType t, const Order o) { return lagrange_n_dofs(t, nullptr, o); }
1090template <> unsigned int FE<3,LAGRANGE>::n_dofs(const ElemType t, const Order o) { return lagrange_n_dofs(t, nullptr, o); }
1091
1092template <> unsigned int FE<0,LAGRANGE>::n_dofs(const Elem * e, const Order o) { return lagrange_n_dofs(e->type(), e, o); }
1093template <> unsigned int FE<1,LAGRANGE>::n_dofs(const Elem * e, const Order o) { return lagrange_n_dofs(e->type(), e, o); }
1094template <> unsigned int FE<2,LAGRANGE>::n_dofs(const Elem * e, const Order o) { return lagrange_n_dofs(e->type(), e, o); }
1095template <> unsigned int FE<3,LAGRANGE>::n_dofs(const Elem * e, const Order o) { return lagrange_n_dofs(e->type(), e, o); }
1096
1097
1098// Do full-specialization for every dimension, instead
1099// of explicit instantiation at the end of this function.
1100template <> unsigned int FE<0,LAGRANGE>::n_dofs_at_node(const ElemType t, const Order o, const unsigned int n) { return lagrange_n_dofs_at_node(t, o, n); }
1101template <> unsigned int FE<1,LAGRANGE>::n_dofs_at_node(const ElemType t, const Order o, const unsigned int n) { return lagrange_n_dofs_at_node(t, o, n); }
1102template <> unsigned int FE<2,LAGRANGE>::n_dofs_at_node(const ElemType t, const Order o, const unsigned int n) { return lagrange_n_dofs_at_node(t, o, n); }
1103template <> unsigned int FE<3,LAGRANGE>::n_dofs_at_node(const ElemType t, const Order o, const unsigned int n) { return lagrange_n_dofs_at_node(t, o, n); }
1104
1105template <> unsigned int FE<0,LAGRANGE>::n_dofs_at_node(const Elem & e, const Order o, const unsigned int n) { return lagrange_n_dofs_at_node(e, o, n); }
1106template <> unsigned int FE<1,LAGRANGE>::n_dofs_at_node(const Elem & e, const Order o, const unsigned int n) { return lagrange_n_dofs_at_node(e, o, n); }
1107template <> unsigned int FE<2,LAGRANGE>::n_dofs_at_node(const Elem & e, const Order o, const unsigned int n) { return lagrange_n_dofs_at_node(e, o, n); }
1108template <> unsigned int FE<3,LAGRANGE>::n_dofs_at_node(const Elem & e, const Order o, const unsigned int n) { return lagrange_n_dofs_at_node(e, o, n); }
1109
1110
1111// Lagrange elements have no dofs per element
1112// (just at the nodes)
1113template <> unsigned int FE<0,LAGRANGE>::n_dofs_per_elem(const ElemType, const Order) { return 0; }
1114template <> unsigned int FE<1,LAGRANGE>::n_dofs_per_elem(const ElemType, const Order) { return 0; }
1115template <> unsigned int FE<2,LAGRANGE>::n_dofs_per_elem(const ElemType, const Order) { return 0; }
1116template <> unsigned int FE<3,LAGRANGE>::n_dofs_per_elem(const ElemType, const Order) { return 0; }
1117
1118template <> unsigned int FE<0,LAGRANGE>::n_dofs_per_elem(const Elem &, const Order) { return 0; }
1119template <> unsigned int FE<1,LAGRANGE>::n_dofs_per_elem(const Elem &, const Order) { return 0; }
1120template <> unsigned int FE<2,LAGRANGE>::n_dofs_per_elem(const Elem &, const Order) { return 0; }
1121template <> unsigned int FE<3,LAGRANGE>::n_dofs_per_elem(const Elem &, const Order) { return 0; }
1122
1123// Lagrange FEMs are always C^0 continuous
1128
1129// Lagrange FEMs are not hierarchic
1130template <> bool FE<0,LAGRANGE>::is_hierarchic() const { return false; }
1131template <> bool FE<1,LAGRANGE>::is_hierarchic() const { return false; }
1132template <> bool FE<2,LAGRANGE>::is_hierarchic() const { return false; }
1133template <> bool FE<3,LAGRANGE>::is_hierarchic() const { return false; }
1134
1135// Lagrange FEM shapes do not need reinit (is this always true?)
1136template <> bool FE<0,LAGRANGE>::shapes_need_reinit() const { return false; }
1137template <> bool FE<1,LAGRANGE>::shapes_need_reinit() const { return false; }
1138template <> bool FE<2,LAGRANGE>::shapes_need_reinit() const { return false; }
1139template <> bool FE<3,LAGRANGE>::shapes_need_reinit() const { return false; }
1140
1141// Methods for computing Lagrange constraints. Note: we pass the
1142// dimension as the last argument to the anonymous helper function.
1143// Also note: we only need instantiations of this function for
1144// Dim==2 and 3.
1145#ifdef LIBMESH_ENABLE_AMR
1146template <>
1148 DofMap & dof_map,
1149 const unsigned int variable_number,
1150 const Elem * elem)
1151{ lagrange_compute_constraints(constraints, dof_map, variable_number, elem, /*Dim=*/2); }
1152
1153template <>
1155 DofMap & dof_map,
1156 const unsigned int variable_number,
1157 const Elem * elem)
1158{ lagrange_compute_constraints(constraints, dof_map, variable_number, elem, /*Dim=*/3); }
1159#endif // LIBMESH_ENABLE_AMR
1160
1161} // namespace libMesh
void ErrorVector unsigned int
The constraint matrix storage format.
Definition dof_map.h:112
This class handles the numbering of degrees of freedom on a mesh.
Definition dof_map.h:181
This is the base class from which all geometric element types are derived.
Definition elem.h:96
virtual unsigned int n_nodes() const =0
virtual ElemType type() const =0
unsigned int p_level() const
Definition elem.h:3246
static Real shape(const unsigned int dim, const FEType &fe_t, const ElemType t, const unsigned int i, const Point &p)
static unsigned int n_dofs(const unsigned int dim, const FEType &fe_t, const ElemType t)
static Point inverse_map(const unsigned int dim, const Elem *elem, const Point &p, const Real tolerance=TOLERANCE, const bool secure=true, const bool extra_checks=true)
Definition fe_map.C:1512
virtual bool is_hierarchic() const override
static unsigned int n_dofs_per_elem(const ElemType t, const Order o)
virtual FEContinuity get_continuity() const override
static void compute_constraints(DofConstraints &constraints, DofMap &dof_map, const unsigned int variable_number, const Elem *elem)
Computes the constraint matrix contributions (for non-conforming adapted meshes) corresponding to var...
static unsigned int n_dofs(const ElemType t, const Order o)
static unsigned int n_dofs_at_node(const ElemType t, const Order o, const unsigned int n)
virtual bool shapes_need_reinit() const override
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.
Definition threads.C:30
std::string enum_to_string(const T e)
The libMesh namespace provides an interface to certain functionality in the library.
LIBMESH_FE_NODAL_SOLN(BERNSTEIN, bernstein_nodal_soln)
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition int_range.h:153
ElemType
Defines an enum for geometric element types.
libmesh_assert(ctx)
void lagrange_nodal_soln(const Elem *elem, const Order order, const std::vector< Number > &elem_soln, std::vector< Number > &nodal_soln, bool add_p_level=true)
Helper functions for Lagrange-based basis functions.
Definition fe_lagrange.C:43
const RemoteElem * remote_elem
Definition remote_elem.C:57
std::map< dof_id_type, Real, std::less< dof_id_type >, Threads::scalable_allocator< std::pair< const dof_id_type, Real > > > DofConstraintRow
A row of the Dof constraint matrix.
Definition dof_map.h:100
uint8_t dof_id_type
Definition id_types.h:67
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
LIBMESH_FE_SIDE_NODAL_SOLN(HIERARCHIC_VEC)
const dof_id_type n_nodes
Definition tecplot_io.C:67