NUMCXX  0.13.20181108
Numerical library for small projects and teaching purposes
Functions
17-numcxx-cg.cxx File Reference
+ Include dependency graph for 17-numcxx-cg.cxx:

Go to the source code of this file.

Functions

int main (void)
 

Function Documentation

int main ( void  )

Definition at line 14 of file 17-numcxx-cg.cxx.

15 {
16  int n=5000; // problem size
17  int max_iter=100; // maximum number of iterations
18  double tol=1.0e-14; // tolerance
19 
20  auto pA=numcxx::DSparseMatrix::create(n,n);
21  auto pF=numcxx::DArray1::create(n);
22  auto pU=numcxx::DArray1::create(n);
23 
24  auto &A=*pA;
25  auto &F=*pF;
26  auto &U=*pU;
27 
28  F=1.0;
29  for (int i=0;i<n;i++)
30  {
31  A(i,i)=3.0;
32  if (i>0) A(i,i-1)=-1;
33  if (i<n-1) A(i,i+1)=-1;
34  }
35  pA->flush();
36 
37 
38  auto pJacobi=numcxx::DPreconJacobi::create(pA);
39  numcxx::TPreconJacobi<double> JacobiSolver(pA);
40 
41 
42  U=0.0;
43  netlib::CG(A,U,F,*pJacobi,max_iter,tol);
44  double residual=normi(A*U-F);
45  std::cout << "residual:" << residual << std::endl;
46 }
static std::shared_ptr< TPreconJacobi< T > > create(const std::shared_ptr< TSparseMatrix< T >> pA)
Create preconditioner.
Jacobi preconditioner class.
A::value_type normi(const A &a)
Maximum norm of array or expression.
Definition: util.ixx:26
int CG(const Matrix &A, Vector &x, const Vector &b, const Preconditioner &M, int &max_iter, Real &tol)
Iterative template routine – CG.
Definition: cg.hxx:28
static std::shared_ptr< TArray1< T > > create(index n1)
Construct smart pointer empty 1D Array.
Definition: tarray1.hxx:81
static std::shared_ptr< TSparseMatrix< T > > create(index n1, index n2)
Static wrapper around corresponding constructor.

+ Here is the call graph for this function: