Difference between grad(f) and f.dx(0)?

Hi,

I have just started to learn FEniCS. I am trying to understand an existing code and in some of the weak functions it uses grad and in some of them it uses .dx(0). I derived the analytical functions by hand both of them come from del(f)/del(x), where f is a scalar variable in the theory.

Can anyone explain what is the difference?

Say that your domain \Omega \subset \mathbb{R}^2, and call (x, y) the vector of coordinates in \Omega. Then \partial f/\partial x is implemented as f.dx(0), \partial f/\partial y is implemented as f.dx(1), while grad(f) is the vector of partial derivatives, i.e. grad(f) = [f.dx(0), f.dx(1)].

1 Like

Thank you!

I think I understand. But for 1d domain, something like u.dx(0)*v.dx(0) should be the same as inner(grad(u), grad(v)), right?

Yes, it is the same.

Thank you very much!