-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinterpolation_pack.f90
More file actions
executable file
·172 lines (159 loc) · 5.57 KB
/
Copy pathinterpolation_pack.f90
File metadata and controls
executable file
·172 lines (159 loc) · 5.57 KB
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
168
169
170
171
172
module interpolation_pack
use global
use write_pack
contains
!::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
subroutine bilinear_interp(xc,yc,uyc,Tc)
real(dp), dimension(:), intent(in) :: xc, yc
complex(C_DOUBLE_COMPLEX), dimension(:,:), intent(in) :: uyc, Tc
real(dp) :: x1, x2, y1, y2
real(dp) :: xi, eta
real(dp) :: dx
integer :: ii, jj
integer :: ic, jc
ic = 1 ! Counter
! Initialize x1 and x2
x1 = xc(ic)
x2 = xc(ic+1)
dx = xp(2) - xp(1)
do ii = 1,Nx ! Loop over x
if (ii == Nx) then
! Initialize x1 and x2
x1 = xc(ic)
x2 = abs(xc(1))
xi = xp(ii) ! Locate x position on refined mesh
jc = 1 ! Counter
! Initialize y1 and y2
y1 = yc(jc)
y2 = yc(jc+1)
do jj = 1,Ny
eta = yp(jj) ! Locate y position on refined mesh
if (eta > y2) then! Check y interpolation points
jc = jc + 1
y1 = yc(jc)
y2 = yc(jc+1)
end if
! Set up coefficients for interpolation formula
c0 = (x2 - x1)*(y2 - y1)
c1 = (x2 - xi)*(y2 - eta)
c2 = (x2 - xi)*(eta - y1)
c3 = (xi - x1)*(y2 - eta)
c4 = (xi - x1)*(eta - y1)
! Interpolate velocity
uy(jj,ii) = (c1*uyc(jc,ic) + c2*uyc(jc+1,ic) + &
& c3*uyc(jc,1) + c4*uyc(jc+1,1)) / c0
! Interpolate temperature
T(jj,ii) = (c1*Tc(jc,ic) + c2*Tc(jc+1,ic) + &
& c3*Tc(jc,1) + c4*Tc(jc+1,1)) / c0
end do
else
xi = xp(ii) ! Locate x position on refined mesh
!if (xi > x2) then ! Check interpolation points
if ((xi - x2) >= dx/2.0_dp) then ! Check interpolation points
ic = ic + 1
x1 = xc(ic)
x2 = xc(ic+1)
end if
jc = 1 ! Counter
! Initialize y1 and y2
y1 = yc(jc)
y2 = yc(jc+1)
do jj = 1,Ny ! Loop over y
eta = yp(jj) ! Locate y position on refined mesh
if (eta > y2) then! Check y interpolation points
jc = jc + 1
y1 = yc(jc)
y2 = yc(jc+1)
end if
! Set up coefficients for interpolation formula
c0 = (x2 - x1)*(y2 - y1)
c1 = (x2 - xi)*(y2 - eta)
c2 = (x2 - xi)*(eta - y1)
c3 = (xi - x1)*(y2 - eta)
c4 = (xi - x1)*(eta - y1)
! Interpolate velocity
uy(jj,ii) = (c1*uyc(jc,ic) + c2*uyc(jc+1,ic) + &
& c3*uyc(jc,ic+1) + c4*uyc(jc+1,ic+1)) / c0
! Interpolate temperature
T(jj,ii) = (c1*Tc(jc,ic) + c2*Tc(jc+1,ic) + &
& c3*Tc(jc,ic+1) + c4*Tc(jc+1,ic+1)) / c0
end do
end if
end do
end subroutine bilinear_interp
!::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
subroutine linear_interp_x(xc,uyc,Tc)
real(dp), dimension(:), intent(in) :: xc
complex(C_DOUBLE_COMPLEX), dimension(:,:), intent(in) :: uyc, Tc
real(dp) :: x1, x2
real(dp) :: xi
real(dp) :: dx
integer :: ii
integer :: ic
ic = 1 ! Counter
! Initialize x1 and x2
x1 = xc(ic)
x2 = xc(ic+1)
dx = xp(2) - xp(1)
do ii = 1,Nx ! Loop over x
xi = xp(ii) ! Locate x position on refined mesh
if (ii == Nx) then
! Initialize x1 and x2
x1 = xc(ic)
x2 = abs(xc(1))
! Set up coefficients for interpolation formula
c0 = (x2 - x1)
c1 = (x2 - xi)
c3 = (xi - x1)
! Interpolate velocity
uy(:,ii) = (c1*uyc(:,ic) + c3*uyc(:,1)) / c0
! Interpolate temperature
T(:,ii) = (c1*Tc(:,ic) + c3*Tc(:,1)) / c0
else
if ((xi - x2) >= dx/2.0_dp) then ! Check interpolation points
ic = ic + 1
x1 = xc(ic)
x2 = xc(ic+1)
end if
! Set up coefficients for interpolation formula
c0 = (x2 - x1)
c1 = (x2 - xi)
c3 = (xi - x1)
! Interpolate velocity
uy(:,ii) = (c1*uyc(:,ic) + c3*uyc(:,ic+1)) / c0
! Interpolate temperature
T(:,ii) = (c1*Tc(:,ic) + c3*Tc(:,ic+1)) / c0
end if
end do
end subroutine linear_interp_x
!::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
subroutine linear_interp_y(yc,uyc,Tc)
real(dp), dimension(:), intent(in) :: yc
complex(C_DOUBLE_COMPLEX), dimension(:,:), intent(in) :: uyc, Tc
real(dp) :: y1, y2
real(dp) :: eta
integer :: jj
integer :: jc
jc = 1 ! Counter
! Initialize x1 and x2
y1 = yc(jc)
y2 = yc(jc+1)
do jj = 1,Ny ! Loop over x
eta = yp(jj) ! Locate x position on refined mesh
if (eta > y2) then ! Check interpolation points
jc = jc + 1
y1 = yc(jc)
y2 = yc(jc+1)
end if
! Set up coefficients for interpolation formula
c0 = (y2 - y1)
c1 = (y2 - eta)
c2 = (eta - y1)
! Interpolate velocity
uy(jj,:) = (c1*uyc(jc,:) + c2*uyc(jc+1,:)) / c0
! Interpolate temperature
T(jj,:) = (c1*Tc(jc,:) + c2*Tc(jc+1,:)) / c0
end do
end subroutine linear_interp_y
!::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
end module interpolation_pack