oomph::MatrixVectorProduct Class Reference

#include <matrix_vector_product.h>

+ Inheritance diagram for oomph::MatrixVectorProduct:

Public Member Functions

 MatrixVectorProduct ()
 Constructor. More...
 
 MatrixVectorProduct (const MatrixVectorProduct &)=delete
 Broken copy constructor. More...
 
void operator= (const MatrixVectorProduct &)=delete
 Broken assignment operator. More...
 
 ~MatrixVectorProduct ()
 Destructor. More...
 
void clean_up_memory ()
 clear the memory More...
 
void setup (CRDoubleMatrix *matrix_pt, const LinearAlgebraDistribution *col_dist_pt=0)
 
void multiply (const DoubleVector &x, DoubleVector &y) const
 
void multiply_transpose (const DoubleVector &x, DoubleVector &y) const
 
const unsignedncol () const
 Access function to the number of columns. More...
 
- 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

bool Using_trilinos
 
CRDoubleMatrixOomph_matrix_pt
 an oomph-lib matrix More...
 
LinearAlgebraDistributionColumn_distribution_pt
 
unsigned Ncol
 number of columns of the matrix More...
 

Additional Inherited Members

- Protected Member Functions inherited from oomph::DistributableLinearAlgebraObject
void clear_distribution ()
 

Detailed Description

Matrix vector product helper class - primarily a wrapper to Trilinos's Epetra matrix vector product methods. This allows the epetra matrix to be assembled once and the matrix vector product to be performed many times.

Constructor & Destructor Documentation

◆ MatrixVectorProduct() [1/2]

oomph::MatrixVectorProduct::MatrixVectorProduct ( )
inline

Constructor.

55  {
56  // null pointers
57 #ifdef OOMPH_HAS_TRILINOS
58  Epetra_matrix_pt = 0;
59 #endif
60  Oomph_matrix_pt = 0;
62  }
CRDoubleMatrix * Oomph_matrix_pt
an oomph-lib matrix
Definition: matrix_vector_product.h:133
LinearAlgebraDistribution * Column_distribution_pt
Definition: matrix_vector_product.h:137

References Column_distribution_pt, and Oomph_matrix_pt.

◆ MatrixVectorProduct() [2/2]

oomph::MatrixVectorProduct::MatrixVectorProduct ( const MatrixVectorProduct )
delete

Broken copy constructor.

◆ ~MatrixVectorProduct()

oomph::MatrixVectorProduct::~MatrixVectorProduct ( )
inline

Destructor.

72  {
73  this->clean_up_memory();
74  }
void clean_up_memory()
clear the memory
Definition: matrix_vector_product.h:77

References clean_up_memory().

Member Function Documentation

◆ clean_up_memory()

void oomph::MatrixVectorProduct::clean_up_memory ( )
inline

clear the memory

78  {
79 #ifdef OOMPH_HAS_TRILINOS
80  delete Epetra_matrix_pt;
81  Epetra_matrix_pt = 0;
82 #endif
83  delete Oomph_matrix_pt;
84  Oomph_matrix_pt = 0;
87  }

References Column_distribution_pt, and Oomph_matrix_pt.

Referenced by oomph::PseudoElasticFSIPreconditioner::clean_up_memory(), setup(), and ~MatrixVectorProduct().

◆ multiply()

void oomph::MatrixVectorProduct::multiply ( const DoubleVector x,
DoubleVector y 
) const

Apply the operator to the vector x and return the result in the vector y

110  {
111 #ifdef PARANOID
112  // check that the distribution of x is setup
113  if (!x.built())
114  {
115  std::ostringstream error_message_stream;
116  error_message_stream << "The distribution of the vector x must be setup";
117  throw OomphLibError(error_message_stream.str(),
120  }
121 
122  // Check to see if the distribution of the matrix column is the same as the
123  // distribution of the vector to be operated on.
124  if (*this->Column_distribution_pt != *x.distribution_pt())
125  {
126  std::ostringstream error_message_stream;
127  error_message_stream
128  << "The distribution of the x Vector is not the same as"
129  << " the column distribution.";
130  throw OomphLibError(error_message_stream.str(),
133  }
134 
135  // if y is setup then it should have the same distribution as
136  // the matrix used to set this up.
137  if (y.built())
138  {
139  if (!(*y.distribution_pt() == *this->distribution_pt()))
140  {
141  std::ostringstream error_message_stream;
142  error_message_stream
143  << "The y vector is setup and therefore must have the same "
144  << "distribution as the matrix used to set up the "
145  "MatrixVectorProduct";
146  throw OomphLibError(error_message_stream.str(),
149  }
150  }
151 #endif
152 
153  // if y is not setup then setup the distribution
154  if (!y.built())
155  {
156  // Resize and initialize the solution vector
157  y.build(this->distribution_pt(), 0.0);
158  }
159 
160  // apply the operator
161  if (Using_trilinos)
162  {
163 #ifdef OOMPH_HAS_TRILINOS
164  trilinos_multiply_helper(x, y);
165 #endif
166  }
167  else
168  {
170  }
171  }
void multiply(const DoubleVector &x, DoubleVector &soln) const
Multiply the matrix by the vector x: soln=Ax.
Definition: matrices.cc:1782
LinearAlgebraDistribution * distribution_pt() const
access to the LinearAlgebraDistribution
Definition: linear_algebra_distribution.h:457
bool Using_trilinos
Definition: matrix_vector_product.h:130
Scalar * y
Definition: level1_cplx_impl.h:128
list x
Definition: plotDoE.py:28
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86

References Column_distribution_pt, oomph::DistributableLinearAlgebraObject::distribution_pt(), oomph::CRDoubleMatrix::multiply(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, Oomph_matrix_pt, Using_trilinos, plotDoE::x, and y.

Referenced by oomph::FSIPreconditioner::preconditioner_solve(), oomph::PseudoElasticFSIPreconditioner::preconditioner_solve(), oomph::PressureBasedSolidLSCPreconditioner::preconditioner_solve(), and oomph::SpaceTimeNavierStokesSubsidiaryPreconditioner::preconditioner_solve().

◆ multiply_transpose()

void oomph::MatrixVectorProduct::multiply_transpose ( const DoubleVector x,
DoubleVector y 
) const

Apply the transpose of the operator to the vector x and return the result in the vector y

179  {
180 #ifdef PARANOID
181  // check that the distribution of x is setup
182  if (!x.built())
183  {
184  std::ostringstream error_message_stream;
185  error_message_stream << "The distribution of the vector x must be setup";
186  throw OomphLibError(error_message_stream.str(),
189  }
190  // Check to see if x.size() = ncol()
191  if (*this->distribution_pt() != *x.distribution_pt())
192  {
193  std::ostringstream error_message_stream;
194  error_message_stream
195  << "This class assumes that the y vector has a uniform "
196  << "distributed distribution.";
197  throw OomphLibError(error_message_stream.str(),
200  }
201  // if y is setup then it should have the same distribution as x
202  if (y.built())
203  {
204  if (!(*y.distribution_pt() == *this->Column_distribution_pt))
205  {
206  std::ostringstream error_message_stream;
207  error_message_stream
208  << "The y vector is setup and therefore must have the same "
209  << "distribution as the vector x";
210  throw OomphLibError(error_message_stream.str(),
213  }
214  }
215 #endif
216 
217  // if y is not setup then setup the distribution
218  if (!y.built())
219  {
220  // Resize and initialize the solution vector
221  y.build(this->Column_distribution_pt, 0.0);
222  }
223 
224  // apply the transpose operator
225  if (Using_trilinos)
226  {
227 #ifdef OOMPH_HAS_TRILINOS
228  trilinos_multiply_transpose_helper(x, y);
229 #endif
230  }
231  else
232  {
234  }
235  }
void multiply_transpose(const DoubleVector &x, DoubleVector &soln) const
Multiply the transposed matrix by the vector x: soln=A^T x.
Definition: matrices.cc:1882

References Column_distribution_pt, oomph::DistributableLinearAlgebraObject::distribution_pt(), oomph::CRDoubleMatrix::multiply_transpose(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, Oomph_matrix_pt, Using_trilinos, plotDoE::x, and y.

Referenced by oomph::PressureBasedSolidLSCPreconditioner::preconditioner_solve(), and oomph::SpaceTimeNavierStokesSubsidiaryPreconditioner::preconditioner_solve().

◆ ncol()

const unsigned& oomph::MatrixVectorProduct::ncol ( ) const
inline

Access function to the number of columns.

111  {
112  return Ncol;
113  }
unsigned Ncol
number of columns of the matrix
Definition: matrix_vector_product.h:140

References Ncol.

◆ operator=()

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

Broken assignment operator.

◆ setup()

void oomph::MatrixVectorProduct::setup ( CRDoubleMatrix matrix_pt,
const LinearAlgebraDistribution col_dist_pt = 0 
)

Setup the matrix vector product operator. WARNING: This class is wrapper to Trilinos Epetra matrix vector multiply methods, if Trilinos is not installed then this class will function as expected, but there will be no computational speed gain. By default the Epetra_CrsMatrix::multiply(...) are employed. The optional argument col_dist_pt is the distribution of: x if using multiply(...) or y if using multiply_transpose(...) where this is A x = y. By default, this is assumed to the uniformly distributed based on matrix_pt->ncol().

43  {
44  // clean memory
45  this->clean_up_memory();
46 
47  // (re)build distribution_pt
48  this->build_distribution(matrix_pt->distribution_pt());
49 
50  // store the number of columns
51  Ncol = matrix_pt->ncol();
52 
53  // determine whether we are using trilinos
54  Using_trilinos = false;
55 #ifdef OOMPH_HAS_TRILINOS
56 #ifdef OOMPH_HAS_MPI
58  {
59  Using_trilinos = true;
60  }
61 #else
62  Using_trilinos = true;
63 #endif
64 #endif
65 
66  // create the column distribution map, if a distribution is not provided,
67  // create a uniformly distributed based on matrix_pt->ncol().
68  // Otherwise, use the provided distribution.
69  if (col_dist_pt == 0)
70  {
71  Column_distribution_pt = new LinearAlgebraDistribution(
72  matrix_pt->distribution_pt()->communicator_pt(),
73  matrix_pt->ncol(),
74  matrix_pt->distribution_pt()->distributed());
75  }
76  else
77  {
78  Column_distribution_pt = new LinearAlgebraDistribution(col_dist_pt);
79  }
80 
81  // setup the operator
82  if (Using_trilinos)
83  {
84 #ifdef OOMPH_HAS_TRILINOS
85  double t_start = TimingHelpers::timer();
86  Epetra_matrix_pt =
88  matrix_pt, Column_distribution_pt);
89  double t_end = TimingHelpers::timer();
90  oomph_info << "Time to build epetra matrix [sec] : " << t_end - t_start
91  << std::endl;
92 #endif
93  }
94  else
95  {
96  double t_start = TimingHelpers::timer();
97  Oomph_matrix_pt = new CRDoubleMatrix(*matrix_pt);
98  double t_end = TimingHelpers::timer();
99  oomph_info << "Time to copy CRDoubleMatrix [sec] : " << t_end - t_start
100  << std::endl;
101  }
102  }
void build_distribution(const LinearAlgebraDistribution *const dist_pt)
Definition: linear_algebra_distribution.h:507
static bool mpi_has_been_initialised()
return true if MPI has been initialised
Definition: oomph_utilities.h:851
double timer()
returns the time in seconds after some point in past
Definition: oomph_utilities.cc:1295
Epetra_CrsMatrix * create_distributed_epetra_matrix(const CRDoubleMatrix *oomph_matrix_pt, const LinearAlgebraDistribution *dist_pt)
Definition: trilinos_helpers.cc:289
OomphInfo oomph_info
Definition: oomph_definitions.cc:319

References oomph::DistributableLinearAlgebraObject::build_distribution(), clean_up_memory(), Column_distribution_pt, oomph::LinearAlgebraDistribution::communicator_pt(), oomph::TrilinosEpetraHelpers::create_distributed_epetra_matrix(), oomph::LinearAlgebraDistribution::distributed(), oomph::DistributableLinearAlgebraObject::distribution_pt(), oomph::MPI_Helpers::mpi_has_been_initialised(), oomph::CRDoubleMatrix::ncol(), Ncol, oomph::oomph_info, Oomph_matrix_pt, oomph::TimingHelpers::timer(), and Using_trilinos.

Referenced by oomph::BlockPreconditioner< MATRIX >::setup_matrix_vector_product().

Member Data Documentation

◆ Column_distribution_pt

LinearAlgebraDistribution* oomph::MatrixVectorProduct::Column_distribution_pt
private

The distribution of: x if using multiply(...) or y if using multiply_transpose(...) where this is A x = y.

Referenced by clean_up_memory(), MatrixVectorProduct(), multiply(), multiply_transpose(), and setup().

◆ Ncol

unsigned oomph::MatrixVectorProduct::Ncol
private

number of columns of the matrix

Referenced by ncol(), and setup().

◆ Oomph_matrix_pt

CRDoubleMatrix* oomph::MatrixVectorProduct::Oomph_matrix_pt
private

◆ Using_trilinos

bool oomph::MatrixVectorProduct::Using_trilinos
private

boolean indicating whether we are using trilinos to perform matvec

Referenced by multiply(), multiply_transpose(), and setup().


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