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

Writing the gradient explicitly

+5 votes

Hi,

Can the grad operator be written in terms of its components in FEniCS? I.e. Instead of

$$ \nabla u $$

which is coded as grad(u), is there some way to code

$$ \partial_x u + \partial_y u$$

Thanks

asked Jun 21, 2014 by sixtysymbols FEniCS User (2,280 points)

1 Answer

+5 votes
 
Best answer

You can try

Dx(u, 0) + Dx(u, 1)
answered Jun 21, 2014 by tianyikillua FEniCS User (1,620 points)
selected Jun 21, 2014 by Øyvind Evju

You can also index the grad operator:

grad(u)[0]+grad(u)[1]

or write it as

u.dx(0)+u.dx(1)

Index notation is also supported, I prefer

Dx(u,i)

Personally.

...