-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwanIntgratSpc.ftn90
348 lines (348 loc) · 11.9 KB
/
SwanIntgratSpc.ftn90
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
345
346
347
348
real function SwanIntgratSpc ( p, fmin, fmax, spcsig, theta, wpar, ecs, uloc, vloc, acloc, itype )
!
! --|-----------------------------------------------------------|--
! | Delft University of Technology |
! | Faculty of Civil Engineering and Geosciences |
! | Environmental Fluid Mechanics Section |
! | P.O. Box 5048, 2600 GA Delft, The Netherlands |
! | |
! | Programmer: Marcel Zijlema |
! --|-----------------------------------------------------------|--
!
!
! SWAN (Simulating WAves Nearshore); a third generation wave model
! Copyright (C) 1993-2024 Delft University of Technology
!
! 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/>.
!
!
! Authors
!
! 40.87: Marcel Zijlema
!
! Updates
!
! 40.87, April 2008: New subroutine
!
! Purpose
!
! Determine p-th moment of energy density spectrum with respect to a part of frequency space
! (the integrand may contain power p of relative or absolute frequency, wave number or group velocity)
!
! Method
!
! Trapezoidal rule is applied
!
! Modules used
!
use ocpcomm4
use swcomm1
use swcomm3
!
implicit none
!
! Argument variables
!
integer, intent(in) :: itype ! indicate the type of integrand; represent power p of
! 1= relative frequency
! 2= absolute frequency
! 3= wave number
! 4= group velocity
!
real, intent(in) :: p ! power of the p-th moment
real, intent(in) :: fmax ! user-specified upper bound of frequency space for integration
real, intent(in) :: fmin ! user-specified lower bound of frequency space for integration
real :: uloc ! ambient u-velocity component at one location
real :: vloc ! ambient v-velocity component at one location
!
real, dimension(MDC,MSC), intent(in) :: acloc ! action density at one location
real, dimension(MDC), intent(in) :: ecs ! help array containing (co)sine of spectral directions
real, dimension(MSC), intent(in) :: spcsig ! relative frequency bins
real, dimension(MDC), intent(in) :: theta ! spectral directions
real, dimension(MSC), intent(in) :: wpar ! wave number or group velocity
!
! Local variables
!
integer :: id ! loop counter over direction bins
integer, save :: ient = 0 ! number of entries in this subroutine
integer :: is ! loop counter over frequency bins
!
real :: cia ! first coefficient in trapezoidal rule
real :: cib ! second coefficient in trapezoidal rule
real :: ctail ! coefficient for high frequency tail in case of (finite) upper bound
real :: ds ! width of frequency bin
real :: dsf ! remaining width of frequency bin near lower/upper bound
real :: ead ! auxiliary factor
real :: ftail ! factor for high frequency tail
real :: ehfr ! energy at high frequency
real :: omeg1 ! absolute frequency (upward bin)
real :: omeg2 ! another absolute frequency (current bin)
real :: pmom ! p-th moment of energy density spectrum
real :: q ! power of the p-th moment + 1
real :: us ! ambient velocity in wave direction
real :: wloc ! local wave parameter (wave number or group velocity)
!
! Structure
!
! Description of the pseudo code
!
! Source text
!
if (ltrace) call strace (ient,'SwanIntgratSpc')
!
q = p + 1.
!
pmom = 0.
!
if ( itype == 1 ) then
!
do is = 2, MSC
!
ds = spcsig(is) - spcsig(is-1)
!
if ( spcsig(is-1) >= fmin .and. spcsig(is) <= fmax ) then
!
cia = 0.5*spcsig(is-1)**q * ds
cib = 0.5*spcsig(is )**q * ds
!
elseif ( spcsig(is) > fmax ) then
!
dsf = fmax - spcsig(is-1)
cib = 0.5*fmax**q * dsf**2 / ds
cia = 0.5*(spcsig(is-1)**q + fmax**q)*dsf - cib
!
elseif ( spcsig(is) > fmin ) then
!
dsf = spcsig(is) - fmin
cia = 0.5*fmin**q * dsf**2 / ds
cib = 0.5*(spcsig(is)**q + fmin**q)*dsf - cia
!
else
!
cia = 0.
cib = 0.
!
endif
!
do id = 1, MDC
!
ead = cia * acloc(id,is-1) + cib * acloc(id,is)
pmom = pmom + ead * ecs(id) * DDIR
!
enddo
!
if ( spcsig(is) > fmax ) exit
!
enddo
!
! add tail contribution, if appropriate
!
if ( fmax > spcsig(MSC) ) then
!
if ( MSC > 3 ) then
!
if ( PWTAIL(1) <= q ) then
call msgerr (2, ' power of moment is too large compared to tail power')
SwanIntgratSpc = -999.
return
endif
!
ftail = 1. / (PWTAIL(1) - q)
!
if ( fmax > 100. ) then
!
ctail = 0.
!
else
!
ctail = fmax**q * (spcsig(MSC)/fmax)**PWTAIL(1)
!
endif
!
do id = 1, MDC
!
ehfr = acloc(id,MSC) * spcsig(MSC) * ecs(id)
pmom = pmom + ehfr * (spcsig(MSC)**q - ctail) * DDIR * ftail
!
enddo
!
endif
!
endif
!
elseif ( itype == 2 ) then
!
do id = 1, MDC
!
us = uloc*cos(theta(id)+ALCQ) + vloc*sin(theta(id)+ALCQ)
!
do is = 2, MSC
!
ds = spcsig(is) - spcsig(is-1)
!
omeg1 = spcsig(is-1) + wpar(is-1) * us
omeg2 = spcsig(is ) + wpar(is ) * us
!
if ( spcsig(is-1) >= fmin .and. spcsig(is) <= fmax ) then
!
cia = 0.5*omeg1**p * spcsig(is-1) * ds
cib = 0.5*omeg2**p * spcsig(is ) * ds
!
elseif ( spcsig(is) > fmax ) then
!
dsf = fmax - spcsig(is-1)
omeg2 = fmax + (wpar(is)*dsf+wpar(is-1)*(ds-dsf)) * us / ds
cib = 0.5*omeg2**p * fmax * dsf**2 / ds
cia = 0.5*(omeg1**p * spcsig(is-1) + omeg2**p * fmax)*dsf - cib
!
elseif ( spcsig(is) > fmin ) then
!
dsf = spcsig(is) - fmin
omeg1 = fmin + (wpar(is-1)*dsf+wpar(is)*(ds-dsf)) * us / ds
cia = 0.5*omeg1**p * fmin * dsf**2 / ds
cib = 0.5*(omeg2**p * spcsig(is) + omeg1**p * fmin)*dsf - cia
!
else
!
cia = 0.
cib = 0.
!
endif
!
ead = cia * acloc(id,is-1) + cib * acloc(id,is)
pmom = pmom + ead * ecs(id) * DDIR
!
if ( spcsig(is) > fmax ) exit
!
enddo
!
enddo
!
! add tail contribution, if appropriate
!
if ( fmax > spcsig(MSC) ) then
!
if ( MSC > 3 ) then
!
ftail = 1. / (PWTAIL(1) - 1.)
!
if ( fmax > 100. ) then
!
ctail = 0.
!
else
!
ctail = fmax**q * (spcsig(MSC)/fmax)**PWTAIL(1)
!
endif
!
do id = 1, MDC
!
us = uloc*cos(theta(id)+ALCQ) + vloc*sin(theta(id)+ALCQ)
omeg2 = spcsig(MSC) + wpar(MSC) * us
!
ehfr = acloc(id,MSC) * spcsig(MSC) * ecs(id)
pmom = pmom + ehfr * (omeg2**p * spcsig(MSC) - ctail) * DDIR * ftail
!
enddo
!
endif
!
endif
!
elseif ( itype == 3 .or. itype == 4 ) then
!
do is = 2, MSC
!
ds = spcsig(is) - spcsig(is-1)
!
if ( spcsig(is-1) >= fmin .and. spcsig(is) <= fmax ) then
!
cia = 0.5*wpar(is-1)**p * spcsig(is-1) * ds
cib = 0.5*wpar(is )**p * spcsig(is ) * ds
!
elseif ( spcsig(is) > fmax ) then
!
dsf = fmax - spcsig(is-1)
wloc = (wpar(is)*dsf+wpar(is-1)*(ds-dsf)) / ds
cib = 0.5*wloc**p * fmax * dsf**2 / ds
cia = 0.5*(wpar(is-1)**p * spcsig(is-1) + wloc**p * fmax)*dsf - cib
!
elseif ( spcsig(is) > fmin ) then
!
dsf = spcsig(is) - fmin
wloc = (wpar(is-1)*dsf+wpar(is)*(ds-dsf)) / ds
cia = 0.5*wloc**p * fmin * dsf**2 / ds
cib = 0.5*(wpar(is)**p * spcsig(is) + wloc**p * fmin)*dsf - cia
!
else
!
cia = 0.
cib = 0.
!
endif
!
do id = 1, MDC
!
ead = cia * acloc(id,is-1) + cib * acloc(id,is)
pmom = pmom + ead * ecs(id) * DDIR
!
enddo
!
if ( spcsig(is) > fmax ) exit
!
enddo
!
! add tail contribution, if appropriate
!
if ( fmax > spcsig(MSC) ) then
!
if ( MSC > 3 ) then
!
ftail = 1. / (PWTAIL(1) - 1.)
!
if ( fmax > 100. ) then
!
ctail = 0.
!
else
!
if ( itype == 3 ) then
!
ctail = (1./GRAV)**p * fmax**(2*p+1) * (spcsig(MSC)/fmax)**PWTAIL(1)
!
elseif ( itype == 4 ) then
!
ctail = (0.5*GRAV)**p * fmax**(1-p) * (spcsig(MSC)/fmax)**PWTAIL(1)
!
endif
!
endif
!
do id = 1, MDC
!
ehfr = acloc(id,MSC) * spcsig(MSC) * ecs(id)
pmom = pmom + ehfr * (wpar(MSC)**p * spcsig(MSC) - ctail) * DDIR * ftail
!
enddo
!
endif
!
endif
!
endif
!
SwanIntgratSpc = pmom
!
end function SwanIntgratSpc