-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsgengrid_s.f90
168 lines (141 loc) · 6.25 KB
/
sgengrid_s.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
!==============================================================================
subroutine sgengrid_s(y,eta,deta,d2eta,y_s,eta_s,deta_s,d2eta_s)
!==============================================================================
use stuff
implicit none
real y(ny), eta(ny), deta(ny), d2eta(ny), th, dth
real :: eta_s(ny-1), y_s(ny-1), deta_s(ny-1), d2eta_s(ny-1)
real :: Lmap
integer i
real, parameter :: three = 3.0
real rd1, rd2, dd, rmax, xi, dxi, cm, b, rc, drmin
!==============================================================================
dth = pi/float(ny-1)
!.... Make mesh in transformed, eta, and Chebyshev space, th
do i = 1, ny
th = float(i-1)*dth
eta(i) = cos(th)
end do
!.... Also make the staggered mesh
do i = 1, ny-1
th = (float(i-1)+pt5)*dth
eta_s(i) = cos(th)
end do
!.... make metric transformations
if (Yi .ne. zero) then ! use algebraic mapping
!.... infinite domain with algebraic mapping
if (ymax .eq. 0) then ! infinite domain with algebraic mapping
Lmap = Yi ! for consistency with input
do i = 1, ny
deta(i) = (eta(i)-one)**2/(two*Lmap)
d2eta(i) = (eta(i)-one)**3/(two*Lmap**2)
if (eta(i) .ne. one) then
y(i) = Lmap*(one+eta(i))/(one-eta(i))
else
y(i) = 1.0e99 ! approximate infinity
end if
if (i.lt.ny) then ! staggered grid
deta_s(i) = (eta_s(i)-one)**2/(two*Lmap)
d2eta_s(i) = (eta_s(i)-one)**3/(two*Lmap**2)
y_s(i) = Lmap*(one+eta_s(i))/(one-eta_s(i))
write(98,10) y_s(i), eta_s(i), deta_s(i), d2eta_s(i)
end if
write(99,10) y(i), eta(i), deta(i), d2eta(i)
end do
else ! Craig Streett's mapping
do i = 1, ny
y(i) = ymax*yi*(one+eta(i)) / (one+two*yi-eta(i))
deta(i) = (two*yi+one-eta(i))**2 / (two*ymax*yi*(yi+one))
d2eta(i) = -pt5*(two*yi+one-eta(i))**3 / (ymax*yi*(yi+one))**2
if (i.lt.ny) then ! staggered grid
y_s(i) = ymax*yi*(one+eta(i)) / (one+two*yi-eta(i))
deta_s(i) = (two*yi+one-eta(i))**2 / (two*ymax*yi*(yi+one))
d2eta_s(i) =-pt5*(two*yi+one-eta(i))**3 / (ymax*yi*(yi+one))**2
end if
end do
end if
else ! Hyperbolic tangent mapping
write(*,"('Enter rmax, drmin, b, rc ==> ',$)")
read(*,*) rmax, drmin, b, rc
cm = ( two * b * tanh(b*rc) + (ny-1)*drmin/rmax * &
& log( cosh(b*(one-rc)) / cosh(b*(one+rc)) ) ) / &
& ( one - (ny-1)*drmin/rmax )
dxi = one / real(ny-1)
do i = 1, ny
xi = one - real(i-1) * dxi
y(i) = rmax*( cm * xi + log( cosh(b*(xi-rc)) / &
& cosh(b*(xi+rc)) ) ) / &
& (cm + log( cosh(b*(one-rc)) / cosh(b*(one+rc)) ) )
deta(i) = one/(rmax*(cm + b*tanh(b*(xi-rc)) - b*tanh(b*(xi+rc))) /&
& (cm + log( cosh(b*(one-rc)) / cosh(b*(one+rc)) ) ) )
d2eta(i) = -(rmax*(-b**2*(tanh(b*(xi-rc)))**2 + &
& b**2*tanh(b*(xi+rc)))/ &
& (cm + log( cosh(b*(one-rc)) / cosh(b*(one+rc)) ) ) ) * &
& deta(i)**3
end do
!.... diagnostic
! do i = 1, ny
! xi = real(i-1) * dxi
! if (i.eq.1) then
! write(69,10) y(i), xi, deta(i), &
! (real(i)-real(i-1))*dxi/(y(i+1)-y(i))
! else if (i.eq.ny) then
! write(69,10) y(i), xi, deta(i), &
! (real(i-1)-real(i-2))*dxi/(y(i)-y(i-1))
! else
! write(69,10) y(i), xi, deta(i), &
! (real(i)-real(i-2))*dxi/(y(i+1)-y(i-1))
! end if
! end do
!.... correct for the xi -> eta mapping
do i = 1, ny
xi = one - real(i-1) * dxi
d2eta(i) = pi**2 * cos(pi * xi) * (deta(i))**2 + &
pi * sin(pi * xi) * d2eta(i)
deta(i) = pi * sin(pi * xi) * deta(i)
end do
! open(10,file='metric.out')
! do i = 1, ny
! if (i.eq.1) then
! write(10,10) y(i), eta(i), deta(i), &
! (eta(i+1)-eta(i))/(y(i+1)-y(i)), &
! d2eta(i), &
! (deta(i+1)-deta(i))/(y(i+1)-y(i))
! else if (i.eq.ny) then
! write(10,10) y(i), eta(i), deta(i), &
! (eta(i)-eta(i-1))/(y(i)-y(i-1)), &
! d2eta(i), &
! (deta(i)-deta(i-1))/(y(i)-y(i-1))
! else
! write(10,10) y(i), eta(i), deta(i), &
! (eta(i+1)-eta(i-1))/(y(i+1)-y(i-1)), &
! d2eta(i), &
! (deta(i+1)-deta(i-1))/(y(i+1)-y(i-1))
! end if
! end do
! close(10)
!.... now do the staggered mesh
do i = 1, ny-1
xi = one - (real(i-1)+pt5) * dxi
y_s(i) = rmax*( cm * xi + log( cosh(b*(xi-rc)) / &
& cosh(b*(xi+rc)) ) ) / &
& (cm + log( cosh(b*(one-rc)) / cosh(b*(one+rc)) ) )
deta_s(i) = one/(rmax*(cm + b*tanh(b*(xi-rc)) - &
& b*tanh(b*(xi+rc))) /&
& (cm + log( cosh(b*(one-rc)) / cosh(b*(one+rc)) ) ) )
d2eta_s(i) = -(rmax*(-b**2*(tanh(b*(xi-rc)))**2 + &
& b**2*tanh(b*(xi+rc)))/ &
& (cm + log( cosh(b*(one-rc)) / cosh(b*(one+rc)) ) ) ) * &
& deta(i)**3
end do
!.... correct for the xi -> eta mapping
do i = 1, ny
xi = one - (real(i-1)+pt5) * dxi
d2eta_s(i) = pi**2 * cos(pi * xi) * (deta_s(i))**2 + &
pi * sin(pi * xi) * d2eta_s(i)
deta_s(i) = pi * sin(pi * xi) * deta_s(i)
end do
end if
return
10 format(8(1x,1pe13.6))
end