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.
dynkeg.F90 in NEMO/branches/2019/dev_r11943_MERGE_2019/src/OCE/DYN – NEMO

source: NEMO/branches/2019/dev_r11943_MERGE_2019/src/OCE/DYN/dynkeg.F90 @ 12340

Last change on this file since 12340 was 12340, checked in by acc, 4 years ago

Branch 2019/dev_r11943_MERGE_2019. This commit introduces basic do loop macro
substitution to the 2019 option 1, merge branch. These changes have been SETTE
tested. The only addition is the do_loop_substitute.h90 file in the OCE directory but
the macros defined therein are used throughout the code to replace identifiable, 2D-
and 3D- nested loop opening and closing statements with single-line alternatives. Code
indents are also adjusted accordingly.

The following explanation is taken from comments in the new header file:

This header file contains preprocessor definitions and macros used in the do-loop
substitutions introduced between version 4.0 and 4.2. The primary aim of these macros
is to assist in future applications of tiling to improve performance. This is expected
to be achieved by alternative versions of these macros in selected locations. The
initial introduction of these macros simply replaces all identifiable nested 2D- and
3D-loops with single line statements (and adjusts indenting accordingly). Do loops
are identifiable if they comform to either:

DO jk = ....

DO jj = .... DO jj = ...

DO ji = .... DO ji = ...
. OR .
. .

END DO END DO

END DO END DO

END DO

and white-space variants thereof.

Additionally, only loops with recognised jj and ji loops limits are treated; these are:
Lower limits of 1, 2 or fs_2
Upper limits of jpi, jpim1 or fs_jpim1 (for ji) or jpj, jpjm1 or fs_jpjm1 (for jj)

The macro naming convention takes the form: DO_2D_BT_LR where:

B is the Bottom offset from the PE's inner domain;
T is the Top offset from the PE's inner domain;
L is the Left offset from the PE's inner domain;
R is the Right offset from the PE's inner domain

So, given an inner domain of 2,jpim1 and 2,jpjm1, a typical example would replace:

DO jj = 2, jpj

DO ji = 1, jpim1
.
.

END DO

END DO

with:

DO_2D_01_10
.
.
END_2D

similar conventions apply to the 3D loops macros. jk loop limits are retained
through macro arguments and are not restricted. This includes the possibility of
strides for which an extra set of DO_3DS macros are defined.

In the example definition below the inner PE domain is defined by start indices of
(kIs, kJs) and end indices of (kIe, KJe)

#define DO_2D_00_00 DO jj = kJs, kJe ; DO ji = kIs, kIe
#define END_2D END DO ; END DO

TO DO:


Only conventional nested loops have been identified and replaced by this step. There are constructs such as:

DO jk = 2, jpkm1

z2d(:,:) = z2d(:,:) + e3w(:,:,jk,Kmm) * z3d(:,:,jk) * wmask(:,:,jk)

END DO

which may need to be considered.

  • Property svn:keywords set to Id
File size: 7.5 KB
Line 
1MODULE dynkeg
2   !!======================================================================
3   !!                       ***  MODULE  dynkeg  ***
4   !! Ocean dynamics:  kinetic energy gradient trend
5   !!======================================================================
6   !! History :  1.0  !  1987-09  (P. Andrich, M.-A. Foujols)  Original code
7   !!            7.0  !  1997-05  (G. Madec)  Split dynber into dynkeg and dynhpg
8   !!  NEMO      1.0  !  2002-07  (G. Madec)  F90: Free form and module
9   !!            3.6  !  2015-05  (N. Ducousso, G. Madec)  add Hollingsworth scheme as an option
10   !!----------------------------------------------------------------------
11   
12   !!----------------------------------------------------------------------
13   !!   dyn_keg      : update the momentum trend with the horizontal tke
14   !!----------------------------------------------------------------------
15   USE oce             ! ocean dynamics and tracers
16   USE dom_oce         ! ocean space and time domain
17   USE trd_oce         ! trends: ocean variables
18   USE trddyn          ! trend manager: dynamics
19   !
20   USE in_out_manager  ! I/O manager
21   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
22   USE lib_mpp         ! MPP library
23   USE prtctl          ! Print control
24   USE timing          ! Timing
25   USE bdy_oce         ! ocean open boundary conditions
26
27   IMPLICIT NONE
28   PRIVATE
29
30   PUBLIC   dyn_keg    ! routine called by step module
31   
32   INTEGER, PARAMETER, PUBLIC  ::   nkeg_C2  = 0   !: 2nd order centered scheme (standard scheme)
33   INTEGER, PARAMETER, PUBLIC  ::   nkeg_HW  = 1   !: Hollingsworth et al., QJRMS, 1983
34   !
35   REAL(wp) ::   r1_48 = 1._wp / 48._wp   !: =1/(4*2*6)
36   
37   !! * Substitutions
38#  include "vectopt_loop_substitute.h90"
39#  include "do_loop_substitute.h90"
40   !!----------------------------------------------------------------------
41   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
42   !! $Id$
43   !! Software governed by the CeCILL license (see ./LICENSE)
44   !!----------------------------------------------------------------------
45CONTAINS
46
47   SUBROUTINE dyn_keg( kt, kscheme, Kmm, puu, pvv, Krhs )
48      !!----------------------------------------------------------------------
49      !!                  ***  ROUTINE dyn_keg  ***
50      !!
51      !! ** Purpose :   Compute the now momentum trend due to the horizontal
52      !!      gradient of the horizontal kinetic energy and add it to the
53      !!      general momentum trend.
54      !!
55      !! ** Method  : * kscheme = nkeg_C2 : 2nd order centered scheme that
56      !!      conserve kinetic energy. Compute the now horizontal kinetic energy
57      !!         zhke = 1/2 [ mi-1( un^2 ) + mj-1( vn^2 ) ]
58      !!              * kscheme = nkeg_HW : Hollingsworth correction following
59      !!      Arakawa (2001). The now horizontal kinetic energy is given by:
60      !!         zhke = 1/6 [ mi-1(  2 * un^2 + ((u(j+1)+u(j-1))/2)^2  )
61      !!                    + mj-1(  2 * vn^2 + ((v(i+1)+v(i-1))/2)^2  ) ]
62      !!     
63      !!      Take its horizontal gradient and add it to the general momentum
64      !!      trend.
65      !!         u(rhs) = u(rhs) - 1/e1u di[ zhke ]
66      !!         v(rhs) = v(rhs) - 1/e2v dj[ zhke ]
67      !!
68      !! ** Action : - Update the (puu(:,:,:,Krhs), pvv(:,:,:,Krhs)) with the hor. ke gradient trend
69      !!             - send this trends to trd_dyn (l_trddyn=T) for post-processing
70      !!
71      !! ** References : Arakawa, A., International Geophysics 2001.
72      !!                 Hollingsworth et al., Quart. J. Roy. Meteor. Soc., 1983.
73      !!----------------------------------------------------------------------
74      INTEGER                             , INTENT( in )  ::  kt               ! ocean time-step index
75      INTEGER                             , INTENT( in )  ::  kscheme          ! =0/1   type of KEG scheme
76      INTEGER                             , INTENT( in )  ::  Kmm, Krhs        ! ocean time level indices
77      REAL(wp), DIMENSION(jpi,jpj,jpk,jpt), INTENT(inout) ::  puu, pvv         ! ocean velocities and RHS of momentum equation
78      !
79      INTEGER  ::   ji, jj, jk             ! dummy loop indices
80      REAL(wp) ::   zu, zv                   ! local scalars
81      REAL(wp), DIMENSION(jpi,jpj,jpk)        ::   zhke
82      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   ztrdu, ztrdv 
83      !!----------------------------------------------------------------------
84      !
85      IF( ln_timing )   CALL timing_start('dyn_keg')
86      !
87      IF( kt == nit000 ) THEN
88         IF(lwp) WRITE(numout,*)
89         IF(lwp) WRITE(numout,*) 'dyn_keg : kinetic energy gradient trend, scheme number=', kscheme
90         IF(lwp) WRITE(numout,*) '~~~~~~~'
91      ENDIF
92
93      IF( l_trddyn ) THEN           ! Save the input trends
94         ALLOCATE( ztrdu(jpi,jpj,jpk) , ztrdv(jpi,jpj,jpk) )
95         ztrdu(:,:,:) = puu(:,:,:,Krhs) 
96         ztrdv(:,:,:) = pvv(:,:,:,Krhs) 
97      ENDIF
98     
99      zhke(:,:,jpk) = 0._wp
100
101      SELECT CASE ( kscheme )             !== Horizontal kinetic energy at T-point  ==!
102      !
103      CASE ( nkeg_C2 )                          !--  Standard scheme  --!
104         DO_3D_01_01( 1, jpkm1 )
105            zu =    puu(ji-1,jj  ,jk,Kmm) * puu(ji-1,jj  ,jk,Kmm)   &
106               &  + puu(ji  ,jj  ,jk,Kmm) * puu(ji  ,jj  ,jk,Kmm)
107            zv =    pvv(ji  ,jj-1,jk,Kmm) * pvv(ji  ,jj-1,jk,Kmm)   &
108               &  + pvv(ji  ,jj  ,jk,Kmm) * pvv(ji  ,jj  ,jk,Kmm)
109            zhke(ji,jj,jk) = 0.25_wp * ( zv + zu )
110         END_3D
111      CASE ( nkeg_HW )                          !--  Hollingsworth scheme  --!
112         DO_3D_00_00( 1, jpkm1 )
113            zu = 8._wp * ( puu(ji-1,jj  ,jk,Kmm) * puu(ji-1,jj  ,jk,Kmm)    &
114               &         + puu(ji  ,jj  ,jk,Kmm) * puu(ji  ,jj  ,jk,Kmm) )  &
115               &   +     ( puu(ji-1,jj-1,jk,Kmm) + puu(ji-1,jj+1,jk,Kmm) ) * ( puu(ji-1,jj-1,jk,Kmm) + puu(ji-1,jj+1,jk,Kmm) )   &
116               &   +     ( puu(ji  ,jj-1,jk,Kmm) + puu(ji  ,jj+1,jk,Kmm) ) * ( puu(ji  ,jj-1,jk,Kmm) + puu(ji  ,jj+1,jk,Kmm) )
117               !
118            zv = 8._wp * ( pvv(ji  ,jj-1,jk,Kmm) * pvv(ji  ,jj-1,jk,Kmm)    &
119               &         + pvv(ji  ,jj  ,jk,Kmm) * pvv(ji  ,jj  ,jk,Kmm) )  &
120               &  +      ( pvv(ji-1,jj-1,jk,Kmm) + pvv(ji+1,jj-1,jk,Kmm) ) * ( pvv(ji-1,jj-1,jk,Kmm) + pvv(ji+1,jj-1,jk,Kmm) )   &
121               &  +      ( pvv(ji-1,jj  ,jk,Kmm) + pvv(ji+1,jj  ,jk,Kmm) ) * ( pvv(ji-1,jj  ,jk,Kmm) + pvv(ji+1,jj  ,jk,Kmm) )
122            zhke(ji,jj,jk) = r1_48 * ( zv + zu )
123         END_3D
124         CALL lbc_lnk( 'dynkeg', zhke, 'T', 1. )
125         !
126      END SELECT 
127      !
128      DO_3D_00_00( 1, jpkm1 )
129         puu(ji,jj,jk,Krhs) = puu(ji,jj,jk,Krhs) - ( zhke(ji+1,jj  ,jk) - zhke(ji,jj,jk) ) / e1u(ji,jj)
130         pvv(ji,jj,jk,Krhs) = pvv(ji,jj,jk,Krhs) - ( zhke(ji  ,jj+1,jk) - zhke(ji,jj,jk) ) / e2v(ji,jj)
131      END_3D
132      !
133      IF( l_trddyn ) THEN                 ! save the Kinetic Energy trends for diagnostic
134         ztrdu(:,:,:) = puu(:,:,:,Krhs) - ztrdu(:,:,:)
135         ztrdv(:,:,:) = pvv(:,:,:,Krhs) - ztrdv(:,:,:)
136         CALL trd_dyn( ztrdu, ztrdv, jpdyn_keg, kt, Kmm )
137         DEALLOCATE( ztrdu , ztrdv )
138      ENDIF
139      !
140      IF(sn_cfctl%l_prtctl)   CALL prt_ctl( tab3d_1=puu(:,:,:,Krhs), clinfo1=' keg  - Ua: ', mask1=umask,   &
141         &                                  tab3d_2=pvv(:,:,:,Krhs), clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
142      !
143      IF( ln_timing )   CALL timing_stop('dyn_keg')
144      !
145   END SUBROUTINE dyn_keg
146
147   !!======================================================================
148END MODULE dynkeg
Note: See TracBrowser for help on using the repository browser.