oomph::MatrixBasedLumpedPreconditioner< MATRIX > Class Template Reference

Matrix-based lumped preconditioner. More...

#include <general_purpose_preconditioners.h>

+ Inheritance diagram for oomph::MatrixBasedLumpedPreconditioner< MATRIX >:

Public Member Functions

 MatrixBasedLumpedPreconditioner ()
 Constructor. More...
 
 ~MatrixBasedLumpedPreconditioner ()
 Destructor. More...
 
 MatrixBasedLumpedPreconditioner (const MatrixBasedDiagPreconditioner &)=delete
 Broken copy constructor. More...
 
void operator= (const MatrixBasedLumpedPreconditioner &)=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 ()
 
bool positive_matrix () const
 
doubleinverse_lumped_vector_pt ()
 
unsignednrow ()
 Access function to number of rows for this preconditioner. More...
 
void clean_up_memory ()
 clean up memory - just delete the inverse lumped vector More...
 
void setup ()
 Setup the lumped preconditioner. Specialisation for CCDoubleMatrix. More...
 
void setup ()
 Setup the lumped preconditioner. Specialisation for CRDoubleMatrix. More...
 
void setup (DoubleMatrixBase *matrix_pt)
 
void setup (const Problem *problem_pt, DoubleMatrixBase *matrix_pt)
 
virtual void setup ()=0
 
- 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)
 

Private Attributes

doubleInv_lumped_diag_pt
 Vector of inverse diagonal entries. More...
 
bool Positive_matrix
 
unsigned Nrow
 

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

template<typename MATRIX>
class oomph::MatrixBasedLumpedPreconditioner< MATRIX >

Matrix-based lumped preconditioner.

Constructor & Destructor Documentation

◆ MatrixBasedLumpedPreconditioner() [1/2]

template<typename MATRIX >
oomph::MatrixBasedLumpedPreconditioner< MATRIX >::MatrixBasedLumpedPreconditioner ( )
inline

Constructor.

85  {
86  // default the positive matrix boolean to false
87  Positive_matrix = false;
88 
89  // set the pointers to the lumped vector to 0
91  };
double * Inv_lumped_diag_pt
Vector of inverse diagonal entries.
Definition: general_purpose_preconditioners.h:166
bool Positive_matrix
Definition: general_purpose_preconditioners.h:169

References oomph::MatrixBasedLumpedPreconditioner< MATRIX >::Inv_lumped_diag_pt, and oomph::MatrixBasedLumpedPreconditioner< MATRIX >::Positive_matrix.

◆ ~MatrixBasedLumpedPreconditioner()

template<typename MATRIX >
oomph::MatrixBasedLumpedPreconditioner< MATRIX >::~MatrixBasedLumpedPreconditioner ( )
inline

Destructor.

95  {
96  this->clean_up_memory();
97  }
void clean_up_memory()
clean up memory - just delete the inverse lumped vector
Definition: general_purpose_preconditioners.h:159

References oomph::MatrixBasedLumpedPreconditioner< MATRIX >::clean_up_memory().

◆ MatrixBasedLumpedPreconditioner() [2/2]

Broken copy constructor.

Member Function Documentation

◆ clean_up_memory()

template<typename MATRIX >
void oomph::MatrixBasedLumpedPreconditioner< MATRIX >::clean_up_memory ( )
inlinevirtual

clean up memory - just delete the inverse lumped vector

Reimplemented from oomph::Preconditioner.

160  {
161  delete[] Inv_lumped_diag_pt;
162  }

References oomph::MatrixBasedLumpedPreconditioner< MATRIX >::Inv_lumped_diag_pt.

Referenced by oomph::MatrixBasedLumpedPreconditioner< MATRIX >::~MatrixBasedLumpedPreconditioner().

◆ inverse_lumped_vector_pt()

template<typename MATRIX >
double* oomph::MatrixBasedLumpedPreconditioner< MATRIX >::inverse_lumped_vector_pt ( )
inline

Access function to the inverse of the lumped vector assembled in the preconditioner setup routine

paranoid check that vector has been created

137  {
139 #ifdef PARANOID
140  if (Inv_lumped_diag_pt == 0)
141  {
142  throw OomphLibError("The inverse lumped vector has not been created. "
143  "Created in setup(...)",
146  }
147 #endif
148  return Inv_lumped_diag_pt;
149  }
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86

References oomph::MatrixBasedLumpedPreconditioner< MATRIX >::Inv_lumped_diag_pt, OOMPH_CURRENT_FUNCTION, and OOMPH_EXCEPTION_LOCATION.

◆ nrow()

template<typename MATRIX >
unsigned& oomph::MatrixBasedLumpedPreconditioner< MATRIX >::nrow ( )
inline

Access function to number of rows for this preconditioner.

154  {
155  return Nrow;
156  }
unsigned Nrow
Definition: general_purpose_preconditioners.h:172

References oomph::MatrixBasedLumpedPreconditioner< MATRIX >::Nrow.

◆ operator=()

template<typename MATRIX >
void oomph::MatrixBasedLumpedPreconditioner< MATRIX >::operator= ( const MatrixBasedLumpedPreconditioner< MATRIX > &  )
delete

Broken assignment operator.

◆ positive_matrix()

template<typename MATRIX >
bool oomph::MatrixBasedLumpedPreconditioner< MATRIX >::positive_matrix ( ) const
inline

Access function to the Positive_matrix which indicates whether lumped matrix was positive

paranoid check that preconditioner has been setup

120  {
122 #ifdef PARANOID
123  if (Inv_lumped_diag_pt == 0)
124  {
125  throw OomphLibError("The preconditioner has not been setup.",
128  }
129 #endif
130  return Positive_matrix;
131  }

References oomph::MatrixBasedLumpedPreconditioner< MATRIX >::Inv_lumped_diag_pt, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, and oomph::MatrixBasedLumpedPreconditioner< MATRIX >::Positive_matrix.

◆ preconditioner_solve()

template<typename MATRIX >
void oomph::MatrixBasedLumpedPreconditioner< MATRIX >::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 lumped matrix.

Implements oomph::Preconditioner.

282  {
283 #ifdef PARANOID
284  if (*r.distribution_pt() != *this->distribution_pt())
285  {
286  std::ostringstream error_message_stream;
287  error_message_stream
288  << "The r vector must have teh same distribution as the "
289  "preconditioner. "
290  << "(this is the same as the matrix passed to setup())";
291  throw OomphLibError(error_message_stream.str(),
294  }
295  if (z.built())
296  {
297  if (*z.distribution_pt() != *this->distribution_pt())
298  {
299  std::ostringstream error_message_stream;
300  error_message_stream
301  << "The z vector distribution has been setup; it must have the "
302  << "same distribution as the r vector (and preconditioner).";
303  throw OomphLibError(error_message_stream.str(),
306  }
307  }
308 #endif
309 
310  z.build(r.distribution_pt(), 0.0);
311  for (unsigned i = 0; i < Nrow; i++)
312  {
313  z[i] = Inv_lumped_diag_pt[i] * r[i];
314  }
315  }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
r
Definition: UniformPSDSelfTest.py:20

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

◆ setup() [1/6]

Setup the lumped preconditioner. Specialisation for CCDoubleMatrix.

Implements oomph::Preconditioner.

168  {
169  // # of rows in the matrix
170  Nrow = matrix_pt()->nrow();
171 
172  // Create the vector for the inverse lumped
173  if (Inv_lumped_diag_pt != 0)
174  {
175  delete[] this->Inv_lumped_diag_pt;
176  }
177  Inv_lumped_diag_pt = new double[this->Nrow];
178 
179  // zero the vector
180  for (unsigned i = 0; i < Nrow; i++)
181  {
182  Inv_lumped_diag_pt[i] = 0.0;
183  }
184 
185  // cast the Double Base Matrix to Compressed Column Double Matrix
186  CCDoubleMatrix* cc_matrix_pt = dynamic_cast<CCDoubleMatrix*>(matrix_pt());
187 
188  // get the matrix
189  int* m_row_index = cc_matrix_pt->row_index();
190  double* m_value = cc_matrix_pt->value();
191  unsigned m_nnz = cc_matrix_pt->nnz();
192 
193  // intially set positive matrix to true
194  Positive_matrix = true;
195 
196  // lump the matrix
197  for (unsigned i = 0; i < m_nnz; i++)
198  {
199  // if the matrix contains negative coefficient the matrix not positive
200  if (m_value[i] < 0.0)
201  {
202  Positive_matrix = false;
203  }
204 
205  // computed lumped matrix - temporarily stored in Inv_lumped_diag_pt
206  Inv_lumped_diag_pt[m_row_index[i]] += m_value[i];
207  }
208 
209  // invert the lumped matrix
210  for (unsigned i = 0; i < Nrow; i++)
211  {
213  }
214 
215  // create the distribution
216  LinearAlgebraDistribution dist(comm_pt(), Nrow, false);
217  this->build_distribution(dist);
218  }
void build_distribution(const LinearAlgebraDistribution *const dist_pt)
Definition: linear_algebra_distribution.h:507
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 i, oomph::SparseMatrix< T, MATRIX_TYPE >::nnz(), oomph::CCMatrix< T >::row_index(), and oomph::SparseMatrix< T, MATRIX_TYPE >::value().

◆ setup() [2/6]

Setup the lumped preconditioner. Specialisation for CRDoubleMatrix.

Implements oomph::Preconditioner.

225  {
226  // first attempt to cast to CRDoubleMatrix
227  CRDoubleMatrix* cr_matrix_pt = dynamic_cast<CRDoubleMatrix*>(matrix_pt());
228 
229  // # of rows in the matrix
230  Nrow = cr_matrix_pt->nrow_local();
231 
232  // Create the vector for the inverse lumped
233  if (Inv_lumped_diag_pt != 0)
234  {
235  delete[] this->Inv_lumped_diag_pt;
236  }
237  Inv_lumped_diag_pt = new double[this->Nrow];
238 
239  // zero the vector
240  for (unsigned i = 0; i < Nrow; i++)
241  {
242  Inv_lumped_diag_pt[i] = 0.0;
243  }
244 
245  // get the matrix
246  int* m_row_start = cr_matrix_pt->row_start();
247  double* m_value = cr_matrix_pt->value();
248 
249  // intially set positive matrix to true
250  Positive_matrix = true;
251 
252  // lump and invert matrix
253  for (unsigned i = 0; i < Nrow; i++)
254  {
255  Inv_lumped_diag_pt[i] = 0.0;
256  for (int j = m_row_start[i]; j < m_row_start[i + 1]; j++)
257  {
258  // if the matrix contains negative coefficient the matrix not positive
259  if (m_value[j] < 0.0)
260  {
261  Positive_matrix = false;
262  }
263 
264  // computed lumped coef (i,i)- temporarily stored in Inv_lumped_diag_pt
265  Inv_lumped_diag_pt[i] += m_value[j];
266  }
267  // invert coef (i,i)
269  }
270 
271  // store the distribution
272  this->build_distribution(cr_matrix_pt->distribution_pt());
273  }
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References oomph::DistributableLinearAlgebraObject::distribution_pt(), i, j, oomph::DistributableLinearAlgebraObject::nrow_local(), oomph::CRDoubleMatrix::row_start(), and oomph::CRDoubleMatrix::value().

◆ setup() [3/6]

template<typename MATRIX >
void oomph::MatrixBasedLumpedPreconditioner< MATRIX >::setup ( )
virtual

Setup the preconditioner (store diagonal) from the fully assembled matrix. Problem pointer is ignored.

Implements oomph::Preconditioner.

◆ setup() [4/6]

template<typename MATRIX >
virtual void oomph::Preconditioner::setup
virtual

For some reason we need to remind the compiler that there is also a function named setup in the base class.

Implements oomph::Preconditioner.

◆ setup() [5/6]

template<typename MATRIX >
void oomph::Preconditioner::setup
inlinevirtual

For some reason we need to remind the compiler that there is also a function named setup in the base class.

Implements oomph::Preconditioner.

121  {
123  setup(matrix_pt);
124  }
void obsolete()
Output warning message.
Definition: oomph_utilities.cc:1102

◆ setup() [6/6]

template<typename MATRIX >
void oomph::Preconditioner::setup
inlinevirtual

For some reason we need to remind the compiler that there is also a function named setup in the base class.

Implements oomph::Preconditioner.

95  {
96  // Store matrix pointer
98 
99  // Extract and store communicator pointer
100  DistributableLinearAlgebraObject* dist_obj_pt =
102  if (dist_obj_pt != 0)
103  {
104  set_comm_pt(dist_obj_pt->distribution_pt()->communicator_pt());
105  }
106  else
107  {
108  set_comm_pt(0);
109  }
110 
111  double setup_time_start = TimingHelpers::timer();
112  setup();
113  double setup_time_finish = TimingHelpers::timer();
114  Setup_time = setup_time_finish - setup_time_start;
115  }
DistributableLinearAlgebraObject()
Default constructor - create a distribution.
Definition: linear_algebra_distribution.h:438
double Setup_time
The time it takes to set up this preconditioner.
Definition: preconditioner.h:243
virtual void set_comm_pt(const OomphCommunicator *const comm_pt)
Set the communicator pointer.
Definition: preconditioner.h:193
virtual void set_matrix_pt(DoubleMatrixBase *matrix_pt)
Set the matrix pointer.
Definition: preconditioner.h:165
double timer()
returns the time in seconds after some point in past
Definition: oomph_utilities.cc:1295

Member Data Documentation

◆ Inv_lumped_diag_pt

◆ Nrow

template<typename MATRIX >
unsigned oomph::MatrixBasedLumpedPreconditioner< MATRIX >::Nrow
private

◆ Positive_matrix


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