Skip to content

Commit

Permalink
Merge pull request #1 from glemieux/fates-landuse-v2-modechecks
Browse files Browse the repository at this point in the history
Update build namelist checks for valid landuse v2 mode combinations
  • Loading branch information
samsrabin authored May 7, 2024
2 parents 0191278 + 2a88002 commit 1ffa406
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 51 deletions.
74 changes: 63 additions & 11 deletions bld/CLMBuildNamelist.pm
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ sub setup_cmdl_fates_mode {
"use_fates_cohort_age_tracking","use_fates_inventory_init","use_fates_fixed_biogeog",
"use_fates_nocomp","use_fates_sp","fates_inventory_ctrl_filename","fates_harvest_mode",
"fates_parteh_mode","use_fates_tree_damage","fates_seeddisp_cadence","use_fates_luh","fluh_timeseries","flandusepftdat",
"use_fates_potentialveg");
"use_fates_potentialveg","use_fates_lupft");
# dis-allow fates specific namelist items with non-fates runs
foreach my $var ( @list ) {
if ( defined($nl->get_value($var)) ) {
Expand Down Expand Up @@ -4370,20 +4370,34 @@ sub setup_logic_fates {
if (&value_is_true( $nl_flags->{'use_fates'}) ) {
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'fates_paramfile', 'phys'=>$nl_flags->{'phys'});
my @list = ( "fates_spitfire_mode", "use_fates_planthydro", "use_fates_ed_st3", "use_fates_ed_prescribed_phys",
"use_fates_inventory_init","use_fates_fixed_biogeog","use_fates_nocomp","fates_seeddisp_cadence",
"fates_harvest_mode","fates_parteh_mode", "use_fates_cohort_age_tracking","use_fates_tree_damage","use_fates_luh" );
"use_fates_inventory_init","fates_seeddisp_cadence",
"fates_harvest_mode","fates_parteh_mode", "use_fates_cohort_age_tracking","use_fates_tree_damage");
foreach my $var ( @list ) {
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, $var, 'use_fates'=>$nl_flags->{'use_fates'},
'use_fates_sp'=>$nl_flags->{'use_fates_sp'} );
}

add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'use_fates_potentialveg', 'use_fates'=>$nl_flags->{'use_fates'});
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'use_fates_lupft', 'use_fates'=>$nl_flags->{'use_fates'});
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'use_fates_luh', 'use_fates'=>$nl_flags->{'use_fates'},
'use_fates_lupft'=>$nl->get_value('use_fates_lupft'),
'use_fates_potentialveg'=>$nl->get_value('use_fates_potentialveg'),
'fates_harvest_mode'=>$nl->get_value('fates_harvest_mode') );
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'use_fates_nocomp', 'use_fates'=>$nl_flags->{'use_fates'},
'use_fates_lupft'=>$nl->get_value('use_fates_lupft'),
'use_fates_sp'=>$nl_flags->{'use_fates_sp'} );
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'use_fates_fixed_biogeog', 'use_fates'=>$nl_flags->{'use_fates'},
'use_fates_lupft'=>$nl->get_value('use_fates_lupft'),
'use_fates_sp'=>$nl_flags->{'use_fates_sp'} );

my $suplnitro = $nl->get_value('suplnitro');
my $parteh_mode = $nl->get_value('fates_parteh_mode');
if ( ($parteh_mode == 1) && ($suplnitro !~ /ALL/) && not &value_is_true( $nl_flags->{'use_fates_sp'}) ) {
$log->fatal_error("supplemental Nitrogen (suplnitro) is NOT set to ALL, FATES is on, " .
"but and FATES-SP is not active, but fates_parteh_mode is 1, so Nitrogen is not active" .
"Change suplnitro back to ALL");
}
#

# 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
#
Expand All @@ -4400,6 +4414,10 @@ sub setup_logic_fates {
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');
}
}
}
my $var = "use_fates_inventory_init";
Expand All @@ -4414,6 +4432,32 @@ sub setup_logic_fates {
}
}
}
# make sure that fates landuse x pft mode has the necessary run mode configurations
# and add the necessary landuse x pft static mapping data default if not defined
my $var = "use_fates_lupft";
if ( defined($nl->get_value($var)) ) {
if ( &value_is_true($nl->get_value($var)) ) {
$var = "flandusepftdat";
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, $var,
'phys'=>$nl_flags->{'phys'}, 'hgrid'=>$nl_flags->{'res'}, nofail=>1 );
my $fname = remove_leading_and_trailing_quotes( $nl->get_value($var) );
if ( ! defined($nl->get_value($var)) ) {
$log->fatal_error("$var is required when use_fates_lupft is set" );
} elsif ( ! -f "$fname" ) {
$log->fatal_error("$fname does NOT point to a valid filename" );
}

# make sure that nocomp and fbg mode are enabled as well as use_fates_luh
my @list = ( "use_fates_luh", "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 use_fates_lupft is true" );
}
}
}
}
# check that fates landuse change mode has the necessary luh2 landuse timeseries data
# and add the default if not defined
my $var = "use_fates_luh";
if ( defined($nl->get_value($var)) ) {
if ( &value_is_true($nl->get_value($var)) ) {
Expand All @@ -4425,30 +4469,38 @@ sub setup_logic_fates {
} elsif ( ! -f "$fname" ) {
$log->fatal_error("$fname does NOT point to a valid filename" );
}

$var = "flandusepftdat";
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, $var, 'phys'=>$nl_flags->{'phys'}, 'hgrid'=>$nl_flags->{'res'}, 'sim_year_range'=>$nl_flags->{'sim_year_range'}, nofail=>1 );
}
}

# check that fates landuse is on and harvest mode is off when potential veg switch is true
my $var = "use_fates_potentialveg";
if ( defined($nl->get_value($var)) ) {
if ( &value_is_true($nl->get_value($var)) ) {
if ( ! &value_is_true($nl->get_value('use_fates_luh')) ) {
$log->fatal_error("use_fates_luh must be true when $var is true" );
}
if ( $nl->get_value('fates_harvest_mode') > 0) {
$log->fatal_error("fates_harvest_mode must be off (i.e. set to zero) when $var is true" );
}
}
}
# Check fates_harvest_mode compatibility
my $var = "fates_harvest_mode";
if ( defined($nl->get_value($var)) ) {
# using fates_harvest_mode with CLM landuse driver data - for user convienence
# if ( $nl->get_value($var) == 2) {
# # Make sure that do_harvest is set to true
# if ( ! &value_is_true($nl->get_value('do_harvest')) ) {
# fatal_error("do_harvest must be true when $var is equal to 2" );
# $log->fatal_error("do_harvest must be true when $var is equal to 2" );
# }
# using fates_harvest mode with raw luh2 harvest data
if ( $nl->get_value($var) > 2) {
# Make sure that use_fates_luh is true when using raw fates luh2 harvest data
if ( ! &value_is_true($nl->get_value('use_fates_luh')) ) {
fatal_error("use_fates_luh is required to be true when $var is greater than 2" );
$log->fatal_error("use_fates_luh is required to be true when $var is greater than 2" );
}
# do_harvest can not be on if we are using the raw fates luh2 harvest data
if ( &value_is_true($nl->get_value('do_harvest')) ) {
fatal_error("do_harvest can not be true when $var is greater than 2" );
$log->fatal_error("do_harvest can not be true when $var is greater than 2" );
}
}
}
Expand Down
20 changes: 12 additions & 8 deletions bld/namelist_files/namelist_defaults_ctsm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2767,17 +2767,21 @@ use_crop=".true.">lnd/clm2/surfdata_map/ctsm5.1.dev052/landuse.timeseries_mpasa1
<use_fates_ed_prescribed_phys use_fates=".true.">.false.</use_fates_ed_prescribed_phys>
<use_fates_inventory_init use_fates=".true.">.false.</use_fates_inventory_init>
<use_fates_sp use_fates=".true.">.false.</use_fates_sp>
<use_fates_lupft use_fates=".true.">.false.</use_fates_lupft>
<use_fates_potentialveg use_fates=".true.">.false.</use_fates_potentialveg>
<use_fates_luh use_fates=".true." fates_harvest_mode="3">.true.</use_fates_luh>
<use_fates_luh use_fates=".true." fates_harvest_mode="4">.true.</use_fates_luh>
<use_fates_luh use_fates=".true.">.false.</use_fates_luh>
<use_fates_luh use_fates=".true." fates_harvest_mode="3" >.true.</use_fates_luh>
<use_fates_luh use_fates=".true." fates_harvest_mode="4" >.true.</use_fates_luh>
<use_fates_luh use_fates=".true." use_fates_lupft=".true.">.true.</use_fates_luh>
<use_fates_luh use_fates=".true." use_fates_potentialveg=".true.">.true.</use_fates_luh>
<use_fates_luh use_fates=".true." >.false.</use_fates_luh>
<fates_parteh_mode use_fates=".true.">1</fates_parteh_mode>
<fates_seeddisp_cadence use_fates=".true.">0</fates_seeddisp_cadence>

<use_fates_nocomp use_fates=".true." use_fates_sp=".true.">.true.</use_fates_nocomp>
<use_fates_nocomp use_fates=".true." >.false.</use_fates_nocomp>
<use_fates_fixed_biogeog use_fates=".true." use_fates_sp=".true.">.true.</use_fates_fixed_biogeog>
<use_fates_fixed_biogeog use_fates=".true." >.false.</use_fates_fixed_biogeog>
<use_fates_nocomp use_fates=".true." use_fates_sp=".true." >.true.</use_fates_nocomp>
<use_fates_nocomp use_fates=".true." use_fates_lupft=".true.">.true.</use_fates_nocomp>
<use_fates_nocomp use_fates=".true." >.false.</use_fates_nocomp>
<use_fates_fixed_biogeog use_fates=".true." use_fates_sp=".true." >.true.</use_fates_fixed_biogeog>
<use_fates_fixed_biogeog use_fates=".true." use_fates_lupft=".true.">.true.</use_fates_fixed_biogeog>
<use_fates_fixed_biogeog use_fates=".true." >.false.</use_fates_fixed_biogeog>

<!-- ========================================= -->
<!-- Defaults for dynamic subgrid -->
Expand Down
8 changes: 7 additions & 1 deletion bld/namelist_files/namelist_definition_ctsm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,12 @@ data (fates_harvest_mode >= 3)
(Also, only valid for use_fates = true and is incompatible with transient runs currently.)
</entry>

<entry id="use_fates_lupft" type="logical" category="physics"
group="elm_inparm" valid_values="" value=".false.">
If TRUE, enable use of fates land use x pft mapping data file.
(Only valid for use_fates = true and is incompatible with transient runs currently.)
</entry>

<entry id="use_fates_potentialveg" type="logical" category="physics"
group="clm_inparm" valid_values="" >
If TRUE, ignore the land-use state vector and transitions, and assert that all lands
Expand All @@ -808,7 +814,7 @@ types to vary over time.

<entry id="flandusepftdat" type="char*256" category="datasets"
input_pathname="abs" group="clm_inparm" valid_values="" >
Full pathname of fates landuse x pft data map.
Full pathname of fates landuse x pft static data map.
</entry>

<entry id="use_luna" type="logical" category="physics"
Expand Down
44 changes: 39 additions & 5 deletions bld/unit_testers/build-namelist_test.pl
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ sub cat_and_create_namelistinfile {
#
# Figure out number of tests that will run
#
my $ntests = 1999;
my $ntests = 2007;

if ( defined($opts{'compare'}) ) {
$ntests += 1353;
$ntests += 1360;
}
plan( tests=>$ntests );

Expand Down Expand Up @@ -1046,9 +1046,8 @@ sub cat_and_create_namelistinfile {
GLC_TWO_WAY_COUPLING=>"FALSE",
phys=>"clm4_5",
},
# TODO SSR: Replace this with fates_harvest_mode
"useloggingButNOTFATES" =>{ options=>"-envxml_dir . -no-megan",
namelst=>"use_fates_logging=.true.",
namelst=>"fates_harvest_mode=1",
GLC_TWO_WAY_COUPLING=>"FALSE",
phys=>"clm4_5",
},
Expand All @@ -1062,11 +1061,16 @@ sub cat_and_create_namelistinfile {
GLC_TWO_WAY_COUPLING=>"FALSE",
phys=>"clm4_5",
},
"useinventorybutnotfile" =>{ options=>"--res 0.9x1.25 --bgc fates --envxml_dir . --no-megan",
"useFATESLUH2butnotfile" =>{ options=>"--res 0.9x1.25 --bgc fates --envxml_dir . --no-megan",
namelst=>"use_fates_luh=.true.",
GLC_TWO_WAY_COUPLING=>"FALSE",
phys=>"clm4_5",
},
"useFATESLUPFTbutnotfile" =>{ options=>"--res 0.9x1.25 --bgc fates --envxml_dir . --no-megan",
namelst=>"use_fates_lupft=.true.",
GLC_TWO_WAY_COUPLING=>"FALSE",
phys=>"clm4_5",
},
"inventoryfileDNE" =>{ options=>"-bgc fates -envxml_dir . -no-megan",
namelst=>"use_fates_luh=.true., fluh_timeseries='zztop'",
GLC_TWO_WAY_COUPLING=>"FALSE",
Expand All @@ -1092,6 +1096,36 @@ sub cat_and_create_namelistinfile {
GLC_TWO_WAY_COUPLING=>"FALSE",
phys=>"clm5_0",
},
"useFATESSPwithLUH" =>{ options=>"-bgc fates -envxml_dir . -no-megan",
namelst=>"use_fates_sp=T,use_fates_luh=T",
GLC_TWO_WAY_COUPLING=>"FALSE",
phys=>"clm5_0",
},
"useFATESPOTVEGwithHARVEST" =>{ options=>"-bgc fates -envxml_dir . -no-megan",
namelst=>"use_fates_potentialveg=T,fates_harvest_mode=1",
GLC_TWO_WAY_COUPLING=>"FALSE",
phys=>"clm5_0",
},
"useFATESHARVEST3WOLUH" =>{ options=>"-bgc fates -envxml_dir . -no-megan",
namelst=>"use_fates_luh=F,fates_harvest_mode=3",
GLC_TWO_WAY_COUPLING=>"FALSE",
phys=>"clm5_0",
},
"useFATESLUPFTWOLUH" =>{ options=>"-bgc fates -envxml_dir . -no-megan",
namelst=>"use_fates_lupft=T,use_fates_luh=F",
GLC_TWO_WAY_COUPLING=>"FALSE",
phys=>"clm5_0",
},
"useFATESLUPFTWONOCOMP" =>{ options=>"-bgc fates -envxml_dir . -no-megan",
namelst=>"use_fates_lupft=T,use_fates_nocomp=F",
GLC_TWO_WAY_COUPLING=>"FALSE",
phys=>"clm5_0",
},
"useFATESLUPFTWOFBG" =>{ options=>"-bgc fates -envxml_dir . -no-megan",
namelst=>"use_fates_lupft=T,use_fates_fixedbiogeog=F",
GLC_TWO_WAY_COUPLING=>"FALSE",
phys=>"clm5_0",
},
"useFATESTRANSWdynPFT" =>{ options=>"-bgc fates -envxml_dir . -use_case 20thC_transient -no-megan",
namelst=>"do_transient_pfts=T",
GLC_TWO_WAY_COUPLING=>"FALSE",
Expand Down
1 change: 1 addition & 0 deletions src/main/clm_varctl.F90
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ module clm_varctl
logical, public :: use_fates_fixed_biogeog = .false. ! true => use fixed biogeography mode
logical, public :: use_fates_nocomp = .false. ! true => use no comopetition mode
logical, public :: use_fates_luh = .false. ! true => use FATES landuse data mode
logical, public :: use_fates_lupft = .false. ! true => use FATES landuse x pft static mapping mode
logical, public :: use_fates_potentialveg = .false. ! true => FATES potential veg only
character(len=256), public :: fluh_timeseries = '' ! filename for fates landuse timeseries data
character(len=256), public :: flandusepftdat = '' ! filename for fates landuse x pft data
Expand Down
3 changes: 3 additions & 0 deletions src/main/controlMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ subroutine control_init(dtime)
use_fates_nocomp, &
use_fates_sp, &
use_fates_luh, &
use_fates_lupft, &
use_fates_potentialveg, &
fluh_timeseries, &
flandusepftdat, &
Expand Down Expand Up @@ -785,6 +786,7 @@ subroutine control_spmd()
call mpi_bcast (use_fates_nocomp, 1, MPI_LOGICAL, 0, mpicom, ier)
call mpi_bcast (use_fates_sp, 1, MPI_LOGICAL, 0, mpicom, ier)
call mpi_bcast (use_fates_luh, 1, MPI_LOGICAL, 0, mpicom, ier)
call mpi_bcast (use_fates_lupft, 1, MPI_LOGICAL, 0, mpicom, ier)
call mpi_bcast (use_fates_potentialveg, 1, MPI_LOGICAL, 0, mpicom, ier)
call mpi_bcast (use_fates_bgc, 1, MPI_LOGICAL, 0, mpicom, ier)
call mpi_bcast (fates_inventory_ctrl_filename, len(fates_inventory_ctrl_filename), MPI_CHARACTER, 0, mpicom, ier)
Expand Down Expand Up @@ -1161,6 +1163,7 @@ subroutine control_print ()
write(iulog, *) ' use_fates_nocomp = ', use_fates_nocomp
write(iulog, *) ' use_fates_sp = ', use_fates_sp
write(iulog, *) ' use_fates_luh= ', use_fates_luh
write(iulog, *) ' use_fates_lupft= ', use_fates_lupft
write(iulog, *) ' use_fates_potentialveg = ', use_fates_potentialveg
write(iulog, *) ' fluh_timeseries = ', trim(fluh_timeseries)
write(iulog, *) ' flandusepftdat = ', trim(flandusepftdat)
Expand Down
Loading

0 comments on commit 1ffa406

Please sign in to comment.