Hello everyone,
This is a follow-up question to my post “Taking higher order derivatives”. I was wondering if it is correct to take second order derivatives of a P3 Lagrange finite element space by performing grad(grad(u)).
E.g:
Given V = FunctionSpace(submesh, “Lagrange”, 3)
u = TrialFunction(V)
to get the second derivative one would need to do:
grad(grad(u))
I am asking this because I got the impression from the responses to my previous post that this would work only when grad(grad(u)) is cell-wise constant i.e only when u is a P2 Lagrange finite element space. Thus, I am concerned that if I do grad(grad(u)) of a P3 Lagrange finite element space then it would not be accurate.
Consider the following MWE, illustrating that you can take second derivatives of a P1:
import fenics as fn
import numpy as np
mesh = fn.UnitSquareMesh(10, 10)
V = fn.FunctionSpace(mesh, "CG", 3)
u = fn.Function(V)
ggu = fn.grad(fn.grad(u))
u.interpolate(fn.Expression("pow(x[0],3)*x[1]", degree=4))
W = fn.FunctionSpace(mesh, "DG", 1)
w = fn.project(ggu[0, 0], W)
with fn.XDMFFile("u.xdmf") as xdmf:
xdmf.write(w)
Thank you @dokken for your reply. So, you recommend instead of using grad(grad(u)) directly in the variational form, I instead project every component to the DG function space W and use that?
Thank you again.
As long as u is a scalar valued function space, you can project grad(grad(u)) into a tensor function space, and then extract the components afterwards for visualization/post processing.