Blame view

fvn_test/test_sparse_dl.f90 1.56 KB
2b83390c6   wdaniau   1) added fvn_spar...
1
2
3
4
5
6
7
8
9
10
11
  program test_sparse
  ! test sparse routine dl, real(8) and integer(8)
  use fvn
  implicit none
  integer(kind=dp_kind), parameter :: nz=12
  integer(kind=dp_kind), parameter :: n=5
  real(kind=dp_kind),dimension(nz) :: A
  real(kind=dp_kind),dimension(n,n) :: As
  integer(kind=dp_kind),dimension(nz) :: Ti,Tj
  real(kind=dp_kind),dimension(n) :: B,x
  integer(kind=dp_kind) :: status,i
c64a05f8a   wdaniau   Sparse Determinan...
12
  real(kind=dp_kind),dimension(2) :: det
2b83390c6   wdaniau   1) added fvn_spar...
13
14
15
16
17
18
19
20
21
22
23
24
  ! Description of the matrix in triplet form
  A = (/ 2.,3.,3.,-1.,4.,4.,-3.,1.,2.,2.,6.,1. /)
  B = (/ 8., 45., -3., 3., 19./)
  Ti = (/ 1,2,1,3,5,2,3,4,5,3,2,5 /)
  Tj = (/ 1,1,2,2,2,3,3,3,3,4,5,5 /)
  
  ! Reconstruction of the matrix in standard form
  ! just needed for printing the matrix here
  As=0.
  do i=1,nz
      As(Ti(i),Tj(i))=A(i)
  end do
4bd212285   wdaniau   Changed sparse ro...
25
26
27
28
  
  ! sparse routines must be fed up with 0-based indices
  Ti=Ti-1
  Tj=Tj-1
2b83390c6   wdaniau   1) added fvn_spar...
29
30
31
32
33
34
35
36
37
38
39
40
41
  write(*,*) "Matrix in standard representation :"
  do i=1,5
      write(*,'(5f8.4)') As(i,:)
  end do
  write(*,*)
  write(*,*) "Standard determinant =", fvn_det(5,As)
  write(*,*)
  write(*,'("Right hand side :",5f8.4)') B
  
  ! can use either specific interface, fvn_dl_sparse_det
  ! either generic one fvn_sparse_det
  call fvn_dl_sparse_det(n,nz,A,Ti,Tj,det,status)
  write(*,*)
c64a05f8a   wdaniau   Sparse Determinan...
42
  write(*,*) "Sparse Det = ",det(1)*10**det(2)
2b83390c6   wdaniau   1) added fvn_spar...
43
44
45
46
47
  ! can use either specific interface fvn_dl_sparse_solve
  ! either generic one fvn_sparse_solve
  ! parameter det is optional
  call fvn_dl_sparse_solve(n,nz,A,Ti,Tj,B,x,status,det)
  write(*,*)
c64a05f8a   wdaniau   Sparse Determinan...
48
  write(*,*) "Sparse Det as solve option = ",det(1)*10**det(2)
2b83390c6   wdaniau   1) added fvn_spar...
49
50
51
52
53
  write(*,*)
  write(*,'("Solution :",5f8.4)') x
  write(*,*)
  write(*,'("Product matrix Solution :",5f8.4)') matmul(As,x)
  end program