dense_submatrix.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_SUBMATRIX_H
21 #define LIBMESH_DENSE_SUBMATRIX_H
22 
23 // Local Includes
24 #include "libmesh/libmesh_common.h"
25 #include "libmesh/dense_matrix.h"
27 
28 // C++ includes
29 
30 namespace libMesh
31 {
32 
43 template<typename T>
45 {
46 public:
47 
54  DenseSubMatrix(DenseMatrix<T> & new_parent,
55  const unsigned int ioff=0,
56  const unsigned int joff=0,
57  const unsigned int m=0,
58  const unsigned int n=0);
59 
64  DenseSubMatrix (DenseSubMatrix &&) = default;
65  DenseSubMatrix (const DenseSubMatrix &) = default;
66  DenseSubMatrix & operator= (const DenseSubMatrix &) = default;
68  virtual ~DenseSubMatrix() = default;
69 
74 
75  virtual void zero() override;
76 
80  T operator() (const unsigned int i,
81  const unsigned int j) const;
82 
86  T & operator() (const unsigned int i,
87  const unsigned int j);
88 
89  virtual T el(const unsigned int i,
90  const unsigned int j) const override
91  { return (*this)(i,j); }
92 
93  virtual T & el(const unsigned int i,
94  const unsigned int j) override
95  { return (*this)(i,j); }
96 
97  virtual void left_multiply (const DenseMatrixBase<T> & M2) override;
98 
99  virtual void right_multiply (const DenseMatrixBase<T> & M3) override;
100 
104  void reposition(const unsigned int ioff,
105  const unsigned int joff,
106  const unsigned int new_m,
107  const unsigned int new_n);
108 
112  unsigned int i_off() const { return _i_off; }
113 
117  unsigned int j_off() const { return _j_off; }
118 
125  void condense(const unsigned int i,
126  const unsigned int j,
127  const T val,
128  DenseSubVector<T> & rhs)
129  {
130  this->parent().condense(this->i_off()+i,
131  this->j_off()+j,
132  val, rhs.parent());
133  }
134 
135 private:
136 
141 
145  unsigned int _i_off;
146 
150  unsigned int _j_off;
151 };
152 
153 
154 // --------------------------------------------------
155 // Constructor
156 template<typename T>
157 inline
159  const unsigned int ioff,
160  const unsigned int joff,
161  const unsigned int new_m,
162  const unsigned int new_n) :
163  DenseMatrixBase<T>(new_m,new_n),
164  _parent_matrix(new_parent)
165 {
166  this->reposition (ioff, joff, new_m, new_n);
167 }
168 
169 
170 template<typename T>
171 inline
172 void DenseSubMatrix<T>::reposition(const unsigned int ioff,
173  const unsigned int joff,
174  const unsigned int new_m,
175  const unsigned int new_n)
176 {
177  _i_off = ioff;
178  _j_off = joff;
179  this->_m = new_m;
180  this->_n = new_n;
181 
182  // Make sure we still fit in the parent matrix.
183  libmesh_assert_less_equal ((this->i_off() + this->m()), _parent_matrix.m());
184  libmesh_assert_less_equal ((this->j_off() + this->n()), _parent_matrix.n());
185 }
186 
187 
188 
189 template<typename T>
190 inline
192 {
193  for (unsigned int i=0; i<this->m(); i++)
194  for (unsigned int j=0; j<this->n(); j++)
195  _parent_matrix(i + this->i_off(),
196  j + this->j_off()) = 0.;
197 }
198 
199 
200 
201 template<typename T>
202 inline
203 T DenseSubMatrix<T>::operator () (const unsigned int i,
204  const unsigned int j) const
205 {
206  libmesh_assert_less (i, this->m());
207  libmesh_assert_less (j, this->n());
208  libmesh_assert_less (i + this->i_off(), _parent_matrix.m());
209  libmesh_assert_less (j + this->j_off(), _parent_matrix.n());
210 
211  return _parent_matrix (i + this->i_off(),
212  j + this->j_off());
213 }
214 
215 
216 template<typename T>
217 inline
218 T & DenseSubMatrix<T>::operator () (const unsigned int i,
219  const unsigned int j)
220 {
221  libmesh_assert_less (i, this->m());
222  libmesh_assert_less (j, this->n());
223  libmesh_assert_less (i + this->i_off(), _parent_matrix.m());
224  libmesh_assert_less (j + this->j_off(), _parent_matrix.n());
225 
226  return _parent_matrix (i + this->i_off(),
227  j + this->j_off());
228 }
229 
230 
231 } // namespace libMesh
232 
233 
234 #endif // LIBMESH_DENSE_SUBMATRIX_H
virtual T & el(const unsigned int i, const unsigned int j) override
virtual void zero() override
unsigned int j_off() const
unsigned int m() const
virtual void left_multiply(const DenseMatrixBase< T > &M2) override
DenseVector< T > & parent()
T operator()(const unsigned int i, const unsigned int j) const
DenseMatrix< T > & parent()
void condense(const unsigned int i, const unsigned int j, const T val, DenseSubVector< T > &rhs)
DenseSubMatrix & operator=(const DenseSubMatrix &)=default
DenseSubMatrix(DenseMatrix< T > &new_parent, const unsigned int ioff=0, const unsigned int joff=0, const unsigned int m=0, const unsigned int n=0)
virtual T el(const unsigned int i, const unsigned int j) const override
void reposition(const unsigned int ioff, const unsigned int joff, const unsigned int new_m, const unsigned int new_n)
unsigned int n() const
A matrix object used for finite element assembly and numerics.
Definition: dense_matrix.h:54
virtual ~DenseSubMatrix()=default
virtual void right_multiply(const DenseMatrixBase< T > &M3) override
DenseMatrix< T > & _parent_matrix
unsigned int i_off() const