forked from dnowacki-usgs/swanmod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SwanSweepSel.f90
377 lines (377 loc) · 12.2 KB
/
SwanSweepSel.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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
subroutine SwanSweepSel ( idcmin, idcmax, anybin, iscmin, iscmax, &
iddlow, iddtop, idtot , isslow, isstop, &
istot , cax , cay , rdx , rdy , &
spcsig)
!
! --|-----------------------------------------------------------|--
! | 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-2015 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 2 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.
!
! A copy of the GNU General Public License is available at
! http://www.gnu.org/copyleft/gpl.html#SEC3
! or by writing to the Free Software Foundation, Inc.,
! 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
!
!
! Authors
!
! 40.80: Marcel Zijlema
!
! Updates
!
! 40.80, July 2007: New subroutine
!
! Purpose
!
! computes frequency-dependent counters in directional space
! and the active bins for considered sweep
!
! Method
!
! In order to have stable computation without a CFL restriction
! certain directional bins lying in the domain of dependence
! of present vertex are determined. These bins belong to the
! sweep which is being processed.
!
! The domain of dependence is enclosed by the two upwave faces
! of the present vertex in the considered cell. The following
! set of criterions determine which directional bin belongs to
! the domain of dependence:
!
! Cx * rdx(1) + Cy * rdy(1) >= 0 and
!
! Cx * rdx(2) + Cy * rdy(2) >= 0
!
! Geometrically, these criterions ensure that the propagation
! direction towards the present vertex is enclosed between
! the upwave faces of that vertex in the considered cell.
!
! The counters of the directional space are frequency dependent.
! Particularly, the higher frequencies are modified by the ambient
! current. The lower frequencies (due to the larger wave transport
! velocity) are less modified by the current.
!
! Next, it is detemined whether a certain bin lies within a specific
! sector enclosure of the considered sweep. This is denoted by a
! logical array anybin.
!
! Modules used
!
use ocpcomm4
use swcomm3
use SwanGriddata
!
implicit none
!
! Argument variables
!
integer, intent(out) :: iddlow ! minimum direction bin that is propagated within a sweep
integer, intent(out) :: iddtop ! maximum direction bin that is propagated within a sweep
integer, intent(out) :: idtot ! maximum number of bins in directional space for considered sweep
integer, intent(out) :: isslow ! minimum frequency that is propagated within a sweep
integer, intent(out) :: isstop ! maximum frequency that is propagated within a sweep
integer, intent(out) :: istot ! maximum number of bins in frequency space for considered sweep
!
integer, dimension(MSC), intent(out) :: idcmax ! maximum frequency-dependent counter in directional space
integer, dimension(MSC), intent(out) :: idcmin ! minimum frequency-dependent counter in directional space
integer, dimension(MDC), intent(out) :: iscmax ! maximum direction-dependent counter in frequency space
integer, dimension(MDC), intent(out) :: iscmin ! minimum direction-dependent counter in frequency space
!
real, dimension(MDC,MSC,ICMAX), intent(in) :: cax ! wave transport velocity in x-direction
real, dimension(MDC,MSC,ICMAX), intent(in) :: cay ! wave transport velocity in y-direction
real, dimension(2), intent(in) :: rdx ! first component of contravariant base vector rdx(b) = a^(b)_1
real, dimension(2), intent(in) :: rdy ! second component of contravariant base vector rdy(b) = a^(b)_2
real, dimension(MSC), intent(in) :: spcsig ! relative frequency bins
!
logical, dimension(MDC,MSC), intent(out) :: anybin ! true if bin is active in considered sweep
!
! Local variables
!
integer :: id ! loop counter over direction bins
integer :: idclow ! minimum counter in directional space for given frequency bin
integer :: idchgh ! maximum counter in directional space for given frequency bin
integer :: iddum ! counter in directional space for considered sweep
integer :: idsum ! total active bins in directional space for given frequency bin
integer, save :: ient = 0 ! number of entries in this subroutine
integer :: is ! loop counter over frequency bins
integer :: isclow ! minimum counter in frequency space for given directional bin
integer :: ischgh ! maximum counter in frequency space for given directional bin
!
real :: caxloc ! local wave transport velocity in x-direction at present vertex
real :: cayloc ! local wave transport velocity in y-direction at present vertex
!
logical :: lowbin ! indicates presence of lowest bin in directional space for given frequency bin
logical :: hghbin ! indicates presence of highest bin in directional space for given frequency bin
!
! Structure
!
! Description of the pseudo code
!
! Source text
!
if (ltrace) call strace (ient,'SwanSweepSel')
!
! initialize parameters and arrays
!
iddlow = 9999
iddtop = -9999
idtot = 1
!
isslow = 9999
isstop = -9999
istot = 1
!
idcmin = 0
idcmax = 0
anybin = .false.
!
iscmin = 1
iscmax = 1
!
! loop over all frequency bins
!
do is = 1, MSC
!
! determine which bin belongs to considered sweep for propagation
!
idsum = 0
!
if ( is == 1 .or. ICUR /= 0 ) then
!
do id = 1, MDC
!
caxloc = cax(id,is,1)*rdx(1) + cay(id,is,1)*rdy(1)
cayloc = cax(id,is,1)*rdx(2) + cay(id,is,1)*rdy(2)
!
if ( caxloc >= 0. .and. cayloc >= 0. ) then
!
anybin(id,is) = .true.
idsum = idsum + 1
isslow = min(is,isslow)
isstop = max(is,isstop)
!
endif
!
enddo
!
else
!
do id = 1, MDC
!
! in case of no current, when first frequency bin is in considered sweep,
! other bins for given direction are in this sweep as well
!
anybin(id,is) = anybin(id,1)
!
if ( anybin(id,1) ) then
idsum = idsum + 1
isstop = max(is,isstop)
endif
!
enddo
!
endif
!
! determine sector enclosure in directional space for considered sweep
!
idclow = 0
idchgh = 0
!
do id = 1, MDC
!
lowbin = .false.
hghbin = .false.
!
if ( anybin(id,is) ) then
!
if ( id == 1 ) then
!
if ( FULCIR ) then
if ( .not.anybin(MDC,is) ) lowbin = .true.
else
lowbin = .true.
endif
!
else
!
if ( .not.anybin(id-1,is) ) lowbin = .true.
!
endif
!
if ( id == MDC ) then
!
if ( FULCIR ) then
if ( .not.anybin(1,is) ) hghbin = .true.
else
hghbin = .true.
endif
!
else
!
if ( .not.anybin(id+1,is) ) hghbin = .true.
!
endif
!
endif
!
if ( lowbin ) idclow = id
if ( hghbin ) idchgh = id
!
enddo
!
! set minimum and maximum counters in directional space for considered sweep
!
idcmin(is) = 1
idcmax(is) = MDC
!
if ( idsum == 0 ) then
!
idcmin(is) = 9
idcmax(is) = -9
!
elseif ( idsum /= MDC ) then
!
if ( idclow > idchgh ) idclow = idclow - MDC
idcmin(is) = idclow
idcmax(is) = idchgh
!
endif
!
if ( idsum /= 0 ) then
iddlow = min ( iddlow , idcmin(is) )
iddtop = max ( iddtop , idcmax(is) )
endif
!
enddo
!
! compute maximum number of bins in directional space for considered sweep
!
if ( iddlow /= 9999 ) then
!
if ( iddtop == -9999 ) then
call msgerr ( 4, 'inconsistency found in SwanSweepSel: no maximum direction bin ' )
return
endif
!
idtot = iddtop - iddlow + 1
!
if ( ICUR > 0 ) then
!
if ( idtot < 3 ) then
iddtop = iddtop + 1
if ( idtot == 1 ) iddlow = iddlow - 1
idtot = 3
endif
!
endif
else
!
if ( iddtop /= -9999 ) then
call msgerr ( 4, 'inconsistency found in SwanSweepSel: no minimum direction bin ' )
return
endif
!
idtot = 0
!
endif
!
if ( idtot > MDC ) then
iddlow = 1
iddtop = MDC
idtot = MDC
endif
!
! compute maximum number of bins in frequency space for considered sweep
!
if ( isslow /= 9999 ) then
!
if ( isstop == -9999 ) then
call msgerr ( 4, 'inconsistency found in SwanSweepSel: no maximum frequency bin ' )
return
endif
!
!if ( isslow /= 1 ) then
! call msgerr ( 4, 'inconsistency found in SwanSweepSel: isslow <> 1 ' )
! return
!endif
!
isslow = 1
!
if ( ICUR > 0 ) isstop = max(min(4,MSC),isstop)
!
istot = isstop - isslow + 1
!
else
!
if ( isstop /= -9999 ) then
call msgerr ( 4, 'inconsistency found in SwanSweepSel: no minimum frequency bin ' )
return
endif
!
istot = 0
!
if ( idtot /= 0 ) then
call msgerr ( 4, 'inconsistency found in SwanSweepSel: istot = 0 and idtot <> 0 ' )
return
endif
!
endif
!
! loop over all direction bins
!
do iddum = iddlow, iddtop
id = mod ( iddum - 1 + MDC , MDC ) + 1
!
lowbin = .false.
!
do is = 1, MSC
if ( anybin(id,is) ) then
if ( .not.lowbin ) then
isclow = is
lowbin = .true.
endif
ischgh = is
endif
enddo
!
! set minimum and maximum counters in frequency space for considered sweep
!
if ( lowbin ) then
!
if ( isclow < isslow .or. ischgh > isstop ) then
call msgerr ( 4, 'inconsistency found in SwanSweepSel: minimum and maximum counters of frequencies not correct ' )
return
endif
!
iscmin(id) = isclow
iscmax(id) = ischgh
!
else ! no frequency bins fall within considered sweep
!
iscmin(id) = 0
iscmax(id) = 0
!
endif
!
enddo
!
end subroutine SwanSweepSel