libMesh
Loading...
Searching...
No Matches
fe_base.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/fe.h"
22#include "libmesh/inf_fe.h"
23#include "libmesh/libmesh_logging.h"
24
25// For projection code:
26#include "libmesh/boundary_info.h"
27#include "libmesh/mesh_base.h"
28#include "libmesh/dense_matrix.h"
29#include "libmesh/dense_vector.h"
30#include "libmesh/dof_map.h"
31#include "libmesh/elem.h"
32#include "libmesh/fe_interface.h"
33#include "libmesh/int_range.h"
34#include "libmesh/numeric_vector.h"
35#include "libmesh/periodic_boundary_base.h"
36#include "libmesh/periodic_boundaries.h"
37#include "libmesh/quadrature.h"
38#include "libmesh/quadrature_gauss.h"
39#include "libmesh/tensor_value.h"
40#include "libmesh/threads.h"
41#include "libmesh/fe_type.h"
42#include "libmesh/enum_to_string.h"
43
44// C++ Includes
45#include <memory>
46
47// Anonymous namespace, for a helper function for periodic boundary
48// constraint calculations
49namespace
50{
51using namespace libMesh;
52
53#ifdef LIBMESH_ENABLE_PERIODIC
54
55// Find the "primary" element around a boundary point:
56const Elem * primary_boundary_point_neighbor(const Elem * elem,
57 const Point & p,
58 const BoundaryInfo & boundary_info,
59 const std::set<boundary_id_type> & boundary_ids)
60{
61 // If we don't find a better alternative, the user will have
62 // provided the primary element
63 const Elem * primary = elem;
64
65 // Container to catch boundary IDs passed back by BoundaryInfo.
66 std::vector<boundary_id_type> bc_ids;
67
68 // Pull object out of the loop to reduce heap operations
69 std::unique_ptr<const Elem> periodic_side;
70
71 std::set<const Elem *> point_neighbors;
72 elem->find_point_neighbors(p, point_neighbors);
73 for (const auto & pt_neighbor : point_neighbors)
74 {
75 // If this point neighbor isn't at least
76 // as coarse as the current primary elem, or if it is at
77 // the same level but has a lower id, then
78 // we won't defer to it.
79 if ((pt_neighbor->level() > primary->level()) ||
80 (pt_neighbor->level() == primary->level() &&
81 pt_neighbor->id() < primary->id()))
82 continue;
83
84 // Otherwise, we will defer to the point neighbor, but only if
85 // one of its sides is on a relevant boundary and that side
86 // contains this vertex
87 bool vertex_on_periodic_side = false;
88 for (auto ns : pt_neighbor->side_index_range())
89 {
90 boundary_info.boundary_ids (pt_neighbor, ns, bc_ids);
91
92 bool on_relevant_boundary = false;
93 for (const auto & id : boundary_ids)
94 if (std::find(bc_ids.begin(), bc_ids.end(), id) != bc_ids.end())
95 on_relevant_boundary = true;
96
97 if (!on_relevant_boundary)
98 continue;
99
100 pt_neighbor->build_side_ptr(periodic_side, ns);
101 if (!periodic_side->contains_point(p))
102 continue;
103
104 vertex_on_periodic_side = true;
105 break;
106 }
107
108 if (vertex_on_periodic_side)
109 primary = pt_neighbor;
110 }
111
112 return primary;
113}
114
115// Find the "primary" element around a boundary edge:
116const Elem * primary_boundary_edge_neighbor(const Elem * elem,
117 const Point & p1,
118 const Point & p2,
119 const BoundaryInfo & boundary_info,
120 const std::set<boundary_id_type> & boundary_ids)
121{
122 // If we don't find a better alternative, the user will have
123 // provided the primary element
124 const Elem * primary = elem;
125
126 std::set<const Elem *> edge_neighbors;
127 elem->find_edge_neighbors(p1, p2, edge_neighbors);
128
129 // Container to catch boundary IDs handed back by BoundaryInfo
130 std::vector<boundary_id_type> bc_ids;
131
132 // Pull object out of the loop to reduce heap operations
133 std::unique_ptr<const Elem> periodic_side;
134
135 for (const auto & e_neighbor : edge_neighbors)
136 {
137 // If this edge neighbor isn't at least
138 // as coarse as the current primary elem, or if it is at
139 // the same level but has a lower id, then
140 // we won't defer to it.
141 if ((e_neighbor->level() > primary->level()) ||
142 (e_neighbor->level() == primary->level() &&
143 e_neighbor->id() < primary->id()))
144 continue;
145
146 // Otherwise, we will defer to the edge neighbor, but only if
147 // one of its sides is on this periodic boundary and that
148 // side contains this edge
149 bool vertex_on_periodic_side = false;
150 for (auto ns : e_neighbor->side_index_range())
151 {
152 boundary_info.boundary_ids (e_neighbor, ns, bc_ids);
154 bool on_relevant_boundary = false;
155 for (const auto & id : boundary_ids)
156 if (std::find(bc_ids.begin(), bc_ids.end(), id) != bc_ids.end())
157 on_relevant_boundary = true;
158
159 if (!on_relevant_boundary)
160 continue;
161
162 e_neighbor->build_side_ptr(periodic_side, ns);
163 if (!(periodic_side->contains_point(p1) &&
164 periodic_side->contains_point(p2)))
165 continue;
166
167 vertex_on_periodic_side = true;
168 break;
169 }
170
171 if (vertex_on_periodic_side)
172 primary = e_neighbor;
173 }
174
175 return primary;
176}
177
178#endif // LIBMESH_ENABLE_PERIODIC
179
180}
181
182namespace libMesh
183{
184
185
186
187// ------------------------------------------------------------
188// FEBase class members
189template <>
190std::unique_ptr<FEGenericBase<Real>>
191FEGenericBase<Real>::build (const unsigned int dim,
192 const FEType & fet)
194 switch (dim)
195 {
196 // 0D
197 case 0:
198 {
199 switch (fet.family)
200 {
201 case CLOUGH:
202 return std::make_unique<FE<0,CLOUGH>>(fet);
203
204 case HERMITE:
205 return std::make_unique<FE<0,HERMITE>>(fet);
206
207 case LAGRANGE:
208 return std::make_unique<FE<0,LAGRANGE>>(fet);
209
210 case L2_LAGRANGE:
211 return std::make_unique<FE<0,L2_LAGRANGE>>(fet);
212
213 case L2_LAGRANGE_GLL:
214 return std::make_unique<FE<0,L2_LAGRANGE_GLL>>(fet);
215
216 case LAGRANGE_GLL:
217 return std::make_unique<FE<0,LAGRANGE_GLL>>(fet);
218
219 case HIERARCHIC:
220 return std::make_unique<FE<0,HIERARCHIC>>(fet);
221
222 case L2_HIERARCHIC:
223 return std::make_unique<FE<0,L2_HIERARCHIC>>(fet);
224
225 case SIDE_HIERARCHIC:
226 return std::make_unique<FE<0,SIDE_HIERARCHIC>>(fet);
227
228 case MONOMIAL:
229 return std::make_unique<FE<0,MONOMIAL>>(fet);
230
231#ifdef LIBMESH_ENABLE_HIGHER_ORDER_SHAPES
232 case SZABAB:
233 return std::make_unique<FE<0,SZABAB>>(fet);
234
235 case BERNSTEIN:
236 return std::make_unique<FE<0,BERNSTEIN>>(fet);
237
239 return std::make_unique<FE<0,RATIONAL_BERNSTEIN>>(fet);
240#endif
241
242 case XYZ:
243 return std::make_unique<FEXYZ<0>>(fet);
244
245 case SCALAR:
246 return std::make_unique<FEScalar<0>>(fet);
247
248 default:
249 libmesh_error_msg("ERROR: Bad FEType.family == " << Utility::enum_to_string(fet.family));
250 }
251 }
252 // 1D
253 case 1:
254 {
255 switch (fet.family)
256 {
257 case CLOUGH:
258 return std::make_unique<FE<1,CLOUGH>>(fet);
259
260 case HERMITE:
261 return std::make_unique<FE<1,HERMITE>>(fet);
262
263 case LAGRANGE:
264 return std::make_unique<FE<1,LAGRANGE>>(fet);
265
266 case L2_LAGRANGE:
267 return std::make_unique<FE<1,L2_LAGRANGE>>(fet);
268
269 case L2_LAGRANGE_GLL:
270 return std::make_unique<FE<1,L2_LAGRANGE_GLL>>(fet);
271
272 case LAGRANGE_GLL:
273 return std::make_unique<FE<1,LAGRANGE_GLL>>(fet);
274
275 case HIERARCHIC:
276 return std::make_unique<FE<1,HIERARCHIC>>(fet);
277
278 case L2_HIERARCHIC:
279 return std::make_unique<FE<1,L2_HIERARCHIC>>(fet);
280
281 case SIDE_HIERARCHIC:
282 return std::make_unique<FE<1,SIDE_HIERARCHIC>>(fet);
283
284 case MONOMIAL:
285 return std::make_unique<FE<1,MONOMIAL>>(fet);
286
287#ifdef LIBMESH_ENABLE_HIGHER_ORDER_SHAPES
288 case SZABAB:
289 return std::make_unique<FE<1,SZABAB>>(fet);
290
291 case BERNSTEIN:
292 return std::make_unique<FE<1,BERNSTEIN>>(fet);
293
295 return std::make_unique<FE<1,RATIONAL_BERNSTEIN>>(fet);
296#endif
297
298 case XYZ:
299 return std::make_unique<FEXYZ<1>>(fet);
300
301 case SCALAR:
302 return std::make_unique<FEScalar<1>>(fet);
303
304 default:
305 libmesh_error_msg("ERROR: Bad FEType.family == " << Utility::enum_to_string(fet.family));
306 }
307 }
308
309
310 // 2D
311 case 2:
312 {
313 switch (fet.family)
314 {
315 case CLOUGH:
316 return std::make_unique<FE<2,CLOUGH>>(fet);
317
318 case HERMITE:
319 return std::make_unique<FE<2,HERMITE>>(fet);
320
321 case LAGRANGE:
322 return std::make_unique<FE<2,LAGRANGE>>(fet);
323
324 case L2_LAGRANGE:
325 return std::make_unique<FE<2,L2_LAGRANGE>>(fet);
326
327 case L2_LAGRANGE_GLL:
328 return std::make_unique<FE<2,L2_LAGRANGE_GLL>>(fet);
329
330 case LAGRANGE_GLL:
331 return std::make_unique<FE<2,LAGRANGE_GLL>>(fet);
332
333 case HIERARCHIC:
334 return std::make_unique<FE<2,HIERARCHIC>>(fet);
335
336 case L2_HIERARCHIC:
337 return std::make_unique<FE<2,L2_HIERARCHIC>>(fet);
338
339 case SIDE_HIERARCHIC:
340 return std::make_unique<FE<2,SIDE_HIERARCHIC>>(fet);
341
342 case MONOMIAL:
343 return std::make_unique<FE<2,MONOMIAL>>(fet);
344
345#ifdef LIBMESH_ENABLE_HIGHER_ORDER_SHAPES
346 case SZABAB:
347 return std::make_unique<FE<2,SZABAB>>(fet);
348
349 case BERNSTEIN:
350 return std::make_unique<FE<2,BERNSTEIN>>(fet);
351
353 return std::make_unique<FE<2,RATIONAL_BERNSTEIN>>(fet);
354#endif
355
356 case XYZ:
357 return std::make_unique<FEXYZ<2>>(fet);
358
359 case SCALAR:
360 return std::make_unique<FEScalar<2>>(fet);
361
362 case SUBDIVISION:
363 return std::make_unique<FESubdivision>(fet);
364
365 default:
366 libmesh_error_msg("ERROR: Bad FEType.family == " << Utility::enum_to_string(fet.family));
367 }
368 }
369
370
371 // 3D
372 case 3:
373 {
374 switch (fet.family)
375 {
376 case CLOUGH:
377 libmesh_error_msg("ERROR: Clough-Tocher elements currently only support 1D and 2D");
378
379 case HERMITE:
380 return std::make_unique<FE<3,HERMITE>>(fet);
381
382 case LAGRANGE:
383 return std::make_unique<FE<3,LAGRANGE>>(fet);
384
385 case L2_LAGRANGE:
386 return std::make_unique<FE<3,L2_LAGRANGE>>(fet);
387
388 case L2_LAGRANGE_GLL:
389 return std::make_unique<FE<3,L2_LAGRANGE_GLL>>(fet);
390
391 case LAGRANGE_GLL:
392 return std::make_unique<FE<3,LAGRANGE_GLL>>(fet);
393
394 case HIERARCHIC:
395 return std::make_unique<FE<3,HIERARCHIC>>(fet);
396
397 case L2_HIERARCHIC:
398 return std::make_unique<FE<3,L2_HIERARCHIC>>(fet);
399
400 case SIDE_HIERARCHIC:
401 return std::make_unique<FE<3,SIDE_HIERARCHIC>>(fet);
402
403 case MONOMIAL:
404 return std::make_unique<FE<3,MONOMIAL>>(fet);
405
406#ifdef LIBMESH_ENABLE_HIGHER_ORDER_SHAPES
407 case SZABAB:
408 return std::make_unique<FE<3,SZABAB>>(fet);
409
410 case BERNSTEIN:
411 return std::make_unique<FE<3,BERNSTEIN>>(fet);
412
414 return std::make_unique<FE<3,RATIONAL_BERNSTEIN>>(fet);
415#endif
416
417 case XYZ:
418 return std::make_unique<FEXYZ<3>>(fet);
419
420 case SCALAR:
421 return std::make_unique<FEScalar<3>>(fet);
422
423 default:
424 libmesh_error_msg("ERROR: Bad FEType.family == " << Utility::enum_to_string(fet.family));
425 }
426 }
427
428 default:
429 libmesh_error_msg("Invalid dimension dim = " << dim);
430 }
431}
432
433
434
435template <>
436std::unique_ptr<FEGenericBase<RealGradient>>
438 const FEType & fet)
439{
440 switch (dim)
441 {
442 // 0D
443 case 0:
444 {
445 switch (fet.family)
446 {
447 case HIERARCHIC_VEC:
448 return std::make_unique<FEHierarchicVec<0>>(fet);
449
451 return std::make_unique<FEL2HierarchicVec<0>>(fet);
452
453 case LAGRANGE_VEC:
454 return std::make_unique<FELagrangeVec<0>>(fet);
455
456 case L2_LAGRANGE_VEC:
457 return std::make_unique<FEL2LagrangeVec<0>>(fet);
458
459 case MONOMIAL_VEC:
460 return std::make_unique<FEMonomialVec<0>>(fet);
461
462 default:
463 libmesh_error_msg("ERROR: Bad FEType.family == " << Utility::enum_to_string(fet.family));
464 }
465 }
466 case 1:
467 {
468 switch (fet.family)
469 {
470 case HIERARCHIC_VEC:
471 return std::make_unique<FEHierarchicVec<1>>(fet);
472
474 return std::make_unique<FEL2HierarchicVec<1>>(fet);
475
476 case LAGRANGE_VEC:
477 return std::make_unique<FELagrangeVec<1>>(fet);
478
479 case L2_LAGRANGE_VEC:
480 return std::make_unique<FEL2LagrangeVec<1>>(fet);
481
482 case MONOMIAL_VEC:
483 return std::make_unique<FEMonomialVec<1>>(fet);
484
485 default:
486 libmesh_error_msg("ERROR: Bad FEType.family == " << Utility::enum_to_string(fet.family));
487 }
488 }
489 case 2:
490 {
491 switch (fet.family)
492 {
493 case HIERARCHIC_VEC:
494 return std::make_unique<FEHierarchicVec<2>>(fet);
495
497 return std::make_unique<FEL2HierarchicVec<2>>(fet);
498
499 case LAGRANGE_VEC:
500 return std::make_unique<FELagrangeVec<2>>(fet);
501
502 case L2_LAGRANGE_VEC:
503 return std::make_unique<FEL2LagrangeVec<2>>(fet);
504
505 case MONOMIAL_VEC:
506 return std::make_unique<FEMonomialVec<2>>(fet);
507
508 case NEDELEC_ONE:
509 return std::make_unique<FENedelecOne<2>>(fet);
510
511 case RAVIART_THOMAS:
512 return std::make_unique<FERaviartThomas<2>>(fet);
513
515 return std::make_unique<FEL2RaviartThomas<2>>(fet);
516
517 default:
518 libmesh_error_msg("ERROR: Bad FEType.family == " << Utility::enum_to_string(fet.family));
519 }
520 }
521 case 3:
522 {
523 switch (fet.family)
524 {
525 case HIERARCHIC_VEC:
526 return std::make_unique<FEHierarchicVec<3>>(fet);
527
529 return std::make_unique<FEL2HierarchicVec<3>>(fet);
530
531 case LAGRANGE_VEC:
532 return std::make_unique<FELagrangeVec<3>>(fet);
533
534 case L2_LAGRANGE_VEC:
535 return std::make_unique<FEL2LagrangeVec<3>>(fet);
536
537 case MONOMIAL_VEC:
538 return std::make_unique<FEMonomialVec<3>>(fet);
539
540 case NEDELEC_ONE:
541 return std::make_unique<FENedelecOne<3>>(fet);
542
543 case RAVIART_THOMAS:
544 return std::make_unique<FERaviartThomas<3>>(fet);
545
547 return std::make_unique<FEL2RaviartThomas<3>>(fet);
548
549 default:
550 libmesh_error_msg("ERROR: Bad FEType.family == " << Utility::enum_to_string(fet.family));
551 }
552 }
553
554 default:
555 libmesh_error_msg("Invalid dimension dim = " << dim);
556 } // switch(dim)
559
560
561
562
563
565#ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
566
567
568template <>
569std::unique_ptr<FEGenericBase<Real>>
571 const FEType & fet)
572{
573 switch (dim)
575
576 // 1D
577 case 1:
578 {
579 switch (fet.radial_family)
580 {
581 case INFINITE_MAP:
582 libmesh_error_msg("ERROR: Can't build an infinite element with FEFamily = " << Utility::enum_to_string(fet.radial_family));
583
584 case JACOBI_20_00:
585 {
586 switch (fet.inf_map)
587 {
588 case CARTESIAN:
589 return std::make_unique<InfFE<1,JACOBI_20_00,CARTESIAN>>(fet);
590
591 default:
592 libmesh_error_msg("ERROR: Can't build an infinite element with InfMapType = " << Utility::enum_to_string(fet.inf_map));
593 }
594 }
595
596 case JACOBI_30_00:
597 {
598 switch (fet.inf_map)
599 {
601 return std::make_unique<InfFE<1,JACOBI_30_00,CARTESIAN>>(fet);
602
603 default:
604 libmesh_error_msg("ERROR: Can't build an infinite element with InfMapType = " << Utility::enum_to_string(fet.inf_map));
605 }
606 }
607
608 case LEGENDRE:
609 {
610 switch (fet.inf_map)
611 {
612 case CARTESIAN:
613 return std::make_unique<InfFE<1,LEGENDRE,CARTESIAN>>(fet);
614
615 default:
616 libmesh_error_msg("ERROR: Can't build an infinite element with InfMapType = " << Utility::enum_to_string(fet.inf_map));
617 }
618 }
619
620 case LAGRANGE:
621 {
622 switch (fet.inf_map)
623 {
624 case CARTESIAN:
625 return std::make_unique<InfFE<1,LAGRANGE,CARTESIAN>>(fet);
626
627 default:
628 libmesh_error_msg("ERROR: Can't build an infinite element with InfMapType = " << Utility::enum_to_string(fet.inf_map));
629 }
630 }
631
632 default:
633 libmesh_error_msg("ERROR: Bad FEType.radial_family= " << Utility::enum_to_string(fet.radial_family));
634 }
635 }
636
637
638
639
640 // 2D
641 case 2:
642 {
643 switch (fet.radial_family)
644 {
645 case INFINITE_MAP:
646 libmesh_error_msg("ERROR: Can't build an infinite element with FEFamily = " << Utility::enum_to_string(fet.radial_family));
647
648 case JACOBI_20_00:
649 {
650 switch (fet.inf_map)
651 {
652 case CARTESIAN:
653 return std::make_unique<InfFE<2,JACOBI_20_00,CARTESIAN>>(fet);
654
655 default:
656 libmesh_error_msg("ERROR: Don't build an infinite element with InfMapType = " << Utility::enum_to_string(fet.inf_map));
657 }
658 }
659
660 case JACOBI_30_00:
661 {
662 switch (fet.inf_map)
663 {
664 case CARTESIAN:
665 return std::make_unique<InfFE<2,JACOBI_30_00,CARTESIAN>>(fet);
666
667 default:
668 libmesh_error_msg("ERROR: Don't build an infinite element with InfMapType = " << Utility::enum_to_string(fet.inf_map));
669 }
670 }
671
672 case LEGENDRE:
673 {
674 switch (fet.inf_map)
675 {
676 case CARTESIAN:
677 return std::make_unique<InfFE<2,LEGENDRE,CARTESIAN>>(fet);
678
679 default:
680 libmesh_error_msg("ERROR: Don't build an infinite element with InfMapType = " << Utility::enum_to_string(fet.inf_map));
681 }
682 }
683
684 case LAGRANGE:
685 {
686 switch (fet.inf_map)
687 {
688 case CARTESIAN:
689 return std::make_unique<InfFE<2,LAGRANGE,CARTESIAN>>(fet);
690
691 default:
692 libmesh_error_msg("ERROR: Don't build an infinite element with InfMapType = " << Utility::enum_to_string(fet.inf_map));
693 }
694 }
695
696 default:
697 libmesh_error_msg("ERROR: Bad FEType.radial_family= " << Utility::enum_to_string(fet.radial_family));
698 }
699 }
700
701
702
703
704 // 3D
705 case 3:
706 {
707 switch (fet.radial_family)
708 {
709 case INFINITE_MAP:
710 libmesh_error_msg("ERROR: Don't build an infinite element with FEFamily = " << Utility::enum_to_string(fet.radial_family));
711
712 case JACOBI_20_00:
713 {
714 switch (fet.inf_map)
715 {
716 case CARTESIAN:
717 return std::make_unique<InfFE<3,JACOBI_20_00,CARTESIAN>>(fet);
718
719 default:
720 libmesh_error_msg("ERROR: Don't build an infinite element with InfMapType = " << Utility::enum_to_string(fet.inf_map));
721 }
722 }
723
724 case JACOBI_30_00:
725 {
726 switch (fet.inf_map)
727 {
728 case CARTESIAN:
729 return std::make_unique<InfFE<3,JACOBI_30_00,CARTESIAN>>(fet);
730
731 default:
732 libmesh_error_msg("ERROR: Don't build an infinite element with InfMapType = " << Utility::enum_to_string(fet.inf_map));
733 }
734 }
735
736 case LEGENDRE:
737 {
738 switch (fet.inf_map)
739 {
740 case CARTESIAN:
741 return std::make_unique<InfFE<3,LEGENDRE,CARTESIAN>>(fet);
742
743 default:
744 libmesh_error_msg("ERROR: Don't build an infinite element with InfMapType = " << Utility::enum_to_string(fet.inf_map));
745 }
746 }
747
748 case LAGRANGE:
749 {
750 switch (fet.inf_map)
751 {
752 case CARTESIAN:
753 return std::make_unique<InfFE<3,LAGRANGE,CARTESIAN>>(fet);
754
755 default:
756 libmesh_error_msg("ERROR: Don't build an infinite element with InfMapType = " << Utility::enum_to_string(fet.inf_map));
757 }
758 }
759
760 default:
761 libmesh_error_msg("ERROR: Bad FEType.radial_family= " << Utility::enum_to_string(fet.radial_family));
762 }
763 }
764
765 default:
766 libmesh_error_msg("Invalid dimension dim = " << dim);
767 }
768}
769
770
771
772template <>
773std::unique_ptr<FEGenericBase<RealGradient>>
775 const FEType & )
776{
777 // No vector types defined... YET.
778 libmesh_not_implemented();
779 return std::unique_ptr<FEVectorBase>();
780}
781
782#endif // ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
783
784
785template <typename OutputType>
787 const std::vector<Point> & qp)
788{
789 //-------------------------------------------------------------------------
790 // Compute the shape function values (and derivatives)
791 // at the Quadrature points. Note that the actual values
792 // have already been computed via init_shape_functions
793
794 // Start logging the shape function computation
795 LOG_ONE_ENTITY_SCOPE("compute_shape_functions()", "FE");
796
797 this->determine_calculations();
798
799 if (calculate_phi)
800 this->_fe_trans->map_phi(this->dim, elem, qp, (*this), this->phi, this->_add_p_level_in_reinit);
801
802 if (calculate_dphi)
803 this->_fe_trans->map_dphi(this->dim, elem, qp, (*this), this->dphi,
804 this->dphidx, this->dphidy, this->dphidz);
805
806#ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
807 if (calculate_d2phi)
808 this->_fe_trans->map_d2phi(this->dim, qp, (*this), this->d2phi,
809 this->d2phidx2, this->d2phidxdy, this->d2phidxdz,
810 this->d2phidy2, this->d2phidydz, this->d2phidz2);
811#endif //LIBMESH_ENABLE_SECOND_DERIVATIVES
812
813 // Only compute curl for vector-valued elements
814 if (calculate_curl_phi && TypesEqual<OutputType,RealGradient>::value)
815 this->_fe_trans->map_curl(this->dim, elem, qp, (*this), this->curl_phi);
816
817 // Only compute div for vector-valued elements
818 if (calculate_div_phi && TypesEqual<OutputType,RealGradient>::value)
819 this->_fe_trans->map_div(this->dim, elem, qp, (*this), this->div_phi);
820}
821
822
823// Here, we rely on the input \p phi_vals for accurate integration of the mass matrix.
824// This is because in contact, we often have customized qrule for mortar segments
825// due to deformation of the element, and the size of \p phi_vals for the secondary
826// element changes accordingly.
827template <>
828void FEGenericBase<Real>::compute_dual_shape_coeffs (const std::vector<Real> & JxW, const std::vector<std::vector<OutputShape>> & phi_vals)
829{
830 // Start logging the dual coeff computation
831 LOG_SCOPE("compute_dual_shape_coeffs()", "FE");
832
833 const unsigned int sz=phi_vals.size();
834 libmesh_error_msg_if(!sz, "ERROR: cannot compute dual shape coefficients with empty phi values");
835
836 //compute dual basis coefficient (dual_coeff)
837 dual_coeff.resize(sz, sz);
838 DenseMatrix<Real> A(sz, sz), D(sz, sz);
839
840 for (const auto i : index_range(phi_vals))
841 for (const auto qp : index_range(phi_vals[i]))
842 {
843 D(i,i) += JxW[qp]*phi_vals[i][qp];
844 for (const auto j : index_range(phi_vals))
845 A(i,j) += JxW[qp]*phi_vals[i][qp]*phi_vals[j][qp];
846 }
847
848 // The integral positivity condition on the dual basis (Popp, Wohlmuth, Gee and Wall, SIAM J. Sci.
849 // Comput. 34(4):B421-B446, 2012, Eq. (4.2)) fails on QUAD8 and TRI6: D(k,k) = \int N_k is -1/3 at a
850 // QUAD8 corner and exactly 0 at a TRI6 vertex (their Eqs. (4.3) and (4.4)), the latter leaving those
851 // dual shape functions identically zero. Biorthogonalize instead against the locally quadratic
852 // transformed basis Ntilde = T N of their Sec. 4.4.1, in which each vertex absorbs a fraction alpha
853 // of its adjacent mid-edge shapes. That replaces D by T^-1 diag(T d), which for this T is the sparse
854 // update below. alpha = 1/5 is recommended there, and makes the weights strictly positive (QUAD8
855 // 1/5 and 4/5, TRI6 1/15 and 1/10) while preserving the partition of unity. T = I elsewhere.
856 // SECOND order on TRI7 is the TRI6 basis, with no degree of freedom at the centroid node, and
857 // L2_LAGRANGE shares the LAGRANGE shape functions.
858 if (_elem && (get_family() == LAGRANGE || get_family() == L2_LAGRANGE) &&
859 (((_elem->type() == TRI6 || _elem->type() == TRI7) && sz == 6) ||
860 (_elem->type() == QUAD8 && sz == 8)))
861 {
862 const Real alpha = Real(1)/5;
863 // Mid-edge nodes are the trailing indices, and only vertex entries are written, so D(m,m) here
864 // is never a value an earlier iteration modified.
865 for (const auto m : make_range(_elem->n_vertices(), sz))
866 for (const auto v : make_range(_elem->n_second_order_adjacent_vertices(m)))
867 {
868 const auto vertex = _elem->second_order_adjacent_vertex(m, v);
869 D(vertex, vertex) += alpha*D(m,m);
870 D(vertex, m) -= alpha*D(m,m);
871 }
872 }
873
874 // dual_coeff = A^-1*D
875 for (const auto j : index_range(phi_vals))
876 {
877 DenseVector<Real> Dcol(sz), coeffcol(sz);
878 for (const auto i : index_range(phi_vals))
879 Dcol(i) = D(i, j);
880 A.cholesky_solve(Dcol, coeffcol);
881
882 for (const auto row : index_range(phi_vals))
883 dual_coeff(row, j)=coeffcol(row);
884 }
885}
886
887template <>
889{
890 // Start logging the shape function computation
891 LOG_SCOPE("compute_dual_shape_functions()", "FE");
892
893 // The dual coeffs matrix should have the same size as phi
894 libmesh_assert(dual_coeff.m() == phi.size());
895 libmesh_assert(dual_coeff.n() == phi.size());
896
897 // initialize dual basis
898 for (const auto j : index_range(phi))
899 for (const auto qp : index_range(phi[j]))
900 {
901 dual_phi[j][qp] = 0;
902 if (calculate_dphi)
903 dual_dphi[j][qp] = 0;
904#ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
905 if (calculate_d2phi)
906 dual_d2phi[j][qp] = 0;
907#endif
908 }
909
910 // compute dual basis
911 for (const auto j : index_range(phi))
912 for (const auto i : index_range(phi))
913 for (const auto qp : index_range(phi[j]))
914 {
915 dual_phi[j][qp] += dual_coeff(i, j) * phi[i][qp];
916 if (calculate_dphi)
917 dual_dphi[j][qp] += dual_coeff(i, j) * dphi[i][qp];
918#ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
919 if (calculate_d2phi)
920 dual_d2phi[j][qp] += dual_coeff(i, j) * d2phi[i][qp];
921#endif
922 }
923}
924
925template <typename OutputType>
926void FEGenericBase<OutputType>::print_phi(std::ostream & os) const
927{
928 for (auto i : index_range(phi))
929 for (auto j : index_range(phi[i]))
930 os << " phi[" << i << "][" << j << "]=" << phi[i][j] << std::endl;
931}
932
933template <typename OutputType>
934void FEGenericBase<OutputType>::print_dual_phi(std::ostream & os) const
935{
936 for (auto i : index_range(dual_phi))
937 for (auto j : index_range(dual_phi[i]))
938 os << " dual_phi[" << i << "][" << j << "]=" << dual_phi[i][j] << std::endl;
939}
940
941
942
943
944template <typename OutputType>
945void FEGenericBase<OutputType>::print_dphi(std::ostream & os) const
946{
947 for (auto i : index_range(dphi))
948 for (auto j : index_range(dphi[i]))
949 os << " dphi[" << i << "][" << j << "]=" << dphi[i][j];
950}
951
952template <typename OutputType>
954{
955 for (auto i : index_range(dphi))
956 for (auto j : index_range(dphi[i]))
957 os << " dual_dphi[" << i << "][" << j << "]=" << dual_dphi[i][j];
958}
959
960
961
962template <typename OutputType>
964{
965 this->calculations_started = true;
966
967 // If the user did not explicitly pre-request something (or nothing)
968 // to be computed, then we throw an error here.
969 bool requested_ok =
970 this->calculate_nothing || this->calculate_phi || this->calculate_dphi ||
971 this->calculate_dphiref || this->calculate_curl_phi || this->calculate_div_phi ||
972 this->calculate_map;
973
974#ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
975 requested_ok = requested_ok || this->calculate_d2phi;
976#endif
977
978 libmesh_error_msg_if(
979 !requested_ok,
980 "You must call one or more of the FE accessors "
981 "(e.g. get_phi(), get_dphi(), get_nothing()) "
982 "_before_ calling reinit()!");
983
984 // Request whichever terms are necessary from the FEMap
985 if (this->calculate_phi)
986 this->_fe_trans->init_map_phi(*this);
987
988 if (this->calculate_dphiref)
989 this->_fe_trans->init_map_dphi(*this);
990
991#ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
992 if (this->calculate_d2phi)
993 this->_fe_trans->init_map_d2phi(*this);
994#endif //LIBMESH_ENABLE_SECOND_DERIVATIVES
995}
996
997
998
999#ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
1000
1001
1002template <typename OutputType>
1003void FEGenericBase<OutputType>::print_d2phi(std::ostream & os) const
1004{
1005 for (auto i : index_range(dphi))
1006 for (auto j : index_range(dphi[i]))
1007 os << " d2phi[" << i << "][" << j << "]=" << d2phi[i][j];
1008}
1009
1010template <typename OutputType>
1012{
1013 for (auto i : index_range(dual_d2phi))
1014 for (auto j : index_range(dual_d2phi[i]))
1015 os << " dual_d2phi[" << i << "][" << j << "]=" << dual_d2phi[i][j];
1016}
1017
1018#endif
1019
1020
1021
1022#ifdef LIBMESH_ENABLE_AMR
1023
1024template <typename OutputType>
1025void
1027 const DofMap & dof_map,
1028 const Elem * elem,
1030 const unsigned int var,
1031 const bool use_old_dof_indices)
1032{
1033 // Side/edge local DOF indices
1034 std::vector<unsigned int> new_side_dofs, old_side_dofs;
1035
1036 // FIXME: what about 2D shells in 3D space?
1037 unsigned int dim = elem->dim();
1038
1039 // Cache n_children(); it's a virtual call but it's const.
1040 const unsigned int n_children = elem->n_children();
1041
1042 // We use local FE objects for now
1043 // FIXME: we should use more, external objects instead for efficiency
1044 const FEType & base_fe_type = dof_map.variable_type(var);
1045 std::unique_ptr<FEGenericBase<OutputShape>> fe
1046 (FEGenericBase<OutputShape>::build(dim, base_fe_type));
1047 std::unique_ptr<FEGenericBase<OutputShape>> fe_coarse
1048 (FEGenericBase<OutputShape>::build(dim, base_fe_type));
1049
1050 std::unique_ptr<QBase> qrule (base_fe_type.default_quadrature_rule(dim));
1051 std::unique_ptr<QBase> qedgerule (base_fe_type.default_quadrature_rule(1));
1052 std::unique_ptr<QBase> qsiderule (base_fe_type.default_quadrature_rule(dim-1));
1053 std::vector<Point> coarse_qpoints;
1054
1055 // The values of the shape functions at the quadrature
1056 // points
1057 const std::vector<std::vector<OutputShape>> & phi_values =
1058 fe->get_phi();
1059 const std::vector<std::vector<OutputShape>> & phi_coarse =
1060 fe_coarse->get_phi();
1061
1062 // The gradients of the shape functions at the quadrature
1063 // points on the child element.
1064 const std::vector<std::vector<OutputGradient>> * dphi_values =
1065 nullptr;
1066 const std::vector<std::vector<OutputGradient>> * dphi_coarse =
1067 nullptr;
1068
1069 const FEContinuity cont = fe->get_continuity();
1070
1071 if (cont == C_ONE)
1072 {
1073 const std::vector<std::vector<OutputGradient>> &
1074 ref_dphi_values = fe->get_dphi();
1075 dphi_values = &ref_dphi_values;
1076 const std::vector<std::vector<OutputGradient>> &
1077 ref_dphi_coarse = fe_coarse->get_dphi();
1078 dphi_coarse = &ref_dphi_coarse;
1079 }
1080
1081 // The Jacobian * quadrature weight at the quadrature points
1082 const std::vector<Real> & JxW =
1083 fe->get_JxW();
1084
1085 // The XYZ locations of the quadrature points on the
1086 // child element
1087 const std::vector<Point> & xyz_values =
1088 fe->get_xyz();
1089
1090 // Number of nodes on parent element
1091 const unsigned int n_nodes = elem->n_nodes();
1092
1093 // Number of dofs on parent element
1094 const unsigned int new_n_dofs =
1095 FEInterface::n_dofs(base_fe_type, elem->max_descendant_p_level(), elem);
1096
1097 // Fixed vs. free DoFs on edge/face projections
1098 std::vector<char> dof_is_fixed(new_n_dofs, false); // bools
1099 std::vector<int> free_dof(new_n_dofs, 0);
1100
1103 Ue.resize(new_n_dofs); Ue.zero();
1104
1105
1106 // When coarsening, in general, we need a series of
1107 // projections to ensure a unique and continuous
1108 // solution. We start by interpolating nodes, then
1109 // hold those fixed and project edges, then
1110 // hold those fixed and project faces, then
1111 // hold those fixed and project interiors
1112
1113 // Copy node values first
1114 {
1115 std::vector<dof_id_type> node_dof_indices;
1116 if (use_old_dof_indices)
1117 dof_map.old_dof_indices (elem, node_dof_indices, var);
1118 else
1119 dof_map.dof_indices (elem, node_dof_indices, var);
1120
1121 unsigned int current_dof = 0;
1122 for (unsigned int n=0; n!= n_nodes; ++n)
1123 {
1124 // FIXME: this should go through the DofMap,
1125 // not duplicate dof_indices code badly!
1126 const unsigned int my_nc =
1127 FEInterface::n_dofs_at_node (base_fe_type, elem->max_descendant_p_level(), elem, n);
1128 if (!elem->is_vertex(n))
1129 {
1130 current_dof += my_nc;
1131 continue;
1132 }
1133
1134 // We're assuming here that child n shares vertex n,
1135 // which is wrong on non-simplices right now
1136 // ... but this code isn't necessary except on elements
1137 // where p refinement creates more vertex dofs; we have
1138 // no such elements yet.
1139 int extra_order = 0;
1140 // if (elem->child_ptr(n)->p_level() < elem->p_level())
1141 // extra_order = elem->child_ptr(n)->p_level();
1142 const unsigned int nc =
1143 FEInterface::n_dofs_at_node (base_fe_type, extra_order, elem, n);
1144 for (unsigned int i=0; i!= nc; ++i)
1145 {
1146 Ue(current_dof) =
1147 old_vector(node_dof_indices[current_dof]);
1148 dof_is_fixed[current_dof] = true;
1149 current_dof++;
1150 }
1151 }
1152 }
1153
1154 FEType fe_type = base_fe_type, temp_fe_type;
1155 fe_type.order = fe_type.order + elem->max_descendant_p_level();
1156
1157 // In 3D, project any edge values next
1158 if (dim > 2 && cont != DISCONTINUOUS)
1159 for (auto e : elem->edge_index_range())
1160 {
1161 FEInterface::dofs_on_edge(elem, dim, fe_type,
1162 e, new_side_dofs);
1163
1164 const unsigned int n_new_side_dofs =
1165 cast_int<unsigned int>(new_side_dofs.size());
1166
1167 // Some edge dofs are on nodes and already
1168 // fixed, others are free to calculate
1169 unsigned int free_dofs = 0;
1170 for (unsigned int i=0; i != n_new_side_dofs; ++i)
1171 if (!dof_is_fixed[new_side_dofs[i]])
1172 free_dof[free_dofs++] = i;
1173 Ke.resize (free_dofs, free_dofs); Ke.zero();
1174 Fe.resize (free_dofs); Fe.zero();
1175 // The new edge coefficients
1176 DenseVector<Number> Uedge(free_dofs);
1177
1178 // Add projection terms from each child sharing
1179 // this edge
1180 for (unsigned int c=0; c != n_children; ++c)
1181 {
1182 if (!elem->is_child_on_edge(c,e))
1183 continue;
1184 const Elem * child = elem->child_ptr(c);
1185
1186 std::vector<dof_id_type> child_dof_indices;
1187 if (use_old_dof_indices)
1188 dof_map.old_dof_indices (child,
1189 child_dof_indices, var);
1190 else
1191 dof_map.dof_indices (child,
1192 child_dof_indices, var);
1193 const unsigned int child_n_dofs =
1194 cast_int<unsigned int>
1195 (child_dof_indices.size());
1196
1197 temp_fe_type = base_fe_type;
1198 temp_fe_type.order = temp_fe_type.order + child->p_level();
1199
1201 temp_fe_type, e, old_side_dofs);
1202
1203 // Initialize both child and parent FE data
1204 // on the child's edge
1205 fe->attach_quadrature_rule (qedgerule.get());
1206 fe->edge_reinit (child, e);
1207 const unsigned int n_qp = qedgerule->n_points();
1208
1209 FEMap::inverse_map (dim, elem, xyz_values,
1210 coarse_qpoints);
1211
1212 fe_coarse->reinit(elem, &coarse_qpoints);
1213
1214 // Loop over the quadrature points
1215 for (unsigned int qp=0; qp<n_qp; qp++)
1216 {
1217 // solution value at the quadrature point
1218 OutputNumber fineval = libMesh::zero;
1219 // solution grad at the quadrature point
1220 OutputNumberGradient finegrad;
1221
1222 // Sum the solution values * the DOF
1223 // values at the quadrature point to
1224 // get the solution value and gradient.
1225 for (unsigned int i=0; i<child_n_dofs;
1226 i++)
1227 {
1228 fineval +=
1229 (old_vector(child_dof_indices[i])*
1230 phi_values[i][qp]);
1231 if (cont == C_ONE)
1232 finegrad += (*dphi_values)[i][qp] *
1233 old_vector(child_dof_indices[i]);
1234 }
1235
1236 // Form edge projection matrix
1237 for (unsigned int sidei=0, freei=0; sidei != n_new_side_dofs; ++sidei)
1238 {
1239 unsigned int i = new_side_dofs[sidei];
1240 // fixed DoFs aren't test functions
1241 if (dof_is_fixed[i])
1242 continue;
1243 for (unsigned int sidej=0, freej=0; sidej != n_new_side_dofs; ++sidej)
1244 {
1245 unsigned int j =
1246 new_side_dofs[sidej];
1247 if (dof_is_fixed[j])
1248 Fe(freei) -=
1249 TensorTools::inner_product(phi_coarse[i][qp],
1250 phi_coarse[j][qp]) *
1251 JxW[qp] * Ue(j);
1252 else
1253 Ke(freei,freej) +=
1254 TensorTools::inner_product(phi_coarse[i][qp],
1255 phi_coarse[j][qp]) *
1256 JxW[qp];
1257 if (cont == C_ONE)
1258 {
1259 if (dof_is_fixed[j])
1260 Fe(freei) -=
1261 TensorTools::inner_product((*dphi_coarse)[i][qp],
1262 (*dphi_coarse)[j][qp]) *
1263 JxW[qp] * Ue(j);
1264 else
1265 Ke(freei,freej) +=
1266 TensorTools::inner_product((*dphi_coarse)[i][qp],
1267 (*dphi_coarse)[j][qp]) *
1268 JxW[qp];
1269 }
1270 if (!dof_is_fixed[j])
1271 freej++;
1272 }
1273 Fe(freei) += TensorTools::inner_product(phi_coarse[i][qp],
1274 fineval) * JxW[qp];
1275 if (cont == C_ONE)
1276 Fe(freei) +=
1277 TensorTools::inner_product(finegrad, (*dphi_coarse)[i][qp]) * JxW[qp];
1278 freei++;
1279 }
1280 }
1281 }
1282 Ke.cholesky_solve(Fe, Uedge);
1283
1284 // Transfer new edge solutions to element
1285 for (unsigned int i=0; i != free_dofs; ++i)
1286 {
1287 Number & ui = Ue(new_side_dofs[free_dof[i]]);
1288 libmesh_assert(std::abs(ui) < TOLERANCE ||
1289 std::abs(ui - Uedge(i)) < TOLERANCE);
1290 ui = Uedge(i);
1291 dof_is_fixed[new_side_dofs[free_dof[i]]] = true;
1292 }
1293 }
1294
1295 // Project any side values (edges in 2D, faces in 3D)
1296 if (dim > 1 && cont != DISCONTINUOUS)
1297 for (auto s : elem->side_index_range())
1298 {
1299 FEInterface::dofs_on_side(elem, dim, fe_type,
1300 s, new_side_dofs);
1301
1302 const unsigned int n_new_side_dofs =
1303 cast_int<unsigned int>(new_side_dofs.size());
1304
1305 // Some side dofs are on nodes/edges and already
1306 // fixed, others are free to calculate
1307 unsigned int free_dofs = 0;
1308 for (unsigned int i=0; i != n_new_side_dofs; ++i)
1309 if (!dof_is_fixed[new_side_dofs[i]])
1310 free_dof[free_dofs++] = i;
1311 Ke.resize (free_dofs, free_dofs); Ke.zero();
1312 Fe.resize (free_dofs); Fe.zero();
1313 // The new side coefficients
1314 DenseVector<Number> Uside(free_dofs);
1315
1316 // Add projection terms from each child sharing
1317 // this side
1318 for (unsigned int c=0; c != n_children; ++c)
1319 {
1320 if (!elem->is_child_on_side(c,s))
1321 continue;
1322 const Elem * child = elem->child_ptr(c);
1323
1324 std::vector<dof_id_type> child_dof_indices;
1325 if (use_old_dof_indices)
1326 dof_map.old_dof_indices (child,
1327 child_dof_indices, var);
1328 else
1329 dof_map.dof_indices (child,
1330 child_dof_indices, var);
1331 const unsigned int child_n_dofs =
1332 cast_int<unsigned int>
1333 (child_dof_indices.size());
1334
1335 temp_fe_type = base_fe_type;
1336 temp_fe_type.order = temp_fe_type.order + child->p_level();
1337
1339 temp_fe_type, s, old_side_dofs);
1340
1341 // Initialize both child and parent FE data
1342 // on the child's side
1343 fe->attach_quadrature_rule (qsiderule.get());
1344 fe->reinit (child, s);
1345 const unsigned int n_qp = qsiderule->n_points();
1346
1347 FEMap::inverse_map (dim, elem, xyz_values,
1348 coarse_qpoints);
1349
1350 fe_coarse->reinit(elem, &coarse_qpoints);
1351
1352 // Loop over the quadrature points
1353 for (unsigned int qp=0; qp<n_qp; qp++)
1354 {
1355 // solution value at the quadrature point
1356 OutputNumber fineval = libMesh::zero;
1357 // solution grad at the quadrature point
1358 OutputNumberGradient finegrad;
1359
1360 // Sum the solution values * the DOF
1361 // values at the quadrature point to
1362 // get the solution value and gradient.
1363 for (unsigned int i=0; i<child_n_dofs;
1364 i++)
1365 {
1366 fineval +=
1367 old_vector(child_dof_indices[i]) *
1368 phi_values[i][qp];
1369 if (cont == C_ONE)
1370 finegrad += (*dphi_values)[i][qp] *
1371 old_vector(child_dof_indices[i]);
1372 }
1373
1374 // Form side projection matrix
1375 for (unsigned int sidei=0, freei=0; sidei != n_new_side_dofs; ++sidei)
1376 {
1377 unsigned int i = new_side_dofs[sidei];
1378 // fixed DoFs aren't test functions
1379 if (dof_is_fixed[i])
1380 continue;
1381 for (unsigned int sidej=0, freej=0; sidej != n_new_side_dofs; ++sidej)
1382 {
1383 unsigned int j =
1384 new_side_dofs[sidej];
1385 if (dof_is_fixed[j])
1386 Fe(freei) -=
1387 TensorTools::inner_product(phi_coarse[i][qp],
1388 phi_coarse[j][qp]) *
1389 JxW[qp] * Ue(j);
1390 else
1391 Ke(freei,freej) +=
1392 TensorTools::inner_product(phi_coarse[i][qp],
1393 phi_coarse[j][qp]) *
1394 JxW[qp];
1395 if (cont == C_ONE)
1396 {
1397 if (dof_is_fixed[j])
1398 Fe(freei) -=
1399 TensorTools::inner_product((*dphi_coarse)[i][qp],
1400 (*dphi_coarse)[j][qp]) *
1401 JxW[qp] * Ue(j);
1402 else
1403 Ke(freei,freej) +=
1404 TensorTools::inner_product((*dphi_coarse)[i][qp],
1405 (*dphi_coarse)[j][qp]) *
1406 JxW[qp];
1407 }
1408 if (!dof_is_fixed[j])
1409 freej++;
1410 }
1411 Fe(freei) += TensorTools::inner_product(fineval, phi_coarse[i][qp]) * JxW[qp];
1412 if (cont == C_ONE)
1413 Fe(freei) +=
1414 TensorTools::inner_product(finegrad, (*dphi_coarse)[i][qp]) * JxW[qp];
1415 freei++;
1416 }
1417 }
1418 }
1419 Ke.cholesky_solve(Fe, Uside);
1420
1421 // Transfer new side solutions to element
1422 for (unsigned int i=0; i != free_dofs; ++i)
1423 {
1424 Number & ui = Ue(new_side_dofs[free_dof[i]]);
1425 libmesh_assert(std::abs(ui) < TOLERANCE ||
1426 std::abs(ui - Uside(i)) < TOLERANCE);
1427 ui = Uside(i);
1428 dof_is_fixed[new_side_dofs[free_dof[i]]] = true;
1429 }
1430 }
1431
1432 // Project the interior values, finally
1433
1434 // Some interior dofs are on nodes/edges/sides and
1435 // already fixed, others are free to calculate
1436 unsigned int free_dofs = 0;
1437 for (unsigned int i=0; i != new_n_dofs; ++i)
1438 if (!dof_is_fixed[i])
1439 free_dof[free_dofs++] = i;
1440 Ke.resize (free_dofs, free_dofs); Ke.zero();
1441 Fe.resize (free_dofs); Fe.zero();
1442 // The new interior coefficients
1443 DenseVector<Number> Uint(free_dofs);
1444
1445 // Add projection terms from each child
1446 for (auto & child : elem->child_ref_range())
1447 {
1448 std::vector<dof_id_type> child_dof_indices;
1449 if (use_old_dof_indices)
1450 dof_map.old_dof_indices (&child,
1451 child_dof_indices, var);
1452 else
1453 dof_map.dof_indices (&child,
1454 child_dof_indices, var);
1455 const unsigned int child_n_dofs =
1456 cast_int<unsigned int>
1457 (child_dof_indices.size());
1458
1459 // Initialize both child and parent FE data
1460 // on the child's quadrature points
1461 fe->attach_quadrature_rule (qrule.get());
1462 fe->reinit (&child);
1463 const unsigned int n_qp = qrule->n_points();
1464
1465 FEMap::inverse_map (dim, elem, xyz_values, coarse_qpoints);
1466
1467 fe_coarse->reinit(elem, &coarse_qpoints);
1468
1469 // Loop over the quadrature points
1470 for (unsigned int qp=0; qp<n_qp; qp++)
1471 {
1472 // solution value at the quadrature point
1473 OutputNumber fineval = libMesh::zero;
1474 // solution grad at the quadrature point
1475 OutputNumberGradient finegrad;
1476
1477 // Sum the solution values * the DOF
1478 // values at the quadrature point to
1479 // get the solution value and gradient.
1480 for (unsigned int i=0; i<child_n_dofs; i++)
1481 {
1482 fineval +=
1483 (old_vector(child_dof_indices[i]) *
1484 phi_values[i][qp]);
1485 if (cont == C_ONE)
1486 finegrad += (*dphi_values)[i][qp] *
1487 old_vector(child_dof_indices[i]);
1488 }
1489
1490 // Form interior projection matrix
1491 for (unsigned int i=0, freei=0;
1492 i != new_n_dofs; ++i)
1493 {
1494 // fixed DoFs aren't test functions
1495 if (dof_is_fixed[i])
1496 continue;
1497 for (unsigned int j=0, freej=0; j !=
1498 new_n_dofs; ++j)
1499 {
1500 if (dof_is_fixed[j])
1501 Fe(freei) -=
1502 TensorTools::inner_product(phi_coarse[i][qp],
1503 phi_coarse[j][qp]) *
1504 JxW[qp] * Ue(j);
1505 else
1506 Ke(freei,freej) +=
1507 TensorTools::inner_product(phi_coarse[i][qp],
1508 phi_coarse[j][qp]) *
1509 JxW[qp];
1510 if (cont == C_ONE)
1511 {
1512 if (dof_is_fixed[j])
1513 Fe(freei) -=
1514 TensorTools::inner_product((*dphi_coarse)[i][qp],
1515 (*dphi_coarse)[j][qp]) *
1516 JxW[qp] * Ue(j);
1517 else
1518 Ke(freei,freej) +=
1519 TensorTools::inner_product((*dphi_coarse)[i][qp],
1520 (*dphi_coarse)[j][qp]) *
1521 JxW[qp];
1522 }
1523 if (!dof_is_fixed[j])
1524 freej++;
1525 }
1526 Fe(freei) += TensorTools::inner_product(phi_coarse[i][qp], fineval) *
1527 JxW[qp];
1528 if (cont == C_ONE)
1529 Fe(freei) += TensorTools::inner_product(finegrad, (*dphi_coarse)[i][qp]) * JxW[qp];
1530 freei++;
1531 }
1532 }
1533 }
1534 Ke.cholesky_solve(Fe, Uint);
1535
1536 // Transfer new interior solutions to element
1537 for (unsigned int i=0; i != free_dofs; ++i)
1538 {
1539 Number & ui = Ue(free_dof[i]);
1540 libmesh_assert(std::abs(ui) < TOLERANCE ||
1541 std::abs(ui - Uint(i)) < TOLERANCE);
1542 ui = Uint(i);
1543 // We should be fixing all dofs by now; no need to keep track of
1544 // that unless we're debugging
1545#ifndef NDEBUG
1546 dof_is_fixed[free_dof[i]] = true;
1547#endif
1548 }
1549
1550#ifndef NDEBUG
1551 // Make sure every DoF got reached!
1552 for (unsigned int i=0; i != new_n_dofs; ++i)
1553 libmesh_assert(dof_is_fixed[i]);
1554#endif
1555}
1556
1557
1558
1559template <typename OutputType>
1560void
1562 const DofMap & dof_map,
1563 const Elem * elem,
1565 const bool use_old_dof_indices)
1566{
1567 Ue.resize(0);
1568
1569 for (auto v : make_range(dof_map.n_variables()))
1570 {
1572
1573 coarsened_dof_values(old_vector, dof_map, elem, Usub,
1574 v, use_old_dof_indices);
1575
1576 Ue.append (Usub);
1577 }
1578}
1579
1580
1581
1582template <typename OutputType>
1583void
1585 DofMap & dof_map,
1586 const unsigned int variable_number,
1587 const Elem * elem)
1588{
1589 libmesh_assert(elem);
1590
1591 const unsigned int Dim = elem->dim();
1592
1593 // Only constrain elements in 2,3D.
1594 if (Dim == 1)
1595 return;
1596
1597 // Only constrain active elements with this method
1598 if (!elem->active())
1599 return;
1600
1601 const Variable & var = dof_map.variable(variable_number);
1602 const FEType & base_fe_type = var.type();
1603 const bool add_p_level = base_fe_type.p_refinement;
1604
1605 // Construct FE objects for this element and its neighbors.
1606 std::unique_ptr<FEGenericBase<OutputShape>> my_fe
1607 (FEGenericBase<OutputShape>::build(Dim, base_fe_type));
1608 my_fe->add_p_level_in_reinit(add_p_level);
1609 const FEContinuity cont = my_fe->get_continuity();
1610
1611 // We don't need to constrain discontinuous elements
1612 if (cont == DISCONTINUOUS)
1613 return;
1614 libmesh_assert (cont == C_ZERO || cont == C_ONE ||
1615 cont == SIDE_DISCONTINUOUS);
1616
1617 // this would require some generalisation:
1618 // - e.g. the 'my_fe'-object needs generalisation
1619 // - due to lack of one-to-one correspondence of DOFs and nodes,
1620 // this doesn't work easily.
1621 if (elem->infinite())
1622 libmesh_not_implemented();
1623
1624 std::unique_ptr<FEGenericBase<OutputShape>> neigh_fe
1625 (FEGenericBase<OutputShape>::build(Dim, base_fe_type));
1626 neigh_fe->add_p_level_in_reinit(add_p_level);
1627
1628 QGauss my_qface(Dim-1, base_fe_type.default_quadrature_order());
1629 my_fe->attach_quadrature_rule (&my_qface);
1630 std::vector<Point> neigh_qface;
1631
1632 const std::vector<Real> & JxW = my_fe->get_JxW();
1633 const std::vector<Point> & q_point = my_fe->get_xyz();
1634 const std::vector<std::vector<OutputShape>> & phi = my_fe->get_phi();
1635 const std::vector<std::vector<OutputShape>> & neigh_phi =
1636 neigh_fe->get_phi();
1637 const std::vector<Point> * face_normals = nullptr;
1638 const std::vector<std::vector<OutputGradient>> * dphi = nullptr;
1639 const std::vector<std::vector<OutputGradient>> * neigh_dphi = nullptr;
1640
1641 std::vector<dof_id_type> my_dof_indices, neigh_dof_indices;
1642 std::vector<unsigned int> my_side_dofs, neigh_side_dofs;
1643
1644 if (cont == C_ONE)
1645 {
1646 const std::vector<Point> & ref_face_normals =
1647 my_fe->get_normals();
1648 face_normals = &ref_face_normals;
1649 const std::vector<std::vector<OutputGradient>> & ref_dphi =
1650 my_fe->get_dphi();
1651 dphi = &ref_dphi;
1652 const std::vector<std::vector<OutputGradient>> & ref_neigh_dphi =
1653 neigh_fe->get_dphi();
1654 neigh_dphi = &ref_neigh_dphi;
1655 }
1656
1659 std::vector<DenseVector<Real>> Ue;
1660
1661 // Look at the element faces. Check to see if we need to
1662 // build constraints.
1663 for (auto s : elem->side_index_range())
1664 {
1665 // Get pointers to the element's neighbor.
1666 const Elem * neigh = elem->neighbor_ptr(s);
1667
1668 if (!neigh)
1669 continue;
1670
1671 if (!var.active_on_subdomain(neigh->subdomain_id()))
1672 continue;
1673
1674 // h refinement constraints:
1675 // constrain dofs shared between
1676 // this element and ones coarser
1677 // than this element.
1678 if (neigh->level() < elem->level())
1679 {
1680 unsigned int s_neigh = neigh->which_neighbor_am_i(elem);
1681 libmesh_assert_less (s_neigh, neigh->n_neighbors());
1682
1683 // Find the minimum p level; we build the h constraint
1684 // matrix with this and then constrain away all higher p
1685 // DoFs.
1686 libmesh_assert(neigh->active());
1687 const unsigned int min_p_level = add_p_level *
1688 std::min(elem->p_level(), neigh->p_level());
1689 // we may need to make the FE objects reinit with the
1690 // minimum shared p_level
1691 const unsigned int old_elem_level = add_p_level * elem->p_level();
1692 if (old_elem_level != min_p_level)
1693 my_fe->set_fe_order(my_fe->get_fe_type().order.get_order() + min_p_level - old_elem_level);
1694 const unsigned int old_neigh_level = add_p_level * neigh->p_level();
1695 if (old_neigh_level != min_p_level)
1696 neigh_fe->set_fe_order(neigh_fe->get_fe_type().order.get_order() + min_p_level - old_neigh_level);
1697
1698 my_fe->reinit(elem, s);
1699
1700 // This function gets called element-by-element, so there
1701 // will be a lot of memory allocation going on. We can
1702 // at least minimize this for the case of the dof indices
1703 // by efficiently preallocating the requisite storage.
1704 // n_nodes is not necessarily n_dofs, but it is better
1705 // than nothing!
1706 my_dof_indices.reserve (elem->n_nodes());
1707 neigh_dof_indices.reserve (neigh->n_nodes());
1708
1709 dof_map.dof_indices (elem, my_dof_indices,
1710 variable_number,
1711 min_p_level);
1712 dof_map.dof_indices (neigh, neigh_dof_indices,
1713 variable_number,
1714 min_p_level);
1715
1716 const unsigned int n_qp = my_qface.n_points();
1717
1718 FEMap::inverse_map (Dim, neigh, q_point, neigh_qface);
1719
1720 neigh_fe->reinit(neigh, &neigh_qface);
1721
1722 // We're only concerned with DOFs whose values (and/or first
1723 // derivatives for C1 elements) are supported on side nodes
1724 FEType elem_fe_type = base_fe_type;
1725 if (old_elem_level != min_p_level)
1726 elem_fe_type.order = base_fe_type.order.get_order() + min_p_level - old_elem_level;
1727 FEType neigh_fe_type = base_fe_type;
1728 if (old_neigh_level != min_p_level)
1729 neigh_fe_type.order = base_fe_type.order.get_order() + min_p_level - old_neigh_level;
1730 FEInterface::dofs_on_side(elem, Dim, elem_fe_type, s, my_side_dofs);
1731 FEInterface::dofs_on_side(neigh, Dim, neigh_fe_type, s_neigh, neigh_side_dofs);
1732
1733 const unsigned int n_side_dofs =
1734 cast_int<unsigned int>(my_side_dofs.size());
1735 libmesh_assert_equal_to (n_side_dofs, neigh_side_dofs.size());
1736
1737#ifndef NDEBUG
1738 for (auto i : my_side_dofs)
1739 libmesh_assert_less(i, my_dof_indices.size());
1740 for (auto i : neigh_side_dofs)
1741 libmesh_assert_less(i, neigh_dof_indices.size());
1742#endif
1743
1744 Ke.resize (n_side_dofs, n_side_dofs);
1745 Ue.resize(n_side_dofs);
1746
1747 // Form the projection matrix, (inner product of fine basis
1748 // functions against fine test functions)
1749 for (unsigned int is = 0; is != n_side_dofs; ++is)
1750 {
1751 const unsigned int i = my_side_dofs[is];
1752 for (unsigned int js = 0; js != n_side_dofs; ++js)
1753 {
1754 const unsigned int j = my_side_dofs[js];
1755 for (unsigned int qp = 0; qp != n_qp; ++qp)
1756 {
1757 Ke(is,js) += JxW[qp] * TensorTools::inner_product(phi[i][qp], phi[j][qp]);
1758 if (cont == C_ONE)
1759 Ke(is,js) += JxW[qp] *
1760 TensorTools::inner_product((*dphi)[i][qp] *
1761 (*face_normals)[qp],
1762 (*dphi)[j][qp] *
1763 (*face_normals)[qp]);
1764 }
1765 }
1766 }
1767
1768 // Form the right hand sides, (inner product of coarse basis
1769 // functions against fine test functions)
1770 for (unsigned int is = 0; is != n_side_dofs; ++is)
1771 {
1772 const unsigned int i = neigh_side_dofs[is];
1773 Fe.resize (n_side_dofs);
1774 for (unsigned int js = 0; js != n_side_dofs; ++js)
1775 {
1776 const unsigned int j = my_side_dofs[js];
1777 for (unsigned int qp = 0; qp != n_qp; ++qp)
1778 {
1779 Fe(js) += JxW[qp] *
1780 TensorTools::inner_product(neigh_phi[i][qp],
1781 phi[j][qp]);
1782 if (cont == C_ONE)
1783 Fe(js) += JxW[qp] *
1784 TensorTools::inner_product((*neigh_dphi)[i][qp] *
1785 (*face_normals)[qp],
1786 (*dphi)[j][qp] *
1787 (*face_normals)[qp]);
1788 }
1789 }
1790 Ke.cholesky_solve(Fe, Ue[is]);
1791 }
1792
1793 for (unsigned int js = 0; js != n_side_dofs; ++js)
1794 {
1795 const unsigned int j = my_side_dofs[js];
1796 const dof_id_type my_dof_g = my_dof_indices[j];
1797 libmesh_assert_not_equal_to (my_dof_g, DofObject::invalid_id);
1798
1799 // Hunt for "constraining against myself" cases before
1800 // we bother creating a constraint row
1801 bool self_constraint = false;
1802 for (unsigned int is = 0; is != n_side_dofs; ++is)
1803 {
1804 const unsigned int i = neigh_side_dofs[is];
1805 const dof_id_type their_dof_g = neigh_dof_indices[i];
1806 libmesh_assert_not_equal_to (their_dof_g, DofObject::invalid_id);
1807
1808 if (their_dof_g == my_dof_g)
1809 {
1810#ifndef NDEBUG
1811 const Real their_dof_value = Ue[is](js);
1812 libmesh_assert_less (std::abs(their_dof_value-1.),
1813 10*TOLERANCE);
1814
1815 for (unsigned int k = 0; k != n_side_dofs; ++k)
1816 libmesh_assert(k == is ||
1817 std::abs(Ue[k](js)) <
1818 10*TOLERANCE);
1819#endif
1820
1821 self_constraint = true;
1822 break;
1823 }
1824 }
1825
1826 if (self_constraint)
1827 continue;
1828
1829 DofConstraintRow * constraint_row;
1830
1831 // we may be running constraint methods concurrently
1832 // on multiple threads, so we need a lock to
1833 // ensure that this constraint is "ours"
1834 {
1835 Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
1836
1837 if (dof_map.is_constrained_dof(my_dof_g))
1838 continue;
1839
1840 constraint_row = &(constraints[my_dof_g]);
1841 libmesh_assert(constraint_row->empty());
1842 }
1843
1844 for (unsigned int is = 0; is != n_side_dofs; ++is)
1845 {
1846 const unsigned int i = neigh_side_dofs[is];
1847 const dof_id_type their_dof_g = neigh_dof_indices[i];
1848 libmesh_assert_not_equal_to (their_dof_g, DofObject::invalid_id);
1849 libmesh_assert_not_equal_to (their_dof_g, my_dof_g);
1850
1851 const Real their_dof_value = Ue[is](js);
1852
1853 if (std::abs(their_dof_value) < 10*TOLERANCE)
1854 continue;
1855
1856 constraint_row->emplace(their_dof_g, their_dof_value);
1857 }
1858 }
1859
1860 my_fe->set_fe_order(my_fe->get_fe_type().order.get_order() + old_elem_level - min_p_level);
1861 neigh_fe->set_fe_order(neigh_fe->get_fe_type().order.get_order() + old_neigh_level - min_p_level);
1862 }
1863
1864 if (add_p_level)
1865 {
1866 // p refinement constraints:
1867 // constrain dofs shared between
1868 // active elements and neighbors with
1869 // lower polynomial degrees
1870 const unsigned int min_p_level =
1871 neigh->min_p_level_by_neighbor(elem, elem->p_level());
1872 if (min_p_level < elem->p_level())
1873 {
1874 // Adaptive p refinement of non-hierarchic bases will
1875 // require more coding
1876 libmesh_assert(my_fe->is_hierarchic());
1877 dof_map.constrain_p_dofs(variable_number, elem,
1878 s, min_p_level);
1879 }
1880 }
1881 }
1882}
1883
1884#endif // #ifdef LIBMESH_ENABLE_AMR
1885
1886
1887
1888#ifdef LIBMESH_ENABLE_PERIODIC
1889template <typename OutputType>
1890void
1893 DofMap & dof_map,
1894 const PeriodicBoundaries & boundaries,
1895 const MeshBase & mesh,
1896 const PointLocatorBase * point_locator,
1897 const unsigned int variable_number,
1898 const Elem * elem)
1899{
1900 // Only bother if we truly have periodic boundaries
1901 if (boundaries.empty())
1902 return;
1903
1904 libmesh_assert(elem);
1905
1906 // Only constrain active elements with this method
1907 if (!elem->active())
1908 return;
1909
1910 if (elem->infinite())
1911 libmesh_not_implemented();
1912
1913 const unsigned int Dim = elem->dim();
1914
1915 // We need sys_number and variable_number for DofObject methods
1916 // later
1917 const unsigned int sys_number = dof_map.sys_number();
1918
1919 const FEType & base_fe_type = dof_map.variable_type(variable_number);
1920
1921 // Construct FE objects for this element and its pseudo-neighbors.
1922 std::unique_ptr<FEGenericBase<OutputShape>> my_fe
1923 (FEGenericBase<OutputShape>::build(Dim, base_fe_type));
1924 const FEContinuity cont = my_fe->get_continuity();
1925
1926 // We don't need to constrain discontinuous elements
1927 if (cont == DISCONTINUOUS)
1928 return;
1929 libmesh_assert (cont == C_ZERO || cont == C_ONE ||
1930 cont == SIDE_DISCONTINUOUS);
1931
1932 // We'll use element size to generate relative tolerances later
1933 const Real primary_hmin = elem->hmin();
1934
1935 std::unique_ptr<FEGenericBase<OutputShape>> neigh_fe
1936 (FEGenericBase<OutputShape>::build(Dim, base_fe_type));
1937
1938 QGauss my_qface(Dim-1, base_fe_type.default_quadrature_order());
1939 my_fe->attach_quadrature_rule (&my_qface);
1940 std::vector<Point> neigh_qface;
1941
1942 const std::vector<Real> & JxW = my_fe->get_JxW();
1943 const std::vector<Point> & q_point = my_fe->get_xyz();
1944 const std::vector<std::vector<OutputShape>> & phi = my_fe->get_phi();
1945 const std::vector<std::vector<OutputShape>> & neigh_phi =
1946 neigh_fe->get_phi();
1947 const std::vector<Point> * face_normals = nullptr;
1948 const std::vector<std::vector<OutputGradient>> * dphi = nullptr;
1949 const std::vector<std::vector<OutputGradient>> * neigh_dphi = nullptr;
1950 std::vector<dof_id_type> my_dof_indices, neigh_dof_indices;
1951 std::vector<unsigned int> my_side_dofs, neigh_side_dofs;
1952
1953 if (cont == C_ONE)
1954 {
1955 const std::vector<Point> & ref_face_normals =
1956 my_fe->get_normals();
1957 face_normals = &ref_face_normals;
1958 const std::vector<std::vector<OutputGradient>> & ref_dphi =
1959 my_fe->get_dphi();
1960 dphi = &ref_dphi;
1961 const std::vector<std::vector<OutputGradient>> & ref_neigh_dphi =
1962 neigh_fe->get_dphi();
1963 neigh_dphi = &ref_neigh_dphi;
1964 }
1965
1968 std::vector<DenseVector<Real>> Ue;
1969
1970 // Container to catch the boundary ids that BoundaryInfo hands us.
1971 std::vector<boundary_id_type> bc_ids;
1972
1973 // Look at the element faces. Check to see if we need to
1974 // build constraints.
1975 const unsigned short int max_ns = elem->n_sides();
1976 for (unsigned short int s = 0; s != max_ns; ++s)
1977 {
1978 if (elem->neighbor_ptr(s))
1979 continue;
1980
1981 mesh.get_boundary_info().boundary_ids (elem, s, bc_ids);
1982
1983 for (const auto & boundary_id : bc_ids)
1984 {
1985 const PeriodicBoundaryBase * periodic = boundaries.boundary(boundary_id);
1986 if (!periodic || !periodic->is_my_variable(variable_number))
1987 continue;
1988
1989 libmesh_assert(point_locator);
1990
1991 // Get pointers to the element's neighbor.
1992 unsigned int s_neigh;
1993 const Elem * neigh = boundaries.neighbor(boundary_id, *point_locator, elem, s, &s_neigh);
1994
1995 libmesh_error_msg_if(neigh == nullptr,
1996 "PeriodicBoundaries point locator object returned nullptr!");
1997
1998 // periodic (and possibly h refinement) constraints:
1999 // constrain dofs shared between
2000 // this element and ones as coarse
2001 // as or coarser than this element.
2002 if (neigh->level() <= elem->level())
2003 {
2004#ifdef LIBMESH_ENABLE_AMR
2005 // Find the minimum p level; we build the h constraint
2006 // matrix with this and then constrain away all higher p
2007 // DoFs.
2008 libmesh_assert(neigh->active());
2009 const unsigned int min_p_level =
2010 std::min(elem->p_level(), neigh->p_level());
2011
2012 // we may need to make the FE objects reinit with the
2013 // minimum shared p_level
2014 // FIXME - I hate using const_cast<> and avoiding
2015 // accessor functions; there's got to be a
2016 // better way to do this!
2017 const unsigned int old_elem_level = elem->p_level();
2018 if (old_elem_level != min_p_level)
2019 (const_cast<Elem *>(elem))->hack_p_level(min_p_level);
2020 const unsigned int old_neigh_level = neigh->p_level();
2021 if (old_neigh_level != min_p_level)
2022 (const_cast<Elem *>(neigh))->hack_p_level(min_p_level);
2023#endif // #ifdef LIBMESH_ENABLE_AMR
2024
2025 // We can do a projection with a single integration,
2026 // due to the assumption of nested finite element
2027 // subspaces.
2028 // FIXME: it might be more efficient to do nodes,
2029 // then edges, then side, to reduce the size of the
2030 // Cholesky factorization(s)
2031 my_fe->reinit(elem, s);
2032
2033 dof_map.dof_indices (elem, my_dof_indices,
2034 variable_number);
2035 dof_map.dof_indices (neigh, neigh_dof_indices,
2036 variable_number);
2037
2038 // We use neigh_dof_indices_all_variables in the case that the
2039 // periodic boundary condition involves mappings between multiple
2040 // variables.
2041 std::vector<std::vector<dof_id_type>> neigh_dof_indices_all_variables;
2042 if(periodic->has_transformation_matrix())
2043 {
2044 const std::set<unsigned int> & variables = periodic->get_variables();
2045 neigh_dof_indices_all_variables.resize(variables.size());
2046 unsigned int index = 0;
2047 for(unsigned int var : variables)
2048 {
2049 dof_map.dof_indices (neigh, neigh_dof_indices_all_variables[index],
2050 var);
2051 index++;
2052 }
2053 }
2054
2055 const unsigned int n_qp = my_qface.n_points();
2056
2057 // Translate the quadrature points over to the
2058 // neighbor's boundary
2059 std::vector<Point> neigh_point(q_point.size());
2060 for (auto i : index_range(neigh_point))
2061 neigh_point[i] = periodic->get_corresponding_pos(q_point[i]);
2062
2063 FEMap::inverse_map (Dim, neigh, neigh_point,
2064 neigh_qface);
2065
2066 neigh_fe->reinit(neigh, &neigh_qface);
2067
2068 // We're only concerned with DOFs whose values (and/or first
2069 // derivatives for C1 elements) are supported on side nodes
2070 FEInterface::dofs_on_side(elem, Dim, base_fe_type, s, my_side_dofs);
2071 FEInterface::dofs_on_side(neigh, Dim, base_fe_type, s_neigh, neigh_side_dofs);
2072
2073 // We're done with functions that examine Elem::p_level(),
2074 // so let's unhack those levels
2075#ifdef LIBMESH_ENABLE_AMR
2076 if (elem->p_level() != old_elem_level)
2077 (const_cast<Elem *>(elem))->hack_p_level(old_elem_level);
2078 if (neigh->p_level() != old_neigh_level)
2079 (const_cast<Elem *>(neigh))->hack_p_level(old_neigh_level);
2080#endif // #ifdef LIBMESH_ENABLE_AMR
2081
2082 const unsigned int n_side_dofs =
2083 cast_int<unsigned int>
2084 (my_side_dofs.size());
2085 libmesh_assert_equal_to (n_side_dofs, neigh_side_dofs.size());
2086
2087 Ke.resize (n_side_dofs, n_side_dofs);
2088 Ue.resize(n_side_dofs);
2089
2090 // Form the projection matrix, (inner product of fine basis
2091 // functions against fine test functions)
2092 for (unsigned int is = 0; is != n_side_dofs; ++is)
2093 {
2094 const unsigned int i = my_side_dofs[is];
2095 for (unsigned int js = 0; js != n_side_dofs; ++js)
2096 {
2097 const unsigned int j = my_side_dofs[js];
2098 for (unsigned int qp = 0; qp != n_qp; ++qp)
2099 {
2100 Ke(is,js) += JxW[qp] *
2101 TensorTools::inner_product(phi[i][qp],
2102 phi[j][qp]);
2103 if (cont == C_ONE)
2104 Ke(is,js) += JxW[qp] *
2105 TensorTools::inner_product((*dphi)[i][qp] *
2106 (*face_normals)[qp],
2107 (*dphi)[j][qp] *
2108 (*face_normals)[qp]);
2109 }
2110 }
2111 }
2112
2113 // Form the right hand sides, (inner product of coarse basis
2114 // functions against fine test functions)
2115 for (unsigned int is = 0; is != n_side_dofs; ++is)
2116 {
2117 const unsigned int i = neigh_side_dofs[is];
2118 Fe.resize (n_side_dofs);
2119 for (unsigned int js = 0; js != n_side_dofs; ++js)
2120 {
2121 const unsigned int j = my_side_dofs[js];
2122 for (unsigned int qp = 0; qp != n_qp; ++qp)
2123 {
2124 Fe(js) += JxW[qp] *
2125 TensorTools::inner_product(neigh_phi[i][qp],
2126 phi[j][qp]);
2127 if (cont == C_ONE)
2128 Fe(js) += JxW[qp] *
2129 TensorTools::inner_product((*neigh_dphi)[i][qp] *
2130 (*face_normals)[qp],
2131 (*dphi)[j][qp] *
2132 (*face_normals)[qp]);
2133 }
2134 }
2135 Ke.cholesky_solve(Fe, Ue[is]);
2136 }
2137
2138 // Make sure we're not adding recursive constraints
2139 // due to the redundancy in the way we add periodic
2140 // boundary constraints
2141 //
2142 // In order for this to work while threaded or on
2143 // distributed meshes, we need a rigorous way to
2144 // avoid recursive constraints. Here it is:
2145 //
2146 // For vertex DoFs, if there is a "prior" element
2147 // (i.e. a coarser element or an equally refined
2148 // element with a lower id) on this boundary which
2149 // contains the vertex point, then we will avoid
2150 // generating constraints; the prior element (or
2151 // something prior to it) may do so. If we are the
2152 // most prior (or "primary") element on this
2153 // boundary sharing this point, then we look at the
2154 // boundary periodic to us, we find the primary
2155 // element there, and if that primary is coarser or
2156 // equal-but-lower-id, then our vertex dofs are
2157 // constrained in terms of that element.
2158 //
2159 // For edge DoFs, if there is a coarser element
2160 // on this boundary sharing this edge, then we will
2161 // avoid generating constraints (we will be
2162 // constrained indirectly via AMR constraints
2163 // connecting us to the coarser element's DoFs). If
2164 // we are the coarsest element sharing this edge,
2165 // then we generate constraints if and only if we
2166 // are finer than the coarsest element on the
2167 // boundary periodic to us sharing the corresponding
2168 // periodic edge, or if we are at equal level but
2169 // our edge nodes have higher ids than the periodic
2170 // edge nodes (sorted from highest to lowest, then
2171 // compared lexicographically)
2172 //
2173 // For face DoFs, we generate constraints if we are
2174 // finer than our periodic neighbor, or if we are at
2175 // equal level but our element id is higher than its
2176 // element id.
2177 //
2178 // If the primary neighbor is also the current elem
2179 // (a 1-element-thick mesh) then we choose which
2180 // vertex dofs to constrain via lexicographic
2181 // ordering on point locations
2182
2183 // FIXME: This code doesn't yet properly handle
2184 // cases where multiple different periodic BCs
2185 // intersect.
2186 std::set<dof_id_type> my_constrained_dofs;
2187
2188 // Container to catch boundary IDs handed back by BoundaryInfo.
2189 std::vector<boundary_id_type> new_bc_ids;
2190
2191 for (auto n : elem->node_index_range())
2192 {
2193 if (!elem->is_node_on_side(n,s))
2194 continue;
2195
2196 const Node & my_node = elem->node_ref(n);
2197
2198 if (elem->is_vertex(n))
2199 {
2200 // Find all boundary ids that include this
2201 // point and have periodic boundary
2202 // conditions for this variable
2203 std::set<boundary_id_type> point_bcids;
2204
2205 for (unsigned int new_s = 0;
2206 new_s != max_ns; ++new_s)
2207 {
2208 if (!elem->is_node_on_side(n,new_s))
2209 continue;
2210
2211 mesh.get_boundary_info().boundary_ids (elem, s, new_bc_ids);
2212
2213 for (const auto & new_boundary_id : new_bc_ids)
2214 {
2215 const PeriodicBoundaryBase * new_periodic = boundaries.boundary(new_boundary_id);
2216 if (new_periodic && new_periodic->is_my_variable(variable_number))
2217 point_bcids.insert(new_boundary_id);
2218 }
2219 }
2220
2221 // See if this vertex has point neighbors to
2222 // defer to
2223 if (primary_boundary_point_neighbor
2224 (elem, my_node, mesh.get_boundary_info(), point_bcids)
2225 != elem)
2226 continue;
2227
2228 // Find the complementary boundary id set
2229 std::set<boundary_id_type> point_pairedids;
2230 for (const auto & new_boundary_id : point_bcids)
2231 {
2232 const PeriodicBoundaryBase * new_periodic = boundaries.boundary(new_boundary_id);
2233 point_pairedids.insert(new_periodic->pairedboundary);
2234 }
2235
2236 // What do we want to constrain against?
2237 const Elem * primary_elem = nullptr;
2238 const Elem * main_neigh = nullptr;
2239 Point main_pt = my_node,
2240 primary_pt = my_node;
2241
2242 for (const auto & new_boundary_id : point_bcids)
2243 {
2244 // Find the corresponding periodic point and
2245 // its primary neighbor
2246 const PeriodicBoundaryBase * new_periodic = boundaries.boundary(new_boundary_id);
2247
2248 const Point neigh_pt =
2249 new_periodic->get_corresponding_pos(my_node);
2250
2251 // If the point is getting constrained
2252 // to itself by this PBC then we don't
2253 // generate any constraints
2254 if (neigh_pt.absolute_fuzzy_equals
2255 (my_node, primary_hmin*TOLERANCE))
2256 continue;
2257
2258 // Otherwise we'll have a constraint in
2259 // one direction or another
2260 if (!primary_elem)
2261 primary_elem = elem;
2262
2263 const Elem * primary_neigh =
2264 primary_boundary_point_neighbor(neigh, neigh_pt,
2266 point_pairedids);
2267
2268 libmesh_assert(primary_neigh);
2269
2270 if (new_boundary_id == boundary_id)
2271 {
2272 main_neigh = primary_neigh;
2273 main_pt = neigh_pt;
2274 }
2275
2276 // Finer elements will get constrained in
2277 // terms of coarser neighbors, not the
2278 // other way around
2279 if ((primary_neigh->level() > primary_elem->level()) ||
2280
2281 // For equal-level elements, the one with
2282 // higher id gets constrained in terms of
2283 // the one with lower id
2284 (primary_neigh->level() == primary_elem->level() &&
2285 primary_neigh->id() > primary_elem->id()) ||
2286
2287 // On a one-element-thick mesh, we compare
2288 // points to see what side gets constrained
2289 (primary_neigh == primary_elem &&
2290 (neigh_pt > primary_pt)))
2291 continue;
2292
2293 primary_elem = primary_neigh;
2294 primary_pt = neigh_pt;
2295 }
2296
2297 if (!primary_elem ||
2298 primary_elem != main_neigh ||
2299 primary_pt != main_pt)
2300 continue;
2301 }
2302 else if (elem->is_edge(n))
2303 {
2304 // Find which edge we're on
2305 unsigned int e=0, ne = elem->n_edges();
2306 for (; e != ne; ++e)
2307 {
2308 if (elem->is_node_on_edge(n,e))
2309 break;
2310 }
2311 libmesh_assert_less (e, elem->n_edges());
2312
2313 // Find the edge end nodes
2314 const Node
2315 * e1 = nullptr,
2316 * e2 = nullptr;
2317 for (auto nn : elem->node_index_range())
2318 {
2319 if (nn == n)
2320 continue;
2321
2322 if (elem->is_node_on_edge(nn, e))
2323 {
2324 if (e1 == nullptr)
2325 {
2326 e1 = elem->node_ptr(nn);
2327 }
2328 else
2329 {
2330 e2 = elem->node_ptr(nn);
2331 break;
2332 }
2333 }
2334 }
2335 libmesh_assert (e1 && e2);
2336
2337 // Find all boundary ids that include this
2338 // edge and have periodic boundary
2339 // conditions for this variable
2340 std::set<boundary_id_type> edge_bcids;
2341
2342 for (unsigned int new_s = 0;
2343 new_s != max_ns; ++new_s)
2344 {
2345 if (!elem->is_node_on_side(n,new_s))
2346 continue;
2347
2348 // We're reusing the new_bc_ids vector created outside the loop over nodes.
2349 mesh.get_boundary_info().boundary_ids (elem, s, new_bc_ids);
2350
2351 for (const auto & new_boundary_id : new_bc_ids)
2352 {
2353 const PeriodicBoundaryBase * new_periodic = boundaries.boundary(new_boundary_id);
2354 if (new_periodic && new_periodic->is_my_variable(variable_number))
2355 edge_bcids.insert(new_boundary_id);
2356 }
2357 }
2358
2359
2360 // See if this edge has neighbors to defer to
2361 if (primary_boundary_edge_neighbor
2362 (elem, *e1, *e2, mesh.get_boundary_info(), edge_bcids)
2363 != elem)
2364 continue;
2365
2366 // Find the complementary boundary id set
2367 std::set<boundary_id_type> edge_pairedids;
2368 for (const auto & new_boundary_id : edge_bcids)
2369 {
2370 const PeriodicBoundaryBase * new_periodic = boundaries.boundary(new_boundary_id);
2371 edge_pairedids.insert(new_periodic->pairedboundary);
2372 }
2373
2374 // What do we want to constrain against?
2375 const Elem * primary_elem = nullptr;
2376 const Elem * main_neigh = nullptr;
2377 Point main_pt1 = *e1,
2378 main_pt2 = *e2,
2379 primary_pt1 = *e1,
2380 primary_pt2 = *e2;
2381
2382 for (const auto & new_boundary_id : edge_bcids)
2383 {
2384 // Find the corresponding periodic edge and
2385 // its primary neighbor
2386 const PeriodicBoundaryBase * new_periodic = boundaries.boundary(new_boundary_id);
2387
2388 Point neigh_pt1 = new_periodic->get_corresponding_pos(*e1),
2389 neigh_pt2 = new_periodic->get_corresponding_pos(*e2);
2390
2391 // If the edge is getting constrained
2392 // to itself by this PBC then we don't
2393 // generate any constraints
2394 if (neigh_pt1.absolute_fuzzy_equals
2395 (*e1, primary_hmin*TOLERANCE) &&
2396 neigh_pt2.absolute_fuzzy_equals
2397 (*e2, primary_hmin*TOLERANCE))
2398 continue;
2399
2400 // Otherwise we'll have a constraint in
2401 // one direction or another
2402 if (!primary_elem)
2403 primary_elem = elem;
2404
2405 const Elem * primary_neigh = primary_boundary_edge_neighbor
2406 (neigh, neigh_pt1, neigh_pt2,
2407 mesh.get_boundary_info(), edge_pairedids);
2408
2409 libmesh_assert(primary_neigh);
2410
2411 if (new_boundary_id == boundary_id)
2412 {
2413 main_neigh = primary_neigh;
2414 main_pt1 = neigh_pt1;
2415 main_pt2 = neigh_pt2;
2416 }
2417
2418 // If we have a one-element thick mesh,
2419 // we'll need to sort our points to get a
2420 // consistent ordering rule
2421 //
2422 // Use >= in this test to make sure that,
2423 // for angular constraints, no node gets
2424 // constrained to itself.
2425 if (primary_neigh == primary_elem)
2426 {
2427 if (primary_pt1 > primary_pt2)
2428 std::swap(primary_pt1, primary_pt2);
2429 if (neigh_pt1 > neigh_pt2)
2430 std::swap(neigh_pt1, neigh_pt2);
2431
2432 if (neigh_pt2 >= primary_pt2)
2433 continue;
2434 }
2435
2436 // Otherwise:
2437 // Finer elements will get constrained in
2438 // terms of coarser ones, not the other way
2439 // around
2440 if ((primary_neigh->level() > primary_elem->level()) ||
2441
2442 // For equal-level elements, the one with
2443 // higher id gets constrained in terms of
2444 // the one with lower id
2445 (primary_neigh->level() == primary_elem->level() &&
2446 primary_neigh->id() > primary_elem->id()))
2447 continue;
2448
2449 primary_elem = primary_neigh;
2450 primary_pt1 = neigh_pt1;
2451 primary_pt2 = neigh_pt2;
2452 }
2453
2454 if (!primary_elem ||
2455 primary_elem != main_neigh ||
2456 primary_pt1 != main_pt1 ||
2457 primary_pt2 != main_pt2)
2458 continue;
2459 }
2460 else if (elem->is_face(n))
2461 {
2462 // If we have a one-element thick mesh,
2463 // use the ordering of the face node and its
2464 // periodic counterpart to determine what
2465 // gets constrained
2466 if (neigh == elem)
2467 {
2468 const Point neigh_pt =
2469 periodic->get_corresponding_pos(my_node);
2470 if (neigh_pt > my_node)
2471 continue;
2472 }
2473
2474 // Otherwise:
2475 // Finer elements will get constrained in
2476 // terms of coarser ones, not the other way
2477 // around
2478 if ((neigh->level() > elem->level()) ||
2479
2480 // For equal-level elements, the one with
2481 // higher id gets constrained in terms of
2482 // the one with lower id
2483 (neigh->level() == elem->level() &&
2484 neigh->id() > elem->id()))
2485 continue;
2486 }
2487
2488 // If we made it here without hitting a continue
2489 // statement, then we're at a node whose dofs
2490 // should be constrained by this element's
2491 // calculations.
2492 const unsigned int n_comp =
2493 my_node.n_comp(sys_number, variable_number);
2494
2495 for (unsigned int i=0; i != n_comp; ++i)
2496 my_constrained_dofs.insert
2497 (my_node.dof_number
2498 (sys_number, variable_number, i));
2499 }
2500
2501 // FIXME: old code for disambiguating periodic BCs:
2502 // this is not threadsafe nor safe to run on a
2503 // non-serialized mesh.
2504 /*
2505 std::vector<bool> recursive_constraint(n_side_dofs, false);
2506
2507 for (unsigned int is = 0; is != n_side_dofs; ++is)
2508 {
2509 const unsigned int i = neigh_side_dofs[is];
2510 const dof_id_type their_dof_g = neigh_dof_indices[i];
2511 libmesh_assert_not_equal_to (their_dof_g, DofObject::invalid_id);
2512
2513 {
2514 Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
2515
2516 if (!dof_map.is_constrained_dof(their_dof_g))
2517 continue;
2518 }
2519
2520 DofConstraintRow & their_constraint_row =
2521 constraints[their_dof_g].first;
2522
2523 for (unsigned int js = 0; js != n_side_dofs; ++js)
2524 {
2525 const unsigned int j = my_side_dofs[js];
2526 const dof_id_type my_dof_g = my_dof_indices[j];
2527 libmesh_assert_not_equal_to (my_dof_g, DofObject::invalid_id);
2528
2529 if (their_constraint_row.count(my_dof_g))
2530 recursive_constraint[js] = true;
2531 }
2532 }
2533 */
2534
2535 for (unsigned int js = 0; js != n_side_dofs; ++js)
2536 {
2537 // FIXME: old code path
2538 // if (recursive_constraint[js])
2539 // continue;
2540
2541 const unsigned int j = my_side_dofs[js];
2542 const dof_id_type my_dof_g = my_dof_indices[j];
2543 libmesh_assert_not_equal_to (my_dof_g, DofObject::invalid_id);
2544
2545 // FIXME: new code path
2546 if (!my_constrained_dofs.count(my_dof_g))
2547 continue;
2548
2549 DofConstraintRow * constraint_row;
2550
2551 // we may be running constraint methods concurrently
2552 // on multiple threads, so we need a lock to
2553 // ensure that this constraint is "ours"
2554 {
2555 Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
2556
2557 if (dof_map.is_constrained_dof(my_dof_g))
2558 continue;
2559
2560 constraint_row = &(constraints[my_dof_g]);
2561 libmesh_assert(constraint_row->empty());
2562 }
2563
2564 for (unsigned int is = 0; is != n_side_dofs; ++is)
2565 {
2566 const unsigned int i = neigh_side_dofs[is];
2567 const dof_id_type their_dof_g = neigh_dof_indices[i];
2568 libmesh_assert_not_equal_to (their_dof_g, DofObject::invalid_id);
2569
2570 // Periodic constraints should never be
2571 // self-constraints
2572 // libmesh_assert_not_equal_to (their_dof_g, my_dof_g);
2573
2574 const Real their_dof_value = Ue[is](js);
2575
2576 if (their_dof_g == my_dof_g)
2577 {
2578 libmesh_assert_less (std::abs(their_dof_value-1.), 1.e-5);
2579 for (unsigned int k = 0; k != n_side_dofs; ++k)
2580 libmesh_assert(k == is || std::abs(Ue[k](js)) < 1.e-5);
2581 continue;
2582 }
2583
2584 if (std::abs(their_dof_value) < 10*TOLERANCE)
2585 continue;
2586
2587 if(!periodic->has_transformation_matrix())
2588 {
2589 constraint_row->emplace(their_dof_g, their_dof_value);
2590 }
2591 else
2592 {
2593 // In this case the current variable is constrained in terms of other variables.
2594 // We assume that all variables in this constraint have the same FE type (this
2595 // is asserted below), and hence we can create the constraint row contribution
2596 // by multiplying their_dof_value by the corresponding row of the transformation
2597 // matrix.
2598
2599 const std::set<unsigned int> & variables = periodic->get_variables();
2600 neigh_dof_indices_all_variables.resize(variables.size());
2601 unsigned int index = 0;
2602 for(unsigned int other_var : variables)
2603 {
2604 libmesh_assert_msg(base_fe_type == dof_map.variable_type(other_var), "FE types must match for all variables involved in constraint");
2605
2606 Real var_weighting = periodic->get_transformation_matrix()(variable_number, other_var);
2607 constraint_row->emplace(neigh_dof_indices_all_variables[index][i],
2608 var_weighting*their_dof_value);
2609 index++;
2610 }
2611 }
2612
2613 }
2614 }
2615 }
2616 // p refinement constraints:
2617 // constrain dofs shared between
2618 // active elements and neighbors with
2619 // lower polynomial degrees
2620#ifdef LIBMESH_ENABLE_AMR
2621 const unsigned int min_p_level =
2622 neigh->min_p_level_by_neighbor(elem, elem->p_level());
2623 if (min_p_level < elem->p_level())
2624 {
2625 // Adaptive p refinement of non-hierarchic bases will
2626 // require more coding
2627 libmesh_assert(my_fe->is_hierarchic());
2628 dof_map.constrain_p_dofs(variable_number, elem,
2629 s, min_p_level);
2630 }
2631#endif // #ifdef LIBMESH_ENABLE_AMR
2632 }
2633 }
2634}
2635
2636#endif // LIBMESH_ENABLE_PERIODIC
2637
2638// ------------------------------------------------------------
2639// Explicit instantiations
2640template class LIBMESH_EXPORT FEGenericBase<Real>;
2641template class LIBMESH_EXPORT FEGenericBase<RealGradient>;
2642
2643} // namespace libMesh
unsigned int dim
The BoundaryInfo class contains information relevant to boundary conditions including storing faces,...
void boundary_ids(const Node *node, std::vector< boundary_id_type > &vec_to_fill) const
Fills a user-provided std::vector with the boundary ids associated with Node node.
Defines a dense matrix for use in Finite Element-type computations.
void cholesky_solve(const DenseVector< T2 > &b, DenseVector< T2 > &x)
For symmetric positive definite (SPD) matrices.
void resize(const unsigned int new_m, const unsigned int new_n)
Resizes the matrix to the specified size and calls zero().
virtual void zero() override final
Sets all elements of the matrix to 0 and resets any decomposition flag which may have been previously...
Defines a dense vector for use in Finite Element-type computations.
void resize(const unsigned int n)
Resize the vector.
virtual void zero() override final
Set every element in the vector to 0.
void append(const DenseVector< T2 > &other_vector)
Append additional entries to (resizing, but unchanging) the vector.
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
void constrain_p_dofs(unsigned int var, const Elem *elem, unsigned int s, unsigned int p)
Constrains degrees of freedom on side s of element elem which correspond to variable number var and t...
unsigned int n_variables() const override
Definition dof_map.h:743
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
Definition dof_map.C:2231
const FEType & variable_type(const unsigned int i) const
Definition dof_map.h:2472
unsigned int sys_number() const
Definition dof_map.h:2424
bool is_constrained_dof(const dof_id_type dof) const
Definition dof_map.h:2510
const Variable & variable(const unsigned int c) const override
Definition dof_map.h:2442
void old_dof_indices(const Elem &elem, unsigned int n, std::vector< dof_id_type > &di, const unsigned int vn) const
Appends to the vector di the old global degree of freedom indices for elem.node_ref(n),...
Definition dof_map.C:2508
unsigned int n_comp(const unsigned int s, const unsigned int var) const
Definition dof_object.h:992
dof_id_type dof_number(const unsigned int s, const unsigned int var, const unsigned int comp) const
static constexpr dof_id_type invalid_id
An invalid id to distinguish an uninitialized DofObject.
Definition dof_object.h:473
dof_id_type id() const
Definition dof_object.h:833
This is the base class from which all geometric element types are derived.
Definition elem.h:96
virtual bool is_node_on_side(const unsigned int n, const unsigned int s) const =0
virtual bool is_child_on_side(const unsigned int c, const unsigned int s) const =0
bool active() const
Definition elem.h:3079
const Node & node_ref(const unsigned int i) const
Definition elem.h:2659
virtual bool is_child_on_edge(const unsigned int c, const unsigned int e) const
Definition elem.C:2435
virtual unsigned int n_nodes() const =0
const Elem * child_ptr(unsigned int i) const
Definition elem.h:3301
unsigned int which_neighbor_am_i(const Elem *e) const
This function tells you which neighbor e is.
Definition elem.h:3057
unsigned int n_neighbors() const
Definition elem.h:812
virtual bool is_face(const unsigned int i) const =0
void find_point_neighbors(const Point &p, std::set< const Elem * > &neighbor_set) const
This function finds all active elements (including this one) which are in the same manifold as this e...
Definition elem.C:907
virtual Real hmin() const
Definition elem.C:623
virtual unsigned short dim() const =0
void find_edge_neighbors(const Point &p1, const Point &p2, std::set< const Elem * > &neighbor_set) const
This function finds all active elements in the same manifold as this element which touch the current ...
Definition elem.C:997
subdomain_id_type subdomain_id() const
Definition elem.h:2712
SimpleRange< ChildRefIter > child_ref_range()
Returns a range with all children of a parent element, usable in range-based for loops.
Definition elem.h:2476
virtual bool is_edge(const unsigned int i) const =0
unsigned int level() const
Definition elem.h:3212
unsigned int min_p_level_by_neighbor(const Elem *neighbor, unsigned int current_min) const
Definition elem.C:2452
const Node * node_ptr(const unsigned int i) const
Definition elem.h:2637
IntRange< unsigned short > edge_index_range() const
Definition elem.h:2830
virtual bool is_vertex(const unsigned int i) const =0
virtual unsigned int n_children() const =0
unsigned int max_descendant_p_level() const
Definition elem.h:3384
IntRange< unsigned short > node_index_range() const
Definition elem.h:2821
virtual bool is_node_on_edge(const unsigned int n, const unsigned int e) const =0
virtual unsigned int n_edges() const =0
virtual unsigned int n_sides() const =0
unsigned int p_level() const
Definition elem.h:3246
const Elem * neighbor_ptr(unsigned int i) const
Definition elem.h:2736
virtual bool infinite() const =0
IntRange< unsigned short > side_index_range() const
Definition elem.h:2848
This class forms the foundation from which generic finite elements may be derived.
Definition fe_base.h:86
virtual_for_inffe void determine_calculations()
Determine which values are to be calculated, for both the FE itself and for the FEMap.
Definition fe_base.C:963
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
void compute_dual_shape_coeffs(const std::vector< Real > &JxW, const std::vector< std::vector< OutputShape > > &phi)
Compute the dual basis coefficients dual_coeff we rely on the JxW (or weights) and the phi values,...
Definition fe_base.h:838
virtual void print_dphi(std::ostream &os) const override
Prints the value of each shape function's derivative at each quadrature point.
Definition fe_base.C:945
static void coarsened_dof_values(const NumericVector< Number > &global_vector, const DofMap &dof_map, const Elem *coarse_elem, DenseVector< Number > &coarse_dofs, const unsigned int var, const bool use_old_dof_indices=false)
Creates a local projection on coarse_elem, based on the DoF values in global_vector for it's children...
Definition fe_base.C:1026
static void compute_proj_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...
Definition fe_base.C:1584
static std::unique_ptr< FEGenericBase > build_InfFE(const unsigned int dim, const FEType &type)
Builds a specific infinite element type.
virtual void print_dual_d2phi(std::ostream &os) const override
Definition fe_base.C:1011
virtual void print_d2phi(std::ostream &os) const override
Prints the value of each shape function's second derivatives at each quadrature point.
Definition fe_base.C:1003
virtual void print_phi(std::ostream &os) const override
Prints the value of each shape function at each quadrature point.
Definition fe_base.C:926
static void compute_periodic_constraints(DofConstraints &constraints, DofMap &dof_map, const PeriodicBoundaries &boundaries, const MeshBase &mesh, const PointLocatorBase *point_locator, const unsigned int variable_number, const Elem *elem)
Computes the constraint matrix contributions (for meshes with periodic boundary conditions) correspon...
Definition fe_base.C:1892
virtual void print_dual_phi(std::ostream &os) const override
Definition fe_base.C:934
TensorTools::MakeNumber< OutputShape >::type OutputNumber
Definition fe_base.h:123
virtual void compute_shape_functions(const Elem *elem, const std::vector< Point > &qp) override
After having updated the jacobian and the transformation from local to global coordinates in FEMap::c...
Definition fe_base.C:786
virtual void print_dual_dphi(std::ostream &os) const override
Definition fe_base.C:953
void compute_dual_shape_functions()
Compute dual_phi, dual_dphi, dual_d2phi It is only valid for this to be called after reinit has occur...
Definition fe_base.h:830
static void dofs_on_side(const Elem *const elem, const unsigned int dim, const FEType &fe_t, unsigned int s, std::vector< unsigned int > &di, const bool add_p_level=true)
Fills the vector di with the local degree of freedom indices associated with side s of element elem A...
static unsigned int n_dofs(const unsigned int dim, const FEType &fe_t, const ElemType t)
static unsigned int n_dofs_at_node(const unsigned int dim, const FEType &fe_t, const ElemType t, const unsigned int n)
static void dofs_on_edge(const Elem *const elem, const unsigned int dim, const FEType &fe_t, unsigned int e, std::vector< unsigned int > &di, const bool add_p_level=true)
Fills the vector di with the local degree of freedom indices associated with edge e of element elem A...
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
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Definition fe_type.h:197
InfMapType inf_map
The coordinate mapping type of the infinite element.
Definition fe_type.h:284
std::unique_ptr< QBase > default_quadrature_rule(const unsigned int dim, const int extraorder=0) const
Definition fe_type.C:35
Order default_quadrature_order() const
Definition fe_type.h:415
OrderWrapper order
The approximation order of the element (at 0 p-refinement level).
Definition fe_type.h:203
bool p_refinement
Whether or not the finite elements for this type increase their p refinement level on geometric eleme...
Definition fe_type.h:292
FEFamily radial_family
The type of approximation in radial direction.
Definition fe_type.h:276
FEFamily family
The type of finite element.
Definition fe_type.h:228
This is the MeshBase class.
Definition mesh_base.h:81
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
Definition mesh_base.h:178
A Node is like a Point, but with more information.
Definition node.h:55
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
int get_order() const
Explicitly request the order as an int.
Definition fe_type.h:80
We're using a class instead of a typedef to allow forward declarations and future flexibility.
PeriodicBoundaryBase * boundary(boundary_id_type id)
const Elem * neighbor(boundary_id_type boundary_id, const PointLocatorBase &point_locator, const Elem *e, unsigned int side, unsigned int *neigh_side=nullptr) const
The base class for defining periodic boundaries.
const DenseMatrix< Real > & get_transformation_matrix() const
Get the transformation matrix, if it is defined.
bool is_my_variable(unsigned int var_num) const
const std::set< unsigned int > & get_variables() const
Get the set of variables for this periodic boundary condition.
virtual Point get_corresponding_pos(const Point &pt) const =0
This function should be overridden by derived classes to define how one finds corresponding nodes on ...
This is the base class for point locators.
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition point.h:41
unsigned int n_points() const
Definition quadrature.h:131
This class implements specific orders of Gauss quadrature.
bool absolute_fuzzy_equals(const TypeVector< T > &rhs, Real tol=TOLERANCE) const
This class defines the notion of a variable in the system.
Definition variable.h:51
bool active_on_subdomain(subdomain_id_type sid) const
Definition variable.h:167
const FEType & type() const
Definition variable.h:144
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
MeshBase & mesh
LIBMESH_DEVICE_INLINE std::enable_if< ScalarTraits< T >::value &&ScalarTraits< T2 >::value, typenameCompareTypes< T, T2 >::supertype >::type inner_product(const T &a, const T2 &b)
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.
@ SIDE_DISCONTINUOUS
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
libmesh_assert(ctx)
const Number zero
.
Definition libmesh.h:297
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
PetscErrorCode PetscInt const PetscInt IS * is
static constexpr Real TOLERANCE
uint8_t dof_id_type
Definition id_types.h:67
@ L2_RAVIART_THOMAS
@ L2_HIERARCHIC_VEC
@ RATIONAL_BERNSTEIN
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition int_range.h:176
const dof_id_type n_nodes
Definition tecplot_io.C:67