TBCI::BdMatrix< T > Class Template Reference

The class BdMatrix is an implementation to store and do operations on sparse Matrices with a band structure. More...

#include <band_matrix.h>

Inheritance diagram for TBCI::BdMatrix< T >:

Inheritance graph
[legend]
Collaboration diagram for TBCI::BdMatrix< T >:

Collaboration graph
[legend]

List of all members.

Public Types

typedef T value_type
typedef T element_type
typedef T aligned_value_type

Public Member Functions

 BdMatrix (const unsigned int=0)
 c'tor tridiagonal
 BdMatrix (const unsigned int, const unsigned int)
 c'tor with rows and columns (which need to be identical)
 BdMatrix (const unsigned int, const BVector< unsigned int > &)
 c'tor with config Vector
 BdMatrix (const BdMatrix< T > &)
 copy c'tor
 BdMatrix (const T &, const unsigned int)
 c'tor variants with initial value on diag (tridiag, with config)
 BdMatrix (const T &, const unsigned int, const BVector< unsigned int > &)
 BdMatrix (const T &, const unsigned int, unsigned int)
 c'tor with # of offdiags (band Matrix)
 BdMatrix (const Matrix< T > &)
 c'tor to copy Matrix and self-determine sparseness
 ~BdMatrix ()
void destroy ()
 destroy object explicitly
template<typename U>
 BdMatrix (const BdMatrix< U > &bm)
 operator TMatrix< T > () const
 cast
T & operator() (const unsigned int, const unsigned int)
 rw member access
tbci_traits< T >::const_refval_type operator() (const unsigned int, const unsigned int) const
 ro member access
BdMatrix< T > & setval (const T &v, const unsigned int r, const unsigned int c)
 autoinsert, sparse class compatible
T & setval (const unsigned int r, const unsigned int c)
tbci_traits< T >::const_refval_type get (const unsigned int i, const unsigned int j) const
BdMatrix< T > & transpose ()
 transpose() does change the object!
BdMatrix< T > & resize (const unsigned int)
BdMatrix< T > & resize (const T &, const unsigned int)
BdMatrix< T > & resize (const unsigned int, const BVector< unsigned int > &)
BdMatrix< T > & resize (const T &, const unsigned int, const BVector< unsigned int > &)
BdMatrix< T > & resize (const BdMatrix< T > &bdm)
 Resizing assignment.
BdMatrix< T > & reconfig (const BVector< unsigned int > &)
BdMatrix< T > & setunit (const T &=1)
BdMatrix< T > & fill (const T &=0)
BdMatrix< T > & clear ()
BdMatrix< T > & adddiag (const unsigned)
BdMatrix< T > & removediag (const unsigned)
BdMatrix< T > & autoinsert (const T &, const unsigned, const unsigned)
BdMatrix< T > & expand (unsigned=0)
BdMatrix< T > & set_row (const Vector< T > &val, const unsigned, const unsigned=0)
 Overwrite row with Vector.
TVector< T > get_row (const unsigned int) const
 Construct Vector from row.
TVector< T > get_col (const unsigned int) const
 Construct Vector from column.
unsigned int size () const
 size: incompatibility to Matrix (!)
unsigned int noelem () const
 Number of elements that are actually stored.
unsigned int rows () const
 number of rows
unsigned int columns () const
 number of columns
const BVector< unsigned int > & getcfg () const
 ro access to config BVector
unsigned int getmaxoff () const
 max distance from main diagonal
trace () const
BdMatrix< T > & operator= (const BdMatrix< T > &)
 The assignment operators in TBCI are NOT resizing.
BdMatrix< T > & operator= (const T &)
BdMatrix< T > & operator+= (const BdMatrix< T > &)
BdMatrix< T > & operator-= (const BdMatrix< T > &)
BdMatrix< T > & operator*= (const T &)
BdMatrix< T > & operator/= (const T &)
bool operator== (const BdMatrix< T > &) const
bool operator!= (const BdMatrix< T > &ma) const
BdMatrix< T > operator+ (const BdMatrix< T > &) const
BdMatrix< T > operator- (const BdMatrix< T > &) const
BdMatrix< T > operator* (const BdMatrix< T > &) const
BdMatrix< T > operator* (const T &) const
BdMatrix< T > operator/ (const T &) const
BdMatrix< T > operator- () const
TVector< T > operator* (const Vector< T > &) const
 Matrix-Vector multiplication.
TVector< T > transMult (const Vector< T > &) const
 Transposed Matrix-Vector multiplication.
TVector< T > dotMult (const Vector< T > &) const
TMatrix< T > operator* (const Matrix< T > &) const
BdMatrix< T > & mult_rows (const Vector< T > &)
 Linewise multiplication.
BdMatrix< T > & div_rows (const Vector< T > &)
BdMatrix< T > & mult_row (const T &, const unsigned)
BdMatrix< T > & div_row (const T &, const unsigned)
const BdMatrix< T > & setoutopts (int w=5, int p=4, char f= ' ') const
BdMatrix< T > inverse () const
template<>
BdMatrix< int > & operator/= (const int &div)
template<>
BdMatrix< unsigned int > & operator/= (const unsigned int &div)

Static Public Member Functions

static const char * mat_info ()

Protected Member Functions

void constructor (const unsigned int, const bool=true)
T * check (const unsigned r, const unsigned c) const
void free_diags (const unsigned)
 Implementation alternative: All memory is allocated in one big chunk (default).
void do_copy (const BdMatrix< T > &)

Protected Attributes

unsigned int dim
unsigned int maxoff
 size, max offset from diag
unsigned long arsz
 # of saved elems,
BVector< unsigned > diagconf
 configuration
BVector< T * > adiag
BVector< T * > bdiag
 pointers to upper and lower diagonals
T * diag

Friends

class ILU0_BdMatrixPreconditioner< T >
class DILU_BdMatrixPreconditioner< T >
class BdMatrix
std::istream & operator>> (std::istream &, BdMatrix< T > &)
std::ostream & operator<< (std::ostream &, const BdMatrix< T > &)
void gaussj (const BdMatrix< T > &, const Matrix< T > &)
int lu_decomp (BdMatrix< T > &)
 LU decompose a TBCI::BdMatrix.
void do_bdmat_vec_mult (const unsigned, const unsigned, TVector< T > *, const BdMatrix< T > *, const Vector< T > *)
void do_bdmat_vec_transmult (const unsigned, const unsigned, TVector< T > *, const BdMatrix< T > *, const Vector< T > *)
void do_bdmat_vec_dotmult (const unsigned, const unsigned, TVector< T > *, const BdMatrix< T > *, const Vector< T > *)


Detailed Description

template<typename T>
class TBCI::BdMatrix< T >

The class BdMatrix is an implementation to store and do operations on sparse Matrices with a band structure.

It stores the main diagonal and additional diagonals of your Matrix as arrays.

This is an efficient way to handle matrices that have only a few diagonals, such as e.g. the typical pentadiagonal systems from solving discretized partial differential equations in 2 dimensions.

Default shape is tridiagonal, additional diagonals to be stored can be given by a BVector argument to the constructor, or by using autoinsert(), which allocates diagonals as needed.

Alternatives: CSCMatrix is a good choice for sparse matrices as well.

Layout:
... d ad1 ad2 ...
bd1. \. \. \.
bd2.\.00 01 02 03 04 .... 0N
... \.10 11 12 13 14 .... 1N
..... 20 21 22 23 24 .... 2N
..... .. .. .. .. .. .... ..
..... .. .. .. .. .. .... ..
..... N0 N1 N2 N3 N4 .... NN

Thus, an element a(i,j) is
diag[i] if i==j
adiag(j-i)[i] if j>i
bdiag(i-j)[j] if i>j

adiag(j-i)[i] with j >= N <=> i + j-i >= N do not exist
bdiag(i-j)[j] with i >= N <=> j + i-j >= N do not exist

Definition at line 103 of file band_matrix.h.


Member Typedef Documentation

template<typename T>
typedef T TBCI::BdMatrix< T >::value_type

Definition at line 131 of file band_matrix.h.

template<typename T>
typedef T TBCI::BdMatrix< T >::element_type

Definition at line 132 of file band_matrix.h.

template<typename T>
typedef T TBCI::BdMatrix< T >::aligned_value_type

Definition at line 133 of file band_matrix.h.


Constructor & Destructor Documentation

template<typename T>
TBCI::BdMatrix< T >::BdMatrix ( const unsigned int  d = 0  )  [inline, explicit]

template<typename T>
TBCI::BdMatrix< T >::BdMatrix ( const unsigned int  d,
const unsigned int  e 
) [inline, explicit]

c'tor with rows and columns (which need to be identical)

Definition at line 501 of file band_matrix.h.

References BCHKNR, TBCI::BdMatrix< T >::clear(), TBCI::BdMatrix< T >::constructor(), TBCI::BdMatrix< T >::diagconf, TBCI::BVector< T >::resize(), and UNLIKELY.

template<typename T>
TBCI::BdMatrix< T >::BdMatrix ( const unsigned int  d,
const BVector< unsigned int > &  conf 
) [inline, explicit]

c'tor with config Vector

Definition at line 511 of file band_matrix.h.

References TBCI::BdMatrix< T >::clear(), and TBCI::BdMatrix< T >::constructor().

template<typename T>
TBCI::BdMatrix< T >::BdMatrix ( const BdMatrix< T > &  mat  )  [inline]

template<typename T>
TBCI::BdMatrix< T >::BdMatrix ( const T &  val,
const unsigned int  d 
) [inline]

c'tor variants with initial value on diag (tridiag, with config)

Definition at line 531 of file band_matrix.h.

References TBCI::BdMatrix< T >::constructor(), TBCI::BdMatrix< T >::diagconf, TBCI::BVector< T >::resize(), TBCI::BdMatrix< T >::setunit(), and UNLIKELY.

template<typename T>
TBCI::BdMatrix< T >::BdMatrix ( const T &  val,
const unsigned int  d,
const BVector< unsigned int > &  conf 
) [inline]

template<typename T>
TBCI::BdMatrix< T >::BdMatrix ( const T &  val,
const unsigned int  d,
unsigned int  mo 
) [inline]

template<typename T>
TBCI::BdMatrix< T >::BdMatrix ( const Matrix< T > &  mat  )  [inline]

template<typename T>
TBCI::BdMatrix< T >::~BdMatrix (  )  [inline]

template<typename T>
template<typename U>
TBCI::BdMatrix< T >::BdMatrix ( const BdMatrix< U > &  bm  )  [inline, explicit]


Member Function Documentation

template<typename T>
void TBCI::BdMatrix< T >::constructor ( const unsigned int  d,
const bool  delout = true 
) [inline, protected]

template<typename T>
T * TBCI::BdMatrix< T >::check ( const unsigned  r,
const unsigned  c 
) const [inline, protected]

template<typename T>
void TBCI::BdMatrix< T >::free_diags ( const unsigned  dummy  )  [inline, protected]

Implementation alternative: All memory is allocated in one big chunk (default).

Definition at line 344 of file band_matrix.h.

References TBCI::BdMatrix< T >::arsz, BDMATDBG, TBCI::BdMatrix< T >::diag, TBCI::BdMatrix< T >::dim, STD__, and TBCIDELETE.

Referenced by TBCI::BdMatrix< T >::operator=(), TBCI::BdMatrix< T >::resize(), and TBCI::BdMatrix< T >::~BdMatrix().

template<typename T>
void TBCI::BdMatrix< T >::do_copy ( const BdMatrix< T > &  bdm  )  [inline, protected]

template<typename T>
void TBCI::BdMatrix< T >::destroy (  )  [inline]

destroy object explicitly

Definition at line 155 of file band_matrix.h.

template<typename T>
static const char* TBCI::BdMatrix< T >::mat_info (  )  [inline, static]

Reimplemented from TBCI::Matrix_Sig< T >.

Definition at line 163 of file band_matrix.h.

template<typename T>
TBCI::BdMatrix< T >::operator TMatrix< T > (  )  const [inline]

template<typename T>
T & TBCI::BdMatrix< T >::operator() ( const unsigned int  r,
const unsigned int  c 
) [inline]

rw member access

Definition at line 650 of file band_matrix.h.

References BCHK, TBCI::BdMatrix< T >::check(), and LIKELY.

template<typename T>
tbci_traits< T >::const_refval_type TBCI::BdMatrix< T >::operator() ( const unsigned int  r,
const unsigned int  c 
) const [inline]

ro member access

Definition at line 663 of file band_matrix.h.

References BCHK, TBCI::BdMatrix< T >::check(), and LIKELY.

template<typename T>
BdMatrix<T>& TBCI::BdMatrix< T >::setval ( const T &  v,
const unsigned int  r,
const unsigned int  c 
) [inline]

autoinsert, sparse class compatible

Definition at line 202 of file band_matrix.h.

Referenced by TBCI::lu_decomp(), and TBCI::operator>>().

template<typename T>
T & TBCI::BdMatrix< T >::setval ( const unsigned int  r,
const unsigned int  c 
) [inline]

template<typename T>
tbci_traits<T>::const_refval_type TBCI::BdMatrix< T >::get ( const unsigned int  i,
const unsigned int  j 
) const [inline]

Definition at line 207 of file band_matrix.h.

template<typename T>
BdMatrix< T > & TBCI::BdMatrix< T >::transpose (  )  [inline]

template<typename T>
BdMatrix< T > & TBCI::BdMatrix< T >::resize ( const unsigned int  nd  )  [inline]

template<typename T>
BdMatrix< T > & TBCI::BdMatrix< T >::resize ( const T &  val,
const unsigned int  nd 
) [inline]

template<typename T>
BdMatrix< T > & TBCI::BdMatrix< T >::resize ( const unsigned int  nd,
const BVector< unsigned int > &  cfg 
) [inline]

template<typename T>
BdMatrix< T > & TBCI::BdMatrix< T >::resize ( const T &  val,
const unsigned int  nd,
const BVector< unsigned int > &  cfg 
) [inline]

Definition at line 801 of file band_matrix.h.

References TBCI::BdMatrix< T >::diag, and TBCI::BdMatrix< T >::resize().

template<typename T>
BdMatrix<T>& TBCI::BdMatrix< T >::resize ( const BdMatrix< T > &  bdm  )  [inline]

Resizing assignment.

Definition at line 222 of file band_matrix.h.

References TBCI::BdMatrix< T >::diagconf, and TBCI::BdMatrix< T >::dim.

template<typename T>
BdMatrix< T > & TBCI::BdMatrix< T >::reconfig ( const BVector< unsigned int > &  cfg  )  [inline]

template<typename T>
BdMatrix< T > & TBCI::BdMatrix< T >::setunit ( const T &  val = 1  )  [inline]

template<typename T>
BdMatrix< T > & TBCI::BdMatrix< T >::fill ( const T &  val = 0  )  [inline]

Reimplemented from TBCI::Matrix_Sig< T >.

Definition at line 1024 of file band_matrix.h.

References TBCI::BdMatrix< T >::arsz, TBCI::BdMatrix< T >::diag, and TBCIFILL.

template<typename T>
BdMatrix< T > & TBCI::BdMatrix< T >::clear (  )  [inline]

template<typename T>
BdMatrix< T > & TBCI::BdMatrix< T >::adddiag ( const unsigned  ndg  )  [inline]

template<typename T>
BdMatrix< T > & TBCI::BdMatrix< T >::removediag ( const unsigned  dg  )  [inline]

template<typename T>
BdMatrix< T > & TBCI::BdMatrix< T >::autoinsert ( const T &  val,
const unsigned  r,
const unsigned  c 
) [inline]

template<typename T>
BdMatrix< T > & TBCI::BdMatrix< T >::expand ( unsigned  m = 0  )  [inline]

template<typename T>
BdMatrix< T > & TBCI::BdMatrix< T >::set_row ( const Vector< T > &  val,
const unsigned  r,
const unsigned  s = 0 
) [inline]

Overwrite row with Vector.

Definition at line 983 of file band_matrix.h.

References TBCI::BdMatrix< T >::autoinsert(), and TBCI::TVector< T >::size().

template<typename T>
TVector< T > TBCI::BdMatrix< T >::get_row ( const unsigned int  r  )  const [inline]

template<typename T>
TVector< T > TBCI::BdMatrix< T >::get_col ( const unsigned int  c  )  const [inline]

template<typename T>
unsigned int TBCI::BdMatrix< T >::size (  )  const [inline]

template<typename T>
unsigned int TBCI::BdMatrix< T >::noelem (  )  const [inline]

Number of elements that are actually stored.

Definition at line 243 of file band_matrix.h.

template<typename T>
unsigned int TBCI::BdMatrix< T >::rows (  )  const [inline]

template<typename T>
unsigned int TBCI::BdMatrix< T >::columns (  )  const [inline]

number of columns

Reimplemented from TBCI::Matrix_Sig< T >.

Definition at line 247 of file band_matrix.h.

Referenced by TBCI::CSCMatrix< T >::CSCMatrix(), and TBCI::LU_invert().

template<typename T>
const BVector<unsigned int>& TBCI::BdMatrix< T >::getcfg (  )  const [inline]

ro access to config BVector

Definition at line 250 of file band_matrix.h.

template<typename T>
unsigned int TBCI::BdMatrix< T >::getmaxoff (  )  const [inline]

max distance from main diagonal

Definition at line 252 of file band_matrix.h.

Referenced by TBCI::LU_bkw_subst(), TBCI::lu_decomp(), and TBCI::LU_fwd_subst().

template<typename T>
T TBCI::BdMatrix< T >::trace (  )  const [inline]

Definition at line 254 of file band_matrix.h.

References ALIGN, MIN_ALIGN, and T.

template<typename T>
BdMatrix< T > & TBCI::BdMatrix< T >::operator= ( const BdMatrix< T > &  mat  )  [inline]

template<typename T>
BdMatrix< T > & TBCI::BdMatrix< T >::operator= ( const T &  val  )  [inline]

Definition at line 1245 of file band_matrix.h.

References TBCI::BdMatrix< T >::setunit().

template<typename T>
BdMatrix< T > & TBCI::BdMatrix< T >::operator+= ( const BdMatrix< T > &  mat  )  [inline]

Definition at line 1283 of file band_matrix.h.

template<typename T>
BdMatrix< T > & TBCI::BdMatrix< T >::operator-= ( const BdMatrix< T > &  mat  )  [inline]

Definition at line 1284 of file band_matrix.h.

template<typename T>
BdMatrix< T > & TBCI::BdMatrix< T >::operator*= ( const T &  mult  )  [inline]

Definition at line 1303 of file band_matrix.h.

template<typename T>
BdMatrix< T > & TBCI::BdMatrix< T >::operator/= ( const T &  div  )  [inline]

template<typename T>
bool TBCI::BdMatrix< T >::operator== ( const BdMatrix< T > &  ma  )  const [inline]

template<typename T>
bool TBCI::BdMatrix< T >::operator!= ( const BdMatrix< T > &  ma  )  const [inline]

Definition at line 280 of file band_matrix.h.

template<typename T>
BdMatrix< T > TBCI::BdMatrix< T >::operator+ ( const BdMatrix< T > &  m2  )  const [inline]

Definition at line 1386 of file band_matrix.h.

template<typename T>
BdMatrix< T > TBCI::BdMatrix< T >::operator- ( const BdMatrix< T > &  m2  )  const [inline]

Definition at line 1387 of file band_matrix.h.

template<typename T>
BdMatrix< T > TBCI::BdMatrix< T >::operator* ( const BdMatrix< T > &  mat2  )  const [inline]

template<typename T>
BdMatrix< T > TBCI::BdMatrix< T >::operator* ( const T &  val  )  const [inline]

Definition at line 1375 of file band_matrix.h.

template<typename T>
BdMatrix< T > TBCI::BdMatrix< T >::operator/ ( const T &  val  )  const [inline]

Definition at line 1374 of file band_matrix.h.

template<typename T>
BdMatrix< T > TBCI::BdMatrix< T >::operator- (  )  const [inline]

template<typename T>
TVector< T > TBCI::BdMatrix< T >::operator* ( const Vector< T > &  vec  )  const [inline]

template<typename T>
TVector< T > TBCI::BdMatrix< T >::transMult ( const Vector< T > &  vec  )  const [inline]

template<typename T>
TVector< T > TBCI::BdMatrix< T >::dotMult ( const Vector< T > &  vec  )  const [inline]

Definition at line 2162 of file band_matrix.h.

References BCHK, and TBCI::TVector< T >::size().

template<typename T>
TMatrix<T> TBCI::BdMatrix< T >::operator* ( const Matrix< T > &   )  const

template<typename T>
BdMatrix< T > & TBCI::BdMatrix< T >::mult_rows ( const Vector< T > &  v  )  [inline]

template<typename T>
BdMatrix< T > & TBCI::BdMatrix< T >::div_rows ( const Vector< T > &  v  )  [inline]

template<typename T>
BdMatrix< T > & TBCI::BdMatrix< T >::mult_row ( const T &  f,
const unsigned  i 
) [inline]

template<typename T>
BdMatrix< T > & TBCI::BdMatrix< T >::div_row ( const T &  d,
const unsigned  i 
) [inline]

template<typename T>
const BdMatrix<T>& TBCI::BdMatrix< T >::setoutopts ( int  w = 5,
int  p = 4,
char  f = ' ' 
) const [inline]

Definition at line 319 of file band_matrix.h.

template<typename T>
BdMatrix<T> TBCI::BdMatrix< T >::inverse (  )  const

template<>
BdMatrix< int > & TBCI::BdMatrix< int >::operator/= ( const int &  div  )  [inline]

Definition at line 1342 of file band_matrix.h.

template<>
BdMatrix< unsigned int > & TBCI::BdMatrix< unsigned int >::operator/= ( const unsigned int &  div  )  [inline]

Definition at line 1343 of file band_matrix.h.


Friends And Related Function Documentation

template<typename T>
friend class ILU0_BdMatrixPreconditioner< T > [friend]

Definition at line 105 of file band_matrix.h.

template<typename T>
friend class DILU_BdMatrixPreconditioner< T > [friend]

Definition at line 106 of file band_matrix.h.

template<typename T>
friend class BdMatrix [friend]

Definition at line 169 of file band_matrix.h.

template<typename T>
std:: istream& operator>> ( std::istream &  istr,
BdMatrix< T > &  mat 
) [friend]

Definition at line 2309 of file band_matrix.h.

template<typename T>
std:: ostream& operator<< ( std::ostream &  ostr,
const BdMatrix< T > &  mat 
) [friend]

Definition at line 2282 of file band_matrix.h.

template<typename T>
void gaussj ( const BdMatrix< T > &  ,
const Matrix< T > &   
) [friend]

template<typename T>
int lu_decomp ( BdMatrix< T > &  mat  )  [friend]

LU decompose a TBCI::BdMatrix.

Decomposition is compactly stored in one BdMatrix The diagonal elements of the lower BdMatrix are all 1 (this is a feature of the algorithm)

Note:
The BdMatrix passed will be changed!

Definition at line 57 of file bd_lu_solver.h.

template<typename T>
void do_bdmat_vec_mult ( const unsigned  start,
const unsigned  end,
TVector< T > *  res,
const BdMatrix< T > *  mat,
const Vector< T > *  vec 
) [friend]

Definition at line 1479 of file band_matrix.h.

Referenced by TBCI::job_bdmat_vec_mult().

template<typename T>
void do_bdmat_vec_transmult ( const unsigned  start,
const unsigned  end,
TVector< T > *  res,
const BdMatrix< T > *  mat,
const Vector< T > *  vec 
) [friend]

Definition at line 1691 of file band_matrix.h.

Referenced by TBCI::job_bdmat_vec_transmult().

template<typename T>
void do_bdmat_vec_dotmult ( const unsigned  start,
const unsigned  end,
TVector< T > *  res,
const BdMatrix< T > *  mat,
const Vector< T > *  vec 
) [friend]

Definition at line 1863 of file band_matrix.h.


Member Data Documentation

template<typename T>
unsigned int TBCI::BdMatrix< T >::dim [protected]

template<typename T>
unsigned int TBCI::BdMatrix< T >::maxoff [protected]

template<typename T>
unsigned long TBCI::BdMatrix< T >::arsz [protected]

template<typename T>
BVector<unsigned> TBCI::BdMatrix< T >::diagconf [protected]

template<typename T>
BVector<T*> TBCI::BdMatrix< T >::adiag [protected]

template<typename T>
BVector<T*> TBCI::BdMatrix< T >::bdiag [protected]

template<typename T>
T* TBCI::BdMatrix< T >::diag [protected]


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

Generated on Wed Nov 20 09:29:16 2013 for TBCI Numerical high perf. C++ Library by  doxygen 1.5.6