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.

class BoundaryAxisBase(low: BCBase, high: BCBase)[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

get_data(idx: Tuple[int, ...]) Tuple[float, Dict[int, float]][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

get_mathematical_representation(field_name: str = 'C') Tuple[str, str][source]

return mathematical representation of the boundary condition

get_point_evaluator(fill: Optional[ndarray] = None) Callable[[ndarray, Tuple[int, ...]], Union[int, float, complex, ndarray]][source]

return a function to evaluate values at a given point

The point can either be a point inside the domain or a virtual point right outside the domain

Parameters

fill (ndarray, optional) – Determines how values out of bounds are handled. If None, a DomainError is raised when out-of-bounds points are requested. Otherwise, the given value is returned.

Returns

A function taking a 1d array and an index as an argument,

returning the value of the array at this index.

Return type

function

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_derivative_evaluator(order: int = 1) Callable[[ndarray, Tuple[int, ...]], Union[int, float, complex, ndarray]][source]

return a function to evaluate the derivative at a point

Parameters

order (int) – The order of the derivative

Returns

A function that can be called with the data array and a tuple indicating around what point the derivative is evaluated. The function returns the central finite difference at the point. The function takes boundary conditions into account if the point lies on the boundary.

Return type

function

make_ghost_cell_setter() Callable[[...], None][source]

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

make_region_evaluator() Callable[[ndarray, Tuple[int, ...]], Tuple[Union[int, float, complex, ndarray], Union[int, float, complex, ndarray], Union[int, float, complex, ndarray]]][source]

return a function to evaluate values in a neighborhood of a point

Returns

A function that can be called with the data array and a tuple indicating around what point the region is evaluated. The function returns the data values left of the point, at the point, and right of the point along the axis associated with this boundary condition. The function takes boundary conditions into account if the point lies on the boundary.

Return type

function

make_virtual_point_evaluators() Tuple[Callable[[...], float], Callable[[...], float]][source]

returns two functions evaluating the value at virtual support points

Returns

Two functions that each take a 1d array as an argument and return the associated value at the virtual support point outside the lower and upper boundary, respectively.

Return type

tuple

property periodic: bool

whether the axis is periodic

Type

bool

set_ghost_cells(data_full: ndarray, *, args=None) 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.

class BoundaryPair(low: BCBase, high: BCBase)[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: int) None[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

Throws:

RuntimeError: if the value does not have rank rank

copy() BoundaryPair[source]

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

extract_component(*indices) BoundaryPair[source]

extracts the boundary pair of the given index.

Parameters

*indices – One or two indices for vector or tensor fields, respectively

classmethod from_data(grid: GridBase, axis: int, data, rank: int = 0) BoundaryPair[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

classmethod get_help() str[source]

Return information on how boundary conditions can be set

high: BCBase

Boundary condition at upper end

Type

BCBase

low: BCBase

Boundary condition at lower end

Type

BCBase

class BoundaryPeriodic(grid: GridBase, axis: int, flip_sign: bool = 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: int) None[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

copy() BoundaryPeriodic[source]

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

extract_component(*indices) BoundaryPeriodic[source]

extracts the boundary pair of the given extract_component.

Parameters

*indices – One or two indices for vector or tensor fields, respectively

property flip_sign

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

Type

bool

high: BCBase

Boundary condition at upper end

Type

BCBase

low: BCBase

Boundary condition at lower end

Type

BCBase

get_boundary_axis(grid: GridBase, axis: int, data, rank: int = 0) BoundaryAxisBase[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