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

Make sure FORTRAN code properly aborts when fire-emission is asked for and it can't be provided #2844

Draft
wants to merge 5 commits into
base: cesm3_0_beta04_changes
Choose a base branch
from
Draft
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
8 changes: 8 additions & 0 deletions bld/unit_testers/build-namelist_test.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,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",
Expand Down
18 changes: 12 additions & 6 deletions cime_config/config_component.xml
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,18 @@
<type>char</type>
<default_value></default_value>
<values>
<!--- All versions -->
<value compset="_CLM[^_]*%SP" >-bgc sp</value>
<value compset="_CLM[^_]*BGC" >-bgc bgc</value>
<value compset="_CLM[^_]*BGC-CROP" >-bgc bgc -crop</value>
<value compset="_CLM[^_]*FATES" >-bgc fates -no-megan</value>
<value compset="_CLM[^_]*FATES-SP" >-bgc fates -no-megan</value>
<!--- All versions with DATM -->
<value compset="DATM[^_]*_CLM[^_]*%SP" >-bgc sp</value>
<value compset="DATM[^_]*_CLM[^_]*BGC" >-bgc bgc</value>
<value compset="DATM[^_]*_CLM[^_]*BGC-CROP" >-bgc bgc -crop</value>

<!-- FATES currently can't use MEGAN, drydep, or fire-emission whether coupled to CAM or NOT-->
<value compset="CLM[^_]*FATES" >--bgc fates --no-megan --no-drydep --no-fire_emiss</value>

<!--- All versions with CAM - turn off sending test drv_flds_in namelists from CTSM -->
<value compset="CAM[^_]*_CLM[^_]*%SP" >--bgc sp --no-megan --no-drydep --no-fire_emiss</value>
<value compset="CAM[^_]*_CLM[^_]*BGC" >--bgc bgc --no-megan --no-drydep --no-fire_emiss</value>
<value compset="CAM[^_]*_CLM[^_]*BGC-CROP" >--bgc bgc --crop --no-megan --no-drydep --no-fire_emiss</value>

<!-- Options specific for CLM4.5 -->
<value compset="_CLM45%[^_]*BGCDV" >-bgc bgc -dynamic_vegetation</value>
Expand Down
9 changes: 9 additions & 0 deletions src/biogeochem/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/biogeochem/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ add_subdirectory(CNVegComputeSeed_test)
add_subdirectory(CNPhenology_test)
add_subdirectory(Latbaset_test)
add_subdirectory(DustEmis_test)
add_subdirectory(CNFireFactory_test)
7 changes: 7 additions & 0 deletions src/biogeochem/test/CNFireFactory_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
78 changes: 78 additions & 0 deletions src/biogeochem/test/CNFireFactory_test/test_CNFireFactory.pf
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions src/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ list(APPEND clm_sources
column_varcon.F90
decompMod.F90
filterColMod.F90
FireMethodType.F90
glc2lndMod.F90
glcBehaviorMod.F90
initSubgridMod.F90
Expand Down
1 change: 1 addition & 0 deletions src/soilbiogeochem/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/unit_test_stubs/share_esmf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
list(APPEND clm_sources
ExcessIceStreamType.F90
FireDataBaseType.F90
PrigentRoughnessStreamType.F90
ZenderSoilErodStreamType.F90
)
Expand Down
123 changes: 123 additions & 0 deletions src/unit_test_stubs/share_esmf/FireDataBaseType.F90
Original file line number Diff line number Diff line change
@@ -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
Loading