Taking partial derivatives in general - is this efficent

Howdy,

So I just want to make sure I’m thinking about this right and or if there is a better way to go about this - if you had a scalar pde eventually and had some partial derivatives that you can’t write in the gradient/nabla format would this be the best way to do it?

from dolfin import *

size=128

p1 = Point(-1.0,-1.0)
p2 = Point(1.0,1.0)
mesh = RectangleMesh(p1,p2,size,size)
V= FunctionSpace(mesh,‘CG’,1)
u=Function(V)

#correct way to define partial derivatives?
uxx = u.dx(0).dx(0)
uyy = u.dx(1).dx(1)
uxy = u.dx(0).dx(1)
uyx = u.dx(1).dx(0)

really complicated derivative just to establish if this is really how you do it

uxyxyxx = u.dx(0).dx(1).dx(0).dx(1).dx(0).dx(0)

I believe this is the correct way, but please read e.g the biharmonic demo. You must take care since the FE shape functions are not infinitely differentiable. Normally you only want one derivative in the weak form, but you can use stabilisation to work around this as described in the demo.

1 Like

Thank you so much for the response and this example. I understand what your saying.