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-2022 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
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
33namespace 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 // =================================================================
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
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.
54 OomphCommunicator serial_comm; // Serial communcator (does nothing)
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);
70 it++)
71 {
72 temp_x[it->second] = x[it->first];
73 }
74
75 // Perform the multiplication
77
78 // Add result to solution vector
79 //??ds not parallel
82 it++)
83 {
84 soln[it->first] += temp_soln[it->second];
85 }
86 }
87 }
88
89} // namespace oomph
virtual void multiply(const DoubleVector &x, DoubleVector &soln) const =0
Multiply the matrix by the vector x: soln=Ax.
A vector in the mathematical sense, initially developed for linear algebra type applications....
Definition: double_vector.h:58
Describes the distribution of a distributable linear algebra type object. Typically this is a contain...
void build(const OomphCommunicator *const comm_pt, const unsigned &first_row, const unsigned &nrow_local, const unsigned &nrow=0)
Sets the distribution. Takes first_row, nrow_local and nrow as arguments. If nrow is not provided or ...
An oomph-lib wrapper to the MPI_Comm communicator object. Just contains an MPI_Comm object (which is ...
Definition: communicator.h:54
unsigned long nrow() const
Return the number of rows of the main matrix.
List of pointers to the matrices that are added to the main matrix.
Vector< const AddedMainNumberingLookup * > Col_map_pt
List of maps between col numbers of the main matrix and the added matrices.
Vector< const AddedMainNumberingLookup * > Row_map_pt
List of maps between row numbers of the main matrix and the added matrices.
unsigned long ncol() const
Return the number of columns of the main matrix.
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...
DoubleMatrixBase * added_matrix_pt(const unsigned &i) const
Access function for ith added matrix (main matrix not included in numbering).
DoubleMatrixBase * Main_matrix_pt
Pointer to the matrix which we are adding the others to.
//////////////////////////////////////////////////////////////////// ////////////////////////////////...