4.1.6.1.2 pde.backends.torch.operators.common module

This module implements infrastructure for differential operators using torch.

TorchDifferentialOperator

Base class for differential operators implemented in torch.

class TorchDifferentialOperator(grid, bcs, *, dtype)[source]

Bases: TorchOperatorBase

Base class for differential 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 (DTypeLike) – The data type of the field using the numpy convention

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.

  • args – Additional arguments passed to ghost cell setters, e.g., the time t.

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_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

class TorchIntegralOperator(grid, *, dtype)[source]

Bases: TorchOperatorBase

Operator integrating a field implemented in torch.

Initialize the torch operator.

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

  • dtype (DTypeLike) – 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