From 13e543725f58c09535757e7a9049344786c4eabd Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Thu, 3 Oct 2024 16:01:00 -0600 Subject: [PATCH 1/6] Add tests for fire_emis with SP bgc mode or BGC mode with nofire, they fail as expected --- bld/unit_testers/build-namelist_test.pl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bld/unit_testers/build-namelist_test.pl b/bld/unit_testers/build-namelist_test.pl index 096409065f..7f46c23790 100755 --- a/bld/unit_testers/build-namelist_test.pl +++ b/bld/unit_testers/build-namelist_test.pl @@ -1111,6 +1111,14 @@ sub cat_and_create_namelistinfile { namelst=>"", phys=>"clm4_5", }, + "useFIREEMISwithNOFIRE" =>{ options=>"--bgc bgc --envxml_dir . --fire_emis", + namelst=>"fire_method='nofire'", + phys=>"clm6_0", + }, + "useFIREEMISwithSP" =>{ options=>"--bgc sp --envxml_dir . --fire_emis", + namelst=>"", + phys=>"clm6_0", + }, "useDRYDEPwithFATES" =>{ options=>"--bgc fates --envxml_dir . --no-megan --drydep", namelst=>"", phys=>"clm4_5", From 36126dc5e1f1883f3ad1b2104bfb893414d26185 Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Fri, 11 Oct 2024 14:26:25 -0600 Subject: [PATCH 2/6] Make CLM_BLDNML_OPTS explicitly turn off drv_flds_in options off for FATES, and also off when coupled to CAM --- cime_config/config_component.xml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/cime_config/config_component.xml b/cime_config/config_component.xml index 540d285a85..c91f81d3cd 100644 --- a/cime_config/config_component.xml +++ b/cime_config/config_component.xml @@ -251,12 +251,18 @@ char - - -bgc sp - -bgc bgc - -bgc bgc -crop - -bgc fates -no-megan - -bgc fates -no-megan + + -bgc sp + -bgc bgc + -bgc bgc -crop + + + --bgc fates --no-megan --no-drydep --no-fire_emiss + + + --bgc sp --no-megan --no-drydep --no-fire_emiss + --bgc bgc --no-megan --no-drydep --no-fire_emiss + --bgc bgc --crop --no-megan --no-drydep --no-fire_emiss -bgc bgc -dynamic_vegetation From 8653d3508fe8d9f0249cc6478d77b39e89423ea9 Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Tue, 22 Oct 2024 23:46:46 -0600 Subject: [PATCH 3/6] Start adding a unit tests for CNFireFactory with just a single simple initialization of the CNFireNorFire class --- .../test/CNFireFactory_test/CMakeLists.txt | 7 + .../CNFireFactory_test/test_CNFireFactory.pf | 78 +++++++++++ .../share_esmf/FireDataBaseType.F90 | 123 ++++++++++++++++++ 3 files changed, 208 insertions(+) create mode 100644 src/biogeochem/test/CNFireFactory_test/CMakeLists.txt create mode 100644 src/biogeochem/test/CNFireFactory_test/test_CNFireFactory.pf create mode 100644 src/unit_test_stubs/share_esmf/FireDataBaseType.F90 diff --git a/src/biogeochem/test/CNFireFactory_test/CMakeLists.txt b/src/biogeochem/test/CNFireFactory_test/CMakeLists.txt new file mode 100644 index 0000000000..433b499197 --- /dev/null +++ b/src/biogeochem/test/CNFireFactory_test/CMakeLists.txt @@ -0,0 +1,7 @@ +set (pfunit_sources + test_CNFireFactory.pf +) + +add_pfunit_ctest(CNFireFActory + TEST_SOURCES "${pfunit_sources}" + LINK_LIBRARIES clm csm_share esmf_wrf_timemgr) diff --git a/src/biogeochem/test/CNFireFactory_test/test_CNFireFactory.pf b/src/biogeochem/test/CNFireFactory_test/test_CNFireFactory.pf new file mode 100644 index 0000000000..1972aa1f23 --- /dev/null +++ b/src/biogeochem/test/CNFireFactory_test/test_CNFireFactory.pf @@ -0,0 +1,78 @@ +module test_CNFireFactory + + ! Tests of CNFireFactory + + use funit + use unittestSubgridMod, only : bounds + use FireMethodType , only : fire_method_type + use CNFireFactoryMod + use shr_kind_mod , only : r8 => shr_kind_r8 + + implicit none + + character(len=5) :: NLFilename = 'firefactorytest_nml' + + @TestCase + type, extends(TestCase) :: TestCNFireFactory + class(fire_method_type), allocatable :: cnfire_method + contains + procedure :: setUp + procedure :: tearDown + procedure :: Init + end type TestCNFireFactory + + contains + + !----------------------------------------------------------------------- + + subroutine setUp(this) + class(TestCNFireFactory), intent(inout) :: this + + integer :: unitn + + ! Create an exmpty namelist file for lifire namelist reading + open( newunit=unitn, file=trim(NLFilename), status='new' ) + write(unitn,*) '&lifire_inparm' + write(unitn,*) '/' + close(unitn) + + end subroutine setUp + !----------------------------------------------------------------------- + + subroutine tearDown(this) + use shr_sys_mod, only : shr_sys_system + class(TestCNFireFactory), intent(inout) :: this + + integer :: rc + + ! A clean method should be added to the fire method class structures + deallocate( this%cnfire_method ) + ! Remove the namelist file + call shr_sys_system( "/bin/rm -f "//trim(NLFilename), rc ) + @assertEqual( rc, 0, "error in removal of temporary lifire namelist file") + + end subroutine tearDown + + !----------------------------------------------------------------------- + + subroutine Init(this, fire_method) + class(TestCNFireFactory), intent(inout) :: this + character(len=*), intent(in) :: fire_method + + call create_cnfire_method(NLFilename, this%cnfire_method) + + end subroutine Init + + !----------------------------------------------------------------------- + + @Test + subroutine nofire_works(this) + class(TestCNFireFactory), intent(inout) :: this + + call this%Init( fire_method = "none") + + end subroutine nofire_works + + !----------------------------------------------------------------------- + +end module test_CNFireFactory \ No newline at end of file diff --git a/src/unit_test_stubs/share_esmf/FireDataBaseType.F90 b/src/unit_test_stubs/share_esmf/FireDataBaseType.F90 new file mode 100644 index 0000000000..57ed5f3631 --- /dev/null +++ b/src/unit_test_stubs/share_esmf/FireDataBaseType.F90 @@ -0,0 +1,123 @@ +module FireDataBaseType + +#include "shr_assert.h" + + !----------------------------------------------------------------------- + ! !DESCRIPTION: + ! module for handling of fire data + ! UNIT-TEST STUB for fire data Streams + ! This just allows the fire code to be tested without + ! reading in the streams data, by faking it and setting it to a + ! constant value. + ! + ! !USES: + use shr_kind_mod , only : r8 => shr_kind_r8, CL => shr_kind_CL + use shr_log_mod , only : errMsg => shr_log_errMsg + use clm_varctl , only : iulog + use spmdMod , only : masterproc, mpicom, iam + use abortutils , only : endrun + use decompMod , only : bounds_type + use FireMethodType , only : fire_method_type + ! + implicit none + private + ! + ! !PUBLIC TYPES: + public :: fire_base_type + ! + type, abstract, extends(fire_method_type) :: fire_base_type + private + ! !PRIVATE MEMBER DATA: + real(r8), public, pointer :: forc_hdm(:) ! Human population density + real(r8), public, pointer :: forc_lnfm(:) ! Lightning frequency + real(r8), public, pointer :: gdp_lf_col(:) ! col global real gdp data (k US$/capita) + real(r8), public, pointer :: peatf_lf_col(:) ! col global peatland fraction data (0-1) + integer , public, pointer :: abm_lf_col(:) ! col global peak month of crop fire emissions + + contains + ! + ! !PUBLIC MEMBER FUNCTIONS: + procedure, public :: FireInit => BaseFireInit ! Initialization of Fire + procedure, public :: BaseFireInit ! Initialization of Fire + procedure, public :: FireInterp ! Interpolate fire data + procedure(FireReadNML_interface), public, deferred :: & + FireReadNML ! Read in namelist for Fire + procedure(need_lightning_and_popdens_interface), public, deferred :: & + need_lightning_and_popdens ! Returns true if need lightning & popdens + + end type fire_base_type + + abstract interface + !----------------------------------------------------------------------- + function need_lightning_and_popdens_interface(this) result(need_lightning_and_popdens) + ! + ! !DESCRIPTION: + ! Returns true if need lightning and popdens, false otherwise + ! + ! USES + import :: fire_base_type + ! + ! !ARGUMENTS: + class(fire_base_type), intent(in) :: this + logical :: need_lightning_and_popdens ! function result + !----------------------------------------------------------------------- + end function need_lightning_and_popdens_interface + end interface + + character(len=*), parameter, private :: sourcefile = & + __FILE__ + +!============================================================================== +contains +!============================================================================== + + subroutine FireReadNML_interface( this, NLFilename ) + ! + ! !DESCRIPTION: + ! Read the namelist for Fire + ! + ! !USES: + ! + ! !ARGUMENTS: + class(fire_base_type) :: this + character(len=*), intent(in) :: NLFilename ! Namelist filename + end subroutine FireReadNML_interface + + !================================================================ + subroutine BaseFireInit( this, bounds, NLFilename ) + ! + ! !DESCRIPTION: + ! Initialize CN Fire module + ! !USES: + use shr_infnan_mod , only : nan => shr_infnan_nan, assignment(=) + ! + ! !ARGUMENTS: + class(fire_base_type) :: this + type(bounds_type), intent(in) :: bounds + character(len=*), intent(in) :: NLFilename + !----------------------------------------------------------------------- + + if ( this%need_lightning_and_popdens() ) then + + end if + + end subroutine BaseFireInit + + !================================================================ + subroutine FireInterp(this,bounds) + ! + ! !DESCRIPTION: + ! Interpolate CN Fire datasets + ! + ! !ARGUMENTS: + class(fire_base_type) :: this + type(bounds_type), intent(in) :: bounds + !----------------------------------------------------------------------- + + if ( this%need_lightning_and_popdens() ) then + + end if + + end subroutine FireInterp + +end module FireDataBaseType From b98fe8c071c292e9b04d1126a85fb5a44dc703e1 Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Tue, 22 Oct 2024 23:48:26 -0600 Subject: [PATCH 4/6] Start adding a unit tests for CNFireFactory with just a single simple initialization of the CNFireNorFire class --- src/biogeochem/CMakeLists.txt | 9 +++++++++ src/biogeochem/test/CMakeLists.txt | 1 + src/main/CMakeLists.txt | 1 + src/soilbiogeochem/CMakeLists.txt | 1 + src/unit_test_stubs/share_esmf/CMakeLists.txt | 1 + 5 files changed, 13 insertions(+) diff --git a/src/biogeochem/CMakeLists.txt b/src/biogeochem/CMakeLists.txt index 270e85838b..7858f3282f 100644 --- a/src/biogeochem/CMakeLists.txt +++ b/src/biogeochem/CMakeLists.txt @@ -2,6 +2,7 @@ # source files that are currently used in unit tests list(APPEND clm_sources + ch4varcon.F90 CNSharedParamsMod.F90 CNPhenologyMod.F90 CNSpeciesMod.F90 @@ -12,6 +13,14 @@ list(APPEND clm_sources DustEmisFactory.F90 CropReprPoolsMod.F90 CropType.F90 + CNFireBaseMod.F90 + CNFireNoFireMod.F90 + CNFireFactoryMod.F90 + CNFireLi2014Mod.F90 + CNFireLi2016Mod.F90 + CNFireLi2021Mod.F90 + CNFireLi2024Mod.F90 + CNVegMatrixMod.F90 CNVegStateType.F90 CNVegCarbonStateType.F90 CNVegCarbonFluxType.F90 diff --git a/src/biogeochem/test/CMakeLists.txt b/src/biogeochem/test/CMakeLists.txt index e22a720523..9cfe1bb847 100644 --- a/src/biogeochem/test/CMakeLists.txt +++ b/src/biogeochem/test/CMakeLists.txt @@ -3,3 +3,4 @@ add_subdirectory(CNVegComputeSeed_test) add_subdirectory(CNPhenology_test) add_subdirectory(Latbaset_test) add_subdirectory(DustEmis_test) +add_subdirectory(CNFireFactory_test) diff --git a/src/main/CMakeLists.txt b/src/main/CMakeLists.txt index 53a6edb8a5..fc324efeb9 100644 --- a/src/main/CMakeLists.txt +++ b/src/main/CMakeLists.txt @@ -20,6 +20,7 @@ list(APPEND clm_sources column_varcon.F90 decompMod.F90 filterColMod.F90 + FireMethodType.F90 glc2lndMod.F90 glcBehaviorMod.F90 initSubgridMod.F90 diff --git a/src/soilbiogeochem/CMakeLists.txt b/src/soilbiogeochem/CMakeLists.txt index e2baa2d1b2..ac467c3e5f 100644 --- a/src/soilbiogeochem/CMakeLists.txt +++ b/src/soilbiogeochem/CMakeLists.txt @@ -2,6 +2,7 @@ # source files that are currently used in unit tests list(APPEND clm_sources + SoilBiogeochemCarbonFluxType.F90 SoilBiogeochemStateType.F90 SoilBiogeochemDecompCascadeConType.F90 SoilBiogeochemStateType.F90 diff --git a/src/unit_test_stubs/share_esmf/CMakeLists.txt b/src/unit_test_stubs/share_esmf/CMakeLists.txt index 1d767543ea..ff92598eaf 100644 --- a/src/unit_test_stubs/share_esmf/CMakeLists.txt +++ b/src/unit_test_stubs/share_esmf/CMakeLists.txt @@ -1,5 +1,6 @@ list(APPEND clm_sources ExcessIceStreamType.F90 + FireDataBaseType.F90 PrigentRoughnessStreamType.F90 ZenderSoilErodStreamType.F90 ) From 2c330c0b66dc241c88f0a87e3c9cd4178b1d7225 Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Thu, 6 Feb 2025 16:26:13 -0700 Subject: [PATCH 5/6] Change to full ESMF library --- src/biogeochem/test/CNFireFactory_test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/biogeochem/test/CNFireFactory_test/CMakeLists.txt b/src/biogeochem/test/CNFireFactory_test/CMakeLists.txt index 433b499197..032e0fa953 100644 --- a/src/biogeochem/test/CNFireFactory_test/CMakeLists.txt +++ b/src/biogeochem/test/CNFireFactory_test/CMakeLists.txt @@ -4,4 +4,4 @@ set (pfunit_sources add_pfunit_ctest(CNFireFActory TEST_SOURCES "${pfunit_sources}" - LINK_LIBRARIES clm csm_share esmf_wrf_timemgr) + LINK_LIBRARIES clm csm_share esmf) From 6d0f1e50a8f56fc04b9486e948c819f9be59b57d Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Fri, 7 Feb 2025 01:18:19 -0700 Subject: [PATCH 6/6] Add tests for each of the Li fire types --- .../CNFireFactory_test/test_CNFireFactory.pf | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/biogeochem/test/CNFireFactory_test/test_CNFireFactory.pf b/src/biogeochem/test/CNFireFactory_test/test_CNFireFactory.pf index 1972aa1f23..3ff93fe151 100644 --- a/src/biogeochem/test/CNFireFactory_test/test_CNFireFactory.pf +++ b/src/biogeochem/test/CNFireFactory_test/test_CNFireFactory.pf @@ -75,4 +75,44 @@ module test_CNFireFactory !----------------------------------------------------------------------- -end module test_CNFireFactory \ No newline at end of file + @Test + subroutine li2014_works(this) + class(TestCNFireFactory), intent(inout) :: this + + call this%Init( fire_method = "li2014qianfrc") + + end subroutine li2014_works + + !----------------------------------------------------------------------- + + @Test + subroutine li2016_works(this) + class(TestCNFireFactory), intent(inout) :: this + + call this%Init( fire_method = "li2016crufrc") + + end subroutine li2016_works + + !----------------------------------------------------------------------- + + @Test + subroutine li2021_works(this) + class(TestCNFireFactory), intent(inout) :: this + + call this%Init( fire_method = "li2021gswpfrc") + + end subroutine li2021_works + + !----------------------------------------------------------------------- + + @Test + subroutine li2024_works(this) + class(TestCNFireFactory), intent(inout) :: this + + call this%Init( fire_method = "li2024gswpfrc") + + end subroutine li2024_works + + !----------------------------------------------------------------------- + +end module test_CNFireFactory