1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2020 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 
18 
19 
20 #ifndef LIBMESH_SUM_SHELL_MATRIX_H
21 #define LIBMESH_SUM_SHELL_MATRIX_H
22 
23 // Local includes
24 #include "libmesh/libmesh_common.h"
25 #include "libmesh/reference_counted_object.h"
26 #include "libmesh/libmesh.h"
27 #include "libmesh/shell_matrix.h"
28 
29 // C++ includes
30 #include <vector>
31 
32 namespace libMesh
33 {
34 
35 /**
36  * This class combines any number of shell matrices to a single shell
37  * matrix by summing them together. All overridden virtual functions
38  * are documented in shell_matrix.h.
39  *
40  * \author Tim Kroeger
41  * \date 2008
42  */
43 template <typename T>
44 class SumShellMatrix : public ShellMatrix<T>
45 {
46 public:
47   /**
48    * Constructor; initializes an empty sum.
49    *
50    * \note An empty sum is not a valid object since a call to \p m()
51    * or \p n() will result in an error.  However, an empty sum is
52    * allowed to be multiplied with a vector and will give the expected
53    * result.
54    */
55   SumShellMatrix (const Parallel::Communicator & comm_in);
56 
57   /**
58    * Constructor that passes a vector of shell matrices.
59    */
60   explicit
61   SumShellMatrix (const std::vector<ShellMatrix<T> *> & mat,
62                   const Parallel::Communicator & comm_in);
63 
64   /**
65    * Destructor.
66    */
67   virtual ~SumShellMatrix ();
68 
69   virtual numeric_index_type m () const override;
70 
71   virtual numeric_index_type n () const override;
72 
73   virtual void vector_mult (NumericVector<T> & dest,
74                             const NumericVector<T> & arg) const override;
75 
76   virtual void vector_mult_add (NumericVector<T> & dest,
77                                 const NumericVector<T> & arg) const override;
78 
79   virtual void get_diagonal (NumericVector<T> & dest) const override;
80 
81   /**
82    * A vector of pointers to the summands.
83    */
84   std::vector<ShellMatrix<T> *> matrices;
85 };
86 
87 
88 
89 //-----------------------------------------------------------------------
90 // SumShellMatrix inline members
91 template <typename T>
92 inline
SumShellMatrix(const Parallel::Communicator & comm_in)93 SumShellMatrix<T>::SumShellMatrix (const Parallel::Communicator & comm_in):
94   ShellMatrix<T>(comm_in),
95   matrices()
96 {}
97 
98 
99 
100 template <typename T>
101 inline
SumShellMatrix(const std::vector<ShellMatrix<T> * > & mat,const Parallel::Communicator & comm_in)102 SumShellMatrix<T>::SumShellMatrix (const std::vector<ShellMatrix<T> *> & mat,
103                                    const Parallel::Communicator & comm_in):
104   ShellMatrix<T>(comm_in),
105   matrices(mat)
106 {}
107 
108 
109 
110 template <typename T>
111 inline
~SumShellMatrix()112 SumShellMatrix<T>::~SumShellMatrix ()
113 {}
114 
115 
116 } // namespace libMesh
117 
118 
119 #endif // LIBMESH_SUM_SHELL_MATRIX_H
120