dense_matrix_base.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2014 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 Delcarations
33 template <typename T> class DenseVectorBase;
34 
35 
36 
37 
45 template<typename T>
47 {
48 
49 protected:
54  DenseMatrixBase(const unsigned int new_m=0,
55  const unsigned int new_n=0) : _m(new_m), _n(new_n) {}
56 
57 public:
61  virtual ~DenseMatrixBase() {}
62 
68  virtual void zero() = 0;
69 
75  virtual T el(const unsigned int i,
76  const unsigned int j) const = 0;
77 
83  virtual T & el(const unsigned int i,
84  const unsigned int j) = 0;
85 
89  virtual void left_multiply (const DenseMatrixBase<T>& M2) = 0;
90 
94  virtual void right_multiply (const DenseMatrixBase<T>& M3) = 0;
95 
99  unsigned int m() const { return _m; }
100 
104  unsigned int n() const { return _n; }
105 
109  void print(std::ostream& os = libMesh::out) const;
110 
116  friend std::ostream& operator << (std::ostream& os, const DenseMatrixBase<T>& m)
117  {
118  m.print(os);
119  return os;
120  }
121 
126  void print_scientific(std::ostream& os) const;
127 
133  template <typename T2, typename T3>
134  typename boostcopy::enable_if_c<
135  ScalarTraits<T2>::value, void >::type
136  add (const T2 factor,
137  const DenseMatrixBase<T3>& mat);
138 
139 protected:
140 
147  void multiply (DenseMatrixBase<T>& M1,
148  const DenseMatrixBase<T>& M2,
149  const DenseMatrixBase<T>& M3);
150 
157  void condense(const unsigned int i,
158  const unsigned int j,
159  const T val,
160  DenseVectorBase<T>& rhs);
161 
165  unsigned int _m;
166 
170  unsigned int _n;
171 };
172 
173 
174 
175 
176 
177 
178 
179 template<typename T>
180 template<typename T2, typename T3>
181 inline
182 typename boostcopy::enable_if_c<
183  ScalarTraits<T2>::value, void >::type
184 DenseMatrixBase<T>::add (const T2 factor,
185  const DenseMatrixBase<T3>& mat)
186 {
187  libmesh_assert_equal_to (this->m(), mat.m());
188  libmesh_assert_equal_to (this->n(), mat.n());
189 
190  for (unsigned int j=0; j<this->n(); j++)
191  for (unsigned int i=0; i<this->m(); i++)
192  this->el(i,j) += factor*mat.el(i,j);
193 }
194 
195 
196 } // namespace libMesh
197 
198 #endif // LIBMESH_DENSE_MATRIX_BASE_H

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:04 UTC

Hosted By:
SourceForge.net Logo