NUMCXX  0.13.20181108
Numerical library for small projects and teaching purposes
tsparsematrix.hxx
Go to the documentation of this file.
1 
7 #ifndef NUMCXX_TSPARSEMATRIX_H
8 #define NUMCXX_TSPARSEMATRIX_H
9 
10 #include <vector>
11 #include "tarray1.hxx"
12 #include "tmatrix.hxx"
13 
14 namespace numcxx
15 {
16 
17  template<typename T> class TSolverUMFPACK;
18  template<typename T> class TPreconJacobi;
19  template<typename T> class TPreconILU;
20 
22  template<typename T>
23  class TSparseMatrix: public TLinOperator<T>, public SparseMatrixExpressionBase
24  {
25  friend class TSolverUMFPACK<T>;
26  friend class TPreconJacobi<T>;
27  friend class TPreconILU<T>;
28  public:
29  typedef T value_type;
30 
31  TSparseMatrix():n(0) {};
32 
36  TSparseMatrix(index n1, index n2);
37 
38 
40  static std::shared_ptr<TSparseMatrix <T> > create(index n1, index n2) {return std::make_shared<TSparseMatrix<T>>(n1,n2);}
41 
44  TSparseMatrix(const std::initializer_list<std::initializer_list<T>> &il);
45 
47  static std::shared_ptr<TSparseMatrix <T> > create(const std::initializer_list<std::initializer_list<T>> &il);
48 
49 
56  T& operator()(int i, int j);
57 
60  void flush();
61 
62 
63  void clear() { flush(); (*pIA)=0.0;}
64 
66  void apply(const TArray<T> &U,TArray<T> &V ) const;
67 
69  std::shared_ptr<TMatrix<T>> copy_as_dense();
70 
72  index shape(int idim) const {return n;}
73 
75  TSparseMatrix(const TSparseMatrix<T>& A)=delete;
76 
77 
78  // std::shared_ptr<TSparseMatrix <T> > copy() const;
79  // std::shared_ptr<TSparseMatrix <T> > clone() const;
80  // T xentry(const index i, const index j) const {return _data[_idx(i,j)];}
81  // template <typename VAL>
82  // TSparseMatrix<T>& operator=(const VAL &expr) { assign(*this,expr); return *this;}
83  // TSparseMatrix<T>& operator=(const TSparseMatrix<T> &expr) { assign(*this,expr); return *this;}
84  // void apply(const TArray1<T> &u, TArray1<T> &v) const;
85 
87  std::shared_ptr<TArray1<int>> pIA;
88 
90  std::shared_ptr<TArray1<int>> pJA;
91 
93  std::shared_ptr<TArray1 <T> > pA;
94 
96  std::shared_ptr<TMatrix<T>> calculate_inverse();
97 
100  bool pattern_changed() const {return _pattern_changed;}
101 
102  private:
103 
104 
105 
106 
107  void pattern_changed(bool chg) {_pattern_changed=chg;};
108 
109 
110  bool _pattern_changed=false;
111  const index n;
112  int maxrow=0;
113 
114  bool _first_flush_done=false;
115  bool empty() const { return !_first_flush_done;};
117  class RowEntry;
118 
120  class Extension;
121 
122  std::shared_ptr<Extension> pExt=nullptr;
123 
124  };
125 
126 }
127 
128 #include "tsparsematrix.ixx"
129 #endif
std::shared_ptr< TArray1< int > > pJA
Column indices.
Jacobi preconditioner class.
std::shared_ptr< TMatrix< T > > calculate_inverse()
Calculate inverse of sparse matrix whuch is dense.
Sparse matrix class using CRS storage scheme.
std::shared_ptr< TMatrix< T > > copy_as_dense()
Create a dense matrix from the sparse matrix.
Header for numcxx::TMatrix.
Header for numcxx::TArray1.
std::shared_ptr< Extension > pExt
void flush()
Re-create the internal data structure in order to accomodated all newly created elements.
TArray is the common template base class for arrays and dense matrices of the numcxx project...
Definition: tarray.hxx:17
bool pattern_changed() const
Check if pattern has changed after last solver update.
ILU preconditioner class.
Definition: tprecon-ilu.hxx:16
void pattern_changed(bool chg)
std::shared_ptr< TArray1< T > > pA
Entries.
unsigned int index
Definition: numcxx.hxx:21
Inline method definitions for class numcxx::TSparseMatrix.
index shape(int idim) const
Return the shape od the matrix.
void apply(const TArray< T > &U, TArray< T > &V) const
Apply sparse matrix to vector.
Numcxx template library.
Definition: expression.ixx:41
T & operator()(int i, int j)
Access operator.
Bridge class for using umfpack as solver for vmatrix.
static std::shared_ptr< TSparseMatrix< T > > create(index n1, index n2)
Static wrapper around corresponding constructor.
Base class for linear operators (matrices, sparse matrices)
Definition: tarray.hxx:284
std::shared_ptr< TArray1< int > > pIA
Row pointers.