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

source: branches/2017/dev_r8600_xios_read_write_v2/NEMOGCM/NEMO/OPA_SRC/SBC/sbcisf.F90 @ 8836

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

#1953 and #1962 Techinal corrections

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