Skip to content

Commit ff84522

Browse files
authored
Merge pull request #1317 from adrifoster/patch_testing
Update to cohort insertion and sorting routines
2 parents fea5f0a + f24f5b5 commit ff84522

35 files changed

+2472
-580
lines changed

biogeochem/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ list(APPEND fates_sources
44
FatesCohortMod.F90
55
FatesAllometryMod.F90
66
DamageMainMod.F90
7+
EDCohortDynamicsMod.F90
78
FatesPatchMod.F90)
89

910
sourcelist_to_parent(fates_sources)

biogeochem/EDCohortDynamicsMod.F90

Lines changed: 104 additions & 377 deletions
Large diffs are not rendered by default.

biogeochem/EDPatchDynamicsMod.F90

Lines changed: 18 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module EDPatchDynamicsMod
99
use EDPftvarcon , only : EDPftvarcon_inst
1010
use EDPftvarcon , only : GetDecompyFrac
1111
use PRTParametersMod , only : prt_params
12-
use EDCohortDynamicsMod , only : fuse_cohorts, sort_cohorts, insert_cohort
12+
use EDCohortDynamicsMod , only : fuse_cohorts
1313
use EDTypesMod , only : area_site => area
1414
use ChecksBalancesMod , only : PatchMassStock
1515
use FatesLitterMod , only : ncwd
@@ -516,17 +516,13 @@ subroutine spawn_patches( currentSite, bc_in)
516516
type (fates_patch_type) , pointer :: currentPatch
517517
type (fates_cohort_type), pointer :: currentCohort
518518
type (fates_cohort_type), pointer :: nc
519-
type (fates_cohort_type), pointer :: storesmallcohort
520-
type (fates_cohort_type), pointer :: storebigcohort
521519
real(r8) :: site_areadis_primary ! total area disturbed (to primary forest) in m2 per site per day
522520
real(r8) :: site_areadis_secondary ! total area disturbed (to secondary forest) in m2 per site per day
523521
real(r8) :: patch_site_areadis ! total area disturbed in m2 per patch per day
524522
real(r8) :: site_areadis ! total site area disturbed in m2 per day
525523
real(r8) :: age ! notional age of this patch in years
526524
integer :: el ! element loop index
527525
integer :: pft ! pft loop index
528-
integer :: tnull ! is there a tallest cohort?
529-
integer :: snull ! is there a shortest cohort?
530526
integer :: levcan ! canopy level
531527
real(r8) :: leaf_c ! leaf carbon [kg]
532528
real(r8) :: fnrt_c ! fineroot carbon [kg]
@@ -562,9 +558,6 @@ subroutine spawn_patches( currentSite, bc_in)
562558
logical :: buffer_patch_used
563559
!---------------------------------------------------------------------
564560

565-
storesmallcohort => null() ! storage of the smallest cohort for insertion routine
566-
storebigcohort => null() ! storage of the largest cohort for insertion routine
567-
568561
if (hlm_use_nocomp .eq. itrue) then
569562
min_nocomp_pft = 0
570563
max_nocomp_pft = numpft
@@ -1249,30 +1242,7 @@ subroutine spawn_patches( currentSite, bc_in)
12491242
! if some plants in the new temporary cohort survived the transfer to the new patch,
12501243
! then put the cohort into the linked list.
12511244
cohort_n_gt_zero: if (nc%n > 0.0_r8) then
1252-
storebigcohort => newPatch%tallest
1253-
storesmallcohort => newPatch%shortest
1254-
if(associated(newPatch%tallest))then
1255-
tnull = 0
1256-
else
1257-
tnull = 1
1258-
newPatch%tallest => nc
1259-
nc%taller => null()
1260-
endif
1261-
1262-
if(associated(newPatch%shortest))then
1263-
snull = 0
1264-
else
1265-
snull = 1
1266-
newPatch%shortest => nc
1267-
nc%shorter => null()
1268-
endif
1269-
1270-
call insert_cohort(newPatch, nc, newPatch%tallest, newPatch%shortest, &
1271-
tnull, snull, storebigcohort, storesmallcohort)
1272-
1273-
newPatch%tallest => storebigcohort
1274-
newPatch%shortest => storesmallcohort
1275-
1245+
call newPatch%InsertCohort(nc)
12761246
else
12771247
! sadly, no plants in the cohort survived. on the bright side, we can deallocate their memory.
12781248
call nc%FreeMemory()
@@ -1285,8 +1255,10 @@ subroutine spawn_patches( currentSite, bc_in)
12851255

12861256
currentCohort => currentCohort%taller
12871257
enddo cohortloop
1258+
call newPatch%ValidateCohorts()
12881259

1289-
call sort_cohorts(currentPatch)
1260+
call currentPatch%SortCohorts()
1261+
call currentPatch%ValidateCohorts()
12901262

12911263
!update area of donor patch
12921264
oldarea = currentPatch%area
@@ -1317,7 +1289,8 @@ subroutine spawn_patches( currentSite, bc_in)
13171289
call terminate_cohorts(currentSite, currentPatch, 1,16,bc_in)
13181290
call fuse_cohorts(currentSite,currentPatch, bc_in)
13191291
call terminate_cohorts(currentSite, currentPatch, 2,16,bc_in)
1320-
call sort_cohorts(currentPatch)
1292+
call currentPatch%SortCohorts()
1293+
call currentPatch%ValidateCohorts()
13211294

13221295
end if areadis_gt_zero_if ! if ( newPatch%area > nearzero ) then
13231296

@@ -1344,7 +1317,8 @@ subroutine spawn_patches( currentSite, bc_in)
13441317
call terminate_cohorts(currentSite, newPatch, 1,17, bc_in)
13451318
call fuse_cohorts(currentSite,newPatch, bc_in)
13461319
call terminate_cohorts(currentSite, newPatch, 2,17, bc_in)
1347-
call sort_cohorts(newPatch)
1320+
call newPatch%SortCohorts()
1321+
call newPatch%ValidateCohorts()
13481322
endif
13491323

13501324

@@ -1675,11 +1649,7 @@ subroutine split_patch(currentSite, currentPatch, new_patch, fraction_to_keep, a
16751649
! !LOCAL VARIABLES:
16761650
integer :: el ! element loop index
16771651
type (fates_cohort_type), pointer :: nc
1678-
type (fates_cohort_type), pointer :: storesmallcohort
1679-
type (fates_cohort_type), pointer :: storebigcohort
16801652
type (fates_cohort_type), pointer :: currentCohort
1681-
integer :: tnull ! is there a tallest cohort?
1682-
integer :: snull ! is there a shortest cohort?
16831653
integer :: pft
16841654
real(r8) :: temp_area
16851655

@@ -1746,34 +1716,14 @@ subroutine split_patch(currentSite, currentPatch, new_patch, fraction_to_keep, a
17461716
! loss of individuals from source patch due to area shrinking
17471717
currentCohort%n = currentCohort%n * fraction_to_keep
17481718

1749-
storebigcohort => new_patch%tallest
1750-
storesmallcohort => new_patch%shortest
1751-
if(associated(new_patch%tallest))then
1752-
tnull = 0
1753-
else
1754-
tnull = 1
1755-
new_patch%tallest => nc
1756-
nc%taller => null()
1757-
endif
1758-
1759-
if(associated(new_patch%shortest))then
1760-
snull = 0
1761-
else
1762-
snull = 1
1763-
new_patch%shortest => nc
1764-
nc%shorter => null()
1765-
endif
1766-
1767-
call insert_cohort(new_patch, nc, new_patch%tallest, new_patch%shortest, &
1768-
tnull, snull, storebigcohort, storesmallcohort)
1769-
1770-
new_patch%tallest => storebigcohort
1771-
new_patch%shortest => storesmallcohort
1719+
call new_patch%InsertCohort(nc)
17721720

17731721
currentCohort => currentCohort%taller
17741722
enddo ! currentCohort
1723+
call new_patch%ValidateCohorts()
17751724

1776-
call sort_cohorts(currentPatch)
1725+
call currentPatch%SortCohorts()
1726+
call currentPatch%ValidateCohorts()
17771727

17781728
!update area of donor patch
17791729
currentPatch%area = currentPatch%area - temp_area
@@ -3116,7 +3066,8 @@ subroutine fuse_patches( csite, bc_in )
31163066
tmpptr => currentPatch%older
31173067
call fuse_2_patches(csite, currentPatch, tpp)
31183068
call fuse_cohorts(csite,tpp, bc_in)
3119-
call sort_cohorts(tpp)
3069+
call tpp%SortCohorts()
3070+
call tpp%ValidateCohorts()
31203071
currentPatch => tmpptr
31213072

31223073
!------------------------------------------------------------------------!
@@ -3238,10 +3189,7 @@ subroutine fuse_2_patches(csite, dp, rp)
32383189
! !LOCAL VARIABLES:
32393190
type (fates_cohort_type), pointer :: currentCohort ! Current Cohort
32403191
type (fates_cohort_type), pointer :: nextc ! Remembers next cohort in list
3241-
type (fates_cohort_type), pointer :: storesmallcohort
3242-
type (fates_cohort_type), pointer :: storebigcohort
32433192
integer :: c,p !counters for pft and litter size class.
3244-
integer :: tnull,snull ! are the tallest and shortest cohorts associated?
32453193
integer :: el ! loop counting index for elements
32463194
integer :: pft ! loop counter for pfts
32473195
type(fates_patch_type), pointer :: youngerp ! pointer to the patch younger than donor
@@ -3321,31 +3269,8 @@ subroutine fuse_2_patches(csite, dp, rp)
33213269
endif
33223270

33233271
do while(associated(dp%shortest))
3324-
3325-
storebigcohort => rp%tallest
3326-
storesmallcohort => rp%shortest
3327-
3328-
if(associated(rp%tallest))then
3329-
tnull = 0
3330-
else
3331-
tnull = 1
3332-
rp%tallest => currentCohort
3333-
endif
3334-
3335-
if(associated(rp%shortest))then
3336-
snull = 0
3337-
else
3338-
snull = 1
3339-
rp%shortest => currentCohort
3340-
endif
3341-
3342-
call insert_cohort(rp, currentCohort, rp%tallest, rp%shortest, &
3343-
tnull, snull, storebigcohort, storesmallcohort)
3344-
3345-
rp%tallest => storebigcohort
3346-
rp%shortest => storesmallcohort
3347-
3348-
!currentCohort%patchptr => rp
3272+
3273+
call rp%InsertCohort(currentCohort)
33493274

33503275
currentCohort => nextc
33513276

@@ -3356,6 +3281,7 @@ subroutine fuse_2_patches(csite, dp, rp)
33563281
endif
33573282

33583283
enddo !cohort
3284+
call rp%ValidateCohorts()
33593285
endif !are there any cohorts?
33603286

33613287
call patch_pft_size_profile(rp) ! Recalculate the patch size profile for the resulting patch

biogeochem/EDPhysiologyMod.F90

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module EDPhysiologyMod
4343
use EDPftvarcon , only : GetDecompyFrac
4444
use FatesInterfaceTypesMod, only : bc_in_type
4545
use FatesInterfaceTypesMod, only : bc_out_type
46-
use EDCohortDynamicsMod , only : create_cohort, sort_cohorts
46+
use EDCohortDynamicsMod , only : create_cohort
4747
use EDCohortDynamicsMod , only : InitPRTObject
4848
use FatesAllometryMod , only : tree_lai_sai
4949
use FatesAllometryMod , only : leafc_from_treelai
@@ -681,7 +681,7 @@ subroutine trim_canopy( currentSite )
681681
! Add debug diagnstic output to determine which patch
682682
if (debug) then
683683
write(fates_log(),*) 'Current patch:', ipatch
684-
write(fates_log(),*) 'Current patch cohorts:', currentPatch%countcohorts
684+
write(fates_log(),*) 'Current patch cohorts:', currentPatch%num_cohorts
685685
endif
686686

687687
icohort = 1
@@ -2791,6 +2791,7 @@ subroutine recruitment(currentSite, currentPatch, bc_in)
27912791
endif any_recruits
27922792
endif use_this_pft_if
27932793
enddo !pft loop
2794+
call currentPatch%ValidateCohorts()
27942795
end subroutine recruitment
27952796

27962797
! ======================================================================================

biogeochem/FatesCohortMod.F90

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module FatesCohortMod
5151

5252
implicit none
5353
private
54-
54+
5555
! PARAMETERS
5656
character(len=*), parameter, private :: sourcefile = __FILE__
5757

@@ -77,7 +77,6 @@ module FatesCohortMod
7777
!---------------------------------------------------------------------------
7878

7979
! VEGETATION STRUCTURE
80-
8180
integer :: pft ! pft index
8281
real(r8) :: n ! number of individuals in cohort per 'area' (10000m2 default) [/m2]
8382
real(r8) :: dbh ! diameter at breast height [cm]
@@ -450,7 +449,7 @@ subroutine NanValues(this)
450449
this%cambial_mort = nan
451450
this%crownfire_mort = nan
452451
this%fire_mort = nan
453-
452+
454453
end subroutine NanValues
455454

456455
!===========================================================================
@@ -547,7 +546,7 @@ subroutine Create(this, prt, pft, nn, height, coage, dbh, status, &
547546
!
548547
! DESCRIPTION:
549548
! set up values for a newly created cohort
550-
549+
551550
! ARGUMENTS
552551
class(fates_cohort_type), intent(inout), target :: this ! cohort object
553552
class(prt_vartypes), intent(inout), pointer :: prt ! The allocated PARTEH object
@@ -574,7 +573,7 @@ subroutine Create(this, prt, pft, nn, height, coage, dbh, status, &
574573

575574
! initialize cohort
576575
call this%Init(prt)
577-
576+
578577
! set values
579578
this%pft = pft
580579
this%crowndamage = crowndamage

0 commit comments

Comments
 (0)