class AutogradLinearSolver[source]

AutogradLinearSolver(*args, **kwargs) :: Function

Base class to create custom autograd.Function

To create a custom autograd.Function, subclass this class and implement the :meth:forward and :meth:backward static methods. Then, to use your custom op in the forward pass, call the class method apply. Do not call :meth:forward directly.

To ensure correctness and best performance, make sure you are calling the correct methods on ctx and validating your backward function using :func:torch.autograd.gradcheck.

See :ref:extending-autograd for more details on how to use this class.

Examples::

>>> class Exp(Function):
>>>     @staticmethod
>>>     def forward(ctx, i):
>>>         result = i.exp()
>>>         ctx.save_for_backward(result)
>>>         return result
>>>
>>>     @staticmethod
>>>     def backward(ctx, grad_output):
>>>         result, = ctx.saved_tensors
>>>         return grad_output * result
>>>
>>> # Use it by calling the apply method:
>>> output = Exp.apply(input)

class LinearSolver[source]

LinearSolver(factorize:bool=True)

A parent class for linear solvers that are used to solve the linear system that solves the PDE. We compute the gradients via torch.autograd and with the adjoint method in the backwards pass.

Type Default Details
factorize bool True Whether the system matrix should be factorized.

LinearSolver.__call__[source]

LinearSolver.__call__(θ:Tensor, A_op:Callable[Tensor, Tensor, Tensor], b:Tensor, A_mat:csc_matrix)

Solves the PDE for the density θ. Returns the solution as a torch.Tensor object.

Type Default Details
θ Tensor The density for which the PDE is solved.
A_op typing.Callable[[torch.Tensor, torch.Tensor], torch.Tensor] A function that takes u and θ as input and outputs the right hand side of the PDE. In other words, this is an operator representing the system matrix.
b Tensor A flattened version of the right side of the PDE.
A_mat csc_matrix The system matrix in sparse format.

class SparseLinearSolver[source]

SparseLinearSolver(use_umfpack:bool=True, factorize:bool=False) :: LinearSolver

A sparse linear solver implementation based on the scipy.sparse.linalg.solve() method that is used to solve the PDE of linear elasticity.

Type Default Details
use_umfpack bool True Whether to use umfpack. If false, then the LU solver from scipy.sparse is used, which is usually slower.
factorize bool False Whether the system matrix should be factorized.