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.
Each differential operator has its fast version, which performs no internal
checks on input and output tensors. For these methods, the user is always
required to specify both components
and d
as lists of strings.
- fast_grad(output_, input_, components, d)[source]#
Compute the gradient of the
output_
with respect to theinput
.Unlike
grad
, this function performs no internal checks on input and output tensors. The user is required to specify bothcomponents
andd
as lists of strings. It is designed to enhance computation speed.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.
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.
- Returns:
The computed gradient tensor.
- Return type:
- fast_div(output_, input_, components, d)[source]#
Compute the divergence of the
output_
with respect toinput
.Unlike
div
, this function performs no internal checks on input and output tensors. The user is required to specify bothcomponents
andd
as lists of strings. It is designed to enhance computation speed.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.
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.
- Return type:
- fast_laplacian(output_, input_, components, d, method='std')[source]#
Compute the laplacian of the
output_
with respect toinput
.Unlike
laplacian
, this function performs no internal checks on input and output tensors. The user is required to specify bothcomponents
andd
as lists of strings. It is designed to enhance computation speed.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.
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.
method (str) – The method used to compute the Laplacian. Available methods are
std
anddivgrad
. Thestd
method computes the trace of the Hessian matrix, while thedivgrad
method computes the divergence of the gradient. Default isstd
.
- Returns:
The computed laplacian tensor.
- Return type:
- fast_advection(output_, input_, velocity_field, components, d)[source]#
Perform the advection operation on the
output_
with respect to theinput
. This operator support vector-valued functions with multiple input coordinates.Unlike
advection
, this function performs no internal checks on input and output tensors. The user is required to specify bothcomponents
andd
as lists of strings. It is designed to enhance computation speed.- 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.
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.
- Returns:
The computed advection tensor.
- Return type:
- grad(output_, input_, components=None, d=None)[source]#
Compute the gradient of the
output_
with respect to theinput
.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 (str | 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 isNone
.d (str | 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 isNone
.
- Raises:
TypeError – If the input tensor is not a LabelTensor.
TypeError – If the output tensor is not a LabelTensor.
RuntimeError – If derivative labels are missing from the
input_
.RuntimeError – If component labels are missing from the
output_
.
- Returns:
The computed gradient tensor.
- Return type:
- div(output_, input_, components=None, d=None)[source]#
Compute the divergence of the
output_
with respect toinput
.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 (str | 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 isNone
.d – 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 isNone
.
- Raises:
TypeError – If the input tensor is not a LabelTensor.
TypeError – If the output tensor is not a LabelTensor.
ValueError – If the length of
components
andd
do not match.
- Returns:
The computed divergence tensor.
- Return type:
- laplacian(output_, input_, components=None, d=None, method='std')[source]#
Compute the laplacian of the
output_
with respect toinput
.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 (str | 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 isNone
.d (str | 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 isNone
.method (str) – The method used to compute the Laplacian. Available methods are
std
anddivgrad
. Thestd
method computes the trace of the Hessian matrix, while thedivgrad
method computes the divergence of the gradient. Default isstd
.
- Raises:
TypeError – If the input tensor is not a LabelTensor.
TypeError – If the output tensor is not a LabelTensor.
ValueError – If the passed method is neither
std
nordivgrad
.
- Returns:
The computed laplacian tensor.
- Return type:
- advection(output_, input_, velocity_field, components=None, d=None)[source]#
Perform the advection operation on the
output_
with respect to theinput
. 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 (str | 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 isNone
.d (str | 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 isNone
.
- Raises:
TypeError – If the input tensor is not a LabelTensor.
TypeError – If the output tensor is not a LabelTensor.
RuntimeError – If the velocity field is not in the output labels.
- Returns:
The computed advection tensor.
- Return type: