-
Notifications
You must be signed in to change notification settings - Fork 2
/
ocean.f90
344 lines (296 loc) · 12.3 KB
/
ocean.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
!!~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~!!
!! !!
!! This file forms part of the Badlands surface processes modelling application. !!
!! !!
!! For full license and copyright information, please refer to the LICENSE.md file !!
!! located at the project root, or contact the authors. !!
!! !!
!!~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~!!
! Loop over node coordinates and find if they belong to local partition.
module wave
implicit none
real(kind=8), parameter::pi = 3.1415926535897931_8
real(kind=8), parameter::onpi = 1.0_8/3.1415926535897931_8
real(kind=8), parameter::pi2 = pi*2.0_8
real(kind=8), parameter::pion2 = pi*0.5_8
real(kind=8), parameter::onpi2 =1.0_8/pi2
real(kind=8), parameter::grav = 9.81_8
contains
subroutine airymodel(dx,dd,h0,depth,src,inland,shadow,c,l,travel,waveH,numrow,numcol)
integer :: numrow,numcol
integer,intent(in) :: shadow
integer,intent(in) :: inland(numrow,numcol)
real(kind=8),intent(in) :: dx
real(kind=8),intent(in) :: dd
real(kind=8),intent(in) :: h0
real(kind=8),intent(in) :: depth(numrow,numcol)
real(kind=8),intent(in) :: src(numrow,numcol)
real(kind=8),intent(out) :: c(numrow,numcol)
real(kind=8),intent(out) :: l(numrow,numcol)
real(kind=8),intent(out) :: travel(numrow,numcol)
real(kind=8),intent(out) :: waveH(numrow,numcol)
integer :: i, j, keeploop, ix, jx, k
real(kind=8) :: TM, MN, l0, f0, k0, dt, tperiod0
real(kind=8) :: cg0, c0, kh, tmp, frac, n
real(kind=8) :: ks(numrow,numcol)
integer,dimension(20)::iradius=(/-2,-1,1,2,-2,-1,0,1,2,-1,0,1,-2,-1,0,1,2,-1,0,-1/)
integer,dimension(20)::jradius=(/ 0,0,0,0,1,1,1,1,1, 2,2,2,-1,-1,-1,-1,-1,-2,-2,-2/)
real(kind=8),dimension(20)::dist=(/2.,1.,1.,2.,sqrt(5.),sqrt(2.),1., &
sqrt(2.),sqrt(5.),sqrt(5.),2.,sqrt(5.),sqrt(5.),sqrt(2.), &
1.,sqrt(2.),sqrt(5.),sqrt(5.),2.,sqrt(5.)/)
c = 0.
ks = 1.
waveH = 0.
! calculate wave length (deep water)
tperiod0 = max(0.47*h0+6.76, pi*pi*sqrt(h0/grav))
l0=grav*tperiod0**2*onpi2
f0=pi2/tperiod0
k0=pi2/l0
! airy wave theory, deep water phase speed
cg0=0.5_8*sqrt(grav/k0) ! group speed
c0=grav*tperiod0*onpi2
! set the step size
l=l0
do j = 1, numcol
do i = 1, numrow
! conct contains all areas not in the shadow of land
! if areas are "exposed and in deep water, give them the "open water" conditions
TM=l0
if(inland(i,j)==0)then
do
MN=0.5_8*(l(i,j)+TM)
TM=l(i,j)
l(i,j)=l0*tanh(pi2*depth(i,j)/MN)
if(abs(l(i,j)-TM)<1.0e-8_8)exit
enddo
c(i,j)=c0*l(i,j)/l0
kh = depth(i,j)*pi2/l(i,j)
tmp = 1.+2.*kh/sinh(2.*kh)
waveH(i,j) = h0/sqrt(tanh(kh)*tmp)
n = 0.5*tmp
ks(i,j) = sqrt(c0/(2.*n*c(i,j)))
endif
end do
end do
! Assign source points
travel = src
! Perform Huygen's principle to find travel time and wave front
keeploop = 1
do
keeploop = 0
do j = 1, numcol
do i = 1, numrow
if(travel(i,j)>=0)then
do k = 1, 20
ix = i+iradius(k)
jx = j+jradius(k)
if(ix>0 .and. ix<=numrow .and. jx>0 .and. jx<=numcol)then
if(inland(ix,jx)==1)then
travel(ix,jx)=-1
else if(travel(ix,jx)<0)then
travel(ix,jx) = travel(i,j)+dist(k)*dx/c(i,j)
keeploop = 1
if(depth(i,j)/l(i,j)<0.5)then
frac = 2.*(1.-dd)*depth(i,j)/l(i,j)+dd
if(waveH(ix,jx)>frac*waveH(i,j)) waveH(ix,jx)=frac*waveH(i,j)
else
if(shadow==1 .and. waveH(ix,jx)>waveH(i,j)) waveH(ix,jx)=waveH(i,j)
endif
else
dt = travel(i,j)+dist(k)*dx/c(i,j)
if(travel(ix,jx)>dt .and. dt>0)then
travel(ix,jx) = dt
if(depth(i,j)/l(i,j)<0.5)then
frac = 2.*(1.-dd)*depth(i,j)/l(i,j)+dd
if(waveH(ix,jx)>frac*waveH(i,j)) waveH(ix,jx)=frac*waveH(i,j)
else
if(shadow==1 .and. waveH(ix,jx)>waveH(i,j)) waveH(ix,jx)=waveH(i,j)
endif
keeploop = 1
endif
endif
endif
end do
endif
end do
end do
if(keeploop == 0)exit
end do
waveH = waveH * ks
return
end subroutine airymodel
subroutine transport(iter,depth,hent,transX,transY,dz,dist,numrow,numcol)
integer :: numrow,numcol
integer,intent(in) :: iter
real(kind=8),intent(in) :: depth(numrow,numcol)
real(kind=8),intent(in) :: hent(numrow,numcol)
real(kind=8),intent(in) :: transX(numrow,numcol)
real(kind=8),intent(in) :: transY(numrow,numcol)
real(kind=8),intent(out) :: dz(numrow,numcol)
real(kind=8),intent(out) :: dist(numrow,numcol)
integer :: i, j, k, loop, it, steps
real(kind=8) :: ent(numrow,numcol),ndepth(numrow,numcol)
dz = 0.
steps = 20.
ndepth = depth+hent
do k = 1, steps
ent = hent/steps
loop = 0
it = 0
do while(loop==0 .and. it<iter)
loop = 1
it = it+1
do j = 2, numcol-1
do i = 2, numrow-1
if(ent(i,j)>0.)then
loop = 0
! Below critical shear stress for entrainment deposit everything
if(hent(i,j)==0.)then
dz(i,j) = dz(i,j)+ent(i,j)
ndepth(i,j) = ndepth(i,j)-ent(i,j)
else
! Along the X-axis
! Moving towards East
if(transX(i,j)>0)then
! Inland deposit inside cell
if(ndepth(i+1,j)<=0)then
dz(i,j) = dz(i,j)+transX(i,j)*ent(i,j)
ndepth(i,j) = ndepth(i,j)-transX(i,j)*ent(i,j)
! Transfert entrained sediment to neighbouring cell
else
! In case the directions are following the same trend
if(transX(i+1,j)>=0)then
ent(i+1,j) = ent(i+1,j)+transX(i,j)*ent(i,j)
! In case the directions are facing each others
else
dz(i,j) = dz(i,j)+0.5*transX(i,j)*ent(i,j)
ndepth(i,j) = ndepth(i,j)-0.5*transX(i,j)*ent(i,j)
dz(i+1,j) = dz(i+1,j)+0.5*transX(i,j)*ent(i,j)
ndepth(i+1,j) = ndepth(i+1,j)-0.5*transX(i,j)*ent(i,j)
endif
endif
! Moving towards West
elseif(transX(i,j)<0)then
! Inland deposit inside cell
if(ndepth(i-1,j)<=0)then
dz(i,j) = dz(i,j)-transX(i,j)*ent(i,j)
ndepth(i,j) = ndepth(i,j)+transX(i,j)*ent(i,j)
! Transfert entrained sediment to neighbouring cell
else
! In case the directions are following the same trend
if(transX(i-1,j)<=0)then
ent(i-1,j) = ent(i-1,j)-transX(i,j)*ent(i,j)
! In case the directions are facing each others
else
dz(i,j) = dz(i,j)-0.5*transX(i,j)*ent(i,j)
ndepth(i,j) = ndepth(i,j)+0.5*transX(i,j)*ent(i,j)
dz(i-1,j) = dz(i-1,j)-0.5*transX(i,j)*ent(i,j)
ndepth(i-1,j) = ndepth(i-1,j)+0.5*transX(i,j)*ent(i,j)
endif
endif
endif
! Along the Y-axis
! Moving towards North
if(transY(i,j)>0)then
! Inland deposit inside cell
if(ndepth(i,j+1)<=0)then
dz(i,j) = dz(i,j)+transY(i,j)*ent(i,j)
ndepth(i,j) = ndepth(i,j)-transY(i,j)*ent(i,j)
! Transfert entrained sediment to neighbouring cell
else
! In case the directions are following the same trend
if(transY(i,j+1)>=0)then
ent(i,j+1) = ent(i,j+1)+transY(i,j)*ent(i,j)
! In case the directions are facing each others
else
dz(i,j) = dz(i,j)+0.5*transY(i,j)*ent(i,j)
ndepth(i,j) = ndepth(i,j)-0.5*transY(i,j)*ent(i,j)
dz(i,j+1) = dz(i,j+1)+0.5*transY(i,j)*ent(i,j)
ndepth(i,j+1) = ndepth(i,j+1)-0.5*transY(i,j)*ent(i,j)
endif
endif
! Moving towards South
elseif(transY(i,j)<0)then
! Inland deposit inside cell
if(ndepth(i,j-1)<=0)then
dz(i,j) = dz(i,j)-transY(i,j)*ent(i,j)
ndepth(i,j) = ndepth(i,j)+transY(i,j)*ent(i,j)
! Transfert entrained sediment to neighbouring cell
else
! In case the directions are following the same trend
if(transY(i,j-1)<=0)then
ent(i,j-1) = ent(i,j-1)-transY(i,j)*ent(i,j)
! In case the directions are facing each others
else
dz(i,j) = dz(i,j)-0.5*transY(i,j)*ent(i,j)
ndepth(i,j) = ndepth(i,j)+0.5*transY(i,j)*ent(i,j)
dz(i,j-1) = dz(i,j-1)-0.5*transY(i,j)*ent(i,j)
ndepth(i,j-1) = ndepth(i,j-1)+0.5*transY(i,j)*ent(i,j)
endif
endif
endif
endif
ent(i,j) = 0.
endif
enddo
enddo
enddo
if(it>=1000)then
dz = dz+ent
ndepth = ndepth-ent
endif
enddo
! Find reworked sediment above water level
dist = 0.
do j = 1, numcol
do i = 1, numrow
if(dz(i,j)>depth(i,j)+hent(i,j).and.depth(i,j)+hent(i,j)>0.)then
dist(i,j) = dz(i,j)-depth(i,j)-hent(i,j)
dz(i,j) = depth(i,j)+hent(i,j)
endif
enddo
enddo
return
end subroutine transport
subroutine diffusion(oelev,dz,coeff,maxth,tstep,nstep,depo,numrow,numcol)
integer :: numrow,numcol
integer,intent(in) :: nstep
real(kind=8),intent(in) :: maxth
real(kind=8),intent(in) :: tstep
real(kind=8),intent(in) :: oelev(numrow,numcol)
real(kind=8),intent(in) :: dz(numrow,numcol)
real(kind=8),intent(in) :: coeff
real(kind=8),intent(out) :: depo(numrow,numcol)
integer :: i,j,i1,j1,k,it
real(kind=8) :: diffmarine(numrow,numcol),elev(numrow,numcol)
integer,dimension(4)::is=(/1,0,-1,0/)
integer,dimension(4)::js=(/0,1,0,-1/)
real(kind=8) :: flx,mindt
depo = dz
elev = oelev
do it=1,nstep
diffmarine = 0.
mindt = tstep
do j = 2, numcol-1
do i = 2, numrow-1
do k = 1,4
i1 = i+is(k)
j1 = j+js(k)
flx = elev(i1,j1)-elev(i,j)
if(depo(i,j)>maxth .and. elev(i,j)>elev(i1,j1))then
diffmarine(i,j) = diffmarine(i,j) + flx*coeff
elseif(depo(i1,j1)>maxth .and. elev(i,j)<elev(i1,j1))then
diffmarine(i,j) = diffmarine(i,j) + flx*coeff
endif
enddo
if(diffmarine(i,j)<0. .and. diffmarine(i,j)*tstep<-depo(i,j))then
mindt = min(-depo(i,j)/diffmarine(i,j),mindt)
endif
enddo
enddo
depo = depo + diffmarine*mindt
elev = elev + diffmarine*mindt
enddo
return
end subroutine diffusion
end module wave