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/2017/dev_r8126_ROBUST08_no_ghost/NEMOGCM/NEMO/OPA_SRC/SBC – NEMO

source: branches/2017/dev_r8126_ROBUST08_no_ghost/NEMOGCM/NEMO/OPA_SRC/SBC/sbcisf.F90 @ 8809

Last change on this file since 8809 was 7968, checked in by clem, 7 years ago

commits following ticket #1889

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