libMesh
dense_matrix_base.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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:
59  virtual ~DenseMatrixBase() {}
60 
66  virtual void zero() = 0;
67 
73  virtual T el(const unsigned int i,
74  const unsigned int j) const = 0;
75 
81  virtual T & el(const unsigned int i,
82  const unsigned int j) = 0;
83 
87  virtual void left_multiply (const DenseMatrixBase<T> & M2) = 0;
88 
92  virtual void right_multiply (const DenseMatrixBase<T> & M3) = 0;
93 
97  unsigned int m() const { return _m; }
98 
102  unsigned int n() const { return _n; }
103 
107  void print(std::ostream & os = libMesh::out) const;
108 
114  friend std::ostream & operator << (std::ostream & os, const DenseMatrixBase<T> & m)
115  {
116  m.print(os);
117  return os;
118  }
119 
124  void print_scientific(std::ostream & os, unsigned precision=8) const;
125 
131  template <typename T2, typename T3>
132  typename boostcopy::enable_if_c<
133  ScalarTraits<T2>::value, void >::type
134  add (const T2 factor,
135  const DenseMatrixBase<T3> & mat);
136 
137 protected:
138 
146  static void multiply (DenseMatrixBase<T> & M1,
147  const DenseMatrixBase<T> & M2,
148  const DenseMatrixBase<T> & M3);
149 
156  void condense(const unsigned int i,
157  const unsigned int j,
158  const T val,
159  DenseVectorBase<T> & rhs);
160 
164  unsigned int _m;
165 
169  unsigned int _n;
170 };
171 
172 
173 
174 
175 
176 
177 
178 template<typename T>
179 template<typename T2, typename T3>
180 inline
181 typename boostcopy::enable_if_c<
182  ScalarTraits<T2>::value, void >::type
183 DenseMatrixBase<T>::add (const T2 factor,
184  const DenseMatrixBase<T3> & mat)
185 {
186  libmesh_assert_equal_to (this->m(), mat.m());
187  libmesh_assert_equal_to (this->n(), mat.n());
188 
189  for (unsigned int j=0; j<this->n(); j++)
190  for (unsigned int i=0; i<this->m(); i++)
191  this->el(i,j) += factor*mat.el(i,j);
192 }
193 
194 
195 } // namespace libMesh
196 
197 #endif // LIBMESH_DENSE_MATRIX_BASE_H
void print_scientific(std::ostream &os, unsigned precision=8) const
Prints the matrix entries with more decimal places in scientific notation.
unsigned int n() const
The libMesh namespace provides an interface to certain functionality in the library.
virtual void left_multiply(const DenseMatrixBase< T > &M2)=0
Performs the operation: (*this) <- M2 * (*this)
unsigned int m() const
DenseMatrixBase(const unsigned int new_m=0, const unsigned int new_n=0)
Constructor.
unsigned int _n
The column dimension.
virtual void right_multiply(const DenseMatrixBase< T > &M3)=0
Performs the operation: (*this) <- (*this) * M3.
boostcopy::enable_if_c< ScalarTraits< T2 >::value, void >::type add(const T2 factor, const DenseMatrixBase< T3 > &mat)
Adds factor to every element in the matrix.
virtual void zero()=0
Set every element in the matrix to 0.
OStreamProxy out
virtual T el(const unsigned int i, const unsigned int j) const =0
Defines an abstract dense vector base class for use in Finite Element-type computations.
Definition: dof_map.h:62
static void multiply(DenseMatrixBase< T > &M1, const DenseMatrixBase< T > &M2, const DenseMatrixBase< T > &M3)
Helper function - Performs the computation M1 = M2 * M3 where: M1 = (m x n) M2 = (m x p) M3 = (p x n)...
Defines an abstract dense matrix base class for use in Finite Element-type computations.
void print(std::ostream &os=libMesh::out) const
Pretty-print the matrix, by default to libMesh::out.
virtual ~DenseMatrixBase()
Destructor.
void condense(const unsigned int i, const unsigned int j, const T val, DenseVectorBase< T > &rhs)
Condense-out the (i,j) entry of the matrix, forcing it to take on the value val.
unsigned int _m
The row dimension.