forked from juliusvira/ctsm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSoilHydrologyType.F90
More file actions
386 lines (332 loc) · 18.8 KB
/
SoilHydrologyType.F90
File metadata and controls
386 lines (332 loc) · 18.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
Module SoilHydrologyType
use shr_kind_mod , only : r8 => shr_kind_r8
use shr_log_mod , only : errMsg => shr_log_errMsg
use abortutils , only : endrun
use decompMod , only : bounds_type
use clm_varpar , only : nlevgrnd, nlayer, nlayert, nlevsoi
use clm_varcon , only : spval
use clm_varctl , only : iulog
use LandunitType , only : lun
use ColumnType , only : col
use WaterStateBulkType , only : waterstatebulk_type
use column_varcon , only : icol_shadewall, icol_road_perv, icol_road_imperv, icol_roof, icol_sunwall
!
! !PUBLIC TYPES:
implicit none
save
!
type, public :: soilhydrology_type
integer :: h2osfcflag ! true => surface water is active (namelist)
real(r8), pointer :: num_substeps_col (:) ! col adaptive timestep counter
! NON-VIC
real(r8), pointer :: frost_table_col (:) ! col frost table depth
real(r8), pointer :: zwt_col (:) ! col water table depth
real(r8), pointer :: zwts_col (:) ! col water table depth, the shallower of the two water depths
real(r8), pointer :: zwt_perched_col (:) ! col perched water table depth
real(r8), pointer :: qcharge_col (:) ! col aquifer recharge rate (mm/s)
real(r8), pointer :: icefrac_col (:,:) ! col fraction of ice
real(r8), pointer :: h2osfc_thresh_col (:) ! col level at which h2osfc "percolates" (time constant)
real(r8), pointer :: xs_urban_col (:) ! col excess soil water above urban ponding limit
! VIC
real(r8), pointer :: hkdepth_col (:) ! col VIC decay factor (m) (time constant)
real(r8), pointer :: b_infil_col (:) ! col VIC b infiltration parameter (time constant)
real(r8), pointer :: ds_col (:) ! col VIC fracton of Dsmax where non-linear baseflow begins (time constant)
real(r8), pointer :: dsmax_col (:) ! col VIC max. velocity of baseflow (mm/day) (time constant)
real(r8), pointer :: Wsvic_col (:) ! col VIC fraction of maximum soil moisutre where non-liear base flow occurs (time constant)
real(r8), pointer :: porosity_col (:,:) ! col VIC porosity (1-bulk_density/soil_density)
real(r8), pointer :: vic_clm_fract_col (:,:,:) ! col VIC fraction of VIC layers in CLM layers
real(r8), pointer :: depth_col (:,:) ! col VIC layer depth of upper layer
real(r8), pointer :: c_param_col (:) ! col VIC baseflow exponent (Qb)
real(r8), pointer :: expt_col (:,:) ! col VIC pore-size distribution related paramter(Q12)
real(r8), pointer :: ksat_col (:,:) ! col VIC Saturated hydrologic conductivity
real(r8), pointer :: phi_s_col (:,:) ! col VIC soil moisture dissusion parameter
real(r8), pointer :: moist_col (:,:) ! col VIC soil moisture (kg/m2) for VIC soil layers
real(r8), pointer :: moist_vol_col (:,:) ! col VIC volumetric soil moisture for VIC soil layers
real(r8), pointer :: max_moist_col (:,:) ! col VIC max layer moist + ice (mm)
real(r8), pointer :: top_moist_col (:) ! col VIC soil moisture in top layers
real(r8), pointer :: top_max_moist_col (:) ! col VIC maximum soil moisture in top layers
real(r8), pointer :: top_ice_col (:) ! col VIC ice len in top layers
real(r8), pointer :: top_moist_limited_col(:) ! col VIC soil moisture in top layers, limited to no greater than top_max_moist_col
real(r8), pointer :: ice_col (:,:) ! col VIC soil ice (kg/m2) for VIC soil layers
real(r8), pointer :: qout_col (:,:) ! flux of water out of soil layer [mm H2O/s]
real(r8), pointer :: qin_col (:,:) ! flux of water into soil layer [mm H2O/s]
contains
! Public routines
procedure, public :: Init
procedure, public :: Restart
! Private routines
procedure, private :: InitAllocate
procedure, private :: InitHistory
procedure, private :: InitCold
procedure, private :: ReadNL
end type soilhydrology_type
character(len=*), parameter, private :: sourcefile = &
__FILE__
!-----------------------------------------------------------------------
contains
!------------------------------------------------------------------------
subroutine Init(this, bounds, NLFilename, waterstatebulk_inst, use_aquifer_layer)
class(soilhydrology_type) :: this
type(bounds_type), intent(in) :: bounds
character(len=*), intent(in) :: NLFilename
type(waterstatebulk_type) , intent(inout) :: waterstatebulk_inst
logical , intent(in) :: use_aquifer_layer ! whether an aquifer layer is used in this run
call this%ReadNL(NLFilename)
call this%InitAllocate(bounds)
call this%InitHistory(bounds, use_aquifer_layer)
call this%InitCold(bounds, waterstatebulk_inst, use_aquifer_layer)
end subroutine Init
!------------------------------------------------------------------------
subroutine InitAllocate(this, bounds)
!
! !DESCRIPTION:
! Initialize module data structure
!
! !USES:
use shr_infnan_mod , only : nan => shr_infnan_nan, assignment(=)
!
! !ARGUMENTS:
class(soilhydrology_type) :: this
type(bounds_type), intent(in) :: bounds
!
! !LOCAL VARIABLES:
integer :: begp, endp
integer :: begc, endc
integer :: begg, endg
!------------------------------------------------------------------------
begp = bounds%begp; endp= bounds%endp
begc = bounds%begc; endc= bounds%endc
begg = bounds%begg; endg= bounds%endg
allocate(this%num_substeps_col (begc:endc)) ; this%num_substeps_col (:) = nan
allocate(this%frost_table_col (begc:endc)) ; this%frost_table_col (:) = nan
allocate(this%zwt_col (begc:endc)) ; this%zwt_col (:) = nan
allocate(this%zwt_perched_col (begc:endc)) ; this%zwt_perched_col (:) = nan
allocate(this%zwts_col (begc:endc)) ; this%zwts_col (:) = nan
allocate(this%qcharge_col (begc:endc)) ; this%qcharge_col (:) = nan
allocate(this%icefrac_col (begc:endc,nlevgrnd)) ; this%icefrac_col (:,:) = nan
allocate(this%h2osfc_thresh_col (begc:endc)) ; this%h2osfc_thresh_col (:) = nan
allocate(this%xs_urban_col (begc:endc)) ; this%xs_urban_col (:) = nan
allocate(this%hkdepth_col (begc:endc)) ; this%hkdepth_col (:) = nan
allocate(this%b_infil_col (begc:endc)) ; this%b_infil_col (:) = nan
allocate(this%ds_col (begc:endc)) ; this%ds_col (:) = nan
allocate(this%dsmax_col (begc:endc)) ; this%dsmax_col (:) = nan
allocate(this%Wsvic_col (begc:endc)) ; this%Wsvic_col (:) = nan
allocate(this%depth_col (begc:endc,nlayert)) ; this%depth_col (:,:) = nan
allocate(this%porosity_col (begc:endc,nlayer)) ; this%porosity_col (:,:) = nan
allocate(this%vic_clm_fract_col (begc:endc,nlayer, nlevsoi)) ; this%vic_clm_fract_col (:,:,:) = nan
allocate(this%c_param_col (begc:endc)) ; this%c_param_col (:) = nan
allocate(this%expt_col (begc:endc,nlayer)) ; this%expt_col (:,:) = nan
allocate(this%ksat_col (begc:endc,nlayer)) ; this%ksat_col (:,:) = nan
allocate(this%phi_s_col (begc:endc,nlayer)) ; this%phi_s_col (:,:) = nan
allocate(this%moist_col (begc:endc,nlayert)) ; this%moist_col (:,:) = nan
allocate(this%moist_vol_col (begc:endc,nlayert)) ; this%moist_vol_col (:,:) = nan
allocate(this%max_moist_col (begc:endc,nlayer)) ; this%max_moist_col (:,:) = nan
allocate(this%top_moist_col (begc:endc)) ; this%top_moist_col (:) = nan
allocate(this%top_max_moist_col (begc:endc)) ; this%top_max_moist_col (:) = nan
allocate(this%top_ice_col (begc:endc)) ; this%top_ice_col (:) = nan
allocate(this%top_moist_limited_col(begc:endc)) ; this%top_moist_limited_col(:) = nan
allocate(this%ice_col (begc:endc,nlayert)) ; this%ice_col (:,:) = nan
allocate(this%qout_col (begc:endc,nlevsoi)) ; this%qout_col (:,:) = nan
allocate(this%qin_col (begc:endc,nlevsoi)) ; this%qin_col (:,:) = nan
end subroutine InitAllocate
!------------------------------------------------------------------------
subroutine InitHistory(this, bounds, use_aquifer_layer)
!
! !USES:
use histFileMod , only : hist_addfld1d, hist_addfld2d
!
! !ARGUMENTS:
class(soilhydrology_type) :: this
type(bounds_type), intent(in) :: bounds
logical , intent(in) :: use_aquifer_layer ! whether an aquifer layer is used in this run
!
! !LOCAL VARIABLES:
integer :: begc, endc
integer :: begg, endg
!------------------------------------------------------------------------
begc = bounds%begc; endc= bounds%endc
begg = bounds%begg; endg= bounds%endg
if (use_aquifer_layer) then
this%qcharge_col(begc:endc) = spval
call hist_addfld1d (fname='QCHARGE', units='mm/s', &
avgflag='A', long_name='aquifer recharge rate (natural vegetated and crop landunits only)', &
ptr_col=this%qcharge_col, l2g_scale_type='veg')
end if
this%num_substeps_col(begc:endc) = spval
call hist_addfld1d (fname='NSUBSTEPS', units='unitless', &
avgflag='A', long_name='number of adaptive timesteps in CLM timestep', &
ptr_col=this%num_substeps_col, l2g_scale_type='veg', &
default='inactive')
this%frost_table_col(begc:endc) = spval
call hist_addfld1d (fname='FROST_TABLE', units='m', &
avgflag='A', long_name='frost table depth (natural vegetated and crop landunits only)', &
ptr_col=this%frost_table_col, l2g_scale_type='veg', default='inactive')
this%zwt_col(begc:endc) = spval
call hist_addfld1d (fname='ZWT', units='m', &
avgflag='A', long_name='water table depth (natural vegetated and crop landunits only)', &
ptr_col=this%zwt_col, l2g_scale_type='veg')
this%zwt_perched_col(begc:endc) = spval
call hist_addfld1d (fname='ZWT_PERCH', units='m', &
avgflag='A', long_name='perched water table depth (natural vegetated and crop landunits only)', &
ptr_col=this%zwt_perched_col, l2g_scale_type='veg')
this%qout_col(begc:endc, :) = spval
call hist_addfld2d (fname="QOUT", units='mm H2O/s', type2d='levsoi', &
avgflag='A', long_name='flux of water out of soil layer', &
ptr_col=this%qout_col, default='inactive')
this%qin_col(begc:endc, :) = spval
call hist_addfld2d (fname="QIN", units='mm H2O/s', type2d='levsoi', &
avgflag='A', long_name='flux of water into soil layer', &
ptr_col=this%qin_col, default='inactive')
end subroutine InitHistory
!-----------------------------------------------------------------------
subroutine InitCold(this, bounds, waterstatebulk_inst, &
use_aquifer_layer)
!
! !USES:
!
! !ARGUMENTS:
class(soilhydrology_type) :: this
type(bounds_type) , intent(in) :: bounds
type(waterstatebulk_type) , intent(inout) :: waterstatebulk_inst
logical , intent(in) :: use_aquifer_layer ! whether an aquifer layer is used in this run
! !LOCAL VARIABLES:
integer :: c,l
!-----------------------------------------------------------------------
! needs to be initialized to spval to avoid problems when
! averaging for the accum field
do c = bounds%begc, bounds%endc
this%num_substeps_col(c) = spval
end do
!-----------------------------------------------------------------------
! Initialize frost table
!-----------------------------------------------------------------------
this%zwt_col(bounds%begc:bounds%endc) = 0._r8
do c = bounds%begc,bounds%endc
l = col%landunit(c)
if (.not. lun%lakpoi(l)) then !not lake
if (lun%urbpoi(l)) then
if (col%itype(c) == icol_road_perv) then
if (use_aquifer_layer) then
! NOTE(wjs, 2018-11-27) There is no fundamental reason why zwt should
! be initialized differently based on use_aquifer_layer, but we (Bill
! Sacks and Sean Swenson) are changing the cold start initialization of
! wa_col when use_aquifer_layer is .false., and so need to come up with
! a different cold start initialization of zwt in that case, but we
! don't want to risk messing up the use_aquifer_layer = .true. case,
! so we're keeping that as it was before.
! Note that the following hard-coded constants (on the next line)
! seem implicitly related to the initial value of wa_col
this%zwt_col(c) = (25._r8 + col%zi(c,nlevsoi)) - waterstatebulk_inst%wa_col(c)/0.2_r8 /1000._r8 ! One meter below soil column
else
this%zwt_col(c) = col%zi(c,col%nbedrock(c))
end if
else
this%zwt_col(c) = spval
end if
! initialize frost_table, zwt_perched
this%zwt_perched_col(c) = spval
this%frost_table_col(c) = spval
else
if (use_aquifer_layer) then
! NOTE(wjs, 2018-11-27) There is no fundamental reason why zwt should
! be initialized differently based on use_aquifer_layer, but we (Bill
! Sacks and Sean Swenson) are changing the cold start initialization of
! wa_col when use_aquifer_layer is .false., and so need to come up with
! a different cold start initialization of zwt in that case, but we
! don't want to risk messing up the use_aquifer_layer = .true. case,
! so we're keeping that as it was before.
! Note that the following hard-coded constants (on the next line) seem
! implicitly related to the initial value of wa_col
this%zwt_col(c) = (25._r8 + col%zi(c,nlevsoi)) - waterstatebulk_inst%wa_col(c)/0.2_r8 /1000._r8
else
this%zwt_col(c) = col%zi(c,col%nbedrock(c))
end if
! initialize frost_table, zwt_perched to bottom of soil column
this%zwt_perched_col(c) = col%zi(c,nlevsoi)
this%frost_table_col(c) = col%zi(c,nlevsoi)
end if
end if
end do
end subroutine InitCold
!------------------------------------------------------------------------
subroutine Restart(this, bounds, ncid, flag)
!
! !USES:
use ncdio_pio , only : file_desc_t, ncd_io, ncd_double
use restUtilMod
!
! !ARGUMENTS:
class(soilhydrology_type) :: this
type(bounds_type) , intent(in) :: bounds
type(file_desc_t) , intent(inout) :: ncid ! netcdf id
character(len=*) , intent(in) :: flag ! 'read' or 'write'
!
! !LOCAL VARIABLES:
logical :: readvar ! determine if variable is on initial file
!-----------------------------------------------------------------------
call restartvar(ncid=ncid, flag=flag, varname='FROST_TABLE', xtype=ncd_double, &
dim1name='column', &
long_name='frost table depth', units='m', &
interpinic_flag='interp', readvar=readvar, data=this%frost_table_col)
if (flag == 'read' .and. .not. readvar) then
this%frost_table_col(bounds%begc:bounds%endc) = col%zi(bounds%begc:bounds%endc,nlevsoi)
end if
call restartvar(ncid=ncid, flag=flag, varname='ZWT', xtype=ncd_double, &
dim1name='column', &
long_name='water table depth', units='m', &
interpinic_flag='interp', readvar=readvar, data=this%zwt_col)
call restartvar(ncid=ncid, flag=flag, varname='ZWT_PERCH', xtype=ncd_double, &
dim1name='column', &
long_name='perched water table depth', units='m', &
interpinic_flag='interp', readvar=readvar, data=this%zwt_perched_col)
if (flag == 'read' .and. .not. readvar) then
this%zwt_perched_col(bounds%begc:bounds%endc) = col%zi(bounds%begc:bounds%endc,nlevsoi)
end if
end subroutine Restart
!-----------------------------------------------------------------------
subroutine ReadNL( this, NLFilename )
!
! !DESCRIPTION:
! Read namelist for SoilHydrology
!
! !USES:
use shr_mpi_mod , only : shr_mpi_bcast
use shr_log_mod , only : errMsg => shr_log_errMsg
use spmdMod , only : masterproc, mpicom
use fileutils , only : getavu, relavu, opnfil
use clm_nlUtilsMod , only : find_nlgroup_name
use clm_varctl , only : iulog
use abortutils , only : endrun
!
! !ARGUMENTS:
class(soilhydrology_type) :: this
character(len=*), intent(IN) :: NLFilename ! Namelist filename
!
! !LOCAL VARIABLES:
integer :: ierr ! error code
integer :: unitn ! unit for namelist file
integer :: h2osfcflag=1 !If surface water is active or not
character(len=32) :: subname = 'SoilHydrology_readnl' ! subroutine name
!-----------------------------------------------------------------------
namelist / clm_soilhydrology_inparm / h2osfcflag
! preset values
h2osfcflag = 1
if ( masterproc )then
unitn = getavu()
write(iulog,*) 'Read in clm_soilhydrology_inparm namelist'
call opnfil (NLFilename, unitn, 'F')
call find_nlgroup_name(unitn, 'clm_soilhydrology_inparm', status=ierr)
if (ierr == 0) then
read(unitn, clm_soilhydrology_inparm, iostat=ierr)
if (ierr /= 0) then
call endrun(msg="ERROR reading clm_soilhydrology_inparm namelist"//errmsg(sourcefile, __LINE__))
end if
else
call endrun(msg="ERROR finding clm_soilhydrology_inparm namelist"//errmsg(sourcefile, __LINE__))
end if
call relavu( unitn )
end if
call shr_mpi_bcast(h2osfcflag, mpicom)
this%h2osfcflag = h2osfcflag
end subroutine ReadNL
end Module SoilHydrologyType