LCOV - code coverage report
Current view: top level - src/fe - fe_hermite_shape_1D.C (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4232 (290bfc) with base 82cc40 Lines: 140 158 88.6 %
Date: 2025-08-27 15:46:53 Functions: 11 17 64.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // The libMesh Finite Element Library.
       2             : // Copyright (C) 2002-2025 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             : // Local includes
      19             : #include "libmesh/fe.h"
      20             : #include "libmesh/elem.h"
      21             : #include "libmesh/fe_interface.h"
      22             : #include "libmesh/utility.h"
      23             : #include "libmesh/enum_to_string.h"
      24             : 
      25             : namespace
      26             : {
      27             : using namespace libMesh;
      28             : 
      29             : // Compute the static coefficients for an element
      30    70045963 : void hermite_compute_coefs(const Elem * elem, Real & d1xd1x, Real & d2xd2x)
      31             : {
      32    70045963 :   const FEFamily mapping_family = FEMap::map_fe_type(*elem);
      33    70045963 :   const FEType map_fe_type(elem->default_order(), mapping_family);
      34             : 
      35             :   // Note: we explicitly don't consider the elem->p_level() when
      36             :   // computing the number of mapping shape functions.
      37             :   const int n_mapping_shape_functions =
      38    70045963 :     FEInterface::n_shape_functions (map_fe_type, /*extra_order=*/0, elem);
      39             : 
      40             :   // Degrees of freedom are at vertices and edge midpoints
      41    70045963 :   static const Point dofpt[2] = {Point(-1), Point(1)};
      42             : 
      43             :   // Mapping functions - first derivatives at each dofpt
      44    75457339 :   std::vector<Real> dxdxi(2);
      45    70045963 :   std::vector<Real> dxidx(2);
      46             : 
      47             :   FEInterface::shape_deriv_ptr shape_deriv_ptr =
      48    70045963 :     FEInterface::shape_deriv_function(map_fe_type, elem);
      49             : 
      50   210137889 :   for (int p = 0; p != 2; ++p)
      51             :     {
      52   150872280 :       dxdxi[p] = 0;
      53   423132824 :       for (int i = 0; i != n_mapping_shape_functions; ++i)
      54             :         {
      55             :           const Real ddxi = shape_deriv_ptr
      56   283040898 :             (map_fe_type, elem, i, 0, dofpt[p], /*add_p_level=*/false);
      57   326619534 :           dxdxi[p] += elem->point(i)(0) * ddxi;
      58             :         }
      59             :     }
      60             : 
      61             :   // Calculate derivative scaling factors
      62    70045963 :   d1xd1x = dxdxi[0];
      63    70045963 :   d2xd2x = dxdxi[1];
      64    70045963 : }
      65             : 
      66             : 
      67             : } // end anonymous namespace
      68             : 
      69             : 
      70             : namespace libMesh
      71             : {
      72             : 
      73             : 
      74    15021188 : LIBMESH_DEFAULT_VECTORIZED_FE(1,HERMITE)
      75             : 
      76             : 
      77             : #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
      78             : 
      79             : template<>
      80    25815638 : Real FEHermite<1>::hermite_raw_shape_second_deriv (const unsigned int i, const Real xi)
      81             : {
      82             :   using Utility::pow;
      83             : 
      84    25815638 :   switch (i)
      85             :     {
      86     6424151 :     case 0:
      87     6424151 :       return 1.5 * xi;
      88     6424151 :     case 1:
      89     6424151 :       return -1.5 * xi;
      90     6424151 :     case 2:
      91     6424151 :       return 0.5 * (-1. + 3.*xi);
      92     6424151 :     case 3:
      93     6424151 :       return 0.5 * (1. + 3.*xi);
      94       92884 :     case 4:
      95       92884 :       return (8.*xi*xi + 4.*(xi*xi-1.))/24.;
      96       11637 :     case 5:
      97       11637 :       return (8.*xi*xi*xi + 12.*xi*(xi*xi-1.))/120.;
      98             :       //      case 6:
      99             :       //        return (8.*pow<4>(xi) + 20.*xi*xi*(xi*xi-1.) +
     100             :       //          2.*(xi*xi-1)*(xi*xi-1))/720.;
     101        1164 :     default:
     102        1164 :       Real denominator = 720., xipower = 1.;
     103       23504 :       for (unsigned n=6; n != i; ++n)
     104             :         {
     105        8991 :           xipower *= xi;
     106        8991 :           denominator *= (n+1);
     107        2307 :         }
     108       15656 :       return (8.*pow<4>(xi)*xipower +
     109       16820 :               (8.*(i-4)+4.)*xi*xi*xipower*(xi*xi-1.) +
     110       14513 :               (i-4)*(i-5)*xipower*(xi*xi-1.)*(xi*xi-1.))/denominator;
     111             :     }
     112             : }
     113             : 
     114             : #endif
     115             : 
     116             : 
     117             : template<>
     118    63093683 : Real FEHermite<1>::hermite_raw_shape_deriv(const unsigned int i, const Real xi)
     119             : {
     120    63093683 :   switch (i)
     121             :     {
     122    15703186 :     case 0:
     123    15703186 :       return 0.75 * (-1. + xi*xi);
     124    15703186 :     case 1:
     125    15703186 :       return 0.75 * (1. - xi*xi);
     126    15703186 :     case 2:
     127    15703186 :       return 0.25 * (-1. - 2.*xi + 3.*xi*xi);
     128    15703186 :     case 3:
     129    15703186 :       return 0.25 * (-1. + 2.*xi + 3.*xi*xi);
     130      227979 :     case 4:
     131      227979 :       return 4.*xi * (xi*xi-1.)/24.;
     132       23633 :     case 5:
     133       23633 :       return (4*xi*xi*(xi*xi-1.) + (xi*xi-1.)*(xi*xi-1.))/120.;
     134             :       //      case 6:
     135             :       //        return (4*xi*xi*xi*(xi*xi-1.) + 2*xi*(xi*xi-1.)*(xi*xi-1.))/720.;
     136        2467 :     default:
     137        2467 :       Real denominator = 720., xipower = 1.;
     138       48045 :       for (unsigned n=6; n != i; ++n)
     139             :         {
     140       18718 :           xipower *= xi;
     141       18718 :           denominator *= (n+1);
     142        4922 :         }
     143       34249 :       return (4*xi*xi*xi*xipower*(xi*xi-1.) +
     144       29327 :               (i-4)*xi*xipower*(xi*xi-1.)*(xi*xi-1.))/denominator;
     145             :     }
     146             : }
     147             : 
     148             : template<>
     149   168104434 : Real FEHermite<1>::hermite_raw_shape(const unsigned int i, const Real xi)
     150             : {
     151   168104434 :   switch (i)
     152             :     {
     153    41918959 :     case 0:
     154    41918959 :       return 0.25 * (2. - 3.*xi + xi*xi*xi);
     155    41918959 :     case 1:
     156    41918959 :       return 0.25 * (2. + 3.*xi - xi*xi*xi);
     157    41918959 :     case 2:
     158    41918959 :       return 0.25 * (1. - xi - xi*xi + xi*xi*xi);
     159    41918959 :     case 3:
     160    41918959 :       return 0.25 * (-1. - xi + xi*xi + xi*xi*xi);
     161             :       // All high order terms have the form x^(p-4)(x^2-1)^2/p!
     162      358848 :     case 4:
     163      358848 :       return (xi*xi-1.) * (xi*xi-1.)/24.;
     164       30883 :     case 5:
     165       30883 :       return xi * (xi*xi-1.) * (xi*xi-1.)/120.;
     166             :       //      case 6:
     167             :       //        return xi*xi * (xi*xi-1.) * (xi*xi-1.)/720.;
     168        3265 :     default:
     169        3265 :       Real denominator = 720., xipower = 1.;
     170       63698 :       for (unsigned n=6; n != i; ++n)
     171             :         {
     172       24831 :           xipower *= xi;
     173       24831 :           denominator *= (n+1);
     174        6497 :         }
     175       38867 :       return (xi*xi*xipower*(xi*xi-1.)*(xi*xi-1.))/denominator;
     176             : 
     177             :     }
     178             : }
     179             : 
     180             : 
     181             : template <>
     182    60545906 : Real FE<1,HERMITE>::shape(const Elem * elem,
     183             :                           const Order libmesh_dbg_var(order),
     184             :                           const unsigned int i,
     185             :                           const Point & p,
     186             :                           const bool libmesh_dbg_var(add_p_level))
     187             : {
     188     5182945 :   libmesh_assert(elem);
     189             : 
     190             :   // Coefficient naming: d(1)d(2n) is the coefficient of the
     191             :   // global shape function corresponding to value 1 in terms of the
     192             :   // local shape function corresponding to normal derivative 2
     193             :   Real d1xd1x, d2xd2x;
     194             : 
     195    60545906 :   hermite_compute_coefs(elem, d1xd1x, d2xd2x);
     196             : 
     197    60545906 :   const ElemType type = elem->type();
     198             : 
     199             : #ifndef NDEBUG
     200             :   const unsigned int totalorder =
     201     5182945 :     order + add_p_level * elem->p_level();
     202             : #endif
     203             : 
     204    60545906 :   switch (type)
     205             :     {
     206             :       // C1 functions on the C1 cubic edge
     207    60545906 :     case EDGE2:
     208             :     case EDGE3:
     209             :       {
     210     5182945 :         libmesh_assert_less (i, totalorder+1);
     211             : 
     212    60545906 :         switch (i)
     213             :           {
     214    15106127 :           case 0:
     215    15106127 :             return FEHermite<1>::hermite_raw_shape(0, p(0));
     216    15106127 :           case 1:
     217    15106127 :             return d1xd1x * FEHermite<1>::hermite_raw_shape(2, p(0));
     218    15106127 :           case 2:
     219    15106127 :             return FEHermite<1>::hermite_raw_shape(1, p(0));
     220    15106127 :           case 3:
     221    15106127 :             return d2xd2x * FEHermite<1>::hermite_raw_shape(3, p(0));
     222      121398 :           default:
     223      121398 :             return FEHermite<1>::hermite_raw_shape(i, p(0));
     224             :           }
     225             :       }
     226           0 :     default:
     227           0 :       libmesh_error_msg("ERROR: Unsupported element type = " << Utility::enum_to_string(type));
     228             :     }
     229             : }
     230             : 
     231             : 
     232             : 
     233             : template <>
     234           0 : Real FE<1,HERMITE>::shape(const ElemType,
     235             :                           const Order,
     236             :                           const unsigned int,
     237             :                           const Point &)
     238             : {
     239           0 :   libmesh_error_msg("Hermite elements require the real element \nto construct gradient-based degrees of freedom.");
     240             :   return 0.;
     241             : }
     242             : 
     243             : 
     244             : template <>
     245           0 : Real FE<1,HERMITE>::shape(const FEType fet,
     246             :                           const Elem * elem,
     247             :                           const unsigned int i,
     248             :                           const Point & p,
     249             :                           const bool add_p_level)
     250             : {
     251           0 :   return FE<1,HERMITE>::shape(elem, fet.order, i, p, add_p_level);
     252             : }
     253             : 
     254             : 
     255             : template <>
     256     4891243 : Real FE<1,HERMITE>::shape_deriv(const Elem * elem,
     257             :                                 const Order libmesh_dbg_var(order),
     258             :                                 const unsigned int i,
     259             :                                 const unsigned int,
     260             :                                 const Point & p,
     261             :                                 const bool libmesh_dbg_var(add_p_level))
     262             : {
     263      125815 :   libmesh_assert(elem);
     264             : 
     265             :   // Coefficient naming: d(1)d(2n) is the coefficient of the
     266             :   // global shape function corresponding to value 1 in terms of the
     267             :   // local shape function corresponding to normal derivative 2
     268             :   Real d1xd1x, d2xd2x;
     269             : 
     270     4891243 :   hermite_compute_coefs(elem, d1xd1x, d2xd2x);
     271             : 
     272     4891243 :   const ElemType type = elem->type();
     273             : 
     274             : #ifndef NDEBUG
     275             :   const unsigned int totalorder =
     276      125815 :     order + add_p_level * elem->p_level();
     277             : #endif
     278             : 
     279     4891243 :   switch (type)
     280             :     {
     281             :       // C1 functions on the C1 cubic edge
     282     4891243 :     case EDGE2:
     283             :     case EDGE3:
     284             :       {
     285      125815 :         libmesh_assert_less (i, totalorder+1);
     286             : 
     287     4891243 :         switch (i)
     288             :           {
     289     1199226 :           case 0:
     290     1199226 :             return FEHermite<1>::hermite_raw_shape_deriv(0, p(0));
     291     1199226 :           case 1:
     292     1199226 :             return d1xd1x * FEHermite<1>::hermite_raw_shape_deriv(2, p(0));
     293     1199226 :           case 2:
     294     1199226 :             return FEHermite<1>::hermite_raw_shape_deriv(1, p(0));
     295     1199226 :           case 3:
     296     1199226 :             return d2xd2x * FEHermite<1>::hermite_raw_shape_deriv(3, p(0));
     297       94339 :           default:
     298       94339 :             return FEHermite<1>::hermite_raw_shape_deriv(i, p(0));
     299             :           }
     300             :       }
     301           0 :     default:
     302           0 :       libmesh_error_msg("ERROR: Unsupported element type = " << Utility::enum_to_string(type));
     303             :     }
     304             : }
     305             : 
     306             : 
     307             : template <>
     308           0 : Real FE<1,HERMITE>::shape_deriv(const ElemType,
     309             :                                 const Order,
     310             :                                 const unsigned int,
     311             :                                 const unsigned int,
     312             :                                 const Point &)
     313             : {
     314           0 :   libmesh_error_msg("Hermite elements require the real element \nto construct gradient-based degrees of freedom.");
     315             :   return 0.;
     316             : }
     317             : 
     318             : template <>
     319           0 : Real FE<1,HERMITE>::shape_deriv(const FEType fet,
     320             :                                 const Elem * elem,
     321             :                                 const unsigned int i,
     322             :                                 const unsigned int j,
     323             :                                 const Point & p,
     324             :                                 const bool add_p_level)
     325             : {
     326           0 :   return FE<1,HERMITE>::shape_deriv(elem, fet.order, i, j, p, add_p_level);
     327             : }
     328             : 
     329             : #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
     330             : 
     331             : 
     332             : template <>
     333     4608814 : Real FE<1,HERMITE>::shape_second_deriv(const Elem * elem,
     334             :                                        const Order libmesh_dbg_var(order),
     335             :                                        const unsigned int i,
     336             :                                        const unsigned int,
     337             :                                        const Point & p,
     338             :                                        const bool libmesh_dbg_var(add_p_level))
     339             : {
     340      102616 :   libmesh_assert(elem);
     341             : 
     342             :   // Coefficient naming: d(1)d(2n) is the coefficient of the
     343             :   // global shape function corresponding to value 1 in terms of the
     344             :   // local shape function corresponding to normal derivative 2
     345             :   Real d1xd1x, d2xd2x;
     346             : 
     347     4608814 :   hermite_compute_coefs(elem, d1xd1x, d2xd2x);
     348             : 
     349     4608814 :   const ElemType type = elem->type();
     350             : 
     351             : #ifndef NDEBUG
     352             :   const unsigned int totalorder =
     353      102616 :     order + add_p_level * elem->p_level();
     354             : #endif
     355             : 
     356     4608814 :   switch (type)
     357             :     {
     358             :       // C1 functions on the C1 cubic edge
     359     4608814 :     case EDGE2:
     360             :     case EDGE3:
     361             :       {
     362      102616 :         libmesh_assert_less (i, totalorder+1);
     363             : 
     364     4608814 :         switch (i)
     365             :           {
     366     1139695 :           case 0:
     367     1139695 :             return FEHermite<1>::hermite_raw_shape_second_deriv(0, p(0));
     368     1139695 :           case 1:
     369     1139695 :             return d1xd1x * FEHermite<1>::hermite_raw_shape_second_deriv(2, p(0));
     370     1139695 :           case 2:
     371     1139695 :             return FEHermite<1>::hermite_raw_shape_second_deriv(1, p(0));
     372     1139695 :           case 3:
     373     1139695 :             return d2xd2x * FEHermite<1>::hermite_raw_shape_second_deriv(3, p(0));
     374       50034 :           default:
     375       50034 :             return FEHermite<1>::hermite_raw_shape_second_deriv(i, p(0));
     376             :           }
     377             :       }
     378           0 :     default:
     379           0 :       libmesh_error_msg("ERROR: Unsupported element type = " << Utility::enum_to_string(type));
     380             :     }
     381             : }
     382             : 
     383             : 
     384             : template <>
     385           0 : Real FE<1,HERMITE>::shape_second_deriv(const ElemType,
     386             :                                        const Order,
     387             :                                        const unsigned int,
     388             :                                        const unsigned int,
     389             :                                        const Point &)
     390             : {
     391           0 :   libmesh_error_msg("Hermite elements require the real element \nto construct gradient-based degrees of freedom.");
     392             :   return 0.;
     393             : }
     394             : 
     395             : template <>
     396           0 : Real FE<1,HERMITE>::shape_second_deriv(const FEType fet,
     397             :                                        const Elem * elem,
     398             :                                        const unsigned int i,
     399             :                                        const unsigned int j,
     400             :                                        const Point & p,
     401             :                                        const bool add_p_level)
     402             : {
     403           0 :   return FE<1,HERMITE>::shape_second_deriv(elem, fet.order, i, j, p, add_p_level);
     404             : }
     405             : 
     406             : 
     407             : #endif
     408             : 
     409             : } // namespace libMesh

Generated by: LCOV version 1.14