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// Version 1.0; svn revision $LastChangedRevision$
7 //LIC//
8 //LIC// $LastChangedDate$
9 //LIC//
10 //LIC// Copyright (C) 2006-2016 Matthias Heil and Andrew Hazel
11 //LIC//
12 //LIC// This library is free software; you can redistribute it and/or
13 //LIC// modify it under the terms of the GNU Lesser General Public
14 //LIC// License as published by the Free Software Foundation; either
15 //LIC// version 2.1 of the License, or (at your option) any later version.
16 //LIC//
17 //LIC// This library is distributed in the hope that it will be useful,
18 //LIC// but WITHOUT ANY WARRANTY; without even the implied warranty of
19 //LIC// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 //LIC// Lesser General Public License for more details.
21 //LIC//
22 //LIC// You should have received a copy of the GNU Lesser General Public
23 //LIC// License along with this library; if not, write to the Free Software
24 //LIC// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 //LIC// 02110-1301 USA.
26 //LIC//
27 //LIC// The authors may be contacted at oomph-lib@maths.man.ac.uk.
28 //LIC//
29 //LIC//====================================================================
30 //Include guards
31 #ifndef OOMPH_MATRIX_VECTOR_PRODUCT_HEADER
32 #define OOMPH_MATRIX_VECTOR_PRODUCT_HEADER
33 
34 
35 // Config header generated by autoconfig
36 #ifdef HAVE_CONFIG_H
37 #include <oomph-lib-config.h>
38 #endif
39 
40 #include "matrices.h"
42 #ifdef OOMPH_HAS_TRILINOS
43 #include "trilinos_helpers.h"
44 #endif
45 
46 namespace oomph {
47 
48 
49 //=============================================================================
50 /// \short Matrix vector product helper class - primarily a wrapper to
51 /// Trilinos's Epetra matrix vector product methods. This allows the
52 /// epetra matrix to be assembled once and the matrix vector product to be
53 /// performed many times.
54 //=============================================================================
56  {
57 
58  public:
59 
60  /// \short Constructor
62  {
63  // null pointers
64 #ifdef OOMPH_HAS_TRILINOS
65  Epetra_matrix_pt = 0;
66 #endif
67  Oomph_matrix_pt = 0;
69  }
70 
71  /// Broken copy constructor
73  {
74  BrokenCopy::broken_copy("MatrixVectorProduct");
75  }
76 
77  /// Broken assignment operator
79  {
80  BrokenCopy::broken_assign("MatrixVectorProduct");
81  }
82 
83  /// \short Destructor
85  {
86  this->clean_up_memory();
87  }
88 
89  /// \short clear the memory
91  {
92 #ifdef OOMPH_HAS_TRILINOS
93  delete Epetra_matrix_pt;
94  Epetra_matrix_pt = 0;
95 #endif
96  delete Oomph_matrix_pt;
97  Oomph_matrix_pt = 0;
100  }
101 
102  /// \short Setup the matrix vector product operator.
103  /// WARNING: This class is wrapper to Trilinos Epetra matrix vector
104  /// multiply methods, if Trilinos is not installed then this class will
105  /// function as expected, but there will be no computational speed gain.
106  /// By default the Epetra_CrsMatrix::multiply(...) are employed.
107  /// The optional argument col_dist_pt is the distribution of:
108  /// x if using multiply(...) or y if using multiply_transpose(...)
109  /// where this is A x = y. By default, this is assumed to the uniformly
110  /// distributed based on matrix_pt->ncol().
111  void setup(CRDoubleMatrix* matrix_pt,
112  const LinearAlgebraDistribution* col_dist_pt=0);
113 
114  /// \short Apply the operator to the vector x and return the result in
115  /// the vector y
116  void multiply(const DoubleVector& x, DoubleVector& y) const;
117 
118  /// \short Apply the transpose of the operator to the vector x and return
119  /// the result in the vector y
120  void multiply_transpose(const DoubleVector& x, DoubleVector& y) const;
121 
122  /// Access function to the number of columns.
123  const unsigned& ncol() const
124  {
125  return Ncol;
126  }
127 
128  private:
129 
130 #ifdef OOMPH_HAS_TRILINOS
131  /// Helper function for multiply(...)
133  (const DoubleVector& x, DoubleVector& y) const;
134 
135  /// Helper function for multiply_transpose(...)
137  (const DoubleVector& x, DoubleVector& y) const;
138 
139  /// \short The Epetra version of the matrix
140  Epetra_CrsMatrix* Epetra_matrix_pt;
141 #endif
142 
143  /// \short boolean indicating whether we are using trilinos to perform
144  /// matvec
146 
147  /// \short an oomph-lib matrix
149 
150  /// \short The distribution of: x if using multiply(...) or y
151  /// if using multiply_transpose(...) where this is A x = y.
153 
154  /// number of columns of the matrix
155  unsigned Ncol;
156  };
157 }
158 #endif
void broken_copy(const std::string &class_name)
Issue error message and terminate execution.
unsigned Ncol
number of columns of the matrix
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...
LinearAlgebraDistribution * Column_distribution_pt
The distribution of: x if using multiply(...) or y if using multiply_transpose(...) where this is A x = y.
const unsigned & ncol() const
Access function to the number of columns.
MatrixVectorProduct(const MatrixVectorProduct &)
Broken copy constructor.
Describes the distribution of a distributable linear algebra type object. Typically this is a contain...
Base class for any linear algebra object that is distributable. Just contains storage for the LinearA...
Epetra_CrsMatrix * Epetra_matrix_pt
The Epetra version of the matrix.
void operator=(const MatrixVectorProduct &)
Broken assignment operator.
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...
bool Using_trilinos
boolean indicating whether we are using trilinos to perform matvec
void trilinos_multiply_helper(const DoubleVector &x, DoubleVector &y) const
Helper function for multiply(...)
void broken_assign(const std::string &class_name)
Issue error message and terminate execution.
void trilinos_multiply_transpose_helper(const DoubleVector &x, DoubleVector &y) const
Helper function for multiply_transpose(...)
CRDoubleMatrix * Oomph_matrix_pt
an oomph-lib matrix
Matrix vector product helper class - primarily a wrapper to Trilinos&#39;s Epetra matrix vector product m...
A vector in the mathematical sense, initially developed for linear algebra type applications. If MPI then this vector can be distributed - its distribution is described by the LinearAlgebraDistribution object at Distribution_pt. Data is stored in a C-style pointer vector (double*)
Definition: double_vector.h:61
void multiply(const DoubleVector &x, DoubleVector &y) const
Apply the operator to the vector x and return the result in the vector y.
void clean_up_memory()
clear the memory
A class for compressed row matrices. This is a distributable object.
Definition: matrices.h:872