oomph::TrilinosPreconditionerBase Class Referenceabstract

Base class for Trilinos preconditioners as oomph-lib preconditioner. More...

#include <trilinos_preconditioners.h>

+ Inheritance diagram for oomph::TrilinosPreconditionerBase:

Public Member Functions

 TrilinosPreconditionerBase ()
 Constructor. More...
 
virtual ~TrilinosPreconditionerBase ()
 Destructor. More...
 
void clean_up_memory ()
 deletes the preconditioner, matrices and maps More...
 
 TrilinosPreconditionerBase (const TrilinosPreconditionerBase &)=delete
 Broken copy constructor. More...
 
void setup ()
 Broken assignment operator. More...
 
void setup (Epetra_CrsMatrix *epetra_matrix_pt)
 
void preconditioner_solve (const DoubleVector &r, DoubleVector &z)
 applies the preconditioner More...
 
Epetra_Operator *& epetra_operator_pt ()
 
Epetra_Operatorepetra_operator_pt () const
 
- Public Member Functions inherited from oomph::Preconditioner
 Preconditioner ()
 Constructor. More...
 
 Preconditioner (const Preconditioner &)=delete
 Broken copy constructor. More...
 
void operator= (const Preconditioner &)=delete
 Broken assignment operator. More...
 
virtual ~Preconditioner ()
 Destructor (empty) More...
 
virtual void preconditioner_solve_transpose (const DoubleVector &r, DoubleVector &z)
 
void setup (DoubleMatrixBase *matrix_pt)
 
void setup (const Problem *problem_pt, DoubleMatrixBase *matrix_pt)
 
void enable_silent_preconditioner_setup ()
 Set up the block preconditioner quietly! More...
 
void disable_silent_preconditioner_setup ()
 Be verbose in the block preconditioner setup. More...
 
virtual DoubleMatrixBasematrix_pt () const
 Get function for matrix pointer. More...
 
virtual void set_matrix_pt (DoubleMatrixBase *matrix_pt)
 Set the matrix pointer. More...
 
virtual const OomphCommunicatorcomm_pt () const
 Get function for comm pointer. More...
 
virtual void set_comm_pt (const OomphCommunicator *const comm_pt)
 Set the communicator pointer. More...
 
double setup_time () const
 Returns the time to setup the preconditioner. More...
 
virtual void turn_into_subsidiary_block_preconditioner (BlockPreconditioner< CRDoubleMatrix > *master_block_prec_pt, const Vector< unsigned > &doftype_in_master_preconditioner_coarse)
 
virtual void turn_into_subsidiary_block_preconditioner (BlockPreconditioner< CRDoubleMatrix > *master_block_prec_pt, const Vector< unsigned > &doftype_in_master_preconditioner_coarse, const Vector< Vector< unsigned >> &doftype_coarsen_map_coarse)
 
- 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)
 

Static Public Attributes

static double Cumulative_preconditioner_solve_time = 0.0
 

Protected Member Functions

virtual void setup_trilinos_preconditioner (Epetra_CrsMatrix *epetra_matrix_pt)=0
 
- Protected Member Functions inherited from oomph::DistributableLinearAlgebraObject
void clear_distribution ()
 

Protected Attributes

Epetra_OperatorEpetra_preconditioner_pt
 
Epetra_CrsMatrix * Epetra_matrix_pt
 
- Protected Attributes inherited from oomph::Preconditioner
bool Silent_preconditioner_setup
 Boolean to indicate whether or not the build should be done silently. More...
 
std::ostream * Stream_pt
 Pointer to the output stream – defaults to std::cout. More...
 

Detailed Description

Base class for Trilinos preconditioners as oomph-lib preconditioner.

Constructor & Destructor Documentation

◆ TrilinosPreconditionerBase() [1/2]

oomph::TrilinosPreconditionerBase::TrilinosPreconditionerBase ( )
inline

Constructor.

60  {
61  // Initialise pointers
63  Epetra_matrix_pt = 0;
64  }
Epetra_Operator * Epetra_preconditioner_pt
Definition: trilinos_preconditioners.h:138
Epetra_CrsMatrix * Epetra_matrix_pt
Definition: trilinos_preconditioners.h:142

References Epetra_matrix_pt, and Epetra_preconditioner_pt.

◆ ~TrilinosPreconditionerBase()

virtual oomph::TrilinosPreconditionerBase::~TrilinosPreconditionerBase ( )
inlinevirtual

Destructor.

68  {
70  }
void clean_up_memory()
deletes the preconditioner, matrices and maps
Definition: trilinos_preconditioners.h:78

References clean_up_memory().

◆ TrilinosPreconditionerBase() [2/2]

oomph::TrilinosPreconditionerBase::TrilinosPreconditionerBase ( const TrilinosPreconditionerBase )
delete

Broken copy constructor.

Member Function Documentation

◆ clean_up_memory()

void oomph::TrilinosPreconditionerBase::clean_up_memory ( )
inlinevirtual

deletes the preconditioner, matrices and maps

Reimplemented from oomph::Preconditioner.

79  {
80  // delete the Epetra preconditioner
83 
84  // delete the epetra matrix
85  delete Epetra_matrix_pt;
86  Epetra_matrix_pt = 0;
87  }

References Epetra_matrix_pt, and Epetra_preconditioner_pt.

Referenced by setup(), and ~TrilinosPreconditionerBase().

◆ epetra_operator_pt() [1/2]

Epetra_Operator*& oomph::TrilinosPreconditionerBase::epetra_operator_pt ( )
inline

Access function to Epetra_preconditioner_pt. For use with TrilinosAztecOOSolver

119  {
121  }

References Epetra_preconditioner_pt.

Referenced by oomph::TrilinosAztecOOSolver::solver_setup().

◆ epetra_operator_pt() [2/2]

Epetra_Operator* oomph::TrilinosPreconditionerBase::epetra_operator_pt ( ) const
inline

Access function to Epetra_preconditioner_pt (const version) For use with TrilinosAztecOOSolver

126  {
128  }

References Epetra_preconditioner_pt.

◆ preconditioner_solve()

void oomph::TrilinosPreconditionerBase::preconditioner_solve ( const DoubleVector r,
DoubleVector z 
)
virtual

applies the preconditioner

preconditioner_solve - applies the preconditioner to the vector r taking distributed oomph-lib vectors (DistributedVector<double>) as arguments.

Implements oomph::Preconditioner.

128  {
129  // Get ready to do cumulative timings
130  double t_start = TimingHelpers::timer();
131 
132 #ifdef PARANOID
133  // check preconditioner data exists
134  if (Epetra_preconditioner_pt == 0)
135  {
136  std::ostringstream error_message;
137  error_message << "preconditioner_solve requires that solver data has "
138  << "been set up" << std::endl;
139  throw OomphLibError(
140  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
141  }
142 
143  if (*this->distribution_pt() != r.distribution_pt())
144  {
145  std::ostringstream error_message;
146  error_message << "The rhs vector and the matrix must have the same "
147  << "distribution.\n";
148  throw OomphLibError(
149  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
150  }
151 #endif
152 
153  // create Epetra version of r
154  Epetra_Vector* epetra_r_pt =
156 
157  // create an empty Epetra vector for z
158  Epetra_Vector* epetra_z_pt =
160  this->distribution_pt());
161 
162  // Apply preconditioner
163  Epetra_preconditioner_pt->ApplyInverse(*epetra_r_pt, *epetra_z_pt);
164 
165  // Copy result to z
166  z.build(this->distribution_pt(), 0.0);
168 
169  // clean up memory
170  delete epetra_r_pt;
171  delete epetra_z_pt;
172 
173 
174  // Add to cumulative solve time
175  double t_end = TimingHelpers::timer();
176  Cumulative_preconditioner_solve_time += (t_end - t_start);
177  }
LinearAlgebraDistribution * distribution_pt() const
access to the LinearAlgebraDistribution
Definition: linear_algebra_distribution.h:457
static double Cumulative_preconditioner_solve_time
Definition: trilinos_preconditioners.h:75
r
Definition: UniformPSDSelfTest.py:20
double timer()
returns the time in seconds after some point in past
Definition: oomph_utilities.cc:1295
void copy_to_oomphlib_vector(const Epetra_Vector *epetra_vec_pt, DoubleVector &oomph_vec)
Definition: trilinos_helpers.cc:180
Epetra_Vector * create_distributed_epetra_vector(const DoubleVector &oomph_vec)
Definition: trilinos_helpers.cc:41
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86

References oomph::DoubleVector::build(), oomph::TrilinosEpetraHelpers::copy_to_oomphlib_vector(), oomph::TrilinosEpetraHelpers::create_distributed_epetra_vector(), Cumulative_preconditioner_solve_time, oomph::DistributableLinearAlgebraObject::distribution_pt(), Epetra_preconditioner_pt, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, UniformPSDSelfTest::r, and oomph::TimingHelpers::timer().

◆ setup() [1/2]

void oomph::TrilinosPreconditionerBase::setup ( )
virtual

Broken assignment operator.

Function to set up a preconditioner for the linear system defined by matrix_pt. This function must be called before using preconditioner_solve. NOTE 1. matrix_pt must point to an object of class CRDoubleMatrix or DistributedCRDoubleMatrix This method should be called by oomph-lib solvers and preconditioners

Implements oomph::Preconditioner.

54  {
55  // clean up the memory
57 
58 #ifdef PARANOID
59  // check the matrix is square
60  if (matrix_pt()->nrow() != matrix_pt()->ncol())
61  {
62  std::ostringstream error_message;
63  error_message << "Preconditioners require a square matrix. "
64  << "Matrix is " << matrix_pt()->nrow() << " by "
65  << matrix_pt()->ncol() << std::endl;
66  throw OomphLibError(
67  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
68  }
69 #endif
70 
71 
72  // get a pointer to the cr double matrix
73  CRDoubleMatrix* cr_matrix_pt = dynamic_cast<CRDoubleMatrix*>(matrix_pt());
74 
75 #ifdef PARANOID
76  if (cr_matrix_pt == 0)
77  {
78  throw OomphLibError("Matrix must be of type CRDoubleMatrix",
81  }
82 #endif
83 
84  // build the distribution of this preconditioner
85  this->build_distribution(cr_matrix_pt->distribution_pt());
86 
87  // create the matrices
89  cr_matrix_pt, this->distribution_pt());
90 
91  // set up preconditioner
93  }
unsigned nrow() const
access function to the number of global rows.
Definition: linear_algebra_distribution.h:463
void build_distribution(const LinearAlgebraDistribution *const dist_pt)
Definition: linear_algebra_distribution.h:507
virtual unsigned long ncol() const =0
Return the number of columns of the matrix.
virtual unsigned long nrow() const =0
Return the number of rows of the matrix.
virtual DoubleMatrixBase * matrix_pt() const
Get function for matrix pointer.
Definition: preconditioner.h:150
virtual void setup_trilinos_preconditioner(Epetra_CrsMatrix *epetra_matrix_pt)=0
Epetra_CrsMatrix * create_distributed_epetra_matrix(const CRDoubleMatrix *oomph_matrix_pt, const LinearAlgebraDistribution *dist_pt)
Definition: trilinos_helpers.cc:289

References oomph::DistributableLinearAlgebraObject::build_distribution(), clean_up_memory(), oomph::TrilinosEpetraHelpers::create_distributed_epetra_matrix(), oomph::DistributableLinearAlgebraObject::distribution_pt(), Epetra_matrix_pt, oomph::Preconditioner::matrix_pt(), oomph::DoubleMatrixBase::ncol(), oomph::DistributableLinearAlgebraObject::nrow(), oomph::DoubleMatrixBase::nrow(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, and setup_trilinos_preconditioner().

Referenced by oomph::TrilinosAztecOOSolver::solver_setup().

◆ setup() [2/2]

void oomph::TrilinosPreconditionerBase::setup ( Epetra_CrsMatrix *  epetra_matrix_pt)

Function to setup a preconditioner for the linear system defined by the oomph-lib oomph_matrix_pt and Epetra epetra_matrix_pt matrices. This method is called by Trilinos solvers.

101  {
102  // clean up old data
103  clean_up_memory();
104 
105  // first try CRDoubleMatrix
106  CRDoubleMatrix* cr_matrix_pt = dynamic_cast<CRDoubleMatrix*>(matrix_pt());
107  if (cr_matrix_pt == 0)
108  {
109  std::ostringstream error_message;
110  error_message << "TrilinosSolver only work with "
111  << "DistributedCRDoubleMatrix matrices" << std::endl;
112  throw OomphLibError(
113  error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
114  }
115 
116  // setup the specific preconditioner
117  setup_trilinos_preconditioner(epetra_matrix_pt);
118  }

References clean_up_memory(), oomph::Preconditioner::matrix_pt(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, and setup_trilinos_preconditioner().

◆ setup_trilinos_preconditioner()

virtual void oomph::TrilinosPreconditionerBase::setup_trilinos_preconditioner ( Epetra_CrsMatrix *  epetra_matrix_pt)
protectedpure virtual

Function to set up a specific Trilinos preconditioner. This is called by setup(...).

Implemented in oomph::TrilinosIFPACKPreconditioner, and oomph::TrilinosMLPreconditioner.

Referenced by setup().

Member Data Documentation

◆ Cumulative_preconditioner_solve_time

double oomph::TrilinosPreconditionerBase::Cumulative_preconditioner_solve_time = 0.0
static

Static double that accumulates the preconditioner solve time of all instantiations of this class. Reset it manually, e.g. after every Newton solve.

//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// Static double that accumulates the preconditioner solve time of all instantiations of this class. Reset it manually, e.g. after every Newton solve.

Referenced by preconditioner_solve().

◆ Epetra_matrix_pt

Epetra_CrsMatrix* oomph::TrilinosPreconditionerBase::Epetra_matrix_pt
protected

Pointer used to store the epetra matrix - only used when this preconditioner is setup using the oomph-lib interface

Referenced by clean_up_memory(), setup(), and TrilinosPreconditionerBase().

◆ Epetra_preconditioner_pt

Epetra_Operator* oomph::TrilinosPreconditionerBase::Epetra_preconditioner_pt
protected

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