Retrieving Basis Functions

More
2 years 7 months ago #4292 by Ben_Latham
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
More
2 years 7 months ago #4293 by christopher
Hi,
here is a small tutorial on how to implement your own basis functions:
docu.ngsolve.org/latest/i-tutorials/unit...FE/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: www.numa.uni-linz.ac.at/Teaching/PhD/Finished/zaglmayr-diss.pdf
More
2 years 7 months ago #4298 by Ben_Latham
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?
More
2 years 7 months ago #4302 by christopher
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.
More
2 years 7 months ago #4303 by joachim
Replied by joachim on topic Retrieving Basis Functions
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[0], y=mp.pnt[1]) # eval shape function vector
More
2 years 7 months ago #4314 by Ben_Latham
Thank you so much, this is very helpful!

Best,
Ben Latham
Time to create page: 0.100 seconds