Skip to content
Draft
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions bld/CLMBuildNamelist.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1834,6 +1834,11 @@ sub process_namelist_inline_logic {
##################################
setup_logic_cropcal_streams($opts, $nl_flags, $definition, $defaults, $nl);

##################################
# namelist group: distparams_streams #
##################################
setup_logic_distparams_streams($opts, $nl_flags, $definition, $defaults, $nl);

##########################################
# namelist group: soil_moisture_streams #
##########################################
Expand Down Expand Up @@ -4600,6 +4605,25 @@ sub setup_logic_cropcal_streams {

#-------------------------------------------------------------------------------

sub setup_logic_distparams_streams {
my ($opts, $nl_flags, $definition, $defaults, $nl) = @_;

add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'use_distributed_parameters');

# Add defaults if using any crop calendar input files
my $distparams_file = $nl->get_value('stream_fldFileName_distparams') ;
my $mesh_file = $nl->get_value('stream_meshfile_distparams') ;

# User provided an input file but set mesh file to empty
if ( !&string_is_undef_or_empty($distparams_file)) {
if ( &string_is_undef_or_empty($mesh_file) ) {
$log->fatal_error("If providing a spatially distributed parameter file, you must provide stream_meshfile_distparams" );
}
}
}

#-------------------------------------------------------------------------------

sub setup_logic_soilwater_movement {
my ($opts, $nl_flags, $definition, $defaults, $nl) = @_;

Expand Down Expand Up @@ -4838,7 +4862,6 @@ sub setup_logic_atm_forcing {
}
}
}

}

#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -5388,7 +5411,7 @@ sub write_output_files {

@groups = qw(clm_inparm ndepdyn_nml popd_streams urbantv_streams light_streams
soil_moisture_streams lai_streams atm2lnd_inparm lnd2atm_inparm clm_canopyhydrology_inparm cnphenology
cropcal_streams megan_opts
cropcal_streams megan_opts distparams_streams
clm_soilhydrology_inparm dynamic_subgrid cnvegcarbonstate
finidat_consistency_checks dynpft_consistency_checks
clm_initinterp_inparm century_soilbgcdecompcascade
Expand Down
6 changes: 6 additions & 0 deletions bld/namelist_files/namelist_defaults_ctsm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2303,6 +2303,12 @@ lnd/clm2/surfdata_esmf/NEON/ctsm5.4.0/surfdata_1x1_NEON_TOOL_hist_2000_78pfts_c2
<stream_fldFileName_gdd20_season_end stream_gdd20_seasons=".true.">lnd/clm2/cropdata/calendars/processed/hdates_ggcmi_crop_calendar_phase3_v1.01_nninterp-hcru_hcru_mt13.2000-2000.20230728_165845.tweaked_latlons.nc</stream_fldFileName_gdd20_season_end>
<stream_meshfile_cropcal cropcals_rx_adapt=".true.">lnd/clm2/cropdata/calendars/processed/360x720_120830_ESMFmesh_c20210507_cdf5.tweaked_latlons.nc</stream_meshfile_cropcal>

<!-- spatially distributed parameters: default settings -->
<use_distributed_parameters>.false.</use_distributed_parameters>

<!-- spatially distributed parameters: default input files -->
<stream_fldFileName_distparams use_distributed_parameters=".true.">no_file_yet</stream_fldFileName_distparams>
<stream_meshfile_distparams use_distributed_parameters=".true.">no_file_yet</stream_meshfile_distparams>

<!-- lightning streams namelist defaults -->

Expand Down
20 changes: 20 additions & 0 deletions bld/namelist_files/namelist_definition_ctsm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2159,6 +2159,26 @@ Filename of input stream data for date (day of year) of end of gdd20 accumulatio
Filename of input stream data for crop calendar inputs
</entry>

<!-- ======================================================================================== -->
<!-- distparams_streams streams Namelist -->
<!-- ======================================================================================== -->

<!-- Distributed parameters -->
<entry id="use_distributed_parameters" type="logical" category="datasets"
group="distparams_streams" valid_values="" >
Flag to enable spatially distributed parameters
</entry>

<entry id="stream_fldfilename_distparams" type="char*512(30)" category="datasets"
input_pathname="abs" group="distparams_streams" valid_values="" >
Filename of input stream data for spatially distributed parameters
</entry>

<entry id="stream_meshfile_distparams" type="char*512" category="datasets"
input_pathname="abs" group="distparams_streams" valid_values="" >
Filename of mesh data for spatially distributed parameters
</entry>

<!-- ======================================================================================== -->
<!-- light_streams streams Namelist (when CN an CLM4_5 is active) -->
<!-- ======================================================================================== -->
Expand Down
5 changes: 3 additions & 2 deletions src/biogeophys/CanopyHydrologyMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ module CanopyHydrologyMod
use WaterStateBulkType , only : waterstatebulk_type
use WaterDiagnosticBulkType , only : waterdiagnosticbulk_type
use WaterTracerUtils , only : CalcTracerFromBulk
use ColumnType , only : col, column_type
use PatchType , only : patch, patch_type
use ColumnType , only : col, column_type
use PatchType , only : patch, patch_type

!
! !PUBLIC TYPES:
implicit none
Expand Down
9 changes: 6 additions & 3 deletions src/biogeophys/InfiltrationExcessRunoffMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ module InfiltrationExcessRunoffMod
use clm_varcon , only : spval
use SoilHydrologyType, only : soilhydrology_type
use SoilStateType , only : soilstate_type
use DistParamType , only : distparams => distributed_parameters
use SaturatedExcessRunoffMod, only : saturated_excess_runoff_type
use WaterFluxBulkType , only : waterfluxbulk_type
use WaterDiagnosticBulkType, only : waterdiagnosticbulk_type
use WaterFluxBulkType , only : waterfluxbulk_type
use WaterDiagnosticBulkType , only : waterdiagnosticbulk_type

implicit none
save
Expand Down Expand Up @@ -267,6 +268,8 @@ subroutine ComputeQinmaxHksat(bounds, num_hydrologyc, filter_hydrologyc, &
soilhydrology_inst, soilstate_inst, &
qinmax_on_unsaturated_area)
!
! USES
use ColumnType , only : col
! !DESCRIPTION:
! Compute qinmax using a parameterization based on hksat
!
Expand Down Expand Up @@ -296,7 +299,7 @@ subroutine ComputeQinmaxHksat(bounds, num_hydrologyc, filter_hydrologyc, &

do fc = 1, num_hydrologyc
c = filter_hydrologyc(fc)
qinmax_on_unsaturated_area(c) = minval(10._r8**(-params_inst%e_ice*(icefrac(c,1:3)))*hksat(c,1:3))
qinmax_on_unsaturated_area(c) = minval(10._r8**(-distparams%e_ice%param_val(col%gridcell(c))*(icefrac(c,1:3)))*hksat(c,1:3))
end do

end associate
Expand Down
37 changes: 7 additions & 30 deletions src/biogeophys/SaturatedExcessRunoffMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ module SaturatedExcessRunoffMod
use clm_varcon , only : spval,ispval
use LandunitType , only : landunit_type
use landunit_varcon , only : istcrop
use ColumnType , only : column_type
use ColumnType , only : column_type
use DistParamType , only : distparams => distributed_parameters
use SoilHydrologyType, only : soilhydrology_type
use SoilStateType, only : soilstate_type
use SoilStateType , only : soilstate_type
use WaterFluxBulkType, only : waterfluxbulk_type

implicit none
Expand Down Expand Up @@ -50,12 +51,6 @@ module SaturatedExcessRunoffMod
procedure, private, nopass :: ComputeFsatTopmodel
procedure, private, nopass :: ComputeFsatVic
end type saturated_excess_runoff_type
public :: readParams

type, private :: params_type
real(r8) :: fff ! Decay factor for fractional saturated area (1/m)
end type params_type
type(params_type), private :: params_inst

! !PRIVATE DATA MEMBERS:

Expand Down Expand Up @@ -175,26 +170,6 @@ subroutine InitCold(this, bounds)

end subroutine InitCold

!-----------------------------------------------------------------------
subroutine readParams( ncid )
!
! !USES:
use ncdio_pio, only: file_desc_t
use paramUtilMod, only: readNcdioScalar
!
! !ARGUMENTS:
implicit none
type(file_desc_t),intent(inout) :: ncid ! pio netCDF file id
!
! !LOCAL VARIABLES:
character(len=*), parameter :: subname = 'readParams_SaturatedExcessRunoff'
!--------------------------------------------------------------------

! Decay factor for fractional saturated area (1/m)
call readNcdioScalar(ncid, 'fff', subname, params_inst%fff)

end subroutine readParams

! ========================================================================
! Science routines
! ========================================================================
Expand Down Expand Up @@ -315,6 +290,8 @@ end subroutine SaturatedExcessRunoff
subroutine ComputeFsatTopmodel(bounds, num_hydrologyc, filter_hydrologyc, &
soilhydrology_inst, soilstate_inst, fsat)
!
! USES
use ColumnType , only : col
! !DESCRIPTION:
! Compute fsat using the TOPModel-based parameterization
!
Expand Down Expand Up @@ -349,9 +326,9 @@ subroutine ComputeFsatTopmodel(bounds, num_hydrologyc, filter_hydrologyc, &
c = filter_hydrologyc(fc)
if (frost_table(c) > zwt_perched(c) .and. frost_table(c) <= zwt(c)) then
! use perched water table to determine fsat (if present)
fsat(c) = wtfact(c) * exp(-0.5_r8*params_inst%fff*zwt_perched(c))
fsat(c) = wtfact(c) * exp(-0.5_r8*distparams%fff%param_val(col%gridcell(c))*zwt_perched(c))
else
fsat(c) = wtfact(c) * exp(-0.5_r8*params_inst%fff*zwt(c))
fsat(c) = wtfact(c) * exp(-0.5_r8*distparams%fff%param_val(col%gridcell(c))*zwt(c))
end if
end do

Expand Down
43 changes: 7 additions & 36 deletions src/biogeophys/SnowCoverFractionSwensonLawrence2012Mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module SnowCoverFractionSwensonLawrence2012Mod
use fileutils , only : getavu, relavu, opnfil
use clm_varcon , only : rpi
use ColumnType , only : column_type
use DistParamType , only : distparams => distributed_parameters
use glcBehaviorMod , only : glc_behavior_type
use landunit_varcon, only : istice
use paramUtilMod , only : readNcdioScalar
Expand All @@ -44,7 +45,6 @@ module SnowCoverFractionSwensonLawrence2012Mod
procedure, public :: Init

procedure, private :: ReadNamelist
procedure, private :: ReadParams
procedure, private :: CheckValidInputs
procedure, private :: SetDerivedParameters
end type snow_cover_fraction_swenson_lawrence_2012_type
Expand All @@ -66,6 +66,8 @@ subroutine UpdateSnowDepthAndFrac(this, bounds, num_c, filter_c, &
lun_itype_col, urbpoi, h2osno_total, snowmelt, int_snow, newsnow, bifall, &
snow_depth, frac_sno, frac_sno_eff)
!
! USES
use ColumnType , only : col
! !DESCRIPTION:
! Update snow depth and snow fraction using the SwensonLawrence2012 parameterization
!
Expand Down Expand Up @@ -121,7 +123,7 @@ subroutine UpdateSnowDepthAndFrac(this, bounds, num_c, filter_c, &
! fsca parameterization based on *changes* in swe
if (h2osno_total(c) == 0._r8) then
if (newsnow(c) > 0._r8) then
frac_sno(c) = tanh(this%accum_factor * newsnow(c))
frac_sno(c) = tanh(distparams%accum_factor%param_val(col%gridcell(c)) * newsnow(c))
else
! NOTE(wjs, 2019-08-07) This resetting of frac_sno to 0 when h2osno_total is 0
! may already be done elsewhere; if it isn't, it possibly *should* be done
Expand All @@ -146,7 +148,7 @@ subroutine UpdateSnowDepthAndFrac(this, bounds, num_c, filter_c, &
!
! This form is algebraically equivalent, but simpler and less prone to
! roundoff errors (see https://github.com/ESCOMP/ctsm/issues/784)
frac_sno(c) = frac_sno(c) + tanh(this%accum_factor * newsnow(c)) * (1._r8 - frac_sno(c))
frac_sno(c) = frac_sno(c) + tanh(distparams%accum_factor%param_val(col%gridcell(c)) * newsnow(c)) * (1._r8 - frac_sno(c))

end if
end if
Expand Down Expand Up @@ -291,7 +293,6 @@ subroutine Init(this, bounds, col, glc_behavior, NLFilename, params_ncid)
type(file_desc_t) , intent(inout) :: params_ncid ! pio netCDF file id for parameter file
!
! !LOCAL VARIABLES:
real(r8) :: n_melt_coef ! n_melt parameter (unitless)
real(r8) :: n_melt_glcmec ! SCA shape parameter for glc_mec columns

character(len=*), parameter :: subname = 'Init'
Expand All @@ -301,10 +302,6 @@ subroutine Init(this, bounds, col, glc_behavior, NLFilename, params_ncid)
NLFilename = NLFilename, &
n_melt_glcmec = n_melt_glcmec)

call this%ReadParams( &
params_ncid = params_ncid, &
n_melt_coef = n_melt_coef)

if (masterproc) then
call this%CheckValidInputs( &
n_melt_glcmec = n_melt_glcmec)
Expand All @@ -314,7 +311,6 @@ subroutine Init(this, bounds, col, glc_behavior, NLFilename, params_ncid)
bounds = bounds, &
col = col, &
glc_behavior = glc_behavior, &
n_melt_coef = n_melt_coef, &
n_melt_glcmec = n_melt_glcmec)

end subroutine Init
Expand Down Expand Up @@ -376,30 +372,6 @@ subroutine ReadNamelist(this, NLFilename, n_melt_glcmec)

end subroutine ReadNamelist

!-----------------------------------------------------------------------
subroutine ReadParams(this, params_ncid, n_melt_coef)
!
! !DESCRIPTION:
! Read netCDF parameters needed for the SwensonLawrence2012 method
!
! !ARGUMENTS:
class(snow_cover_fraction_swenson_lawrence_2012_type), intent(inout) :: this
type(file_desc_t) , intent(inout) :: params_ncid ! pio netCDF file id for parameter file
real(r8) , intent(out) :: n_melt_coef ! n_melt parameter (unitless)
!
! !LOCAL VARIABLES:

character(len=*), parameter :: subname = 'ReadParams'
!-----------------------------------------------------------------------

! Accumulation constant for fractional snow covered area (unitless)
call readNcdioScalar(params_ncid, 'accum_factor', subname, this%accum_factor)

! n_melt parameter (unitless)
call readNcdioScalar(params_ncid, 'n_melt_coef', subname, n_melt_coef)

end subroutine ReadParams

!-----------------------------------------------------------------------
subroutine CheckValidInputs(this, n_melt_glcmec)
!
Expand Down Expand Up @@ -430,7 +402,7 @@ subroutine CheckValidInputs(this, n_melt_glcmec)
end subroutine CheckValidInputs

!-----------------------------------------------------------------------
subroutine SetDerivedParameters(this, bounds, col, glc_behavior, n_melt_coef, n_melt_glcmec)
subroutine SetDerivedParameters(this, bounds, col, glc_behavior, n_melt_glcmec)
!
! !DESCRIPTION:
! Set parameters that are derived from other inputs
Expand All @@ -440,7 +412,6 @@ subroutine SetDerivedParameters(this, bounds, col, glc_behavior, n_melt_coef, n_
type(bounds_type) , intent(in) :: bounds
type(column_type) , intent(in) :: col
type(glc_behavior_type) , intent(in) :: glc_behavior
real(r8) , intent(in) :: n_melt_coef
real(r8) , intent(in) :: n_melt_glcmec ! SCA shape parameter for glc_mec columns
!
! !LOCAL VARIABLES:
Expand All @@ -461,7 +432,7 @@ subroutine SetDerivedParameters(this, bounds, col, glc_behavior, n_melt_coef, n_
! value of n_melt.
this%n_melt(c) = n_melt_glcmec
else
this%n_melt(c) = n_melt_coef / max(10._r8, col%topo_std(c))
this%n_melt(c) = distparams%n_melt_coef%param_val(col%gridcell(c)) / max(10._r8, col%topo_std(c))
end if
end do

Expand Down
Loading