tmdsimpy.NonlinearSolver

class tmdsimpy.NonlinearSolver(Dscale=1)

Bases: object

Class to provide an interface to linear and nonlinear solution methods.

Parameters:
Dscalefloat, optional

Argument for potential future implementation for conditioning the nonlinear problem. Is not implemented.

See also

tmdsimpy.jax.NonlinearSolverOMP

Alternative solver class that provides a consistent interface, but uses JAX to do more parallel operations.

Notes

Class is implemented to provide a consistent interface to different libraries for linear and nonlinear solutions.

__init__(Dscale=1)

Methods

__init__([Dscale])

conditioning_wrapper(fun, CtoP[, RPtoC])

Function to create a wrap a provided function and add conditioning.

eigs(K[, M, subset_by_index])

Conduct eigenvalue analysis for a linear system.

lin_factor(A)

Save information for solving a linear system.

lin_factored_solve(factor_res, b)

Solve the linear system with saved data.

lin_solve(A, b)

Solve the linear system A @ x = b

nsolve(fun, X0[, verbose, xtol])

Nonlinear solution to find zeros of a function.

conditioning_wrapper(fun, CtoP, RPtoC=1.0)

Function to create a wrap a provided function and add conditioning.

Parameters:
funfunction

Function that is to be wrapped in condition space. Function should take two arguments, one is unknown vector Xp, other is optional argument of calc_grad=True. The calc_grad=True is only passed to fun, if calc_grad=False is passed to the fun_conditioned that is returned.

CtoP(N,) numpy.ndarray

Vector describing conversion from physical coordinates to conditioned coordinates for the unknown vector that is input to fun.

RPtoCfloat, optional

Scales the full ouptut residual vector by this magnitude. The default is 1.0.

Returns:
fun_conditionedfunction

Function that describes the same nonlinear problem as fun, but in a conditioned space. Function takes input of Xc where Xp = CtoP * Xc. Second optional input to the fuction is calc_grad=True. This function returns a residual vector for conditioned inputs. If calc_grad=True, the Jacobian in conditioned space is also returned by this function.

eigs(K, M=None, subset_by_index=[0, 2])

Conduct eigenvalue analysis for a linear system.

Parameters:
K(N,N) numpy.ndarray

Stiffness matrix for general second order system. Assumed to be symmetric.

M(N,N) numpy.ndarray, optional

Mass matrix for general second order system. This must be symmetric positive definite. The default is None.

subset_by_indexlist of length 2, optional

Subset indices for which eigenvalues should be calculated. See scipy.linalg.eigh for more details. Let M be the number of requested eigenvalues by this parameter by setting it as [0,M]. The default is [0, 2].

Returns:
eigvals(M,) numpy.ndarray

Eigenvalues of the linear problem.

eigvecs(N,M) numpy.ndarray

Eigenvectors of linear problem with columns corresponding to individual eigenvalues.

See also

scipy.linalg.eigh

The eigen problem solver that is called here. This just provides an interface that can be made consistent with different approaches.

lin_factor(A)

Save information for solving a linear system.

This version simply stores and fully solves later.

Parameters:
A(N,N) numpy.ndarray

Linear system matrix for later solving.

Returns:
factor_restuple

Resulting data from factoring the matrix A, can be passed to lin_factored_solve to solve the linear system. This solver version does not do anything other than return A in a tuple

See also

lin_factored_solve

Method to solve the linear problem with the saved data.

lin_factored_solve(factor_res, b)

Solve the linear system with saved data.

This solves the problem A @ x = b where A is stored in factor_res and b is passed here.

Parameters:
factor_restuple

Collected data from self.lin_factor that will be used here. This version just is the tuple (A,)

b(N,) numpy.ndarray

Right hand side vector.

Returns:
x(N,) numpy.ndarray

Solution to the linear problem

See also

lin_factor

Method to call to create factor_res from linear system.

lin_solve(A, b)

Solve the linear system A @ x = b

Parameters:
A(N,N) numpy.ndarray

Linear system matrix.

b(N,) numpy.ndarray

Right hand side vector.

Returns:
x(N,) numpy.ndarray

Solution to the linear problem

nsolve(fun, X0, verbose=True, xtol=None)

Nonlinear solution to find zeros of a function.

Parameters:
funfunction

Function to solve that takes input like X0 and returns a residual vector of the same size and the square derivative matrix.

X0(N,) numpy.ndarray

Initial guess for the solution vector.

verbosebool, optional

Flag to print final solution result details. The default is True.

xtolfloat, optional

Tolerance for a solution step size to consider the problem solved. If None, then xtol = 1e-6*N. The default is None.

Returns:
X(N,) numpy.ndarray

Solution vector.

R(N,) numpy.ndarray

Residual evaluated at X or fun(X)[0].

dRdX(N,N) numpy.ndarray

Derivative of residual at X or fun(X)[1].

soldict

Dictionary of details about the solution to the problem. This is taken directly from scipy.optimize.root.

See also

scipy.optimize.root

Solver function that is used here. This method just provides an interface that allows for consistent implementation with other solvers.