# Differentiation with respect to spatial coordinate

Dear all,
I have read the “diff” explanation in the UFL documentation. Then I wrote a simple code to test the differentiation with respect to spatial coordinate. However when I run the following test code:

from dolfin import *

mesh = UnitSquareMesh(5, 5)
V = FunctionSpace(mesh, "CG", 1)

u= Function(V)
u.interpolate(Expression("2*x[0]+7*x[1]*x[1]+10", degree=1))

a1 = Expression("x[0]-3", degree=1)
a1 = variable(a1)

a2 = Expression("x[1]-8", degree=1)
a2 = variable(a2)

f1 = diff(u, a1)
f2 = diff(u, a2)

F = assemble(f1*f2*dx)
print("F:", F)


an error “ufl_legacy.log.UFLException: This integral is missing an integration domain” occurred.
Any help will be appreciated. Thank you very much in advance.

Best regards.

The error messages says that you are supposed to use diff on expressions like F, not your f1 and f2.

Sorry, I don’t get it. Let me change my question a little bit. Now I want to write a variational form in Fenics. It is $$F=\int_{\Omega}\frac{\partial u}{\partial(x-3)}\frac{\partial v}{\partial(y-8)}dx$$ (It is just a test so it has no physical meaning), where u is the trial function and v is the test function.
So I write it as:

from dolfin import *

mesh = UnitSquareMesh(5, 5)
V = FunctionSpace(mesh, "CG", 1)

u = TrialFunction(V)
v = TestFunction(V)

a1 = Expression("x[0]-3", degree=1)
a1 = variable(a1)

a2 = Expression("x[1]-8", degree=1)
a2 = variable(a2)

F = diff(u, a1) * diff(v, a2) *dx


However the same error occurred “This integral is missing an integration domain.”

That’s not like any partial derivative I’ve ever seen, and I doubt it has any mathematical sense. If you want \frac{\partial u}{\partial x} you can use u.dx(0), \frac{\partial u}{\partial y} then u.dx(1), and so on.

I understand now. Thank you very much. But if I want $$\frac{\partial u}{\partial x}$$ and u is a vector function, what should we use?

Still u.dx(0), I think.

OK. I understand now. Thank you very much for your kind help.