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.
usrdef_zgr.F90 in NEMO/branches/2021/dev_r14318_RK3_stage1_tsplit/tests/SEICHE/MY_SRC – NEMO

source: NEMO/branches/2021/dev_r14318_RK3_stage1_tsplit/tests/SEICHE/MY_SRC/usrdef_zgr.F90 @ 14597

Last change on this file since 14597 was 14597, checked in by jchanut, 3 years ago

#2634: Implement Marsaleix (2008) and Demange (2019) test case (an external SEICHE over a 2DV stratified ocean and a seamount). One can optionnaly retrieve a standard external or 2 layer internal Seiche with a flat bottom.

File size: 12.4 KB
Line 
1MODULE usrdef_zgr
2   !!======================================================================
3   !!                     ***  MODULE usrdef_zgr  ***
4   !!
5   !!                       ===  SEICHE case  ===
6   !!
7   !! user defined :  vertical coordinate system of a user configuration
8   !!======================================================================
9   !! History :  4.0  ! 2016-08  (G. Madec, S. Flavoni)  Original code
10   !!                 ! 2021-01  (J. Chanut)  SEICHE test case
11   !!----------------------------------------------------------------------
12
13   !!----------------------------------------------------------------------
14   !!   usr_def_zgr   : user defined vertical coordinate system (required)
15   !!       zgr_z1d   : reference 1D z-coordinate
16   !!---------------------------------------------------------------------
17   USE oce            ! ocean variables
18   USE dom_oce ,  ONLY: mi0, mi1   ! ocean space and time domain
19   USE dom_oce ,  ONLY: glamt      ! ocean space and time domain
20   USE usrdef_nam     ! User defined : namelist variables
21   !
22   USE in_out_manager ! I/O manager
23   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
24   USE lib_mpp        ! distributed memory computing library
25   USE timing         ! Timing
26
27   IMPLICIT NONE
28   PRIVATE
29
30   PUBLIC   usr_def_zgr   ! called by domzgr.F90
31
32   !! * Substitutions
33#  include "do_loop_substitute.h90"
34   !!----------------------------------------------------------------------
35   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
36   !! $Id: usrdef_zgr.F90 14053 2020-12-03 13:48:38Z techene $
37   !! Software governed by the CeCILL license (see ./LICENSE)
38   !!----------------------------------------------------------------------
39CONTAINS             
40
41   SUBROUTINE usr_def_zgr( ld_zco  , ld_zps  , ld_sco  , ld_isfcav,    &   ! type of vertical coordinate
42      &                    pdept_1d, pdepw_1d, pe3t_1d , pe3w_1d  ,    &   ! 1D reference vertical coordinate
43      &                    pdept , pdepw ,                             &   ! 3D t & w-points depth
44      &                    pe3t  , pe3u  , pe3v , pe3f ,               &   ! vertical scale factors
45      &                    pe3w  , pe3uw , pe3vw,                      &   !     -      -      -
46      &                    k_top  , k_bot    )                             ! top & bottom ocean level
47      !!---------------------------------------------------------------------
48      !!              ***  ROUTINE usr_def_zgr  ***
49      !!
50      !! ** Purpose :   User defined the vertical coordinates
51      !!
52      !!----------------------------------------------------------------------
53      LOGICAL                   , INTENT(in   ) ::   ld_zco, ld_zps, ld_sco      ! vertical coordinate flags ( read in namusr_def )
54      LOGICAL                   , INTENT(  out) ::   ld_isfcav                   ! under iceshelf cavity flag
55      REAL(wp), DIMENSION(:)    , INTENT(  out) ::   pdept_1d, pdepw_1d          ! 1D grid-point depth     [m]
56      REAL(wp), DIMENSION(:)    , INTENT(  out) ::   pe3t_1d , pe3w_1d           ! 1D grid-point depth     [m]
57      REAL(wp), DIMENSION(:,:,:), INTENT(  out) ::   pdept, pdepw                ! grid-point depth        [m]
58      REAL(wp), DIMENSION(:,:,:), INTENT(  out) ::   pe3t , pe3u , pe3v , pe3f   ! vertical scale factors  [m]
59      REAL(wp), DIMENSION(:,:,:), INTENT(  out) ::   pe3w , pe3uw, pe3vw         ! i-scale factors
60      INTEGER , DIMENSION(:,:)  , INTENT(  out) ::   k_top, k_bot                ! first & last ocean level
61      !
62      INTEGER  ::   ji, jj, jk        ! dummy indices
63      INTEGER  ::   ik                ! local integers
64      REAL(wp) ::   zfact, z1_jpkm1   ! local scalar
65      REAL(wp) ::   ze3min            ! local scalar
66      REAL(wp), DIMENSION(jpi,jpj) ::   zht, zhu, z2d   ! 2D workspace
67      !!----------------------------------------------------------------------
68      !
69      IF(lwp) WRITE(numout,*)
70      IF(lwp) WRITE(numout,*) 'usr_def_zgr : SEICHE configuration (z(ps)- or s-coordinate closed box ocean without cavities)'
71      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
72      !
73      !
74      ! type of vertical coordinate
75      ! ---------------------------
76      ! already set in usrdef_nam.F90 by reading the namusr_def namelist except for ISF
77      ld_isfcav = .FALSE.
78      !
79      !
80      ! Build the vertical coordinate system
81      ! ------------------------------------
82      !
83      !                       !==  UNmasked meter bathymetry  ==!
84      !
85      zht(:,:) = rn_H 
86      zhu(:,:) = rn_H 
87      !
88      IF ( ln_bump ) THEN
89         zht(:,:) = rn_H - rn_hbump*EXP(-(glamt(:,:)/15._wp)**2)
90      ENDIF
91      !
92      ! at u-point: averaging zht
93      DO ji = 1, jpim1
94         zhu(ji,:) = 0.5_wp * ( zht(ji,:) + zht(ji+1,:) )
95      END DO
96      CALL lbc_lnk( 'usrdef_zgr', zhu, 'U', 1.0_wp ) 
97      WHERE ( zhu(:,:)==0._wp ) zhu(:,:) = rn_H
98      !     
99      CALL zgr_z1d( pdept_1d, pdepw_1d, pe3t_1d , pe3w_1d )   ! Reference z-coordinate system
100      !
101      !
102      !                       !==  top masked level bathymetry  ==!  (all coordinates)
103      !
104      ! no ocean cavities : top ocean level is ONE, except over land
105      ! the ocean basin surrounded by land (1 grid-point) set through lbc_lnk call as jperio=0
106      z2d(:,:) = 1._wp                    ! surface ocean is the 1st level
107      CALL lbc_lnk( 'usrdef_zgr', z2d, 'T', 1. )        ! closed basin since jperio = 0 (see userdef_nam.F90)
108      k_top(:,:) = NINT( z2d(:,:) )
109      !
110      !                             
111      !
112      IF ( ld_sco ) THEN      !==  s-coordinate  ==!   (terrain-following coordinate)
113         !
114         k_bot(:,:) = jpkm1 * k_top(:,:)  !* bottom ocean = jpk-1 (here use k_top as a land mask)
115         !
116         !                                !* terrain-following coordinate with e3.(k)=cst)
117         !                                !  SEICHE case : identical with j-index (T=V, U=F)
118         z1_jpkm1 = 1._wp / REAL( jpkm1 , wp)
119         DO jk = 1, jpk
120            pdept(:,:,jk) = zht(:,:) * z1_jpkm1 * ( REAL( jk   , wp ) - 0.5_wp )
121            pdepw(:,:,jk) = zht(:,:) * z1_jpkm1 * ( REAL( jk-1 , wp )          )
122            pe3t (:,:,jk) = zht(:,:) * z1_jpkm1
123            pe3u (:,:,jk) = zhu(:,:) * z1_jpkm1
124            pe3v (:,:,jk) = zht(:,:) * z1_jpkm1
125            pe3f (:,:,jk) = zhu(:,:) * z1_jpkm1
126            pe3w (:,:,jk) = zht(:,:) * z1_jpkm1
127            pe3uw(:,:,jk) = zhu(:,:) * z1_jpkm1
128            pe3vw(:,:,jk) = zht(:,:) * z1_jpkm1
129         END DO     
130      ENDIF
131      !
132      !
133      IF ( ld_zco ) THEN      !==  z-coordinate  ==!   (step-like topography)
134         !
135         !                                !* bottom ocean compute from the depth of grid-points
136         k_bot(:,:) = jpkm1 * k_top(:,:)     ! here use k_top as a land mask
137         DO jk = 1, jpkm1
138            WHERE( pdept_1d(jk) < zht(:,:) .AND. zht(:,:) <= pdept_1d(jk+1) )   k_bot(:,:) = jk * k_top(:,:)
139         END DO
140         !                                !* horizontally uniform coordinate (reference z-co everywhere)
141         DO jk = 1, jpk
142            pdept(:,:,jk) = pdept_1d(jk)
143            pdepw(:,:,jk) = pdepw_1d(jk)
144            pe3t (:,:,jk) = pe3t_1d (jk)
145            pe3u (:,:,jk) = pe3t_1d (jk)
146            pe3v (:,:,jk) = pe3t_1d (jk)
147            pe3f (:,:,jk) = pe3t_1d (jk)
148            pe3w (:,:,jk) = pe3w_1d (jk)
149            pe3uw(:,:,jk) = pe3w_1d (jk)
150            pe3vw(:,:,jk) = pe3w_1d (jk)
151         END DO
152      ENDIF
153      !
154      !
155      IF ( ld_zps ) THEN      !==  zps-coordinate  ==!   (partial bottom-steps)
156         !
157         ze3min = 0.1_wp * rn_dz
158         IF(lwp) WRITE(numout,*) '   minimum thickness of the partial cells = 10 % of e3 = ', ze3min
159         !
160         !
161         !                                !* bottom ocean compute from the depth of grid-points
162         k_bot(:,:) = jpkm1
163         DO jk = jpkm1, 1, -1
164            WHERE( zht(:,:) < pdepw_1d(jk) + ze3min )   k_bot(:,:) = jk-1
165         END DO
166         !
167         !                                !* vertical coordinate system
168         DO jk = 1, jpk                      ! initialization to the reference z-coordinate
169            pdept(:,:,jk) = pdept_1d(jk)
170            pdepw(:,:,jk) = pdepw_1d(jk)
171            pe3t (:,:,jk) = pe3t_1d (jk)
172            pe3u (:,:,jk) = pe3t_1d (jk)
173            pe3v (:,:,jk) = pe3t_1d (jk)
174            pe3f (:,:,jk) = pe3t_1d (jk)
175            pe3w (:,:,jk) = pe3w_1d (jk)
176            pe3uw(:,:,jk) = pe3w_1d (jk)
177            pe3vw(:,:,jk) = pe3w_1d (jk)
178         END DO
179         DO_2D( 1, 1, 1, 1 )
180            ik = k_bot(ji,jj)
181            pdepw(ji,jj,ik+1) = MIN( zht(ji,jj) , pdepw_1d(ik+1) )
182            pe3t (ji,jj,ik  ) = pdepw(ji,jj,ik+1) - pdepw(ji,jj,ik)
183            pe3t (ji,jj,ik+1) = pe3t (ji,jj,ik  ) 
184            !
185            pdept(ji,jj,ik  ) = pdepw(ji,jj,ik  ) + pe3t (ji,jj,ik  ) * 0.5_wp
186            pdept(ji,jj,ik+1) = pdepw(ji,jj,ik+1) + pe3t (ji,jj,ik+1) * 0.5_wp
187            pe3w (ji,jj,ik+1) = pdept(ji,jj,ik+1) - pdept(ji,jj,ik)              ! = pe3t (ji,jj,ik  )
188            pe3w (ji,jj,ik  ) = pdept(ji,jj,ik  ) - pdept(ji,jj,ik-1)            ! st caution ik > 1
189         END_2D         
190         !                                   ! bottom scale factors and depth at  U-, V-, UW and VW-points
191         !                                   ! usually Computed as the minimum of neighbooring scale factors
192         pe3u (:,:,:) = pe3t(:,:,:)          ! HERE SEICHE configuration :
193         pe3v (:,:,:) = pe3t(:,:,:)          !    e3 increases with i-index and identical with j-index
194         pe3f (:,:,:) = pe3t(:,:,:)          !    so e3 minimum of (i,i+1) points is (i) point
195         pe3uw(:,:,:) = pe3w(:,:,:)          !    in j-direction e3v=e3t and e3f=e3v
196         pe3vw(:,:,:) = pe3w(:,:,:)          !    ==>>  no need of lbc_lnk calls
197         !     
198      ENDIF
199      !
200   END SUBROUTINE usr_def_zgr
201
202
203   SUBROUTINE zgr_z1d( pdept_1d, pdepw_1d, pe3t_1d , pe3w_1d )   ! 1D reference vertical coordinate
204      !!----------------------------------------------------------------------
205      !!                   ***  ROUTINE zgr_z1d  ***
206      !!
207      !! ** Purpose :   set the depth of model levels and the resulting
208      !!      vertical scale factors.
209      !!
210      !! ** Method  :   1D z-coordinate system (use in all type of coordinate)
211      !!       The depth of model levels is set from dep(k), an analytical function:
212      !!                   w-level: depw_1d  = dep(k)
213      !!                   t-level: dept_1d  = dep(k+0.5)
214      !!       The scale factors are the discrete derivative of the depth:
215      !!                   e3w_1d(jk) = dk[ dept_1d ]
216      !!                   e3t_1d(jk) = dk[ depw_1d ]
217      !!
218      !!            ===    Here constant vertical resolution   ===
219      !!
220      !! ** Action  : - pdept_1d, pdepw_1d : depth of T- and W-point (m)
221      !!              - pe3t_1d , pe3w_1d  : scale factors at T- and W-levels (m)
222      !!----------------------------------------------------------------------
223      REAL(wp), DIMENSION(:), INTENT(out) ::   pdept_1d, pdepw_1d   ! 1D grid-point depth        [m]
224      REAL(wp), DIMENSION(:), INTENT(out) ::   pe3t_1d , pe3w_1d    ! 1D vertical scale factors  [m]
225      !
226      INTEGER  ::   jk       ! dummy loop indices
227      REAL(wp) ::   zt, zw   ! local scalar
228      !!----------------------------------------------------------------------
229      !
230      IF(lwp) THEN                         ! Parameter print
231         WRITE(numout,*)
232         WRITE(numout,*) '    zgr_z1d : Reference vertical z-coordinates: uniform dz = ', rn_dz
233         WRITE(numout,*) '    ~~~~~~~'
234      ENDIF
235      !
236      ! Reference z-coordinate (depth - scale factor at T- and W-points)   ! Madec & Imbard 1996 function
237      ! ----------------------
238      DO jk = 1, jpk
239         zw = REAL( jk , wp )
240         zt = REAL( jk , wp ) + 0.5_wp
241         pdepw_1d(jk) =    rn_dz *   REAL( jk-1 , wp )
242         pdept_1d(jk) =    rn_dz * ( REAL( jk-1 , wp ) + 0.5_wp )
243         pe3w_1d (jk) =    rn_dz
244         pe3t_1d (jk) =    rn_dz
245      END DO
246      !
247      IF(lwp) THEN                        ! control print
248         WRITE(numout,*)
249         WRITE(numout,*) '              Reference 1D z-coordinate depth and scale factors:'
250         WRITE(numout, "(9x,' level  gdept_1d  gdepw_1d  e3t_1d   e3w_1d  ')" )
251         WRITE(numout, "(10x, i4, 4f9.2)" ) ( jk, pdept_1d(jk), pdepw_1d(jk), pe3t_1d(jk), pe3w_1d(jk), jk = 1, jpk )
252      ENDIF
253      !
254   END SUBROUTINE zgr_z1d
255   
256   !!======================================================================
257END MODULE usrdef_zgr
Note: See TracBrowser for help on using the repository browser.