pyoptmat.solvers: integrating structural material models

A few common functions related to solving nonlinear and linear systems of equations. These functions exist to “torchify” these common tasks. As always, the routines accept batched input.

class pyoptmat.solvers.JacobiPreconitionerOperator(A)

Bases: object

Jacobi preconditioning based on another matrix

Parameters:

A (torch.tensor) – operator to take diagonal from

dot(x)

Batched matrix-vector product

This object returns x_i / A_ii

Parameters:

x (torch.tensor) – input to linear operator

Returns:

result of the linear operator

Return type:

y (torch.tensor)

class pyoptmat.solvers.LUPreconitionerOperator(A)

Bases: object

Full LU preconditioning based on another matrix

Parameters:

A (torch.tensor) – operator to LU factorize

dot(x)

Batched matrix-vector product

This object does the backsolves to calculate (LU)^-1 * x

Parameters:

x (torch.tensor) – input to linear operator

Returns:

result of the linear operator

Return type:

y (torch.tensor)

class pyoptmat.solvers.NoOp

Bases: object

Linear operator that does nothing

dot(x)

Batched matrix-vector product

Here just returns the input unmodified

Parameters:

x (torch.tensor) – input to linear operator

Returns:

result of the linear operator

Return type:

y (torch.tensor)

class pyoptmat.solvers.PreconditionerReuseNonlinearSolver(nonlinear_solver=<function newton_raphson>)

Bases: object

Maintains preconditioner reuse through subsequent linear solves

solve(fn, x0, rtol=1e-06, atol=1e-10, miter=100, ltol=1e-10)

Solve the nonlinear system

pyoptmat.solvers.gmres(A, b, x0=None, M=<pyoptmat.solvers.NoOp object>, tol=1e-10, maxiter: int = 100, check=5, return_iters=False, eps=1e-15)

Solve a linear system of equations using GMRES

Parameters:
  • A (torch.tensor) – black matrix

  • b (torch.tensor) – black RHS

Keyword Arguments:
  • x0 (torch.tensor) – initial guess, defaults to zeros

  • M (LinearOperator) – preconditioning operator

  • tol (float) – absolute tolerance for solve

  • maxiter (int) – maximum number of iterations

  • check (int) – how often to check the residual

  • return_iters (bool) – return iteration count along with solution

  • eps (float) – small number to avoid zero vectors

Returns:

block results k (int, optional): iteration count

Return type:

x (torch.tensor)

pyoptmat.solvers.jacobi_gmres(A, *args, **kwargs)

Solve a linear system of equations using Jacobi preconditioned GMRES

Parameters:
  • A (torch.tensor) – black matrix

  • b (torch.tensor) – black RHS

Keyword Arguments:
  • x0 (torch.tensor) – initial guess, defaults to zeros

  • M (LinearOperator) – preconditioning operator

  • tol (float) – absolute tolerance for solve

  • maxiter (int) – maximum number of iterations

  • check (int) – how often to check the residual

Returns:

block results

Return type:

x (torch.tensor)

pyoptmat.solvers.jacobi_iteration_linear_solve(A, b)

Do one iteration of the Jacobi method on the provided linear system of equations

Parameters:
  • A (torch.tensor) – block matrix

  • b (torch.tensor) – block RHS

pyoptmat.solvers.lu_gmres(A, *args, **kwargs)

Solve a linear system of equations using LU preconditioned GMRES

This is an entirely pointless operation, but useful in testing

Parameters:
  • A (torch.tensor) – black matrix

  • b (torch.tensor) – black RHS

Keyword Arguments:
  • x0 (torch.tensor) – initial guess, defaults to zeros

  • M (LinearOperator) – preconditioning operator

  • tol (float) – absolute tolerance for solve

  • maxiter (int) – maximum number of iterations

  • check (int) – how often to check the residual

Returns:

block results

Return type:

x (torch.tensor)

pyoptmat.solvers.lu_linear_solve(A, b, return_iters=False)

Solve a linear system of equations with the built in torch.linalg.solve

Parameters:
  • A (torch.tensor) – block matrix

  • b (torch.tensor) – block RHS

pyoptmat.solvers.newton_raphson(fn, x0, linsolver='lu', rtol=1e-06, atol=1e-10, miter=100)

Solve a nonlinear system with Newton’s method. Return the solution and the last Jacobian

Parameters:
  • fn (function) – function that returns the residual and Jacobian

  • x0 (torch.tensor) – starting point

Keyword Arguments:
  • linsolver (string) – method to use to solve the linear system, options are “diag” or “lu”. Defaults to “lu”. See pyoptmat.solvers.solve_linear_system()

  • rtol (float) – nonlinear relative tolerance

  • atol (float) – nonlinear absolute tolerance

  • miter (int) – maximum number of nonlinear iterations

Returns:

solution to system of equations and

Jacobian evaluated at that point

Return type:

torch.tensor, torch.tensor

pyoptmat.solvers.newton_raphson_bt(fn, x0, linsolver='lu', rtol=1e-06, atol=1e-10, miter=100, max_bt=5)

Solve a nonlinear system with Newton’s method. Return the solution and the last Jacobian

Parameters:
  • fn (function) – function that returns the residual and Jacobian

  • x0 (torch.tensor) – starting point

Keyword Arguments:
  • linsolver (string or function) – method to use to solve the linear system, strain options are “diag” or “lu”. Defaults to “lu”.

  • rtol (float) – nonlinear relative tolerance

  • atol (float) – nonlinear absolute tolerance

  • miter (int) – maximum number of nonlinear iterations

  • max_bt (int) – maximum number of backtracking line search iterations

Returns:

solution to system of equations and

Jacobian evaluated at that point

Return type:

torch.tensor, torch.tensor