4.2.3.2 pde.grids.operators.common module

Common functions that are used by many operators.

make_derivative(grid, axis=0, method='central')[source]

Make a derivative operator along a single axis using numba compilation.

Parameters:
  • grid (GridBase) – The grid for which the operator is created

  • axis (int) – The axis along which the derivative will be taken

  • method (str) – The method for calculating the derivative. Possible values are ‘central’, ‘forward’, and ‘backward’.

Returns:

A function that can be applied to an full array of values including those at ghost cells. The result will be an array of the same shape containing the actual derivatives at the valid (interior) grid points.

Return type:

OperatorType

make_derivative2(grid, axis=0)[source]

Make a second-order derivative operator along a single axis.

Parameters:
  • grid (GridBase) – The grid for which the operator is created

  • axis (int) – The axis along which the derivative will be taken

Returns:

A function that can be applied to an full array of values including those at ghost cells. The result will be an array of the same shape containing the actual derivatives at the valid (interior) grid points.

Return type:

OperatorType

make_general_poisson_solver(matrix, vector, method='auto')[source]

Make an operator that solves Poisson’s problem.

Parameters:
  • matrix – The (sparse) matrix representing the laplace operator on the given grid.

  • vector – The constant part representing the boundary conditions of the Laplace operator.

  • method (str) – The chosen method for implementing the operator

Returns:

A function that can be applied to an array of values to obtain the solution to Poisson’s equation where the array is used as the right hand side

Return type:

OperatorType

make_laplace_from_matrix(matrix, vector)[source]

Make a Laplace operator using matrix vector products.

Parameters:
  • matrix – (Sparse) matrix representing the laplace operator on the given grid

  • vector – Constant part representing the boundary conditions of the Laplace operator

Returns:

A function that can be applied to an array of values to obtain the result of applying the linear operator matrix and the offset given by vector.

Return type:

Callable[[ndarray, ndarray | None], ndarray]

uniform_discretization(grid)[source]

Returns the uniform discretization or raises RuntimeError.

Parameters:

grid (GridBase) – The grid whose discretization is tested

Raises:

RuntimeError

Returns:

the common discretization of all axes

Return type:

float