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-2025 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// Config header
31#ifdef HAVE_CONFIG_H
32#include <oomph-lib-config.h>
33#endif
34
35#include "matrices.h"
37#ifdef OOMPH_HAS_TRILINOS
38#include "trilinos_helpers.h"
39#endif
40
41namespace oomph
42{
43 //=============================================================================
44 /// Matrix vector product helper class - primarily a wrapper to
45 /// Trilinos's Epetra matrix vector product methods. This allows the
46 /// epetra matrix to be assembled once and the matrix vector product to be
47 /// performed many times.
48 //=============================================================================
50 {
51 public:
52 /// Constructor
54 {
55 // null pointers
56#ifdef OOMPH_HAS_TRILINOS
58#endif
61 }
62
63 /// Broken copy constructor
65
66 /// Broken assignment operator
67 void operator=(const MatrixVectorProduct&) = delete;
68
69 /// Destructor
71 {
72 this->clean_up_memory();
73 }
74
75 /// clear the memory
77 {
78#ifdef OOMPH_HAS_TRILINOS
79 delete Epetra_matrix_pt;
81#endif
82 delete Oomph_matrix_pt;
86 }
87
88 /// Setup the matrix vector product operator.
89 /// WARNING: This class is wrapper to Trilinos Epetra matrix vector
90 /// multiply methods, if Trilinos is not installed then this class will
91 /// function as expected, but there will be no computational speed gain.
92 /// By default the Epetra_CrsMatrix::multiply(...) are employed.
93 /// The optional argument col_dist_pt is the distribution of:
94 /// x if using multiply(...) or y if using multiply_transpose(...)
95 /// where this is A x = y. By default, this is assumed to the uniformly
96 /// distributed based on matrix_pt->ncol().
97 void setup(CRDoubleMatrix* matrix_pt,
99
100 /// Apply the operator to the vector x and return the result in
101 /// the vector y
102 void multiply(const DoubleVector& x, DoubleVector& y) const;
103
104 /// Apply the transpose of the operator to the vector x and return
105 /// the result in the vector y
106 void multiply_transpose(const DoubleVector& x, DoubleVector& y) const;
107
108 /// Access function to the number of columns.
109 const unsigned& ncol() const
110 {
111 return Ncol;
112 }
113
114 private:
115#ifdef OOMPH_HAS_TRILINOS
116 /// Helper function for multiply(...)
117 void trilinos_multiply_helper(const DoubleVector& x, DoubleVector& y) const;
118
119 /// Helper function for multiply_transpose(...)
121 DoubleVector& y) const;
122
123 /// The Epetra version of the matrix
125#endif
126
127 /// boolean indicating whether we are using trilinos to perform
128 /// matvec
130
131 /// an oomph-lib matrix
133
134 /// The distribution of: x if using multiply(...) or y
135 /// if using multiply_transpose(...) where this is A x = y.
137
138 /// number of columns of the matrix
139 unsigned Ncol;
140 };
141} // namespace oomph
142#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....
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.
TAdvectionDiffusionReactionElement<NREAGENT,DIM,NNODE_1D> elements are isoparametric triangular DIM-d...
DRAIG: Change all instances of (SPATIAL_DIM) to (DIM-1).