Dear All,
I would like to know what are the possibilities to implement higher order derivatives of a test function in NGSolve.
- From a previous forum topic, I saw that a hessian differential operator had already been implemented for H1, which is already great.
- From another forum topic I saw that that there might exist additional DifferentialOperator using an add-on library called ngxfem. (Do you have any insight on this?)
Is there any updates on this matter?
Are there other tricks that I should know to implement higher order derivatives of test functions?
Thanking you in advance for your help,
Vincent
Hi Vincent,
you can interpolate (element-wise) nodes of an expression tree into another fe-space, which allows to build higher order (element-wise!) derivatives:
from ngsolve import *
mesh = Mesh(unit_square.GenerateMesh(maxh=2))
fes = H1(mesh, order=3)
u,v = fes.TnT()
fes2 = L2(mesh, order=2)**2
def Hesse(u):
return u.Operator("hesse")
bf2a = BilinearForm(InnerProduct(Hesse(u), Hesse(v)) * dx).Assemble()
print (bf2a.mat.DeleteZeroElements(1e-10))
bf2b = BilinearForm(InnerProduct(grad(Interpolate(grad(u), fes2)), grad(Interpolate(grad(v), fes2))) * dx).Assemble()
print(bf2b.mat.DeleteZeroElements(1e-10))
fes3 = (L2(mesh, order=1)**2)**2
def Diff3a(u):
return grad(Interpolate(grad(Interpolate(grad(u), fes2)), fes3))
def Diff3b(u):
return grad(Interpolate(Hesse(u), fes3))
bf3a = BilinearForm(InnerProduct(Diff3a(u), Diff3a(v))*dx).Assemble()
print(bf3a.mat.DeleteZeroElements(1e-10))
bf3b = BilinearForm(InnerProduct(Diff3b(u), Diff3b(v))*dx).Assemble()
print(bf3b.mat.DeleteZeroElements(1e-10))
bf2a and bf2b provide the same matrices, as well as bf3a and bf3b. This feature is not heavily tested, better to double-check your results.
Joachim
Hello Joachim,
Thank you very much for your quick reply.
I tried to implement the trick on a simple biharmonic case for which I have the analytical solution.
You will find the jupyter notebook attached.
The solution distribution seems correct:
- The Hessian trick is not too good (see first notebook cell).
- The fes interpolation can be very close (see second notebook cell) to the exact distribution if you choose specific orders for your main and second finite element spaces (3->2 not OK, 4->2 not OK, 5->3 and 7->5 ok).
However, I always get a large constant factor between analytical and real solution. Intuitively, I would guess it is because my BCs are not constraining sufficiently the solution, but I would love to have your expert eyes on this matter. Do you have any idea?
Also, the trick does not work for HCurl. Do you know why? Any chance I can make the trick work on a HCurl space?
Thanking you in advance for your help,
Vincent
Test_higher_order.ipynb (653.2 KB)
it would be boring if it were so easy ![:slight_smile: :slight_smile:](https://forum.ngsolve.org/images/emoji/twitter/slight_smile.png?v=12)
If you want to solve a 4th order equation, it is not enough just computing second order derivatives. You need a C^1-continuous fe-space, or DG, or mixed methods, or …
An intuitive explanation is that (higher order) derivatives produce distributional terms on element interfaces. My recommendation is the (hybridized) Hellan-Herrmann-Johnson method.
see:
https://docu.ngsolve.org/latest/i-tutorials/unit-2.9-fourthorder/fourthorder.html
or
https://jschoeberl.github.io/iFEM/plates_shells/1_hhj.html
Joachim
1 Like
Hello Joachim,
Sorry for the naive question.
I will take a look at the Hellan-Herrmann-Johnson method.
Thank you!!
Vincent
Hello Joachim,
Thank you again for your help.
I implemented a mixed method to the biharmonic problem in ngsolve and it worked perfectly.
Are there any reasons why this would not be the preferred method to handle higher order operators (going to order 6 or even 10)?
Looking forward to reading from you soon,
Vincent