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 // Local includes
21 #include "libmesh/sum_shell_matrix.h"
22 #include "libmesh/numeric_vector.h"
23 #include "libmesh/int_range.h"
24 
25 namespace libMesh
26 {
27 
28 template <typename T>
m()29 numeric_index_type SumShellMatrix<T>::m () const
30 {
31   libmesh_assert(!matrices.empty());
32   const numeric_index_type n_rows = matrices[0]->m();
33 #ifndef NDEBUG
34   for (auto i : index_range(matrices))
35     libmesh_assert_equal_to (matrices[i]->m(), n_rows);
36 #endif
37   return n_rows;
38 }
39 
40 
41 
42 template <typename T>
n()43 numeric_index_type SumShellMatrix<T>::n () const
44 {
45   libmesh_assert(!matrices.empty());
46   const numeric_index_type n_cols = matrices[0]->n();
47 #ifndef NDEBUG
48   for (auto i : index_range(matrices))
49     libmesh_assert_equal_to (matrices[i]->n(), n_cols);
50 #endif
51   return n_cols;
52 }
53 
54 
55 
56 template <typename T>
vector_mult(NumericVector<T> & dest,const NumericVector<T> & arg)57 void SumShellMatrix<T>::vector_mult (NumericVector<T> & dest,
58                                      const NumericVector<T> & arg) const
59 {
60   dest.zero();
61   this->vector_mult_add(dest,arg);
62 }
63 
64 
65 
66 template <typename T>
vector_mult_add(NumericVector<T> & dest,const NumericVector<T> & arg)67 void SumShellMatrix<T>::vector_mult_add (NumericVector<T> & dest,
68                                          const NumericVector<T> & arg) const
69 {
70   for (auto i : index_range(matrices))
71     matrices[i]->vector_mult_add(dest, arg);
72 }
73 
74 
75 
76 template <typename T>
get_diagonal(NumericVector<T> & dest)77 void SumShellMatrix<T>::get_diagonal (NumericVector<T> & dest) const
78 {
79   std::unique_ptr<NumericVector<T>> a = dest.zero_clone();
80   for (auto i : index_range(matrices))
81     {
82       matrices[i]->get_diagonal(*a);
83       dest += *a;
84     }
85 }
86 
87 
88 
89 //------------------------------------------------------------------
90 // Explicit instantiations
91 template class SumShellMatrix<Number>;
92 
93 } // namespace libMesh
94