Skip to content

Commit

Permalink
Merge pull request #880 from rgknox/cnp-dynamic-root-allom-dfdd-api21…
Browse files Browse the repository at this point in the history
…-symfix

nutrient dynamics v2 of allocation and acquisition
  • Loading branch information
rgknox authored Dec 2, 2022
2 parents 474fa84 + 3027e30 commit e663a6e
Show file tree
Hide file tree
Showing 40 changed files with 4,871 additions and 2,949 deletions.
85 changes: 48 additions & 37 deletions biogeochem/EDCanopyStructureMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ module EDCanopyStructureMod
use FatesInterfaceTypesMod, only : bc_in_type
use FatesPlantHydraulicsMod, only : UpdateH2OVeg,InitHydrCohort, RecruitWaterStorage
use PRTGenericMod, only : leaf_organ
use PRTGenericMod, only : all_carbon_elements
use PRTGenericMod, only : leaf_organ
use PRTGenericMod, only : fnrt_organ
use PRTGenericMod, only : sapw_organ
use PRTGenericMod, only : store_organ
use PRTGenericMod, only : repro_organ
use PRTGenericMod, only : struct_organ
use PRTGenericMod, only : SetState
use FatesRunningMeanMod, only : ema_lpa
use PRTGenericMod, only : carbon12_element

! CIME Globals
use shr_log_mod , only : errMsg => shr_log_errMsg
Expand Down Expand Up @@ -143,7 +142,6 @@ subroutine canopy_structure( currentSite , bc_in )
logical :: area_not_balanced ! logical controlling if the patch layer areas
! have successfully been redistributed
integer :: return_code ! math checks on variables will return>0 if problems exist

! We only iterate because of possible imprecisions generated by the cohort
! termination process. These should be super small, so at the most
! try to re-balance 3 times. If that doesn't give layer areas
Expand Down Expand Up @@ -321,7 +319,7 @@ subroutine canopy_structure( currentSite , bc_in )
currentCohort => currentCohort%shorter
enddo
endif

currentPatch => currentPatch%younger
enddo !patch

Expand Down Expand Up @@ -629,11 +627,11 @@ subroutine DemoteFromLayer(currentSite,currentPatch,i_lyr,bc_in)
if(currentCohort%canopy_layer == i_lyr )then

cc_loss = currentCohort%excl_weight
leaf_c = currentCohort%prt%GetState(leaf_organ,all_carbon_elements)
store_c = currentCohort%prt%GetState(store_organ,all_carbon_elements)
fnrt_c = currentCohort%prt%GetState(fnrt_organ,all_carbon_elements)
sapw_c = currentCohort%prt%GetState(sapw_organ,all_carbon_elements)
struct_c = currentCohort%prt%GetState(struct_organ,all_carbon_elements)
leaf_c = currentCohort%prt%GetState(leaf_organ,carbon12_element)
store_c = currentCohort%prt%GetState(store_organ,carbon12_element)
fnrt_c = currentCohort%prt%GetState(fnrt_organ,carbon12_element)
sapw_c = currentCohort%prt%GetState(sapw_organ,carbon12_element)
struct_c = currentCohort%prt%GetState(struct_organ,carbon12_element)

if ( (cc_loss-currentCohort%c_area) > -nearzero .and. &
(cc_loss-currentCohort%c_area) < area_target_precision ) then
Expand Down Expand Up @@ -663,24 +661,26 @@ subroutine DemoteFromLayer(currentSite,currentPatch,i_lyr,bc_in)

allocate(copyc)

! (keep as an example)
! Initialize running means
!allocate(copyc%tveg_lpa)
!!allocate(copyc%l2fr_ema)
! Note, no need to give a starter value here,
! that will be taken care of in copy_cohort()
!!call copyc%l2fr_ema%InitRMean(ema_60day)

! Initialize the PARTEH object and point to the
! correct boundary condition fields
copyc%prt => null()
call InitPRTObject(copyc%prt)
call InitPRTBoundaryConditions(copyc)

if( hlm_use_planthydro.eq.itrue ) then
call InitHydrCohort(currentSite,copyc)
endif

! (keep as an example)
! Initialize running means
!allocate(copyc%tveg_lpa)
!call copyc%tveg_lpa%InitRMean(ema_lpa, &
! init_value=currentPatch%tveg_lpa%GetMean())

call copy_cohort(currentCohort, copyc)

call InitPRTBoundaryConditions(copyc)

newarea = currentCohort%c_area - cc_loss
copyc%n = currentCohort%n*newarea/currentCohort%c_area
currentCohort%n = currentCohort%n - copyc%n
Expand Down Expand Up @@ -723,6 +723,12 @@ subroutine DemoteFromLayer(currentSite,currentPatch,i_lyr,bc_in)
end if

! kill the ones which go into canopy layers that are not allowed
! USE THIS OVERRIDE IF YOU ARE FORCING A ONE COHORT SIMULATION
! (also make sure to turn off germination, external seed rain,
! (use only one PFT, and make sure disturb_frac is 0)
! (RGK-0822)
!if(currentCohort%canopy_layer>1) then

if(currentCohort%canopy_layer>nclmax )then
! put the litter from the terminated cohorts
! straight into the fragmenting pools
Expand Down Expand Up @@ -834,11 +840,11 @@ subroutine PromoteIntoLayer(currentSite,currentPatch,i_lyr)
!look at the cohorts in the canopy layer below...
if(currentCohort%canopy_layer == i_lyr+1)then

leaf_c = currentCohort%prt%GetState(leaf_organ,all_carbon_elements)
store_c = currentCohort%prt%GetState(store_organ,all_carbon_elements)
fnrt_c = currentCohort%prt%GetState(fnrt_organ,all_carbon_elements)
sapw_c = currentCohort%prt%GetState(sapw_organ,all_carbon_elements)
struct_c = currentCohort%prt%GetState(struct_organ,all_carbon_elements)
leaf_c = currentCohort%prt%GetState(leaf_organ,carbon12_element)
store_c = currentCohort%prt%GetState(store_organ,carbon12_element)
fnrt_c = currentCohort%prt%GetState(fnrt_organ,carbon12_element)
sapw_c = currentCohort%prt%GetState(sapw_organ,carbon12_element)
struct_c = currentCohort%prt%GetState(struct_organ,carbon12_element)

currentCohort%canopy_layer = i_lyr
call carea_allom(currentCohort%dbh,currentCohort%n,currentSite%spread, &
Expand Down Expand Up @@ -1098,11 +1104,11 @@ subroutine PromoteIntoLayer(currentSite,currentPatch,i_lyr)
if( (currentCohort%canopy_layer == i_lyr+1) ) then

cc_gain = currentCohort%prom_weight
leaf_c = currentCohort%prt%GetState(leaf_organ,all_carbon_elements)
store_c = currentCohort%prt%GetState(store_organ,all_carbon_elements)
fnrt_c = currentCohort%prt%GetState(fnrt_organ,all_carbon_elements)
sapw_c = currentCohort%prt%GetState(sapw_organ,all_carbon_elements)
struct_c = currentCohort%prt%GetState(struct_organ,all_carbon_elements)
leaf_c = currentCohort%prt%GetState(leaf_organ,carbon12_element)
store_c = currentCohort%prt%GetState(store_organ,carbon12_element)
fnrt_c = currentCohort%prt%GetState(fnrt_organ,carbon12_element)
sapw_c = currentCohort%prt%GetState(sapw_organ,carbon12_element)
struct_c = currentCohort%prt%GetState(struct_organ,carbon12_element)

if ( (cc_gain-currentCohort%c_area) > -nearzero .and. &
(cc_gain-currentCohort%c_area) < area_target_precision ) then
Expand All @@ -1121,11 +1127,17 @@ subroutine PromoteIntoLayer(currentSite,currentPatch,i_lyr)

allocate(copyc)


!!allocate(copyc%l2fr_ema)
! Note, no need to give a starter value here,
! that will be taken care of in copy_cohort()
!!call copyc%l2fr_ema%InitRMean(ema_60day)

! Initialize the PARTEH object and point to the
! correct boundary condition fields
copyc%prt => null()
call InitPRTObject(copyc%prt)
call InitPRTBoundaryConditions(copyc)


if( hlm_use_planthydro.eq.itrue ) then
call InitHydrCohort(CurrentSite,copyc)
Expand All @@ -1138,7 +1150,8 @@ subroutine PromoteIntoLayer(currentSite,currentPatch,i_lyr)
! init_value=currentPatch%tveg_lpa%GetMean())

call copy_cohort(currentCohort, copyc) !makes an identical copy...

call InitPRTBoundaryConditions(copyc)

newarea = currentCohort%c_area - cc_gain !new area of existing cohort

call carea_allom(currentCohort%dbh,currentCohort%n,currentSite%spread, &
Expand Down Expand Up @@ -1327,13 +1340,11 @@ subroutine canopy_summarization( nsites, sites, bc_in )
do while(associated(currentCohort))

ft = currentCohort%pft


leaf_c = currentCohort%prt%GetState(leaf_organ, all_carbon_elements)
sapw_c = currentCohort%prt%GetState(sapw_organ, all_carbon_elements)
struct_c = currentCohort%prt%GetState(struct_organ, all_carbon_elements)
fnrt_c = currentCohort%prt%GetState(fnrt_organ, all_carbon_elements)
store_c = currentCohort%prt%GetState(store_organ, all_carbon_elements)
leaf_c = currentCohort%prt%GetState(leaf_organ, carbon12_element)
sapw_c = currentCohort%prt%GetState(sapw_organ, carbon12_element)
struct_c = currentCohort%prt%GetState(struct_organ, carbon12_element)
fnrt_c = currentCohort%prt%GetState(fnrt_organ, carbon12_element)
store_c = currentCohort%prt%GetState(store_organ, carbon12_element)

! Update the cohort's index within the size bin classes
! Update the cohort's index within the SCPF classification system
Expand Down Expand Up @@ -2168,7 +2179,7 @@ subroutine UpdateCohortLAI(currentCohort, canopy_layer_tlai, total_canopy_area)
real(r8) :: leaf_c ! leaf carbon [kg]

! Obtain the leaf carbon
leaf_c = currentCohort%prt%GetState(leaf_organ,all_carbon_elements)
leaf_c = currentCohort%prt%GetState(leaf_organ,carbon12_element)


! Note that tree_lai has an internal check on the canopy locatoin
Expand Down
Loading

0 comments on commit e663a6e

Please sign in to comment.