Skip to content

Commit

Permalink
Merge branch 'master' into spitfire_cleanup
Browse files Browse the repository at this point in the history
Conflicts:
	components/clm/src/ED/biogeochem/EDPhysiologyMod.F90
	components/clm/src/ED/fire/SFMainMod.F90
	components/clm/src/ED/main/EDInitMod.F90
  • Loading branch information
jkshuman committed Mar 14, 2017
2 parents f28668c + 0ea3fed commit 3cf2821
Show file tree
Hide file tree
Showing 40 changed files with 6,906 additions and 5,101 deletions.
4 changes: 2 additions & 2 deletions cime/cime_config/cesm/machines/config_compilers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,8 @@ for mct, etc.
<compiler COMPILER="gnu" MACH="eddi">
<NETCDF_PATH>$(NETCDF_HOME)</NETCDF_PATH>
<ADD_CPPDEFS> -DLinux -DCPRGNU </ADD_CPPDEFS>
<ADD_FFLAGS> -ffree-line-length-132 </ADD_FFLAGS>
<ADD_FFLAGS DEBUG="TRUE"> -ffpe-trap=invalid,zero,overflow </ADD_FFLAGS> <!---finit-integer=0-->
<ADD_FFLAGS DEBUG="FALSE"> -ffree-line-length-132 </ADD_FFLAGS>
<ADD_FFLAGS DEBUG="TRUE"> -g -fbacktrace -fbounds-check -ffpe-trap=invalid,zero,overflow -Wline-truncation</ADD_FFLAGS> <!---finit-integer=0-->
<ADD_SLIBS> -L$(NETCDF_HOME)/lib/ -lnetcdff -lnetcdf -lcurl -llapack -lblas</ADD_SLIBS>
<GPTL_CPPDEFS> -DHAVE_VPRINTF -DHAVE_GETTIMEOFDAY </GPTL_CPPDEFS>
<ESMF_LIBDIR></ESMF_LIBDIR>
Expand Down
4 changes: 0 additions & 4 deletions cime/cime_config/cesm/machines/config_machines.xml
Original file line number Diff line number Diff line change
Expand Up @@ -861,10 +861,6 @@
</batch_system>
<mpirun mpilib="mpi-serial">
<executable></executable>
<arguments>
<arg name="num_tasks">-np {{ num_tasks }}</arg>
<arg name="tasks_per_node"> -npernode {{ tasks_per_node }}</arg>
</arguments>
</mpirun>
<mpirun mpilib="default">
<executable>mpirun</executable>
Expand Down
126 changes: 79 additions & 47 deletions components/clm/src/ED/biogeochem/EDCanopyStructureMod.F90

Large diffs are not rendered by default.

134 changes: 81 additions & 53 deletions components/clm/src/ED/biogeochem/EDCohortDynamicsMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@ module EDCohortDynamicsMod
! Cohort stuctures in ED.
!
! !USES:
use abortutils , only : endrun
use FatesGlobals , only : endrun => fates_endrun
use FatesGlobals , only : fates_log
use FatesInterfaceMod , only : hlm_freq_day
use FatesConstantsMod , only : r8 => fates_r8
use shr_log_mod , only : errMsg => shr_log_errMsg
use FatesConstantsMod , only : fates_unset_int
use pftconMod , only : pftcon
use EDEcophysContype , only : EDecophyscon
use EDGrowthFunctionsMod , only : c_area, tree_lai
use EDTypesMod , only : ed_site_type, ed_patch_type, ed_cohort_type
use EDTypesMod , only : fusetol, cp_nclmax
use EDtypesMod , only : ncwd, numcohortsperpatch, udata
use EDtypesMod , only : sclass_ed,nlevsclass_ed,AREA
use EDtypesMod , only : min_npm2, min_nppatch, min_n_safemath
use EDTypesMod , only : fusetol
use EDTypesMod , only : nclmax
use EDTypesMod , only : ncwd
use EDTypesMod , only : maxCohortsPerPatch
use EDTypesMod , only : sclass_ed,nlevsclass_ed,AREA
use EDTypesMod , only : min_npm2, min_nppatch
use EDTypesMod , only : min_n_safemath
! CIME globals
use shr_log_mod , only : errMsg => shr_log_errMsg
!
implicit none
private
Expand Down Expand Up @@ -73,7 +79,6 @@ subroutine create_cohort(patchptr, pft, nn, hite, dbh, &
!----------------------------------------------------------------------

allocate(new_cohort)
udata%cohort_number = udata%cohort_number + 1 !give each cohort a unique number for checking cohort fusing routine.

call nan_cohort(new_cohort) ! Make everything in the cohort not-a-number
call zero_cohort(new_cohort) ! Zero things that need to be zeroed.
Expand All @@ -82,7 +87,8 @@ subroutine create_cohort(patchptr, pft, nn, hite, dbh, &
! Define cohort state variable
!**********************/

new_cohort%indexnumber = udata%cohort_number
new_cohort%indexnumber = fates_unset_int ! Cohort indexing was not thread-safe, setting
! bogus value for the time being (RGK-012017)
new_cohort%siteptr => patchptr%siteptr
new_cohort%patchptr => patchptr
new_cohort%pft = pft
Expand All @@ -92,6 +98,7 @@ subroutine create_cohort(patchptr, pft, nn, hite, dbh, &
new_cohort%dbh = dbh
new_cohort%canopy_trim = ctrim
new_cohort%canopy_layer = clayer
new_cohort%canopy_layer_yesterday = real(clayer, r8)
new_cohort%laimemory = laimemory
new_cohort%bdead = bdead
new_cohort%balive = balive
Expand All @@ -109,7 +116,7 @@ subroutine create_cohort(patchptr, pft, nn, hite, dbh, &

if (new_cohort%dbh <= 0.0_r8 .or. new_cohort%n == 0._r8 .or. new_cohort%pft == 0 ) then
write(fates_log(),*) 'ED: something is zero in create_cohort', &
new_cohort%indexnumber,new_cohort%dbh,new_cohort%n, &
new_cohort%dbh,new_cohort%n, &
new_cohort%pft
call endrun(msg=errMsg(sourcefile, __LINE__))
endif
Expand Down Expand Up @@ -184,6 +191,9 @@ subroutine allocate_live_biomass(cc_p,mode)
! accounts for the fact that live biomass may decline in the off-season,
! making leaf_memory unrealistic.
real(r8) :: ratio_balive ! ratio between root+shoot biomass now and root+shoot biomass when leaves fell off.
real(r8) :: new_bl
real(r8) :: new_br
real(r8) :: new_bsw

integer :: ft ! functional type
integer :: leaves_off_switch
Expand Down Expand Up @@ -218,69 +228,68 @@ subroutine allocate_live_biomass(cc_p,mode)
! Use different proportions if the leaves are on vs off
if(leaves_off_switch==0)then

! Tracking npp/gpp diagnostics only occur after growth derivatives is called
if(mode==1)then
! it will not be able to put out as many leaves as it had previous timestep
currentcohort%npp_leaf = currentcohort%npp_leaf + &
max(0.0_r8,currentcohort%balive*leaf_frac - currentcohort%bl)/udata%deltat
end if
new_bl = currentcohort%balive*leaf_frac

currentcohort%bl = currentcohort%balive*leaf_frac
new_br = pftcon%froot_leaf(ft) * (currentcohort%balive + currentcohort%laimemory) * leaf_frac

new_bsw = EDecophyscon%sapwood_ratio(ft) * currentcohort%hite *(currentcohort%balive + &
currentcohort%laimemory)*leaf_frac

!diagnose the root and stem biomass from the functional balance hypothesis. This is used when the leaves are
!fully on.
if(mode==1)then
if(mode==1)then

currentcohort%npp_leaf = currentcohort%npp_leaf + &
max(0.0_r8,new_bl - currentcohort%bl) / hlm_freq_day

currentcohort%npp_froot = currentcohort%npp_froot + &
max(0._r8,pftcon%froot_leaf(ft)*(currentcohort%balive+currentcohort%laimemory)*leaf_frac - currentcohort%br) / &
udata%deltat
max(0._r8,new_br - currentcohort%br) / hlm_freq_day

currentcohort%npp_bsw = max(0._r8,EDecophyscon%sapwood_ratio(ft) * currentcohort%hite *(currentcohort%balive + &
currentcohort%laimemory)*leaf_frac - currentcohort%bsw)/udata%deltat
currentcohort%npp_bsw = max(0.0_r8, new_bsw - currentcohort%bsw)/hlm_freq_day

currentcohort%npp_bdead = currentCohort%dbdeaddt

end if

currentcohort%bl = new_bl
currentcohort%br = new_br
currentcohort%bsw = new_bsw

currentcohort%br = pftcon%froot_leaf(ft) * (currentcohort%balive + currentcohort%laimemory) * leaf_frac
currentcohort%bsw = EDecophyscon%sapwood_ratio(ft) * currentcohort%hite *(currentcohort%balive + &
currentcohort%laimemory)*leaf_frac


else ! Leaves are on (leaves_off_switch==1)

!the purpose of this section is to figure out the root and stem biomass when the leaves are off
!at this point, we know the former leaf mass (laimemory) and the current alive mass
!because balive may decline in the off-season, we need to adjust the root and stem biomass that are predicted
!from the laimemory, for the fact that we now might not have enough live biomass to support the hypothesized root mass
!thus, we use 'ratio_balive' to adjust br and bsw. Apologies that this is so complicated! RF
else ! Leaves are off (leaves_off_switch==1)


currentcohort%bl = 0.0_r8
!the purpose of this section is to figure out the root and stem biomass when the leaves are off
!at this point, we know the former leaf mass (laimemory) and the current alive mass
!because balive may decline in the off-season, we need to adjust the
!root and stem biomass that are predicted from the laimemory, for the fact that we now might
!not have enough live biomass to support the hypothesized root mass
!thus, we use 'ratio_balive' to adjust br and bsw. Apologies that this is so complicated! RF

ideal_balive = currentcohort%laimemory * pftcon%froot_leaf(ft) + &
currentcohort%laimemory* EDecophyscon%sapwood_ratio(ft) * currentcohort%hite
currentcohort%br = pftcon%froot_leaf(ft) * (ideal_balive + currentcohort%laimemory) * leaf_frac
currentcohort%bsw = EDecophyscon%sapwood_ratio(ft) * currentcohort%hite *(ideal_balive + &
currentcohort%laimemory)*leaf_frac

ratio_balive = currentcohort%balive / ideal_balive
currentcohort%br = currentcohort%br * ratio_balive
currentcohort%bsw = currentcohort%bsw * ratio_balive
ratio_balive = currentcohort%balive / ideal_balive

new_br = pftcon%froot_leaf(ft) * (ideal_balive + currentcohort%laimemory) * &
leaf_frac * ratio_balive
new_bsw = EDecophyscon%sapwood_ratio(ft) * currentcohort%hite * &
(ideal_balive + currentcohort%laimemory) * leaf_frac * ratio_balive

! Diagnostics
if(mode==1)then

currentcohort%npp_froot = currentcohort%npp_froot + &
max(0.0_r8,pftcon%froot_leaf(ft)*(ideal_balive + &
currentcohort%laimemory)*leaf_frac*ratio_balive-currentcohort%br)/udata%deltat
max(0.0_r8,new_br-currentcohort%br)/hlm_freq_day

currentcohort%npp_bsw = max(0.0_r8,EDecophyscon%sapwood_ratio(ft) * currentcohort%hite *(ideal_balive + &
currentcohort%laimemory)*leaf_frac*ratio_balive - currentcohort%bsw)/udata%deltat
currentcohort%npp_bsw = max(0.0_r8, new_bsw-currentcohort%bsw)/hlm_freq_day

currentcohort%npp_bdead = currentCohort%dbdeaddt

end if

currentcohort%bl = 0.0_r8
currentcohort%br = new_br
currentcohort%bsw = new_bsw

endif

if (abs(currentcohort%balive -currentcohort%bl- currentcohort%br - currentcohort%bsw)>1e-12) then
Expand Down Expand Up @@ -329,6 +338,7 @@ subroutine nan_cohort(cc_p)
currentCohort%pft = fates_unset_int ! pft number
currentCohort%indexnumber = fates_unset_int ! unique number for each cohort. (within clump?)
currentCohort%canopy_layer = fates_unset_int ! canopy status of cohort (1 = canopy, 2 = understorey, etc.)
currentCohort%canopy_layer_yesterday = nan ! recent canopy status of cohort (1 = canopy, 2 = understorey, etc.)
currentCohort%NV = fates_unset_int ! Number of leaf layers: -
currentCohort%status_coh = fates_unset_int ! growth status of plant (2 = leaves on , 1 = leaves off)
currentCohort%size_class = fates_unset_int ! size class index
Expand Down Expand Up @@ -475,7 +485,7 @@ subroutine zero_cohort(cc_p)
end subroutine zero_cohort

!-------------------------------------------------------------------------------------!
subroutine terminate_cohorts( patchptr )
subroutine terminate_cohorts( siteptr, patchptr )
!
! !DESCRIPTION:
! terminates cohorts when they get too small
Expand All @@ -485,6 +495,7 @@ subroutine terminate_cohorts( patchptr )
use SFParamsMod, only : SF_val_CWD_frac
!
! !ARGUMENTS
type (ed_site_type), intent(inout), target :: siteptr
type (ed_patch_type), intent(inout), target :: patchptr
!
! !LOCAL VARIABLES:
Expand All @@ -493,6 +504,7 @@ subroutine terminate_cohorts( patchptr )
type (ed_cohort_type) , pointer :: nextc
integer :: terminate ! do we terminate (1) or not (0)
integer :: c ! counter for litter size class.
integer :: levcan ! canopy level
!----------------------------------------------------------------------

currentPatch => patchptr
Expand Down Expand Up @@ -525,7 +537,7 @@ subroutine terminate_cohorts( patchptr )
endif

! In the third canopy layer
if (currentCohort%canopy_layer > cp_nclmax ) then
if (currentCohort%canopy_layer > nclmax ) then
terminate = 1
if ( DEBUG ) then
write(fates_log(),*) 'terminating cohorts 2', currentCohort%canopy_layer
Expand Down Expand Up @@ -554,6 +566,17 @@ subroutine terminate_cohorts( patchptr )
endif

if (terminate == 1) then
! preserve a record of the to-be-terminated cohort for mortality accounting
if (currentCohort%canopy_layer .eq. 1) then
levcan = 1
else
levcan = 2
endif
siteptr%terminated_nindivs(currentCohort%size_class,currentCohort%pft,levcan) = &
siteptr%terminated_nindivs(currentCohort%size_class,currentCohort%pft,levcan) + currentCohort%n
!
siteptr%termination_carbonflux(levcan) = siteptr%termination_carbonflux(levcan) + &
currentCohort%n * currentCohort%b
if (.not. associated(currentCohort%taller)) then
currentPatch%tallest => currentCohort%shorter
else
Expand Down Expand Up @@ -597,7 +620,7 @@ subroutine fuse_cohorts(patchptr)
! Join similar cohorts to reduce total number
!
! !USES:
use EDTypesMod , only : cp_nlevcan
use EDTypesMod , only : nlevcan
!
! !ARGUMENTS
type (ed_patch_type), intent(inout), target :: patchptr
Expand Down Expand Up @@ -626,7 +649,7 @@ subroutine fuse_cohorts(patchptr)
iterate = 1
fusion_took_place = 0
currentPatch => patchptr
maxcohorts = numCohortsPerPatch
maxcohorts = maxCohortsPerPatch

!---------------------------------------------------------------------!
! Keep doing this until nocohorts <= maxcohorts !
Expand Down Expand Up @@ -749,7 +772,11 @@ subroutine fuse_cohorts(patchptr)
currentCohort%npp_bseed = (currentCohort%n*currentCohort%npp_bseed + nextc%n*nextc%npp_bseed)/newn
currentCohort%npp_store = (currentCohort%n*currentCohort%npp_store + nextc%n*nextc%npp_store)/newn

do i=1, cp_nlevcan
! recent canopy history
currentCohort%canopy_layer_yesterday = (currentCohort%n*currentCohort%canopy_layer_yesterday + &
nextc%n*nextc%canopy_layer_yesterday)/newn

do i=1, nlevcan
if (currentCohort%year_net_uptake(i) == 999._r8 .or. nextc%year_net_uptake(i) == 999._r8) then
currentCohort%year_net_uptake(i) = min(nextc%year_net_uptake(i),currentCohort%year_net_uptake(i))
else
Expand Down Expand Up @@ -1006,8 +1033,7 @@ subroutine copy_cohort( currentCohort,copyc )
o => currentCohort
n => copyc

udata%cohort_number = udata%cohort_number + 1
n%indexnumber = udata%cohort_number
n%indexnumber = fates_unset_int

! VEGETATION STRUCTURE
n%pft = o%pft
Expand All @@ -1027,6 +1053,7 @@ subroutine copy_cohort( currentCohort,copyc )
n%gscan = o%gscan
n%leaf_cost = o%leaf_cost
n%canopy_layer = o%canopy_layer
n%canopy_layer_yesterday = o%canopy_layer_yesterday
n%nv = o%nv
n%status_coh = o%status_coh
n%canopy_trim = o%canopy_trim
Expand All @@ -1038,13 +1065,14 @@ subroutine copy_cohort( currentCohort,copyc )
n%gpp_acc_hold = o%gpp_acc_hold
n%gpp_acc = o%gpp_acc
n%gpp_tstep = o%gpp_tstep

n%npp_acc_hold = o%npp_acc_hold
n%npp_tstep = o%npp_tstep
n%npp_acc = o%npp_acc

if ( DEBUG ) write(fates_log(),*) 'EDcohortDyn Ia ',o%npp_acc
if ( DEBUG ) write(fates_log(),*) 'EDcohortDyn Ib ',o%resp_acc

n%npp_acc_hold = o%npp_acc_hold
n%resp_tstep = o%resp_tstep
n%resp_acc = o%resp_acc
n%resp_acc_hold = o%resp_acc_hold
Expand Down
Loading

0 comments on commit 3cf2821

Please sign in to comment.