• Advertisement
Sign in to follow this  

Staggered grid implementation

This topic is 3549 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I did some reading on fluid simulation and found that to get a stable discretization you have to use a staggered grid. How exactly is a staggered grid implemented. From what I understood, you have to store the velocities at the faces, but isn't this exactly the same as storing the velocities per cell and performing trilinear interpolation between x and x+1, y and y+1, z and z+1 everytime I want to access a value inside a cell. Or is there more to it? Some (pseudo) code would be helpful if I"m wrong with that. Thanks, Icebraker

Share this post


Link to post
Share on other sites
Advertisement
A staggered grid stores axial velocity at the faces. That is, each face which is parallel to the XY plane will store the Z velocity which is at the center of the face, each face which is parallel to the XZ plane will store Y the velocity which is at the center of the face, etc.

Share this post


Link to post
Share on other sites
Well, I understand that, but where is the difference in implementing? I mean, if I just store three velocities per cell and interpolate them with the neighbouring cells x+1,y,z ; x,y+1,a and x,y,,z+1 , then this should give me the velocities inside the cell of a staggered grid ... and as it doesn't really matter where on the face I store it I might as well store it at the integer part of the cell. Therefore, to obtain any velocity value inside the cell I simply do trilinear interpolation with the calls x+1,y,z; x,y+1,z and x,y,z+1 if I understand this correctly....

Share this post


Link to post
Share on other sites
Quote:
as it doesn't really matter where on the face I store it I might as well store it at the integer part of the cell.

It certainly does matter. The points at which you store the velocity are the only points that have the exact correct velocity. All the other points, you're using interpolation to make your best guess. It turns out that the staggered grid gives you useful places to know the exact velocity, particularly when you need to calculate the divergence. It also simplifies much of the math.

Share this post


Link to post
Share on other sites
But the axial velocity is constant over one face, isn't it? I currently store the velocities at the integer part of the cell and interpolate using the following cole (only shown for u):

xFrac = x-(int)x; // Same for y and z
i_int = (int)x; j_int = (int)y; k_int = (int)z;

u1 = lerp(xFrac, u[i_int][j_int][k_int], u[i_int+1][j_int][k_int]);
u2 = lerp(xFrac, u[i_int][j_int+1][k_int], u[i_int+1][j_int+1][k_int]);
u3 = lerp(xFrac, u[i_int][j_int][k_int+1], u[i_int+1][j_int][k_int+1]);
u4 = lerp(xFrac, u[i_int][j_int+1][k_int+1], u[i_int+1][j_int+1][k_int+1]);
u5 = lerp(yFrac, u1, u2);
u6 = lerp(yFrac, u3, u4);
u7 = lerp(zFrac, u5, u6);

However, a symmetric drop becomes assymmetric, so I think there must be something wrong here... What am I doing wrong?

Share this post


Link to post
Share on other sites
Quote:
Original post by Icebraker
But the axial velocity is constant over one face, isn't it?

Nope. Why would it be? Why would every particle of the gas passing through a random square inch in space just happen to have exactly the same Z velocity?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement