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

derivative in one direction

+3 votes

Instead of the gradient of a scalar trial function u(x,y), I want to only compute the derivate along x.

My solution would be:
Define a vector-field function e_x of unit vectors in x-direction and carry out the projection of the gradient: inner(e_x, grad(u))

However, this seems rather complicated. Is there a better way to compute the derivate (like an implemented function in UFL?)

Thanks in advance

asked May 28, 2014 by jegmi FEniCS Novice (270 points)

1 Answer

+5 votes
 
Best answer

This can easily be handled like this:

from dolfin import *
mesh = UnitSquareMesh(4,4)
expr = Expression("4*x[0]*x[1]") # Dummy Expression

V = FunctionSpace(mesh, "CG", 1) # Space for function
Q = FunctionSpace(mesh, "DG", 0) # Space for derivative
u = project(expr, V)

udx = project(u.dx(0), Q) # u.dx(1) for y-derivative

plot(u)
plot(udx)
interactive()
answered May 28, 2014 by Øyvind Evju FEniCS Expert (17,700 points)
selected May 29, 2014 by jegmi

I was hoping for something like that! Thank you!

Another way to do this is: Dx(u, 0) .

...