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

source: trunk/NEMOGCM/NEMO/OPA_SRC/SBC/sbcisf.F90 @ 8329

Last change on this file since 8329 was 8329, checked in by rblod, 7 years ago

Lines over 132 see ticket #1921

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