dense_submatrix.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_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 
33 
34 
43 // ------------------------------------------------------------
44 // DenseSubMatrix class definition
45 template<typename T>
47 {
48 public:
49 
56  DenseSubMatrix(DenseMatrix<T>& new_parent,
57  const unsigned int ioff=0,
58  const unsigned int joff=0,
59  const unsigned int m=0,
60  const unsigned int n=0);
61 
65  DenseSubMatrix (const DenseSubMatrix<T>& other_matrix);
66 
70  virtual ~DenseSubMatrix() {}
71 
72 
76  DenseMatrix<T>& parent () { return _parent_matrix; }
77 
81  virtual void zero();
82 
86  T operator() (const unsigned int i,
87  const unsigned int j) const;
88 
92  T & operator() (const unsigned int i,
93  const unsigned int j);
94 
98  virtual T el(const unsigned int i,
99  const unsigned int j) const { return (*this)(i,j); }
100 
104  virtual T & el(const unsigned int i,
105  const unsigned int j) { return (*this)(i,j); }
106 
110  virtual void left_multiply (const DenseMatrixBase<T>& M2);
111 
115  virtual void right_multiply (const DenseMatrixBase<T>& M3);
116 
120  void reposition(const unsigned int ioff,
121  const unsigned int joff,
122  const unsigned int new_m,
123  const unsigned int new_n);
124 
128  unsigned int i_off() const { return _i_off; }
129 
133  unsigned int j_off() const { return _j_off; }
134 
141  void condense(const unsigned int i,
142  const unsigned int j,
143  const T val,
144  DenseSubVector<T>& rhs)
145  {
146  this->parent().condense(this->i_off()+i,
147  this->j_off()+j,
148  val, rhs.parent());
149  }
150 
151 private:
152 
156  DenseMatrix<T>& _parent_matrix;
157 
161  unsigned int _i_off;
162 
166  unsigned int _j_off;
167 };
168 
169 
170 // --------------------------------------------------
171 // Constructor
172 template<typename T>
173 inline
175  const unsigned int ioff,
176  const unsigned int joff,
177  const unsigned int new_m,
178  const unsigned int new_n)
179  : DenseMatrixBase<T>(new_m,new_n),
180  _parent_matrix(new_parent)
181 {
182  this->reposition (ioff, joff, new_m, new_n);
183 }
184 
185 
186 // Copy Constructor
187 template<typename T>
188 inline
189 DenseSubMatrix<T>::DenseSubMatrix(const DenseSubMatrix<T>& other_matrix)
190  : DenseMatrixBase<T>(other_matrix._m, other_matrix._n),
191  _parent_matrix(other_matrix._parent_matrix)
192 {
193  _i_off = other_matrix._i_off;
194  _j_off = other_matrix._j_off;
195 }
196 
197 
198 template<typename T>
199 inline
200 void DenseSubMatrix<T>::reposition(const unsigned int ioff,
201  const unsigned int joff,
202  const unsigned int new_m,
203  const unsigned int new_n)
204 {
205  _i_off = ioff;
206  _j_off = joff;
207  this->_m = new_m;
208  this->_n = new_n;
209 
210  // Make sure we still fit in the parent matrix.
211  libmesh_assert_less_equal ((this->i_off() + this->m()), _parent_matrix.m());
212  libmesh_assert_less_equal ((this->j_off() + this->n()), _parent_matrix.n());
213 }
214 
215 
216 
217 template<typename T>
218 inline
220 {
221  for (unsigned int i=0; i<this->m(); i++)
222  for (unsigned int j=0; j<this->n(); j++)
223  _parent_matrix(i + this->i_off(),
224  j + this->j_off()) = 0.;
225 }
226 
227 
228 
229 template<typename T>
230 inline
231 T DenseSubMatrix<T>::operator () (const unsigned int i,
232  const unsigned int j) const
233 {
234  libmesh_assert_less (i, this->m());
235  libmesh_assert_less (j, this->n());
236  libmesh_assert_less (i + this->i_off(), _parent_matrix.m());
237  libmesh_assert_less (j + this->j_off(), _parent_matrix.n());
238 
239  return _parent_matrix (i + this->i_off(),
240  j + this->j_off());
241 }
242 
243 
244 template<typename T>
245 inline
246 T & DenseSubMatrix<T>::operator () (const unsigned int i,
247  const unsigned int j)
248 {
249  libmesh_assert_less (i, this->m());
250  libmesh_assert_less (j, this->n());
251  libmesh_assert_less (i + this->i_off(), _parent_matrix.m());
252  libmesh_assert_less (j + this->j_off(), _parent_matrix.n());
253 
254  return _parent_matrix (i + this->i_off(),
255  j + this->j_off());
256 }
257 
258 
259 } // namespace libMesh
260 
261 
262 #endif // LIBMESH_DENSE_SUBMATRIX_H

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

Hosted By:
SourceForge.net Logo