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

Crown damage module #788

Merged
merged 104 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from 100 commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
49b41a0
[ cancel endrun for buggy error check ]
JessicaNeedham Sep 29, 2021
e68c22c
Squashed commit of all crown damage work
JessicaNeedham Sep 30, 2021
d090bfd
[ Uncomment a check that was breaking runs ]
JessicaNeedham Sep 30, 2021
fc3ed80
[ Fix bug with understory number densities ]
Oct 1, 2021
ad11283
Merge remote-tracking branch 'jfneedham_repo/JessicaNeedham-crowndama…
Oct 1, 2021
177876b
[moving damage module to biogeochem ]
JessicaNeedham Dec 9, 2021
d700c60
[bracket the increase in maxCohortsPerPatch in logic so it only incre…
JessicaNeedham Dec 9, 2021
63e513d
[ Revert number of canopy layers back to 2 ]
JessicaNeedham Dec 9, 2021
7c585f9
[Change min_n_safemath and min_npm2 to default values. ]
JessicaNeedham Dec 15, 2021
21b802b
[ Remove unnecessary history variables]
JessicaNeedham Dec 15, 2021
86d423e
Merge remote-tracking branch 'jfneedham_repo/JessicaNeedham-crowndama…
JessicaNeedham Dec 16, 2021
efeb680
[ Add comments to FatesAllometry related to crown damage ]
JessicaNeedham Dec 16, 2021
7484d25
[ Correct typo in parameter file ]
JessicaNeedham Dec 16, 2021
c00b89d
[Update comments in parameter file with more details on
JessicaNeedham Dec 16, 2021
1e1242b
[ Add comments on crowndamage declaration ]
JessicaNeedham Dec 17, 2021
586cf0c
Merge remote-tracking branch 'ngeet_repo/master'
JessicaNeedham Dec 17, 2021
b7cb23d
Merge branch 'master' into damage_temp
JessicaNeedham Jan 7, 2022
b2937ab
[ Remove old damage history dimensions and fix bugs with
JessicaNeedham Jan 10, 2022
ca903c4
[ update units on damage history variables ]
JessicaNeedham Jan 10, 2022
cc5a60b
[ Remove branch frac as a cohort variable ]
JessicaNeedham Jan 28, 2022
092f9df
Merge remote-tracking branch 'ngeet_repo/master'
JessicaNeedham Feb 7, 2022
ada5ce7
Merge branch 'master' into branch_frac_fix
JessicaNeedham Feb 12, 2022
a5f752b
[ Fix merge conflicts in EDCanopySturctureMod ]
JessicaNeedham Feb 14, 2022
14399fc
[ Add damage x damage dimension back ]
JessicaNeedham Feb 14, 2022
1324109
[ Fix bug with if statements in fateshistoryinterface ]
JessicaNeedham Feb 16, 2022
14ef508
Merge branch 'branch_frac_fix' into JessicaNeedham-crowndamage_module
JessicaNeedham Feb 16, 2022
6b6ed7f
[ Remove cdcd dimension ]
JessicaNeedham Feb 17, 2022
d15081f
[ update comments on branch_frac ]
JessicaNeedham Feb 28, 2022
a3bb261
[ delete old variables from EDInitMod]
JessicaNeedham Mar 1, 2022
36e8faf
[ Remove old history variables ]
JessicaNeedham Mar 2, 2022
6ea0259
Merge remote-tracking branch 'ngeet_repo/master'
JessicaNeedham Mar 8, 2022
7ed9029
[ and remove the last damage_clux and damage_rate variables ]
JessicaNeedham Mar 2, 2022
63edb53
[ Change default damage param values ]
JessicaNeedham Mar 7, 2022
d59e249
Merge remote-tracking branch 'ngeet_repo/master'
JessicaNeedham Mar 9, 2022
c8d86d1
[ remove damage_cflux ]
JessicaNeedham Mar 10, 2022
4a622fe
Merge branch 'master' into JessicaNeedham-crowndamage_module
JessicaNeedham Mar 11, 2022
64abd25
Merge branch 'master' into JessicaNeedham-crowndamage_module
JessicaNeedham Mar 21, 2022
442639f
[ Add damage only dimension back. ]
JessicaNeedham Mar 22, 2022
6f0e682
[ Make crown damage bin edges flexible ]
JessicaNeedham Mar 22, 2022
78b4f1a
[ Fixing flexible damage bins ]
JessicaNeedham Mar 23, 2022
d9ee7ab
[Fix bug in defining nlevdamage ]
JessicaNeedham Apr 3, 2022
f0352aa
[ fixing canopy_too_full error - possibly from bad merge ]
JessicaNeedham Apr 3, 2022
8f994c2
[ Fix canopy too full error with damage code ]
JessicaNeedham Apr 16, 2022
f28f532
[ make damage timings be controlled by event_code as in
JessicaNeedham May 13, 2022
2613582
[ Fixing damage event codes ]
JessicaNeedham May 14, 2022
758d902
[ create a single hlm_use_crown_damage switch and make a parameter
JessicaNeedham May 26, 2022
4d1cd0a
Merge branch 'master' into crowndamage-deconflict
glemieux May 26, 2022
ece0c71
converting new procedures to CamelCase
glemieux May 26, 2022
f73d65d
[ change damage bin edges ]
JessicaNeedham May 26, 2022
59d4357
converting logical from CamelCase back to original format
glemieux May 26, 2022
657ba0a
adding target_c_area local to UpdateCohortLAI
glemieux May 26, 2022
cc2d5f8
fixing erroneous damage_time name changes
glemieux May 27, 2022
6b21b53
fixing bad merge
glemieux May 27, 2022
a76d62f
[ update UpdateCohortLAI to accommodate extra arguments needed for da…
JessicaNeedham May 27, 2022
f0e8c30
Merge remote-tracking branch 'glemieux_repo/crowndamage-deconflict' i…
JessicaNeedham May 27, 2022
50dc896
Merge remote-tracking branch 'jfneedham_repo/JessicaNeedham-crowndama…
JessicaNeedham Jun 21, 2022
c1bb091
First pass at resolving conflicts between the damage module and api 2…
rgknox Jun 28, 2022
e85d1f4
Updated argument name in UpdateCohortLai
rgknox Jun 29, 2022
bb345fc
Added the undamaged class named constant
rgknox Jun 29, 2022
ce6f93b
[ Change tree_sai so that it is affected by damage ]
JessicaNeedham Jun 29, 2022
d2dfb73
Minor variable name change for readability
rgknox Jun 30, 2022
21ae55e
Merge branch 'JessicaNeedham-crowndamage_module-merged' of github.com…
rgknox Jun 30, 2022
71c56b1
Inremental change towards damage recovery refactor
rgknox Jun 30, 2022
010a95f
Second pass through splitting allocation and modularizing the recover…
rgknox Jun 30, 2022
02b661a
Minor updates to damage recovery
rgknox Jun 30, 2022
db14473
Applying the phase argument to carbon allocation in parteh
rgknox Jun 30, 2022
daafba1
cleaning up damage boundary condition to parteh, adding in phase hook…
rgknox Jun 30, 2022
f6bfc64
Various merge resolutions and fixes for new damge recovery scheme
rgknox Jul 1, 2022
b660f7b
Moving DamageRecovery to cohortdynamics
rgknox Jul 1, 2022
bfe205c
resolution on moving damagerecovery
rgknox Jul 1, 2022
84e84b9
Removed check on use_tree_damage, which is allowed now
rgknox Jul 1, 2022
650077a
Fixes to use_tree_damage
rgknox Jul 1, 2022
71c41c6
Making tree_sai in canopy_trim use actual area
rgknox Jul 3, 2022
52f5b87
argument re-ordering in crowndamage allometry argument and adding in …
rgknox Jul 5, 2022
b266106
Removed a redundant (double) allocation call
rgknox Jul 6, 2022
34a6fe3
Removed patch level damage code, in preparation for moving it to a pr…
rgknox Jul 6, 2022
3351666
Added declaration of global hlm_use_tree_damage
rgknox Jul 6, 2022
b9d7b97
First pass at the new damage application routine
rgknox Jul 6, 2022
3e2aeab
Adding variable definitions to the damage generation routine
rgknox Jul 11, 2022
85f7e55
Added module use statements to damage and litter generation module
rgknox Jul 12, 2022
c263eac
conflict resolutions on damage branch
rgknox Sep 13, 2022
eadc895
Syntax updates for tree damage mode
rgknox Sep 16, 2022
32a5a4d
slight correction to crown damage calc
rgknox Sep 16, 2022
cf91237
Fixes to allocation phases vis-a-vis recovery
rgknox Sep 16, 2022
dc3e5f4
Subtle fixes to the allocation phasing and damage
rgknox Sep 16, 2022
d5e9ad4
Fixes, yet again, to allocation and phasing
rgknox Sep 16, 2022
38d9f32
Changes to sapwood respiration to account for aboveground damage.
Sep 16, 2022
6fc3bef
Fix the sapwood respiration bug
Sep 17, 2022
c955cf1
Slight update to allow FATES CNP to work with new phased allocation, …
rgknox Sep 20, 2022
ae40104
Added user name checks for damage mode and parteh 2
rgknox Sep 20, 2022
2b064f0
Updated error statement for fates cnp and tree damage
rgknox Sep 20, 2022
79f3065
Conflict resolutions
rgknox Sep 20, 2022
f998407
reverting nlevleaf
rgknox Sep 21, 2022
35dad01
Changing how damage fraction is calculated to account for variable
Sep 22, 2022
86dd566
Merge remote-tracking branch 'jfneedham_repo/JessicaNeedham-crowndama…
Sep 22, 2022
bec8928
Tidy up some debugging print statements
Sep 24, 2022
3efa3d0
Fix damage transition matrix to account for flexible damage bins
Sep 26, 2022
0251401
add crowndamage to allometry calls in EDPhysiologyMod
Sep 26, 2022
de822e4
Update sapwood respiration to fix damage related bug
Sep 27, 2022
e5b0121
Tidy comments on damage code
Oct 4, 2022
9dddd74
Update biogeophys/FatesPlantRespPhotosynthMod.F90
glemieux Oct 24, 2022
ab4e75b
fix whitespace and add comment
glemieux Oct 24, 2022
b1e4a1a
add debug check
glemieux Oct 24, 2022
adfba93
Merge tag 'sci.1.59.7_api.24.1.0' into JessicaNeedham-crowndamage_module
glemieux Oct 24, 2022
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
229 changes: 229 additions & 0 deletions biogeochem/DamageMainMod.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
module DamageMainMod

use FatesConstantsMod , only : r8 => fates_r8
use FatesConstantsMod , only : i4 => fates_int
use FatesConstantsMod , only : itrue, ifalse
use FatesConstantsMod , only : years_per_day
use FatesConstantsMod , only : nearzero
use FatesGlobals , only : fates_log
use FatesGlobals , only : endrun => fates_endrun
use shr_log_mod , only : errMsg => shr_log_errMsg
use EDPftvarcon , only : EDPftvarcon_inst
use EDParamsMod , only : damage_event_code
use EDParamsMod , only : ED_val_history_damage_bin_edges
use EDTypesMod , only : ed_site_type
use EDTypesMod , only : ed_patch_type
use EDTypesMod , only : ed_cohort_type
use EDTypesMod , only : AREA
use FatesInterfaceTypesMod, only : hlm_current_day
use FatesInterfaceTypesMod, only : hlm_current_month
use FatesInterfaceTypesMod, only : hlm_current_year
use FatesInterfaceTypesMod, only : hlm_model_day
use FatesInterfaceTypesMod, only : hlm_day_of_year

implicit none
private

logical, protected :: damage_time ! if true then damage occurs during current time step

character(len=*), parameter, private :: sourcefile = &
__FILE__

public :: GetCrownReduction
public :: GetDamageFrac
public :: IsItDamageTime
public :: damage_time
public :: GetDamageMortality


logical :: debug = .false. ! for debugging


! The following is the special classification for undamaged plants
! and is used in contexts where cohort%damageclass is used. This is
! to flag to the user that an undamaged plant is assumed in those contexts

integer, parameter, public :: undamaged_class = 1


! ============================================================================
! ============================================================================

contains




subroutine IsItDamageTime(is_master, currentSite)

!----------------------------------------------------------------------------
! This subroutine determines whether damage should occur (it is called daily)
! This is almost an exact replica of the IsItLoggingTime subroutine
!-----------------------------------------------------------------------------


integer, intent(in) :: is_master
type(ed_site_type), intent(inout), target :: currentSite

integer :: icode ! Integer equivalent of the event code (parameter file only allows reals)
integer :: damage_date ! Day of month for damage extracted from event code
integer :: damage_month ! Month of year for damage extracted from event code
integer :: damage_year ! Year for damage extracted from event code
integer :: model_day_int ! Model day

character(len=64) :: fmt = '(a,i2.2,a,i2.2,a,i4.4)'

damage_time = .false.
icode = int(damage_event_code)

model_day_int = int(hlm_model_day)

if(icode .eq. 1) then
! Damage is turned off
damage_time = .false.

else if(icode .eq. 2) then
! Damage event on first time step
if(model_day_int .eq.1) then
damage_time = .true.
end if

else if(icode .eq. 3) then
! Damage event every day - this is not recommended as it will result in a very large
! number of cohorts which will likely be terminated
damage_time = .true.

else if(icode .eq. 4) then
! Damage event once a month
if(hlm_current_day.eq.1 ) then
damage_time = .true.
end if

else if(icode < 0 .and. icode > -366) then
! Damage event every year on a specific day of the year
! specified as negative day of year
if(hlm_day_of_year .eq. abs(icode) ) then
damage_time = .true.
end if

else if(icode > 10000 ) then
! Specific Event: YYYYMMDD
damage_date = icode - int(100* floor(real(icode,r8)/100._r8))
damage_year = floor(real(icode,r8)/10000._r8)
damage_month = floor(real(icode,r8)/100._r8) - damage_year*100

if(hlm_current_day .eq. damage_date .and. &
hlm_current_month .eq. damage_month .and. &
hlm_current_year .eq. damage_year ) then
damage_time = .true.
end if

else
! Bad damage event flag
write(fates_log(),*) 'An invalid damage code was specified in fates_params'
write(fates_log(),*) 'Check DamageMainMod.F90:IsItDamageTime()'
write(fates_log(),*) 'for a breakdown of the valid codes and change'
write(fates_log(),*) 'fates_damage_event_code in the file accordingly.'
write(fates_log(),*) 'exiting'
call endrun(msg=errMsg(sourcefile, __LINE__))
end if

if(damage_time .and. (is_master.eq.itrue) ) then
write(fates_log(),fmt) 'Damage Event Enacted on date: ', &
hlm_current_month,'-', hlm_current_day,'-',hlm_current_year
end if

return

end subroutine IsItDamageTime

!----------------------------------------------------------------------------

subroutine GetDamageFrac(cc_cd, nc_cd, pft, dist_frac)


! Given the current cohort damage class find the fraction of individuals
! going to the new damage class.
! This subroutine consults a look up table of transitions from param derived.

! USES
use FatesParameterDerivedMod, only : param_derived


! ARGUMENTS
integer, intent(in) :: cc_cd ! current cohort crown damage
integer, intent(in) :: nc_cd ! new cohort crown damage
integer, intent(in) :: pft ! plant functional type
real(r8), intent(out) :: dist_frac ! fraction of current cohort moving to
! new damage level

dist_frac = param_derived%damage_transitions(cc_cd, nc_cd, pft)

end subroutine GetDamageFrac

!-------------------------------------------------------

subroutine GetCrownReduction(crowndamage, crown_reduction)

!------------------------------------------------------------------
! This subroutine takes the crown damage class of a cohort (integer)
! and returns the fraction of the crown that is lost.
!-------------------------------------------------------------------

integer(i4), intent(in) :: crowndamage ! crown damage class of the cohort
real(r8), intent(out) :: crown_reduction ! fraction of crown lost from damage

crown_reduction = ED_val_history_damage_bin_edges(crowndamage)/100.0_r8

return
end subroutine GetCrownReduction


!----------------------------------------------------------------------------------------


subroutine GetDamageMortality(crowndamage,pft, dgmort)

!------------------------------------------------------------------
! This subroutine calculates damage-dependent mortality.
! Not all damage related mortality will be captured by mechanisms in FATES
! (e.g. carbon starvation mortality). Damage could also lead to damage
! due to unrepresented mechanisms such as pathogens or increased
! vulnerability to wind throws. This function captures mortality due to
! those unrepresented mechanisms.
!------------------------------------------------------------------

use EDPftvarcon , only : EDPftvarcon_inst

integer(i4), intent(in) :: crowndamage ! crown damage class of the cohort
integer(i4), intent(in) :: pft ! plant functional type
real(r8), intent(out) :: dgmort ! mortality directly associated with damage

! local variables
real(r8) :: damage_mort_p1 ! inflection point of the damage mortalty relationship
real(r8) :: damage_mort_p2 ! rate parameter for the damage mortality relationship
real(r8) :: crown_loss ! fraction of crown lost

damage_mort_p1 = EDPftvarcon_inst%damage_mort_p1(pft)
damage_mort_p2 = EDPftvarcon_inst%damage_mort_p2(pft)

! make damage mortality a function of crownloss and not crowndamage
! class so that it doesn't need to be re-parameterised if the number
! of damage classes change.
crown_loss = ED_val_history_damage_bin_edges(crowndamage)/100.0_r8

if (crowndamage .eq. 1 ) then
dgmort = 0.0_r8
else
dgmort = 1.0_r8 / (1.0_r8 + exp(-1.0_r8 * damage_mort_p2 * &
(crown_loss - damage_mort_p1) ) )

end if

return
end subroutine GetDamageMortality
!----------------------------------------------------------------------------------------


end module DamageMainMod

Loading