Staggered grids

Google Collab Book

Staggered grids are a key component of the marker-and-cell (MAC) method [Harlow and Welch 1965]. They sample the velocity components not at the cell centers but in staggered form at the corresponding face centers. Their main advantage is that the divergence of a cell can be computed exactly.

ΦFlow only stores valid velocity values in memory. This may require non-uniform tensors for the values since the numbers of horizontal and vertical faces are generally not equal. Depending on the boundary conditions, the outer-most values may also be redundant and, thus, not stored.

image

ΦFlow represents staggered grids as instances of StaggeredGrid. They have the same properties as CenteredGrid but the values field may reference a non-uniform tensor to reflect the varying number of x, y and z sample points.

Here, each component of the values tensor has one more sample point in the direction it is facing. If the extrapolation was extrapolation.ZERO, it would be one less (see above image).

Creating Staggered Grids

The StaggeredGrid constructor supports two modes:

Examples:

Staggered grids can also be created from other fields using field.at() or @ by passing an existing StaggeredGrid.

Some field functions also return StaggeredGrids:

Values Tensor

For non-periodic staggered grids, the values tensor is non-uniform to reflect the different number of sample points for each component.

Functions to get a uniform tensor:

Slicing

Like tensors, grids can be sliced using the standard syntax. When selecting a vector component, such as x or y, the result is represented as a CenteredGrid with shifted locations.

Slicing spatial dimensions on grids is different from slicing the values tensor directly. Here, a sub-grid is selected. The number of sample points depends on the grid type and extrapolation.

Slicing along batch dimensions has no special effect, this just slices the values.

Fields can also be sliced using unstack(). This returns a tuple of all slices along a dimension.