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.
limthd_dif.F90 in trunk/NEMOGCM/NEMO/LIM_SRC_3 – NEMO

source: trunk/NEMOGCM/NEMO/LIM_SRC_3/limthd_dif.F90 @ 3319

Last change on this file since 3319 was 3294, checked in by rblod, 12 years ago

Merge of 3.4beta into the trunk

  • Property svn:keywords set to Id
File size: 38.0 KB
Line 
1MODULE limthd_dif
2   !!======================================================================
3   !!                       ***  MODULE limthd_dif ***
4   !!                       heat diffusion in sea ice
5   !!                   computation of surface and inner T 
6   !!======================================================================
7   !! History :  LIM  ! 02-2003 (M. Vancoppenolle) original 1D code
8   !!                 ! 06-2005 (M. Vancoppenolle) 3d version
9   !!                 ! 11-2006 (X Fettweis) Vectorization by Xavier
10   !!                 ! 04-2007 (M. Vancoppenolle) Energy conservation
11   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
12   !!----------------------------------------------------------------------
13#if defined key_lim3
14   !!----------------------------------------------------------------------
15   !!   'key_lim3'                                      LIM3 sea-ice model
16   !!----------------------------------------------------------------------
17   USE par_oce          ! ocean parameters
18   USE phycst           ! physical constants (ocean directory)
19   USE ice              ! LIM-3 variables
20   USE par_ice          ! LIM-3 parameters
21   USE thd_ice          ! LIM-3: thermodynamics
22   USE in_out_manager   ! I/O manager
23   USE lib_mpp          ! MPP library
24   USE wrk_nemo         ! work arrays
25
26   IMPLICIT NONE
27   PRIVATE
28
29   PUBLIC   lim_thd_dif   ! called by lim_thd
30
31   REAL(wp) ::   epsi20 = 1e-20     ! constant values
32   REAL(wp) ::   epsi13 = 1e-13     ! constant values
33
34   !!----------------------------------------------------------------------
35   !! NEMO/LIM3 4.0 , UCL - NEMO Consortium (2011)
36   !! $Id$
37   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
38   !!----------------------------------------------------------------------
39CONTAINS
40
41   SUBROUTINE lim_thd_dif( kideb , kiut , jl )
42      !!------------------------------------------------------------------
43      !!                ***  ROUTINE lim_thd_dif  ***
44      !! ** Purpose :
45      !!           This routine determines the time evolution of snow and sea-ice
46      !!           temperature profiles.
47      !! ** Method  :
48      !!           This is done by solving the heat equation diffusion with
49      !!           a Neumann boundary condition at the surface and a Dirichlet one
50      !!           at the bottom. Solar radiation is partially absorbed into the ice.
51      !!           The specific heat and thermal conductivities depend on ice salinity
52      !!           and temperature to take into account brine pocket melting. The
53      !!           numerical
54      !!           scheme is an iterative Crank-Nicolson on a non-uniform multilayer grid
55      !!           in the ice and snow system.
56      !!
57      !!           The successive steps of this routine are
58      !!           1.  Thermal conductivity at the interfaces of the ice layers
59      !!           2.  Internal absorbed radiation
60      !!           3.  Scale factors due to non-uniform grid
61      !!           4.  Kappa factors
62      !!           Then iterative procedure begins
63      !!           5.  specific heat in the ice
64      !!           6.  eta factors
65      !!           7.  surface flux computation
66      !!           8.  tridiagonal system terms
67      !!           9.  solving the tridiagonal system with Gauss elimination
68      !!           Iterative procedure ends according to a criterion on evolution
69      !!           of temperature
70      !!
71      !! ** Arguments :
72      !!           kideb , kiut : Starting and ending points on which the
73      !!                         the computation is applied
74      !!
75      !! ** Inputs / Ouputs : (global commons)
76      !!           surface temperature : t_su_b
77      !!           ice/snow temperatures   : t_i_b, t_s_b
78      !!           ice salinities          : s_i_b
79      !!           number of layers in the ice/snow: nlay_i, nlay_s
80      !!           profile of the ice/snow layers : z_i, z_s
81      !!           total ice/snow thickness : ht_i_b, ht_s_b
82      !!
83      !! ** External :
84      !!
85      !! ** References :
86      !!
87      !! ** History :
88      !!           (02-2003) Martin Vancoppenolle, Louvain-la-Neuve, Belgium
89      !!           (06-2005) Martin Vancoppenolle, 3d version
90      !!           (11-2006) Vectorized by Xavier Fettweis (UCL-ASTR)
91      !!           (04-2007) Energy conservation tested by M. Vancoppenolle
92      !!------------------------------------------------------------------
93      INTEGER , INTENT (in) ::   kideb   ! Start point on which the  the computation is applied
94      INTEGER , INTENT (in) ::   kiut    ! End point on which the  the computation is applied
95      INTEGER , INTENT (in) ::   jl      ! Category number
96
97      !! * Local variables
98      INTEGER ::   ji          ! spatial loop index
99      INTEGER ::   ii, ij      ! temporary dummy loop index
100      INTEGER ::   numeq       ! current reference number of equation
101      INTEGER ::   layer       ! vertical dummy loop index
102      INTEGER ::   nconv       ! number of iterations in iterative procedure
103      INTEGER ::   minnumeqmin, maxnumeqmax
104
105      INTEGER , POINTER, DIMENSION(:) ::   numeqmin   ! reference number of top equation
106      INTEGER , POINTER, DIMENSION(:) ::   numeqmax   ! reference number of bottom equation
107      INTEGER , POINTER, DIMENSION(:) ::   isnow      ! switch for presence (1) or absence (0) of snow
108
109      !! * New local variables       
110      REAL(wp), POINTER, DIMENSION(:,:) ::   ztcond_i   !Ice thermal conductivity
111      REAL(wp), POINTER, DIMENSION(:,:) ::   zradtr_i   !Radiation transmitted through the ice
112      REAL(wp), POINTER, DIMENSION(:,:) ::   zradab_i   !Radiation absorbed in the ice
113      REAL(wp), POINTER, DIMENSION(:,:) ::   zkappa_i   !Kappa factor in the ice
114
115      REAL(wp), POINTER, DIMENSION(:,:) ::   zradtr_s   !Radiation transmited through the snow
116      REAL(wp), POINTER, DIMENSION(:,:) ::   zradab_s   !Radiation absorbed in the snow
117      REAL(wp), POINTER, DIMENSION(:,:) ::   zkappa_s   !Kappa factor in the snow
118
119      REAL(wp), POINTER, DIMENSION(:,:) ::   ztiold      !Old temperature in the ice
120      REAL(wp), POINTER, DIMENSION(:,:) ::   zeta_i      !Eta factor in the ice
121      REAL(wp), POINTER, DIMENSION(:,:) ::   ztitemp     !Temporary temperature in the ice to check the convergence
122      REAL(wp), POINTER, DIMENSION(:,:) ::   zspeche_i   !Ice specific heat
123      REAL(wp), POINTER, DIMENSION(:,:) ::   z_i         !Vertical cotes of the layers in the ice
124
125      REAL(wp), POINTER, DIMENSION(:,:) ::   zeta_s      !Eta factor in the snow
126      REAL(wp), POINTER, DIMENSION(:,:) ::   ztstemp     !Temporary temperature in the snow to check the convergence
127      REAL(wp), POINTER, DIMENSION(:,:) ::   ztsold      !Temporary temperature in the snow
128      REAL(wp), POINTER, DIMENSION(:,:) ::   z_s         !Vertical cotes of the layers in the snow
129
130      REAL(wp), POINTER, DIMENSION(:,:)   ::   zindterm    ! Independent term
131      REAL(wp), POINTER, DIMENSION(:,:)   ::   zindtbis    ! temporary independent term
132      REAL(wp), POINTER, DIMENSION(:,:)   ::   zdiagbis
133      REAL(wp), POINTER, DIMENSION(:,:,:) ::   ztrid       ! tridiagonal system terms
134
135      REAL(wp), POINTER, DIMENSION(:) ::   ztfs        ! ice melting point
136      REAL(wp), POINTER, DIMENSION(:) ::   ztsuold     ! old surface temperature (before the iterative procedure )
137      REAL(wp), POINTER, DIMENSION(:) ::   ztsuoldit   ! surface temperature at previous iteration
138      REAL(wp), POINTER, DIMENSION(:) ::   zh_i        ! ice layer thickness
139      REAL(wp), POINTER, DIMENSION(:) ::   zh_s        ! snow layer thickness
140      REAL(wp), POINTER, DIMENSION(:) ::   zfsw        ! solar radiation absorbed at the surface
141      REAL(wp), POINTER, DIMENSION(:) ::   zf          ! surface flux function
142      REAL(wp), POINTER, DIMENSION(:) ::   dzf         ! derivative of the surface flux function
143
144      REAL(wp) ::   zeps      =  1.e-10_wp    !
145      REAL(wp) ::   zg1s      =  2._wp        ! for the tridiagonal system
146      REAL(wp) ::   zg1       =  2._wp        !
147      REAL(wp) ::   zgamma    =  18009._wp    ! for specific heat
148      REAL(wp) ::   zbeta     =  0.117_wp     ! for thermal conductivity (could be 0.13)
149      REAL(wp) ::   zraext_s  =  1.e+8_wp     ! extinction coefficient of radiation in the snow
150      REAL(wp) ::   zkimin    =  0.10_wp      ! minimum ice thermal conductivity
151      REAL(wp) ::   zht_smin  =  1.e-4_wp     ! minimum snow depth
152
153      REAL(wp) ::   ztmelt_i    ! ice melting temperature
154      REAL(wp) ::   zerritmax   ! current maximal error on temperature
155      REAL(wp), POINTER, DIMENSION(:) ::   zerrit       ! current error on temperature
156      REAL(wp), POINTER, DIMENSION(:) ::   zdifcase     ! case of the equation resolution (1->4)
157      REAL(wp), POINTER, DIMENSION(:) ::   zftrice      ! solar radiation transmitted through the ice
158      REAL(wp), POINTER, DIMENSION(:) ::   zihic, zhsu
159      !!------------------------------------------------------------------
160      !
161      CALL wrk_alloc( kiut, numeqmin, numeqmax, isnow )   ! integer
162      CALL wrk_alloc( kiut,nlay_i+1, ztcond_i, zradtr_i, zradab_i, zkappa_i, ztiold, zeta_i, ztitemp, zspeche_i, z_i, kjstart=0 )
163      CALL wrk_alloc( kiut,nlay_s+1, zradtr_s, zradab_s, zkappa_s, zeta_s, ztstemp, ztsold, z_s, kjstart=0 )
164      CALL wrk_alloc( kiut,jkmax+2, zindterm, zindtbis, zdiagbis )
165      CALL wrk_alloc( kiut,jkmax+2,3, ztrid )
166      CALL wrk_alloc( kiut, ztfs, ztsuold, ztsuoldit, zh_i, zh_s, zfsw, zf, dzf )
167      CALL wrk_alloc( kiut, zerrit, zdifcase, zftrice, zihic, zhsu )
168
169      !------------------------------------------------------------------------------!
170      ! 1) Initialization                                                            !
171      !------------------------------------------------------------------------------!
172      !
173      DO ji = kideb , kiut
174         ! is there snow or not
175         isnow(ji)= INT(  1._wp - MAX( 0._wp , SIGN(1._wp, - ht_s_b(ji) ) )  )
176         ! surface temperature of fusion
177!!gm ???  ztfs(ji) = rtt !!!????
178         ztfs(ji) = isnow(ji) * rtt + (1.0-isnow(ji)) * rtt
179         ! layer thickness
180         zh_i(ji) = ht_i_b(ji) / nlay_i
181         zh_s(ji) = ht_s_b(ji) / nlay_s
182      END DO
183
184      !--------------------
185      ! Ice / snow layers
186      !--------------------
187
188      z_s(:,0) = 0._wp   ! vert. coord. of the up. lim. of the 1st snow layer
189      z_i(:,0) = 0._wp   ! vert. coord. of the up. lim. of the 1st ice layer
190
191      DO layer = 1, nlay_s            ! vert. coord of the up. lim. of the layer-th snow layer
192         DO ji = kideb , kiut
193            z_s(ji,layer) = z_s(ji,layer-1) + ht_s_b(ji) / nlay_s
194         END DO
195      END DO
196
197      DO layer = 1, nlay_i            ! vert. coord of the up. lim. of the layer-th ice layer
198         DO ji = kideb , kiut
199            z_i(ji,layer) = z_i(ji,layer-1) + ht_i_b(ji) / nlay_i
200         END DO
201      END DO
202      !
203      !------------------------------------------------------------------------------|
204      ! 2) Radiations                                                                |
205      !------------------------------------------------------------------------------|
206      !
207      !-------------------
208      ! Computation of i0
209      !-------------------
210      ! i0 describes the fraction of solar radiation which does not contribute
211      ! to the surface energy budget but rather penetrates inside the ice.
212      ! We assume that no radiation is transmitted through the snow
213      ! If there is no no snow
214      ! zfsw    = (1-i0).qsr_ice   is absorbed at the surface
215      ! zftrice = io.qsr_ice       is below the surface
216      ! fstbif  = io.qsr_ice.exp(-k(h_i)) transmitted below the ice
217
218      DO ji = kideb , kiut
219         ! switches
220         isnow(ji) = INT(  1._wp - MAX( 0._wp , SIGN( 1._wp , - ht_s_b(ji) ) )  ) 
221         ! hs > 0, isnow = 1
222         zhsu (ji) = hnzst  ! threshold for the computation of i0
223         zihic(ji) = MAX( 0._wp , 1._wp - ( ht_i_b(ji) / zhsu(ji) ) )     
224
225         i0(ji)    = ( 1._wp - isnow(ji) ) * ( fr1_i0_1d(ji) + zihic(ji) * fr2_i0_1d(ji) )
226         !fr1_i0_1d = i0 for a thin ice surface
227         !fr1_i0_2d = i0 for a thick ice surface
228         !            a function of the cloud cover
229         !
230         !i0(ji)     =  (1.0-FLOAT(isnow(ji)))*3.0/(100*ht_s_b(ji)+10.0)
231         !formula used in Cice
232      END DO
233
234      !-------------------------------------------------------
235      ! Solar radiation absorbed / transmitted at the surface
236      ! Derivative of the non solar flux
237      !-------------------------------------------------------
238      DO ji = kideb , kiut
239         zfsw   (ji) =  qsr_ice_1d(ji) * ( 1 - i0(ji) )   ! Shortwave radiation absorbed at surface
240         zftrice(ji) =  qsr_ice_1d(ji) *       i0(ji)     ! Solar radiation transmitted below the surface layer
241         dzf    (ji) = dqns_ice_1d(ji)                    ! derivative of incoming nonsolar flux
242      END DO
243
244      !---------------------------------------------------------
245      ! Transmission - absorption of solar radiation in the ice
246      !---------------------------------------------------------
247
248      DO ji = kideb, kiut           ! snow initialization
249         zradtr_s(ji,0) = zftrice(ji)     ! radiation penetrating through snow
250      END DO
251
252      DO layer = 1, nlay_s          ! Radiation through snow
253         DO ji = kideb, kiut
254            !                             ! radiation transmitted below the layer-th snow layer
255            zradtr_s(ji,layer) = zradtr_s(ji,0) * EXP( - zraext_s * ( MAX ( 0._wp , z_s(ji,layer) ) ) )
256            !                             ! radiation absorbed by the layer-th snow layer
257            zradab_s(ji,layer) = zradtr_s(ji,layer-1) - zradtr_s(ji,layer)
258         END DO
259      END DO
260
261      DO ji = kideb, kiut           ! ice initialization
262         zradtr_i(ji,0) = zradtr_s(ji,nlay_s) * isnow(ji) + zftrice(ji) * ( 1._wp - isnow(ji) )
263      END DO
264
265      DO layer = 1, nlay_i          ! Radiation through ice
266         DO ji = kideb, kiut
267            !                             ! radiation transmitted below the layer-th ice layer
268            zradtr_i(ji,layer) = zradtr_i(ji,0) * EXP( - kappa_i * ( MAX ( 0._wp , z_i(ji,layer) ) ) )
269            !                             ! radiation absorbed by the layer-th ice layer
270            zradab_i(ji,layer) = zradtr_i(ji,layer-1) - zradtr_i(ji,layer)
271         END DO
272      END DO
273
274      DO ji = kideb, kiut           ! Radiation transmitted below the ice
275         fstbif_1d(ji) = fstbif_1d(ji) + zradtr_i(ji,nlay_i) * a_i_b(ji) / at_i_b(ji)
276      END DO
277
278      ! +++++
279      ! just to check energy conservation
280      DO ji = kideb, kiut
281         ii                = MOD( npb(ji) - 1, jpi ) + 1
282         ij                = ( npb(ji) - 1 ) / jpi + 1
283         fstroc(ii,ij,jl) = zradtr_i(ji,nlay_i)
284      END DO
285      ! +++++
286
287      DO layer = 1, nlay_i
288         DO ji = kideb, kiut
289            radab(ji,layer) = zradab_i(ji,layer)
290         END DO
291      END DO
292
293
294      !
295      !------------------------------------------------------------------------------|
296      !  3) Iterative procedure begins                                               |
297      !------------------------------------------------------------------------------|
298      !
299      DO ji = kideb, kiut        ! Old surface temperature
300         ztsuold  (ji) =  t_su_b(ji)                              ! temperature at the beg of iter pr.
301         ztsuoldit(ji) =  t_su_b(ji)                              ! temperature at the previous iter
302         t_su_b   (ji) =  MIN( t_su_b(ji), ztfs(ji)-0.00001 )     ! necessary
303         zerrit   (ji) =  1000._wp                                ! initial value of error
304      END DO
305
306      DO layer = 1, nlay_s       ! Old snow temperature
307         DO ji = kideb , kiut
308            ztsold(ji,layer) =  t_s_b(ji,layer)
309         END DO
310      END DO
311
312      DO layer = 1, nlay_i       ! Old ice temperature
313         DO ji = kideb , kiut
314            ztiold(ji,layer) =  t_i_b(ji,layer)
315         END DO
316      END DO
317
318      nconv     =  0           ! number of iterations
319      zerritmax =  1000._wp    ! maximal value of error on all points
320
321      DO WHILE ( zerritmax > maxer_i_thd .AND. nconv < nconv_i_thd )
322         !
323         nconv = nconv + 1
324         !
325         !------------------------------------------------------------------------------|
326         ! 4) Sea ice thermal conductivity                                              |
327         !------------------------------------------------------------------------------|
328         !
329         IF( thcon_i_swi == 0 ) THEN      ! Untersteiner (1964) formula
330            DO ji = kideb , kiut
331               ztcond_i(ji,0)        = rcdic + zbeta*s_i_b(ji,1) / MIN(-zeps,t_i_b(ji,1)-rtt)
332               ztcond_i(ji,0)        = MAX(ztcond_i(ji,0),zkimin)
333            END DO
334            DO layer = 1, nlay_i-1
335               DO ji = kideb , kiut
336                  ztcond_i(ji,layer) = rcdic + zbeta*( s_i_b(ji,layer) + s_i_b(ji,layer+1) ) /  &
337                     MIN(-2.0_wp * zeps, t_i_b(ji,layer)+t_i_b(ji,layer+1) - 2.0_wp * rtt)
338                  ztcond_i(ji,layer) = MAX(ztcond_i(ji,layer),zkimin)
339               END DO
340            END DO
341         ENDIF
342
343         IF( thcon_i_swi == 1 ) THEN      ! Pringle et al formula included: 2.11 + 0.09 S/T - 0.011.T
344            DO ji = kideb , kiut
345               ztcond_i(ji,0) = rcdic + 0.090_wp * s_i_b(ji,1) / MIN( -zeps, t_i_b(ji,1)-rtt )   &
346                  &                   - 0.011_wp * ( t_i_b(ji,1) - rtt ) 
347               ztcond_i(ji,0) = MAX( ztcond_i(ji,0), zkimin )
348            END DO
349            DO layer = 1, nlay_i-1
350               DO ji = kideb , kiut
351                  ztcond_i(ji,layer) = rcdic + 0.090_wp * ( s_i_b(ji,layer) + s_i_b(ji,layer+1) )   &
352                     &                                  / MIN(-2.0_wp * zeps, t_i_b(ji,layer)+t_i_b(ji,layer+1) - 2.0_wp * rtt)   &
353                     &                       - 0.0055_wp* ( t_i_b(ji,layer) + t_i_b(ji,layer+1) - 2.0*rtt ) 
354                  ztcond_i(ji,layer) = MAX( ztcond_i(ji,layer), zkimin )
355               END DO
356            END DO
357            DO ji = kideb , kiut
358               ztcond_i(ji,nlay_i) = rcdic + 0.090_wp * s_i_b(ji,nlay_i) / MIN(-zeps,t_bo_b(ji)-rtt)   &
359                  &                        - 0.011_wp * ( t_bo_b(ji) - rtt ) 
360               ztcond_i(ji,nlay_i) = MAX( ztcond_i(ji,nlay_i), zkimin )
361            END DO
362         ENDIF
363         !
364         !------------------------------------------------------------------------------|
365         !  5) kappa factors                                                            |
366         !------------------------------------------------------------------------------|
367         !
368         DO ji = kideb, kiut
369
370            !-- Snow kappa factors
371            zkappa_s(ji,0)         = rcdsn / MAX(zeps,zh_s(ji))
372            zkappa_s(ji,nlay_s)    = rcdsn / MAX(zeps,zh_s(ji))
373         END DO
374
375         DO layer = 1, nlay_s-1
376            DO ji = kideb , kiut
377               zkappa_s(ji,layer)  = 2.0 * rcdsn / &
378                  MAX(zeps,2.0*zh_s(ji))
379            END DO
380         END DO
381
382         DO layer = 1, nlay_i-1
383            DO ji = kideb , kiut
384               !-- Ice kappa factors
385               zkappa_i(ji,layer)  = 2.0*ztcond_i(ji,layer)/ &
386                  MAX(zeps,2.0*zh_i(ji)) 
387            END DO
388         END DO
389
390         DO ji = kideb , kiut
391            zkappa_i(ji,0)        = ztcond_i(ji,0)/MAX(zeps,zh_i(ji))
392            zkappa_i(ji,nlay_i)   = ztcond_i(ji,nlay_i) / MAX(zeps,zh_i(ji))
393            !-- Interface
394            zkappa_s(ji,nlay_s)   = 2.0*rcdsn*ztcond_i(ji,0)/MAX(zeps, &
395               (ztcond_i(ji,0)*zh_s(ji) + rcdsn*zh_i(ji)))
396            zkappa_i(ji,0)        = zkappa_s(ji,nlay_s)*isnow(ji) &
397               + zkappa_i(ji,0)*(1.0-isnow(ji))
398         END DO
399         !
400         !------------------------------------------------------------------------------|
401         ! 6) Sea ice specific heat, eta factors                                        |
402         !------------------------------------------------------------------------------|
403         !
404         DO layer = 1, nlay_i
405            DO ji = kideb , kiut
406               ztitemp(ji,layer)   = t_i_b(ji,layer)
407               zspeche_i(ji,layer) = cpic + zgamma*s_i_b(ji,layer)/ &
408                  MAX((t_i_b(ji,layer)-rtt)*(ztiold(ji,layer)-rtt),zeps)
409               zeta_i(ji,layer)    = rdt_ice / MAX(rhoic*zspeche_i(ji,layer)*zh_i(ji), &
410                  zeps)
411            END DO
412         END DO
413
414         DO layer = 1, nlay_s
415            DO ji = kideb , kiut
416               ztstemp(ji,layer) = t_s_b(ji,layer)
417               zeta_s(ji,layer)  = rdt_ice / MAX(rhosn*cpic*zh_s(ji),zeps)
418            END DO
419         END DO
420         !
421         !------------------------------------------------------------------------------|
422         ! 7) surface flux computation                                                  |
423         !------------------------------------------------------------------------------|
424         !
425         DO ji = kideb , kiut
426
427            ! update of the non solar flux according to the update in T_su
428            qnsr_ice_1d(ji) = qnsr_ice_1d(ji) + dqns_ice_1d(ji) * & 
429               ( t_su_b(ji) - ztsuoldit(ji) )
430
431            ! update incoming flux
432            zf(ji)    =   zfsw(ji)              & ! net absorbed solar radiation
433               + qnsr_ice_1d(ji)           ! non solar total flux
434            ! (LWup, LWdw, SH, LH)
435
436         END DO
437
438         !
439         !------------------------------------------------------------------------------|
440         ! 8) tridiagonal system terms                                                  |
441         !------------------------------------------------------------------------------|
442         !
443         !!layer denotes the number of the layer in the snow or in the ice
444         !!numeq denotes the reference number of the equation in the tridiagonal
445         !!system, terms of tridiagonal system are indexed as following :
446         !!1 is subdiagonal term, 2 is diagonal and 3 is superdiagonal one
447
448         !!ice interior terms (top equation has the same form as the others)
449
450         DO numeq=1,jkmax+2
451            DO ji = kideb , kiut
452               ztrid(ji,numeq,1) = 0.
453               ztrid(ji,numeq,2) = 0.
454               ztrid(ji,numeq,3) = 0.
455               zindterm(ji,numeq)= 0.
456               zindtbis(ji,numeq)= 0.
457               zdiagbis(ji,numeq)= 0.
458            ENDDO
459         ENDDO
460
461         DO numeq = nlay_s + 2, nlay_s + nlay_i 
462            DO ji = kideb , kiut
463               layer              = numeq - nlay_s - 1
464               ztrid(ji,numeq,1)  =  - zeta_i(ji,layer)*zkappa_i(ji,layer-1)
465               ztrid(ji,numeq,2)  =  1.0 + zeta_i(ji,layer)*(zkappa_i(ji,layer-1) + &
466                  zkappa_i(ji,layer))
467               ztrid(ji,numeq,3)  =  - zeta_i(ji,layer)*zkappa_i(ji,layer)
468               zindterm(ji,numeq) =  ztiold(ji,layer) + zeta_i(ji,layer)* &
469                  zradab_i(ji,layer)
470            END DO
471         ENDDO
472
473         numeq =  nlay_s + nlay_i + 1
474         DO ji = kideb , kiut
475            !!ice bottom term
476            ztrid(ji,numeq,1)  =  - zeta_i(ji,nlay_i)*zkappa_i(ji,nlay_i-1)   
477            ztrid(ji,numeq,2)  =  1.0 + zeta_i(ji,nlay_i)*( zkappa_i(ji,nlay_i)*zg1 &
478               +  zkappa_i(ji,nlay_i-1) )
479            ztrid(ji,numeq,3)  =  0.0
480            zindterm(ji,numeq) =  ztiold(ji,nlay_i) + zeta_i(ji,nlay_i)* &
481               ( zradab_i(ji,nlay_i) + zkappa_i(ji,nlay_i)*zg1 &
482               *  t_bo_b(ji) ) 
483         ENDDO
484
485
486         DO ji = kideb , kiut
487            IF ( ht_s_b(ji).gt.0.0 ) THEN
488               !
489               !------------------------------------------------------------------------------|
490               !  snow-covered cells                                                          |
491               !------------------------------------------------------------------------------|
492               !
493               !!snow interior terms (bottom equation has the same form as the others)
494               DO numeq = 3, nlay_s + 1
495                  layer =  numeq - 1
496                  ztrid(ji,numeq,1)   =  - zeta_s(ji,layer)*zkappa_s(ji,layer-1)
497                  ztrid(ji,numeq,2)   =  1.0 + zeta_s(ji,layer)*( zkappa_s(ji,layer-1) + &
498                     zkappa_s(ji,layer) )
499                  ztrid(ji,numeq,3)   =  - zeta_s(ji,layer)*zkappa_s(ji,layer)
500                  zindterm(ji,numeq)  =  ztsold(ji,layer) + zeta_s(ji,layer)* &
501                     zradab_s(ji,layer)
502               END DO
503
504               !!case of only one layer in the ice (ice equation is altered)
505               IF ( nlay_i.eq.1 ) THEN
506                  ztrid(ji,nlay_s+2,3)    =  0.0
507                  zindterm(ji,nlay_s+2)   =  zindterm(ji,nlay_s+2) + zkappa_i(ji,1)* &
508                     t_bo_b(ji) 
509               ENDIF
510
511               IF ( t_su_b(ji) .LT. rtt ) THEN
512
513                  !------------------------------------------------------------------------------|
514                  !  case 1 : no surface melting - snow present                                  |
515                  !------------------------------------------------------------------------------|
516                  zdifcase(ji)    =  1.0
517                  numeqmin(ji)    =  1
518                  numeqmax(ji)    =  nlay_i + nlay_s + 1
519
520                  !!surface equation
521                  ztrid(ji,1,1) = 0.0
522                  ztrid(ji,1,2) = dzf(ji) - zg1s*zkappa_s(ji,0)
523                  ztrid(ji,1,3) = zg1s*zkappa_s(ji,0)
524                  zindterm(ji,1) = dzf(ji)*t_su_b(ji)   - zf(ji)
525
526                  !!first layer of snow equation
527                  ztrid(ji,2,1)  =  - zkappa_s(ji,0)*zg1s*zeta_s(ji,1)
528                  ztrid(ji,2,2)  =  1.0 + zeta_s(ji,1)*(zkappa_s(ji,1) + zkappa_s(ji,0)*zg1s)
529                  ztrid(ji,2,3)  =  - zeta_s(ji,1)* zkappa_s(ji,1)
530                  zindterm(ji,2) =  ztsold(ji,1) + zeta_s(ji,1)*zradab_s(ji,1)
531
532               ELSE 
533                  !
534                  !------------------------------------------------------------------------------|
535                  !  case 2 : surface is melting - snow present                                  |
536                  !------------------------------------------------------------------------------|
537                  !
538                  zdifcase(ji)    =  2.0
539                  numeqmin(ji)    =  2
540                  numeqmax(ji)    =  nlay_i + nlay_s + 1
541
542                  !!first layer of snow equation
543                  ztrid(ji,2,1)  =  0.0
544                  ztrid(ji,2,2)  =  1.0 + zeta_s(ji,1) * ( zkappa_s(ji,1) + &
545                     zkappa_s(ji,0) * zg1s )
546                  ztrid(ji,2,3)  =  - zeta_s(ji,1)*zkappa_s(ji,1) 
547                  zindterm(ji,2) = ztsold(ji,1) + zeta_s(ji,1) *            &
548                     ( zradab_s(ji,1) +                         &
549                     zkappa_s(ji,0) * zg1s * t_su_b(ji) ) 
550               ENDIF
551            ELSE
552               !
553               !------------------------------------------------------------------------------|
554               !  cells without snow                                                          |
555               !------------------------------------------------------------------------------|
556               !
557               IF (t_su_b(ji) .LT. rtt) THEN
558                  !
559                  !------------------------------------------------------------------------------|
560                  !  case 3 : no surface melting - no snow                                       |
561                  !------------------------------------------------------------------------------|
562                  !
563                  zdifcase(ji)      =  3.0
564                  numeqmin(ji)      =  nlay_s + 1
565                  numeqmax(ji)      =  nlay_i + nlay_s + 1
566
567                  !!surface equation   
568                  ztrid(ji,numeqmin(ji),1)   =  0.0
569                  ztrid(ji,numeqmin(ji),2)   =  dzf(ji) - zkappa_i(ji,0)*zg1   
570                  ztrid(ji,numeqmin(ji),3)   =  zkappa_i(ji,0)*zg1
571                  zindterm(ji,numeqmin(ji))  =  dzf(ji)*t_su_b(ji) - zf(ji)
572
573                  !!first layer of ice equation
574                  ztrid(ji,numeqmin(ji)+1,1) =  - zkappa_i(ji,0) * zg1 * zeta_i(ji,1)
575                  ztrid(ji,numeqmin(ji)+1,2) =  1.0 + zeta_i(ji,1) * ( zkappa_i(ji,1) & 
576                     + zkappa_i(ji,0) * zg1 )
577                  ztrid(ji,numeqmin(ji)+1,3) =  - zeta_i(ji,1)*zkappa_i(ji,1) 
578                  zindterm(ji,numeqmin(ji)+1)=  ztiold(ji,1) + zeta_i(ji,1)*zradab_i(ji,1) 
579
580                  !!case of only one layer in the ice (surface & ice equations are altered)
581
582                  IF (nlay_i.eq.1) THEN
583                     ztrid(ji,numeqmin(ji),1)    =  0.0
584                     ztrid(ji,numeqmin(ji),2)    =  dzf(ji) - zkappa_i(ji,0)*2.0
585                     ztrid(ji,numeqmin(ji),3)    =  zkappa_i(ji,0)*2.0
586                     ztrid(ji,numeqmin(ji)+1,1)  =  -zkappa_i(ji,0)*2.0*zeta_i(ji,1)
587                     ztrid(ji,numeqmin(ji)+1,2)  =  1.0 + zeta_i(ji,1)*(zkappa_i(ji,0)*2.0 + &
588                        zkappa_i(ji,1))
589                     ztrid(ji,numeqmin(ji)+1,3)  =  0.0
590
591                     zindterm(ji,numeqmin(ji)+1) =  ztiold(ji,1) + zeta_i(ji,1)* &
592                        ( zradab_i(ji,1) + zkappa_i(ji,1)*t_bo_b(ji) )
593                  ENDIF
594
595               ELSE
596
597                  !
598                  !------------------------------------------------------------------------------|
599                  ! case 4 : surface is melting - no snow                                        |
600                  !------------------------------------------------------------------------------|
601                  !
602                  zdifcase(ji)    =  4.0
603                  numeqmin(ji)    =  nlay_s + 2
604                  numeqmax(ji)    =  nlay_i + nlay_s + 1
605
606                  !!first layer of ice equation
607                  ztrid(ji,numeqmin(ji),1)      =  0.0
608                  ztrid(ji,numeqmin(ji),2)      =  1.0 + zeta_i(ji,1)*(zkappa_i(ji,1) + zkappa_i(ji,0)* &
609                     zg1) 
610                  ztrid(ji,numeqmin(ji),3)      =  - zeta_i(ji,1) * zkappa_i(ji,1)
611                  zindterm(ji,numeqmin(ji))     =  ztiold(ji,1) + zeta_i(ji,1)*( zradab_i(ji,1) + &
612                     zkappa_i(ji,0) * zg1 * t_su_b(ji) ) 
613
614                  !!case of only one layer in the ice (surface & ice equations are altered)
615                  IF (nlay_i.eq.1) THEN
616                     ztrid(ji,numeqmin(ji),1)  =  0.0
617                     ztrid(ji,numeqmin(ji),2)  =  1.0 + zeta_i(ji,1)*(zkappa_i(ji,0)*2.0 + &
618                        zkappa_i(ji,1))
619                     ztrid(ji,numeqmin(ji),3)  =  0.0
620                     zindterm(ji,numeqmin(ji)) =  ztiold(ji,1) + zeta_i(ji,1)* &
621                        (zradab_i(ji,1) + zkappa_i(ji,1)*t_bo_b(ji)) &
622                        + t_su_b(ji)*zeta_i(ji,1)*zkappa_i(ji,0)*2.0
623                  ENDIF
624
625               ENDIF
626            ENDIF
627
628         END DO
629
630         !
631         !------------------------------------------------------------------------------|
632         ! 9) tridiagonal system solving                                                |
633         !------------------------------------------------------------------------------|
634         !
635
636         ! Solve the tridiagonal system with Gauss elimination method.
637         ! Thomas algorithm, from Computational fluid Dynamics, J.D. ANDERSON,
638         ! McGraw-Hill 1984. 
639
640         maxnumeqmax = 0
641         minnumeqmin = jkmax+4
642
643         DO ji = kideb , kiut
644            zindtbis(ji,numeqmin(ji)) =  zindterm(ji,numeqmin(ji))
645            zdiagbis(ji,numeqmin(ji)) =  ztrid(ji,numeqmin(ji),2)
646            minnumeqmin               =  MIN(numeqmin(ji),minnumeqmin)
647            maxnumeqmax               =  MAX(numeqmax(ji),maxnumeqmax)
648         END DO
649
650         DO layer = minnumeqmin+1, maxnumeqmax
651            DO ji = kideb , kiut
652               numeq               =  min(max(numeqmin(ji)+1,layer),numeqmax(ji))
653               zdiagbis(ji,numeq)  =  ztrid(ji,numeq,2) - ztrid(ji,numeq,1)* &
654                  ztrid(ji,numeq-1,3)/zdiagbis(ji,numeq-1)
655               zindtbis(ji,numeq)  =  zindterm(ji,numeq) - ztrid(ji,numeq,1)* &
656                  zindtbis(ji,numeq-1)/zdiagbis(ji,numeq-1)
657            END DO
658         END DO
659
660         DO ji = kideb , kiut
661            ! ice temperatures
662            t_i_b(ji,nlay_i)    =  zindtbis(ji,numeqmax(ji))/zdiagbis(ji,numeqmax(ji))
663         END DO
664
665         DO numeq = nlay_i + nlay_s + 1, nlay_s + 2, -1
666            DO ji = kideb , kiut
667               layer    =  numeq - nlay_s - 1
668               t_i_b(ji,layer)  =  (zindtbis(ji,numeq) - ztrid(ji,numeq,3)* &
669                  t_i_b(ji,layer+1))/zdiagbis(ji,numeq)
670            END DO
671         END DO
672
673         DO ji = kideb , kiut
674            ! snow temperatures     
675            IF (ht_s_b(ji).GT.0) &
676               t_s_b(ji,nlay_s)     =  (zindtbis(ji,nlay_s+1) - ztrid(ji,nlay_s+1,3) &
677               *  t_i_b(ji,1))/zdiagbis(ji,nlay_s+1) &
678               *        MAX(0.0,SIGN(1.0,ht_s_b(ji)-zeps)) 
679
680            ! surface temperature
681            isnow(ji)     = INT(1.0-max(0.0,sign(1.0,-ht_s_b(ji))))
682            ztsuoldit(ji) = t_su_b(ji)
683            IF (t_su_b(ji) .LT. ztfs(ji)) &
684               t_su_b(ji) = ( zindtbis(ji,numeqmin(ji)) - ztrid(ji,numeqmin(ji),3)* ( isnow(ji)*t_s_b(ji,1)   &
685               &          + (1.0-isnow(ji))*t_i_b(ji,1) ) ) / zdiagbis(ji,numeqmin(ji)) 
686         END DO
687         !
688         !--------------------------------------------------------------------------
689         !  10) Has the scheme converged ?, end of the iterative procedure         |
690         !--------------------------------------------------------------------------
691         !
692         ! check that nowhere it has started to melt
693         ! zerrit(ji) is a measure of error, it has to be under maxer_i_thd
694         DO ji = kideb , kiut
695            t_su_b(ji) =  MAX(  MIN( t_su_b(ji) , ztfs(ji) ) , 190._wp  )
696            zerrit(ji) =  ABS( t_su_b(ji) - ztsuoldit(ji) )     
697         END DO
698
699         DO layer  =  1, nlay_s
700            DO ji = kideb , kiut
701               ii = MOD( npb(ji) - 1, jpi ) + 1
702               ij = ( npb(ji) - 1 ) / jpi + 1
703               t_s_b(ji,layer) = MAX(  MIN( t_s_b(ji,layer), rtt ), 190._wp  )
704               zerrit(ji)      = MAX(zerrit(ji),ABS(t_s_b(ji,layer) - ztstemp(ji,layer)))
705            END DO
706         END DO
707
708         DO layer  =  1, nlay_i
709            DO ji = kideb , kiut
710               ztmelt_i        = -tmut * s_i_b(ji,layer) + rtt 
711               t_i_b(ji,layer) =  MAX(MIN(t_i_b(ji,layer),ztmelt_i),190.0)
712               zerrit(ji)      =  MAX(zerrit(ji),ABS(t_i_b(ji,layer) - ztitemp(ji,layer)))
713            END DO
714         END DO
715
716         ! Compute spatial maximum over all errors
717         ! note that this could be optimized substantially by iterating only the non-converging points
718         zerritmax = 0._wp
719         DO ji = kideb, kiut
720            zerritmax = MAX( zerritmax, zerrit(ji) )   
721         END DO
722         IF( lk_mpp ) CALL mpp_max( zerritmax, kcom=ncomm_ice )
723
724      END DO  ! End of the do while iterative procedure
725
726      IF( ln_nicep ) THEN
727         WRITE(numout,*) ' zerritmax : ', zerritmax
728         WRITE(numout,*) ' nconv     : ', nconv
729      ENDIF
730
731      !
732      !-------------------------------------------------------------------------!
733      !   11) Fluxes at the interfaces                                          !
734      !-------------------------------------------------------------------------!
735      DO ji = kideb, kiut
736         !                                ! update of latent heat fluxes
737         qla_ice_1d (ji) = qla_ice_1d (ji) + dqla_ice_1d(ji) * ( t_su_b(ji) - ztsuold(ji) )
738         !                                ! surface ice conduction flux
739         isnow(ji)       = INT(  1._wp - MAX( 0._wp, SIGN( 1._wp, -ht_s_b(ji) ) )  )
740         fc_su(ji)       =  -           isnow(ji)   * zkappa_s(ji,0) * zg1s * (t_s_b(ji,1) - t_su_b(ji))   &
741            &               - ( 1._wp - isnow(ji) ) * zkappa_i(ji,0) * zg1  * (t_i_b(ji,1) - t_su_b(ji))
742         !                                ! bottom ice conduction flux
743         fc_bo_i(ji)     =  - zkappa_i(ji,nlay_i) * ( zg1*(t_bo_b(ji) - t_i_b(ji,nlay_i)) )
744      END DO
745
746      !-------------------------!
747      ! Heat conservation       !
748      !-------------------------!
749      IF( con_i ) THEN
750         DO ji = kideb, kiut
751            ! Upper snow value
752            fc_s(ji,0) = - isnow(ji) * zkappa_s(ji,0) * zg1s * ( t_s_b(ji,1) - t_su_b(ji) ) 
753            ! Bott. snow value
754            fc_s(ji,1) = - isnow(ji)* zkappa_s(ji,1) * ( t_i_b(ji,1) - t_s_b(ji,1) ) 
755         END DO
756         DO ji = kideb, kiut         ! Upper ice layer
757            fc_i(ji,0) = - isnow(ji) * &  ! interface flux if there is snow
758               ( zkappa_i(ji,0)  * ( t_i_b(ji,1) - t_s_b(ji,nlay_s ) ) ) &
759               - ( 1.0 - isnow(ji) ) * ( zkappa_i(ji,0) * & 
760               zg1 * ( t_i_b(ji,1) - t_su_b(ji) ) ) ! upper flux if not
761         END DO
762         DO layer = 1, nlay_i - 1         ! Internal ice layers
763            DO ji = kideb, kiut
764               fc_i(ji,layer) = - zkappa_i(ji,layer) * ( t_i_b(ji,layer+1) - t_i_b(ji,layer) )
765               ii = MOD( npb(ji) - 1, jpi ) + 1
766               ij = ( npb(ji) - 1 ) / jpi + 1
767            END DO
768         END DO
769         DO ji = kideb, kiut         ! Bottom ice layers
770            fc_i(ji,nlay_i) = - zkappa_i(ji,nlay_i) * ( zg1*(t_bo_b(ji) - t_i_b(ji,nlay_i)) )
771         END DO
772      ENDIF
773      !
774      CALL wrk_dealloc( kiut, numeqmin, numeqmax, isnow )   ! integer
775      CALL wrk_dealloc( kiut,nlay_i+1, ztcond_i, zradtr_i, zradab_i, zkappa_i, ztiold, zeta_i, ztitemp, zspeche_i, z_i, kjstart=0 )
776      CALL wrk_dealloc( kiut,nlay_s+1, zradtr_s, zradab_s, zkappa_s, zeta_s, ztstemp, ztsold, z_s, kjstart=0 )
777      CALL wrk_dealloc( kiut,jkmax+2, zindterm, zindtbis, zdiagbis )
778      CALL wrk_dealloc( kiut,jkmax+2,3, ztrid )
779      CALL wrk_dealloc( kiut, ztfs, ztsuold, ztsuoldit, zh_i, zh_s, zfsw, zf, dzf )
780      CALL wrk_dealloc( kiut, zerrit, zdifcase, zftrice, zihic, zhsu )
781
782   END SUBROUTINE lim_thd_dif
783
784#else
785   !!----------------------------------------------------------------------
786   !!                   Dummy Module                 No LIM-3 sea-ice model
787   !!----------------------------------------------------------------------
788CONTAINS
789   SUBROUTINE lim_thd_dif          ! Empty routine
790   END SUBROUTINE lim_thd_dif
791#endif
792   !!======================================================================
793END MODULE limthd_dif
Note: See TracBrowser for help on using the repository browser.