Toggle navigation
Documentation
Big picture
The finite element method
The data structure
Not-so-quick guide
Optimisation
Order of action functions
Example codes and tutorials
List of example codes and tutorials
Meshing
Solvers
MPI parallel processing
Post-processing/visualisation
Other
Change log
Creating documentation
Coding conventions
Index
FAQ
Installation
Installation guide
Copyright
About
People
Contact/Get involved
Publications
Acknowledgements
Picture show
Go
src
generic
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
"
37
#include "
linear_algebra_distribution.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
//=============================================================================
50
class
MatrixVectorProduct
:
public
DistributableLinearAlgebraObject
51
{
52
public
:
53
/// Constructor
54
MatrixVectorProduct
()
55
{
56
// null pointers
57
#ifdef OOMPH_HAS_TRILINOS
58
Epetra_matrix_pt
= 0;
59
#endif
60
Oomph_matrix_pt
= 0;
61
Column_distribution_pt
= 0;
62
}
63
64
/// Broken copy constructor
65
MatrixVectorProduct
(
const
MatrixVectorProduct
&) =
delete
;
66
67
/// Broken assignment operator
68
void
operator=
(
const
MatrixVectorProduct
&) =
delete
;
69
70
/// Destructor
71
~MatrixVectorProduct
()
72
{
73
this->
clean_up_memory
();
74
}
75
76
/// clear the memory
77
void
clean_up_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;
85
delete
Column_distribution_pt
;
86
Column_distribution_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(...)
121
void
trilinos_multiply_transpose_helper
(
const
DoubleVector
& x,
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
130
bool
Using_trilinos
;
131
132
/// an oomph-lib matrix
133
CRDoubleMatrix
*
Oomph_matrix_pt
;
134
135
/// The distribution of: x if using multiply(...) or y
136
/// if using multiply_transpose(...) where this is A x = y.
137
LinearAlgebraDistribution
*
Column_distribution_pt
;
138
139
/// number of columns of the matrix
140
unsigned
Ncol
;
141
};
142
}
// namespace oomph
143
#endif
oomph::CRDoubleMatrix
A class for compressed row matrices. This is a distributable object.
Definition:
matrices.h:888
oomph::DistributableLinearAlgebraObject
Base class for any linear algebra object that is distributable. Just contains storage for the LinearA...
Definition:
linear_algebra_distribution.h:435
oomph::DoubleVector
A vector in the mathematical sense, initially developed for linear algebra type applications....
Definition:
double_vector.h:58
oomph::LinearAlgebraDistribution
Describes the distribution of a distributable linear algebra type object. Typically this is a contain...
Definition:
linear_algebra_distribution.h:64
oomph::MatrixVectorProduct
Matrix vector product helper class - primarily a wrapper to Trilinos's Epetra matrix vector product m...
Definition:
matrix_vector_product.h:51
oomph::MatrixVectorProduct::Epetra_matrix_pt
Epetra_CrsMatrix * Epetra_matrix_pt
The Epetra version of the matrix.
Definition:
matrix_vector_product.h:125
oomph::MatrixVectorProduct::trilinos_multiply_transpose_helper
void trilinos_multiply_transpose_helper(const DoubleVector &x, DoubleVector &y) const
Helper function for multiply_transpose(...)
Definition:
matrix_vector_product.cc:287
oomph::MatrixVectorProduct::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.
Definition:
matrix_vector_product.cc:177
oomph::MatrixVectorProduct::MatrixVectorProduct
MatrixVectorProduct(const MatrixVectorProduct &)=delete
Broken copy constructor.
oomph::MatrixVectorProduct::clean_up_memory
void clean_up_memory()
clear the memory
Definition:
matrix_vector_product.h:77
oomph::MatrixVectorProduct::Oomph_matrix_pt
CRDoubleMatrix * Oomph_matrix_pt
an oomph-lib matrix
Definition:
matrix_vector_product.h:133
oomph::MatrixVectorProduct::trilinos_multiply_helper
void trilinos_multiply_helper(const DoubleVector &x, DoubleVector &y) const
Helper function for multiply(...)
Definition:
matrix_vector_product.cc:242
oomph::MatrixVectorProduct::Column_distribution_pt
LinearAlgebraDistribution * Column_distribution_pt
The distribution of: x if using multiply(...) or y if using multiply_transpose(......
Definition:
matrix_vector_product.h:137
oomph::MatrixVectorProduct::ncol
const unsigned & ncol() const
Access function to the number of columns.
Definition:
matrix_vector_product.h:110
oomph::MatrixVectorProduct::multiply
void multiply(const DoubleVector &x, DoubleVector &y) const
Apply the operator to the vector x and return the result in the vector y.
Definition:
matrix_vector_product.cc:108
oomph::MatrixVectorProduct::Using_trilinos
bool Using_trilinos
boolean indicating whether we are using trilinos to perform matvec
Definition:
matrix_vector_product.h:130
oomph::MatrixVectorProduct::~MatrixVectorProduct
~MatrixVectorProduct()
Destructor.
Definition:
matrix_vector_product.h:71
oomph::MatrixVectorProduct::Ncol
unsigned Ncol
number of columns of the matrix
Definition:
matrix_vector_product.h:140
oomph::MatrixVectorProduct::setup
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...
Definition:
matrix_vector_product.cc:41
oomph::MatrixVectorProduct::MatrixVectorProduct
MatrixVectorProduct()
Constructor.
Definition:
matrix_vector_product.h:54
oomph::MatrixVectorProduct::operator=
void operator=(const MatrixVectorProduct &)=delete
Broken assignment operator.
linear_algebra_distribution.h
matrices.h
oomph
//////////////////////////////////////////////////////////////////// ////////////////////////////////...
Definition:
advection_diffusion_elements.cc:30
trilinos_helpers.h