libMesh
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Attributes | List of all members
libMesh::DenseSubMatrix< T > Class Template Reference

Defines a dense submatrix for use in Finite Element-type computations. More...

#include <dense_submatrix.h>

Inheritance diagram for libMesh::DenseSubMatrix< T >:
[legend]

Public Member Functions

 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. More...
 
 DenseSubMatrix (DenseSubMatrix &&)=default
 The 5 special functions can be defaulted for this class, as it does not manage any memory itself. More...
 
 DenseSubMatrix (const DenseSubMatrix &)=default
 
DenseSubMatrixoperator= (const DenseSubMatrix &)=default
 
DenseSubMatrixoperator= (DenseSubMatrix &&)=default
 
virtual ~DenseSubMatrix ()=default
 
DenseMatrix< T > & parent ()
 
virtual void zero () override
 Set every element in the matrix to 0. More...
 
operator() (const unsigned int i, const unsigned int j) const
 
T & operator() (const unsigned int i, const unsigned int j)
 
virtual T el (const unsigned int i, const unsigned int j) const override
 
virtual T & el (const unsigned int i, const unsigned int j) override
 
virtual void left_multiply (const DenseMatrixBase< T > &M2) override
 Performs the operation: (*this) <- M2 * (*this) More...
 
virtual void right_multiply (const DenseMatrixBase< T > &M3) override
 Performs the operation: (*this) <- (*this) * M3. More...
 
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. More...
 
unsigned int i_off () const
 
unsigned int j_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. More...
 
unsigned int m () const
 
unsigned int n () const
 
void print (std::ostream &os=libMesh::out) const
 Pretty-print the matrix, by default to libMesh::out. More...
 
void print_scientific (std::ostream &os, unsigned precision=8) const
 Prints the matrix entries with more decimal places in scientific notation. More...
 
template<typename T2 , typename T3 >
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. More...
 

Protected Member Functions

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. More...
 

Static Protected Member Functions

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) More...
 

Protected Attributes

unsigned int _m
 The row dimension. More...
 
unsigned int _n
 The column dimension. More...
 

Private Attributes

DenseMatrix< T > & _parent_matrix
 The parent matrix that contains this submatrix. More...
 
unsigned int _i_off
 The row offset into the parent matrix. More...
 
unsigned int _j_off
 The column offset into the parent matrix. More...
 

Detailed Description

template<typename T>
class libMesh::DenseSubMatrix< T >

Defines a dense submatrix for use in Finite Element-type computations.

Useful for storing element stiffness matrices before summation into a global matrix, particularly when you have systems of equations. All overridden virtual functions are documented in dense_matrix_base.h.

Author
Benjamin S. Kirk
Date
2003

Definition at line 44 of file dense_submatrix.h.

Constructor & Destructor Documentation

◆ DenseSubMatrix() [1/3]

template<typename T >
libMesh::DenseSubMatrix< T >::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.

Creates a dense submatrix of the matrix parent. The submatrix has dimensions $(m \times n)$, and the $(0,0)$ entry of the submatrix is located at the $(ioff,joff)$ location in the parent matrix.

Definition at line 158 of file dense_submatrix.h.

References libMesh::DenseSubMatrix< T >::reposition().

162  :
163  DenseMatrixBase<T>(new_m,new_n),
164  _parent_matrix(new_parent)
165 {
166  this->reposition (ioff, joff, new_m, new_n);
167 }
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.
DenseMatrix< T > & _parent_matrix
The parent matrix that contains this submatrix.

◆ DenseSubMatrix() [2/3]

template<typename T>
libMesh::DenseSubMatrix< T >::DenseSubMatrix ( DenseSubMatrix< T > &&  )
default

The 5 special functions can be defaulted for this class, as it does not manage any memory itself.

◆ DenseSubMatrix() [3/3]

template<typename T>
libMesh::DenseSubMatrix< T >::DenseSubMatrix ( const DenseSubMatrix< T > &  )
default

◆ ~DenseSubMatrix()

template<typename T>
virtual libMesh::DenseSubMatrix< T >::~DenseSubMatrix ( )
virtualdefault

Member Function Documentation

◆ add()

template<typename T >
template<typename T2 , typename T3 >
boostcopy::enable_if_c< ScalarTraits< T2 >::value, void >::type libMesh::DenseMatrixBase< T >::add ( const T2  factor,
const DenseMatrixBase< T3 > &  mat 
)
inherited

Adds factor to every element in the matrix.

This should only work if T += T2 * T3 is valid C++ and if T2 is scalar. Return type is void

Definition at line 188 of file dense_matrix_base.h.

References libMesh::DenseMatrixBase< T >::el(), libMesh::DenseMatrixBase< T >::m(), and libMesh::DenseMatrixBase< T >::n().

190 {
191  libmesh_assert_equal_to (this->m(), mat.m());
192  libmesh_assert_equal_to (this->n(), mat.n());
193 
194  for (unsigned int j=0; j<this->n(); j++)
195  for (unsigned int i=0; i<this->m(); i++)
196  this->el(i,j) += factor*mat.el(i,j);
197 }
unsigned int m() const
virtual T el(const unsigned int i, const unsigned int j) const =0
unsigned int n() const

◆ condense() [1/2]

template<typename T>
void libMesh::DenseSubMatrix< T >::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.

This is useful in numerical simulations for applying boundary conditions. Preserves the symmetry of the matrix.

Definition at line 125 of file dense_submatrix.h.

References libMesh::DenseSubMatrix< T >::i_off(), libMesh::DenseSubMatrix< T >::j_off(), libMesh::DenseSubVector< T >::parent(), and libMesh::DenseSubMatrix< T >::parent().

129  {
130  this->parent().condense(this->i_off()+i,
131  this->j_off()+j,
132  val, rhs.parent());
133  }
unsigned int j_off() const
DenseMatrix< T > & parent()
unsigned int i_off() const

◆ condense() [2/2]

template<typename T>
void libMesh::DenseMatrixBase< T >::condense ( const unsigned int  i,
const unsigned int  j,
const T  val,
DenseVectorBase< T > &  rhs 
)
protectedinherited

Condense-out the (i,j) entry of the matrix, forcing it to take on the value val.

This is useful in numerical simulations for applying boundary conditions. Preserves the symmetry of the matrix.

Referenced by libMesh::DenseMatrix< Real >::condense().

◆ el() [1/2]

template<typename T>
virtual T libMesh::DenseSubMatrix< T >::el ( const unsigned int  i,
const unsigned int  j 
) const
overridevirtual
Returns
The (i,j) element of the matrix. Since internal data representations may differ, you must redefine this function.

Implements libMesh::DenseMatrixBase< T >.

Definition at line 89 of file dense_submatrix.h.

91  { return (*this)(i,j); }

◆ el() [2/2]

template<typename T>
virtual T& libMesh::DenseSubMatrix< T >::el ( const unsigned int  i,
const unsigned int  j 
)
overridevirtual
Returns
The (i,j) element of the matrix as a writable reference. Since internal data representations may differ, you must redefine this function.

Implements libMesh::DenseMatrixBase< T >.

Definition at line 93 of file dense_submatrix.h.

95  { return (*this)(i,j); }

◆ i_off()

template<typename T>
unsigned int libMesh::DenseSubMatrix< T >::i_off ( ) const
Returns
The row offset into the parent matrix.

Definition at line 112 of file dense_submatrix.h.

References libMesh::DenseSubMatrix< T >::_i_off.

Referenced by libMesh::DenseSubMatrix< T >::condense().

112 { return _i_off; }
unsigned int _i_off
The row offset into the parent matrix.

◆ j_off()

template<typename T>
unsigned int libMesh::DenseSubMatrix< T >::j_off ( ) const
Returns
The column offset into the parent matrix.

Definition at line 117 of file dense_submatrix.h.

References libMesh::DenseSubMatrix< T >::_j_off.

Referenced by libMesh::DenseSubMatrix< T >::condense().

117 { return _j_off; }
unsigned int _j_off
The column offset into the parent matrix.

◆ left_multiply()

template<typename T>
virtual void libMesh::DenseSubMatrix< T >::left_multiply ( const DenseMatrixBase< T > &  M2)
overridevirtual

Performs the operation: (*this) <- M2 * (*this)

Implements libMesh::DenseMatrixBase< T >.

◆ m()

template<typename T>
unsigned int libMesh::DenseMatrixBase< T >::m ( ) const
inherited

◆ multiply()

template<typename T>
static void libMesh::DenseMatrixBase< T >::multiply ( DenseMatrixBase< T > &  M1,
const DenseMatrixBase< T > &  M2,
const DenseMatrixBase< T > &  M3 
)
staticprotectedinherited

Helper function - Performs the computation M1 = M2 * M3 where: M1 = (m x n) M2 = (m x p) M3 = (p x n)

◆ n()

template<typename T>
unsigned int libMesh::DenseMatrixBase< T >::n ( ) const
inherited

◆ operator()() [1/2]

template<typename T >
T libMesh::DenseSubMatrix< T >::operator() ( const unsigned int  i,
const unsigned int  j 
) const
Returns
The (i,j) element of the submatrix.

Definition at line 203 of file dense_submatrix.h.

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 }
unsigned int j_off() const
unsigned int m() const
unsigned int n() const
DenseMatrix< T > & _parent_matrix
The parent matrix that contains this submatrix.
unsigned int i_off() const

◆ operator()() [2/2]

template<typename T >
T & libMesh::DenseSubMatrix< T >::operator() ( const unsigned int  i,
const unsigned int  j 
)
Returns
The (i,j) element of the submatrix as a writable reference.

Definition at line 218 of file dense_submatrix.h.

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 }
unsigned int j_off() const
unsigned int m() const
unsigned int n() const
DenseMatrix< T > & _parent_matrix
The parent matrix that contains this submatrix.
unsigned int i_off() const

◆ operator=() [1/2]

template<typename T>
DenseSubMatrix& libMesh::DenseSubMatrix< T >::operator= ( const DenseSubMatrix< T > &  )
default

◆ operator=() [2/2]

template<typename T>
DenseSubMatrix& libMesh::DenseSubMatrix< T >::operator= ( DenseSubMatrix< T > &&  )
default

◆ parent()

template<typename T>
DenseMatrix<T>& libMesh::DenseSubMatrix< T >::parent ( )
Returns
A reference to the parent matrix.

Definition at line 73 of file dense_submatrix.h.

References libMesh::DenseSubMatrix< T >::_parent_matrix.

Referenced by libMesh::DenseSubMatrix< T >::condense().

73 { return _parent_matrix; }
DenseMatrix< T > & _parent_matrix
The parent matrix that contains this submatrix.

◆ print()

template<typename T>
void libMesh::DenseMatrixBase< T >::print ( std::ostream &  os = libMesh::out) const
inherited

Pretty-print the matrix, by default to libMesh::out.

◆ print_scientific()

template<typename T>
void libMesh::DenseMatrixBase< T >::print_scientific ( std::ostream &  os,
unsigned  precision = 8 
) const
inherited

Prints the matrix entries with more decimal places in scientific notation.

◆ reposition()

template<typename T >
void libMesh::DenseSubMatrix< T >::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.

Definition at line 172 of file dense_submatrix.h.

Referenced by libMesh::DenseSubMatrix< T >::DenseSubMatrix().

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 }
unsigned int j_off() const
unsigned int m() const
unsigned int _i_off
The row offset into the parent matrix.
unsigned int _j_off
The column offset into the parent matrix.
unsigned int _n
The column dimension.
unsigned int n() const
unsigned int _m
The row dimension.
DenseMatrix< T > & _parent_matrix
The parent matrix that contains this submatrix.
unsigned int i_off() const

◆ right_multiply()

template<typename T>
virtual void libMesh::DenseSubMatrix< T >::right_multiply ( const DenseMatrixBase< T > &  M3)
overridevirtual

Performs the operation: (*this) <- (*this) * M3.

Implements libMesh::DenseMatrixBase< T >.

◆ zero()

template<typename T >
void libMesh::DenseSubMatrix< T >::zero ( )
overridevirtual

Set every element in the matrix to 0.

You must redefine what you mean by zeroing the matrix since it depends on how your values are stored.

Implements libMesh::DenseMatrixBase< T >.

Definition at line 191 of file dense_submatrix.h.

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 }
unsigned int j_off() const
unsigned int m() const
unsigned int n() const
DenseMatrix< T > & _parent_matrix
The parent matrix that contains this submatrix.
unsigned int i_off() const

Member Data Documentation

◆ _i_off

template<typename T>
unsigned int libMesh::DenseSubMatrix< T >::_i_off
private

The row offset into the parent matrix.

Definition at line 145 of file dense_submatrix.h.

Referenced by libMesh::DenseSubMatrix< T >::i_off().

◆ _j_off

template<typename T>
unsigned int libMesh::DenseSubMatrix< T >::_j_off
private

The column offset into the parent matrix.

Definition at line 150 of file dense_submatrix.h.

Referenced by libMesh::DenseSubMatrix< T >::j_off().

◆ _m

template<typename T>
unsigned int libMesh::DenseMatrixBase< T >::_m
protectedinherited

The row dimension.

Definition at line 169 of file dense_matrix_base.h.

Referenced by libMesh::DenseMatrixBase< T >::m().

◆ _n

template<typename T>
unsigned int libMesh::DenseMatrixBase< T >::_n
protectedinherited

The column dimension.

Definition at line 174 of file dense_matrix_base.h.

Referenced by libMesh::DenseMatrixBase< T >::n().

◆ _parent_matrix

template<typename T>
DenseMatrix<T>& libMesh::DenseSubMatrix< T >::_parent_matrix
private

The parent matrix that contains this submatrix.

Definition at line 140 of file dense_submatrix.h.

Referenced by libMesh::DenseSubMatrix< T >::parent().


The documentation for this class was generated from the following file: