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.
sbcisf.F90 in branches/UKMO/dev_isf_flx_UKESM_r9321/NEMOGCM/NEMO/OPA_SRC/SBC – NEMO

source: branches/UKMO/dev_isf_flx_UKESM_r9321/NEMOGCM/NEMO/OPA_SRC/SBC/sbcisf.F90 @ 10026

Last change on this file since 10026 was 10026, checked in by mathiot, 6 years ago

Compute isf heat content flx using interface S in of far field S + add isfmask to simplify isf masking

File size: 47.4 KB
Line 
1MODULE sbcisf
2   !!======================================================================
3   !!                       ***  MODULE  sbcisf  ***
4   !! Surface module :  update surface ocean boundary condition under ice
5   !!                   shelf
6   !!======================================================================
7   !! History :  3.2   !  2011-02  (C.Harris  ) Original code isf cav
8   !!            X.X   !  2006-02  (C. Wang   ) Original code bg03
9   !!            3.4   !  2013-03  (P. Mathiot) Merging + parametrization
10   !!----------------------------------------------------------------------
11
12   !!----------------------------------------------------------------------
13   !!   sbc_isf        : update sbc under ice shelf
14   !!----------------------------------------------------------------------
15   USE oce             ! ocean dynamics and tracers
16   USE dom_oce         ! ocean space and time domain
17   USE phycst          ! physical constants
18   USE eosbn2          ! equation of state
19   USE sbc_oce         ! surface boundary condition: ocean fields
20   USE zdfbfr          !
21   !
22   USE in_out_manager  ! I/O manager
23   USE iom             ! I/O manager library
24   USE fldread         ! read input field at current time step
25   USE lbclnk          !
26   USE wrk_nemo        ! Memory allocation
27   USE timing          ! Timing
28   USE lib_fortran     ! glob_sum
29
30   IMPLICIT NONE
31   PRIVATE
32
33   PUBLIC   sbc_isf, sbc_isf_div, sbc_isf_alloc  ! routine called in sbcmod and divcur
34
35   ! public in order to be able to output then
36
37   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   risf_tsc_b, risf_tsc  !: before and now T & S isf contents [K.m/s & PSU.m/s] 
38   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   qisf, qhcisf          !: latent heat and heat content flux from ice shelf  [W/m2]
39   REAL(wp), PUBLIC ::   rn_hisf_tbl                 !: thickness of top boundary layer [m]
40   INTEGER , PUBLIC ::   nn_isfblk                   !: flag to choose the bulk formulation to compute the ice shelf melting
41   INTEGER , PUBLIC ::   nn_gammablk                 !: flag to choose how the exchange coefficient is computed
42   REAL(wp), PUBLIC ::   rn_gammat0                  !: temperature exchange coeficient []
43   REAL(wp), PUBLIC ::   rn_gammas0                  !: salinity    exchange coeficient []
44
45   REAL(wp)   , PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  rzisf_tbl              !:depth of calving front (shallowest point) nn_isf ==2/3
46   REAL(wp)   , PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  rhisf_tbl, rhisf_tbl_0 !:thickness of tbl  [m]
47   REAL(wp)   , PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  r1_hisf_tbl            !:1/thickness of tbl
48   REAL(wp)   , PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  ralpha                 !:proportion of bottom cell influenced by tbl
49   REAL(wp)   , PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  risfLeff               !:effective length (Leff) BG03 nn_isf==2
50   REAL(wp)   , PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)     ::  ttbl, stbl, utbl, vtbl !:top boundary layer variable at T point
51   INTEGER,    PUBLIC, ALLOCATABLE, SAVE, DIMENSION (:,:)      ::  misfkt, misfkb         !:Level of ice shelf base
52
53   REAL(wp), PUBLIC, SAVE ::   rcpi     = 2000.0_wp     ! specific heat of ice shelf             [J/kg/K]
54   REAL(wp), PUBLIC, SAVE ::   rkappa   = 1.54e-6_wp    ! heat diffusivity through the ice-shelf [m2/s]
55   REAL(wp), PUBLIC, SAVE ::   rhoisf   = 920.0_wp      ! volumic mass of ice shelf              [kg/m3]
56   REAL(wp), PUBLIC, SAVE ::   tsurf    = -20.0_wp      ! air temperature on top of ice shelf    [C]
57   REAL(wp), PUBLIC, SAVE ::   rlfusisf = 0.334e6_wp    ! latent heat of fusion of ice shelf     [J/kg]
58
59!: Variable used in fldread to read the forcing file (nn_isf == 4 .OR. nn_isf == 3)
60   CHARACTER(len=100), PUBLIC           :: cn_dirisf  = './' !: Root directory for location of ssr files
61   TYPE(FLD_N)       , PUBLIC           :: sn_fwfisf         !: information about the isf melting file to be read
62   TYPE(FLD), ALLOCATABLE, DIMENSION(:) :: sf_fwfisf
63   TYPE(FLD_N)       , PUBLIC           :: sn_rnfisf         !: information about the isf melting param.   file to be read
64   TYPE(FLD), ALLOCATABLE, DIMENSION(:) :: sf_rnfisf           
65   TYPE(FLD_N)       , PUBLIC           :: sn_depmax_isf     !: information about the grounding line depth file to be read
66   TYPE(FLD_N)       , PUBLIC           :: sn_depmin_isf     !: information about the calving   line depth file to be read
67   TYPE(FLD_N)       , PUBLIC           :: sn_Leff_isf       !: information about the effective length     file to be read
68   
69   !! * Substitutions
70#  include "domzgr_substitute.h90"
71   !!----------------------------------------------------------------------
72   !! NEMO/OPA 3.0 , LOCEAN-IPSL (2008)
73   !! $Id$
74   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
75   !!----------------------------------------------------------------------
76CONTAINS
77 
78  SUBROUTINE sbc_isf(kt)
79      !!---------------------------------------------------------------------
80      !!                  ***  ROUTINE sbc_isf  ***
81      !!
82      !! ** Purpose : Compute Salt and Heat fluxes related to ice_shelf
83      !!              melting and freezing
84      !!
85      !! ** Method  :  4 parameterizations are available according to nn_isf
86      !!               nn_isf = 1 : Realistic ice_shelf formulation
87      !!                        2 : Beckmann & Goose parameterization
88      !!                        3 : Specified runoff in deptht (Mathiot & al. )
89      !!                        4 : specified fwf and heat flux forcing beneath the ice shelf
90      !!----------------------------------------------------------------------
91      INTEGER, INTENT(in)          ::   kt         ! ocean time step
92      INTEGER                      ::   ji, jj, jk, ijkmin, inum, ierror
93      INTEGER                      ::   ikt, ikb   ! top and bottom level of the isf boundary layer
94      REAL(wp)                     ::   zgreenland_fwfisf_sum, zantarctica_fwfisf_sum
95      REAL(wp)                     ::   rmin
96      REAL(wp)                     ::   zhk
97      CHARACTER(len=256)           ::   cfisf , cvarzisf, cvarhisf   ! name for isf file
98      CHARACTER(LEN=256)           :: cnameis                     ! name of iceshelf file
99      CHARACTER (LEN=32)           :: cvarLeff                    ! variable name for efficient Length scale
100      INTEGER                      :: ios                         ! Local integer output status for namelist read
101
102      REAL(wp), DIMENSION(:,:,:), POINTER :: zfwfisf3d, zqhcisf3d, zqlatisf3d
103      REAL(wp), DIMENSION(:,:  ), POINTER :: ztfrz, zdep         ! freezing temperature (ztfrz) at depth (zdep)
104      !
105      !!---------------------------------------------------------------------
106      NAMELIST/namsbc_isf/ nn_isfblk, rn_hisf_tbl, rn_gammat0, rn_gammas0, nn_gammablk, &
107                         & sn_fwfisf, sn_rnfisf, sn_depmax_isf, sn_depmin_isf, sn_Leff_isf
108      !
109      !
110      !                                         ! ====================== !
111      IF( kt == nit000 ) THEN                   !  First call kt=nit000  !
112         !                                      ! ====================== !
113         REWIND( numnam_ref )              ! Namelist namsbc_rnf in reference namelist : Runoffs
114         READ  ( numnam_ref, namsbc_isf, IOSTAT = ios, ERR = 901)
115901      IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_isf in reference namelist', lwp )
116
117         REWIND( numnam_cfg )              ! Namelist namsbc_rnf in configuration namelist : Runoffs
118         READ  ( numnam_cfg, namsbc_isf, IOSTAT = ios, ERR = 902 )
119902      IF( ios /= 0 ) CALL ctl_nam ( ios , 'namsbc_isf in configuration namelist', lwp )
120         IF(lwm) WRITE ( numond, namsbc_isf )
121
122
123         IF ( lwp ) WRITE(numout,*)
124         IF ( lwp ) WRITE(numout,*) 'sbc_isf: heat flux of the ice shelf'
125         IF ( lwp ) WRITE(numout,*) '~~~~~~~~~'
126         IF ( lwp ) WRITE(numout,*) 'sbcisf :' 
127         IF ( lwp ) WRITE(numout,*) '~~~~~~~~'
128         IF ( lwp ) WRITE(numout,*) '        nn_isf      = ', nn_isf
129         IF ( lwp ) WRITE(numout,*) '        nn_isfblk   = ', nn_isfblk
130         IF ( lwp ) WRITE(numout,*) '        rn_hisf_tbl = ', rn_hisf_tbl
131         IF ( lwp ) WRITE(numout,*) '        nn_gammablk = ', nn_gammablk 
132         IF ( lwp ) WRITE(numout,*) '        rn_tfri2    = ', rn_tfri2 
133         !
134         ! Allocate public variable
135         IF ( sbc_isf_alloc()  /= 0 )         CALL ctl_stop( 'STOP', 'sbc_isf : unable to allocate arrays' )
136         !
137         ! initialisation
138         qisf(:,:)        = 0._wp  ; fwfisf(:,:) = 0._wp
139         risf_tsc(:,:,:)  = 0._wp
140         !
141         ! define isf tbl tickness, top and bottom indice
142         IF      (nn_isf == 1) THEN
143            rhisf_tbl(:,:) = rn_hisf_tbl
144            misfkt(:,:)    = mikt(:,:)         ! same indice for bg03 et cav => used in isfdiv
145         ELSE IF ((nn_isf == 3) .OR. (nn_isf == 2)) THEN
146            ALLOCATE( sf_rnfisf(1), STAT=ierror )
147            ALLOCATE( sf_rnfisf(1)%fnow(jpi,jpj,1), sf_rnfisf(1)%fdta(jpi,jpj,1,2) )
148            CALL fld_fill( sf_rnfisf, (/ sn_rnfisf /), cn_dirisf, 'sbc_isf_init', 'read fresh water flux isf data', 'namsbc_isf' )
149
150            !: read effective lenght (BG03)
151            IF (nn_isf == 2) THEN
152               ! Read Data and save some integral values
153               CALL iom_open( sn_Leff_isf%clname, inum )
154               cvarLeff  = 'soLeff'               !: variable name for Efficient Length scale
155               CALL iom_get( inum, jpdom_data, cvarLeff, risfLeff , 1)
156               CALL iom_close(inum)
157               !
158               risfLeff = risfLeff*1000           !: convertion in m
159            END IF
160
161           ! read depth of the top and bottom of the isf top boundary layer (in this case, isf front depth and grounding line depth)
162            CALL iom_open( sn_depmax_isf%clname, inum )
163            cvarhisf = TRIM(sn_depmax_isf%clvar)
164            CALL iom_get( inum, jpdom_data, cvarhisf, rhisf_tbl, 1) !: depth of deepest point of the ice shelf base
165            CALL iom_close(inum)
166            !
167            CALL iom_open( sn_depmin_isf%clname, inum )
168            cvarzisf = TRIM(sn_depmin_isf%clvar)
169            CALL iom_get( inum, jpdom_data, cvarzisf, rzisf_tbl, 1) !: depth of shallowest point of the ice shelves base
170            CALL iom_close(inum)
171            !
172            rhisf_tbl(:,:) = rhisf_tbl(:,:) - rzisf_tbl(:,:)        !: tickness isf boundary layer
173
174           !! compute first level of the top boundary layer
175           DO ji = 1, jpi
176              DO jj = 1, jpj
177                  jk = 2
178                  DO WHILE ( jk .LE. mbkt(ji,jj) .AND. gdepw_0(ji,jj,jk) < rzisf_tbl(ji,jj) ) ;  jk = jk + 1 ;  END DO
179                  misfkt(ji,jj) = jk-1
180               END DO
181            END DO
182
183         ELSE IF ( nn_isf == 4 ) THEN
184            ! as in nn_isf == 1
185            rhisf_tbl(:,:) = rn_hisf_tbl
186            misfkt(:,:)    = mikt(:,:)         ! same indice for bg03 et cav => used in isfdiv
187           
188            ! load variable used in fldread (use for temporal interpolation of isf fwf forcing)
189            ALLOCATE( sf_fwfisf(1), STAT=ierror )
190            ALLOCATE( sf_fwfisf(1)%fnow(jpi,jpj,1), sf_fwfisf(1)%fdta(jpi,jpj,1,2) )
191            CALL fld_fill( sf_fwfisf, (/ sn_fwfisf /), cn_dirisf, 'sbc_isf_init', 'read fresh water flux isf data', 'namsbc_isf' )
192         END IF
193         
194         ! save initial top boundary layer thickness         
195         rhisf_tbl_0(:,:) = rhisf_tbl(:,:)
196
197      END IF
198
199      !                                            ! ---------------------------------------- !
200      IF( kt /= nit000 ) THEN                      !          Swap of forcing fields          !
201         !                                         ! ---------------------------------------- !
202         fwfisf_b  (:,:  ) = fwfisf  (:,:  )               ! Swap the ocean forcing fields except at nit000
203         risf_tsc_b(:,:,:) = risf_tsc(:,:,:)               ! where before fields are set at the end of the routine
204         !
205      ENDIF
206
207      IF( MOD( kt-1, nn_fsbc) == 0 ) THEN
208         ! allocation
209         CALL wrk_alloc( jpi,jpj, ztfrz, zdep  )
210
211         ! compute bottom level of isf tbl and thickness of tbl below the ice shelf
212         DO jj = 1,jpj
213            DO ji = 1,jpi
214               ikt = misfkt(ji,jj)
215               ikb = misfkt(ji,jj)
216               ! thickness of boundary layer at least the top level thickness
217               rhisf_tbl(ji,jj) = MAX(rhisf_tbl_0(ji,jj), fse3t_n(ji,jj,ikt))
218
219               ! determine the deepest level influenced by the boundary layer
220               DO jk = ikt, mbkt(ji,jj)
221                  IF ( (SUM(fse3t_n(ji,jj,ikt:jk-1)) .LT. rhisf_tbl(ji,jj)) .AND. (tmask(ji,jj,jk) == 1) ) ikb = jk
222               END DO
223               rhisf_tbl(ji,jj) = MIN(rhisf_tbl(ji,jj), SUM(fse3t_n(ji,jj,ikt:ikb)))  ! limit the tbl to water thickness.
224               misfkb(ji,jj) = ikb                                                  ! last wet level of the tbl
225               r1_hisf_tbl(ji,jj) = 1._wp / rhisf_tbl(ji,jj)
226
227               zhk           = SUM( fse3t(ji, jj, ikt:ikb - 1)) * r1_hisf_tbl(ji,jj)  ! proportion of tbl cover by cell from ikt to ikb - 1
228               ralpha(ji,jj) = rhisf_tbl(ji,jj) * (1._wp - zhk ) / fse3t(ji,jj,ikb)  ! proportion of bottom cell influenced by boundary layer
229            END DO
230         END DO
231
232         ! compute salf and heat flux
233         SELECT CASE ( nn_isf )
234         CASE ( 1 )    ! realistic ice shelf formulation
235            ! compute T/S/U/V for the top boundary layer
236            CALL sbc_isf_tbl(tsn(:,:,:,jp_tem),ttbl(:,:),'T')
237            CALL sbc_isf_tbl(tsn(:,:,:,jp_sal),stbl(:,:),'T')
238            CALL sbc_isf_tbl(un(:,:,:)        ,utbl(:,:),'U')
239            CALL sbc_isf_tbl(vn(:,:,:)        ,vtbl(:,:),'V')
240            ! iom print
241            CALL iom_put('ttbl',ttbl(:,:))
242            CALL iom_put('stbl',stbl(:,:))
243            CALL iom_put('utbl',utbl(:,:))
244            CALL iom_put('vtbl',vtbl(:,:))
245            ! compute fwf and heat flux
246            CALL sbc_isf_cav (kt)
247
248         CASE ( 2 )    ! Beckmann and Goosse parametrisation
249            stbl(:,:)   = soce
250            CALL sbc_isf_bg03(kt)
251
252         CASE ( 3 )    ! specified runoff in depth (Mathiot et al., XXXX in preparation)
253            CALL fld_read ( kt, nn_fsbc, sf_rnfisf   )
254            fwfisf(:,:) = - sf_rnfisf(1)%fnow(:,:,1)         ! fwf  flux from the isf (fwfisf <0 mean melting)
255
256            IF( lk_oasis) THEN
257            ! nn_coupled_iceshelf_fluxes uninitialised unless lk_oasis=true
258            IF( nn_coupled_iceshelf_fluxes .gt. 0 ) THEN
259
260              ! Adjust total iceshelf melt rates so that sum of iceberg calving and iceshelf melting in the northern
261              ! and southern hemispheres equals rate of increase of mass of greenland and antarctic ice sheets
262              ! to preserve total freshwater conservation in coupled models without an active ice sheet model.
263 
264              ! All related global sums must be done bit reproducibly
265               zgreenland_fwfisf_sum = glob_sum( fwfisf(:,:) * e1t(:,:) * e2t(:,:) * greenland_icesheet_mask(:,:) )
266
267               ! use ABS function because we need to preserve the sign of fwfisf
268               WHERE( greenland_icesheet_mask(:,:) == 1.0 )                                                                  &
269              &    fwfisf(:,:) = fwfisf(:,:)  * ABS( greenland_icesheet_mass_rate_of_change * (1.0-rn_greenland_calving_fraction) &
270              &                           / ( zgreenland_fwfisf_sum + 1.0e-10_wp ) )
271
272               ! check
273               IF(lwp) WRITE(numout, *) 'Greenland iceshelf melting climatology (kg/s) : ',zgreenland_fwfisf_sum
274
275               zgreenland_fwfisf_sum = glob_sum( fwfisf(:,:) * e1t(:,:) * e2t(:,:) * greenland_icesheet_mask(:,:) )
276
277               IF(lwp) WRITE(numout, *) 'Greenland iceshelf melting adjusted value (kg/s) : ',zgreenland_fwfisf_sum
278
279               zantarctica_fwfisf_sum = glob_sum( fwfisf(:,:) * e1t(:,:) * e2t(:,:) * antarctica_icesheet_mask(:,:) )
280
281               ! use ABS function because we need to preserve the sign of fwfisf
282               WHERE( antarctica_icesheet_mask(:,:) == 1.0 ) &
283              &    fwfisf(:,:) = fwfisf(:,:)  * ABS( antarctica_icesheet_mass_rate_of_change * (1.0-rn_antarctica_calving_fraction) &
284              &                           / ( zantarctica_fwfisf_sum + 1.0e-10_wp ) )
285     
286               ! check
287               IF(lwp) WRITE(numout, *) 'Antarctica iceshelf melting climatology (kg/s) : ',zantarctica_fwfisf_sum
288
289               zantarctica_fwfisf_sum = glob_sum( fwfisf(:,:) * e1t(:,:) * e2t(:,:) * antarctica_icesheet_mask(:,:) )
290
291               IF(lwp) WRITE(numout, *) 'Antarctica iceshelf melting adjusted value (kg/s) : ',zantarctica_fwfisf_sum
292
293            ENDIF
294            ENDIF
295
296            qisf(:,:)   = fwfisf(:,:) * rlfusisf              ! heat        flux
297            stbl(:,:)   = soce
298
299         CASE ( 4 )    ! specified fwf and heat flux forcing beneath the ice shelf
300            CALL fld_read ( kt, nn_fsbc, sf_fwfisf   )
301            fwfisf(:,:) =   sf_fwfisf(1)%fnow(:,:,1)            ! fwf  flux from the isf (fwfisf <0 mean melting)
302
303            IF( lk_oasis) THEN
304            ! nn_coupled_iceshelf_fluxes uninitialised unless lk_oasis=true
305            IF( nn_coupled_iceshelf_fluxes .gt. 0 ) THEN
306
307              ! Adjust total iceshelf melt rates so that sum of iceberg calving and iceshelf melting in the northern
308              ! and southern hemispheres equals rate of increase of mass of greenland and antarctic ice sheets
309              ! to preserve total freshwater conservation in coupled models without an active ice sheet model.
310
311              ! All related global sums must be done bit reproducibly
312               zgreenland_fwfisf_sum = glob_sum( fwfisf(:,:) * e1t(:,:) * e2t(:,:) * greenland_icesheet_mask(:,:) )
313
314               ! use ABS function because we need to preserve the sign of fwfisf
315               WHERE( greenland_icesheet_mask(:,:) == 1.0 )                                                                  &
316              &    fwfisf(:,:) = fwfisf(:,:)  * ABS( greenland_icesheet_mass_rate_of_change * (1.0-rn_greenland_calving_fraction) &
317              &                           / ( zgreenland_fwfisf_sum + 1.0e-10_wp ) )
318
319               ! check
320               IF(lwp) WRITE(numout, *) 'Greenland iceshelf melting climatology (kg/s) : ',zgreenland_fwfisf_sum
321
322               zgreenland_fwfisf_sum = glob_sum( fwfisf(:,:) * e1t(:,:) * e2t(:,:) * greenland_icesheet_mask(:,:) )
323
324               IF(lwp) WRITE(numout, *) 'Greenland iceshelf melting adjusted value (kg/s) : ',zgreenland_fwfisf_sum
325
326               zantarctica_fwfisf_sum = glob_sum( fwfisf(:,:) * e1t(:,:) * e2t(:,:) * antarctica_icesheet_mask(:,:) )
327
328               ! use ABS function because we need to preserve the sign of fwfisf
329               WHERE( antarctica_icesheet_mask(:,:) == 1.0 ) &
330              &    fwfisf(:,:) = fwfisf(:,:)  * ABS( antarctica_icesheet_mass_rate_of_change * (1.0-rn_antarctica_calving_fraction) &
331              &                           / ( zantarctica_fwfisf_sum + 1.0e-10_wp ) )
332     
333               ! check
334               IF(lwp) WRITE(numout, *) 'Antarctica iceshelf melting climatology (kg/s) : ',zantarctica_fwfisf_sum
335
336               zantarctica_fwfisf_sum = glob_sum( fwfisf(:,:) * e1t(:,:) * e2t(:,:) * antarctica_icesheet_mask(:,:) )
337
338               IF(lwp) WRITE(numout, *) 'Antarctica iceshelf melting adjusted value (kg/s) : ',zantarctica_fwfisf_sum
339
340            ENDIF
341            ENDIF
342
343            qisf(:,:)   = fwfisf(:,:) * rlfusisf              ! heat        flux
344            stbl(:,:)   = soce
345
346         END SELECT
347
348         ! compute heat content
349         ! heat content flux for nn_isf==1 is done in sbcisf_cav
350         SELECT CASE ( nn_isf )
351         CASE ( 2, 3, 4 )
352            DO jj = 1,jpj
353               DO ji = 1,jpi
354                  zdep(ji,jj)=fsdepw_n(ji,jj,misfkt(ji,jj))
355               END DO
356            END DO
357            CALL eos_fzp( stbl(:,:), ztfrz(:,:), zdep(:,:) )
358            qhcisf(:,:) = - fwfisf(:,:) * ztfrz(:,:) * rcp
359         END SELECT
360         
361         ! compute tsc due to isf
362         risf_tsc(:,:,jp_tem) = (qisf(:,:) + qhcisf(:,:)) * r1_rau0_rcp
363         risf_tsc(:,:,jp_sal) = 0.0_wp
364
365         ! output
366         IF( iom_use('qlatisf' ) )   CALL iom_put('qlatisf', qisf  )
367         IF( iom_use('fwfisf'  ) )   CALL iom_put('fwfisf' , fwfisf)
368         IF( iom_use('qhcisf'  ) )   CALL iom_put('qhcisf' , qhcisf)
369
370         ! lbclnk
371         CALL lbc_lnk(risf_tsc(:,:,jp_tem),'T',1.)
372         CALL lbc_lnk(risf_tsc(:,:,jp_sal),'T',1.)
373         CALL lbc_lnk(fwfisf(:,:)         ,'T',1.)
374         CALL lbc_lnk(qisf(:,:)           ,'T',1.)
375
376!=============================================================================================================================================
377         IF ( iom_use('fwfisf3d') .OR. iom_use('qlatisf3d') .OR. iom_use('qhcisf3d')) THEN
378            CALL wrk_alloc( jpi,jpj,jpk, zfwfisf3d, zqhcisf3d, zqlatisf3d )
379
380            zfwfisf3d(:,:,:) = 0.0_wp                         ! 3d ice shelf melting (kg/m2/s)
381            zqhcisf3d(:,:,:) = 0.0_wp                         ! 3d heat content flux (W/m2)
382            zqlatisf3d(:,:,:)= 0.0_wp                         ! 3d ice shelf melting latent heat flux (W/m2)
383
384            DO jj = 1,jpj
385               DO ji = 1,jpi
386                  ikt = misfkt(ji,jj)
387                  ikb = misfkb(ji,jj)
388                  DO jk = ikt, ikb - 1
389                     zfwfisf3d (ji,jj,jk) = zfwfisf3d (ji,jj,jk) + fwfisf(ji,jj) * r1_hisf_tbl(ji,jj) * fse3t(ji,jj,jk)
390                     zqhcisf3d (ji,jj,jk) = zqhcisf3d (ji,jj,jk) + qhcisf(ji,jj) * r1_hisf_tbl(ji,jj) * fse3t(ji,jj,jk)
391                     zqlatisf3d(ji,jj,jk) = zqlatisf3d(ji,jj,jk) + qisf  (ji,jj) * r1_hisf_tbl(ji,jj) * fse3t(ji,jj,jk)
392                  END DO
393                  zfwfisf3d (ji,jj,jk) = zfwfisf3d (ji,jj,jk) + fwfisf(ji,jj) * r1_hisf_tbl(ji,jj) * ralpha(ji,jj) * fse3t(ji,jj,jk)
394                  zqhcisf3d (ji,jj,jk) = zqhcisf3d (ji,jj,jk) + qhcisf(ji,jj) * r1_hisf_tbl(ji,jj) * ralpha(ji,jj) * fse3t(ji,jj,jk)
395                  zqlatisf3d(ji,jj,jk) = zqlatisf3d(ji,jj,jk) + qisf  (ji,jj) * r1_hisf_tbl(ji,jj) * ralpha(ji,jj) * fse3t(ji,jj,jk)
396               END DO
397            END DO
398
399            CALL iom_put('fwfisf3d' , zfwfisf3d (:,:,:))
400            CALL iom_put('qlatisf3d', zqlatisf3d(:,:,:))
401            CALL iom_put('qhcisf3d' , zqhcisf3d (:,:,:))
402
403            CALL wrk_dealloc( jpi,jpj,jpk, zfwfisf3d, zqhcisf3d, zqlatisf3d )
404         END IF
405!=============================================================================================================================================
406
407         IF( kt == nit000 ) THEN                         !   set the forcing field at nit000 - 1    !
408            IF( ln_rstart .AND.    &                     ! Restart: read in restart file
409                 & iom_varid( numror, 'fwf_isf_b', ldstop = .FALSE. ) > 0 ) THEN
410               IF(lwp) WRITE(numout,*) '          nit000-1 isf tracer content forcing fields read in the restart file'
411               CALL iom_get( numror, jpdom_autoglo, 'fwf_isf_b', fwfisf_b(:,:) )   ! before salt content isf_tsc trend
412               CALL iom_get( numror, jpdom_autoglo, 'isf_sc_b', risf_tsc_b(:,:,jp_sal) )   ! before salt content isf_tsc trend
413               CALL iom_get( numror, jpdom_autoglo, 'isf_hc_b', risf_tsc_b(:,:,jp_tem) )   ! before salt content isf_tsc trend
414            ELSE
415               fwfisf_b(:,:)    = fwfisf(:,:)
416               risf_tsc_b(:,:,:)= risf_tsc(:,:,:)
417            END IF
418         END IF
419         !
420         ! deallocation
421         CALL wrk_dealloc( jpi,jpj, ztfrz, zdep  )
422      END IF
423     
424  END SUBROUTINE sbc_isf
425
426
427  INTEGER FUNCTION sbc_isf_alloc()
428      !!----------------------------------------------------------------------
429      !!               ***  FUNCTION sbc_isf_rnf_alloc  ***
430      !!----------------------------------------------------------------------
431      sbc_isf_alloc = 0       ! set to zero if no array to be allocated
432      IF( .NOT. ALLOCATED( qisf ) ) THEN
433         ALLOCATE(  risf_tsc(jpi,jpj,jpts), risf_tsc_b(jpi,jpj,jpts), qisf(jpi,jpj)   , &
434               &    rhisf_tbl(jpi,jpj)    , r1_hisf_tbl(jpi,jpj), rzisf_tbl(jpi,jpj)  , &
435               &    ttbl(jpi,jpj)         , stbl(jpi,jpj)       , utbl(jpi,jpj)       , &
436               &    vtbl(jpi, jpj)        , risfLeff(jpi,jpj)   , rhisf_tbl_0(jpi,jpj), &
437               &    ralpha(jpi,jpj)       , misfkt(jpi,jpj)     , misfkb(jpi,jpj)     , &
438               &    qhcisf(jpi,jpj), STAT= sbc_isf_alloc )
439         !
440         IF( lk_mpp             )   CALL mpp_sum ( sbc_isf_alloc )
441         IF( sbc_isf_alloc /= 0 )   CALL ctl_warn('sbc_isf_alloc: failed to allocate arrays.')
442         !
443      END IF
444  END FUNCTION
445
446  SUBROUTINE sbc_isf_bg03(kt)
447      !!---------------------------------------------------------------------
448      !!                  ***  ROUTINE sbc_isf_bg03  ***
449      !!
450      !! ** Purpose : add net heat and fresh water flux from ice shelf melting
451      !!          into the adjacent ocean
452      !!
453      !! ** Method  :   See reference
454      !!
455      !! ** Reference : Beckmann and Goosse (2003), "A parameterization of ice shelf-ocean
456      !!         interaction for climate models", Ocean Modelling 5(2003) 157-170.
457      !!         (hereafter BG)
458      !! History :
459      !!         06-02  (C. Wang) Original code
460      !!----------------------------------------------------------------------
461      INTEGER, INTENT ( in ) :: kt
462      !
463      INTEGER  :: ji, jj, jk ! dummy loop index
464      INTEGER  :: ik         ! current level
465      REAL(wp) :: zt_sum     ! sum of the temperature between 200m and 600m
466      REAL(wp) :: zt_ave     ! averaged temperature between 200m and 600m
467      REAL(wp) :: ztfrz     ! freezing point temperature at depth z
468      REAL(wp) :: zpress     ! pressure to compute the freezing point in depth
469      !!----------------------------------------------------------------------
470
471      IF ( nn_timing == 1 ) CALL timing_start('sbc_isf_bg03')
472      !
473      DO ji = 1, jpi
474         DO jj = 1, jpj
475            ik = misfkt(ji,jj)
476            !! Initialize arrays to 0 (each step)
477            zt_sum = 0.e0_wp
478            IF ( ik > 1 ) THEN
479               ! 1. -----------the average temperature between 200m and 600m ---------------------
480               DO jk = misfkt(ji,jj),misfkb(ji,jj)
481                  ! freezing point temperature  at ice shelf base BG eq. 2 (JMM sign pb ??? +7.64e-4 !!!)
482                  ! after verif with UNESCO, wrong sign in BG eq. 2
483                  ! Calculate freezing temperature
484                  CALL eos_fzp(stbl(ji,jj), ztfrz, gdept_n(ji,jj,jk)) 
485                  zt_sum = zt_sum + (tsn(ji,jj,jk,jp_tem)-ztfrz) * fse3t(ji,jj,jk) * tmask(ji,jj,jk)  ! sum temp
486               END DO
487               zt_ave = zt_sum/rhisf_tbl(ji,jj) ! calcul mean value
488               ! 2. ------------Net heat flux and fresh water flux due to the ice shelf
489               ! For those corresponding to zonal boundary   
490               qisf(ji,jj) = - rau0 * rcp * rn_gammat0 * risfLeff(ji,jj) * e1t(ji,jj) * zt_ave  &
491                           & / (e1t(ji,jj) * e2t(ji,jj)) * tmask(ji,jj,jk)
492             
493               fwfisf(ji,jj) = qisf(ji,jj) / rlfusisf          !fresh water flux kg/(m2s)                 
494               fwfisf(ji,jj) = fwfisf(ji,jj) * ( soce / stbl(ji,jj) )
495               !add to salinity trend
496            ELSE
497               qisf(ji,jj) = 0._wp ; fwfisf(ji,jj) = 0._wp
498            END IF
499         END DO
500      END DO
501      !
502      IF( nn_timing == 1 )  CALL timing_stop('sbc_isf_bg03')
503      !
504  END SUBROUTINE sbc_isf_bg03
505
506   SUBROUTINE sbc_isf_cav( kt )
507      !!---------------------------------------------------------------------
508      !!                     ***  ROUTINE sbc_isf_cav  ***
509      !!
510      !! ** Purpose :   handle surface boundary condition under ice shelf
511      !!
512      !! ** Method  : -
513      !!
514      !! ** Action  :   utau, vtau : remain unchanged
515      !!                taum, wndm : remain unchanged
516      !!                qns        : update heat flux below ice shelf
517      !!                emp, emps  : update freshwater flux below ice shelf
518      !!---------------------------------------------------------------------
519      INTEGER, INTENT(in)          ::   kt         ! ocean time step
520      !
521      INTEGER  ::   ji, jj     ! dummy loop indices
522      INTEGER  ::   nit
523      REAL(wp) ::   zlamb1, zlamb2, zlamb3
524      REAL(wp) ::   zeps1,zeps2,zeps3,zeps4,zeps6,zeps7
525      REAL(wp) ::   zaqe,zbqe,zcqe,zaqer,zdis,zcfac
526      REAL(wp) ::   zeps = 1.e-20_wp       
527      REAL(wp) ::   zerr
528      REAL(wp), DIMENSION(:,:), POINTER ::   ztfrz, zsfrz
529      REAL(wp), DIMENSION(:,:), POINTER ::   zgammat, zgammas 
530      REAL(wp), DIMENSION(:,:), POINTER ::   zfwflx, zhtflx, zhtflx_b
531      LOGICAL  ::   lit
532      !!---------------------------------------------------------------------
533      ! coeficient for linearisation of potential tfreez
534      ! Crude approximation for pressure (but commonly used)
535      IF ( ln_useCT ) THEN   ! linearisation from Jourdain et al. (2017)
536         zlamb1 =-0.0564_wp
537         zlamb2 = 0.0773_wp
538         zlamb3 =-7.8633e-8 * grav * rau0
539      ELSE                  ! linearisation from table 4 (Asay-Davis et al., 2015)
540         zlamb1 =-0.0573_wp
541         zlamb2 = 0.0832_wp
542         zlamb3 =-7.53e-8 * grav * rau0
543      ENDIF
544      !
545      IF( nn_timing == 1 )  CALL timing_start('sbc_isf_cav')
546      !
547      CALL wrk_alloc( jpi,jpj, ztfrz  , zsfrz  , zgammat, zgammas  )
548      CALL wrk_alloc( jpi,jpj, zfwflx, zhtflx , zhtflx_b )
549
550      ! initialisation
551      zgammat(:,:) = rn_gammat0 ; zgammas (:,:) = rn_gammas0
552      zhtflx (:,:) = 0.0_wp     ; zhtflx_b(:,:) = 0.0_wp   
553      zfwflx (:,:) = 0.0_wp     ; zsfrz(:,:) = 0.0_wp
554
555      ! compute ice shelf melting
556      nit = 1 ; lit = .TRUE.
557      DO WHILE ( lit )    ! maybe just a constant number of iteration as in blk_core is fine
558         SELECT CASE ( nn_isfblk )
559         CASE ( 1 )   !  ISOMIP formulation (2 equations) for volume flux (Hunter et al., 2006)
560            ! Calculate freezing temperature
561            CALL eos_fzp( stbl(:,:), ztfrz(:,:), risfdep(:,:) )
562
563            ! compute gammat every where (2d)
564            CALL sbc_isf_gammats(zgammat, zgammas, zhtflx, zfwflx)
565           
566            ! compute upward heat flux zhtflx and upward water flux zwflx
567            DO jj = 1, jpj
568               DO ji = 1, jpi
569                  zhtflx(ji,jj) =   zgammat(ji,jj)*rcp*rau0*(ttbl(ji,jj)-ztfrz(ji,jj))
570                  zfwflx(ji,jj) = - zhtflx(ji,jj)/rlfusisf
571               END DO
572            END DO
573
574            ! Compute heat flux and upward fresh water flux
575            qisf  (:,:) = - zhtflx(:,:) * ssisfmask(:,:)
576            fwfisf(:,:) =   zfwflx(:,:) * ssisfmask(:,:)
577
578         CASE ( 2 )  ! ISOMIP+ formulation (3 equations) for volume flux (Asay-Davis et al., 2015)
579            ! compute gammat every where (2d)
580            CALL sbc_isf_gammats(zgammat, zgammas, zhtflx, zfwflx)
581
582            ! compute upward heat flux zhtflx and upward water flux zwflx
583            ! Resolution of a 2d equation from equation 21, 22 and 23 to find Sb (Asay-Davis et al., 2015)
584            DO jj = 1, jpj
585               DO ji = 1, jpi
586                  ! compute coeficient to solve the 2nd order equation
587                  zeps1 = rcp*rau0*zgammat(ji,jj)
588                  zeps2 = rlfusisf*rau0*zgammas(ji,jj)
589                  zeps3 = rhoisf*rcpi*rkappa/MAX(risfdep(ji,jj),zeps)
590                  zeps4 = zlamb2+zlamb3*risfdep(ji,jj)
591                  zeps6 = zeps4-ttbl(ji,jj)
592                  zeps7 = zeps4-tsurf
593                  zaqe  = zlamb1 * (zeps1 + zeps3)
594                  zaqer = 0.5_wp/MIN(zaqe,-zeps)
595                  zbqe  = zeps1*zeps6+zeps3*zeps7-zeps2
596                  zcqe  = zeps2*stbl(ji,jj)
597                  zdis  = zbqe*zbqe-4.0_wp*zaqe*zcqe               
598
599                  ! Presumably zdis can never be negative because gammas is very small compared to gammat
600                  ! compute s freeze
601                  zsfrz(ji,jj)=(-zbqe-SQRT(zdis))*zaqer
602                  IF ( zsfrz(ji,jj) < 0.0_wp ) zsfrz(ji,jj)=(-zbqe+SQRT(zdis))*zaqer
603
604                  ! compute t freeze (eq. 22)
605                  ztfrz(ji,jj)=( zeps4+zlamb1*zsfrz(ji,jj) ) * ssisfmask(ji,jj)
606 
607                  ! zfwflx is upward water flux
608                  ! zhtflx is upward heat flux (out of ocean)
609                  ! compute the upward water and heat flux (eq. 28 and eq. 29)
610                  zfwflx(ji,jj) = rau0 * zgammas(ji,jj) * (zsfrz(ji,jj)-stbl(ji,jj)) / MAX(zsfrz(ji,jj),zeps)
611                  zhtflx(ji,jj) = zgammat(ji,jj) * rau0 * rcp * (ttbl(ji,jj) - ztfrz(ji,jj) ) 
612               END DO
613            END DO
614            !
615            ! mask heat and water flux
616            fwfisf(:,:) =   zfwflx(:,:) * ssisfmask(:,:)
617            qisf  (:,:) = - zhtflx(:,:) * ssisfmask(:,:)
618            !
619            ! compute heat content flux
620            qhcisf(:,:) = - fwfisf(:,:) * ztfrz(:,:) * rcp 
621
622         END SELECT
623
624         ! define if we need to iterate (nn_gammablk 0/1 do not need iteration)
625         IF ( nn_gammablk <  2 ) THEN ; lit = .FALSE.
626         ELSE                           
627            ! check total number of iteration
628            IF (nit >= 100) THEN ; CALL ctl_stop( 'STOP', 'sbc_isf_hol99 : too many iteration ...' )
629            ELSE                 ; nit = nit + 1
630            END IF
631
632            ! compute error between 2 iterations
633            ! if needed save gammat and compute zhtflx_b for next iteration
634            zerr = MAXVAL(ABS(zhtflx-zhtflx_b))
635            IF ( zerr <= 0.01_wp ) THEN ; lit = .FALSE.
636            ELSE                        ; zhtflx_b(:,:) = zhtflx(:,:)
637            END IF
638         END IF
639      END DO
640      !
641      CALL iom_put('isftfrz'  , ztfrz  )
642      CALL iom_put('isfsfrz'  , zsfrz  )
643      CALL iom_put('isfgammat', zgammat)
644      CALL iom_put('isfgammas', zgammas)
645      !
646      CALL wrk_dealloc( jpi,jpj, ztfrz  , zgammat, zgammas  )
647      CALL wrk_dealloc( jpi,jpj, zfwflx, zhtflx , zhtflx_b )
648      !
649      IF( nn_timing == 1 )  CALL timing_stop('sbc_isf_cav')
650      !
651   END SUBROUTINE sbc_isf_cav
652
653   SUBROUTINE sbc_isf_gammats(pgt, pgs, pqhisf, pqwisf )
654      !!----------------------------------------------------------------------
655      !! ** Purpose    : compute the coefficient echange for heat flux
656      !!
657      !! ** Method     : gamma assume constant or depends of u* and stability
658      !!
659      !! ** References : Holland and Jenkins, 1999, JPO, p1787-1800, eq 14
660      !!                Jenkins et al., 2010, JPO, p2298-2312
661      !!---------------------------------------------------------------------
662      REAL(wp), DIMENSION(:,:), INTENT(out) :: pgt, pgs
663      REAL(wp), DIMENSION(:,:), INTENT(in ) :: pqhisf, pqwisf
664      !
665      INTEGER  :: ikt                       
666      INTEGER  :: ji, jj                     ! loop index
667      REAL(wp), DIMENSION(:,:), POINTER :: zustar           ! U, V at T point and friction velocity
668      REAL(wp) :: zdku, zdkv                 ! U, V shear
669      REAL(wp) :: zPr, zSc, zRc              ! Prandtl, Scmidth and Richardson number
670      REAL(wp) :: zmob, zmols                ! Monin Obukov length, coriolis factor at T point
671      REAL(wp) :: zbuofdep, zhnu             ! Bouyancy length scale, sublayer tickness
672      REAL(wp) :: zhmax                      ! limitation of mol
673      REAL(wp) :: zetastar                   ! stability parameter
674      REAL(wp) :: zgmolet, zgmoles, zgturb   ! contribution of modelecular sublayer and turbulence
675      REAL(wp) :: zcoef                      ! temporary coef
676      REAL(wp) :: zdep
677      REAL(wp) :: zeps = 1.0e-20_wp   
678      REAL(wp), PARAMETER :: zxsiN = 0.052_wp   ! dimensionless constant
679      REAL(wp), PARAMETER :: znu   = 1.95e-6_wp ! kinamatic viscosity of sea water (m2.s-1)
680      REAL(wp), DIMENSION(2) :: zts, zab
681      !!---------------------------------------------------------------------
682      CALL wrk_alloc( jpi,jpj, zustar )
683      !
684      SELECT CASE ( nn_gammablk )
685      CASE ( 0 ) ! gamma is constant (specified in namelist)
686         !! ISOMIP formulation (Hunter et al, 2006)
687         pgt(:,:) = rn_gammat0
688         pgs(:,:) = rn_gammas0
689
690      CASE ( 1 ) ! gamma is assume to be proportional to u*
691         !! Jenkins et al., 2010, JPO, p2298-2312
692         !! Adopted by Asay-Davis et al. (2015)
693
694         !! compute ustar (eq. 24)
695         zustar(:,:) = SQRT( rn_tfri2 * (utbl(:,:) * utbl(:,:) + vtbl(:,:) * vtbl(:,:) + rn_tfeb2) )
696
697         !! Compute gammats
698         pgt(:,:) = zustar(:,:) * rn_gammat0
699         pgs(:,:) = zustar(:,:) * rn_gammas0
700     
701      CASE ( 2 ) ! gamma depends of stability of boundary layer
702         !! Holland and Jenkins, 1999, JPO, p1787-1800, eq 14
703         !! as MOL depends of flux and flux depends of MOL, best will be iteration (TO DO)
704         !! compute ustar
705         zustar(:,:) = SQRT( rn_tfri2 * (utbl(:,:) * utbl(:,:) + vtbl(:,:) * vtbl(:,:) + rn_tfeb2) )
706
707         !! compute Pr and Sc number (can be improved)
708         zPr =   13.8_wp
709         zSc = 2432.0_wp
710
711         !! compute gamma mole
712         zgmolet = 12.5_wp * zPr ** (2.0/3.0) - 6.0_wp
713         zgmoles = 12.5_wp * zSc ** (2.0/3.0) - 6.0_wp
714
715         !! compute gamma
716         DO ji=2,jpi
717            DO jj=2,jpj
718               ikt = mikt(ji,jj)
719
720               IF (zustar(ji,jj) == 0._wp) THEN           ! only for kt = 1 I think
721                  pgt = rn_gammat0
722                  pgs = rn_gammas0
723               ELSE
724                  !! compute Rc number (as done in zdfric.F90)
725                  zcoef = 0.5_wp / fse3w(ji,jj,ikt)
726                  !                                            ! shear of horizontal velocity
727                  zdku = zcoef * (  un(ji-1,jj  ,ikt  ) + un(ji,jj,ikt  )  &
728                     &             -un(ji-1,jj  ,ikt+1) - un(ji,jj,ikt+1)  )
729                  zdkv = zcoef * (  vn(ji  ,jj-1,ikt  ) + vn(ji,jj,ikt  )  &
730                     &             -vn(ji  ,jj-1,ikt+1) - vn(ji,jj,ikt+1)  )
731                  !                                            ! richardson number (minimum value set to zero)
732                  zRc = rn2(ji,jj,ikt+1) / MAX( zdku*zdku + zdkv*zdkv, zeps )
733
734                  !! compute bouyancy
735                  zts(jp_tem) = ttbl(ji,jj)
736                  zts(jp_sal) = stbl(ji,jj)
737                  zdep        = fsdepw(ji,jj,ikt)
738                  !
739                  CALL eos_rab( zts, zdep, zab )
740                  !
741                  !! compute length scale
742                  zbuofdep = grav * ( zab(jp_tem) * pqhisf(ji,jj) - zab(jp_sal) * pqwisf(ji,jj) )  !!!!!!!!!!!!!!!!!!!!!!!!!!!!
743
744                  !! compute Monin Obukov Length
745                  ! Maximum boundary layer depth
746                  zhmax = fsdept(ji,jj,mbkt(ji,jj)) - fsdepw(ji,jj,mikt(ji,jj)) - 0.001_wp
747                  ! Compute Monin obukhov length scale at the surface and Ekman depth:
748                  zmob   = zustar(ji,jj) ** 3 / (vkarmn * (zbuofdep + zeps))
749                  zmols  = SIGN(1._wp, zmob) * MIN(ABS(zmob), zhmax) * tmask(ji,jj,ikt)
750
751                  !! compute eta* (stability parameter)
752                  zetastar = 1._wp / ( SQRT(1._wp + MAX(zxsiN * zustar(ji,jj) / ( ABS(ff(ji,jj)) * zmols * zRc ), 0.0_wp)))
753
754                  !! compute the sublayer thickness
755                  zhnu = 5 * znu / zustar(ji,jj)
756
757                  !! compute gamma turb
758                  zgturb = 1._wp / vkarmn * LOG(zustar(ji,jj) * zxsiN * zetastar * zetastar / ( ABS(ff(ji,jj)) * zhnu )) &
759                  &      + 1._wp / ( 2 * zxsiN * zetastar ) - 1._wp / vkarmn
760
761                  !! compute gammats
762                  pgt(ji,jj) = zustar(ji,jj) / (zgturb + zgmolet)
763                  pgs(ji,jj) = zustar(ji,jj) / (zgturb + zgmoles)
764               END IF
765            END DO
766         END DO
767         CALL lbc_lnk(pgt(:,:),'T',1.)
768         CALL lbc_lnk(pgs(:,:),'T',1.)
769      END SELECT
770      CALL wrk_dealloc( jpi,jpj, zustar )
771      !
772   END SUBROUTINE sbc_isf_gammats
773
774   SUBROUTINE sbc_isf_tbl( pvarin, pvarout, cd_ptin )
775      !!----------------------------------------------------------------------
776      !!                  ***  SUBROUTINE sbc_isf_tbl  ***
777      !!
778      !! ** Purpose : compute mean T/S/U/V in the boundary layer at T- point
779      !!
780      !!----------------------------------------------------------------------
781      REAL(wp), DIMENSION(:,:,:), INTENT( in  ) :: pvarin
782      REAL(wp), DIMENSION(:,:)  , INTENT( out ) :: pvarout
783      CHARACTER(len=1),           INTENT( in  ) :: cd_ptin ! point of variable in/out
784      !
785      REAL(wp) :: ze3, zhk
786      REAL(wp), DIMENSION(:,:), POINTER :: zhisf_tbl ! thickness of the tbl
787
788      INTEGER :: ji, jj, jk                  ! loop index
789      INTEGER :: ikt, ikb                    ! top and bottom index of the tbl
790      !!----------------------------------------------------------------------
791      ! allocation
792      CALL wrk_alloc( jpi,jpj, zhisf_tbl)
793     
794      ! initialisation
795      pvarout(:,:)=0._wp
796   
797      SELECT CASE ( cd_ptin )
798      CASE ( 'U' ) ! compute U in the top boundary layer at T- point
799         DO jj = 1,jpj
800            DO ji = 1,jpi
801               ikt = miku(ji,jj) ; ikb = miku(ji,jj)
802               ! thickness of boundary layer at least the top level thickness
803               zhisf_tbl(ji,jj) = MAX(rhisf_tbl_0(ji,jj), fse3u_n(ji,jj,ikt))
804
805               ! determine the deepest level influenced by the boundary layer
806               DO jk = ikt+1, mbku(ji,jj)
807                  IF ( (SUM(fse3u_n(ji,jj,ikt:jk-1)) < zhisf_tbl(ji,jj)) .AND. (umask(ji,jj,jk) == 1) ) ikb = jk
808               END DO
809               zhisf_tbl(ji,jj) = MIN(zhisf_tbl(ji,jj), SUM(fse3u_n(ji,jj,ikt:ikb)))  ! limit the tbl to water thickness.
810
811               ! level fully include in the ice shelf boundary layer
812               DO jk = ikt, ikb - 1
813                  ze3 = fse3u_n(ji,jj,jk)
814                  pvarout(ji,jj) = pvarout(ji,jj) + pvarin(ji,jj,jk) / zhisf_tbl(ji,jj) * ze3
815               END DO
816
817               ! level partially include in ice shelf boundary layer
818               zhk = SUM( fse3u_n(ji, jj, ikt:ikb - 1)) / zhisf_tbl(ji,jj)
819               pvarout(ji,jj) = pvarout(ji,jj) + pvarin(ji,jj,ikb) * (1._wp - zhk)
820            END DO
821         END DO
822         DO jj = 2,jpj
823            DO ji = 2,jpi
824               pvarout(ji,jj) = 0.5_wp * (pvarout(ji,jj) + pvarout(ji-1,jj))
825            END DO
826         END DO
827         CALL lbc_lnk(pvarout,'T',-1.)
828     
829      CASE ( 'V' ) ! compute V in the top boundary layer at T- point
830         DO jj = 1,jpj
831            DO ji = 1,jpi
832               ikt = mikv(ji,jj) ; ikb = mikv(ji,jj)
833               ! thickness of boundary layer at least the top level thickness
834               zhisf_tbl(ji,jj) = MAX(rhisf_tbl_0(ji,jj), fse3v_n(ji,jj,ikt))
835
836               ! determine the deepest level influenced by the boundary layer
837               DO jk = ikt+1, mbkv(ji,jj)
838                  IF ( (SUM(fse3v_n(ji,jj,ikt:jk-1)) < zhisf_tbl(ji,jj)) .AND. (vmask(ji,jj,jk) == 1) ) ikb = jk
839               END DO
840               zhisf_tbl(ji,jj) = MIN(zhisf_tbl(ji,jj), SUM(fse3v_n(ji,jj,ikt:ikb)))  ! limit the tbl to water thickness.
841
842               ! level fully include in the ice shelf boundary layer
843               DO jk = ikt, ikb - 1
844                  ze3 = fse3v_n(ji,jj,jk)
845                  pvarout(ji,jj) = pvarout(ji,jj) + pvarin(ji,jj,jk) / zhisf_tbl(ji,jj) * ze3
846               END DO
847
848               ! level partially include in ice shelf boundary layer
849               zhk = SUM( fse3v_n(ji, jj, ikt:ikb - 1)) / zhisf_tbl(ji,jj)
850               pvarout(ji,jj) = pvarout(ji,jj) + pvarin(ji,jj,ikb) * (1._wp - zhk)
851            END DO
852         END DO
853         DO jj = 2,jpj
854            DO ji = 2,jpi
855               pvarout(ji,jj) = 0.5_wp * (pvarout(ji,jj) + pvarout(ji,jj-1))
856            END DO
857         END DO
858         CALL lbc_lnk(pvarout,'T',-1.)
859
860      CASE ( 'T' ) ! compute T in the top boundary layer at T- point
861         DO jj = 1,jpj
862            DO ji = 1,jpi
863               ikt = misfkt(ji,jj)
864               ikb = misfkb(ji,jj)
865
866               ! level fully include in the ice shelf boundary layer
867               DO jk = ikt, ikb - 1
868                  ze3 = fse3t_n(ji,jj,jk)
869                  pvarout(ji,jj) = pvarout(ji,jj) + pvarin(ji,jj,jk) * r1_hisf_tbl(ji,jj) * ze3
870               END DO
871
872               ! level partially include in ice shelf boundary layer
873               zhk = SUM( fse3t_n(ji, jj, ikt:ikb - 1)) * r1_hisf_tbl(ji,jj)
874               pvarout(ji,jj) = pvarout(ji,jj) + pvarin(ji,jj,ikb) * (1._wp - zhk)
875            END DO
876         END DO
877      END SELECT
878
879      ! mask mean tbl value
880      pvarout(:,:) = pvarout(:,:) * ssisfmask(:,:)
881
882      ! deallocation
883      CALL wrk_dealloc( jpi,jpj, zhisf_tbl )     
884      !
885   END SUBROUTINE sbc_isf_tbl
886     
887
888   SUBROUTINE sbc_isf_div( phdivn )
889      !!----------------------------------------------------------------------
890      !!                  ***  SUBROUTINE sbc_isf_div  ***
891      !!       
892      !! ** Purpose :   update the horizontal divergence with the runoff inflow
893      !!
894      !! ** Method  :   
895      !!                CAUTION : risf_tsc(:,:,jp_sal) is negative (outflow) increase the
896      !!                          divergence and expressed in m/s
897      !!
898      !! ** Action  :   phdivn   decreased by the runoff inflow
899      !!----------------------------------------------------------------------
900      REAL(wp), DIMENSION(:,:,:), INTENT( inout ) ::   phdivn   ! horizontal divergence
901      !
902      INTEGER  ::   ji, jj, jk   ! dummy loop indices
903      INTEGER  ::   ikt, ikb 
904      REAL(wp) ::   zhk
905      REAL(wp) ::   zfact     ! local scalar
906      !!----------------------------------------------------------------------
907      !
908      zfact   = 0.5_wp
909      !
910      IF ( lk_vvl ) THEN     ! need to re compute level distribution of isf fresh water
911         DO jj = 1,jpj
912            DO ji = 1,jpi
913               ikt = misfkt(ji,jj)
914               ikb = misfkt(ji,jj)
915               ! thickness of boundary layer at least the top level thickness
916               rhisf_tbl(ji,jj) = MAX(rhisf_tbl_0(ji,jj), fse3t(ji,jj,ikt))
917
918               ! determine the deepest level influenced by the boundary layer
919               DO jk = ikt+1, mbkt(ji,jj)
920                  IF ( (SUM(fse3t(ji,jj,ikt:jk-1)) <  rhisf_tbl(ji,jj)) .AND. (tmask(ji,jj,jk) == 1) ) ikb = jk
921               END DO
922               rhisf_tbl(ji,jj) = MIN(rhisf_tbl(ji,jj), SUM(fse3t(ji,jj,ikt:ikb)))  ! limit the tbl to water thickness.
923               misfkb(ji,jj) = ikb                                                  ! last wet level of the tbl
924               r1_hisf_tbl(ji,jj) = 1._wp / rhisf_tbl(ji,jj)
925
926               zhk           = SUM( fse3t(ji, jj, ikt:ikb - 1)) * r1_hisf_tbl(ji,jj) ! proportion of tbl cover by cell from ikt to ikb - 1
927               ralpha(ji,jj) = rhisf_tbl(ji,jj) * (1._wp - zhk ) / fse3t(ji,jj,ikb)  ! proportion of bottom cell influenced by boundary layer
928            END DO
929         END DO
930      END IF 
931      !
932      !==   ice shelf melting distributed over several levels   ==!
933      DO jj = 1,jpj
934         DO ji = 1,jpi
935               ikt = misfkt(ji,jj)
936               ikb = misfkb(ji,jj)
937               ! level fully include in the ice shelf boundary layer
938               DO jk = ikt, ikb - 1
939                  phdivn(ji,jj,jk) = phdivn(ji,jj,jk) + ( fwfisf(ji,jj) + fwfisf_b(ji,jj) ) &
940                    &              * r1_hisf_tbl(ji,jj) * r1_rau0 * zfact
941               END DO
942               ! level partially include in ice shelf boundary layer
943               phdivn(ji,jj,ikb) = phdivn(ji,jj,ikb) + ( fwfisf(ji,jj) &
944                    &            + fwfisf_b(ji,jj) ) * r1_hisf_tbl(ji,jj) * r1_rau0 * zfact * ralpha(ji,jj) 
945         END DO
946      END DO
947      !
948   END SUBROUTINE sbc_isf_div
949   !!======================================================================
950END MODULE sbcisf
Note: See TracBrowser for help on using the repository browser.