LCOV - code coverage report
Current view: top level - include/fe - fe_lagrange_shape_1D.h (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4573 (924896) with base 3f0912 Lines: 106 106 100.0 %
Date: 2026-11-18 21:52:26 Functions: 11 11 100.0 %
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             : #ifndef LIBMESH_FE_LAGRANGE_SHAPE_1D_H
      20             : #define LIBMESH_FE_LAGRANGE_SHAPE_1D_H
      21             : 
      22             : // Local includes
      23             : #include "libmesh/libmesh_device.h"
      24             : #include "libmesh/enum_order.h" // FIRST, SECOND, etc.
      25             : #include "libmesh/point.h"
      26             : 
      27             : // Inline functions useful to inline on tensor elements.
      28             : 
      29             : namespace libMesh
      30             : {
      31             : 
      32             : LIBMESH_DEVICE_INLINE
      33   516872864 : Real fe_lagrange_1D_linear_shape(const unsigned int i,
      34             :                                  const Real xi)
      35             : {
      36   516872864 :   libmesh_assert_less (i, 2);
      37             : 
      38  1414495154 :   switch (i)
      39             :     {
      40   728439452 :     case 0:
      41   900034944 :       return .5*(1. - xi);
      42             : 
      43             :     // case 1
      44   728439452 :     default:
      45   900034944 :       return .5*(1. + xi);
      46             :     }
      47             : }
      48             : 
      49             : 
      50             : 
      51             : LIBMESH_DEVICE_INLINE
      52  6530962197 : Real fe_lagrange_1D_quadratic_shape(const unsigned int i,
      53             :                                     const Real xi)
      54             : {
      55  2264705442 :   libmesh_assert_less (i, 3);
      56             : 
      57  8721960153 :   switch (i)
      58             :     {
      59  2906118538 :     case 0:
      60  2906118538 :       return .5*xi*(xi - 1.);
      61             : 
      62  2906118538 :     case 1:
      63  2906118538 :       return .5*xi*(xi + 1);
      64             : 
      65             :     // case 2
      66  2909723077 :     default:
      67  2932223563 :       return (1. - xi*xi);
      68             :     }
      69             : }
      70             : 
      71             : 
      72             : 
      73             : LIBMESH_DEVICE_INLINE
      74       38080 : Real fe_lagrange_1D_cubic_shape(const unsigned int i,
      75             :                                 const Real xi)
      76             : {
      77       10656 :   libmesh_assert_less (i, 4);
      78             : 
      79       38080 :   switch (i)
      80             :     {
      81        9520 :     case 0:
      82        9520 :       return 9./16.*(1./9.-xi*xi)*(xi-1.);
      83             : 
      84        9520 :     case 1:
      85        9520 :       return -9./16.*(1./9.-xi*xi)*(xi+1.);
      86             : 
      87        9520 :     case 2:
      88        9520 :       return 27./16.*(1.-xi*xi)*(1./3.-xi);
      89             : 
      90             :     // case 3
      91        9520 :     default:
      92        9520 :       return 27./16.*(1.-xi*xi)*(1./3.+xi);
      93             :     }
      94             : }
      95             : 
      96             : 
      97             : 
      98             : LIBMESH_DEVICE_INLINE
      99    29900100 : Real fe_lagrange_1D_shape(const Order order,
     100             :                           const unsigned int i,
     101             :                           const Real xi)
     102             : {
     103     8826669 :   libmesh_assert_less_equal(order, THIRD);
     104             : 
     105    29900100 :   switch (order)
     106             :     {
     107             :       // Lagrange linears
     108     1127142 :     case FIRST:
     109     1127142 :       return fe_lagrange_1D_linear_shape(i, xi);
     110             : 
     111             :       // Lagrange quadratics
     112    19296027 :     case SECOND:
     113    19296027 :       return fe_lagrange_1D_quadratic_shape(i, xi);
     114             : 
     115             :       // Lagrange cubics
     116             :       // case THIRD
     117       38080 :     default:
     118       38080 :       return fe_lagrange_1D_cubic_shape(i, xi);
     119             :     }
     120             : }
     121             : 
     122             : 
     123             : 
     124             : LIBMESH_DEVICE_INLINE
     125   146446524 : Real fe_lagrange_1D_linear_shape_deriv(const unsigned int i,
     126             :                                        const unsigned int libmesh_dbg_var(j),
     127             :                                        const Real)
     128             : {
     129             :   // only d()/dxi in 1D!
     130   146446524 :   libmesh_assert_equal_to (j, 0);
     131             : 
     132   146446524 :   libmesh_assert_less (i, 2);
     133             : 
     134   403005382 :   switch (i)
     135             :     {
     136    73223262 :     case 0:
     137    73223262 :       return -.5;
     138             : 
     139             :     // case 1
     140   179252913 :     default:
     141   136470821 :       return .5;
     142             :     }
     143             : }
     144             : 
     145             : 
     146             : LIBMESH_DEVICE_INLINE
     147  1029137401 : Real fe_lagrange_1D_quadratic_shape_deriv(const unsigned int i,
     148             :                                           const unsigned int libmesh_dbg_var(j),
     149             :                                           const Real xi)
     150             : {
     151             :   // only d()/dxi in 1D!
     152  1029137401 :   libmesh_assert_equal_to (j, 0);
     153             : 
     154  1029137401 :   libmesh_assert_less (i, 3);
     155             : 
     156  4057954858 :   switch (i)
     157             :     {
     158  1352205362 :     case 0:
     159  1352205362 :       return xi-.5;
     160             : 
     161  1352205362 :     case 1:
     162  1352205362 :       return xi+.5;
     163             : 
     164             :     // case 2
     165  1353544134 :     default:
     166  1362421842 :       return -2.*xi;
     167             :     }
     168             : }
     169             : 
     170             : 
     171             : LIBMESH_DEVICE_INLINE
     172       34880 : Real fe_lagrange_1D_cubic_shape_deriv(const unsigned int i,
     173             :                                       const unsigned int libmesh_dbg_var(j),
     174             :                                       const Real xi)
     175             : {
     176             :   // only d()/dxi in 1D!
     177        8880 :   libmesh_assert_equal_to (j, 0);
     178             : 
     179        8880 :   libmesh_assert_less (i, 4);
     180             : 
     181       34880 :   switch (i)
     182             :     {
     183        8720 :     case 0:
     184        8720 :       return -9./16.*(3.*xi*xi-2.*xi-1./9.);
     185             : 
     186        8720 :     case 1:
     187        8720 :       return -9./16.*(-3.*xi*xi-2.*xi+1./9.);
     188             : 
     189        8720 :     case 2:
     190        8720 :       return 27./16.*(3.*xi*xi-2./3.*xi-1.);
     191             : 
     192             :     // case 3
     193        8720 :     default:
     194        8720 :       return 27./16.*(-3.*xi*xi-2./3.*xi+1.);
     195             :     }
     196             : }
     197             : 
     198             : 
     199             : 
     200             : LIBMESH_DEVICE_INLINE
     201    91240802 : Real fe_lagrange_1D_shape_deriv(const Order order,
     202             :                                 const unsigned int i,
     203             :                                 const unsigned int j,
     204             :                                 const Real xi)
     205             : {
     206    28755536 :   libmesh_assert_less_equal(order, THIRD);
     207             : 
     208    91240802 :   switch (order)
     209             :     {
     210    21787316 :     case FIRST:
     211    21787316 :       return fe_lagrange_1D_linear_shape_deriv(i, j, xi);
     212             : 
     213     6959340 :     case SECOND:
     214     6959340 :       return fe_lagrange_1D_quadratic_shape_deriv(i, j, xi);
     215             : 
     216             :     // case THIRD
     217       34880 :     default:
     218       34880 :       return fe_lagrange_1D_cubic_shape_deriv(i, j, xi);
     219             :     }
     220             : }
     221             : 
     222             : 
     223             : #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
     224             : 
     225             : // fe_lagrange_1D_linear_shape_second_deriv is 0
     226             : 
     227             : 
     228             : LIBMESH_DEVICE_INLINE
     229    36774311 : Real fe_lagrange_1D_quadratic_shape_second_deriv(const unsigned int i,
     230             :                                                  const unsigned int libmesh_dbg_var(j),
     231             :                                                  const Real)
     232             : {
     233             :   // Don't need to switch on j.  1D shape functions
     234             :   // depend on xi only!
     235    36774311 :   libmesh_assert_equal_to (j, 0);
     236    36774311 :   libmesh_assert_less(i, 3);
     237             : 
     238   121461425 :   switch (i)
     239             :     {
     240    12138457 :     case 0:
     241    12138457 :       return 1.;
     242             : 
     243    12138457 :     case 1:
     244    12138457 :       return 1.;
     245             : 
     246             :     // case 2
     247    40596845 :     default:
     248    39083936 :       return -2.;
     249             :     }
     250             : }
     251             : 
     252             : 
     253             : LIBMESH_DEVICE_INLINE
     254        5808 : Real fe_lagrange_1D_cubic_shape_second_deriv(const unsigned int i,
     255             :                                              const unsigned int libmesh_dbg_var(j),
     256             :                                              const Real xi)
     257             : {
     258             :   // Don't need to switch on j.  1D shape functions
     259             :   // depend on xi only!
     260        1936 :   libmesh_assert_equal_to (j, 0);
     261        1936 :   libmesh_assert_less(i, 4);
     262             : 
     263        5808 :   switch (i)
     264             :     {
     265        1452 :     case 0:
     266        1452 :       return -9./16.*(6.*xi-2);
     267             : 
     268        1452 :     case 1:
     269        1452 :       return -9./16.*(-6*xi-2.);
     270             : 
     271        1452 :     case 2:
     272        1452 :       return 27./16.*(6*xi-2./3.);
     273             : 
     274             :     // case 2
     275        1452 :     default:
     276        1452 :       return 27./16.*(-6*xi-2./3.);
     277             :     }
     278             : }
     279             : 
     280             : 
     281             : 
     282             : LIBMESH_DEVICE_INLINE
     283      298004 : Real fe_lagrange_1D_shape_second_deriv(const Order order,
     284             :                                        const unsigned int i,
     285             :                                        const unsigned int j,
     286             :                                        const Real xi)
     287             : {
     288      100313 :   libmesh_assert_less_equal(order, THIRD);
     289             : 
     290      397501 :   switch (order)
     291             :     {
     292             :     // All second derivatives of linears are zero....
     293       13312 :     case FIRST:
     294       13312 :       return 0.;
     295             : 
     296       85065 :     case SECOND:
     297       85065 :       return fe_lagrange_1D_quadratic_shape_second_deriv(i, j, xi);
     298             : 
     299             :     // case THIRD
     300        7744 :     default:
     301        7744 :       return fe_lagrange_1D_cubic_shape_second_deriv(i, j, xi);
     302             :     } // end switch (order)
     303             : }
     304             : 
     305             : #endif // LIBMESH_ENABLE_SECOND_DERIVATIVES
     306             : 
     307             : }
     308             : 
     309             : #endif // LIBMESH_FE_LAGRANGE_SHAPE_1D_H

Generated by: LCOV version 1.14