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.
Changeset 12340 for NEMO/branches/2019/dev_r11943_MERGE_2019/src/ICE/icethd.F90 – NEMO

Ignore:
Timestamp:
2020-01-27T15:31:53+01:00 (4 years ago)
Author:
acc
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • NEMO/branches/2019/dev_r11943_MERGE_2019/src/ICE/icethd.F90

    r12236 r12340  
    5454   !! * Substitutions 
    5555#  include "vectopt_loop_substitute.h90" 
     56#  include "do_loop_substitute.h90" 
    5657   !!---------------------------------------------------------------------- 
    5758   !! NEMO/ICE 4.0 , NEMO Consortium (2018) 
     
    109110         zu_io(:,:) = u_ice(:,:) - ssu_m(:,:) 
    110111         zv_io(:,:) = v_ice(:,:) - ssv_m(:,:) 
    111          DO jj = 2, jpjm1  
    112             DO ji = fs_2, fs_jpim1 
    113                zfric(ji,jj) = rn_cio * ( 0.5_wp *  & 
    114                   &                    (  zu_io(ji,jj) * zu_io(ji,jj) + zu_io(ji-1,jj) * zu_io(ji-1,jj)   & 
    115                   &                     + zv_io(ji,jj) * zv_io(ji,jj) + zv_io(ji,jj-1) * zv_io(ji,jj-1) ) ) * tmask(ji,jj,1) 
    116             END DO 
    117          END DO 
     112         DO_2D_00_00 
     113            zfric(ji,jj) = rn_cio * ( 0.5_wp *  & 
     114               &                    (  zu_io(ji,jj) * zu_io(ji,jj) + zu_io(ji-1,jj) * zu_io(ji-1,jj)   & 
     115               &                     + zv_io(ji,jj) * zv_io(ji,jj) + zv_io(ji,jj-1) * zv_io(ji,jj-1) ) ) * tmask(ji,jj,1) 
     116         END_2D 
    118117      ELSE      !  if no ice dynamics => transmit directly the atmospheric stress to the ocean 
    119          DO jj = 2, jpjm1 
    120             DO ji = fs_2, fs_jpim1 
    121                zfric(ji,jj) = r1_rau0 * SQRT( 0.5_wp *  & 
    122                   &                         (  utau(ji,jj) * utau(ji,jj) + utau(ji-1,jj) * utau(ji-1,jj)   & 
    123                   &                          + vtau(ji,jj) * vtau(ji,jj) + vtau(ji,jj-1) * vtau(ji,jj-1) ) ) * tmask(ji,jj,1) 
    124             END DO 
    125          END DO 
     118         DO_2D_00_00 
     119            zfric(ji,jj) = r1_rau0 * SQRT( 0.5_wp *  & 
     120               &                         (  utau(ji,jj) * utau(ji,jj) + utau(ji-1,jj) * utau(ji-1,jj)   & 
     121               &                          + vtau(ji,jj) * vtau(ji,jj) + vtau(ji,jj-1) * vtau(ji,jj-1) ) ) * tmask(ji,jj,1) 
     122         END_2D 
    126123      ENDIF 
    127124      CALL lbc_lnk( 'icethd', zfric, 'T',  1. ) 
     
    130127      ! Partial computation of forcing for the thermodynamic sea ice model 
    131128      !--------------------------------------------------------------------! 
    132       DO jj = 1, jpj 
    133          DO ji = 1, jpi 
    134             rswitch  = tmask(ji,jj,1) * MAX( 0._wp , SIGN( 1._wp , at_i(ji,jj) - epsi10 ) ) ! 0 if no ice 
    135             ! 
    136             !           !  solar irradiance transmission at the mixed layer bottom and used in the lead heat budget 
    137             !           !  practically no "direct lateral ablation" 
    138             !            
    139             !           !  net downward heat flux from the ice to the ocean, expressed as a function of ocean  
    140             !           !  temperature and turbulent mixing (McPhee, 1992) 
    141             ! 
    142             ! --- Energy received in the lead from atm-oce exchanges, zqld is defined everywhere (J.m-2) --- ! 
    143             zqld =  tmask(ji,jj,1) * rdt_ice *  & 
    144                &    ( ( 1._wp - at_i_b(ji,jj) ) * qsr_oce(ji,jj) * frq_m(ji,jj) +  & 
    145                &      ( 1._wp - at_i_b(ji,jj) ) * qns_oce(ji,jj) + qemp_oce(ji,jj) ) 
    146  
    147             ! --- Energy needed to bring ocean surface layer until its freezing (mostly<0 but >0 if supercooling, J.m-2) --- ! 
    148             zqfr     = rau0 * rcp * e3t_m(ji,jj) * ( t_bo(ji,jj) - ( sst_m(ji,jj) + rt0 ) ) * tmask(ji,jj,1)  ! both < 0 (t_bo < sst) and > 0 (t_bo > sst) 
    149             zqfr_neg = MIN( zqfr , 0._wp )                                                                    ! only < 0 
    150  
    151             ! --- Sensible ocean-to-ice heat flux (mostly>0 but <0 if supercooling, W/m2) 
    152             zfric_u            = MAX( SQRT( zfric(ji,jj) ), zfric_umin )  
    153             qsb_ice_bot(ji,jj) = rswitch * rau0 * rcp * zch * zfric_u * ( ( sst_m(ji,jj) + rt0 ) - t_bo(ji,jj) ) ! W.m-2 
    154  
    155             qsb_ice_bot(ji,jj) = rswitch * MIN( qsb_ice_bot(ji,jj), - zqfr_neg * r1_rdtice / MAX( at_i(ji,jj), epsi10 ) ) 
    156             ! upper bound for qsb_ice_bot: the heat retrieved from the ocean must be smaller than the heat necessary to reach  
    157             !                              the freezing point, so that we do not have SST < T_freeze 
    158             !                              This implies: - ( qsb_ice_bot(ji,jj) * at_i(ji,jj) * rtdice ) - zqfr >= 0 
    159  
    160             !-- Energy Budget of the leads (J.m-2), source of ice growth in open water. Must be < 0 to form ice 
    161             qlead(ji,jj) = MIN( 0._wp , zqld - ( qsb_ice_bot(ji,jj) * at_i(ji,jj) * rdt_ice ) - zqfr ) 
    162  
    163             ! If there is ice and leads are warming => transfer energy from the lead budget and use it for bottom melting  
    164             ! If the grid cell is fully covered by ice (no leads) => transfer energy from the lead budget to the ice bottom budget 
    165             IF( ( zqld >= 0._wp .AND. at_i(ji,jj) > 0._wp ) .OR. at_i(ji,jj) >= (1._wp - epsi10) ) THEN 
    166                fhld (ji,jj) = rswitch * zqld * r1_rdtice / MAX( at_i(ji,jj), epsi10 ) ! divided by at_i since this is (re)multiplied by a_i in icethd_dh.F90 
    167                qlead(ji,jj) = 0._wp 
    168             ELSE 
    169                fhld (ji,jj) = 0._wp 
    170             ENDIF 
    171             ! 
    172             ! Net heat flux on top of the ice-ocean [W.m-2] 
    173             ! --------------------------------------------- 
    174             qt_atm_oi(ji,jj) = qns_tot(ji,jj) + qsr_tot(ji,jj)  
    175          END DO 
    176       END DO 
     129      DO_2D_11_11 
     130         rswitch  = tmask(ji,jj,1) * MAX( 0._wp , SIGN( 1._wp , at_i(ji,jj) - epsi10 ) ) ! 0 if no ice 
     131         ! 
     132         !           !  solar irradiance transmission at the mixed layer bottom and used in the lead heat budget 
     133         !           !  practically no "direct lateral ablation" 
     134         !            
     135         !           !  net downward heat flux from the ice to the ocean, expressed as a function of ocean  
     136         !           !  temperature and turbulent mixing (McPhee, 1992) 
     137         ! 
     138         ! --- Energy received in the lead from atm-oce exchanges, zqld is defined everywhere (J.m-2) --- ! 
     139         zqld =  tmask(ji,jj,1) * rdt_ice *  & 
     140            &    ( ( 1._wp - at_i_b(ji,jj) ) * qsr_oce(ji,jj) * frq_m(ji,jj) +  & 
     141            &      ( 1._wp - at_i_b(ji,jj) ) * qns_oce(ji,jj) + qemp_oce(ji,jj) ) 
     142 
     143         ! --- Energy needed to bring ocean surface layer until its freezing (mostly<0 but >0 if supercooling, J.m-2) --- ! 
     144         zqfr     = rau0 * rcp * e3t_m(ji,jj) * ( t_bo(ji,jj) - ( sst_m(ji,jj) + rt0 ) ) * tmask(ji,jj,1)  ! both < 0 (t_bo < sst) and > 0 (t_bo > sst) 
     145         zqfr_neg = MIN( zqfr , 0._wp )                                                                    ! only < 0 
     146 
     147         ! --- Sensible ocean-to-ice heat flux (mostly>0 but <0 if supercooling, W/m2) 
     148         zfric_u            = MAX( SQRT( zfric(ji,jj) ), zfric_umin )  
     149         qsb_ice_bot(ji,jj) = rswitch * rau0 * rcp * zch * zfric_u * ( ( sst_m(ji,jj) + rt0 ) - t_bo(ji,jj) ) ! W.m-2 
     150 
     151         qsb_ice_bot(ji,jj) = rswitch * MIN( qsb_ice_bot(ji,jj), - zqfr_neg * r1_rdtice / MAX( at_i(ji,jj), epsi10 ) ) 
     152         ! upper bound for qsb_ice_bot: the heat retrieved from the ocean must be smaller than the heat necessary to reach  
     153         !                              the freezing point, so that we do not have SST < T_freeze 
     154         !                              This implies: - ( qsb_ice_bot(ji,jj) * at_i(ji,jj) * rtdice ) - zqfr >= 0 
     155 
     156         !-- Energy Budget of the leads (J.m-2), source of ice growth in open water. Must be < 0 to form ice 
     157         qlead(ji,jj) = MIN( 0._wp , zqld - ( qsb_ice_bot(ji,jj) * at_i(ji,jj) * rdt_ice ) - zqfr ) 
     158 
     159         ! If there is ice and leads are warming => transfer energy from the lead budget and use it for bottom melting  
     160         ! If the grid cell is fully covered by ice (no leads) => transfer energy from the lead budget to the ice bottom budget 
     161         IF( ( zqld >= 0._wp .AND. at_i(ji,jj) > 0._wp ) .OR. at_i(ji,jj) >= (1._wp - epsi10) ) THEN 
     162            fhld (ji,jj) = rswitch * zqld * r1_rdtice / MAX( at_i(ji,jj), epsi10 ) ! divided by at_i since this is (re)multiplied by a_i in icethd_dh.F90 
     163            qlead(ji,jj) = 0._wp 
     164         ELSE 
     165            fhld (ji,jj) = 0._wp 
     166         ENDIF 
     167         ! 
     168         ! Net heat flux on top of the ice-ocean [W.m-2] 
     169         ! --------------------------------------------- 
     170         qt_atm_oi(ji,jj) = qns_tot(ji,jj) + qsr_tot(ji,jj)  
     171      END_2D 
    177172       
    178173      ! In case we bypass open-water ice formation 
     
    202197         ! select ice covered grid points 
    203198         npti = 0 ; nptidx(:) = 0 
    204          DO jj = 1, jpj 
    205             DO ji = 1, jpi 
    206                IF ( a_i(ji,jj,jl) > epsi10 ) THEN      
    207                   npti         = npti  + 1 
    208                   nptidx(npti) = (jj - 1) * jpi + ji 
    209                ENDIF 
    210             END DO 
    211          END DO 
     199         DO_2D_11_11 
     200            IF ( a_i(ji,jj,jl) > epsi10 ) THEN      
     201               npti         = npti  + 1 
     202               nptidx(npti) = (jj - 1) * jpi + ji 
     203            ENDIF 
     204         END_2D 
    212205 
    213206         IF( npti > 0 ) THEN  ! If there is no ice, do nothing. 
Note: See TracChangeset for help on using the changeset viewer.