Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ add_subdirectory(tests/unit/count_cohorts_test fates_count_cohorts_utest)
add_subdirectory(tests/unit/fire_equations_test fates_fire_equations_utest)
add_subdirectory(tests/unit/quadratic_roots_test fates_quadratic_roots_utest)
add_subdirectory(tests/unit/great_circle_test fates_great_circle_utest)
add_subdirectory(tests/unit/leaf_biophysics_test fates_leaf_biophysics_utest)
3 changes: 3 additions & 0 deletions testing/config/unit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ test_dir = fates_quadratic_roots_utest
[great_circle]
test_dir = fates_great_circle_utest

[leaf_biophysics]
test_dir = fates_leaf_biophysics_utest

6 changes: 6 additions & 0 deletions testing/tests/unit/leaf_biophysics_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
set(pfunit_sources test_LeafBiophysics.pf)

add_pfunit_ctest(LeafBiophysics
TEST_SOURCES "${pfunit_sources}"
LINK_LIBRARIES fates csm_share)

81 changes: 81 additions & 0 deletions testing/tests/unit/leaf_biophysics_test/test_LeafBiophysics.pf
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
module test_LeafBiophysics
!
! DESCRIPTION:
! Unit tests for LeafBiophysicsMod routines in FATES.
!
use FatesConstantsMod, only : r8 => fates_r8, tfrz => t_water_freeze_k_1atm
use LeafBiophysicsMod, only : QSat, &
StomatalCondMedlyn, &
StomatalCondBallBerry, &
LowstorageMainRespReduction, &
LeafLayerMaintenanceRespiration_Ryan_1991, &
LeafLayerMaintenanceRespiration_Atkin_etal_2017, &
GetCanopyGasParameters, &
DecayCoeffVcmax, &
GetConstrainedVPress, &
VeloToMolarCF, &
LeafHumidityStomaResis, &
rsmax0, &
lb_params, &
c3_path_index, &
c4_path_index
use funit

implicit none

@TestCase
type, extends(TestCase) :: TestLeafBiophysics
contains
procedure :: setUp
procedure :: tearDown
end type TestLeafBiophysics

! 1.e-13_r8: Precision tolerance near the 64-bit float limit used for exact matching.
real(r8), parameter :: tol = 1.e-13_r8

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We actually need to start migrating to using this constant in more of the models internal code.


contains

subroutine setUp(this)
! lb_params is normally loaded from the FATES NetCDF parameter file at run-time;
! here we manually set the minimum fields needed for two synthetic PFTs (C3, C4).
class(TestLeafBiophysics), intent(inout) :: this

allocate(lb_params%c3psn(2))
allocate(lb_params%maintresp_leaf_ryan1991_baserate(2))
allocate(lb_params%maintresp_leaf_atkin2017_baserate(2))
allocate(lb_params%maintresp_reduction_curvature(2))
allocate(lb_params%maintresp_reduction_intercept(2))

! Pathway flags; module-level constants from LeafBiophysicsMod.
lb_params%c3psn(1) = c3_path_index
lb_params%c3psn(2) = c4_path_index

! FATES default (fates_params_default.cdl): 2.525e-06 gC gN-1 s-1 for all PFTs.
lb_params%maintresp_leaf_ryan1991_baserate(1) = 2.525e-6_r8
lb_params%maintresp_leaf_ryan1991_baserate(2) = 2.525e-6_r8

! FATES default r0 for PFT 1 (tropical broadleaf evergreen): 1.756 umol CO2 m-2 s-1.
lb_params%maintresp_leaf_atkin2017_baserate(1) = 1.756_r8
lb_params%maintresp_leaf_atkin2017_baserate(2) = 1.756_r8

! Non-default values chosen to exercise two branches of LowstorageMainRespReduction:
! 1.0 -> linear branch (FATES default is 0.01; 1=linear, 0=maximally curved)
! 0.5 -> curved power-law branch
lb_params%maintresp_reduction_curvature(1) = 1.0_r8
lb_params%maintresp_reduction_curvature(2) = 0.5_r8

! Non-default (FATES default=1.0); 0.8 gives non-trivial hand-calculable values.
lb_params%maintresp_reduction_intercept(1) = 0.8_r8
lb_params%maintresp_reduction_intercept(2) = 0.8_r8
end subroutine setUp

subroutine tearDown(this)
class(TestLeafBiophysics), intent(inout) :: this
deallocate(lb_params%c3psn)
deallocate(lb_params%maintresp_leaf_ryan1991_baserate)
deallocate(lb_params%maintresp_leaf_atkin2017_baserate)
deallocate(lb_params%maintresp_reduction_curvature)
deallocate(lb_params%maintresp_reduction_intercept)
end subroutine tearDown

end module test_LeafBiophysics