scimba_torch.physical_models.elliptic_pde.linear_order_2

General linear order-2 and specific PDEs of advection-reaction-diffusion problems.

Functions

a_laplacian(spatial_dim)

Return the diffusion matrix function for the Laplacian operator.

b_laplacian(spatial_dim)

Return the advection vector function for the Laplacian operator.

c_laplacian()

Return the reaction coefficient function for the Laplacian operator.

d_dirichlet()

Return the boundary reaction coefficient function for Dirichlet BCs.

e_dirichlet()

Return the boundary diffusion coefficient function for Dirichlet BCs.

Classes

DivAGradUPDE(space, spatial_dim, f, g, **kwargs)

Diffusion-only PDE over a subdomain \(\Omega \subset \mathbb{R}^d\).

LinearOrder2PDE(space, spatial_dim, f, g, ...)

General linear order-2 PDE over a subdomain \(\Omega \subset \mathbb{R}^d\).

a_laplacian(spatial_dim)[source]

Return the diffusion matrix function for the Laplacian operator.

Parameters:

spatial_dim (int) – The spatial dimension of the problem.

Return type:

Callable[[Tensor], Tensor]

Returns:

A function that takes a tensor of shape (N, spatial_dim) and returns a tensor of shape (N, spatial_dim, spatial_dim).

b_laplacian(spatial_dim)[source]

Return the advection vector function for the Laplacian operator.

Parameters:

spatial_dim (int) – The spatial dimension of the problem.

Return type:

Callable[[Tensor], Tensor]

Returns:

A function that takes a tensor of shape (N, spatial_dim) and returns a tensor of shape (N, spatial_dim).

c_laplacian()[source]

Return the reaction coefficient function for the Laplacian operator.

Return type:

Callable[[Tensor], Tensor]

Returns:

A function that takes a tensor of shape (N, spatial_dim) and returns a tensor of shape (N, 1).

d_dirichlet()[source]

Return the boundary reaction coefficient function for Dirichlet BCs.

Return type:

Callable[[Tensor], Tensor]

Returns:

A function that takes a tensor of shape (N, spatial_dim) and returns a tensor of shape (N, 1).

e_dirichlet()[source]

Return the boundary diffusion coefficient function for Dirichlet BCs.

Return type:

Callable[[Tensor], Tensor]

Returns:

A function that takes a tensor of shape (N, spatial_dim) and returns a tensor of shape (N, 1).

class LinearOrder2PDE(space, spatial_dim, f, g, **kwargs)[source]

Bases: object

General linear order-2 PDE over a subdomain \(\Omega \subset \mathbb{R}^d\).

The equation is:

\[\mu \left( -\operatorname{div}(A(x) \nabla u(x)) + \operatorname{div}(b(x) u(x)) + c(x) u(x) \right) = f(x)\]

for \(x\) in the interior of \(\Omega\).

On the boundary \(\partial\Omega\):

\[e \left( A(x) \nabla u(x) \cdot n(x) \right) + d(x) u(x) = g(x)\]
where:
  • \(u\) is the unknown function,

  • \(f\), \(g\) are given functions,

  • \(\mu \in \mathbb{R}\) is a parameter,

  • \(A(x)\) is a matrix in \(\mathbb{R}^{d \times d}\) (diffusion),

  • \(b(x)\) is a vector in \(\mathbb{R}^d\) (advection),

  • \(c(x), d(x), e\) are scalars (reaction, boundary coefficients),

  • \(n(x)\) is the outward normal at \(x\),

  • \(\operatorname{div}\) is the divergence operator,

  • \(\nabla\) is the gradient operator,

  • \(\cdot\) is the dot product.

For instance:
  • Laplace equation with Dirichlet boundary: \(A(x) = I\), \(b(x) = 0\), \(c(x) = 0\), \(d(x) = 1\), \(e = 0\).

  • Neumann boundary: \(d(x) = 0\), \(e = 1\).

Parameters:
  • space (AbstractApproxSpace) – Approximation space used for the PDE.

  • spatial_dim (int) – Spatial dimension of the problem.

  • f (Callable) – Right-hand side function for the PDE.

  • g (Callable) – Right-hand side function for the boundary conditions.

  • **kwargs – Additional keyword arguments for coefficients A, b, c, d, e.

space: AbstractApproxSpace

Approximation space

spatial_dim: int

Spatial dimension

A: Callable

the A function

b: Callable

the b function

c: Callable

the c function

d: Callable

the d function

e: float

the e coefficient

f: Callable

the right-hand side function for the PDE

g: Callable

the right-hand side function for the boundary conditions

grad(w, y)[source]

Compute the gradient of the tensor w with respect to the tensor y.

Parameters:
Return type:

Union[Tensor, Generator[Tensor, None, None]]

Returns:

Gradient tensor

rhs(w, x, mu)[source]

Compute the right-hand side (RHS) of the PDE.

Parameters:
Returns:

The source term ( f(x, mu) ).

Return type:

torch.Tensor

bc_rhs(w, x, n, mu)[source]

Compute the RHS for the boundary conditions.

Parameters:
Returns:

The boundary condition ( g(x, mu) ).

Return type:

torch.Tensor

operator(w, x, mu)[source]

Compute the differential operator of the PDE.

Parameters:
Returns:

The result of applying the operator to the state.

Return type:

torch.Tensor

functional_operator(func, x, mu, theta)[source]

Compute the differential operator of the PDE using functional programming.

Parameters:
  • func (VarArgCallable) – Function representing the state.

  • x (Tensor) – Spatial coordinates tensor.

  • mu (Tensor) – Parameter tensor.

  • theta (Tensor) – Additional parameters for the function.

Return type:

Tensor

Returns:

The result of applying the operator to the state.

bc_operator(w, x, n, mu)[source]

Compute the operator for the boundary conditions.

Parameters:
Return type:

Tensor

Returns:

The boundary operator applied to the state.

functional_operator_bc(func, x, n, mu, theta)[source]

Compute the boundary operator using functional programming.

Parameters:
  • func (VarArgCallable) – Function representing the state.

  • x (Tensor) – Boundary coordinates tensor.

  • n (Tensor) – Normal vector tensor.

  • mu (Tensor) – Parameter tensor.

  • theta (Tensor) – Additional parameters for the function.

Return type:

Tensor

Returns:

The boundary operator applied to the state.

class DivAGradUPDE(space, spatial_dim, f, g, **kwargs)[source]

Bases: LinearOrder2PDE

Diffusion-only PDE over a subdomain \(\Omega \subset \mathbb{R}^d\).

The equation is:

\[\mu \left( -\operatorname{div}(A(x) \nabla u(x)) \right) = f(x)\]

for \(x\) in the interior of \(\Omega\).

On the boundary \(\partial\Omega\):

\[e \left( A(x) \nabla u(x) \cdot n(x) \right) + d(x) u(x) = g(x)\]
where:
  • \(u\) is the unknown function,

  • \(f\), \(g\) are given functions,

  • \(\mu \in \mathbb{R}\) is a parameter,

  • \(A(x)\) is a matrix in \(\mathbb{R}^{d \times d}\) (diffusion),

  • \(d(x), e\) are scalars (boundary coefficients),

  • \(n(x)\) is the outward normal at \(x\),

  • \(\operatorname{div}\) is the divergence operator,

  • \(\nabla\) is the gradient operator,

  • \(\cdot\) is the dot product.

For instance:
  • Laplace equation with Dirichlet boundary: \(A(x) = I\), \(d(x) = 1\), \(e = 0\).

  • Neumann boundary: \(d(x) = 0\), \(e = 1\).

Parameters:
  • space (AbstractApproxSpace) – Approximation space used for the PDE.

  • spatial_dim (int) – Spatial dimension of the problem.

  • f (Callable) – Right-hand side function for the PDE.

  • g (Callable) – Right-hand side function for the boundary conditions.

  • **kwargs – Additional keyword arguments for coefficients A, d, e.

Raises:

KeyError – If ‘b’ or ‘c’ are provided in kwargs, as they are not used in this model.

linearform(w, x, mu)[source]

Compute the right-hand side (RHS) of the PDE.

Parameters:
Return type:

Tensor

Returns:

The source term ( f(x, mu) ).

quadraticform(w, x, mu)[source]

Compute the differential operator of the PDE.

Parameters:
Returns:

The result of applying the operator to the state.

Return type:

torch.Tensor

energy_matrix(vals, x, mu)[source]

Compute the energy matrix.

Parameters:
  • vals (dict) – A dictionary containing precomputed values, including the evaluation of the function and its gradients.

  • x (Tensor) – Spatial coordinates tensor.

  • mu (Tensor) – Parameter tensor.

Return type:

Tensor

Returns:

The energy matrix.