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
32namespace 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 // =================================================================
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
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.
53 OomphCommunicator serial_comm; // Serial communcator (does nothing)
56
57 // Create temporary output DoubleVector
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
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
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
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....
double size() const
Calculate the size of the element (length, area, volume,...) in Eulerian computational coordinates....
Definition elements.cc:4320
Describes the distribution of a distributable linear algebra type object. Typically this is a contain...
An oomph-lib wrapper to the MPI_Comm communicator object. Just contains an MPI_Comm object (which is ...
unsigned long nrow() const
Return the number of rows of the main matrix.
Vector< DoubleMatrixBase * > Added_matrix_pt
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.
TAdvectionDiffusionReactionElement<NREAGENT,DIM,NNODE_1D> elements are isoparametric triangular DIM-d...
DRAIG: Change all instances of (SPATIAL_DIM) to (DIM-1).