4.1.3.1 pde.backends.numpy.backend module
Defines base class of backends that implement computations.
- class NumpyBackend(name='')[source]
Bases:
BackendBaseBasic backend from which all other backends inherit.
- Parameters:
name (str)
- compile_function(func)[source]
General method that compiles a user function.
- Parameters:
func (callable) – The function that needs to be compiled for this backend
- Return type:
TFunc
- make_data_setter(grid, bcs=None)[source]
Create a function to set the valid part of a full data array.
- Parameters:
bcs (
BoundariesBase, optional) – If supplied, the returned function also enforces boundary conditions by setting the ghost cells to the correct valuesbackend (str) – The backend to use for making the operator
grid (GridBase)
- Returns:
Takes two numpy arrays, setting the valid data in the first one, using the second array. The arrays need to be allocated already and they need to have the correct dimensions, which are not checked. If bcs are given, a third argument is allowed, which sets arguments for the BCs.
- Return type:
callable
- make_expression_function(expression, *, single_arg=False, user_funcs=None)[source]
Return a function evaluating an expression for a particular backend.
- Parameters:
expression (
ExpressionBase) – The expression that is converted to a functionsingle_arg (bool) – Determines whether the returned function accepts all variables in a single argument as an array or whether all variables need to be supplied separately.
user_funcs (dict) – Additional functions that can be used in the expression.
- Returns:
the function
- Return type:
function
- make_ghost_cell_setter(boundaries)[source]
Return function that sets the ghost cells on a full array.
- Parameters:
boundaries (
BoundariesBase) – Defines the boundary conditions for a particular grid, for which the setter should be defined.- Returns:
Callable with signature
(data_full: NumericArray, 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:
- make_inner_prod_operator(field, *, conjugate=True)[source]
Return operator calculating the dot product between two fields.
This supports both products between two vectors as well as products between a vector and a tensor.
- Parameters:
field (
DataFieldBase) – Field for which the inner product is definedconjugate (bool) – Whether to use the complex conjugate for the second operand
- Returns:
function that takes two instance of
ndarray, which contain the discretized data of the two operands. An optional third argument can specify the output array to which the result is written.- Return type:
Callable[[NumericArray, NumericArray, NumericArray | None], NumericArray]
- make_inner_stepper(solver, stepper_style, state, dt)[source]
Return a stepper function using an explicit scheme.
- Parameters:
solver (
SolverBase) – The solver instance, which determines how the stepper is constructedstate (
FieldBase) – An example for the state from which the grid and other information can be extracteddt (float) – Time step used (Uses
SolverBase.dt_defaultif None)stepper_style (Literal['fixed', 'adaptive'])
- Returns:
Function that can be called to advance the state from time t_start to time t_end. The function call signature is (state: numpy.ndarray, t_start: float, t_end: float)
- Return type:
Callable
- make_integrator(grid)[source]
Return function that integrates discretized data over a grid.
If this function is used in a multiprocessing run (using MPI), the integrals are performed on all subgrids and then accumulated. Each process then receives the same value representing the global integral.
- Parameters:
grid (
GridBase) – Grid for which the operator is needed- Returns:
A function that takes a numpy array and returns the integral with the correct weights given by the cell volumes.
- Return type:
Callable[[NumericArray], NumberOrArray]
- make_noise_realization(eq, state)[source]
Return a function for evaluating the noise term of the PDE.
- make_operator(grid, operator, bcs, **kwargs)[source]
Return a compiled function applying an operator with boundary conditions.
- Parameters:
operator (str) – Identifier for the operator. Some examples are ‘laplace’, ‘gradient’, or ‘divergence’. The registered operators for this grid can be obtained from the
operatorsattribute.bcs (
BoundariesBase, optional) – The boundary conditions used before the operator is applied**kwargs – Specifies extra arguments influencing how the operator is created.
grid (GridBase)
- Return type:
The returned function takes the discretized data on the grid as an input and returns the data to which the operator operator has been applied. The function only takes the valid grid points and allocates memory for the ghost points internally to apply the boundary conditions specified as bc. Note that the function supports an optional argument out, which if given should provide space for the valid output array without the ghost cells. The result of the operator is then written into this output array.
The function also accepts an optional parameter args, which is forwarded to set_ghost_cells. This allows setting boundary conditions based on external parameters, like time.
- Returns:
the function that applies the operator. This function has the signature (arr: NumericArray, out: NumericArray = None, args=None).
- Return type:
callable
- Parameters:
grid (GridBase)
operator (str | OperatorInfo)
bcs (BoundariesBase)
- make_outer_prod_operator(field)[source]
Return operator calculating the outer product between two fields.
This supports typically only supports products between two vector fields.
- Parameters:
field (
DataFieldBase) – Field for which the outer product is definedconjugate (bool) – Whether to use the complex conjugate for the second operand
- Returns:
function that takes two instance of
ndarray, which contain the discretized data of the two operands. An optional third argument can specify the output array to which the result is written.- Return type:
Callable[[NumericArray, NumericArray, NumericArray | None], NumericArray]