Sparse matrix. More...
#include <sparseMatrix.hh>


Public Types | |
| typedef Cmplxtype< F >::type | c_type |
| Real type of data type. | |
| typedef _HashedSMatrix_iterator< F, const F &, const F * > | const_iterator |
| typedef _HashedSMatrix_iterator< F, F &, F * > | iterator |
| typedef Realtype< F >::type | r_type |
| Real type of data type. | |
| typedef F | type |
| Type of data, e.g. matrix entries. | |
| typedef F | value_type |
Public Member Functions | |
| template<class H , class I > | |
| void | addInto (Matrix< H > &dest, const I fact, const uint rowoffset=0, const uint coloffset=0) const |
This matrix is added as block to the given matrix dest. | |
| template<class H , class I > | |
| void | addIntoT (Matrix< H > &dest, const I fact, const uint rowoffset=0, const uint coloffset=0) const |
| The transposed of this matrix is added as block to the given matrix. | |
| iterator | begin (uint row=0) |
Iterator over the elements, standing at position (row,c), where row is the given row number and c the first non-zero entry. | |
| const_iterator | begin (uint row=0) const |
Constant iterator over the elements, standing at position (row,c), where row is the given row number and c the first non-zero entry. | |
| void | compress (Real threshold=EPS) |
| Compresses the matrix by dropping small entries. | |
| virtual void | convertCCS (F *a, int *asub, int *xa) const |
Converts to CCS format and writes values to field a, the row number asub and the index of the first value of each column xa. | |
| virtual void | convertCRS (F *a, int *asub, int *xa) const |
Converts to CRS format and writes values to field a, the column number asub and the index of the first value of each row xa. | |
| void | copy (const SparseMatrix< F > &n) |
Copies n to this matrix. | |
| virtual const uint | dimX () const |
| Returns the size of the image space of the operator (number of rows of the corresponding matrix) | |
| virtual const uint | dimY () const |
| Returns the size of the source space of the operator (number of columns of the corresponding matrix) | |
| const_iterator | end () const |
| Last entrance of the particular order. | |
| iterator | end () |
| Iterator, standing behind last element. | |
| void | histogram (std::map< int, uint > &hist) const |
| Creates a histogram of the matrix entries. | |
| const HashedSparseMatrix< F > * | m () const |
| Returns the sparse matrix itself. | |
| float | memory () const |
| Memory usage in byte. | |
| void | multiply (const SparseMatrix< F > &fact, Matrix< F > &dest) const |
Multiplies this matrix with fact and adds the result to dest. | |
| template<class H > | |
| void | multiply (const H &fact, Matrix< F > &dest) const |
Multiplies this matrix with fact and adds the result to dest. | |
| const uint | nofCols () const |
| Number of columns. | |
| const uint | nofRows () const |
| Number of rows. | |
| virtual void | operator() (const Function< r_type > &fncY, Function< F > &fncX) |
Computes fncX = A(fncY) where A is this matrix. | |
| template<class H , class I > | |
| void | operator() (const Vector< H > &fncY, Vector< I > &fncX) |
Multiplies the matrix with fncY. The result is fncX. | |
| virtual F | operator() (const uint i, const uint j) const |
Returns entry with indices i and j. | |
| virtual void | operator() (const Function< c_type > &fncY, Function< c_type > &fncX) |
Application operator for complex function fncY. | |
| virtual F & | operator() (const uint i, const uint j) |
Returns and allows access to entry with indices i and j. | |
| SparseMatrix< F > & | operator*= (const F factor) |
| void | operator= (const SparseMatrix< F > &) |
| virtual bool | operator== (const Matrix< F > &otherMat) const |
| template<class H > | |
| SparseMatrix (const SparseMatrix< H > &fncX) | |
| Constructor. | |
| template<class G > | |
| SparseMatrix (const Space< G > &spc, BilinearForm< F, G > &bf, const Real threshold=0.0) | |
| Constructor. | |
| template<class G > | |
| SparseMatrix (const Space< G > &spcX, const Space< G > &spcY) | |
| Constructor. | |
| template<class G > | |
| SparseMatrix (const Space< G > &spc, const Vector< F > &x, const Vector< F > &y) | |
| Constructor of rank 1 matrix. | |
| template<class G > | |
| SparseMatrix (const Space< G > &spcX, const Space< G > &spcY, BilinearForm< F, G > &bf, const Real threshold=0.0) | |
| Constructor. | |
| template<class G > | |
| SparseMatrix (const Space< G > &spc, const F *const v, const int i=-1) | |
| Constructor of partial rank 1 matrix. | |
| SparseMatrix (uint dim) | |
| template<class H > | |
| SparseMatrix (Operator< H > &A, bool slow=false) | |
| Constructor. | |
| template<class H > | |
| SparseMatrix (const SparseMatrix< H > &fncX, F fnc(const H &)) | |
| Constructor. | |
| SparseMatrix (uint nofrows, uint nofcols) | |
| Constructor. | |
| SparseMatrix (const SparseMatrix< F > &m, bool t=false) | |
| Copy constructor. | |
| template<class H > | |
| SparseMatrix (const SparseMatrix< H > &fncX, const F &fnc(const H &)) | |
| bool | storeMatlab (const std::string filename, const std::string name="", bool append=false) const |
| Stores the matrix in a Matlab sparse matrix. | |
| void | symmetrize () |
| Makes sure a theoretically symmetric matrix is symmetric in memory too. | |
| virtual void | transpMult (const Vector< r_type > &fncY, Vector< F > &fncX) |
Multiplies the transpose of the matrix with fncY and adds the results to fncX. | |
| virtual void | transpMult (const Vector< c_type > &fncY, Vector< c_type > &fncX) |
| virtual uint | used () const |
| Returns the number of used entries in the matrix. | |
| void | write (char *fname) const |
| Writes the matrix to a file. | |
Static Public Member Functions | |
| template<class G > | |
| static void | assembly (Matrix< F > &dest, const Space< G > &spc, BilinearForm< F, G > &bf, const Real threshold=0.0) |
Assembly operator for dest using the bilinear form bf. | |
| template<class G > | |
| static void | assembly (Matrix< F > &dest, BilinearForm< F, G > &bf, const ElementPairList< G > &pairs) |
Assembly operator for dest using the bilinear form bf. | |
| template<class G > | |
| static void | assembly (Matrix< F > &dest, const Space< G > &spcX, const Space< G > &spcY, BilinearForm< F, G > &bf, const Real threshold=0.0) |
Assembly operator for dest using the bilinear form bf. | |
Timing Interface | |
These functions are used to get timings from class internal computations. The values are stored in a user defined concepts::InOutParameters structure in different arrays (see concepts::ResultsTable table; table.addMap(concepts::ResultsTable::DOUBLE, "jacobian", output); table.addMap(concepts::ResultsTable::DOUBLE, "whole_sumfact", output); std::ofstream ofs("table.gnuplot"); ofs << std::setprecision(20); table.print<concepts::ResultsTable::GNUPLOT>(ofs); | |
| static void | setTimings (InOutParameters *timings) |
| Sets the class to store the timing values in. | |
| static bool | timings () |
| Returns true if the class is able to do timings. | |
Protected Member Functions | |
| virtual std::ostream & | info (std::ostream &os) const |
| Returns information in an output stream. | |
Protected Attributes | |
| uint | dimX_ |
| Dimension of image space and the source space. | |
| uint | dimY_ |
Private Member Functions | |
| virtual void | apply_ (const Vector< F > &fncY, Vector< F > &fncX) |
| void | copyConstructor_ (const SparseMatrix< F > &m, bool t) |
Private Attributes | |
| std::auto_ptr < HashedSparseMatrix< F > > | m_ |
| The matrix. | |
| uint | nX_ |
| Dimension of image space (spcX_) | |
| uint | nY_ |
| Dimension of source space (spcY_) | |
Static Private Attributes | |
| static uint | storeMatlabCounter_ |
| Counts number of Matlab outputs (used to uniquely name the matrices) | |
Sparse matrix.
The matrix has the size m x n where m is the dimension of the image space (spaceX) and n is the dimension of the source space (spaceY).
The matrix is setup and assembled in the constructor. It calls the bilinear form on every element of the space and uses the T matrices of the elements to assemble the element matrices into the global matrix.
There are quite a few solver which can be used to solve the system.
Definition at line 53 of file sparseMatrix.hh.
| typedef Cmplxtype<F>::type concepts::SparseMatrix< F >::c_type |
Real type of data type.
Reimplemented from concepts::Matrix< F >.
Definition at line 58 of file sparseMatrix.hh.
| typedef _HashedSMatrix_iterator<F, const F&, const F*> concepts::SparseMatrix< F >::const_iterator |
Reimplemented from concepts::Matrix< F >.
Definition at line 61 of file sparseMatrix.hh.
| typedef _HashedSMatrix_iterator<F, F&, F*> concepts::SparseMatrix< F >::iterator |
Reimplemented from concepts::Matrix< F >.
Definition at line 60 of file sparseMatrix.hh.
| typedef Realtype<F>::type concepts::SparseMatrix< F >::r_type |
Real type of data type.
Reimplemented from concepts::Matrix< F >.
Definition at line 56 of file sparseMatrix.hh.
typedef F concepts::Operator< F >::type [inherited] |
Type of data, e.g. matrix entries.
Reimplemented in concepts::AfterIteration< F >, and concepts::SubMatrixN< F >.
Definition at line 43 of file compositions.hh.
typedef F concepts::Matrix< F >::value_type [inherited] |
| concepts::SparseMatrix< F >::SparseMatrix | ( | const Space< G > & | spcX, |
| const Space< G > & | spcY | ||
| ) | [inline] |
| concepts::SparseMatrix< F >::SparseMatrix | ( | uint | nofrows, |
| uint | nofcols | ||
| ) | [inline] |
| concepts::SparseMatrix< F >::SparseMatrix | ( | uint | dim | ) | [inline] |
Definition at line 81 of file sparseMatrix.hh.
| concepts::SparseMatrix< F >::SparseMatrix | ( | const Space< G > & | spcX, |
| const Space< G > & | spcY, | ||
| BilinearForm< F, G > & | bf, | ||
| const Real | threshold = 0.0 |
||
| ) |
Constructor.
Computes the global matrix by assembling the element matrices.
This constructor features a double loop over the elements of the image and the source space. On each combination, the bilinear form is called. You can force this constructor to execute the double loop in such a way that only for diagonal combinations of the elements in both space the integration and assembling is executed. Use single and set it to true.
Use this constructor, if spcX != spcY or if you have local matrices which express the interaction of the two elements., const Real eps = 0.0, const Real eps = 0.0
In non-symmetric FEM (eg. DGFEM), one has to solve AT u = f. This constructor computes A and not AT.
| spcX | Image space |
| spcY | Source space |
| bf | Bilinear form |
| eps | entries, which absolute value is smaller then eps times the maximal absolute value of the element matrix are set to zero. |
| concepts::SparseMatrix< F >::SparseMatrix | ( | const Space< G > & | spc, |
| BilinearForm< F, G > & | bf, | ||
| const Real | threshold = 0.0 |
||
| ) |
Constructor.
Computes the global matrix by assembling the element matrices.
| spc | Image and source space |
| bf | Bilinear form |
| eps | entries, which absolute value is smaller then eps times the maximal absolute value of the element matrix are set to zero. |
| concepts::SparseMatrix< F >::SparseMatrix | ( | const SparseMatrix< F > & | m, |
| bool | t = false |
||
| ) |
Copy constructor.
If t is set to true, the matrix is transposed during the copy process
| concepts::SparseMatrix< F >::SparseMatrix | ( | const Space< G > & | spc, |
| const F *const | v, | ||
| const int | i = -1 |
||
| ) |
Constructor of partial rank 1 matrix.
The matrix is set to
where the bottom entries of x are given by v and, if i >= 0, x(i) = 1 and x(0:i) = 0.
| spc | Image and source space |
| v | Partial vector for rank 1 product |
| i | Shift index, i==-1 means that v has the full size of x |
| concepts::SparseMatrix< F >::SparseMatrix | ( | const Space< G > & | spc, |
| const Vector< F > & | x, | ||
| const Vector< F > & | y | ||
| ) |
Constructor of rank 1 matrix.
The matrix is set to
.
| spc | Image and source space |
| x | First vector |
| y | Second vector |
| concepts::SparseMatrix< F >::SparseMatrix | ( | Operator< H > & | A, |
| bool | slow = false |
||
| ) |
Constructor.
Converts A to a sparse matrix.
In case, the slow mode is allowed, the matrix is computed by multiplying A with the standard basis vectors and entering the results into the matrix. This is a O(n^2) operation.
| A | Operator to store as sparse matrix |
| slow | Also do slow O(n^2) conversion if nothing else is left. |
| concepts::SparseMatrix< F >::SparseMatrix | ( | const SparseMatrix< H > & | fncX, |
| F | fncconst H & | ||
| ) |
Constructor.
Use this constructor to create a matrix of type F out of a matrix with entries of type H. The F type vector consists of elementwise evaluations of the function fnc.
Definition at line 334 of file sparseMatrix.hh.

| concepts::SparseMatrix< F >::SparseMatrix | ( | const SparseMatrix< H > & | fncX, |
| const F & | fncconst H & | ||
| ) |
| concepts::SparseMatrix< F >::SparseMatrix | ( | const SparseMatrix< H > & | fncX | ) |
Constructor.
Use this constructor to create a matrix of type F out of a matrix with entries of type H. The F type vector consists of elementwise conversions.
Definition at line 352 of file sparseMatrix.hh.

| void concepts::SparseMatrix< F >::addInto | ( | Matrix< H > & | dest, |
| const I | fact, | ||
| const uint | rowoffset = 0, |
||
| const uint | coloffset = 0 |
||
| ) | const |
This matrix is added as block to the given matrix dest.
| dest | Matrix into which this matrix should be added. |
| fact | Factor by which this matrix should be multiplied. |
| rowoffset | Row in dest, where block begins. |
| coloffset | Column in dest, where block begins. |
For example: Given a real matrix R. Then one construct a complex one by
SparseMatrix<Cmplx> C(spc,spc);
R.addInto(C, 1.0);
Definition at line 390 of file sparseMatrix.hh.

| void concepts::SparseMatrix< F >::addIntoT | ( | Matrix< H > & | dest, |
| const I | fact, | ||
| const uint | rowoffset = 0, |
||
| const uint | coloffset = 0 |
||
| ) | const |
The transposed of this matrix is added as block to the given matrix.
| dest | Matrix into which this matrix should be added. |
| fact | Factor by which this matrix should be multiplied. |
| rowoffset | Row in dest, where block begins. |
| coloffset | Column in dest, where block begins. |
Definition at line 419 of file sparseMatrix.hh.

| virtual void concepts::SparseMatrix< F >::apply_ | ( | const Vector< F > & | fncY, |
| Vector< F > & | fncX | ||
| ) | [inline, private, virtual] |
Definition at line 326 of file sparseMatrix.hh.
| static void concepts::Matrix< F >::assembly | ( | Matrix< F > & | dest, |
| const Space< G > & | spc, | ||
| BilinearForm< F, G > & | bf, | ||
| const Real | threshold = 0.0 |
||
| ) | [static, inherited] |
Assembly operator for dest using the bilinear form bf.
This assembly operator does not compute element matrices for two different elements. The elements are taken from the space spc.
| static void concepts::Matrix< F >::assembly | ( | Matrix< F > & | dest, |
| const Space< G > & | spcX, | ||
| const Space< G > & | spcY, | ||
| BilinearForm< F, G > & | bf, | ||
| const Real | threshold = 0.0 |
||
| ) | [static, inherited] |
Assembly operator for dest using the bilinear form bf.
This assembly operator computes also the element matrices for two different elements (coming from spcX and spcY).
| static void concepts::Matrix< F >::assembly | ( | Matrix< F > & | dest, |
| BilinearForm< F, G > & | bf, | ||
| const ElementPairList< G > & | pairs | ||
| ) | [static, inherited] |
Assembly operator for dest using the bilinear form bf.
This assembly operator uses the element pairs taken from pairs. For every two elements found in a ElementPair in pairs, the bilinear form is evaluated and the result assembled into dest.
| const_iterator concepts::SparseMatrix< F >::begin | ( | uint | row = 0 | ) | const |
Constant iterator over the elements, standing at position (row,c), where row is the given row number and c the first non-zero entry.
If there is not entry in this line, the iterators stand at the next non-zero entry or it is end(), if the matrix is empty.
Reimplemented from concepts::Matrix< F >.
| iterator concepts::SparseMatrix< F >::begin | ( | uint | row = 0 | ) |
Iterator over the elements, standing at position (row,c), where row is the given row number and c the first non-zero entry.
If there is not entry in this line, the iterators stand at the next non-zero entry or it is end(), if the matrix is empty.
Reimplemented from concepts::Matrix< F >.
| void concepts::SparseMatrix< F >::compress | ( | Real | threshold = EPS | ) | [inline] |
Compresses the matrix by dropping small entries.
All matrix entries which are smaller than a certain threshold times the largest entry of the matrix are deleted from the matrix.
Definition at line 297 of file sparseMatrix.hh.
| virtual void concepts::SparseMatrix< F >::convertCCS | ( | F * | a, |
| int * | asub, | ||
| int * | xa | ||
| ) | const [virtual] |
Converts to CCS format and writes values to field a, the row number asub and the index of the first value of each column xa.
The fields have to be allocated with enough memory.
Implements concepts::CRSConvertable< F >.
| virtual void concepts::SparseMatrix< F >::convertCRS | ( | F * | a, |
| int * | asub, | ||
| int * | xa | ||
| ) | const [virtual] |
Converts to CRS format and writes values to field a, the column number asub and the index of the first value of each row xa.
The fields have to be allocated with enough memory.
Implements concepts::CRSConvertable< F >.
| void concepts::SparseMatrix< F >::copy | ( | const SparseMatrix< F > & | n | ) |
Copies n to this matrix.
| void concepts::SparseMatrix< F >::copyConstructor_ | ( | const SparseMatrix< F > & | m, |
| bool | t | ||
| ) | [private] |
| virtual const uint concepts::Operator< F >::dimX | ( | ) | const [inline, virtual, inherited] |
Returns the size of the image space of the operator (number of rows of the corresponding matrix)
Definition at line 87 of file compositions.hh.
| virtual const uint concepts::Operator< F >::dimY | ( | ) | const [inline, virtual, inherited] |
Returns the size of the source space of the operator (number of columns of the corresponding matrix)
Definition at line 92 of file compositions.hh.
| iterator concepts::Matrix< F >::end | ( | ) | [inline, inherited] |
| const_iterator concepts::SparseMatrix< F >::end | ( | ) | const |
Last entrance of the particular order.
Reimplemented from concepts::Matrix< F >.
| void concepts::SparseMatrix< F >::histogram | ( | std::map< int, uint > & | hist | ) | const |
Creates a histogram of the matrix entries.
| virtual std::ostream& concepts::SparseMatrix< F >::info | ( | std::ostream & | os | ) | const [protected, virtual] |
Returns information in an output stream.
Reimplemented from concepts::Operator< F >.
| const HashedSparseMatrix<F>* concepts::SparseMatrix< F >::m | ( | ) | const [inline] |
Returns the sparse matrix itself.
Definition at line 245 of file sparseMatrix.hh.
| float concepts::SparseMatrix< F >::memory | ( | ) | const [inline] |
Memory usage in byte.
Definition at line 288 of file sparseMatrix.hh.
| void concepts::SparseMatrix< F >::multiply | ( | const SparseMatrix< F > & | fact, |
| Matrix< F > & | dest | ||
| ) | const [inline] |
Multiplies this matrix with fact and adds the result to dest.
Definition at line 277 of file sparseMatrix.hh.
| void concepts::SparseMatrix< F >::multiply | ( | const H & | fact, |
| Matrix< F > & | dest | ||
| ) | const [inline] |
Multiplies this matrix with fact and adds the result to dest.
Definition at line 282 of file sparseMatrix.hh.
| const uint concepts::Matrix< F >::nofCols | ( | ) | const [inline, inherited] |
| const uint concepts::Matrix< F >::nofRows | ( | ) | const [inline, inherited] |
| virtual void concepts::SparseMatrix< F >::operator() | ( | const Function< r_type > & | fncY, |
| Function< F > & | fncX | ||
| ) | [virtual] |
Computes fncX = A(fncY) where A is this matrix.
Implements concepts::Matrix< F >.
| void concepts::SparseMatrix< F >::operator() | ( | const Vector< H > & | fncY, |
| Vector< I > & | fncX | ||
| ) | [inline] |
Multiplies the matrix with fncY. The result is fncX.
Definition at line 195 of file sparseMatrix.hh.
| virtual F concepts::SparseMatrix< F >::operator() | ( | const uint | i, |
| const uint | j | ||
| ) | const [inline, virtual] |
Returns entry with indices i and j.
Implements concepts::Matrix< F >.
Definition at line 224 of file sparseMatrix.hh.
| virtual F& concepts::SparseMatrix< F >::operator() | ( | const uint | i, |
| const uint | j | ||
| ) | [inline, virtual] |
Returns and allows access to entry with indices i and j.
Implements concepts::Matrix< F >.
Definition at line 226 of file sparseMatrix.hh.
| virtual void concepts::SparseMatrix< F >::operator() | ( | const Function< c_type > & | fncY, |
| Function< c_type > & | fncX | ||
| ) | [virtual] |
Application operator for complex function fncY.
Computes fncX = A(fncY) where A is this operator. fncX becomes complex.
In derived classes its enough to implement the operator() for complex Operator's. If a real counterpart is not implemented, the function fncY is splitted into real and imaginary part and the application operator for real functions is called for each. Then the result is combined.
If in a derived class the operator() for complex Operator's is not implemented, a exception is thrown from here.
Implements concepts::Matrix< F >.
| SparseMatrix<F>& concepts::SparseMatrix< F >::operator*= | ( | const F | factor | ) | [inline] |
Definition at line 228 of file sparseMatrix.hh.
| void concepts::SparseMatrix< F >::operator= | ( | const SparseMatrix< F > & | ) |
| virtual bool concepts::Matrix< F >::operator== | ( | const Matrix< F > & | otherMat | ) | const [inline, virtual, inherited] |
| static void concepts::Matrix< F >::setTimings | ( | InOutParameters * | timings | ) | [static, inherited] |
Sets the class to store the timing values in.
Additionally, the timeCntr_ is reset to 0. This counter is used to fill in the values into the arrays listed below in subsequent calls. The following timings are taken and stored in timings:
bilinear_form tmatrix_apply global_assembly | bool concepts::SparseMatrix< F >::storeMatlab | ( | const std::string | filename, |
| const std::string | name = "", |
||
| bool | append = false |
||
| ) | const |
Stores the matrix in a Matlab sparse matrix.
| void concepts::SparseMatrix< F >::symmetrize | ( | ) |
Makes sure a theoretically symmetric matrix is symmetric in memory too.
| static bool concepts::Matrix< F >::timings | ( | ) | [static, inherited] |
Returns true if the class is able to do timings.
The ability to do timings depends on a compiler switch in matrix.cc file.
| virtual void concepts::SparseMatrix< F >::transpMult | ( | const Vector< c_type > & | fncY, |
| Vector< c_type > & | fncX | ||
| ) | [virtual] |
Implements concepts::Matrix< F >.
| virtual void concepts::SparseMatrix< F >::transpMult | ( | const Vector< r_type > & | fncY, |
| Vector< F > & | fncX | ||
| ) | [virtual] |
Multiplies the transpose of the matrix with fncY and adds the results to fncX.
Implements concepts::Matrix< F >.
| virtual uint concepts::SparseMatrix< F >::used | ( | ) | const [inline, virtual] |
Returns the number of used entries in the matrix.
Implements concepts::CRSConvertable< F >.
Definition at line 286 of file sparseMatrix.hh.
| void concepts::SparseMatrix< F >::write | ( | char * | fname | ) | const |
Writes the matrix to a file.
| fname | Filename |
uint concepts::Operator< F >::dimX_ [protected, inherited] |
Dimension of image space and the source space.
Definition at line 96 of file compositions.hh.
uint concepts::Operator< F >::dimY_ [protected, inherited] |
Definition at line 96 of file compositions.hh.
std::auto_ptr<HashedSparseMatrix<F> > concepts::SparseMatrix< F >::m_ [private] |
The matrix.
Definition at line 319 of file sparseMatrix.hh.
uint concepts::SparseMatrix< F >::nX_ [private] |
Dimension of image space (spcX_)
Definition at line 313 of file sparseMatrix.hh.
uint concepts::SparseMatrix< F >::nY_ [private] |
Dimension of source space (spcY_)
Definition at line 316 of file sparseMatrix.hh.
uint concepts::SparseMatrix< F >::storeMatlabCounter_ [static, private] |
Counts number of Matlab outputs (used to uniquely name the matrices)
Definition at line 322 of file sparseMatrix.hh.