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 @ 10074

Last change on this file since 10074 was 10074, checked in by nicolasmartin, 6 years ago

Fix previous commit with wrong svn:keywords property

  • Property svn:keywords set to Id
File size: 12.4 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 "vectopt_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( 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         DO jj = 1, jpj                      ! top scale factors and depth at T- and W-points
137            DO ji = 1, jpi
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               END IF
153            END DO
154         END DO         
155         DO jj = 1, jpj                      ! bottom scale factors and depth at T- and W-points
156            DO ji = 1, jpi
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 DO
166         END DO         
167         !                                   ! bottom scale factors and depth at  U-, V-, UW and VW-points
168         pe3u (:,:,:) = pe3t(:,:,:)
169         pe3uw(:,:,:) = pe3w(:,:,:)
170         DO jk = 1, jpk                      ! Computed as the minimum of neighbooring scale factors
171            DO jj = 1, jpjm1
172               DO ji = 1, jpi
173                  pe3v (ji,jj,jk) = MIN( pe3t(ji,jj,jk), pe3t(ji,jj+1,jk) )
174                  pe3vw(ji,jj,jk) = MIN( pe3w(ji,jj,jk), pe3w(ji,jj+1,jk) )
175                  pe3f (ji,jj,jk) = pe3v(ji,jj,jk)
176               END DO
177            END DO
178         END DO
179         CALL lbc_lnk( pe3v , 'V', 1._wp )   ;   CALL lbc_lnk( pe3vw, 'V', 1._wp )
180         CALL lbc_lnk( pe3f , 'F', 1._wp )
181         DO jk = 1, jpk
182            ! set to z-scale factor if zero (i.e. along closed boundaries) because of lbclnk
183            WHERE( pe3u (:,:,jk) == 0._wp )   pe3u (:,:,jk) = pe3t_1d(jk)
184            WHERE( pe3v (:,:,jk) == 0._wp )   pe3v (:,:,jk) = pe3t_1d(jk)
185            WHERE( pe3f (:,:,jk) == 0._wp )   pe3f (:,:,jk) = pe3t_1d(jk)
186            WHERE( pe3uw(:,:,jk) == 0._wp )   pe3uw(:,:,jk) = pe3w_1d(jk)
187            WHERE( pe3vw(:,:,jk) == 0._wp )   pe3vw(:,:,jk) = pe3w_1d(jk)
188         END DO
189         !
190      ENDIF
191      !
192   END SUBROUTINE usr_def_zgr
193
194
195   SUBROUTINE zgr_z1d( pdept_1d, pdepw_1d, pe3t_1d , pe3w_1d )   ! 1D reference vertical coordinate
196      !!----------------------------------------------------------------------
197      !!                   ***  ROUTINE zgr_z1d  ***
198      !!
199      !! ** Purpose :   set the depth of model levels and the resulting
200      !!      vertical scale factors.
201      !!
202      !! ** Method  :   1D z-coordinate system (use in all type of coordinate)
203      !!       The depth of model levels is set from dep(k), an analytical function:
204      !!                   w-level: depw_1d  = dep(k)
205      !!                   t-level: dept_1d  = dep(k+0.5)
206      !!       The scale factors are the discrete derivative of the depth:
207      !!                   e3w_1d(jk) = dk[ dept_1d ]
208      !!                   e3t_1d(jk) = dk[ depw_1d ]
209      !!
210      !!            ===    Here constant vertical resolution   ===
211      !!
212      !! ** Action  : - pdept_1d, pdepw_1d : depth of T- and W-point (m)
213      !!              - pe3t_1d , pe3w_1d  : scale factors at T- and W-levels (m)
214      !!----------------------------------------------------------------------
215      REAL(wp), DIMENSION(:), INTENT(out) ::   pdept_1d, pdepw_1d   ! 1D grid-point depth        [m]
216      REAL(wp), DIMENSION(:), INTENT(out) ::   pe3t_1d , pe3w_1d    ! 1D vertical scale factors  [m]
217      !
218      INTEGER  ::   jk       ! dummy loop indices
219      REAL(wp) ::   zt, zw   ! local scalar
220      !!----------------------------------------------------------------------
221      !
222      IF(lwp) THEN                         ! Parameter print
223         WRITE(numout,*)
224         WRITE(numout,*) '    zgr_z1d : Reference vertical z-coordinates: uniform dz = ', rn_e3
225         WRITE(numout,*) '    ~~~~~~~'
226      ENDIF
227      !
228      ! Reference z-coordinate (depth - scale factor at T- and W-points)   ! Madec & Imbard 1996 function
229      ! ----------------------
230      DO jk = 1, jpk
231         zw = REAL( jk , wp )
232         zt = REAL( jk , wp ) + 0.5_wp
233         pdepw_1d(jk) =    rn_e3 *   REAL( jk-1 , wp )
234         pdept_1d(jk) =    rn_e3 * ( REAL( jk-1 , wp ) + 0.5_wp )
235         pe3w_1d (jk) =    rn_e3
236         pe3t_1d (jk) =    rn_e3
237      END DO
238      !
239      IF(lwp) THEN                        ! control print
240         WRITE(numout,*)
241         WRITE(numout,*) '              Reference 1D z-coordinate depth and scale factors:'
242         WRITE(numout, "(9x,' level  gdept_1d  gdepw_1d  e3t_1d   e3w_1d  ')" )
243         WRITE(numout, "(10x, i4, 4f9.2)" ) ( jk, pdept_1d(jk), pdepw_1d(jk), pe3t_1d(jk), pe3w_1d(jk), jk = 1, jpk )
244      ENDIF
245      !
246   END SUBROUTINE zgr_z1d
247   
248   !!======================================================================
249END MODULE usrdef_zgr
Note: See TracBrowser for help on using the repository browser.