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