-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_serial.f90
85 lines (80 loc) · 2.45 KB
/
main_serial.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
program main_serial
implicit none
! 1D Transient head conduction equation. Mid plane symmetry, and convection BC on left.
! Explicit Scheme
integer, parameter :: PREC = kind( 1.0d0 ) ! double precision
integer, parameter :: xnodes=100 ! x grid points
integer, parameter :: ynodes=xnodes ! y grid points
real(PREC) :: pi = 4 * atan( 1._PREC ) ! pi
real(PREC) :: a=1.0 ! x domain length
real(PREC) :: b=1.0 ! y domain length
real(PREC) :: x ! x-location
real(PREC) :: y ! y-location
real(PREC) :: dx ! x grid spacing
real(PREC) :: dt ! t grid spacing
real(PREC) :: R ! Cell Reynolds Number
real(PREC) :: CFL=0.3_PREC ! CLF Number
real :: start, finish
real(PREC) :: Tn(xnodes) = 1._PREC
real(PREC) :: Tnp1(xnodes) = 1._PREC
real(PREC) :: eps = epsilon(1._PREC)
real(PREC) :: norm_np1=0.0
real(PREC) :: norm_n=1.0
real(PREC) :: resd
real(PREC) :: h=1.0
real(PREC) :: k=1.0
real(PREC) :: T_inf=0.0
integer :: un=11
integer :: ierror
integer :: i ! x spatial counter
integer :: j ! y spatial counter
integer :: max_iter=1001 ! maximum iteration count
integer :: count=0
open(unit=un,file="Tn_output.txt",status="replace",iostat=ierror)
! if (ierror==1) then
! write(*,*) "Error opening Tn output file."
! else
! write(un,100) xnodes,',',ynodes
! end if
100 format(I10,1A,I10)
dx = a / (xnodes-1)
dt = dx*dx*CFL
write(*,*) dt
call cpu_time(start)
! Main loop
resd=1
! Initialization
do i=1,xnodes
Tn(i)=1.0
Tnp1(i)=1.0
end do
!do while (resd>1e-3.and.count<max_iter)
do while (count<max_iter)
resd=0
Tnp1(1)=Tn(1)+dt/dx/dx*(2*Tn(2)-2*Tn(1))
Tnp1(xnodes)=(Tnp1(xnodes)+h*dx/k*T_inf)/(1+h*dx/k)
count = count+1
do i=2,xnodes-1
Tnp1(i)=Tn(i)+dt/dx/dx*(Tn(i+1)-2*Tn(i)+Tn(i-1))
end do
Tnp1(1)=Tn(1)+dt/dx/dx*(2*Tn(2)-2*Tn(1))
Tnp1(xnodes)=(Tnp1(xnodes)+h*dx/k*T_inf)/(1+h*dx/k)
do i=2,xnodes-1
resd=sqrt(abs(Tn(i)**2-Tnp1(i)**2))+resd
end do
do i=1,xnodes
Tn(i)=Tnp1(i)
end do
write(*,*) resd
end do
! write(*,*) resd
call cpu_time(finish)
print '("Time = ",f9.3," seconds.")',finish-start
do i=1,xnodes
! do j=1,ynodes
write(un,101) Tnp1(i)
! end do
end do
101 format(f10.5,',')
close(un)
end program main_serial