LCOV - code coverage report
Current view: top level - src/fe - fe_bernstein.C (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4573 (924896) with base 3f0912 Lines: 140 202 69.3 %
Date: 2026-11-18 21:52:26 Functions: 33 62 53.2 %
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             : 
      19             : 
      20             : // Local includes
      21             : #include "libmesh/libmesh_config.h"
      22             : 
      23             : #ifdef LIBMESH_ENABLE_HIGHER_ORDER_SHAPES
      24             : 
      25             : #include "libmesh/elem.h"
      26             : #include "libmesh/enum_to_string.h"
      27             : #include "libmesh/fe.h"
      28             : #include "libmesh/fe_interface.h"
      29             : #include "libmesh/fe_macro.h"
      30             : 
      31             : namespace libMesh
      32             : {
      33             : 
      34             : // ------------------------------------------------------------
      35             : // Bernstein-specific implementations, Steffen Petersen 2005
      36             : 
      37             : // Anonymous namespace for local helper functions
      38             : namespace {
      39             : 
      40           0 : void bernstein_nodal_soln(const Elem * elem,
      41             :                           const Order order,
      42             :                           const std::vector<Number> & elem_soln,
      43             :                           std::vector<Number> & nodal_soln,
      44             :                           const bool add_p_level)
      45             : {
      46           0 :   const unsigned int n_nodes = elem->n_nodes();
      47             : 
      48           0 :   const ElemType elem_type = elem->type();
      49             : 
      50           0 :   nodal_soln.resize(n_nodes);
      51             : 
      52           0 :   const Order totalorder = order + add_p_level*elem->p_level();
      53             : 
      54             :   // FEType object to be passed to various FEInterface functions below.
      55           0 :   FEType fe_type(order, BERNSTEIN);
      56             : 
      57           0 :   switch (totalorder)
      58             :     {
      59             :       // Constant shape functions
      60           0 :     case CONSTANT:
      61             :       {
      62           0 :         libmesh_assert_equal_to (elem_soln.size(), 1);
      63             : 
      64           0 :         std::fill(nodal_soln.begin(), nodal_soln.end(), elem_soln[0]);
      65             : 
      66           0 :         return;
      67             :       }
      68             : 
      69             : 
      70             :       // For other bases do interpolation at the nodes
      71             :       // explicitly.
      72           0 :     case FIRST:
      73             :     case SECOND:
      74             :     case THIRD:
      75             :     case FOURTH:
      76             :     case FIFTH:
      77             :     case SIXTH:
      78             :       {
      79             :         const unsigned int n_sf =
      80           0 :           FEInterface::n_shape_functions(fe_type, elem);
      81             : 
      82           0 :         std::vector<Point> refspace_nodes;
      83           0 :         FEBase::get_refspace_nodes(elem_type,refspace_nodes);
      84           0 :         libmesh_assert_equal_to (refspace_nodes.size(), n_nodes);
      85           0 :         libmesh_assert_equal_to (elem_soln.size(), n_sf);
      86             : 
      87             :         // Zero before summation
      88           0 :         std::fill(nodal_soln.begin(), nodal_soln.end(), 0);
      89             : 
      90           0 :         for (unsigned int n=0; n<n_nodes; n++)
      91             :           // u_i = Sum (alpha_i phi_i)
      92           0 :           for (unsigned int i=0; i<n_sf; i++)
      93           0 :             nodal_soln[n] += elem_soln[i] *
      94           0 :               FEInterface::shape(fe_type, elem, i, refspace_nodes[n]);
      95             : 
      96           0 :         return;
      97             :       }
      98             : 
      99           0 :     default:
     100           0 :       libmesh_error_msg("ERROR: Invalid total order " << totalorder);
     101             :     }
     102             : } //  bernstein_nodal_soln()
     103             : 
     104             : 
     105             : 
     106    31706172 : unsigned int BERNSTEIN_n_dofs(const ElemType t, const Order o)
     107             : {
     108    31706172 :   switch (t)
     109             :     {
     110      244365 :     case NODEELEM:
     111      244365 :       return 1;
     112       94562 :     case EDGE2:
     113             :     case EDGE3:
     114             :     case EDGE4:
     115      349288 :       return (o+1);
     116        9391 :     case QUAD4:
     117             :     case QUADSHELL4:
     118        9391 :       libmesh_assert_less (o, 2);
     119             :       libmesh_fallthrough();
     120             :     case QUAD8:
     121             :     case QUADSHELL8:
     122             :       {
     123      119344 :         if (o == 1)
     124        9391 :           return 4;
     125       82626 :         else if (o == 2)
     126       20658 :           return 8;
     127             :         else
     128           0 :           libmesh_error_msg("ERROR: Invalid Order " << Utility::enum_to_string(o) << " selected for BERNSTEIN FE family!");
     129             :       }
     130     5409169 :     case QUAD9:
     131             :     case QUADSHELL9:
     132    18621402 :       return ((o+1)*(o+1));
     133      279927 :     case HEX8:
     134      279927 :       libmesh_assert_less (o, 2);
     135             :       libmesh_fallthrough();
     136             :     case HEX20:
     137             :       {
     138     3771624 :         if (o == 1)
     139      279927 :           return 8;
     140     2653434 :         else if (o == 2)
     141      663360 :           return 20;
     142             :         else
     143           0 :           libmesh_error_msg("ERROR: Invalid Order " << Utility::enum_to_string(o) << " selected for BERNSTEIN FE family!");
     144             :       }
     145     1994023 :     case HEX27:
     146     8043134 :       return ((o+1)*(o+1)*(o+1));
     147        8769 :     case TRI3:
     148             :     case TRISHELL3:
     149        8769 :       libmesh_assert_less (o, 2);
     150             :       libmesh_fallthrough();
     151             :     case TRI6:
     152             :     case TRI7:
     153      243062 :       return ((o+1)*(o+2)/2);
     154       32044 :     case TET4:
     155       32044 :       libmesh_assert_less (o, 2);
     156             :       libmesh_fallthrough();
     157             :     case TET10:
     158             :     case TET14:
     159       41634 :       libmesh_assert_less (o, 3);
     160      157821 :       return ((o+1)*(o+2)*(o+3)/6);
     161           0 :     case INVALID_ELEM:
     162           0 :       return 0;
     163           0 :     default:
     164           0 :       libmesh_error_msg("ERROR: Invalid ElemType " << Utility::enum_to_string(t) << " selected for BERNSTEIN FE family!");
     165             :     }
     166             : } // BERNSTEIN_n_dofs()
     167             : 
     168             : 
     169             : 
     170    23355535 : unsigned int BERNSTEIN_n_dofs(const Elem * e, const Order o)
     171             : {
     172     8828766 :   libmesh_assert(e);
     173    31706172 :   return BERNSTEIN_n_dofs(e->type(), o);
     174             : }
     175             : 
     176             : 
     177             : 
     178     6820119 : unsigned int BERNSTEIN_n_dofs_at_node(const ElemType t,
     179             :                                       const Order o,
     180             :                                       const unsigned int n)
     181             : {
     182     6820119 :   switch (t)
     183             :     {
     184      184751 :     case NODEELEM:
     185      184751 :       return 1;
     186             : 
     187       10024 :     case EDGE2:
     188             :     case EDGE3:
     189       10024 :       switch (n)
     190             :         {
     191        1988 :         case 0:
     192             :         case 1:
     193        1988 :           return 1;
     194         672 :         case 2:
     195         672 :           libmesh_assert (o>1);
     196        2576 :           return (o-1);
     197           0 :         default:
     198           0 :           libmesh_error_msg("ERROR: Invalid node ID " << n << " selected for EDGE2/3!");
     199             :         }
     200        2492 :     case EDGE4:
     201        2492 :       switch (n)
     202             :         {
     203         350 :         case 0:
     204             :         case 1:
     205         350 :           return 1;
     206         154 :         case 2:
     207         154 :           libmesh_assert (o>2);
     208         588 :           return (o-1)/2;  // floor
     209         588 :         case 3:
     210         154 :           libmesh_assert (o>2);
     211         588 :           return o/2;          // "ceiling", add extra DoFs here first
     212           0 :         default:
     213           0 :           libmesh_error_msg("ERROR: Invalid node ID " << n << " selected for EDGE4!");
     214             :         }
     215       78344 :     case TRI3:
     216        2464 :       libmesh_assert_less (n, 3);
     217        2464 :       libmesh_assert_less (o, 2);
     218             :       libmesh_fallthrough();
     219             :     case TRI6:
     220             :       // Internal DoFs are associated with the elem on a Tri6, or node 6 on a Tri7
     221       14770 :       libmesh_assert_less (n, 6);
     222             :       libmesh_fallthrough();
     223             :     case TRI7:
     224      104958 :       switch (n)
     225             :         {
     226       15316 :         case 0:
     227             :         case 1:
     228             :         case 2:
     229       15316 :           return 1;
     230             : 
     231       11760 :         case 3:
     232             :         case 4:
     233             :         case 5:
     234       42672 :           return (o-1);
     235             : 
     236        2002 :         case 6:
     237        7294 :           return ((o-1)*(o-2)/2);
     238           0 :         default:
     239           0 :           libmesh_error_msg("ERROR: Invalid node ID " << n << " selected for TRI!");
     240             :         }
     241     3568533 :     case QUAD4:
     242        1596 :       libmesh_assert_less (n, 4);
     243        1596 :       libmesh_assert_less (o, 2);
     244             :       libmesh_fallthrough();
     245             :     case QUAD8:
     246        1596 :       libmesh_assert_less (n, 8);
     247        1596 :       libmesh_assert_less (o, 3);
     248             :       libmesh_fallthrough();
     249             :     case QUAD9:
     250             :       {
     251     4923425 :         switch (n)
     252             :           {
     253      611896 :           case 0:
     254             :           case 1:
     255             :           case 2:
     256             :           case 3:
     257      611896 :             return 1;
     258             : 
     259      595484 :           case 4:
     260             :           case 5:
     261             :           case 6:
     262             :           case 7:
     263     2161947 :             return (o-1);
     264             : 
     265      149108 :           case 8:
     266      541451 :             return ((o-1)*(o-1));
     267             : 
     268           0 :           default:
     269           0 :             libmesh_error_msg("ERROR: Invalid node ID " << n << " selected for QUAD9!");
     270             :           }
     271             :       }
     272      460724 :     case HEX8:
     273        4956 :       libmesh_assert_less (n, 8);
     274        4956 :       libmesh_assert_less (o, 2);
     275             :       libmesh_fallthrough();
     276             :     case HEX20:
     277        4956 :       libmesh_assert_less (n, 20);
     278        4956 :       libmesh_assert_less (o, 3);
     279             :       libmesh_fallthrough();
     280             :     case HEX27:
     281      599756 :       switch (n)
     282             :         {
     283       46948 :         case 0:
     284             :         case 1:
     285             :         case 2:
     286             :         case 3:
     287             :         case 4:
     288             :         case 5:
     289             :         case 6:
     290             :         case 7:
     291       46948 :           return 1;
     292             : 
     293       61224 :         case 8:
     294             :         case 9:
     295             :         case 10:
     296             :         case 11:
     297             :         case 12:
     298             :         case 13:
     299             :         case 14:
     300             :         case 15:
     301             :         case 16:
     302             :         case 17:
     303             :         case 18:
     304             :         case 19:
     305      255904 :           return (o-1);
     306             : 
     307       30648 :         case 20:
     308             :         case 21:
     309             :         case 22:
     310             :         case 23:
     311             :         case 24:
     312             :         case 25:
     313      128104 :           return ((o-1)*(o-1));
     314             : 
     315        5168 :         case 26:
     316       21604 :           return ((o-1)*(o-1)*(o-1));
     317             : 
     318           0 :         default:
     319           0 :           libmesh_error_msg("ERROR: Invalid node ID " << n << " selected for HEX27!");
     320             :         }
     321      390852 :     case TET4:
     322       21588 :       libmesh_assert_less (n, 4);
     323       21588 :       libmesh_assert_less (o, 2);
     324             :       libmesh_fallthrough();
     325             :     case TET10:
     326       72114 :       libmesh_assert_less (n, 10);
     327             :       libmesh_fallthrough();
     328             :     case TET14:
     329      142744 :       libmesh_assert_less (o, 3);
     330      369264 :       switch (n)
     331             :         {
     332       65352 :         case 0:
     333             :         case 1:
     334             :         case 2:
     335             :         case 3:
     336       65352 :           return 1;
     337             : 
     338       57288 :         case 4:
     339             :         case 5:
     340             :         case 6:
     341             :         case 7:
     342             :         case 8:
     343             :         case 9:
     344      206976 :           return (o-1);
     345             : 
     346       20104 :         case 10:
     347             :         case 11:
     348             :         case 12:
     349             :         case 13:
     350       20104 :           return 0;
     351             : 
     352           0 :         default:
     353           0 :           libmesh_error_msg("ERROR: Invalid node ID " << n << " selected for TET4/10/14!");
     354             :         }
     355           0 :     case INVALID_ELEM:
     356           0 :       return 0;
     357           0 :     default:
     358           0 :       libmesh_error_msg("ERROR: Invalid ElemType " << Utility::enum_to_string(t) << " selected for BERNSTEIN FE family!");
     359             :     }
     360             : } // BERNSTEIN_n_dofs_at_node()
     361             : 
     362             : 
     363             : 
     364      476579 : unsigned int BERNSTEIN_n_dofs_at_node(const Elem & e,
     365             :                                       const Order o,
     366             :                                       const unsigned int n)
     367             : {
     368      650917 :   return BERNSTEIN_n_dofs_at_node(e.type(), o, n);
     369             : }
     370             : 
     371             : 
     372             : 
     373     1271891 : unsigned int BERNSTEIN_n_dofs_per_elem(const ElemType t, const Order o)
     374             : {
     375      921024 :   switch (t)
     376             :     {
     377      180939 :     case NODEELEM:
     378             :     case EDGE2:
     379             :     case EDGE3:
     380             :     case EDGE4:
     381      180939 :       return 0;
     382        1092 :     case TRI3:
     383             :     case TRISHELL3:
     384             :     case QUAD4:
     385             :     case QUADSHELL4:
     386        1092 :       return 0;
     387        1750 :     case TRI6:
     388        6328 :       return ((o-1)*(o-2)/2);
     389        1750 :     case TRI7:
     390        1750 :       return 0;
     391           0 :     case QUAD8:
     392             :     case QUADSHELL8:
     393           0 :       if (o <= 2)
     394           0 :         return 0;
     395             :       libmesh_fallthrough();
     396             :     case QUAD9:
     397             :     case QUADSHELL9:
     398      147944 :       return 0;
     399         588 :     case HEX8:
     400         588 :       libmesh_assert_less (o, 2);
     401         588 :       return 0;
     402           0 :     case HEX20:
     403           0 :       libmesh_assert_less (o, 3);
     404           0 :       return 0;
     405        3980 :     case HEX27:
     406        3980 :       return 0;
     407        4508 :     case TET4:
     408        4508 :       libmesh_assert_less (o, 2);
     409             :       libmesh_fallthrough();
     410             :     case TET10:
     411             :     case TET14:
     412       12824 :       libmesh_assert_less (o, 3);
     413       12824 :       return 0;
     414           0 :     case INVALID_ELEM:
     415           0 :       return 0;
     416           0 :     default:
     417           0 :       libmesh_error_msg("ERROR: Invalid ElemType " << Utility::enum_to_string(t) << " selected for BERNSTEIN FE family!");
     418             :     }
     419             : } // BERNSTEIN_n_dofs_per_elem
     420             : 
     421             : 
     422             : 
     423      921024 : unsigned int BERNSTEIN_n_dofs_per_elem(const Elem & e, const Order o)
     424             : {
     425     1271891 :   return BERNSTEIN_n_dofs_per_elem(e.type(), o);
     426             : }
     427             : 
     428             : } // anonymous namespace
     429             : 
     430             : 
     431             : // Instantiate (side_) nodal_soln() function for every dimension
     432           0 : LIBMESH_FE_NODAL_SOLN(BERNSTEIN, bernstein_nodal_soln)
     433           0 : LIBMESH_FE_SIDE_NODAL_SOLN(BERNSTEIN)
     434             : 
     435             : // Instantiate n_dofs*() functions for every dimension
     436    39798182 : LIBMESH_DEFAULT_NDOFS(BERNSTEIN)
     437             : 
     438             : // Bernstein FEMs are C^0 continuous
     439           0 : template <> FEContinuity FE<0,BERNSTEIN>::get_continuity() const { return C_ZERO; }
     440        2694 : template <> FEContinuity FE<1,BERNSTEIN>::get_continuity() const { return C_ZERO; }
     441        9683 : template <> FEContinuity FE<2,BERNSTEIN>::get_continuity() const { return C_ZERO; }
     442       17523 : template <> FEContinuity FE<3,BERNSTEIN>::get_continuity() const { return C_ZERO; }
     443             : 
     444             : // Bernstein FEMs are not hierarchic
     445           0 : template <> bool FE<0,BERNSTEIN>::is_hierarchic() const { return false; }
     446          20 : template <> bool FE<1,BERNSTEIN>::is_hierarchic() const { return false; }
     447          65 : template <> bool FE<2,BERNSTEIN>::is_hierarchic() const { return false; }
     448          37 : template <> bool FE<3,BERNSTEIN>::is_hierarchic() const { return false; }
     449             : 
     450             : #ifdef LIBMESH_ENABLE_AMR
     451             : // compute_constraints() specializations are only needed for 2 and 3D
     452             : template <>
     453        1008 : void FE<2,BERNSTEIN>::compute_constraints (DofConstraints & constraints,
     454             :                                            DofMap & dof_map,
     455             :                                            const unsigned int variable_number,
     456             :                                            const Elem * elem)
     457        1008 : { compute_proj_constraints(constraints, dof_map, variable_number, elem); }
     458             : 
     459             : template <>
     460        4256 : void FE<3,BERNSTEIN>::compute_constraints (DofConstraints & constraints,
     461             :                                            DofMap & dof_map,
     462             :                                            const unsigned int variable_number,
     463             :                                            const Elem * elem)
     464        4256 : { compute_proj_constraints(constraints, dof_map, variable_number, elem); }
     465             : #endif // #ifdef LIBMESH_ENABLE_AMR
     466             : 
     467             : // Bernstein shapes need reinit only for approximation orders >= 3,
     468             : // but we might reach that with p refinement
     469           0 : template <> bool FE<0,BERNSTEIN>::shapes_need_reinit() const { return true; }
     470         284 : template <> bool FE<1,BERNSTEIN>::shapes_need_reinit() const { return true; }
     471        2715 : template <> bool FE<2,BERNSTEIN>::shapes_need_reinit() const { return true; }
     472        9379 : template <> bool FE<3,BERNSTEIN>::shapes_need_reinit() const { return true; }
     473             : 
     474             : } // namespace libMesh
     475             : 
     476             : #endif //LIBMESH_ENABLE_HIGHER_ORDER_SHAPES

Generated by: LCOV version 1.14