An interface to the Trilinos AztecOO classes allowing it to be used as an Oomph-lib LinearSolver. The AztecOO solver is a Krylov Subspace solver; the solver type (either CG, GMRES or BiCGStab) can be set using solver_type(). This solver can be preconditioned with Trilinos Preconditioners (derived from TrilinosPreconditionerBase) or Oomph-lib preconditioners (derived from Preconditioner). Preconditioners are set using preconditioner_pt(). More...
#include <trilinos_solver.h>
Public Types | |
enum | AztecOO_solver_types { CG, GMRES, BiCGStab } |
Enumerated list to define which AztecOO solver is used. More... | |
Public Member Functions | |
TrilinosAztecOOSolver () | |
Constructor. More... | |
~TrilinosAztecOOSolver () | |
Destructor - delete the solver and the matrices. More... | |
TrilinosAztecOOSolver (const TrilinosAztecOOSolver &) | |
Broken copy constructor. More... | |
void | operator= (const TrilinosAztecOOSolver &) |
Broken assignment operator. More... | |
void | enable_aztecoo_workaround_for_epetra_matrix_setup () |
Enable workaround for creating of epetra matrix that respects aztecoo's ordering requirements. More... | |
void | disable_aztecoo_workaround_for_epetra_matrix_setup () |
Disable workaround for creating of epetra matrix that respects aztecoo's ordering requirements. More... | |
bool | is_aztecoo_workaround_for_epetra_matrix_setup_enabled () |
Is workaround for creating of epetra matrix that respects aztecoo's ordering requirements enabled? More... | |
void | clean_up_memory () |
Clean up method - deletes the solver, the matrices and the preconditioner. More... | |
void | solve (Problem *const &problem_pt, DoubleVector &solution) |
Function which uses problem_pt's get_jacobian(...) function to generate a linear system which is then solved. This function deletes any existing internal data and then generates a new AztecOO solver. More... | |
void | solve (DoubleMatrixBase *const &matrix_pt, const DoubleVector &rhs, DoubleVector &solution) |
Function to solve the linear system defined by matrix_pt and rhs. NOTE 1. The matrix has to be of type CRDoubleMatrix or DistributedCRDoubleMatrix. NOTE 2. This function will delete any existing internal data and generate a new AztecOO solver. More... | |
void | resolve (const DoubleVector &rhs, DoubleVector &solution) |
Function to resolve a linear system using the existing solver data, allowing a solve with a new right hand side vector. This function must be used after a call to solve(...) with enable_resolve set to true. More... | |
void | disable_resolve () |
Disable resolve function (overloads the LinearSolver disable_resolve function). More... | |
void | enable_delete_matrix () |
Call if the matrix can be deleted. More... | |
void | disable_delete_matrix () |
\ short Call if the matrix can not be deleted (default) More... | |
unsigned & | max_iter () |
Access function to Max_iter. More... | |
unsigned | iterations () const |
Acess function to Iterations. More... | |
double & | tolerance () |
Access function to Tolerance. More... | |
unsigned & | solver_type () |
Access function to Solver_type. More... | |
double | jacobian_setup_time () |
Function to return Jacobian_setup_time;. More... | |
double | linear_solver_solution_time () |
Function to return Linear_solver_solution_time. More... | |
void | enable_assemble_serial_jacobian () |
Set the assembly of the serial jacobian when performing a problem-based solve. More... | |
void | disable_assemble_serial_jacobian () |
Unset the assembly of the serial jacobian. More... | |
![]() | |
IterativeLinearSolver () | |
Constructor: Set (default) trivial preconditioner and set defaults for tolerance and max. number of iterations. More... | |
IterativeLinearSolver (const IterativeLinearSolver &) | |
Broken copy constructor. More... | |
void | operator= (const IterativeLinearSolver &) |
Broken assignment operator. More... | |
virtual | ~IterativeLinearSolver () |
Destructor (empty) More... | |
Preconditioner *& | preconditioner_pt () |
Access function to preconditioner. More... | |
Preconditioner *const & | preconditioner_pt () const |
Access function to preconditioner (const version) More... | |
double & | tolerance () |
Access to convergence tolerance. More... | |
unsigned & | max_iter () |
Access to max. number of iterations. More... | |
void | enable_doc_convergence_history () |
Enable documentation of the convergence history. More... | |
void | disable_doc_convergence_history () |
Disable documentation of the convergence history. More... | |
void | open_convergence_history_file_stream (const std::string &file_name, const std::string &zone_title="") |
Write convergence history into file with specified filename (automatically switches on doc). Optional second argument is a string that can be used (as a zone title) to identify what case we're running (e.g. what combination of linear solver and preconditioner or parameter values are used). More... | |
void | close_convergence_history_file_stream () |
Close convergence history output stream. More... | |
double | jacobian_setup_time () const |
returns the time taken to assemble the jacobian matrix and residual vector More... | |
double | linear_solver_solution_time () const |
return the time taken to solve the linear system More... | |
virtual double | preconditioner_setup_time () const |
returns the the time taken to setup the preconditioner More... | |
void | enable_setup_preconditioner_before_solve () |
Setup the preconditioner before the solve. More... | |
void | disable_setup_preconditioner_before_solve () |
Don't set up the preconditioner before the solve. More... | |
void | enable_error_after_max_iter () |
Throw an error if we don't converge within max_iter. More... | |
void | disable_error_after_max_iter () |
Don't throw an error if we don't converge within max_iter (default). More... | |
void | enable_iterative_solver_as_preconditioner () |
void | disable_iterative_solver_as_preconditioner () |
![]() | |
LinearSolver () | |
Empty constructor, initialise the member data. More... | |
LinearSolver (const LinearSolver &dummy) | |
Broken copy constructor. More... | |
void | operator= (const LinearSolver &) |
Broken assignment operator. More... | |
virtual | ~LinearSolver () |
Empty virtual destructor. More... | |
void | enable_doc_time () |
Enable documentation of solve times. More... | |
void | disable_doc_time () |
Disable documentation of solve times. More... | |
bool | is_doc_time_enabled () const |
Is documentation of solve times enabled? More... | |
bool | is_resolve_enabled () const |
Boolean flag indicating if resolves are enabled. More... | |
virtual void | enable_resolve () |
Enable resolve (i.e. store matrix and/or LU decomposition, say) Virtual so it can be overloaded to perform additional tasks. More... | |
virtual void | solve (DoubleMatrixBase *const &matrix_pt, const Vector< double > &rhs, Vector< double > &result) |
Linear-algebra-type solver: Takes pointer to a matrix and rhs vector and returns the solution of the linear system. More... | |
virtual void | enable_computation_of_gradient () |
function to enable the computation of the gradient required for the globally convergent Newton method More... | |
void | disable_computation_of_gradient () |
function to disable the computation of the gradient required for the globally convergent Newton method More... | |
void | reset_gradient () |
function to reset the size of the gradient before each Newton solve More... | |
void | get_gradient (DoubleVector &gradient) |
function to access the gradient, provided it has been computed More... | |
![]() | |
DistributableLinearAlgebraObject () | |
Default constructor - create a distribution. More... | |
DistributableLinearAlgebraObject (const DistributableLinearAlgebraObject &matrix) | |
Broken copy constructor. More... | |
void | operator= (const DistributableLinearAlgebraObject &) |
Broken assignment operator. More... | |
virtual | ~DistributableLinearAlgebraObject () |
Destructor. More... | |
LinearAlgebraDistribution * | distribution_pt () const |
access to the LinearAlgebraDistribution More... | |
unsigned | nrow () const |
access function to the number of global rows. More... | |
unsigned | nrow_local () const |
access function for the num of local rows on this processor. More... | |
unsigned | nrow_local (const unsigned &p) const |
access function for the num of local rows on this processor. More... | |
unsigned | first_row () const |
access function for the first row on this processor More... | |
unsigned | first_row (const unsigned &p) const |
access function for the first row on this processor More... | |
bool | distributed () const |
distribution is serial or distributed More... | |
bool | distribution_built () const |
void | build_distribution (const LinearAlgebraDistribution *const dist_pt) |
setup the distribution of this distributable linear algebra object More... | |
void | build_distribution (const LinearAlgebraDistribution &dist) |
setup the distribution of this distributable linear algebra object More... | |
Protected Member Functions | |
void | solve_using_AztecOO (Epetra_Vector *&rhs_pt, Epetra_Vector *&soln_pt) |
Helper function performs the actual solve once the AztecOO solver is set up. More... | |
void | solver_setup (DoubleMatrixBase *const &matrix_pt) |
Helper function for setting up the solver. Converts the oomph-lib matrices to Epetra matrices, sets up the preconditioner, creates the Trilinos Aztec00 solver and passes in the matrix, preconditioner and parameters. More... | |
![]() | |
void | clear_distribution () |
clear the distribution of this distributable linear algebra object More... | |
Protected Attributes | |
bool | Use_aztecoo_workaround_for_epetra_matrix_setup |
Use workaround for creating of epetra matrix that respects aztecoo's ordering requirements. More... | |
unsigned | Iterations |
Stores number of iterations used. More... | |
AztecOO * | AztecOO_solver_pt |
Pointer to the AztecOO solver. More... | |
double | Jacobian_setup_time |
Stores set up time for Jacobian. More... | |
double | Linear_solver_solution_time |
Stores time for the solution (excludes time to set up preconditioner) More... | |
bool | Delete_matrix |
Trilinos copies matrix data from oomph-lib's own CRDoubleMatrix or DistributedCRDoubleMatrix to Trilinos's Epetra format - the Trilinos solver no longer requires the oomph-lib matrices and therefore they could be deleted to save memory. This must be requested explicitly by setting this flag to TRUE. NOTE: The matrix is deleted after the preconditioner is setup. More... | |
bool | Assemble_serial_jacobian |
If true, when performing a problem based solve a serial matrix will be requested from Problem::get_jacobian(...). Defaults to true. More... | |
unsigned | Solver_type |
Defines which solver is set up - available types are defined in AztecOO_solver_types. More... | |
bool | Using_problem_based_solve |
Helper flag keeping track of whether we called the linear algebra or problem-based solve function. More... | |
Epetra_CrsMatrix * | Epetra_matrix_pt |
A pointer for the linear system matrix in Epetra_CrsMatrix format. More... | |
Epetra_Operator * | Epetra_preconditioner_pt |
A pointer to the Epetra_Operator for the preconditioner. This is only used if the preconditioner NOT a Trilinos preconditioner. More... | |
DoubleMatrixBase * | Oomph_matrix_pt |
Oomph lib matrix pointer. More... | |
Problem * | Problem_pt |
A pointer to the underlying problem (NULL if MATRIX based solve) The problem_pt is stored here in a problem based solve for the preconditioner. More... | |
bool | If_oomphlib_preconditioner_use_epetra_values |
![]() | |
bool | Doc_convergence_history |
Flag indicating if the convergence history is to be documented. More... | |
std::ofstream | Output_file_stream |
Output file stream for convergence history. More... | |
double | Tolerance |
Convergence tolerance. More... | |
unsigned | Max_iter |
Maximum number of iterations. More... | |
Preconditioner * | Preconditioner_pt |
Pointer to the preconditioner. More... | |
double | Jacobian_setup_time |
Jacobian setup time. More... | |
double | Solution_time |
linear solver solution time More... | |
double | Preconditioner_setup_time |
Preconditioner setup time. More... | |
bool | Setup_preconditioner_before_solve |
indicates whether the preconditioner should be setup before solve. Default = true; More... | |
bool | Throw_error_after_max_iter |
Should we throw an error instead of just returning when we hit the max iterations? More... | |
bool | Use_iterative_solver_as_preconditioner |
Use the iterative solver as preconditioner. More... | |
bool | First_time_solve_when_used_as_preconditioner |
![]() | |
bool | Enable_resolve |
Boolean that indicates whether the matrix (or its factors, in the case of direct solver) should be stored so that the resolve function can be used. More... | |
bool | Doc_time |
Boolean flag that indicates whether the time taken. More... | |
bool | Compute_gradient |
flag that indicates whether the gradient required for the globally convergent Newton method should be computed or not More... | |
bool | Gradient_has_been_computed |
flag that indicates whether the gradient was computed or not More... | |
DoubleVector | Gradient_for_glob_conv_newton_solve |
DoubleVector storing the gradient for the globally convergent Newton method. More... | |
Additional Inherited Members | |
![]() | |
static IdentityPreconditioner | Default_preconditioner |
Default preconditioner: The base class for preconditioners is a fully functional (if trivial!) preconditioner. More... | |
An interface to the Trilinos AztecOO classes allowing it to be used as an Oomph-lib LinearSolver. The AztecOO solver is a Krylov Subspace solver; the solver type (either CG, GMRES or BiCGStab) can be set using solver_type(). This solver can be preconditioned with Trilinos Preconditioners (derived from TrilinosPreconditionerBase) or Oomph-lib preconditioners (derived from Preconditioner). Preconditioners are set using preconditioner_pt().
Definition at line 294 of file trilinos_solver.h.
Enumerated list to define which AztecOO solver is used.
if this solver is using an oomph-lib preconditioner then the vectors passed to preconditioner_solve(...) should be using the values in the epetra vector as external data. If the vectors are using external data then rebuild(...) methods cannot be used be used in the preconditioner.
Enumerator | |
---|---|
CG | |
GMRES | |
BiCGStab |
Definition at line 482 of file trilinos_solver.h.
|
inline |
|
inline |
Destructor - delete the solver and the matrices.
Definition at line 333 of file trilinos_solver.h.
|
inline |
Broken copy constructor.
Definition at line 348 of file trilinos_solver.h.
References oomph::BrokenCopy::broken_copy().
|
inlinevirtual |
Clean up method - deletes the solver, the matrices and the preconditioner.
Reimplemented from oomph::LinearSolver.
Definition at line 375 of file trilinos_solver.h.
References oomph::Preconditioner::clean_up_memory().
Referenced by solve(), and solver_setup().
|
inline |
Unset the assembly of the serial jacobian.
Definition at line 469 of file trilinos_solver.h.
|
inline |
Disable workaround for creating of epetra matrix that respects aztecoo's ordering requirements.
Definition at line 366 of file trilinos_solver.h.
|
inline |
\ short Call if the matrix can not be deleted (default)
Definition at line 444 of file trilinos_solver.h.
|
inlinevirtual |
Disable resolve function (overloads the LinearSolver disable_resolve function).
Reimplemented from oomph::LinearSolver.
Definition at line 434 of file trilinos_solver.h.
|
inline |
Set the assembly of the serial jacobian when performing a problem-based solve.
Definition at line 466 of file trilinos_solver.h.
|
inline |
Enable workaround for creating of epetra matrix that respects aztecoo's ordering requirements.
Definition at line 361 of file trilinos_solver.h.
|
inline |
Call if the matrix can be deleted.
Definition at line 441 of file trilinos_solver.h.
|
inline |
Is workaround for creating of epetra matrix that respects aztecoo's ordering requirements enabled?
Definition at line 371 of file trilinos_solver.h.
|
inlinevirtual |
Acess function to Iterations.
Implements oomph::IterativeLinearSolver.
Definition at line 450 of file trilinos_solver.h.
|
inline |
Function to return Jacobian_setup_time;.
Definition at line 459 of file trilinos_solver.h.
|
inline |
Function to return Linear_solver_solution_time.
Definition at line 462 of file trilinos_solver.h.
|
inline |
Access function to Max_iter.
Definition at line 447 of file trilinos_solver.h.
References oomph::BlackBoxFDNewtonSolver::Max_iter.
|
inline |
Broken assignment operator.
Definition at line 354 of file trilinos_solver.h.
References oomph::BrokenCopy::broken_assign().
|
virtual |
Function to resolve a linear system using the existing solver data, allowing a solve with a new right hand side vector. This function must be used after a call to solve(...) with enable_resolve set to true.
Reimplemented from oomph::LinearSolver.
Definition at line 505 of file trilinos_solver.cc.
References oomph::DoubleVector::build(), oomph::DoubleVector::built(), oomph::TrilinosEpetraHelpers::copy_to_oomphlib_vector(), oomph::TrilinosEpetraHelpers::create_distributed_epetra_vector(), oomph::DistributableLinearAlgebraObject::distribution_built(), oomph::DistributableLinearAlgebraObject::distribution_pt(), oomph::LinearSolver::Doc_time, Epetra_matrix_pt, Linear_solver_solution_time, oomph::DistributableLinearAlgebraObject::nrow(), oomph::oomph_info, solve_using_AztecOO(), and oomph::TimingHelpers::timer().
|
virtual |
Function which uses problem_pt's get_jacobian(...) function to generate a linear system which is then solved. This function deletes any existing internal data and then generates a new AztecOO solver.
Function which uses problem_pt's get_jacobian(...) function to generate a linear system which is then solved. This function deletes any existing internal data and then generates a new AztecOO solver.
Implements oomph::LinearSolver.
Definition at line 49 of file trilinos_solver.cc.
References oomph::DoubleVector::build(), oomph::DistributableLinearAlgebraObject::build_distribution(), oomph::DoubleVector::built(), clean_up_memory(), oomph::DistributableLinearAlgebraObject::distribution_pt(), oomph::LinearSolver::Doc_time, oomph::Problem::get_jacobian(), Jacobian_setup_time, oomph::oomph_info, Oomph_matrix_pt, Problem_pt, oomph::DoubleVector::redistribute(), oomph::TimingHelpers::timer(), and Using_problem_based_solve.
|
virtual |
Function to solve the linear system defined by matrix_pt and rhs. NOTE 1. The matrix has to be of type CRDoubleMatrix or DistributedCRDoubleMatrix. NOTE 2. This function will delete any existing internal data and generate a new AztecOO solver.
Function to solve the linear system defined by matrix_pt and rhs. NOTE 1. The matrix has to be of type CRDoubleMatrix or DistributedCRDoubleMatrix. NOTE 2. This function will delete any existing internal data and generate a new AztecOO solver.
Reimplemented from oomph::LinearSolver.
Definition at line 145 of file trilinos_solver.cc.
References oomph::DoubleVector::build(), oomph::DoubleVector::built(), clean_up_memory(), oomph::LinearAlgebraDistribution::communicator_pt(), oomph::TrilinosEpetraHelpers::copy_to_oomphlib_vector(), oomph::TrilinosEpetraHelpers::create_distributed_epetra_vector(), oomph::DistributableLinearAlgebraObject::distribution_pt(), oomph::LinearSolver::Doc_time, oomph::LinearSolver::Enable_resolve, oomph::IterativeLinearSolver::First_time_solve_when_used_as_preconditioner, Linear_solver_solution_time, oomph::DoubleMatrixBase::ncol(), oomph::DoubleMatrixBase::nrow(), oomph::DistributableLinearAlgebraObject::nrow(), oomph::oomph_info, solve_using_AztecOO(), solver_setup(), oomph::TimingHelpers::timer(), and oomph::IterativeLinearSolver::Use_iterative_solver_as_preconditioner.
|
protected |
Helper function performs the actual solve once the AztecOO solver is set up.
Helper function performs the actual solve once the AztecOO solver is set up (i.e. solver_setup() is called)
Definition at line 588 of file trilinos_solver.cc.
References AztecOO_solver_pt, oomph::LinearSolver::Doc_time, Iterations, oomph::IterativeLinearSolver::Max_iter, oomph::oomph_info, and oomph::IterativeLinearSolver::Tolerance.
|
protected |
Helper function for setting up the solver. Converts the oomph-lib matrices to Epetra matrices, sets up the preconditioner, creates the Trilinos Aztec00 solver and passes in the matrix, preconditioner and parameters.
Helper function for setting up the solver. Converts the oomph-lib matrices to Epetra matrices, sets up the preconditioner, creates the Trilinos Aztec00 solver and passes in the matrix, preconditioner and parameters.
Definition at line 296 of file trilinos_solver.cc.
References AztecOO_solver_pt, BiCGStab, oomph::DistributableLinearAlgebraObject::build_distribution(), CG, clean_up_memory(), oomph::TrilinosEpetraHelpers::create_distributed_epetra_matrix(), oomph::TrilinosEpetraHelpers::create_distributed_epetra_matrix_for_aztecoo(), Delete_matrix, oomph::DistributableLinearAlgebraObject::distribution_pt(), oomph::LinearSolver::Doc_time, Epetra_matrix_pt, oomph::TrilinosPreconditionerBase::epetra_operator_pt(), Epetra_preconditioner_pt, GMRES, oomph::IterativeLinearSolver::Max_iter, oomph::oomph_info, Oomph_matrix_pt, oomph::IterativeLinearSolver::Preconditioner_pt, oomph::Preconditioner::set_matrix_pt(), oomph::Preconditioner::setup(), oomph::TrilinosPreconditionerBase::setup(), oomph::IterativeLinearSolver::Setup_preconditioner_before_solve, Solver_type, oomph::TimingHelpers::timer(), Use_aztecoo_workaround_for_epetra_matrix_setup, and Using_problem_based_solve.
Referenced by solve().
|
inline |
Access function to Solver_type.
Definition at line 456 of file trilinos_solver.h.
|
inline |
Access function to Tolerance.
Definition at line 453 of file trilinos_solver.h.
|
protected |
If true, when performing a problem based solve a serial matrix will be requested from Problem::get_jacobian(...). Defaults to true.
Definition at line 524 of file trilinos_solver.h.
|
protected |
Pointer to the AztecOO solver.
Definition at line 506 of file trilinos_solver.h.
Referenced by solve_using_AztecOO(), and solver_setup().
|
protected |
Trilinos copies matrix data from oomph-lib's own CRDoubleMatrix or DistributedCRDoubleMatrix to Trilinos's Epetra format - the Trilinos solver no longer requires the oomph-lib matrices and therefore they could be deleted to save memory. This must be requested explicitly by setting this flag to TRUE. NOTE: The matrix is deleted after the preconditioner is setup.
Definition at line 520 of file trilinos_solver.h.
Referenced by solver_setup().
|
protected |
A pointer for the linear system matrix in Epetra_CrsMatrix format.
Definition at line 535 of file trilinos_solver.h.
Referenced by resolve(), and solver_setup().
|
protected |
A pointer to the Epetra_Operator for the preconditioner. This is only used if the preconditioner NOT a Trilinos preconditioner.
Definition at line 539 of file trilinos_solver.h.
Referenced by solver_setup().
|
protected |
if this solver is using an oomph-lib preconditioner then the vectors passed to preconditioner_solve(...) should be using the values in the epetra vector as external data. If the vectors are using external data then rebuild(...) methods cannot be used.
Definition at line 553 of file trilinos_solver.h.
|
protected |
Stores number of iterations used.
Definition at line 503 of file trilinos_solver.h.
Referenced by solve_using_AztecOO().
|
protected |
Stores set up time for Jacobian.
Definition at line 509 of file trilinos_solver.h.
Referenced by solve().
|
protected |
Stores time for the solution (excludes time to set up preconditioner)
Definition at line 512 of file trilinos_solver.h.
|
protected |
Oomph lib matrix pointer.
Definition at line 542 of file trilinos_solver.h.
Referenced by solve(), and solver_setup().
|
protected |
A pointer to the underlying problem (NULL if MATRIX based solve) The problem_pt is stored here in a problem based solve for the preconditioner.
Definition at line 547 of file trilinos_solver.h.
Referenced by solve().
|
protected |
Defines which solver is set up - available types are defined in AztecOO_solver_types.
Definition at line 528 of file trilinos_solver.h.
Referenced by solver_setup().
|
protected |
Use workaround for creating of epetra matrix that respects aztecoo's ordering requirements.
Definition at line 500 of file trilinos_solver.h.
Referenced by solver_setup().
|
protected |
Helper flag keeping track of whether we called the linear algebra or problem-based solve function.
Definition at line 532 of file trilinos_solver.h.
Referenced by solve(), and solver_setup().