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

source: branches/2017/dev_r8600_xios_read_write/NEMOGCM/NEMO/OPA_SRC/SBC/sbcisf.F90 @ 8793

Last change on this file since 8793 was 8793, checked in by andmirek, 6 years ago

#1953 and #1962 change lxios_read to lrxios to be consistent with write branch

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