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

Dynamic roots md bugfix rkupdates #2

Merged
Changes from 1 commit
Commits
Show all changes
232 commits
Select commit Hold shift + click to select a range
d9f2ca0
roll back snow burial change
rosiealice Apr 30, 2020
3fc6a94
initial set of nocomp changes. doesn't work yet
rosiealice Apr 30, 2020
a08cbcd
phase 2 of nocomp mods
rosiealice May 1, 2020
3f92ed8
first pass through spawn_patches
rosiealice May 1, 2020
db960fd
added initialization mods
rosiealice May 4, 2020
782b61a
debug in EPD. will need rolling back
rosiealice May 4, 2020
ff0cf19
init fixes. gets out of init loop
rosiealice May 6, 2020
92f547a
rolling back changes in EDPatchdynamics to allow debugging of EDInit …
rosiealice May 7, 2020
ca1a60b
this version of edinit works. committing before cleaning up
rosiealice May 7, 2020
ed08bf1
modify number of patches and patch initialization
rosiealice May 14, 2020
8ed597a
make disturbance arrays in EPD
rosiealice May 15, 2020
7e77c3d
modifications to spawn patches for PFT array disturbance
rosiealice May 15, 2020
b48de6a
modifications to terminate_patches for PFT loops
rosiealice May 19, 2020
8e8e91f
reformatting the PFT loop in spawn patches
rosiealice May 20, 2020
2b08a8d
removing write statements from EDInit
rosiealice May 20, 2020
30659c9
fixing issues with area in spawn patches2667
rosiealice May 20, 2020
02db378
fixed references to currentPatch in terminate patches
rosiealice May 20, 2020
34f3532
added olderp ref to cp loop in terminate patches
rosiealice May 20, 2020
ce71fda
located error in the small size tolerances. Eraase <1% patches to fix
rosiealice May 20, 2020
9ad82a7
added filter to init cohorts
rosiealice May 22, 2020
ba0aca6
fixed memory leak. removed write statements
rosiealice May 25, 2020
7dda68f
changes to make one pft per patch
rosiealice May 25, 2020
5dcef9f
turning off patch dynamics allows nocomp to run
rosiealice May 26, 2020
1e1f013
fixing error in spawn_patches
rosiealice May 26, 2020
630d571
initial go at converstion matrix. Hard wired, e dimensional
rosiealice May 26, 2020
1e4d30c
fixing patch dynamics bug in EDmain
rosiealice May 26, 2020
2ee7316
fixing erroneous error check
rosiealice May 27, 2020
aa620f9
2D pft mapping array
rosiealice May 27, 2020
a69ac89
implement new hlm_pft_map 2D parameter
rosiealice May 27, 2020
6927dec
adding usage of hlm_pft_map
rosiealice May 27, 2020
f0170fd
added default values for hlm_pft_map to the parameter file
rosiealice May 27, 2020
ea3c635
modify EDINIT to allow HLM_pftno from parameter file to dictate initi…
rosiealice Jun 3, 2020
f7e876d
reverting spawn patches back to master and therefore removing all the…
rosiealice Jul 10, 2020
4aace9f
merged into charlies fates_harvest_offmaster branch, with merge commi…
rosiealice Jul 10, 2020
80a9cdc
Merge branch 'master' of https://github.com/NGEET/fates into new_fate…
rosiealice Sep 4, 2020
c4ae298
comment in EDInit
rosiealice Sep 7, 2020
cceff87
fixed apparent merge conflict in patch dynamics
rosiealice Sep 7, 2020
e0f3481
modifications to write statements in EDInit
rosiealice Sep 7, 2020
312766e
a few more comments and a small fix to merge conflicts
rosiealice Sep 7, 2020
0a5a866
added patch ID's to the new create_patch calls from landuse mods
rosiealice Sep 7, 2020
0d72001
added comment to restart interface
rosiealice Sep 7, 2020
91ee991
added switch names to FatesInterfaceTypesMod.F90
rosiealice Sep 7, 2020
f146bc1
assert that patch dynamics are off when SP mode is on
rosiealice Sep 7, 2020
8d099f3
allocate SP input variables in FatesInterfaceMod
rosiealice Sep 8, 2020
365561f
defined SP input variables in FatesInterfaceTypesMod
rosiealice Sep 8, 2020
b128762
changed nocmp and SP transfer from HLM to active in FatesInterfaceMod…
rosiealice Sep 8, 2020
94b7aff
added check so that nocomp needs to be on for SP to work in FatesInte…
rosiealice Sep 8, 2020
87cd492
changed dimensions of SP input variables to maxpft
rosiealice Sep 8, 2020
aeec142
fixed a bunch of annoying spacing in EDInit
rosiealice Sep 8, 2020
4d46a8b
allocated FATES site SP input variables with PFT arrays
rosiealice Sep 8, 2020
e38c726
turning off cohort and patch dynamics in SP mode
rosiealice Sep 8, 2020
3118ea3
added call to satellite_phenology routine in EDMain
rosiealice Sep 8, 2020
406c72b
begun satellite_phenology subroutine
rosiealice Sep 8, 2020
552a0ed
added weighting code for SP variables. need to finish
rosiealice Sep 8, 2020
b163fbd
modified comments for pft_areafrac calculation
rosiealice Sep 9, 2020
12310b0
added normalization to SP variable weighting. Changed indents
rosiealice Sep 9, 2020
cf3ed64
added leafc_from_treelai to FatesAllometryMod
rosiealice Sep 9, 2020
21e09a4
removed refences to canopy_lai in leafc_from_treelai
rosiealice Sep 9, 2020
c501b56
added call to leafc_from_treelai
rosiealice Sep 9, 2020
d149ae6
added calls to allometry functions to estimate cohort properties
rosiealice Sep 9, 2020
57ba8a3
added fixed value of spread to c_area
rosiealice Sep 10, 2020
ae27d49
added setstate call for leaf carbon in satellite_phenology
rosiealice Sep 10, 2020
d5d4466
added hlm_use_nocomp to FatesInterfaceTypesMod
rosiealice Sep 10, 2020
fda950c
broadcast nocomp parameter in FatesInterfaceMod.F90
rosiealice Sep 10, 2020
0d84faf
uncomment nocomp statement in FatesInterfaceMod
rosiealice Sep 11, 2020
f8f4867
remove typo in EDInitMod
rosiealice Sep 11, 2020
11961e4
removed extra write statements from EDPatchDynamicsMod
rosiealice Sep 11, 2020
fe2169f
added comment on EDPatchDynamicsMod
rosiealice Sep 11, 2020
812aa3b
debugging
rosiealice Sep 11, 2020
a49c7dd
changed SP input variable names in FatesInterfaceTypesMod
rosiealice Sep 11, 2020
875c9d4
debugging EDPhysiologyMod.F90
rosiealice Sep 11, 2020
e4762b2
debugging main/EDMainMod.F90
rosiealice Sep 11, 2020
a33655a
read use_sp in FatesInterfaceMod.F90
rosiealice Sep 11, 2020
97b39f1
commenting out balance check
rosiealice Sep 11, 2020
0028a57
turned off balance check calls in SP mode in EDMain
rosiealice Sep 14, 2020
6bfa6b2
check for hlm_pft_area
rosiealice Sep 14, 2020
eefda99
merge conflicts on EDPhysiology
rosiealice Sep 14, 2020
9eefda8
check for hlm_pft_area
rosiealice Sep 14, 2020
b5e9bcd
Update main/EDInitMod.F90
rosiealice Sep 14, 2020
ae5582d
Typo main/EDInitMod.F90
rosiealice Sep 14, 2020
a812a35
Small number tolerance in main/EDInitMod.F90
rosiealice Sep 14, 2020
5a46423
removed now irrelevant comment in FatesInterfaceMod.F90
rosiealice Sep 14, 2020
95737dd
minor typo in biogeochem/EDPatchDynamicsMod.F90
rosiealice Sep 14, 2020
9f38e0c
comment in biogeochem/EDPatchDynamicsMod.F90
rosiealice Sep 14, 2020
74a4fe7
typo in EDPftvarcon.F90
rosiealice Sep 14, 2020
68d8825
Merge branch 'nocomp_PR_branch' of https://github.com/rosiealice/fate…
rosiealice Sep 14, 2020
6b1d5f2
removing modifications from terminate_patches
rosiealice Sep 14, 2020
a0efc39
endif statements in teminate patches
rosiealice Sep 14, 2020
948eb2a
spacing in terminate patches
rosiealice Sep 14, 2020
025aabf
remove set_patchno call
rosiealice Sep 14, 2020
1f316f9
merge conflicts from nocomp branch
rosiealice Sep 14, 2020
d0a5256
code to manage bare gound in SP mode
rosiealice Sep 14, 2020
573dad5
debugging after merge
rosiealice Sep 14, 2020
867ff49
fixing bare ground initialization errors. now runs
rosiealice Sep 15, 2020
49d1eee
moved SP check on totalbalancecheck into subroutine
rosiealice Sep 16, 2020
40686b4
changes to EDPhysiology to get treelai calcas right
rosiealice Sep 17, 2020
47a0057
changes to FatesAllometryMod.F90 to get treelai right
rosiealice Sep 17, 2020
b7fa39c
added check for no cohorts in bare patch
rosiealice Sep 17, 2020
d755c44
added check to avoid copying cohorts in sp mode
rosiealice Sep 17, 2020
06db829
remove write
rosiealice Sep 17, 2020
8c8b559
changed copy cohort error
rosiealice Sep 18, 2020
c5d084a
checks in EDcanopystructure
rosiealice Sep 21, 2020
95089d1
added carea to create_cohort
rosiealice Sep 21, 2020
4202f4b
added carea to create_cohort in inventory
rosiealice Sep 21, 2020
003a7a3
updates to satelllite phenology in edphys
rosiealice Sep 21, 2020
f34b399
large EDInit updates. now runs to third ts
rosiealice Sep 21, 2020
77729ab
modified initialization of SP variables
rosiealice Sep 28, 2020
5fb8de8
seperate loops in satellite_phenology
rosiealice Sep 28, 2020
1afadcc
modified nan check
rosiealice Sep 28, 2020
aec6d70
merged to master
rosiealice Sep 28, 2020
aa04775
fixing compile errors in FatesAllometry
rosiealice Sep 29, 2020
e104855
fixing compiling/merge errors in EDpftvarcn
rosiealice Sep 29, 2020
ee3ce52
fixing last compiling/merge errors in EDpftvarcn
rosiealice Sep 29, 2020
1b96395
fixing merge errors in EDInit
rosiealice Sep 29, 2020
0635560
turning off trim canopy
rosiealice Sep 29, 2020
96abe15
setting pa label
rosiealice Oct 5, 2020
8eec520
made pft_label_pa variable
rosiealice Oct 5, 2020
5796f36
added checks on all FATES loops that use IFP to not include bare grou…
rosiealice Oct 8, 2020
6b2d062
added modificaitons to set_patchno to make bareground patches have a …
rosiealice Oct 8, 2020
5893d97
changes to EDCanopystructure. Running at this point with LAI OK and G…
rosiealice Oct 8, 2020
e4032f9
modified hlm_pft_map to have correct relation between fates and hlm pfts
rosiealice Oct 30, 2020
df2173d
copying minor changes from nocomp code review in EDInit
rosiealice Nov 5, 2020
c2a18bb
modified comments in canopystructure
rosiealice Nov 5, 2020
f8de4d8
tidying up CanopyStructure
rosiealice Nov 5, 2020
a1d8710
reverted aimin change
rosiealice Nov 5, 2020
efeadf1
removing redundant check from copycohort
rosiealice Nov 5, 2020
3c56759
minor fixes to spacing in patch dynamics
rosiealice Nov 5, 2020
49015da
added start_patch and removed pre-initpatch checks
rosiealice Nov 5, 2020
9bd54e3
modified error statements in canopystructure
rosiealice Nov 5, 2020
d6edbb3
modified area_pft units in nocomp mode
rosiealice Nov 5, 2020
abadd8d
adding check which requires SP mode to also use fixed_biogeog mode
rosiealice Nov 6, 2020
1b035ac
fixing issue with IFP bareground couting in defualt mode
rosiealice Nov 6, 2020
a7ad770
modifying comments in EDPhysiology
rosiealice Nov 6, 2020
ca81774
reverting canopy area error tolerance back to previous higher value
rosiealice Nov 13, 2020
2a7c346
updated ncvarsort.py and modify_fates_paramfile.py to work with new f…
ckoven Nov 20, 2020
5f55696
Update biogeochem/EDCanopyStructureMod.F90
rosiealice Nov 23, 2020
ef67e8c
Update biogeochem/EDCanopyStructureMod.F90 CDK2
rosiealice Nov 23, 2020
518b621
Update biogeochem/EDCanopyStructureMod.F90 CDK3
rosiealice Nov 23, 2020
90bbd1e
add currentPatch%nocomp_pft_label to log file HT
rosiealice Nov 23, 2020
7e4d62d
Update biogeochem/EDPhysiologyMod.F90 CDK5
rosiealice Nov 23, 2020
4d8af4a
remove use_sp statement from canopy structure routine
rosiealice Nov 23, 2020
64a08bf
Merge branch 'fates_sp_sept' of https://github.com/rosiealice/fates i…
rosiealice Nov 23, 2020
a396a83
add dummy n variable
rosiealice Nov 23, 2020
04b9e9d
indenting in fatesinterface
rosiealice Nov 23, 2020
e1129ce
Update main/FatesRestartInterfaceMod.F90 CDK6
rosiealice Nov 23, 2020
206a844
change comment. HT
rosiealice Nov 23, 2020
4611ded
Update biogeochem/EDPhysiologyMod.F90 HT1
rosiealice Nov 23, 2020
60dcff6
removed sumarea calcs from edphysiology
rosiealice Nov 24, 2020
12c6d6f
tidy up leafc_from_treelai function
rosiealice Nov 24, 2020
a9269df
moving negative check into small patch loop in edinit as per HT request
rosiealice Nov 24, 2020
4a67dd8
removed sp_patch_index
rosiealice Nov 24, 2020
1f19809
added cmments to area check in EDInit
rosiealice Nov 24, 2020
e9f0728
Merge branch 'fates_sp_sept' of https://github.com/rosiealice/fates i…
rosiealice Nov 24, 2020
9b31a8c
Update biogeochem/EDCohortDynamicsMod.F90 CDK7
rosiealice Nov 25, 2020
6a4dec9
indenting all of EDCanopyStructureMod.F90
rosiealice Nov 25, 2020
627b962
indenting all of EDInit
rosiealice Nov 25, 2020
125c850
editing comments for clarity from CDK/HT review
rosiealice Nov 25, 2020
1d3f4c0
indenting and comments in EDSurfaceAlbedoMod.F90
rosiealice Nov 25, 2020
543c4d7
indenting EDAccumulateFluxesMod.F90
rosiealice Nov 25, 2020
73e8799
indenting EDBtranMod.F90
rosiealice Nov 25, 2020
b24f468
indenting EDPhysiologyMod.F90
rosiealice Nov 25, 2020
74f33d5
biogeophys/FatesPlantHydraulicsMod.F90
rosiealice Nov 25, 2020
8b553d4
Update main/EDInitMod.F90 CDK8
rosiealice Nov 25, 2020
6dbca88
auto indenting all of FatesPlantRespPhotosynthMod.F90
rosiealice Nov 25, 2020
c49dc43
Merge branch 'fates_sp_sept' of https://github.com/rosiealice/fates i…
rosiealice Nov 25, 2020
ba597bd
ading comments on arbitrary initialization in SP mode
rosiealice Nov 25, 2020
dc02a57
Merge pull request #4 from ckoven/fates_sp_sept
rosiealice Nov 26, 2020
29d528b
comments on pft_areafracweighting from HT
rosiealice Nov 26, 2020
9f1d7e5
removing type in EDInit
rosiealice Nov 26, 2020
513b40f
Merge branch 'fates_sp_sept' of https://github.com/rosiealice/fates i…
rosiealice Nov 26, 2020
c7e4df8
merging conflicts
rosiealice Nov 26, 2020
56b0617
Merge tag 'sci.1.43.4_api.14.2.0' into fates_sp_sept-mergemaster2
glemieux Apr 9, 2021
d38a25a
cleaning up merge for successful build
glemieux Apr 9, 2021
0fc7a17
allocating sp_mode related variables to start at zero
glemieux Apr 12, 2021
588ac12
removing the nocomp_pft_label check as the was resulting in invalid z…
glemieux Apr 21, 2021
7fba81e
adding hui's logic to exclude sai calculation from lai during sp mode
glemieux May 10, 2021
1d215b8
adding sp mode check in create_cohort to avoid setting sai as well
glemieux May 17, 2021
62cbbe7
trying Hui's suggested fix per issue 745
glemieux May 25, 2021
f60e0ee
Merge pull request #5 from glemieux/fates_sp_sept-mm2-zeroidx-huimatch
rosiealice May 27, 2021
e9a5da9
removing nocomp pft label check in radiation restart update
glemieux Jun 2, 2021
58c33ee
correcting logic check for ST3 mode
glemieux Jun 3, 2021
d901f9f
removing redundeant newparea call and deallocation which was causing …
glemieux Jun 4, 2021
0010efe
adding c_area to restart interface
glemieux Jun 11, 2021
7fe7af7
adding instantaneous gpp and npp to restart
glemieux Jun 23, 2021
64c53d3
Revert "adding instantaneous gpp and npp to restart"
glemieux Jun 24, 2021
d987947
cleaning up old code
glemieux Jun 24, 2021
b87f252
more cleanup
glemieux Jun 24, 2021
3150bdc
Initialized a script that will take an existing cdl file and create a…
rgknox Jul 5, 2021
a7a8844
removed temporary text overrides for batch cdl converter
rgknox Jul 5, 2021
2704375
Added sorting to the batch parameter script
rgknox Jul 6, 2021
5730ced
adding restart variables for calculating area index profiles
glemieux Jul 9, 2021
3942a66
Merge tag 'sci.1.46.0_api.16.0.0' into fates_sp_sept_merge-api16
glemieux Jul 20, 2021
2c892f7
Updated the batchPatch and modify_fates_paramfile scripts to allow pa…
rgknox Jul 21, 2021
d00e61a
Merge tag 'sci.1.46.2_api.16.1.0' into fates_sp_sept_merge-api16-1
glemieux Jul 22, 2021
5b25b2b
fixing missing season_decid check in EDInitMod due to bad merge
glemieux Jul 22, 2021
3676b71
Merge branch 'fates_sp_sept_ersfix' into fates_sp_sept_merge-api16-1-…
glemieux Jul 23, 2021
bd58525
adding diagnostics
glemieux Aug 3, 2021
55e17e1
adding tlai_profile output to diagnostics
glemieux Aug 3, 2021
eb9b850
fixing duplicates from poor merge
glemieux Aug 5, 2021
f2c3156
adding frag scaler diag
glemieux Aug 5, 2021
a0f6624
Fixing no comp label check
glemieux Aug 5, 2021
9cc3e7c
fixedbiogeog passes bfb now
glemieux Aug 6, 2021
58a427e
Updates to enable scalars in the BatchPatch script, also some tweaks …
rgknox Aug 9, 2021
a5c2d9d
Update to the bci parameter patch file.
rgknox Aug 9, 2021
e065f7f
Updated notes on the bci patch xml file to include Koven et al. 2019
rgknox Aug 9, 2021
9e646dc
manually reverting diagnostic writes
glemieux Aug 12, 2021
d94ca1a
removing more diagnostics
glemieux Aug 12, 2021
ec99726
refactoring the linked list for zero patch area with nocomp
glemieux Aug 13, 2021
5111220
Slight refactoring ed_ecosystems_dynamics for simplicity
glemieux Aug 13, 2021
443550d
reverting all the area_pft indexing commits
glemieux Aug 25, 2021
28473d0
Update biogeochem/EDPhysiologyMod.F90
glemieux Sep 1, 2021
1341f4b
Merge branch 'fates_sp_sept_revert_area_pft' into fates_sp_sept
glemieux Sep 1, 2021
a260f31
adding hist var for sp lai by pft
ckoven Sep 2, 2021
455617d
removing init and c_leaf arguments to assign_cohort_SP_properties
ckoven Sep 2, 2021
919e27f
Revert "removing init and c_leaf arguments to assign_cohort_SP_proper…
ckoven Sep 3, 2021
5664f68
changing area_pft indexing in init
ckoven Sep 3, 2021
482fc94
debug
ckoven Sep 3, 2021
d2892e4
fixing loop bounds
ckoven Sep 3, 2021
c009135
indexing bc_outs to ignore the bare-groun PFTs entirely.
ckoven Sep 3, 2021
3507ad3
Revert "adding hist var for sp lai by pft"
ckoven Sep 3, 2021
70c3195
bugfixes
ckoven Sep 3, 2021
cc5b2ed
added fire variables to allow nocomp to pass restart comparison with …
ckoven Sep 15, 2021
5f88d09
Merge pull request #7 from ckoven/spmode_firerestdebug
glemieux Sep 15, 2021
54e35d1
correcting the location of the ncl cohort index assignment
glemieux Sep 15, 2021
f32d831
Merge pull request #703 from rosiealice/fates_sp_sept
glemieux Sep 17, 2021
70917d4
Conflict resolution on batch patch modifications to ../tools/modify_f…
rgknox Sep 22, 2021
70a3e13
Merge pull request #765 from rgknox/mod-e3sm-testparam
rgknox Sep 27, 2021
b7fd5f5
Removed unnecessary manual attribution statement (author history in g…
rgknox Sep 27, 2021
f7aa5b1
Merge resolution of rooting depth with master. Unification of crown d…
rgknox Sep 30, 2021
a7b29b4
Small fix in batch params script to workaround parser bug
rgknox Sep 30, 2021
a3b094f
cleaning up root depth branch
rgknox Oct 1, 2021
c944640
Created subroutine for maximum rooting depth, passing that into root …
rgknox Oct 1, 2021
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
Prev Previous commit
Next Next commit
modifications to terminate_patches for PFT loops
  • Loading branch information
rosiealice committed May 19, 2020
commit b48de6a9ac573292064337628d01feadd268b090
199 changes: 165 additions & 34 deletions biogeochem/EDPatchDynamicsMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module EDPatchDynamicsMod
use FatesInterfaceMod , only : hlm_days_per_year
use FatesInterfaceMod , only : numpft
use FatesInterfaceMod , only : hlm_use_nocomp
use FatesInterfaceMod , only : hlm_use_fixed_biogeog
use FatesGlobals , only : endrun => fates_endrun
use FatesConstantsMod , only : r8 => fates_r8
use FatesConstantsMod , only : itrue, ifalse
Expand Down Expand Up @@ -102,7 +103,7 @@ module EDPatchDynamicsMod
character(len=*), parameter, private :: sourcefile = &
__FILE__

logical, parameter :: debug = .false.
logical, parameter :: debug = .true.

! When creating new patches from other patches, we need to send some of the
! litter from the old patch to the new patch. Likewise, when plants die
Expand Down Expand Up @@ -478,6 +479,7 @@ subroutine spawn_patches( currentSite, bc_in)
currentPatch => currentPatch%older
enddo ! end loop over patches. sum area disturbed for all patches.

write(*,*) 'areadis', site_areadis_primary_pft(1:12)
! It is possible that no disturbance area was generated
if ( (site_areadis_primary + site_areadis_secondary) > nearzero) then

Expand Down Expand Up @@ -513,12 +515,12 @@ subroutine spawn_patches( currentSite, bc_in)
site_areadis_primary_pft(nocomp_pft), primaryforest,nocomp_pft)
! Initialize the litter pools to zero
do el=1,num_elements
call new_patch_primary%litter(el)%InitConditions(&
call new_patch_primary_pft(nocomp_pft)%litter(el)%InitConditions(&
init_leaf_fines=0._r8, init_root_fines=0._r8, init_ag_cwd=0._r8, &
init_bg_cwd =0._r8, init_seed =0._r8, init_seed_germ=0._r8)
end do
new_patch_primary%tallest => null()
new_patch_primary%shortest => null()
new_patch_primary_pft(nocomp_pft)%tallest => null()
new_patch_primary_pft(nocomp_pft)%shortest => null()
end if !area
end do !pft
endif !nocomp
Expand Down Expand Up @@ -552,12 +554,12 @@ subroutine spawn_patches( currentSite, bc_in)
call create_patch(currentSite, new_patch_secondary_pft(nocomp_pft), age, &
site_areadis_secondary_pft(nocomp_pft), secondaryforest,nocomp_pft)
do el=1,num_elements
call new_patch_secondary%litter(el)%InitConditions(&
call new_patch_secondary_pft(nocomp_pft)%litter(el)%InitConditions(&
init_leaf_fines=0._r8, init_root_fines=0._r8, init_ag_cwd=0._r8, &
init_bg_cwd =0._r8, init_seed =0._r8, init_seed_germ=0._r8)
end do
new_patch_secondary%tallest => null()
new_patch_secondary%shortest => null()
new_patch_secondary_pft(nocomp_pft)%tallest => null()
new_patch_secondary_pft(nocomp_pft)%shortest => null()
end if !area
end do !pft
endif !nocomp
Expand All @@ -584,10 +586,20 @@ subroutine spawn_patches( currentSite, bc_in)
if (currentPatch%anthro_disturbance_label .eq. primaryforest .and. &
(currentPatch%disturbance_mode .ne. dtype_ilog)) then
new_patch => new_patch_primary
rec_type = primaryforest
else
new_patch => new_patch_secondary
rec_type = secondaryforest
endif

if(hlm_use_nocomp.eq.itrue)then !nocomp case
if(rec_type.eq.primaryforest)then
new_patch => new_patch_primary_pft(currentPatch%nocomp_pft_label)
else
new_patch => new_patch_secondary_pft(currentPatch%nocomp_pft_label)
endif
endif

if(.not.associated(new_patch))then
write(fates_log(),*) 'Patch spawning has attempted to point to'
write(fates_log(),*) 'an un-allocated patch'
Expand Down Expand Up @@ -1061,41 +1073,81 @@ subroutine spawn_patches( currentSite, bc_in)
!** INSERT NEW PATCH(ES) INTO LINKED LIST
!**********`***************/

if ( site_areadis_primary .gt. nearzero) then
! currentPatch is the youngest of the pre-existing patches.
!newpatch_primary_pft and newpatch_secondary_pft need to be added into the mix

if(hlm_use_nocomp.eq.ifalse)then
if ( site_areadis_primary .gt. nearzero) then
currentPatch => currentSite%youngest_patch
new_patch_primary%older => currentPatch
new_patch_primary%younger => null()
currentPatch%younger => new_patch_primary
currentSite%youngest_patch => new_patch_primary
endif
endif

if ( site_areadis_secondary .gt. nearzero) then
if ( site_areadis_secondary .gt. nearzero) then
currentPatch => currentSite%youngest_patch
new_patch_secondary%older => currentPatch
new_patch_secondary%younger=> null()
currentPatch%younger => new_patch_secondary
currentSite%youngest_patch => new_patch_secondary
endif

endif
else !nocomp case with one new patch for each PFT
do nocomp_pft=1,numpft
if ( site_areadis_primary_pft(nocomp_pft) .gt. nearzero) then
currentPatch => currentSite%youngest_patch
new_patch_primary_pft(nocomp_pft)%older => currentPatch
new_patch_primary_pft(nocomp_pft)%younger => null()
currentPatch%younger => new_patch_primary_pft(nocomp_pft)
currentSite%youngest_patch => new_patch_primary_pft(nocomp_pft)
endif

if ( site_areadis_secondary .gt. nearzero) then
currentPatch => currentSite%youngest_patch
new_patch_secondary_pft(nocomp_pft)%older => currentPatch
new_patch_secondary_pft(nocomp_pft)%younger=> null()
currentPatch%younger => new_patch_secondary_pft(nocomp_pft)
currentSite%youngest_patch => new_patch_secondary_pft(nocomp_pft)
endif
enddo !pft
endif !nocomp

! sort out the cohorts, since some of them may be so small as to need removing.
! the first call to terminate cohorts removes sparse number densities,
! the second call removes for all other reasons (sparse culling must happen
! before fusion)

if ( site_areadis_primary .gt. nearzero) then
call terminate_cohorts(currentSite, new_patch_primary, 1,17)
call fuse_cohorts(currentSite,new_patch_primary, bc_in)
call terminate_cohorts(currentSite, new_patch_primary, 2,17)
call sort_cohorts(new_patch_primary)
endif

if ( site_areadis_secondary .gt. nearzero) then
call terminate_cohorts(currentSite, new_patch_secondary, 1,18)
call fuse_cohorts(currentSite,new_patch_secondary, bc_in)
call terminate_cohorts(currentSite, new_patch_secondary, 2,18)
call sort_cohorts(new_patch_secondary)
endif
if(hlm_use_nocomp.eq.ifalse)then
if ( site_areadis_primary .gt. nearzero) then
call terminate_cohorts(currentSite, new_patch_primary, 1,17)
call fuse_cohorts(currentSite,new_patch_primary, bc_in)
call terminate_cohorts(currentSite, new_patch_primary, 2,17)
call sort_cohorts(new_patch_primary)
endif

if ( site_areadis_secondary .gt. nearzero) then
call terminate_cohorts(currentSite, new_patch_secondary, 1,18)
call fuse_cohorts(currentSite,new_patch_secondary, bc_in)
call terminate_cohorts(currentSite, new_patch_secondary, 2,18)
call sort_cohorts(new_patch_secondary)
endif

else !nocomp case
do nocomp_pft=1,numpft
if ( site_areadis_primary_pft(nocomp_pft) .gt. nearzero) then
call terminate_cohorts(currentSite, new_patch_primary_pft(nocomp_pft), 1,17)
call fuse_cohorts(currentSite,new_patch_primary_pft(nocomp_pft), bc_in)
call terminate_cohorts(currentSite, new_patch_primary_pft(nocomp_pft), 2,17)
call sort_cohorts(new_patch_primary_pft(nocomp_pft))
endif
if ( site_areadis_primary_pft(nocomp_pft) .gt. nearzero) then
call terminate_cohorts(currentSite, new_patch_secondary_pft(nocomp_pft), 1,18)
call fuse_cohorts(currentSite, new_patch_secondary_pft(nocomp_pft), bc_in)
call terminate_cohorts(currentSite, new_patch_secondary_pft(nocomp_pft), 2,18)
call sort_cohorts(new_patch_secondary_pft(nocomp_pft))
endif
enddo !pft
endif !nocomp

endif !end new_patch area

Expand Down Expand Up @@ -1155,7 +1207,7 @@ subroutine check_patch_area( currentSite )
end if

if(debug) then
write(fates_log(),*) 'Total patch area precision being fixed, adjusting'
write(fates_log(),*) 'Total patch area precision being fixed, adjusting',(areatot-area_site)
write(fates_log(),*) 'largest patch. This may have slight impacts on carbon balance.'
end if

Expand Down Expand Up @@ -2455,8 +2507,10 @@ subroutine fuse_2_patches(csite, dp, rp)
end if

! We have no need for the dp pointer anymore, we have passed on it's legacy
write(*,*) 'deallocating' ,dp%nocomp_pft_label, rp%nocomp_pft_label
call dealloc_patch(dp)
deallocate(dp)

! deallocate(dp)


if(associated(youngerp))then
Expand Down Expand Up @@ -2500,9 +2554,13 @@ subroutine terminate_patches(currentSite)
type(ed_patch_type), pointer :: currentPatch
type(ed_patch_type), pointer :: olderPatch
type(ed_patch_type), pointer :: youngerPatch
type(ed_patch_type), pointer :: fusingPatch
integer, parameter :: max_cycles = 10 ! After 10 loops through
! You should had fused
integer :: count_cycles
integer :: is_youngest
integer :: is_oldest
integer :: found_fusion_patch

real(r8) areatot ! variable for checking whether the total patch area is wrong.
!---------------------------------------------------------------------
Expand All @@ -2513,13 +2571,17 @@ subroutine terminate_patches(currentSite)
do while(associated(currentPatch))

if(currentPatch%area <= min_patch_area)then


if(hlm_use_fixed_biogeog.eq.ifalse)then !just fuse to older or younger cohort.

! Even if the patch area is small, avoid fusing it into its neighbor
! if it is the youngest of all patches. We do this in attempts to maintain
! a discrete patch for very young patches
! However, if the patch to be fused is excessivlely small, then fuse
! at all costs. If it is not fused, it will make

! the current patch is NOT the youngest. Or is it very very small.
! so, skip merging if it is the youngest, unless the youngest is tiny.
if ( .not.associated(currentPatch,currentSite%youngest_patch) .or. &
currentPatch%area <= min_patch_area_forced ) then

Expand Down Expand Up @@ -2553,10 +2615,71 @@ subroutine terminate_patches(currentSite)

! The fusion process has updated the "younger" pointer on currentPatch

endif
endif
endif
endif ! older or younder patch
endif ! very small area

else !nocomp. We cannot fuse to patches with a different PFT identity in no competition mode.

! Each patch has a PFT identity, and so cannot simply fuse to the older or younger patch
! For each small current patch, we must first search older patch candidates, and then younger
! patch candidates.
! need to think about the youngest of PFT logic later.

is_youngest = itrue !try and find a younger same-PFT patch
! discover if this is the youngest patch of its PFT
fusingPatch => currentPatch%younger !if it's the youngest overall then it's defacto youngest of PFT
do while(associated(fusingPatch).and.is_youngest.eq.itrue)
if(fusingPatch%nocomp_pft_label.eq.currentPatch%nocomp_pft_label)then
is_youngest = ifalse ! we found a yonger patch, so this isn't the youngest one.
endif ! PFT
fusingPatch => fusingPatch%younger
enddo !fusing patch

is_oldest = itrue !try and find a younger same-PFT patch
! discover if this is the youngest patch of its PFT
fusingPatch => currentPatch%older !if it's the youngest overall then it's defacto youngest of PFT
do while(associated(fusingPatch).and.is_oldest.eq.itrue)
if(fusingPatch%nocomp_pft_label.eq.currentPatch%nocomp_pft_label)then
is_oldest = ifalse ! we found a yonger patch, so this isn't the youngest one.
endif ! PFT
fusingPatch => fusingPatch%older
enddo !fusing patch

if (is_youngest.eq.itrue .or. currentPatch%area <= min_patch_area_forced ) then

found_fusion_patch = ifalse

fusingPatch => currentPatch%older
do while(associated(fusingPatch).and.found_fusion_patch.eq.ifalse )
if(fusingPatch%nocomp_pft_label.eq.currentPatch%nocomp_pft_label)then
if(debug) &
write(fates_log(),*) 'fusing to older patch of same PFT - this one is too small',&
currentPatch%area, fusingPatch%area, &
currentPatch%nocomp_pft_label, fusingPatch%nocomp_pft_label
call fuse_2_patches(currentSite, fusingPatch, currentPatch)
found_fusion_patch=itrue
endif ! PFT
fusingPatch => fusingPatch%older
enddo !fusing patch

! if no older patches, search younger ones.
fusingPatch => currentPatch%younger
do while(associated(fusingPatch).and.found_fusion_patch.eq.ifalse )
if(fusingPatch%nocomp_pft_label.eq.currentPatch%nocomp_pft_label)then
if(debug) &
write(fates_log(),*) 'fusing to younger patch of same PFT - this one is too small',&
currentPatch%area, fusingPatch%area , &
currentPatch%nocomp_pft_label, fusingPatch%nocomp_pft_label
call fuse_2_patches(currentSite, fusingPatch, currentPatch)
found_fusion_patch=itrue
endif ! PFT
fusingPatch => fusingPatch%younger
enddo !fusing patch
endif ! not youngest, or is very small patch
endif !nocomp
endif ! small area


! It is possible that an incredibly small patch just fused into another incredibly
! small patch, resulting in an incredibly small patch. It is also possible that this
! resulting incredibly small patch is the oldest patch. If this was true than
Expand All @@ -2570,25 +2693,33 @@ subroutine terminate_patches(currentSite)
else
count_cycles = count_cycles + 1
end if

if(count_cycles > max_cycles) then
if(is_oldest.eq.itrue.and.is_youngest.eq.itrue.and.hlm_use_fixed_biogeog)then
write(fates_log(),*) 'this is the only patch of this PFT'
currentPatch => currentPatch%older
else !not the only patch
write(fates_log(),*) 'FATES is having difficulties fusing very small patches.'
write(fates_log(),*) 'It is possible that a either a secondary or primary'
write(fates_log(),*) 'patch has become the only patch of its kind, and it is'
write(fates_log(),*) 'is very very small. You can test your luck by'
write(fates_log(),*) 'disabling the endrun statement following this message.'
write(fates_log(),*) 'FATES may or may not continue to operate within error'
write(fates_log(),*) 'tolerances, but will generate another fail if it does not.'

write(fates_log(),*) 'cp pft',currentPatch%nocomp_pft_label,currentPatch%area

call endrun(msg=errMsg(sourcefile, __LINE__))

! Note to user. If you DO decide to remove the end-run above this line
! Make sure that you keep the pointer below this line, or you will get
! an infinite loop.
currentPatch => currentPatch%older
count_cycles = 0
end if
end if !only patch
end if !count cycles

enddo
enddo !patch loop

!check area is not exceeded
call check_patch_area( currentSite )
Expand Down