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/CONFIG/TEST_CASES/ISOMIP/MY_SRC – NEMO

source: branches/2017/dev_merge_2017/NEMOGCM/CONFIG/TEST_CASES/ISOMIP/MY_SRC/usrdef_zgr.F90 @ 9125

Last change on this file since 9125 was 9125, checked in by timgraham, 6 years ago

Removed wrk_arrays from whole code. No change in SETTE results from this.

File size: 12.6 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: ln_zco, ln_zps, ln_sco          ! ocean space and time domain
19   USE dom_oce ,  ONLY: mj0   , mj1   , nimpp , njmpp   ! ocean space and time domain
20   USE dom_oce ,  ONLY: glamt , gphit                   ! ocean space and time domain
21   USE usrdef_nam     ! User defined : namelist variables
22   !
23   USE in_out_manager ! I/O manager
24   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
25   USE lib_mpp        ! distributed memory computing library
26   USE timing         ! Timing
27
28   IMPLICIT NONE
29   PRIVATE
30
31   PUBLIC   usr_def_zgr   ! called by domzgr.F90
32
33  !! * Substitutions
34#  include "vectopt_loop_substitute.h90"
35   !!----------------------------------------------------------------------
36   !! NEMO/OPA 4.0 , NEMO Consortium (2016)
37   !! $Id$
38   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
39   !!----------------------------------------------------------------------
40CONTAINS             
41
42   SUBROUTINE usr_def_zgr( ld_zco  , ld_zps  , ld_sco  , ld_isfcav,    &   ! type of vertical coordinate
43      &                    pdept_1d, pdepw_1d, pe3t_1d , pe3w_1d  ,    &   ! 1D reference vertical coordinate
44      &                    pdept , pdepw ,                             &   ! 3D t & w-points depth
45      &                    pe3t  , pe3u  , pe3v , pe3f ,               &   ! vertical scale factors
46      &                    pe3w  , pe3uw , pe3vw,                      &   !     -      -      -
47      &                    k_top  , k_bot    )                             ! top & bottom ocean level
48      !!---------------------------------------------------------------------
49      !!              ***  ROUTINE usr_def_zgr  ***
50      !!
51      !! ** Purpose :   User defined the vertical coordinates
52      !!
53      !!----------------------------------------------------------------------
54      LOGICAL                   , INTENT(out) ::   ld_zco, ld_zps, ld_sco      ! vertical coordinate flags
55      LOGICAL                   , INTENT(out) ::   ld_isfcav                   ! under iceshelf cavity flag
56      REAL(wp), DIMENSION(:)    , INTENT(out) ::   pdept_1d, pdepw_1d          ! 1D grid-point depth     [m]
57      REAL(wp), DIMENSION(:)    , INTENT(out) ::   pe3t_1d , pe3w_1d           ! 1D grid-point depth     [m]
58      REAL(wp), DIMENSION(:,:,:), INTENT(out) ::   pdept, pdepw                ! grid-point depth        [m]
59      REAL(wp), DIMENSION(:,:,:), INTENT(out) ::   pe3t , pe3u , pe3v , pe3f   ! vertical scale factors  [m]
60      REAL(wp), DIMENSION(:,:,:), INTENT(out) ::   pe3w , pe3uw, pe3vw         ! i-scale factors
61      INTEGER , DIMENSION(:,:)  , INTENT(out) ::   k_top, k_bot                ! first & last ocean level
62      !
63      INTEGER  ::   ji , jj, jk       ! dummy indices
64      INTEGER  ::   ij0, ij1          ! dummy indices 
65      INTEGER  ::   ik                ! local integers
66      REAL(wp) ::   zfact, z1_jpkm1   ! local scalar
67      REAL(wp) ::   ze3min, zdepth    ! local scalar
68      REAL(wp), DIMENSION(jpi,jpj) ::   zht  , zhu         ! bottom depth
69      REAL(wp), DIMENSION(jpi,jpj) ::   zhisf, zhisfu      ! top depth
70      REAL(wp), DIMENSION(jpi,jpj) ::   zmsk 
71      REAL(wp), DIMENSION(jpi,jpj) ::   z2d                ! 2d workspace
72      !!----------------------------------------------------------------------
73      !
74      IF(lwp) WRITE(numout,*)
75      IF(lwp) WRITE(numout,*) 'usr_def_zgr : ISOMIP configuration (z(ps)- or s-coordinate closed box ocean without cavities)'
76      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
77      !
78      !
79      ! type of vertical coordinate
80      ! ---------------------------
81      ! set in usrdef_nam.F90 by reading the namusr_def namelist except for ISF
82      ln_zco    = .FALSE.      ! z-partial-step coordinate
83      ln_zps    = .TRUE.       ! z-partial-step coordinate
84      ln_sco    = .FALSE.      ! s-coordinate
85      ld_isfcav = .TRUE.       ! ISF Ice Shelves Flag
86      !
87      !
88      ! Build the vertical coordinate system
89      ! ------------------------------------
90      !
91      !                       !==  isfdraft  ==!
92      !
93      ! the ocean basin surrounded by land (1 grid-point) set through lbc_lnk call as jperio=0
94      z2d(:,:) = 1._wp                    ! surface ocean is the 1st level
95      CALL lbc_lnk( z2d, 'T', 1. )        ! closed basin since jperio = 0 (see userdef_nam.F90)
96      zmsk(:,:) = NINT( z2d(:,:) )
97      !
98      !
99      zht  (:,:) = rbathy 
100      zhisf(:,:) = 200._wp
101      ij0 = 1 ; ij1 = 40
102      DO jj = mj0(ij0), mj1(ij1)
103         zhisf(:,jj)=700.0_wp-(gphit(:,jj)+80.0_wp)*125.0_wp
104      END DO
105      zhisf(:,:) = zhisf(:,:) * zmsk(:,:)
106      !
107      CALL zgr_z1d( pdept_1d, pdepw_1d, pe3t_1d , pe3w_1d )   ! Reference z-coordinate system
108      !
109      !                       !==  top masked level bathymetry  ==!  (all coordinates)
110      !
111      IF ( ln_zps ) THEN      !==  zps-coordinate  ==!   (partial bottom-steps)
112         !
113         ze3min = 0.1_wp * rn_e3
114         IF(lwp) WRITE(numout,*) '   minimum thickness of the partial cells = 10 % of e3 = ', ze3min
115         !
116         !                                !* bottom ocean compute from the depth of grid-points
117         k_bot(:,:) = jpkm1
118         DO jk = jpkm1, 1, -1
119            WHERE( zht(:,:) < pdepw_1d(jk) + ze3min )   k_bot(:,:) = jk-1
120         END DO
121         !                                !* top ocean compute from the depth of grid-points
122         k_top(:,:) = 1                   !
123         DO jk = 2, jpkm1
124            zdepth = pdepw_1d(jk+1) - ze3min
125            WHERE( zhisf(:,:) > 0.0 .AND. zhisf(:,:) >= zdepth )   k_top(:,:) = (jk + 1) 
126         END DO
127         !
128         !                                   !* vertical coordinate system
129         DO jk = 1, jpk                      ! initialization to the reference z-coordinate
130            pdept(:,:,jk) = pdept_1d(jk)
131            pdepw(:,:,jk) = pdepw_1d(jk)
132            pe3t (:,:,jk) = pe3t_1d (jk)
133            pe3u (:,:,jk) = pe3t_1d (jk)
134            pe3v (:,:,jk) = pe3t_1d (jk)
135            pe3f (:,:,jk) = pe3t_1d (jk)
136            pe3w (:,:,jk) = pe3w_1d (jk)
137            pe3uw(:,:,jk) = pe3w_1d (jk)
138            pe3vw(:,:,jk) = pe3w_1d (jk)
139         END DO
140         DO jj = 1, jpj                      ! top scale factors and depth at T- and W-points
141            DO ji = 1, jpi
142               ik = k_top(ji,jj)
143               IF ( ik > 2 ) THEN
144                  ! pdeptw at the interface
145                  pdepw(ji,jj,ik  ) = MAX( zhisf(ji,jj) , pdepw(ji,jj,ik) )
146                  ! e3t in both side of the interface
147                  pe3t (ji,jj,ik  ) = pdepw(ji,jj,ik+1) - pdepw(ji,jj,ik)
148                  ! pdept in both side of the interface (from previous e3t)
149                  pdept(ji,jj,ik  ) = pdepw(ji,jj,ik  ) + pe3t (ji,jj,ik  ) * 0.5_wp
150                  pdept(ji,jj,ik-1) = pdepw(ji,jj,ik  ) - pe3t (ji,jj,ik  ) * 0.5_wp
151                  ! pe3w on both side of the interface
152                  pe3w (ji,jj,ik+1) = pdept(ji,jj,ik+1) - pdept(ji,jj,ik  )
153                  pe3w (ji,jj,ik  ) = pdept(ji,jj,ik  ) - pdept(ji,jj,ik-1)
154                  ! e3t into the ice shelf
155                  pe3t (ji,jj,ik-1) = pdepw(ji,jj,ik  ) - pdepw(ji,jj,ik-1)
156               END IF
157            END DO
158         END DO         
159         DO jj = 1, jpj                      ! bottom scale factors and depth at T- and W-points
160            DO ji = 1, jpi
161               ik = k_bot(ji,jj)
162               pdepw(ji,jj,ik+1) = MIN( zht(ji,jj) , pdepw_1d(ik+1) )
163               pe3t (ji,jj,ik  ) = pdepw(ji,jj,ik+1) - pdepw(ji,jj,ik)
164               pe3t (ji,jj,ik+1) = pe3t (ji,jj,ik  ) 
165               !
166               pdept(ji,jj,ik  ) = pdepw(ji,jj,ik  ) + pe3t (ji,jj,ik  ) * 0.5_wp
167               pdept(ji,jj,ik+1) = pdepw(ji,jj,ik+1) + pe3t (ji,jj,ik+1) * 0.5_wp
168               pe3w (ji,jj,ik+1) = pdept(ji,jj,ik+1) - pdept(ji,jj,ik)
169            END DO
170         END DO         
171         !                                   ! bottom scale factors and depth at  U-, V-, UW and VW-points
172         pe3u (:,:,:) = pe3t(:,:,:)
173         pe3uw(:,:,:) = pe3w(:,:,:)
174         DO jk = 1, jpk                      ! Computed as the minimum of neighbooring scale factors
175            DO jj = 1, jpjm1
176               DO ji = 1, jpi
177                  pe3v (ji,jj,jk) = MIN( pe3t(ji,jj,jk), pe3t(ji,jj+1,jk) )
178                  pe3vw(ji,jj,jk) = MIN( pe3w(ji,jj,jk), pe3w(ji,jj+1,jk) )
179                  pe3f (ji,jj,jk) = pe3v(ji,jj,jk)
180               END DO
181            END DO
182         END DO
183         CALL lbc_lnk( pe3v , 'V', 1._wp )   ;   CALL lbc_lnk( pe3vw, 'V', 1._wp )
184         CALL lbc_lnk( pe3f , 'F', 1._wp )
185         DO jk = 1, jpk
186            ! set to z-scale factor if zero (i.e. along closed boundaries) because of lbclnk
187            WHERE( pe3u (:,:,jk) == 0._wp )   pe3u (:,:,jk) = pe3t_1d(jk)
188            WHERE( pe3v (:,:,jk) == 0._wp )   pe3v (:,:,jk) = pe3t_1d(jk)
189            WHERE( pe3f (:,:,jk) == 0._wp )   pe3f (:,:,jk) = pe3t_1d(jk)
190            WHERE( pe3uw(:,:,jk) == 0._wp )   pe3uw(:,:,jk) = pe3w_1d(jk)
191            WHERE( pe3vw(:,:,jk) == 0._wp )   pe3vw(:,:,jk) = pe3w_1d(jk)
192         END DO
193         !
194      ENDIF
195      !
196   END SUBROUTINE usr_def_zgr
197
198
199   SUBROUTINE zgr_z1d( pdept_1d, pdepw_1d, pe3t_1d , pe3w_1d )   ! 1D reference vertical coordinate
200      !!----------------------------------------------------------------------
201      !!                   ***  ROUTINE zgr_z1d  ***
202      !!
203      !! ** Purpose :   set the depth of model levels and the resulting
204      !!      vertical scale factors.
205      !!
206      !! ** Method  :   1D z-coordinate system (use in all type of coordinate)
207      !!       The depth of model levels is set from dep(k), an analytical function:
208      !!                   w-level: depw_1d  = dep(k)
209      !!                   t-level: dept_1d  = dep(k+0.5)
210      !!       The scale factors are the discrete derivative of the depth:
211      !!                   e3w_1d(jk) = dk[ dept_1d ]
212      !!                   e3t_1d(jk) = dk[ depw_1d ]
213      !!
214      !!            ===    Here constant vertical resolution   ===
215      !!
216      !! ** Action  : - pdept_1d, pdepw_1d : depth of T- and W-point (m)
217      !!              - pe3t_1d , pe3w_1d  : scale factors at T- and W-levels (m)
218      !!----------------------------------------------------------------------
219      REAL(wp), DIMENSION(:), INTENT(out) ::   pdept_1d, pdepw_1d   ! 1D grid-point depth        [m]
220      REAL(wp), DIMENSION(:), INTENT(out) ::   pe3t_1d , pe3w_1d    ! 1D vertical scale factors  [m]
221      !
222      INTEGER  ::   jk       ! dummy loop indices
223      REAL(wp) ::   zt, zw   ! local scalar
224      !!----------------------------------------------------------------------
225      !
226      IF(lwp) THEN                         ! Parameter print
227         WRITE(numout,*)
228         WRITE(numout,*) '    zgr_z1d : Reference vertical z-coordinates: uniform dz = ', rn_e3
229         WRITE(numout,*) '    ~~~~~~~'
230      ENDIF
231      !
232      ! Reference z-coordinate (depth - scale factor at T- and W-points)   ! Madec & Imbard 1996 function
233      ! ----------------------
234      DO jk = 1, jpk
235         zw = REAL( jk , wp )
236         zt = REAL( jk , wp ) + 0.5_wp
237         pdepw_1d(jk) =    rn_e3 *   REAL( jk-1 , wp )
238         pdept_1d(jk) =    rn_e3 * ( REAL( jk-1 , wp ) + 0.5_wp )
239         pe3w_1d (jk) =    rn_e3
240         pe3t_1d (jk) =    rn_e3
241      END DO
242      !
243      IF(lwp) THEN                        ! control print
244         WRITE(numout,*)
245         WRITE(numout,*) '              Reference 1D z-coordinate depth and scale factors:'
246         WRITE(numout, "(9x,' level  gdept_1d  gdepw_1d  e3t_1d   e3w_1d  ')" )
247         WRITE(numout, "(10x, i4, 4f9.2)" ) ( jk, pdept_1d(jk), pdepw_1d(jk), pe3t_1d(jk), pe3w_1d(jk), jk = 1, jpk )
248      ENDIF
249      !
250   END SUBROUTINE zgr_z1d
251   
252   !!======================================================================
253END MODULE usrdef_zgr
Note: See TracBrowser for help on using the repository browser.