ParMooN
 All Classes Functions Variables Friends Pages
Public Member Functions | Protected Attributes | Friends | List of all members
TMatrix Class Reference
Inheritance diagram for TMatrix:
Inheritance graph
[legend]
Collaboration diagram for TMatrix:
Collaboration graph
[legend]

Public Member Functions

 TMatrix (TStructure *structure)
 
 TMatrix (TStructure *structure, double *Entries)
 
void SetStructure (TStructure *structure)
 reset the structure, this may mean that the entries need to be reallocated
 
 TMatrix (int nRows, int nCols)
 
 ~TMatrix ()
 
void Reset ()
 
int GetN_Rows () const
 
int GetN_Columns () const
 
int GetN_Entries () const
 
int GetHangingN_Entries () const
 
int * GetKCol () const
 
int * GetHangingKCol () const
 
int * GetHangingRowPtr () const
 
int * GetRowPtr () const
 
TStructureGetStructure () const
 
double * GetEntries () const
 
double GetNorm (int p=-1) const
 
int Write (const char *filename) const
 
void Print (const char *name="a") const
 Print matrix into the shell.
 
void PrintFull (std::string name="", int fieldWidth=4) const
 print the full matrix, including all zeros More...
 
void add (int i, int j, double val)
 
void add (int i, std::map< int, double > vals, double factor=1.0)
 
void add (std::map< int, std::map< int, double > > vals, double factor=1.0)
 
void set (int i, int j, double val)
 
const double & get (int i, int j) const
 
double & get (int i, int j)
 
void setEntries (double *entries)
 
TMatrixGetTransposed () const
 return a new TMatrix which is the transposed of this matrix More...
 
void changeRows (std::map< int, std::map< int, double > > entries, bool deleteOldArrays=false)
 replace several rows in the matrix with new entries. More...
 
virtual TMatrixoperator+= (const TMatrix *A)
 add another matrix to this one More...
 
virtual TMatrixoperator-= (const TMatrix *A)
 substract another matrix to this one More...
 
virtual TMatrixoperator+= (const TMatrix &A)
 add another matrix to this one More...
 
virtual TMatrixoperator*= (const double a)
 scale matrix by a factor
 
TMatrixoperator= (const TMatrix &A)
 copy entries from A to this More...
 
void multiply (const double *const x, double *y, double a=1.0) const
 compute y += a * A*x More...
 
TMatrixmultiply (const TMatrix *const B, double a=1.0) const
 compute matrix-matrix product C = a*A*B, More...
 
void scale (const double *const factor, bool from_left=true)
 scale a matrix using a vector More...
 
void remove_zeros (double tol=0.0)
 remove all entries from sparsity structure where a zero is stored More...
 
double & operator() (const int i, const int j)
 get/set a specific matrix entry More...
 
const double & operator() (const int i, const int j) const
 get a specific matrix entry More...
 

Protected Attributes

TStructurestructure
 
double * Entries
 

Friends

double * operator* (const TMatrix &A, const double *x)
 compute y = A*x (Matrix-Vector-Multiplication) More...
 

Constructor & Destructor Documentation

TMatrix::TMatrix ( TStructure structure)

generate the matrix, intialize entries with zeros

Here is the call graph for this function:

Here is the caller graph for this function:

TMatrix::TMatrix ( TStructure structure,
double *  Entries 
)

generate the matrix with given entries

TMatrix::TMatrix ( int  nRows,
int  nCols 
)

create a nRows*nCols zero matrix

TMatrix::~TMatrix ( )

destructor: free Entries array

Member Function Documentation

void TMatrix::changeRows ( std::map< int, std::map< int, double > >  entries,
bool  deleteOldArrays = false 
)

replace several rows in the matrix with new entries.

Replace rows by new ones. This changes the sparsity pattern of the matrix. Therefore reallocation is necessary. The old arrays are no longer needed (for this matrix) and will be deleted if the flag 'deleteOldArrays' is set to true.

If there are no rows to change, i.e. if entries.size()==0, nothing is done.

Parameters
entriesfor every row a map of columns-to-entries map
deleteOldArraysremove old arrays in matrix and structure

Here is the call graph for this function:

Here is the caller graph for this function:

double* TMatrix::GetEntries ( ) const
inline

return matrix entries

Here is the caller graph for this function:

int* TMatrix::GetHangingKCol ( ) const
inline

return array HangingKCol

Here is the call graph for this function:

int TMatrix::GetHangingN_Entries ( ) const
inline

return number of matrix entries for hanging node data

Here is the call graph for this function:

Here is the caller graph for this function:

int* TMatrix::GetHangingRowPtr ( ) const
inline

return array HangingRowPtr

Here is the call graph for this function:

int* TMatrix::GetKCol ( ) const
inline

return array KCol

Here is the call graph for this function:

Here is the caller graph for this function:

int TMatrix::GetN_Columns ( ) const
inline

return number of columns

Here is the call graph for this function:

Here is the caller graph for this function:

int TMatrix::GetN_Entries ( ) const
inline

return number of matrix entries

Here is the call graph for this function:

Here is the caller graph for this function:

int TMatrix::GetN_Rows ( ) const
inline

return number of rows

Here is the call graph for this function:

Here is the caller graph for this function:

double TMatrix::GetNorm ( int  p = -1) const

return the norm of the matrix. p is -2 for Frobenius norm -1 for maximum absolute row sum 0 for maximum entry 1 for maximum absolute column sum 2 for euclidean norm,

Here is the call graph for this function:

Here is the caller graph for this function:

int* TMatrix::GetRowPtr ( ) const
inline

return array RowPtr

Here is the call graph for this function:

Here is the caller graph for this function:

TStructure* TMatrix::GetStructure ( ) const
inline

return structure

Here is the caller graph for this function:

TMatrix* TMatrix::GetTransposed ( ) const

return a new TMatrix which is the transposed of this matrix

If this is an object of a derived class (e.g. TMatrix2D, TSquareMatrix), then the number of active degrees of freedom is not taken into account. The returned TMatrix is really the algebraic transposed matrix.

void TMatrix::multiply ( const double *const  x,
double *  y,
double  a = 1.0 
) const

compute y += a * A*x

'A' is this TMatrix and 'x', and 'y' are given vectors. The scalar 'a' is a scaling factor

Parameters
xarray representing the vector which is multiplied by this matrix
yarray representing the vector to which a * A*x is added
ascaling factor, default is 1.0

Here is the call graph for this function:

TMatrix * TMatrix::multiply ( const TMatrix *const  B,
double  a = 1.0 
) const

compute matrix-matrix product C = a*A*B,

'A' is this matrix, 'a' is a scalar factor, 'B' is given. Then matrix 'C' is created during this function and the user is responsible to delete C.

Note that this is rather slow.

Parameters
Bmatrix to be multiplied (from right) to this matrix
ascaling factor, default is 1.0

Here is the call graph for this function:

double & TMatrix::operator() ( const int  i,
const int  j 
)

get/set a specific matrix entry

This will give an error if that entry is not in the sparsity structure

const double & TMatrix::operator() ( const int  i,
const int  j 
) const

get a specific matrix entry

This will give an error if that entry is not in the sparsity structure

TMatrix & TMatrix::operator+= ( const TMatrix A)
virtual

add another matrix to this one

This is of course only possible if the corresponding structures are the same.

Here is the call graph for this function:

virtual TMatrix& TMatrix::operator+= ( const TMatrix A)
inlinevirtual

add another matrix to this one

This is of course only possible if the corresponding structures are the same. This method exists only for convenience and uses the same method with a pointer to A instead of the reference.

TMatrix & TMatrix::operator-= ( const TMatrix A)
virtual

substract another matrix to this one

This is of course only possible if the corresponding structures are the same.

Here is the call graph for this function:

TMatrix & TMatrix::operator= ( const TMatrix A)

copy entries from A to this

This is of course only possible if the corresponding structures are the same.

Here is the call graph for this function:

void TMatrix::PrintFull ( std::string  name = "",
int  fieldWidth = 4 
) const

print the full matrix, including all zeros

This is only meaningful for very small matrices.

Here is the call graph for this function:

void TMatrix::remove_zeros ( double  tol = 0.0)

remove all entries from sparsity structure where a zero is stored

This changes the sparsity structure of this matrix. Afterwards all stored entries are nonzero. This can help if a lot of zeros are explicitly stored in the matrix. Afterwards matrix operations should be faster.

if tol is greater or equal to zero, all entries with magnitude smaller than tol are removed. If tol is smaller than zero, tol is set such that the ratio of the largest over the smallest entry in the resulting matrix is smaller than 10^{15}.

Here is the call graph for this function:

void TMatrix::Reset ( )

reset matrix entries to zero

Here is the call graph for this function:

Here is the caller graph for this function:

void TMatrix::scale ( const double *const  factor,
bool  from_left = true 
)

scale a matrix using a vector

think of this as multipling this matrix with a diagonal matrix from the left (if the second argument is true). The parameter 'factor' are the entries of that diagonal matrix.

The i-th row (colum if from_left is false) is scaled by the i-th entry in 'factor'.

The array 'factor' must be of size this->GetN_Rows() if 'from_left' is true or of size this->GetN_Columns() otherwise.

If all entries in 'factor' are the same, you can use operator*= as well.

Parameters
factorarray of scaling factors
from_leftscale rows (true) or columns (false)

Here is the call graph for this function:

int TMatrix::Write ( const char *  filename) const

write matrix into file

Friends And Related Function Documentation

double* operator* ( const TMatrix A,
const double *  x 
)
friend

compute y = A*x (Matrix-Vector-Multiplication)

Note that 'y' is created here and it is up to the user to delete it.

Member Data Documentation

double* TMatrix::Entries
protected

matrix elements in an array

TStructure* TMatrix::structure
protected

Sparse structure of the matrix


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