4.2.1.4 pde.grids.boundaries.axis module

This module handles the boundaries of a single axis of a grid. There are generally only two options, depending on whether the axis of the underlying grid is defined as periodic or not. If it is periodic, the class BoundaryPeriodic should be used, while non-periodic axes have more option, which are represented by BoundaryPair.

BoundaryAxisBase

Base class for defining boundaries of a single axis in a grid.

BoundaryPair

Represents the two boundaries of an axis along a single dimension.

BoundaryPeriodic

Represent a periodic axis.

class BoundaryAxisBase(low, high)[source]

Bases: object

Base class for defining boundaries of a single axis in a grid.

Parameters:
  • low (BCBase) – Instance describing the lower boundary

  • high (BCBase) – Instance describing the upper boundary

property axis: int

The axis along which the boundaries are defined

Type:

int

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

copy()[source]

Return a copy of itself, but with a reference to the same grid.

Return type:

BoundaryAxisBase

classmethod get_help()[source]

Return information on how boundary conditions can be set.

Return type:

str

get_mathematical_representation(field_name='C')[source]

Return mathematical representation of the boundary condition.

Parameters:

field_name (str)

Return type:

tuple[str, str]

get_sparse_matrix_data(idx)[source]

Sets the elements of the sparse representation of this condition.

Parameters:

idx (tuple) – The index of the point that must lie on the boundary condition

Returns:

A constant value and a dictionary with indices and factors that can be used to calculate this virtual point

Return type:

float, dict

property grid: GridBase

Underlying grid.

Type:

GridBase

high: BCBase

Boundary condition at upper end.

Type:

BCBase

low: BCBase

Boundary condition at lower end.

Type:

BCBase

make_ghost_cell_setter()[source]

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

Return type:

GhostCellSetter

property periodic: bool

whether the axis is periodic

Type:

bool

property rank: int

rank of the associated boundary condition

Type:

int

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

Set the ghost cell values for all boundaries.

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

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

Return type:

None

class BoundaryPair(low, high)[source]

Bases: BoundaryAxisBase

Represents the two boundaries of an axis along a single dimension.

Parameters:
  • low (BCBase) – Instance describing the lower boundary

  • high (BCBase) – Instance describing the upper boundary

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 the value does not have rank rank

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

Create boundary pair from some data.

Parameters:
  • grid (GridBase) – The grid for which the boundary conditions are defined

  • axis (int) – The axis to which this boundary condition is associated

  • data (str or dict) – Data that describes the boundary pair

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

Returns:

the instance created from the data

Return type:

BoundaryPair

Throws:

ValueError if data cannot be interpreted as a boundary pair

class BoundaryPeriodic(grid, axis, flip_sign=False)[source]

Bases: BoundaryPair

Represent a periodic axis.

Parameters:
  • grid (GridBase) – The grid for which the boundary conditions are defined

  • axis (int) – The axis to which this boundary condition is associated

  • flip_sign (bool) – Impose different signs on the two sides of the boundary

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

copy()[source]

Return a copy of itself, but with a reference to the same grid.

Return type:

BoundaryPeriodic

property flip_sign

Whether different signs are imposed on the two sides of the boundary

Type:

bool

get_boundary_axis(grid, axis, data, rank=0)[source]

Return object representing the boundary condition for a single axis.

Parameters:
  • grid (GridBase) – The grid for which the boundary conditions are defined

  • axis (int) – The axis to which this boundary condition is associated

  • data (str or tuple or dict) – Data describing the boundary conditions for this axis

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

Returns:

Appropriate boundary condition for the axis

Return type:

BoundaryAxisBase