linear_rhs_checker.py#

Define the LinearRHSChecker class.

LinearRHSChecker manages caching of solutions and right-hand sides for linear solves.

class openmdao.solvers.linear.linear_rhs_checker.LinearRHSChecker(system, max_cache_entries=3, check_zero=False, rtol=3e-16, atol=3e-16, collect_stats=False, verbose=False)[source]

Bases: object

Class that manages caching of linear solutions.

Parameters:
systemSystem

The system that owns the solver that owns this LinearRHSChecker.

max_cache_entriesint

Maximum number of solutions to cache. Defaults to 3.

check_zerobool

If True, check if the RHS vector is zero. Defaults to False.

rtolfloat

Relative tolerance for equivalence checks. Defaults to 3e-16.

atolfloat

Absolute tolerance for equivalence checks. Defaults to 3e-16.

collect_statsbool

If True, collect cache statistics. Defaults to False.

verbosebool

If True, print out whenever a cache hit occurs. Defaults to False.

Attributes:
_cacheslist

List of cached solutions.

_ncompute_totalsint

Total number of compute_totals calls. Used to determine when to reset the cache.

_check_zerobool

If True, check if the RHS vector is zero.

_rtolfloat

Relative tolerance for equivalence check.

_atolfloat

Absolute tolerance for equivalence check.

_statsdict or None

Dictionary to store cache statistics.

_verbosebool

If True, print out whenever a cache hit occurs.

_solver_msginfostr

The message info for the solver that owns this LinearRHSChecker.

__init__(system, max_cache_entries=3, check_zero=False, rtol=3e-16, atol=3e-16, collect_stats=False, verbose=False)[source]

Initialize the LinearRHSChecker.

add_solution(rhs, solution, copy)[source]

Add a solution to the cache.

Parameters:
rhsndarray

The RHS vector.

solutionndarray

The solution vector.

copybool

If True, make a copy of the RHS and solution vectors before storing them.

static check_options(system, options)[source]

Check the options dictionary for the presence of LinearRHSChecker options.

Parameters:
systemSystem

The system that owns the solver that owns this LinearRHSChecker.

optionsdict

The options dictionary.

clear()[source]

Clear the cache.

static create(system, opts)[source]

Conditionally create a LinearRHSChecker instance.

Parameters:
systemSystem

The system that owns the solver that owns this LinearRHSChecker.

optsdict or bool

Options for the LinearRHSChecker. If True, the LinearRHSChecker will be created with default options. If a dict, the values will override the defaults.

Returns:
LinearRHSChecker or None

A LinearRHSChecker instance if it was created, None otherwise.

get_solution(rhs_arr, system)[source]

Return a cached solution if the RHS vector matches a cached vector.

Also indicates if the RHS vector is zero.

Parameters:
rhs_arrndarray

The RHS vector.

systemSystem

The system that owns the solver that owns this LinearRHSChecker.

Returns:
ndarray or None

The cached solution if the RHS vector matches a cached vector, or None if no match is found.

bool

True if the rhs array is zero.

options = ('check_zero', 'rtol', 'atol', 'max_cache_entries', 'collect_stats', 'auto', 'verbose')