NUMCXX  0.13.20181108
Numerical library for small projects and teaching purposes
tprecon-jacobi.ixx
Go to the documentation of this file.
1 #include <cassert>
2 namespace numcxx
3 {
4 
6  template<typename T>
7  inline TPreconJacobi<T>::TPreconJacobi(const std::shared_ptr<TSparseMatrix<T>> pMatrix)
8  {
9  pInvDiag=std::make_shared<TArray1<T>>(pMatrix->shape(0));
10  update(*pMatrix);
11  }
12 
13  template<typename T>
15  {
16  pInvDiag=std::make_shared<TArray1<T>>(A.shape(0));
17  update(A);
18  }
19 
20 
22  template<typename T>
23  inline std::shared_ptr<TPreconJacobi<T>> TPreconJacobi<T>::create(const std::shared_ptr<TSparseMatrix<T>> pA)
24  {
25  return std::make_shared<TPreconJacobi<T>>(pA);
26  }
27 
29  template<typename T>
31  {
32  int n=M.shape(0);
33  assert(n==pInvDiag->size());
34  auto &InvDiag=*pInvDiag;
35  for (int i=0;i<n;i++)
36  InvDiag(i)=1.0/M(i,i);
37 
38  M.pattern_changed(false);
39  }
40 
42  template<typename T>
43  inline void TPreconJacobi<T>::solve( TArray<T> & Sol, const TArray<T> & Rhs) const
44  {
45  Sol.resize(Rhs.size());
46  int n=pInvDiag->size();
47  auto &InvDiag=*pInvDiag;
48  for (int i=0;i<n;i++)
49  Sol(i)=Rhs(i)*InvDiag(i);
50  }
51 
52 
53 }
static std::shared_ptr< TPreconJacobi< T > > create(const std::shared_ptr< TSparseMatrix< T >> pA)
Create preconditioner.
Sparse matrix class using CRS storage scheme.
void solve(TArray< T > &Sol, const TArray< T > &Rhs) const
Solve preconditioning system.
TPreconJacobi(const std::shared_ptr< TSparseMatrix< T >> pA)
Create Preconditioner.
TArray is the common template base class for arrays and dense matrices of the numcxx project...
Definition: tarray.hxx:17
size_t size() const
Obtain size of array.
Definition: tarray.hxx:58
bool pattern_changed() const
Check if pattern has changed after last solver update.
virtual void update(void)
Definition: tarray.hxx:280
index shape(int idim) const
Return the shape od the matrix.
void resize(size_t n)
Resize array.
Definition: tarray.ixx:282
Numcxx template library.
Definition: expression.ixx:41