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
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-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
27
28
#include "
matrices.h
"
29
#include "
double_vector.h
"
30
#include "
sum_of_matrices.h
"
31
32
namespace
oomph
33
{
34
// =================================================================
35
/// Matrix-vector multiplication for a sumofmatrices class. Just
36
/// delegate each multiplication to the appropriate class then add up the
37
/// results.
38
// =================================================================
39
void
SumOfMatrices::multiply
(
const
DoubleVector
& x,
DoubleVector
&
soln
)
const
40
{
41
// We assume that appropriate checks and initialisation on x and soln are
42
// carried out within the individual matrix multiplys.
43
44
// Multiply for the main matrix
45
Main_matrix_pt
->
multiply
(x,
soln
);
46
47
// Now add contribution for the added matrices
48
for
(
unsigned
i_matrix
= 0;
i_matrix
<
Added_matrix_pt
.
size
();
i_matrix
++)
49
{
50
// If possible copy the matrix distribution, otherwise it isn't
51
// distributed so make a serial LinearAlgebraDistribution object.
52
LinearAlgebraDistribution
col_dist
,
row_dist
;
53
OomphCommunicator
serial_comm
;
// Serial communcator (does nothing)
54
col_dist
.build(&
serial_comm
,
added_matrix_pt
(
i_matrix
)->
ncol
(),
false
);
55
row_dist
.build(&
serial_comm
,
added_matrix_pt
(
i_matrix
)->
nrow
(),
false
);
56
57
// Create temporary output DoubleVector
58
DoubleVector
temp_soln
(
row_dist
);
59
60
// Create a const iterator for the map (faster than .find() or []
61
// access, const means can't change the map via the iterator).
62
std::map<unsigned, unsigned>::const_iterator
it
;
63
64
// Pull out the appropriate values into a temp vector
65
//??ds not parallel
66
DoubleVector
temp_x
(
col_dist
);
67
for
(
it
=
Col_map_pt
[
i_matrix
]->main_to_added_mapping_pt()->
begin
();
68
it
!=
Col_map_pt
[
i_matrix
]->main_to_added_mapping_pt()->
end
();
69
it
++)
70
{
71
temp_x
[
it
->second] = x[
it
->first];
72
}
73
74
// Perform the multiplication
75
Added_matrix_pt
[
i_matrix
]->multiply(
temp_x
,
temp_soln
);
76
77
// Add result to solution vector
78
//??ds not parallel
79
for
(
it
=
Row_map_pt
[
i_matrix
]->main_to_added_mapping_pt()->
begin
();
80
it
!=
Row_map_pt
[
i_matrix
]->main_to_added_mapping_pt()->
end
();
81
it
++)
82
{
83
soln
[
it
->first] +=
temp_soln
[
it
->second];
84
}
85
}
86
}
87
88
}
// 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:39
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
TAdvectionDiffusionReactionElement<NREAGENT,DIM,NNODE_1D> elements are isoparametric triangular DIM-d...
Definition
Tadvection_diffusion_reaction_elements.h:66
double_vector.h
matrices.h
oomph
DRAIG: Change all instances of (SPATIAL_DIM) to (DIM-1).
Definition
advection_diffusion_elements.cc:30
sum_of_matrices.h