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 branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/USR – NEMO

source: branches/2017/dev_merge_2017/NEMOGCM/NEMO/OPA_SRC/USR/usrdef_zgr.F90 @ 9124

Last change on this file since 9124 was 9124, checked in by gm, 6 years ago

dev_merge_2017: ln_timing instead of nn_timing + restricted timing to nemo_init and routine called by step in OPA_SRC

File size: 12.6 KB
Line 
1MODULE usrdef_zgr
2   !!======================================================================
3   !!                       ***  MODULE  usrdef_zgr  ***
4   !!
5   !!                       ===  GYRE configuration  ===
6   !!
7   !! User defined : vertical coordinate system of a user configuration
8   !!======================================================================
9   !! History :  4.0  ! 2016-06  (G. Madec)  Original code
10   !!----------------------------------------------------------------------
11
12   !!----------------------------------------------------------------------
13   !!   usr_def_zgr   : user defined vertical coordinate system
14   !!      zgr_z      : reference 1D z-coordinate
15   !!      zgr_top_bot: ocean top and bottom level indices
16   !!      zgr_zco    : 3D verticl coordinate in pure z-coordinate case
17   !!---------------------------------------------------------------------
18   USE oce            ! ocean variables
19   USE dom_oce        ! ocean domain
20   USE depth_e3       ! depth <=> e3
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 wrk_nemo       ! Memory allocation
26
27   IMPLICIT NONE
28   PRIVATE
29
30   PUBLIC   usr_def_zgr        ! called by domzgr.F90
31
32   !! * Substitutions
33#  include "vectopt_loop_substitute.h90"
34   !!----------------------------------------------------------------------
35   !! NEMO/OPA 4.0 , NEMO Consortium (2016)
36   !! $Id:$
37   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
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(out) ::   ld_zco, ld_zps, ld_sco      ! vertical coordinate flags
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  ::   inum   ! local logical unit
63      REAL(WP) ::   z_zco, z_zps, z_sco, z_cav
64      REAL(wp), DIMENSION(jpi,jpj) ::   z2d   ! 2D workspace
65      !!----------------------------------------------------------------------
66      !
67      IF(lwp) WRITE(numout,*)
68      IF(lwp) WRITE(numout,*) 'usr_def_zgr : GYRE configuration (z-coordinate closed flat box ocean without cavities)'
69      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
70      !
71      !
72      ! type of vertical coordinate
73      ! ---------------------------
74      ld_zco    = .TRUE.         ! GYRE case:  z-coordinate without ocean cavities
75      ld_zps    = .FALSE.
76      ld_sco    = .FALSE.
77      ld_isfcav = .FALSE.
78      !
79      !
80      ! Build the vertical coordinate system
81      ! ------------------------------------
82      CALL zgr_z( pdept_1d, pdepw_1d, pe3t_1d , pe3w_1d )   ! Reference z-coordinate system
83      !
84      CALL zgr_msk_top_bot( k_top , k_bot )                 ! masked top and bottom ocean t-level indices
85      !
86      !                                                     ! z-coordinate (3D arrays) from the 1D z-coord.
87      CALL zgr_zco( pdept_1d, pdepw_1d, pe3t_1d, pe3w_1d,   &   ! in  : 1D reference vertical coordinate
88         &          pdept   , pdepw   ,                     &   ! out : 3D t & w-points depth
89         &          pe3t    , pe3u    , pe3v   , pe3f   ,   &   !       vertical scale factors
90         &          pe3w    , pe3uw   , pe3vw             )     !           -      -      -
91      !
92   END SUBROUTINE usr_def_zgr
93
94
95   SUBROUTINE zgr_z( pdept_1d, pdepw_1d, pe3t_1d , pe3w_1d )   ! 1D reference vertical coordinate
96      !!----------------------------------------------------------------------
97      !!                   ***  ROUTINE zgr_z  ***
98      !!
99      !! ** Purpose :   set the 1D depth of model levels and the resulting
100      !!              vertical scale factors.
101      !!
102      !! ** Method  :   1D z-coordinate system (use in all type of coordinate)
103      !!       The depth of model levels is set from dep(k), an analytical function:
104      !!                   w-level: depw_1d  = dep(k)
105      !!                   t-level: dept_1d  = dep(k+0.5)
106      !!       The scale factors are the discrete derivative of the depth:
107      !!                   e3w_1d(jk) = dk[ dept_1d ]
108      !!                   e3t_1d(jk) = dk[ depw_1d ]
109      !!           with at top and bottom :
110      !!                   e3w_1d( 1 ) = 2 * ( dept_1d( 1 ) - depw_1d( 1 ) )
111      !!                   e3t_1d(jpk) = 2 * ( dept_1d(jpk) - depw_1d(jpk) )
112      !!       The depth are then re-computed from the sum of e3. This ensures
113      !!    that depths are identical when reading domain configuration file.
114      !!    Indeed, only e3. are saved in this file, depth are compute by a call
115      !!    to the e3_to_depth subroutine.
116      !!
117      !!       Here the Madec & Imbard (1996) function is used.
118      !!
119      !! ** Action  : - pdept_1d, pdepw_1d : depth of T- and W-point (m)
120      !!              - pe3t_1d , pe3w_1d  : scale factors at T- and W-levels (m)
121      !!
122      !! Reference : Marti, Madec & Delecluse, 1992, JGR, 97, No8, 12,763-12,766.
123      !!             Madec and Imbard, 1996, Clim. Dyn.
124      !!----------------------------------------------------------------------
125      REAL(wp), DIMENSION(:)    , INTENT(out) ::   pdept_1d, pdepw_1d   ! 1D grid-point depth        [m]
126      REAL(wp), DIMENSION(:)    , INTENT(out) ::   pe3t_1d , pe3w_1d    ! 1D vertical scale factors  [m]
127      !
128      INTEGER  ::   jk       ! dummy loop indices
129      REAL(wp) ::   zt, zw   ! local scalars
130      REAL(wp) ::   zsur, za0, za1, zkth, zacr   ! Values for the Madec & Imbard (1996) function 
131      !!----------------------------------------------------------------------
132      !
133      ! Set parameters of z(k) function
134      ! -------------------------------
135      zsur = -2033.194295283385_wp       
136      za0  =   155.8325369664153_wp 
137      za1  =   146.3615918601890_wp
138      zkth =    17.28520372419791_wp   
139      zacr =     5.0_wp       
140      !
141      IF(lwp) THEN            ! Parameter print
142         WRITE(numout,*)
143         WRITE(numout,*) '    zgr_z   : Reference vertical z-coordinates '
144         WRITE(numout,*) '    ~~~~~~~'
145         WRITE(numout,*) '       GYRE case : MI96 function with the following coefficients :'
146         WRITE(numout,*) '                 zsur = ', zsur
147         WRITE(numout,*) '                 za0  = ', za0
148         WRITE(numout,*) '                 za1  = ', za1
149         WRITE(numout,*) '                 zkth = ', zkth
150         WRITE(numout,*) '                 zacr = ', zacr
151      ENDIF
152
153      !
154      ! 1D Reference z-coordinate    (using Madec & Imbard 1996 function)
155      ! -------------------------
156      !
157      DO jk = 1, jpk          ! depth at T and W-points
158         zw = REAL( jk , wp )
159         zt = REAL( jk , wp ) + 0.5_wp
160         pdepw_1d(jk) = ( zsur + za0 * zw + za1 * zacr *  LOG( COSH( (zw-zkth) / zacr ) )  )
161         pdept_1d(jk) = ( zsur + za0 * zt + za1 * zacr *  LOG( COSH( (zt-zkth) / zacr ) )  )
162      END DO
163      !
164      !                       ! e3t and e3w from depth
165      CALL depth_to_e3( pdept_1d, pdepw_1d, pe3t_1d, pe3w_1d ) 
166      !
167      !                       ! recompute depths from SUM(e3)  <== needed
168      CALL e3_to_depth( pe3t_1d, pe3w_1d, pdept_1d, pdepw_1d ) 
169      !
170      IF(lwp) THEN                        ! control print
171         WRITE(numout,*)
172         WRITE(numout,*) '              Reference 1D z-coordinate depth and scale factors:'
173         WRITE(numout, "(9x,' level  gdept_1d  gdepw_1d  e3t_1d   e3w_1d  ')" )
174         WRITE(numout, "(10x, i4, 4f9.2)" ) ( jk, pdept_1d(jk), pdepw_1d(jk), pe3t_1d(jk), pe3w_1d(jk), jk = 1, jpk )
175      ENDIF
176      !
177   END SUBROUTINE zgr_z
178
179
180   SUBROUTINE zgr_msk_top_bot( k_top , k_bot )
181      !!----------------------------------------------------------------------
182      !!                    ***  ROUTINE zgr_msk_top_bot  ***
183      !!
184      !! ** Purpose :   set the masked top and bottom ocean t-levels
185      !!
186      !! ** Method  :   GYRE case = closed flat box ocean without ocean cavities
187      !!                   k_top = 1     except along north, south, east and west boundaries
188      !!                   k_bot = jpk-1 except along north, south, east and west boundaries
189      !!
190      !! ** Action  : - k_top : first wet ocean level index
191      !!              - k_bot : last  wet ocean level index
192      !!----------------------------------------------------------------------
193      INTEGER , DIMENSION(:,:), INTENT(out) ::   k_top , k_bot   ! first & last wet ocean level
194      !
195      REAL(wp), DIMENSION(jpi,jpj) ::   z2d   ! 2D local workspace
196      !!----------------------------------------------------------------------
197      !
198      IF(lwp) WRITE(numout,*)
199      IF(lwp) WRITE(numout,*) '    zgr_top_bot : defines the top and bottom wet ocean levels.'
200      IF(lwp) WRITE(numout,*) '    ~~~~~~~~~~~'
201      IF(lwp) WRITE(numout,*) '       GYRE case : closed flat box ocean without ocean cavities'
202      !
203      z2d(:,:) = REAL( jpkm1 , wp )          ! flat bottom
204      !
205      CALL lbc_lnk( z2d, 'T', 1. )           ! set surrounding land to zero (here jperio=0 ==>> closed)
206      !
207      k_bot(:,:) = INT( z2d(:,:) )           ! =jpkm1 over the ocean point, =0 elsewhere
208      !
209      k_top(:,:) = MIN( 1 , k_bot(:,:) )     ! = 1    over the ocean point, =0 elsewhere
210      !
211   END SUBROUTINE zgr_msk_top_bot
212   
213
214   SUBROUTINE zgr_zco( pdept_1d, pdepw_1d, pe3t_1d, pe3w_1d,   &   ! in : 1D reference vertical coordinate
215      &                pdept   , pdepw   ,                     &   ! out: 3D t & w-points depth
216      &                pe3t    , pe3u    , pe3v   , pe3f   ,   &   !      vertical scale factors
217      &                pe3w    , pe3uw   , pe3vw             )     !          -      -      -
218      !!----------------------------------------------------------------------
219      !!                  ***  ROUTINE zgr_zco  ***
220      !!
221      !! ** Purpose :   define the reference z-coordinate system
222      !!
223      !! ** Method  :   set 3D coord. arrays to reference 1D array
224      !!----------------------------------------------------------------------
225      REAL(wp), DIMENSION(:)    , INTENT(in   ) ::   pdept_1d, pdepw_1d          ! 1D grid-point depth       [m]
226      REAL(wp), DIMENSION(:)    , INTENT(in   ) ::   pe3t_1d , pe3w_1d           ! 1D vertical scale factors [m]
227      REAL(wp), DIMENSION(:,:,:), INTENT(  out) ::   pdept, pdepw                ! grid-point depth          [m]
228      REAL(wp), DIMENSION(:,:,:), INTENT(  out) ::   pe3t , pe3u , pe3v , pe3f   ! vertical scale factors    [m]
229      REAL(wp), DIMENSION(:,:,:), INTENT(  out) ::   pe3w , pe3uw, pe3vw         !    -       -      -
230      !
231      INTEGER  ::   jk
232      !!----------------------------------------------------------------------
233      !
234      DO jk = 1, jpk
235         pdept(:,:,jk) = pdept_1d(jk)
236         pdepw(:,:,jk) = pdepw_1d(jk)
237         pe3t (:,:,jk) = pe3t_1d (jk)
238         pe3u (:,:,jk) = pe3t_1d (jk)
239         pe3v (:,:,jk) = pe3t_1d (jk)
240         pe3f (:,:,jk) = pe3t_1d (jk)
241         pe3w (:,:,jk) = pe3w_1d (jk)
242         pe3uw(:,:,jk) = pe3w_1d (jk)
243         pe3vw(:,:,jk) = pe3w_1d (jk)
244      END DO
245      !
246   END SUBROUTINE zgr_zco
247
248   !!======================================================================
249END MODULE usrdef_zgr
Note: See TracBrowser for help on using the repository browser.