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/2021/dev_r14116_HPC-10_mcastril_Mixed_Precision_implementation/src/OCE/SBC – NEMO

source: NEMO/branches/2021/dev_r14116_HPC-10_mcastril_Mixed_Precision_implementation/src/OCE/SBC/sbcmod.F90 @ 15540

Last change on this file since 15540 was 15540, checked in by sparonuz, 3 years ago

Mixed precision version, tested up to 30 years on ORCA2.

  • Property svn:keywords set to Id
File size: 35.4 KB
Line 
1MODULE sbcmod
2   !!======================================================================
3   !!                       ***  MODULE  sbcmod  ***
4   !! Surface module :  provide to the ocean its surface boundary condition
5   !!======================================================================
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
13   !!            3.4  ! 2011-11  (C. Harris) CICE added as an option
14   !!            3.5  ! 2012-11  (A. Coward, G. Madec) Rethink of heat, mass and salt surface fluxes
15   !!            3.6  ! 2014-11  (P. Mathiot, C. Harris) add ice shelves melting
16   !!            4.0  ! 2016-06  (L. Brodeau) new general bulk formulation
17   !!            4.0  ! 2019-03  (F. Lemarié & G. Samson)  add ABL compatibility (ln_abl=TRUE)
18   !!            4.2  ! 2020-12  (G. Madec, E. Clementi) modified wave forcing and coupling
19   !!----------------------------------------------------------------------
20
21   !!----------------------------------------------------------------------
22   !!   sbc_init      : read namsbc namelist
23   !!   sbc           : surface ocean momentum, heat and freshwater boundary conditions
24   !!   sbc_final     : Finalize CICE ice model (if used)
25   !!----------------------------------------------------------------------
26   USE oce            ! ocean dynamics and tracers
27   USE dom_oce        ! ocean space and time domain
28   USE closea         ! closed seas
29   USE phycst         ! physical constants
30   USE sbc_phy, ONLY : pp_cldf
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
37   USE sbcblk         ! surface boundary condition: bulk formulation
38   USE sbcabl         ! atmospheric boundary layer
39   USE sbcice_if      ! surface boundary condition: ice-if sea-ice model
40#if defined key_si3
41   USE icestp         ! surface boundary condition: SI3 sea-ice model
42#endif
43   USE sbcice_cice    ! surface boundary condition: CICE sea-ice model
44   USE sbccpl         ! surface boundary condition: coupled formulation
45   USE cpl_oasis3     ! OASIS routines for coupling
46   USE sbcclo         ! surface boundary condition: closed sea correction
47   USE sbcssr         ! surface boundary condition: sea surface restoring
48   USE sbcrnf         ! surface boundary condition: runoffs
49   USE sbcapr         ! surface boundary condition: atmo pressure
50   USE sbcfwb         ! surface boundary condition: freshwater budget
51   USE icbstp         ! Icebergs
52   USE icb_oce  , ONLY : ln_passive_mode      ! iceberg interaction mode
53   USE traqsr         ! active tracers: light penetration
54   USE sbcwave        ! Wave module
55   USE bdy_oce   , ONLY: ln_bdy
56   USE usrdef_sbc     ! user defined: surface boundary condition
57   USE closea         ! closed sea
58   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
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
65   USE wet_dry
66   USE diu_bulk, ONLY:   ln_diurnal_only   ! diurnal SST diagnostic
67
68   IMPLICIT NONE
69   PRIVATE
70
71   PUBLIC   sbc        ! routine called by step.F90
72   PUBLIC   sbc_init   ! routine called by opa.F90
73
74   INTEGER ::   nsbc   ! type of surface boundary condition (deduced from namsbc informations)
75   !! * Substitutions
76#  include "do_loop_substitute.h90"
77#  include "single_precision_substitute.h90"
78   !!----------------------------------------------------------------------
79   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
80   !! $Id$
81   !! Software governed by the CeCILL license (see ./LICENSE)
82   !!----------------------------------------------------------------------
83CONTAINS
84
85   SUBROUTINE sbc_init( Kbb, Kmm, Kaa )
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
92      !!                Call init routines for all other SBC modules that have one
93      !!
94      !! ** Action  : - read namsbc parameters
95      !!              - nsbc: type of sbc
96      !!----------------------------------------------------------------------
97      INTEGER, INTENT(in) ::   Kbb, Kmm, Kaa         ! ocean time level indices
98      INTEGER ::   ios, icpt                         ! local integer
99      LOGICAL ::   ll_purecpl, ll_opa, ll_not_nemo   ! local logical
100      !!
101      NAMELIST/namsbc/ nn_fsbc  ,                                                    &
102         &             ln_usr   , ln_flx   , ln_blk   , ln_abl,                      &
103         &             ln_cpl   , ln_mixcpl, nn_components,                          &
104         &             nn_ice   , ln_ice_embd,                                       &
105         &             ln_traqsr, ln_dm2dc ,                                         &
106         &             ln_rnf   , nn_fwb     , ln_ssr   , ln_apr_dyn,                &
107         &             ln_wave  , nn_lsm
108      !!----------------------------------------------------------------------
109      !
110      IF(lwp) THEN
111         WRITE(numout,*)
112         WRITE(numout,*) 'sbc_init : surface boundary condition setting'
113         WRITE(numout,*) '~~~~~~~~ '
114      ENDIF
115      !
116      !                       !**  read Surface Module namelist
117      READ  ( numnam_ref, namsbc, IOSTAT = ios, ERR = 901)
118901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc in reference namelist' )
119      READ  ( numnam_cfg, namsbc, IOSTAT = ios, ERR = 902 )
120902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc in configuration namelist' )
121      IF(lwm) WRITE( numond, namsbc )
122      !
123#if ! defined key_mpi_off
124      ncom_fsbc = nn_fsbc    ! make nn_fsbc available for lib_mpp
125#endif
126#if ! defined key_si3
127      IF( nn_ice == 2 )    nn_ice = 0  ! without key key_si3 you cannot use si3...
128#endif
129      !
130      !
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
138         WRITE(numout,*) '         ABL          formulation                   ln_abl        = ', ln_abl
139         WRITE(numout,*) '         Surface wave (forced or coupled)           ln_wave       = ', ln_wave
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
143!!gm  lk_oasis is controlled by key_oasis3  ===>>>  It shoud be removed from the namelist
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
148         WRITE(numout,*) '         ice embedded into ocean                    ln_ice_embd   = ', ln_ice_embd
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
157      ENDIF
158      !
159      IF( .NOT.ln_usr ) THEN     ! the model calendar needs some specificities (except in user defined case)
160         IF( MOD( rday , rn_Dt ) /= 0. )   CALL ctl_stop( 'the time step must devide the number of second of in a day' )
161         IF( MOD( rday , 2.  ) /= 0. )   CALL ctl_stop( 'the number of second of in a day must be an even number'    )
162         IF( MOD( rn_Dt  , 2.  ) /= 0. )   CALL ctl_stop( 'the time step (in second) must be an even number'           )
163      ENDIF
164      !                       !**  check option consistency
165      !
166      IF(lwp) WRITE(numout,*)       !* Single / Multi - executable (NEMO / OCE+SAS)
167      SELECT CASE( nn_components )
168      CASE( jp_iam_nemo )
169         IF(lwp) WRITE(numout,*) '   ==>>>   NEMO configured as a single executable (i.e. including both OCE and Surface module)'
170      CASE( jp_iam_oce  )
171         IF(lwp) WRITE(numout,*) '   ==>>>   Multi executable configuration. Here, OCE component'
172         IF( .NOT.lk_oasis )   CALL ctl_stop( 'sbc_init : OCE-SAS coupled via OASIS, but key_oasis3 disabled' )
173         IF( ln_cpl        )   CALL ctl_stop( 'sbc_init : OCE-SAS coupled via OASIS, but ln_cpl = T in OCE'   )
174         IF( ln_mixcpl     )   CALL ctl_stop( 'sbc_init : OCE-SAS coupled via OASIS, but ln_mixcpl = T in OCE' )
175      CASE( jp_iam_sas  )
176         IF(lwp) WRITE(numout,*) '   ==>>>   Multi executable configuration. Here, SAS component'
177         IF( .NOT.lk_oasis )   CALL ctl_stop( 'sbc_init : OCE-SAS coupled via OASIS, but key_oasis3 disabled' )
178         IF( ln_mixcpl     )   CALL ctl_stop( 'sbc_init : OCE-SAS coupled via OASIS, but ln_mixcpl = T in OCE' )
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
198      CASE( 1 )                        !- Ice-cover climatology ("Ice-if" model)
199      CASE( 2 )                        !- SI3  ice model
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' )
202      CASE( 3 )                        !- CICE ice model
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                                )   &
206            &                   CALL ctl_stop( 'sbc_init : CICE sea-ice model not currently available with AGRIF' )
207      CASE DEFAULT                     !- not supported
208      END SELECT
209      IF( ln_diurnal .AND. .NOT. (ln_blk.OR.ln_abl) )   CALL ctl_stop( "sbc_init: diurnal flux processing only implemented for bulk forcing" )
210      !
211      !                       !**  allocate and set required variables
212      !
213      !                             !* allocate sbc arrays
214      IF( sbc_oce_alloc() /= 0 )   CALL ctl_stop( 'sbc_init : unable to allocate sbc_oce arrays' )
215#if ! defined key_si3 && ! defined key_cice
216      IF( sbc_ice_alloc() /= 0 )   CALL ctl_stop( 'sbc_init : unable to allocate sbc_ice arrays' )
217#endif
218      !
219      !
220      IF( sbc_ssr_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'sbc_init : unable to allocate sbc_ssr arrays' )
221      IF( .NOT.ln_ssr ) THEN               !* Initialize qrp and erp if no restoring
222         qrp(:,:) = 0._wp
223         erp(:,:) = 0._wp
224      ENDIF
225      !
226      IF( nn_ice == 0 ) THEN        !* No sea-ice in the domain : ice fraction is always zero
227         IF( nn_components /= jp_iam_oce )   fr_i(:,:) = 0._wp    ! except for OCE in SAS-OCE coupled case
228      ENDIF
229      !
230      sfx   (:,:) = 0._wp           !* salt flux due to freezing/melting
231      fmmflx(:,:) = 0._wp           !* freezing minus melting flux
232      cloud_fra(:,:) = pp_cldf      !* cloud fraction over sea ice (used in si3)
233
234      taum(:,:) = 0._wp             !* wind stress module (needed in GLS in case of reduced restart)
235
236      !                          ! Choice of the Surface Boudary Condition (set nsbc)
237      nday_qsr = -1   ! allow initialization at the 1st call !LB: now warm-layer of COARE* calls "sbc_dcy_param" of sbcdcy.F90!
238      IF( ln_dm2dc ) THEN           !* daily mean to diurnal cycle
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_oce )   &
241            &   CALL ctl_stop( 'qsr diurnal cycle from daily values requires flux, bulk or abl formulation' )
242      ENDIF
243      !                             !* Choice of the Surface Boudary Condition
244      !                             (set nsbc)
245      !
246      ll_purecpl  = ln_cpl .AND. .NOT.ln_mixcpl
247      ll_opa      = nn_components == jp_iam_oce
248      ll_not_nemo = nn_components /= jp_iam_nemo
249      icpt = 0
250      !
251      IF( ln_usr          ) THEN   ;   nsbc = jp_usr     ; icpt = icpt + 1   ;   ENDIF       ! user defined         formulation
252      IF( ln_flx          ) THEN   ;   nsbc = jp_flx     ; icpt = icpt + 1   ;   ENDIF       ! flux                 formulation
253      IF( ln_blk          ) THEN   ;   nsbc = jp_blk     ; icpt = icpt + 1   ;   ENDIF       ! bulk                 formulation
254      IF( ln_abl          ) THEN   ;   nsbc = jp_abl     ; icpt = icpt + 1   ;   ENDIF       ! ABL                  formulation
255      IF( ll_purecpl      ) THEN   ;   nsbc = jp_purecpl ; icpt = icpt + 1   ;   ENDIF       ! Pure Coupled         formulation
256      IF( ll_opa          ) THEN   ;   nsbc = jp_none    ; icpt = icpt + 1   ;   ENDIF       ! opa coupling via SAS module
257      !
258      IF( icpt /= 1 )    CALL ctl_stop( 'sbc_init : choose ONE and only ONE sbc option' )
259      !
260      IF(lwp) THEN                     !- print the choice of surface flux formulation
261         WRITE(numout,*)
262         SELECT CASE( nsbc )
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'
266         CASE( jp_abl     )   ;   WRITE(numout,*) '   ==>>>   ABL  formulation'
267         CASE( jp_purecpl )   ;   WRITE(numout,*) '   ==>>>   pure coupled formulation'
268!!gm abusive use of jp_none ??   ===>>> need to be check and changed by adding a jp_sas parameter
269         CASE( jp_none    )   ;   WRITE(numout,*) '   ==>>>   OCE coupled to SAS via oasis'
270            IF( ln_mixcpl )       WRITE(numout,*) '               + forced-coupled mixed formulation'
271         END SELECT
272         IF( ll_not_nemo  )       WRITE(numout,*) '               + OASIS coupled SAS'
273      ENDIF
274      !
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
279      !     nn_fsbc initialization if OCE-SAS coupling via OASIS
280      !     SAS time-step has to be declared in OASIS (mandatory) -> nn_fsbc has to be modified accordingly
281      IF( nn_components /= jp_iam_nemo ) THEN
282         IF( nn_components == jp_iam_oce )   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)
284         !
285         IF(lwp)THEN
286            WRITE(numout,*)
287            WRITE(numout,*)"   OCE-SAS coupled via OASIS : nn_fsbc re-defined from OASIS namcouple ", nn_fsbc
288            WRITE(numout,*)
289         ENDIF
290      ENDIF
291      !
292      !                             !* check consistency between model timeline and nn_fsbc
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
302      ENDIF
303      !
304      IF( MOD( rday, REAL(nn_fsbc, wp) * rn_Dt ) /= 0 )   &
305         &  CALL ctl_warn( 'sbc_init : nn_fsbc is NOT a multiple of the number of time steps in a day' )
306      !
307      IF( ln_dm2dc .AND. NINT(rday) / ( nn_fsbc * NINT(rn_Dt) ) < 8  )   &
308         &   CALL ctl_warn( 'sbc_init : diurnal cycle for qsr: the sampling of the diurnal cycle is too small...' )
309      !
310
311      !                       !**  associated modules : initialization
312      !
313                          CALL sbc_ssm_init ( Kbb, Kmm ) ! Sea-surface mean fields initialization
314      !
315      IF( l_sbc_clo   )   CALL sbc_clo_init              ! closed sea surface initialisation
316      !
317      IF( ln_blk      )   CALL sbc_blk_init              ! bulk formulae initialization
318
319      IF( ln_abl      )   CALL sbc_abl_init              ! Atmospheric Boundary Layer (ABL)
320
321      IF( ln_ssr      )   CALL sbc_ssr_init              ! Sea-Surface Restoring initialization
322      !
323      !
324                          CALL sbc_rnf_init( Kmm )       ! Runof initialization
325      !
326      IF( ln_apr_dyn )    CALL sbc_apr_init              ! Atmo Pressure Forcing initialization
327      !
328#if defined key_si3
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
332                          CALL ice_init( Kbb, Kmm, Kaa )         ! ICE initialization
333      ENDIF
334#endif
335      IF( nn_ice == 3 )   CALL cice_sbc_init( nsbc, Kbb, Kmm )   ! CICE initialization
336      !
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
355      !
356   END SUBROUTINE sbc_init
357
358
359   SUBROUTINE sbc( kt, Kbb, Kmm )
360      !!---------------------------------------------------------------------
361      !!                    ***  ROUTINE sbc  ***
362      !!
363      !! ** Purpose :   provide at each time-step the ocean surface boundary
364      !!                condition (momentum, heat and freshwater fluxes)
365      !!
366      !! ** Method  :   blah blah  to be written ?????????
367      !!                CAUTION : never mask the surface stress field (tke sbc)
368      !!
369      !! ** Action  : - set the ocean surface boundary condition at before and now
370      !!                time step, i.e.
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
373      !!              - updte the ice fraction : fr_i
374      !!----------------------------------------------------------------------
375      INTEGER, INTENT(in) ::   kt   ! ocean time step
376      INTEGER, INTENT(in) ::   Kbb, Kmm   ! ocean time level indices
377      INTEGER  ::   jj, ji          ! dummy loop argument
378      !
379      LOGICAL ::   ll_sas, ll_opa   ! local logical
380      !
381      REAL(wp) ::     zthscl        ! wd  tanh scale
382      REAL(wp), DIMENSION(jpi,jpj) ::  zwdht, zwght  ! wd dep over wd limit, wgt
383
384      !!---------------------------------------------------------------------
385      !
386      IF( ln_timing )   CALL timing_start('sbc')
387      !
388      !                                            ! ---------------------------------------- !
389      IF( kt /= nit000 ) THEN                      !          Swap of forcing fields          !
390         !                                         ! ---------------------------------------- !
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 (:,:)
396         IF( ln_rnf ) THEN
397            rnf_b    (:,:  ) = rnf    (:,:  )
398            rnf_tsc_b(:,:,:) = rnf_tsc(:,:,:)
399         ENDIF
400        !
401      ENDIF
402      !                                            ! ---------------------------------------- !
403      !                                            !        forcing field computation         !
404      !                                            ! ---------------------------------------- !
405      !
406      ll_sas = nn_components == jp_iam_sas               ! component flags
407      ll_opa = nn_components == jp_iam_oce
408      !
409      IF( .NOT.ll_sas )   CALL sbc_ssm ( kt, Kbb, Kmm )  ! mean ocean sea surface variables (sst_m, sss_m, ssu_m, ssv_m)
410      !
411      !                                            !==  sbc formulation  ==!
412      !
413      !
414      SELECT CASE( nsbc )                                ! Compute ocean surface boundary condition
415      !                                                  ! (i.e. utau,vtau, qns, qsr, emp, sfx)
416      CASE( jp_usr   )     ;   CALL usrdef_sbc_oce( kt, Kbb )                        ! user defined formulation
417      CASE( jp_flx     )   ;   CALL sbc_flx       ( kt )                             ! flux formulation
418      CASE( jp_blk     )
419         IF( ll_sas    )       CALL sbc_cpl_rcv   ( kt, nn_fsbc, nn_ice, Kbb, Kmm )   ! OCE-SAS coupling: SAS receiving fields from OCE
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 )   ! OCE-wave coupling
423             CALL sbc_wave ( kt, Kmm )
424         ENDIF
425                               CALL sbc_blk       ( kt )                    ! bulk formulation for the ocean
426                               !
427      CASE( jp_abl     )
428         IF( ll_sas    )       CALL sbc_cpl_rcv   ( kt, nn_fsbc, nn_ice, Kbb, Kmm )   ! OCE-SAS coupling: SAS receiving fields from OCE
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
432      CASE( jp_none    )
433         IF( ll_opa    )       CALL sbc_cpl_rcv   ( kt, nn_fsbc, nn_ice, Kbb, Kmm )  ! OCE-SAS coupling: OCE receiving fields from SAS
434      END SELECT
435      !
436      IF( ln_mixcpl )          CALL sbc_cpl_rcv   ( kt, nn_fsbc, nn_ice, Kbb, Kmm )  ! forced-coupled mixed formulation after forcing
437      !
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         !
444         CALL lbc_lnk( 'sbcwave', utau, 'U', -1._wp , vtau, 'V', -1._wp )
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(:,:)
454         CALL lbc_lnk( 'sbcwave', utau, 'U', -1._wp, vtau, 'V', -1._wp )
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
464      CALL lbc_lnk( 'sbcmod', taum(:,:), 'T', 1._wp )
465      !
466      !                                            !==  Misc. Options  ==!
467      !
468      SELECT CASE( nn_ice )                                       ! Update heat and freshwater fluxes over sea-ice areas
469      CASE(  1 )   ;         CALL sbc_ice_if   ( kt, Kbb, Kmm )   ! Ice-cover climatology ("Ice-if" model)
470#if defined key_si3
471      CASE(  2 )   ;         CALL ice_stp  ( kt, Kbb, Kmm, nsbc ) ! SI3 ice model
472#endif
473      CASE(  3 )   ;         CALL sbc_ice_cice ( kt, nsbc )       ! CICE ice model
474      END SELECT
475
476      IF( ln_icebergs    )   CALL icb_stp( kt, Kmm )              ! compute icebergs
477
478      ! Icebergs do not melt over the haloes.
479      ! So emp values over the haloes are no more consistent with the inner domain values.
480      ! A lbc_lnk is therefore needed to ensure reproducibility and restartability.
481      ! see ticket #2113 for discussion about this lbc_lnk.
482      ! The lbc_lnk is also needed for SI3 with nn_hls > 1 as emp is not yet defined for these points in iceupdate.F90
483      IF( (ln_icebergs .AND. .NOT. ln_passive_mode) .OR. (nn_ice == 2 .AND. nn_hls == 2) ) THEN
484         CALL lbc_lnk( 'sbcmod', emp, 'T', 1.0_wp )
485      ENDIF
486
487      IF( ln_rnf         )   CALL sbc_rnf( kt )                   ! add runoffs to fresh water fluxes
488
489      IF( ln_ssr         )   CALL sbc_ssr( kt )                        ! add SST/SSS damping term
490
491      IF( nn_fwb    /= 0 )   CALL sbc_fwb( kt, nn_fwb, nn_fsbc, Kmm )  ! control the freshwater budget
492
493      ! Special treatment of freshwater fluxes over closed seas in the model domain
494      ! Should not be run if ln_diurnal_only
495      IF( l_sbc_clo      )   CALL sbc_clo( kt )
496
497!!$!RBbug do not understand why see ticket 667
498!!$!clem: it looks like it is necessary for the north fold (in certain circumstances). Don't know why.
499!!$      CALL lbc_lnk( 'sbcmod', emp, 'T', 1.0_wp )
500      IF( ll_wd ) THEN     ! If near WAD point limit the flux for now
501         zthscl = atanh(rn_wd_sbcfra)                     ! taper frac default is .999
502         zwdht(:,:) = ssh(:,:,Kmm) + ht_0(:,:) - rn_wdmin1   ! do this calc of water
503                                                     ! depth above wd limit once
504         WHERE( zwdht(:,:) <= 0.0 )
505            taum(:,:) = 0.0
506            utau(:,:) = 0.0
507            vtau(:,:) = 0.0
508            qns (:,:) = 0.0
509            qsr (:,:) = 0.0
510            emp (:,:) = min(emp(:,:),0.0) !can allow puddles to grow but not shrink
511            sfx (:,:) = 0.0
512         END WHERE
513         zwght(:,:) = tanh(zthscl*zwdht(:,:))
514         WHERE( zwdht(:,:) > 0.0  .and. zwdht(:,:) < rn_wd_sbcdep ) !  5 m hard limit here is arbitrary
515            qsr  (:,:) =  qsr(:,:)  * zwght(:,:)
516            qns  (:,:) =  qns(:,:)  * zwght(:,:)
517            taum (:,:) =  taum(:,:) * zwght(:,:)
518            utau (:,:) =  utau(:,:) * zwght(:,:)
519            vtau (:,:) =  vtau(:,:) * zwght(:,:)
520            sfx  (:,:) =  sfx(:,:)  * zwght(:,:)
521            emp  (:,:) =  emp(:,:)  * zwght(:,:)
522         END WHERE
523      ENDIF
524      !
525      IF( kt == nit000 ) THEN                          !   set the forcing field at nit000 - 1    !
526         !                                             ! ---------------------------------------- !
527         IF( ln_rstart .AND. .NOT.l_1st_euler ) THEN            !* Restart: read in restart file
528            IF(lwp) WRITE(numout,*) '          nit000-1 surface forcing fields read in the restart file'
529            CALL iom_get( numror, jpdom_auto, 'utau_b', utau_b )   ! i-stress
530            CALL iom_get( numror, jpdom_auto, 'vtau_b', vtau_b )   ! j-stress
531            CALL iom_get( numror, jpdom_auto,  'qns_b',  qns_b )   ! non solar heat flux
532            CALL iom_get( numror, jpdom_auto,  'emp_b',  emp_b )   ! freshwater flux
533            ! NB: The 3D heat content due to qsr forcing (qsr_hc_b) is treated in traqsr
534            ! To ensure restart capability with 3.3x/3.4 restart files    !! to be removed in v3.6
535            IF( iom_varid( numror, 'sfx_b', ldstop = .FALSE. ) > 0 ) THEN
536               CALL iom_get( numror, jpdom_auto, 'sfx_b', sfx_b )  ! before salt flux (T-point)
537            ELSE
538               sfx_b (:,:) = sfx(:,:)
539            ENDIF
540         ELSE                                                   !* no restart: set from nit000 values
541            IF(lwp) WRITE(numout,*) '          nit000-1 surface forcing fields set to nit000'
542            utau_b(:,:) = utau(:,:)
543            vtau_b(:,:) = vtau(:,:)
544            qns_b (:,:) = qns (:,:)
545            emp_b (:,:) = emp (:,:)
546            sfx_b (:,:) = sfx (:,:)
547         ENDIF
548      ENDIF
549      !                                                ! ---------------------------------------- !
550      IF( lrst_oce ) THEN                              !      Write in the ocean restart file     !
551         !                                             ! ---------------------------------------- !
552         IF(lwp) WRITE(numout,*)
553         IF(lwp) WRITE(numout,*) 'sbc : ocean surface forcing fields written in ocean restart file ',   &
554            &                    'at it= ', kt,' date= ', ndastp
555         IF(lwp) WRITE(numout,*) '~~~~'
556         CALL iom_rstput( kt, nitrst, numrow, 'utau_b' , utau )
557         CALL iom_rstput( kt, nitrst, numrow, 'vtau_b' , vtau )
558         CALL iom_rstput( kt, nitrst, numrow, 'qns_b'  , qns  )
559         ! The 3D heat content due to qsr forcing is treated in traqsr
560         ! CALL iom_rstput( kt, nitrst, numrow, 'qsr_b'  , qsr  )
561         CALL iom_rstput( kt, nitrst, numrow, 'emp_b'  , emp  )
562         CALL iom_rstput( kt, nitrst, numrow, 'sfx_b'  , sfx  )
563      ENDIF
564      !                                                ! ---------------------------------------- !
565      !                                                !        Outputs and control print         !
566      !                                                ! ---------------------------------------- !
567      IF( MOD( kt-1, nn_fsbc ) == 0 ) THEN
568         CALL iom_put( "empmr"  , emp   - rnf )                ! upward water flux
569         CALL iom_put( "empbmr" , emp_b - rnf )                ! before upward water flux ( needed to recalculate the time evolution of ssh in offline )
570         CALL iom_put( "saltflx", sfx         )                ! downward salt flux (includes virtual salt flux beneath ice in linear free surface case)
571         CALL iom_put( "fmmflx" , fmmflx      )                ! Freezing-melting water flux
572         CALL iom_put( "qt"     , qns + qsr   )                ! total heat flux
573         CALL iom_put( "qns"    , qns         )                ! solar heat flux
574         CALL iom_put( "qsr"    ,       qsr   )                ! solar heat flux
575         IF( nn_ice > 0 .OR. ll_opa )   CALL iom_put( "ice_cover", fr_i )   ! ice fraction
576         CALL iom_put( "taum"   , taum        )                ! wind stress module
577         CALL iom_put( "wspd"   , wndm        )                ! wind speed  module over free ocean or leads in presence of sea-ice
578         CALL iom_put( "qrp"    , qrp         )                ! heat flux damping
579         CALL iom_put( "erp"    , erp         )                ! freshwater flux damping
580      ENDIF
581      !
582      IF(sn_cfctl%l_prtctl) THEN     ! print mean trends (used for debugging)
583         CALL prt_ctl(tab2d_1=fr_i                , clinfo1=' fr_i     - : ', mask1=tmask )
584         CALL prt_ctl(tab2d_1=(emp-rnf)           , clinfo1=' emp-rnf  - : ', mask1=tmask )
585         CALL prt_ctl(tab2d_1=CASTDP((sfx-rnf))           , clinfo1=' sfx-rnf  - : ', mask1=tmask )
586         CALL prt_ctl(tab2d_1=CASTDP(qns)                 , clinfo1=' qns      - : ', mask1=tmask )
587         CALL prt_ctl(tab2d_1=CASTDP(qsr)                 , clinfo1=' qsr      - : ', mask1=tmask )
588         CALL prt_ctl(tab3d_1=tmask               , clinfo1=' tmask    - : ', mask1=tmask, kdim=jpk )
589         CALL prt_ctl(tab3d_1=ts(:,:,:,jp_tem,Kmm), clinfo1=' sst      - : ', mask1=tmask, kdim=1   )
590         CALL prt_ctl(tab3d_1=ts(:,:,:,jp_sal,Kmm), clinfo1=' sss      - : ', mask1=tmask, kdim=1   )
591         CALL prt_ctl(tab2d_1=utau                , clinfo1=' utau     - : ', mask1=umask,                      &
592            &         tab2d_2=vtau                , clinfo2=' vtau     - : ', mask2=vmask )
593      ENDIF
594
595      IF( kt == nitend )   CALL sbc_final         ! Close down surface module if necessary
596      !
597      IF( ln_timing )   CALL timing_stop('sbc')
598      !
599   END SUBROUTINE sbc
600
601
602   SUBROUTINE sbc_final
603      !!---------------------------------------------------------------------
604      !!                    ***  ROUTINE sbc_final  ***
605      !!
606      !! ** Purpose :   Finalize CICE (if used)
607      !!---------------------------------------------------------------------
608      !
609      IF( nn_ice == 3 )   CALL cice_sbc_final
610      !
611   END SUBROUTINE sbc_final
612
613   !!======================================================================
614END MODULE sbcmod
Note: See TracBrowser for help on using the repository browser.