Equations#

Equations are used in PINA to make easy the training. During problem definition each equation passed to a Condition object must be an Equation or SystemEquation. An Equation is simply a wrapper over callable python functions, while SystemEquation is a wrapper arounf a list of callable python functions. We provide a wide rage of already implemented equations to ease the code writing, such as FixedValue, Laplace, and many more.

class EquationInterface[source]#

Bases: object

The abstract AbstractProblem class. All the class defining a PINA Problem should be inheritied from this class.

In the definition of a PINA problem, the fundamental elements are: the output variables, the condition(s), and the domain(s) where the conditions are applied.

abstract residual(input_, output_, params_)[source]#

Residual computation of the equation.

Parameters:
  • input (LabelTensor) – Input points to evaluate the equation.

  • output (LabelTensor) – Output vectors given by my model (e.g., a FeedForward model).

  • params (dict) – Dictionary of unknown parameters, eventually related to an InverseProblem.

Returns:

The residual evaluation of the specified equation.

Return type:

LabelTensor

class Equation(equation)[source]#

Bases: EquationInterface

Equation class for specifing any equation in PINA. Each equation passed to a Condition object must be an Equation or SystemEquation.

Parameters:

equation (Callable) – A torch callable equation to evaluate the residual.

residual(input_, output_, params_=None)[source]#

Residual computation of the equation.

Parameters:
  • input (LabelTensor) – Input points to evaluate the equation.

  • output (LabelTensor) – Output vectors given by a model (e.g, a FeedForward model).

  • params (dict) – Dictionary of parameters related to the inverse problem (if any). If the equation is not related to an InverseProblem, the parameters are initialized to None and the residual is computed as equation(input_, output_). Otherwise, the parameters are automatically initialized in the ranges specified by the user.

Returns:

The residual evaluation of the specified equation.

Return type:

LabelTensor

class SystemEquation(list_equation, reduction=None)[source]#

Bases: Equation

System of Equation class for specifing any system of equations in PINA. Each equation passed to a Condition object must be an Equation or SystemEquation. A SystemEquation is specified by a list of equations.

Parameters:
  • equation (Callable) – A torch callable equation to evaluate the residual

  • reduction (str) – Specifies the reduction to apply to the output: None | mean | sum | callable. None: no reduction will be applied, mean: the output sum will be divided by the number of elements in the output, sum: the output will be summed. callable is a callable function to perform reduction, no checks guaranteed. Default: None.

residual(input_, output_, params_=None)[source]#

Residual computation for the equations of the system.

Parameters:
  • input (LabelTensor) – Input points to evaluate the system of equations.

  • output (LabelTensor) – Output vectors given by a model (e.g, a FeedForward model).

  • params (dict) – Dictionary of parameters related to the inverse problem (if any). If the equation is not related to an InverseProblem, the parameters are initialized to None and the residual is computed as equation(input_, output_). Otherwise, the parameters are automatically initialized in the ranges specified by the user.

Returns:

The residual evaluation of the specified system of equations, aggregated by the reduction defined in the __init__.

Return type:

LabelTensor

class FixedValue(value, components=None)[source]#

Bases: Equation

Fixed Value Equation class. This class can be used to enforced a fixed value for a specific condition, e.g. Dirichlet Boundary conditions.

Parameters:
  • value (float) – Value to be mantained fixed.

  • components (list(str)) – the name of the output variables to calculate the gradient for. It should be a subset of the output labels. If None, all the output variables are considered. Default is None.

class FixedGradient(value, components=None, d=None)[source]#

Bases: Equation

Fixed Gradient Equation class. This class can be used to enforced a fixed gradient for a specific condition.

Parameters:
  • value (float) – Value to be mantained fixed.

  • components (list(str)) – the name of the output variables to calculate the gradient for. It should be a subset of the output labels. If None, all the output variables are considered. Default is None.

  • d (list(str)) – the name of the input variables on which the gradient is calculated. d should be a subset of the input labels. If None, all the input variables are considered. Default is None.

class FixedFlux(value, components=None, d=None)[source]#

Bases: Equation

Fixed Flux Equation class. This class can be used to enforced a fixed flux for a specific condition.

Parameters:
  • value (float) – Value to be mantained fixed.

  • components (list(str)) – the name of the output variables to calculate the flux for. It should be a subset of the output labels. If None, all the output variables are considered. Default is None.

  • d (list(str)) – the name of the input variables on which the flux is calculated. d should be a subset of the input labels. If None, all the input variables are considered. Default is None.

class Laplace(components=None, d=None)[source]#

Bases: Equation

Laplace Equation class. This class can be used to enforced a Laplace equation for a specific condition (force term set to zero).

Parameters:
  • components (list(str)) – the name of the output variables to calculate the flux for. It should be a subset of the output labels. If None, all the output variables are considered. Default is None.

  • d (list(str)) – the name of the input variables on which the flux is calculated. d should be a subset of the input labels. If None, all the input variables are considered. Default is None.