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
sum_of_matrices.cc
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-2024 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
27
28
#include "
matrices.h
"
29
#include "
double_vector.h
"
30
#include "
sum_of_matrices.h
"
31
32
33
namespace
oomph
34
{
35
// =================================================================
36
/// Matrix-vector multiplication for a sumofmatrices class. Just
37
/// delegate each multiplication to the appropriate class then add up the
38
/// results.
39
// =================================================================
40
void
SumOfMatrices::multiply
(
const
DoubleVector
& x,
DoubleVector
&
soln
)
const
41
{
42
// We assume that appropriate checks and initialisation on x and soln are
43
// carried out within the individual matrix multiplys.
44
45
// Multiply for the main matrix
46
Main_matrix_pt
->
multiply
(x,
soln
);
47
48
// Now add contribution for the added matrices
49
for
(
unsigned
i_matrix
= 0;
i_matrix
<
Added_matrix_pt
.
size
();
i_matrix
++)
50
{
51
// If possible copy the matrix distribution, otherwise it isn't
52
// distributed so make a serial LinearAlgebraDistribution object.
53
LinearAlgebraDistribution
col_dist
,
row_dist
;
54
OomphCommunicator
serial_comm
;
// Serial communcator (does nothing)
55
col_dist
.build(&
serial_comm
,
added_matrix_pt
(
i_matrix
)->
ncol
(),
false
);
56
row_dist
.build(&
serial_comm
,
added_matrix_pt
(
i_matrix
)->
nrow
(),
false
);
57
58
// Create temporary output DoubleVector
59
DoubleVector
temp_soln
(
row_dist
);
60
61
// Create a const iterator for the map (faster than .find() or []
62
// access, const means can't change the map via the iterator).
63
std::map<unsigned, unsigned>::const_iterator
it
;
64
65
// Pull out the appropriate values into a temp vector
66
//??ds not parallel
67
DoubleVector
temp_x
(
col_dist
);
68
for
(
it
=
Col_map_pt
[
i_matrix
]->main_to_added_mapping_pt()->
begin
();
69
it
!=
Col_map_pt
[
i_matrix
]->main_to_added_mapping_pt()->
end
();
70
it
++)
71
{
72
temp_x
[
it
->second] = x[
it
->first];
73
}
74
75
// Perform the multiplication
76
Added_matrix_pt
[
i_matrix
]->multiply(
temp_x
,
temp_soln
);
77
78
// Add result to solution vector
79
//??ds not parallel
80
for
(
it
=
Row_map_pt
[
i_matrix
]->main_to_added_mapping_pt()->
begin
();
81
it
!=
Row_map_pt
[
i_matrix
]->main_to_added_mapping_pt()->
end
();
82
it
++)
83
{
84
soln
[
it
->first] +=
temp_soln
[
it
->second];
85
}
86
}
87
}
88
89
}
// namespace oomph
oomph::DoubleMatrixBase::multiply
virtual void multiply(const DoubleVector &x, DoubleVector &soln) const =0
Multiply the matrix by the vector x: soln=Ax.
oomph::DoubleVector
A vector in the mathematical sense, initially developed for linear algebra type applications....
Definition
double_vector.h:58
oomph::FiniteElement::size
double size() const
Calculate the size of the element (length, area, volume,...) in Eulerian computational coordinates....
Definition
elements.cc:4320
oomph::LinearAlgebraDistribution
Describes the distribution of a distributable linear algebra type object. Typically this is a contain...
Definition
linear_algebra_distribution.h:64
oomph::OomphCommunicator
An oomph-lib wrapper to the MPI_Comm communicator object. Just contains an MPI_Comm object (which is ...
Definition
communicator.h:54
oomph::SumOfMatrices::nrow
unsigned long nrow() const
Return the number of rows of the main matrix.
Definition
sum_of_matrices.h:501
oomph::SumOfMatrices::Added_matrix_pt
Vector< DoubleMatrixBase * > Added_matrix_pt
List of pointers to the matrices that are added to the main matrix.
Definition
sum_of_matrices.h:268
oomph::SumOfMatrices::Col_map_pt
Vector< const AddedMainNumberingLookup * > Col_map_pt
List of maps between col numbers of the main matrix and the added matrices.
Definition
sum_of_matrices.h:276
oomph::SumOfMatrices::Row_map_pt
Vector< const AddedMainNumberingLookup * > Row_map_pt
List of maps between row numbers of the main matrix and the added matrices.
Definition
sum_of_matrices.h:272
oomph::SumOfMatrices::ncol
unsigned long ncol() const
Return the number of columns of the main matrix.
Definition
sum_of_matrices.h:515
oomph::SumOfMatrices::multiply
void multiply(const DoubleVector &x, DoubleVector &soln) const
Multiply: just call multiply on each of the matrices and add up the results (with appropriate bookeep...
Definition
sum_of_matrices.cc:40
oomph::SumOfMatrices::added_matrix_pt
DoubleMatrixBase * added_matrix_pt(const unsigned &i) const
Access function for ith added matrix (main matrix not included in numbering).
Definition
sum_of_matrices.h:485
oomph::SumOfMatrices::Main_matrix_pt
DoubleMatrixBase * Main_matrix_pt
Pointer to the matrix which we are adding the others to.
Definition
sum_of_matrices.h:265
oomph::TAdvectionDiffusionReactionElement
//////////////////////////////////////////////////////////////////////
Definition
Tadvection_diffusion_reaction_elements.h:66
double_vector.h
matrices.h
oomph
//////////////////////////////////////////////////////////////////// ////////////////////////////////...
Definition
advection_diffusion_elements.cc:30
sum_of_matrices.h