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

Last change on this file since 10491 was 10491, checked in by mathiot, 5 years ago

Minor changes in isf load computation to fit change in DOMAINcfg

  • Property svn:keywords set to Id
File size: 12.5 KB
RevLine 
[7715]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   !!----------------------------------------------------------------------
[10073]35   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
[7715]36   !! $Id$
[10073]37   !! Software governed by the CeCILL license (see ./LICENSE)
[7715]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      !!----------------------------------------------------------------------
[9135]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
[7715]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      ! ---------------------------
[8018]80      ! set in usrdef_nam.F90 by reading the namusr_def namelist except for ISF
81      ld_isfcav = .TRUE.       ! ISF Ice Shelves Flag
[7715]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
[10425]91      CALL lbc_lnk( 'usrdef_zgr', z2d, 'T', 1. )        ! closed basin since jperio = 0 (see userdef_nam.F90)
[7715]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      !
[9135]107      IF ( ld_zps ) THEN      !==  zps-coordinate  ==!   (partial bottom-steps)
[7715]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)
[10491]152                  pe3w (ji,jj,ik-1) = pdept(ji,jj,ik-1) - pdept(ji,jj,ik-2)
[7715]153               END IF
154            END DO
155         END DO         
156         DO jj = 1, jpj                      ! bottom scale factors and depth at T- and W-points
157            DO ji = 1, jpi
158               ik = k_bot(ji,jj)
159               pdepw(ji,jj,ik+1) = MIN( zht(ji,jj) , pdepw_1d(ik+1) )
160               pe3t (ji,jj,ik  ) = pdepw(ji,jj,ik+1) - pdepw(ji,jj,ik)
161               pe3t (ji,jj,ik+1) = pe3t (ji,jj,ik  ) 
162               !
163               pdept(ji,jj,ik  ) = pdepw(ji,jj,ik  ) + pe3t (ji,jj,ik  ) * 0.5_wp
164               pdept(ji,jj,ik+1) = pdepw(ji,jj,ik+1) + pe3t (ji,jj,ik+1) * 0.5_wp
165               pe3w (ji,jj,ik+1) = pdept(ji,jj,ik+1) - pdept(ji,jj,ik)
166            END DO
167         END DO         
168         !                                   ! bottom scale factors and depth at  U-, V-, UW and VW-points
[9089]169         pe3u (:,:,:) = pe3t(:,:,:)
170         pe3uw(:,:,:) = pe3w(:,:,:)
171         DO jk = 1, jpk                      ! Computed as the minimum of neighbooring scale factors
[7715]172            DO jj = 1, jpjm1
[9089]173               DO ji = 1, jpi
[7715]174                  pe3v (ji,jj,jk) = MIN( pe3t(ji,jj,jk), pe3t(ji,jj+1,jk) )
175                  pe3vw(ji,jj,jk) = MIN( pe3w(ji,jj,jk), pe3w(ji,jj+1,jk) )
[9089]176                  pe3f (ji,jj,jk) = pe3v(ji,jj,jk)
[7715]177               END DO
178            END DO
179         END DO
[10425]180         CALL lbc_lnk( 'usrdef_zgr', pe3v , 'V', 1._wp )   ;   CALL lbc_lnk( 'usrdef_zgr', pe3vw, 'V', 1._wp )
181         CALL lbc_lnk( 'usrdef_zgr', pe3f , 'F', 1._wp )
[9089]182         DO jk = 1, jpk
[7715]183            ! set to z-scale factor if zero (i.e. along closed boundaries) because of lbclnk
184            WHERE( pe3u (:,:,jk) == 0._wp )   pe3u (:,:,jk) = pe3t_1d(jk)
185            WHERE( pe3v (:,:,jk) == 0._wp )   pe3v (:,:,jk) = pe3t_1d(jk)
[9089]186            WHERE( pe3f (:,:,jk) == 0._wp )   pe3f (:,:,jk) = pe3t_1d(jk)
[7715]187            WHERE( pe3uw(:,:,jk) == 0._wp )   pe3uw(:,:,jk) = pe3w_1d(jk)
188            WHERE( pe3vw(:,:,jk) == 0._wp )   pe3vw(:,:,jk) = pe3w_1d(jk)
189         END DO
190         !
191      ENDIF
192      !
193   END SUBROUTINE usr_def_zgr
194
195
196   SUBROUTINE zgr_z1d( pdept_1d, pdepw_1d, pe3t_1d , pe3w_1d )   ! 1D reference vertical coordinate
197      !!----------------------------------------------------------------------
198      !!                   ***  ROUTINE zgr_z1d  ***
199      !!
200      !! ** Purpose :   set the depth of model levels and the resulting
201      !!      vertical scale factors.
202      !!
203      !! ** Method  :   1D z-coordinate system (use in all type of coordinate)
204      !!       The depth of model levels is set from dep(k), an analytical function:
205      !!                   w-level: depw_1d  = dep(k)
206      !!                   t-level: dept_1d  = dep(k+0.5)
207      !!       The scale factors are the discrete derivative of the depth:
208      !!                   e3w_1d(jk) = dk[ dept_1d ]
209      !!                   e3t_1d(jk) = dk[ depw_1d ]
210      !!
211      !!            ===    Here constant vertical resolution   ===
212      !!
213      !! ** Action  : - pdept_1d, pdepw_1d : depth of T- and W-point (m)
214      !!              - pe3t_1d , pe3w_1d  : scale factors at T- and W-levels (m)
215      !!----------------------------------------------------------------------
216      REAL(wp), DIMENSION(:), INTENT(out) ::   pdept_1d, pdepw_1d   ! 1D grid-point depth        [m]
217      REAL(wp), DIMENSION(:), INTENT(out) ::   pe3t_1d , pe3w_1d    ! 1D vertical scale factors  [m]
218      !
219      INTEGER  ::   jk       ! dummy loop indices
220      REAL(wp) ::   zt, zw   ! local scalar
221      !!----------------------------------------------------------------------
222      !
223      IF(lwp) THEN                         ! Parameter print
224         WRITE(numout,*)
225         WRITE(numout,*) '    zgr_z1d : Reference vertical z-coordinates: uniform dz = ', rn_e3
226         WRITE(numout,*) '    ~~~~~~~'
227      ENDIF
228      !
229      ! Reference z-coordinate (depth - scale factor at T- and W-points)   ! Madec & Imbard 1996 function
230      ! ----------------------
231      DO jk = 1, jpk
232         zw = REAL( jk , wp )
233         zt = REAL( jk , wp ) + 0.5_wp
234         pdepw_1d(jk) =    rn_e3 *   REAL( jk-1 , wp )
235         pdept_1d(jk) =    rn_e3 * ( REAL( jk-1 , wp ) + 0.5_wp )
236         pe3w_1d (jk) =    rn_e3
237         pe3t_1d (jk) =    rn_e3
238      END DO
239      !
240      IF(lwp) THEN                        ! control print
241         WRITE(numout,*)
242         WRITE(numout,*) '              Reference 1D z-coordinate depth and scale factors:'
243         WRITE(numout, "(9x,' level  gdept_1d  gdepw_1d  e3t_1d   e3w_1d  ')" )
244         WRITE(numout, "(10x, i4, 4f9.2)" ) ( jk, pdept_1d(jk), pdepw_1d(jk), pe3t_1d(jk), pe3w_1d(jk), jk = 1, jpk )
245      ENDIF
246      !
247   END SUBROUTINE zgr_z1d
248   
249   !!======================================================================
250END MODULE usrdef_zgr
Note: See TracBrowser for help on using the repository browser.