4.2.1.3 pde.grids.boundaries.axes module

This module handles the boundaries of all axes of a grid.

BoundariesBase

Base class keeping information about how to set conditions on all boundaries.

BoundariesList

Defines boundary conditions for all axes individually.

BoundariesSetter

Represents a function that sets ghost cells to determine boundary conditions.

set_default_bc

Set a default boundary condition.

class BoundariesBase[source]

Bases: object

Base class keeping information about how to set conditions on all boundaries.

classmethod from_data(data, **kwargs)[source]

Creates all boundaries from given data.

Parameters:
  • data (str or dict or callable) – Data that describes the boundaries. If this is a callable, we create BoundariesSetter. In all other, cases BoundariesList is created and data can either be string denoting a specific boundary condition applied to all sides or a dictionary with detailed information.

  • **kwargs – In some cases additional data can be specified or is even required. For instance, BoundariesList expects a grid (GridBase): to which the boundary condition are associated, and it can use a rank (int), which sets the tensorial rank of the field for this boundary condition.

Return type:

BoundariesBase

classmethod get_help()[source]

Return information on how boundary conditions can be set.

Return type:

str

make_ghost_cell_setter()[source]

Return function that sets the ghost cells on a full array.

Returns:

Callable with signature (data_full: np.ndarray, args=None), which sets the ghost cells of the full data, potentially using additional information in args (e.g., the time t during solving a PDE)

Return type:

GhostCellSetter

set_ghost_cells(data_full, *, args=None)[source]

Set the ghost cells for all boundaries.

Parameters:
  • data_full (ndarray) – The full field data including ghost points

  • set_corners (bool) – Determines whether the corner cells are set using interpolation

  • args – Additional arguments that might be supported by special boundary conditions.

Return type:

None

class BoundariesList(boundaries)[source]

Bases: BoundariesBase

Defines boundary conditions for all axes individually.

Initialize with a list of boundaries.

Parameters:

boundaries (list[BoundaryAxisBase])

property boundaries: Iterator[BCBase]

Iterator over all non-periodic boundaries.

check_value_rank(rank)[source]

Check whether the values at the boundaries have the correct rank.

Parameters:

rank (int) – The tensorial rank of the field for this boundary condition

Return type:

None

Throws:

RuntimeError: if any value does not have rank rank

copy()[source]

Create a copy of the current boundaries.

Return type:

BoundariesList

classmethod from_data(data, *, grid, rank=0, **kwargs)[source]

Creates all boundaries from given data.

Parameters:
  • grid (GridBase) – The grid with which the boundary condition is associated

  • data (str or dict) – Data that describes the boundaries. This should either be a string naming a boundary condition or a dictionary with detailed information.

  • rank (int) – The tensorial rank of the field for this boundary condition

Return type:

BoundariesList

get_mathematical_representation(field_name='C')[source]

Return mathematical representation of the boundary condition.

Parameters:

field_name (str)

Return type:

str

make_ghost_cell_setter()[source]

Return function that sets the ghost cells on a full array.

Return type:

GhostCellSetter

property periodic: list[bool]

a boolean array indicating which dimensions are periodic according to the boundary conditions.

Type:

ndarray

set_ghost_cells(data_full, *, set_corners=False, args=None)[source]

Set the ghost cells for all boundaries.

Parameters:
  • data_full (ndarray) – The full field data including ghost points

  • set_corners (bool) – Determines whether the corner cells are set using interpolation

  • args – Additional arguments that might be supported by special boundary conditions.

Return type:

None

class BoundariesSetter(setter)[source]

Bases: BoundariesBase

Represents a function that sets ghost cells to determine boundary conditions.

The function must have accept a ndarray, which contains the full field data including the ghost points, and a second, optional argument, which is a dictionary containing additional parameters, like the current time point t in case of a simulation.

Example

Here is an example for a simple boundary setter, which sets specific boundary conditions in the x-direction and periodic conditions in the y-direction of a grid with two axes. Note that this boundary condition will not work for grids with other number of axes and no additional checks are performed.

def setter(data, args=None):
    data[0, :] = data[1, :]  # Vanishing derivative at left side
    data[-1, :] = 2 - data[-2, :]  # Fixed value `1` at right side
    data[:, 0] = data[:, -2]  # Periodic BC at top
    data[:, -1] = data[:, 1]  # Periodic BC at bottom
Parameters:

setter (GhostCellSetter)

classmethod from_data(data, **kwargs)[source]

Creates all boundaries from given data.

Parameters:

data (callable) – Function that sets the ghost cells

Return type:

BoundariesSetter

make_ghost_cell_setter()[source]

Return function that sets the ghost cells on a full array.

Returns:

Callable with signature (data_full: np.ndarray, args=None), which sets the ghost cells of the full data, potentially using additional information in args (e.g., the time t during solving a PDE)

Return type:

GhostCellSetter

set_ghost_cells(data_full, *, args=None)[source]

Set the ghost cells for all boundaries.

Parameters:
  • data_full (ndarray) – The full field data including ghost points

  • set_corners (bool) – Determines whether the corner cells are set using interpolation

  • args – Additional arguments that might be supported by special boundary conditions.

Return type:

None

set_default_bc(bc_data, default)[source]

Set a default boundary condition.

Parameters:
  • bc_data (str or list or tuple or dict or callable) – User-supplied data specifying boundary conditions

  • default (dict | str | BCBase) – Default condition that should be imposed where user conditions are not given

Returns:

Modified bc_data with added defaults

Return type:

dict[str, dict | str | BCBase] | dict | str | BCBase | tuple[dict | str | BCBase, dict | str | BCBase] | BoundaryAxisBase | Sequence[dict[str, dict | str | BCBase] | dict | str | BCBase | tuple[dict | str | BCBase, dict | str | BCBase] | BoundaryAxisBase] | Callable | BoundariesBase