diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt index 7c19f7cc99..2f4e2cb497 100644 --- a/testing/CMakeLists.txt +++ b/testing/CMakeLists.txt @@ -8,3 +8,4 @@ add_subdirectory(functional_testing/fire fates_fuel_ftest) ## Unit tests add_subdirectory(unit_testing/fire_weather_test fates_fire_weather_utest) add_subdirectory(unit_testing/fire_fuel_test fates_fire_fuel_utest) +add_subdirectory(unit_testing/parteh_test fates_parteh_utest) diff --git a/testing/unit_testing/parteh_test/CMakeLists.txt b/testing/unit_testing/parteh_test/CMakeLists.txt new file mode 100644 index 0000000000..a29b276e47 --- /dev/null +++ b/testing/unit_testing/parteh_test/CMakeLists.txt @@ -0,0 +1,5 @@ +set(pfunit_sources test_PRTAllometricCNP.pf) + +add_pfunit_ctest(PRTAllometricCNP + TEST_SOURCES "${pfunit_sources}" + LINK_LIBRARIES fates csm_share) diff --git a/testing/unit_testing/parteh_test/test_PRTAllometricCNP.pf b/testing/unit_testing/parteh_test/test_PRTAllometricCNP.pf new file mode 100644 index 0000000000..87df978c5e --- /dev/null +++ b/testing/unit_testing/parteh_test/test_PRTAllometricCNP.pf @@ -0,0 +1,103 @@ +module test_PRTAllometricCNP + ! + ! DESCRIPTION: + ! Test the FATES PRTAllometricCNPMod subroutines + ! + use funit + use FatesConstantsMod, only : r8 => fates_r8 + use FatesConstantsMod, only : default_regeneration + use FatesConstantsMod, only : mm_per_cm + use FatesConstantsMod, only : min_max_dbh_for_trees + use PRTParametersMod, only : prt_params + use PRTGenericMod, only : store_organ + use PRTAllometricCNPMod, only : cnp_allom_prt_vartypes + use PRTAllometricCNPMod, only : stoich_growth_min + use PRTAllometricCNPMod, only : acnp_bc_inout_id_dbh + use PRTAllometricCNPMod, only : acnp_bc_in_id_pft + use PRTAllometricCNPMod, only : acnp_bc_in_id_nc_repro + use PRTAllometricCNPMod, only : acnp_bc_in_id_pc_repro + + implicit none + + @TestCase + type, extends(TestCase) :: TestPRTAllomCNP + type(cnp_allom_prt_vartypes) :: cnp_allom_prt + !contains + ! procedure :: setUp + end type TestPRTAllomCNP + + ! assertEqual tolerance + real(r8), parameter :: tol = 1.e-13_r8 + + contains + + !subroutine setUp(this) + ! class(TestPRTAllomCNP), intent(inout) :: this + ! ! Globals and parameters + !end subroutine setUp + + @Test + subroutine EstimateGrowthNC_ReproBoundsCheck(this) + + ! Test that CN growth estimate passes if the C reproductive fraction is exactly one + + class(TestPRTAllomCNP), intent(inout) :: this ! test object + + !! Globals + ! targets for associations + integer, parameter :: repro_id = 5 ! non-public parameter from PRTAllometricCNPMod + integer, parameter :: num_intgr_vars = 7 + integer, target :: ipft = 1 + real(r8), target :: dbh = 1._r8 + real(r8), target :: nc_repro = 0._r8 + real(r8), target :: pc_repro = 0._r8 + + !! subroutine arguments + ! Dummy arguments, not used for repro_id case + real(r8) :: dummy_target_c(1) = 0._r8 + real(r8) :: dummy_target_dcdd(1) = 0._r8 + + ! Necessary arguments + logical :: state_mask(num_intgr_vars) = .false. ! state mask, intent(in) + real(r8) :: avg_nc ! Average N:C ratio, intent(out) + real(r8) :: avg_pc ! Average P:C ratio, intent(out) + + ! Initialize the prt_param type and values + allocate(prt_params%allom_dbh_maxheight(acnp_bc_in_id_pft)) + allocate(prt_params%dbh_repro_threshold(acnp_bc_in_id_pft)) + allocate(prt_params%seed_alloc(acnp_bc_in_id_pft)) + + prt_params%allom_dbh_maxheight(acnp_bc_in_id_pft) = 1000._r8 ! current default param + prt_params%dbh_repro_threshold(acnp_bc_in_id_pft) = 90._r8 ! current default param + prt_params%seed_alloc(acnp_bc_in_id_pft) = 1._r8 ! assigned to repro_c_frac + + ! Unused for repro check + allocate(prt_params%seed_alloc_mature(acnp_bc_in_id_pft)) + allocate(prt_params%repro_alloc_b(acnp_bc_in_id_pft)) + allocate(prt_params%repro_alloc_a(acnp_bc_in_id_pft)) + allocate(prt_params%organ_param_id(1)) + allocate(prt_params%nitr_stoich_p1(1,1)) + allocate(prt_params%phos_stoich_p1(1,1)) + + ! Manually initialize minimum necessary PRT vartype subtypes + allocate(this%cnp_allom_prt%bc_inout(acnp_bc_inout_id_dbh)) + allocate(this%cnp_allom_prt%bc_in(acnp_bc_in_id_pc_repro)) + + this%cnp_allom_prt%bc_inout(acnp_bc_inout_id_dbh)%rval => dbh + this%cnp_allom_prt%bc_in(acnp_bc_in_id_pft)%ival => ipft + this%cnp_allom_prt%bc_in(acnp_bc_in_id_nc_repro)%rval => nc_repro + this%cnp_allom_prt%bc_in(acnp_bc_in_id_pc_repro)%rval => pc_repro + + ! only test the repro_id case + state_mask(repro_id) = .true. + + call this%cnp_allom_prt%EstimateGrowthNC(dummy_target_c,dummy_target_dcdd, & + state_mask,avg_nc,avg_pc) + + @assertEqual(avg_nc, 1._r8, tolerance=tol) + @assertEqual(avg_pc, 1._r8, tolerance=tol) + + end subroutine EstimateGrowthNC_ReproBoundsCheck + + +end module test_PRTAllometricCNP diff --git a/testing/unit_tests.cfg b/testing/unit_tests.cfg index 179b924735..cd776e6130 100644 --- a/testing/unit_tests.cfg +++ b/testing/unit_tests.cfg @@ -3,3 +3,6 @@ test_dir = fates_fire_weather_utest [fire_fuel] test_dir = fates_fire_fuel_utest + +[parteh] +test_dir = fates_parteh_utest