Skip to content

Commit

Permalink
Merge pull request #6 from glemieux/cross_grid_seed-isitdisptime_fix
Browse files Browse the repository at this point in the history
Fix parameter file read bug as well as old parameter file overwrite code
  • Loading branch information
YanlanLiu authored Feb 14, 2023
2 parents e27983b + db94598 commit f9d6a42
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 18 deletions.
15 changes: 11 additions & 4 deletions biogeochem/EDPhysiologyMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1582,6 +1582,8 @@ subroutine SeedUpdate( currentSite, bc_in, bc_out)
! !USES:
use EDTypesMod, only : area
use EDTypesMod, only : homogenize_seed_pfts
use FatesInterfaceTypesMod, only : fates_dispersal_kernel_mode
use FatesInterfaceTypesMod, only : fates_dispersal_kernel_none
!use FatesInterfaceTypesMod, only : hlm_use_fixed_biogeog ! For future reduced complexity?
!
! !ARGUMENTS
Expand All @@ -1597,6 +1599,7 @@ subroutine SeedUpdate( currentSite, bc_in, bc_out)
integer :: pft
real(r8) :: store_m_to_repro ! mass sent from storage to reproduction upon death [kg/plant]
real(r8) :: site_seed_rain(maxpft) ! This is the sum of seed-rain for the site [kg/site/day]
real(r8) :: site_disp_frac(maxpft) ! Fraction of seeds to disperse out to other sites
real(r8) :: seed_in_external ! Mass of externally generated seeds [kg/m2/day]
real(r8) :: seed_stoich ! Mass ratio of nutrient per C12 in seeds [kg/kg]
real(r8) :: seed_prod ! Seed produced in this dynamics step [kg/day]
Expand All @@ -1607,8 +1610,12 @@ subroutine SeedUpdate( currentSite, bc_in, bc_out)
do el = 1, num_elements

site_seed_rain(:) = 0._r8
site_disp_frac(:) = 0._r8

EDPftvarcon_inst%seed_dispersal_fraction(:) = 0.2 ! to be specified in the parameter file or calculated using dispersal kernel
! If the dispersal kernel is not turned on, keep the dispersal fraction at zero
if (fates_dispersal_kernel_mode .ne. fates_dispersal_kernel_none) then
site_disp_frac(:) = EDPftvarcon_inst%seed_dispersal_fraction(:)
end if

element_id = element_list(el)

Expand Down Expand Up @@ -1678,7 +1685,7 @@ subroutine SeedUpdate( currentSite, bc_in, bc_out)
if(currentSite%use_this_pft(pft).eq.itrue)then
! Seed input from local sources (within site)

litt%seed_in_local(pft) = litt%seed_in_local(pft) + site_seed_rain(pft)*(1-EDPftvarcon_inst%seed_dispersal_fraction(pft))/area ![kg/m2/day]
litt%seed_in_local(pft) = litt%seed_in_local(pft) + site_seed_rain(pft)*(1-site_disp_frac(pft))/area ![kg/m2/day]
!write(fates_log(),*) 'pft, litt%seed_in_local(pft), site_seed_rain(pft): ', pft, litt%seed_in_local(pft), site_seed_rain(pft)

! If there is forced external seed rain, we calculate the input mass flux
Expand Down Expand Up @@ -1715,14 +1722,14 @@ subroutine SeedUpdate( currentSite, bc_in, bc_out)
enddo

do pft = 1,numpft
site_mass%seed_out = site_mass%seed_out + site_seed_rain(pft)*EDPftvarcon_inst%seed_dispersal_fraction(pft) ![kg/site/day]
site_mass%seed_out = site_mass%seed_out + site_seed_rain(pft)*site_disp_frac(pft) ![kg/site/day]
!write(fates_log(),*) 'pft, site_seed_rain(pft), site_mass%seed_out: ', pft, site_mass%seed_out
end do

end do

do pft = 1,numpft
bc_out%seed_out(pft) = bc_out%seed_out(pft) + site_seed_rain(pft)*EDPftvarcon_inst%seed_dispersal_fraction(pft) ![kg/site/day]
bc_out%seed_out(pft) = bc_out%seed_out(pft) + site_seed_rain(pft)*site_disp_frac(pft) ![kg/site/day]
! write(fates_log(),*) 'pft, bc_in%seed_in(pft), bc_out%seed_out(pft): ', pft, bc_in%seed_in(pft), bc_out%seed_out(pft)
end do

Expand Down
39 changes: 25 additions & 14 deletions main/EDPftvarcon.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1649,45 +1649,56 @@ subroutine FatesCheckParams(is_master)
do ipft = 1,npft


! Check that parameter ranges for the seed dispersal scale parameter make sense
! Check that the seed dispersal parameters are all set if one of them is set
!-----------------------------------------------------------------------------------
if (( EDPftvarcon_inst%seed_dispersal_param_A(ipft) < fates_check_param_set ) .and. &
(( EDPftvarcon_inst%seed_dispersal_max_dist(ipft) > fates_check_param_set ) .or. &
( EDPftvarcon_inst%seed_dispersal_param_B(ipft) > fates_check_param_set )) ) then
(( EDPftvarcon_inst%seed_dispersal_max_dist(ipft) > fates_check_param_set ) .or. &
( EDPftvarcon_inst%seed_dispersal_param_B(ipft) > fates_check_param_set ) .or. &
( EDPftvarcon_inst%seed_dispersal_fraction(ipft) > fates_check_param_set ))) then

write(fates_log(),*) 'Seed dispersal is on per fates_seed_dispersal_param_A being set'
write(fates_log(),*) 'Please also set fates_seed_dispersal_param_B and fates_seed_dispersal_max_dist'
write(fates_log(),*) 'Please provide values for all other seed_dispersal parameters'
write(fates_log(),*) 'See Bullock et al. (2017) for reasonable values'
write(fates_log(),*) 'Aborting'
call endrun(msg=errMsg(sourcefile, __LINE__))
end if

! Check that parameter ranges for the seed dispersal shape parameter make sense
!-----------------------------------------------------------------------------------
if (( EDPftvarcon_inst%seed_dispersal_param_B(ipft) < fates_check_param_set ) .and. &
(( EDPftvarcon_inst%seed_dispersal_max_dist(ipft) > fates_check_param_set ) .or. &
( EDPftvarcon_inst%seed_dispersal_param_A(ipft) > fates_check_param_set ))) then
(( EDPftvarcon_inst%seed_dispersal_max_dist(ipft) > fates_check_param_set ) .or. &
( EDPftvarcon_inst%seed_dispersal_param_A(ipft) > fates_check_param_set ) .or. &
( EDPftvarcon_inst%seed_dispersal_fraction(ipft) > fates_check_param_set ))) then

write(fates_log(),*) 'Seed dispersal is on per fates_seed_dispersal_param_B being set'
write(fates_log(),*) 'Please also set fates_seed_dispersal_param_A and fates_seed_dispersal_max_dist'
write(fates_log(),*) 'Please provide values for all other seed_dispersal parameters'
write(fates_log(),*) 'See Bullock et al. (2017) for reasonable values'
write(fates_log(),*) 'Aborting'
call endrun(msg=errMsg(sourcefile, __LINE__))
end if

! Check that parameter ranges for the seed dispersal shape parameter make sense
!-----------------------------------------------------------------------------------
if (( EDPftvarcon_inst%seed_dispersal_max_dist(ipft) < fates_check_param_set ) .and. &
(( EDPftvarcon_inst%seed_dispersal_param_B(ipft) > fates_check_param_set ) .or. &
( EDPftvarcon_inst%seed_dispersal_param_A(ipft) > fates_check_param_set ))) then
(( EDPftvarcon_inst%seed_dispersal_param_B(ipft) > fates_check_param_set ) .or. &
( EDPftvarcon_inst%seed_dispersal_param_A(ipft) > fates_check_param_set ) .or. &
( EDPftvarcon_inst%seed_dispersal_fraction(ipft) > fates_check_param_set ))) then

write(fates_log(),*) 'Seed dispersal is on per seed_dispersal_max_dist being set'
write(fates_log(),*) 'Please also set fates_seed_dispersal_param_A and fates_seed_dispersal_param_B'
write(fates_log(),*) 'Please provide values for all other seed_dispersal parameters'
write(fates_log(),*) 'See Bullock et al. (2017) for reasonable values'
write(fates_log(),*) 'Aborting'
call endrun(msg=errMsg(sourcefile, __LINE__))
end if

if (( EDPftvarcon_inst%seed_dispersal_fraction(ipft) < fates_check_param_set ) .and. &
(( EDPftvarcon_inst%seed_dispersal_param_B(ipft) > fates_check_param_set ) .or. &
( EDPftvarcon_inst%seed_dispersal_param_A(ipft) > fates_check_param_set ) .or. &
( EDPftvarcon_inst%seed_dispersal_max_dist(ipft) > fates_check_param_set ))) then

write(fates_log(),*) 'Seed dispersal is on per seed_dispersal_fraction being set'
write(fates_log(),*) 'Please provide values for all other seed_dispersal parameters'
write(fates_log(),*) 'See Bullock et al. (2017) for reasonable values'
write(fates_log(),*) 'Aborting'
call endrun(msg=errMsg(sourcefile, __LINE__))
end if

! Check that parameter ranges for the seed dispersal fraction make sense
!-----------------------------------------------------------------------------------
if (( EDPftvarcon_inst%seed_dispersal_fraction(ipft) < fates_check_param_set ) .and. &
Expand Down
7 changes: 7 additions & 0 deletions main/FatesDispersalMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ logical function IsItDispersalTime(setdispersedflag)
! to pass dispersed seeds to fates. Set dispersed flag to false. Given that this must
! happen after WrapSeedGlobal, but can be threaded this takes place at the top of the
! dynamics_driv call.

use FatesInterfaceTypesMod, only : fates_dispersal_kernel_mode
use FatesInterfaceTypesMod, only : fates_dispersal_kernel_none

! Arguments
logical, optional :: setdispersedflag ! Has the global dispersal been completed?
Expand All @@ -215,6 +218,10 @@ logical function IsItDispersalTime(setdispersedflag)

! The default return value is false
IsItDispersalTime = .false.

! Check if seed dispersal mode is 'turned on' by checking the parameter values
! If it is off, return false by default
if (fates_dispersal_kernel_mode .eq. fates_dispersal_kernel_none) return

! Check if set dispersal flag is provided. This should be provided during a check
! when the flag should be set to true after the global dispersal
Expand Down

0 comments on commit f9d6a42

Please sign in to comment.