Skip to content

Commit

Permalink
move seed regen model switch from EDParamsMod to FatesInterfaceTypesMod
Browse files Browse the repository at this point in the history
  • Loading branch information
glemieux committed Dec 11, 2024
1 parent 8e58d4d commit c89b770
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 78 deletions.
18 changes: 9 additions & 9 deletions biogeochem/EDPatchDynamicsMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module EDPatchDynamicsMod
use EDTypesMod , only : elem_diag_type
use EDTypesMod , only : min_patch_area
use EDTypesMod , only : min_patch_area_forced
use EDParamsMod , only : regeneration_model
use FatesInterfaceTypesMod, only : hlm_regeneration_model
use FatesInterfaceTypesMod, only : numpft
use FatesConstantsMod , only : dtype_ifall
use FatesConstantsMod , only : dtype_ilog
Expand Down Expand Up @@ -697,7 +697,7 @@ subroutine spawn_patches( currentSite, bc_in)

call newPatch%Create(age, site_areadis, i_landusechange_receiverpatchlabel, i_nocomp_pft, &
num_swb, numpft, currentSite%nlevsoil, hlm_current_tod, &
regeneration_model)
hlm_regeneration_model)

! Initialize the litter pools to zero, these
! pools will be populated by looping over the existing patches
Expand Down Expand Up @@ -1410,7 +1410,7 @@ subroutine spawn_patches( currentSite, bc_in)

call buffer_patch%Create(0._r8, 0._r8, i_land_use_label, 0, &
num_swb, numpft, currentSite%nlevsoil, hlm_current_tod, &
regeneration_model)
hlm_regeneration_model)

! Initialize the litter pools to zero
do el=1,num_elements
Expand Down Expand Up @@ -1598,7 +1598,7 @@ subroutine spawn_patches( currentSite, bc_in)
if ( .not. buffer_patch_in_linked_list) then
if (buffer_patch%area .lt. rsnbl_math_prec) then
! here we need to deallocate the buffer patch so that we don't get a memory leak.
call buffer_patch%FreeMemory(regeneration_model, numpft)
call buffer_patch%FreeMemory(hlm_regeneration_model, numpft)
deallocate(buffer_patch, stat=istat, errmsg=smsg)
if (istat/=0) then
write(fates_log(),*) 'dealloc: fail on deallocate(dp):'//trim(smsg)
Expand All @@ -1615,7 +1615,7 @@ subroutine spawn_patches( currentSite, bc_in)
end if
else
! buffer patch was never even used. deallocate.
call buffer_patch%FreeMemory(regeneration_model, numpft)
call buffer_patch%FreeMemory(hlm_regeneration_model, numpft)
deallocate(buffer_patch, stat=istat, errmsg=smsg)
if (istat/=0) then
write(fates_log(),*) 'dealloc: fail on deallocate(dp):'//trim(smsg)
Expand Down Expand Up @@ -1707,7 +1707,7 @@ subroutine split_patch(currentSite, currentPatch, new_patch, fraction_to_keep, a
call new_patch%Create(0._r8, temp_area, &
currentPatch%land_use_label, currentPatch%nocomp_pft_label, &
num_swb, numpft, currentSite%nlevsoil, hlm_current_tod, &
regeneration_model)
hlm_regeneration_model)

! Initialize the litter pools to zero, these
! pools will be populated shortly
Expand Down Expand Up @@ -3285,7 +3285,7 @@ subroutine fuse_2_patches(csite, dp, rp)
call rp%tveg24%FuseRMean(dp%tveg24,rp%area*inv_sum_area)
call rp%tveg_lpa%FuseRMean(dp%tveg_lpa,rp%area*inv_sum_area)

if ( regeneration_model == TRS_regeneration ) then
if ( hlm_regeneration_model == TRS_regeneration ) then
call rp%seedling_layer_par24%FuseRMean(dp%seedling_layer_par24,rp%area*inv_sum_area)
call rp%sdlng_mort_par%FuseRMean(dp%sdlng_mort_par,rp%area*inv_sum_area)
call rp%sdlng2sap_par%FuseRMean(dp%sdlng2sap_par,rp%area*inv_sum_area)
Expand Down Expand Up @@ -3378,7 +3378,7 @@ subroutine fuse_2_patches(csite, dp, rp)
end if

! We have no need for the dp pointer anymore, we have passed on it's legacy
call dp%FreeMemory(regeneration_model, numpft)
call dp%FreeMemory(hlm_regeneration_model, numpft)
deallocate(dp, stat=istat, errmsg=smsg)
if (istat/=0) then
write(fates_log(),*) 'dealloc006: fail on deallocate(dp):'//trim(smsg)
Expand Down Expand Up @@ -3927,7 +3927,7 @@ subroutine CopyPatchMeansTimers(dp, rp)
call rp%tveg_lpa%CopyFromDonor(dp%tveg_lpa)
call rp%tveg_longterm%CopyFromDonor(dp%tveg_longterm)

if ( regeneration_model == TRS_regeneration ) then
if ( hlm_regeneration_model == TRS_regeneration ) then
call rp%seedling_layer_par24%CopyFromDonor(dp%seedling_layer_par24)
call rp%sdlng_mort_par%CopyFromDonor(dp%sdlng_mort_par)
call rp%sdlng2sap_par%CopyFromDonor(dp%sdlng2sap_par)
Expand Down
28 changes: 14 additions & 14 deletions biogeochem/EDPhysiologyMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ module EDPhysiologyMod
use EDParamsMod , only : q10_mr
use EDParamsMod , only : q10_froz
use EDParamsMod , only : logging_export_frac
use EDParamsMod , only : regeneration_model
use EDParamsMod , only : sdlng_mort_par_timescale
use FatesPlantHydraulicsMod , only : AccumulateMortalityWaterStorage
use FatesConstantsMod , only : itrue,ifalse
Expand Down Expand Up @@ -144,7 +143,8 @@ module EDPhysiologyMod
use FatesParameterDerivedMod, only : param_derived
use FatesPlantHydraulicsMod, only : InitHydrCohort
use PRTInitParamsFatesMod, only : NewRecruitTotalStoichiometry
use FatesInterfaceTypesMod , only : hlm_use_luh
use FatesInterfaceTypesMod, only : hlm_use_luh
use FatesInterfaceTypesMod, only : hlm_regeneration_model

implicit none
private
Expand Down Expand Up @@ -2161,7 +2161,7 @@ subroutine SeedUpdate( currentSite )
litt%seed_in_local(pft) = litt%seed_in_local(pft) + site_seed_rain(pft)*(1.0_r8-site_disp_frac(pft))/area ![kg/m2/day]

! If we are using the Tree Recruitment Scheme (TRS) with or w/o seedling dynamics
if ( any(regeneration_model == [TRS_regeneration, TRS_no_seedling_dyn]) .and. &
if ( any(hlm_regeneration_model == [TRS_regeneration, TRS_no_seedling_dyn]) .and. &
prt_params%allom_dbh_maxheight(pft) > min_max_dbh_for_trees) then

! Send a fraction of reproductive carbon to litter to account for
Expand Down Expand Up @@ -2219,7 +2219,7 @@ subroutine SeedDecay( litt , currentPatch, bc_in )
!
! !DESCRIPTION:
! 1. Flux from seed pool into leaf litter pool
! 2. If the TRS with seedling dynamics is on (regeneration_model = 3)
! 2. If the TRS with seedling dynamics is on (hlm_regeneration_model = 3)
! then we calculate seedling mortality here (i.e. flux from seedling pool
! (into leaf litter pool)
!
Expand Down Expand Up @@ -2253,7 +2253,7 @@ subroutine SeedDecay( litt , currentPatch, bc_in )

! If the TRS is switched off or the pft can't get big enough to be considered a tree
! then use FATES default regeneration.
if ( regeneration_model == default_regeneration .or. &
if ( hlm_regeneration_model == default_regeneration .or. &
prt_params%allom_dbh_maxheight(pft) < min_max_dbh_for_trees ) then

! Default seed decay (TRS is off)
Expand All @@ -2265,7 +2265,7 @@ subroutine SeedDecay( litt , currentPatch, bc_in )
! If the TRS is switched on and the pft is a tree then add non-seed reproductive biomass
! to the seed decay flux. This was added to litt%seed_decay in the previously called SeedIn
! subroutine
if ( any(regeneration_model == [TRS_regeneration, TRS_no_seedling_dyn]) .and. &
if ( any(hlm_regeneration_model == [TRS_regeneration, TRS_no_seedling_dyn]) .and. &
prt_params%allom_dbh_maxheight(pft) > min_max_dbh_for_trees ) then

litt%seed_decay(pft) = litt%seed_decay(pft) + &! From non-seed reproductive biomass (added in
Expand All @@ -2275,9 +2275,9 @@ subroutine SeedDecay( litt , currentPatch, bc_in )
end if


! If the TRS is switched on with seedling dynamics (regeneration_model = 2)
! If the TRS is switched on with seedling dynamics (hlm_regeneration_model = 2)
! then calculate seedling mortality.
if_trs_germ_decay: if ( regeneration_model == TRS_regeneration .and. &
if_trs_germ_decay: if ( hlm_regeneration_model == TRS_regeneration .and. &
prt_params%allom_dbh_maxheight(pft) > min_max_dbh_for_trees ) then

!----------------------------------------------------------------------
Expand Down Expand Up @@ -2383,16 +2383,16 @@ subroutine SeedGermination( litt, cold_stat, drought_stat, bc_in, currentPatch )

! If the TRS's seedling dynamics is switched off, then we use FATES's default approach
! to germination
if_tfs_or_def: if ( regeneration_model == default_regeneration .or. &
regeneration_model == TRS_no_seedling_dyn .or. &
if_tfs_or_def: if ( hlm_regeneration_model == default_regeneration .or. &
hlm_regeneration_model == TRS_no_seedling_dyn .or. &
prt_params%allom_dbh_maxheight(pft) < min_max_dbh_for_trees ) then

litt%seed_germ_in(pft) = min(litt%seed(pft) * EDPftvarcon_inst%germination_rate(pft), &
max_germination)*years_per_day

! If TRS seedling dynamics is switched on we calculate seedling emergence (i.e. germination)
! as a pft-specific function of understory light and soil moisture.
else if ( regeneration_model == TRS_regeneration .and. &
else if ( hlm_regeneration_model == TRS_regeneration .and. &
prt_params%allom_dbh_maxheight(pft) > min_max_dbh_for_trees ) then

! Step 1. Calculate how germination rate is modified by understory light
Expand Down Expand Up @@ -2638,15 +2638,15 @@ subroutine recruitment(currentSite, currentPatch, bc_in)

! If TRS seedling dynamics is switched off then the available mass to make new recruits
! is everything in the seed_germ pool.
if (regeneration_model == default_regeneration .or. &
regeneration_model == TRS_no_seedling_dyn .or. &
if (hlm_regeneration_model == default_regeneration .or. &
hlm_regeneration_model == TRS_no_seedling_dyn .or. &
prt_params%allom_dbh_maxheight(ft) < min_max_dbh_for_trees) then

mass_avail = currentPatch%area * currentPatch%litter(el)%seed_germ(ft)

! If TRS seedling dynamics is on then calculate the available mass to make new recruits
! as a pft-specific function of light and soil moisture in the seedling layer.
else if (regeneration_model == TRS_regeneration .and. &
else if (hlm_regeneration_model == TRS_regeneration .and. &
prt_params%allom_dbh_maxheight(ft) > min_max_dbh_for_trees) then

sdlng2sap_par = currentPatch%sdlng2sap_par%GetMean()* &
Expand Down
6 changes: 3 additions & 3 deletions main/EDInitMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ module EDInitMod
use FatesConstantsMod , only : nearzero, area_error_4, area_error_3
use FatesGlobals , only : endrun => fates_endrun
use EDParamsMod , only : nclmax
use EDParamsMod , only : regeneration_model
use FatesGlobals , only : fates_log
use FatesInterfaceTypesMod , only : hlm_is_restart
use FatesInterfaceTypesMod , only : hlm_current_tod
use FatesInterfaceTypesMod , only : hlm_regeneration_model
use EDPftvarcon , only : EDPftvarcon_inst
use PRTParametersMod , only : prt_params
use EDCohortDynamicsMod , only : create_cohort, fuse_cohorts, sort_cohorts
Expand Down Expand Up @@ -782,7 +782,7 @@ subroutine init_patches( nsites, sites, bc_in)

call newp%Create(age, newparea, nocomp_bareground_land, nocomp_bareground, &
num_swb, numpft, sites(s)%nlevsoil, hlm_current_tod, &
regeneration_model)
hlm_regeneration_model)

! set pointers for first patch (or only patch, if nocomp is false)
newp%patchno = 1
Expand Down Expand Up @@ -861,7 +861,7 @@ subroutine init_patches( nsites, sites, bc_in)

call newp%Create(age, newparea, i_lu_state, nocomp_pft, &
num_swb, numpft, sites(s)%nlevsoil, hlm_current_tod, &
regeneration_model)
hlm_regeneration_model)

if (is_first_patch) then !is this the first patch?
! set pointers for first patch (or only patch, if nocomp is false)
Expand Down
17 changes: 1 addition & 16 deletions main/EDParamsMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,7 @@ module EDParamsMod
real(r8),protected, public :: ED_val_cohort_age_fusion_tol ! minimum fraction in differece in cohort age between cohorts
real(r8),protected, public :: ED_val_patch_fusion_tol ! minimum fraction in difference in profiles between patches
real(r8),protected, public :: ED_val_canopy_closure_thresh ! site-level canopy closure point where trees take on forest (narrow) versus savannah (wide) crown allometry
integer,protected, public :: regeneration_model ! Switch for choosing between regeneration models:
! (1) for Fates default
! (2) for the Tree Recruitment Scheme (Hanbury-Brown et al., 2022)
! (3) for the Tree Recruitment Scheme without seedling dynamics



logical,protected, public :: active_crown_fire ! flag, 1=active crown fire 0=no active crown fire
character(len=param_string_length),parameter :: fates_name_active_crown_fire = "fates_fire_active_crown_fire"

Expand Down Expand Up @@ -150,7 +145,6 @@ module EDParamsMod
character(len=param_string_length),parameter,public :: ED_name_cohort_age_fusion_tol = "fates_cohort_age_fusion_tol"
character(len=param_string_length),parameter,public :: ED_name_patch_fusion_tol= "fates_patch_fusion_tol"
character(len=param_string_length),parameter,public :: ED_name_canopy_closure_thresh= "fates_canopy_closure_thresh"
character(len=param_string_length),parameter,public :: ED_name_regeneration_model= "fates_regeneration_model"

character(len=param_string_length),parameter,public :: name_theta_cj_c3 = "fates_leaf_theta_cj_c3"
character(len=param_string_length),parameter,public :: name_theta_cj_c4 = "fates_leaf_theta_cj_c4"
Expand Down Expand Up @@ -303,7 +297,6 @@ subroutine FatesParamsInit()
ED_val_cohort_age_fusion_tol = nan
ED_val_patch_fusion_tol = nan
ED_val_canopy_closure_thresh = nan
regeneration_model = -9
max_cohort_per_patch = -9
hydr_kmax_rsurf1 = nan
hydr_kmax_rsurf2 = nan
Expand Down Expand Up @@ -440,9 +433,6 @@ subroutine FatesRegisterParams(fates_params)
call fates_params%RegisterParameter(name=ED_name_canopy_closure_thresh, dimension_shape=dimension_shape_scalar, &
dimension_names=dim_names_scalar)

call fates_params%RegisterParameter(name=ED_name_regeneration_model, dimension_shape=dimension_shape_scalar, &
dimension_names=dim_names_scalar)

call fates_params%RegisterParameter(name=maxcohort_name, dimension_shape=dimension_shape_scalar, &
dimension_names=dim_names_scalar)

Expand Down Expand Up @@ -638,10 +628,6 @@ subroutine FatesReceiveParams(fates_params)
call fates_params%RetrieveParameter(name=ED_name_canopy_closure_thresh, &
data=ED_val_canopy_closure_thresh)

call fates_params%RetrieveParameter(name=ED_name_regeneration_model, &
data=tmpreal)
regeneration_model = nint(tmpreal)

call fates_params%RetrieveParameter(name=maxcohort_name, &
data=tmpreal)
max_cohort_per_patch = nint(tmpreal)
Expand Down Expand Up @@ -807,7 +793,6 @@ subroutine FatesReportParams(is_master)
write(fates_log(),fmt0) 'ED_val_cohort_age_fusion_tol = ',ED_val_cohort_age_fusion_tol
write(fates_log(),fmt0) 'ED_val_patch_fusion_tol = ',ED_val_patch_fusion_tol
write(fates_log(),fmt0) 'ED_val_canopy_closure_thresh = ',ED_val_canopy_closure_thresh
write(fates_log(),fmt0) 'regeneration_model = ',regeneration_model
write(fates_log(),fmt0) 'hydro_kmax_rsurf1 = ',hydr_kmax_rsurf1
write(fates_log(),fmt0) 'hydro_kmax_rsurf2 = ',hydr_kmax_rsurf2
write(fates_log(),fmt0) 'hydro_psi0 = ',hydr_psi0
Expand Down
11 changes: 0 additions & 11 deletions main/EDPftvarcon.F90
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ module EDPftvarcon
use FatesConstantsMod , only : default_regeneration
use FatesConstantsMod , only : TRS_regeneration
use FatesConstantsMod , only : TRS_no_seedling_dyn
use EDParamsMod , only : regeneration_model

! CIME Globals
use shr_log_mod , only : errMsg => shr_log_errMsg
Expand Down Expand Up @@ -1857,16 +1856,6 @@ subroutine FatesCheckParams(is_master)

if(.not.is_master) return

if(.not.any(regeneration_model == [default_regeneration, &
TRS_regeneration, &
TRS_no_seedling_dyn] )) then
write(fates_log(),*) 'The regeneration model must be set to a known model type'
write(fates_log(),*) 'the default is 1, and the Hanbury-Brown models are 2 and 3'
write(fates_log(),*) 'You specified fates_regeneration_model = ',regeneration_model
write(fates_log(),*) 'Aborting'
call endrun(msg=errMsg(sourcefile, __LINE__))
end if

select case (hlm_parteh_mode)
case (prt_cnp_flex_allom_hyp)

Expand Down
13 changes: 12 additions & 1 deletion main/FatesInterfaceMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ module FatesInterfaceMod
use EDParamsMod , only : maxpatches_by_landuse
use EDParamsMod , only : max_cohort_per_patch
use FatesRadiationMemMod , only : num_swb,ivis,inir
use EDParamsMod , only : regeneration_model
use EDParamsMod , only : nclmax
use EDParamsMod , only : nlevleaf
use EDParamsMod , only : maxpft
Expand Down Expand Up @@ -1482,6 +1481,7 @@ subroutine set_fates_ctrlparms(tag,ival,rval,cval)
hlm_maintresp_leaf_model = unset_int
hlm_mort_cstarvation_model = unset_int
hlm_radiation_model = unset_int
hlm_regeneration_model = unset_int
hlm_use_logging = unset_int
hlm_use_ed_st3 = unset_int
hlm_use_ed_prescribed_phys = unset_int
Expand Down Expand Up @@ -1806,6 +1806,11 @@ subroutine set_fates_ctrlparms(tag,ival,rval,cval)
call endrun(msg=errMsg(sourcefile, __LINE__))
end if

if(hlm_regeneration_model .eq. unset_int) then
write(fates_log(), *) 'seed regeneration model is unset: hlm_regeneration_model exiting'
call endrun(msg=errMsg(sourcefile, __LINE__))
end if

if(hlm_use_sp.eq.itrue.and.hlm_use_nocomp.eq.ifalse)then
write(fates_log(), *) 'SP cannot be on if nocomp mode is off. Exiting. '
call endrun(msg=errMsg(sourcefile, __LINE__))
Expand Down Expand Up @@ -2057,6 +2062,12 @@ subroutine set_fates_ctrlparms(tag,ival,rval,cval)
write(fates_log(),*) 'Transfering hlm_radiation_model ',ival,' to FATES'
end if

case('regeneration_model')
hlm_regeneration_model = ival
if (fates_global_verbose()) then
write(fates_log(),*) 'Transfering hlm_regeneration_model ',ival,' to FATES'
end if

case('use_logging')
hlm_use_logging = ival
if (fates_global_verbose()) then
Expand Down
Loading

0 comments on commit c89b770

Please sign in to comment.