LCOV - code coverage report
Current view: top level - src/fe - fe_monomial.C (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4573 (924896) with base 3f0912 Lines: 60 70 85.7 %
Date: 2026-11-18 21:52:26 Functions: 38 58 65.5 %
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/fe.h"
      22             : #include "libmesh/fe_monomial_n_dofs.h"
      23             : #include "libmesh/elem.h"
      24             : #include "libmesh/enum_to_string.h"
      25             : #include "libmesh/fe_interface.h"
      26             : #include "libmesh/fe_macro.h"
      27             : 
      28             : namespace libMesh
      29             : {
      30             : 
      31     5926308 : unsigned int monomial_n_dofs(const Elem * e, const Order o)
      32             : {
      33     2154036 :   libmesh_assert(e);
      34     5926308 :   return monomial_n_dofs(e->type(), o);
      35             : }
      36             : 
      37             : 
      38     5926350 : unsigned int monomial_n_dofs(const ElemType t, const Order o)
      39             : {
      40             :   // The counts live in a header so that device code, which cannot call in
      41             :   // here, reads the same ones; reporting the error stays here.
      42     5926350 :   const unsigned int n = FECounts::monomial_n_dofs(t, o);
      43             : 
      44     5926350 :   libmesh_error_msg_if(n == invalid_uint,
      45             :                        "ERROR: Bad ElemType = " << Utility::enum_to_string(t) <<
      46             :                        " for " << Utility::enum_to_string(o) << " order approximation!");
      47             : 
      48     5926350 :   return n;
      49             : } // monomial_n_dofs()
      50             : 
      51             : 
      52             : // Anonymous namespace for local helper functions
      53             : namespace {
      54             : 
      55      383333 : void monomial_nodal_soln(const Elem * elem,
      56             :                          const Order order,
      57             :                          const std::vector<Number> & elem_soln,
      58             :                          std::vector<Number> & nodal_soln,
      59             :                          const bool add_p_level)
      60             : {
      61      383333 :   const unsigned int n_nodes = elem->n_nodes();
      62             : 
      63      383333 :   const ElemType elem_type = elem->type();
      64             : 
      65      383333 :   nodal_soln.resize(n_nodes);
      66             : 
      67      494899 :   const Order totalorder = order + add_p_level*elem->p_level();
      68             : 
      69      383333 :   switch (totalorder)
      70             :     {
      71             :       // Constant shape functions
      72      211976 :     case CONSTANT:
      73             :       {
      74      105988 :         libmesh_assert_equal_to (elem_soln.size(), 1);
      75             : 
      76      317964 :         std::fill(nodal_soln.begin(), nodal_soln.end(), elem_soln[0]);
      77             : 
      78      105988 :         return;
      79             :       }
      80             : 
      81             : 
      82             :       // For other orders, do interpolation at the nodes
      83             :       // explicitly.
      84        5578 :     default:
      85             :       {
      86             :         // FEType object to be passed to various FEInterface functions below.
      87        5578 :         FEType fe_type(order, MONOMIAL);
      88             : 
      89             :         const unsigned int n_sf =
      90       22312 :           FEInterface::n_shape_functions(fe_type, elem);
      91             : 
      92       11156 :         std::vector<Point> refspace_nodes;
      93       22312 :         FEBase::get_refspace_nodes(elem_type,refspace_nodes);
      94        5578 :         libmesh_assert_equal_to (refspace_nodes.size(), n_nodes);
      95        5578 :         libmesh_assert_equal_to (elem_soln.size(), n_sf);
      96             : 
      97             :         // Zero before summation
      98        5578 :         std::fill(nodal_soln.begin(), nodal_soln.end(), 0);
      99             : 
     100      238036 :         for (unsigned int n=0; n<n_nodes; n++)
     101             :           // u_i = Sum (alpha_i phi_i)
     102     1039920 :           for (unsigned int i=0; i<n_sf; i++)
     103     1030245 :             nodal_soln[n] += elem_soln[i] *
     104     1030245 :               FEInterface::shape(fe_type, elem, i, refspace_nodes[n]);
     105             : 
     106        5578 :         return;
     107             :       } // default
     108             :     } // switch
     109             : } // monomial_nodal_soln()
     110             : 
     111             : 
     112             : 
     113             : 
     114             : } // anonymous namespace
     115             : 
     116             : 
     117             : // Instantiate (side_) nodal_soln() function for every dimension
     118      383333 : LIBMESH_FE_NODAL_SOLN(MONOMIAL, monomial_nodal_soln)
     119           0 : LIBMESH_FE_SIDE_NODAL_SOLN(MONOMIAL)
     120             : 
     121             : 
     122             : // Full specialization of n_dofs() function for every dimension
     123           0 : template <> unsigned int FE<0,MONOMIAL>::n_dofs(const ElemType t, const Order o) { return monomial_n_dofs(t, o); }
     124          14 : template <> unsigned int FE<1,MONOMIAL>::n_dofs(const ElemType t, const Order o) { return monomial_n_dofs(t, o); }
     125          14 : template <> unsigned int FE<2,MONOMIAL>::n_dofs(const ElemType t, const Order o) { return monomial_n_dofs(t, o); }
     126          14 : template <> unsigned int FE<3,MONOMIAL>::n_dofs(const ElemType t, const Order o) { return monomial_n_dofs(t, o); }
     127             : 
     128           2 : template <> unsigned int FE<0,MONOMIAL>::n_dofs(const Elem * e, const Order o) { return monomial_n_dofs(e, o); }
     129        4485 : template <> unsigned int FE<1,MONOMIAL>::n_dofs(const Elem * e, const Order o) { return monomial_n_dofs(e, o); }
     130      267341 : template <> unsigned int FE<2,MONOMIAL>::n_dofs(const Elem * e, const Order o) { return monomial_n_dofs(e, o); }
     131     1259691 : template <> unsigned int FE<3,MONOMIAL>::n_dofs(const Elem * e, const Order o) { return monomial_n_dofs(e, o); }
     132             : 
     133             : // Full specialization of n_dofs_at_node() function for every dimension.
     134             : // Monomials have no dofs at nodes, only element dofs.
     135           9 : template <> unsigned int FE<0,MONOMIAL>::n_dofs_at_node(const ElemType, const Order, const unsigned int) { return 0; }
     136       20840 : template <> unsigned int FE<1,MONOMIAL>::n_dofs_at_node(const ElemType, const Order, const unsigned int) { return 0; }
     137     3280207 : template <> unsigned int FE<2,MONOMIAL>::n_dofs_at_node(const ElemType, const Order, const unsigned int) { return 0; }
     138    25894378 : template <> unsigned int FE<3,MONOMIAL>::n_dofs_at_node(const ElemType, const Order, const unsigned int) { return 0; }
     139             : 
     140          32 : template <> unsigned int FE<0,MONOMIAL>::n_dofs_at_node(const Elem &, const Order, const unsigned int) { return 0; }
     141       26711 : template <> unsigned int FE<1,MONOMIAL>::n_dofs_at_node(const Elem &, const Order, const unsigned int) { return 0; }
     142     1036939 : template <> unsigned int FE<2,MONOMIAL>::n_dofs_at_node(const Elem &, const Order, const unsigned int) { return 0; }
     143     4913299 : template <> unsigned int FE<3,MONOMIAL>::n_dofs_at_node(const Elem &, const Order, const unsigned int) { return 0; }
     144             : 
     145             : // Full specialization of n_dofs_per_elem() function for every dimension.
     146           0 : template <> unsigned int FE<0,MONOMIAL>::n_dofs_per_elem(const ElemType t, const Order o) { return monomial_n_dofs(t, o); }
     147           0 : template <> unsigned int FE<1,MONOMIAL>::n_dofs_per_elem(const ElemType t, const Order o) { return monomial_n_dofs(t, o); }
     148           0 : template <> unsigned int FE<2,MONOMIAL>::n_dofs_per_elem(const ElemType t, const Order o) { return monomial_n_dofs(t, o); }
     149           0 : template <> unsigned int FE<3,MONOMIAL>::n_dofs_per_elem(const ElemType t, const Order o) { return monomial_n_dofs(t, o); }
     150             : 
     151          31 : template <> unsigned int FE<0,MONOMIAL>::n_dofs_per_elem(const Elem & e, const Order o) { return monomial_n_dofs(&e, o); }
     152       16483 : template <> unsigned int FE<1,MONOMIAL>::n_dofs_per_elem(const Elem & e, const Order o) { return monomial_n_dofs(&e, o); }
     153      630914 : template <> unsigned int FE<2,MONOMIAL>::n_dofs_per_elem(const Elem & e, const Order o) { return monomial_n_dofs(&e, o); }
     154     2180376 : template <> unsigned int FE<3,MONOMIAL>::n_dofs_per_elem(const Elem & e, const Order o) { return monomial_n_dofs(&e, o); }
     155             : 
     156             : 
     157             : // Full specialization of get_continuity() function for every dimension.
     158          35 : template <> FEContinuity FE<0,MONOMIAL>::get_continuity() const { return DISCONTINUOUS; }
     159        3199 : template <> FEContinuity FE<1,MONOMIAL>::get_continuity() const { return DISCONTINUOUS; }
     160       17665 : template <> FEContinuity FE<2,MONOMIAL>::get_continuity() const { return DISCONTINUOUS; }
     161       37928 : template <> FEContinuity FE<3,MONOMIAL>::get_continuity() const { return DISCONTINUOUS; }
     162             : 
     163             : // Full specialization of is_hierarchic() function for every dimension.
     164             : // The monomials are hierarchic!
     165           0 : template <> bool FE<0,MONOMIAL>::is_hierarchic() const { return true; }
     166          20 : template <> bool FE<1,MONOMIAL>::is_hierarchic() const { return true; }
     167         103 : template <> bool FE<2,MONOMIAL>::is_hierarchic() const { return true; }
     168         170 : template <> bool FE<3,MONOMIAL>::is_hierarchic() const { return true; }
     169             : 
     170             : #ifdef LIBMESH_ENABLE_AMR
     171             : 
     172             : // Full specialization of compute_constraints() function for 2D and
     173             : // 3D only.  There are no constraints for discontinuous elements, so
     174             : // we do nothing.
     175           0 : template <> void FE<2,MONOMIAL>::compute_constraints (DofConstraints &, DofMap &, const unsigned int, const Elem *) {}
     176           0 : template <> void FE<3,MONOMIAL>::compute_constraints (DofConstraints &, DofMap &, const unsigned int, const Elem *) {}
     177             : 
     178             : #endif // #ifdef LIBMESH_ENABLE_AMR
     179             : 
     180             : // Full specialization of shapes_need_reinit() function for every dimension.
     181           0 : template <> bool FE<0,MONOMIAL>::shapes_need_reinit() const { return false; }
     182         539 : template <> bool FE<1,MONOMIAL>::shapes_need_reinit() const { return false; }
     183      254951 : template <> bool FE<2,MONOMIAL>::shapes_need_reinit() const { return false; }
     184      920472 : template <> bool FE<3,MONOMIAL>::shapes_need_reinit() const { return false; }
     185             : 
     186             : } // namespace libMesh

Generated by: LCOV version 1.14