Skip to content

Commit

Permalink
Merge conflicts resolved. Nastiest conflicts were insdie allocate_liv…
Browse files Browse the repository at this point in the history
…e_biomass() where the day frequency was updated in master and the head had some pretty drastic overhaul on order of operations.
  • Loading branch information
rgknox committed Feb 2, 2017
2 parents 5c4e164 + b56080e commit 19ec489
Show file tree
Hide file tree
Showing 12 changed files with 541 additions and 429 deletions.
6 changes: 3 additions & 3 deletions biogeochem/EDCanopyStructureMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,12 @@ subroutine canopy_structure( currentSite )
endif
!call terminate_cohorts(currentPatch)
if(promswitch == 1)then
! write(fates_log(),*) 'cohort loop',currentCohort%pft,currentCohort%indexnumber,currentPatch%patchno
! write(fates_log(),*) 'cohort loop',currentCohort%pft,currentPatch%patchno
endif
!----------- End of cohort splitting ------------------------------!
else
if(promswitch == 1)then
! write(fates_log(),*) 'cohort list',currentCohort%pft,currentCohort%indexnumber, &
! write(fates_log(),*) 'cohort list',currentCohort%pft, &
! currentCohort%canopy_layer,currentCohort%c_area
endif
endif
Expand All @@ -485,7 +485,7 @@ subroutine canopy_structure( currentSite )
!currentPatch%patchno,z,i,lower_cohort_switch
endif
if(promswitch == 1.and.associated(currentPatch%tallest))then
! write(fates_log(),*) 'cohorts',currentCohort%pft,currentCohort%indexnumber,currentPatch%patchno, &
! write(fates_log(),*) 'cohorts',currentCohort%pft,currentPatch%patchno, &
!currentCohort%c_area
endif
enddo !arealayer loop
Expand Down
28 changes: 15 additions & 13 deletions biogeochem/EDCohortDynamicsMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ module EDCohortDynamicsMod
! !USES:
use abortutils , only : endrun
use FatesGlobals , only : fates_log
use FatesGlobals , only : freq_day
use FatesConstantsMod , only : r8 => fates_r8
use FatesConstantsMod , only : fates_unset_int
use shr_log_mod , only : errMsg => shr_log_errMsg
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, maxcohortsperpatch, udata
use EDtypesMod , only : ncwd, maxcohortsperpatch
use EDtypesMod , only : sclass_ed,nlevsclass_ed,AREA
use EDtypesMod , only : min_npm2, min_nppatch, min_n_safemath
!
Expand Down Expand Up @@ -73,7 +75,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 +83,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 @@ -109,7 +111,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 @@ -221,6 +223,7 @@ subroutine allocate_live_biomass(cc_p,mode)
! Use different proportions if the leaves are on vs off
if(leaves_off_switch==0)then


new_bl = currentcohort%balive*leaf_frac

new_br = pftcon%froot_leaf(ft) * (currentcohort%balive + currentcohort%laimemory) * leaf_frac
Expand All @@ -233,13 +236,13 @@ subroutine allocate_live_biomass(cc_p,mode)
if(mode==1)then

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

currentcohort%npp_froot = currentcohort%npp_froot + &
max(0._r8,new_br - currentcohort%br) / udata%deltat
currentcohort%npp_bsw = max(0._r8,new_bsw - currentcohort%bsw)/udata%deltat
max(0._r8,new_br - currentcohort%br) / freq_day

currentcohort%npp_bsw = max(0.0_r8, new_bsw - currentcohort%bsw)/freq_day

currentcohort%npp_bdead = currentCohort%dbdeaddt

end if
Expand Down Expand Up @@ -271,9 +274,9 @@ subroutine allocate_live_biomass(cc_p,mode)
if(mode==1)then

currentcohort%npp_froot = currentcohort%npp_froot + &
max(0.0_r8,new_br-currentcohort%br)/udata%deltat
max(0.0_r8,new_br-currentcohort%br)/freq_day

currentcohort%npp_bsw = max(0.0_r8, new_bsw-currentcohort%bsw)/udata%deltat
currentcohort%npp_bsw = max(0.0_r8, new_bsw-currentcohort%bsw)/freq_day

currentcohort%npp_bdead = currentCohort%dbdeaddt

Expand Down Expand Up @@ -1008,8 +1011,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 Down
34 changes: 17 additions & 17 deletions biogeochem/EDGrowthFunctionsMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module EDGrowthFunctionsMod
! ============================================================================

use shr_kind_mod , only : r8 => shr_kind_r8
use clm_varctl , only : iulog
use FatesGlobals , only : fates_log
use pftconMod , only : pftcon
use EDEcophysContype , only : EDecophyscon
use EDTypesMod , only : ed_cohort_type, cp_nlevcan, dinc_ed
Expand Down Expand Up @@ -76,7 +76,7 @@ real(r8) function Hite( cohort_in )
c = 0.37_r8

if(cohort_in%dbh <= 0._r8)then
write(iulog,*) 'ED: dbh less than zero problem!',cohort_in%indexnumber
write(fates_log(),*) 'ED: dbh less than zero problem!'
cohort_in%dbh = 0.1_r8
endif

Expand Down Expand Up @@ -106,7 +106,7 @@ real(r8) function Bleaf( cohort_in )
real(r8) :: slascaler ! changes the target biomass according to the SLA

if(cohort_in%dbh < 0._r8.or.cohort_in%pft == 0.or.cohort_in%dbh > 1000.0_r8)then
write(iulog,*) 'problems in bleaf',cohort_in%dbh,cohort_in%pft
write(fates_log(),*) 'problems in bleaf',cohort_in%dbh,cohort_in%pft
endif

if(cohort_in%dbh <= EDecophyscon%max_dbh(cohort_in%pft))then
Expand All @@ -117,7 +117,7 @@ real(r8) function Bleaf( cohort_in )
slascaler = 0.03_r8/pftcon%slatop(cohort_in%pft)
bleaf = bleaf * slascaler

!write(iulog,*) 'bleaf',bleaf, slascaler,cohort_in%pft
!write(fates_log(),*) 'bleaf',bleaf, slascaler,cohort_in%pft

!Adjust for canopies that have become so deep that their bottom layer is not producing any carbon...
!nb this will change the allometry and the effects of this remain untested. RF. April 2014
Expand All @@ -141,7 +141,7 @@ real(r8) function tree_lai( cohort_in )
real(r8) :: slat ! the sla of the top leaf layer. m2/kgC

if( cohort_in%bl < 0._r8 .or. cohort_in%pft == 0 ) then
write(iulog,*) 'problem in treelai',cohort_in%bl,cohort_in%pft
write(fates_log(),*) 'problem in treelai',cohort_in%bl,cohort_in%pft
endif

if( cohort_in%status_coh == 2 ) then ! are the leaves on?
Expand All @@ -162,7 +162,7 @@ real(r8) function tree_lai( cohort_in )
! at the moments cp_nlevcan default is 40, which is very large, so exceeding this would clearly illustrate a
! huge error
if(cohort_in%treelai > cp_nlevcan*dinc_ed)then
write(iulog,*) 'too much lai' , cohort_in%treelai , cohort_in%pft , cp_nlevcan * dinc_ed
write(fates_log(),*) 'too much lai' , cohort_in%treelai , cohort_in%pft , cp_nlevcan * dinc_ed
endif

return
Expand All @@ -186,7 +186,7 @@ real(r8) function tree_sai( cohort_in )
sai_scaler = 0.05_r8 ! here, a high biomass of 20KgC per m2 gives us a high SAI of 1.0.

if( cohort_in%bdead < 0._r8 .or. cohort_in%pft == 0 ) then
write(iulog,*) 'problem in treesai',cohort_in%bdead,cohort_in%pft
write(fates_log(),*) 'problem in treesai',cohort_in%bdead,cohort_in%pft
endif

cohort_in%c_area = c_area(cohort_in) ! call the tree area
Expand All @@ -199,7 +199,7 @@ real(r8) function tree_sai( cohort_in )
! at the moments cp_nlevcan default is 40, which is very large, so exceeding this would clearly illustrate a
! huge error
if(cohort_in%treesai > cp_nlevcan*dinc_ed)then
write(iulog,*) 'too much sai' , cohort_in%treesai , cohort_in%pft , cp_nlevcan * dinc_ed
write(fates_log(),*) 'too much sai' , cohort_in%treesai , cohort_in%pft , cp_nlevcan * dinc_ed
endif

return
Expand All @@ -223,13 +223,13 @@ real(r8) function c_area( cohort_in )
real(r8) :: dbh ! Tree diameter at breat height. cm.

if (DEBUG_growth) then
write(iulog,*) 'z_area 1',cohort_in%dbh,cohort_in%pft
write(iulog,*) 'z_area 2',EDecophyscon%max_dbh
write(iulog,*) 'z_area 3',pftcon%woody
write(iulog,*) 'z_area 4',cohort_in%n
write(iulog,*) 'z_area 5',cohort_in%patchptr%spread
write(iulog,*) 'z_area 6',cohort_in%canopy_layer
write(iulog,*) 'z_area 7',ED_val_grass_spread
write(fates_log(),*) 'z_area 1',cohort_in%dbh,cohort_in%pft
write(fates_log(),*) 'z_area 2',EDecophyscon%max_dbh
write(fates_log(),*) 'z_area 3',pftcon%woody
write(fates_log(),*) 'z_area 4',cohort_in%n
write(fates_log(),*) 'z_area 5',cohort_in%patchptr%spread
write(fates_log(),*) 'z_area 6',cohort_in%canopy_layer
write(fates_log(),*) 'z_area 7',ED_val_grass_spread
end if

dbh = min(cohort_in%dbh,EDecophyscon%max_dbh(cohort_in%pft))
Expand Down Expand Up @@ -371,8 +371,8 @@ subroutine mortality_rates( cohort_in,cmort,hmort,bmort )
endif

else
write(iulog,*) 'dbh problem in mortality_rates', &
cohort_in%dbh,cohort_in%pft,cohort_in%n,cohort_in%canopy_layer,cohort_in%indexnumber
write(fates_log(),*) 'dbh problem in mortality_rates', &
cohort_in%dbh,cohort_in%pft,cohort_in%n,cohort_in%canopy_layer
endif

!mortality_rates = bmort + hmort + cmort
Expand Down
14 changes: 7 additions & 7 deletions biogeochem/EDPatchDynamicsMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ module EDPatchDynamicsMod
use shr_kind_mod , only : r8 => shr_kind_r8;
use shr_infnan_mod , only : nan => shr_infnan_nan, assignment(=)
use clm_varctl , only : iulog
use FatesGlobals , only : freq_day
use pftconMod , only : pftcon
use EDCohortDynamicsMod , only : fuse_cohorts, sort_cohorts, insert_cohort
use EDtypesMod , only : ncwd, n_dbh_bins, ntol, numpft_ed, area, dbhmax, maxPatchesPerCol
use EDTypesMod , only : ed_site_type, ed_patch_type, ed_cohort_type, udata
use EDTypesMod , only : ed_site_type, ed_patch_type, ed_cohort_type
use EDTypesMod , only : min_patch_area, cp_numlevgrnd, cp_numSWb
!
implicit none
Expand Down Expand Up @@ -45,7 +46,6 @@ subroutine disturbance_rates( site_in)
!
! !USES:
use EDGrowthFunctionsMod , only : c_area, mortality_rates
use EDTypesMod , only : udata
!
! !ARGUMENTS:
type(ed_site_type) , intent(inout), target :: site_in
Expand Down Expand Up @@ -85,7 +85,7 @@ subroutine disturbance_rates( site_in)
if(currentCohort%canopy_layer == 1)then

currentPatch%disturbance_rates(1) = currentPatch%disturbance_rates(1) + &
min(1.0_r8,currentCohort%dmort)*udata%deltat*currentCohort%c_area/currentPatch%area
min(1.0_r8,currentCohort%dmort)*freq_day*currentCohort%c_area/currentPatch%area

endif

Expand Down Expand Up @@ -271,7 +271,7 @@ subroutine spawn_patches( currentSite )
! because this is the part of the original patch where no trees have actually fallen
! The diagnostic cmort,bmort and hmort rates have already been saved

currentCohort%n = currentCohort%n * (1.0_r8 - min(1.0_r8,currentCohort%dmort * udata%deltat))
currentCohort%n = currentCohort%n * (1.0_r8 - min(1.0_r8,currentCohort%dmort * freq_day))

nc%n = 0.0_r8 ! kill all of the trees who caused the disturbance.
nc%cmort = nan ! The mortality diagnostics are set to nan because the cohort should dissappear
Expand All @@ -298,7 +298,7 @@ subroutine spawn_patches( currentSite )
! so with the number density must come the effective mortality rates.

nc%fmort = 0.0_r8 ! Should had also been zero in the donor
nc%imort = ED_val_understorey_death/udata%deltat ! This was zero in the donor
nc%imort = ED_val_understorey_death/freq_day ! This was zero in the donor
nc%cmort = currentCohort%cmort
nc%hmort = currentCohort%hmort
nc%bmort = currentCohort%bmort
Expand Down Expand Up @@ -336,7 +336,7 @@ subroutine spawn_patches( currentSite )
! loss of individual from fire in new patch.
nc%n = nc%n * (1.0_r8 - currentCohort%fire_mort)

nc%fmort = currentCohort%fire_mort/udata%deltat
nc%fmort = currentCohort%fire_mort/freq_day
nc%imort = 0.0_r8
nc%cmort = currentCohort%cmort
nc%hmort = currentCohort%hmort
Expand Down Expand Up @@ -716,7 +716,7 @@ subroutine mortality_litter_fluxes(cp_target, new_patch_target, patch_site_aread
!currentCohort%dmort = mortality_rates(currentCohort)
!the disturbance calculations are done with the previous n, c_area and d_mort. So it's probably &
!not right to recalcualte dmort here.
canopy_dead = currentCohort%n * min(1.0_r8,currentCohort%dmort * udata%deltat)
canopy_dead = currentCohort%n * min(1.0_r8,currentCohort%dmort * freq_day)

currentPatch%canopy_mortality_woody_litter = currentPatch%canopy_mortality_woody_litter + &
canopy_dead*(currentCohort%bdead+currentCohort%bsw)
Expand Down
Loading

0 comments on commit 19ec489

Please sign in to comment.