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.
sbcmod.F90 in NEMO/branches/2020/dev_r14116_HPC-04_mcastril_Mixed_Precision_implementation_final/src/OCE/SBC – NEMO

source: NEMO/branches/2020/dev_r14116_HPC-04_mcastril_Mixed_Precision_implementation_final/src/OCE/SBC/sbcmod.F90 @ 14495

Last change on this file since 14495 was 14219, checked in by mcastril, 4 years ago

Add Mixed Precision support by Oriol Tintó

  • Property svn:keywords set to Id
File size: 35.3 KB
RevLine 
[888]1MODULE sbcmod
2   !!======================================================================
3   !!                       ***  MODULE  sbcmod  ***
4   !! Surface module :  provide to the ocean its surface boundary condition
5   !!======================================================================
[2528]6   !! History :  3.0  ! 2006-07  (G. Madec)  Original code
7   !!            3.1  ! 2008-08  (S. Masson, A. Caubel, E. Maisonnave, G. Madec) coupled interface
8   !!            3.3  ! 2010-04  (M. Leclair, G. Madec)  Forcing averaged over 2 time steps
9   !!            3.3  ! 2010-10  (S. Masson)  add diurnal cycle
10   !!            3.3  ! 2010-09  (D. Storkey) add ice boundary conditions (BDY)
11   !!             -   ! 2010-11  (G. Madec) ice-ocean stress always computed at each ocean time-step
12   !!             -   ! 2010-10  (J. Chanut, C. Bricaud, G. Madec)  add the surface pressure forcing
[3294]13   !!            3.4  ! 2011-11  (C. Harris) CICE added as an option
[3625]14   !!            3.5  ! 2012-11  (A. Coward, G. Madec) Rethink of heat, mass and salt surface fluxes
[7646]15   !!            3.6  ! 2014-11  (P. Mathiot, C. Harris) add ice shelves melting
16   !!            4.0  ! 2016-06  (L. Brodeau) new general bulk formulation
[12377]17   !!            4.0  ! 2019-03  (F. Lemarié & G. Samson)  add ABL compatibility (ln_abl=TRUE)
[14072]18   !!            4.2  ! 2020-12  (G. Madec, E. Clementi) modified wave forcing and coupling
[888]19   !!----------------------------------------------------------------------
20
21   !!----------------------------------------------------------------------
[6140]22   !!   sbc_init      : read namsbc namelist
23   !!   sbc           : surface ocean momentum, heat and freshwater boundary conditions
[7646]24   !!   sbc_final     : Finalize CICE ice model (if used)
[888]25   !!----------------------------------------------------------------------
[6140]26   USE oce            ! ocean dynamics and tracers
27   USE dom_oce        ! ocean space and time domain
[12377]28   USE closea         ! closed seas
[6140]29   USE phycst         ! physical constants
[14072]30   USE sbc_phy, ONLY : pp_cldf
[6140]31   USE sbc_oce        ! Surface boundary condition: ocean fields
32   USE trc_oce        ! shared ocean-passive tracers variables
33   USE sbc_ice        ! Surface boundary condition: ice fields
34   USE sbcdcy         ! surface boundary condition: diurnal cycle
35   USE sbcssm         ! surface boundary condition: sea-surface mean variables
36   USE sbcflx         ! surface boundary condition: flux formulation
[7646]37   USE sbcblk         ! surface boundary condition: bulk formulation
[12377]38   USE sbcabl         ! atmospheric boundary layer
[6140]39   USE sbcice_if      ! surface boundary condition: ice-if sea-ice model
[9570]40#if defined key_si3
[9656]41   USE icestp         ! surface boundary condition: SI3 sea-ice model
[9019]42#endif
[9656]43   USE sbcice_cice    ! surface boundary condition: CICE sea-ice model
[7646]44   USE sbccpl         ! surface boundary condition: coupled formulation
[6140]45   USE cpl_oasis3     ! OASIS routines for coupling
[12377]46   USE sbcclo         ! surface boundary condition: closed sea correction
[6140]47   USE sbcssr         ! surface boundary condition: sea surface restoring
48   USE sbcrnf         ! surface boundary condition: runoffs
[14072]49   USE sbcapr         ! surface boundary condition: atmo pressure
[6140]50   USE sbcfwb         ! surface boundary condition: freshwater budget
51   USE icbstp         ! Icebergs
[9940]52   USE icb_oce  , ONLY : ln_passive_mode      ! iceberg interaction mode
[6140]53   USE traqsr         ! active tracers: light penetration
54   USE sbcwave        ! Wave module
[7646]55   USE bdy_oce   , ONLY: ln_bdy
56   USE usrdef_sbc     ! user defined: surface boundary condition
[9161]57   USE closea         ! closed sea
[14007]58   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
[6140]59   !
60   USE prtctl         ! Print control                    (prt_ctl routine)
61   USE iom            ! IOM library
62   USE in_out_manager ! I/O manager
63   USE lib_mpp        ! MPP library
64   USE timing         ! Timing
[10499]65   USE wet_dry
[12377]66   USE diu_bulk, ONLY:   ln_diurnal_only   ! diurnal SST diagnostic
[888]67
68   IMPLICIT NONE
69   PRIVATE
70
71   PUBLIC   sbc        ! routine called by step.F90
[1725]72   PUBLIC   sbc_init   ! routine called by opa.F90
[7646]73
[888]74   INTEGER ::   nsbc   ! type of surface boundary condition (deduced from namsbc informations)
[14007]75   !! * Substitutions
76#  include "do_loop_substitute.h90"
[14219]77#  include "single_precision_substitute.h90"
[888]78   !!----------------------------------------------------------------------
[10068]79   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
[1146]80   !! $Id$
[10068]81   !! Software governed by the CeCILL license (see ./LICENSE)
[888]82   !!----------------------------------------------------------------------
83CONTAINS
84
[12377]85   SUBROUTINE sbc_init( Kbb, Kmm, Kaa )
[888]86      !!---------------------------------------------------------------------
87      !!                    ***  ROUTINE sbc_init ***
88      !!
89      !! ** Purpose :   Initialisation of the ocean surface boundary computation
90      !!
91      !! ** Method  :   Read the namsbc namelist and set derived parameters
[3607]92      !!                Call init routines for all other SBC modules that have one
[888]93      !!
94      !! ** Action  : - read namsbc parameters
95      !!              - nsbc: type of sbc
96      !!----------------------------------------------------------------------
[12377]97      INTEGER, INTENT(in) ::   Kbb, Kmm, Kaa         ! ocean time level indices
[7646]98      INTEGER ::   ios, icpt                         ! local integer
99      LOGICAL ::   ll_purecpl, ll_opa, ll_not_nemo   ! local logical
[1037]100      !!
[7646]101      NAMELIST/namsbc/ nn_fsbc  ,                                                    &
[12377]102         &             ln_usr   , ln_flx   , ln_blk   , ln_abl,                      &
[9019]103         &             ln_cpl   , ln_mixcpl, nn_components,                          &
104         &             nn_ice   , ln_ice_embd,                                       &
[7646]105         &             ln_traqsr, ln_dm2dc ,                                         &
[14007]106         &             ln_rnf   , nn_fwb     , ln_ssr   , ln_apr_dyn,                &
107         &             ln_wave  , nn_lsm
[1037]108      !!----------------------------------------------------------------------
[6140]109      !
[888]110      IF(lwp) THEN
111         WRITE(numout,*)
112         WRITE(numout,*) 'sbc_init : surface boundary condition setting'
113         WRITE(numout,*) '~~~~~~~~ '
114      ENDIF
[6140]115      !
[7646]116      !                       !**  read Surface Module namelist
[4147]117      READ  ( numnam_ref, namsbc, IOSTAT = ios, ERR = 901)
[11536]118901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc in reference namelist' )
[4147]119      READ  ( numnam_cfg, namsbc, IOSTAT = ios, ERR = 902 )
[11536]120902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc in configuration namelist' )
[6140]121      IF(lwm) WRITE( numond, namsbc )
122      !
[10425]123#if defined key_mpp_mpi
124      ncom_fsbc = nn_fsbc    ! make nn_fsbc available for lib_mpp
125#endif
[13477]126#if ! defined key_si3
127      IF( nn_ice == 2 )    nn_ice = 0  ! without key key_si3 you cannot use si3...
128#endif
[7646]129      !
[13216]130      !
[7646]131      IF(lwp) THEN                  !* Control print
132         WRITE(numout,*) '   Namelist namsbc (partly overwritten with CPP key setting)'
133         WRITE(numout,*) '      frequency update of sbc (and ice)             nn_fsbc       = ', nn_fsbc
134         WRITE(numout,*) '      Type of air-sea fluxes : '
135         WRITE(numout,*) '         user defined formulation                   ln_usr        = ', ln_usr
136         WRITE(numout,*) '         flux         formulation                   ln_flx        = ', ln_flx
137         WRITE(numout,*) '         bulk         formulation                   ln_blk        = ', ln_blk
[12377]138         WRITE(numout,*) '         ABL          formulation                   ln_abl        = ', ln_abl
[14007]139         WRITE(numout,*) '         Surface wave (forced or coupled)           ln_wave       = ', ln_wave
[7646]140         WRITE(numout,*) '      Type of coupling (Ocean/Ice/Atmosphere) : '
141         WRITE(numout,*) '         ocean-atmosphere coupled formulation       ln_cpl        = ', ln_cpl
142         WRITE(numout,*) '         mixed forced-coupled     formulation       ln_mixcpl     = ', ln_mixcpl
[14072]143!!gm  lk_oasis is controlled by key_oasis3  ===>>>  It shoud be removed from the namelist
[7646]144         WRITE(numout,*) '         OASIS coupling (with atm or sas)           lk_oasis      = ', lk_oasis
145         WRITE(numout,*) '         components of your executable              nn_components = ', nn_components
146         WRITE(numout,*) '      Sea-ice : '
147         WRITE(numout,*) '         ice management in the sbc (=0/1/2/3)       nn_ice        = ', nn_ice
[9019]148         WRITE(numout,*) '         ice embedded into ocean                    ln_ice_embd   = ', ln_ice_embd
[7646]149         WRITE(numout,*) '      Misc. options of sbc : '
150         WRITE(numout,*) '         Light penetration in temperature Eq.       ln_traqsr     = ', ln_traqsr
151         WRITE(numout,*) '            daily mean to diurnal cycle qsr            ln_dm2dc   = ', ln_dm2dc
152         WRITE(numout,*) '         Sea Surface Restoring on SST and/or SSS    ln_ssr        = ', ln_ssr
153         WRITE(numout,*) '         FreshWater Budget control  (=0/1/2)        nn_fwb        = ', nn_fwb
154         WRITE(numout,*) '         Patm gradient added in ocean & ice Eqs.    ln_apr_dyn    = ', ln_apr_dyn
155         WRITE(numout,*) '         runoff / runoff mouths                     ln_rnf        = ', ln_rnf
156         WRITE(numout,*) '         nb of iterations if land-sea-mask applied  nn_lsm        = ', nn_lsm
[888]157      ENDIF
[6140]158      !
[7646]159      IF( .NOT.ln_usr ) THEN     ! the model calendar needs some specificities (except in user defined case)
[12489]160         IF( MOD( rday , rn_Dt ) /= 0. )   CALL ctl_stop( 'the time step must devide the number of second of in a day' )
[7646]161         IF( MOD( rday , 2.  ) /= 0. )   CALL ctl_stop( 'the number of second of in a day must be an even number'    )
[12489]162         IF( MOD( rn_Dt  , 2.  ) /= 0. )   CALL ctl_stop( 'the time step (in second) must be an even number'           )
[888]163      ENDIF
[7646]164      !                       !**  check option consistency
[4161]165      !
[14072]166      IF(lwp) WRITE(numout,*)       !* Single / Multi - executable (NEMO / OPA+SAS)
[7646]167      SELECT CASE( nn_components )
168      CASE( jp_iam_nemo )
[9190]169         IF(lwp) WRITE(numout,*) '   ==>>>   NEMO configured as a single executable (i.e. including both OPA and Surface module)'
[7646]170      CASE( jp_iam_opa  )
[9190]171         IF(lwp) WRITE(numout,*) '   ==>>>   Multi executable configuration. Here, OPA component'
[7646]172         IF( .NOT.lk_oasis )   CALL ctl_stop( 'sbc_init : OPA-SAS coupled via OASIS, but key_oasis3 disabled' )
173         IF( ln_cpl        )   CALL ctl_stop( 'sbc_init : OPA-SAS coupled via OASIS, but ln_cpl = T in OPA'   )
174         IF( ln_mixcpl     )   CALL ctl_stop( 'sbc_init : OPA-SAS coupled via OASIS, but ln_mixcpl = T in OPA' )
175      CASE( jp_iam_sas  )
[9190]176         IF(lwp) WRITE(numout,*) '   ==>>>   Multi executable configuration. Here, SAS component'
[7646]177         IF( .NOT.lk_oasis )   CALL ctl_stop( 'sbc_init : OPA-SAS coupled via OASIS, but key_oasis3 disabled' )
178         IF( ln_mixcpl     )   CALL ctl_stop( 'sbc_init : OPA-SAS coupled via OASIS, but ln_mixcpl = T in OPA' )
179      CASE DEFAULT
180         CALL ctl_stop( 'sbc_init : unsupported value for nn_components' )
181      END SELECT
182      !                             !* coupled options
183      IF( ln_cpl ) THEN
184         IF( .NOT. lk_oasis )   CALL ctl_stop( 'sbc_init : coupled mode with an atmosphere model (ln_cpl=T)',   &
185            &                                  '           required to defined key_oasis3' )
186      ENDIF
187      IF( ln_mixcpl ) THEN
188         IF( .NOT. lk_oasis )   CALL ctl_stop( 'sbc_init : mixed forced-coupled mode (ln_mixcpl=T) ',   &
189            &                                  '           required to defined key_oasis3' )
190         IF( .NOT.ln_cpl    )   CALL ctl_stop( 'sbc_init : mixed forced-coupled mode (ln_mixcpl=T) requires ln_cpl = T' )
191         IF( nn_components /= jp_iam_nemo )    &
192            &                   CALL ctl_stop( 'sbc_init : the mixed forced-coupled mode (ln_mixcpl=T) ',   &
193            &                                   '          not yet working with sas-opa coupling via oasis' )
194      ENDIF
195      !                             !* sea-ice
196      SELECT CASE( nn_ice )
197      CASE( 0 )                        !- no ice in the domain
[14072]198      CASE( 1 )                        !- Ice-cover climatology ("Ice-if" model)
[9656]199      CASE( 2 )                        !- SI3  ice model
[12377]200         IF( .NOT.( ln_blk .OR. ln_cpl .OR. ln_abl .OR. ln_usr ) )   &
201            &                   CALL ctl_stop( 'sbc_init : SI3 sea-ice model requires ln_blk or ln_cpl or ln_abl or ln_usr = T' )
[9019]202      CASE( 3 )                        !- CICE ice model
[12377]203         IF( .NOT.( ln_blk .OR. ln_cpl .OR. ln_abl .OR. ln_usr ) )   &
204            &                   CALL ctl_stop( 'sbc_init : CICE sea-ice model requires ln_blk or ln_cpl or ln_abl or ln_usr = T' )
205         IF( lk_agrif                                )   &
[14072]206            &                   CALL ctl_stop( 'sbc_init : CICE sea-ice model not currently available with AGRIF' )
[7646]207      CASE DEFAULT                     !- not supported
208      END SELECT
[13722]209      IF( ln_diurnal .AND. .NOT. (ln_blk.OR.ln_abl) )   CALL ctl_stop( "sbc_init: diurnal flux processing only implemented for bulk forcing" )
[7646]210      !
211      !                       !**  allocate and set required variables
212      !
213      !                             !* allocate sbc arrays
[5836]214      IF( sbc_oce_alloc() /= 0 )   CALL ctl_stop( 'sbc_init : unable to allocate sbc_oce arrays' )
[9570]215#if ! defined key_si3 && ! defined key_cice
[9019]216      IF( sbc_ice_alloc() /= 0 )   CALL ctl_stop( 'sbc_init : unable to allocate sbc_ice arrays' )
217#endif
[7646]218      !
[12276]219      !
220      IF( sbc_ssr_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'sbc_init : unable to allocate sbc_ssr arrays' )
[14072]221      IF( .NOT.ln_ssr ) THEN               !* Initialize qrp and erp if no restoring
[12276]222         qrp(:,:) = 0._wp
223         erp(:,:) = 0._wp
224      ENDIF
225      !
[7646]226      IF( nn_ice == 0 ) THEN        !* No sea-ice in the domain : ice fraction is always zero
[7753]227         IF( nn_components /= jp_iam_opa )   fr_i(:,:) = 0._wp    ! except for OPA in SAS-OPA coupled case
[7646]228      ENDIF
229      !
[7753]230      sfx   (:,:) = 0._wp           !* salt flux due to freezing/melting
231      fmmflx(:,:) = 0._wp           !* freezing minus melting flux
[13546]232      cloud_fra(:,:) = pp_cldf      !* cloud fraction over sea ice (used in si3)
[1037]233
[7753]234      taum(:,:) = 0._wp             !* wind stress module (needed in GLS in case of reduced restart)
235
[2528]236      !                          ! Choice of the Surface Boudary Condition (set nsbc)
[12377]237      nday_qsr = -1   ! allow initialization at the 1st call !LB: now warm-layer of COARE* calls "sbc_dcy_param" of sbcdcy.F90!
[7646]238      IF( ln_dm2dc ) THEN           !* daily mean to diurnal cycle
[12377]239         !LB:nday_qsr = -1   ! allow initialization at the 1st call
240         IF( .NOT.( ln_flx .OR. ln_blk .OR. ln_abl ) .AND. nn_components /= jp_iam_opa )   &
241            &   CALL ctl_stop( 'qsr diurnal cycle from daily values requires flux, bulk or abl formulation' )
[7646]242      ENDIF
243      !                             !* Choice of the Surface Boudary Condition
244      !                             (set nsbc)
[5407]245      !
[7646]246      ll_purecpl  = ln_cpl .AND. .NOT.ln_mixcpl
247      ll_opa      = nn_components == jp_iam_opa
248      ll_not_nemo = nn_components /= jp_iam_nemo
[888]249      icpt = 0
[7646]250      !
251      IF( ln_usr          ) THEN   ;   nsbc = jp_usr     ; icpt = icpt + 1   ;   ENDIF       ! user defined         formulation
[5407]252      IF( ln_flx          ) THEN   ;   nsbc = jp_flx     ; icpt = icpt + 1   ;   ENDIF       ! flux                 formulation
[7646]253      IF( ln_blk          ) THEN   ;   nsbc = jp_blk     ; icpt = icpt + 1   ;   ENDIF       ! bulk                 formulation
[12377]254      IF( ln_abl          ) THEN   ;   nsbc = jp_abl     ; icpt = icpt + 1   ;   ENDIF       ! ABL                  formulation
[5407]255      IF( ll_purecpl      ) THEN   ;   nsbc = jp_purecpl ; icpt = icpt + 1   ;   ENDIF       ! Pure Coupled         formulation
[7646]256      IF( ll_opa          ) THEN   ;   nsbc = jp_none    ; icpt = icpt + 1   ;   ENDIF       ! opa coupling via SAS module
[2528]257      !
[7646]258      IF( icpt /= 1 )    CALL ctl_stop( 'sbc_init : choose ONE and only ONE sbc option' )
[5836]259      !
[7646]260      IF(lwp) THEN                     !- print the choice of surface flux formulation
[888]261         WRITE(numout,*)
[6140]262         SELECT CASE( nsbc )
[9190]263         CASE( jp_usr     )   ;   WRITE(numout,*) '   ==>>>   user defined forcing formulation'
264         CASE( jp_flx     )   ;   WRITE(numout,*) '   ==>>>   flux formulation'
265         CASE( jp_blk     )   ;   WRITE(numout,*) '   ==>>>   bulk formulation'
[12377]266         CASE( jp_abl     )   ;   WRITE(numout,*) '   ==>>>   ABL  formulation'
[9190]267         CASE( jp_purecpl )   ;   WRITE(numout,*) '   ==>>>   pure coupled formulation'
[7646]268!!gm abusive use of jp_none ??   ===>>> need to be check and changed by adding a jp_sas parameter
[9190]269         CASE( jp_none    )   ;   WRITE(numout,*) '   ==>>>   OPA coupled to SAS via oasis'
270            IF( ln_mixcpl )       WRITE(numout,*) '               + forced-coupled mixed formulation'
[6140]271         END SELECT
[9190]272         IF( ll_not_nemo  )       WRITE(numout,*) '               + OASIS coupled SAS'
[888]273      ENDIF
274      !
[7646]275      !                             !* OASIS initialization
276      !
277      IF( lk_oasis )   CALL sbc_cpl_init( nn_ice )   ! Must be done before: (1) first time step
278      !                                              !                      (2) the use of nn_fsbc
[6140]279      !     nn_fsbc initialization if OPA-SAS coupling via OASIS
[7646]280      !     SAS time-step has to be declared in OASIS (mandatory) -> nn_fsbc has to be modified accordingly
[6140]281      IF( nn_components /= jp_iam_nemo ) THEN
[12489]282         IF( nn_components == jp_iam_opa )   nn_fsbc = cpl_freq('O_SFLX') / NINT(rn_Dt)
283         IF( nn_components == jp_iam_sas )   nn_fsbc = cpl_freq('I_SFLX') / NINT(rn_Dt)
[5407]284         !
285         IF(lwp)THEN
286            WRITE(numout,*)
287            WRITE(numout,*)"   OPA-SAS coupled via OASIS : nn_fsbc re-defined from OASIS namcouple ", nn_fsbc
288            WRITE(numout,*)
289         ENDIF
290      ENDIF
[6140]291      !
[7646]292      !                             !* check consistency between model timeline and nn_fsbc
[11536]293      IF( ln_rst_list .OR. nn_stock /= -1 ) THEN   ! we will do restart files
294         IF( MOD( nitend - nit000 + 1, nn_fsbc) /= 0 ) THEN
295            WRITE(ctmp1,*) 'sbc_init : experiment length (', nitend - nit000 + 1, ') is NOT a multiple of nn_fsbc (', nn_fsbc, ')'
296            CALL ctl_stop( ctmp1, 'Impossible to properly do model restart' )
297         ENDIF
298         IF( .NOT. ln_rst_list .AND. MOD( nn_stock, nn_fsbc) /= 0 ) THEN   ! we don't use nn_stock if ln_rst_list
299            WRITE(ctmp1,*) 'sbc_init : nn_stock (', nn_stock, ') is NOT a multiple of nn_fsbc (', nn_fsbc, ')'
300            CALL ctl_stop( ctmp1, 'Impossible to properly do model restart' )
301         ENDIF
[5407]302      ENDIF
303      !
[12489]304      IF( MOD( rday, REAL(nn_fsbc, wp) * rn_Dt ) /= 0 )   &
[7646]305         &  CALL ctl_warn( 'sbc_init : nn_fsbc is NOT a multiple of the number of time steps in a day' )
[5407]306      !
[12489]307      IF( ln_dm2dc .AND. NINT(rday) / ( nn_fsbc * NINT(rn_Dt) ) < 8  )   &
[7646]308         &   CALL ctl_warn( 'sbc_init : diurnal cycle for qsr: the sampling of the diurnal cycle is too small...' )
[4152]309      !
[14072]310
[7646]311      !                       !**  associated modules : initialization
[3764]312      !
[12377]313                          CALL sbc_ssm_init ( Kbb, Kmm ) ! Sea-surface mean fields initialization
[5385]314      !
[12377]315      IF( l_sbc_clo   )   CALL sbc_clo_init              ! closed sea surface initialisation
316      !
[13546]317      IF( ln_blk      )   CALL sbc_blk_init              ! bulk formulae initialization
[7646]318
[13546]319      IF( ln_abl      )   CALL sbc_abl_init              ! Atmospheric Boundary Layer (ABL)
[12377]320
[13546]321      IF( ln_ssr      )   CALL sbc_ssr_init              ! Sea-Surface Restoring initialization
[6140]322      !
[7788]323      !
[12377]324                          CALL sbc_rnf_init( Kmm )       ! Runof initialization
[6140]325      !
[12377]326      IF( ln_apr_dyn )    CALL sbc_apr_init              ! Atmo Pressure Forcing initialization
[8524]327      !
[9570]328#if defined key_si3
[9019]329      IF( lk_agrif .AND. nn_ice == 0 ) THEN            ! allocate ice arrays in case agrif + ice-model + no-ice in child grid
330                          IF( sbc_ice_alloc() /= 0 )   CALL ctl_stop('STOP', 'sbc_ice_alloc : unable to allocate arrays' )
331      ELSEIF( nn_ice == 2 ) THEN
[12377]332                          CALL ice_init( Kbb, Kmm, Kaa )         ! ICE initialization
[9019]333      ENDIF
334#endif
[12377]335      IF( nn_ice == 3 )   CALL cice_sbc_init( nsbc, Kbb, Kmm )   ! CICE initialization
[6140]336      !
[14007]337      IF( ln_wave     ) THEN
338                          CALL sbc_wave_init                     ! surface wave initialisation
339      ELSE
340                          IF(lwp) WRITE(numout,*)
341                          IF(lwp) WRITE(numout,*) '   No surface waves : all wave related logical set to false'
342                          ln_sdw       = .false.
343                          ln_stcor     = .false.
344                          ln_cdgw      = .false.
345                          ln_tauoc     = .false.
346                          ln_wave_test = .false.
347                          ln_charn     = .false.
348                          ln_taw       = .false.
349                          ln_phioc     = .false.
350                          ln_bern_srfc = .false.
351                          ln_breivikFV_2016 = .false.
352                          ln_vortex_force = .false.
353                          ln_stshear  = .false.
354      ENDIF
[7646]355      !
[888]356   END SUBROUTINE sbc_init
357
358
[12377]359   SUBROUTINE sbc( kt, Kbb, Kmm )
[888]360      !!---------------------------------------------------------------------
361      !!                    ***  ROUTINE sbc  ***
[7646]362      !!
[888]363      !! ** Purpose :   provide at each time-step the ocean surface boundary
364      !!                condition (momentum, heat and freshwater fluxes)
365      !!
[7646]366      !! ** Method  :   blah blah  to be written ?????????
[888]367      !!                CAUTION : never mask the surface stress field (tke sbc)
368      !!
[7646]369      !! ** Action  : - set the ocean surface boundary condition at before and now
370      !!                time step, i.e.
[3625]371      !!                utau_b, vtau_b, qns_b, qsr_b, emp_n, sfx_b, qrp_b, erp_b
372      !!                utau  , vtau  , qns  , qsr  , emp  , sfx  , qrp  , erp
[1037]373      !!              - updte the ice fraction : fr_i
[888]374      !!----------------------------------------------------------------------
[7646]375      INTEGER, INTENT(in) ::   kt   ! ocean time step
[12377]376      INTEGER, INTENT(in) ::   Kbb, Kmm   ! ocean time level indices
[14007]377      INTEGER  ::   jj, ji          ! dummy loop argument
[7646]378      !
379      LOGICAL ::   ll_sas, ll_opa   ! local logical
[10499]380      !
381      REAL(wp) ::     zthscl        ! wd  tanh scale
[14072]382      REAL(wp), DIMENSION(jpi,jpj) ::  zwdht, zwght  ! wd dep over wd limit, wgt
[10499]383
[888]384      !!---------------------------------------------------------------------
[3294]385      !
[9124]386      IF( ln_timing )   CALL timing_start('sbc')
[3294]387      !
[2528]388      !                                            ! ---------------------------------------- !
389      IF( kt /= nit000 ) THEN                      !          Swap of forcing fields          !
390         !                                         ! ---------------------------------------- !
[7753]391         utau_b(:,:) = utau(:,:)                         ! Swap the ocean forcing fields
392         vtau_b(:,:) = vtau(:,:)                         ! (except at nit000 where before fields
393         qns_b (:,:) = qns (:,:)                         !  are set at the end of the routine)
394         emp_b (:,:) = emp (:,:)
395         sfx_b (:,:) = sfx (:,:)
[12377]396         IF( ln_rnf ) THEN
[7753]397            rnf_b    (:,:  ) = rnf    (:,:  )
398            rnf_tsc_b(:,:,:) = rnf_tsc(:,:,:)
[6460]399         ENDIF
[7788]400        !
[2528]401      ENDIF
402      !                                            ! ---------------------------------------- !
403      !                                            !        forcing field computation         !
404      !                                            ! ---------------------------------------- !
[1482]405      !
[7646]406      ll_sas = nn_components == jp_iam_sas               ! component flags
407      ll_opa = nn_components == jp_iam_opa
408      !
[12377]409      IF( .NOT.ll_sas )   CALL sbc_ssm ( kt, Kbb, Kmm )  ! mean ocean sea surface variables (sst_m, sss_m, ssu_m, ssv_m)
[7646]410      !
411      !                                            !==  sbc formulation  ==!
[14007]412      !
[14072]413      !
[2528]414      SELECT CASE( nsbc )                                ! Compute ocean surface boundary condition
[3625]415      !                                                  ! (i.e. utau,vtau, qns, qsr, emp, sfx)
[14072]416      CASE( jp_usr   )     ;   CALL usrdef_sbc_oce( kt, Kbb )                        ! user defined formulation
[12377]417      CASE( jp_flx     )   ;   CALL sbc_flx       ( kt )                             ! flux formulation
[7646]418      CASE( jp_blk     )
[12377]419         IF( ll_sas    )       CALL sbc_cpl_rcv   ( kt, nn_fsbc, nn_ice, Kbb, Kmm )   ! OPA-SAS coupling: SAS receiving fields from OPA
[14007]420!!!!!!!!!!! ATTENTION:ln_wave is not only used for oasis coupling !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
421         IF( ln_wave )   THEN
422             IF ( lk_oasis )  CALL sbc_cpl_rcv ( kt, nn_fsbc, nn_ice, Kbb, Kmm )   ! OPA-wave coupling
423             CALL sbc_wave ( kt, Kmm )
424         ENDIF
[7646]425                               CALL sbc_blk       ( kt )                    ! bulk formulation for the ocean
426                               !
[12377]427      CASE( jp_abl     )
428         IF( ll_sas    )       CALL sbc_cpl_rcv   ( kt, nn_fsbc, nn_ice, Kbb, Kmm )   ! OPA-SAS coupling: SAS receiving fields from OPA
429                               CALL sbc_abl       ( kt )                    ! ABL  formulation for the ocean
430                               !
431      CASE( jp_purecpl )   ;   CALL sbc_cpl_rcv   ( kt, nn_fsbc, nn_ice, Kbb, Kmm )   ! pure coupled formulation
[7646]432      CASE( jp_none    )
[12377]433         IF( ll_opa    )       CALL sbc_cpl_rcv   ( kt, nn_fsbc, nn_ice, Kbb, Kmm )  ! OPA-SAS coupling: OPA receiving fields from SAS
[888]434      END SELECT
[7646]435      !
[12377]436      IF( ln_mixcpl )          CALL sbc_cpl_rcv   ( kt, nn_fsbc, nn_ice, Kbb, Kmm )  ! forced-coupled mixed formulation after forcing
[6140]437      !
[14007]438      IF( ln_wave .AND. ln_tauoc )  THEN            ! Wave stress reduction
439         DO_2D( 0, 0, 0, 0)
440            utau(ji,jj) = utau(ji,jj) * ( tauoc_wave(ji,jj) + tauoc_wave(ji-1,jj) ) * 0.5_wp
441            vtau(ji,jj) = vtau(ji,jj) * ( tauoc_wave(ji,jj) + tauoc_wave(ji,jj-1) ) * 0.5_wp
442         END_2D
443         !
[14219]444         CALL lbc_lnk_multi( 'sbcwave', utau, 'U', -1._wp , vtau, 'V', -1._wp )
[14007]445         !
446         taum(:,:) = taum(:,:)*tauoc_wave(:,:)
447         !
448         IF( kt == nit000 )   CALL ctl_warn( 'sbc: You are subtracting the wave stress to the ocean.',   &
449            &                                'If not requested select ln_tauoc=.false.' )
450         !
451      ELSEIF( ln_wave .AND. ln_taw ) THEN                  ! Wave stress reduction
452         utau(:,:) = utau(:,:) - tawx(:,:) + twox(:,:)
453         vtau(:,:) = vtau(:,:) - tawy(:,:) + twoy(:,:)
[14219]454         CALL lbc_lnk_multi( 'sbcwave', utau, 'U', -1._wp, vtau, 'V', -1._wp )
[14007]455         !
456         DO_2D( 0, 0, 0, 0)
457             taum(ji,jj) = sqrt((.5*(utau(ji-1,jj)+utau(ji,jj)))**2 + (.5*(vtau(ji,jj-1)+vtau(ji,jj)))**2)
458         END_2D
459         !
460         IF( kt == nit000 )   CALL ctl_warn( 'sbc: You are subtracting the wave stress to the ocean.',   &
461            &                                'If not requested select ln_taw=.false.' )
462         !
463      ENDIF
[14219]464      CALL lbc_lnk( 'sbcmod', taum(:,:), 'T', 1._wp )
[9023]465      !
[2528]466      !                                            !==  Misc. Options  ==!
[6140]467      !
[3632]468      SELECT CASE( nn_ice )                                       ! Update heat and freshwater fluxes over sea-ice areas
[12377]469      CASE(  1 )   ;         CALL sbc_ice_if   ( kt, Kbb, Kmm )   ! Ice-cover climatology ("Ice-if" model)
[9570]470#if defined key_si3
[12377]471      CASE(  2 )   ;         CALL ice_stp  ( kt, Kbb, Kmm, nsbc ) ! SI3 ice model
[9019]472#endif
473      CASE(  3 )   ;         CALL sbc_ice_cice ( kt, nsbc )       ! CICE ice model
[7646]474      END SELECT
[888]475
[9940]476      IF( ln_icebergs    )   THEN
[14030]477                                     CALL icb_stp( kt, Kmm )           ! compute icebergs
[14072]478         ! Icebergs do not melt over the haloes.
479         ! So emp values over the haloes are no more consistent with the inner domain values.
[12377]480         ! A lbc_lnk is therefore needed to ensure reproducibility and restartability.
481         ! see ticket #2113 for discussion about this lbc_lnk.
[13226]482         IF( .NOT. ln_passive_mode ) CALL lbc_lnk( 'sbcmod', emp, 'T', 1.0_wp ) ! ensure restartability with icebergs
[9940]483      ENDIF
[3609]484
[3632]485      IF( ln_rnf         )   CALL sbc_rnf( kt )                   ! add runoffs to fresh water fluxes
[7646]486
[12377]487      IF( ln_ssr         )   CALL sbc_ssr( kt )                        ! add SST/SSS damping term
[888]488
[12377]489      IF( nn_fwb    /= 0 )   CALL sbc_fwb( kt, nn_fwb, nn_fsbc, Kmm )  ! control the freshwater budget
[888]490
[9161]491      ! Special treatment of freshwater fluxes over closed seas in the model domain
492      ! Should not be run if ln_diurnal_only
[14072]493      IF( l_sbc_clo      )   CALL sbc_clo( kt )
[6140]494
[9439]495!!$!RBbug do not understand why see ticket 667
496!!$!clem: it looks like it is necessary for the north fold (in certain circumstances). Don't know why.
[13226]497!!$      CALL lbc_lnk( 'sbcmod', emp, 'T', 1.0_wp )
[12377]498      IF( ll_wd ) THEN     ! If near WAD point limit the flux for now
[14072]499         zthscl = atanh(rn_wd_sbcfra)                     ! taper frac default is .999
[12377]500         zwdht(:,:) = ssh(:,:,Kmm) + ht_0(:,:) - rn_wdmin1   ! do this calc of water
[10499]501                                                     ! depth above wd limit once
502         WHERE( zwdht(:,:) <= 0.0 )
503            taum(:,:) = 0.0
504            utau(:,:) = 0.0
505            vtau(:,:) = 0.0
506            qns (:,:) = 0.0
507            qsr (:,:) = 0.0
508            emp (:,:) = min(emp(:,:),0.0) !can allow puddles to grow but not shrink
509            sfx (:,:) = 0.0
510         END WHERE
511         zwght(:,:) = tanh(zthscl*zwdht(:,:))
512         WHERE( zwdht(:,:) > 0.0  .and. zwdht(:,:) < rn_wd_sbcdep ) !  5 m hard limit here is arbitrary
513            qsr  (:,:) =  qsr(:,:)  * zwght(:,:)
514            qns  (:,:) =  qns(:,:)  * zwght(:,:)
515            taum (:,:) =  taum(:,:) * zwght(:,:)
516            utau (:,:) =  utau(:,:) * zwght(:,:)
517            vtau (:,:) =  vtau(:,:) * zwght(:,:)
518            sfx  (:,:) =  sfx(:,:)  * zwght(:,:)
519            emp  (:,:) =  emp(:,:)  * zwght(:,:)
520         END WHERE
521      ENDIF
[2502]522      !
[2528]523      IF( kt == nit000 ) THEN                          !   set the forcing field at nit000 - 1    !
524         !                                             ! ---------------------------------------- !
[14053]525         IF( ln_rstart .AND. .NOT.l_1st_euler ) THEN            !* Restart: read in restart file
526            IF(lwp) WRITE(numout,*) '          nit000-1 surface forcing fields read in the restart file'
527            CALL iom_get( numror, jpdom_auto, 'utau_b', utau_b )   ! i-stress
528            CALL iom_get( numror, jpdom_auto, 'vtau_b', vtau_b )   ! j-stress
529            CALL iom_get( numror, jpdom_auto,  'qns_b',  qns_b )   ! non solar heat flux
530            CALL iom_get( numror, jpdom_auto,  'emp_b',  emp_b )   ! freshwater flux
531            ! NB: The 3D heat content due to qsr forcing (qsr_hc_b) is treated in traqsr
[3625]532            ! To ensure restart capability with 3.3x/3.4 restart files    !! to be removed in v3.6
533            IF( iom_varid( numror, 'sfx_b', ldstop = .FALSE. ) > 0 ) THEN
[13970]534               CALL iom_get( numror, jpdom_auto, 'sfx_b', sfx_b )  ! before salt flux (T-point)
[3625]535            ELSE
[7753]536               sfx_b (:,:) = sfx(:,:)
[3625]537            ENDIF
[2528]538         ELSE                                                   !* no restart: set from nit000 values
539            IF(lwp) WRITE(numout,*) '          nit000-1 surface forcing fields set to nit000'
[7753]540            utau_b(:,:) = utau(:,:)
541            vtau_b(:,:) = vtau(:,:)
542            qns_b (:,:) = qns (:,:)
543            emp_b (:,:) = emp (:,:)
544            sfx_b (:,:) = sfx (:,:)
[2528]545         ENDIF
546      ENDIF
547      !                                                ! ---------------------------------------- !
548      IF( lrst_oce ) THEN                              !      Write in the ocean restart file     !
549         !                                             ! ---------------------------------------- !
550         IF(lwp) WRITE(numout,*)
551         IF(lwp) WRITE(numout,*) 'sbc : ocean surface forcing fields written in ocean restart file ',   &
552            &                    'at it= ', kt,' date= ', ndastp
553         IF(lwp) WRITE(numout,*) '~~~~'
[13970]554         CALL iom_rstput( kt, nitrst, numrow, 'utau_b' , utau )
555         CALL iom_rstput( kt, nitrst, numrow, 'vtau_b' , vtau )
556         CALL iom_rstput( kt, nitrst, numrow, 'qns_b'  , qns  )
[2528]557         ! The 3D heat content due to qsr forcing is treated in traqsr
558         ! CALL iom_rstput( kt, nitrst, numrow, 'qsr_b'  , qsr  )
[13970]559         CALL iom_rstput( kt, nitrst, numrow, 'emp_b'  , emp  )
560         CALL iom_rstput( kt, nitrst, numrow, 'sfx_b'  , sfx  )
[2528]561      ENDIF
562      !                                                ! ---------------------------------------- !
563      !                                                !        Outputs and control print         !
564      !                                                ! ---------------------------------------- !
[1482]565      IF( MOD( kt-1, nn_fsbc ) == 0 ) THEN
[14053]566         CALL iom_put( "empmr"  , emp   - rnf )                ! upward water flux
567         CALL iom_put( "empbmr" , emp_b - rnf )                ! before upward water flux ( needed to recalculate the time evolution of ssh in offline )
568         CALL iom_put( "saltflx", sfx         )                ! downward salt flux (includes virtual salt flux beneath ice in linear free surface case)
569         CALL iom_put( "fmmflx" , fmmflx      )                ! Freezing-melting water flux
570         CALL iom_put( "qt"     , qns + qsr   )                ! total heat flux
571         CALL iom_put( "qns"    , qns         )                ! solar heat flux
572         CALL iom_put( "qsr"    ,       qsr   )                ! solar heat flux
[7646]573         IF( nn_ice > 0 .OR. ll_opa )   CALL iom_put( "ice_cover", fr_i )   ! ice fraction
[14053]574         CALL iom_put( "taum"   , taum        )                ! wind stress module
575         CALL iom_put( "wspd"   , wndm        )                ! wind speed  module over free ocean or leads in presence of sea-ice
576         CALL iom_put( "qrp"    , qrp         )                ! heat flux damping
577         CALL iom_put( "erp"    , erp         )                ! freshwater flux damping
[1482]578      ENDIF
579      !
[12377]580      IF(sn_cfctl%l_prtctl) THEN     ! print mean trends (used for debugging)
[14053]581         CALL prt_ctl(tab2d_1=fr_i                , clinfo1=' fr_i     - : ', mask1=tmask )
582         CALL prt_ctl(tab2d_1=(emp-rnf)           , clinfo1=' emp-rnf  - : ', mask1=tmask )
583         CALL prt_ctl(tab2d_1=(sfx-rnf)           , clinfo1=' sfx-rnf  - : ', mask1=tmask )
584         CALL prt_ctl(tab2d_1=qns                 , clinfo1=' qns      - : ', mask1=tmask )
585         CALL prt_ctl(tab2d_1=qsr                 , clinfo1=' qsr      - : ', mask1=tmask )
586         CALL prt_ctl(tab3d_1=tmask               , clinfo1=' tmask    - : ', mask1=tmask, kdim=jpk )
[14219]587         CALL prt_ctl(tab3d_1=CASTWP(ts(:,:,:,jp_tem,Kmm)), clinfo1=' sst      - : ', mask1=tmask, kdim=1   )
588         CALL prt_ctl(tab3d_1=CASTWP(ts(:,:,:,jp_sal,Kmm)), clinfo1=' sss      - : ', mask1=tmask, kdim=1   )
[12377]589         CALL prt_ctl(tab2d_1=utau                , clinfo1=' utau     - : ', mask1=umask,                      &
590            &         tab2d_2=vtau                , clinfo2=' vtau     - : ', mask2=vmask )
[888]591      ENDIF
[3294]592
593      IF( kt == nitend )   CALL sbc_final         ! Close down surface module if necessary
[888]594      !
[9124]595      IF( ln_timing )   CALL timing_stop('sbc')
[3294]596      !
[888]597   END SUBROUTINE sbc
598
[3764]599
[3294]600   SUBROUTINE sbc_final
601      !!---------------------------------------------------------------------
602      !!                    ***  ROUTINE sbc_final  ***
[3764]603      !!
604      !! ** Purpose :   Finalize CICE (if used)
[3294]605      !!---------------------------------------------------------------------
[3764]606      !
[9019]607      IF( nn_ice == 3 )   CALL cice_sbc_final
[3294]608      !
609   END SUBROUTINE sbc_final
610
[888]611   !!======================================================================
612END MODULE sbcmod
Note: See TracBrowser for help on using the repository browser.