GridBase#

class fridom.framework.grid.GridBase(n_dims: int)[source]#

Bases: object

Base class for all grids in the framework.

Description#

This class does not implement any functionality, but provides a template for all grid classes in the framework. The base class also sets default flags and attributes that are common to all grids. Child classes should override these flags and attributes as needed.

Flags#

fourier_transform_availablebool

Indicates whether the grid supports fast fourier transforms.

mpi_availablebool

Indicates whether the grid supports MPI parallelization.

__init__(n_dims: int) None[source]#

Methods

__init__(n_dims)

create_array([pad, spectral, topo])

Create an array.

create_random_array([seed, pad, spectral, topo])

Create a random array.

fft(arr[, padding, bc_types, positions, axes])

Perform a (fast) fourier transform on the input array.

get_mesh([position, spectral])

Get the meshgrid of the grid points.

ifft(arr[, padding, bc_types, positions, axes])

Perform an inverse (fast) fourier transform on the input array.

omega(k[, use_discrete])

Compute the dispersion relation of the model.

pad(arr)

Add halo padding to an array.

setup(mset)

Initialize the grid from the model settings.

sync(arr[, flat_axes])

Synchronize the halo (boundary) points of an array across all MPI ranks.

sync_multi(arrs)

Synchronize the halo (boundary) points of multiple arrays across all MPI ranks.

unpad(arr)

Remove the halo padding from an array.

vec_p(s[, use_discrete])

Computes the projection vector of the linear operator of the mode s.

vec_q(s[, use_discrete])

Computes the eigenvector of the linear operator of the mode s.

Attributes

K

The wavenumber of the grid.

L

The length of the grid in each dimension.

N

The number of grid points in each dimension.

X

The meshgrid of the grid points.

cell_center

The position of the cell centers.

dV

The volume element of the grid.

diff_module

The differential operator module.

domain_decomp

The domain decomposition object.

dx

The grid spacing in each dimension.

fourier_transform_available

Indicates whether the grid supports fast fourier transforms.

info

Return a dictionary with information about the grid.

interp_module

The interpolation operator module.

k_global

The global wavenumber of the grid.

mpi_available

Indicates whether the grid supports MPI parallelization.

mset

The model settings object.

n_dims

The number of dimensions of the grid.

omega_analytical

Analytical dispersion relation.

omega_space_discrete

Dispersion relation with space-discretization effects.

omega_time_discrete

Dispersion relation with space-time-discretization effects.

periodic_bounds

A tuple of booleans indicating whether the grid is periodic in each dimension.

spectral_grid

Indicates whether the grid is a spectral grid.

total_grid_points

The total number of grid points in the grid.

water_mask

Get the water mask.

x_global

The x-vector of the global grid points.

Examples using fridom.framework.grid.GridBase#

Barotropic Jet

Barotropic Jet

Reflecting Wave Package

Reflecting Wave Package

Internal Gravity Wave Maker

Internal Gravity Wave Maker

Convection and Closures

Convection and Closures

Multiple Wave Makers

Multiple Wave Makers

Rayleigh-Taylor Instability

Rayleigh-Taylor Instability

Rayleigh-Bénard Convection

Rayleigh-Bénard Convection

Single Internal Wave

Single Internal Wave

Dancing Eddies

Dancing Eddies

Symmetric Instability

Symmetric Instability

Tracers and Eddies

Tracers and Eddies

Barotropic Instability

Barotropic Instability
setup(mset: ModelSettingsBase) None[source]#

Initialize the grid from the model settings.

Parameters#

msetModelSettingsBase

The model settings object. This is for example needed to determine the required halo size.

get_mesh(position: Position | None = None, spectral: bool = False) tuple[ndarray][source]#

Get the meshgrid of the grid points.

Parameters#

positionPosition or None (default: None)

The position of the field.

spectralbool (default: False)

Whether to return the meshgrid of the spectral domain.

Returns#

tuple[ndarray]

The meshgrid of the grid points.

abstract fft(arr: ndarray, padding=FFTPadding.NOPADDING, bc_types: tuple[BCType] | None = None, positions: tuple[AxisPosition] | None = None, axes: tuple[int] | None = None) ndarray[source]#

Perform a (fast) fourier transform on the input array.

Parameters#

arrndarray

The input array.

paddingFFTPadding (default: FFTPadding.NOPADDING)

The padding to apply to the array.

bc_typestuple[BCType] or None (default: None)

The boundary conditions to apply to each axis.

positionstuple[AxisPosition] or None (default: None)

The position of the field.

axestuple[int] or None (default: None)

The axes to transform.

Returns#

ndarray

The transformed array.

abstract ifft(arr: ndarray, padding=FFTPadding.NOPADDING, bc_types: tuple[BCType] | None = None, positions: tuple[AxisPosition] | None = None, axes: tuple[int] | None = None) ndarray[source]#

Perform an inverse (fast) fourier transform on the input array.

Parameters#

arrndarray

The input array.

paddingFFTPadding (default: FFTPadding.NOPADDING)

The padding to apply to the array.

bc_typestuple[BCType] or None (default: None)

The boundary conditions to apply to each axis.

positionstuple[AxisPosition] or None (default: None)

The position of the field.

axestuple[int] or None (default: None)

The axes to transform.

Returns#

ndarray

The transformed array.

abstract omega(k: tuple[float] | tuple[ndarray], use_discrete: bool = False) ndarray[source]#

Compute the dispersion relation of the model.

Parameters#

ktuple[float] | tuple[ndarray]

The wave numbers

use_discretebool (default: False)

Whether to include space-discretization effects.

Returns#

ndarray

The dispersion relation (omega(k)).

abstract vec_q(s: int, use_discrete: bool = True) StateBase[source]#

Computes the eigenvector of the linear operator of the mode s.

Parameters#

sint

The mode (which eigenvalue / eigenvector to compute).

use_discretebool (default: True)

Whether to include space-discretization effects.

Returns#

StateBase

The eigenvector of the linear operator.

abstract vec_p(s: int, use_discrete: bool = True) StateBase[source]#

Computes the projection vector of the linear operator of the mode s.

Parameters#

sint

The mode (which eigenvalue / eigenvector to compute).

use_discretebool (default: True)

Whether to include space-discretization effects.

Returns#

StateBase

The projection vector of the linear operator.

property omega_analytical: ndarray#

Analytical dispersion relation.

property omega_space_discrete: ndarray#

Dispersion relation with space-discretization effects.

property omega_time_discrete#

Dispersion relation with space-time-discretization effects. Warning: The computation may be very slow.

sync(arr: ndarray, flat_axes: list[int] | None = None) ndarray[source]#

Synchronize the halo (boundary) points of an array across all MPI ranks.

Parameters#

arrndarray

The array to synchronize.

Returns#

ndarray

The synchronized array.

sync_multi(arrs: tuple[ndarray]) tuple[ndarray][source]#

Synchronize the halo (boundary) points of multiple arrays across all MPI ranks.

Parameters#

arrslist[ndarray]

The list of arrays to synchronize.

Returns#

list[ndarray]

The synchronized list of arrays.

unpad(arr: ndarray) ndarray[source]#

Remove the halo padding from an array.

Parameters#

arrndarray

The padded array.

Returns#

ndarray

The unpadded array.

pad(arr: ndarray) ndarray[source]#

Add halo padding to an array.

Parameters#

arrndarray

The unpadded array.

Returns#

ndarray

The padded array.

create_array(pad: bool = True, spectral: bool = False, topo: tuple[bool] | None = None) ndarray[source]#

Create an array.

Parameters#

padbool

Whether to add padding to the array.

spectralbool

Whether the array is in spectral space.

topotuple[bool] | None

The topology of the array. Axes with false are flat (only one grid point)

create_random_array(seed: int = 1234, pad: bool = True, spectral: bool = False, topo: tuple[bool] | None = None) ndarray[source]#

Create a random array.

Parameters#

seedint

The seed for the random number generator.

padbool

Whether to add padding to the array.

spectralbool

Whether the array is in spectral space.

topotuple[bool] | None

The topology of the array. Axes with false are flat (only one grid point)

property info: dict#

Return a dictionary with information about the grid.

Description#

This method should be overridden by the child class to return a dictionary with information about the grid. This information is used to print the grid in the __repr__ method.

property diff_module: DiffModule#

The differential operator module.

property interp_module: InterpolationModule#

The interpolation operator module.

property water_mask: WaterMask#

Get the water mask.

property mset: ModelSettingsBase | None#

The model settings object.

property domain_decomp: DomainDecomposition#

The domain decomposition object.

property n_dims: int#

The number of dimensions of the grid.

property N: tuple[int]#

The number of grid points in each dimension.

property L: tuple[float]#

The length of the grid in each dimension.

property total_grid_points: int#

The total number of grid points in the grid.

property periodic_bounds: list[bool]#

A tuple of booleans indicating whether the grid is periodic in each dimension.

property cell_center: Position#

The position of the cell centers.

property X: tuple[ndarray]#

The meshgrid of the grid points.

property x_global: tuple[ndarray]#

The x-vector of the global grid points.

property K: ndarray#

The wavenumber of the grid.

property k_global: ndarray#

The global wavenumber of the grid.

property dx: tuple[ndarray]#

The grid spacing in each dimension.

property dV: ndarray#

The volume element of the grid.

property fourier_transform_available: bool#

Indicates whether the grid supports fast fourier transforms.

property mpi_available: bool#

Indicates whether the grid supports MPI parallelization.

property spectral_grid: bool#

Indicates whether the grid is a spectral grid.