Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle case where LAI+SAI exceeds array by clipping instead of crashing #1269

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion biogeochem/EDCanopyStructureMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -2245,7 +2245,7 @@ subroutine UpdateCohortLAI(currentCohort, canopy_layer_tlai, total_canopy_area)
! Update LAI and related variables for a given cohort

! Uses
use EDParamsMod, only : dlower_vai
use EDParamsMod, only : dlower_vai, dinc_vai

! Arguments
type(fates_cohort_type),intent(inout), target :: currentCohort
Expand All @@ -2272,6 +2272,12 @@ subroutine UpdateCohortLAI(currentCohort, canopy_layer_tlai, total_canopy_area)
currentCohort%vcmax25top,4)
end if

! cap leaf allometries that are larger than the allowable array space.
if( (currentCohort%treelai + currentCohort%treesai) > (sum(dinc_vai)) )then
currentCohort%treelai = sum(dinc_vai) * (1._r8 - prt_params%allom_sai_scaler(currentCohort%pft))
currentCohort%treesai = sum(dinc_vai) * prt_params%allom_sai_scaler(currentCohort%pft)
endif

! Number of actual vegetation layers in this cohort's crown
currentCohort%nv = count((currentCohort%treelai+currentCohort%treesai) .gt. dlower_vai(:)) + 1

Expand Down
6 changes: 6 additions & 0 deletions biogeochem/EDPhysiologyMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,12 @@ subroutine trim_canopy( currentSite )
currentPatch%canopy_layer_tlai, currentCohort%treelai, &
currentCohort%vcmax25top,0 )

! cap leaf allometries that are larger than the allowable array space.
if( (currentCohort%treelai + currentCohort%treesai) > (sum(dinc_vai)) )then
currentCohort%treelai = sum(dinc_vai) * (1._r8 - prt_params%allom_sai_scaler(currentCohort%pft))
currentCohort%treesai = sum(dinc_vai) * prt_params%allom_sai_scaler(currentCohort%pft)
endif

currentCohort%nv = count((currentCohort%treelai+currentCohort%treesai) .gt. dlower_vai(:)) + 1

if (currentCohort%nv > nlevleaf)then
Expand Down
48 changes: 26 additions & 22 deletions biogeochem/FatesAllometryMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -829,29 +829,33 @@ real(r8) function tree_sai(pft, dbh, crowndamage, canopy_trim, elongf_stem, c_ar

if( (treelai + tree_sai) > (sum(dinc_vai)) )then

call h_allom(dbh,pft,h)

write(fates_log(),*) 'The leaf and stem are predicted for a cohort, maxed out the array size'
write(fates_log(),*) 'lai: ',treelai
write(fates_log(),*) 'sai: ',tree_sai
write(fates_log(),*) 'lai+sai: ',treelai+tree_sai
write(fates_log(),*) 'target_bleaf: ', target_bleaf
write(fates_log(),*) 'area: ', c_area
write(fates_log(),*) 'target_lai: ',target_lai
write(fates_log(),*) 'dinc_vai:',dinc_vai
write(fates_log(),*) 'nlevleaf,sum(dinc_vai):',nlevleaf,sum(dinc_vai)
write(fates_log(),*) 'pft: ',pft
write(fates_log(),*) 'call id: ',call_id
write(fates_log(),*) 'n: ',nplant
write(fates_log(),*) 'dbh: ',dbh,' dbh_max: ',prt_params%allom_dbh_maxheight(pft)
write(fates_log(),*) 'h: ',h
write(fates_log(),*) 'canopy_trim: ',canopy_trim
write(fates_log(),*) 'canopy layer: ',cl
write(fates_log(),*) 'canopy_tlai: ',canopy_lai(:)
write(fates_log(),*) 'vcmax25top: ',vcmax25top
call endrun(msg=errMsg(sourcefile, __LINE__))
! output warning message. use a separate warning index for each PFT that encounters this error.
warn_msg = 'Lai+sai for cohort maxed out the array size. lai, sai, pft, dbh: '//trim(N2S(treelai))// &
', '//trim(N2S(tree_sai))//', '//trim(I2S(pft))//', '//trim(N2S(dbh))
call FatesWarn(warn_msg,index=100+pft)

! old error message below.
! call h_allom(dbh,pft,h)
! write(fates_log(),*) 'lai: ',treelai
! write(fates_log(),*) 'sai: ',tree_sai
! write(fates_log(),*) 'lai+sai: ',treelai+tree_sai
! write(fates_log(),*) 'target_bleaf: ', target_bleaf
! write(fates_log(),*) 'area: ', c_area
! write(fates_log(),*) 'target_lai: ',target_lai
! write(fates_log(),*) 'dinc_vai:',dinc_vai
! write(fates_log(),*) 'nlevleaf,sum(dinc_vai):',nlevleaf,sum(dinc_vai)
! write(fates_log(),*) 'pft: ',pft
! write(fates_log(),*) 'call id: ',call_id
! write(fates_log(),*) 'n: ',nplant
! write(fates_log(),*) 'dbh: ',dbh,' dbh_max: ',prt_params%allom_dbh_maxheight(pft)
! write(fates_log(),*) 'h: ',h
! write(fates_log(),*) 'canopy_trim: ',canopy_trim
! write(fates_log(),*) 'canopy layer: ',cl
! write(fates_log(),*) 'canopy_tlai: ',canopy_lai(:)
! write(fates_log(),*) 'vcmax25top: ',vcmax25top
! call endrun(msg=errMsg(sourcefile, __LINE__))
end if



return
Expand Down