oomph::MatrixBasedDiagPreconditioner Class Reference

Matrix-based diagonal preconditioner. More...

#include <general_purpose_preconditioners.h>

+ Inheritance diagram for oomph::MatrixBasedDiagPreconditioner:

Public Member Functions

 MatrixBasedDiagPreconditioner ()
 Constructor (empty) More...
 
 ~MatrixBasedDiagPreconditioner ()
 Destructor (empty) More...
 
 MatrixBasedDiagPreconditioner (const MatrixBasedDiagPreconditioner &)=delete
 Broken copy constructor. More...
 
void operator= (const MatrixBasedDiagPreconditioner &)=delete
 Broken assignment operator. More...
 
void preconditioner_solve (const DoubleVector &r, DoubleVector &z)
 Apply preconditioner to z, i.e. z=D^-1. More...
 
void setup ()
 
- 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 void clean_up_memory ()
 Clean up memory (empty). Generic interface function. 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)
 

Private Attributes

Vector< doubleInv_diag
 Vector of inverse diagonal entries. More...
 

Additional Inherited Members

- Protected Member Functions inherited from oomph::DistributableLinearAlgebraObject
void clear_distribution ()
 
- 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

Matrix-based diagonal preconditioner.

Constructor & Destructor Documentation

◆ MatrixBasedDiagPreconditioner() [1/2]

oomph::MatrixBasedDiagPreconditioner::MatrixBasedDiagPreconditioner ( )
inline

Constructor (empty)

52 {};

◆ ~MatrixBasedDiagPreconditioner()

oomph::MatrixBasedDiagPreconditioner::~MatrixBasedDiagPreconditioner ( )
inline

Destructor (empty)

55 {};

◆ MatrixBasedDiagPreconditioner() [2/2]

oomph::MatrixBasedDiagPreconditioner::MatrixBasedDiagPreconditioner ( const MatrixBasedDiagPreconditioner )
delete

Broken copy constructor.

Member Function Documentation

◆ operator=()

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

Broken assignment operator.

◆ preconditioner_solve()

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

Apply preconditioner to z, i.e. z=D^-1.

Apply preconditioner: Multiply r by the inverse of the diagonal.

Implements oomph::Preconditioner.

119  {
120 #ifdef PARANOID
121  if (*r.distribution_pt() != *this->distribution_pt())
122  {
123  std::ostringstream error_message_stream;
124  error_message_stream
125  << "The r vector must have the same distribution as the "
126  "preconditioner. "
127  << "(this is the same as the matrix passed to setup())";
128  throw OomphLibError(error_message_stream.str(),
131  }
132  if (z.built())
133  {
134  if (*z.distribution_pt() != *this->distribution_pt())
135  {
136  std::ostringstream error_message_stream;
137  error_message_stream
138  << "The z vector distribution has been setup; it must have the "
139  << "same distribution as the r vector (and preconditioner).";
140  throw OomphLibError(error_message_stream.str(),
143  }
144  }
145 #endif
146 
147  // if z has not been setup then rebuild it
148  if (!z.built())
149  {
150  z.build(this->distribution_pt(), 0.0);
151  }
152 
153  // apply the preconditioner
154  const double* r_values = r.values_pt();
155  double* z_values = z.values_pt();
156  unsigned nrow_local = this->nrow_local();
157  for (unsigned i = 0; i < nrow_local; i++)
158  {
159  z_values[i] = Inv_diag[i] * r_values[i];
160  }
161  }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
LinearAlgebraDistribution * distribution_pt() const
access to the LinearAlgebraDistribution
Definition: linear_algebra_distribution.h:457
unsigned nrow_local() const
access function for the num of local rows on this processor.
Definition: linear_algebra_distribution.h:469
Vector< double > Inv_diag
Vector of inverse diagonal entries.
Definition: general_purpose_preconditioners.h:73
r
Definition: UniformPSDSelfTest.py:20
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86

References oomph::DoubleVector::build(), oomph::DoubleVector::built(), oomph::DistributableLinearAlgebraObject::distribution_pt(), i, Inv_diag, oomph::DistributableLinearAlgebraObject::nrow_local(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, UniformPSDSelfTest::r, and oomph::DoubleVector::values_pt().

◆ setup()

void oomph::MatrixBasedDiagPreconditioner::setup ( )
virtual

Setup the preconditioner (store diagonal) from the fully assembled matrix.

Setup diagonal preconditioner: Store the inverse of the diagonal entries from the fully assembled matrix.

Implements oomph::Preconditioner.

44  {
45  // first attempt to cast to DistributableLinearAlgebraObject
46  DistributableLinearAlgebraObject* dist_matrix_pt =
48 
49  // if it is a distributable matrix
50  if (dist_matrix_pt != 0)
51  {
52  // cache the number of first_rows and nrow_local
53  unsigned nrow_local = dist_matrix_pt->nrow_local();
54  unsigned first_row = dist_matrix_pt->first_row();
55 
56  // resize the inverse diagonal storage
57  Inv_diag.resize(nrow_local);
58 
59  // Extract the diagonal entries
60  for (unsigned i = 0; i < nrow_local; i++)
61  {
62  unsigned index = i + first_row;
63 #ifdef PARANOID
64  if ((*matrix_pt())(i, index) == 0.0)
65  {
66  throw OomphLibError(
67  "Zero diagonal in matrix --> Cannot use diagonal preconditioner.",
70  }
71 #endif
72  Inv_diag[i] = 1.0 / (*matrix_pt())(i, index);
73  }
74 
75  // store the distribution
76  this->build_distribution(dist_matrix_pt->distribution_pt());
77  }
78 
79  // else it is not a distributable matrix
80  else
81  {
82  // # of rows in the matrix
83  unsigned n_row = matrix_pt()->nrow();
84 
85  // Resize the Inv_diag vector to accommodate the # of
86  // diagonal entries
87  Inv_diag.resize(n_row);
88 
89  // Extract the diagonal entries
90  for (unsigned i = 0; i < n_row; i++)
91  {
92 #ifdef PARANOID
93  if ((*matrix_pt())(i, i) == 0.0)
94  {
95  throw OomphLibError(
96  "Zero diagonal in matrix --> Cannot use diagonal preconditioner.",
99  }
100  else
101 #endif
102  {
103  Inv_diag[i] = 1.0 / (*matrix_pt())(i, i);
104  }
105  }
106 
107  // create the distribution
108  LinearAlgebraDistribution dist(comm_pt(), n_row, false);
109  this->build_distribution(dist);
110  }
111  }
unsigned first_row() const
access function for the first row on this processor
Definition: linear_algebra_distribution.h:481
void build_distribution(const LinearAlgebraDistribution *const dist_pt)
Definition: linear_algebra_distribution.h:507
DistributableLinearAlgebraObject()
Default constructor - create a distribution.
Definition: linear_algebra_distribution.h:438
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 const OomphCommunicator * comm_pt() const
Get function for comm pointer.
Definition: preconditioner.h:171

References oomph::DistributableLinearAlgebraObject::build_distribution(), oomph::DistributableLinearAlgebraObject::distribution_pt(), oomph::DistributableLinearAlgebraObject::first_row(), i, Inv_diag, oomph::Preconditioner::matrix_pt(), oomph::DoubleMatrixBase::nrow(), oomph::DistributableLinearAlgebraObject::nrow_local(), OOMPH_CURRENT_FUNCTION, and OOMPH_EXCEPTION_LOCATION.

Member Data Documentation

◆ Inv_diag

Vector<double> oomph::MatrixBasedDiagPreconditioner::Inv_diag
private

Vector of inverse diagonal entries.

Referenced by preconditioner_solve(), and setup().


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