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

source: NEMO/branches/2019/dev_r11943_MERGE_2019/src/OCE/DYN/dynzad.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: 5.3 KB
Line 
1MODULE dynzad
2   !!======================================================================
3   !!                       ***  MODULE  dynzad  ***
4   !! Ocean dynamics : vertical advection trend
5   !!======================================================================
6   !! History :  OPA  ! 1991-01  (G. Madec) Original code
7   !!   NEMO     0.5  ! 2002-07  (G. Madec) Free form, F90
8   !!----------------------------------------------------------------------
9   
10   !!----------------------------------------------------------------------
11   !!   dyn_zad       : vertical advection momentum trend
12   !!----------------------------------------------------------------------
13   USE oce            ! ocean dynamics and tracers
14   USE dom_oce        ! ocean space and time domain
15   USE sbc_oce        ! surface boundary condition: ocean
16   USE trd_oce        ! trends: ocean variables
17   USE trddyn         ! trend manager: dynamics
18   !
19   USE in_out_manager ! I/O manager
20   USE lib_mpp        ! MPP library
21   USE prtctl         ! Print control
22   USE timing         ! Timing
23
24   IMPLICIT NONE
25   PRIVATE
26   
27   PUBLIC   dyn_zad       ! routine called by dynadv.F90
28
29   !! * Substitutions
30#  include "vectopt_loop_substitute.h90"
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 dyn_zad ( kt, Kmm, puu, pvv, Krhs )
40      !!----------------------------------------------------------------------
41      !!                  ***  ROUTINE dynzad  ***
42      !!
43      !! ** Purpose :   Compute the now vertical momentum advection trend and
44      !!      add it to the general trend of momentum equation.
45      !!
46      !! ** Method  :   The now vertical advection of momentum is given by:
47      !!         w dz(u) = u(rhs) + 1/(e1e2u*e3u) mk+1[ mi(e1e2t*ww) dk(u) ]
48      !!         w dz(v) = v(rhs) + 1/(e1e2v*e3v) mk+1[ mj(e1e2t*ww) dk(v) ]
49      !!      Add this trend to the general trend (puu(:,:,:,Krhs),pvv(:,:,:,Krhs)):
50      !!         (u(rhs),v(rhs)) = (u(rhs),v(rhs)) + w dz(u,v)
51      !!
52      !! ** Action  : - Update (puu(:,:,:,Krhs),pvv(:,:,:,Krhs)) with the vert. momentum adv. trends
53      !!              - Send the trends to trddyn for diagnostics (l_trddyn=T)
54      !!----------------------------------------------------------------------
55      INTEGER                             , INTENT( in )  ::  kt               ! ocean time-step inedx
56      INTEGER                             , INTENT( in )  ::  Kmm, Krhs        ! ocean time level indices
57      REAL(wp), DIMENSION(jpi,jpj,jpk,jpt), INTENT(inout) ::  puu, pvv         ! ocean velocities and RHS of momentum equation
58      !
59      INTEGER  ::   ji, jj, jk   ! dummy loop indices
60      REAL(wp) ::   zua, zva     ! local scalars
61      REAL(wp), DIMENSION(jpi,jpj)     ::   zww
62      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwuw, zwvw
63      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   ztrdu, ztrdv
64      !!----------------------------------------------------------------------
65      !
66      IF( ln_timing )   CALL timing_start('dyn_zad')
67      !
68      IF( kt == nit000 ) THEN
69         IF(lwp) WRITE(numout,*)
70         IF(lwp) WRITE(numout,*) 'dyn_zad : 2nd order vertical advection scheme'
71      ENDIF
72
73      IF( l_trddyn )   THEN         ! Save puu(:,:,:,Krhs) and pvv(:,:,:,Krhs) trends
74         ALLOCATE( ztrdu(jpi,jpj,jpk) , ztrdv(jpi,jpj,jpk) ) 
75         ztrdu(:,:,:) = puu(:,:,:,Krhs) 
76         ztrdv(:,:,:) = pvv(:,:,:,Krhs) 
77      ENDIF
78     
79      DO jk = 2, jpkm1              ! Vertical momentum advection at level w and u- and v- vertical
80         DO_2D_01_01
81            zww(ji,jj) = 0.25_wp * e1e2t(ji,jj) * ww(ji,jj,jk)
82         END_2D
83         DO_2D_00_00
84            zwuw(ji,jj,jk) = ( zww(ji+1,jj  ) + zww(ji,jj) ) * ( puu(ji,jj,jk-1,Kmm) - puu(ji,jj,jk,Kmm) )
85            zwvw(ji,jj,jk) = ( zww(ji  ,jj+1) + zww(ji,jj) ) * ( pvv(ji,jj,jk-1,Kmm) - pvv(ji,jj,jk,Kmm) )
86         END_2D
87      END DO
88      !
89      ! Surface and bottom advective fluxes set to zero
90      DO_2D_00_00
91         zwuw(ji,jj, 1 ) = 0._wp
92         zwvw(ji,jj, 1 ) = 0._wp
93         zwuw(ji,jj,jpk) = 0._wp
94         zwvw(ji,jj,jpk) = 0._wp
95      END_2D
96      !
97      DO_3D_00_00( 1, jpkm1 )
98         puu(ji,jj,jk,Krhs) = puu(ji,jj,jk,Krhs) - ( zwuw(ji,jj,jk) + zwuw(ji,jj,jk+1) ) * r1_e1e2u(ji,jj) / e3u(ji,jj,jk,Kmm)
99         pvv(ji,jj,jk,Krhs) = pvv(ji,jj,jk,Krhs) - ( zwvw(ji,jj,jk) + zwvw(ji,jj,jk+1) ) * r1_e1e2v(ji,jj) / e3v(ji,jj,jk,Kmm)
100      END_3D
101
102      IF( l_trddyn ) THEN           ! save the vertical advection trends for diagnostic
103         ztrdu(:,:,:) = puu(:,:,:,Krhs) - ztrdu(:,:,:)
104         ztrdv(:,:,:) = pvv(:,:,:,Krhs) - ztrdv(:,:,:)
105         CALL trd_dyn( ztrdu, ztrdv, jpdyn_zad, kt, Kmm )
106         DEALLOCATE( ztrdu, ztrdv ) 
107      ENDIF
108      !                             ! Control print
109      IF(sn_cfctl%l_prtctl)   CALL prt_ctl( tab3d_1=puu(:,:,:,Krhs), clinfo1=' zad  - Ua: ', mask1=umask,   &
110         &                                  tab3d_2=pvv(:,:,:,Krhs), clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
111      !
112      IF( ln_timing )   CALL timing_stop('dyn_zad')
113      !
114   END SUBROUTINE dyn_zad
115
116   !!======================================================================
117END MODULE dynzad
Note: See TracBrowser for help on using the repository browser.