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

Refactor of patch and cohort objects #1024

Merged
merged 80 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
b619322
move cohort to its own module
Apr 3, 2023
8f64de3
initial refactor of cohort type
Apr 4, 2023
6799bd1
more refactoring
Apr 5, 2023
a182e1d
moving parameters around
Apr 5, 2023
fc5009e
Merge branch 'main' into unit_test_framework
Apr 5, 2023
1171e82
move cohort type into its own module
Apr 7, 2023
a186683
remove unused dependencies
Apr 7, 2023
f1dcd48
move more subroutines to cohort type
Apr 7, 2023
443075b
move more methods to cohort type
Apr 7, 2023
72d3a14
move patch type to its own module
Apr 10, 2023
9ec7d62
move create methods to patch type
Apr 10, 2023
cfb5fb0
move more methods to patch type
Apr 10, 2023
3a391a7
add allocate statement
Apr 11, 2023
2b06387
add unit testing folder
Apr 11, 2023
a1b971c
update io methods for unit testing
Apr 11, 2023
2d58d24
adding makefile
Apr 11, 2023
87ebac6
move structure around to facilitate cmake
Apr 11, 2023
89e5ae8
updates for making
Apr 11, 2023
925b257
add Cmakelists
Apr 11, 2023
9ce7eea
update for making
Apr 12, 2023
b9ec30f
more updates for cmake
Apr 12, 2023
5a2fb0e
move cmakelists
Apr 12, 2023
7ee366c
works except for netcdf
Apr 12, 2023
ec5d6b5
add testing functionality
Apr 12, 2023
4e8936d
working for netcdf
Apr 13, 2023
ffeb8ee
adding a namelist
Apr 13, 2023
41ee71f
accidentally added build
Apr 13, 2023
5dd504f
updates to add more modules
Apr 14, 2023
a9a28a4
move test directories
Apr 14, 2023
cbba0d3
trying to get share to work
Apr 14, 2023
0ff67f3
rearranging structure
Apr 14, 2023
9e9c4d1
working now
Apr 14, 2023
a78f44f
more cmake stuff
Apr 21, 2023
924ec76
put use statements back
Apr 24, 2023
23e5b9f
trying to add parameters
Apr 27, 2023
915a0e1
update unit test
May 2, 2023
de31624
update unit test
May 2, 2023
db98e2a
just refactor stuff
May 2, 2023
74cb26b
refactor copy and dealloc
May 4, 2023
ce12d05
update for refactor
May 4, 2023
34b0fa0
fix circular dependencies with hydraulics objects
May 4, 2023
f93a8b4
Merge branch 'main' into patch_refactor
May 4, 2023
9a6a903
get rid of CMakeLists, only for unit test branch
May 5, 2023
243137f
put cohort mod in biogeochem folder
May 5, 2023
1e0e02f
put endrun back
May 8, 2023
e5e3f49
remove allocatable arrays
May 8, 2023
3d5709b
add abort back
May 8, 2023
447b2f4
add fragmentation scalar
May 8, 2023
20f9cb1
add shr_sys_abort use
May 8, 2023
ecae3ab
fragmentation scalar
May 8, 2023
21c7c96
begin to update for style
May 9, 2023
d6ff82c
Merge branch 'patch_refactor_noallocate' into patch_refactor
May 9, 2023
e8c2ea8
update style on patchmod
May 9, 2023
4b9e9d5
update style to match style guide
May 9, 2023
a265ef3
update for style
May 10, 2023
772d687
Merge branch 'main' into patch_refactor
May 10, 2023
548467d
add target
May 10, 2023
5916d15
get rid of temporary cohort allocation
May 15, 2023
6a8f12b
do_inventory_out off
May 15, 2023
8bd42ea
remove temp cohort
May 16, 2023
3879006
update l2fr definition
May 16, 2023
614e4a4
dangling pointer
May 16, 2023
4745516
update to target
May 16, 2023
f93741b
fix crown_damage
May 16, 2023
f539a24
Merge branch 'main' into patch_refactor
Jun 15, 2023
f47c2ee
Merge branch 'main' into patch_refactor
Jul 7, 2023
64c5036
merge conflicts fix
Jul 13, 2023
436a956
Fix EDInitMod.F90 initialisation of drought deciduous variables
mpaiao Jul 7, 2023
b6816f6
fix init error
Jul 26, 2023
f458ea7
Remove duplicated init of the drought deciduous local variables
mpaiao Jul 7, 2023
7a64fe8
Merge commit '6d424f467a6236ff24c41be2143244ae0a43b2f8' into patch_re…
Jul 26, 2023
a67e006
Merge commit '43d5e55480154e4bd487edd8da3f54e9c6bc4c42' into patch_re…
Jul 26, 2023
84f96f0
Merge branch 'main' into patch_refactor
Jul 27, 2023
44668e2
remove default
Jul 27, 2023
1054ce5
fix deallocate
Jul 27, 2023
8bfb215
remove duplicate uses
Jul 28, 2023
8f7f9b2
address comments
Jul 28, 2023
e0311ca
Update biogeochem/EDCohortDynamicsMod.F90
adrifoster Jul 28, 2023
cf41e0a
fix spmode cohort height initialization
glemieux Aug 1, 2023
a6c3a74
remove duplicate calculation of leaf_c
glemieux Aug 7, 2023
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
8 changes: 2 additions & 6 deletions biogeochem/DamageMainMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ module DamageMainMod
use EDPftvarcon , only : EDPftvarcon_inst
use EDParamsMod , only : damage_event_code
use EDParamsMod , only : ED_val_history_damage_bin_edges
use EDTypesMod , only : ed_site_type
use EDTypesMod , only : ed_patch_type
use EDTypesMod , only : ed_cohort_type
use EDTypesMod , only : AREA
use FatesInterfaceTypesMod, only : hlm_current_day
use FatesInterfaceTypesMod, only : hlm_current_month
use FatesInterfaceTypesMod, only : hlm_current_year
Expand Down Expand Up @@ -54,7 +50,7 @@ module DamageMainMod



subroutine IsItDamageTime(is_master, currentSite)
subroutine IsItDamageTime(is_master)

!----------------------------------------------------------------------------
! This subroutine determines whether damage should occur (it is called daily)
Expand All @@ -63,7 +59,7 @@ subroutine IsItDamageTime(is_master, currentSite)


integer, intent(in) :: is_master
type(ed_site_type), intent(inout), target :: currentSite
!type(ed_site_type), intent(inout), target :: currentSite

integer :: icode ! Integer equivalent of the event code (parameter file only allows reals)
integer :: damage_date ! Day of month for damage extracted from event code
Expand Down
88 changes: 43 additions & 45 deletions biogeochem/EDCanopyStructureMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ module EDCanopyStructureMod
use EDPftvarcon , only : EDPftvarcon_inst
use PRTParametersMod , only : prt_params
use FatesAllometryMod , only : carea_allom
use EDCohortDynamicsMod , only : copy_cohort, terminate_cohorts, terminate_cohort, fuse_cohorts
use EDCohortDynamicsMod , only : terminate_cohorts, terminate_cohort, fuse_cohorts
use EDCohortDynamicsMod , only : InitPRTObject
use EDCohortDynamicsMod , only : InitPRTBoundaryConditions
use FatesAllometryMod , only : tree_lai
use FatesAllometryMod , only : tree_sai
use EDtypesMod , only : ed_site_type, ed_patch_type, ed_cohort_type
use EDTypesMod , only : nclmax
use EDTypesMod , only : nlevleaf
use EDtypesMod , only : ed_site_type
use FatesPatchMod, only : fates_patch_type
use FatesCohortMod, only : fates_cohort_type
use EDParamsMod , only : nclmax
use EDParamsMod , only : nlevleaf
use EDtypesMod , only : AREA
use EDLoggingMortalityMod , only : UpdateHarvestC
use FatesGlobals , only : endrun => fates_endrun
Expand Down Expand Up @@ -136,8 +137,8 @@ subroutine canopy_structure( currentSite , bc_in )

!
! !LOCAL VARIABLES:
type(ed_patch_type) , pointer :: currentPatch
type(ed_cohort_type), pointer :: currentCohort
type(fates_patch_type) , pointer :: currentPatch
type(fates_cohort_type), pointer :: currentCohort
integer :: i_lyr ! current layer index
integer :: z ! Current number of canopy layers. (1= canopy, 2 = understorey)
integer :: ipft
Expand Down Expand Up @@ -337,18 +338,17 @@ end subroutine canopy_structure
subroutine DemoteFromLayer(currentSite,currentPatch,i_lyr,bc_in)

use EDParamsMod, only : ED_val_comp_excln
use SFParamsMod, only : SF_val_CWD_frac

! !ARGUMENTS
type(ed_site_type), intent(inout) :: currentSite
type(ed_patch_type), intent(inout) :: currentPatch
type(fates_patch_type), intent(inout) :: currentPatch
integer, intent(in) :: i_lyr ! Current canopy layer of interest
type(bc_in_type), intent(in) :: bc_in

! !LOCAL VARIABLES:
type(ed_cohort_type), pointer :: currentCohort
type(ed_cohort_type), pointer :: copyc
type(ed_cohort_type), pointer :: nextc ! The next cohort in line
type(fates_cohort_type), pointer :: currentCohort
type(fates_cohort_type), pointer :: copyc
type(fates_cohort_type), pointer :: nextc ! The next cohort in line
integer :: i_cwd ! Index for CWD pool
real(r8) :: cc_loss ! cohort crown area loss in demotion (m2)
real(r8) :: leaf_c ! leaf carbon [kg]
Expand Down Expand Up @@ -670,7 +670,7 @@ subroutine DemoteFromLayer(currentSite,currentPatch,i_lyr,bc_in)
!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()
! that will be taken care of in copy()
!!call copyc%l2fr_ema%InitRMean(ema_60day)

! Initialize the PARTEH object and point to the
Expand All @@ -682,8 +682,8 @@ subroutine DemoteFromLayer(currentSite,currentPatch,i_lyr,bc_in)
call InitHydrCohort(currentSite,copyc)
endif

call copy_cohort(currentCohort, copyc)
call InitPRTBoundaryConditions(copyc)
call currentCohort%Copy(copyc)
call copyc%InitPRTBoundaryConditions()

newarea = currentCohort%c_area - cc_loss
copyc%n = currentCohort%n*newarea/currentCohort%c_area
Expand Down Expand Up @@ -797,13 +797,13 @@ subroutine PromoteIntoLayer(currentSite,currentPatch,i_lyr)

! !ARGUMENTS
type(ed_site_type), intent(inout), target :: currentSite
type(ed_patch_type), intent(inout), target :: currentPatch
type(fates_patch_type), intent(inout), target :: currentPatch
integer, intent(in) :: i_lyr ! Current canopy layer of interest

! !LOCAL VARIABLES:
type(ed_cohort_type), pointer :: currentCohort
type(ed_cohort_type), pointer :: copyc
type(ed_cohort_type), pointer :: nextc ! the next cohort, or used for looping
type(fates_cohort_type), pointer :: currentCohort
type(fates_cohort_type), pointer :: copyc
type(fates_cohort_type), pointer :: nextc ! the next cohort, or used for looping
! cohorts against the current

real(r8) :: scale_factor ! for prob. exclusion - scales weight to a fraction
Expand Down Expand Up @@ -1138,7 +1138,7 @@ subroutine PromoteIntoLayer(currentSite,currentPatch,i_lyr)

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

! Initialize the PARTEH object and point to the
Expand All @@ -1157,8 +1157,8 @@ subroutine PromoteIntoLayer(currentSite,currentPatch,i_lyr)
!call copyc%tveg_lpa%InitRMean(ema_lpa,&
! init_value=currentPatch%tveg_lpa%GetMean())

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

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

Expand Down Expand Up @@ -1243,8 +1243,8 @@ subroutine canopy_spread( currentSite )
type (ed_site_type), intent(inout), target :: currentSite
!
! !LOCAL VARIABLES:
type (ed_cohort_type), pointer :: currentCohort
type (ed_patch_type) , pointer :: currentPatch
type (fates_cohort_type), pointer :: currentCohort
type (fates_patch_type) , pointer :: currentPatch
real(r8) :: sitelevel_canopyarea ! Amount of canopy in top layer at the site level
real(r8) :: inc ! Arbitrary daily incremental change in canopy area
integer :: z
Expand Down Expand Up @@ -1308,8 +1308,8 @@ subroutine canopy_summarization( nsites, sites, bc_in )
type(bc_in_type) , intent(in) :: bc_in(nsites)
!
! !LOCAL VARIABLES:
type (ed_patch_type) , pointer :: currentPatch
type (ed_cohort_type) , pointer :: currentCohort
type (fates_patch_type) , pointer :: currentPatch
type (fates_cohort_type) , pointer :: currentCohort
integer :: s
integer :: ft ! plant functional type
integer :: ifp ! the number of the vegetated patch (1,2,3). In SP mode bareground patch is 0
Expand Down Expand Up @@ -1499,7 +1499,8 @@ subroutine leaf_area_profile( currentSite )

! !USES:

use EDtypesMod , only : area, dinc_vai, dlower_vai, hitemax, n_hite_bins
use EDtypesMod , only : area, hitemax, n_hite_bins
use EDParamsMod, only : dinc_vai, dlower_vai

!
! !ARGUMENTS
Expand All @@ -1508,8 +1509,8 @@ subroutine leaf_area_profile( currentSite )

!
! !LOCAL VARIABLES:
type (ed_patch_type) , pointer :: currentPatch
type (ed_cohort_type) , pointer :: currentCohort
type (fates_patch_type) , pointer :: currentPatch
type (fates_cohort_type) , pointer :: currentCohort
real(r8) :: remainder !Thickness of layer at bottom of canopy.
real(r8) :: fleaf ! fraction of cohort incepting area that is leaves.
integer :: ft ! Plant functional type index.
Expand Down Expand Up @@ -1801,8 +1802,8 @@ subroutine update_hlm_dynamics(nsites,sites,fcolumn,bc_out)
! to vegetation coverage to the host land model.
! ----------------------------------------------------------------------------------

use EDTypesMod , only : ed_patch_type, ed_cohort_type, &
ed_site_type, AREA
use EDTypesMod , only : ed_site_type, AREA
use FatesPatchMod, only : fates_patch_type
use FatesInterfaceTypesMod , only : bc_out_type

!
Expand All @@ -1813,9 +1814,9 @@ subroutine update_hlm_dynamics(nsites,sites,fcolumn,bc_out)
type(bc_out_type), intent(inout) :: bc_out(nsites)

! Locals
type (ed_cohort_type) , pointer :: currentCohort
type (fates_cohort_type) , pointer :: currentCohort
integer :: s, ifp, c, p
type (ed_patch_type) , pointer :: currentPatch
type (fates_patch_type) , pointer :: currentPatch
real(r8) :: bare_frac_area
real(r8) :: total_patch_area
real(r8) :: total_canopy_area
Expand Down Expand Up @@ -2031,7 +2032,7 @@ function calc_areaindex(cpatch,ai_type) result(ai)
! ----------------------------------------------------------------------------------

! Arguments
type(ed_patch_type),intent(in), target :: cpatch
type(fates_patch_type),intent(in), target :: cpatch
character(len=*),intent(in) :: ai_type

integer :: cl,ft
Expand Down Expand Up @@ -2095,12 +2096,12 @@ subroutine CanopyLayerArea(currentPatch,site_spread,layer_index,layer_area)
! ---------------------------------------------------------------------------------------------

! Arguments
type(ed_patch_type),intent(inout), target :: currentPatch
type(fates_patch_type),intent(inout), target :: currentPatch
real(r8),intent(in) :: site_spread
integer,intent(in) :: layer_index
real(r8),intent(inout) :: layer_area

type(ed_cohort_type), pointer :: currentCohort
type(fates_cohort_type), pointer :: currentCohort


layer_area = 0.0_r8
Expand All @@ -2125,14 +2126,11 @@ subroutine UpdatePatchLAI(currentPatch)
! and related variables
! ---------------------------------------------------------------------------------------------

! Uses
use EDtypesMod, only : dlower_vai

! Arguments
type(ed_patch_type),intent(inout), target :: currentPatch
type(fates_patch_type),intent(inout), target :: currentPatch

! Local Variables
type(ed_cohort_type), pointer :: currentCohort
type(fates_cohort_type), pointer :: currentCohort
integer :: cl ! Canopy layer index
integer :: ft ! Plant functional type index

Expand Down Expand Up @@ -2175,10 +2173,10 @@ subroutine UpdateCohortLAI(currentCohort, canopy_layer_tlai, total_canopy_area)
! Update LAI and related variables for a given cohort

! Uses
use EDtypesMod, only : dlower_vai
use EDParamsMod, only : dlower_vai

! Arguments
type(ed_cohort_type),intent(inout), target :: currentCohort
type(fates_cohort_type),intent(inout), target :: currentCohort
real(r8), intent(in) :: canopy_layer_tlai(nclmax) ! total leaf area index of each canopy layer
real(r8), intent(in) :: total_canopy_area ! either patch%total_canopy_area or patch%area

Expand Down Expand Up @@ -2220,11 +2218,11 @@ function NumPotentialCanopyLayers(currentPatch,site_spread,include_substory) res
! the understory in the event the understory has reached maximum allowable area.
! --------------------------------------------------------------------------------------------

type(ed_patch_type),target :: currentPatch
type(fates_patch_type),target :: currentPatch
real(r8),intent(in) :: site_spread
logical :: include_substory

type(ed_cohort_type),pointer :: currentCohort
type(fates_cohort_type),pointer :: currentCohort

integer :: z
real(r8) :: c_area
Expand Down
Loading