oomph::ILUZeroPreconditioner< CRDoubleMatrix > Class Reference

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

#include <general_purpose_preconditioners.h>

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

Public Member Functions

 ILUZeroPreconditioner ()
 Constructor (empty) More...
 
 ILUZeroPreconditioner (const ILUZeroPreconditioner &)=delete
 Broken copy constructor. More...
 
void operator= (const ILUZeroPreconditioner &)=delete
 Broken assignment operator. More...
 
 ~ILUZeroPreconditioner ()
 Destructor (empty) More...
 
void preconditioner_solve (const DoubleVector &r, DoubleVector &z)
 Apply preconditioner to r. More...
 
void setup ()
 setup ILU(0) preconditioner for Matrices of CRDoubleMatrix 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_row_start
 Row start for upper triangular matrix. More...
 
Vector< CompressedMatrixCoefficientU_row_entry
 
Vector< unsignedL_row_start
 Row 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 CRDoubleMatrix Format.

Constructor & Destructor Documentation

◆ ILUZeroPreconditioner() [1/2]

Constructor (empty)

316 {};

◆ ILUZeroPreconditioner() [2/2]

◆ ~ILUZeroPreconditioner()

Destructor (empty)

326 {};

Member Function Documentation

◆ operator=()

Broken assignment operator.

◆ preconditioner_solve()

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

Apply preconditioner to r.

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

Implements oomph::Preconditioner.

684  {
685  // # of rows in the matrix
686  int n_row = r.nrow();
687 
688  // store the distribution of z
689  LinearAlgebraDistribution* z_dist = 0;
690  if (z.built())
691  {
692  z_dist = new LinearAlgebraDistribution(z.distribution_pt());
693  }
694 
695  // copy r to z
696  z = r;
697 
698  // if z is distributed then change to global
699  if (z.distributed())
700  {
701  z.redistribute(this->distribution_pt());
702  }
703 
704  // solve Ly=r (note L matrix is unit and diagonal is not stored)
705  double t;
706  for (int i = 0; i < n_row; i++)
707  {
708  t = 0;
709  for (unsigned j = L_row_start[i]; j < L_row_start[i + 1]; j++)
710  {
711  t = t + L_row_entry[j].value() * z[L_row_entry[j].index()];
712  }
713  z[i] = z[i] - t;
714  }
715 
716  // solve Uz=y
717  for (int i = n_row - 1; i >= 0; i--)
718  {
719  t = 0;
720  for (unsigned j = U_row_start[i] + 1; j < U_row_start[i + 1]; j++)
721  {
722  t = t + U_row_entry[j].value() * z[U_row_entry[j].index()];
723  }
724  z[i] = z[i] - t;
725  z[i] = z[i] / U_row_entry[U_row_start[i]].value();
726  }
727 
728  // if the distribution of z was preset the redistribute to original
729  if (z_dist != 0)
730  {
731  z.redistribute(z_dist);
732  delete z_dist;
733  }
734  }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
LinearAlgebraDistribution * distribution_pt() const
access to the LinearAlgebraDistribution
Definition: linear_algebra_distribution.h:457
Vector< CompressedMatrixCoefficient > U_row_entry
Definition: general_purpose_preconditioners.h:342
Vector< unsigned > U_row_start
Row start for upper triangular matrix.
Definition: general_purpose_preconditioners.h:338
Vector< unsigned > L_row_start
Row start for lower triangular matrix.
Definition: general_purpose_preconditioners.h:345
Vector< CompressedMatrixCoefficient > L_row_entry
Definition: general_purpose_preconditioners.h:349
r
Definition: UniformPSDSelfTest.py:20
t
Definition: plotPSD.py:36
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 plotPSD::t.

◆ setup()

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

setup ILU(0) preconditioner for Matrices of CRDoubleMatrix Type

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

Implements oomph::Preconditioner.

475  {
476  // cast the Double Base Matrix to Compressed Column Double Matrix
477  CRDoubleMatrix* cr_matrix_pt = dynamic_cast<CRDoubleMatrix*>(matrix_pt());
478 
479 #ifdef PARANOID
480  if (cr_matrix_pt == 0)
481  {
482  std::ostringstream error_msg;
483  error_msg << "Failed to conver matrix_pt to CRDoubleMatrix*.";
484  throw OomphLibError(
486  }
487 #endif
488 
489  // if the matrix is distributed then build global version
490  bool built_global = false;
491  if (cr_matrix_pt->distributed())
492  {
493  // get the global matrix
494  CRDoubleMatrix* global_matrix_pt = cr_matrix_pt->global_matrix();
495 
496  // store at cr_matrix pointer
497  cr_matrix_pt = global_matrix_pt;
498 
499  // set the flag so we can delete later
500  built_global = true;
501  }
502 
503  // store the Distribution
504  this->build_distribution(cr_matrix_pt->distribution_pt());
505 
506  // number of rows in matrix
507  int n_row = cr_matrix_pt->nrow();
508 
509  // declares variables to store number of non zero entires in L and U
510  int l_nz = 0;
511  int u_nz = 0;
512 
513  // create space for m matrix
514  int* m_row_start;
515  int* m_column_index;
516  double* m_value;
517 
518  // get the m matrix
519  m_row_start = cr_matrix_pt->row_start();
520  m_column_index = cr_matrix_pt->column_index();
521  m_value = cr_matrix_pt->value();
522 
523  // find number non zero entries in L and U
524  for (int i = 0; i < n_row; i++)
525  {
526  for (int j = m_row_start[i]; j < m_row_start[i + 1]; j++)
527  {
528  if (m_column_index[j] < i)
529  {
530  l_nz++;
531  }
532  else
533  {
534  u_nz++;
535  }
536  }
537  }
538 
539  // resize vectors to store the data for the lower prior to building the
540  // matrices
541  L_row_start.resize(n_row + 1);
542  L_row_entry.resize(l_nz);
543 
544  // and the upper matrix
545  U_row_start.resize(n_row + 1);
546  U_row_entry.resize(u_nz);
547 
548  // set first column pointers to zero
549  L_row_start[0] = 0;
550  U_row_start[0] = 0;
551 
552  // split the matrix into L and U
553  for (int i = 0; i < n_row; i++)
554  {
555  L_row_start[i + 1] = L_row_start[i];
556  U_row_start[i + 1] = U_row_start[i];
557  for (int j = m_row_start[i]; j < m_row_start[i + 1]; j++)
558  {
559  if (m_column_index[j] < i)
560  {
561  int k = L_row_start[i + 1]++;
562  L_row_entry[k].value() = m_value[j];
563  L_row_entry[k].index() = m_column_index[j];
564  }
565  else
566  {
567  int k = U_row_start[i + 1]++;
568  U_row_entry[k].value() = m_value[j];
569  U_row_entry[k].index() = m_column_index[j];
570  }
571  }
572  }
573 
574 
575  // factorise matrix
576  unsigned i, j, pn, qn, rn;
577  pn = 0;
578  qn = 0;
579  rn = 0;
580  double multiplier;
581  for (i = 1; i < static_cast<unsigned>(n_row); i++)
582  {
583  for (j = L_row_start[i]; j < L_row_start[i + 1]; j++)
584  {
585  pn = U_row_start[L_row_entry[j].index()];
586  multiplier = (L_row_entry[j].value() /= U_row_entry[pn].value());
587  qn = j + 1;
588  rn = U_row_start[i];
589  for (pn++; pn < U_row_start[L_row_entry[j].index() + 1] &&
590  U_row_entry[pn].index() < i;
591  pn++)
592  {
593  while (qn < L_row_start[i + 1] &&
594  L_row_entry[qn].index() < U_row_entry[pn].index())
595  qn++;
596  if (qn < L_row_start[i + 1] &&
597  U_row_entry[pn].index() == L_row_entry[qn].index())
598  L_row_entry[qn].value() -= multiplier * U_row_entry[pn].value();
599  }
600  for (; pn < U_row_start[L_row_entry[j].index() + 1]; pn++)
601  {
602  while (rn < U_row_start[i + 1] &&
603  U_row_entry[rn].index() < U_row_entry[pn].index())
604  rn++;
605  if (rn < U_row_start[i + 1] &&
606  U_row_entry[pn].index() == U_row_entry[rn].index())
607  U_row_entry[rn].value() -= multiplier * U_row_entry[pn].value();
608  }
609  }
610  }
611 
612  // if we built the global matrix then delete it
613  if (built_global)
614  {
615  delete cr_matrix_pt;
616  }
617  }
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
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::CRDoubleMatrix::column_index(), oomph::DistributableLinearAlgebraObject::distributed(), oomph::DistributableLinearAlgebraObject::distribution_pt(), oomph::CRDoubleMatrix::global_matrix(), i, j, k, oomph::Preconditioner::matrix_pt(), Global_Physical_Variables::multiplier(), oomph::CRDoubleMatrix::nrow(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, oomph::CRDoubleMatrix::row_start(), Eigen::value, and oomph::CRDoubleMatrix::value().

Member Data Documentation

◆ L_row_entry

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

◆ L_row_start

Row start for lower triangular matrix.

◆ U_row_entry

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

◆ U_row_start

Row start for upper triangular matrix.


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