LCOV - code coverage report
Current view: top level - src/fe - fe_abstract.C (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4573 (924896) with base 3f0912 Lines: 449 627 71.6 %
Date: 2026-11-18 21:52:26 Functions: 7 13 53.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // The libMesh Finite Element Library.
       2             : // Copyright (C) 2002-2026 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
       3             : 
       4             : // This library is free software; you can redistribute it and/or
       5             : // modify it under the terms of the GNU Lesser General Public
       6             : // License as published by the Free Software Foundation; either
       7             : // version 2.1 of the License, or (at your option) any later version.
       8             : 
       9             : // This library is distributed in the hope that it will be useful,
      10             : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12             : // Lesser General Public License for more details.
      13             : 
      14             : // You should have received a copy of the GNU Lesser General Public
      15             : // License along with this library; if not, write to the Free Software
      16             : // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
      17             : 
      18             : // libmesh includes
      19             : #include "libmesh/fe.h"
      20             : #include "libmesh/libmesh_logging.h"
      21             : #include "libmesh/enum_elem_type.h"
      22             : #include "libmesh/boundary_info.h"
      23             : #include "libmesh/mesh_base.h"
      24             : #include "libmesh/dense_matrix.h"
      25             : #include "libmesh/dense_vector.h"
      26             : #include "libmesh/dof_map.h"
      27             : #include "libmesh/elem.h"
      28             : #include "libmesh/fe_interface.h"
      29             : #include "libmesh/numeric_vector.h"
      30             : #include "libmesh/periodic_boundaries.h"
      31             : #include "libmesh/periodic_boundary.h"
      32             : #include "libmesh/quadrature.h"
      33             : #include "libmesh/quadrature_gauss.h"
      34             : #include "libmesh/remote_elem.h"
      35             : #include "libmesh/tensor_value.h"
      36             : #include "libmesh/threads.h"
      37             : #include "libmesh/enum_to_string.h"
      38             : 
      39             : #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
      40             : #include "libmesh/inf_fe.h"
      41             : #include "libmesh/fe_interface_macros.h"
      42             : #endif
      43             : 
      44             : namespace libMesh
      45             : {
      46             : 
      47     2688307 : FEAbstract::FEAbstract(const unsigned int d,
      48     2688307 :                        const FEType & fet) :
      49     1205724 :   _fe_map( FEMap::build(fet) ),
      50     1205724 :   dim(d),
      51     1205724 :   calculations_started(false),
      52     1205724 :   calculate_dual(false),
      53     1205724 :   calculate_default_dual_coeff(true),
      54     1205724 :   calculate_nothing(false),
      55     1205724 :   calculate_map(false),
      56     1205724 :   calculate_phi(false),
      57     1205724 :   calculate_dphi(false),
      58     1205724 :   calculate_d2phi(false),
      59     1205724 :   calculate_curl_phi(false),
      60     1205724 :   calculate_div_phi(false),
      61     1205724 :   calculate_dphiref(false),
      62     1205724 :   fe_type(fet),
      63     1205724 :   _elem_type(INVALID_ELEM),
      64     1205724 :   _elem(nullptr),
      65     1205724 :   _elem_p_level(0),
      66     1205724 :   _p_level(0),
      67     1205724 :   qrule(nullptr),
      68     1205724 :   shapes_on_quadrature(false),
      69     1205724 :   _n_total_qp(0),
      70     2688307 :   _add_p_level_in_reinit(fet.p_refinement)
      71             : {
      72     2688307 : }
      73             : 
      74             : 
      75     1205724 : FEAbstract::~FEAbstract() = default;
      76             : 
      77             : 
      78      783252 : std::unique_ptr<FEAbstract> FEAbstract::build(const unsigned int dim,
      79             :                                               const FEType & fet)
      80             : {
      81      783252 :   switch (dim)
      82             :     {
      83             :       // 0D
      84        6478 :     case 0:
      85             :       {
      86        6478 :         switch (fet.family)
      87             :           {
      88           0 :           case CLOUGH:
      89           0 :             return std::make_unique<FE<0,CLOUGH>>(fet);
      90             : 
      91           0 :           case HERMITE:
      92           0 :             return std::make_unique<FE<0,HERMITE>>(fet);
      93             : 
      94        3774 :           case LAGRANGE:
      95        3774 :             return std::make_unique<FE<0,LAGRANGE>>(fet);
      96             : 
      97           0 :           case LAGRANGE_VEC:
      98           0 :             return std::make_unique<FE<0,LAGRANGE_VEC>>(fet);
      99             : 
     100          72 :           case L2_LAGRANGE:
     101          72 :             return std::make_unique<FE<0,L2_LAGRANGE>>(fet);
     102             : 
     103           0 :           case L2_LAGRANGE_GLL:
     104           0 :             return std::make_unique<FE<0,L2_LAGRANGE_GLL>>(fet);
     105             : 
     106           0 :           case LAGRANGE_GLL:
     107           0 :             return std::make_unique<FE<0,LAGRANGE_GLL>>(fet);
     108             : 
     109          72 :           case L2_LAGRANGE_VEC:
     110          72 :             return std::make_unique<FE<0,L2_LAGRANGE_VEC>>(fet);
     111             : 
     112           0 :           case HIERARCHIC_VEC:
     113           0 :             return std::make_unique<FE<0,HIERARCHIC_VEC>>(fet);
     114             : 
     115           0 :           case HIERARCHIC:
     116           0 :             return std::make_unique<FE<0,HIERARCHIC>>(fet);
     117             : 
     118         112 :           case L2_HIERARCHIC:
     119         112 :             return std::make_unique<FE<0,L2_HIERARCHIC>>(fet);
     120             : 
     121           0 :           case L2_HIERARCHIC_VEC:
     122           0 :             return std::make_unique<FE<0,L2_HIERARCHIC_VEC>>(fet);
     123             : 
     124          72 :           case SIDE_HIERARCHIC:
     125          72 :             return std::make_unique<FE<0,SIDE_HIERARCHIC>>(fet);
     126             : 
     127         360 :           case MONOMIAL:
     128         360 :             return std::make_unique<FE<0,MONOMIAL>>(fet);
     129             : 
     130           0 :           case MONOMIAL_VEC:
     131           0 :             return std::make_unique<FE<0,MONOMIAL_VEC>>(fet);
     132             : 
     133             : #ifdef LIBMESH_ENABLE_HIGHER_ORDER_SHAPES
     134           0 :           case SZABAB:
     135           0 :             return std::make_unique<FE<0,SZABAB>>(fet);
     136             : 
     137           0 :           case BERNSTEIN:
     138           0 :             return std::make_unique<FE<0,BERNSTEIN>>(fet);
     139             : 
     140        1308 :           case RATIONAL_BERNSTEIN:
     141        1308 :             return std::make_unique<FE<0,RATIONAL_BERNSTEIN>>(fet);
     142             : #endif
     143             : 
     144           0 :           case XYZ:
     145           0 :             return std::make_unique<FEXYZ<0>>(fet);
     146             : 
     147         404 :           case SCALAR:
     148         404 :             return std::make_unique<FEScalar<0>>(fet);
     149             : 
     150           0 :           case NEDELEC_ONE:
     151           0 :             return std::make_unique<FENedelecOne<0>>(fet);
     152             : 
     153         304 :           case RAVIART_THOMAS:
     154         304 :             return std::make_unique<FERaviartThomas<0>>(fet);
     155             : 
     156           0 :           case L2_RAVIART_THOMAS:
     157           0 :             return std::make_unique<FEL2RaviartThomas<0>>(fet);
     158             : 
     159           0 :           case SUBDIVISION:
     160           0 :             return std::make_unique<FESubdivision>(fet);
     161             : 
     162           0 :           default:
     163           0 :             libmesh_error_msg("ERROR: Bad FEType.family= " << Utility::enum_to_string(fet.family));
     164             :           }
     165             :       }
     166             :       // 1D
     167       88326 :     case 1:
     168             :       {
     169       88326 :         switch (fet.family)
     170             :           {
     171           0 :           case CLOUGH:
     172           0 :             return std::make_unique<FE<1,CLOUGH>>(fet);
     173             : 
     174       14208 :           case HERMITE:
     175       14208 :             return std::make_unique<FE<1,HERMITE>>(fet);
     176             : 
     177        8732 :           case LAGRANGE:
     178        8732 :             return std::make_unique<FE<1,LAGRANGE>>(fet);
     179             : 
     180           0 :           case LAGRANGE_VEC:
     181           0 :             return std::make_unique<FE<1,LAGRANGE_VEC>>(fet);
     182             : 
     183        3276 :           case L2_LAGRANGE:
     184        3276 :             return std::make_unique<FE<1,L2_LAGRANGE>>(fet);
     185             : 
     186       13104 :           case L2_LAGRANGE_GLL:
     187       13104 :             return std::make_unique<FE<1,L2_LAGRANGE_GLL>>(fet);
     188             : 
     189        5460 :           case LAGRANGE_GLL:
     190        5460 :             return std::make_unique<FE<1,LAGRANGE_GLL>>(fet);
     191             : 
     192           0 :           case L2_LAGRANGE_VEC:
     193           0 :             return std::make_unique<FE<1,L2_LAGRANGE_VEC>>(fet);
     194             : 
     195           0 :           case HIERARCHIC_VEC:
     196           0 :             return std::make_unique<FE<1,HIERARCHIC_VEC>>(fet);
     197             : 
     198       12094 :           case HIERARCHIC:
     199       12094 :             return std::make_unique<FE<1,HIERARCHIC>>(fet);
     200             : 
     201        5460 :           case L2_HIERARCHIC:
     202        5460 :             return std::make_unique<FE<1,L2_HIERARCHIC>>(fet);
     203             : 
     204           0 :           case L2_HIERARCHIC_VEC:
     205           0 :             return std::make_unique<FE<1,L2_HIERARCHIC_VEC>>(fet);
     206             : 
     207        2574 :           case SIDE_HIERARCHIC:
     208        2574 :             return std::make_unique<FE<1,SIDE_HIERARCHIC>>(fet);
     209             : 
     210        7038 :           case MONOMIAL:
     211        7038 :             return std::make_unique<FE<1,MONOMIAL>>(fet);
     212             : 
     213           0 :           case MONOMIAL_VEC:
     214           0 :             return std::make_unique<FE<1,MONOMIAL_VEC>>(fet);
     215             : 
     216             : #ifdef LIBMESH_ENABLE_HIGHER_ORDER_SHAPES
     217        4368 :           case SZABAB:
     218        4368 :             return std::make_unique<FE<1,SZABAB>>(fet);
     219             : 
     220        5460 :           case BERNSTEIN:
     221        5460 :             return std::make_unique<FE<1,BERNSTEIN>>(fet);
     222             : 
     223        2184 :           case RATIONAL_BERNSTEIN:
     224        2184 :             return std::make_unique<FE<1,RATIONAL_BERNSTEIN>>(fet);
     225             : #endif
     226             : 
     227        4368 :           case XYZ:
     228        4368 :             return std::make_unique<FEXYZ<1>>(fet);
     229             : 
     230           0 :           case SCALAR:
     231           0 :             return std::make_unique<FEScalar<1>>(fet);
     232             : 
     233           0 :           case NEDELEC_ONE:
     234           0 :             return std::make_unique<FENedelecOne<1>>(fet);
     235             : 
     236           0 :           case RAVIART_THOMAS:
     237           0 :             return std::make_unique<FERaviartThomas<1>>(fet);
     238             : 
     239           0 :           case L2_RAVIART_THOMAS:
     240           0 :             return std::make_unique<FEL2RaviartThomas<1>>(fet);
     241             : 
     242           0 :           case SUBDIVISION:
     243           0 :             return std::make_unique<FESubdivision>(fet);
     244             : 
     245           0 :           default:
     246           0 :             libmesh_error_msg("ERROR: Bad FEType.family= " << Utility::enum_to_string(fet.family));
     247             :           }
     248             :       }
     249             : 
     250             : 
     251             :       // 2D
     252      380659 :     case 2:
     253             :       {
     254      380659 :         switch (fet.family)
     255             :           {
     256        6958 :           case CLOUGH:
     257        6958 :             return std::make_unique<FE<2,CLOUGH>>(fet);
     258             : 
     259        6272 :           case HERMITE:
     260        6272 :             return std::make_unique<FE<2,HERMITE>>(fet);
     261             : 
     262      186069 :           case LAGRANGE:
     263      186069 :             return std::make_unique<FE<2,LAGRANGE>>(fet);
     264             : 
     265        6048 :           case LAGRANGE_VEC:
     266        6048 :             return std::make_unique<FE<2,LAGRANGE_VEC>>(fet);
     267             : 
     268       11400 :           case L2_LAGRANGE:
     269       11400 :             return std::make_unique<FE<2,L2_LAGRANGE>>(fet);
     270             : 
     271       13104 :           case L2_LAGRANGE_GLL:
     272       13104 :             return std::make_unique<FE<2,L2_LAGRANGE_GLL>>(fet);
     273             : 
     274        5694 :           case LAGRANGE_GLL:
     275        5694 :             return std::make_unique<FE<2,LAGRANGE_GLL>>(fet);
     276             : 
     277         396 :           case L2_LAGRANGE_VEC:
     278         396 :             return std::make_unique<FE<2,L2_LAGRANGE_VEC>>(fet);
     279             : 
     280           0 :           case HIERARCHIC_VEC:
     281           0 :             return std::make_unique<FE<2,HIERARCHIC_VEC>>(fet);
     282             : 
     283       45368 :           case HIERARCHIC:
     284       45368 :             return std::make_unique<FE<2,HIERARCHIC>>(fet);
     285             : 
     286       15092 :           case L2_HIERARCHIC:
     287       15092 :             return std::make_unique<FE<2,L2_HIERARCHIC>>(fet);
     288             : 
     289         336 :           case L2_HIERARCHIC_VEC:
     290         336 :             return std::make_unique<FE<2,L2_HIERARCHIC_VEC>>(fet);
     291             : 
     292        9192 :           case SIDE_HIERARCHIC:
     293        9192 :             return std::make_unique<FE<2,SIDE_HIERARCHIC>>(fet);
     294             : 
     295       26780 :           case MONOMIAL:
     296       26780 :             return std::make_unique<FE<2,MONOMIAL>>(fet);
     297             : 
     298         168 :           case MONOMIAL_VEC:
     299         168 :             return std::make_unique<FE<2,MONOMIAL_VEC>>(fet);
     300             : 
     301             : #ifdef LIBMESH_ENABLE_HIGHER_ORDER_SHAPES
     302       12168 :           case SZABAB:
     303       12168 :             return std::make_unique<FE<2,SZABAB>>(fet);
     304             : 
     305       12012 :           case BERNSTEIN:
     306       12012 :             return std::make_unique<FE<2,BERNSTEIN>>(fet);
     307             : 
     308        4384 :           case RATIONAL_BERNSTEIN:
     309        4384 :             return std::make_unique<FE<2,RATIONAL_BERNSTEIN>>(fet);
     310             : #endif
     311             : 
     312       17952 :           case XYZ:
     313       17952 :             return std::make_unique<FEXYZ<2>>(fet);
     314             : 
     315         324 :           case SCALAR:
     316         324 :             return std::make_unique<FEScalar<2>>(fet);
     317             : 
     318         258 :           case NEDELEC_ONE:
     319         258 :             return std::make_unique<FENedelecOne<2>>(fet);
     320             : 
     321         520 :           case RAVIART_THOMAS:
     322         520 :             return std::make_unique<FERaviartThomas<2>>(fet);
     323             : 
     324         164 :           case L2_RAVIART_THOMAS:
     325         164 :             return std::make_unique<FEL2RaviartThomas<2>>(fet);
     326             : 
     327           0 :           case SUBDIVISION:
     328           0 :             return std::make_unique<FESubdivision>(fet);
     329             : 
     330           0 :           default:
     331           0 :             libmesh_error_msg("ERROR: Bad FEType.family= " << Utility::enum_to_string(fet.family));
     332             :           }
     333             :       }
     334             : 
     335             : 
     336             :       // 3D
     337      307789 :     case 3:
     338             :       {
     339      307789 :         switch (fet.family)
     340             :           {
     341           0 :           case CLOUGH:
     342           0 :             libmesh_error_msg("ERROR: Clough-Tocher elements currently only support 1D and 2D");
     343             : 
     344        1638 :           case HERMITE:
     345        1638 :             return std::make_unique<FE<3,HERMITE>>(fet);
     346             : 
     347       61706 :           case LAGRANGE:
     348       61706 :             return std::make_unique<FE<3,LAGRANGE>>(fet);
     349             : 
     350        9156 :           case LAGRANGE_VEC:
     351        9156 :             return std::make_unique<FE<3,LAGRANGE_VEC>>(fet);
     352             : 
     353       23576 :           case L2_LAGRANGE:
     354       23576 :             return std::make_unique<FE<3,L2_LAGRANGE>>(fet);
     355             : 
     356       19656 :           case L2_LAGRANGE_GLL:
     357       19656 :             return std::make_unique<FE<3,L2_LAGRANGE_GLL>>(fet);
     358             : 
     359        6903 :           case LAGRANGE_GLL:
     360        6903 :             return std::make_unique<FE<3,LAGRANGE_GLL>>(fet);
     361             : 
     362         252 :           case L2_LAGRANGE_VEC:
     363         252 :             return std::make_unique<FE<3,L2_LAGRANGE_VEC>>(fet);
     364             : 
     365           0 :           case HIERARCHIC_VEC:
     366           0 :             return std::make_unique<FE<3,HIERARCHIC_VEC>>(fet);
     367             : 
     368       30645 :           case HIERARCHIC:
     369       30645 :             return std::make_unique<FE<3,HIERARCHIC>>(fet);
     370             : 
     371       32025 :           case L2_HIERARCHIC:
     372       32025 :             return std::make_unique<FE<3,L2_HIERARCHIC>>(fet);
     373             : 
     374         126 :           case L2_HIERARCHIC_VEC:
     375         126 :             return std::make_unique<FE<3,L2_HIERARCHIC_VEC>>(fet);
     376             : 
     377       12870 :           case SIDE_HIERARCHIC:
     378       12870 :             return std::make_unique<FE<3,SIDE_HIERARCHIC>>(fet);
     379             : 
     380       50619 :           case MONOMIAL:
     381       50619 :             return std::make_unique<FE<3,MONOMIAL>>(fet);
     382             : 
     383           0 :           case MONOMIAL_VEC:
     384           0 :             return std::make_unique<FE<3,MONOMIAL_VEC>>(fet);
     385             : 
     386             : #ifdef LIBMESH_ENABLE_HIGHER_ORDER_SHAPES
     387           0 :           case SZABAB:
     388           0 :             return std::make_unique<FE<3,SZABAB>>(fet);
     389             : 
     390       11466 :           case BERNSTEIN:
     391       11466 :             return std::make_unique<FE<3,BERNSTEIN>>(fet);
     392             : 
     393        5214 :           case RATIONAL_BERNSTEIN:
     394        5214 :             return std::make_unique<FE<3,RATIONAL_BERNSTEIN>>(fet);
     395             : #endif
     396             : 
     397       41202 :           case XYZ:
     398       41202 :             return std::make_unique<FEXYZ<3>>(fet);
     399             : 
     400         120 :           case SCALAR:
     401         120 :             return std::make_unique<FEScalar<3>>(fet);
     402             : 
     403         234 :           case NEDELEC_ONE:
     404         234 :             return std::make_unique<FENedelecOne<3>>(fet);
     405             : 
     406         258 :           case RAVIART_THOMAS:
     407         258 :             return std::make_unique<FERaviartThomas<3>>(fet);
     408             : 
     409         123 :           case L2_RAVIART_THOMAS:
     410         123 :             return std::make_unique<FEL2RaviartThomas<3>>(fet);
     411             : 
     412           0 :           default:
     413           0 :             libmesh_error_msg("ERROR: Bad FEType.family= " << Utility::enum_to_string(fet.family));
     414             :           }
     415             :       }
     416             : 
     417           0 :     default:
     418           0 :       libmesh_error_msg("Invalid dimension dim = " << dim);
     419             :     }
     420             : }
     421             : 
     422             : 
     423             : 
     424    11381703 : void FEAbstract::get_refspace_nodes(const ElemType itemType, std::vector<Point> & nodes)
     425             : {
     426    11381703 :   const unsigned int n_nodes = Elem::type_to_n_nodes_map[itemType];
     427    11381703 :   if (n_nodes == invalid_uint)
     428           0 :     libmesh_error_msg("Number of nodes is not well-defined for " <<
     429             :                       Utility::enum_to_string(itemType));
     430             : 
     431    11381703 :   nodes.resize(n_nodes);
     432    11381703 :   switch(itemType)
     433             :     {
     434       28512 :     case NODEELEM:
     435             :       {
     436      114048 :         nodes[0] = Point (0.,0.,0.);
     437      114048 :         return;
     438             :       }
     439        6676 :     case EDGE3:
     440             :       {
     441       26696 :         nodes[2] = Point (0.,0.,0.);
     442             :         libmesh_fallthrough();
     443             :       }
     444     1913002 :     case EDGE2:
     445             :       {
     446     1913002 :         nodes[0] = Point (-1.,0.,0.);
     447     1913002 :         nodes[1] = Point (1.,0.,0.);
     448     1913002 :         return;
     449             :       }
     450           6 :     case EDGE4: // not nested with EDGE3
     451             :       {
     452          24 :         nodes[0] = Point (-1.,0.,0.);
     453          24 :         nodes[1] = Point (1.,0.,0.);
     454          24 :         nodes[2] = Point (-1./3.,0.,0.);
     455          24 :         nodes[3] = Point (1./3.,0.,0.);
     456          24 :         return;
     457             :       }
     458      124289 :     case TRI7:
     459             :       {
     460      498398 :         nodes[6] = Point (1./3.,1./3.,0.);
     461             :         libmesh_fallthrough();
     462             :       }
     463     1914249 :     case TRI6:
     464             :       {
     465     1914249 :         nodes[3] = Point (.5,0.,0.);
     466     1914249 :         nodes[4] = Point (.5,.5,0.);
     467     1914249 :         nodes[5] = Point (0.,.5,0.);
     468             :         libmesh_fallthrough();
     469             :       }
     470     2692964 :     case TRI3:
     471             :     case TRISHELL3:
     472             :       {
     473     2692964 :         nodes[0] = Point (0.,0.,0.);
     474     2692964 :         nodes[1] = Point (1.,0.,0.);
     475     2692964 :         nodes[2] = Point (0.,1.,0.);
     476     2692964 :         return;
     477             :       }
     478      195257 :     case QUAD9:
     479             :     case QUADSHELL9:
     480             :       {
     481      691413 :         nodes[8] = Point (0.,0.,0.);
     482             :         libmesh_fallthrough();
     483             :       }
     484      729552 :     case QUAD8:
     485             :     case QUADSHELL8:
     486             :       {
     487      729552 :         nodes[4] = Point (0.,-1.,0.);
     488      729552 :         nodes[5] = Point (1.,0.,0.);
     489      729552 :         nodes[6] = Point (0.,1.,0.);
     490      729552 :         nodes[7] = Point (-1.,0.,0.);
     491             :         libmesh_fallthrough();
     492             :       }
     493     2064913 :     case QUAD4:
     494             :     case QUADSHELL4:
     495             :       {
     496     2064913 :         nodes[0] = Point (-1.,-1.,0.);
     497     2064913 :         nodes[1] = Point (1.,-1.,0.);
     498     2064913 :         nodes[2] = Point (1.,1.,0.);
     499     2064913 :         nodes[3] = Point (-1.,1.,0.);
     500     2064913 :         return;
     501             :       }
     502      998148 :     case TET14:
     503             :       {
     504     3999856 :         nodes[10] = Point (1/Real(3),1/Real(3),0.);
     505     3999856 :         nodes[11] = Point (1/Real(3),0.,1/Real(3));
     506     3999856 :         nodes[12] = Point (1/Real(3),1/Real(3),1/Real(3));
     507     3999856 :         nodes[13] = Point (0.,1/Real(3),1/Real(3));
     508             :         libmesh_fallthrough();
     509             :       }
     510     4018082 :     case TET10:
     511             :       {
     512     4018082 :         nodes[4] = Point (.5,0.,0.);
     513     4018082 :         nodes[5] = Point (.5,.5,0.);
     514     4018082 :         nodes[6] = Point (0.,.5,0.);
     515     4018082 :         nodes[7] = Point (0.,0.,.5);
     516     4018082 :         nodes[8] = Point (.5,0.,.5);
     517     4018082 :         nodes[9] = Point (0.,.5,.5);
     518             :         libmesh_fallthrough();
     519             :       }
     520     4018680 :     case TET4:
     521             :       {
     522     4018680 :         nodes[0] = Point (0.,0.,0.);
     523     4018680 :         nodes[1] = Point (1.,0.,0.);
     524     4018680 :         nodes[2] = Point (0.,1.,0.);
     525     4018680 :         nodes[3] = Point (0.,0.,1.);
     526     4018680 :         return;
     527             :       }
     528       37569 :     case HEX27:
     529             :       {
     530      153346 :         nodes[20] = Point (0.,0.,-1.);
     531      153346 :         nodes[21] = Point (0.,-1.,0.);
     532      153346 :         nodes[22] = Point (1.,0.,0.);
     533      153346 :         nodes[23] = Point (0.,1.,0.);
     534      153346 :         nodes[24] = Point (-1.,0.,0.);
     535      153346 :         nodes[25] = Point (0.,0.,1.);
     536      153346 :         nodes[26] = Point (0.,0.,0.);
     537             :         libmesh_fallthrough();
     538             :       }
     539      155036 :     case HEX20:
     540             :       {
     541      155036 :         nodes[8] = Point (0.,-1.,-1.);
     542      155036 :         nodes[9] = Point (1.,0.,-1.);
     543      155036 :         nodes[10] = Point (0.,1.,-1.);
     544      155036 :         nodes[11] = Point (-1.,0.,-1.);
     545      155036 :         nodes[12] = Point (-1.,-1.,0.);
     546      155036 :         nodes[13] = Point (1.,-1.,0.);
     547      155036 :         nodes[14] = Point (1.,1.,0.);
     548      155036 :         nodes[15] = Point (-1.,1.,0.);
     549      155036 :         nodes[16] = Point (0.,-1.,1.);
     550      155036 :         nodes[17] = Point (1.,0.,1.);
     551      155036 :         nodes[18] = Point (0.,1.,1.);
     552      155036 :         nodes[19] = Point (-1.,0.,1.);
     553             :         libmesh_fallthrough();
     554             :       }
     555      491914 :     case HEX8:
     556             :       {
     557      491914 :         nodes[0] = Point (-1.,-1.,-1.);
     558      491914 :         nodes[1] = Point (1.,-1.,-1.);
     559      491914 :         nodes[2] = Point (1.,1.,-1.);
     560      491914 :         nodes[3] = Point (-1.,1.,-1.);
     561      491914 :         nodes[4] = Point (-1.,-1.,1.);
     562      491914 :         nodes[5] = Point (1.,-1.,1.);
     563      491914 :         nodes[6] = Point (1.,1.,1.);
     564      491914 :         nodes[7] = Point (-1.,1.,1.);
     565      491914 :         return;
     566             :       }
     567        8062 :     case PRISM21:
     568             :       {
     569       31919 :         nodes[20] = Point (1/Real(3),1/Real(3),0);
     570             :         libmesh_fallthrough();
     571             :       }
     572       50425 :     case PRISM20:
     573             :       {
     574       50425 :         nodes[18] = Point (1/Real(3),1/Real(3),-1);
     575       50425 :         nodes[19] = Point (1/Real(3),1/Real(3),1);
     576             :         libmesh_fallthrough();
     577             :       }
     578       77503 :     case PRISM18:
     579             :       {
     580       77503 :         nodes[15] = Point (.5,0.,0.);
     581       77503 :         nodes[16] = Point (.5,.5,0.);
     582       77503 :         nodes[17] = Point (0.,.5,0.);
     583             :         libmesh_fallthrough();
     584             :       }
     585       77615 :     case PRISM15:
     586             :       {
     587       77615 :         nodes[6] = Point (.5,0.,-1.);
     588       77615 :         nodes[7] = Point (.5,.5,-1.);
     589       77615 :         nodes[8] = Point (0.,.5,-1.);
     590       77615 :         nodes[9] = Point (0.,0.,0.);
     591       77615 :         nodes[10] = Point (1.,0.,0.);
     592       77615 :         nodes[11] = Point (0.,1.,0.);
     593       77615 :         nodes[12] = Point (.5,0.,1.);
     594       77615 :         nodes[13] = Point (.5,.5,1.);
     595       77615 :         nodes[14] = Point (0.,.5,1.);
     596             :         libmesh_fallthrough();
     597             :       }
     598       86018 :     case PRISM6:
     599             :       {
     600       86018 :         nodes[0] = Point (0.,0.,-1.);
     601       86018 :         nodes[1] = Point (1.,0.,-1.);
     602       86018 :         nodes[2] = Point (0.,1.,-1.);
     603       86018 :         nodes[3] = Point (0.,0.,1.);
     604       86018 :         nodes[4] = Point (1.,0.,1.);
     605       86018 :         nodes[5] = Point (0.,1.,1.);
     606       86018 :         return;
     607             :       }
     608          14 :     case PYRAMID18:
     609             :       {
     610             :         // triangle centers
     611          49 :         nodes[14] = Point (0., -2/Real(3),1/Real(3));
     612          49 :         nodes[15] = Point (2/Real(3),0.,1/Real(3));
     613          49 :         nodes[16] = Point (0.,2/Real(3),1/Real(3));
     614          49 :         nodes[17] = Point (-2/Real(3),0.,1/Real(3));
     615             : 
     616             :         libmesh_fallthrough();
     617             :       }
     618          91 :     case PYRAMID14:
     619             :       {
     620             :         // base center
     621          91 :         nodes[13] = Point (0.,0.,0.);
     622             : 
     623             :         libmesh_fallthrough();
     624             :       }
     625         133 :     case PYRAMID13:
     626             :       {
     627             :         // base midedge
     628         133 :         nodes[5] = Point (0.,-1.,0.);
     629         133 :         nodes[6] = Point (1.,0.,0.);
     630         133 :         nodes[7] = Point (0.,1.,0.);
     631         133 :         nodes[8] = Point (-1,0.,0.);
     632             : 
     633             :         // lateral midedge
     634         133 :         nodes[9] = Point (-.5,-.5,.5);
     635         133 :         nodes[10] = Point (.5,-.5,.5);
     636         133 :         nodes[11] = Point (.5,.5,.5);
     637         133 :         nodes[12] = Point (-.5,.5,.5);
     638             : 
     639             :         libmesh_fallthrough();
     640             :       }
     641         140 :     case PYRAMID5:
     642             :       {
     643             :         // base corners
     644         140 :         nodes[0] = Point (-1.,-1.,0.);
     645         140 :         nodes[1] = Point (1.,-1.,0.);
     646         140 :         nodes[2] = Point (1.,1.,0.);
     647         140 :         nodes[3] = Point (-1.,1.,0.);
     648             :         // apex
     649         140 :         nodes[4] = Point (0.,0.,1.);
     650         140 :         return;
     651             :       }
     652             : 
     653           0 :     default:
     654           0 :       libmesh_error_msg("ERROR: Unknown element type " << Utility::enum_to_string(itemType));
     655             :     }
     656             : }
     657             : 
     658             : 
     659             : 
     660             : #ifdef LIBMESH_ENABLE_DEPRECATED
     661           0 : bool FEAbstract::on_reference_element(const Point & p, const ElemType t, const Real eps)
     662             : {
     663             :   // Use Elem::on_reference_element() instead
     664             :   libmesh_deprecated();
     665             : 
     666           0 :   libmesh_assert_greater_equal (eps, 0.);
     667             : 
     668           0 :   const Real xi   = p(0);
     669             : #if LIBMESH_DIM > 1
     670           0 :   const Real eta  = p(1);
     671             : #else
     672             :   const Real eta  = 0.;
     673             : #endif
     674             : #if LIBMESH_DIM > 2
     675           0 :   const Real zeta = p(2);
     676             : #else
     677             :   const Real zeta  = 0.;
     678             : #endif
     679             : 
     680           0 :   switch (t)
     681             :     {
     682           0 :     case NODEELEM:
     683             :       {
     684           0 :         return (!xi && !eta && !zeta);
     685             :       }
     686           0 :     case EDGE2:
     687             :     case EDGE3:
     688             :     case EDGE4:
     689             :       {
     690             :         // The reference 1D element is [-1,1].
     691           0 :         if ((xi >= -1.-eps) &&
     692           0 :             (xi <=  1.+eps))
     693           0 :           return true;
     694             : 
     695           0 :         return false;
     696             :       }
     697             : 
     698             : 
     699           0 :     case TRI3:
     700             :     case TRISHELL3:
     701             :     case TRI6:
     702             :     case TRI7:
     703             :       {
     704             :         // The reference triangle is isosceles
     705             :         // and is bound by xi=0, eta=0, and xi+eta=1.
     706           0 :         if ((xi  >= 0.-eps) &&
     707           0 :             (eta >= 0.-eps) &&
     708           0 :             ((xi + eta) <= 1.+eps))
     709           0 :           return true;
     710             : 
     711           0 :         return false;
     712             :       }
     713             : 
     714             : 
     715           0 :     case QUAD4:
     716             :     case QUADSHELL4:
     717             :     case QUAD8:
     718             :     case QUADSHELL8:
     719             :     case QUAD9:
     720             :     case QUADSHELL9:
     721             :       {
     722             :         // The reference quadrilateral element is [-1,1]^2.
     723           0 :         if ((xi  >= -1.-eps) &&
     724           0 :             (xi  <=  1.+eps) &&
     725           0 :             (eta >= -1.-eps) &&
     726           0 :             (eta <=  1.+eps))
     727           0 :           return true;
     728             : 
     729           0 :         return false;
     730             :       }
     731             : 
     732             : 
     733           0 :     case TET4:
     734             :     case TET10:
     735             :     case TET14:
     736             :       {
     737             :         // The reference tetrahedral is isosceles
     738             :         // and is bound by xi=0, eta=0, zeta=0,
     739             :         // and xi+eta+zeta=1.
     740           0 :         if ((xi   >= 0.-eps) &&
     741           0 :             (eta  >= 0.-eps) &&
     742           0 :             (zeta >= 0.-eps) &&
     743           0 :             ((xi + eta + zeta) <= 1.+eps))
     744           0 :           return true;
     745             : 
     746           0 :         return false;
     747             :       }
     748             : 
     749             : 
     750           0 :     case HEX8:
     751             :     case HEX20:
     752             :     case HEX27:
     753             :       {
     754             :         /*
     755             :           if ((xi   >= -1.) &&
     756             :           (xi   <=  1.) &&
     757             :           (eta  >= -1.) &&
     758             :           (eta  <=  1.) &&
     759             :           (zeta >= -1.) &&
     760             :           (zeta <=  1.))
     761             :           return true;
     762             :         */
     763             : 
     764             :         // The reference hexahedral element is [-1,1]^3.
     765           0 :         if ((xi   >= -1.-eps) &&
     766           0 :             (xi   <=  1.+eps) &&
     767           0 :             (eta  >= -1.-eps) &&
     768           0 :             (eta  <=  1.+eps) &&
     769           0 :             (zeta >= -1.-eps) &&
     770           0 :             (zeta <=  1.+eps))
     771             :           {
     772             :             //    libMesh::out << "Strange Point:\n";
     773             :             //    p.print();
     774           0 :             return true;
     775             :           }
     776             : 
     777           0 :         return false;
     778             :       }
     779             : 
     780           0 :     case PRISM6:
     781             :     case PRISM15:
     782             :     case PRISM18:
     783             :     case PRISM20:
     784             :     case PRISM21:
     785             :       {
     786             :         // Figure this one out...
     787             :         // inside the reference triangle with zeta in [-1,1]
     788           0 :         if ((xi   >=  0.-eps) &&
     789           0 :             (eta  >=  0.-eps) &&
     790           0 :             (zeta >= -1.-eps) &&
     791           0 :             (zeta <=  1.+eps) &&
     792           0 :             ((xi + eta) <= 1.+eps))
     793           0 :           return true;
     794             : 
     795           0 :         return false;
     796             :       }
     797             : 
     798             : 
     799           0 :     case PYRAMID5:
     800             :     case PYRAMID13:
     801             :     case PYRAMID14:
     802             :     case PYRAMID18:
     803             :       {
     804             :         // Check that the point is on the same side of all the faces
     805             :         // by testing whether:
     806             :         //
     807             :         // n_i.(x - x_i) <= 0
     808             :         //
     809             :         // for each i, where:
     810             :         //   n_i is the outward normal of face i,
     811             :         //   x_i is a point on face i.
     812           0 :         if ((-eta - 1. + zeta <= 0.+eps) &&
     813           0 :             (  xi - 1. + zeta <= 0.+eps) &&
     814           0 :             ( eta - 1. + zeta <= 0.+eps) &&
     815           0 :             ( -xi - 1. + zeta <= 0.+eps) &&
     816           0 :             (            zeta >= 0.-eps))
     817           0 :           return true;
     818             : 
     819           0 :         return false;
     820             :       }
     821             : 
     822             : #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
     823           0 :     case INFHEX8:
     824             :     case INFHEX16:
     825             :     case INFHEX18:
     826             :       {
     827             :         // The reference infhex8 is a [-1,1]^3.
     828           0 :         if ((xi   >= -1.-eps) &&
     829           0 :             (xi   <=  1.+eps) &&
     830           0 :             (eta  >= -1.-eps) &&
     831           0 :             (eta  <=  1.+eps) &&
     832           0 :             (zeta >= -1.-eps) &&
     833           0 :             (zeta <=  1.+eps))
     834             :           {
     835           0 :             return true;
     836             :           }
     837           0 :         return false;
     838             :       }
     839             : 
     840           0 :     case INFPRISM6:
     841             :     case INFPRISM12:
     842             :       {
     843             :         // inside the reference triangle with zeta in [-1,1]
     844           0 :         if ((xi   >=  0.-eps) &&
     845           0 :             (eta  >=  0.-eps) &&
     846           0 :             (zeta >= -1.-eps) &&
     847           0 :             (zeta <=  1.+eps) &&
     848           0 :             ((xi + eta) <= 1.+eps))
     849             :           {
     850           0 :             return true;
     851             :           }
     852             : 
     853           0 :         return false;
     854             :       }
     855             : #endif
     856             : 
     857           0 :     default:
     858           0 :       libmesh_error_msg("ERROR: Unknown element type " << Utility::enum_to_string(t));
     859             :     }
     860             : 
     861             :   // If we get here then the point is _not_ in the
     862             :   // reference element.   Better return false.
     863             : 
     864             :   return false;
     865             : }
     866             : #endif // LIBMESH_ENABLE_DEPRECATED
     867             : 
     868             : 
     869             : 
     870           0 : void FEAbstract::print_JxW(std::ostream & os) const
     871             : {
     872           0 :   this->_fe_map->print_JxW(os);
     873           0 : }
     874             : 
     875             : 
     876             : 
     877           0 : void FEAbstract::print_xyz(std::ostream & os) const
     878             : {
     879           0 :   this->_fe_map->print_xyz(os);
     880           0 : }
     881             : 
     882             : 
     883           0 : void FEAbstract::print_info(std::ostream & os) const
     884             : {
     885           0 :   os << "phi[i][j]: Shape function i at quadrature pt. j" << std::endl;
     886           0 :   this->print_phi(os);
     887             : 
     888           0 :   os << "dphi[i][j]: Shape function i's gradient at quadrature pt. j" << std::endl;
     889           0 :   this->print_dphi(os);
     890             : 
     891           0 :   os << "XYZ locations of the quadrature pts." << std::endl;
     892           0 :   this->print_xyz(os);
     893             : 
     894           0 :   os << "Values of JxW at the quadrature pts." << std::endl;
     895           0 :   this->print_JxW(os);
     896           0 : }
     897             : 
     898             : 
     899           0 : std::ostream & operator << (std::ostream & os, const FEAbstract & fe)
     900             : {
     901           0 :   fe.print_info(os);
     902           0 :   return os;
     903             : }
     904             : 
     905             : 
     906             : 
     907             : #ifdef LIBMESH_ENABLE_AMR
     908             : 
     909             : #ifdef LIBMESH_ENABLE_NODE_CONSTRAINTS
     910     1042482 : void FEAbstract::compute_node_constraints (NodeConstraints & constraints,
     911             :                                            const Elem * elem)
     912             : {
     913      521241 :   libmesh_assert(elem);
     914             : 
     915     1042482 :   const unsigned int Dim = elem->dim();
     916             : 
     917             :   // Only constrain elements in 2,3D.
     918     1042482 :   if (Dim == 1)
     919       96436 :     return;
     920             : 
     921             :   // Only constrain active and ancestor elements
     922     1028054 :   if (elem->subactive())
     923       39948 :     return;
     924             : 
     925             : 
     926             : #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
     927      948158 :   if (elem->infinite())
     928             :     {
     929        2112 :       const FEType fe_t(elem->default_order(), FEMap::map_fe_type(*elem));
     930             : 
     931             :       // expand the infinite_compute_constraint in its template-arguments.
     932        2112 :       switch(Dim)
     933             :       {
     934           0 :          case 2:
     935             :             {
     936           0 :             inf_fe_family_mapping_switch(2, inf_compute_node_constraints (constraints, elem) , ,; break;);
     937           0 :             break;
     938             :           }
     939        1056 :          case 3:
     940             :             {
     941        2112 :             inf_fe_family_mapping_switch(3, inf_compute_node_constraints (constraints, elem) , ,; break;);
     942        1056 :             break;
     943             :             }
     944           0 :          default:
     945           0 :            libmesh_error_msg("Invalid dim = " << Dim);
     946             :       }
     947        1056 :       return;
     948             :     }
     949             : 
     950             : #endif
     951      946046 :   const FEFamily mapping_family = FEMap::map_fe_type(*elem);
     952      946046 :   const FEType fe_type(elem->default_side_order(), mapping_family);
     953             : 
     954             :   // Pull objects out of the loop to reduce heap operations
     955      946046 :   std::vector<const Node *> my_nodes, parent_nodes;
     956      946046 :   std::unique_ptr<const Elem> my_side, parent_side;
     957             : 
     958             :   // Look at the element faces.  Check to see if we need to
     959             :   // build constraints.
     960     4708276 :   for (auto s : elem->side_index_range())
     961     7395967 :     if (elem->neighbor_ptr(s) != nullptr &&
     962     3505244 :         elem->neighbor_ptr(s) != remote_elem)
     963     3505244 :       if (elem->neighbor_ptr(s)->level() < elem->level()) // constrain dofs shared between
     964             :         {                                                 // this element and ones coarser
     965             :           // than this element.
     966             :           // Get pointers to the elements of interest and its parent.
     967      117176 :           const Elem * parent = elem->parent();
     968             : 
     969             :           // This can't happen...  Only level-0 elements have nullptr
     970             :           // parents, and no level-0 elements can be at a higher
     971             :           // level than their neighbors!
     972       58588 :           libmesh_assert(parent);
     973             : 
     974      117176 :           elem->build_side_ptr(my_side, s);
     975      117176 :           parent->build_side_ptr(parent_side, s);
     976             : 
     977      117176 :           const unsigned int n_side_nodes = my_side->n_nodes();
     978             : 
     979       58588 :           my_nodes.clear();
     980      117176 :           my_nodes.reserve (n_side_nodes);
     981       58588 :           parent_nodes.clear();
     982      117176 :           parent_nodes.reserve (n_side_nodes);
     983             : 
     984      439428 :           for (unsigned int n=0; n != n_side_nodes; ++n)
     985      483378 :             my_nodes.push_back(my_side->node_ptr(n));
     986             : 
     987      439428 :           for (unsigned int n=0; n != n_side_nodes; ++n)
     988      483378 :             parent_nodes.push_back(parent_side->node_ptr(n));
     989             : 
     990      380840 :           for (unsigned int my_side_n=0;
     991      439428 :                my_side_n < n_side_nodes;
     992             :                my_side_n++)
     993             :             {
     994             :               // We can have an FE type that supports an order
     995             :               // partially, such that sides do not support the same
     996             :               // order.  E.g. we say that a LAGRANGE PRISM21 supports
     997             :               // "third" order to distinguish its shape functions from
     998             :               // a PRISM18, but the QUAD9 sides will still only
     999             :               // support second order.
    1000      322252 :               FEType side_fe_type = fe_type;
    1001             :               const int side_max_order =
    1002      322252 :                 FEInterface::max_order(fe_type, my_side->type());
    1003             : 
    1004      322252 :               if ((int)fe_type.order > side_max_order)
    1005        2736 :                 side_fe_type.order = side_max_order;
    1006             : 
    1007             :               // Do not use the p_level(), if any, that is inherited by the side.
    1008      161126 :               libmesh_assert_less
    1009             :                 (my_side_n,
    1010             :                  FEInterface::n_dofs(side_fe_type, /*extra_order=*/0,
    1011             :                                      my_side.get()));
    1012             : 
    1013      322252 :               const Node * my_node = my_nodes[my_side_n];
    1014             : 
    1015             :               // The support point of the DOF
    1016      322252 :               const Point & support_point = *my_node;
    1017             : 
    1018             :               // Figure out where my node lies on their reference element.
    1019             :               const Point mapped_point = FEMap::inverse_map(Dim-1,
    1020             :                                                             parent_side.get(),
    1021      322252 :                                                             support_point);
    1022             : 
    1023             :               // Compute the parent's side shape function values.
    1024     1170914 :               for (unsigned int their_side_n=0;
    1025     1332040 :                    their_side_n < n_side_nodes;
    1026             :                    their_side_n++)
    1027             :                 {
    1028             :                   // Do not use the p_level(), if any, that is inherited by the side.
    1029      504894 :                   libmesh_assert_less
    1030             :                     (their_side_n,
    1031             :                      FEInterface::n_dofs(side_fe_type,
    1032             :                                          /*extra_order=*/0,
    1033             :                                          parent_side.get()));
    1034             : 
    1035     1514682 :                   const Node * their_node = parent_nodes[their_side_n];
    1036      504894 :                   libmesh_assert(their_node);
    1037             : 
    1038             :                   // Do not use the p_level(), if any, that is inherited by the side.
    1039     1009788 :                   const Real their_value = FEInterface::shape(side_fe_type,
    1040             :                                                               /*extra_order=*/0,
    1041             :                                                               parent_side.get(),
    1042             :                                                               their_side_n,
    1043     1009788 :                                                               mapped_point);
    1044             : 
    1045      504894 :                   const Real their_mag = std::abs(their_value);
    1046             : #ifdef DEBUG
    1047             :                   // Protect for the case u_i ~= u_j,
    1048             :                   // in which case i better equal j.
    1049      504894 :                   if (their_mag > 0.999)
    1050             :                     {
    1051       82114 :                       libmesh_assert_equal_to (my_node, their_node);
    1052       82114 :                       libmesh_assert_less (std::abs(their_value - 1.), 0.001);
    1053             :                     }
    1054             :                   else
    1055             : #endif
    1056             :                     // To make nodal constraints useful for constructing
    1057             :                     // sparsity patterns faster, we need to get EVERY
    1058             :                     // POSSIBLE constraint coupling identified, even if
    1059             :                     // there is no coupling in the isoparametric
    1060             :                     // Lagrange case.
    1061      927674 :                     if (their_mag < 1.e-5)
    1062             :                       {
    1063             :                         // since we may be running this method concurrently
    1064             :                         // on multiple threads we need to acquire a lock
    1065             :                         // before modifying the shared constraint_row object.
    1066      217162 :                         Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
    1067             : 
    1068             :                         // A reference to the constraint row.
    1069      434324 :                         NodeConstraintRow & constraint_row = constraints[my_node].first;
    1070             : 
    1071      434324 :                         constraint_row.emplace(their_node, 0.);
    1072             :                       }
    1073             :                   // To get nodal coordinate constraints right, only
    1074             :                   // add non-zero and non-identity values for Lagrange
    1075             :                   // basis functions.
    1076             :                     else // (1.e-5 <= their_mag <= .999)
    1077             :                       {
    1078             :                         // since we may be running this method concurrently
    1079             :                         // on multiple threads we need to acquire a lock
    1080             :                         // before modifying the shared constraint_row object.
    1081      411236 :                         Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
    1082             : 
    1083             :                         // A reference to the constraint row.
    1084      493350 :                         NodeConstraintRow & constraint_row = constraints[my_node].first;
    1085             : 
    1086      205618 :                         constraint_row.emplace(their_node, their_value);
    1087             :                       }
    1088             :                 }
    1089             :             }
    1090             :         }
    1091             : }
    1092             : 
    1093             : #endif // LIBMESH_ENABLE_NODE_CONSTRAINTS
    1094             : 
    1095             : #endif // #ifdef LIBMESH_ENABLE_AMR
    1096             : 
    1097             : 
    1098             : 
    1099             : #ifdef LIBMESH_ENABLE_PERIODIC
    1100             : 
    1101             : #ifdef LIBMESH_ENABLE_NODE_CONSTRAINTS
    1102      130172 : void FEAbstract::compute_periodic_node_constraints (NodeConstraints & constraints,
    1103             :                                                     const PeriodicBoundaries & boundaries,
    1104             :                                                     const MeshBase & mesh,
    1105             :                                                     const PointLocatorBase * point_locator,
    1106             :                                                     const Elem * elem)
    1107             : {
    1108             :   // Only bother if we truly have periodic boundaries
    1109      130172 :   if (boundaries.empty())
    1110       39030 :     return;
    1111             : 
    1112       65086 :   libmesh_assert(elem);
    1113             : 
    1114             :   // Only constrain active elements with this method
    1115       65086 :   if (!elem->active())
    1116       19515 :     return;
    1117             : 
    1118       91142 :   const unsigned int Dim = elem->dim();
    1119             : 
    1120       91142 :   const FEFamily mapping_family = FEMap::map_fe_type(*elem);
    1121       91142 :   const FEType fe_type(elem->default_side_order(), mapping_family);
    1122             : 
    1123             :   // Pull objects out of the loop to reduce heap operations
    1124       91142 :   std::vector<const Node *> my_nodes, neigh_nodes;
    1125       91142 :   std::unique_ptr<const Elem> my_side, neigh_side;
    1126             : 
    1127             :   // Look at the element faces.  Check to see if we need to
    1128             :   // build constraints.
    1129       91142 :   std::vector<boundary_id_type> bc_ids;
    1130      443726 :   for (auto s : elem->side_index_range())
    1131             :     {
    1132      528876 :       if (elem->neighbor_ptr(s))
    1133      172806 :         continue;
    1134             : 
    1135        6972 :       mesh.get_boundary_info().boundary_ids (elem, s, bc_ids);
    1136       12896 :       for (const auto & boundary_id : bc_ids)
    1137             :         {
    1138        5924 :           const PeriodicBoundaryBase * periodic = boundaries.boundary(boundary_id);
    1139        5924 :           if (periodic)
    1140             :             {
    1141        2712 :               libmesh_assert(point_locator);
    1142             : 
    1143             :               // Get pointers to the element's neighbor.
    1144             :               unsigned int s_neigh;
    1145        5424 :               const Elem * neigh = boundaries.neighbor(boundary_id, *point_locator, elem, s, &s_neigh);
    1146             : 
    1147        5424 :               libmesh_error_msg_if
    1148             :                 (!neigh, "PeriodicBoundaries can't find a periodic neighbor for element " <<
    1149             :                          elem->id() << " side " << s);
    1150             : 
    1151             :               // h refinement constraints:
    1152             :               // constrain dofs shared between
    1153             :               // this element and ones as coarse
    1154             :               // as or coarser than this element.
    1155        5424 :               if (neigh->level() <= elem->level())
    1156             :                 {
    1157             : #ifdef LIBMESH_ENABLE_AMR
    1158        2264 :                   libmesh_assert(neigh->active());
    1159             : #endif // #ifdef LIBMESH_ENABLE_AMR
    1160             : 
    1161        4528 :                   elem->build_side_ptr(my_side, s);
    1162        4528 :                   neigh->build_side_ptr(neigh_side, s_neigh);
    1163             : 
    1164        4528 :                   const unsigned int n_side_nodes = my_side->n_nodes();
    1165             : 
    1166        2264 :                   my_nodes.clear();
    1167        4528 :                   my_nodes.reserve (n_side_nodes);
    1168        2264 :                   neigh_nodes.clear();
    1169        4528 :                   neigh_nodes.reserve (n_side_nodes);
    1170             : 
    1171       14528 :                   for (unsigned int n=0; n != n_side_nodes; ++n)
    1172       15000 :                     my_nodes.push_back(my_side->node_ptr(n));
    1173             : 
    1174       14528 :                   for (unsigned int n=0; n != n_side_nodes; ++n)
    1175       15000 :                     neigh_nodes.push_back(neigh_side->node_ptr(n));
    1176             : 
    1177             :                   // Make sure we're not adding recursive constraints
    1178             :                   // due to the redundancy in the way we add periodic
    1179             :                   // boundary constraints, or adding constraints to
    1180             :                   // nodes that already have AMR constraints
    1181        6792 :                   std::vector<bool> skip_constraint(n_side_nodes, false);
    1182             : 
    1183       12264 :                   for (unsigned int my_side_n=0;
    1184       14528 :                        my_side_n < n_side_nodes;
    1185             :                        my_side_n++)
    1186             :                     {
    1187             :                       // Do not use the p_level(), if any, that is inherited by the side.
    1188        5000 :                       libmesh_assert_less (my_side_n, FEInterface::n_dofs(fe_type, /*extra_order=*/0, my_side.get()));
    1189             : 
    1190       15000 :                       const Node * my_node = my_nodes[my_side_n];
    1191             : 
    1192             :                       // If we've already got a constraint on this
    1193             :                       // node, then the periodic constraint is
    1194             :                       // redundant
    1195             :                       {
    1196        5000 :                         Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
    1197             : 
    1198        5000 :                         if (constraints.count(my_node))
    1199             :                           {
    1200        3998 :                             skip_constraint[my_side_n] = true;
    1201        1999 :                             continue;
    1202             :                           }
    1203             :                       }
    1204             : 
    1205             :                       // Compute the neighbors's side shape function values.
    1206       17485 :                       for (unsigned int their_side_n=0;
    1207       20486 :                            their_side_n < n_side_nodes;
    1208             :                            their_side_n++)
    1209             :                         {
    1210             :                           // Do not use the p_level(), if any, that is inherited by the side.
    1211        7242 :                           libmesh_assert_less (their_side_n, FEInterface::n_dofs(fe_type, /*extra_order=*/0, neigh_side.get()));
    1212             : 
    1213       21726 :                           const Node * their_node = neigh_nodes[their_side_n];
    1214             : 
    1215             :                           // If there's a constraint on an opposing node,
    1216             :                           // we need to see if it's constrained by
    1217             :                           // *our side* making any periodic constraint
    1218             :                           // on us recursive
    1219             :                           {
    1220        7242 :                             Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
    1221             : 
    1222        7242 :                             if (!constraints.count(their_node))
    1223        4558 :                               continue;
    1224             : 
    1225             :                             const NodeConstraintRow & their_constraint_row =
    1226        5368 :                               constraints[their_node].first;
    1227             : 
    1228       19764 :                             for (unsigned int orig_side_n=0;
    1229       22448 :                                  orig_side_n < n_side_nodes;
    1230             :                                  orig_side_n++)
    1231             :                               {
    1232             :                                 // Do not use the p_level(), if any, that is inherited by the side.
    1233        8540 :                                 libmesh_assert_less (orig_side_n, FEInterface::n_dofs(fe_type, /*extra_order=*/0, my_side.get()));
    1234             : 
    1235       25620 :                                 const Node * orig_node = my_nodes[orig_side_n];
    1236             : 
    1237        8540 :                                 if (their_constraint_row.count(orig_node))
    1238       10784 :                                   skip_constraint[orig_side_n] = true;
    1239             :                               }
    1240             :                           }
    1241             :                         }
    1242             :                     }
    1243       12264 :                   for (unsigned int my_side_n=0;
    1244       14528 :                        my_side_n < n_side_nodes;
    1245             :                        my_side_n++)
    1246             :                     {
    1247             :                       // Do not use the p_level(), if any, that is inherited by the side.
    1248        5000 :                       libmesh_assert_less (my_side_n, FEInterface::n_dofs(fe_type, /*extra_order=*/0, my_side.get()));
    1249             : 
    1250       15000 :                       if (skip_constraint[my_side_n])
    1251        5714 :                         continue;
    1252             : 
    1253        4286 :                       const Node * my_node = my_nodes[my_side_n];
    1254             : 
    1255             :                       // Figure out where my node lies on their reference element.
    1256        4286 :                       const Point neigh_point = periodic->get_corresponding_pos(*my_node);
    1257             : 
    1258             :                       // Figure out where my node lies on their reference element.
    1259             :                       const Point mapped_point =
    1260             :                         FEMap::inverse_map(Dim-1, neigh_side.get(),
    1261        4286 :                                            neigh_point);
    1262             : 
    1263       11539 :                       for (unsigned int their_side_n=0;
    1264       13682 :                            their_side_n < n_side_nodes;
    1265             :                            their_side_n++)
    1266             :                         {
    1267             :                           // Do not use the p_level(), if any, that is inherited by the side.
    1268        4698 :                           libmesh_assert_less (their_side_n, FEInterface::n_dofs(fe_type, /*extra_order=*/0, neigh_side.get()));
    1269             : 
    1270       14094 :                           const Node * their_node = neigh_nodes[their_side_n];
    1271        4698 :                           libmesh_assert(their_node);
    1272             : 
    1273             :                           // Do not use the p_level(), if any, that is inherited by the side.
    1274        9396 :                           const Real their_value = FEInterface::shape(fe_type,
    1275             :                                                                       /*extra_order=*/0,
    1276             :                                                                       neigh_side.get(),
    1277             :                                                                       their_side_n,
    1278        9396 :                                                                       mapped_point);
    1279             : 
    1280             :                           // since we may be running this method concurrently
    1281             :                           // on multiple threads we need to acquire a lock
    1282             :                           // before modifying the shared constraint_row object.
    1283             :                           {
    1284        9396 :                             Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
    1285             : 
    1286             :                             NodeConstraintRow & constraint_row =
    1287        9396 :                               constraints[my_node].first;
    1288             : 
    1289        4698 :                             constraint_row.emplace(their_node, their_value);
    1290             :                           }
    1291             :                         }
    1292             :                     }
    1293             :                 }
    1294             :             }
    1295             :         }
    1296             :     }
    1297             : }
    1298             : #endif // LIBMESH_ENABLE_NODE_CONSTRAINTS
    1299             : 
    1300             : #endif // LIBMESH_ENABLE_PERIODIC
    1301             : 
    1302             : 
    1303      853012 : unsigned int FEAbstract::n_quadrature_points () const
    1304             : {
    1305      240186 :   if (this->shapes_on_quadrature)
    1306             :     {
    1307      240170 :       libmesh_assert(this->qrule);
    1308      240170 :       libmesh_assert_equal_to(this->qrule->n_points(),
    1309             :                               this->_n_total_qp);
    1310             :     }
    1311      853012 :   return this->_n_total_qp;
    1312             : }
    1313             : 
    1314             : } // namespace libMesh

Generated by: LCOV version 1.14