# Basis function/shape function of P2 triangular & tetrahedral element

**URL:** <https://community.freefem.org/t/basis-function-shape-function-of-p2-triangular-tetrahedral-element/4140>\
**Category:** General Discussion\
**Created:** [November 24, 2025, 2:24am UTC](https://community.freefem.org/t/basis-function-shape-function-of-p2-triangular-tetrahedral-element/4140 "2025-11-24T02:24:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![MatrixVector](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@MatrixVector](https://community.freefem.org/u/MatrixVector)\
**Post date:** [November 24, 2025, 2:24am UTC](https://community.freefem.org/t/basis-function-shape-function-of-p2-triangular-tetrahedral-element/4140/1 "2025-11-24T02:24:01Z")

</div>

I’m doing a postprocessing work which needs to calculate the Gauss integration points’ Cartesian coordinates. One way to implement this is substituting the Gauss coordinates into the basis functions or shape functions, and then multiplying the basis function vector with the element nodal coordinates vector.

Here, my question is about the basis functions used in FreeFem++. I found it is a bit different from that in the monograph of “The Finite Element Method Its Basis and Fundamentals” by Zienkiewicz, Taylor & Govindjee. According to the source code

[FreeFem-sources/src/femlib/P012\_2d.cpp at master · FreeFem/FreeFem-sources · GitHub](https://github.com/FreeFem/FreeFem-sources/blob/master/src/femlib/P012_2d.cpp#L164)

[FreeFem-sources/src/femlib/P012\_3d.cpp at master · FreeFem/FreeFem-sources · GitHub](https://github.com/FreeFem/FreeFem-sources/blob/master/src/femlib/P012_3d.cpp#L199)

where the `nvedge` array can be found in

[FreeFem-sources/src/femlib/Mesh2dn.cpp at master · FreeFem/FreeFem-sources · GitHub](https://github.com/FreeFem/FreeFem-sources/blob/master/src/femlib/Mesh2dn.cpp)

[FreeFem-sources/src/femlib/Mesh3dn.cpp at master · FreeFem/FreeFem-sources · GitHub](https://github.com/FreeFem/FreeFem-sources/blob/master/src/femlib/Mesh3dn.cpp)

The basis functions for P2 triangular element is

```cpp
// P2 Lagrange shape functions
[l0 * (2 * l0 - 1), 
 l1 * (2 * l1 - 1), 
 l2 * (2 * l2 - 1), 
 4 * l1 * l2, 
 4 * l2 * l0, 
 4 * l0 * l1];

```

and for P2 tetrahedral element is

```cpp
// P2 Lagrange shape functions
[l0 * (2 * l0 - 1),
 l1 * (2 * l1 - 1),
 l2 * (2 * l2 - 1),
 l3 * (2 * l3 - 1),
 4 * l0 * l1,
 4 * l0 * l2,
 4 * l0 * l3,
 4 * l1 * l2,
 4 * l1 * l3,
 4 * l2 * l3];

```

Are the above results correct?
