Operators#

Module for vectorized differential operators implementation.

Differential operators are used to define differential problems and are implemented to run efficiently on various accelerators, including CPU, GPU, TPU, and MPS.

Each differential operator takes the following inputs: - A tensor on which the operator is applied. - A tensor with respect to which the operator is computed. - The names of the output variables for which the operator is evaluated. - The names of the variables with respect to which the operator is computed.

grad(output_, input_, components=None, d=None)[source]#

Compute the gradient of the output_ with respect to the input.

This operator supports both vector-valued and scalar-valued functions with one or multiple input coordinates.

Parameters:
  • output (LabelTensor) – The output tensor on which the gradient is computed.

  • input (LabelTensor) – The input tensor with respect to which the gradient is computed.

  • components (list[str]) – The names of the output variables for which to compute the gradient. It must be a subset of the output labels. If None, all output variables are considered. Default is None.

  • d (list[str]) – The names of the input variables with respect to which the gradient is computed. It must be a subset of the input labels. If None, all input variables are considered. Default is None.

Raises:
  • TypeError – If the input tensor is not a LabelTensor.

  • RuntimeError – If the output is a scalar field and the components are not equal to the output labels.

  • NotImplementedError – If the output is neither a vector field nor a scalar field.

Returns:

The computed gradient tensor.

Return type:

LabelTensor

div(output_, input_, components=None, d=None)[source]#

Compute the divergence of the output_ with respect to input.

This operator supports vector-valued functions with multiple input coordinates.

Parameters:
  • output (LabelTensor) – The output tensor on which the divergence is computed.

  • input (LabelTensor) – The input tensor with respect to which the divergence is computed.

  • components (list[str]) – The names of the output variables for which to compute the divergence. It must be a subset of the output labels. If None, all output variables are considered. Default is None.

  • d (list[str]) – The names of the input variables with respect to which the divergence is computed. It must be a subset of the input labels. If None, all input variables are considered. Default is None.

Raises:
  • TypeError – If the input tensor is not a LabelTensor.

  • ValueError – If the output is a scalar field.

  • ValueError – If the number of components is not equal to the number of input variables.

Returns:

The computed divergence tensor.

Return type:

LabelTensor

laplacian(output_, input_, components=None, d=None, method='std')[source]#

Compute the laplacian of the output_ with respect to input.

This operator supports both vector-valued and scalar-valued functions with one or multiple input coordinates.

Parameters:
  • output (LabelTensor) – The output tensor on which the laplacian is computed.

  • input (LabelTensor) – The input tensor with respect to which the laplacian is computed.

  • components (list[str]) – The names of the output variables for which to compute the laplacian. It must be a subset of the output labels. If None, all output variables are considered. Default is None.

  • d (list[str]) – The names of the input variables with respect to which the laplacian is computed. It must be a subset of the input labels. If None, all input variables are considered. Default is None.

  • method (str) – The method used to compute the Laplacian. Default is std.

Raises:

NotImplementedError – If std=divgrad.

Returns:

The computed laplacian tensor.

Return type:

LabelTensor

advection(output_, input_, velocity_field, components=None, d=None)[source]#

Perform the advection operation on the output_ with respect to the input. This operator support vector-valued functions with multiple input coordinates.

Parameters:
  • output (LabelTensor) – The output tensor on which the advection is computed.

  • input (LabelTensor) – the input tensor with respect to which advection is computed.

  • velocity_field (str) – The name of the output variable used as velocity field. It must be chosen among the output labels.

  • components (list[str]) – The names of the output variables for which to compute the advection. It must be a subset of the output labels. If None, all output variables are considered. Default is None.

  • d (list[str]) – The names of the input variables with respect to which the advection is computed. It must be a subset of the input labels. If None, all input variables are considered. Default is None.

Returns:

The computed advection tensor.

Return type:

LabelTensor