LCOV - code coverage report
Current view: top level - include/fe - fe_lagrange_shape_1D.h (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4640 (c5f9f0) with base a68dd6 Lines: 106 106 100.0 %
Date: 2026-11-02 23:02:27 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/enum_order.h" // FIRST, SECOND, etc.
      24             : #include "libmesh/point.h"
      25             : 
      26             : // Inline functions useful to inline on tensor elements.
      27             : 
      28             : namespace libMesh
      29             : {
      30             : 
      31             : inline
      32   407308406 : Real fe_lagrange_1D_linear_shape(const unsigned int i,
      33             :                                  const Real xi)
      34             : {
      35   407308406 :   libmesh_assert_less (i, 2);
      36             : 
      37  4164554076 :   switch (i)
      38             :     {
      39  2082277038 :     case 0:
      40  2115573891 :       return .5*(1. - xi);
      41             : 
      42             :     // case 1
      43  2082277038 :     default:
      44  2115573891 :       return .5*(1. + xi);
      45             :     }
      46             : }
      47             : 
      48             : 
      49             : 
      50             : inline
      51 24017639580 : Real fe_lagrange_1D_quadratic_shape(const unsigned int i,
      52             :                                     const Real xi)
      53             : {
      54  2059792065 :   libmesh_assert_less (i, 3);
      55             : 
      56 25994762121 :   switch (i)
      57             :     {
      58  8667569083 :     case 0:
      59  8687503800 :       return .5*xi*(xi - 1.);
      60             : 
      61  8667569083 :     case 1:
      62  8671368019 :       return .5*xi*(xi + 1);
      63             : 
      64             :     // case 2
      65  8659623955 :     default:
      66  8758292132 :       return (1. - xi*xi);
      67             :     }
      68             : }
      69             : 
      70             : 
      71             : 
      72             : inline
      73      142168 : Real fe_lagrange_1D_cubic_shape(const unsigned int i,
      74             :                                 const Real xi)
      75             : {
      76        9004 :   libmesh_assert_less (i, 4);
      77             : 
      78      142168 :   switch (i)
      79             :     {
      80       35542 :     case 0:
      81       35542 :       return 9./16.*(1./9.-xi*xi)*(xi-1.);
      82             : 
      83       35542 :     case 1:
      84       35542 :       return -9./16.*(1./9.-xi*xi)*(xi+1.);
      85             : 
      86       35542 :     case 2:
      87       35542 :       return 27./16.*(1.-xi*xi)*(1./3.-xi);
      88             : 
      89             :     // case 3
      90       35542 :     default:
      91       35542 :       return 27./16.*(1.-xi*xi)*(1./3.+xi);
      92             :     }
      93             : }
      94             : 
      95             : 
      96             : 
      97             : inline
      98    89757271 : Real fe_lagrange_1D_shape(const Order order,
      99             :                           const unsigned int i,
     100             :                           const Real xi)
     101             : {
     102     8771704 :   libmesh_assert_less_equal(order, THIRD);
     103             : 
     104    89757271 :   switch (order)
     105             :     {
     106             :       // Lagrange linears
     107     1125498 :     case FIRST:
     108     1125498 :       return fe_lagrange_1D_linear_shape(i, xi);
     109             : 
     110             :       // Lagrange quadratics
     111    74595561 :     case SECOND:
     112    74595561 :       return fe_lagrange_1D_quadratic_shape(i, xi);
     113             : 
     114             :       // Lagrange cubics
     115             :       // case THIRD
     116      142168 :     default:
     117      142168 :       return fe_lagrange_1D_cubic_shape(i, xi);
     118             :     }
     119             : }
     120             : 
     121             : 
     122             : 
     123             : inline
     124   115659492 : Real fe_lagrange_1D_linear_shape_deriv(const unsigned int i,
     125             :                                        const unsigned int libmesh_dbg_var(j),
     126             :                                        const Real)
     127             : {
     128             :   // only d()/dxi in 1D!
     129   115659492 :   libmesh_assert_equal_to (j, 0);
     130             : 
     131   115659492 :   libmesh_assert_less (i, 2);
     132             : 
     133  1247042794 :   switch (i)
     134             :     {
     135    57829746 :     case 0:
     136    57829746 :       return -.5;
     137             : 
     138             :     // case 1
     139   634811270 :     default:
     140   580174858 :       return .5;
     141             :     }
     142             : }
     143             : 
     144             : 
     145             : inline
     146   956095928 : Real fe_lagrange_1D_quadratic_shape_deriv(const unsigned int i,
     147             :                                           const unsigned int libmesh_dbg_var(j),
     148             :                                           const Real xi)
     149             : {
     150             :   // only d()/dxi in 1D!
     151   956095928 :   libmesh_assert_equal_to (j, 0);
     152             : 
     153   956095928 :   libmesh_assert_less (i, 3);
     154             : 
     155 12407955774 :   switch (i)
     156             :     {
     157  4137031247 :     case 0:
     158  4149166437 :       return xi-.5;
     159             : 
     160  4137031247 :     case 1:
     161  4139320889 :       return xi+.5;
     162             : 
     163             :     // case 2
     164  4133893280 :     default:
     165  4180587492 :       return -2.*xi;
     166             :     }
     167             : }
     168             : 
     169             : 
     170             : inline
     171      118800 : Real fe_lagrange_1D_cubic_shape_deriv(const unsigned int i,
     172             :                                       const unsigned int libmesh_dbg_var(j),
     173             :                                       const Real xi)
     174             : {
     175             :   // only d()/dxi in 1D!
     176        7456 :   libmesh_assert_equal_to (j, 0);
     177             : 
     178        7456 :   libmesh_assert_less (i, 4);
     179             : 
     180      118800 :   switch (i)
     181             :     {
     182       29700 :     case 0:
     183       29700 :       return -9./16.*(3.*xi*xi-2.*xi-1./9.);
     184             : 
     185       29700 :     case 1:
     186       29700 :       return -9./16.*(-3.*xi*xi-2.*xi+1./9.);
     187             : 
     188       29700 :     case 2:
     189       29700 :       return 27./16.*(3.*xi*xi-2./3.*xi-1.);
     190             : 
     191             :     // case 3
     192       29700 :     default:
     193       29700 :       return 27./16.*(-3.*xi*xi-2./3.*xi+1.);
     194             :     }
     195             : }
     196             : 
     197             : 
     198             : 
     199             : inline
     200   358538486 : Real fe_lagrange_1D_shape_deriv(const Order order,
     201             :                                 const unsigned int i,
     202             :                                 const unsigned int j,
     203             :                                 const Real xi)
     204             : {
     205    28707630 :   libmesh_assert_less_equal(order, THIRD);
     206             : 
     207   358538486 :   switch (order)
     208             :     {
     209    21786140 :     case FIRST:
     210    21786140 :       return fe_lagrange_1D_linear_shape_deriv(i, j, xi);
     211             : 
     212     6914034 :     case SECOND:
     213     6914034 :       return fe_lagrange_1D_quadratic_shape_deriv(i, j, xi);
     214             : 
     215             :     // case THIRD
     216      118800 :     default:
     217      118800 :       return fe_lagrange_1D_cubic_shape_deriv(i, j, xi);
     218             :     }
     219             : }
     220             : 
     221             : 
     222             : #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
     223             : 
     224             : // fe_lagrange_1D_linear_shape_second_deriv is 0
     225             : 
     226             : 
     227             : inline
     228    35561225 : Real fe_lagrange_1D_quadratic_shape_second_deriv(const unsigned int i,
     229             :                                                  const unsigned int libmesh_dbg_var(j),
     230             :                                                  const Real)
     231             : {
     232             :   // Don't need to switch on j.  1D shape functions
     233             :   // depend on xi only!
     234    35561225 :   libmesh_assert_equal_to (j, 0);
     235    35561225 :   libmesh_assert_less(i, 3);
     236             : 
     237   503512755 :   switch (i)
     238             :     {
     239    11740345 :     case 0:
     240    11740345 :       return 1.;
     241             : 
     242    11740345 :     case 1:
     243    11740345 :       return 1.;
     244             : 
     245             :     // case 2
     246   167591405 :     default:
     247   156627110 :       return -2.;
     248             :     }
     249             : }
     250             : 
     251             : 
     252             : inline
     253       15136 : Real fe_lagrange_1D_cubic_shape_second_deriv(const unsigned int i,
     254             :                                              const unsigned int libmesh_dbg_var(j),
     255             :                                              const Real xi)
     256             : {
     257             :   // Don't need to switch on j.  1D shape functions
     258             :   // depend on xi only!
     259        1376 :   libmesh_assert_equal_to (j, 0);
     260        1376 :   libmesh_assert_less(i, 4);
     261             : 
     262       15136 :   switch (i)
     263             :     {
     264        3784 :     case 0:
     265        3784 :       return -9./16.*(6.*xi-2);
     266             : 
     267        3784 :     case 1:
     268        3784 :       return -9./16.*(-6*xi-2.);
     269             : 
     270        3784 :     case 2:
     271        3784 :       return 27./16.*(6*xi-2./3.);
     272             : 
     273             :     // case 2
     274        3784 :     default:
     275        3784 :       return 27./16.*(-6*xi-2./3.);
     276             :     }
     277             : }
     278             : 
     279             : 
     280             : 
     281             : inline
     282     1522294 : Real fe_lagrange_1D_shape_second_deriv(const Order order,
     283             :                                        const unsigned int i,
     284             :                                        const unsigned int j,
     285             :                                        const Real xi)
     286             : {
     287       98879 :   libmesh_assert_less_equal(order, THIRD);
     288             : 
     289     1620357 :   switch (order)
     290             :     {
     291             :     // All second derivatives of linears are zero....
     292       13068 :     case FIRST:
     293       13068 :       return 0.;
     294             : 
     295       84435 :     case SECOND:
     296       84435 :       return fe_lagrange_1D_quadratic_shape_second_deriv(i, j, xi);
     297             : 
     298             :     // case THIRD
     299       16512 :     default:
     300       16512 :       return fe_lagrange_1D_cubic_shape_second_deriv(i, j, xi);
     301             :     } // end switch (order)
     302             : }
     303             : 
     304             : #endif // LIBMESH_ENABLE_SECOND_DERIVATIVES
     305             : 
     306             : }
     307             : 
     308             : #endif // LIBMESH_FE_LAGRANGE_SHAPE_1D_H

Generated by: LCOV version 1.14