[Fortran] 纯文本查看 复制代码
subroutine absorption(p0,p,m,lamda,kmax,mmax,nmax)
!solve the second part
implicit none
integer :: i,m
integer :: kmax,mmax,nmax
real,dimension(kmax,mmax,nmax) :: p,p0
real,dimension(nmax):: x,y
real,dimension(nmax):: a,c,d
real,external :: work
! y-p_m,x-p_m+1
real :: lamda
do i=1,nmax
a(i)=-lamda
c(i)=-lamda
d(i)=1+2*lamda
end do
do i=1,kmax
y=p0(i,m,:)
x=work(a,c,d,y,nmax)
p(i,m,:)=x(:)
end do
end subroutine absorption
[Fortran] 纯文本查看 复制代码
function work(a,c,d,b,ranka)
! lamda-matrix A;y-right side;m-A(rank-1*rank-1)
implicit none
integer ranka,i
real,dimension(ranka):: a,c,d,work,y,b,r,delta,beta
!real :: lamda,d,c,a
!d=1+2*lamda
!a=-lamda
!c=-a
r(1)=d(1)
delta(1)=c(1)/r(1)
y(1)=b(1)/r(1)
do i=2,ranka
beta(i)=a(i)
r(i)=d(i)-beta(i)*delta(i-1)
delta(i)=c(i)/r(i)
y(i)=(b(i)-beta(i)*y(i-1))/r(i)
end do
! step1:Ly=b
work(ranka)=y(ranka)
do i=ranka-1,1,-1
work(i)=y(i)-delta(i)*work(i+1)
end do
! step2:Ux(work)=y
end function work
[Fortran] 纯文本查看 复制代码
module workMod
contains
function work(a,c,d,b,ranka)
! lamda-matrix A;y-right side;m-A(rank-1*rank-1)
implicit none
integer ranka,i
real,dimension(ranka):: a,c,d,work,y,b,r,delta,beta
!real :: lamda,d,c,a
!d=1+2*lamda
!a=-lamda
!c=-a
r(1)=d(1)
delta(1)=c(1)/r(1)
y(1)=b(1)/r(1)
do i=2,ranka
beta(i)=a(i)
r(i)=d(i)-beta(i)*delta(i-1)
delta(i)=c(i)/r(i)
y(i)=(b(i)-beta(i)*y(i-1))/r(i)
end do
! step1:Ly=b
work(ranka)=y(ranka)
do i=ranka-1,1,-1
work(i)=y(i)-delta(i)*work(i+1)
end do
! step2:Ux(work)=y
end function work
end module workMod
subroutine absorption(p0,p,m,lamda,kmax,mmax,nmax)
use workMod
implicit none
integer :: i,m
integer :: kmax,mmax,nmax
real,dimension(kmax,mmax,nmax) :: p,p0
real,dimension(nmax):: x,y
real,dimension(nmax):: a,c,d
! y-p_m,x-p_m+1
real :: lamda
do i=1,nmax
a(i)=-lamda
c(i)=-lamda
d(i)=1+2*lamda
end do
do i=1,kmax
y=p0(i,m,:)
x=work(a,c,d,y,nmax)
p(i,m,:)=x(:)
end do
end subroutine absorption