Grid#
- class fridom.framework.grid.cartesian.grid.Grid(N: list[int], L: list[float], periodic_bounds: list[bool] | None = None, domain_decomp: DomainDecomposition | None = None, diff_mod: DiffModule | None = None, interp_mod: InterpolationModule | None = None)[source]#
Bases:
GridBaseAn n-dimensional cartesian grid with capabilities for fourier transforms.
Description#
The cartesian grid is a regular grid with constant grid spacing in each direction. The grid can be periodic in some directions and non-periodic in others.
Parameters#
- Ntuple[int]
Number of grid points in each direction.
- Ltuple[float]
Domain size in meters in each direction.
- periodic_boundstuple[bool], (default: None)
A list of booleans that indicate whether the axis is periodic. If True, the axis is periodic, if False, the axis is non-periodic. Default is True for all axes.
- shared_axeslist[int], (default: None)
A list of integers that indicate which axes are shared among MPI ranks. Default is None, which means that no fourier transforms are available.
- diff_modDiffModule, (default: None)
A module that contains the differentiation operators. If None, the finite differences module is used.
- interp_modInterpolationModule, (default: None)
A module that contains the interpolation methods. If None, the linear interpolation module is used.
Examples#
import fridom.framework as fr # construct a 3D grid: grid = fr.grid.CartesianGrid( N=(32, 32, 8), # 32x32x8 grid points L=(100.0, 100.0, 10.0), # 100m x 100m x 10m domain periodic_bounds=(True, True, False), # non-periodic in z shared_axes=[0, 1] # slab decomposition, shared in x and y ) # setup the grid using the model settings mset = fr.ModelSettingsBase(grid) mset.setup() # get the meshgrids X, Y, Z = grid.X # physical meshgrid of the local domain KX, KY, KZ = grid.K # spectral meshgrid of the local domain # get the grid spacing dx, dy, dz = grid.dx
- __init__(N: list[int], L: list[float], periodic_bounds: list[bool] | None = None, domain_decomp: DomainDecomposition | None = None, diff_mod: DiffModule | None = None, interp_mod: InterpolationModule | None = None) None[source]#
Methods
__init__(N, L[, periodic_bounds, ...])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[, req_halo, fft_module])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
Spectral meshgrid on the local domain.
Domain size in each direction.
Grid points in each direction.
XThe meshgrid of the grid points.
cell_centerThe position of the cell centers.
characteristic_functionThe characteristic function of the grid (1 inside the domain, 0 outside).
dVThe volume element of the grid.
diff_moduleThe differential operator module.
domain_decompThe domain decomposition object.
dxThe grid spacing in each dimension.
fourier_transform_availableIndicates whether the grid supports fast fourier transforms.
haloThe halo size of the grid.
Return a dictionary with information about the grid.
interp_moduleThe interpolation operator module.
Global spectral k-vectors.
Spectral k-vectors on the local domain.
mpi_availableIndicates whether the grid supports MPI parallelization.
msetThe model settings object.
n_dimsThe number of dimensions of the grid.
omega_analyticalAnalytical dispersion relation.
omega_space_discreteDispersion relation with space-discretization effects.
omega_time_discreteDispersion relation with space-time-discretization effects.
periodic_boundsA tuple of booleans indicating whether the grid is periodic in each dimension.
spectral_gridIndicates whether the grid is a spectral grid.
total_grid_pointsThe total number of grid points in the grid.
water_maskGet the water mask.
x_globalThe x-vector of the global grid points.
Examples using
fridom.framework.grid.cartesian.Grid#- setup(mset: ModelSettingsBase, req_halo: int | None = None, fft_module: FFT | None = None) 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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 L: tuple#
Domain size in each direction.
- property N: tuple#
Grid points in each direction.
- property K: tuple | None#
Spectral meshgrid on the local domain.
- property k_local: tuple | None#
Spectral k-vectors on the local domain.
- property k_global: tuple | None#
Global spectral k-vectors.