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

Open
wants to merge 36 commits into
base: cesm3_0_beta04_changes
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
13e5437
Add tests for fire_emis with SP bgc mode or BGC mode with nofire, the…
ekluzek Oct 3, 2024
36126dc
Make CLM_BLDNML_OPTS explicitly turn off drv_flds_in options off for …
ekluzek Oct 11, 2024
8653d35
Start adding a unit tests for CNFireFactory with just a single simple…
ekluzek Oct 23, 2024
b98fe8c
Start adding a unit tests for CNFireFactory with just a single simple…
ekluzek Oct 23, 2024
cfff96a
Merge remote-tracking branch 'escomp/cesm3_0_beta04_changes' into fir…
ekluzek Oct 23, 2024
69e1ccf
Merge remote-tracking branch 'escomp/cesm3_0_beta04_changes' into fir…
ekluzek Feb 6, 2025
2c330c0
Change to full ESMF library
ekluzek Feb 6, 2025
6d0f1e5
Add tests for each of the Li fire types
ekluzek Feb 7, 2025
3d81a1b
Add LAI stream to compile list
ekluzek Mar 4, 2025
9f7527e
Add check_dim_size
ekluzek Mar 4, 2025
e022783
Add FireClean method
ekluzek Mar 4, 2025
29b5b61
Make pointers set to NULL, and add BaseFireClean method
ekluzek Mar 4, 2025
61826eb
Add shr_expr and fire_emis to list
ekluzek Mar 4, 2025
de0c358
Add more setup and teardown, and also add several more tests, and inc…
ekluzek Mar 4, 2025
d4707b6
Initialize pointer to NULL, add clean method, add some returns after …
ekluzek Mar 4, 2025
fad3d1b
Add a note about the call to the base BaseFireClean method failing at…
ekluzek Mar 4, 2025
2fcc081
Get one of the failing tests working by implementing an init method t…
ekluzek Mar 5, 2025
39661d6
Get the last test working by aborting if fire-emissions are on in SP …
ekluzek Mar 5, 2025
ed88834
Add CNFireSetFireMethod for unit testing of the CNFireFactory, remove…
ekluzek Mar 5, 2025
570c5fe
Initialize fire_method to UNSET, so it will fail if it isn't set by s…
ekluzek Mar 6, 2025
6bcac0c
The unit testing actually doesn't need to call the fire_emis namelist…
ekluzek Mar 6, 2025
ad3d766
Add FATES Fire factory files to list
ekluzek Mar 6, 2025
4e36aa4
Add unit-tester for FATESFireFactory, two tests pass, two fail becaus…
ekluzek Mar 7, 2025
52c290a
Add unit-tester for FATESFireFactory, two tests pass, two fail becaus…
ekluzek Mar 7, 2025
a6fb39a
Get another test working, by checking that fire-emissions are off for…
ekluzek Mar 7, 2025
bbcc2a1
Merge tag 'ctsm5.3.030' into fire_emis
ekluzek Mar 7, 2025
99676ab
Don't allocate cnfire if NOT a BGC case
ekluzek Mar 10, 2025
bf6170e
Don't set stream types to NULL as they aren't pointers
ekluzek Mar 10, 2025
236a0a4
Make sure fire-emissions is off for FatesSp and FatesSt3 modes, which…
ekluzek Mar 11, 2025
14ad093
Add a fates_use_ed_st3 test and make sure it works
ekluzek Mar 11, 2025
1e5bfff
Get new namelist tests to work
ekluzek Mar 12, 2025
ae3fc28
Add failing test that both fates_sp and fates_st3 can be active at th…
ekluzek Mar 13, 2025
d7a23c7
Merge remote-tracking branch 'escomp/cesm3_0_beta04_changes' into fir…
ekluzek Mar 13, 2025
d0ba1ac
Change query of use_fates_sp to use nl_flags
ekluzek Mar 13, 2025
026d24f
Another update to use nl_flags query for use_fates_sp
ekluzek Mar 13, 2025
8caba7c
Don't allow both use_fates_sp and use_fates_ed_st3 to be on at the sa…
ekluzek Mar 13, 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
59 changes: 36 additions & 23 deletions bld/CLMBuildNamelist.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4073,7 +4073,16 @@ sub setup_logic_fire_emis {
if ( &value_is_true( $nl_flags->{'use_fates'} ) ) {
$log->warning("Fire emission option $var can NOT be on when FATES is also on.\n" .
" DON'T use the '--fire_emis' option when '--bgc fates' is activated");
}
} elsif ( ! &value_is_true( $nl_flags->{'use_cn'} ) ) {
$log->fatal_error("Fire emission option $var can NOT be on BGC SP Satellite Phenology.\n" .
" DON'T use the '--fire_emis' option when '--bgc sp' is activated");
} elsif ( &value_is_true( $nl_flags->{'use_cn'}) ) {
my $fire_method = remove_leading_and_trailing_quotes( $nl->get_value('fire_method') );
if ( $fire_method eq "nofire" ) {
$log->fatal_error("Fire emission option $var can NOT be on with BGC and fire_method=='nofire'.\n" .
" DON'T use the '--fire_emis' option when fire_method is nofire");
}
}
}
}
}
Expand Down Expand Up @@ -4236,7 +4245,7 @@ sub setup_logic_lai_streams {
if ( &value_is_true($nl_flags->{'use_crop'}) && &value_is_true($nl->get_value('use_lai_streams')) ) {
$log->fatal_error("turning use_lai_streams on is incompatable with use_crop set to true.");
}
if ( $nl_flags->{'bgc_mode'} eq "sp" || ($nl_flags->{'bgc_mode'} eq "fates" && &value_is_true($nl->get_value('use_fates_sp')) )) {
if ( $nl_flags->{'bgc_mode'} eq "sp" || ($nl_flags->{'bgc_mode'} eq "fates" && &value_is_true($nl_flags->{'use_fates_sp'}) )) {
if ( &value_is_true($nl->get_value('use_lai_streams')) ) {
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'use_lai_streams');
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'lai_mapalgo',
Expand Down Expand Up @@ -4746,29 +4755,26 @@ sub setup_logic_fates {
# For FATES SP mode make sure no-competetiion, and fixed-biogeography are also set
# And also check for other settings that can't be trigged on as well
#
my $var = "use_fates_sp";
if ( defined($nl->get_value($var)) ) {
if ( &value_is_true($nl->get_value($var)) ) {
my @list = ( "use_fates_nocomp", "use_fates_fixed_biogeog" );
foreach my $var ( @list ) {
if ( ! &value_is_true($nl->get_value($var)) ) {
$log->fatal_error("$var is required when FATES SP is on (use_fates_sp)" );
}
}
# spit-fire can't be on with FATES SP mode is active
if ( $nl->get_value('fates_spitfire_mode') > 0 ) {
$log->fatal_error('fates_spitfire_mode can NOT be set to greater than 0 when use_fates_sp is true');
}
if ( &value_is_true($nl_flags->{'use_fates_sp'}) ) {
my @list = ( "use_fates_nocomp", "use_fates_fixed_biogeog" );
foreach my $var ( @list ) {
if ( ! &value_is_true($nl->get_value($var)) ) {
$log->fatal_error("$var is required when FATES SP is on (use_fates_sp)" );
}
}
# spit-fire can't be on with FATES SP mode is active
if ( $nl->get_value('fates_spitfire_mode') > 0 ) {
$log->fatal_error('fates_spitfire_mode can NOT be set to greater than 0 when use_fates_sp is true');
}

# fates landuse can't be on with FATES SP mode is active
if ( &value_is_true($nl->get_value('use_fates_luh')) ) {
$log->fatal_error('use_fates_luh can NOT be true when use_fates_sp is true');
}
# fates landuse can't be on with FATES SP mode is active
if ( &value_is_true($nl->get_value('use_fates_luh')) ) {
$log->fatal_error('use_fates_luh can NOT be true when use_fates_sp is true');
}

# hydro isn't currently supported to work when FATES SP mode is active
if (&value_is_true( $nl->get_value('use_fates_planthydro') )) {
$log->fatal_error('fates sp mode is currently not supported to work with fates hydro');
}
# hydro isn't currently supported to work when FATES SP mode is active
if (&value_is_true( $nl->get_value('use_fates_planthydro') )) {
$log->fatal_error('fates sp mode is currently not supported to work with fates hydro');
}
}
my $var = "use_fates_inventory_init";
Expand All @@ -4793,6 +4799,13 @@ sub setup_logic_fates {
}
}
}
# Check that both FaTES-SP and FATES ST3 aren't both on
my $var = "use_fates_ed_st3";
if ( defined($nl->get_value($var)) ) {
if ( &value_is_true($nl->get_value($var)) && &value_is_true($nl_flags->{'use_fates_sp'}) ) {
$log->fatal_error("$var can NOT also be true with use_fates_sp true" );
}
}
# check that fates landuse change mode has the necessary luh2 landuse timeseries data
# and add the default if not defined. Do not add default if use_fates_potentialveg is true.
# If fixed biogeography is on, make sure that flandusepftdat is avilable.
Expand Down
20 changes: 16 additions & 4 deletions bld/unit_testers/build-namelist_test.pl
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ sub cat_and_create_namelistinfile {
#
# Figure out number of tests that will run
#
my $ntests = 3264;
my $ntests = 3375;

if ( defined($opts{'compare'}) ) {
$ntests += 1980;
Expand Down Expand Up @@ -288,7 +288,7 @@ sub cat_and_create_namelistinfile {
&make_config_cache($phys);
my @mfiles = ( "lnd_in", "drv_flds_in", $tempfile );
my $mfiles = NMLTest::CompFiles->new( $cwd, @mfiles );
foreach my $options ( "-drydep", "-megan", "-drydep -megan", "-fire_emis", "-drydep -megan -fire_emis" ) {
foreach my $options ( "-drydep --bgc sp", "-megan --bgc sp", "-drydep -megan --bgc bgc", "-fire_emis --bgc bgc", "-drydep -megan -fire_emis --bgc bgc" ) {
&make_env_run();
eval{ system( "$bldnml -envxml_dir . $options > $tempfile 2>&1 " ); };
is( $@, '', "options: $options" );
Expand Down Expand Up @@ -576,8 +576,8 @@ sub cat_and_create_namelistinfile {
"--res 1.9x2.5 --bgc bgc --use_case 1850-2100_SSP2-4.5_transient --namelist '&a start_ymd=19101023/'",
"-namelist \"&a dust_emis_method='Zender_2003', zender_soil_erod_source='lnd' /'\"",
"-bgc bgc -use_case 2000_control -namelist \"&a fire_method='nofire'/\" -crop",
"-res 0.9x1.25 -bgc sp -use_case 1850_noanthro_control -drydep -fire_emis",
"-res 0.9x1.25 -bgc bgc -use_case 1850_noanthro_control -drydep -fire_emis -light_res 360x720",
"-res 0.9x1.25 -bgc sp -use_case 1850_noanthro_control -drydep",
"-res 0.9x1.25 -bgc bgc -use_case 1850_noanthro_control -drydep -fire_emis -megan -light_res 360x720",
"--bgc bgc --light_res none --namelist \"&a fire_method='nofire'/\"",
"--bgc fates --light_res 360x720 --no-megan --namelist \"&a fates_spitfire_mode=2/\"",
"--bgc fates --light_res none --no-megan --namelist \"&a fates_spitfire_mode=1/\"",
Expand Down Expand Up @@ -1093,6 +1093,10 @@ sub cat_and_create_namelistinfile {
namelst=>"suplnitro='NONE'",
phys=>"clm6_0",
},
"FATESwBothSpST3" =>{ options=>"--bgc fates --envxml_dir . --no-megan",
namelst=>"use_fates_sp = TRUE, use_fates_ed_st3 = TRUE",
phys=>"clm6_0",
},
"FireNoneButBGCfireon" =>{ options=>"-bgc bgc -envxml_dir . -light_res none",
namelst=>"fire_method='li2021gswpfrc'",
phys=>"clm6_0",
Expand Down Expand Up @@ -1145,6 +1149,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 @@ -241,12 +241,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
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ add_subdirectory(${CLM_ROOT}/share/unit_test_stubs/util csm_share_stubs)
list ( APPEND drv_sources_needed
${CLM_ROOT}/components/cmeps/cesm/nuopc_cap_share/glc_elevclass_mod.F90
${CLM_ROOT}/components/cmeps/cesm/nuopc_cap_share/shr_dust_emis_mod.F90
${CLM_ROOT}/components/cmeps/cesm/nuopc_cap_share/shr_expr_parser_mod.F90
${CLM_ROOT}/components/cmeps/cesm/nuopc_cap_share/shr_fire_emis_mod.F90
)

# Add CLM source directories
Expand Down
14 changes: 14 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 All @@ -20,6 +29,11 @@ list(APPEND clm_sources
CNVegNitrogenFluxType.F90
CNCIsoAtmTimeSeriesReadMod.F90
CNVegComputeSeedMod.F90
FATESFireBase.F90
FATESFireDataMod.F90
FATESFireFactoryMod.F90
FATESFireNoDataMod.F90
SatellitePhenologyMod.F90
SpeciesBaseType.F90
SpeciesIsotopeType.F90
SpeciesNonIsotopeType.F90
Expand Down
26 changes: 24 additions & 2 deletions src/biogeochem/CNFireBaseMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,15 @@ module CNFireBaseMod
private
! !PRIVATE MEMBER DATA:
! !PUBLIC MEMBER DATA (used by extensions of the base class):
real(r8), public, pointer :: btran2_patch (:) ! patch root zone soil wetness factor (0 to 1)
real(r8), public, pointer :: btran2_patch (:) => NULL() ! patch root zone soil wetness factor (0 to 1)

contains
!
! !PUBLIC MEMBER FUNCTIONS:
procedure, public :: CNFireInit ! Initialization of Fire
procedure, public :: FireInit => CNFireInit ! Initialization of Fire
procedure, public :: CNFireCleanBase ! Deallocate fire data
procedure, public :: FireClean => CNFireCleanBase ! Deallocate fire data
procedure, public :: FireReadNML ! Read in namelist for CNFire
procedure, public :: CNFireReadParams ! Read in constant parameters from the paramsfile
procedure, public :: CNFireFluxes ! Calculate fire fluxes
Expand Down Expand Up @@ -185,6 +188,24 @@ subroutine InitHistory( this, bounds )
ptr_patch=this%btran2_patch, l2g_scale_type='veg')
end subroutine InitHistory

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

subroutine CNFireCleanBase( this )
!
! Deallocate data
!
! !ARGUMENTS:
class(cnfire_base_type) :: this
!-----------------------------------------------------------------------
! Call the base class clean method
!call this%BaseFireClean()

if ( associated(this%btran2_patch) )then
deallocate(this%btran2_patch)
end if
this%btran2_patch => NULL()
end subroutine CNFireCleanBase

!----------------------------------------------------------------------
subroutine CNFire_calc_fire_root_wetness_Li2014( this, bounds, &
num_exposedvegp, filter_exposedvegp, num_noexposedvegp, filter_noexposedvegp, &
Expand Down Expand Up @@ -331,7 +352,6 @@ subroutine FireReadNML( this, NLFilename )
use shr_nl_mod , only : shr_nl_find_group_name
use spmdMod , only : masterproc, mpicom
use shr_mpi_mod , only : shr_mpi_bcast
use clm_varctl , only : iulog
!
! !ARGUMENTS:
class(cnfire_base_type) :: this
Expand Down Expand Up @@ -392,9 +412,11 @@ subroutine FireReadNML( this, NLFilename )
read(unitn, nml=lifire_inparm, iostat=ierr)
if (ierr /= 0) then
call endrun(msg="ERROR reading "//nmlname//"namelist"//errmsg(sourcefile, __LINE__))
return
end if
else
call endrun(msg="ERROR could NOT find "//nmlname//"namelist"//errmsg(sourcefile, __LINE__))
return
end if
call relavu( unitn )
end if
Expand Down
32 changes: 26 additions & 6 deletions src/biogeochem/CNFireFactoryMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ module CNFireFactoryMod
use abortutils , only : endrun
use shr_log_mod , only : errMsg => shr_log_errMsg
use clm_varctl , only : iulog
use shr_kind_mod , only : CS => SHR_KIND_CS

implicit none
save
private
!
! !PUBLIC ROUTINES:
public :: CNFireReadNML ! read the fire namelist
public :: CNFireReadNML ! read the fire factory namelist to get the CN fire_method to use
public :: create_cnfire_method ! create an object of class fire_method_type
! For Unit Testing:
public :: CNFireSetFireMethod ! Set the fire_method

! !PRIVATE DATA MEMBERS:
character(len=80), private :: fire_method = "li2014qianfrc"
character(len=CS), private :: fire_method = "UNSET"

character(len=*), parameter, private :: sourcefile = &
__FILE__
Expand Down Expand Up @@ -63,9 +66,11 @@ subroutine CNFireReadNML( NLFilename )
read(unitn, nml=cnfire_inparm, iostat=ierr)
if (ierr /= 0) then
call endrun(msg="ERROR reading "//nmlname//"namelist"//errmsg(sourcefile, __LINE__))
return
end if
else
call endrun(msg="ERROR finding "//nmlname//"namelist"//errmsg(sourcefile, __LINE__))
return
end if
call relavu( unitn )
end if
Expand All @@ -89,7 +94,6 @@ subroutine create_cnfire_method( NLFilename, cnfire_method )
! is determined based on a namelist parameter.
!
! !USES:
use shr_kind_mod , only : SHR_KIND_CL
use FireMethodType , only : fire_method_type
use CNFireNoFireMod , only : cnfire_nofire_type
use CNFireLi2014Mod , only : cnfire_li2014_type
Expand All @@ -103,7 +107,6 @@ subroutine create_cnfire_method( NLFilename, cnfire_method )
class(fire_method_type), allocatable, intent(inout) :: cnfire_method
!
! !LOCAL VARIABLES:
character(len=*), parameter :: subname = 'create_cnfire_method'
!-----------------------------------------------------------------------

select case (trim(fire_method))
Expand All @@ -120,13 +123,30 @@ subroutine create_cnfire_method( NLFilename, cnfire_method )
allocate(cnfire_li2024_type :: cnfire_method)

case default
write(iulog,*) subname//' ERROR: unknown method: ', fire_method
call endrun(msg=errMsg(sourcefile, __LINE__))
write(iulog,*) 'Unrecognized fire_method ' // errMsg(sourcefile, __LINE__)
call endrun( msg='Unknown option for namelist item fire_method: ' // trim(fire_method) )
! For unit-testing, make sure a valid cnfire_method is set and return, otherwise it fails with a seg-fault
allocate(cnfire_nofire_type :: cnfire_method)
return

end select
call cnfire_method%FireReadNML( NLFilename )

end subroutine create_cnfire_method
!-----------------------------------------------------------------------

subroutine CNFireSetFireMethod( fire_method_in )
!
! !DESCRIPTION:
! Set the fire_method (to be used in unit testing)
!
! !USES:
! !ARGUMENTS:
character(len=*), intent(IN) :: fire_method_in

fire_method = trim(fire_method_in)

end subroutine CNFireSetFireMethod
!-----------------------------------------------------------------------

end module CNFireFactoryMod
Loading