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/trunk/tests/ISOMIP/MY_SRC – NEMO

source: NEMO/trunk/tests/ISOMIP/MY_SRC/usrdef_zgr.F90 @ 12740

Last change on this file since 12740 was 12740, checked in by smasson, 4 years ago

trunk: update/debug of tests and C1D, see #2442

  • Property svn:keywords set to Id
File size: 12.2 KB
Line 
1MODULE usrdef_zgr
2   !!======================================================================
3   !!                     ***  MODULE usrdef_zgr  ***
4   !!
5   !!                       ===  ISOMIP 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   !!                 ! 2017-02  (P. Mathiot, S. Flavoni)  Adapt code to ISOMIP 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: mj0   , mj1   , nimpp , njmpp   ! ocean space and time domain
19   USE dom_oce ,  ONLY: glamt , gphit                   ! 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$
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  ::   ij0, ij1          ! dummy indices 
64      INTEGER  ::   ik                ! local integers
65      REAL(wp) ::   zfact, z1_jpkm1   ! local scalar
66      REAL(wp) ::   ze3min, zdepth    ! local scalar
67      REAL(wp), DIMENSION(jpi,jpj) ::   zht  , zhu         ! bottom depth
68      REAL(wp), DIMENSION(jpi,jpj) ::   zhisf, zhisfu      ! top depth
69      REAL(wp), DIMENSION(jpi,jpj) ::   zmsk 
70      REAL(wp), DIMENSION(jpi,jpj) ::   z2d                ! 2d workspace
71      !!----------------------------------------------------------------------
72      !
73      IF(lwp) WRITE(numout,*)
74      IF(lwp) WRITE(numout,*) 'usr_def_zgr : ISOMIP configuration (z(ps)- or s-coordinate closed box ocean without cavities)'
75      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
76      !
77      !
78      ! type of vertical coordinate
79      ! ---------------------------
80      ! set in usrdef_nam.F90 by reading the namusr_def namelist except for ISF
81      ld_isfcav = .TRUE.       ! ISF Ice Shelves Flag
82      !
83      !
84      ! Build the vertical coordinate system
85      ! ------------------------------------
86      !
87      !                       !==  isfdraft  ==!
88      !
89      ! the ocean basin surrounded by land (1 grid-point) set through lbc_lnk call as jperio=0
90      z2d(:,:) = 1._wp                    ! surface ocean is the 1st level
91      CALL lbc_lnk( 'usrdef_zgr', z2d, 'T', 1. )        ! closed basin since jperio = 0 (see userdef_nam.F90)
92      zmsk(:,:) = NINT( z2d(:,:) )
93      !
94      !
95      zht  (:,:) = rbathy 
96      zhisf(:,:) = 200._wp
97      ij0 = 1 ; ij1 = 40
98      DO jj = mj0(ij0), mj1(ij1)
99         zhisf(:,jj)=700.0_wp-(gphit(:,jj)+80.0_wp)*125.0_wp
100      END DO
101      zhisf(:,:) = zhisf(:,:) * zmsk(:,:)
102      !
103      CALL zgr_z1d( pdept_1d, pdepw_1d, pe3t_1d , pe3w_1d )   ! Reference z-coordinate system
104      !
105      !                       !==  top masked level bathymetry  ==!  (all coordinates)
106      !
107      IF ( ld_zps ) THEN      !==  zps-coordinate  ==!   (partial bottom-steps)
108         !
109         ze3min = 0.1_wp * rn_e3
110         IF(lwp) WRITE(numout,*) '   minimum thickness of the partial cells = 10 % of e3 = ', ze3min
111         !
112         !                                !* bottom ocean compute from the depth of grid-points
113         k_bot(:,:) = jpkm1
114         DO jk = jpkm1, 1, -1
115            WHERE( zht(:,:) < pdepw_1d(jk) + ze3min )   k_bot(:,:) = jk-1
116         END DO
117         !                                !* top ocean compute from the depth of grid-points
118         k_top(:,:) = 1                   !
119         DO jk = 2, jpkm1
120            zdepth = pdepw_1d(jk+1) - ze3min
121            WHERE( zhisf(:,:) > 0.0 .AND. zhisf(:,:) >= zdepth )   k_top(:,:) = (jk + 1) 
122         END DO
123         !
124         !                                   !* vertical coordinate system
125         DO jk = 1, jpk                      ! initialization to the reference z-coordinate
126            pdept(:,:,jk) = pdept_1d(jk)
127            pdepw(:,:,jk) = pdepw_1d(jk)
128            pe3t (:,:,jk) = pe3t_1d (jk)
129            pe3u (:,:,jk) = pe3t_1d (jk)
130            pe3v (:,:,jk) = pe3t_1d (jk)
131            pe3f (:,:,jk) = pe3t_1d (jk)
132            pe3w (:,:,jk) = pe3w_1d (jk)
133            pe3uw(:,:,jk) = pe3w_1d (jk)
134            pe3vw(:,:,jk) = pe3w_1d (jk)
135         END DO
136         ! top scale factors and depth at T- and W-points
137         DO_2D_11_11
138            ik = k_top(ji,jj)
139            IF ( ik > 2 ) THEN
140               ! pdeptw at the interface
141               pdepw(ji,jj,ik  ) = MAX( zhisf(ji,jj) , pdepw(ji,jj,ik) )
142               ! e3t in both side of the interface
143               pe3t (ji,jj,ik  ) = pdepw(ji,jj,ik+1) - pdepw(ji,jj,ik)
144               ! pdept in both side of the interface (from previous e3t)
145               pdept(ji,jj,ik  ) = pdepw(ji,jj,ik  ) + pe3t (ji,jj,ik  ) * 0.5_wp
146               pdept(ji,jj,ik-1) = pdepw(ji,jj,ik  ) - pe3t (ji,jj,ik  ) * 0.5_wp
147               ! pe3w on both side of the interface
148               pe3w (ji,jj,ik+1) = pdept(ji,jj,ik+1) - pdept(ji,jj,ik  )
149               pe3w (ji,jj,ik  ) = pdept(ji,jj,ik  ) - pdept(ji,jj,ik-1)
150               ! e3t into the ice shelf
151               pe3t (ji,jj,ik-1) = pdepw(ji,jj,ik  ) - pdepw(ji,jj,ik-1)
152               pe3w (ji,jj,ik-1) = pdept(ji,jj,ik-1) - pdept(ji,jj,ik-2)
153            END IF
154         END_2D
155         ! bottom scale factors and depth at T- and W-points
156         DO_2D_11_11
157            ik = k_bot(ji,jj)
158            pdepw(ji,jj,ik+1) = MIN( zht(ji,jj) , pdepw_1d(ik+1) )
159            pe3t (ji,jj,ik  ) = pdepw(ji,jj,ik+1) - pdepw(ji,jj,ik)
160            pe3t (ji,jj,ik+1) = pe3t (ji,jj,ik  ) 
161            !
162            pdept(ji,jj,ik  ) = pdepw(ji,jj,ik  ) + pe3t (ji,jj,ik  ) * 0.5_wp
163            pdept(ji,jj,ik+1) = pdepw(ji,jj,ik+1) + pe3t (ji,jj,ik+1) * 0.5_wp
164            pe3w (ji,jj,ik+1) = pdept(ji,jj,ik+1) - pdept(ji,jj,ik)
165         END_2D       
166         !                                   ! bottom scale factors and depth at  U-, V-, UW and VW-points
167         pe3u (:,:,:) = pe3t(:,:,:)
168         pe3uw(:,:,:) = pe3w(:,:,:)
169         DO_3D_00_00( 1, jpk )
170         !                                   ! Computed as the minimum of neighbooring scale factors
171            pe3v (ji,jj,jk) = MIN( pe3t(ji,jj,jk), pe3t(ji,jj+1,jk) )
172            pe3vw(ji,jj,jk) = MIN( pe3w(ji,jj,jk), pe3w(ji,jj+1,jk) )
173            pe3f (ji,jj,jk) = pe3v(ji,jj,jk)
174         END_3D
175         CALL lbc_lnk( 'usrdef_zgr', pe3v , 'V', 1._wp )   ;   CALL lbc_lnk( 'usrdef_zgr', pe3vw, 'V', 1._wp )
176         CALL lbc_lnk( 'usrdef_zgr', pe3f , 'F', 1._wp )
177         DO jk = 1, jpk
178            ! set to z-scale factor if zero (i.e. along closed boundaries) because of lbclnk
179            WHERE( pe3u (:,:,jk) == 0._wp )   pe3u (:,:,jk) = pe3t_1d(jk)
180            WHERE( pe3v (:,:,jk) == 0._wp )   pe3v (:,:,jk) = pe3t_1d(jk)
181            WHERE( pe3f (:,:,jk) == 0._wp )   pe3f (:,:,jk) = pe3t_1d(jk)
182            WHERE( pe3uw(:,:,jk) == 0._wp )   pe3uw(:,:,jk) = pe3w_1d(jk)
183            WHERE( pe3vw(:,:,jk) == 0._wp )   pe3vw(:,:,jk) = pe3w_1d(jk)
184         END DO
185         !
186      ENDIF
187      !
188   END SUBROUTINE usr_def_zgr
189
190
191   SUBROUTINE zgr_z1d( pdept_1d, pdepw_1d, pe3t_1d , pe3w_1d )   ! 1D reference vertical coordinate
192      !!----------------------------------------------------------------------
193      !!                   ***  ROUTINE zgr_z1d  ***
194      !!
195      !! ** Purpose :   set the depth of model levels and the resulting
196      !!      vertical scale factors.
197      !!
198      !! ** Method  :   1D z-coordinate system (use in all type of coordinate)
199      !!       The depth of model levels is set from dep(k), an analytical function:
200      !!                   w-level: depw_1d  = dep(k)
201      !!                   t-level: dept_1d  = dep(k+0.5)
202      !!       The scale factors are the discrete derivative of the depth:
203      !!                   e3w_1d(jk) = dk[ dept_1d ]
204      !!                   e3t_1d(jk) = dk[ depw_1d ]
205      !!
206      !!            ===    Here constant vertical resolution   ===
207      !!
208      !! ** Action  : - pdept_1d, pdepw_1d : depth of T- and W-point (m)
209      !!              - pe3t_1d , pe3w_1d  : scale factors at T- and W-levels (m)
210      !!----------------------------------------------------------------------
211      REAL(wp), DIMENSION(:), INTENT(out) ::   pdept_1d, pdepw_1d   ! 1D grid-point depth        [m]
212      REAL(wp), DIMENSION(:), INTENT(out) ::   pe3t_1d , pe3w_1d    ! 1D vertical scale factors  [m]
213      !
214      INTEGER  ::   jk       ! dummy loop indices
215      REAL(wp) ::   zt, zw   ! local scalar
216      !!----------------------------------------------------------------------
217      !
218      IF(lwp) THEN                         ! Parameter print
219         WRITE(numout,*)
220         WRITE(numout,*) '    zgr_z1d : Reference vertical z-coordinates: uniform dz = ', rn_e3
221         WRITE(numout,*) '    ~~~~~~~'
222      ENDIF
223      !
224      ! Reference z-coordinate (depth - scale factor at T- and W-points)   ! Madec & Imbard 1996 function
225      ! ----------------------
226      DO jk = 1, jpk
227         zw = REAL( jk , wp )
228         zt = REAL( jk , wp ) + 0.5_wp
229         pdepw_1d(jk) =    rn_e3 *   REAL( jk-1 , wp )
230         pdept_1d(jk) =    rn_e3 * ( REAL( jk-1 , wp ) + 0.5_wp )
231         pe3w_1d (jk) =    rn_e3
232         pe3t_1d (jk) =    rn_e3
233      END DO
234      !
235      IF(lwp) THEN                        ! control print
236         WRITE(numout,*)
237         WRITE(numout,*) '              Reference 1D z-coordinate depth and scale factors:'
238         WRITE(numout, "(9x,' level  gdept_1d  gdepw_1d  e3t_1d   e3w_1d  ')" )
239         WRITE(numout, "(10x, i4, 4f9.2)" ) ( jk, pdept_1d(jk), pdepw_1d(jk), pe3t_1d(jk), pe3w_1d(jk), jk = 1, jpk )
240      ENDIF
241      !
242   END SUBROUTINE zgr_z1d
243   
244   !!======================================================================
245END MODULE usrdef_zgr
Note: See TracBrowser for help on using the repository browser.