oomph::IterativeLinearSolver Class Referenceabstract

#include <iterative_linear_solver.h>

+ Inheritance diagram for oomph::IterativeLinearSolver:

Public Member Functions

 IterativeLinearSolver ()
 
 IterativeLinearSolver (const IterativeLinearSolver &)=delete
 Broken copy constructor. More...
 
void operator= (const IterativeLinearSolver &)=delete
 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...
 
doubletolerance ()
 Access to convergence tolerance. More...
 
unsignedmax_iter ()
 Access to max. number of iterations. More...
 
virtual unsigned iterations () const =0
 Number of iterations taken. 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="")
 
void close_convergence_history_file_stream ()
 Close convergence history output stream. More...
 
double jacobian_setup_time () const
 
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 ()
 
- Public Member Functions inherited from oomph::LinearSolver
 LinearSolver ()
 Empty constructor, initialise the member data. More...
 
 LinearSolver (const LinearSolver &dummy)=delete
 Broken copy constructor. More...
 
void operator= (const LinearSolver &)=delete
 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 ()
 
virtual void disable_resolve ()
 
virtual void solve (Problem *const &problem_pt, DoubleVector &result)=0
 
virtual void solve (DoubleMatrixBase *const &matrix_pt, const DoubleVector &rhs, DoubleVector &result)
 
virtual void solve (DoubleMatrixBase *const &matrix_pt, const Vector< double > &rhs, Vector< double > &result)
 
virtual void solve_transpose (Problem *const &problem_pt, DoubleVector &result)
 
virtual void solve_transpose (DoubleMatrixBase *const &matrix_pt, const DoubleVector &rhs, DoubleVector &result)
 
virtual void solve_transpose (DoubleMatrixBase *const &matrix_pt, const Vector< double > &rhs, Vector< double > &result)
 
virtual void resolve (const DoubleVector &rhs, DoubleVector &result)
 
virtual void resolve_transpose (const DoubleVector &rhs, DoubleVector &result)
 
virtual void clean_up_memory ()
 
virtual void enable_computation_of_gradient ()
 
void disable_computation_of_gradient ()
 
void reset_gradient ()
 
void get_gradient (DoubleVector &gradient)
 function to access the gradient, provided it has been computed More...
 
- Public Member Functions inherited from oomph::DistributableLinearAlgebraObject
 DistributableLinearAlgebraObject ()
 Default constructor - create a distribution. More...
 
 DistributableLinearAlgebraObject (const DistributableLinearAlgebraObject &matrix)=delete
 Broken copy constructor. More...
 
void operator= (const DistributableLinearAlgebraObject &)=delete
 Broken assignment operator. More...
 
virtual ~DistributableLinearAlgebraObject ()
 Destructor. More...
 
LinearAlgebraDistributiondistribution_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)
 
void build_distribution (const LinearAlgebraDistribution &dist)
 

Protected Attributes

bool Doc_convergence_history
 
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...
 
PreconditionerPreconditioner_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
 
bool Throw_error_after_max_iter
 
bool Use_iterative_solver_as_preconditioner
 Use the iterative solver as preconditioner. More...
 
bool First_time_solve_when_used_as_preconditioner
 
- Protected Attributes inherited from oomph::LinearSolver
bool Enable_resolve
 
bool Doc_time
 Boolean flag that indicates whether the time taken. More...
 
bool Compute_gradient
 
bool Gradient_has_been_computed
 flag that indicates whether the gradient was computed or not More...
 
DoubleVector Gradient_for_glob_conv_newton_solve
 

Static Protected Attributes

static IdentityPreconditioner Default_preconditioner
 

Additional Inherited Members

- Protected Member Functions inherited from oomph::DistributableLinearAlgebraObject
void clear_distribution ()
 

Detailed Description

Base class for all linear iterative solvers. This merely defines standard interfaces for linear iterative solvers, so that different solvers can be used in a clean and transparent manner.

Constructor & Destructor Documentation

◆ IterativeLinearSolver() [1/2]

oomph::IterativeLinearSolver::IterativeLinearSolver ( )
inline

Constructor: Set (default) trivial preconditioner and set defaults for tolerance and max. number of iterations

59  {
60  // Set pointer to default preconditioner
62 
63  // Set default convergence tolerance
64  Tolerance = 1.0e-8;
65 
66  // Set maximum number of iterations
67  Max_iter = 100;
68 
69  // set default for document convergence history
71 
72  // set default
74 
76 
77  // By default the iterative solver is not used as preconditioner
79 
80  // Indicates whether this is the first time we call the solve
81  // method
83  }
bool Use_iterative_solver_as_preconditioner
Use the iterative solver as preconditioner.
Definition: iterative_linear_solver.h:265
bool First_time_solve_when_used_as_preconditioner
Definition: iterative_linear_solver.h:270
double Tolerance
Convergence tolerance.
Definition: iterative_linear_solver.h:239
Preconditioner * Preconditioner_pt
Pointer to the preconditioner.
Definition: iterative_linear_solver.h:245
bool Throw_error_after_max_iter
Definition: iterative_linear_solver.h:262
double Preconditioner_setup_time
Preconditioner setup time.
Definition: iterative_linear_solver.h:254
static IdentityPreconditioner Default_preconditioner
Definition: iterative_linear_solver.h:236
unsigned Max_iter
Maximum number of iterations.
Definition: iterative_linear_solver.h:242
bool Doc_convergence_history
Definition: iterative_linear_solver.h:228
bool Setup_preconditioner_before_solve
Definition: iterative_linear_solver.h:258

References Default_preconditioner, Doc_convergence_history, First_time_solve_when_used_as_preconditioner, Max_iter, Preconditioner_pt, Setup_preconditioner_before_solve, Throw_error_after_max_iter, Tolerance, and Use_iterative_solver_as_preconditioner.

◆ IterativeLinearSolver() [2/2]

oomph::IterativeLinearSolver::IterativeLinearSolver ( const IterativeLinearSolver )
delete

Broken copy constructor.

◆ ~IterativeLinearSolver()

virtual oomph::IterativeLinearSolver::~IterativeLinearSolver ( )
inlinevirtual

Destructor (empty)

92 {}

Member Function Documentation

◆ close_convergence_history_file_stream()

void oomph::IterativeLinearSolver::close_convergence_history_file_stream ( )
inline

Close convergence history output stream.

162  {
163  if (Output_file_stream.is_open()) Output_file_stream.close();
164  }
std::ofstream Output_file_stream
Output file stream for convergence history.
Definition: iterative_linear_solver.h:231

References Output_file_stream.

Referenced by PreconditionedFSICollapsibleChannelProblem< ELEMENT >::actions_after_newton_solve(), and PreconditionedFSICollapsibleChannelProblem< ELEMENT >::actions_before_newton_convergence_check().

◆ disable_doc_convergence_history()

void oomph::IterativeLinearSolver::disable_doc_convergence_history ( )
inline

Disable documentation of the convergence history.

129  {
130  Doc_convergence_history = false;
131  }

References Doc_convergence_history.

◆ disable_error_after_max_iter()

void oomph::IterativeLinearSolver::disable_error_after_max_iter ( )
inline

Don't throw an error if we don't converge within max_iter (default).

205  {
207  }

References Throw_error_after_max_iter.

◆ disable_iterative_solver_as_preconditioner()

void oomph::IterativeLinearSolver::disable_iterative_solver_as_preconditioner ( )
inline

Disables the iterative solver be used as preconditioner (when calling the solve method it bypass the setup solver method – currently only used by Trilinos solver —)

221  {
223  }

References Use_iterative_solver_as_preconditioner.

◆ disable_setup_preconditioner_before_solve()

void oomph::IterativeLinearSolver::disable_setup_preconditioner_before_solve ( )
inline

Don't set up the preconditioner before the solve.

193  {
195  }

References Setup_preconditioner_before_solve.

◆ enable_doc_convergence_history()

void oomph::IterativeLinearSolver::enable_doc_convergence_history ( )
inline

Enable documentation of the convergence history.

123  {
125  }

References Doc_convergence_history.

Referenced by main().

◆ enable_error_after_max_iter()

void oomph::IterativeLinearSolver::enable_error_after_max_iter ( )
inline

Throw an error if we don't converge within max_iter.

199  {
201  }

References Throw_error_after_max_iter.

Referenced by oomph::MyProblem::build().

◆ enable_iterative_solver_as_preconditioner()

void oomph::IterativeLinearSolver::enable_iterative_solver_as_preconditioner ( )
inline

Enables the iterative solver be used as preconditioner (when calling the solve method it bypass the setup solver method – currently only used by Trilinos solver —)

213  {
215  }

References Use_iterative_solver_as_preconditioner.

◆ enable_setup_preconditioner_before_solve()

void oomph::IterativeLinearSolver::enable_setup_preconditioner_before_solve ( )
inline

Setup the preconditioner before the solve.

187  {
189  }

References Setup_preconditioner_before_solve.

◆ iterations()

◆ jacobian_setup_time()

double oomph::IterativeLinearSolver::jacobian_setup_time ( ) const
inlinevirtual

returns the time taken to assemble the jacobian matrix and residual vector

Reimplemented from oomph::LinearSolver.

169  {
170  return Jacobian_setup_time;
171  }
double Jacobian_setup_time
Jacobian setup time.
Definition: iterative_linear_solver.h:248

References Jacobian_setup_time.

◆ linear_solver_solution_time()

double oomph::IterativeLinearSolver::linear_solver_solution_time ( ) const
inlinevirtual

return the time taken to solve the linear system

Reimplemented from oomph::LinearSolver.

175  {
176  return Solution_time;
177  }
double Solution_time
linear solver solution time
Definition: iterative_linear_solver.h:251

References Solution_time.

◆ max_iter()

◆ open_convergence_history_file_stream()

void oomph::IterativeLinearSolver::open_convergence_history_file_stream ( const std::string &  file_name,
const std::string &  zone_title = "" 
)
inline

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).

140  {
141  // start docing
143 
144  // Close if it's open
145  if (Output_file_stream.is_open())
146  {
147  Output_file_stream.close();
148  }
149 
150  // Open new one
151  Output_file_stream.open(file_name.c_str());
152 
153  // Write tecplot zone header
154  Output_file_stream << "VARIABLES=\"iterations\", \"scaled residual\""
155  << std::endl;
156  Output_file_stream << "ZONE T=\"" << zone_title << "\"" << std::endl;
157  Output_file_stream << 0 << " " << 1.0 << std::endl;
158  }
string file_name
Definition: Particles2023AnalysisHung.py:321

References Doc_convergence_history, Particles2023AnalysisHung::file_name, and Output_file_stream.

Referenced by PreconditionedFSICollapsibleChannelProblem< ELEMENT >::actions_before_newton_convergence_check(), MultiPoissonProblem< ELEMENT >::MultiPoissonProblem(), PMLStructuredCubicHelmholtz< ELEMENT >::set_gmres_multigrid_solver(), PMLHelmholtzMGProblem< ELEMENT >::set_gmres_multigrid_solver(), FluxPoissonMGProblem< ELEMENT, MESH >::set_multigrid_solver(), and UnitCubePoissonMGProblem< ELEMENT, MESH >::set_multigrid_solver().

◆ operator=()

void oomph::IterativeLinearSolver::operator= ( const IterativeLinearSolver )
delete

Broken assignment operator.

◆ preconditioner_pt() [1/2]

Preconditioner*& oomph::IterativeLinearSolver::preconditioner_pt ( )
inline

◆ preconditioner_pt() [2/2]

Preconditioner* const& oomph::IterativeLinearSolver::preconditioner_pt ( ) const
inline

Access function to preconditioner (const version)

102  {
103  return Preconditioner_pt;
104  }

References Preconditioner_pt.

◆ preconditioner_setup_time()

virtual double oomph::IterativeLinearSolver::preconditioner_setup_time ( ) const
inlinevirtual

returns the the time taken to setup the preconditioner

Reimplemented in oomph::GS< CRDoubleMatrix >, and oomph::GS< MATRIX >.

181  {
183  }

References Preconditioner_setup_time.

Referenced by oomph::MyProblem::actions_after_explicit_stage(), and oomph::MyProblem::actions_after_newton_step().

◆ tolerance()

Member Data Documentation

◆ Default_preconditioner

IdentityPreconditioner oomph::IterativeLinearSolver::Default_preconditioner
staticprotected

Default preconditioner: The base class for preconditioners is a fully functional (if trivial!) preconditioner.

Default preconditioner for iterative solvers: The base class for preconditioners is a fully functional (if trivial!) preconditioner.

Referenced by IterativeLinearSolver().

◆ Doc_convergence_history

◆ First_time_solve_when_used_as_preconditioner

bool oomph::IterativeLinearSolver::First_time_solve_when_used_as_preconditioner
protected

When the iterative solver is used a preconditioner then we call the setup of solver method only once (the first time the solve method is called)

Referenced by IterativeLinearSolver(), and oomph::TrilinosAztecOOSolver::solve().

◆ Jacobian_setup_time

◆ Max_iter

◆ Output_file_stream

std::ofstream oomph::IterativeLinearSolver::Output_file_stream
protected

◆ Preconditioner_pt

Preconditioner* oomph::IterativeLinearSolver::Preconditioner_pt
protected

◆ Preconditioner_setup_time

double oomph::IterativeLinearSolver::Preconditioner_setup_time
protected

Preconditioner setup time.

Referenced by preconditioner_setup_time(), and oomph::AugmentedProblemGMRES::solve_helper().

◆ Setup_preconditioner_before_solve

bool oomph::IterativeLinearSolver::Setup_preconditioner_before_solve
protected

◆ Solution_time

◆ Throw_error_after_max_iter

bool oomph::IterativeLinearSolver::Throw_error_after_max_iter
protected

◆ Tolerance

◆ Use_iterative_solver_as_preconditioner

bool oomph::IterativeLinearSolver::Use_iterative_solver_as_preconditioner
protected

The documentation for this class was generated from the following files: