# Retrieving Basis Functions

Hello,
Is there any way to easily recover the basis functions on an element? I see that the transformation from reference element to global element can be obtained by element.GetTrafo(), and in the documentation the element is described as containing the shape functions, is there any way to quickly return them? Failing that, if I wan to implement them myself, are the basis functions used the traditional hat functions? (for example, in the case of order 2 on triangular faces, the P2 basis functions)

Best,
Ben Latham

Hi,
here is a small tutorial on how to implement your own basis functions:
https://docu.ngsolve.org/latest/i-tutorials/unit-9.1-C%2B%2BFE/CppExtension.html

NGSolve uses (for the H1 space) a hierarchical basis you can find the implementation in fem/h1hofe_impl.hpp
a good reference for this is here: Institute of Numerical Mathematics - PhD theses

Thank you very much for the prompt response and the references. I take it then that there is no way within the existing code to retrieve the basis functions in a way where they can be evaluated, either in the reference element or the global space?

Ah yes, you can create a mesh just containing the reference element and set a gridfunction to unit vectors and evaluate it. Is that what you mean? Also in the tutorial is how to draw the single basis functions by setting gf to unit vectors.

The finite element space can create a finite element, which can be evaluated from Python, in reference coordinates.
If you have global coordinate, you first have to find the element-nr and local coordinates.

fes = H1(mesh, order=2)
fe = fes.GetFE(ElementId(VOL,0))
print (fe.CalcShape(x=0,y=0))

mp = mesh(x=0.2,y=0.2) # find element nr and local coordinates
el = fes.GetFE(ElementId(VOL, mp.nr)) # create finite element
el.CalcShape(x=mp.pnt, y=mp.pnt) # eval shape function vector

Thank you so much, this is very helpful!

Best,
Ben Latham