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
About
People
Contact/Get involved
Publications
Acknowledgements
Copyright
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-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
"
36
#include "
linear_algebra_distribution.h
"
37
#ifdef OOMPH_HAS_TRILINOS
38
#include "
trilinos_helpers.h
"
39
#endif
40
41
namespace
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
//=============================================================================
49
class
MatrixVectorProduct
:
public
DistributableLinearAlgebraObject
50
{
51
public
:
52
/// Constructor
53
MatrixVectorProduct
()
54
{
55
// null pointers
56
#ifdef OOMPH_HAS_TRILINOS
57
Epetra_matrix_pt
= 0;
58
#endif
59
Oomph_matrix_pt
= 0;
60
Column_distribution_pt
= 0;
61
}
62
63
/// Broken copy constructor
64
MatrixVectorProduct
(
const
MatrixVectorProduct
&) =
delete
;
65
66
/// Broken assignment operator
67
void
operator=
(
const
MatrixVectorProduct
&) =
delete
;
68
69
/// Destructor
70
~MatrixVectorProduct
()
71
{
72
this->
clean_up_memory
();
73
}
74
75
/// clear the memory
76
void
clean_up_memory
()
77
{
78
#ifdef OOMPH_HAS_TRILINOS
79
delete
Epetra_matrix_pt
;
80
Epetra_matrix_pt
= 0;
81
#endif
82
delete
Oomph_matrix_pt
;
83
Oomph_matrix_pt
= 0;
84
delete
Column_distribution_pt
;
85
Column_distribution_pt
= 0;
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,
98
const
LinearAlgebraDistribution
*
col_dist_pt
= 0);
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(...)
120
void
trilinos_multiply_transpose_helper
(
const
DoubleVector
& x,
121
DoubleVector
& y)
const
;
122
123
/// The Epetra version of the matrix
124
Epetra_CrsMatrix
*
Epetra_matrix_pt
;
125
#endif
126
127
/// boolean indicating whether we are using trilinos to perform
128
/// matvec
129
bool
Using_trilinos
;
130
131
/// an oomph-lib matrix
132
CRDoubleMatrix
*
Oomph_matrix_pt
;
133
134
/// The distribution of: x if using multiply(...) or y
135
/// if using multiply_transpose(...) where this is A x = y.
136
LinearAlgebraDistribution
*
Column_distribution_pt
;
137
138
/// number of columns of the matrix
139
unsigned
Ncol
;
140
};
141
}
// namespace oomph
142
#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:50
oomph::MatrixVectorProduct::Epetra_matrix_pt
Epetra_CrsMatrix * Epetra_matrix_pt
The Epetra version of the matrix.
Definition
matrix_vector_product.h:124
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:76
oomph::MatrixVectorProduct::Oomph_matrix_pt
CRDoubleMatrix * Oomph_matrix_pt
an oomph-lib matrix
Definition
matrix_vector_product.h:132
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:136
oomph::MatrixVectorProduct::ncol
const unsigned & ncol() const
Access function to the number of columns.
Definition
matrix_vector_product.h:109
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:129
oomph::MatrixVectorProduct::~MatrixVectorProduct
~MatrixVectorProduct()
Destructor.
Definition
matrix_vector_product.h:70
oomph::MatrixVectorProduct::Ncol
unsigned Ncol
number of columns of the matrix
Definition
matrix_vector_product.h:139
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:53
oomph::MatrixVectorProduct::operator=
void operator=(const MatrixVectorProduct &)=delete
Broken assignment operator.
oomph::TAdvectionDiffusionReactionElement
TAdvectionDiffusionReactionElement<NREAGENT,DIM,NNODE_1D> elements are isoparametric triangular DIM-d...
Definition
Tadvection_diffusion_reaction_elements.h:66
linear_algebra_distribution.h
matrices.h
oomph
DRAIG: Change all instances of (SPATIAL_DIM) to (DIM-1).
Definition
advection_diffusion_elements.cc:30
trilinos_helpers.h