WAVEWATCH III  beta 0.0.1
w3str1md.F90
Go to the documentation of this file.
1 
7 
8 #include "w3macros.h"
9 !/ ------------------------------------------------------------------- /
17 MODULE w3str1md
18  !/
19  !/ +-----------------------------------+
20  !/ | WAVEWATCH III NOAA/NCEP |
21  !/ | A. J. van der Westhuysen |
22  !/ | FORTRAN 90 |
23  !/ | Last update : 13-Jan-2013 |
24  !/ +-----------------------------------+
25  !/
26  !/ 13 Jan-2013 : Origination, based on SWAN v40.91 code ( version 4.08 )
27  !/
28  !/ Copyright 2009 National Weather Service (NWS),
29  !/ National Oceanic and Atmospheric Administration. All rights
30  !/ reserved. WAVEWATCH III is a trademark of the NWS.
31  !/ No unauthorized use without permission.
32  !/
33  ! 1. Purpose :
34  !
35  ! Module for inclusion of triad nonlinear interaction according to
36  ! Eldeberky's (1996) Lumped Triad Interaction (LTA) source term.
37  !
38  ! 2. Variables and types :
39  !
40  ! Name Type Scope Description
41  ! ----------------------------------------------------------------
42  ! ----------------------------------------------------------------
43  !
44  ! 3. Subroutines and functions :
45  !
46  ! Name Type Scope Description
47  ! ----------------------------------------------------------------
48  ! W3STR1 Subr. Public User supplied triad interactions.
49  ! ----------------------------------------------------------------
50  !
51  ! 4. Subroutines and functions used :
52  !
53  ! Name Type Module Description
54  ! ----------------------------------------------------------------
55  ! STRACE Subr. W3SERVMD Subroutine tracing.
56  ! ----------------------------------------------------------------
57  !
58  ! 5. Remarks :
59  !
60  ! WAVEWATCH III is designed as a highly plug-compatible code.
61  ! Source term modules can be included as self-contained modules,
62  ! with limited changes needed to the interface of routine calls
63  ! in W3SRCE, and in the point postprocessing programs only.
64  ! Codes submitted for inclusion in WAVEWATCH III should be
65  ! self-contained in the way described below, and might be
66  ! provided with distributions fully integrated in the data
67  ! structure, or as an optional version of this module to be
68  ! included by the user.
69  !
70  ! Rules for preparing a module to be included in or distributed
71  ! with WAVEWATCH III :
72  !
73  ! - Fully document the code following the outline given in this
74  ! file, and according to all other WAVEWATCH III routines.
75  ! - Provide a file with necessary modifications to W3SRCE and
76  ! all other routines that require modification.
77  ! - Provide a test case with expected results.
78  ! - It is strongly recommended that the programming style used
79  ! in WAVEWATCH III is followed, in particular
80  ! a) for readability, write as if in fixed FORTRAN format
81  ! regarding column use, even though all files are F90
82  ! free format.
83  ! b) I prefer upper case programming for permanent code,
84  ! as I use lower case in debugging and temporary code.
85  !
86  ! This module needs to be self-contained in the following way.
87  !
88  ! a) All saved variables connected with this source term need
89  ! to be declared in the module header. Upon acceptance as
90  ! permanent code, they will be converted to the WAVEWATCH III
91  ! dynamic data structure.
92  ! b) Provide a separate computation and initialization routine.
93  ! In the submission, the initialization should be called
94  ! from the computation routine upon the first call to the
95  ! routine. Upon acceptance as permanent code, the
96  ! initialization routine will be moved to a more appropriate
97  ! location in the code (i.e., being absorbed in ww3_grid or
98  ! being moved to W3IOGR).
99  !
100  ! See notes in the file below where to add these elements.
101  !
102  ! 6. Switches :
103  !
104  ! !/S Enable subroutine tracing.
105  !
106  ! 7. Source code :
107  !/
108  !/ ------------------------------------------------------------------- /
109  !/
110  ! *****************************************
111  ! *** Declare saved variables here ***
112  ! *** public or private as appropriate ***
113  ! *****************************************
114  !
115  PUBLIC
116  !/
117 CONTAINS
118  !/ ------------------------------------------------------------------- /
183  SUBROUTINE w3str1 (A, AOLD, CG, WN, DEPTH, IX, S, D)
184  !/
185  !/ +-----------------------------------+
186  !/ | WAVEWATCH III NOAA/NCEP |
187  !/ | A. J. van der Westhuysen |
188  !/ | A. Roland |
189  !/ | FORTRAN 90 |
190  !/ | Last update : 13-Jan-2013 |
191  !/ +-----------------------------------+
192  !/
193  !/ 13 Jan-2013 : Origination, based on SWAN v40.91 code ( version 4.08 )
194  !/ 05 Oct-2016 : Avoiding divide by zero for EMEAN ( version 5.15 )
195  !/ 28 Feb-2023 : Improvement of efficiency and stability ( version 7.xx)
196  !/
197  ! 1. Purpose :
198  !
199  ! Triad interaction source term computed using the Lumped Triad
200  ! Appproximation (LTA) of Eldeberky (1996).
201  !
202  ! 2. Method :
203  !
204  ! (Taken from SWAN v40.91, based on code by Marcel Zijlema, TU Delft)
205  !
206  ! The parametrized biphase is given by:
207  !
208  ! 0.2
209  ! beta = - pi/2 + pi/2 tanh ( ----- )
210  ! Ur
211  !
212  ! where Ur is the Ursell number.
213  !
214  ! The source term as function of frequency p is:
215  !
216  ! + -
217  ! S(p) = S(p) + S(p)
218  !
219  ! in which
220  !
221  ! +
222  ! S(p) = alpha Cp Cg,p (R(p/2,p/2))**2 sin (|beta|) ( E(p/2)**2 -2 E(p) E(p/2) )
223  !
224  ! - +
225  ! S(p) = - 2 S(2p)
226  !
227  ! with alpha a tunable coefficient and R(p/2,p/2) is the interaction
228  ! coefficient of which the expression can be found in Eldeberky (1996).
229  !
230  ! Note that a slightly adapted formulation of the LTA is used in
231  ! in the SWAN model:
232  !
233  ! - Only positive contributions to higher harmonics are considered
234  ! here (no energy is transferred to lower harmonics).
235  !
236  ! - The mean frequency in the expression of the Ursell number
237  ! is calculated according to the first order moment over the
238  ! zeroth order moment (personal communication, Y.Eldeberky, 1997).
239  !
240  ! - The interactions are calculated up to 2.5 times the mean
241  ! frequency only.
242  !
243  ! - Since the spectral grid is logarithmically distributed in frequency
244  ! space, the interactions between central bin and interacting bin
245  ! are interpolated such that the distance between these bins is
246  ! factor 2 (nearly).
247  !
248  ! - The interactions are calculated in terms of energy density
249  ! instead of action density. So the action density spectrum
250  ! is firstly converted to the energy density grid, then the
251  ! interactions are calculated and then the spectrum is converted
252  ! to the action density spectrum back.
253  !
254  ! 3. Parameters :
255  !
256  ! Parameter list
257  ! ----------------------------------------------------------------
258  ! A R.A. I Action density spectrum (1-D)
259  ! CG R.A. I Group velocities.
260  ! WN R.A. I Wavenumbers.
261  ! DEPTH Real I Mean water depth.
262  ! EMEAN Real I Mean wave energy.
263  ! FMEAN Real I Mean wave frequency.
264  ! S R.A. O Source term (1-D version).
265  ! D R.A. O Diagonal term of derivative (1-D version).
266  ! ----------------------------------------------------------------
267  !
268  ! 4. Subroutines used :
269  !
270  ! Name Type Module Description
271  ! ----------------------------------------------------------------
272  ! STRACE Subr. W3SERVMD Subroutine tracing.
273  ! ----------------------------------------------------------------
274  !
275  ! 5. Called by :
276  !
277  ! Name Type Module Description
278  ! ----------------------------------------------------------------
279  ! W3SRCE Subr. W3SRCEMD Source term integration.
280  ! W3EXPO Subr. N/A Point output post-processor.
281  ! GXEXPO Subr. N/A GrADS point output post-processor.
282  ! ----------------------------------------------------------------
283  !
284  ! 6. Error messages :
285  !
286  ! None.
287  !
288  ! 7. Remarks :
289  !
290  ! 8. Structure :
291  !
292  ! Determine resonance condition and the maximum discrete freq.
293  ! for which the interactions are calculated.
294  !
295  ! If Ursell number larger than prescribed value compute interactions
296  ! Calculate biphase
297  ! Do for each direction
298  ! Convert action density to energy density
299  ! Do for all frequencies
300  ! Calculate interaction coefficient and interaction factor
301  ! Compute interactions and store results in matrix
302  !
303  ! 9. Switches :
304  !
305  ! !/S Enable subroutine tracing.
306  !
307  ! 10. Source code :
308  !
309  !/ ------------------------------------------------------------------- /
310  USE constants, ONLY: grav, pi, tpi
311  USE w3gdatmd, ONLY: nk, nth, nspec, dth, sig, dden, fte, ftf
312  USE w3odatmd, ONLY: ndse
313  USE w3servmd, ONLY: extcde
314 #ifdef W3_S
315  USE w3servmd, ONLY: strace
316 #endif
317  !/
318  IMPLICIT NONE
319  !/
320  !/ ------------------------------------------------------------------- /
321  !/ Parameter list
322  !/
323  REAL, INTENT(IN) :: CG(NK), WN(NK), DEPTH, A(NSPEC), AOLD(NSPEC)
324  INTEGER, INTENT(IN) :: IX
325  REAL, INTENT(OUT) :: S(NSPEC), D(NSPEC)
326  !/
327  !/ ------------------------------------------------------------------- /
328  !/ Local parameters
329  !/
330  ! AUX1 : auxiliary real
331  ! AUX2 : auxiliary real
332  ! BIPH : parameterized biphase of the spectrum
333  ! C0 : phase velocity at central bin
334  ! CM : phase velocity at interacting bin
335  ! DEP : water depth
336  ! DEP_2 : water depth to power 2
337  ! DEP_3 : water depth to power 3
338  ! E : energy density as function of frequency
339  ! E0 : energy density at central bin
340  ! EM : energy density at interacting bin
341  ! HS : significant wave height
342  ! FT : auxiliary real indicating multiplication factor
343  ! for triad contribution
344  ! I1 : auxiliary integer
345  ! I2 : auxiliary integer
346  ! ID : counter
347  ! IDDUM : loop counter in direction space
348  ! IENT : number of entries
349  ! II : loop counter
350  ! IS : loop counter in frequency space
351  ! ISM : negative range for IS
352  ! ISM1 : negative range for IS
353  ! ISMAX : maximum of the counter in frequency space for
354  ! which the triad interactions are calculated (cut-off)
355  ! ISP : positive range for IS
356  ! ISP1 : positive range for IS
357  ! RINT : interaction coefficient
358  ! SA : interaction contribution of triad
359  ! SIGPICG : sigma times 2pi/Cg (a Jacobian for E(f) -> E(k))
360  ! SINBPH: absolute sine of biphase
361  ! STRI : total triad contribution
362  ! WISM : interpolation weight factor corresponding to lower harmonic
363  ! WISM1 : interpolation weight factor corresponding to lower harmonic
364  ! WISP : interpolation weight factor corresponding to higher harmonic
365  ! WISP1 : interpolation weight factor corresponding to higher harmonic
366  ! W0 : radian frequency of central bin
367  ! WM : radian frequency of interacting bin
368  ! WN0 : wave number at central bin
369  ! WNM : wave number at interacting bin
370  ! XIS : rate between two succeeding frequency counters
371  ! XISLN : log of XIS
372  !
373 #ifdef W3_S
374  INTEGER, SAVE :: IENT = 0
375 #endif
376  INTEGER :: I1, I2, ID, IDDUM, II, IS, ISM, ISM1, ISMAX
377  INTEGER :: ISP, ISP1, ITH, IK
378  REAL :: AUX1, AUX2, BIPH, C0, CM, DEP, DEP_2, DEP_3, E0, EM, HS
379  REAL :: FT, RINT, SIGPICG, SINBPH, STRI, WISM, WISM1, WISP
380  REAL :: WISP1, W0, WM, WN0, WNM, XIS, XISLN, EDM, ED0, G9DEP, STRI2
381  REAL :: E(NK), SA(NTH,100), SA2(NTH,100), A2(NSPEC), A3(NSPEC), HMAX
382  REAL :: EB(NK), EBAND, EMEAN, SIGM01, ED(NK)
383 !----- Temp (to be moved) -----
384  REAL :: EF(NK), JACEPS, DIFFSTR
385  REAL :: PTRIAD(5)
386  REAL :: URSELL, ALPHAR
387 !------------------------------
388 !/
389 !/ ------------------------------------------------------------------- /
390 !/
391 #ifdef W3_S
392  CALL strace (ient, 'W3STR1')
393 #endif
394 
395 !AR: todo: check all PRX routines for differences, check original thesis of elderberky.
396 !
397 ! 1. Integral over directions
398 !
399  sigm01 = 0.
400  emean = 0.
401  jaceps = 1e-12
402 
403  hmax = depth * 0.73
404 
405  DO ik=1, nk
406  eb(ik) = 0.
407  ed(ik) = 0.
408  DO ith=1, nth
409  eb(ik) = eb(ik) + a(ith+(ik-1)*nth)
410  ed(ik) = ed(ik) + a(ith+(ik-1)*nth) * dden(ik) / cg(ik)
411  END DO
412  END DO
413 !
414 ! 2. Integrate over frequencies.
415 !
416  DO ik=1, nk
417  eb(ik) = eb(ik) * dden(ik) / cg(ik)
418  emean = emean + eb(ik)
419  sigm01 = sigm01 + eb(ik)*sig(ik)
420  END DO
421 !
422 ! 3. Add tail beyond discrete spectrum
423 ! ( DTH * SIG(NK) absorbed in FTxx )
424 !
425  eband = eb(nk) / dden(nk)
426  emean = emean + eband * fte
427  sigm01 = sigm01 + eband * ftf
428 !
429 ! 4. Final processing
430 !
431  sigm01 = sigm01 / emean
432 
433 !---- Temporary parameters (to be replaced by namelists) -----
434 
435  ptriad(1) = 1.
436  ptriad(2) = 10.
437  ptriad(3) = 10. ! not used
438  ptriad(4) = 0.2
439  ptriad(5) = 0.01
440 
441  hs = 4.*sqrt( max(0.,emean) )
442  ursell = (grav*hs)/(2.*sqrt(2.)*sigm01**2*depth**2)
443 !---------------------------------------------
444 
445  dep = depth
446  dep_2 = dep**2
447  dep_3 = dep**3
448  g9dep = grav * dep
449 !
450 ! --- compute some indices in sigma space
451 !
452  i2 = int(float(nk) / 2.)
453  i1 = i2 - 1
454  xis = sig(i2) / sig(i1)
455  xisln = log( xis )
456 
457  isp = int( log(2.) / xisln )
458  isp1 = isp + 1
459  wisp = (2. - xis**isp) / (xis**isp1 - xis**isp)
460  wisp1 = 1. - wisp
461 
462  ism = int( log(0.5) / xisln )
463  ism1 = ism - 1
464  wism = (xis**ism -0.5) / (xis**ism - xis**ism1)
465  wism1 = 1. - wism
466 
467  e = 0.
468  sa = 0.
469 !
470 ! --- compute maximum frequency for which interactions are calculated
471 !
472  ismax = 1
473  DO ik = 1, nk
474  IF ( sig(ik) .LT. ( ptriad(2) * sigm01) ) THEN
475  ismax = ik
476  ENDIF
477  ENDDO
478  ismax = max( ismax , isp1 )
479 !
480 ! --- compute 3-wave interactions
481 !
482  IF (ursell.GE.ptriad(5) ) THEN ! AR: No need for switching it off from my point of view!
483 !
484 ! --- calculate biphase
485 !
486  biph = (0.5*pi)*(tanh(ptriad(4)/ursell)-1.)
487  sinbph = abs(sin(biph) )
488  ef = 0.
489 
490  DO ith = 1, nth
491  DO ik = 1, nk
492  e(ik) = a(ith+(ik-1)*nth) * tpi * sig(ik) / cg(ik)
493  ef(ik) = ef(ik) + e(ik)
494  END DO
495  DO ik = 1, ismax
496  e0 = e(ik)
497  ed0 = eb(ik)
498  w0 = sig(ik)
499  wn0 = wn(ik)
500  c0 = w0 / wn0
501  IF ( ik.GT.-ism1 ) THEN
502  em = wism * e(ik+ism1) + wism1 * e(ik+ism)
503  edm = wism * eb(ik+ism1) + wism1 * eb(ik+ism)
504  wm = wism * sig(ik+ism1) + wism1 * sig(ik+ism)
505  wnm = wism * wn(ik+ism1) + wism1 * wn(ik+ism)
506  cm = wm / wnm
507  ELSE
508  em = 0.
509  edm = 0.
510  wm = 0.
511  wnm = 0.
512  cm = 0.
513  END IF
514  aux1 = wnm**2 * ( g9dep + 2*cm**2 )
515  aux2 = wn0*dep* (g9dep+(2./15.)*grav*dep_3*wn0**2-(2./5.)*w0**2*dep_2)
516  rint = aux1 / aux2
517  ft = ptriad(1) * c0 * cg(ik) * rint**2 * sinbph
518  sa(ith,ik) = max(0.,ft * ( em * em - 2. * em * e0)) ! 1/(m²*s²) * m4 = m²/s² !!! [m²/s]
519  END DO
520  END DO
521 
522  DO ik = 1, nk - 1
523  sigpicg = sig(ik)*tpi/cg(ik) ! 1/s * s/m = 1/m
524  DO ith = 1, nth
525  stri = sa(ith,ik) - 2 * (wisp * sa(ith,ik+isp1) + wisp1 * sa(ith,ik+isp))
526  IF (a(ith+(ik-1)*nth) .gt. jaceps) THEN
527  d(ith+(ik-1)*nth) = stri / ((a(ith+(ik-1)*nth)) * sigpicg)
528  s(ith+(ik-1)*nth) = stri / sigpicg
529  ELSE
530  d(ith+(ik-1)*nth) = 0.
531  s(ith+(ik-1)*nth) = 0.
532  ENDIF
533  END DO
534  END DO
535  ELSE
536  d = 0.
537  s = 0.
538  END IF
539 
540  !/
541  !/ End of W3STR1 ----------------------------------------------------- /
542  !/
543  END SUBROUTINE w3str1
544  !/ ------------------------------------------------------------------- /
545 END MODULE w3str1md
w3gdatmd::nk
integer, pointer nk
Definition: w3gdatmd.F90:1230
constants::pi
real, parameter pi
PI Value of Pi.
Definition: constants.F90:71
w3str1md::w3str1
subroutine w3str1(A, AOLD, CG, WN, DEPTH, IX, S, D)
Triad interaction source term computed using the Lumped Triad Appproximation (LTA) of Eldeberky (1996...
Definition: w3str1md.F90:184
w3gdatmd::dth
real, pointer dth
Definition: w3gdatmd.F90:1232
w3gdatmd::nspec
integer, pointer nspec
Definition: w3gdatmd.F90:1230
w3str1md
Module for inclusion of triad nonlinear interaction according to Eldeberky's (1996) Lumped Triad Inte...
Definition: w3str1md.F90:17
w3gdatmd::sig
real, dimension(:), pointer sig
Definition: w3gdatmd.F90:1234
w3odatmd::ndse
integer, pointer ndse
Definition: w3odatmd.F90:456
w3servmd
Definition: w3servmd.F90:3
w3gdatmd::nth
integer, pointer nth
Definition: w3gdatmd.F90:1230
w3odatmd
Definition: w3odatmd.F90:3
constants::tpi
real, parameter tpi
TPI 2*Pi.
Definition: constants.F90:72
w3servmd::strace
subroutine strace(IENT, SNAME)
Definition: w3servmd.F90:148
w3gdatmd::fte
real, pointer fte
Definition: w3gdatmd.F90:1232
constants
Define some much-used constants for global use (all defined as PARAMETER).
Definition: constants.F90:20
w3gdatmd::dden
real, dimension(:), pointer dden
Definition: w3gdatmd.F90:1234
w3gdatmd
Definition: w3gdatmd.F90:16
w3servmd::extcde
subroutine extcde(IEXIT, UNIT, MSG, FILE, LINE, COMM)
Definition: w3servmd.F90:736
w3gdatmd::ftf
real, pointer ftf
Definition: w3gdatmd.F90:1232
constants::grav
real, parameter grav
GRAV Acc.
Definition: constants.F90:61