SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
hydro_soildif.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 ! #########
6  SUBROUTINE hydro_soildif(HRUNOFF,HHORT,PTSTEP, &
7  pbcoef,pwsat,pcondsat,pmpotsat,pwfc,pdg,pdzg, &
8  pdzdif,ppg,pletr,pleg,pevapcor,pf2wght, &
9  pwg,pwgi,ptg,pps,pqsat,pqsati, &
10  pdrain,phorton,pfsat,kwg_layer, &
11  kmax_layer,klayer_hort,ptopqs,pqsb,pfwtd,pwtd )
12 ! ##########################################################################
13 !
14 !
15 !!**** *HYDRO_SOILDIF*
16 !
17 !! PURPOSE
18 !! -------
19 ! This subroutine solves the 1-D (z) mass conservation equation
20 ! (mixed-form Richard's equation: tendency in terms of volumetric
21 ! water content, gradient in terms of matric potential)
22 ! for liquid water (using Darcy's Law for the vertical flux)
23 ! together with the Clapp and Hornberger (1978) simplification to
24 ! the Brooks and Corey (1966) empirical model for relating matric
25 ! potential and hydraulic conductivity to soil water content.
26 ! Any set of parameters can be used (eg. Clapp and Hornberger 1978;
27 ! Cosby et al. 1984; etc.) Modifications to the equations is also
28 ! made for the Van Genucten model/relationships. The equations
29 ! also incorporate vapor transfer for dry soils. The soil porosity
30 ! is modified in the presence of soil ice. Soil ice content
31 ! is also updated herein due to changes resulting from sublimation.
32 ! The layer averaged set of equations are time differenced
33 ! using an implicit time scheme.
34 ! The equations/model *assume* a heterogeneous soil texture profile,
35 ! however, if the soil properties are homogeneous, the equations
36 ! collapse into the standard homogeneous approach (i.e. give the
37 ! same results as). The eqs are solved rapidly by taking advantage of the
38 ! fact that the matrix is tridiagonal.
39 ! Note that the exponential profile of hydraulic conductivity with soil
40 ! depth is applied to interfacial conductivity (or interblock)
41 !
42 !
43 !!** METHOD
44 !! ------
45 !
46 ! Direct calculation
47 !
48 !! EXTERNAL
49 !! --------
50 !
51 ! None
52 !!
53 !! IMPLICIT ARGUMENTS
54 !! ------------------
55 !!
56 !! USE MODD_CST
57 !! USE MODI_TRIDIAG_GROUND
58 !!
59 !! REFERENCE
60 !! ---------
61 !!
62 !! Boone (2000)
63 !! Boone et al. (2000)
64 !!
65 !! AUTHOR
66 !! ------
67 !! A. Boone * Meteo-France *
68 !!
69 !! MODIFICATIONS
70 !! -------------
71 !! Original 16/02/00 Boone
72 !! Modif 04/2010 B.Decharme: geometric mean for interfacial conductivity
73 !! Brook and Corey
74 !! Modif 08/2011 B.Decharme: Optimization using global loops
75 !! 10/12 B.Decharme: EVAPCOR snow correction in DIF
76 !! 04/13 B.Decharme: Subsurface runoff if SGH (DIF option only)
77 !! 07/2013 B.Decharme: Surface / Water table depth coupling
78 !! 01/2016 B.Decharme: Bug : if no surface runoff (HRUNOFF=WSAT) then no Horton
79 !-------------------------------------------------------------------------------
80 !
81 !* 0. DECLARATIONS
82 ! ------------
83 !
84 USE modd_surf_par, ONLY : xundef, nundef
85 USE modd_csts, ONLY : xrholw
86 USE modd_isba_par, ONLY : xwgmin
87 !
89 !
90 USE yomhook ,ONLY : lhook, dr_hook
91 USE parkind1 ,ONLY : jprb
92 !
93 IMPLICIT NONE
94 !
95  CHARACTER(LEN=*), INTENT(IN) :: hrunoff ! surface runoff formulation
96 ! ! 'WSAT'
97 ! ! 'DT92'
98 ! ! 'SGH ' Topmodel
99 !
100  CHARACTER(LEN=*), INTENT(IN) :: hhort ! Hortonian runoff
101 !
102 REAL, INTENT(IN) :: ptstep ! Model time step (s)
103 !
104 REAL, DIMENSION(:), INTENT(IN) :: pps, ppg, pletr, pleg, pevapcor, pfsat, &
105  pfwtd, pwtd
106 ! PPS = surface pressure (Pa)
107 ! PPG = throughfall rate:
108 ! rate at which water reaches the surface
109 ! of the soil (from snowmelt, rain, canopy
110 ! drip, etc...) (m/s)
111 ! PLETR = transpiration rate (m/s)
112 ! PLEG = bare-soil evaporation rate (m/s)
113 ! PEVAPCOR = correction for any excess evaporation
114 ! from snow as it completely ablates (m/s)
115 ! PFSAT = Saturated fraction
116 ! PFWTD = grid-cell fraction of water table to rise
117 ! PWTD = water table depth negative below soil surface (m)
118 !
119 REAL, DIMENSION(:,:), INTENT(IN) :: pqsat,pqsati
120 ! specific humidity at saturation
121 !
122 REAL, DIMENSION(:,:), INTENT(IN) :: ptg, pdg, pdzg, pdzdif
123 ! PTG = layer-average soil temperatures (K)
124 ! PDG = soil layer depth (m)
125 ! PDZG= soil layer thicknesses (m)
126 ! PDZDIF = distance between the midpoints of consecutive layers (m)
127 !
128 REAL, DIMENSION(:,:), INTENT(IN) :: pwsat, pcondsat, pf2wght, pwfc
129 ! PWSAT = porosity profile (m3 m-3)
130 ! PCONDSAT = hydraulic conductivity at saturation (m s-1)
131 ! PF2WGHT = root-zone transpiration weights (-)
132 ! PWFC = field capacity water content (m3 m-3)
133 !
134 REAL, DIMENSION(:,:), INTENT(IN) :: pbcoef,pmpotsat
135 ! PMPOTSAT = matric potential at saturation (m) (BC parameters)
136 ! PBCOEF = slope of the retention curve (-) (BC parameters)
137 !
138 INTEGER, DIMENSION(:), INTENT(IN) :: kwg_layer
139 ! KWG_LAYER = Number of soil moisture layers
140 !
141 INTEGER, INTENT(IN) :: kmax_layer
142 ! KMAX_LAYER = Max number of soil moisture layers (DIF option)
143 !
144 INTEGER, INTENT(IN) :: klayer_hort! DIF optimization
145 !
146 REAL, DIMENSION(:,:), INTENT(INOUT) :: pwg, pwgi
147 ! PWG = volumetric liquid water content (m3 m-3)
148 ! PWGI = volumetric ice content (m3 m-3)
149 !
150 REAL, DIMENSION(:), INTENT(OUT) :: pdrain, phorton
151 ! PDRAIN = drainage (flux out of model base) (kg m-2 s-1)
152 ! PHORTON = runoff (due to saturation (lateral) (kg m-2 s-1)
153 
154 REAL, DIMENSION(:,:), INTENT(IN) :: ptopqs
155 ! PTOPQS = Topmodel subsurface flow by layer (m/s)
156 !
157 REAL, DIMENSION(:), INTENT(OUT) :: pqsb !Lateral subsurface flow [kg/m²/s]
158 !
159 !
160 !* 0.2 declarations of local variables
161 !
162 INTEGER :: jj, jl ! loop control
163 !
164 INTEGER :: ini, inl, idepth ! Number of point and grid layers
165 !
166 REAL, DIMENSION(SIZE(PDZG,1)) :: zinfiltmax, zinfiltc, zexcess, zdgn, zwgtot, zpsiwtd, zwtd
167 ! ZINFILTMAX = maximum allowable infiltration rate
168 ! (from Darcy's Law) (m s-1)
169 ! ZEXCESS = working variable: excess soil water
170 ! which is used as a constraint
171 ! ZDGN = Depth of the last node (m)
172 ! and the water table (m s-1)
173 ! ZWGTOT = total soil moisture for ZINFNEG computation
174 ! ZPSIWTD = matric potential at saturation for water table depth coupling
175 ! ZWTD = water table depth positive below soil surface (m)
176 !
177 REAL, DIMENSION(SIZE(PDZG,1),SIZE(PDZG,2)) :: zwflux, zdfluxdt1, zdfluxdt2, zwfluxn
178 ! ZWFLUX = vertical soil water flux (+ up) (m s-1)
179 ! ZDFLUXDT = total vertical flux derrivative
180 ! ZDFLUXDT1 = vertical flux derrivative: dF_j/dw_j
181 ! ZDFLUXDT2 = vertical flux derrivative: dF_j/dw_j+1
182 ! ZWFLUXN = vertical soil water flux at end of time
183 !
184 REAL, DIMENSION(SIZE(PDZG,1),SIZE(PDZG,2)) :: zpsi, zk, znu, zwsat, zhead, &
185  zvapcond, zfrz, zki, &
186  zcapacity, zinfneg
187 ! ZNU = interfacial total conductivity (m s-1)
188 ! at level z_j
189 ! ZK = hydraulic conductivity (m s-1)
190 ! ZHEAD = matric potential gradient (-)
191 ! ZWSAT = ice modified soil porosity (m3 m-3)
192 ! ZFRZ = diffusion coefficient for freezing (-)
193 ! ZVAPCOND = vapor conductivity (m s-1)
194 ! ZKI = interfacial hydraulic conductivity (m s-1) at level z_j
195 ! ZCAPACITY = simple volumetric water holding capacity estimate for
196 ! wetting front penetration (-)
197 ! ZINFNEG = Negative infiltration (m s-1)
198 !
199 REAL, DIMENSION(SIZE(PDZG,1),SIZE(PDZG,2)) :: zamtrx, zbmtrx, zcmtrx, zfrc, zsol, &
200  ztopqs
201 ! ZAMTRX = leftmost diagonal element of tri-diagonal
202 ! coefficient matrix
203 ! ZBMTRX = center diagonal element (vector)
204 ! ZCMTRX = rightmost diagonal element (vector)
205 ! ZFRC = forcing function (vector)
206 ! ZSOL = solution vector
207 !
208 REAL, DIMENSION(SIZE(PDZG,1),SIZE(PDZG,2)) :: zinflayer
209 !
210 REAL, PARAMETER :: zwght = 0.5 ! time scheme weight for calculating flux.
211 ! varies from 0 (explicit time scheme)
212 ! to 1 (backward difference implicit)
213 ! Default is 1/2 (Crank-Nicholson)
214 !
215 REAL, PARAMETER :: zeice = 6.0 ! Ice vertical diffusion impedence factor
216 !
217 REAL :: zlog10, zs, zlog, zwdrain
218 !
219 REAL :: zdkdt1, zdkdt2, zdheaddt1, zdheaddt2
220 ! ZDKDT1 = hydraulic conductivity derrivative w/r/t upper layer water content
221 ! ZDKDT2 = "" lower layer water content
222 ! ZDHEADDT1 = matric potential gradient derrivative w/r/t upper layer water content
223 ! ZDHEADDT2 = "" lower layer water content
224 !
225 REAL(KIND=JPRB) :: zhook_handle
226 !
227 !-------------------------------------------------------------------------------
228 !
229 ! 0. Initialization:
230 ! ---------------
231 !
232 IF (lhook) CALL dr_hook('HYDRO_SOILDIF',0,zhook_handle)
233 !
234 ini = SIZE(pdzg(:,:),1)
235 inl = kmax_layer
236 !
237 zlog10 = log(10.0)
238 !
239 pdrain(:) = 0.0
240 pqsb(:) = 0.0
241 phorton(:) = 0.0
242 zinfiltc(:) = 0.0
243 zexcess(:) = 0.0
244 zinfiltmax(:) = 0.0
245 !
246 zdgn(:) = xundef
247 zpsiwtd(:) = xundef
248 zwtd(:) = xundef
249 !
250 zinfneg(:,:) = 0.0
251 zinflayer(:,:) = 0.0
252 zfrc(:,:) = 0.0
253 zfrz(:,:) = 0.0
254 !
255 zwsat(:,:) = xundef
256 zcapacity(:,:) = xundef
257 zpsi(:,:) = xundef
258 zk(:,:) = xundef
259 zvapcond(:,:) = xundef
260 zki(:,:) = xundef
261 zsol(:,:) = xundef
262 znu(:,:) = xundef
263 zhead(:,:) = xundef
264 zwflux(:,:) = xundef
265 zwfluxn(:,:) = xundef
266 zdfluxdt1(:,:) = xundef
267 zdfluxdt2(:,:) = xundef
268 zamtrx(:,:) = xundef
269 zbmtrx(:,:) = xundef
270 zcmtrx(:,:) = xundef
271 !
272 ! Modification/addition of frozen soil parameters
273 ! -----------------------------------------------
274 !
275 DO jl=1,inl
276  DO jj=1,ini
277 !
278  idepth=kwg_layer(jj)
279  IF(jl<=idepth)THEN
280 !
281 ! Modify soil porosity as ice assumed to become part
282 ! of solid soil matrix (with respect to liquid flow):
283  zwsat(jj,jl) = max(xwgmin, pwsat(jj,jl)-pwgi(jj,jl))
284 !
285 ! Factor from (Johnsson and Lundin 1991), except here it is normalized so that it
286 ! goes to zero in the limit as all available pore space is filled up with ice.
287 ! For now, a simple constant is used for all soils. Further modifications
288 ! will be made as research warrents.
289 ! Old : 10.**(-ZEICE*(PWGI(JJ,JL)/(PWGI(JJ,JL)+PWG(JJ,JL))))
290  zfrz(jj,jl) = exp(zlog10*(-zeice*(pwgi(jj,jl)/(pwgi(jj,jl)+pwg(jj,jl)))))
291 !
292  ENDIF
293 !
294  ENDDO
295 ENDDO
296 !
297 ! Lateral sub-surface flow (m s-1) if Topmodel
298 ! --------------------------------------------
299 !
300  IF(hrunoff=='SGH')THEN
301  ztopqs(:,:)=zfrz(:,:)*ptopqs(:,:)
302  ELSE
303  ztopqs(:,:)=0.0
304  ENDIF
305 !
306 ! 1. Infiltration at "t"
307 ! -------------------
308 !
309 ! Surface flux term (m s-1): Infiltration (and surface runoff)
310 ! Surface fluxes are limited a Green-Ampt approximation from Abramopoulos et al
311 ! (1988) and Entekhabi and Eagleson (1989).
312 ! Note : when Horton option is used, infiltration already calculated in hydro_sgh
313 IF(hrunoff/='WSAT'.AND.hhort/='SGH')THEN
314 ! Green-Ampt approximation for maximum infiltration (derived form)
315  zinfiltmax(:) = infmax_func(pwg,zwsat,zfrz,pcondsat,pmpotsat,pbcoef,pdzg,pdg,klayer_hort)
316 ! Fast(temporal)-response runoff (surface excess) (m s-1):
317  phorton(:) = (1.-pfsat(:)) * max(0.0,ppg(:)-zinfiltmax(:))
318 ENDIF
319 !
320 !
321 ! 2. Initialise soil moisture profile according to infiltration terms at "t"
322 ! ----------------------------------------------------------------------
323 !
324 !Surface cumulative infiltration (m)
325 zinfiltc(:) = max(0.0,ppg(:)-phorton(:))*ptstep
326 !
327 DO jl=1,inl
328  DO jj=1,ini
329  idepth=kwg_layer(jj)
330  IF(jl<=idepth)THEN
331 ! Simple volumetric water holding capacity estimate for wetting front penetration
332  zcapacity(jj,jl) = max(0.0,zwsat(jj,jl)-pwg(jj,jl))*pdzg(jj,jl)
333 ! Infiltration terms (m) :
334  zinflayer(jj,jl) = min(zinfiltc(jj),zcapacity(jj,jl))
335 ! Soil moisture (m3/m3) :
336  pwg(jj,jl) = pwg(jj,jl)+zinflayer(jj,jl)/pdzg(jj,jl)
337 ! Put remainding infiltration into the next layer (m)
338  zinfiltc(jj) = zinfiltc(jj) - zinflayer(jj,jl)
339  ENDIF
340  ENDDO
341 ENDDO
342 !
343 ! 3. Compute Fast(temporal)-response runoff and Possible negative infiltration
344 ! -------------------------------------------------------------------------
345 !
346 !Possible negative infiltration (m s-1)
347 zwgtot(:)=0.0
348 DO jl=1,inl
349  DO jj=1,ini
350  idepth=kwg_layer(jj)
351  IF(jl<idepth)THEN
352  zinfneg(jj,jl) = (min(0.0,ppg(jj))-pevapcor(jj))*pdzg(jj,jl)*pwg(jj,jl)
353  zwgtot(jj ) = zwgtot(jj)+pdzg(jj,jl)*pwg(jj,jl)
354  ENDIF
355  ENDDO
356 ENDDO
357 DO jl=1,inl
358  DO jj=1,ini
359  zinfneg(jj,jl) = zinfneg(jj,jl)/zwgtot(jj)
360  ENDDO
361 ENDDO
362 !
363 !Fast(temporal)-response runoff (surface excess) (kg m2 s-1):
364 !special case : if infiltration > total soil capacity
365 phorton(:)=(phorton(:)+zinfiltc(:)/ptstep)*xrholw
366 !
367 !
368 ! 4. Initialise matric potential and hydraulic conductivity at "t"
369 ! -------------------------------------------------------------
370 !
371 DO jl=1,inl
372  DO jj=1,ini
373  idepth=kwg_layer(jj)
374  IF(jl<=idepth)THEN
375 ! Matric potential (m) :
376 ! psi=mpotsat*(w/wsat)**(-bcoef)
377  zs = min(1.0,pwg(jj,jl)/zwsat(jj,jl))
378  zlog = pbcoef(jj,jl)*log(zs)
379  zpsi(jj,jl) = pmpotsat(jj,jl)*exp(-zlog)
380 ! Hydraulic conductivity from matric potential (m s-1):
381 ! k=frz*condsat*(psi/mpotsat)**(-2-3/bcoef)
382  zlog = -zlog*(2.0+3.0/pbcoef(jj,jl))
383  zk(jj,jl) = zfrz(jj,jl)*pcondsat(jj,jl)*exp(-zlog)
384  ENDIF
385  ENDDO
386 ENDDO
387 !
388 ! Prepare water table depth coupling
389 ! ----------------------------------
390 !
391 DO jj=1,ini
392  idepth=kwg_layer(jj)
393 ! Depth of the last node
394  zdgn(jj) = 0.5*(pdg(jj,idepth)+pdg(jj,idepth-1))
395  zpsiwtd(jj) = zpsi(jj,idepth)
396  IF(pwtd(jj)/=xundef)THEN
397 ! Water table depth
398  zwtd(jj) = max(pdg(jj,idepth),-pwtd(jj))
399 ! Modify matric potential at saturation for water table coupling
400  zs = min(1.0,zwsat(jj,idepth)/pwsat(jj,idepth))
401  zlog = pbcoef(jj,idepth)*log(zs)
402  zpsiwtd(jj) = pmpotsat(jj,idepth)*exp(-zlog)
403  ENDIF
404 ENDDO
405 !
406 ! 5. Vapor diffusion conductivity (m s-1)
407 ! ------------------------------------
408 !
409 zvapcond(:,:) = vapcondcf(ptg,pps,pwg,pwgi,zpsi,pwsat,pwfc,pqsat,pqsati,kwg_layer,inl)
410 zvapcond(:,:) = zfrz(:,:)*zvapcond(:,:)
411 !
412 ! 6. Linearized water flux: values at "t"
413 ! ------------------------------------
414 ! calculate flux at the beginning of the time step:
415 !
416 DO jl=1,inl
417  DO jj=1,ini
418 !
419  idepth=kwg_layer(jj)
420  IF(jl<idepth)THEN
421 !
422 ! Total interfacial conductivity (m s-1) And Potential gradient (dimensionless):
423  zki(jj,jl) = sqrt(zk(jj,jl)*zk(jj,jl+1))
424  znu(jj,jl) = zki(jj,jl) + sqrt(zvapcond(jj,jl)*zvapcond(jj,jl+1))
425  zhead(jj,jl) = (zpsi(jj,jl)-zpsi(jj,jl+1))/pdzdif(jj,jl)
426 !
427 ! Total Sub-surface soil water fluxes (m s-1): (+ up, - down) using Darcy's
428 ! Law with an added linear drainage term:
429  zwflux(jj,jl) = -znu(jj,jl) * zhead(jj,jl) - zki(jj,jl)
430 !
431  ELSEIF(jl==idepth)THEN !Last layers
432 !
433 ! Total interfacial conductivity (m s-1) And Potential gradient (dimensionless):
434  zki(jj,idepth) = zk(jj,idepth)
435  znu(jj,idepth) = zk(jj,idepth) * pfwtd(jj)
436  zhead(jj,idepth) = (zpsi(jj,idepth)-zpsiwtd(jj))/(zwtd(jj)-zdgn(jj))
437 !
438 ! Total Sub-surface soil water fluxes (m s-1): (+ up, - down) using Darcy's
439 ! Law with an added linear drainage term:
440  zwflux(jj,idepth) = -znu(jj,idepth) * zhead(jj,idepth) - zki(jj,idepth)
441 !
442  ENDIF
443 !
444  ENDDO
445 ENDDO
446 !
447 !
448 ! 7. Linearized water flux: values at "t+dt"
449 ! ---------------------------------------
450 ! Flux Derrivative terms, see A. Boone thesis (Annexe E).
451 !
452 DO jl=1,inl
453  DO jj=1,ini
454  idepth=kwg_layer(jj)
455  IF(jl<idepth)THEN
456  zdheaddt1 = -pbcoef(jj,jl )*zpsi(jj,jl )/(pwg(jj,jl )*pdzdif(jj,jl))
457  zdheaddt2 = -pbcoef(jj,jl+1)*zpsi(jj,jl+1)/(pwg(jj,jl+1)*pdzdif(jj,jl))
458  zdkdt1 = (2.*pbcoef(jj,jl )+3.)*zki(jj,jl)/(2.0*pwg(jj,jl ))
459  zdkdt2 = (2.*pbcoef(jj,jl+1)+3.)*zki(jj,jl)/(2.0*pwg(jj,jl+1))
460 ! Total Flux derrivative terms:
461  zdfluxdt1(jj,jl) = -zdkdt1*zhead(jj,jl) - znu(jj,jl)*zdheaddt1 - zdkdt1
462  zdfluxdt2(jj,jl) = -zdkdt2*zhead(jj,jl) + znu(jj,jl)*zdheaddt2 - zdkdt2
463  ELSEIF(jl==idepth)THEN !Last layers
464  zdheaddt1 = -pbcoef(jj,idepth)*zpsi(jj,idepth)/(pwg(jj,idepth)*(zwtd(jj)-zdgn(jj))) &
465  +pbcoef(jj,idepth)*zpsiwtd(jj )/(zwsat(jj,idepth)*(zwtd(jj)-zdgn(jj)))
466  zdheaddt2 = 0.0
467  zdkdt1 = (2.*pbcoef(jj,idepth)+3.)*zk(jj,idepth)/pwg(jj,idepth)
468  zdkdt2 = 0.0
469 ! Total Flux derrivative terms:
470  zdfluxdt1(jj,idepth) = -zdkdt1*zhead(jj,idepth)*pfwtd(jj) - znu(jj,idepth)*zdheaddt1 - zdkdt1
471  zdfluxdt2(jj,idepth) = -zdkdt2*zhead(jj,idepth)*pfwtd(jj) + znu(jj,idepth)*zdheaddt2 - zdkdt2
472  ENDIF
473  ENDDO
474 ENDDO
475 !
476 ! 8. Jacobian Matrix coefficients and Forcing function
477 ! -------------------------------------------------
478 !
479 !surface layer:
480 zfrc(:,1) = zwflux(:,1) - pleg(:) - pf2wght(:,1)*pletr(:) + zinfneg(:,1) - ztopqs(:,1)
481 zamtrx(:,1) = 0.0
482 zbmtrx(:,1) = (pdzg(:,1)/ptstep) - zwght*zdfluxdt1(:,1)
483 zcmtrx(:,1) = -zwght*zdfluxdt2(:,1)
484 !
485 !Other sub-surface layers:
486 DO jl=2,inl
487  DO jj=1,ini
488  idepth=kwg_layer(jj)
489  IF(jl<=idepth)THEN
490  zfrc(jj,jl) = zwflux(jj,jl) - zwflux(jj,jl-1) - pf2wght(jj,jl)*pletr(jj) + zinfneg(jj,jl) - ztopqs(jj,jl)
491  zamtrx(jj,jl) = zwght*zdfluxdt1(jj,jl-1)
492  zbmtrx(jj,jl) = (pdzg(jj,jl)/ptstep) - zwght*(zdfluxdt1(jj,jl)-zdfluxdt2(jj,jl-1))
493  zcmtrx(jj,jl) = -zwght*zdfluxdt2(jj,jl)
494  ENDIF
495  ENDDO
496 ENDDO
497 !
498 !Solve Matrix Equation: tridiagonal system: solve for soil
499 !water (volumetric water content) tendencies:
500 !
501  CALL tridiag_dif(zamtrx,zbmtrx,zcmtrx,zfrc,kwg_layer,inl,zsol)
502 !
503 ! 9. Final calculations and diagnostics:
504 ! -----------------------------------
505 !
506 !
507 DO jl=1,inl
508  DO jj=1,ini
509 !
510  idepth=kwg_layer(jj)
511  IF(jl<idepth)THEN
512 !
513 ! Update liquid water content (m3 m-3):
514  pwg(jj,jl) = pwg(jj,jl) + zsol(jj,jl)
515 !
516 ! Supersaturated drainage (kg m-2 s-1):
517  zexcess(jj) = max(0.0, pwg(jj,jl) - zwsat(jj,jl))
518  pwg(jj,jl ) = min(pwg(jj,jl),zwsat(jj,jl))
519  pwg(jj,jl+1) = pwg(jj,jl+1) + zexcess(jj)*(pdzg(jj,jl)/pdzg(jj,jl+1))
520 !
521 ! final fluxes (at end of time step) (m s-1):
522  zwfluxn(jj,jl) = zwflux(jj,jl) + zdfluxdt1(jj,jl)*zsol(jj,jl) + zdfluxdt2(jj,jl)*zsol(jj,jl+1)
523 !
524 ! Total topmodel subsurface flow
525  pqsb(jj) = pqsb(jj) + ztopqs(jj,jl)*xrholw
526 !
527  ELSEIF(jl==idepth)THEN
528 !
529 ! Update liquid water content (m3 m-3):
530  pwg(jj,idepth) = pwg(jj,idepth) + zsol(jj,idepth)
531 !
532 ! Supersaturated drainage (kg m-2 s-1):
533  zexcess(jj) = max(0.0, pwg(jj,idepth) - zwsat(jj,idepth))
534  pwg(jj,idepth) = min(pwg(jj,idepth),zwsat(jj,idepth))
535  pdrain(jj) = pdrain(jj) + zexcess(jj)*pdzg(jj,idepth)*xrholw/ptstep
536 !
537 ! final fluxes (at end of time step) (m s-1):
538  zwfluxn(jj,idepth) = zwflux(jj,idepth) + zdfluxdt1(jj,idepth)*zsol(jj,idepth)
539 !
540 ! Drainage or baseflow out of bottom of model (slow time response) (kg m-2 s-1):
541 ! Final fluxes (if needed) over the time step (kg m-2 s-1)
542 ! would be calculated as (for water budget checks) as F = [ wgt*F(t+dt) + (1.-wgt)*F(t) ]*XRHOLW
543  pdrain(jj) = pdrain(jj)-(zwght*zwfluxn(jj,idepth)+(1.-zwght)*zwflux(jj,idepth))*xrholw
544 !
545 ! Total topmodel subsurface flow
546  pqsb(jj) = pqsb(jj) + ztopqs(jj,idepth)*xrholw
547 !
548  ENDIF
549 !
550  ENDDO
551 ENDDO
552 !
553 ! Possible correction/Constraint application:
554 !
555 DO jl=1,inl
556  DO jj=1,ini
557  idepth=kwg_layer(jj)
558  IF(jl<idepth)THEN
559 ! if the soil water happens to fall below the minimum, then
560 ! extract needed water from the layer below: this should
561 ! generally be non-existant: but added to ensure conservation
562 ! even for the most extreme events.
563  zexcess(jj) = max(0., xwgmin - pwg(jj,jl))
564  pwg(jj,jl) = pwg(jj,jl) + zexcess(jj)
565  pwg(jj,jl+1) = pwg(jj,jl+1) - zexcess(jj)*pdzg(jj,jl)/pdzg(jj,jl+1)
566  ELSEIF(jl==idepth.AND.pwg(jj,idepth)<xwgmin)THEN
567 ! NOTE, negative moisture can arise for *completely* dry/dessicated soils
568 ! owing to the above check because vertical fluxes
569 ! can be *very* small but nonzero. Here correct owing to
570 ! small numerical drainage.
571  pdrain(jj) = pdrain(jj) + min(0.0,pwg(jj,idepth)-xwgmin)*pdzg(jj,idepth)*xrholw/ptstep
572  pwg(jj,idepth) = xwgmin
573  ENDIF
574  ENDDO
575 ENDDO
576 !
577 IF (lhook) CALL dr_hook('HYDRO_SOILDIF',1,zhook_handle)
578 !
579 END SUBROUTINE hydro_soildif
580 
581 
582 
583 
584 
585 
subroutine hydro_soildif(HRUNOFF, HHORT, PTSTEP, PBCOEF, PWSAT, PCONDSAT, PMPOTSAT, PWFC, PDG, PDZG, PDZDIF, PPG, PLETR, PLEG, PEVAPCOR, PF2WGHT, PWG, PWGI, PTG, PPS, PQSAT, PQSATI, PDRAIN, PHORTON, PFSAT, KWG_LAYER, KMAX_LAYER, KLAYER_HORT, PTOPQS, PQSB, PFWTD, PWTD)