Skip to content

Commit

Permalink
Merge pull request #1300 from glemieux/parameter-switch-migration
Browse files Browse the repository at this point in the history
Migrate parameter file switches that are moving to HLM namelist
  • Loading branch information
glemieux authored Feb 24, 2025
2 parents 655d784 + 3b4d20c commit a91cc42
Show file tree
Hide file tree
Showing 20 changed files with 2,195 additions and 296 deletions.
8 changes: 4 additions & 4 deletions biogeochem/EDCanopyStructureMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ module EDCanopyStructureMod
use FatesCohortMod, only : fates_cohort_type
use EDParamsMod , only : nclmax
use EDParamsMod , only : nlevleaf
use EDParamsMod , only : radiation_model
use EDtypesMod , only : AREA
use EDLoggingMortalityMod , only : UpdateHarvestC
use FatesGlobals , only : endrun => fates_endrun
Expand Down Expand Up @@ -1314,10 +1313,11 @@ subroutine canopy_summarization( nsites, sites, bc_in )
! ---------------------------------------------------------------------------------

use FatesInterfaceTypesMod , only : hlm_use_cohort_age_tracking
use FatesInterfaceTypesMod , only : hlm_radiation_model
use FatesSizeAgeTypeIndicesMod, only : sizetype_class_index
use FatesSizeAgeTypeIndicesMod, only : coagetype_class_index
use EDtypesMod , only : area
use FatesConstantsMod , only : itrue
use EDtypesMod , only : area
use FatesConstantsMod , only : itrue

! !ARGUMENTS
integer , intent(in) :: nsites
Expand Down Expand Up @@ -1451,7 +1451,7 @@ subroutine canopy_summarization( nsites, sites, bc_in )

call leaf_area_profile(sites(s))

if(radiation_model.eq.twostr_solver) then
if(hlm_radiation_model.eq.twostr_solver) then
call FatesConstructRadElements(sites(s),bc_in(s)%fcansno_pa,bc_in(s)%coszen_pa)
end if

Expand Down
6 changes: 3 additions & 3 deletions biogeochem/EDMortalityFunctionsMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module EDMortalityFunctionsMod
use FatesCohortMod , only : fates_cohort_type
use EDTypesMod , only : ed_site_type
use EDParamsMod, only : maxpft
use EDParamsMod , only : mort_cstarvation_model
use FatesConstantsMod , only : itrue,ifalse
use FatesConstantsMod , only : cstarvation_model_lin
use FatesConstantsMod , only : cstarvation_model_exp
Expand Down Expand Up @@ -68,6 +67,7 @@ subroutine mortality_rates( cohort_in,bc_in, btran_ft, mean_temp, &
use FatesConstantsMod, only : fates_check_param_set
use DamageMainMod, only : GetDamageMortality
use EDParamsmod, only : soil_tfrz_thresh
use FatesInterfaceTypesMod, only : hlm_mort_cstarvation_model

type (fates_cohort_type), intent(in) :: cohort_in
type (bc_in_type), intent(in) :: bc_in
Expand Down Expand Up @@ -204,7 +204,7 @@ subroutine mortality_rates( cohort_in,bc_in, btran_ft, mean_temp, &
call storage_fraction_of_target(target_leaf_c, store_c, frac)

! Select the carbon starvation mortality model (linear or exponential)s.
select case (mort_cstarvation_model)
select case (hlm_mort_cstarvation_model)
case (cstarvation_model_lin)
! Linear model. Carbon starvation mortality will be zero when fraction of
! storage is greater than or equal to mort_upthresh_cstarvation, and will
Expand All @@ -223,7 +223,7 @@ subroutine mortality_rates( cohort_in,bc_in, btran_ft, mean_temp, &

case default
write(fates_log(),*) &
'Invalid carbon starvation model (',mort_cstarvation_model,').'
'Invalid carbon starvation model (',hlm_mort_cstarvation_model,').'
call endrun(msg=errMsg(sourcefile, __LINE__))
end select

Expand Down
18 changes: 9 additions & 9 deletions biogeochem/EDPatchDynamicsMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,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 @@ -682,7 +682,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 @@ -1371,7 +1371,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 @@ -1559,7 +1559,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 @@ -1576,7 +1576,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 @@ -1664,7 +1664,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 @@ -3188,7 +3188,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 @@ -3259,7 +3259,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 @@ -3810,7 +3810,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 @@ -98,7 +98,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 @@ -143,7 +142,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 @@ -2157,7 +2157,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 @@ -2215,7 +2215,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 @@ -2249,7 +2249,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 @@ -2261,7 +2261,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 @@ -2271,9 +2271,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 @@ -2379,16 +2379,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 @@ -2634,15 +2634,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
18 changes: 9 additions & 9 deletions biogeophys/FatesPlantHydraulicsMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ module FatesPlantHydraulicsMod
use EDParamsMod , only : hydr_psi0
use EDParamsMod , only : hydr_psicap
use EDParamsMod , only : hydr_htftype_node
use EDParamsMod , only : hydr_solver

use EDTypesMod , only : ed_site_type
use FatesPatchMod , only : fates_patch_type
Expand All @@ -64,6 +63,7 @@ module FatesPlantHydraulicsMod
use FatesInterfaceTypesMod , only : hlm_ipedof
use FatesInterfaceTypesMod , only : numpft
use FatesInterfaceTypesMod , only : nlevsclass
use FatesInterfaceTypesMod , only : hlm_hydr_solver

use FatesAllometryMod, only : bleaf
use FatesAllometryMod, only : bsap_allom
Expand Down Expand Up @@ -1419,7 +1419,7 @@ subroutine InitHydrSites(sites,bc_in)
case(rhizlayer_aggmeth_none)

csite_hydr%nlevrhiz = bc_in(s)%nlevsoil
call sites(s)%si_hydr%InitHydrSite(numpft,nlevsclass,hydr_solver,bc_in(s)%nlevsoil)
call sites(s)%si_hydr%InitHydrSite(numpft,nlevsclass,hlm_hydr_solver,bc_in(s)%nlevsoil)

do j=1,csite_hydr%nlevrhiz
csite_hydr%map_r2s(j,1) = j
Expand All @@ -1431,7 +1431,7 @@ subroutine InitHydrSites(sites,bc_in)
case(rhizlayer_aggmeth_combine12)

csite_hydr%nlevrhiz = max(1,bc_in(s)%nlevsoil-1)
call sites(s)%si_hydr%InitHydrSite(numpft,nlevsclass,hydr_solver,bc_in(s)%nlevsoil)
call sites(s)%si_hydr%InitHydrSite(numpft,nlevsclass,hlm_hydr_solver,bc_in(s)%nlevsoil)

csite_hydr%map_r2s(1,1) = 1
j_bc = min(2,bc_in(s)%nlevsoil) ! this protects 1 soil layer
Expand All @@ -1449,7 +1449,7 @@ subroutine InitHydrSites(sites,bc_in)
case(rhizlayer_aggmeth_balN)

csite_hydr%nlevrhiz = min(aggN,bc_in(s)%nlevsoil)
call sites(s)%si_hydr%InitHydrSite(numpft,nlevsclass,hydr_solver,bc_in(s)%nlevsoil)
call sites(s)%si_hydr%InitHydrSite(numpft,nlevsclass,hlm_hydr_solver,bc_in(s)%nlevsoil)

ntoagg = int(ceiling(real(bc_in(s)%nlevsoil)/real(csite_hydr%nlevrhiz)-nearzero))

Expand Down Expand Up @@ -2583,21 +2583,21 @@ subroutine hydraulics_bc ( nsites, sites, bc_in, bc_out, dtime)
! from leaf to the current soil layer. This does NOT
! update cohort%th_*

if(hydr_solver == hydr_solver_2DNewton) then
if(hlm_hydr_solver == hydr_solver_2DNewton) then

call MatSolve2D(csite_hydr,ccohort,ccohort_hydr, &
dtime,qflx_tran_veg_indiv, &
sapflow,rootuptake(1:nlevrhiz),wb_err_plant,dwat_plant, &
dth_layershell_col)

elseif(hydr_solver == hydr_solver_2DPicard) then
elseif(hlm_hydr_solver == hydr_solver_2DPicard) then

call PicardSolve2D(csite_hydr,ccohort,ccohort_hydr, &
dtime,qflx_tran_veg_indiv, &
sapflow,rootuptake(1:nlevrhiz),wb_err_plant,dwat_plant, &
dth_layershell_col,csite_hydr%num_nodes)

elseif(hydr_solver == hydr_solver_1DTaylor ) then
elseif(hlm_hydr_solver == hydr_solver_1DTaylor ) then

! ---------------------------------------------------------------------------------
! Approach: do nlevsoi_hyd sequential solutions to Richards' equation,
Expand Down Expand Up @@ -4938,7 +4938,7 @@ subroutine MatSolve2D(csite_hydr,cohort,cohort_hydr, &


! This NaN's the scratch arrays
call csite_hydr%FlushSiteScratch(hydr_solver)
call csite_hydr%FlushSiteScratch(hlm_hydr_solver)

! This is the maximum number of iterations needed for this cohort
! (each soil layer has a different number, this saves the max)
Expand Down Expand Up @@ -5714,7 +5714,7 @@ subroutine PicardSolve2D(csite_hydr,cohort,cohort_hydr, &
ft => cohort%pft)

! This NaN's the scratch arrays
call csite_hydr%FlushSiteScratch(hydr_solver)
call csite_hydr%FlushSiteScratch(hlm_hydr_solver)

! This is the maximum number of iterations needed for this cohort
! (each soil layer has a different number, this saves the max)
Expand Down
Loading

0 comments on commit a91cc42

Please sign in to comment.