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.

cumulative_integral(field, axis[, direction])

Compute the cumulative integral of a field along a given axis.

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.

integrate(field[, axes])

Integrate a scalar field over a given domain.

max(field[, axes])

Compute the maximum of a field over the given axes.

min(field[, axes])

Compute the minimum of a field over the given axes.

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.

sum(field[, axes])

Sum a field over the given axes.

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.

characteristic_function

The characteristic function of the grid (1 inside the domain, 0 outside).

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.

halo

The halo size of the grid.

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

Convection and Closures

Convection and Closures

Dancing Eddies

Dancing Eddies

Internal Gravity Wave Maker

Internal Gravity Wave Maker

Multiple Wave Makers

Multiple Wave Makers

Rayleigh-Bénard Convection

Rayleigh-Bénard Convection

Rayleigh-Taylor Instability

Rayleigh-Taylor Instability

Single Internal Wave

Single Internal Wave

Symmetric Instability

Symmetric Instability

Tracers and Eddies

Tracers and Eddies

Reflecting Wave Package

Reflecting Wave Package

Barotropic Instability.

Barotropic Instability.

Equatorial Waves.

Equatorial Waves.
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) VectorField[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#

fr.VectorField

The eigenvector of the linear operator.

abstract vec_p(s: int, use_discrete: bool = True) VectorField[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#

fr.VectorField

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)

abstract sum(field: ScalarField, axes: tuple[int] | None = None) ScalarField[source]#

Sum a field over the given axes.

Parameters#

fieldScalarField

The field to sum.

axestuple[int] or None (default: None)

The axes to sum over. If None, all axes are summed over.

Returns#

ScalarField

The summed field with no extend in the summed axes.

abstract min(field: ScalarField, axes: tuple[int] | None = None) ScalarField[source]#

Compute the minimum of a field over the given axes.

Parameters#

fieldScalarField

The field to compute the minimum.

axestuple[int] or None (default: None)

The axes to compute the minimum over. If None, all axes are used.

Returns#

ScalarField

The field with the minimum value in the given axes.

abstract max(field: ScalarField, axes: tuple[int] | None = None) ScalarField[source]#

Compute the maximum of a field over the given axes.

Parameters#

fieldScalarField

The field to compute the maximum.

axestuple[int] or None (default: None)

The axes to compute the maximum over. If None, all axes are used.

Returns#

ScalarField

The field with the maximum value in the given axes.

abstract integrate(field: ScalarField, axes: tuple[int] | None = None) ScalarField[source]#

Integrate a scalar field over a given domain.

Parameters#

fieldScalarField

The field to integrate.

axestuple[int] or None (default: None)

The axes to integrate over.

Returns#

ScalarField

The integrated field with no extend in the integrated axes.

abstract cumulative_integral(field: ScalarField, axis: int, direction: Literal['forward', 'backward'] = 'forward') ScalarField[source]#

Compute the cumulative integral of a field along a given axis.

Description#

The cumulative integral computes the integral starting at one end of the domain and accumulates the integral along the specified axis. The integral is computed in either the forward or backward direction.

Forward integral:

\[F(x) = \int_{x_0}^{x} f(x') dx'\]

with axis \(x\) and \(x_0\) the lower bound of the domain.

Backward integral:

\[F(x) = \int_{x}^{x_1} f(x') dx'\]

with axis \(x\) and \(x_1\) the upper bound of the domain.

Parameters#

fieldScalarField

The field to integrate.

axisint

The axis to integrate over.

directionstr (default is “forward”)

The direction of the integration. Can be “forward” or “backward”.

Returns#

ScalarField

The cumulative integral of the field along the given axis.

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 halo: int#

The halo size of the grid.

To change the halo size of the grid, modify the halo attribute of the model settings.

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 characteristic_function: ScalarField#

The characteristic function of the grid (1 inside the domain, 0 outside).

Description#

The characteristic function is a scalar field that is 1 inside the domain and 0 outside. It is useful for masking fields or for integrating over the domain. For example, the total volume of the domain can be computed as the integral of the characteristic function.

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.