DomainDecomposition#

class fridom.framework.domain_decomposition.domain_decomposition.DomainDecomposition(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: object

Construct a grid of processors and decompose a global domain into subdomains.

Description#

Decompose the global domain into subdomains for parallel computing. The domain decomposition is done in a cartesian grid of processors. The decomposition can be done in multiple dimensions. Axes that are shared between processors can be specified (e.g. for fft)

        ----------------------------------- 
       /                /                /| 
      /                /                / | 
     /                /                /  | 
    /                /                /   | 
   /                /                /    | 
  /                /                /    /| 
 /                /                /    / | 
 ----------------------------------    /  | 
|                |                |   /   | 
|   PROCESSOR    |   PROCESSOR    |  /    | 
|     0, 1       |     1, 1       | /    /
|                |                |/    /
|----------------|----------------|    /     ^
|                |                |   /     /
|   PROCESSOR    |   PROCESSOR    |  /     / shared_axis
|     0, 0       |     1, 0       | /     /
|                |                |/
----------------------------------- 

Parameters#

shapetuple[int]

The total number of grid points in each dimension.

haloint, optional (default=0)

The number of halo cells (ghost cells) around the local domain for the exchange of boundary values.

periodstuple[bool], optional (default=None)

A list of booleans indicating whether the domain is periodic in each dimension. If None, all dimensions are periodic.

shared_axeslist[int], optional (default=None)

A list of axes that are shared between processors.

device_idslist[int], optional (default=None)

Optional list of device ids to use. If None, all devices are used. This option is useful for coupled simulations.

__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)

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)

Remove padding from an array.

unpad_extend(arr)

Remove the extension of the array (for spectral padding)

Attributes

device_ids

List of device ids.

halo

Width of the halo region (same for all dimensions).

i_am_active

Whether the current process is active in this domain.

n_dims

Number of dimensions.

p_dims

Number of processes in each dimension.

parallel

Whether the domain is parallel.

periods

Periodic boundaries of the domain.

rank

Rank of the current process.

shape

Shape of the domain (number of grid points).

shared_axes

Axes shared by all processes.

size

Number of processes.

abstract 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.

sync_multiple(arr: list[ndarray]) list[ndarray][source]#

Synchronize the halo regions of multiple arrays across all processes.

Parameters#

arrlist[ndarray]

The list of arrays to synchronize.

parallel_forward_transform(func: callable) callable[source]#

Parallel forward transform.

Parameters#

funccallable

The function to apply the forward transform to. func(arr: ndarray, axes: list[int] | None = None) -> ndarray

parallel_backward_transform(func: callable) callable[source]#

Parallel backward transform.

Parameters#

funccallable

The function to apply the backward transform to. func(arr: ndarray, axes: list[int] | None = None) -> ndarray

abstract pad(arr: ndarray) ndarray[source]#

Add padding to an array.

Parameters#

arrndarray

The array to pad.

abstract unpad(arr: ndarray) 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.

abstract 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.

abstract 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)

abstract 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 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.

abstract 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.

abstract 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.

abstract 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.

abstract 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.

abstract 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.

abstract 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.

shard_map(func: callable) callable[source]#

Decorator to apply a function to the active processes only.

Parameters#

funccallable

The function to apply.

property n_dims: int#

Number of dimensions.

property shape: tuple[int]#

Shape of the domain (number of grid points).

property halo: int#

Width of the halo region (same for all dimensions).

property periods: tuple[bool] | None#

Periodic boundaries of the domain.

property parallel: bool#

Whether the domain is parallel.

property rank: int#

Rank of the current process.

property size: int#

Number of processes.

property device_ids: list[int] | None#

List of device ids.

property i_am_active: bool#

Whether the current process is active in this domain.

property p_dims: tuple[int]#

Number of processes in each dimension.

property shared_axes: tuple[int]#

Axes shared by all processes.