4.1.5.1.2 pde.backends.torch.operators.common module

This module implements infrastructure for differential operators using torch.

TorchOperator

Base class for operators implemented in torch.

class IntegralOperator(grid, *, dtype=<class 'numpy.float64'>)[source]

Bases: Module

Operator integrating a field implemented in torch.

Initialize the torch operator.

Parameters:
  • grid (GridBase) – The grid on which the operator acts

  • dtype – The data type of the field

forward(arr)[source]

Fill internal data array, apply operator, and return valid data.

Parameters:

arr (Tensor)

Return type:

Tensor

class TorchOperator(grid, bcs, *, dtype=<class 'numpy.float64'>)[source]

Bases: Module

Base class for operators implemented in torch.

Initialize the torch operator.

Parameters:
  • grid (GridBase) – The grid on which the operator acts

  • bcs (BoundariesList or None) – The boundary conditions applied to the field. If None, no boundary conditions are enforced and it is assumed that the operator is applied to the full field.

  • dtype – The data type of the field

data_full: Tensor
get_full_data(arr, args=None)[source]

Get full data array including ghost cells.

Parameters:

arr (torch.Tensor) – The input data. If boundary conditions are applied, this should contain only the valid grid points. Otherwise, it should already include ghost cells.

Returns:

The full data array including ghost cells with boundary conditions applied if necessary.

Return type:

torch.Tensor

rank_in: int = 0

The rank of the input tensor

Type:

int

set_ghost_cells(args=None)[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)

set_valid(arr)[source]

Set valid data in the internal full array.

Parameters:

arr (torch.Tensor) – The data of the valid grid points

Return type:

None