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

source: branches/2017/dev_r7881_no_wrk_alloc/NEMOGCM/NEMO/OPA_SRC/SBC/sbcisf.F90 @ 7910

Last change on this file since 7910 was 7910, checked in by timgraham, 7 years ago

All wrk_alloc removed

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