NUMCXX  0.13.20181108
Numerical library for small projects and teaching purposes
Public Member Functions | Static Public Member Functions | Public Attributes | Private Attributes | List of all members
numcxx::TPreconILU< T > Class Template Reference

Description

template<typename T>
class numcxx::TPreconILU< T >

ILU preconditioner class.

Definition at line 16 of file tprecon-ilu.hxx.

+ Inheritance diagram for numcxx::TPreconILU< T >:
+ Collaboration diagram for numcxx::TPreconILU< T >:

Public Member Functions

 TPreconILU (const std::shared_ptr< TSparseMatrix< T >> pA)
 Create Preconditioner. More...
 
 TPreconILU (TSparseMatrix< T > &A)
 
 ~TPreconILU ()
 
void update (TSparseMatrix< T > &A)
 Perform actual computation preconditioner. More...
 
void solve (TArray< T > &Sol, const TArray< T > &Rhs) const
 Solve preconditioning system. More...
 
virtual void update (void)
 

Static Public Member Functions

static std::shared_ptr< TPreconILU< T > > create (const std::shared_ptr< TSparseMatrix< T >> pA)
 Create preconditioner. More...
 

Public Attributes

std::shared_ptr< TArray1< T > > pInvDiag
 
std::shared_ptr< TArray1< int > > pDiagIdx
 

Private Attributes

std::shared_ptr< TArray1< T > > pA
 
std::shared_ptr< TArray1< int > > pIA
 
std::shared_ptr< TArray1< int > > pJA
 

Constructor & Destructor Documentation

template<typename T >
numcxx::TPreconILU< T >::TPreconILU ( const std::shared_ptr< TSparseMatrix< T >>  pA)
inline

Create Preconditioner.

Definition at line 7 of file tprecon-ilu.ixx.

8  {
9  pInvDiag=std::make_shared<TArray1<T>>(pMatrix->shape(0));
10  pDiagIdx=std::make_shared<TArray1<int>>(pMatrix.shape(0));
11  update(*pMatrix);
12  }
std::shared_ptr< TArray1< T > > pInvDiag
Definition: tprecon-ilu.hxx:20
virtual void update(void)
Definition: tarray.hxx:280
std::shared_ptr< TArray1< int > > pDiagIdx
Definition: tprecon-ilu.hxx:21
template<typename T >
numcxx::TPreconILU< T >::TPreconILU ( TSparseMatrix< T > &  A)
inline

Definition at line 15 of file tprecon-ilu.ixx.

16  {
17  pInvDiag=std::make_shared<TArray1<T>>(A.shape(0));
18  pDiagIdx=std::make_shared<TArray1<int>>(A.shape(0));
19  update(A);
20  }
std::shared_ptr< TArray1< T > > pInvDiag
Definition: tprecon-ilu.hxx:20
virtual void update(void)
Definition: tarray.hxx:280
std::shared_ptr< TArray1< int > > pDiagIdx
Definition: tprecon-ilu.hxx:21

+ Here is the call graph for this function:

template<typename T >
numcxx::TPreconILU< T >::~TPreconILU ( )
inline

Definition at line 27 of file tprecon-ilu.hxx.

27 {};

+ Here is the call graph for this function:

Member Function Documentation

template<typename T >
std::shared_ptr< TPreconILU< T > > numcxx::TPreconILU< T >::create ( const std::shared_ptr< TSparseMatrix< T >>  pA)
inlinestatic

Create preconditioner.

Definition at line 24 of file tprecon-ilu.ixx.

25  {
26  return std::make_shared<TPreconILU<T>>(pA);
27  }
std::shared_ptr< TArray1< T > > pA
Definition: tprecon-ilu.hxx:39
template<typename T >
void numcxx::TPreconILU< T >::update ( TSparseMatrix< T > &  A)
inline

Perform actual computation preconditioner.

Perform actual computation of LU factorization.

Definition at line 31 of file tprecon-ilu.ixx.

32  {
33 
34  int n=M.shape(0);
35  pA=M.pA;
36  pIA=M.pIA;
37  pJA=M.pJA;
38 
39  auto & A=*pA;
40  auto & IA=*pIA;
41  auto & JA=*pJA;
42  auto & XD=*pInvDiag;
43  auto & ID=*pDiagIdx;
44 
45  for (int i=0; i<n; i++)
46  {
47  for (int j=IA(i);j<IA(i+1);j++)
48  if (JA(j)==i)
49  {
50  ID(i)=j;
51  break;
52  }
53  XD(i)=A(ID(i));
54  }
55 
56  for (int i=0; i<n; i++)
57  {
58  XD(i)=1.0/XD(i);
59  for(int j=ID(i)+1;j<IA(i+1);j++)
60  {
61  int k;
62  bool found=false;
63  for(k=IA(JA(j));k<IA(JA(j)+1);k++)
64  {
65  if (JA(k)==i)
66  {
67  found=true;
68  break;
69  }
70  }
71  if (found) XD(JA(j))-=A(k)*XD(i)*A(j);
72  }
73  }
74 
75  M.pattern_changed(false);
76  }
std::shared_ptr< TArray1< T > > pA
Definition: tprecon-ilu.hxx:39
std::shared_ptr< TArray1< int > > pIA
Definition: tprecon-ilu.hxx:40
std::shared_ptr< TArray1< T > > pInvDiag
Definition: tprecon-ilu.hxx:20
std::shared_ptr< TArray1< int > > pJA
Definition: tprecon-ilu.hxx:41
std::shared_ptr< TArray1< int > > pDiagIdx
Definition: tprecon-ilu.hxx:21

+ Here is the call graph for this function:

template<typename T >
void numcxx::TPreconILU< T >::solve ( TArray< T > &  Sol,
const TArray< T > &  Rhs 
) const
inlinevirtual

Solve preconditioning system.

Solve LU factorized system.

Reimplemented from numcxx::TLinSolver< T >.

Definition at line 80 of file tprecon-ilu.ixx.

81  {
82  int n=pIA->size()-1;
83  auto & A=*pA;
84  auto & IA=*pIA;
85  auto & JA=*pJA;
86  auto & XD=*pInvDiag;
87  auto & ID=*pDiagIdx;
88 
89  Sol.resize(Rhs.size());
90  for (int i=0; i<n; i++)
91  {
92  T x=0.0;
93  for(int j=IA(i);j<ID(i);j++)
94  x+=A(j)*Sol(JA(j));
95  Sol(i)=XD(i)*(Rhs(i)-x);
96  }
97 
98  for (int i=n-1; i>=0; i--)
99  {
100  T x=0.0;
101  for(int j=ID(i)+1;j<IA(i+1);j++)
102  x += Sol(JA(j))*A(j);
103  Sol(i)-=x*XD(i);
104  }
105  }
std::shared_ptr< TArray1< T > > pA
Definition: tprecon-ilu.hxx:39
std::shared_ptr< TArray1< int > > pIA
Definition: tprecon-ilu.hxx:40
std::shared_ptr< TArray1< T > > pInvDiag
Definition: tprecon-ilu.hxx:20
std::shared_ptr< TArray1< int > > pJA
Definition: tprecon-ilu.hxx:41
std::shared_ptr< TArray1< int > > pDiagIdx
Definition: tprecon-ilu.hxx:21

+ Here is the call graph for this function:

template<typename T >
virtual void numcxx::TLinSolver< T >::update ( void  )
inlinevirtualinherited

Reimplemented in numcxx::TSolverUMFPACK< T >, and numcxx::TSolverLapackLU< T >.

Definition at line 280 of file tarray.hxx.

280 {};

Member Data Documentation

template<typename T >
std::shared_ptr< TArray1<T> > numcxx::TPreconILU< T >::pInvDiag

Definition at line 20 of file tprecon-ilu.hxx.

template<typename T >
std::shared_ptr< TArray1<int> > numcxx::TPreconILU< T >::pDiagIdx

Definition at line 21 of file tprecon-ilu.hxx.

template<typename T >
std::shared_ptr<TArray1<T> > numcxx::TPreconILU< T >::pA
private

Definition at line 39 of file tprecon-ilu.hxx.

template<typename T >
std::shared_ptr<TArray1<int> > numcxx::TPreconILU< T >::pIA
private

Definition at line 40 of file tprecon-ilu.hxx.

template<typename T >
std::shared_ptr<TArray1<int> > numcxx::TPreconILU< T >::pJA
private

Definition at line 41 of file tprecon-ilu.hxx.


The documentation for this class was generated from the following files: