Grad vs Grad


I am chasing a bug for my Navier-Stokes solver using Hdiv-HDG for a more than a week, and finally found out that for Hdiv-space, the correct way to calculate the gradient is using
Grad instead of grad
This is a bit odd, as I am always using the lower-case grad operator… lol

So what’s the difference???
Is there any documentation I can found on the source code on the implementation of differential operators?
This kind of bugs are extremely hard find as the lower case grad operator is also stable, but produce inaccurate results…


Alright, it looks like that Grad is simply grad.trans…

Hi, there was an inconsistency in the grad, for example in the VectorH1 and H1(…, dim=3) once it is the jacobin and once the transpose.
To not break old code we introduced the Grad as a consistent version over all spaces.

Thanks for the clarification!

Hi Christopher,

I cannot understand when you say grad is transpose? Do you mean that grad(u) is the row vector when u is a scalar field? Thank you.


You can do

print (Grad(u).dims)

to get the vector/matrix/tensor shape of the expression.

grad(u) of a scalar is a vector (i.e. a first order tensor), and we do not distinguish between row or col vector.

A simple method to figure out the ordering of the matrix (tensor) is drawing:

u = GridFunction(VectorH1( … ))
u.Set( (x+2*y, 0) )
Draw (Grad(u)[0,1], mesh)

Recommendation: use grad(u) for scalar, and Grad(u) for vectorial functions.


Hi Joachim,

I am kind of confused about your final recommendation. Based on my understanding of this forum, if u is a vectorial field, in Einstein notation we have:
grad(u) = d u_j / d u_i delta_i delta_j
Grad(u) = d u_i / d u_j delta_i delta_j
where delta_i represent the unit vectors. And based on my understanding, the first one (grad) is the true mathematical definition of gradient operator. So why should one use Grad(u)?


people like to think of the Jacobi-matrix (e.g. in mechanics), then Grad(u) is the one to use,