matrix_vector_product.h
Go to the documentation of this file.
1 // LIC// ====================================================================
2 // LIC// This file forms part of oomph-lib, the object-oriented,
3 // LIC// multi-physics finite-element library, available
4 // LIC// at http://www.oomph-lib.org.
5 // LIC//
6 // LIC// Copyright (C) 2006-2023 Matthias Heil and Andrew Hazel
7 // LIC//
8 // LIC// This library is free software; you can redistribute it and/or
9 // LIC// modify it under the terms of the GNU Lesser General Public
10 // LIC// License as published by the Free Software Foundation; either
11 // LIC// version 2.1 of the License, or (at your option) any later version.
12 // LIC//
13 // LIC// This library is distributed in the hope that it will be useful,
14 // LIC// but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // LIC// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // LIC// Lesser General Public License for more details.
17 // LIC//
18 // LIC// You should have received a copy of the GNU Lesser General Public
19 // LIC// License along with this library; if not, write to the Free Software
20 // LIC// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 // LIC// 02110-1301 USA.
22 // LIC//
23 // LIC// The authors may be contacted at oomph-lib@maths.man.ac.uk.
24 // LIC//
25 // LIC//====================================================================
26 // Include guards
27 #ifndef OOMPH_MATRIX_VECTOR_PRODUCT_HEADER
28 #define OOMPH_MATRIX_VECTOR_PRODUCT_HEADER
29 
30 
31 // Config header generated by autoconfig
32 #ifdef HAVE_CONFIG_H
33 #include <oomph-lib-config.h>
34 #endif
35 
36 #include "matrices.h"
38 #ifdef OOMPH_HAS_TRILINOS
39 #include "trilinos_helpers.h"
40 #endif
41 
42 namespace oomph
43 {
44  //=============================================================================
45  /// Matrix vector product helper class - primarily a wrapper to
46  /// Trilinos's Epetra matrix vector product methods. This allows the
47  /// epetra matrix to be assembled once and the matrix vector product to be
48  /// performed many times.
49  //=============================================================================
51  {
52  public:
53  /// Constructor
55  {
56  // null pointers
57 #ifdef OOMPH_HAS_TRILINOS
58  Epetra_matrix_pt = 0;
59 #endif
60  Oomph_matrix_pt = 0;
62  }
63 
64  /// Broken copy constructor
66 
67  /// Broken assignment operator
68  void operator=(const MatrixVectorProduct&) = delete;
69 
70  /// Destructor
72  {
73  this->clean_up_memory();
74  }
75 
76  /// 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  }
88 
89  /// Setup the matrix vector product operator.
90  /// WARNING: This class is wrapper to Trilinos Epetra matrix vector
91  /// multiply methods, if Trilinos is not installed then this class will
92  /// function as expected, but there will be no computational speed gain.
93  /// By default the Epetra_CrsMatrix::multiply(...) are employed.
94  /// The optional argument col_dist_pt is the distribution of:
95  /// x if using multiply(...) or y if using multiply_transpose(...)
96  /// where this is A x = y. By default, this is assumed to the uniformly
97  /// distributed based on matrix_pt->ncol().
98  void setup(CRDoubleMatrix* matrix_pt,
99  const LinearAlgebraDistribution* col_dist_pt = 0);
100 
101  /// Apply the operator to the vector x and return the result in
102  /// the vector y
103  void multiply(const DoubleVector& x, DoubleVector& y) const;
104 
105  /// Apply the transpose of the operator to the vector x and return
106  /// the result in the vector y
107  void multiply_transpose(const DoubleVector& x, DoubleVector& y) const;
108 
109  /// Access function to the number of columns.
110  const unsigned& ncol() const
111  {
112  return Ncol;
113  }
114 
115  private:
116 #ifdef OOMPH_HAS_TRILINOS
117  /// Helper function for multiply(...)
118  void trilinos_multiply_helper(const DoubleVector& x, DoubleVector& y) const;
119 
120  /// Helper function for multiply_transpose(...)
122  DoubleVector& y) const;
123 
124  /// The Epetra version of the matrix
125  Epetra_CrsMatrix* Epetra_matrix_pt;
126 #endif
127 
128  /// boolean indicating whether we are using trilinos to perform
129  /// matvec
131 
132  /// an oomph-lib matrix
134 
135  /// The distribution of: x if using multiply(...) or y
136  /// if using multiply_transpose(...) where this is A x = y.
138 
139  /// number of columns of the matrix
140  unsigned Ncol;
141  };
142 } // namespace oomph
143 #endif
A class for compressed row matrices. This is a distributable object.
Definition: matrices.h:888
Base class for any linear algebra object that is distributable. Just contains storage for the LinearA...
A vector in the mathematical sense, initially developed for linear algebra type applications....
Definition: double_vector.h:58
Describes the distribution of a distributable linear algebra type object. Typically this is a contain...
Matrix vector product helper class - primarily a wrapper to Trilinos's Epetra matrix vector product m...
Epetra_CrsMatrix * Epetra_matrix_pt
The Epetra version of the matrix.
void trilinos_multiply_transpose_helper(const DoubleVector &x, DoubleVector &y) const
Helper function for multiply_transpose(...)
void 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.
MatrixVectorProduct(const MatrixVectorProduct &)=delete
Broken copy constructor.
void clean_up_memory()
clear the memory
CRDoubleMatrix * Oomph_matrix_pt
an oomph-lib matrix
void trilinos_multiply_helper(const DoubleVector &x, DoubleVector &y) const
Helper function for multiply(...)
LinearAlgebraDistribution * Column_distribution_pt
The distribution of: x if using multiply(...) or y if using multiply_transpose(......
const unsigned & ncol() const
Access function to the number of columns.
void multiply(const DoubleVector &x, DoubleVector &y) const
Apply the operator to the vector x and return the result in the vector y.
bool Using_trilinos
boolean indicating whether we are using trilinos to perform matvec
unsigned Ncol
number of columns of the matrix
void 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 ve...
void operator=(const MatrixVectorProduct &)=delete
Broken assignment operator.
//////////////////////////////////////////////////////////////////// ////////////////////////////////...