I have a 3D irregular mesh. Each coordinate point holds a specific data, say , for example, temperature.
For a specific point, how do I calculate the temperature gradient ?
I have a 3D irregular mesh. Each coordinate point holds a specific data, say , for example, temperature.
For a specific point, how do I calculate the temperature gradient ?
Copyright © 2021 JogjaFile Inc.
Ideally in this scenario, you would not have the data just at the mesh points, but would rather be doing some kind of a finite element type construction, which would give you the temperature as a function on each mesh element. Then the gradient would be given as part of the profile (i.e. you could analytically differentiate at every point except perhaps points on the boundary of a mesh element).
The next best thing would be data points on a regular mesh. Then you could approximate the partial derivatives directly, and assemble them into the gradient vector.
Since you don't even have that, you can do the following. At a mesh point $x$, find three nearby mesh points $x_1,x_2,x_3$. Then $\frac{f(x)-f(x_i)}{\| x-x_i \|}$ should be approximately the directional derivative of $f$ at $x$ in the direction $x-x_i$. That directional derivative is exactly $\nabla f(x) \cdot \frac{x-x_i}{\| x-x_i \|}$.
Now assume for numerical purposes that
$$f(x)-f(x_i)=\nabla f(x) \cdot (x-x_i).$$
This is a system of three linear scalar equations in three scalar unknowns (namely the components of $\nabla f(x)$). Provided the $x-x_i$ are linearly independent, it has a unique solution, so you can solve it in principle. Depending on how irregular your mesh is, you could have issues with numerical instability.