Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
30541e7
Add FatesEcotypesMod and support infrastructure.
samsrabin Mar 13, 2024
436d0ef
Add useful parameter files.
samsrabin Aug 16, 2024
cdd5854
Add IS_FOREST* and other useful outputs.
samsrabin Aug 13, 2024
3a72788
Avoid arrays for experimental forest definitions.
samsrabin Oct 16, 2024
a1b7ee7
is_patch_forest_tcthresh(): Handle 0-area patches.
samsrabin Oct 17, 2024
60191cf
Combine isforest functions into one.
samsrabin Oct 17, 2024
d5e9642
Add FatesEdgeForestMod and testing.
samsrabin Mar 27, 2024
f3e4e2e
Add FATES_FOREST_AREA_EB history output.
samsrabin Mar 29, 2024
15291b8
Move edge bin parameters to FATES param file.
samsrabin Apr 15, 2024
ecf7ec1
My diagnostic outputs now use group_dyna_*.
samsrabin Oct 17, 2024
54e543d
Delete unneeded use "FatesIOVariableKindMod" in FatesHistoryInterface…
samsrabin Oct 18, 2024
aa3b3b9
Fix and rename edge forest bin variables.
samsrabin Oct 18, 2024
21efc2c
Cleanup
samsrabin Oct 18, 2024
d3cd1d4
Revert "My diagnostic outputs now use group_dyna_*."
samsrabin Oct 18, 2024
b1858ab
Revert "Delete unneeded use "FatesIOVariableKindMod" in FatesHistoryI…
samsrabin Oct 18, 2024
15112f8
Revert "Revert "My diagnostic outputs now use group_dyna_*.""
samsrabin Oct 20, 2024
870d928
Move FATES_IS_FOREST_AP calc to update_history_dyn2_ageclass().
samsrabin Oct 21, 2024
a8f9da0
Revert "Revert "Delete unneeded use "FatesIOVariableKindMod" in Fates…
samsrabin Oct 21, 2024
6e0d63f
Remove ED_val_edgeforest_decay from FatesConstantsMod.
samsrabin Oct 21, 2024
e200957
Add some .cdl parameter files.
samsrabin Oct 23, 2024
69a5946
Merge branch 'refactor-history-2' into edge-area-202410
samsrabin Nov 1, 2024
fe31f1d
Remove check that edge forest param lengths match nlevedgeforest.
samsrabin Nov 4, 2024
0f73382
Remove unused edge bin param use statements.
samsrabin Nov 4, 2024
7c2ae8a
Fix error from merge of refactor-history-2.
samsrabin Nov 4, 2024
bc6c6bd
Replace edge forest parameters in code. BROKEN (intentionally).
samsrabin Nov 4, 2024
7cd5631
Add param file to work with previous.
samsrabin Nov 4, 2024
f83e79c
Merge tag 'sci.1.78.0_api.36.0.0' into edge-area-202410
samsrabin Jun 23, 2025
6ae8443
Merge tag 'sci.1.78.1_api.36.0.0' into edge-area-202410
samsrabin Jun 23, 2025
784e050
Merge tag 'sci.1.78.2_api.36.0.0' into edge-area-202410
samsrabin Jun 23, 2025
ebefc1c
Merge tag 'sci.1.79.1_api.36.1.0' into edge-area-202410
samsrabin Jun 23, 2025
9faeb35
Merge tag 'sci.1.79.1_api.36.1.0_tools.2.1.0' into edge-area-202410
samsrabin Jun 23, 2025
e4e710c
Merge tag 'sci.1.79.2_api.36.1.0' into edge-area-202410
samsrabin Jun 23, 2025
b70d12f
Merge tag 'sci.1.79.3_api.37.0.0' into edge-area-202410
samsrabin Jun 23, 2025
a0f0619
Merge tag 'sci.1.80.0_api.37.0.0' into edge-area-202410
samsrabin Jun 23, 2025
14d854a
Merge tag 'sci.1.80.10_api.37.0.0' into edge-area-202410
samsrabin Jun 23, 2025
2bcf4ad
Merge tag 'sci.1.80.11_api.37.0.0' into edge-area-202410
samsrabin Jun 23, 2025
3fc52fd
Merge tag 'sci.1.80.12_api.37.0.0' into edge-area-202410
samsrabin Jun 23, 2025
826d246
Merge tag 'sci.1.80.13_api.37.0.0' into edge-area-202410
samsrabin Jun 23, 2025
4d5e9f4
Merge tag 'sci.1.80.14_api.37.0.0' into edge-area-202410
samsrabin Jun 23, 2025
c97f24d
Merge tag 'sci.1.81.0_api.37.1.0' into edge-area-202410
samsrabin Jun 23, 2025
25d788c
Merge tag 'sci.1.81.1_api.37.1.0' into edge-area-202410
samsrabin Jun 23, 2025
b086894
Merge tag 'sci.1.81.1_api.38.0.0' into edge-area-202410
samsrabin Jun 23, 2025
c7627a7
Merge tag 'sci.1.82.4_api.39.0.0' into edge-area-202410
samsrabin Jun 23, 2025
9eef47a
Merge tag 'sci.1.82.5_api.39.0.0' into edge-area-202410
samsrabin Jun 23, 2025
b959e46
Merge tag 'sci.1.83.0_api.39.0.0' into edge-area-202410
samsrabin Jun 23, 2025
f31ebbd
Merge tag 'sci.1.83.1_api.39.0.0' into edge-area-202410
samsrabin Jun 23, 2025
d9845cd
Merge tag 'sci.1.84.0_api.40.0.0' into edge-area-202410
samsrabin Jun 23, 2025
39cc40d
Move CalculateTreeGrassAreaSite() to FatesEdgeForestMod.
samsrabin Jun 23, 2025
87f618b
Fix FatesHistoryInterfaceMod.
samsrabin Jun 23, 2025
b11baa6
Update default edge params with values from dev .cdl file.
samsrabin Jun 23, 2025
1b74e78
get_fraction_of_edgeforest_in_each_bin() is now called and uses read-…
samsrabin Jun 23, 2025
0b21684
Factor out new subroutine assign_patch_to_bins().
samsrabin Jun 30, 2025
a138ca8
Slight refactor of assign_patch_to_bins() for testing.
samsrabin Jun 30, 2025
6053313
Add a unit test of assign_patch_to_bins().
samsrabin Jun 30, 2025
7fc7a20
Merge tag 'sci.1.85.2_api.40.0.0' into edge-area-202410
samsrabin Jun 30, 2025
fe6392c
Temporarily comment out some tests that need updating.
samsrabin Jun 30, 2025
ec6d636
Fix test_assign_patch_to_bins_01.
samsrabin Jun 30, 2025
e228dc3
Trim trailing whitespace from test_EdgeForest.pf.
samsrabin Jun 30, 2025
ff96724
Add more tests of assign_patch_to_bins().
samsrabin Jun 30, 2025
f438c80
Add test_get_fraction_of_edgeforest_in_each_bin_x0.
samsrabin Jul 1, 2025
d546b41
If cell is 100% forest, it's all deep forest.
samsrabin Jul 1, 2025
55cdedf
Fix gffeb_gaussian_numerator().
samsrabin Jul 1, 2025
323e770
Add tests of get_fraction_of_edgeforest_in_each_bin().
samsrabin Jul 1, 2025
927c138
Add test_get_fraction_of_edgeforest_in_each_bin_norm().
samsrabin Jul 1, 2025
82708f8
Add test_gffeb_quadratic().
samsrabin Jul 1, 2025
4ceb9bd
Combine gaussian and lognormal num/denom functions.
samsrabin Jul 1, 2025
f656191
Add test_gffeb_gaussian_numerator().
samsrabin Jul 1, 2025
d131ac9
Add gffeb_norm() and tests.
samsrabin Jul 1, 2025
84beddc
Add "edge forest" functional test (for now just does allometry tests).
samsrabin Jul 2, 2025
9a4c719
Edge forest test now does edge forest thing. Bad, though.
samsrabin Jul 2, 2025
35a3623
Add lognormal and quadratic fits. Also bad.
samsrabin Jul 2, 2025
5583964
Print parameters for each fit.
samsrabin Jul 2, 2025
2f2f21f
Add function is_param_set().
samsrabin Jul 2, 2025
ded84c4
is_param_set(): Compare against fates_check_param_set instead of just…
samsrabin Jul 2, 2025
3b34506
Add bin num to test printout.
samsrabin Jul 2, 2025
70c8632
Fix quadratic test printout.
samsrabin Jul 2, 2025
abdcf86
Add plot of forest fraction in every bin.
samsrabin Jul 7, 2025
c1940a9
It's FRACTION nonforest, not percent.
samsrabin Jul 7, 2025
97a180f
Fix gffeb_norm_denominator().
samsrabin Jul 7, 2025
ed8d688
Fit is fraction FOREST, not fraction nonforest.
samsrabin Jul 7, 2025
3fc2a31
Replace one test values with something independent.
samsrabin Jul 7, 2025
12f21da
Add checks of edge forest parameters.
samsrabin Jul 7, 2025
9759e2f
FatesInterfaceMod: Refactor a confusing nested if-block.
samsrabin Jul 8, 2025
af1eb80
Add hlm_use_edge_forest flag.
samsrabin Jul 8, 2025
01b8be2
Explicitly import shr_infnan_isnan.
samsrabin Jul 10, 2025
2dc6817
Compare hlm_use_edge_forest to itrue.
samsrabin Jul 10, 2025
cab8e6f
Add newlines at end of new files.
samsrabin Jul 14, 2025
a72885a
Add and use utility function logical_to_real().
samsrabin Jul 14, 2025
8462bf2
Merge branch 'fix_testing_ssr' into edge-area-202410
samsrabin Jul 14, 2025
61a24ed
Make logical_to_real() public.
samsrabin Jul 14, 2025
235c88f
Functional tests: Import utils_plotting.
samsrabin Jul 16, 2025
26fb9a0
Edge forest functional test: Use new sample_colormap().
samsrabin Jul 16, 2025
471ed00
Edge forest functional test: Edge distances in legend.
samsrabin Jul 16, 2025
f8a62fd
Edge forest functional testing: Add dashed line for normalized.
samsrabin Jul 16, 2025
ec60dfb
Change longname of fates_levedge.
samsrabin Jul 16, 2025
e30b402
Delete experimental parameter files.
samsrabin Jul 16, 2025
824ec00
Clean up FATES edge forest work.
samsrabin Jul 16, 2025
118d799
Testing Python: Prep for unit tests reading param files.
samsrabin Jul 18, 2025
e88ca2a
Testing bugfix: Convert use_param_file to boolean.
samsrabin Jul 23, 2025
efcf267
GetSyntheticPatchData(): Optionally specify one patch name.
samsrabin Jul 18, 2025
3ed9356
Add Ecotypes unit test. FAILING!
samsrabin Jul 18, 2025
1327b01
Fix is_patch_forest() w/ grass biomass. FIXES ecotypes test.
samsrabin Jul 19, 2025
2b63956
Testing: Print final parameter file path.
samsrabin Jul 23, 2025
db5bea4
Merge branch 'main' into edge-area-202410
samsrabin Jul 23, 2025
a5f5a3b
Merge tag 'sci.1.87.0_api.41.0.0' into edge-area-202410
samsrabin Aug 25, 2025
4d3b7d4
Don't set nlevedgeforest=1 if hlm_use_edge_forest false.
samsrabin Sep 9, 2025
233e525
Remove an unused 'use hlm_use_tree_damage'.
samsrabin Oct 3, 2025
7ffd6f0
Change procedure names from snake_case to PascalCase.
samsrabin Oct 3, 2025
4ac9ac1
Move GetNumberOfPatches() from FatesEdgeForestMod to ed_site_type.
samsrabin Oct 3, 2025
a8c0c35
Expand description of RankForestEdgeProximity().
samsrabin Oct 3, 2025
1476eb3
Fix docstring in edge_forest_test.py.
samsrabin Oct 3, 2025
a88bfb0
test_EdgeForest.pf: Fix test name conflict.
samsrabin Oct 3, 2025
131d93a
Ecotypes unit test: Don't read parameter file.
samsrabin Oct 3, 2025
de669c9
Revert some now-unneeded changes to testing scripts.
samsrabin Oct 4, 2025
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
10 changes: 10 additions & 0 deletions biogeochem/EDCanopyStructureMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module EDCanopyStructureMod
use FatesInterfaceTypesMod , only : hlm_use_planthydro
use FatesInterfaceTypesMod , only : hlm_use_cohort_age_tracking
use FatesInterfaceTypesMod , only : hlm_use_sp
use FatesInterfaceTypesMod , only : hlm_use_edge_forest
use FatesInterfaceTypesMod , only : numpft
use FatesInterfaceTypesMod, only : bc_in_type
use FatesPlantHydraulicsMod, only : UpdateH2OVeg,InitHydrCohort, RecruitWaterStorage
Expand Down Expand Up @@ -1319,6 +1320,9 @@ subroutine canopy_summarization( nsites, sites, bc_in )
use FatesSizeAgeTypeIndicesMod, only : coagetype_class_index
use EDtypesMod , only : area
use FatesConstantsMod , only : itrue
use FatesEcotypesMod , only : IsPatchForest
use EDParamsMod , only : forest_tree_fraction_threshold
use FatesEdgeForestMod , only : CalculateEdgeForestArea

! !ARGUMENTS
integer , intent(in) :: nsites
Expand Down Expand Up @@ -1447,9 +1451,15 @@ subroutine canopy_summarization( nsites, sites, bc_in )
currentPatch%total_canopy_area = currentPatch%area
endif

currentPatch%is_forest = IsPatchForest(currentPatch, forest_tree_fraction_threshold)

currentPatch => currentPatch%younger
end do !patch loop

if (hlm_use_edge_forest == itrue) then
call CalculateEdgeForestArea(sites(s))
end if

call leaf_area_profile(sites(s))

if(hlm_radiation_model.eq.twostr_solver) then
Expand Down
14 changes: 14 additions & 0 deletions biogeochem/FatesPatchMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module FatesPatchMod
use FatesRadiationMemMod, only : num_rad_stream_types
use FatesInterfaceTypesMod, only : hlm_hio_ignore_val
use FatesInterfaceTypesMod, only : numpft
use FatesInterfaceTypesMod, only : nlevedgeforest
use shr_infnan_mod, only : nan => shr_infnan_nan, assignment(=)
use shr_log_mod, only : errMsg => shr_log_errMsg

Expand Down Expand Up @@ -74,6 +75,12 @@ module FatesPatchMod

!---------------------------------------------------------------------------

! FOREST INFO
logical :: is_forest ! whether the patch is "forest" according to FATES param file criteria
real(r8), dimension(:), allocatable :: area_in_edgeforest_bins

!---------------------------------------------------------------------------

! RUNNING MEANS
!class(rmean_type), pointer :: t2m ! place-holder for 2m air temperature (variable window-size)
class(rmean_type), pointer :: tveg24 ! 24-hour mean vegetation temperature [K]
Expand Down Expand Up @@ -279,6 +286,7 @@ subroutine Init(this, num_swb, num_levsoil)
allocate(this%sabs_dir(num_swb))
allocate(this%sabs_dif(num_swb))
allocate(this%fragmentation_scaler(num_levsoil))
allocate(this%area_in_edgeforest_bins(nlevedgeforest))

! initialize all values to nan
call this%NanValues()
Expand Down Expand Up @@ -453,6 +461,10 @@ subroutine NanValues(this)
this%ncl_p = fates_unset_int
this%land_use_label = fates_unset_int
this%age_since_anthro_disturbance = nan

! FOREST INFO
this%is_forest = .false.
this%area_in_edgeforest_bins(:) = nan

! LEAF ORGANIZATION
this%pft_agb_profile(:,:) = nan
Expand Down Expand Up @@ -898,6 +910,7 @@ subroutine FreeMemory(this, regeneration_model, numpft)
this%sabs_dir, &
this%sabs_dif, &
this%fragmentation_scaler, &
this%area_in_edgeforest_bins, &
stat=istat, errmsg=smsg)

! These arrays are allocated via a call from EDCanopyStructureMod
Expand Down Expand Up @@ -1227,6 +1240,7 @@ subroutine Dump(this)
write(fates_log(),*) 'pa%ncl_p = ',this%ncl_p
write(fates_log(),*) 'pa%total_canopy_area = ',this%total_canopy_area
write(fates_log(),*) 'pa%total_tree_area = ',this%total_tree_area
write(fates_log(),*) 'pa%is_forest = ',this%is_forest
write(fates_log(),*) 'pa%total_grass_area = ',this%total_grass_area
write(fates_log(),*) 'pa%zstar = ',this%zstar
write(fates_log(),*) 'pa%gnd_alb_dif = ',this%gnd_alb_dif(:)
Expand Down
2 changes: 1 addition & 1 deletion fire/SFMainMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ subroutine UpdateFireWeather(currentSite, bc_in)

use FatesConstantsMod, only : tfrz => t_water_freeze_k_1atm
use FatesConstantsMod, only : sec_per_day, sec_per_min
use EDTypesMod, only : CalculateTreeGrassAreaSite
use FatesEdgeForestMod, only : CalculateTreeGrassAreaSite
use FatesInterfaceTypesMod, only : hlm_use_managed_fire
use SFParamsMod, only : SF_val_rxfire_tpup, SF_val_rxfire_tplw, SF_val_rxfire_rhup, &
SF_val_rxfire_rhlw, SF_val_rxfire_wdup, SF_val_rxfire_wdlw
Expand Down
9 changes: 8 additions & 1 deletion main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ list(APPEND clm_sources
EDTypesMod.F90
EDPftvarcon.F90
FatesConstantsMod.F90
FatesEcotypesMod.F90
FatesEdgeForestMod.F90
FatesEdgeForestParamsMod.F90
FatesHydraulicsMemMod.F90
FatesParametersInterface.F90
FatesUtilsMod.F90
Expand All @@ -27,6 +30,10 @@ list(APPEND fates_sources
FatesSizeAgeTypeIndicesMod.F90
FatesIntegratorsMod.F90
FatesUtilsMod.F90
FatesSynchronizedParamsMod.F90)
FatesSynchronizedParamsMod.F90
FatesEcotypesMod.F90
FatesEdgeForestMod.F90
FatesEdgeForestParamsMod.F90
)

sourcelist_to_parent(fates_sources)
28 changes: 27 additions & 1 deletion main/EDParamsMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ module EDParamsMod
integer, protected, public :: max_cohort_per_patch
character(len=param_string_length), parameter, public :: maxcohort_name = "fates_maxcohort"


! Ecotypes parameters
real(r8),protected,public :: forest_tree_fraction_threshold ! Tree fraction above which a patch is "forest"
character(len=param_string_length),parameter,public :: forest_tree_fraction_threshold_name = "fates_forest_tree_fraction_threshold"

! Logging Control Parameters (ONLY RELEVANT WHEN USE_FATES_LOGGING = TRUE)
! ----------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -266,6 +268,7 @@ module EDParamsMod
character(len=param_string_length),parameter,public :: eca_name_plant_escalar = "fates_cnp_eca_plant_escalar"

public :: FatesParamsInit
public :: FatesParamsInitForFactory
public :: FatesRegisterParams
public :: FatesReceiveParams
public :: FatesReportParams
Expand Down Expand Up @@ -342,6 +345,7 @@ subroutine FatesParamsInit()
dev_arbitrary = nan
damage_event_code = -9
damage_canopy_layer_code = -9
forest_tree_fraction_threshold = nan
landuse_grazing_carbon_use_eff = nan
landuse_grazing_nitrogen_use_eff = nan
landuse_grazing_phosphorus_use_eff = nan
Expand All @@ -350,6 +354,21 @@ subroutine FatesParamsInit()

end subroutine FatesParamsInit

!-----------------------------------------------------------------------

subroutine FatesParamsInitForFactory()
! Initialize some parameters that are needed for unit-testing factories

allocate(ED_val_history_ageclass_bin_edges(7))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samsrabin these are also still allocated here: https://github.com/samsrabin/fates/blob/edge-area-202410/main/EDParamsMod.F90#L119

Do we need to remove those statements?

ED_val_history_ageclass_bin_edges = [0, 1, 2, 5, 10, 20, 50]

allocate(ED_val_history_sizeclass_bin_edges(13))
ED_val_history_sizeclass_bin_edges = [0, 5, 10, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100]

allocate(ED_val_history_coageclass_bin_edges(13))
ED_val_history_coageclass_bin_edges = [0, 5]
end subroutine FatesParamsInitForFactory

!-----------------------------------------------------------------------
subroutine FatesRegisterParams(fates_params)
! Register the parameters we want the host to provide, and
Expand Down Expand Up @@ -518,6 +537,9 @@ subroutine FatesRegisterParams(fates_params)

call fates_params%RegisterParameter(name=damage_name_canopy_layer_code, dimension_shape=dimension_shape_scalar, &
dimension_names=dim_names_scalar)

call fates_params%RegisterParameter(name=forest_tree_fraction_threshold_name, dimension_shape=dimension_shape_scalar, &
dimension_names=dim_names_scalar)

call fates_params%RegisterParameter(name=name_landuse_grazing_carbon_use_eff, dimension_shape=dimension_shape_scalar, &
dimension_names=dim_names_scalar)
Expand Down Expand Up @@ -739,6 +761,9 @@ subroutine FatesReceiveParams(fates_params)
data=tmpreal)
damage_canopy_layer_code = nint(tmpreal)

call fates_params%RetrieveParameter(name=forest_tree_fraction_threshold_name, &
data=forest_tree_fraction_threshold)

! parameters that are arrays of size defined within the params file and thus need allocating as well
call fates_params%RetrieveParameterAllocate(name=ED_name_history_sizeclass_bin_edges, &
data=ED_val_history_sizeclass_bin_edges)
Expand Down Expand Up @@ -864,6 +889,7 @@ subroutine FatesReportParams(is_master)
write(fates_log(),'(a,L2)') 'active_crown_fire = ',active_crown_fire
write(fates_log(),fmt0) 'damage_event_code = ',damage_event_code
write(fates_log(),fmt0) 'damage_canopy_layer_code = ', damage_canopy_layer_code
write(fates_log(),fmt0) 'forest_tree_fraction_threshold = ', forest_tree_fraction_threshold
write(fates_log(),fmt0) 'landuse_grazing_carbon_use_eff = ', landuse_grazing_carbon_use_eff
write(fates_log(),fmt0) 'name_landuse_grazing_nitrogen_use_eff = ', name_landuse_grazing_nitrogen_use_eff
write(fates_log(),fmt0) 'name_landuse_grazing_phosphorus_use_eff = ', name_landuse_grazing_phosphorus_use_eff
Expand Down
57 changes: 23 additions & 34 deletions main/EDTypesMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -605,12 +605,12 @@ module EDTypesMod

procedure, public :: get_current_landuse_statevector
procedure, public :: get_secondary_young_fraction
procedure, public :: GetNumberOfPatches

end type ed_site_type

! Make public necessary subroutines and functions
public :: dump_site
public :: CalculateTreeGrassAreaSite
public :: set_patchno

contains
Expand Down Expand Up @@ -737,39 +737,6 @@ end subroutine ZeroMassBalFlux

! =====================================================================================

subroutine CalculateTreeGrassAreaSite(csite, tree_fraction, grass_fraction, bare_fraction)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to FatesEdgeForestMod, I think because of circular dependencies.

!
! DESCRIPTION:
! Calculates total grass, tree, and bare fractions for a site

! ARGUMENTS:
type(ed_site_type), intent(inout) :: csite ! site object
real(r8), intent(out) :: tree_fraction ! total site tree fraction
real(r8), intent(out) :: grass_fraction ! total site grass fraction
real(r8), intent(out) :: bare_fraction ! total site bare fraction

! LOCALS:
type(fates_patch_type), pointer :: currentPatch ! patch object

tree_fraction = 0.0_r8
grass_fraction = 0.0_r8

currentPatch => csite%oldest_patch
do while(associated(currentPatch))
if (currentPatch%nocomp_pft_label /= nocomp_bareground) then
call currentPatch%UpdateTreeGrassArea()
tree_fraction = tree_fraction + currentPatch%total_tree_area/AREA
grass_fraction = grass_fraction + currentPatch%total_grass_area/AREA
end if
currentPatch => currentPatch%younger
end do

! if cover > 1.0, grasses are under the trees
grass_fraction = min(grass_fraction, 1.0_r8 - tree_fraction)
bare_fraction = 1.0_r8 - tree_fraction - grass_fraction

end subroutine CalculateTreeGrassAreaSite

!---------------------------------------------------------------------------------------

subroutine dump_site(csite)
Expand Down Expand Up @@ -865,4 +832,26 @@ function get_secondary_young_fraction(this) result(secondary_young_fraction)

end function get_secondary_young_fraction

function GetNumberOfPatches(this) result(n_patches)
! DESCRIPTION
! Returns number of patches at site
!
! ARGUMENTS:
class(ed_site_type) :: this
!
! RETURN VALUE:
integer :: n_patches
!
! LOCAL VARIABLES:
type(fates_patch_type), pointer :: currentPatch

n_patches = 0
currentPatch => this%youngest_patch
do while(associated(currentPatch))
n_patches = n_patches + 1
currentPatch => currentPatch%older
enddo

end function GetNumberOfPatches

end module EDTypesMod
81 changes: 81 additions & 0 deletions main/FatesEcotypesMod.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
module FatesEcotypesMod

use FatesConstantsMod, only : r8 => fates_r8
use EDTypesMod, only : ed_site_type
use FatesPatchMod, only : fates_patch_type

implicit none
private ! By default everything is private

! Make public necessary subroutines and functions
public :: IsPatchForest
! For unit testing
public :: DoesPatchHaveForest_TreeCover
public :: DoesPatchHaveForest_GrassBiomass

contains

! =====================================================================================

function DoesPatchHaveForest_TreeCover(patchptr, forest_tree_fraction_threshold)
! DESCRIPTION:
! Return boolean: Is this patch "forest"?
!
! ARGUMENTS:
type(fates_patch_type), intent(in), pointer :: patchptr ! pointer to patch object
real(r8), intent(in) :: forest_tree_fraction_threshold ! Tree fraction above which a patch is "forest"
!
! RETURN VALUE
logical :: DoesPatchHaveForest_TreeCover
!
! LOCAL VARIABLES
real(r8) :: tree_fraction = 0._r8

if (patchptr%area > 0._r8) then
tree_fraction = patchptr%total_tree_area / patchptr%area
else
tree_fraction = 0._r8
end if

DoesPatchHaveForest_TreeCover = tree_fraction > forest_tree_fraction_threshold

end function DoesPatchHaveForest_TreeCover


function DoesPatchHaveForest_GrassBiomass(patchptr, grass_biomass_threshold)
! DESCRIPTION:
! Return boolean: Does this patch have grass biomass above a threshold?
!
! ARGUMENTS:
type(fates_patch_type), intent(in), pointer :: patchptr ! pointer to patch object
real(r8), intent(in) :: grass_biomass_threshold ! Live grass biomass (kgC/m2) above which a patch is considered to "have grass"
!
! RETURN VALUE
logical :: DoesPatchHaveForest_GrassBiomass

DoesPatchHaveForest_GrassBiomass = patchptr%livegrass > grass_biomass_threshold

end function DoesPatchHaveForest_GrassBiomass


function IsPatchForest(patchptr, forest_tree_fraction_threshold, grass_biomass_threshold)
! DESCRIPTION:
! Return boolean: Is this patch forest according to tree cover and, optionally, grass biomass?
!
! ARGUMENTS:
type(fates_patch_type), intent(in), pointer :: patchptr ! pointer to patch object
real(r8), intent(in) :: forest_tree_fraction_threshold ! Tree fraction above which a patch is "forest"
real(r8), intent(in), optional :: grass_biomass_threshold ! Live grass biomass (kgC/m2) above which a patch is considered to "have grass"
!
! RETURN VALUE
logical :: IsPatchForest

IsPatchForest = DoesPatchHaveForest_TreeCover(patchptr, forest_tree_fraction_threshold)
if (IsPatchForest .and. present(grass_biomass_threshold)) then
IsPatchForest = .not. DoesPatchHaveForest_GrassBiomass(patchptr, grass_biomass_threshold)
end if

end function IsPatchForest


end module FatesEcotypesMod
Loading