New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
sbcwave.F90 in branches/2017/dev_r7881_no_wrk_alloc/NEMOGCM/NEMO/OPA_SRC/SBC – NEMO

source: branches/2017/dev_r7881_no_wrk_alloc/NEMOGCM/NEMO/OPA_SRC/SBC/sbcwave.F90 @ 7910

Last change on this file since 7910 was 7910, checked in by timgraham, 7 years ago

All wrk_alloc removed

  • Property svn:keywords set to Id
File size: 17.6 KB
Line 
1MODULE sbcwave
2   !!======================================================================
3   !!                       ***  MODULE  sbcwave  ***
4   !! Wave module
5   !!======================================================================
6   !! History :  3.3  !  2011-09  (M. Adani)  Original code: Drag Coefficient
7   !!         :  3.4  !  2012-10  (M. Adani)  Stokes Drift
8   !!            3.6  !  2014-09  (E. Clementi,P. Oddo) New Stokes Drift Computation
9   !!             -   !  2016-12  (G. Madec, E. Clementi) update Stoke drift computation
10   !!                                                    + add sbc_wave_ini routine
11   !!----------------------------------------------------------------------
12
13   !!----------------------------------------------------------------------
14   !!   sbc_stokes    : calculate 3D Stokes-drift velocities
15   !!   sbc_wave      : wave data from wave model in netcdf files
16   !!   sbc_wave_init : initialisation fo surface waves
17   !!----------------------------------------------------------------------
18   USE phycst         ! physical constants
19   USE oce            ! ocean variables
20   USE sbc_oce        ! Surface boundary condition: ocean fields
21   USE zdf_oce,  ONLY : ln_zdfqiao
22   USE bdy_oce        ! open boundary condition variables
23   USE domvvl         ! domain: variable volume layers
24   !
25   USE iom            ! I/O manager library
26   USE in_out_manager ! I/O manager
27   USE lib_mpp        ! distribued memory computing library
28   USE fldread        ! read input fields
29
30   IMPLICIT NONE
31   PRIVATE
32
33   PUBLIC   sbc_stokes      ! routine called in sbccpl
34   PUBLIC   sbc_wave        ! routine called in sbcmod
35   PUBLIC   sbc_wave_init   ! routine called in sbcmod
36   
37   ! Variables checking if the wave parameters are coupled (if not, they are read from file)
38   LOGICAL, PUBLIC ::   cpl_hsig   = .FALSE.
39   LOGICAL, PUBLIC ::   cpl_phioc  = .FALSE.
40   LOGICAL, PUBLIC ::   cpl_sdrftx = .FALSE.
41   LOGICAL, PUBLIC ::   cpl_sdrfty = .FALSE.
42   LOGICAL, PUBLIC ::   cpl_wper   = .FALSE.
43   LOGICAL, PUBLIC ::   cpl_wnum   = .FALSE.
44   LOGICAL, PUBLIC ::   cpl_wstrf  = .FALSE.
45   LOGICAL, PUBLIC ::   cpl_wdrag  = .FALSE.
46
47   INTEGER ::   jpfld    ! number of files to read for stokes drift
48   INTEGER ::   jp_usd   ! index of stokes drift  (i-component) (m/s)    at T-point
49   INTEGER ::   jp_vsd   ! index of stokes drift  (j-component) (m/s)    at T-point
50   INTEGER ::   jp_hsw   ! index of significant wave hight      (m)      at T-point
51   INTEGER ::   jp_wmp   ! index of mean wave period            (s)      at T-point
52
53   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_cd      ! structure of input fields (file informations, fields read) Drag Coefficient
54   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_sd      ! structure of input fields (file informations, fields read) Stokes Drift
55   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_wn      ! structure of input fields (file informations, fields read) wave number for Qiao
56   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_tauoc   ! structure of input fields (file informations, fields read) normalized wave stress into the ocean
57   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:)   ::   cdn_wave            !:
58   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:)   ::   hsw, wmp, wnum      !:
59   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:)   ::   tauoc_wave          !: 
60   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:)   ::   tsd2d               !:
61   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:)   ::   div_sd              !: barotropic stokes drift divergence
62   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:)   ::   ut0sd, vt0sd        !: surface Stokes drift velocities at t-point
63   REAL(wp), PUBLIC, ALLOCATABLE, DIMENSION(:,:,:) ::   usd  , vsd  , wsd   !: Stokes drift velocities at u-, v- & w-points, resp.
64
65   !! * Substitutions
66#  include "vectopt_loop_substitute.h90"
67   !!----------------------------------------------------------------------
68   !! NEMO/OPA 3.7 , NEMO Consortium (2014)
69   !! $Id$
70   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
71   !!----------------------------------------------------------------------
72CONTAINS
73
74   SUBROUTINE sbc_stokes( )
75      !!---------------------------------------------------------------------
76      !!                     ***  ROUTINE sbc_stokes  ***
77      !!
78      !! ** Purpose :   compute the 3d Stokes Drift according to Breivik et al.,
79      !!                2014 (DOI: 10.1175/JPO-D-14-0020.1)
80      !!
81      !! ** Method  : - Calculate Stokes transport speed
82      !!              - Calculate horizontal divergence
83      !!              - Integrate the horizontal divergenze from the bottom
84      !! ** action 
85      !!---------------------------------------------------------------------
86      INTEGER  ::   jj, ji, jk   ! dummy loop argument
87      INTEGER  ::   ik           ! local integer
88      REAL(wp) ::  ztransp, zfac, ztemp, zsp0
89      REAL(wp) ::  zdep_u, zdep_v, zkh_u, zkh_v, zda_u, zda_v
90      REAL(wp), DIMENSION(jpi,jpj)   ::   zk_t, zk_u, zk_v, zu0_sd, zv0_sd   ! 2D workspace
91      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ze3divh                            ! 3D workspace
92      !!---------------------------------------------------------------------
93      !
94      !
95      !
96      zfac =  2.0_wp * rpi / 16.0_wp
97      DO jj = 1, jpj                ! exp. wave number at t-point    (Eq. (19) in Breivick et al. (2014) )
98         DO ji = 1, jpi
99               ! Stokes drift velocity estimated from Hs and Tmean
100               ztransp = zfac * hsw(ji,jj)*hsw(ji,jj) / MAX( wmp(ji,jj) , 0.0000001_wp )
101               ! Stokes surface speed
102               zsp0 = SQRT( ut0sd(ji,jj)*ut0sd(ji,jj) + vt0sd(ji,jj)*vt0sd(ji,jj) )
103               tsd2d(ji,jj) = zsp0
104               ! Wavenumber scale
105               zk_t(ji,jj) = ABS( zsp0 ) / MAX( ABS( 5.97_wp*ztransp ) , 0.0000001_wp )
106         END DO
107      END DO     
108      DO jj = 1, jpjm1              ! exp. wave number & Stokes drift velocity at u- & v-points
109         DO ji = 1, jpim1
110            zk_u(ji,jj) = 0.5_wp * ( zk_t(ji,jj) + zk_t(ji+1,jj) )
111            zk_v(ji,jj) = 0.5_wp * ( zk_t(ji,jj) + zk_t(ji,jj+1) )
112            !
113            zu0_sd(ji,jj) = 0.5_wp * ( ut0sd(ji,jj) + ut0sd(ji+1,jj) )
114            zv0_sd(ji,jj) = 0.5_wp * ( vt0sd(ji,jj) + vt0sd(ji,jj+1) )
115         END DO
116      END DO
117      !
118      !                       !==  horizontal Stokes Drift 3D velocity  ==!
119      DO jk = 1, jpkm1
120         DO jj = 2, jpjm1
121            DO ji = 2, jpim1
122               zdep_u = 0.5_wp * ( gdept_n(ji,jj,jk) + gdept_n(ji+1,jj,jk) )
123               zdep_v = 0.5_wp * ( gdept_n(ji,jj,jk) + gdept_n(ji,jj+1,jk) )
124               !                         
125               zkh_u = zk_u(ji,jj) * zdep_u     ! k * depth
126               zkh_v = zk_v(ji,jj) * zdep_v
127               !                                ! Depth attenuation
128               zda_u = EXP( -2.0_wp*zkh_u ) / ( 1.0_wp + 8.0_wp*zkh_u )
129               zda_v = EXP( -2.0_wp*zkh_v ) / ( 1.0_wp + 8.0_wp*zkh_v )
130               !
131               usd(ji,jj,jk) = zda_u * zu0_sd(ji,jj) * umask(ji,jj,jk)
132               vsd(ji,jj,jk) = zda_v * zv0_sd(ji,jj) * vmask(ji,jj,jk)
133            END DO
134         END DO
135      END DO   
136      CALL lbc_lnk( usd(:,:,:), 'U', vsd(:,:,:), 'V', -1. )
137      !
138      !                       !==  vertical Stokes Drift 3D velocity  ==!
139      !
140      DO jk = 1, jpkm1               ! Horizontal e3*divergence
141         DO jj = 2, jpj
142            DO ji = fs_2, jpi
143               ze3divh(ji,jj,jk) = (  e2u(ji  ,jj) * e3u_n(ji  ,jj,jk) * usd(ji  ,jj,jk)    &
144                  &                 - e2u(ji-1,jj) * e3u_n(ji-1,jj,jk) * usd(ji-1,jj,jk)    &
145                  &                 + e1v(ji,jj  ) * e3v_n(ji,jj  ,jk) * vsd(ji,jj  ,jk)    &
146                  &                 - e1v(ji,jj-1) * e3v_n(ji,jj-1,jk) * vsd(ji,jj-1,jk)  ) * r1_e1e2t(ji,jj)
147            END DO
148         END DO
149      END DO
150      !
151      IF( .NOT. AGRIF_Root() ) THEN
152         IF( nbondi ==  1 .OR. nbondi == 2 )   ze3divh(nlci-1,   :  ,:) = 0._wp      ! east
153         IF( nbondi == -1 .OR. nbondi == 2 )   ze3divh(  2   ,   :  ,:) = 0._wp      ! west
154         IF( nbondj ==  1 .OR. nbondj == 2 )   ze3divh(  :   ,nlcj-1,:) = 0._wp      ! north
155         IF( nbondj == -1 .OR. nbondj == 2 )   ze3divh(  :   ,  2   ,:) = 0._wp      ! south
156      ENDIF
157      !
158      CALL lbc_lnk( ze3divh, 'T', 1. )
159      !
160      IF( ln_linssh ) THEN   ;   ik = 1   ! none zero velocity through the sea surface
161      ELSE                   ;   ik = 2   ! w=0 at the surface (set one for all in sbc_wave_init)
162      ENDIF
163      DO jk = jpkm1, ik, -1          ! integrate from the bottom the hor. divergence (NB: at k=jpk w is always zero)
164         wsd(:,:,jk) = wsd(:,:,jk+1) - ze3divh(:,:,jk)
165      END DO
166      !
167      IF( ln_bdy ) THEN
168         DO jk = 1, jpkm1
169            wsd(:,:,jk) = wsd(:,:,jk) * bdytmask(:,:)
170         END DO
171      ENDIF
172      !                       !==  Horizontal divergence of barotropic Stokes transport  ==!
173      div_sd(:,:) = 0._wp
174      DO jk = 1, jpkm1                                 !
175        div_sd(:,:) = div_sd(:,:) + ze3divh(:,:,jk)
176      END DO
177      !
178      CALL iom_put( "ustokes",  usd  )
179      CALL iom_put( "vstokes",  vsd  )
180      CALL iom_put( "wstokes",  wsd  )
181      !
182      !
183   END SUBROUTINE sbc_stokes
184
185
186   SUBROUTINE sbc_wave( kt )
187      !!---------------------------------------------------------------------
188      !!                     ***  ROUTINE sbc_wave  ***
189      !!
190      !! ** Purpose :   read wave parameters from wave model  in netcdf files.
191      !!
192      !! ** Method  : - Read namelist namsbc_wave
193      !!              - Read Cd_n10 fields in netcdf files
194      !!              - Read stokes drift 2d in netcdf files
195      !!              - Read wave number in netcdf files
196      !!              - Compute 3d stokes drift using Breivik et al.,2014
197      !!                formulation
198      !! ** action 
199      !!---------------------------------------------------------------------
200      INTEGER, INTENT(in   ) ::   kt   ! ocean time step
201      !!---------------------------------------------------------------------
202      !
203      IF( ln_cdgw .AND. .NOT. cpl_wdrag ) THEN     !==  Neutral drag coefficient  ==!
204         CALL fld_read( kt, nn_fsbc, sf_cd )             ! read from external forcing
205         cdn_wave(:,:) = sf_cd(1)%fnow(:,:,1)
206      ENDIF
207
208      IF( ln_tauoc .AND. .NOT. cpl_wstrf ) THEN    !==  Wave induced stress  ==!
209         CALL fld_read( kt, nn_fsbc, sf_tauoc )          ! read wave norm stress from external forcing
210         tauoc_wave(:,:) = sf_tauoc(1)%fnow(:,:,1)
211      ENDIF
212
213      IF( ln_sdw )  THEN                           !==  Computation of the 3d Stokes Drift  ==!
214         !
215         IF( jpfld > 0 ) THEN                            ! Read from file only if the field is not coupled
216            CALL fld_read( kt, nn_fsbc, sf_sd )          ! read wave parameters from external forcing
217            IF( jp_hsw > 0 )   hsw  (:,:) = sf_sd(jp_hsw)%fnow(:,:,1)   ! significant wave height
218            IF( jp_wmp > 0 )   wmp  (:,:) = sf_sd(jp_wmp)%fnow(:,:,1)   ! wave mean period
219            IF( jp_usd > 0 )   ut0sd(:,:) = sf_sd(jp_usd)%fnow(:,:,1)   ! 2D zonal Stokes Drift at T point
220            IF( jp_vsd > 0 )   vt0sd(:,:) = sf_sd(jp_vsd)%fnow(:,:,1)   ! 2D meridional Stokes Drift at T point
221         ENDIF
222         !
223         ! Read also wave number if needed, so that it is available in coupling routines
224         IF( ln_zdfqiao .AND. .NOT.cpl_wnum ) THEN
225            CALL fld_read( kt, nn_fsbc, sf_wn )          ! read wave parameters from external forcing
226            wnum(:,:) = sf_wn(1)%fnow(:,:,1)
227         ENDIF
228           
229         !                                         !==  Computation of the 3d Stokes Drift  ==!
230         !
231         IF( jpfld == 4 )   CALL sbc_stokes()            ! Calculate only if required fields are read
232         !                                               ! In coupled wave model-NEMO case the call is done after coupling
233         !
234      ENDIF
235      !
236   END SUBROUTINE sbc_wave
237
238
239   SUBROUTINE sbc_wave_init
240      !!---------------------------------------------------------------------
241      !!                     ***  ROUTINE sbc_wave_init  ***
242      !!
243      !! ** Purpose :   read wave parameters from wave model  in netcdf files.
244      !!
245      !! ** Method  : - Read namelist namsbc_wave
246      !!              - Read Cd_n10 fields in netcdf files
247      !!              - Read stokes drift 2d in netcdf files
248      !!              - Read wave number in netcdf files
249      !!              - Compute 3d stokes drift using Breivik et al.,2014
250      !!                formulation
251      !! ** action 
252      !!---------------------------------------------------------------------
253      INTEGER ::   ierror, ios   ! local integer
254      INTEGER ::   ifpr
255      !!
256      CHARACTER(len=100)     ::  cn_dir                          ! Root directory for location of drag coefficient files
257      TYPE(FLD_N), ALLOCATABLE, DIMENSION(:) ::   slf_i     ! array of namelist informations on the fields to read
258      TYPE(FLD_N)            ::  sn_cdg, sn_usd, sn_vsd,  &
259                             &   sn_hsw, sn_wmp, sn_wnum, sn_tauoc      ! informations about the fields to be read
260      !
261      NAMELIST/namsbc_wave/  sn_cdg, cn_dir, sn_usd, sn_vsd, sn_hsw, sn_wmp, sn_wnum, sn_tauoc
262      !!---------------------------------------------------------------------
263      !
264      REWIND( numnam_ref )              ! Namelist namsbc_wave in reference namelist : File for drag coeff. from wave model
265      READ  ( numnam_ref, namsbc_wave, IOSTAT = ios, ERR = 901)
266901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_wave in reference namelist', lwp )
267         
268      REWIND( numnam_cfg )              ! Namelist namsbc_wave in configuration namelist : File for drag coeff. from wave model
269      READ  ( numnam_cfg, namsbc_wave, IOSTAT = ios, ERR = 902 )
270902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_wave in configuration namelist', lwp )
271      IF(lwm) WRITE ( numond, namsbc_wave )
272      !
273      IF( ln_cdgw ) THEN
274         IF( .NOT. cpl_wdrag ) THEN
275            ALLOCATE( sf_cd(1), STAT=ierror )           !* allocate and fill sf_wave with sn_cdg
276            IF( ierror > 0 )   CALL ctl_stop( 'STOP', 'sbc_wave_init: unable to allocate sf_wave structure' )
277            !
278                                   ALLOCATE( sf_cd(1)%fnow(jpi,jpj,1)   )
279            IF( sn_cdg%ln_tint )   ALLOCATE( sf_cd(1)%fdta(jpi,jpj,1,2) )
280            CALL fld_fill( sf_cd, (/ sn_cdg /), cn_dir, 'sbc_wave_init', 'Wave module ', 'namsbc_wave' )
281         ENDIF
282         ALLOCATE( cdn_wave(jpi,jpj) )
283      ENDIF
284
285      IF( ln_tauoc ) THEN
286         IF( .NOT. cpl_wstrf ) THEN
287            ALLOCATE( sf_tauoc(1), STAT=ierror )           !* allocate and fill sf_wave with sn_tauoc
288            IF( ierror > 0 )   CALL ctl_stop( 'STOP', 'sbc_wave_init: unable to allocate sf_wave structure' )
289            !
290                                    ALLOCATE( sf_tauoc(1)%fnow(jpi,jpj,1)   )
291            IF( sn_tauoc%ln_tint )  ALLOCATE( sf_tauoc(1)%fdta(jpi,jpj,1,2) )
292            CALL fld_fill( sf_tauoc, (/ sn_tauoc /), cn_dir, 'sbc_wave_init', 'Wave module', 'namsbc_wave' )
293         ENDIF
294         ALLOCATE( tauoc_wave(jpi,jpj) )
295      ENDIF
296
297      IF( ln_sdw ) THEN   ! Find out how many fields have to be read from file if not coupled
298         jpfld=0
299         jp_usd=0   ;   jp_vsd=0   ;   jp_hsw=0   ;   jp_wmp=0
300         IF( .NOT. cpl_sdrftx ) THEN
301            jpfld  = jpfld + 1
302            jp_usd = jpfld
303         ENDIF
304         IF( .NOT. cpl_sdrfty ) THEN
305            jpfld  = jpfld + 1
306            jp_vsd = jpfld
307         ENDIF
308         IF( .NOT. cpl_hsig ) THEN
309            jpfld  = jpfld + 1
310            jp_hsw = jpfld
311         ENDIF
312         IF( .NOT. cpl_wper ) THEN
313            jpfld  = jpfld + 1
314            jp_wmp = jpfld
315         ENDIF
316
317         ! Read from file only the non-coupled fields
318         IF( jpfld > 0 ) THEN
319            ALLOCATE( slf_i(jpfld) )
320            IF( jp_usd > 0 )   slf_i(jp_usd) = sn_usd
321            IF( jp_vsd > 0 )   slf_i(jp_vsd) = sn_vsd
322            IF( jp_hsw > 0 )   slf_i(jp_hsw) = sn_hsw
323            IF( jp_wmp > 0 )   slf_i(jp_wmp) = sn_wmp
324            ALLOCATE( sf_sd(jpfld), STAT=ierror )   !* allocate and fill sf_sd with stokes drift
325            IF( ierror > 0 )   CALL ctl_stop( 'STOP', 'sbc_wave_init: unable to allocate sf_wave structure' )
326            !
327            DO ifpr= 1, jpfld
328               ALLOCATE( sf_sd(ifpr)%fnow(jpi,jpj,1) )
329               IF( slf_i(ifpr)%ln_tint )   ALLOCATE( sf_sd(ifpr)%fdta(jpi,jpj,1,2) )
330            END DO
331            !
332            CALL fld_fill( sf_sd, slf_i, cn_dir, 'sbc_wave_init', 'Wave module ', 'namsbc_wave' )
333         ENDIF
334         ALLOCATE( usd  (jpi,jpj,jpk), vsd  (jpi,jpj,jpk), wsd(jpi,jpj,jpk) )
335         ALLOCATE( hsw  (jpi,jpj)    , wmp  (jpi,jpj)     )
336         ALLOCATE( ut0sd(jpi,jpj)    , vt0sd(jpi,jpj)     )
337         ALLOCATE( div_sd(jpi,jpj) )
338         ALLOCATE( tsd2d (jpi,jpj) )
339         usd(:,:,:) = 0._wp
340         vsd(:,:,:) = 0._wp
341         wsd(:,:,:) = 0._wp
342         ! Wave number needed only if ln_zdfqiao=T
343         IF( .NOT. cpl_wnum ) THEN
344            ALLOCATE( sf_wn(1), STAT=ierror )           !* allocate and fill sf_wave with sn_wnum
345            IF( ierror > 0 )   CALL ctl_stop( 'STOP', 'sbc_wave_init: unable toallocate sf_wave structure' )
346                                   ALLOCATE( sf_wn(1)%fnow(jpi,jpj,1)   )
347            IF( sn_wnum%ln_tint )  ALLOCATE( sf_wn(1)%fdta(jpi,jpj,1,2) )
348            CALL fld_fill( sf_wn, (/ sn_wnum /), cn_dir, 'sbc_wave', 'Wave module', 'namsbc_wave' )
349         ENDIF
350         ALLOCATE( wnum(jpi,jpj) )
351      ENDIF
352      !
353   END SUBROUTINE sbc_wave_init
354
355   !!======================================================================
356END MODULE sbcwave
Note: See TracBrowser for help on using the repository browser.