Compute the gradient of a quantiy on a grid

  • Context: Undergrad 
  • Thread starter Thread starter matteo86bo
  • Start date Start date
  • Tags Tags
    Gradient Grid
Click For Summary
SUMMARY

This discussion focuses on computing the gradient of a quantity defined on a grid, specifically addressing the challenges of calculating gradients in both 2D and 3D grids. The incorrect method of using \(\nabla\rho(i)=\frac{\rho(i)}{\Delta(i)}\) is highlighted, and the correct approach involves using finite difference approximations. For 3D gradients, the "5-point finite difference approximation" is introduced, with a specific formula provided for the x-direction. The need for a comprehensive formula that incorporates all 27 neighboring cells in a 3D grid is emphasized.

PREREQUISITES
  • Understanding of gradient computation in vector calculus
  • Familiarity with finite difference methods
  • Knowledge of grid structures in numerical simulations
  • Basic concepts of 2D and 3D spatial analysis
NEXT STEPS
  • Research "5-point finite difference approximation" for gradient calculation
  • Explore methods for incorporating diagonal neighbors in 3D gradient calculations
  • Study "central difference methods" for improved accuracy in gradient estimation
  • Investigate "finite volume methods" for gradient computation in grid-based simulations
USEFUL FOR

Researchers, numerical analysts, and engineers working with grid-based simulations, particularly those involved in computational fluid dynamics and spatial data analysis.

matteo86bo
Messages
56
Reaction score
0
Hi, this might be a stupid question, but I was wondering how to computer the gradient of a quantity on a grid. I mean I have a grid made of cells (not necessarily of the same size) where the variable [itex]\rho[/itex] is defined at the center of every cell. How can I compute the gradient of this quantity?
It is wrong doing this:
[itex]\nabla\rho(i)=\frac{\rho(i)}{\Delta(i)}[/itex]
where [itex]\Delta(i)[/itex] is the size of cell i.
I can't come up with other methods ...
 
Physics news on Phys.org
I assume you are talking about a two-dimensional grid. The length of the gradient at each point is the fastest rate of increase over all directions and its direction is the direction in which you have that fastest increase. Assuming a rectangular grid so that each point has four immediate neighbors, each point has only four "neighbors" so you can only calculate four derivatives (difference between values at neighboring points divided by distance between those two points). Determine which of those is largest, take the value as the length of the gradient and its direction as the direction from the point to that neighbor (so there are only four possible directions.

You can extend that slightly by also using the "secondary" neighbors, lying on the "diagonal" of a grid square, giving 8 possible direction. You will have to take the longer diagonal distance into account.
 
I didn't understand all you said ... I think I found the solution but I'm still a little bit concerned.

I need to computer a 3D gradient and for every direction I can use the "5-point finite difference approximation" of the gradient...

[tex] (\nabla\rho)_x=\frac{4}{3}\frac{\rho_{i+1}-\rho_{i-1}}{2\Delta x}-\frac{1}{3}\frac{\rho_{i+2}-\rho_{i-2}}{4\Delta x}[/tex]

But how can I take into account the "diagonal" of the cube? The above formula compute the gradient only for one specific directorion ... I would like to know if there exists a formula to compute it by taking into account all the 27 neighbouring cells ...
 

Similar threads

  • · Replies 18 ·
Replies
18
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 38 ·
2
Replies
38
Views
7K
  • · Replies 1 ·
Replies
1
Views
2K