NUMCXX  0.13.20181108
Numerical library for small projects and teaching purposes
16-numcxx-umfpack-sharedptr.cxx
Go to the documentation of this file.
1 
7 #include <iostream>
8 #include <limits>
9 #include <cassert>
10 #include <numcxx/numcxx.hxx>
11 
12 
13 int main(void)
14 {
15  int n=5000;
16  auto pA=numcxx::DSparseMatrix::create(n,n);
17  auto pF=numcxx::DArray1::create(n);
18  auto pU=numcxx::DArray1::create(n);
19 
20  auto &A=*pA;
21  auto &F=*pF;
22  auto &U=*pU;
23 
24  F=1.0;
25  for (int i=0;i<n;i++)
26  {
27  A(i,i)=3.0;
28  if (i>0) A(i,i-1)=-1;
29  if (i<n-1) A(i,i+1)=-1;
30  }
31  pA->flush();
32 
33  auto pUmfpack=numcxx::DSolverUMFPACK::create(pA);
34  pUmfpack->update();
35  pUmfpack->solve(U,F);
36  double residual=normi(A*U-F);
37 
38  std::cout << "residual:" << residual << std::endl;
39 }
40 
41 
static std::shared_ptr< TSolverUMFPACK< T > > create(const std::shared_ptr< TSparseMatrix< T >> pA)
Create LU factorization class.
A::value_type normi(const A &a)
Maximum norm of array or expression.
Definition: util.ixx:26
Main header of the library.
static std::shared_ptr< TArray1< T > > create(index n1)
Construct smart pointer empty 1D Array.
Definition: tarray1.hxx:81
int main(void)
static std::shared_ptr< TSparseMatrix< T > > create(index n1, index n2)
Static wrapper around corresponding constructor.