SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
init_coupl_topd.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 ! #######################
7  SUBROUTINE init_coupl_topd (DGEI, I, UG, U, &
8  hprogram,ki)
9 ! #######################
10 !
11 !!**** *INIT_COUPL_TOPD*
12 !!
13 !! PURPOSE
14 !! -------
15 !! This routine aims at initialising the variables
16 ! needed for coupling with Topmodel.
17 !
18 !!** METHOD
19 !! ------
20 !
21 !! EXTERNAL
22 !! --------
23 !!
24 !! none
25 !!
26 !! IMPLICIT ARGUMENTS
27 !! ------------------
28 !!
29 !!
30 !! REFERENCE
31 !! ---------
32 !!
33 !!
34 !!
35 !! AUTHOR
36 !! ------
37 !!
38 !! K. Chancibault * LTHE / Meteo-France *
39 !!
40 !! MODIFICATIONS
41 !! -------------
42 !!
43 !! Original 16/10/2003
44 !! Modif BV : supression of variables specific to Topmodel
45 !! 20/12/2007 - mll : Adaptation between a lonlat grid system for ISBA
46 !! and lambert II projection for topmodel
47 !! 11/2011: Modif BV : Creation of masks between ISBA and TOPODYN
48 ! transfered in PGD step (routine init_pgd_topd)
49 !! 03/2014: Modif BV : New organisation for first time step (displacement
50 !! in coupl_topd)
51 !-------------------------------------------------------------------------------
52 !
53 !* 0. DECLARATIONS
54 ! ------------
55 !
56 ! Modules
57 !
59 USE modd_isba_n, ONLY : isba_t
61 USE modd_surf_atm_n, ONLY : surf_atm_t
62 !
63 USE modd_coupling_topd, ONLY : xwstopi, xwfctopi, xdtopi, xas_nature, xatop,&
64  xcstopi, xwtopt, xavg_runoffcm, xavg_draincm,&
65  xdtopt, xka_pre, xkac_pre, nmaski, xdmaxfc, &
66  xwg_full, xwstopt, xwfctopt, nmaskt, &
67  nnbv_in_mesh, xbv_in_mesh, xtotbv_in_mesh,&
68  xrunoff_top, nnpix,&
69  xfrac_d2, xfrac_d3, xwgi_full,&
70  xrun_torout, xdr_torout,&
71  lstock_topd,nnb_stp_restart,nmaskt_patch
72 USE modd_dummy_exp_profile,ONLY :xf_param, xc_depth_ratio
73 USE modd_topodyn, ONLY : nncat, xmpara, xcstopt, nmesht, xdxt,&
74  nnmc, xrtop_d2, nnb_topd_step, xdmaxt
75 !
76 USE modd_surf_par, ONLY : xundef, nundef
77 
78 !
79 ! Interfaces
80 USE modi_get_luout
81 USE modi_read_file_masktopd
84 USE modi_isba_to_topd
85 USE modi_restart_coupl_topd
86 USE modi_avg_patch_wg
87 USE modi_dg_dfto3l
88 !
89 USE mode_soil
90 !
91 USE yomhook ,ONLY : lhook, dr_hook
92 USE parkind1 ,ONLY : jprb
93 !
94 IMPLICIT NONE
95 !
96 !* 0.1 declarations of arguments
97 !
98 !
99 TYPE(diag_evap_isba_t), INTENT(INOUT) :: dgei
100 TYPE(isba_t), INTENT(INOUT) :: i
101 TYPE(surf_atm_grid_t), INTENT(INOUT) :: ug
102 TYPE(surf_atm_t), INTENT(INOUT) :: u
103 !
104  CHARACTER(LEN=*), INTENT(IN) :: hprogram !
105 INTEGER, INTENT(IN) :: ki ! Grid dimensions
106 !
107 !* 0.2 declarations of local variables
108 !
109 !REAL, DIMENSION(:), ALLOCATABLE :: ZDTAV ! Averaged depth soil on TOP-LAT grid
110 REAL, DIMENSION(:), ALLOCATABLE :: zsand_full, zclay_full, zdg_full ! Isba variables on the full domain
111 REAL, DIMENSION(:), ALLOCATABLE :: zfrac ! fraction of SurfEx mesh that covers one or several catchments
112 REAL, DIMENSION(:), ALLOCATABLE :: zdmaxav ! dificit maximal moyen par bassin
113 REAL, DIMENSION(:),ALLOCATABLE :: zsandtopi, zclaytopi!, ZWWILTTOPI !sand and clay fractions on TOPMODEL layers
114 !
115 !ludo
116 REAL, DIMENSION(:), ALLOCATABLE :: zksat !ksat surf
117 REAL, DIMENSION(:), ALLOCATABLE :: zdg2_full, zdg3_full, zwg2_full, zwg3_full, zrtop_d2
118 REAL,DIMENSION(:), ALLOCATABLE :: zwgi_full, z_wfctopi, z_wstopi
119 !
120 REAL :: zcoef_anis !coefficient anisotropie Ksat:
121  ! Ksat horiz=ZCOEF*Ksat vert
122 INTEGER :: jj,ji ! loop control
123 INTEGER :: jcat,jmesh ! loop control
124 INTEGER :: iluout ! Logical unit for output filr
125 !
126 REAL, DIMENSION(SIZE(I%XWG,1),3) :: zwg_3l,zwgi_3l,zdg_3l
127 !
128 REAL(KIND=JPRB) :: zhook_handle
129 !-------------------------------------------------------------------------------
130 IF (lhook) CALL dr_hook('INIT_COUPL_TOPD',0,zhook_handle)
131 !
132  CALL get_luout(hprogram,iluout)
133 !
134 WRITE(iluout,*) 'INITIALISATION INIT_COUPL_TOPD'
135 !
136 ALLOCATE(nmaskt(nncat,nmesht))
137 nmaskt(:,:) = nundef
138 !
139 !* 1 Initialization:
140 ! ---------------
141 ALLOCATE(nmaskt_patch(SIZE(i%XWG,1)))
142 !
143 IF (i%CISBA=='DIF') THEN
144  CALL dg_dfto3l(i, &
145  SIZE(i%XWG,1),zdg_3l)
146 ELSEIF (i%CISBA=='3-L') THEN
147  CALL avg_patch_wg(i, &
148  SIZE(i%XWG,1),zwg_3l,zwgi_3l,zdg_3l)
149 ENDIF
150 ! la surface saturee, à l'initialisation est nulle, donc on initialise les lambdas de telle sorte qu'aucun pixel ne soit sature
151 ALLOCATE(xka_pre(nncat,nmesht))
152 ALLOCATE(xkac_pre(nncat))
153 xka_pre(:,:) = 0.0
154 xkac_pre(:) = maxval(xka_pre) + 1.
155 !
156 !Cumulated runoff initialisation
157 ALLOCATE(xrunoff_top(u%NSIZE_NATURE))
158 xrunoff_top(:) = dgei%XAVG_RUNOFFC(:)
159 !
160 IF(.NOT.ALLOCATED(xavg_runoffcm)) ALLOCATE(xavg_runoffcm(u%NSIZE_NATURE))
161 xavg_runoffcm(:) = dgei%XAVG_RUNOFFC(:)
162 !
163 IF(.NOT.ALLOCATED(xavg_draincm )) ALLOCATE(xavg_draincm(u%NSIZE_NATURE))
164 xavg_draincm(:) = dgei%XAVG_DRAINC(:)
165 !
166 !
167 ! Reading masks
168  CALL read_file_masktopd(ki)
169 !
170 !* 2.1 Fraction of SurfEx mesh with TOPMODEL
171 ! -------------------------------------
172 !
173 ALLOCATE(nnbv_in_mesh(ki,nncat))
174 ALLOCATE(xbv_in_mesh(ki,nncat))
175 ALLOCATE(xtotbv_in_mesh(ki))
176 !
177 xtotbv_in_mesh(:) = 0.0
178 !
179 DO jj=1,ki
180  !
181  xbv_in_mesh(jj,:) = 0.0
182  !
183  DO ji=1,nncat
184  nnbv_in_mesh(jj,ji) = count( nmaski(jj,ji,:)/=nundef )
185  xbv_in_mesh(jj,ji) = REAL(NNBV_IN_MESH(JJ,JI)) * xdxt(ji)**2
186  xtotbv_in_mesh(jj) = xtotbv_in_mesh(jj) + xbv_in_mesh(jj,ji)
187  ENDDO
188  !
189  IF (xtotbv_in_mesh(jj)> ug%XMESH_SIZE(jj)) THEN
190  xbv_in_mesh(jj,:) = xbv_in_mesh(jj,:) * ug%XMESH_SIZE(jj)/xtotbv_in_mesh(jj)
191  xtotbv_in_mesh(jj) = ug%XMESH_SIZE(jj)
192  ENDIF
193 ENDDO
194 !
195 !* 2.2 Fraction of SurfEx mesh with each catchment
196 ! -------------------------------------------
197 !
198 ALLOCATE(zfrac(ki)) ! fraction not covered by catchments
199 zfrac(:) = ( ug%XMESH_SIZE(:)-xtotbv_in_mesh(:) ) / ug%XMESH_SIZE(:)
200 zfrac(:) = min(max(zfrac(:),0.),1.)
201 !
202 ALLOCATE(xatop(u%NSIZE_NATURE)) ! fraction covered by catchments part nature
203  CALL pack_same_rank(u%NR_NATURE,(1.-zfrac),xatop)
204 !
205 !
206 IF (hprogram=='POST ') goto 10
207 !
208 !* 3.0 Wsat, Wfc and depth for TOPODYN on ISBA grid
209 ! --------------------------------------------
210 !* 3.1 clay, sand fraction, depth hydraulic conductivity at saturation of the layer for TOPODYN
211 ! ---------------------------------------------------------
212 !
213 ALLOCATE(zsand_full(ki))
214 ALLOCATE(zclay_full(ki))
215  CALL unpack_same_rank(u%NR_NATURE,i%XSAND(:,2),zsand_full)
216  CALL unpack_same_rank(u%NR_NATURE,i%XCLAY(:,2),zclay_full)
217 !
218 !ludo prof variable pour tr lat (OK car sol homogene verticalement, faux sinon)
219 ALLOCATE(zdg2_full(ki))
220 ALLOCATE(zdg3_full(ki))
221  CALL unpack_same_rank(u%NR_NATURE,zdg_3l(:,2),zdg2_full)
222  CALL unpack_same_rank(u%NR_NATURE,zdg_3l(:,3),zdg3_full)
223 !
224 !
225 ALLOCATE(zrtop_d2(ki))
226 zrtop_d2(:) = 0.
227 !
228 DO jmesh=1,ki
229  IF ( zdg2_full(jmesh)/=xundef .AND. zfrac(jmesh)<1. ) THEN
230 ! ZRTOP_D2(JMESH) = 0.
231  DO jcat=1,nncat
232  !moyenne ponderee pour cas ou plusieurs bv sur maille
233  zrtop_d2(jmesh) = zrtop_d2(jmesh) + xrtop_d2(jcat)*min(xbv_in_mesh(jmesh,jcat)/xtotbv_in_mesh(jmesh),1.)
234  END DO
235  ENDIF
236 ENDDO
237 !ZTOP_D2 * D2 < D3 : the depth concerned by lateral transfers is lower than D2
238 WHERE( zdg2_full/=xundef .AND. zrtop_d2*zdg2_full>zdg3_full ) zrtop_d2(:) = zdg3_full(:)/zdg2_full(:)
239 !
240 DEALLOCATE(zfrac)
241 !
242 ALLOCATE(xfrac_d2(ki))
243 ALLOCATE(xfrac_d3(ki))
244 xfrac_d2(:)=1.
245 xfrac_d3(:)=0.
246 !
247 IF (i%CISBA=='3-L') THEN
248  WHERE( zdg2_full/=xundef ) ! if the depth is < D2
249  xfrac_d2(:) = min(1.,zrtop_d2(:))
250  END WHERE
251  WHERE( zdg2_full/=xundef .AND. zrtop_d2*zdg2_full>zdg2_full ) ! if the depth is > D2
252  xfrac_d3(:) = (zrtop_d2(:)*zdg2_full(:)-zdg2_full(:)) / (zdg3_full(:)-zdg2_full(:))
253  xfrac_d3(:) = max(0.,xfrac_d3(:))
254  END WHERE
255 ENDIF
256  !
257 ALLOCATE(zdg_full(ki))
258 WHERE (zdg2_full/=xundef)
259  zdg_full = xfrac_d2*zdg2_full + xfrac_d3*(zdg3_full-zdg2_full)
260 ELSEWHERE
261  zdg_full = xundef
262 END WHERE
263 !
264 ALLOCATE(zsandtopi(ki))
265 ALLOCATE(zclaytopi(ki))
266 zsandtopi(:)=0.0
267 zclaytopi(:)=0.0
268 ALLOCATE(xdtopi(ki))
269 xdtopi(:)=0.0
270 WHERE ( zdg_full/=xundef .AND. zdg_full/=0. )
271  xdtopi = zdg_full
272  zsandtopi = zsandtopi + zsand_full * zdg_full
273  zclaytopi = zclaytopi + zclay_full * zdg_full
274  zsandtopi = zsandtopi / xdtopi
275  zclaytopi = zclaytopi / xdtopi
276 ELSEWHERE
277  zsandtopi = xundef
278  zclaytopi = xundef
279  xdtopi = xundef
280 END WHERE
281 DEALLOCATE(zsand_full)
282 DEALLOCATE(zclay_full)
283 !
284 !* 4.1 depth of the Isba layer on TOP-LAT grid
285 ! ---------------------------------------
286 !
287 ALLOCATE(xdtopt(nncat,nmesht))
288 xdtopt(:,:) = 0.0
289  CALL isba_to_topd(xdtopi,xdtopt)
290 !
291 !* 3.2 Wsat and Wfc on TOPODYN layer
292 ! -----------------------------
293 !
294 ALLOCATE(xwstopi(ki))
295 ALLOCATE(xwfctopi(ki))
296 xwstopi(:) = 0.0
297 xwfctopi(:) = 0.0
298 xwstopi = wsat_func_1d(zclaytopi,zsandtopi,i%CPEDOTF)
299 IF (i%CISBA=='2-L' .OR. i%CISBA=='3-L') THEN
300  ! field capacity at hydraulic conductivity = 0.1mm/day
301  xwfctopi = wfc_func_1d(zclaytopi,zsandtopi,i%CPEDOTF)
302 ELSE IF (i%CISBA=='DIF') THEN
303  ! field capacity at water potential = 0.33bar
304  xwfctopi = w33_func_1d(zclaytopi,zsandtopi,i%CPEDOTF)
305 END IF
306 !
307 !modif ludo test ksat exp
308 WRITE(iluout,*) 'CKSAT==',i%CKSAT
309 
310 ALLOCATE(zksat(ki))
311 zksat(:) = 0.0
312 ALLOCATE(xcstopi(ki))
313 xcstopi(:) = 0.0
314 IF( i%CKSAT=='SGH' .OR. i%CKSAT=='EXP' ) THEN
315  !
316  !valeur patch 1 (idem wsat wfc) a voir cas ou il existe plusieurs patchs
317  CALL unpack_same_rank(u%NR_NATURE,i%XCONDSAT(:,1,1),zksat)
318  !passage de definition Ksat(profondeur) en Ksat(deficit)
319  WHERE ( zdg_full/=xundef .AND. (xwstopi-xwfctopi/=0.) )
320  xcstopi(:) = zksat(:) / (xwstopi(:)-xwfctopi(:))
321  END WHERE
322  !
323 ELSE
324  !
325  xcstopi(:) = hydcondsat_func(zclaytopi,zsandtopi,i%CPEDOTF)
326  !passage de definition Ksat(profondeur) en Ksat(deficit)
327  WHERE ( zdg_full/=xundef .AND. (xwstopi-xwfctopi/=0.) )
328  xcstopi(:) = xcstopi(:) / (xwstopi(:)-xwfctopi(:))
329  END WHERE
330  !
331 ENDIF
332 !
333 DEALLOCATE(zsandtopi)
334 DEALLOCATE(zclaytopi)
335 DEALLOCATE(zrtop_d2)
336 !
337 !* 4.3 Ko on TOP-LAT grid
338 ! ------------------
339 !
340 ALLOCATE(xcstopt(nncat,nmesht))
341  CALL isba_to_topd(xcstopi,xcstopt)
342 WHERE (xcstopt == xundef) xcstopt = 0.0
343  zcoef_anis = 1.
344  xcstopt = xcstopt*zcoef_anis
345 !
346 !
347 ALLOCATE(xwg_full(ki))
348 ALLOCATE(xwgi_full(ki))
349 ALLOCATE(xwtopt(nncat,nmesht))
350 xwtopt(:,:) = 0.0
351 ALLOCATE(xwstopt(nncat,nmesht))
352 ALLOCATE(xwfctopt(nncat,nmesht))
353 ALLOCATE(xdmaxfc(nncat,nmesht))
354 xdmaxfc(:,:) = xundef
355 ALLOCATE(xdmaxt(nncat,nmesht))
356 xdmaxt(:,:)=xundef
357 !
358 ALLOCATE(zwg2_full(ki))
359 ALLOCATE(zwg3_full(ki))
360 !
361  CALL unpack_same_rank(u%NR_NATURE,zwg_3l(:,2),zwg2_full)
362  CALL unpack_same_rank(u%NR_NATURE,zwg_3l(:,3),zwg3_full)
363 !
364 WHERE ( zdg_full/=xundef .AND. zdg_full/=0. )
365  xwg_full = xfrac_d2*(zdg2_full/zdg_full)*zwg2_full + xfrac_d3*((zdg3_full-zdg2_full)/zdg_full)*zwg3_full
366 ELSEWHERE
367  xwg_full = xundef
368 END WHERE
369 
370 xwgi_full = 0.
371 !
372 !
373 !* 4.4 Initialisation of the previous time step water storage on topodyn-lat grid
374 ! --------------------------------------------------------------------------
375 !* 4.5 M parameter on TOPODYN grid
376 ! ------------------------
377 !* 4.5.1 Mean depth soil on catchment
378 !
379 ALLOCATE(xmpara(nncat))
380 xmpara(:) = 0.0
381 IF (.NOT.ALLOCATED(xf_param)) ALLOCATE(xf_param(SIZE(i%XF_PARAM)))
382 !
383 !
384 !* 5.0 Initial saturated area computation
385 ! -----------------------------------------------------------
386 !
387 ALLOCATE(xas_nature(u%NSIZE_NATURE))
388 xas_nature(:) = 0.0
389 !
390 !* 6.0 Stock management in case of restart
391 ! -----------------------------------------------------------
392 !
393 10 CONTINUE
394 !
395 !stock
396 ALLOCATE(xrun_torout(nncat,nnb_topd_step+nnb_stp_restart))
397 ALLOCATE(xdr_torout(nncat,nnb_topd_step+nnb_stp_restart))
398 xrun_torout(:,:) = 0.
399 xdr_torout(:,:) = 0.
400 !
401 IF (hprogram=='POST ') goto 20
402 !
403 IF (lstock_topd) CALL restart_coupl_topd(ug, u, &
404  hprogram,ki)
405 !
406 !* 7.0 deallocate
407 ! ----------
408 !
409 DEALLOCATE(zdg2_full)
410 DEALLOCATE(zdg3_full)
411 DEALLOCATE(zwg2_full)
412 DEALLOCATE(zwg3_full)
413 !
414 20 CONTINUE
415 !
416 IF (lhook) CALL dr_hook('INIT_COUPL_TOPD',1,zhook_handle)
417 !
418 END SUBROUTINE init_coupl_topd
419 
420 
421 
422 
423 
424 
425 
subroutine dg_dfto3l(I, KI, PDG)
Definition: dg_dfto3l.F90:7
real function, dimension(size(pclay)) wfc_func_1d(PCLAY, PSAND, HPEDOTF)
Definition: mode_soil.F90:535
subroutine restart_coupl_topd(UG, U, HPROGRAM, KI)
subroutine read_file_masktopd(KI)
subroutine avg_patch_wg(I, KI, PWG, PWGI, PDG)
Definition: avg_patch_wg.F90:7
subroutine get_luout(HPROGRAM, KLUOUT)
Definition: get_luout.F90:6
real function, dimension(size(pclay)) w33_func_1d(PCLAY, PSAND, HPEDOTF)
Definition: mode_soil.F90:560
real function, dimension(size(psand)) wsat_func_1d(PCLAY, PSAND, HPEDOTF)
Definition: mode_soil.F90:486
subroutine init_coupl_topd(DGEI, I, UG, U, HPROGRAM, KI)
subroutine isba_to_topd(PVARI, PVART)
Definition: isba_to_topd.F90:7