concepts::SparseMatrix< F > Class Template Reference
Sparse matrix. More...
#include <compositions.hh>
Public Types | |
typedef Cmplxtype< F >::type | c_type |
Complex type of data type. More... | |
typedef _HashedSMatrix_iterator< F, const F &, const F * > | const_iterator |
typedef std::conditional< std::is_same< typename Realtype< F >::type, F >::value, typename Realtype< F >::type, typename Cmplxtype< F >::type >::type | d_type |
Data type, depending if F is real or complex. More... | |
typedef _HashedSMatrix_iterator< F, F &, F * > | iterator |
typedef Realtype< F >::type | r_type |
Real type of data type. More... | |
Public Member Functions | |
template<class H , class I > | |
void | add (const Vector< H > &v, const I fact, const uint rowoffset=0, const uint coloffset=0) |
Copies the vector v multiplied by fact on position (rowoffset , coloffset ) More... | |
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 . More... | |
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. More... | |
template<class H , class I > | |
void | addT (const Vector< H > &v, const I fact, const uint rowoffset=0, const uint coloffset=0) |
Copies the transpose of the vector v multiplied by fact on position (rowoffset , coloffset ) More... | |
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. More... | |
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. More... | |
void | compress (Real threshold=EPS) |
Compresses the matrix by dropping small entries. More... | |
virtual void | convertCCS (F *a, int *asub, int *xa) const |
virtual void | convertCRS (F *a, int *asub, int *xa) const |
virtual void | convertIJK (F *, int *, int *) const |
void | copy (const SparseMatrix< F > &n) |
Copies n to this matrix. More... | |
const_iterator | end () const |
Last entrance of the particular order. More... | |
void | histogram (std::map< int, uint > &hist) const |
Creates a histogram of the matrix entries. More... | |
const HashedSparseMatrix< F > * | m () const |
Returns the sparse matrix itself. More... | |
float | memory () const |
Memory usage in byte. More... | |
template<class H > | |
void | multiply (const H &fact, Matrix< F > &dest) const |
Multiplies this matrix with fact and adds the result to dest . More... | |
void | multiply (const SparseMatrix< F > &fact, Matrix< F > &dest) const |
Multiplies this matrix with fact and adds the result to dest . More... | |
virtual void | operator() (const Function< c_type > &fncY, Function< c_type > &fncX) |
virtual void | operator() (const Function< r_type > &fncY, Function< F > &fncX) |
virtual F & | operator() (const uint i, const uint j) |
virtual F | operator() (const uint i, const uint j) const |
template<class H , class I > | |
void | operator() (const Vector< H > &fncY, Vector< I > &fncX) |
Multiplies the matrix with fncY . The result is fncX . More... | |
SparseMatrix< F > & | operator*= (const F factor) |
void | operator= (const SparseMatrix< F > &) |
virtual void | resize (uint m, uint n) |
Sets a new size, previous data might be lost More... | |
template<class G > | |
SparseMatrix (const Space< G > &spc, const BilinearForm< F, G > &bf, const Real eps=0.0) | |
Constructor. More... | |
template<class G > | |
SparseMatrix (const Space< G > &spc, const BilinearForm< F, G > &bf, const Sequence< ElementWithCell< G > * > &seq, const Real eps=0.0) | |
Constructor. More... | |
template<class G > | |
SparseMatrix (const Space< G > &spc, const F *const v, const int i=-1) | |
Constructor of partial rank 1 matrix. More... | |
template<class G > | |
SparseMatrix (const Space< G > &spc, const Sequence< bool > &seq, const BilinearForm< F, G > &bf, const Real eps=0.0) | |
Constructor. More... | |
template<class G > | |
SparseMatrix (const Space< G > &spc, const Vector< F > &x, const Vector< F > &y) | |
Constructor of rank 1 matrix. More... | |
template<class G > | |
SparseMatrix (const Space< G > &spcX, const Space< G > &spcY) | |
Constructor. More... | |
template<class G > | |
SparseMatrix (const Space< G > &spcX, const Space< G > &spcY, const BilinearForm< F, G > &bf, const Real eps=0.0, const bool single=false) | |
Constructor. More... | |
template<class G > | |
SparseMatrix (const Space< G > &spcX, const Space< G > &spcY, const BilinearForm< F, G > &bf, const Sequence< ElementWithCell< G > * > &seq, const Real eps=0.0) | |
Constructor. More... | |
template<class G > | |
SparseMatrix (const Space< G > &spcX, const Space< G > &spcY, const Sequence< bool > &seq, const BilinearForm< F, G > &bf, const Real eps=0.0, const bool single=false) | |
Constructor. More... | |
SparseMatrix (const Space< typename Realtype< F >::type > &spc, const BilinearFormContainer< F > bf, const Real eps=0.0) | |
Constructor. More... | |
SparseMatrix (const SparseMatrix< F > &m, bool t=false) | |
Copy constructor. More... | |
template<class H > | |
SparseMatrix (const SparseMatrix< H > &fncX) | |
Constructor. More... | |
template<class H > | |
SparseMatrix (const SparseMatrix< H > &fncX, const F &fnc(const H &)) | |
template<class H > | |
SparseMatrix (const SparseMatrix< H > &fncX, F fnc(const H &)) | |
Constructor. More... | |
template<class H > | |
SparseMatrix (Operator< H > &A, bool slow=false) | |
Constructor. More... | |
SparseMatrix (uint dim=0) | |
SparseMatrix (uint nofrows, uint nofcols) | |
Constructor. More... | |
bool | storeMatlab (const std::string filename, const std::string name="", bool append=false) const |
Stores the matrix in a Matlab sparse matrix. More... | |
void | symmetrize () |
Makes sure a theoretically symmetric matrix is symmetric in memory too. More... | |
virtual void | transpMult (const Vector< c_type > &fncY, Vector< c_type > &fncX) |
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 . More... | |
virtual uint | used () const |
Returns the number of used entries in the matrix. More... | |
void | write (char *fname) const |
Writes the matrix to a file. More... | |
virtual | ~SparseMatrix () |
Protected Member Functions | |
virtual std::ostream & | info (std::ostream &os) const |
Private Member Functions | |
virtual void | apply_ (const Vector< F > &fncY, Vector< F > &fncX) |
void | copyConstructor_ (const SparseMatrix< F > &m, bool t) |
Private Attributes | |
std::unique_ptr< HashedSparseMatrix< F > > | m_ |
The matrix. More... | |
uint | nX_ |
Dimension of image space (spcX_) More... | |
uint | nY_ |
Dimension of source space (spcY_) More... | |
Static Private Attributes | |
static uint | storeMatlabCounter_ |
Counts number of Matlab outputs (used to uniquely name the matrices) More... | |
Detailed Description
template<class F>
class concepts::SparseMatrix< F >
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.
- See also
- TMatrixBase
- CG
- GMRes
- Examples
- arpackppTutorial.cc, BGT_0.cc, elasticity2D_tutorial.cc, and exactDtN.cc.
Definition at line 25 of file compositions.hh.
Member Typedef Documentation
◆ c_type
typedef Cmplxtype<F>::type concepts::SparseMatrix< F >::c_type |
Complex type of data type.
Definition at line 70 of file sparseMatrix.hh.
◆ const_iterator
typedef _HashedSMatrix_iterator<F, const F&, const F*> concepts::SparseMatrix< F >::const_iterator |
Definition at line 76 of file sparseMatrix.hh.
◆ d_type
typedef std::conditional<std::is_same<typename Realtype<F>::type, F>::value , typename Realtype<F>::type, typename Cmplxtype<F>::type >::type concepts::SparseMatrix< F >::d_type |
Data type, depending if F is real or complex.
Definition at line 73 of file sparseMatrix.hh.
◆ iterator
typedef _HashedSMatrix_iterator<F, F&, F*> concepts::SparseMatrix< F >::iterator |
Definition at line 75 of file sparseMatrix.hh.
◆ r_type
typedef Realtype<F>::type concepts::SparseMatrix< F >::r_type |
Real type of data type.
Definition at line 68 of file sparseMatrix.hh.
Constructor & Destructor Documentation
◆ SparseMatrix() [1/17]
|
inline |
◆ SparseMatrix() [2/17]
|
inline |
◆ SparseMatrix() [3/17]
|
inline |
Definition at line 96 of file sparseMatrix.hh.
◆ SparseMatrix() [4/17]
concepts::SparseMatrix< F >::SparseMatrix | ( | const Space< G > & | spcX, |
const Space< G > & | spcY, | ||
const BilinearForm< F, G > & | bf, | ||
const Real | eps = 0.0 , |
||
const bool | single = false |
||
) |
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.
- Parameters
-
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.
◆ SparseMatrix() [5/17]
concepts::SparseMatrix< F >::SparseMatrix | ( | const Space< G > & | spcX, |
const Space< G > & | spcY, | ||
const Sequence< bool > & | seq, | ||
const BilinearForm< F, G > & | bf, | ||
const Real | eps = 0.0 , |
||
const bool | single = false |
||
) |
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.
- Parameters
-
spcX Image space spcY Source space seq Flag on where the elements have to be built 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. single Diagonal parameter flag
◆ SparseMatrix() [6/17]
concepts::SparseMatrix< F >::SparseMatrix | ( | const Space< G > & | spcX, |
const Space< G > & | spcY, | ||
const BilinearForm< F, G > & | bf, | ||
const Sequence< ElementWithCell< G > * > & | seq, | ||
const Real | eps = 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.
- Parameters
-
spcX Image space spcY Source space bf Bilinear form seq Sequence of elements to take into account for the Image space eps entries, which absolute value is smaller then eps times the maximal absolute value of the element matrix are set to zero.
◆ SparseMatrix() [7/17]
concepts::SparseMatrix< F >::SparseMatrix | ( | const Space< G > & | spc, |
const BilinearForm< F, G > & | bf, | ||
const Real | eps = 0.0 |
||
) |
Constructor.
Computes the global matrix by assembling the element matrices.
- Parameters
-
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.
◆ SparseMatrix() [8/17]
concepts::SparseMatrix< F >::SparseMatrix | ( | const Space< typename Realtype< F >::type > & | spc, |
const BilinearFormContainer< F > | bf, | ||
const Real | eps = 0.0 |
||
) |
Constructor.
Computes the global matrix by assembling the element matrices.
- Parameters
-
spc Image and source space bf bilinearform Container eps entries, which absolute value is smaller then eps times the maximal absolute value of the element matrix are set to zero.
◆ SparseMatrix() [9/17]
concepts::SparseMatrix< F >::SparseMatrix | ( | const Space< G > & | spc, |
const Sequence< bool > & | seq, | ||
const BilinearForm< F, G > & | bf, | ||
const Real | eps = 0.0 |
||
) |
Constructor.
Computes the global matrix by assembling the element matrices.
- Parameters
-
spc Image and source space seq Flag on where the elements have to be built 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.
◆ SparseMatrix() [10/17]
concepts::SparseMatrix< F >::SparseMatrix | ( | const Space< G > & | spc, |
const BilinearForm< F, G > & | bf, | ||
const Sequence< ElementWithCell< G > * > & | seq, | ||
const Real | eps = 0.0 |
||
) |
Constructor.
Computes the partial matrix by assembling the element matrices on a given subdomain
- Parameters
-
spc Image and source space bf Bilinear form seq Sequence of elements to take into account eps entries, which absolute value is smaller then eps times the maximal absolute value of the element matrix are set to zero.
◆ SparseMatrix() [11/17]
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
◆ SparseMatrix() [12/17]
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.
- Parameters
-
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
◆ SparseMatrix() [13/17]
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 .
- Parameters
-
spc Image and source space x First vector y Second vector
◆ SparseMatrix() [14/17]
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.
- Parameters
-
A Operator to store as sparse matrix slow Also do slow O(n^2) conversion if nothing else is left.
◆ SparseMatrix() [15/17]
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 482 of file sparseMatrix.hh.
◆ SparseMatrix() [16/17]
concepts::SparseMatrix< F >::SparseMatrix | ( | const SparseMatrix< H > & | fncX, |
const F & | fncconst H & | ||
) |
Definition at line 518 of file sparseMatrix.hh.
◆ SparseMatrix() [17/17]
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 500 of file sparseMatrix.hh.
◆ ~SparseMatrix()
|
inlinevirtual |
Definition at line 313 of file sparseMatrix.hh.
Member Function Documentation
◆ add()
void concepts::SparseMatrix< F >::add | ( | const Vector< H > & | v, |
const I | fact, | ||
const uint | rowoffset = 0 , |
||
const uint | coloffset = 0 |
||
) |
Copies the vector v
multiplied by fact
on position (rowoffset
, coloffset
)
Definition at line 597 of file sparseMatrix.hh.
◆ addInto()
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
.
- Parameters
-
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 538 of file sparseMatrix.hh.
◆ addIntoT()
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.
- Parameters
-
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 567 of file sparseMatrix.hh.
◆ addT()
void concepts::SparseMatrix< F >::addT | ( | const Vector< H > & | v, |
const I | fact, | ||
const uint | rowoffset = 0 , |
||
const uint | coloffset = 0 |
||
) |
Copies the transpose of the vector v
multiplied by fact
on position (rowoffset
, coloffset
)
Definition at line 613 of file sparseMatrix.hh.
◆ apply_()
|
inlineprivatevirtual |
Definition at line 474 of file sparseMatrix.hh.
◆ begin() [1/2]
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.
◆ begin() [2/2]
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.
◆ compress()
|
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 444 of file sparseMatrix.hh.
◆ convertCCS()
|
virtual |
◆ convertCRS()
|
virtual |
◆ convertIJK()
|
virtual |
◆ copy()
void concepts::SparseMatrix< F >::copy | ( | const SparseMatrix< F > & | n | ) |
Copies n
to this matrix.
◆ copyConstructor_()
|
private |
◆ end()
const_iterator concepts::SparseMatrix< F >::end | ( | ) | const |
Last entrance of the particular order.
◆ histogram()
void concepts::SparseMatrix< F >::histogram | ( | std::map< int, uint > & | hist | ) | const |
Creates a histogram of the matrix entries.
◆ info()
|
protectedvirtual |
◆ m()
|
inline |
Returns the sparse matrix itself.
Definition at line 378 of file sparseMatrix.hh.
◆ memory()
|
inline |
Memory usage in byte.
Definition at line 435 of file sparseMatrix.hh.
◆ multiply() [1/2]
|
inline |
Multiplies this matrix with fact
and adds the result to dest
.
Definition at line 429 of file sparseMatrix.hh.
◆ multiply() [2/2]
|
inline |
Multiplies this matrix with fact
and adds the result to dest
.
Definition at line 424 of file sparseMatrix.hh.
◆ operator()() [1/5]
|
virtual |
◆ operator()() [2/5]
|
virtual |
◆ operator()() [3/5]
|
inlinevirtual |
Definition at line 353 of file sparseMatrix.hh.
◆ operator()() [4/5]
|
inlinevirtual |
Definition at line 351 of file sparseMatrix.hh.
◆ operator()() [5/5]
|
inline |
Multiplies the matrix with fncY
. The result is fncX
.
Definition at line 322 of file sparseMatrix.hh.
◆ operator*=()
|
inline |
Definition at line 355 of file sparseMatrix.hh.
◆ operator=()
void concepts::SparseMatrix< F >::operator= | ( | const SparseMatrix< F > & | ) |
◆ resize()
|
inlinevirtual |
Sets a new size, previous data might be lost
Definition at line 361 of file sparseMatrix.hh.
◆ storeMatlab()
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.
- Returns
- true if the writes was successfull
◆ symmetrize()
void concepts::SparseMatrix< F >::symmetrize | ( | ) |
Makes sure a theoretically symmetric matrix is symmetric in memory too.
◆ transpMult() [1/2]
|
virtual |
◆ transpMult() [2/2]
|
virtual |
Multiplies the transpose of the matrix with fncY
and adds the results to fncX
.
◆ used()
|
inlinevirtual |
Returns the number of used entries in the matrix.
Definition at line 433 of file sparseMatrix.hh.
◆ write()
void concepts::SparseMatrix< F >::write | ( | char * | fname | ) | const |
Writes the matrix to a file.
- Parameters
-
fname Filename
Member Data Documentation
◆ m_
|
private |
The matrix.
Definition at line 467 of file sparseMatrix.hh.
◆ nX_
|
private |
Dimension of image space (spcX_)
Definition at line 461 of file sparseMatrix.hh.
◆ nY_
|
private |
Dimension of source space (spcY_)
Definition at line 464 of file sparseMatrix.hh.
◆ storeMatlabCounter_
|
staticprivate |
Counts number of Matlab outputs (used to uniquely name the matrices)
Definition at line 470 of file sparseMatrix.hh.
The documentation for this class was generated from the following files:
- operator/compositions.hh
- operator/sparseMatrix.hh