libMesh
dense_submatrix.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_SUBMATRIX_H
21 #define LIBMESH_DENSE_SUBMATRIX_H
22 
23 // Local Includes
24 #include "libmesh/libmesh_common.h"
25 #include "libmesh/dense_matrix.h"
26 #include "libmesh/dense_subvector.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 
63  DenseSubMatrix (const DenseSubMatrix<T> & other_matrix);
64 
68  virtual ~DenseSubMatrix() {}
69 
74 
75  virtual void zero() libmesh_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 libmesh_override
91  { return (*this)(i,j); }
92 
93  virtual T & el(const unsigned int i,
94  const unsigned int j) libmesh_override
95  { return (*this)(i,j); }
96 
97  virtual void left_multiply (const DenseMatrixBase<T> & M2) libmesh_override;
98 
99  virtual void right_multiply (const DenseMatrixBase<T> & M3) libmesh_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 // Copy Constructor
171 template<typename T>
172 inline
174  DenseMatrixBase<T>(other_matrix._m, other_matrix._n),
175  _parent_matrix(other_matrix._parent_matrix)
176 {
177  _i_off = other_matrix._i_off;
178  _j_off = other_matrix._j_off;
179 }
180 
181 
182 template<typename T>
183 inline
184 void DenseSubMatrix<T>::reposition(const unsigned int ioff,
185  const unsigned int joff,
186  const unsigned int new_m,
187  const unsigned int new_n)
188 {
189  _i_off = ioff;
190  _j_off = joff;
191  this->_m = new_m;
192  this->_n = new_n;
193 
194  // Make sure we still fit in the parent matrix.
195  libmesh_assert_less_equal ((this->i_off() + this->m()), _parent_matrix.m());
196  libmesh_assert_less_equal ((this->j_off() + this->n()), _parent_matrix.n());
197 }
198 
199 
200 
201 template<typename T>
202 inline
204 {
205  for (unsigned int i=0; i<this->m(); i++)
206  for (unsigned int j=0; j<this->n(); j++)
207  _parent_matrix(i + this->i_off(),
208  j + this->j_off()) = 0.;
209 }
210 
211 
212 
213 template<typename T>
214 inline
215 T DenseSubMatrix<T>::operator () (const unsigned int i,
216  const unsigned int j) const
217 {
218  libmesh_assert_less (i, this->m());
219  libmesh_assert_less (j, this->n());
220  libmesh_assert_less (i + this->i_off(), _parent_matrix.m());
221  libmesh_assert_less (j + this->j_off(), _parent_matrix.n());
222 
223  return _parent_matrix (i + this->i_off(),
224  j + this->j_off());
225 }
226 
227 
228 template<typename T>
229 inline
230 T & DenseSubMatrix<T>::operator () (const unsigned int i,
231  const unsigned int j)
232 {
233  libmesh_assert_less (i, this->m());
234  libmesh_assert_less (j, this->n());
235  libmesh_assert_less (i + this->i_off(), _parent_matrix.m());
236  libmesh_assert_less (j + this->j_off(), _parent_matrix.n());
237 
238  return _parent_matrix (i + this->i_off(),
239  j + this->j_off());
240 }
241 
242 
243 } // namespace libMesh
244 
245 
246 #endif // LIBMESH_DENSE_SUBMATRIX_H
virtual T & el(const unsigned int i, const unsigned int j) libmesh_override
virtual void right_multiply(const DenseMatrixBase< T > &M3) libmesh_override
Performs the operation: (*this) <- (*this) * M3.
unsigned int n() const
The libMesh namespace provides an interface to certain functionality in the library.
unsigned int _i_off
The row offset into the parent matrix.
DenseVector< T > & parent()
virtual ~DenseSubMatrix()
Destructor.
Defines a dense subvector for use in finite element computations.
DenseMatrix< T > & parent()
unsigned int _j_off
The column offset into the parent matrix.
unsigned int m() const
unsigned int i_off() const
void condense(const unsigned int i, const unsigned int j, const T val, DenseSubVector< T > &rhs)
Condense-out the (i,j) entry of the matrix, forcing it to take on the value val.
Defines a dense submatrix for use in Finite Element-type computations.
virtual T el(const unsigned int i, const unsigned int j) const libmesh_override
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)
Constructor.
unsigned int _n
The column dimension.
T operator()(const unsigned int i, const unsigned int j) const
virtual void zero() libmesh_override
Set every element in the matrix to 0.
void reposition(const unsigned int ioff, const unsigned int joff, const unsigned int new_m, const unsigned int new_n)
Changes the location of the submatrix in the parent matrix.
Defines an abstract dense matrix base class for use in Finite Element-type computations.
Defines a dense matrix for use in Finite Element-type computations.
Definition: dof_map.h:64
unsigned int j_off() const
virtual void left_multiply(const DenseMatrixBase< T > &M2) libmesh_override
Performs the operation: (*this) <- M2 * (*this)
unsigned int _m
The row dimension.
DenseMatrix< T > & _parent_matrix
The parent matrix that contains this submatrix.