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 2715 for trunk/NEMOGCM/NEMO/OPA_SRC/TRA/trabbl.F90 – NEMO

Ignore:
Timestamp:
2011-03-30T17:58:35+02:00 (13 years ago)
Author:
rblod
Message:

First attempt to put dynamic allocation on the trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/NEMOGCM/NEMO/OPA_SRC/TRA/trabbl.F90

    r2528 r2715  
    1717   !!   'key_trabbl'   or                             bottom boundary layer 
    1818   !!---------------------------------------------------------------------- 
     19   !!   tra_bbl_alloc : allocate trabbl arrays 
    1920   !!   tra_bbl       : update the tracer trends due to the bottom boundary layer (advective and/or diffusive) 
    2021   !!   tra_bbl_dif   : generic routine to compute bbl diffusive trend 
     
    5354   REAL(wp), PUBLIC ::   rn_gambbl  = 10.0_wp   !: lateral coeff. for bottom boundary layer scheme [s] 
    5455 
    55    REAL(wp), DIMENSION(jpi,jpj), PUBLIC ::   utr_bbl  , vtr_bbl   ! u- (v-) transport in the bottom boundary layer 
    56    REAL(wp), DIMENSION(jpi,jpj), PUBLIC ::   ahu_bbl  , ahv_bbl   ! masked diffusive bbl coefficients at u and v-points 
    57  
    58    INTEGER , DIMENSION(jpi,jpj) ::   mbku_d   , mbkv_d      ! vertical index of the "lower" bottom ocean U/V-level 
    59    INTEGER , DIMENSION(jpi,jpj) ::   mgrhu    , mgrhv       ! = +/-1, sign of grad(H) in u-(v-)direction 
    60    REAL(wp), DIMENSION(jpi,jpj) ::   ahu_bbl_0, ahv_bbl_0   ! diffusive bbl flux coefficients at u and v-points 
    61    REAL(wp), DIMENSION(jpi,jpj) ::   e3u_bbl_0, e3v_bbl_0   ! thichness of the bbl (e3) at u and v-points 
    62    REAL(wp), DIMENSION(jpi,jpj) ::   e1e2t_r   ! thichness of the bbl (e3) at u and v-points 
    63    LOGICAL, PUBLIC              ::   l_bbl                    !: flag to compute bbl diffu. flux coef and transport 
     56   LOGICAL , PUBLIC ::   l_bbl                  !: flag to compute bbl diffu. flux coef and transport 
     57    
     58   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:), PUBLIC ::   utr_bbl  , vtr_bbl   ! u- (v-) transport in the bottom boundary layer 
     59   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:), PUBLIC ::   ahu_bbl  , ahv_bbl   ! masked diffusive bbl coeff. at u & v-pts 
     60 
     61   INTEGER , ALLOCATABLE, SAVE, DIMENSION(:,:) ::   mbku_d   , mbkv_d      ! vertical index of the "lower" bottom ocean U/V-level 
     62   INTEGER , ALLOCATABLE, SAVE, DIMENSION(:,:) ::   mgrhu    , mgrhv       ! = +/-1, sign of grad(H) in u-(v-)direction 
     63   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ahu_bbl_0, ahv_bbl_0   ! diffusive bbl flux coefficients at u and v-points 
     64   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   e3u_bbl_0, e3v_bbl_0   ! thichness of the bbl (e3) at u and v-points 
     65   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   r1_e1e2t               ! inverse of the cell surface at t-point      [1/m2] 
    6466 
    6567   !! * Substitutions 
     
    7274   !!---------------------------------------------------------------------- 
    7375CONTAINS 
     76 
     77   INTEGER FUNCTION tra_bbl_alloc() 
     78      !!---------------------------------------------------------------------- 
     79      !!                ***  FUNCTION tra_bbl_alloc  *** 
     80      !!---------------------------------------------------------------------- 
     81      ALLOCATE( utr_bbl  (jpi,jpj) , ahu_bbl  (jpi,jpj) , mbku_d  (jpi,jpj) , mgrhu(jpi,jpj) ,     & 
     82         &      vtr_bbl  (jpi,jpj) , ahv_bbl  (jpi,jpj) , mbkv_d  (jpi,jpj) , mgrhv(jpi,jpj) ,     & 
     83         &      ahu_bbl_0(jpi,jpj) , ahv_bbl_0(jpi,jpj) ,                                          & 
     84         &      e3u_bbl_0(jpi,jpj) , e3v_bbl_0(jpi,jpj) , r1_e1e2t(jpi,jpj)                  , STAT= tra_bbl_alloc ) 
     85         ! 
     86      IF( lk_mpp            )   CALL mpp_sum ( tra_bbl_alloc ) 
     87      IF( tra_bbl_alloc > 0 )   CALL ctl_warn('tra_bbl_alloc: allocation of arrays failed.') 
     88   END FUNCTION tra_bbl_alloc 
     89 
    7490 
    7591   SUBROUTINE tra_bbl( kt ) 
     
    153169      !!              Campin, J.-M., and H. Goosse, 1999, Tellus, 412-430. 
    154170      !!----------------------------------------------------------------------   
    155       INTEGER                              , INTENT(in   ) ::   kjpt    ! number of tracers 
    156       REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb   ! before and now tracer fields 
    157       REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::   pta   ! tracer trend  
    158       !! 
     171      USE wrk_nemo, ONLY:   wrk_in_use, wrk_not_released 
     172      USE wrk_nemo, ONLY:   zptb => wrk_2d_1 
     173      ! 
     174      INTEGER                              , INTENT(in   ) ::   kjpt   ! number of tracers 
     175      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb    ! before and now tracer fields 
     176      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::   pta    ! tracer trend  
     177      ! 
    159178      INTEGER  ::   ji, jj, jn   ! dummy loop indices 
    160179      INTEGER  ::   ik           ! local integers 
    161180      REAL(wp) ::   zbtr         ! local scalars 
    162       REAL(wp), DIMENSION(jpi,jpj) ::   zptb   ! tracer trend  
    163       !!---------------------------------------------------------------------- 
     181      !!---------------------------------------------------------------------- 
     182      ! 
     183      IF( wrk_in_use(2,1) ) THEN 
     184         CALL ctl_stop('tra_bbl_dif: ERROR: requested workspace array unavailable')   ;   RETURN 
     185      ENDIF 
    164186      ! 
    165187      DO jn = 1, kjpt                                     ! tracer loop 
     
    185207#  endif 
    186208               ik = mbkt(ji,jj)                            ! bottom T-level index 
    187                zbtr = e1e2t_r(ji,jj)  / fse3t(ji,jj,ik) 
     209               zbtr = r1_e1e2t(ji,jj)  / fse3t(ji,jj,ik) 
    188210               pta(ji,jj,ik,jn) = pta(ji,jj,ik,jn)                                                         & 
    189211                  &               + (   ahu_bbl(ji  ,jj  ) * ( zptb(ji+1,jj  ) - zptb(ji  ,jj  ) )   & 
     
    196218      END DO                                                ! end tracer 
    197219      !                                                     ! =========== 
     220      IF( wrk_not_released(2,1) )   CALL ctl_stop('tra_bbl_dif: failed to release workspace array') 
     221      ! 
    198222   END SUBROUTINE tra_bbl_dif 
    199223    
     
    214238      !!              Campin, J.-M., and H. Goosse, 1999, Tellus, 412-430. 
    215239      !!----------------------------------------------------------------------   
    216       INTEGER                              , INTENT(in   ) ::   kjpt    ! number of tracers 
    217       REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb   ! before and now tracer fields 
    218       REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::   pta   ! tracer trend  
    219       !! 
     240      INTEGER                              , INTENT(in   ) ::   kjpt   ! number of tracers 
     241      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb    ! before and now tracer fields 
     242      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::   pta    ! tracer trend  
     243      ! 
    220244      INTEGER  ::   ji, jj, jk, jn           ! dummy loop indices 
    221245      INTEGER  ::   iis , iid , ijs , ijd    ! local integers 
     
    242266                  ! 
    243267                  !                                               ! up  -slope T-point (shelf bottom point) 
    244                   zbtr = e1e2t_r(iis,jj) / fse3t(iis,jj,ikus) 
     268                  zbtr = r1_e1e2t(iis,jj) / fse3t(iis,jj,ikus) 
    245269                  ztra = zu_bbl * ( ptb(iid,jj,ikus,jn) - ptb(iis,jj,ikus,jn) ) * zbtr 
    246270                  pta(iis,jj,ikus,jn) = pta(iis,jj,ikus,jn) + ztra 
    247271                  !                    
    248272                  DO jk = ikus, ikud-1                            ! down-slope upper to down T-point (deep column) 
    249                      zbtr = e1e2t_r(iid,jj) / fse3t(iid,jj,jk) 
     273                     zbtr = r1_e1e2t(iid,jj) / fse3t(iid,jj,jk) 
    250274                     ztra = zu_bbl * ( ptb(iid,jj,jk+1,jn) - ptb(iid,jj,jk,jn) ) * zbtr 
    251275                     pta(iid,jj,jk,jn) = pta(iid,jj,jk,jn) + ztra 
    252276                  END DO 
    253277                  !  
    254                   zbtr = e1e2t_r(iid,jj) / fse3t(iid,jj,ikud) 
     278                  zbtr = r1_e1e2t(iid,jj) / fse3t(iid,jj,ikud) 
    255279                  ztra = zu_bbl * ( ptb(iis,jj,ikus,jn) - ptb(iid,jj,ikud,jn) ) * zbtr 
    256280                  pta(iid,jj,ikud,jn) = pta(iid,jj,ikud,jn) + ztra 
     
    264288                  !  
    265289                  ! up  -slope T-point (shelf bottom point) 
    266                   zbtr = e1e2t_r(ji,ijs) / fse3t(ji,ijs,ikvs) 
     290                  zbtr = r1_e1e2t(ji,ijs) / fse3t(ji,ijs,ikvs) 
    267291                  ztra = zv_bbl * ( ptb(ji,ijd,ikvs,jn) - ptb(ji,ijs,ikvs,jn) ) * zbtr 
    268292                  pta(ji,ijs,ikvs,jn) = pta(ji,ijs,ikvs,jn) + ztra 
    269293                  !                    
    270294                  DO jk = ikvs, ikvd-1                            ! down-slope upper to down T-point (deep column) 
    271                      zbtr = e1e2t_r(ji,ijd) / fse3t(ji,ijd,jk) 
     295                     zbtr = r1_e1e2t(ji,ijd) / fse3t(ji,ijd,jk) 
    272296                     ztra = zv_bbl * ( ptb(ji,ijd,jk+1,jn) - ptb(ji,ijd,jk,jn) ) * zbtr 
    273297                     pta(ji,ijd,jk,jn) = pta(ji,ijd,jk,jn)  + ztra 
    274298                  END DO 
    275299                  !                                               ! down-slope T-point (deep bottom point) 
    276                   zbtr = e1e2t_r(ji,ijd) / fse3t(ji,ijd,ikvd) 
     300                  zbtr = r1_e1e2t(ji,ijd) / fse3t(ji,ijd,ikvd) 
    277301                  ztra = zv_bbl * ( ptb(ji,ijs,ikvs,jn) - ptb(ji,ijd,ikvd,jn) ) * zbtr 
    278302                  pta(ji,ijd,ikvd,jn) = pta(ji,ijd,ikvd,jn) + ztra 
     
    314338      !!              Campin, J.-M., and H. Goosse, 1999, Tellus, 412-430. 
    315339      !!----------------------------------------------------------------------   
     340      USE wrk_nemo, ONLY:   wrk_in_use, wrk_not_released 
     341      USE wrk_nemo, ONLY:   zub => wrk_2d_1 , ztb => wrk_2d_2                      ! 2D workspace 
     342      USE wrk_nemo, ONLY:   zvb => wrk_2d_3 , zsb => wrk_2d_4 , zdep => wrk_2d_5 
     343      ! 
    316344      INTEGER         , INTENT(in   ) ::   kt       ! ocean time-step index 
    317345      CHARACTER(len=3), INTENT(in   ) ::   cdtype   ! =TRA or TRC (tracer indicator) 
     
    323351      REAL(wp) ::   zsign, zsigna, zgbbl      ! local scalars 
    324352      REAL(wp) ::   zgdrho, zt, zs, zh        !   -      - 
    325       REAL(wp), DIMENSION(jpi,jpj) ::   zub, zvb, ztb, zsb, zdep  !  2D workspace 
    326353      !! 
    327354      REAL(wp) ::   fsalbt, fsbeta, pft, pfs, pfh   ! statement function 
     
    357384                                          - 0.121555e-07 ) * pfh 
    358385      !!---------------------------------------------------------------------- 
    359        
     386 
     387      IF( wrk_in_use(2, 1,2,3,4,5) ) THEN 
     388         CALL ctl_stop('bbl: requested workspace arrays unavailable')   ;   RETURN 
     389      ENDIF 
     390      
    360391      IF( kt == nit000 )  THEN 
    361392         IF(lwp)  WRITE(numout,*) 
     
    494525      ENDIF 
    495526      ! 
     527      IF( wrk_not_released(2, 1,2,3,4,5) )   CALL ctl_stop('bbl: failed to release workspace arrays') 
     528      ! 
    496529   END SUBROUTINE bbl 
    497530 
     
    504537      !! 
    505538      !! ** Method  :   Read the nambbl namelist and check the parameters 
    506       !!              called by tra_bbl at the first timestep (nit000) 
    507       !!---------------------------------------------------------------------- 
     539      !!              called by nemo_init at the first timestep (nit000) 
     540      !!---------------------------------------------------------------------- 
     541      USE wrk_nemo, ONLY:   wrk_in_use, wrk_not_released 
     542      USE wrk_nemo, ONLY:   zmbk => wrk_2d_1       ! 2D workspace 
    508543      INTEGER ::   ji, jj               ! dummy loop indices 
    509544      INTEGER ::   ii0, ii1, ij0, ij1   ! temporary integer 
    510       REAL(wp), DIMENSION(jpi,jpj) ::   zmbk   ! 2D workspace  
    511545      !! 
    512546      NAMELIST/nambbl/ nn_bbl_ldf, nn_bbl_adv, rn_ahtbbl, rn_gambbl 
    513547      !!---------------------------------------------------------------------- 
     548 
     549      IF( wrk_in_use(2,1) ) THEN 
     550         CALL ctl_stop('tra_bbl_init: requested workspace array unavailable')   ;   RETURN 
     551      ENDIF 
    514552 
    515553      REWIND ( numnam )              !* Read Namelist nambbl : bottom boundary layer scheme 
     
    528566         WRITE(numout,*) '          advective bbl coefficient           rn_gambbl  = ', rn_gambbl, ' s' 
    529567      ENDIF 
    530        
     568 
     569      !                              ! allocate trabbl arrays 
     570      IF( tra_bbl_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'tra_bbl_init : unable to allocate arrays' ) 
     571      
    531572      IF( nn_bbl_adv == 1 )    WRITE(numout,*) '       * Advective BBL using upper velocity' 
    532573      IF( nn_bbl_adv == 2 )    WRITE(numout,*) '       * Advective BBL using velocity = F( delta rho)' 
     
    536577 
    537578      !                             !* inverse of surface of T-cells 
    538       e1e2t_r(:,:) = 1.0 / ( e1t(:,:) * e2t(:,:) ) 
     579      r1_e1e2t(:,:) = 1._wp / ( e1t(:,:) * e2t(:,:) ) 
    539580       
    540581      !                             !* vertical index of  "deep" bottom u- and v-points 
     
    594635      ENDIF 
    595636      ! 
     637      IF( wrk_not_released(2,1) )   CALL ctl_stop('tra_bbl_init: failed to release workspace array') 
     638      ! 
    596639   END SUBROUTINE tra_bbl_init 
    597640 
Note: See TracChangeset for help on using the changeset viewer.