oomph::ILUZeroPreconditioner< CCDoubleMatrix > Class Reference

ILU(0) Preconditioner for matrices of CCDoubleMatrix Format. More...

#include <general_purpose_preconditioners.h>

+ Inheritance diagram for oomph::ILUZeroPreconditioner< CCDoubleMatrix >:

Public Member Functions

 ILUZeroPreconditioner ()
 Constructor (empty) More...
 
 ~ILUZeroPreconditioner ()
 Destructor (empty) More...
 
 ILUZeroPreconditioner (const ILUZeroPreconditioner &)=delete
 Broken copy constructor. More...
 
void operator= (const ILUZeroPreconditioner &)=delete
 Broken assignment operator. More...
 
void preconditioner_solve (const DoubleVector &r, DoubleVector &z)
 Apply preconditioner to r. More...
 
void setup ()
 setup ILU(0) preconditioner for Matrices of CCDoubleMatrix type More...
 
- 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< unsignedU_column_start
 Column start for upper triangular matrix. More...
 
Vector< CompressedMatrixCoefficientU_row_entry
 
Vector< unsignedL_column_start
 Column start for lower triangular matrix. More...
 
Vector< CompressedMatrixCoefficientL_row_entry
 

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

ILU(0) Preconditioner for matrices of CCDoubleMatrix Format.

Constructor & Destructor Documentation

◆ ILUZeroPreconditioner() [1/2]

Constructor (empty)

272 {};

◆ ~ILUZeroPreconditioner()

Destructor (empty)

275 {};

◆ ILUZeroPreconditioner() [2/2]

Member Function Documentation

◆ operator=()

Broken assignment operator.

◆ preconditioner_solve()

void oomph::ILUZeroPreconditioner< CCDoubleMatrix >::preconditioner_solve ( const DoubleVector r,
DoubleVector z 
)
virtual

Apply preconditioner to r.

Apply ILU(0) preconditioner for CCDoubleMatrix: Solve Ly=r then Uz=y and return z

Implements oomph::Preconditioner.

626  {
627  // # of rows in the matrix
628  int n_row = r.nrow();
629 
630  // store the distribution of z
631  LinearAlgebraDistribution* z_dist = 0;
632  if (z.built())
633  {
634  z_dist = new LinearAlgebraDistribution(z.distribution_pt());
635  }
636 
637  // copy r to z
638  z = r;
639 
640  // if z is distributed then change to global
641  if (z.distributed())
642  {
643  z.redistribute(this->distribution_pt());
644  }
645 
646  // solve Ly=r (note L matrix is unit and diagonal is not stored)
647  for (unsigned i = 0; i < static_cast<unsigned>(n_row); i++)
648  {
649  for (unsigned j = L_column_start[i]; j < L_column_start[i + 1]; j++)
650  {
651  z[L_row_entry[j].index()] =
652  z[L_row_entry[j].index()] - z[i] * L_row_entry[j].value();
653  }
654  }
655 
656  // solve Uz=y
657  double x;
658  for (int i = n_row - 1; i >= 0; i--)
659  {
660  x = z[i] / U_row_entry[U_column_start[i + 1] - 1].value();
661  z[i] = x;
662  for (unsigned j = U_column_start[i]; j < U_column_start[i + 1] - 1; j++)
663  {
664  z[U_row_entry[j].index()] =
665  z[U_row_entry[j].index()] - x * U_row_entry[j].value();
666  }
667  }
668 
669  // if the distribution of z was preset the redistribute to original
670  if (z_dist != 0)
671  {
672  z.redistribute(z_dist);
673  delete z_dist;
674  }
675  }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
LinearAlgebraDistribution * distribution_pt() const
access to the LinearAlgebraDistribution
Definition: linear_algebra_distribution.h:457
Vector< unsigned > L_column_start
Column start for lower triangular matrix.
Definition: general_purpose_preconditioners.h:300
Vector< CompressedMatrixCoefficient > U_row_entry
Definition: general_purpose_preconditioners.h:297
Vector< CompressedMatrixCoefficient > L_row_entry
Definition: general_purpose_preconditioners.h:304
Vector< unsigned > U_column_start
Column start for upper triangular matrix.
Definition: general_purpose_preconditioners.h:293
r
Definition: UniformPSDSelfTest.py:20
list x
Definition: plotDoE.py:28
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References oomph::DoubleVector::built(), oomph::DistributableLinearAlgebraObject::distributed(), oomph::DistributableLinearAlgebraObject::distribution_pt(), i, j, UniformPSDSelfTest::r, oomph::DoubleVector::redistribute(), and plotDoE::x.

◆ setup()

void oomph::ILUZeroPreconditioner< CCDoubleMatrix >::setup ( )
virtual

setup ILU(0) preconditioner for Matrices of CCDoubleMatrix type

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

Implements oomph::Preconditioner.

327  {
328  // cast the Double Base Matrix to Compressed Column Double Matrix
329  CCDoubleMatrix* cc_matrix_pt = dynamic_cast<CCDoubleMatrix*>(matrix_pt());
330 
331 #ifdef PARANOID
332  if (cc_matrix_pt == 0)
333  {
334  std::ostringstream error_msg;
335  error_msg << "Failed to conver matrix_pt to CCDoubleMatrix*.";
336  throw OomphLibError(
338  }
339 #endif
340 
341  // number of rows in matrix
342  int n_row = cc_matrix_pt->nrow();
343 
344  // set the distribution
345  LinearAlgebraDistribution dist(comm_pt(), n_row, false);
346  this->build_distribution(dist);
347 
348  // declares variables to store number of non zero entires in L and U
349  int l_nz = 0;
350  int u_nz = 0;
351 
352  // create space for m matrix
353  int* m_column_start;
354  int* m_row_index;
355  double* m_value;
356 
357  // get the m matrix
358  m_column_start = cc_matrix_pt->column_start();
359  m_row_index = cc_matrix_pt->row_index();
360  m_value = cc_matrix_pt->value();
361 
362  // find number non zero entries in L and U
363  for (int i = 0; i < n_row; i++)
364  {
365  for (int j = m_column_start[i]; j < m_column_start[i + 1]; j++)
366  {
367  if (m_row_index[j] > i)
368  {
369  l_nz++;
370  }
371  else
372  {
373  u_nz++;
374  }
375  }
376  }
377 
378  // resize vectors to store the data for the lower prior to building the
379  // matrices
380  L_column_start.resize(n_row + 1);
381  L_row_entry.resize(l_nz);
382 
383  // and the upper matrix
384  U_column_start.resize(n_row + 1);
385  U_row_entry.resize(u_nz);
386 
387  // set first column pointers to zero
388  L_column_start[0] = 0;
389  U_column_start[0] = 0;
390 
391  // split the matrix into L and U
392  for (int i = 0; i < n_row; i++)
393  {
396  for (int j = m_column_start[i]; j < m_column_start[i + 1]; j++)
397  {
398  if (m_row_index[j] > i)
399  {
400  int k = L_column_start[i + 1]++;
401  L_row_entry[k].index() = m_row_index[j];
402  L_row_entry[k].value() = m_value[j];
403  }
404  else
405  {
406  int k = U_column_start[i + 1]++;
407  U_row_entry[k].index() = m_row_index[j];
408  U_row_entry[k].value() = m_value[j];
409  }
410  }
411  }
412 
413  // sort each row entry vector into row index order for each column
414 
415  // loop over the columns
416  for (unsigned i = 0; i < unsigned(n_row); i++)
417  {
418  // sort the columns of the L matrix
419  std::sort(L_row_entry.begin() + L_column_start[i],
420  L_row_entry.begin() + L_column_start[i + 1]);
421 
422  // sort the columns of the U matrix
423  std::sort(U_row_entry.begin() + U_column_start[i],
424  U_row_entry.begin() + U_column_start[i + 1]);
425  }
426 
427 
428  // factorise matrix
429  int i;
430  unsigned j, pn, qn, rn;
431  pn = 0;
432  qn = 0;
433  rn = 0;
434  double multiplier;
435  for (i = 0; i < n_row - 1; i++)
436  {
437  multiplier = U_row_entry[U_column_start[i + 1] - 1].value();
438  for (j = L_column_start[i]; j < L_column_start[i + 1]; j++)
440  for (j = U_column_start[i + 1]; j < U_column_start[i + 2] - 1; j++)
441  {
442  multiplier = U_row_entry[j].value();
443  qn = j + 1;
444  rn = L_column_start[i + 1];
445  for (pn = L_column_start[U_row_entry[j].index()];
446  pn < L_column_start[U_row_entry[j].index() + 1] &&
447  static_cast<int>(L_row_entry[pn].index()) <= i + 1;
448  pn++)
449  {
450  while (qn < U_column_start[i + 2] &&
451  U_row_entry[qn].index() < L_row_entry[pn].index())
452  qn++;
453  if (qn < U_column_start[i + 2] &&
454  L_row_entry[pn].index() == U_row_entry[qn].index())
455  U_row_entry[qn].value() -= multiplier * L_row_entry[pn].value();
456  }
457  for (; pn < L_column_start[U_row_entry[j].index() + 1]; pn++)
458  {
459  while (rn < L_column_start[i + 2] &&
460  L_row_entry[rn].index() < L_row_entry[pn].index())
461  rn++;
462  if (rn < L_column_start[i + 2] &&
463  L_row_entry[pn].index() == L_row_entry[rn].index())
464  L_row_entry[rn].value() -= multiplier * L_row_entry[pn].value();
465  }
466  }
467  }
468  }
void build_distribution(const LinearAlgebraDistribution *const dist_pt)
Definition: linear_algebra_distribution.h:507
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
char char char int int * k
Definition: level2_impl.h:374
squared absolute value
Definition: GlobalFunctions.h:87
double multiplier(const Vector< double > &xi)
Definition: disk_oscillation.cc:63
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86

References oomph::DistributableLinearAlgebraObject::build_distribution(), oomph::CCMatrix< T >::column_start(), oomph::Preconditioner::comm_pt(), i, j, k, oomph::Preconditioner::matrix_pt(), Global_Physical_Variables::multiplier(), oomph::CCDoubleMatrix::nrow(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, oomph::CCMatrix< T >::row_index(), Eigen::value, and oomph::SparseMatrix< T, MATRIX_TYPE >::value().

Member Data Documentation

◆ L_column_start

Column start for lower triangular matrix.

◆ L_row_entry

Row entry for the lower triangular matrix (each element of the vector contains the row index and coefficient)

◆ U_column_start

Column start for upper triangular matrix.

◆ U_row_entry

Row entry for the upper triangular matrix (each element of the vector contains the row index and coefficient)


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