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 |
TStructure * | GetStructure () 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) |
TMatrix * | GetTransposed () 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 TMatrix & | operator+= (const TMatrix *A) |
add another matrix to this one More... | |
virtual TMatrix & | operator-= (const TMatrix *A) |
substract another matrix to this one More... | |
virtual TMatrix & | operator+= (const TMatrix &A) |
add another matrix to this one More... | |
virtual TMatrix & | operator*= (const double a) |
scale matrix by a factor | |
TMatrix & | operator= (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... | |
TMatrix * | multiply (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 | |
TStructure * | structure |
double * | Entries |
Friends | |
double * | operator* (const TMatrix &A, const double *x) |
compute y = A*x (Matrix-Vector-Multiplication) More... | |
TMatrix::TMatrix | ( | TStructure * | structure | ) |
generate the matrix, intialize entries with zeros
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
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.
entries | for every row a map of columns-to-entries map |
deleteOldArrays | remove old arrays in matrix and structure |
|
inline |
return matrix entries
|
inline |
return array HangingKCol
|
inline |
return number of matrix entries for hanging node data
|
inline |
return array HangingRowPtr
|
inline |
return array KCol
|
inline |
return number of columns
|
inline |
return number of matrix entries
|
inline |
return number of rows
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,
|
inline |
return array RowPtr
|
inline |
return structure
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
x | array representing the vector which is multiplied by this matrix |
y | array representing the vector to which a * A*x is added |
a | scaling factor, default is 1.0 |
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.
B | matrix to be multiplied (from right) to this matrix |
a | scaling factor, default is 1.0 |
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
add another matrix to this one
This is of course only possible if the corresponding structures are the same.
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.
substract another matrix to this one
This is of course only possible if the corresponding structures are the same.
copy entries from A to this
This is of course only possible if the corresponding structures are the same.
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.
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}.
void TMatrix::Reset | ( | ) |
reset matrix entries to zero
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.
factor | array of scaling factors |
from_left | scale rows (true) or columns (false) |
int TMatrix::Write | ( | const char * | filename | ) | const |
write matrix into file
|
friend |
compute y = A*x (Matrix-Vector-Multiplication)
Note that 'y' is created here and it is up to the user to delete it.
|
protected |
matrix elements in an array
|
protected |
Sparse structure of the matrix