oomph::HypreSolver Class Reference

#include <hypre_solver.h>

+ Inheritance diagram for oomph::HypreSolver:

Public Member Functions

 HypreSolver ()
 Constructor. More...
 
 ~HypreSolver ()
 Empty destructor. More...
 
 HypreSolver (const HypreSolver &)=delete
 Broken copy constructor. More...
 
void operator= (const HypreSolver &)=delete
 Broken assignment operator. More...
 
void disable_resolve ()
 
unsignedmax_iter ()
 Access function to Max_iter. More...
 
doubletolerance ()
 Access function to Tolerance. More...
 
unsignedhypre_method ()
 Access function to Hypre_method flag – specified via enumeration. More...
 
unsignedinternal_preconditioner ()
 
void amg_using_simple_smoothing ()
 
unsignedamg_simple_smoother ()
 Access function to AMG_simple_smoother flag. More...
 
void amg_using_complex_smoothing ()
 
unsignedamg_complex_smoother ()
 Access function to AMG_complex_smoother flag. More...
 
unsignedamg_print_level ()
 Access function to AMG_print_level. More...
 
unsignedamg_smoother_iterations ()
 Access function to AMG_smoother_iterations. More...
 
unsignedamg_coarsening ()
 Access function to AMG_coarsening flag. More...
 
unsignedamg_max_levels ()
 Access function to AMG_max_levels. More...
 
doubleamg_damping ()
 Access function to AMG_damping parameter. More...
 
doubleamg_strength ()
 Access function to AMG_strength. More...
 
doubleamg_max_row_sum ()
 Access function to AMG_max_row_sum. More...
 
doubleamg_truncation ()
 Access function to AMG_truncation. More...
 
intparasails_symmetry ()
 Access function to ParaSails symmetry flag. More...
 
intparasails_nlevel ()
 Access function to ParaSails nlevel parameter. More...
 
doubleparasails_thresh ()
 Access function to ParaSails thresh parameter. More...
 
doubleparasails_filter ()
 Access function to ParaSails filter parameter. More...
 
doubleeuclid_droptol ()
 Access function to Euclid drop tolerance parameter. More...
 
inteuclid_level ()
 
void enable_euclid_rowScale ()
 Enable euclid rowScaling. More...
 
void disable_euclid_rowScale ()
 Disable euclid row scaling. More...
 
void enable_euclid_using_BJ ()
 
void disable_euclid_using_BJ ()
 
void euclid_using_ILUK ()
 
void euclid_using_ILUT ()
 
unsignedeuclid_print_level ()
 
unsignedkrylov_print_level ()
 Access function to Krylov_print_level. More...
 
void enable_delete_matrix ()
 
void disable_delete_matrix ()
 
void solve (Problem *const &problem_pt, DoubleVector &solution)
 
void solve (DoubleMatrixBase *const &matrix_pt, const DoubleVector &rhs, DoubleVector &solution)
 
void resolve (const DoubleVector &rhs, DoubleVector &solution)
 
void clean_up_memory ()
 Function deletes all solver data. More...
 
- 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 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_transpose (const DoubleVector &rhs, DoubleVector &result)
 
virtual double jacobian_setup_time () const
 
virtual double linear_solver_solution_time () const
 
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)
 
- Public Member Functions inherited from oomph::HypreInterface
 HypreInterface ()
 Constructor. More...
 
 ~HypreInterface ()
 Destructor. More...
 
 HypreInterface (const HypreInterface &)=delete
 Broken copy constructor. More...
 
void operator= (const HypreInterface &)=delete
 Broken assignment operator. More...
 
void enable_hypre_error_messages ()
 Turn on the hypre error messages. More...
 
void disable_hypre_error_messages ()
 Turn off hypre error messages. More...
 
unsigned existing_solver ()
 Function to return value of which solver (if any) is currently stored. More...
 
unsigned existing_preconditioner ()
 Function return value of which preconditioner (if any) is stored. More...
 

Private Attributes

bool Delete_matrix
 

Additional Inherited Members

- Public Types inherited from oomph::HypreInterface
enum  Hypre_method_types {
  CG , GMRES , BiCGStab , BoomerAMG ,
  Euclid , ParaSails , None
}
 
- Public Attributes inherited from oomph::HypreInterface
bool AMGEuclidSmoother_use_block_jacobi
 
bool AMGEuclidSmoother_use_row_scaling
 
bool AMGEuclidSmoother_use_ilut
 
unsigned AMGEuclidSmoother_level
 
double AMGEuclidSmoother_drop_tol
 
unsigned AMGEuclidSmoother_print_level
 
- Protected Member Functions inherited from oomph::DistributableLinearAlgebraObject
void clear_distribution ()
 
- Protected Member Functions inherited from oomph::HypreInterface
void hypre_clean_up_memory ()
 Function deletes all solver data. More...
 
void hypre_matrix_setup (CRDoubleMatrix *matrix_pt)
 
void hypre_solver_setup ()
 
void hypre_solve (const DoubleVector &rhs, DoubleVector &solution)
 
- 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
 
- Protected Attributes inherited from oomph::HypreInterface
bool Output_info
 Flag is true to output info and results of timings. More...
 
unsigned Max_iter
 Maximum number of iterations used in solver. More...
 
double Tolerance
 Tolerance used to terminate solver. More...
 
unsigned Hypre_method
 Hypre method flag. Valid values are specified in enumeration. More...
 
unsigned Internal_preconditioner
 
unsigned AMG_print_level
 
unsigned AMG_max_levels
 Maximum number of levels used in AMG. More...
 
double AMG_max_row_sum
 Parameter to identify diagonally dominant parts of the matrix in AMG. More...
 
bool AMG_using_simple_smoothing
 
unsigned AMG_simple_smoother
 
unsigned AMG_complex_smoother
 
unsigned AMG_smoother_iterations
 The number of smoother iterations to apply. More...
 
double AMG_damping
 Damping factor for BoomerAMG smoothed Jacobi or hybrid SOR. More...
 
double AMG_strength
 Connection strength threshold parameter for BoomerAMG. More...
 
double AMG_truncation
 Interpolation truncation factor for BoomerAMG. More...
 
unsigned AMG_coarsening
 
int ParaSails_symmetry
 
int ParaSails_nlevel
 ParaSails nlevel parameter. More...
 
double ParaSails_thresh
 ParaSails thresh parameter. More...
 
double ParaSails_filter
 ParaSails filter parameter. More...
 
double Euclid_droptol
 Euclid drop tolerance for ILU(k) and ILUT factorization. More...
 
bool Euclid_rowScale
 Flag to switch on Euclid row scaling. More...
 
bool Euclid_using_ILUT
 Flag to determine if ILUT (if true) or ILU(k) is used in Euclid. More...
 
bool Euclid_using_BJ
 Flag to determine if Block Jacobi is used instead of PILU. More...
 
int Euclid_level
 Euclid level parameter for ILU(k) factorization. More...
 
unsigned Euclid_print_level
 
unsigned Krylov_print_level
 
bool Hypre_error_messages
 
bool Delete_input_data
 

Detailed Description

///////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// An LinearSolver class using the suite of Hypre solvers to allow

BoomerAMG (AMG), CG, GMRES or BiCGStab

to be used for LinearSolver::solve(...) or LinearSolver::resolve(...).

The Krylov subspace solvers (CG, GMRES and BiCGStab) may be preconditioned using:

BoomerAMG, Euclid or ParaSails

By default GMRES without preconditioning is used.

Constructor & Destructor Documentation

◆ HypreSolver() [1/2]

oomph::HypreSolver::HypreSolver ( )
inline

Constructor.

518  {
519  // Hypre copies matrix data from oomph-lib's CRDoubleMatrix
520  // and Distributed CRDoubleMatrix into its own data structures,
521  // doubling the memory requirements for the matrix.
522  // As far as the Hypre solvers are concerned the oomph-lib matrix
523  // is no longer required and could be deleted to save memory.
524  // However, this will not be the expected behaviour and therefore
525  // needs to be requested explicitly by the user by changing this
526  // flag from false (its default) to true.
527  Delete_matrix = false;
528 
529  // Do we want to output results of timings?
530  Doc_time = true;
531  }
bool Delete_matrix
Definition: hypre_solver.h:806
bool Doc_time
Boolean flag that indicates whether the time taken.
Definition: linear_solver.h:77

References Delete_matrix, and oomph::LinearSolver::Doc_time.

◆ ~HypreSolver()

oomph::HypreSolver::~HypreSolver ( )
inline

Empty destructor.

534 {}

◆ HypreSolver() [2/2]

oomph::HypreSolver::HypreSolver ( const HypreSolver )
delete

Broken copy constructor.

Member Function Documentation

◆ amg_coarsening()

unsigned& oomph::HypreSolver::amg_coarsening ( )
inline

Access function to AMG_coarsening flag.

615  {
616  return AMG_coarsening;
617  }
unsigned AMG_coarsening
Definition: hypre_solver.h:386

References oomph::HypreInterface::AMG_coarsening.

◆ amg_complex_smoother()

unsigned& oomph::HypreSolver::amg_complex_smoother ( )
inline

Access function to AMG_complex_smoother flag.

597  {
598  return AMG_complex_smoother;
599  }
unsigned AMG_complex_smoother
Definition: hypre_solver.h:360

References oomph::HypreInterface::AMG_complex_smoother.

◆ amg_damping()

double& oomph::HypreSolver::amg_damping ( )
inline

Access function to AMG_damping parameter.

627  {
628  return AMG_damping;
629  }
double AMG_damping
Damping factor for BoomerAMG smoothed Jacobi or hybrid SOR.
Definition: hypre_solver.h:366

References oomph::HypreInterface::AMG_damping.

◆ amg_max_levels()

unsigned& oomph::HypreSolver::amg_max_levels ( )
inline

Access function to AMG_max_levels.

621  {
622  return AMG_max_levels;
623  }
unsigned AMG_max_levels
Maximum number of levels used in AMG.
Definition: hypre_solver.h:330

References oomph::HypreInterface::AMG_max_levels.

◆ amg_max_row_sum()

double& oomph::HypreSolver::amg_max_row_sum ( )
inline

Access function to AMG_max_row_sum.

639  {
640  return AMG_max_row_sum;
641  }
double AMG_max_row_sum
Parameter to identify diagonally dominant parts of the matrix in AMG.
Definition: hypre_solver.h:333

References oomph::HypreInterface::AMG_max_row_sum.

◆ amg_print_level()

unsigned& oomph::HypreSolver::amg_print_level ( )
inline

Access function to AMG_print_level.

603  {
604  return AMG_print_level;
605  }
unsigned AMG_print_level
Definition: hypre_solver.h:327

References oomph::HypreInterface::AMG_print_level.

Referenced by main(), and TetmeshPoissonProblem< ELEMENT >::TetmeshPoissonProblem().

◆ amg_simple_smoother()

unsigned& oomph::HypreSolver::amg_simple_smoother ( )
inline

Access function to AMG_simple_smoother flag.

584  {
585  return AMG_simple_smoother;
586  }
unsigned AMG_simple_smoother
Definition: hypre_solver.h:351

References oomph::HypreInterface::AMG_simple_smoother.

Referenced by main(), and TetmeshPoissonProblem< ELEMENT >::TetmeshPoissonProblem().

◆ amg_smoother_iterations()

unsigned& oomph::HypreSolver::amg_smoother_iterations ( )
inline

Access function to AMG_smoother_iterations.

609  {
611  }
unsigned AMG_smoother_iterations
The number of smoother iterations to apply.
Definition: hypre_solver.h:363

References oomph::HypreInterface::AMG_smoother_iterations.

◆ amg_strength()

double& oomph::HypreSolver::amg_strength ( )
inline

Access function to AMG_strength.

633  {
634  return AMG_strength;
635  }
double AMG_strength
Connection strength threshold parameter for BoomerAMG.
Definition: hypre_solver.h:369

References oomph::HypreInterface::AMG_strength.

◆ amg_truncation()

double& oomph::HypreSolver::amg_truncation ( )
inline

Access function to AMG_truncation.

645  {
646  return AMG_truncation;
647  }
double AMG_truncation
Interpolation truncation factor for BoomerAMG.
Definition: hypre_solver.h:372

References oomph::HypreInterface::AMG_truncation.

◆ amg_using_complex_smoothing()

void oomph::HypreSolver::amg_using_complex_smoothing ( )
inline

Function to select use of 'complex' AMG smoothers as controlled by AMG_complex_smoother flag

591  {
593  }
bool AMG_using_simple_smoothing
Definition: hypre_solver.h:338

References oomph::HypreInterface::AMG_using_simple_smoothing.

◆ amg_using_simple_smoothing()

void oomph::HypreSolver::amg_using_simple_smoothing ( )
inline

Function to select use of 'simple' AMG smoothers as controlled by AMG_simple_smoother flag

578  {
580  }

References oomph::HypreInterface::AMG_using_simple_smoothing.

◆ clean_up_memory()

void oomph::HypreSolver::clean_up_memory ( )
virtual

Function deletes all solver data.

clean_up_memory() deletes any existing solver data

Reimplemented from oomph::LinearSolver.

1587  {
1589  }
void hypre_clean_up_memory()
Function deletes all solver data.
Definition: hypre_solver.cc:1301

References oomph::HypreInterface::hypre_clean_up_memory().

Referenced by disable_resolve(), and solve().

◆ disable_delete_matrix()

void oomph::HypreSolver::disable_delete_matrix ( )
inline

Hypre copies matrix data from oomph-lib's CRDoubleMatrix or DistributedCRDoubleMatrix into its own data structures, doubling the memory requirements for the matrix. Calling this function ensures that the matrix is not deleted.

761  {
762  Delete_matrix = false;
763  }

References Delete_matrix.

◆ disable_euclid_rowScale()

void oomph::HypreSolver::disable_euclid_rowScale ( )
inline

Disable euclid row scaling.

694  {
695  Euclid_rowScale = false;
696  }
bool Euclid_rowScale
Flag to switch on Euclid row scaling.
Definition: hypre_solver.h:409

References oomph::HypreInterface::Euclid_rowScale.

◆ disable_euclid_using_BJ()

void oomph::HypreSolver::disable_euclid_using_BJ ( )
inline

Disable use of Block Jacobi, so PILU will be used

708  {
709  Euclid_using_BJ = false;
710  }
bool Euclid_using_BJ
Flag to determine if Block Jacobi is used instead of PILU.
Definition: hypre_solver.h:415

References oomph::HypreInterface::Euclid_using_BJ.

◆ disable_resolve()

void oomph::HypreSolver::disable_resolve ( )
inlinevirtual

Disable resolve function (overloads the LinearSolver disable_resolve function).

Reimplemented from oomph::LinearSolver.

545  {
546  Enable_resolve = false;
547  clean_up_memory();
548  }
void clean_up_memory()
Function deletes all solver data.
Definition: hypre_solver.cc:1586
bool Enable_resolve
Definition: linear_solver.h:73

References clean_up_memory(), and oomph::LinearSolver::Enable_resolve.

◆ enable_delete_matrix()

void oomph::HypreSolver::enable_delete_matrix ( )
inline

Hypre copies matrix data from oomph-lib's CRDoubleMatrix or DistributedCRDoubleMatrix into its own data structures, doubling the memory requirements for the matrix. As far as the Hypre solvers are concerned the oomph-lib matrix is no longer required and could be deleted to save memory. However, this will not be the expected behaviour and therefore needs to be requested explicitly by the user by calling this function which changes the flag from false (its default) to true.

752  {
753  Delete_matrix = true;
754  }

References Delete_matrix.

◆ enable_euclid_rowScale()

void oomph::HypreSolver::enable_euclid_rowScale ( )
inline

Enable euclid rowScaling.

688  {
689  Euclid_rowScale = true;
690  }

References oomph::HypreInterface::Euclid_rowScale.

◆ enable_euclid_using_BJ()

void oomph::HypreSolver::enable_euclid_using_BJ ( )
inline

Enable use of Block Jacobi as opposed to PILU

701  {
702  Euclid_using_BJ = true;
703  }

References oomph::HypreInterface::Euclid_using_BJ.

◆ euclid_droptol()

double& oomph::HypreSolver::euclid_droptol ( )
inline

Access function to Euclid drop tolerance parameter.

675  {
676  return Euclid_droptol;
677  }
double Euclid_droptol
Euclid drop tolerance for ILU(k) and ILUT factorization.
Definition: hypre_solver.h:406

References oomph::HypreInterface::Euclid_droptol.

◆ euclid_level()

int& oomph::HypreSolver::euclid_level ( )
inline

Access function to Euclid level parameter for ILU(k) factorization

682  {
683  return Euclid_level;
684  }
int Euclid_level
Euclid level parameter for ILU(k) factorization.
Definition: hypre_solver.h:418

References oomph::HypreInterface::Euclid_level.

◆ euclid_print_level()

unsigned& oomph::HypreSolver::euclid_print_level ( )
inline

Function to set the level of printing from Euclid when the Euclid destructor is called 0: no printing (default) 1: prints summary of runtime settings and timings 2: as 1 plus prints memory usage

732  {
733  return Euclid_print_level;
734  }
unsigned Euclid_print_level
Definition: hypre_solver.h:425

References oomph::HypreInterface::Euclid_print_level.

◆ euclid_using_ILUK()

void oomph::HypreSolver::euclid_using_ILUK ( )
inline

Function to switch on ILU(k) factorization for Euclid (default is ILU(k) factorization)

715  {
716  Euclid_using_ILUT = false;
717  }
bool Euclid_using_ILUT
Flag to determine if ILUT (if true) or ILU(k) is used in Euclid.
Definition: hypre_solver.h:412

References oomph::HypreInterface::Euclid_using_ILUT.

◆ euclid_using_ILUT()

void oomph::HypreSolver::euclid_using_ILUT ( )
inline

Function to switch on ILUT factorization for Euclid (default is ILU(k) factorization)

722  {
723  Euclid_using_ILUT = true;
724  }

References oomph::HypreInterface::Euclid_using_ILUT.

◆ hypre_method()

unsigned& oomph::HypreSolver::hypre_method ( )
inline

Access function to Hypre_method flag – specified via enumeration.

564  {
565  return Hypre_method;
566  }
unsigned Hypre_method
Hypre method flag. Valid values are specified in enumeration.
Definition: hypre_solver.h:314

References oomph::HypreInterface::Hypre_method.

Referenced by main(), and TetmeshPoissonProblem< ELEMENT >::TetmeshPoissonProblem().

◆ internal_preconditioner()

unsigned& oomph::HypreSolver::internal_preconditioner ( )
inline

Access function to Internal_preconditioner flag – specified via enumeration.

571  {
573  }
unsigned Internal_preconditioner
Definition: hypre_solver.h:320

References oomph::HypreInterface::Internal_preconditioner.

Referenced by main().

◆ krylov_print_level()

unsigned& oomph::HypreSolver::krylov_print_level ( )
inline

Access function to Krylov_print_level.

738  {
739  return Krylov_print_level;
740  }
unsigned Krylov_print_level
Definition: hypre_solver.h:429

References oomph::HypreInterface::Krylov_print_level.

Referenced by main(), and TetmeshPoissonProblem< ELEMENT >::TetmeshPoissonProblem().

◆ max_iter()

unsigned& oomph::HypreSolver::max_iter ( )
inline

Access function to Max_iter.

552  {
553  return Max_iter;
554  }
unsigned Max_iter
Maximum number of iterations used in solver.
Definition: hypre_solver.h:308

References oomph::HypreInterface::Max_iter.

Referenced by main(), and TetmeshPoissonProblem< ELEMENT >::TetmeshPoissonProblem().

◆ operator=()

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

Broken assignment operator.

◆ parasails_filter()

double& oomph::HypreSolver::parasails_filter ( )
inline

Access function to ParaSails filter parameter.

669  {
670  return ParaSails_filter;
671  }
double ParaSails_filter
ParaSails filter parameter.
Definition: hypre_solver.h:403

References oomph::HypreInterface::ParaSails_filter.

◆ parasails_nlevel()

int& oomph::HypreSolver::parasails_nlevel ( )
inline

Access function to ParaSails nlevel parameter.

657  {
658  return ParaSails_nlevel;
659  }
int ParaSails_nlevel
ParaSails nlevel parameter.
Definition: hypre_solver.h:397

References oomph::HypreInterface::ParaSails_nlevel.

◆ parasails_symmetry()

int& oomph::HypreSolver::parasails_symmetry ( )
inline

Access function to ParaSails symmetry flag.

651  {
652  return ParaSails_symmetry;
653  }
int ParaSails_symmetry
Definition: hypre_solver.h:394

References oomph::HypreInterface::ParaSails_symmetry.

◆ parasails_thresh()

double& oomph::HypreSolver::parasails_thresh ( )
inline

Access function to ParaSails thresh parameter.

663  {
664  return ParaSails_thresh;
665  }
double ParaSails_thresh
ParaSails thresh parameter.
Definition: hypre_solver.h:400

References oomph::HypreInterface::ParaSails_thresh.

◆ resolve()

void oomph::HypreSolver::resolve ( const DoubleVector rhs,
DoubleVector solution 
)
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.

Resolve performs a linear solve using current solver data (if such data exists).

Reimplemented from oomph::LinearSolver.

1533  {
1534 #ifdef PARANOID
1535  // check solver data exists
1536  if (existing_solver() == None)
1537  {
1538  std::ostringstream error_message;
1539  error_message << "resolve(...) requires that solver data has been "
1540  << "set up by a previous call to solve(...) after "
1541  << "a call to enable_resolve()" << std::endl;
1542  throw OomphLibError(
1543  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
1544  }
1545  // check that rhs has the same distribution as the matrix (now stored
1546  // in Distribution_pt)
1547  if (*this->distribution_pt() != *rhs.distribution_pt())
1548  {
1549  std::ostringstream error_message;
1550  error_message << "The distribution of the rhs vector and the matrix "
1551  << " must be the same" << std::endl;
1552  throw OomphLibError(
1553  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
1554  }
1555  // if the solution is setup make sure it has the same distribution as
1556  // the matrix as well
1557  if (solution.built())
1558  {
1559  if (*this->distribution_pt() != *solution.distribution_pt())
1560  {
1561  std::ostringstream error_message;
1562  error_message << "The distribution of the solution vector is setup "
1563  << "there it must be the same as the matrix."
1564  << std::endl;
1565  throw OomphLibError(error_message.str(),
1568  }
1569  }
1570 #endif
1571 
1572  // Set Output_info flag for HypreInterface
1574 
1575  // solve
1576  hypre_solve(rhs, solution);
1577 
1578  // Note: never delete solver data as the preconditioner is typically
1579  // called repeatedly.
1580  }
LinearAlgebraDistribution * distribution_pt() const
access to the LinearAlgebraDistribution
Definition: linear_algebra_distribution.h:457
bool Output_info
Flag is true to output info and results of timings.
Definition: hypre_solver.h:305
void hypre_solve(const DoubleVector &rhs, DoubleVector &solution)
Definition: hypre_solver.cc:1086
@ None
Definition: hypre_solver.h:263
unsigned existing_solver()
Function to return value of which solver (if any) is currently stored.
Definition: hypre_solver.h:267
void solution(const Vector< double > &x, Vector< double > &u)
Definition: two_d_biharmonic.cc:113
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86

References oomph::DistributableLinearAlgebraObject::distribution_pt(), oomph::LinearSolver::Doc_time, oomph::HypreInterface::existing_solver(), oomph::HypreInterface::hypre_solve(), oomph::HypreInterface::None, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, oomph::HypreInterface::Output_info, and BiharmonicTestFunctions1::solution().

◆ solve() [1/2]

void oomph::HypreSolver::solve ( DoubleMatrixBase *const &  matrix_pt,
const DoubleVector rhs,
DoubleVector solution 
)
virtual

Function to solve the linear system defined by matrix_pt and rhs. This function will delete any existing internal data and generate a new Hypre solver. Note: The matrix has to be of type CRDoubleMatrix or Distributed CRDoubleMatrix. Note: Hypre copies matrix data from oomph-lib's CRDoubleMatrix or DistributedCRDoubleMatrix into its own data structures, doubling the memory requirements for the matrix. As far as the Hypre solvers are concerned, the oomph-lib matrix is no longer required and could be deleted to save memory. However, this will not be the expected behaviour and therefore needs to be requested explicitly by the user by calling the enable_delete_matrix() function.

Uses HypreInterface::hypre_solve(...) to solve the linear system for a CRDoubleMatrix or a DistributedCRDoubleMatrix. In the latter case, the rhs needs to be distributed too, i.e. the length of the rhs vector must be equal to the number of rows stored locally. Note: the returned solution vector is never distributed, i.e. all processors hold all values

Reimplemented from oomph::LinearSolver.

1439  {
1440 #ifdef PARANOID
1441  // check the matrix is square
1442  if (matrix_pt->nrow() != matrix_pt->ncol())
1443  {
1444  std::ostringstream error_message;
1445  error_message << "HypreSolver require a square matrix. "
1446  << "Matrix is " << matrix_pt->nrow() << " by "
1447  << matrix_pt->ncol() << std::endl;
1448  throw OomphLibError(
1449  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
1450  }
1451 #endif
1452 
1453  // Set Output_time flag for HypreInterface
1455 
1456  // Clean up existing solver data
1457  clean_up_memory();
1458 
1459  // Set flag to decide if oomphlib matrix can be deleted
1460  // (Recall that Delete_matrix defaults to false).
1462 
1463  // Try cast to a CRDoubleMatrix
1464  CRDoubleMatrix* cr_matrix_pt = dynamic_cast<CRDoubleMatrix*>(matrix_pt);
1465 
1466  // If cast successful set things up for a serial solve
1467  if (cr_matrix_pt)
1468  {
1469  // rebuild the distribution
1470  this->build_distribution(cr_matrix_pt->distribution_pt());
1471 
1472 #ifdef PARANOID
1473  // check that rhs has the same distribution as the matrix (now stored
1474  // in Distribution_pt)
1475  if (*this->distribution_pt() != *rhs.distribution_pt())
1476  {
1477  std::ostringstream error_message;
1478  error_message << "The distribution of the rhs vector and the matrix "
1479  << " must be the same" << std::endl;
1480  throw OomphLibError(error_message.str(),
1483  }
1484  // if the solution is setup make sure it has the same distribution as
1485  // the matrix as well
1486  if (solution.built())
1487  {
1488  if (*this->distribution_pt() != *solution.distribution_pt())
1489  {
1490  std::ostringstream error_message;
1491  error_message << "The distribution of the solution vector is setup "
1492  << "there it must be the same as the matrix."
1493  << std::endl;
1494  throw OomphLibError(error_message.str(),
1497  }
1498  }
1499 #endif
1500 
1501  hypre_matrix_setup(cr_matrix_pt);
1502  }
1503  else
1504  {
1505 #ifdef PARANOID
1506  std::ostringstream error_message;
1507  error_message << "HypreSolver only work with "
1508  << "CRDoubleMatrix matrices" << std::endl;
1509  throw OomphLibError(
1510  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
1511 #endif
1512  }
1513 
1514  // call hypre_setup to generate Hypre matrix and linear solver data
1516 
1517  // perform hypre_solve
1518  hypre_solve(rhs, solution);
1519 
1520  // delete solver data if required
1521  if (!Enable_resolve)
1522  {
1523  clean_up_memory();
1524  }
1525  }
void build_distribution(const LinearAlgebraDistribution *const dist_pt)
Definition: linear_algebra_distribution.h:507
bool Delete_input_data
Definition: hypre_solver.h:445
void hypre_matrix_setup(CRDoubleMatrix *matrix_pt)
Definition: hypre_solver.cc:513
void hypre_solver_setup()
Definition: hypre_solver.cc:558

References oomph::DistributableLinearAlgebraObject::build_distribution(), clean_up_memory(), oomph::HypreInterface::Delete_input_data, Delete_matrix, oomph::DistributableLinearAlgebraObject::distribution_pt(), oomph::LinearSolver::Doc_time, oomph::LinearSolver::Enable_resolve, oomph::HypreInterface::hypre_matrix_setup(), oomph::HypreInterface::hypre_solve(), oomph::HypreInterface::hypre_solver_setup(), oomph::DoubleMatrixBase::ncol(), oomph::DoubleMatrixBase::nrow(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, oomph::HypreInterface::Output_info, and BiharmonicTestFunctions1::solution().

◆ solve() [2/2]

void oomph::HypreSolver::solve ( Problem *const &  problem_pt,
DoubleVector solution 
)
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 Hypre solver.

//////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// Problem-based solve function to generate the Jacobian matrix and residual vector and use HypreInterface::hypre_solver_setup(...) and HypreInterface::hypre_solve(...) to solve the linear system. This function will delete any existing data. Note: the returned solution vector is NOT distributed, i.e. all processors hold all values because this is what the Newton solver requires.

Implements oomph::LinearSolver.

1384  {
1385  double t_start = TimingHelpers::timer();
1386 
1387  // Set Output_time flag for HypreInterface
1389 
1390  // Delete any existing solver data
1391  clean_up_memory();
1392 
1393  // Set flag to allow deletion of the oomphlib Jacobian matrix
1394  // (we're in control)
1395  Delete_input_data = true;
1396 
1397  // Get oomph-lib Jacobian matrix and residual vector
1398  DoubleVector residual;
1399  CRDoubleMatrix* matrix = new CRDoubleMatrix;
1400  problem_pt->get_jacobian(residual, *matrix);
1401 
1402  // Output times
1403  if (Doc_time)
1404  {
1405  oomph_info << "Time to generate Jacobian and residual [s] : ";
1406  double t_end = TimingHelpers::timer();
1407  oomph_info << t_end - t_start << std::endl;
1408  }
1409 
1410  // generate hypre matrix
1412 
1413  // call hypre_solver_setup to generate linear solver data
1415 
1416  // perform hypre_solve
1417  hypre_solve(residual, solution);
1418 
1419  // delete solver data if required
1420  if (!Enable_resolve)
1421  {
1422  clean_up_memory();
1423  }
1424  }
std::vector< double > DoubleVector
loads clump configuration
Definition: ClumpInput.h:26
Eigen::Map< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor >, 0, Eigen::OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Definition: common.h:85
double timer()
returns the time in seconds after some point in past
Definition: oomph_utilities.cc:1295
OomphInfo oomph_info
Definition: oomph_definitions.cc:319

References clean_up_memory(), oomph::HypreInterface::Delete_input_data, oomph::LinearSolver::Doc_time, oomph::LinearSolver::Enable_resolve, oomph::Problem::get_jacobian(), oomph::HypreInterface::hypre_matrix_setup(), oomph::HypreInterface::hypre_solve(), oomph::HypreInterface::hypre_solver_setup(), matrix(), oomph::oomph_info, oomph::HypreInterface::Output_info, BiharmonicTestFunctions1::solution(), and oomph::TimingHelpers::timer().

◆ tolerance()

double& oomph::HypreSolver::tolerance ( )
inline

Access function to Tolerance.

558  {
559  return Tolerance;
560  }
double Tolerance
Tolerance used to terminate solver.
Definition: hypre_solver.h:311

References oomph::HypreInterface::Tolerance.

Referenced by main(), and TetmeshPoissonProblem< ELEMENT >::TetmeshPoissonProblem().

Member Data Documentation

◆ Delete_matrix

bool oomph::HypreSolver::Delete_matrix
private

Hypre copies matrix data from oomph-lib's CRDoubleMatrix or DistributedCRDoubleMatrix into its own data structures, doubling the memory requirements for the matrix. As far as the Hypre solvers are concerned the oomph-lib matrix is no longer required and could be deleted to save memory. However, this will not be the expected behaviour and therefore needs to be requested explicitly by the user by changing this flag from false (its default) to true.

Referenced by disable_delete_matrix(), enable_delete_matrix(), HypreSolver(), and solve().


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