-
Notifications
You must be signed in to change notification settings - Fork 0
/
tridagr.F90
73 lines (60 loc) · 1.88 KB
/
tridagr.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
subroutine tridagr(ar,br,cr,knownr,potr)
implicit none
include 'runhydro.h'
include 'pot.h'
!***************************************************************************
!*
! tridagr solves for potr from the linear tridiagonal system of equations
! with br being the diagonal elements of the matrix, ar and cr are the
! off-diagonal elements and knownr is the right hand side. The code
! comes from section 2.4, page 43 of Numerical Recipes in Fortran, 2nd ed.
!*
!***************************************************************************
!*
!* Subroutine Arguments
real, dimension(numr) :: ar, cr
real, dimension(numr,numphi) :: br
real, dimension(numr,numz,numphi) :: knownr, potr
!*
!***************************************************************************
!*
!* Local Variables
real, dimension(numr,numphi) :: bet, gam
integer :: j, k, l
!*
!***************************************************************************
! initialize the local variables
gam = 0.0
bet = 0.0
j = 0
k = 0
l = 0
! setup
do l = 1, numphi
bet(2,l) = br(2,l)
enddo
do l = 1, numphi
do k = zlwb, zupb
potr(2,k,l) = knownr(2,k,l) / bet(2,l)
enddo
enddo
! decomposition and forward substitution
do l = 1, numphi
do j = 3, numr-1
gam(j,l) = cr(j-1) / bet(j-1,l)
bet(j,l) = br(j,l) - ar(j)*gam(j,l)
do k = zlwb, zupb
potr(j,k,l) = (knownr(j,k,l)-ar(j)*potr(j-1,k,l))/ bet(j,l)
enddo
enddo
enddo
! back subsitution
do l = 1, numphi
do k = zlwb, zupb
do j = numr-2, 2, -1
potr(j,k,l) = potr(j,k,l) - gam(j+1,l)*potr(j+1,k,l)
enddo
enddo
enddo
return
end subroutine tridagr