SURFEX v8.1
General documentation of Surfex
init_top.F90
Go to the documentation of this file.
1 !SFX_LIC Copyright 1994-2014 CNRS, Meteo-France and Universite Paul Sabatier
2 !SFX_LIC This is part of the SURFEX software governed by the CeCILL-C licence
3 !SFX_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
4 !SFX_LIC for details. version 1.
5 ! ######spl
6  SUBROUTINE init_top (IO, S, K, NK, NP, KLUOUT, PM )
7 !
8 ! #####################################################################
9 !
10 !!**** *INIT_TOP*
11 !!
12 !! PURPOSE
13 !! =======
14 !
15 ! Calculates the new array of the Datin-Saulnier TOPMODEL framework fonction for xsat and compute each
16 ! satured fraction for each xsat value of the grids cells but also the active TOPMODEL-layer array, the
17 ! driest fraction array and the normalized mean deficit array.
18 ! For calculate new array, we use the incomplete gamma function. (see gamma_inc.f for more detail)
19 !
20 ! Note that over land point where topographic index do not exist, a VIC
21 ! distribution is used with Bcoef at least equal to 0.1. This value can be
22 ! change in namelist
23 !
24 !!
25 !! AUTHOR
26 !! ------
27 !! B. Decharme
28 !!
29 !! MODIFICATIONS
30 !! -------------
31 !! Original 01/2008
32 ! B. decharme 04/2013 : DIF lateral drainage
33 ! CTI linear regression done in PGD (HTOPREG deleted)
34 !
35 !-------------------------------------------------------------------------------
36 !
37 !
40 !
41 USE modd_surf_par,ONLY : xundef
42 !
43 USE modd_sgh_par, ONLY : x2, x4, xregp, xrega
44 !
45 USE modi_dgam
46 USE modi_gammas
47 !
48 USE yomhook ,ONLY : lhook, dr_hook
49 USE parkind1 ,ONLY : jprb
50 !
51 USE modi_abor1_sfx
52 !
53 !* 0. DECLARATIONS
54 ! ===================
55 !
56 IMPLICIT NONE
57 !
58 !* 0.1 declarations of arguments
59 !
60 !
61 TYPE(isba_options_t), INTENT(INOUT) :: IO
62 TYPE(isba_s_t), INTENT(INOUT) :: S
63 TYPE(isba_k_t), INTENT(INOUT) :: K
64 TYPE(isba_nk_t), INTENT(INOUT) :: NK
65 TYPE(isba_np_t), INTENT(INOUT) :: NP
66 !
67 INTEGER, INTENT(IN) :: KLUOUT
68 !
69 REAL, DIMENSION(:), INTENT(INOUT) :: PM
70 ! PM = exponential decay factor of the local deficit
71 !
72 !* 0.2 declarations of local variables
73 !
74 TYPE(isba_k_t), POINTER :: KK
75 TYPE(isba_p_t), POINTER :: PK
76 !
77 REAL, DIMENSION(SIZE(PM)) :: ZD_TOP, ZWSAT_AVG, ZWD0_AVG
78 ! ZD_TOP = Topmodel active layer
79 !
80 REAL :: ZXI, ZPHI, ZNU, ZTI_MEAN, ZTI_MIN, ZTI_MAX, ZTI_STD, ZTI_SKEW
81 ! ZTI_MEAN= ti mean after regression
82 ! ZXI = ti pdf parameter
83 ! ZPHI = ti pdf parameter
84 ! ZNU = ti pdf parameter
85 !
86 REAL :: ZFTOT, ZYMAX, ZYMIN
87 REAL :: ZGYMAX, ZGYMIN
88 ! ZFTOT = total fraction of a grid cell
89 ! ZYMAX = yi maximum variable
90 ! ZYMIN = yi minimum variable
91 ! ZGYMAX = incomplete gamma function for ymax (GAMSTAR result)
92 ! ZGYMIN = incomplete gamma function for ymin (GAMSTAR result)
93 !
94 REAL :: ZXSAT_IND, ZYSAT, ZY0, ZDMOY, ZXMOY, ZFMED, ZF0
95 ! ZXSAT_IND = Satured index for all index
96 ! ZYSAT = changing variable of satured index
97 ! ZY0 = changing variable of dry index
98 ! ZDMOY = grid cell average deficit (= Dbar/M)
99 ! ZXMOY = ti mean value on wet (1-fsat-f0) fraction
100 ! ZF0 = dry fraction
101 ! ZFMED = wet (1-fsat-f0) fraction
102 !
103 REAL :: ZG, ZGYSAT, ZGY0
104 ! ZG = GAM result
105 ! ZGYSAT = the incomplete gamma function for ysat (GAMSTAR result)
106 ! ZGY0 = the incomplete gamma function for y0 (GAMSTAR result)
107 !
108 REAL :: ZD0, ZPAS, ZCOR
109 ! ZD0 = Normalized TOPMODEL maximum deficit D0/M coefficient
110 ! ZPAS = pas for calculate the new xsat values array
111 !
112 INTEGER :: IFLG, IFLGST
113 ! IFLG = incomplete gamma function error flag (GAM result)
114 ! IFLGST = incomplete gamma function error flag (GAMSTAR result)
115 ! (see gamma_inc.f for more detail)
116 !
117 REAL :: ZNO, ZAR, ZTOT
118 !
119 REAL :: ZFUP, ZFDOWN, ZQUP, ZQDOWN, ZSLOPEQ, ZWUP, ZWDOWN, ZSLOPEW
120 !
121 INTEGER, DIMENSION (1):: ID
122 !
123 INTEGER :: INI, JI, IND, JSI_MIN, JSI_MAX, IPAS, &
124  JL, INL, JP, IMASK
125 REAL(KIND=JPRB) :: ZHOOK_HANDLE
126 !
127 !-------------------------------------------------------------------------------
128 !
129 ! 1 TOPMODEL SURFACE RUNOFF SCHEME
130 ! ================================
131 !
132 ! 1.1 initialisation of local variable
133 ! ----------------------------------------
134 !
135 ! Grid cells number
136 !
137 IF (lhook) CALL dr_hook('INIT_TOP',0,zhook_handle)
138 !
139 ini = SIZE(pm(:))
140 inl = io%NGROUND_LAYER
141 ipas = SIZE(s%XTAB_FSAT,2)
142 !
143 ! GAM result (not use here !)
144 !
145 zg = 0.0
146 !
147 zd_top(:) = 0.0
148 zwsat_avg(:) = 0.0
149 zwd0_avg(:) = 0.0
150 !
151 ! soil properties for runoff (m)
152 !
153 IF (io%CISBA == 'DIF') THEN
154 !
155  DO jp=1,io%NPATCH
156 
157  pk => np%AL(jp)
158  kk => nk%AL(jp)
159 
160  IF (pk%NSIZE_P == 0 ) cycle
161 
162  DO jl=1,inl
163  DO ji=1,pk%NSIZE_P
164  !
165  imask = pk%NR_P(ji)
166  !
167  zd_top(imask) = zd_top(imask) + pk%XPATCH(ji) * pk%XSOILWGHT(ji,jl)
168  zwsat_avg(imask) = zwsat_avg(imask) + pk%XPATCH(ji) * pk%XSOILWGHT(ji,jl) * k%XWSAT(imask,jl)
169  zwd0_avg(imask) = zwd0_avg(imask) + pk%XPATCH(ji) * pk%XSOILWGHT(ji,jl) * k%XWD0 (imask,jl)
170  !
171  ENDDO
172  ENDDO
173  ENDDO
174 !
175  WHERE(zd_top(:)>0.0)
176  zwsat_avg(:)=zwsat_avg(:)/zd_top(:)
177  zwd0_avg(:)=zwd0_avg(:)/zd_top(:)
178  ENDWHERE
179 !
180 ELSE
181 !
182  DO jp=1,io%NPATCH
183  !
184  pk => np%AL(jp)
185  kk => nk%AL(jp)
186  !
187  IF (pk%NSIZE_P == 0 ) cycle
188  !
189  DO ji=1,pk%NSIZE_P
190  !
191  imask = pk%NR_P(ji)
192  !
193  zd_top(imask)=zd_top(imask) + pk%XRUNOFFD(ji) * pk%XPATCH(ji)
194  !
195  ENDDO
196  !
197  ENDDO
198  !
199  zwsat_avg(:) = k%XWSAT(:,1)
200  zwd0_avg(:) = k%XWD0 (:,1)
201  !
202 ENDIF
203 !
204 !
205 ! 1.2 Algorithme
206 ! ------------------
207 !
208 !grid cells loops
209 !
210 zar = 0.0
211 ztot= 0.0
212 zno = 0.0
213 !
214 DO ji=1,ini
215 !
216  IF(s%XTI_MEAN(ji)==xundef)THEN
217 !
218 ! *Case where the Topographics index are not defined.
219 ! --------------------------------------------------------
220  zno=zno+1.0
221  s%XTAB_FSAT(ji,:)=0.0
222  s%XTAB_WTOP(ji,:)=xundef
223  s%XTAB_QTOP(ji,:)=0.0
224 !
225  pm(ji) =xundef
226 !
227  ELSE
228 !
229  ztot = ztot + 1.0
230 !
231 ! 1.2.0 first initialisation
232 ! --------------------------
233 !
234  zxi = 0.0
235  zphi = 0.0
236  znu = 0.0
237 !
238 ! New version : Regressions directly in the pgd
239 ! 1000 meter DEM to 2m DEM (PAN AND KING 2012)
240 !
241  zti_mean=s%XTI_MEAN(ji)
242  zti_min =s%XTI_MIN (ji)
243  zti_max =s%XTI_MAX (ji)
244  zti_std =s%XTI_STD (ji)
245  zti_skew=s%XTI_SKEW(ji)
246 !
247 ! Calculate topographic index pdf parameters
248 !
249 ! Numerical problem especialy over Greenland
250  IF(zti_skew<=0.2)THEN
251 !
252  zti_skew=0.2
253 !
254  WRITE(kluout,*)'TI_SKEW is too low or negatif (=',zti_skew,'),'
255  WRITE(kluout,*)'then PHI is too big for the grid-cell',ji,'So,GAMMA(PHI) -> +inf.'
256  WRITE(kluout,*)'The applied solution is to put TI_SKEW = 0.2'
257  IF(zti_std<1.0)THEN
258  WRITE(kluout,*)'In addition TI_STD is too low (=',zti_std,'),'
259  WRITE(kluout,*)'The applied solution is to put TI_STD = 1.0'
260  zti_std=1.0
261  ENDIF
262 !
263  zar = zar +1.0
264 !
265  zxi = zti_skew*zti_std/x2
266  zphi = (zti_std/zxi)**x2
267 !
268  ELSE
269 !
270  zxi = zti_skew*zti_std/x2
271  zphi = (zti_std/zxi)**x2
272 !
273  ENDIF
274 !
275  znu = zti_mean-zphi*zxi
276 !
277 ! Exponential decay factor of the local deficit
278 !
279  pm(ji) =(zwsat_avg(ji)-zwd0_avg(ji))*zd_top(ji)/x4
280 !
281 ! 1.2.1 Calculate grid cell pdf total density FTOT = F(ymin --> ymax)
282 ! -------------------------------------------------------------------
283 !
284 ! Normalized TOPMODEL maximum deficit D0/M coefficient
285 !
286  zd0 = (zwsat_avg(ji)-zwd0_avg(ji))*zd_top(ji)/pm(ji)
287 !
288 ! Initialise
289 !
290  zgymax = 0.0
291  zgymin = 0.0
292  zftot = 0.0
293  zymin = 0.0
294  zymax = 0.0
295 !
296 ! variable changing yi ---> (ti-nu)/xi
297 !
298  zymin = (zti_min-znu)/zxi
299  zymax = (zti_max-znu)/zxi
300 !
301 ! Supress numerical artifact
302 !
303  zcor = abs(min(0.0,zymin))
304 !
305  zymin = max(0.0,zymin+zcor)
306  zymax = zymax+zcor
307 !
308 ! Errors flags indicating a number of error condition in G and GSTAR
309 ! (see gamma_inc.f for more detail)
310 !
311  iflg =0
312  iflgst =0
313 !
314 ! Computation of F(0 --> ymin)
315 !
316  CALL dgam(zphi,zymin,10.,zg,zgymin,iflg,iflgst)
317 !
318 ! if the incomplete gamma function don't work, print why
319 !
320  IF (iflgst/=0)THEN
321  WRITE(kluout,*)'GRID-CELL =',ji,'FLGST= ',iflgst,'PHI= ',zphi,'YMIN= ',zymin
322  CALL abor1_sfx('INIT_TOP: (1) PROBLEM WITH DGAM FUNCTION')
323  ENDIF
324 !
325 ! Computation of F(0 --> ymax)
326 !
327  CALL dgam(zphi,zymax,10.,zg,zgymax,iflg,iflgst)
328 !
329 ! if the incomplete gamma function don't work, print why
330 !
331  IF (iflgst/=0)THEN
332  WRITE(kluout,*)'GRID-CELL =',ji,'FLGST= ',iflgst,'PHI= ',zphi,'YMAX= ',zymax
333  CALL abor1_sfx('INIT_TOP: (2) PROBLEM WITH DGAM FUNCTION')
334  ENDIF
335 !
336 ! FTOT = F(0 --> ymax) - F(0 --> ymin)
337 !
338  zftot=zgymax-zgymin
339 !
340 ! initialization water content and fraction
341 !
342  s%XTAB_WTOP(ji,1) = zwsat_avg(ji)
343  s%XTAB_FSAT(ji,1) = 1.0
344  s%XTAB_QTOP(ji,1) = 0.0
345 !
346  s%XTAB_WTOP(ji,ipas) = zwd0_avg(ji)
347  s%XTAB_FSAT(ji,ipas) = 0.0
348  s%XTAB_QTOP(ji,ipas) = 0.0
349 !
350 ! Define the new limits for the satured index loop
351 !
352  jsi_min = 2
353  jsi_max = ipas-1
354  zpas = (zti_max-zti_min)/REAL(ipas-1)
355 !
356 ! 1.2.2 Calculate all topmodel arrays
357 ! -----------------------------------
358 !
359 ! Satured index loop
360 !
361  DO ind=jsi_min,jsi_max
362 !
363 ! initialize of loops variables
364 !
365  zxsat_ind = 0.0
366  zysat = 0.0
367  zy0 = 0.0
368  zdmoy = 0.0
369  zxmoy = 0.0
370  zfmed = 0.0
371 !
372 ! Initialize of incomplete gamma function flags and variables
373 !
374  iflg = 0
375  iflgst = 0
376  zgysat = 0.0
377  zgy0 = 0.0
378 !
379 ! calculate xsat for all new index
380 !
381  zxsat_ind=zti_min+REAL(ind-1)*ZPAS
382 !
383 ! Changing variable to compute incomplete gamma function
384 !
385  zysat=(zxsat_ind-znu)/zxi
386  zy0 =((zxsat_ind-zd0)-znu)/zxi
387 !
388 ! Calculate Y0 and ysat and assume ymin < y0 < ymax !
389 
390  zysat=max(zymin,min(zysat+zcor,zymax))
391  zy0 =max(zymin,min(zy0 +zcor,zymax))
392 !
393 ! call incomplete gamma function for xsat
394 !
395  CALL dgam(zphi,zysat,10.,zg,zgysat,iflg,iflgst)
396 !
397 ! if the incomplete gamma function don't works, print why
398 !
399  IF (iflgst/=0)THEN
400  WRITE(kluout,*)'GRID-CELL= ',ji,'FLGST= ',iflgst,'PHI= ',zphi,'YSAT= ',zysat
401  CALL abor1_sfx('INIT_TOP: (3) PROBLEM WITH DGAM FUNCTION')
402  ENDIF
403 !
404 ! call incomplete gamma function for xsat
405 !
406  CALL dgam(zphi,zy0,10.,zg,zgy0,iflg,iflgst)
407 !
408 ! if the incomplete gamma function don't works, print why
409 !
410  IF (iflgst/=0)THEN
411  WRITE(kluout,*)'GRID-CELL= ',ji,'FLGST= ',iflgst,'PHI= ',zphi,'Y0= ',zy0
412  CALL abor1_sfx('INIT_TOP: (4) PROBLEM WITH DGAM FUNCTION')
413  ENDIF
414 !
415 ! compute satured fraction as FSAT = F(0 --> ymax) - F(0 --> ysat)
416 !
417  s%XTAB_FSAT(ji,ind)=max(0.0,(zgymax-zgysat)/zftot)
418 !
419 ! Compute driest fraction
420 !
421  zf0=max(0.0,(zgy0-zgymin)/zftot)
422 !
423 ! Calculate FMED
424 !
425  zfmed=(1.0-s%XTAB_FSAT(ji,ind)-zf0)
426 !
427  IF (zfmed/=0.0) THEN
428 !
429 ! Compute the new x mean, xmoy', over the wet fraction Fwet
430 !
431  zxmoy = znu+zxi*(zphi-zcor+(exp(-zy0)*(zy0**(zphi/x2))*(zy0**(zphi/x2)) &
432  - exp(-zysat)*(zysat**(zphi/x2))*(zysat**(zphi/x2)))/(zfmed*gammas(zphi)))
433 !
434 ! supress numerical artifacs
435 !
436  zxmoy =max((zxsat_ind-zd0),min(zxsat_ind,zxmoy))
437 !
438 ! Calculate the mean normalysed deficit as Dbar/M = (1-fsat-f0)*(xsat-xmoy')+f0*D0/M
439 !
440  zdmoy = zfmed*(zxsat_ind-zxmoy)+zf0*zd0
441 !
442  ENDIF
443 !
444 ! supress numerical artifacs
445 !
446  zdmoy = max(0.0,min(zdmoy,zd0))
447 !
448 ! Solves Dbar = (Wsat-WT)*d_top with Dbar/M (=ZDMOY) = (Wsat-WT)*d_top/M
449 !
450  s%XTAB_WTOP(ji,ind) = zwsat_avg(ji)-(pm(ji)*zdmoy/zd_top(ji))
451 
452 ! Solves Qs = FMED * M * Ks * exp(-Xsat) / Ks (dimentionless)
453 !
454  s%XTAB_QTOP(ji,ind) = zfmed*pm(ji)*exp(-zxsat_ind)
455 !
456  ENDDO
457 !
458  ENDIF
459 !
460 ENDDO
461 !
462 ! supress numerical artifacs for boundaries conditions
463 !
464 DO ji=1,ini
465 !
466 ! Upper boundary
467 !
468  IF(s%XTAB_WTOP(ji,2)==zwsat_avg(ji))THEN
469 !
470  zfup=s%XTAB_FSAT(ji,1)
471  zwup=s%XTAB_WTOP(ji,1)
472  zqup=s%XTAB_QTOP(ji,1)
473 !
474  id(:)=maxloc(s%XTAB_WTOP(ji,:),s%XTAB_WTOP(ji,:)<zwsat_avg(ji))
475 !
476  zfdown=s%XTAB_FSAT(ji,id(1))
477  zwdown=s%XTAB_WTOP(ji,id(1))
478  zqdown=s%XTAB_QTOP(ji,id(1))
479 !
480  zslopew=(zwup-zwdown)/(zfup-zfdown)
481  zslopeq=(zqup-zqdown)/(zfup-zfdown)
482 !
483  DO ind=2,id(1)-1
484  s%XTAB_WTOP(ji,ind)=zwdown+(s%XTAB_FSAT(ji,ind)-zfdown)*zslopew
485  s%XTAB_QTOP(ji,ind)=zqdown+(s%XTAB_FSAT(ji,ind)-zfdown)*zslopeq
486  ENDDO
487 !
488  ENDIF
489 !
490 ! Lower boundary
491 !
492  WHERE(s%XTAB_FSAT(ji,:)<=0.0 )
493  s%XTAB_WTOP(ji,:)=zwd0_avg(ji)
494  s%XTAB_QTOP(ji,:)=0.0
495  ENDWHERE
496  WHERE(s%XTAB_WTOP(ji,:)<=zwd0_avg(ji))
497  s%XTAB_FSAT(ji,:)=0.0
498  s%XTAB_QTOP(ji,:)=0.0
499  ENDWHERE
500 !
501 ENDDO
502 !
503 WRITE(kluout,*)'-------------------TOPMODEL SUM-UP-------------------------'
504 WRITE(kluout,*)'Number of grid-cells ',ini,'Number of Topmodel points',int(ztot)
505 IF(ini/=0) THEN
506  WRITE(kluout,*)'Percentage of non TOPMODEL grid-cells',(100.*zno/float(ini))
507 ENDIF
508 IF(ztot>0.0)THEN
509  WRITE(kluout,*)'Percentage of arranged (TI-SKE=0.2) grid-cells',(100.*zar/ztot)
510 ENDIF
511 WRITE(kluout,*)'-----------------------------------------------------------'
512 !
513 IF (lhook) CALL dr_hook('INIT_TOP',1,zhook_handle)
514 !
515 !-------------------------------------------------------------------------------
516 !
517 END SUBROUTINE init_top
subroutine init_top(IO, S, K, NK, NP, KLUOUT, PM)
Definition: init_top.F90:7
real, parameter xrega
real, parameter xregp
real, parameter x4
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:7
real, parameter xundef
integer, parameter jprb
Definition: parkind1.F90:32
real function gammas(PX)
Definition: gammas.F90:7
logical lhook
Definition: yomhook.F90:15
static ll_t maxloc
Definition: getcurheap.c:48
real, parameter x2
subroutine dgam(PA, PX, PACC, PG, PGSTAR, KFLG, KFLGST)
Definition: dgam.F90:132