Skip to content

Grid Classes

Arakawa C-grid spatial discretization containers for 1-D, 2-D, and 3-D domains.

1-D Grid

finitevolx.ArakawaCGrid1D

Bases: Module

1-D Arakawa C-grid.

Parameters:

Name Type Description Default
Nx int

Total number of cells in x (including 2 ghost cells).

required
Lx float

Physical domain length in x.

required
dx float

Grid spacing in x.

required
Source code in finitevolx/_src/grid/grid.py
class ArakawaCGrid1D(eqx.Module):
    """1-D Arakawa C-grid.

    Parameters
    ----------
    Nx : int
        Total number of cells in x (including 2 ghost cells).
    Lx : float
        Physical domain length in x.
    dx : float
        Grid spacing in x.
    """

    Nx: int
    Lx: float
    dx: float

    @classmethod
    def from_interior(cls, nx_interior: int, Lx: float) -> "ArakawaCGrid1D":
        """Construct grid from interior cell count.

        Parameters
        ----------
        nx_interior : int
            Number of interior (physical) cells.
        Lx : float
            Physical domain length.

        Returns
        -------
        ArakawaCGrid1D
        """
        Nx = nx_interior + 2
        dx = Lx / nx_interior
        return cls(Nx=Nx, Lx=Lx, dx=dx)

from_interior(nx_interior, Lx) classmethod

Construct grid from interior cell count.

Parameters:

Name Type Description Default
nx_interior int

Number of interior (physical) cells.

required
Lx float

Physical domain length.

required

Returns:

Type Description
ArakawaCGrid1D
Source code in finitevolx/_src/grid/grid.py
@classmethod
def from_interior(cls, nx_interior: int, Lx: float) -> "ArakawaCGrid1D":
    """Construct grid from interior cell count.

    Parameters
    ----------
    nx_interior : int
        Number of interior (physical) cells.
    Lx : float
        Physical domain length.

    Returns
    -------
    ArakawaCGrid1D
    """
    Nx = nx_interior + 2
    dx = Lx / nx_interior
    return cls(Nx=Nx, Lx=Lx, dx=dx)

2-D Grid

finitevolx.ArakawaCGrid2D

Bases: Module

2-D Arakawa C-grid.

Parameters:

Name Type Description Default
Nx int

Total number of cells in x (including 2 ghost cells).

required
Ny int

Total number of cells in y (including 2 ghost cells).

required
Lx float

Physical domain length in x.

required
Ly float

Physical domain length in y.

required
dx float

Grid spacing in x.

required
dy float

Grid spacing in y.

required
Notes

Array layout (total shape [Ny, Nx])::

j=Ny-1  +--+--+--+  ghost row (north)
        |  |  |  |
j=2     +--+--+--+
j=1     +--+--+--+  physical interior  [1:-1, 1:-1]
j=0     +--+--+--+  ghost row (south)
        i=0  ...  i=Nx-1
        ghost    ghost
        (west)   (east)

Colocation convention::

T[j, i]  cell centre    at  (i*dx,     j*dy    )
U[j, i]  east face      at  ((i+1/2)*dx, j*dy  )
V[j, i]  north face     at  (i*dx,    (j+1/2)*dy)
X[j, i]  NE corner      at  ((i+1/2)*dx,(j+1/2)*dy)
Source code in finitevolx/_src/grid/grid.py
class ArakawaCGrid2D(eqx.Module):
    """2-D Arakawa C-grid.

    Parameters
    ----------
    Nx : int
        Total number of cells in x (including 2 ghost cells).
    Ny : int
        Total number of cells in y (including 2 ghost cells).
    Lx : float
        Physical domain length in x.
    Ly : float
        Physical domain length in y.
    dx : float
        Grid spacing in x.
    dy : float
        Grid spacing in y.

    Notes
    -----
    Array layout (total shape [Ny, Nx])::

        j=Ny-1  +--+--+--+  ghost row (north)
                |  |  |  |
        j=2     +--+--+--+
        j=1     +--+--+--+  physical interior  [1:-1, 1:-1]
        j=0     +--+--+--+  ghost row (south)
                i=0  ...  i=Nx-1
                ghost    ghost
                (west)   (east)

    Colocation convention::

        T[j, i]  cell centre    at  (i*dx,     j*dy    )
        U[j, i]  east face      at  ((i+1/2)*dx, j*dy  )
        V[j, i]  north face     at  (i*dx,    (j+1/2)*dy)
        X[j, i]  NE corner      at  ((i+1/2)*dx,(j+1/2)*dy)
    """

    Nx: int
    Ny: int
    Lx: float
    Ly: float
    dx: float
    dy: float

    @classmethod
    def from_interior(
        cls, nx_interior: int, ny_interior: int, Lx: float, Ly: float
    ) -> "ArakawaCGrid2D":
        """Construct grid from interior cell counts.

        Parameters
        ----------
        nx_interior : int
            Number of interior (physical) cells in x.
        ny_interior : int
            Number of interior (physical) cells in y.
        Lx : float
            Physical domain length in x.
        Ly : float
            Physical domain length in y.

        Returns
        -------
        ArakawaCGrid2D
        """
        Nx = nx_interior + 2
        Ny = ny_interior + 2
        dx = Lx / nx_interior
        dy = Ly / ny_interior
        return cls(Nx=Nx, Ny=Ny, Lx=Lx, Ly=Ly, dx=dx, dy=dy)

from_interior(nx_interior, ny_interior, Lx, Ly) classmethod

Construct grid from interior cell counts.

Parameters:

Name Type Description Default
nx_interior int

Number of interior (physical) cells in x.

required
ny_interior int

Number of interior (physical) cells in y.

required
Lx float

Physical domain length in x.

required
Ly float

Physical domain length in y.

required

Returns:

Type Description
ArakawaCGrid2D
Source code in finitevolx/_src/grid/grid.py
@classmethod
def from_interior(
    cls, nx_interior: int, ny_interior: int, Lx: float, Ly: float
) -> "ArakawaCGrid2D":
    """Construct grid from interior cell counts.

    Parameters
    ----------
    nx_interior : int
        Number of interior (physical) cells in x.
    ny_interior : int
        Number of interior (physical) cells in y.
    Lx : float
        Physical domain length in x.
    Ly : float
        Physical domain length in y.

    Returns
    -------
    ArakawaCGrid2D
    """
    Nx = nx_interior + 2
    Ny = ny_interior + 2
    dx = Lx / nx_interior
    dy = Ly / ny_interior
    return cls(Nx=Nx, Ny=Ny, Lx=Lx, Ly=Ly, dx=dx, dy=dy)

3-D Grid

finitevolx.ArakawaCGrid3D

Bases: Module

3-D Arakawa C-grid.

Parameters:

Name Type Description Default
Nx int

Total number of cells in x (including 2 ghost cells).

required
Ny int

Total number of cells in y (including 2 ghost cells).

required
Nz int

Total number of cells in z (including 2 ghost cells).

required
Lx float

Physical domain length in x.

required
Ly float

Physical domain length in y.

required
Lz float

Physical domain length in z.

required
dx float

Grid spacing in x.

required
dy float

Grid spacing in y.

required
dz float

Grid spacing in z.

required
Source code in finitevolx/_src/grid/grid.py
class ArakawaCGrid3D(eqx.Module):
    """3-D Arakawa C-grid.

    Parameters
    ----------
    Nx : int
        Total number of cells in x (including 2 ghost cells).
    Ny : int
        Total number of cells in y (including 2 ghost cells).
    Nz : int
        Total number of cells in z (including 2 ghost cells).
    Lx : float
        Physical domain length in x.
    Ly : float
        Physical domain length in y.
    Lz : float
        Physical domain length in z.
    dx : float
        Grid spacing in x.
    dy : float
        Grid spacing in y.
    dz : float
        Grid spacing in z.
    """

    Nx: int
    Ny: int
    Nz: int
    Lx: float
    Ly: float
    Lz: float
    dx: float
    dy: float
    dz: float

    @classmethod
    def from_interior(
        cls,
        nx_interior: int,
        ny_interior: int,
        nz_interior: int,
        Lx: float,
        Ly: float,
        Lz: float,
    ) -> "ArakawaCGrid3D":
        """Construct grid from interior cell counts.

        Parameters
        ----------
        nx_interior : int
            Number of interior cells in x.
        ny_interior : int
            Number of interior cells in y.
        nz_interior : int
            Number of interior cells in z.
        Lx : float
            Physical domain length in x.
        Ly : float
            Physical domain length in y.
        Lz : float
            Physical domain length in z.

        Returns
        -------
        ArakawaCGrid3D
        """
        Nx = nx_interior + 2
        Ny = ny_interior + 2
        Nz = nz_interior + 2
        dx = Lx / nx_interior
        dy = Ly / ny_interior
        dz = Lz / nz_interior
        return cls(Nx=Nx, Ny=Ny, Nz=Nz, Lx=Lx, Ly=Ly, Lz=Lz, dx=dx, dy=dy, dz=dz)

    def horizontal_grid(self) -> "ArakawaCGrid2D":
        """Extract the horizontal 2-D grid from this 3-D grid.

        Returns
        -------
        ArakawaCGrid2D
            A 2-D grid with the same Nx, Ny, Lx, Ly, dx, dy.
        """
        return ArakawaCGrid2D(
            Nx=self.Nx, Ny=self.Ny, Lx=self.Lx, Ly=self.Ly, dx=self.dx, dy=self.dy
        )

from_interior(nx_interior, ny_interior, nz_interior, Lx, Ly, Lz) classmethod

Construct grid from interior cell counts.

Parameters:

Name Type Description Default
nx_interior int

Number of interior cells in x.

required
ny_interior int

Number of interior cells in y.

required
nz_interior int

Number of interior cells in z.

required
Lx float

Physical domain length in x.

required
Ly float

Physical domain length in y.

required
Lz float

Physical domain length in z.

required

Returns:

Type Description
ArakawaCGrid3D
Source code in finitevolx/_src/grid/grid.py
@classmethod
def from_interior(
    cls,
    nx_interior: int,
    ny_interior: int,
    nz_interior: int,
    Lx: float,
    Ly: float,
    Lz: float,
) -> "ArakawaCGrid3D":
    """Construct grid from interior cell counts.

    Parameters
    ----------
    nx_interior : int
        Number of interior cells in x.
    ny_interior : int
        Number of interior cells in y.
    nz_interior : int
        Number of interior cells in z.
    Lx : float
        Physical domain length in x.
    Ly : float
        Physical domain length in y.
    Lz : float
        Physical domain length in z.

    Returns
    -------
    ArakawaCGrid3D
    """
    Nx = nx_interior + 2
    Ny = ny_interior + 2
    Nz = nz_interior + 2
    dx = Lx / nx_interior
    dy = Ly / ny_interior
    dz = Lz / nz_interior
    return cls(Nx=Nx, Ny=Ny, Nz=Nz, Lx=Lx, Ly=Ly, Lz=Lz, dx=dx, dy=dy, dz=dz)

horizontal_grid()

Extract the horizontal 2-D grid from this 3-D grid.

Returns:

Type Description
ArakawaCGrid2D

A 2-D grid with the same Nx, Ny, Lx, Ly, dx, dy.

Source code in finitevolx/_src/grid/grid.py
def horizontal_grid(self) -> "ArakawaCGrid2D":
    """Extract the horizontal 2-D grid from this 3-D grid.

    Returns
    -------
    ArakawaCGrid2D
        A 2-D grid with the same Nx, Ny, Lx, Ly, dx, dy.
    """
    return ArakawaCGrid2D(
        Nx=self.Nx, Ny=self.Ny, Lx=self.Lx, Ly=self.Ly, dx=self.dx, dy=self.dy
    )