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