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_hgr.F90 in NEMO/trunk/tests/ICE_AGRIF/MY_SRC – NEMO

source: NEMO/trunk/tests/ICE_AGRIF/MY_SRC/usrdef_hgr.F90

Last change on this file was 15119, checked in by jchanut, 3 years ago

#2638, changes to accomodate nn_hls=2 and AGRIF zooms crossing cyclic boundaries. E-W case ok, update for North-Fold still needed.

  • Property svn:keywords set to Id
File size: 9.0 KB
Line 
1MODULE usrdef_hgr
2   !!======================================================================
3   !!                       ***  MODULE  usrdef_hgr  ***
4   !!
5   !!                      ===  ICE_AGRIF configuration  ===
6   !!
7   !! User defined :   mesh and Coriolis parameter of a user configuration
8   !!======================================================================
9   !! History :  NEMO  ! 2016-08  (S. Flavoni, G. Madec)  Original code
10   !!----------------------------------------------------------------------
11
12   !!----------------------------------------------------------------------
13   !!   usr_def_hgr    : initialize the horizontal mesh for ICE_AGRIF configuration
14   !!----------------------------------------------------------------------
15   USE dom_oce         ! ocean space and time domain
16   USE par_oce         ! ocean space and time domain
17   USE phycst          ! physical constants
18   USE usrdef_nam, ONLY: rn_dx, rn_dy, ln_corio, rn_ppgphi0   ! horizontal resolution in meters
19   !                                                            coriolis and reference latitude
20   USE in_out_manager  ! I/O manager
21   USE lib_mpp         ! MPP library
22   
23   IMPLICIT NONE
24   PRIVATE
25
26   REAL(wp) :: roffsetx, roffsety ! Offset in km to first f-point
27
28   PUBLIC   usr_def_hgr   ! called by domhgr.F90
29
30   !! * Substitutions
31#  include "do_loop_substitute.h90"
32   !!----------------------------------------------------------------------
33   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
34   !! $Id$
35   !! Software governed by the CeCILL license (see ./LICENSE)
36   !!----------------------------------------------------------------------
37CONTAINS
38
39   SUBROUTINE usr_def_hgr( plamt , plamu , plamv  , plamf  ,   &   ! geographic position (required)
40      &                    pphit , pphiu , pphiv  , pphif  ,   &   !
41      &                    kff   , pff_f , pff_t  ,            &   ! Coriolis parameter  (if domain not on the sphere)
42      &                    pe1t  , pe1u  , pe1v   , pe1f   ,   &   ! scale factors       (required)
43      &                    pe2t  , pe2u  , pe2v   , pe2f   ,   &   !
44      &                    ke1e2u_v      , pe1e2u , pe1e2v     )   ! u- & v-surfaces (if gridsize reduction is used in strait(s))
45      !!----------------------------------------------------------------------
46      !!                  ***  ROUTINE usr_def_hgr  ***
47      !!
48      !! ** Purpose :   user defined mesh and Coriolis parameter
49      !!
50      !! ** Method  :   set all intent(out) argument to a proper value
51      !!                ICE_AGRIF configuration : uniform grid spacing (rn_dx)
52      !!                without Coriolis force (f=0)
53      !!
54      !! ** Action  : - define longitude & latitude of t-, u-, v- and f-points (in kms)
55      !!              - define coriolis parameter at f-point if the domain in not on the sphere (on beta-plane)
56      !!              - define i- & j-scale factors at t-, u-, v- and f-points (in meters)
57      !!              - define u- & v-surfaces (if gridsize reduction is used in some straits) (in m2)
58      !!----------------------------------------------------------------------
59      REAL(wp), DIMENSION(:,:), INTENT(out) ::   plamt, plamu, plamv, plamf   ! longitude outputs                     [degrees]
60      REAL(wp), DIMENSION(:,:), INTENT(out) ::   pphit, pphiu, pphiv, pphif   ! latitude outputs                      [degrees]
61      INTEGER                 , INTENT(out) ::   kff                          ! =1 Coriolis parameter computed here, =0 otherwise
62      REAL(wp), DIMENSION(:,:), INTENT(out) ::   pff_f, pff_t                 ! Coriolis factor at f-point                [1/s]
63      REAL(wp), DIMENSION(:,:), INTENT(out) ::   pe1t, pe1u, pe1v, pe1f       ! i-scale factors                             [m]
64      REAL(wp), DIMENSION(:,:), INTENT(out) ::   pe2t, pe2u, pe2v, pe2f       ! j-scale factors                             [m]
65      INTEGER                 , INTENT(out) ::   ke1e2u_v                     ! =1 u- & v-surfaces computed here, =0 otherwise
66      REAL(wp), DIMENSION(:,:), INTENT(out) ::   pe1e2u, pe1e2v               ! u- & v-surfaces (if reduction in strait)   [m2]
67      !
68      INTEGER  ::   ji, jj     ! dummy loop indices
69      REAL(wp) ::   zbeta, zf0
70      REAL(wp) ::   zti, ztj   ! local scalars
71      !!-------------------------------------------------------------------------------
72      !
73      IF(lwp) WRITE(numout,*)
74      IF(lwp) WRITE(numout,*) 'usr_def_hgr : ICE_AGRIF configuration bassin'
75      IF(lwp) WRITE(numout,*)
76      IF(lwp) WRITE(numout,*) '          f-plane with irregular grid-spacing (+- 10%)'
77      IF(lwp) WRITE(numout,*) '          the max is given by rn_dx and rn_dy' 
78      !
79      !
80      ! Position coordinates (in kilometers)
81      !                          ==========
82      ! Offset is given at first f-point, i.e. at (i,j) = (nn_hls+1, nn_hls+1)
83      ! Here we assume the grid is centred around a T-point at the middle of
84      ! of the domain (hence domain size is odd)
85      roffsetx = (-REAL(Ni0glo-1, wp) + 1._wp) * 0.5 * 1.e-3 * rn_dx
86      roffsety = (-REAL(Nj0glo-1, wp) + 1._wp) * 0.5 * 1.e-3 * rn_dy
87#if defined key_agrif
88      IF( .NOT.Agrif_Root() ) THEN
89         ! deduce offset from parent:
90         roffsetx = Agrif_Parent(roffsetx) &
91            & + (-(nbghostcells_x_w - 1) + (Agrif_Parent(nbghostcells_x_w) &
92            & + Agrif_Ix()-2)*Agrif_Rhox()) * 1.e-3 * rn_dx
93         roffsety = Agrif_Parent(roffsety) &
94            & + (-(nbghostcells_y_s - 1) + (Agrif_Parent(nbghostcells_y_s) &
95            & + Agrif_Iy()-2)*Agrif_Rhoy()) * 1.e-3 * rn_dy
96      ENDIF
97#endif
98      DO_2D( nn_hls, nn_hls, nn_hls, nn_hls )
99         zti = REAL( mig0(ji)-1, wp )  ! start at i=0 in the global grid without halos
100         ztj = REAL( mjg0(jj)-1, wp )  ! start at j=0 in the global grid without halos
101
102         plamt(ji,jj) = roffsetx + rn_dx * 1.e-3 * ( zti - 0.5_wp )
103         plamu(ji,jj) = roffsetx + rn_dx * 1.e-3 *   zti
104         plamv(ji,jj) = plamt(ji,jj)
105         plamf(ji,jj) = plamu(ji,jj)
106
107         pphit(ji,jj) = roffsety + rn_dy * 1.e-3 * ( ztj - 0.5_wp )
108         pphiv(ji,jj) = roffsety + rn_dy * 1.e-3 *   ztj
109         pphiu(ji,jj) = pphit(ji,jj)
110         pphif(ji,jj) = pphiv(ji,jj)
111      END_2D
112      !
113      ! Horizontal scale factors (in meters)
114      !                              ======
115!! ==> EITHER 1) variable scale factors
116!! clem: This can be used with a 1proc simulation but I think it breaks repro when >1procs are used     
117!!         DO jj = 1, jpj
118!!            DO ji = 1, jpi
119!!               !!pe1t(ji,jj) = rn_dx * EXP( -0.8/REAL(jpiglo**2) * (mi0(ji)-REAL(jpiglo+1)*0.5)**2 )  ! gaussian shape
120!!               !!pe2t(ji,jj) = rn_dy * EXP( -0.8/REAL(jpjglo**2) * (mj0(jj)-REAL(jpjglo+1)*0.5)**2 )  ! gaussian shape
121!!               pe1t(ji,jj) = rn_dx * ( 1. -0.1 * ABS(REAL(mi0(ji))-REAL(jpiglo+1)*0.5) / (1.-REAL(jpiglo+1)*0.5) ) ! linear shape
122!!               pe2t(ji,jj) = rn_dy * ( 1. -0.1 * ABS(REAL(mj0(jj))-REAL(jpjglo+1)*0.5) / (1.-REAL(jpjglo+1)*0.5) ) ! linear shape
123!!            END DO
124!!         END DO
125!!#if defined key_agrif
126!!         IF( .NOT. Agrif_Root() ) THEN ! only works if the zoom is positioned at the center of the parent grid
127!!            DO jj = 1, jpj
128!!               DO ji = 1, jpi
129!!                  pe1t(ji,jj) = rn_dx * ( 1. -0.1 * ABS(REAL(mi0(ji))-REAL(jpiglo+1)*0.5) / (1.-REAL(jpiglo+1)*0.5)  &
130!!                     &                            * REAL(jpiglo) / REAL(Agrif_Parent(jpiglo) * Agrif_Rhox()) )       ! factor to match parent grid
131!!                  pe2t(ji,jj) = rn_dy * ( 1. -0.1 * ABS(REAL(mj0(jj))-REAL(jpjglo+1)*0.5) / (1.-REAL(jpjglo+1)*0.5)  &
132!!                     &                            * REAL(jpjglo) / REAL(Agrif_Parent(jpjglo) * Agrif_Rhoy()) )       ! factor to match parent grid
133!!               END DO
134!!            END DO
135!!         ENDIF
136!!#endif
137!! ==> OR 2) constant scale factors
138         pe1t(:,:) = rn_dx
139         pe2t(:,:) = rn_dy
140!! ==> END
141         
142      pe1u(:,:) = pe1t(:,:)      ;      pe2u(:,:) = pe2t(:,:)
143      pe1v(:,:) = pe1t(:,:)      ;      pe2v(:,:) = pe2t(:,:)
144      pe1f(:,:) = pe1t(:,:)      ;      pe2f(:,:) = pe2t(:,:)
145
146      !                             ! NO reduction of grid size in some straits
147      ke1e2u_v = 0                  !    ==>> u_ & v_surfaces will be computed in dom_ghr routine
148      pe1e2u(:,:) = 0._wp           !    CAUTION: set to zero to avoid error with some compilers that
149      pe1e2v(:,:) = 0._wp           !             require an initialization of INTENT(out) arguments
150      !
151      !
152      !                       !==  Coriolis parameter  ==!
153      kff = 1                       !  indicate not to compute Coriolis parameter afterward
154      !
155      IF( ln_corio ) THEN
156         zbeta = 2._wp * omega * COS( rad * rn_ppgphi0 ) / ra
157         zf0   = 2._wp * omega * SIN( rad * rn_ppgphi0 )
158         pff_f(:,:) = zf0 + zbeta * pphif(:,:) * 1.e+3
159         pff_t(:,:) = zf0 + zbeta * pphit(:,:) * 1.e+3
160      ELSE
161         pff_f(:,:) = 0.
162         pff_t(:,:) = 0.
163      ENDIF
164      !
165   END SUBROUTINE usr_def_hgr
166
167   !!======================================================================
168END MODULE usrdef_hgr
Note: See TracBrowser for help on using the repository browser.