Evaluation of grad function in Dolfin

Hi there,

I am trying to calculate the dot product of gradients of TestFunction(u) and TrialFunction(v). And I am working on 2D domain.

When I do;

dot(grad(u), grad(v))

it works perfectly. But when I customly define the grad function as;

def gradient(u):
    return dolf.Dx(u, 0) + dolf.Dx(u, 1) 

and using

dot(gradient(u), gradient(v))

giving completely different results. Could you please explain why?

That’s not the gradient you’ve written, it’s the divergence.

Consider something like

def gradient(u):
    return dolf.as_vector((dolf.Dx(u, 0), dolf.Dx(u, 1)))
1 Like

Thank you for your quick reply :slight_smile: