Greetings 
Does anyone know if diff() is a partial derivative or a derivative?
For instance, would the following:
w0 = ((1-p)**2)*Psi + (Gc/(2*l))*p**2 + ((Gc*l)/2)*(grad(p))**2
W0_diffPhi = diff(w0, p)
result in the grad(p) being differentiated too or just the terms with p?
Thanks in advance to anyone who knows.
dokken
2
It is a partial derivative, see the following minimal example:
import ufl
from dolfin import *
mesh = UnitSquareMesh(10, 10)
V = FunctionSpace(mesh, "Lagrange", 1)
u = Function(V)
u.interpolate(Expression("x[0]+2*x[1]", degree=1))
# Gives 0, as the variable is `u`, not grad(u)
a = grad(u)[0]*grad(u)[0]
p = diff(a, u)
print(ufl.algorithms.expand_derivatives(p), assemble(p*dx))
# Gives a value
q = variable(ufl.grad(u)[0])
a1 = inner(q, q)
p1 = diff(a1, q)
print(ufl.algorithms.expand_derivatives(p1), assemble(p1*dx))
# Gives a value
a3 = inner(u, u)**2
p3 = diff(a3, u)
print(ufl.algorithms.expand_derivatives(p3), assemble(p3*dx))
see: Form language — Unified Form Language (UFL) 2021.1.0 documentation
for more info
2 Likes
Thanks so much Jorgen! Really appreciate