存储值,针对每个迭代计数检查新值

时间:2016-10-27 22:39:49

标签: fortran fortran90 gfortran

我有一个程序为每个新的迭代计数i计算一个新值(L2norm)。我想在迭代i中检查此值与迭代时的值(i + 1)。并查看差异是否小于某些特定值。如何在迭代i(L2old)中存储此值并在i + 1(L2norm)处针对L2norm进行检查

如果我设置L2old = L2norm,我每次都会得到零。我想要一个非零值。

我的计划的一部分:

module hei

use sub_solver

implicit none
contains

subroutine heis(f,T,n)

integer, intent(in) :: n
double precision, intent(in) :: f
double precision, dimension(:,:), allocatable :: T
double precision pi,re,L2norm
integer i
pi=3.14159265359

do i=1,50



call BC(n,T)

call gauss_seidel(n,T)

call L2normsolver(n,T,L2norm)

if (abs(L2old-L2norm) .LE. 0.0000001) then

    exit

end if

L2old=L2norm

end do

write(*,*)'iteration count',i

end subroutine heis
end module hei


subroutine L2normsolver(n,T,L2norm)

integer, intent(in) :: n
double precision, dimension(:,:), allocatable :: T
integer i,j
double precision errorsum,L2norm,pi,h,x,y

pi=3.14159265359
h=1/n
errorsum=0

!Sums up all the errors

do i=2,n+1
  do j=2,n+1

   x=(j-1.5)*1/n
   y=(i-1.5)*1/n

   errorsum=errorsum+(T(i,j)-(cos(pi*x)*sinh(pi*y))/sinh(pi))**2

   end do
end do

!L2 norm
L2norm=sqrt(errorsum/(n**2))


end subroutine L2normsolver

0 个答案:

没有答案