[Gmsh] computing gradient

Ondrej Certik ondrej at certik.cz
Mon May 2 20:35:53 CEST 2005


Hello,
first I would like to thank for a wonderful tool for
the pre/postprocessing. It really saves my time.

I would like to ask - what is the best way to compute a gradient of
a scalar field, which is given in nodes?

1)I computed it like this: I only have a triangular mesh and computed a
gradient vector on every triangle (see (**) for details) and then
computed a vector on every node by averaging the vectors at the
neighbouring triangles.

2)I applied Gradient Plugin to the same scalar field.

I plotted 1) and 2) here

http://ondrej.certik.cz/gmsh/grad.png

(the blue vectors are from the plugin, the grey vectors are mine).

As you can clearly see, it's not exactly equal (although roughly it is).
Where could be the problem?

I can provide all the *.msh, *.pos etc, if you want, but I think it
isn't important. The problem is probably how I compute the gradient.
That's why I ask.

I looked in the sources of the Gradient plugin, you compute some
Jacobians etc. - could you please briefly explain how it works, so I
could think why it gives different results?

Thanks,
Ondrej Certik


(**) The triangle is given in 2D by (x1,y1), (x2,y2), (x3,y3) nodes and
we have scalars (a1, a2, a3) associated to these nodes so I interpolate
a plane by these three points in 3D: (x1,y1,a1), (x2,y2,a2), (x3,y3,a3)
and compute a gradient using this plane. So I in fact approximate the
scalar function by a plane on the triangle.