solver_base.py

Base class for linear and nonlinear solvers.

class openmdao.solvers.solver_base.LineSearch[source]

Bases: openmdao.solvers.solver_base.SolverBase

Base class for all linesearch subsolvers. Line search is used by other solvers such as the Newton solver. Inherit from this class to create a new custom line search.

Options:

options[‘iprint’] : int(0)

Set to 0 to disable printing, set to 1 to print iteration totals to stdout, set to 2 to print the residual each iteration to stdout.

solve(params, unknowns, resids, system, solver, alpha, fnorm, fnorm0, metadata=None)[source]

Take the gradient calculated by the parent solver and figure out how far to go.

Args:

params : VecWrapper

VecWrapper containing parameters. (p)

unknowns : VecWrapper

VecWrapper containing outputs and states. (u)

resids : VecWrapper

VecWrapper containing residuals. (r)

system : System

Parent System object.

metadata : dict, optional

Dictionary containing execution metadata (e.g. iteration coordinate).

solver : Solver

Parent solver instance.

alpha : float

Initial over-relaxation factor as used in parent solver.

fnorm : float

Initial norm of the residual for absolute tolerance check.

fnorm0 : float

Initial norm of the residual for relative tolerance check.

class openmdao.solvers.solver_base.LinearSolver[source]

Bases: openmdao.solvers.solver_base.SolverBase

Base class for all linear solvers. Inherit from this class to create a new custom linear solver.

Options:

options[‘iprint’] : int(0)

Set to 0 to disable printing, set to 1 to print iteration totals to stdout, set to 2 to print the residual each iteration to stdout.

add_recorder(recorder)[source]

Appends the given recorder to this solver’s list of recorders.

Args:

recorder: `BaseRecorder`

A recorder object.

solve(rhs, system, mode)[source]

Solves the linear system for the problem in self.system. The full solution vector is returned. This function must be defined when inheriting.

Args:

rhs : ndarray

Array containing the right-hand side for the linear solve. Also possibly a 2D array with multiple right-hand sides.

system : System

Parent System object.

mode : string

Derivative mode, can be ‘fwd’ or ‘rev’.

Returns:

ndarray : Solution vector

class openmdao.solvers.solver_base.MultLinearSolver[source]

Bases: openmdao.solvers.solver_base.LinearSolver

Base class for ScipyGMRES and DirectSolver. Adds a mult method.

mult(arg)[source]

Applies Jacobian matrix. Mode is determined by the system. This is a GMRES callback and is called by DirectSolver.solve.

Args:

arg : ndarray

Incoming vector

Returns:

ndarray : Matrix vector product of arg with jacobian

class openmdao.solvers.solver_base.NonLinearSolver[source]

Bases: openmdao.solvers.solver_base.SolverBase

Base class for all nonlinear solvers. Inherit from this class to create a new custom nonlinear solver.

Options:

options[‘iprint’] : int(0)

Set to 0 to disable printing, set to 1 to print iteration totals to stdout, set to 2 to print the residual each iteration to stdout.

add_recorder(recorder)[source]

Appends the given recorder to this solver’s list of recorders.

Args:

recorder: `BaseRecorder`

A recorder object.

solve(params, unknowns, resids, system, metadata=None)[source]

Drive all residuals in self.system and all subsystems to zero. This includes all implicit components. This function must be defined when inheriting.

Args:

params : VecWrapper

VecWrapper containing parameters. (p)

unknowns : VecWrapper

VecWrapper containing outputs and states. (u)

resids : VecWrapper

VecWrapper containing residuals. (r)

system : System

Parent System object.

metadata : dict, optional

Dictionary containing execution metadata (e.g. iteration coordinate).

class openmdao.solvers.solver_base.SolverBase[source]

Bases: object

Common base class for Linear and Nonlinear solver. Should not be used by users. Always inherit from LinearSolver or NonlinearSolver.

cleanup()[source]

Clean up resources prior to exit.

generate_docstring()[source]

Generates a numpy-style docstring for a user-created System class.

Returns:

docstring : str

string that contains a basic numpy docstring.

print_all_convergence(level=2)[source]

Turns on iprint for this solver and all subsolvers. Override if your solver has subsolvers.

Args:

level : int(2)

iprint level. Set to 2 to print residuals each iteration; set to 1 to print just the iteration totals.

print_norm(solver_string, system, iteration, res, res0, msg=None, indent=0, solver='NL', u_norm=None)[source]

Prints out the norm of the residual in a neat readable format.

Args:

solver_string: string

Unique string to identify your solver type (e.g., ‘LN_GS’ or ‘NEWTON’).

system: system

Parent system, which contains pathname and the preconditioning flag.

iteration: int

Current iteration number

res: float

Norm of the absolute residual value.

res0: float

Norm of the baseline initial residual for relative comparison.

msg: string, optional

Message that indicates convergence.

ident: int, optional

Additional indentation levels for subiterations.

solver: string, optional

Solver type if not LN or NL (mostly for line search operations.)

u_norm: float, optional

Norm of the u vector, if applicable.

setup(sub)[source]

Solvers override to define post-setup initiailzation.

Args:

sub: `System`

System that owns this solver.

openmdao.solvers.solver_base.error_wrap_nl(fn)[source]

Decorator adds some error-handling for floating point errors to any driver function.