2025-09-05 09:42:21 +02:00

264 lines
13 KiB
Fortran
Executable File

MODULE usrdef_zgr
!!======================================================================
!! *** MODULE usrdef_zgr ***
!!
!! === SWG configuration ===
!!
!! User defined : vertical coordinate system of a user configuration
!!======================================================================
!! History : 4.0 ! 2016-06 (G. Madec) Original code
!! - ! 2020-03 (A. Nasser) Shallow Water Eq. configuration
!!----------------------------------------------------------------------
!!----------------------------------------------------------------------
!! usr_def_zgr : user defined vertical coordinate system
!! zgr_z : reference 1D z-coordinate
!! zgr_top_bot: ocean top and bottom level indices
!! zgr_zco : 3D verticl coordinate in pure z-coordinate case
!!---------------------------------------------------------------------
USE oce ! ocean variables
USE dom_oce ! ocean domain
USE depth_e3 ! depth <=> e3
USE usrdef_nam
!
USE in_out_manager ! I/O manager
USE lbclnk ! ocean lateral boundary conditions (or mpp link)
USE lib_mpp ! distributed memory computing library
IMPLICIT NONE
PRIVATE
PUBLIC usr_def_zgr ! called by domzgr.F90
!! * Substitutions
# include "do_loop_substitute.h90"
!!----------------------------------------------------------------------
!! NEMO/OCE 4.0 , NEMO Consortium (2018)
!! $Id: usrdef_zgr.F90 10425 2018-12-19 21:54:16Z smasson $
!! Software governed by the CeCILL license (see ./LICENSE)
!!----------------------------------------------------------------------
CONTAINS
SUBROUTINE usr_def_zgr( ld_zco , ld_zps , ld_sco , ld_isfcav, & ! type of vertical coordinate
& pdept_1d, pdepw_1d, pe3t_1d , pe3w_1d , & ! 1D reference vertical coordinate
& pdept , pdepw , & ! 3D t & w-points depth
& pe3t , pe3u , pe3v , pe3f , & ! vertical scale factors
& pe3w , pe3uw , pe3vw , & ! - - -
& k_top , k_bot ) ! top & bottom ocean level
!!---------------------------------------------------------------------
!! *** ROUTINE usr_def_zgr ***
!!
!! ** Purpose : User defined the vertical coordinates
!!
!!----------------------------------------------------------------------
LOGICAL , INTENT(out) :: ld_zco, ld_zps, ld_sco ! vertical coordinate flags
LOGICAL , INTENT(out) :: ld_isfcav ! under iceshelf cavity flag
REAL(wp), DIMENSION(:) , INTENT(out) :: pdept_1d, pdepw_1d ! 1D grid-point depth [m]
REAL(wp), DIMENSION(:) , INTENT(out) :: pe3t_1d , pe3w_1d ! 1D grid-point depth [m]
REAL(wp), DIMENSION(:,:,:), INTENT(out) :: pdept, pdepw ! grid-point depth [m]
REAL(wp), DIMENSION(:,:,:), INTENT(out) :: pe3t , pe3u , pe3v , pe3f ! vertical scale factors [m]
REAL(wp), DIMENSION(:,:,:), INTENT(out) :: pe3w , pe3uw, pe3vw ! i-scale factors
INTEGER , DIMENSION(:,:) , INTENT(out) :: k_top, k_bot ! first & last ocean level
!
INTEGER :: inum ! local logical unit
REAL(WP) :: z_zco, z_zps, z_sco, z_cav
REAL(wp), DIMENSION(jpi,jpj) :: z2d ! 2D workspace
!!----------------------------------------------------------------------
!
IF(lwp) WRITE(numout,*)
IF(lwp) WRITE(numout,*) 'usr_def_zgr : SWG configuration (z-coordinate closed flat box ocean without cavities)'
IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
!
!
! type of vertical coordinate
! ---------------------------
ld_zco = .FALSE. ! SWG case: z-coordinate without ocean cavities
ld_zps = .FALSE.
ld_sco = .TRUE.
ld_isfcav = .FALSE.
!
!
! Build the vertical coordinate system
! ------------------------------------
CALL zgr_z( pdept_1d, pdepw_1d, pe3t_1d , pe3w_1d ) ! Reference z-coordinate system
!
CALL zgr_msk_top_bot( k_top , k_bot) ! masked top and bottom ocean t-level indices
!
! ! z-coordinate (3D arrays) from the 1D z-coord.
CALL zgr_zco( pdept_1d, pdepw_1d, pe3t_1d, pe3w_1d, & ! in : 1D reference vertical coordinate
& pdept , pdepw , & ! out : 3D t & w-points depth
& pe3t , pe3u , pe3v , pe3f , & ! vertical scale factors
& pe3w , pe3uw , pe3vw ) ! - - -
!
END SUBROUTINE usr_def_zgr
SUBROUTINE zgr_z( pdept_1d, pdepw_1d, pe3t_1d , pe3w_1d ) ! 1D reference vertical coordinate
!!----------------------------------------------------------------------
!! *** ROUTINE zgr_z ***
!!
!! ** Purpose : set the 1D depth of model levels and the resulting
!! vertical scale factors.
!!
!! ** Method : 1D z-coordinate system (use in all type of coordinate)
!! The depth of model levels is set from dep(k), an analytical function:
!! w-level: depw_1d = dep(k)
!! t-level: dept_1d = dep(k+0.5)
!! The scale factors are the discrete derivative of the depth:
!! e3w_1d(jk) = dk[ dept_1d ]
!! e3t_1d(jk) = dk[ depw_1d ]
!! with at top and bottom :
!! e3w_1d( 1 ) = 2 * ( dept_1d( 1 ) - depw_1d( 1 ) )
!! e3t_1d(jpk) = 2 * ( dept_1d(jpk) - depw_1d(jpk) )
!! The depth are then re-computed from the sum of e3. This ensures
!! that depths are identical when reading domain configuration file.
!! Indeed, only e3. are saved in this file, depth are compute by a call
!! to the e3_to_depth subroutine.
!!
!! Here the Madec & Imbard (1996) function is used.
!!
!! ** Action : - pdept_1d, pdepw_1d : depth of T- and W-point (m)
!! - pe3t_1d , pe3w_1d : scale factors at T- and W-levels (m)
!!
!! Reference : Marti, Madec & Delecluse, 1992, JGR, 97, No8, 12,763-12,766.
!! Madec and Imbard, 1996, Clim. Dyn.
!!----------------------------------------------------------------------
REAL(wp), DIMENSION(:) , INTENT(out) :: pdept_1d, pdepw_1d ! 1D grid-point depth [m]
REAL(wp), DIMENSION(:) , INTENT(out) :: pe3t_1d , pe3w_1d ! 1D vertical scale factors [m]
!
INTEGER :: jk ! dummy loop indices
!!----------------------------------------------------------------------
!
!
IF(lwp) THEN ! Parameter print
WRITE(numout,*)
WRITE(numout,*) ' zgr_z : Reference vertical z-coordinates '
WRITE(numout,*) ' ~~~~~~~'
ENDIF
!
! 1D Reference z-coordinate (using Madec & Imbard 1996 function)
! -------------------------
!
! depth at T and W-points
pdepw_1d(1) = 0._wp
pdept_1d(1) = 250._wp
!
pdepw_1d(2) = 500._wp
pdept_1d(2) = 750._wp
!
! ! e3t and e3w from depth
CALL depth_to_e3( pdept_1d, pdepw_1d, pe3t_1d, pe3w_1d )
!
! ! recompute depths from SUM(e3) <== needed
CALL e3_to_depth( pe3t_1d, pe3w_1d, pdept_1d, pdepw_1d )
!
IF(lwp) THEN ! control print
WRITE(numout,*)
WRITE(numout,*) ' Reference 1D z-coordinate depth and scale factors:'
WRITE(numout, "(9x,' level gdept_1d gdepw_1d e3t_1d e3w_1d ')" )
WRITE(numout, "(10x, i4, 4f9.2)" ) ( jk, pdept_1d(jk), pdepw_1d(jk), pe3t_1d(jk), pe3w_1d(jk), jk = 1, jpk )
ENDIF
!
END SUBROUTINE zgr_z
SUBROUTINE zgr_msk_top_bot( k_top , k_bot)
!!----------------------------------------------------------------------
!! *** ROUTINE zgr_msk_top_bot ***
!!
!! ** Purpose : set the masked top and bottom ocean t-levels
!!
!! ** Method : SWG case = closed flat box ocean without ocean cavities
!! k_top = 1 except along north, south, east and west boundaries
!! k_bot = jpk-1 except along north, south, east and west boundaries
!!
!! ** Action : - k_top : first wet ocean level index
!! - k_bot : last wet ocean level index
!!----------------------------------------------------------------------
INTEGER , DIMENSION(:,:), INTENT(out) :: k_top , k_bot ! first & last wet ocean level
!
REAL(wp), DIMENSION(jpi,jpj) :: z2d ! 2D local workspace
INTEGER :: ji, jj ! dummy loop indices
REAL(wp) :: zylim0, zylim1, zxlim0, zxlim1 ! limit of the domain [m]
REAL(WP) :: zcoeff ! local scalar
!!----------------------------------------------------------------------
!
IF(lwp) WRITE(numout,*)
IF(lwp) WRITE(numout,*) ' zgr_top_bot : defines the top and bottom wet ocean levels.'
IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~'
IF(lwp) WRITE(numout,*) ' SWG case : closed flat box ocean without ocean cavities'
!
z2d(:,:) = REAL( jpkm1 , wp ) ! flat bottom
!
CALL lbc_lnk( 'usrdef_zgr', z2d, 'T', 1._wp ) ! set surrounding land to zero (closed boundaries)
!
zylim0 = 10000._wp ! +10km
zylim1 = 2010000._wp ! 2010km
zxlim0 = 10000._wp ! +10km
zxlim1 = 2010000._wp ! 2010km
!
DO_2D( nn_hls, nn_hls, nn_hls, nn_hls )
! if T point in the 2000 km x 2000 km domain
! IF ( gphit(ji,jj) > zylim0 .AND. gphit(ji,jj) < zylim1 .AND. &
! & glamt(ji,jj) > zxlim0 .AND. glamt(ji,jj) < zxlim1 ) THEN
! if U,V points are in the 2000 km x 2000 km domain
IF ( gphiv(ji,jj) > zylim0 .AND. gphiv(ji,jj) < zylim1 .AND. &
& glamu(ji,jj) > zxlim0 .AND. glamu(ji,jj) < zxlim1 ) THEN
k_top(ji,jj) = 1 ! = ocean
k_bot(ji,jj) = NINT( z2d(ji,jj) )
ELSE
k_top(ji,jj) = 0 ! = land
k_bot(ji,jj) = 0
END IF
END_2D
! mask the lonely corners
DO_2D( 0, 0, 0, 0 )
zcoeff = k_top(ji+1,jj) + k_top(ji,jj+1) &
+ k_top(ji-1,jj) + k_top(ji,jj-1)
IF ( zcoeff <= 1._wp ) THEN
k_top(ji,jj) = 0 ! = land
k_bot(ji,jj) = 0
END IF
END_2D
!
END SUBROUTINE zgr_msk_top_bot
SUBROUTINE zgr_zco( pdept_1d, pdepw_1d, pe3t_1d, pe3w_1d, & ! in : 1D reference vertical coordinate
& pdept , pdepw , & ! out: 3D t & w-points depth
& pe3t , pe3u , pe3v , pe3f , & ! vertical scale factors
& pe3w , pe3uw , pe3vw ) ! - - -
!!----------------------------------------------------------------------
!! *** ROUTINE zgr_zco ***
!!
!! ** Purpose : define the reference z-coordinate system
!!
!! ** Method : set 3D coord. arrays to reference 1D array
!!----------------------------------------------------------------------
REAL(wp), DIMENSION(:) , INTENT(in ) :: pdept_1d, pdepw_1d ! 1D grid-point depth [m]
REAL(wp), DIMENSION(:) , INTENT(in ) :: pe3t_1d , pe3w_1d ! 1D vertical scale factors [m]
REAL(wp), DIMENSION(:,:,:), INTENT( out) :: pdept, pdepw ! grid-point depth [m]
REAL(wp), DIMENSION(:,:,:), INTENT( out) :: pe3t , pe3u , pe3v , pe3f ! vertical scale factors [m]
REAL(wp), DIMENSION(:,:,:), INTENT( out) :: pe3w , pe3uw, pe3vw ! - - -
!
INTEGER :: jk
!!----------------------------------------------------------------------
!
DO jk = 1, jpk
pdept(:,:,jk) = pdept_1d(jk)
pdepw(:,:,jk) = pdepw_1d(jk)
pe3t (:,:,jk) = pe3t_1d (jk)
pe3u (:,:,jk) = pe3t_1d (jk)
pe3v (:,:,jk) = pe3t_1d (jk)
pe3f (:,:,jk) = pe3t_1d (jk)
pe3w (:,:,jk) = pe3w_1d (jk)
pe3uw(:,:,jk) = pe3w_1d (jk)
pe3vw(:,:,jk) = pe3w_1d (jk)
END DO
!
END SUBROUTINE zgr_zco
!!======================================================================
END MODULE usrdef_zgr