dense_matrix_base.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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_DENSE_MATRIX_BASE_H
21 #define LIBMESH_DENSE_MATRIX_BASE_H
22 
23 // Local Includes
24 #include "libmesh/libmesh_common.h"
25 #include "libmesh/compare_types.h"
26 
27 // C++ includes
28 
29 namespace libMesh
30 {
31 
32 // Forward declarations
33 template <typename T> class DenseVectorBase;
34 
43 template<typename T>
45 {
46 
47 protected:
52  DenseMatrixBase(const unsigned int new_m=0,
53  const unsigned int new_n=0) : _m(new_m), _n(new_n) {}
54 
55 public:
60  DenseMatrixBase (DenseMatrixBase &&) = default;
61  DenseMatrixBase (const DenseMatrixBase &) = default;
62  DenseMatrixBase & operator= (const DenseMatrixBase &) = default;
64  virtual ~DenseMatrixBase() = default;
65 
71  virtual void zero() = 0;
72 
78  virtual T el(const unsigned int i,
79  const unsigned int j) const = 0;
80 
86  virtual T & el(const unsigned int i,
87  const unsigned int j) = 0;
88 
92  virtual void left_multiply (const DenseMatrixBase<T> & M2) = 0;
93 
97  virtual void right_multiply (const DenseMatrixBase<T> & M3) = 0;
98 
102  unsigned int m() const { return _m; }
103 
107  unsigned int n() const { return _n; }
108 
112  void print(std::ostream & os = libMesh::out) const;
113 
119  friend std::ostream & operator << (std::ostream & os, const DenseMatrixBase<T> & m)
120  {
121  m.print(os);
122  return os;
123  }
124 
129  void print_scientific(std::ostream & os, unsigned precision=8) const;
130 
136  template <typename T2, typename T3>
137  typename boostcopy::enable_if_c<
138  ScalarTraits<T2>::value, void >::type
139  add (const T2 factor,
140  const DenseMatrixBase<T3> & mat);
141 
142 protected:
143 
151  static void multiply (DenseMatrixBase<T> & M1,
152  const DenseMatrixBase<T> & M2,
153  const DenseMatrixBase<T> & M3);
154 
161  void condense(const unsigned int i,
162  const unsigned int j,
163  const T val,
164  DenseVectorBase<T> & rhs);
165 
169  unsigned int _m;
170 
174  unsigned int _n;
175 };
176 
177 
178 
179 
180 
181 
182 
183 template<typename T>
184 template<typename T2, typename T3>
185 inline
186 typename boostcopy::enable_if_c<
187  ScalarTraits<T2>::value, void >::type
188 DenseMatrixBase<T>::add (const T2 factor,
189  const DenseMatrixBase<T3> & mat)
190 {
191  libmesh_assert_equal_to (this->m(), mat.m());
192  libmesh_assert_equal_to (this->n(), mat.n());
193 
194  for (unsigned int j=0; j<this->n(); j++)
195  for (unsigned int i=0; i<this->m(); i++)
196  this->el(i,j) += factor*mat.el(i,j);
197 }
198 
199 
200 } // namespace libMesh
201 
202 #endif // LIBMESH_DENSE_MATRIX_BASE_H
unsigned int m() const
void print(std::ostream &os=libMesh::out) const
virtual T el(const unsigned int i, const unsigned int j) const =0
virtual void left_multiply(const DenseMatrixBase< T > &M2)=0
DenseMatrixBase(const unsigned int new_m=0, const unsigned int new_n=0)
DenseMatrixBase & operator=(const DenseMatrixBase &)=default
virtual void right_multiply(const DenseMatrixBase< T > &M3)=0
void print_scientific(std::ostream &os, unsigned precision=8) const
boostcopy::enable_if_c< ScalarTraits< T2 >::value, void >::type add(const T2 factor, const DenseMatrixBase< T3 > &mat)
virtual void zero()=0
static void multiply(DenseMatrixBase< T > &M1, const DenseMatrixBase< T > &M2, const DenseMatrixBase< T > &M3)
unsigned int n() const
OStreamProxy out(std::cout)
virtual ~DenseMatrixBase()=default
void condense(const unsigned int i, const unsigned int j, const T val, DenseVectorBase< T > &rhs)