[Gmsh] computing gradient

Christophe Geuzaine geuzaine at acm.caltech.edu
Wed May 4 19:08:27 CEST 2005


Ondrej Certik wrote:
> 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?
> 

Hello Ondrej,

Gmsh's Gradient plugin works as follows:

- we define a mapping from a reference element (e.g., a triangle) in a 
reference coordinate system ("u,v,w") into the "real" space where the 
mesh lives (with coordinates "x,y,z")

- we compute the gradient in the reference coordinates u,v,w using 
finite element-type basis functions (that computation is done per 
element, not per node)

- then we transform the gradient in the u,v,w coordinates into the 
gradient in the x,y,z coordinates. This involves the (inverse of the) 
Jacobian of the mapping.

Hope this helps,

Christophe



> 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.
> _______________________________________________
> gmsh mailing list
> gmsh at geuz.org
> http://www.geuz.org/mailman/listinfo/gmsh
> 
> 


-- 
Christophe Geuzaine
Applied and Computational Mathematics, Caltech
geuzaine at acm.caltech.edu - http://geuz.org