This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

How to calculate the laplacian / second derivatives?

+2 votes

My current problem involves the Laplace operator of a known function f in the weak formulation. Since $\Delta f = \nabla \cdot \nabla f$, I figured I could just use div(grad(f)) here. However, this returns a function that is zero everywhere?

As the code below shows, I also tried applying the second derivatives directly. Am I correct to believe that f.dx(0).dx(0) is UFL for $\frac{\partial^2 f}{\partial x^2}$?

from dolfin import *
mesh = UnitCubeMesh(30, 30, 30)
V = FunctionSpace(mesh, 'CG', 1)
expr = Expression('x[0]*x[0]*x[0] - x[1]*x[1]*x[2]')
f = project(expr, V)
plot(f, interactive=True)
plot(grad(f), interactive=True)
plot(div(grad(f)), interactive=True)
plot(f.dx(0).dx(0) + f.dx(1).dx(1) + f.dx(2).dx(2), interactive=True)

ps I am currently using version 1.4

asked Oct 30, 2015 by maartent FEniCS User (3,910 points)

The second-derivative of a CG1-function should be 0. However, you are correct in your assumption.

That is indeed something I overlooked, CG2 works fine. Thanks!

1 Answer

+1 vote
 
Best answer

so you could project to CG2 ...

answered Nov 2, 2015 by KristianE FEniCS Expert (12,900 points)
selected Nov 2, 2015 by maartent
...