petsc_direct_solver.py#

LinearSolver that uses PETSc for LU factor/solve.

class openmdao.solvers.linear.petsc_direct_solver.PETScDirectSolver(**kwargs)[source]

Bases: DirectSolver

LinearSolver that uses PETSc for LU factor/solve.

Parameters:
**kwargsdict

Options dictionary.

SOLVER = 'LN: PETScDirect'
__init__(**kwargs)[source]

Declare the solver options.

add_recorder(recorder)

Add a recorder to the solver’s RecordingManager.

Parameters:
recorder<CaseRecorder>

A recorder instance to be added to RecManager.

can_solve_cycle()

Return True if this solver can solve groups with cycles.

Returns:
bool

True if this solver can solve groups with cycles.

cleanup()

Clean up resources prior to exit.

does_recursive_applies()

Return False.

By default, assume linear solvers don’t do recursive apply_linear calls.

Returns:
bool

True if solver makes recursive apply_linear calls on its subsystems.

get_outputs_dir(*subdirs, mkdir=False)

Get the path under which all output files of this solver are to be placed.

Parameters:
*subdirsstr

Subdirectories nested under the relevant problem output directory. To create {prob_output_dir}/a/b one would pass solver.get_outputs_dir(‘a’, ‘b’).

mkdirbool

If True, attempt to create this directory if it does not exist.

Returns:
pathlib.Path

The path of the outputs directory for the problem.

get_reports_dir()

Get the path to the directory where the report files should go.

If it doesn’t exist, it will be created.

Returns:
str

The path to the directory where reports should be written.

property msginfo

Return info to prepend to messages.

Returns:
str

Info to prepend to messages.

raise_petsc_error(e, system, matrix)[source]

Raise an error based on the issue that PETSc had with the linearize.

Parameters:
eError

Error returned by PETSc.

system<System>

System containing the Directsolver.

matrixndarray

Matrix of interest.

record_iteration(**kwargs)

Record an iteration of the current Solver.

Parameters:
**kwargsdict

Keyword arguments (used for abs and rel error).

report_failure(msg)

Report a failure that has occurred.

The msg may be printed or ignored depending on the iprint option, and may raise an AnalysisError depending on the err_on_non_converge option.

Parameters:
msgstr

Message indicating the failure.

solve(mode, rel_systems=None)[source]

Run the solver.

Parameters:
modestr

‘fwd’ or ‘rev’.

rel_systemsset of str

Names of systems relevant to the current solve. Deprecated.

use_relevance()

Return True if relevance should be active.

Returns:
bool

True if relevance should be active.

class openmdao.solvers.linear.petsc_direct_solver.PETScLU(A: ~scipy.sparse._matrix.spmatrix, sparse_solver_name: str = None, comm=<mpi4py.MPI.Intracomm object>)[source]

Bases: object

Wrapper for PETSc LU decomposition, using petsc4py.

Parameters:
Andarray or <scipy.sparse.csc_matrix>

Matrix to use in solving x @ A == b.

sparse_solver_namestr

Name of the direct solver from PETSc to use.

comm<mpi4py.MPI.Intracomm>

The system MPI communicator.

Attributes:
orig_Andarray or <scipy.sparse.csc_matrix>

Originally provided matrix.

A<petsc4py.PETSc.Mat>

Assembled PETSc AIJ (compressed sparse row format) matrix.

ksp<petsc4py.PETSc.KSP>

PETSc Krylov Subspace Solver context.

running_mpibool

Is the script currently being run under MPI (True) or not (False).

comm<mpi4py.MPI.Intracomm>

The system MPI communicator.

_x<petsc4py.PETSc.Vec>

Sequential (non-distributed) PETSc vector to store the solve solution.

__init__(A: ~scipy.sparse._matrix.spmatrix, sparse_solver_name: str = None, comm=<mpi4py.MPI.Intracomm object>)[source]

Initialize and setup the PETSc LU Direct Solver object.

solve(b: ndarray, transpose: bool = False) ndarray[source]

Solve the linear system using only the preconditioner direct solver.

Parameters:
bndarray

Input data for the right hand side.

transposebool

Is A.T @ x == b being solved (True) or A @ x == b (False).

Returns:
ndarray

The solution array.

openmdao.solvers.linear.petsc_direct_solver.check_err_on_singular(name, value)[source]

Check the value of the “err_on_singular” option on the PETScDirectSolver.

Parameters:
namestr

Name of the option being checked.

valuebool

Value of the option being checked.