SingleDecomposition#
- class fridom.framework.domain_decomposition.SingleDecomposition(shape: tuple[int], halo: int = 0, periods: tuple[bool] | None = None, shared_axes: tuple[int] | None = None, device_ids: list[int] | None = None)[source]#
Bases:
DomainDecomposition- __init__(shape: tuple[int], halo: int = 0, periods: tuple[bool] | None = None, shared_axes: tuple[int] | None = None, device_ids: list[int] | None = None)[source]#
Methods
__init__(shape[, halo, periods, ...])create_array([pad, spectral, topo])Create an array.
create_meshgrid(*args[, pad, spectral])Create a meshgrid of arrays.
create_random_array([seed, pad, spectral, topo])Create a random array.
cumsum(arr, axis)Cumulative sum of an array along a specified axis.
gather(arr[, slc, dest_rank, spectral])Gather an array to a single process.
inv_cumsum(arr, axis)Inverse cumulative sum of an array along a specified axis.
max(arr[, axes, spectral])Find the maximum value of an array across specified axes.
min(arr[, axes, spectral])Find the minimum value of an array across specified axes.
pad(arr[, flat_axes])Add padding to an array.
pad_extend(arr)Extend the array with zeros (for spectral padding)
pad_trim(arr)Set the padded region to zero (for spectral padding)
parallel_backward_transform(func)Parallel backward transform.
parallel_forward_transform(func)Parallel forward transform.
roll(arr, shift, axis)Roll an array along specified axes.
shard_map(func)Decorator to apply a function to the active processes only.
sum(arr[, axes, spectral])Sum an array across specified axes.
sync(arr[, flat_axes])Synchronize the halo regions of an array across all processes.
sync_multiple(arr)Synchronize the halo regions of multiple arrays across all processes.
unpad(arr[, flat_axes])Remove padding from an array.
unpad_extend(arr)Remove the extension of the array (for spectral padding)
Attributes
device_idsList of device ids.
haloWidth of the halo region (same for all dimensions).
i_am_activeWhether the current process is active in this domain.
n_dimsNumber of dimensions.
p_dimsNumber of processes in each dimension.
parallelWhether the domain is parallel.
periodsPeriodic boundaries of the domain.
rankRank of the current process.
shapeShape of the domain (number of grid points).
shared_axesAxes shared by all processes.
sizeNumber of processes.
- sync(arr: ndarray, flat_axes: list[int] | None = None) ndarray[source]#
Synchronize the halo regions of an array across all processes.
Parameters#
- arrndarray
The array to synchronize.
- flat_axeslist[int] | None
Dimensions which are flat (no halo exchange). If None, all dimensions are exchanged.
- pad(arr: ndarray, flat_axes: tuple[int] | None = None) ndarray[source]#
Add padding to an array.
Parameters#
- arrndarray
The array to pad.
- unpad(arr: ndarray, flat_axes: tuple[int] | None = None) ndarray[source]#
Remove padding from an array.
Parameters#
- arrndarray
The array to unpad.
- pad_extend(arr: ndarray) ndarray[source]#
Extend the array with zeros (for spectral padding)
Parameters#
- arrndarray
The array to pad.
Returns#
- ndarray
The padded array.
- unpad_extend(arr: ndarray) ndarray[source]#
Remove the extension of the array (for spectral padding)
Parameters#
- arrndarray
The array to unpad.
Returns#
- ndarray
The unpadded array.
- pad_trim(arr: ndarray) ndarray[source]#
Set the padded region to zero (for spectral padding)
Parameters#
- arrndarray
The array to pad.
- gather(arr: ndarray, slc: tuple[slice] | None = None, dest_rank: int | None = None, spectral: bool = False) ndarray[source]#
Gather an array to a single process.
Parameters#
- arrndarray
The array to gather.
- slctuple[slice] (default=None)
The slice of the array to gather. If None, gather the entire array.
- dest_rankint (default=None)
The rank of the process to gather to. If None, gather to all processes.
- spectralbool
Whether the array is in spectral space.
- 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)
- create_meshgrid(*args: ndarray, pad: bool = True, spectral: bool = False) tuple[ndarray][source]#
Create a meshgrid of arrays.
Parameters#
- argsndarray
The arrays to meshgrid.
- padbool
Whether to add padding to the meshgrid.
- spectralbool
Whether the meshgrid is in spectral space.
- sum(arr: ndarray, axes: list[int] | None = None, spectral: bool = False) ndarray[source]#
Sum an array across specified axes.
Parameters#
- arrndarray
The array to sum.
- axeslist[int] | None
The axes to sum across. If None, sum across all axes.
- spectralbool
Whether the array is in spectral space.
- max(arr: ndarray, axes: list[int] | None = None, spectral: bool = False) ndarray[source]#
Find the maximum value of an array across specified axes.
Parameters#
- arrndarray
The array to find the maximum value of.
- axeslist[int] | None
The axes to find the maximum value across. If None, find the maximum value across all axes.
- spectralbool
Whether the array is in spectral space.
- min(arr: ndarray, axes: list[int] | None = None, spectral: bool = False) ndarray[source]#
Find the minimum value of an array across specified axes.
Parameters#
- arrndarray
The array to find the minimum value of.
- axeslist[int] | None
The axes to find the minimum value across. If None, find the minimum value across all axes.
- spectralbool
Whether the array is in spectral space.
- cumsum(arr: ndarray, axis: int) ndarray[source]#
Cumulative sum of an array along a specified axis.
Parameters#
- arrndarray
The array to cumsum.
- axisint
The axis to cumsum along.
- inv_cumsum(arr: ndarray, axis: int) ndarray[source]#
Inverse cumulative sum of an array along a specified axis.
Parameters#
- arrndarray
The array to inv_cumsum.
- axisint
The axis to inv_cumsum along.
- roll(arr: ndarray, shift: int | tuple[int], axis: int | tuple[int]) ndarray[source]#
Roll an array along specified axes.
Parameters#
- arrndarray
The array to roll.
- shiftint | tuple[int]
The number of places by which elements are shifted. Rolling the array [1,2,3,4,5] with shift=1 results in [5,1,2,3,4]. If a tuple is given, the axis must also be a tuple of the same length.
- axisint | tuple[int]
The axis or axes to roll along. If a tuple is given, the shift must also be a tuple of the same length.