-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.f90
150 lines (131 loc) · 4.94 KB
/
tests.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
!> SWiM - a semi-Lagrangian, semi-implicit shallow water model in
!! Cartesian coordiates
!! Copyright (C) 2008-2012 Christian Lerrahn
!!
!! This program is free software: you can redistribute it and/or modify
!! it under the terms of the GNU General Public License as published by
!! the Free Software Foundation, either version 3 of the License, or
!! (at your option) any later version.
!!
!! This program is distributed in the hope that it will be useful,
!! but WITHOUT ANY WARRANTY; without even the implied warranty of
!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
!! GNU General Public License for more details.
!!
!! You should have received a copy of the GNU General Public License
!! along with this program. If not, see <http://www.gnu.org/licenses/>.
!> tests.f90
!> Calculates exact solutions for test cases
module tests
use grid
implicit none
contains
!> Returns exact solution for testcase
!> @param testcase Testcase to calculate exact solution for
subroutine exact_solution(testcase)
integer :: i,j,ix,iy,iold,testcase
real :: dim,r,theta,alpha,xold,yold,tx,ty,kvec,lvec
if (testcase.eq.2.or.testcase.eq.3.or.&
&testcase.eq.6) then ! moving at fixed velocity
do j=(gc+1),(ydim+gc)
do i=(gc+1),(xdim+gc)
tx = time*u(i,j)/deltax&
&-floor((time*u(i,j)/deltax)/real(xdim))*real(xdim)
ty = time*v(i,j)/deltay&
&-floor((time*v(i,j)/deltay)/real(ydim))*real(ydim)
xold = real(i)-tx
if (xold.le.gc) then
xold = xdim+xold
end if
yold = real(j)-ty
if (yold.le.gc) then
yold = ydim+yold
end if
exact(i,j) = .1*phibar*exp(-5.e-3*(xold-xdim/2.-gc+1.)**2. - 5.e-4*(yold-ydim/2.-gc+1.)**2.)
end do
end do
elseif (testcase.eq.16) then ! rotating stretched Gaussian
dim = real(min(xdim,ydim)/2)
do j=(gc+1),(ydim+gc)
do i=(gc+1),(xdim+gc)
ix = i-xdim/2-gc
iy = j-ydim/2-gc
r = sqrt(real(ix)**2.+real(iy)**2.)
! find angle
theta = 0.
if (r.ne.0) then
theta = asin(real(iy)/r)
end if
if (ix.lt.0) then
theta = -theta+pi
end if
alpha = 0.
if ((r/dim).lt..75) then
alpha = theta - time/deltax
elseif ((r/dim).lt.1.) then
alpha = theta - (1.-(r/dim))/(1.-.75)*time/deltax
else
alpha = theta
end if
xold = r*cos(alpha)+real(dim+gc)
yold = r*sin(alpha)+real(dim+gc)
exact(i,j) = .1*phibar*exp(-5.e-3*(xold-xdim/2.-gc+1.)**2. - 5.e-4*(yold-ydim/2.-gc+1.)**2.)
end do
end do
elseif (testcase.eq.26) then ! rotating bar
dim = real(min(xdim,ydim)/2)
do j=(gc+1),(ydim+gc)
do i=(gc+1),(xdim+gc)
ix = i-xdim/2-gc
iy = j-ydim/2-gc
r = sqrt(real(ix)**2.+real(iy)**2.)
! find angle
theta = 0.
if (r.ne.0) then
theta = asin(real(iy)/r)
end if
if (ix.lt.0) then
theta = -theta+pi
end if
alpha = 0.
if ((r/dim).lt..75) then
alpha = theta - time/deltax
elseif ((r/dim).lt.1.) then
alpha = theta - (1.-(r/dim))/(1.-.75)*time/deltax
else
alpha = theta
end if
iold = int(r*cos(alpha))+dim+gc
if (iold.gt.(xdim/2+1).and.iold.lt.(xdim/2+gc+1)) then
exact(i,j) = 100.
else
exact(i,j) = 1.
end if
end do
end do
elseif ((testcase.ge.30.and.testcase.lt.50).and.&
&(mod(testcase,10).eq.0.or.&
&mod(mod(testcase,10),2).eq.0.or.&
&mod(mod(testcase,10),3).eq.0)) then ! geostrophic motion
kvec = 2.*pi/real(xdim)
lvec = 2.*pi/real(ydim)
do j=(gc+1),(ydim+gc)
do i=(gc+1),(xdim+gc)
if (testcase.ne.44.and.testcase.ne.49) then ! exact solution for phi
exact(i,j) = 1.e-3*phibar*cos(kvec*real(i-gc)+lvec*real(j-gc))
elseif (testcase.eq.44) then ! exact solution for v
exact(i,j) = -1.e-3*phibar*kvec/(f*deltax)*sin(kvec*real(i-gc)+lvec*real(j-gc-.5))
else ! exact solution for u
exact(i,j) = 1.e-3*phibar*lvec/(f*deltay)*sin(kvec*real(i-gc-.5)+lvec*real(j-gc))
end if
end do
end do
else
do j=(gc+1),(ydim+gc)
do i=(gc+1),(xdim+gc)
exact(i,j) = 0.
end do
end do
end if
end subroutine exact_solution
end module tests