WAVEWATCH III  beta 0.0.1
w3sbs1md.F90
Go to the documentation of this file.
1 
7 
8 #include "w3macros.h"
9 
21 !/ ------------------------------------------------------------------- /
22 MODULE w3sbs1md
23  !/
24  !/ +-----------------------------------+
25  !/ | WAVEWATCH III SHOM |
26  !/ | F. Ardhuin |
27  !/ | FORTRAN 90 |
28  !/ | Last update : 14-Nov-2010 |
29  !/ +-----------------------------------+
30  !/
31  !/ 15-Jul-2005 : Origination. ( version 3.07 )
32  !/ 23-Jun-2006 : Formatted for submitting code for ( version 3.09 )
33  !/ inclusion in WAVEWATCH III.
34  !/ 10-May-2007 : adapt from version 2.22.SHOM ( version 3.10.SHOM )
35  !/ 14-Nov-2010 : include scaling factor and clean up ( version 3.14 )
36  !/
37  ! 1. Purpose :
38  !
39  ! This module computes a scattering term
40  ! based on the theory by Ardhuin and Magne (JFM 2007)
41  !
42  ! 2. Variables and types :
43  !
44  ! Name Type Scope Description
45  ! ----------------------------------------------------------------
46  ! ----------------------------------------------------------------
47  !
48  ! 3. Subroutines and functions :
49  !
50  ! Name Type Scope Description
51  ! ----------------------------------------------------------------
52  ! W3SBS1 Subr. Public bottom scattering
53  ! INSBS1 Subr. Public Corresponding initialization routine.
54  ! ----------------------------------------------------------------
55  !
56  ! 4. Subroutines and functions used :
57  !
58  ! Name Type Module Description
59  ! ----------------------------------------------------------------
60  ! STRACE Subr. W3SERVMD Subroutine tracing.
61  ! ----------------------------------------------------------------
62  !
63  ! 5. Remarks :
64  !
65  !
66  ! 6. Switches :
67  !
68  ! !/S Enable subroutine tracing.
69  !
70  ! 7. Source code :
71  !/
72  !/ ------------------------------------------------------------------- /
73  !/
74  !
75  PUBLIC
76  !/
77  !/ Public variables
78  !/
79  REAL, DIMENSION(:,:), ALLOCATABLE :: botspec
80  INTEGER, PARAMETER :: nkscat = 30 !number of wavenumbers
81  DOUBLE PRECISION ,DIMENSION(:,:,:) , ALLOCATABLE :: scatmatv !scattering matrices
82  DOUBLE PRECISION ,DIMENSION(:,:,:) , ALLOCATABLE :: scatmata !original matrix
83  DOUBLE PRECISION ,DIMENSION(:,:) , ALLOCATABLE :: scatmatd
84  CHARACTER(len=10) :: botspec_indicator
85  INTEGER :: nkbx, nkby
86  REAL :: dkbx, dkby, kwmin, kwmax
87  REAL, PARAMETER :: scattcutoff=0.
88  REAL :: curtx, curty
89  !/
90 CONTAINS
97 
112  SUBROUTINE w3sbs1(A, CG, WN, DEPTH, CX1, CY1, &
113  TAUSCX, TAUSCY, S, D)
114  !/
115  !/ +-----------------------------------+
116  !/ | WAVEWATCH III NOAA/NCEP |
117  !/ | F. Ardhuin |
118  !/ | FORTRAN 90 |
119  !/ | Last update : 23-Jun-2006 |
120  !/ +-----------------------------------+
121  !/
122  !/ 15-Jul-2005 : Origination. ( version 3.07 )
123  !/ 23-Jun-2006 : Formatted for submitting code for ( version 3.09 )
124  !/ inclusion in WAVEWATCH III.
125  !/
126  ! 1. Purpose :
127  !
128  ! Bottom scattering source term
129  !
130  ! 2. Method :
131  !
132  ! Without current, goes through a diagonalization of the matrix
133  ! problem S(f,:) = M(f,:,:)**E(f,:)
134  ! With current, integrates the source term along the resonant locus
135  !
136  ! 3. Parameters :
137  !
138  ! Parameter list
139  ! ----------------------------------------------------------------
140  ! A R.A. I Action density spectrum (1-D)
141  ! CG R.A. I Group velocities.
142  ! WN R.A. I Wavenumbers.
143  ! DEPTH Real I Mean water depth.
144  ! S R.A. O Source term (1-D version).
145  ! D R.A. O Diagonal term of derivative (1-D version).
146  ! CX1-Y1 R.A. I Current components at ISEA.
147  ! TAUSCX-Y R.A. I Change of wave momentum due to scattering
148  ! ----------------------------------------------------------------
149  !
150  ! 4. Subroutines used :
151  !
152  ! Name Type Module Description
153  ! ----------------------------------------------------------------
154  ! STRACE Subr. W3SERVMD Subroutine tracing.
155  ! ----------------------------------------------------------------
156  !
157  ! 5. Called by :
158  !
159  ! Name Type Module Description
160  ! ----------------------------------------------------------------
161  ! W3SRCE Subr. W3SRCEMD Source term integration.
162  ! W3EXPO Subr. N/A Point output post-processor.
163  ! GXEXPO Subr. N/A GrADS point output post-processor.
164  ! ----------------------------------------------------------------
165  !
166  ! 6. Error messages :
167  !
168  ! None.
169  !
170  ! 7. Remarks :
171  !
172  ! 8. Structure :
173  !
174  ! See source code.
175  !
176  ! 9. Switches :
177  !
178  ! !/S Enable subroutine tracing.
179  !
180  ! 10. Source code :
181  !
182  !/ ------------------------------------------------------------------- /
183  USE constants
184  USE w3gdatmd, ONLY: nk, nth, nspec, sig, dth, dden, &
185  ecos, esin, ec2, mapth, mapwn, &
186  sig2, dsii
187 #ifdef W3_S
188  USE w3servmd, ONLY: strace
189 #endif
190  !/
191  !
192  IMPLICIT NONE
193  !/
194  !/ ------------------------------------------------------------------- /
195  !/ Parameter list
196  !/
197  REAL, INTENT(IN) :: CG(NK), WN(NK), DEPTH
198  REAL, INTENT(IN) :: A(NTH,NK)
199  REAL, INTENT(IN) :: CX1, CY1
200  REAL, INTENT(OUT) :: TAUSCX, TAUSCY
201  REAL, INTENT(OUT) :: S(NSPEC), D(NSPEC)
202  !/
203  !/ ------------------------------------------------------------------- /
204  !/ Local parameters
205  !/
206  INTEGER :: ISPEC, IK, NSCUT, ITH, ITH2, i, j,iajust,iajust2
207 #ifdef W3_S
208  INTEGER, SAVE :: IENT = 0
209 #endif
210  LOGICAL, SAVE :: FIRST = .true.
211  INTEGER :: MATRICES = 0
212 
213  REAL :: R1, R2, R3
214 
215  REAL :: WN2(NSPEC, NTH), Ka(NSPEC), &
216  Kb(NSPEC, NTH), WNBOT(NSPEC, NTH), &
217  B(NSPEC, NTH)
218  REAL :: kbotxi, kbotyi, xbk, &
219  ybk,integral, kbotx, kboty, count,count2
220 
221  INTEGER :: ibk, jbk, ik2
222  REAL :: SIGP,KU, KPU, CGK, CGPK, WN2i, xk2, Ap, kcutoff, ECC2, &
223  variance , integral1,integral1b,integral2, SB(NK,NTH), integral3,&
224  ajust,absajust,aa,bb,LNORM,UdotL,KdotKP,MBANDC
225  REAL :: KD, Kfactor, kscaled, kmod , CHECKSUM, ETOT
226  REAL :: SMATRIX(NTH,NTH),SMATRIX2(NTH,NTH)
227  DOUBLE PRECISION :: AVECT(NTH)
228 
229  curtx=cx1
230  curty=cy1
231 
232  count=0
233  !/
234  !/ ------------------------------------------------------------------- /
235  !/
236 #ifdef W3_S
237  CALL strace (ient, 'W3SBS1')
238 #endif
239  !
240  ! 0. Initializations ------------------------------------------------ *
241  !
242  ! **********************************************************
243  ! *** The initialization routine should include all ***
244  ! *** initialization, including reading data from files. ***
245  ! **********************************************************
246  !
247  IF ( first ) THEN
248  CALL insbs1( 1 )
249  first = .false.
250  END IF
251  IF (( (abs(cx1)+abs(cy1)).EQ.0.).AND.(matrices.EQ.0) ) THEN
252  kwmin=max(max(dkbx,dkby),sig(1)**2/grav)
253  kwmax=min(nkbx*dkbx,nkby*dkby)*0.25
254  WRITE(*,*) 'k range:',kwmin,kwmax,sig(1)**2/grav
255  CALL insbs1( 2 )
256  matrices = 1
257  END IF
258  !
259  ! 1. Sets scattering term to zero
260  !
261  d = 0.
262  s = 0.
263  tauscx=0.
264  tauscy=0.
265  !
266  ! 3. Bottom scattering ================================================== *
267  !
268  IF ( depth*wn(1) .LE. 6 ) THEN
269  !
270  ! 3.a Ardhuin and Herbers JFM 2000: no current
271  !
272  IF ((abs(cx1)+abs(cy1).EQ.0.).AND.(matrices.EQ.1)) THEN
273  DO ik=1,nk
274  kd=wn(ik)*depth
275  IF ( kd .LE. 6 .AND.wn(ik).LT.kwmax ) THEN
276  ! Test on kwmax means that scattering is not computed if interaction goes beyond the shortest resolved
277  ! bottom component. This should probably be replaced by a warning...
278  kfactor=(wn(ik)**4)*sig(ik)*pi*4. &
279  /(sinh(2*kd)*(2*kd+sinh(2*kd)))
280  kscaled=(nkscat-2)*(wn(ik)-kwmin)/(kwmax-kwmin)
281  avect=dble(a(:,ik))
282  IF (kscaled.LT.0) THEN
283  ibk=0
284  kmod=0.
285  ELSE
286  ibk=int(kscaled)
287  kmod=mod(kscaled,1.0)
288  END IF
289  s((ik-1)*nth+1:ik*nth) &
290  =real(matmul(scatmatv(ibk,:,:),kfactor*scatmatd(ibk,:) &
291  *matmul(transpose(scatmatv(ibk,:,:)),avect))*(1.-kmod))
292  s((ik-1)*nth+1:ik*nth) &
293  =s((ik-1)*nth+1:ik*nth) &
294  +real(matmul(scatmatv(ibk+1,:,:),kfactor*scatmatd(ibk+1,:) &
295  *matmul(transpose(scatmatv(ibk+1,:,:)),avect))*kmod)
296  checksum=abs(sum(s((ik-1)*nth+1:ik*nth) ))
297  etot=sum(a(:,ik))
298  IF (checksum.GT.0.01*etot) WRITE(*,*) &
299  'Energy not conserved:',ik,depth,checksum,etot
300  ELSE
301  s((ik-1)*nth+1:ik*nth)=0.
302  END IF
303  END DO
304  ELSE
305  ! 3.b
306  ! Case with current (Ardhuin and Magne JFM 2007)
307  ! Compute k' (WN2) from k (WN) and U (CX1, CY1)
308  ! using : k'=(Cg+k.U/k)/(Cg+k'.U/k')
309  !
310  DO ith2=1, nth
311 
312  DO ispec=1, nspec
313 
314  ku=cx1 * ecos(mapth(ispec))+cy1 * esin(mapth(ispec))
315  kpu=cx1 * ecos(ith2)+ cy1 * esin(ith2)
316  cgk=cg(mapwn(ispec))
317  IF ((cgk+kpu).LT.0.1*cgk) kpu=-0.9*cgk
318  IF ((cgk+ku).LT.0.1*cgk) ku=-0.9*cg(mapwn(ispec))
319  wn2(ispec,ith2)= wn(mapwn(ispec))*(cgk+ku)/(cgk+kpu)
320  END DO
321 
322  END DO
323  !
324  ! 3.c Compute the coupling coefficient as a product of two terms
325  !
326  ! K=0.5*pi k'^2 * M(k,k')^2 / [sig*sig' *(k'*Cg'+k'.U)]
327  ! (Magne and Ardhuin JFM 2007)
328  !
329  ! K=Ka(k)*Kb(k,k',theta')
330  !
331  ! Ka = ...
332  ! here Mc is neglected
333  !
334  DO ispec=1, nspec
335  ka(ispec)= 4*pi*sig2(ispec) * wn(mapwn(ispec)) / &
336  sinh(min(2*wn(mapwn(ispec))*depth,20.))
337 
338  DO ith2=1, nth
339  ku=cx1 * ecos(mapth(ispec))+cy1 * esin(mapth(ispec))
340  kpu=cx1 * ecos(ith2)+ cy1 * esin(ith2)
341  sigp=sqrt(grav*wn2(ispec,ith2)*tanh(wn2(ispec,ith2)*depth))
342  cgpk=sigp*(0.5+wn2(ispec,ith2)*depth &
343  /sinh(min(2*wn2(ispec,ith2)*depth,20.)))/wn2(ispec, ith2)
344 
345  kb(ispec, ith2)= wn2(ispec, ith2)**3 &
346  *ec2(1+abs(mapth(ispec)-ith2)) / &
347  ( &
348  2*wn2(ispec, ith2)*depth + &
349  sinh(min(2*wn2(ispec,ith2)*depth,20.)) &
350  *(1+wn2(ispec,ith2)*kpu*2/sigp) &
351  )
352 
353  !
354  ! Other option for computing also Mc
355  !
356  ! UdotL=WN(MAPWN(ISPEC))*KU-KPU*WN2(ISPEC,ITH2)
357  ! KdotKP=EC(1+ABS(MAPTH(ISPEC)-ITH2))*WN2(ISPEC,ITH2)*WN(MAPWN(ISPEC))
358  ! LNORM=sqrt(WN(MAPWN(ISPEC))**2+WN2(ISPEC, ITH2)**2-2*KdotKP)
359  ! MBANDC=grav*KdotKP &
360  ! /(COSH(MIN(WN2(ISPEC,ITH2)*DEPTH,20.))*COSH(MIN(WN(MAPWN(ISPEC))*DEPTH,20.)
361  ! +(UdotL*(SIGP*(WN(MAPWN(ISPEC))**2-KdotKP)+SIG2(ISPEC)*(KdotKP-WN2(ISPEC, ITH2)**2)) &
362  ! - UdotL**2*(KdotKP-SIGP*SIG2(ISPEC)*(SIGP*SIG2(ISPEC)+UdotL**2)/GRAV**2)) &
363  ! /(LNORM*(UdotL**2/(GRAV*LNORM)-TANH(MIN(LNORM*DEPTH,20.)))*COSH(MIN(LNORM*DEPTH,20.)))
364  ! Kb(ISPEC,ITH2)= WN2(ISPEC, ITH2)**2
365  ! /((SIG2(ISPEC)*SIGP*WN2(ISPEC, ITH2)*(CGPK+KPU)) &
366  ! *MBANDC**2
367  !
368  END DO
369  END DO
370  !
371  ! 3.a Bilinear interpolation of the bottom spectrum BOTSPEC
372  ! along the locus -> B(ISPEC,ITH2)
373  !
374  b(:,:)=0
375  DO ispec=1, nspec
376  kcutoff=scattcutoff*wn(mapwn(ispec))
377  DO ith2=1,nth
378  kbotx=wn(mapwn(ispec))*ecos(mapth(ispec)) - &
379  wn2(ispec, ith2) * ecos(ith2)
380  kboty=wn(mapwn(ispec))*esin(mapth(ispec)) - &
381  wn2(ispec, ith2) * esin(ith2)
382  !
383  ! 3.a.1 test if the bottom wavenumber is larger than the cutoff
384  ! otherwise the interaction is set to zero
385 
386  IF ((kbotx**2+kboty**2)>(kcutoff**2)) THEN
387 
388  kbotxi=real(nkbx-mod(nkbx,2))/2.+1.+kbotx/dkbx ! The MOD(nkbx,2) is either 1 or 0
389  kbotyi=real(nkby-mod(nkby,2))/2.+1.+kboty/dkby ! k=0 is at ik=(nkbx-1)/2+1 if kkbx is odd
390 
391  ibk=max(min(int(kbotxi),nkbx-1),1)
392  xbk=mod(kbotxi,1.0)
393  jbk=max(min(int(kbotyi),nkby-1),1)
394  ybk=mod(kbotyi,1.0)
395 
396  b(ispec,ith2)=( &
397  (botspec(ibk,jbk)*(1-ybk)+ &
398  botspec(ibk,jbk+1)*ybk)*(1-xbk) &
399  + &
400  (botspec(ibk+1,jbk)*(1-ybk)+ &
401  botspec(ibk+1,jbk+1)*ybk)*xbk &
402  )
403  END IF
404  END DO
405  END DO
406  !
407  ! 4. compute Sbscat
408  ! 4.a linear interpolation of A(k', theta') -> Ap
409  !
410 
411  ! 4.b computation of the source term
412  integral2=0.
413  integral3=0.
414  smatrix(:,:)=0.
415  DO ispec=1, nspec
416  integral=0
417  DO ith2=1, nth
418  iajust=1
419  DO i=2,nk
420  if(wn2(ispec,ith2).GE.wn(i)) iajust=i
421  END DO
422  iajust=max(iajust,1)
423  iajust2=min(iajust+1,nk)
424  IF (iajust.EQ.iajust2) THEN
425  ap=a(ith2,iajust)
426  ELSE
427  bb=(wn2(ispec,ith2)-wn(iajust))/(wn(iajust2)-wn(iajust))
428  aa=(wn(iajust2)-wn2(ispec,ith2))/(wn(iajust2)-wn(iajust))
429  ap=(a(ith2,iajust)*aa+a(ith2,iajust2)*bb)
430  END IF
431 
432  integral=integral + ka(ispec)*kb(ispec, ith2)*b(ispec,ith2)* &
433  ( ap*wn(mapwn(ispec))/wn2(ispec,ith2)- a(mapth(ispec),mapwn(ispec))) *dth
434  ! the factor WN/WN2 accounts for the fact that N(K) and N(K')
435  ! have different Jacobian transforms from kx,ky to k,theta
436 
437  integral1=integral1+kb(ispec, ith2)*b(ispec,ith2)*ap*wn(mapwn(ispec))/wn2(ispec,ith2)*dth &
438  *dth*dsii(mapwn(ispec))/cg(mapwn(ispec))
439  integral1b=integral1b+kb(ispec, ith2)*b(ispec,ith2)*a(mapth(ispec),mapwn(ispec))*dth &
440  *dth*dsii(mapwn(ispec))/cg(mapwn(ispec))
441  END DO
442  s(ispec)=s(ispec)+integral
443 
444  integral2=integral2+s(ispec)*dth*dsii(mapwn(ispec))/cg(mapwn(ispec))
445  integral3=integral3+abs(s(ispec))*dth*dsii(mapwn(ispec))/cg(mapwn(ispec))
446  END DO
447  END IF
448 #ifdef W3_T
449  print*,'BOTTOM SCAT CHECKSUM:',integral2,integral3,integral1,integral1b
450 #endif
451 
452 #ifdef W3_T
453  DO ith=1,120
454  WRITE(6,'(120G15.7)') smatrix(ith,:)
455  END DO
456 #endif
457  END IF
458 
459  !/
460  !/ End of W3SBS1 ----------------------------------------------------- /
461  !/
462  END SUBROUTINE w3sbs1
463  !/ ------------------------------------------------------------------- /
472 
473  SUBROUTINE insbs1( inistep )
474  !/
475  !/ +-----------------------------------+
476  !/ | WAVEWATCH III NOAA/NCEP |
477  !/ | F. Ardhuin |
478  !/ | FORTRAN 90 |
479  !/ | Last update : 23-Jun-2006 |
480  !/ +-----------------------------------+
481  !/
482  !/ 23-Jun-2006 : Origination. ( version 3.09 )
483  !/
484  ! 1. Purpose :
485  !
486  ! Initialization for bottom scattering source term routine.
487  !
488  ! 2. Method :
489  !
490  ! 3. Parameters :
491  !
492  ! Parameter list
493  ! ----------------------------------------------------------------
494  ! ----------------------------------------------------------------
495  !
496  ! 4. Subroutines used :
497  !
498  ! Name Type Module Description
499  ! ----------------------------------------------------------------
500  ! STRACE Subr. W3SERVMD Subroutine tracing.
501  ! ----------------------------------------------------------------
502  !
503  ! 5. Called by :
504  !
505  ! Name Type Module Description
506  ! ----------------------------------------------------------------
507  ! W3SBS1 Subr. W3SBS1MD Corresponding source term.
508  ! ----------------------------------------------------------------
509  !
510  ! 6. Error messages :
511  !
512  ! None.
513  !
514  ! 7. Remarks :
515  !
516  ! 8. Structure :
517  !
518  ! See source code.
519  !
520  ! 9. Switches :
521  !
522  ! !/S Enable subroutine tracing.
523  !
524  ! 10. Source code :
525  !
526  !/ ------------------------------------------------------------------- /
527  USE w3gdatmd, ONLY: nk, nth, nspec, sig, dth, dden, ecos, esin
528  USE w3servmd, ONLY: diagonalize
529 #ifdef W3_S
530  USE w3servmd, ONLY: strace
531 #endif
532  !/
533  IMPLICIT NONE
534  !/
535  !/ ------------------------------------------------------------------- /
536  !/ Parameter list
537  !/
538  INTEGER, INTENT(IN) :: inistep
539  !/
540  !/ ------------------------------------------------------------------- /
541  !/ Local parameters
542  !/
543 #ifdef W3_S
544  INTEGER, SAVE :: IENT = 0
545 #endif
546  INTEGER :: I, J, K1, K2, IK, JK, NROT
547  REAL :: kbotx, kboty, kcurr, kcutoff, variance
548  REAL :: kbotxi, kbotyi, xk, yk
549  DOUBLE PRECISION, ALLOCATABLE,DIMENSION(:,:) :: AMAT, V
550  DOUBLE PRECISION, ALLOCATABLE,DIMENSION(:) :: D
551  !/
552  !/ ------------------------------------------------------------------- /
553  !/
554 #ifdef W3_S
555  CALL strace (ient, 'INSBS1')
556 #endif
557  !
558  IF (inistep.EQ.1) THEN
559  !
560  ! 1. Reads bottom spectrum
561  !
562  OPEN(183,file= 'bottomspectrum.inp', status='old')
563  READ(183,*) nkbx, nkby
564  READ(183,*) dkbx, dkby
565  WRITE(*,*) 'Bottom spec. dim.:', nkbx, nkby, dkbx, dkby
566  ALLOCATE(botspec(nkbx, nkby))
567  DO i=1, nkbx
568  READ(183,*) botspec(i,:)
569  END DO
570  CLOSE(183)
571  variance=0
572  DO i=1,nkbx
573  DO j=1,nkby
574  variance=variance+botspec(i,j)*dkbx*dkby
575  END DO
576  END DO
577  WRITE(*,*) 'Bottom variance:', variance
578  !
579  ELSE
580  !
581  ! 2. Precomputed the scatering matrices for zero current
582  !
583  ! The Scattering source term is expressed as a matrix problem for
584  ! a list of wavenumbers k0
585  ! in the range of wavenumbers used in the model.
586  ! i.e. S(k0,theta)=Kfactor*SCATMATA ** TRANSPOSE (E(k0,theta))
587  !
588  ! in which
589  !
590  ! Kfactor is a scalar computed in CALCSOURCE as
591  ! Kfactor=tailfactor*(Kp(I,J)**4)*2.*pi*FREQ(J)*pi*4./(SINH(HND)*(HND+SINH(HND)))
592  !
593  ! SCATMATA is a square matrix of size NTH*NTH
594  !
595  ! S(k0,theta) and E(k0,theta) are the vectors giving the directional source term
596  ! and spectrum at a fixed wavenumber
597  !
598  ALLOCATE(scatmata(0:nkscat-1,1:nth,1:nth))
599  ALLOCATE(amat(nth,nth))
600  DO i=0,nkscat-1
601  ! kcurr is the current surface wavenumber for which
602  ! the scattering matrices are evaluated
603  kcurr=kwmin+i*(kwmax-kwmin)/(nkscat-2)
604  kcutoff=scattcutoff*kcurr
605  DO k1=1,nth
606  DO k2=1,nth
607  kbotx=-kcurr*(ecos(k2)-ecos(k1))
608  kboty=-kcurr*(esin(k2)-esin(k1))
609  amat(k1,k2)=0.
610  ! Tests if the bottom wavenumber is larger than the cutoff
611  ! Otherwise the interaction is set to zero
612  IF ((kbotx**2+kboty**2) > (kcutoff**2)) THEN
613  !WARNING : THERE MAY BE A BUG : spectrum not symmetric when
614  ! nkbx is odd !!
615 
616  kbotxi=real(nkbx)/2.+1.+kbotx/dkbx
617  kbotyi=real(nkby)/2.+1.+kboty/dkby
618  !WRITE(6,*) 'Bottom wavenumber i:',kbotxi,kbotyi
619  ik=int(kbotxi)
620  xk=mod(kbotxi,1.0)
621  jk=int(kbotyi)
622  yk=mod(kbotyi,1.0)
623  IF (ik.GE.nkbx) ik=nkbx-1
624  IF (jk.GE.nkby) jk=nkby-1
625  IF (ik.LT.1) ik=1
626  IF (jk.LT.1) jk=1
627  ! Bilinear interpolation of the bottom spectrum
628  amat(k1,k2)=((botspec(ik,jk ) *(1-yk) &
629  +botspec(ik,jk+1) *yk )*(1-xk) &
630  +(botspec(ik+1,jk) *(1-yk) &
631  +botspec(ik+1,jk+1)*yk) *xk) &
632  *(ecos(k1)*ecos(k2)+esin(k1)*esin(k2))**2
633  END IF
634  END DO
635  amat(k1,k1)=amat(k1,k1)-sum(amat(k1,:))
636  END DO
637  amat(:,:)=dth*(amat(:,:)+transpose(amat(:,:)))*0.5
638  !makes sure the matrix is exactly symmetric
639  !which should already be the case if the bottom
640  ! spectrum is really symmetric
641  scatmata(i,:,:)=amat(:,:)
642  END DO
643  ALLOCATE(scatmatd(0:nkscat-1,nth))
644  ALLOCATE(scatmatv(0:nkscat-1,nth,nth))
645  ALLOCATE(v(nth,nth))
646  ALLOCATE(d(nth))
647  DO i=0,nkscat-1
648  amat(:,:)=scatmata(i,:,:)
649  !
650  !diagonalizes the matrix A
651  !D is a vector with the eigenvalues, V is the matrix made of the
652  !eigenvectors so that VD2Vt=A with D2(i,j)=delta(i,j)D(i)
653  !and VVt=Id, so that exp(A)=Vexp(D2)Vt
654  !
655  CALL diagonalize(amat,d,v,nrot)
656  scatmatd(i,:)=d(:) !eigen values
657  scatmatv(i,:,:)=v(:,:) !eigen vectors
658  kcurr=kwmin+i*(kwmax-kwmin)/(nkscat-2)
659  WRITE(*,*) 'Scattering matrix diagonalized for k= ',kcurr,',',i+1,'out of ',nkscat
660  END DO
661  END IF
662 
663  !/
664  !/ End of INSBS1 ----------------------------------------------------- /
665  !/
666  END SUBROUTINE insbs1
667  !/
668  !/ End of module INSBS1MD -------------------------------------------- /
669  !/
670 END MODULE w3sbs1md
w3gdatmd::nk
integer, pointer nk
Definition: w3gdatmd.F90:1230
constants::pi
real, parameter pi
PI Value of Pi.
Definition: constants.F90:71
w3gdatmd::dth
real, pointer dth
Definition: w3gdatmd.F90:1232
w3sbs1md::kwmax
real kwmax
Definition: w3sbs1md.F90:86
w3gdatmd::nspec
integer, pointer nspec
Definition: w3gdatmd.F90:1230
w3sbs1md::nkbx
integer nkbx
Definition: w3sbs1md.F90:85
w3sbs1md::kwmin
real kwmin
Definition: w3sbs1md.F90:86
w3sbs1md::botspec
real, dimension(:,:), allocatable botspec
Definition: w3sbs1md.F90:79
w3gdatmd::mapth
integer, dimension(:), pointer mapth
Definition: w3gdatmd.F90:1231
w3sbs1md::botspec_indicator
character(len=10) botspec_indicator
Definition: w3sbs1md.F90:84
w3sbs1md::curtx
real curtx
Definition: w3sbs1md.F90:88
w3gdatmd::sig
real, dimension(:), pointer sig
Definition: w3gdatmd.F90:1234
w3sbs1md::dkbx
real dkbx
Definition: w3sbs1md.F90:86
w3gdatmd::ecos
real, dimension(:), pointer ecos
Definition: w3gdatmd.F90:1234
w3gdatmd::esin
real, dimension(:), pointer esin
Definition: w3gdatmd.F90:1234
w3sbs1md::scattcutoff
real, parameter scattcutoff
Definition: w3sbs1md.F90:87
w3sbs1md::curty
real curty
Definition: w3sbs1md.F90:88
w3servmd
Definition: w3servmd.F90:3
w3gdatmd::dsii
real, dimension(:), pointer dsii
Definition: w3gdatmd.F90:1234
w3gdatmd::nth
integer, pointer nth
Definition: w3gdatmd.F90:1230
w3sbs1md::scatmatd
double precision, dimension(:,:), allocatable scatmatd
Definition: w3sbs1md.F90:83
w3sbs1md::scatmatv
double precision, dimension(:,:,:), allocatable scatmatv
Definition: w3sbs1md.F90:81
w3sbs1md::w3sbs1
subroutine w3sbs1(A, CG, WN, DEPTH, CX1, CY1, TAUSCX, TAUSCY, S, D)
Bottom scattering source term.
Definition: w3sbs1md.F90:114
file
file(STRINGS ${CMAKE_BINARY_DIR}/switch switch_strings) separate_arguments(switches UNIX_COMMAND $
Definition: CMakeLists.txt:3
w3sbs1md::scatmata
double precision, dimension(:,:,:), allocatable scatmata
Definition: w3sbs1md.F90:82
w3gdatmd::sig2
real, dimension(:), pointer sig2
Definition: w3gdatmd.F90:1234
w3servmd::diagonalize
subroutine diagonalize(a1, d, v, nrot)
Definition: w3servmd.F90:1840
w3sbs1md::nkscat
integer, parameter nkscat
Definition: w3sbs1md.F90:80
w3servmd::strace
subroutine strace(IENT, SNAME)
Definition: w3servmd.F90:148
w3gdatmd::mapwn
integer, dimension(:), pointer mapwn
Definition: w3gdatmd.F90:1231
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
w3sbs1md
This module computes a scattering term based on the theory by Ardhuin and Magne (JFM 2007).
Definition: w3sbs1md.F90:22
w3sbs1md::dkby
real dkby
Definition: w3sbs1md.F90:86
w3gdatmd::ec2
real, dimension(:), pointer ec2
Definition: w3gdatmd.F90:1234
w3sbs1md::nkby
integer nkby
Definition: w3sbs1md.F90:85
constants::grav
real, parameter grav
GRAV Acc.
Definition: constants.F90:61
w3sbs1md::insbs1
subroutine insbs1(inistep)
Initialization for bottom scattering source term routine.
Definition: w3sbs1md.F90:474