Skip to content

Commit

Permalink
Add fates landuse x pft API code
Browse files Browse the repository at this point in the history
Adds luh2 harvest data read to fates landuse module

This will enables the use of the raw LUH2 harvest data when running with
fates in land use mode + wood harvest mode
  • Loading branch information
glemieux committed Jun 18, 2024
1 parent 4156260 commit 8771e50
Show file tree
Hide file tree
Showing 14 changed files with 504 additions and 141 deletions.
122 changes: 98 additions & 24 deletions components/elm/bld/ELMBuildNamelist.pm
Original file line number Diff line number Diff line change
Expand Up @@ -808,12 +808,28 @@ sub setup_cmdl_fates_mode {

# The following variables may be set by the user and are compatible with use_fates
# no need to set defaults, covered in a different routine
my @list = ( "fates_spitfire_mode", "use_vertsoilc", "use_century_decomp", "fates_seeddisp_cadence",
"use_fates_planthydro", "use_fates_ed_st3", "use_fates_ed_prescribed_phys",
"use_fates_inventory_init", "use_fates_fixed_biogeog", "use_fates_nocomp","use_fates_sp",
"fates_inventory_ctrl_filename","use_fates_logging", "use_fates_tree_damage",
"use_fates_parteh_mode","use_fates_cohort_age_tracking","use_snicar_ad", "use_fates_luh",
"fluh_timeseries","fates_history_dimlevel");
my @list = ( "fates_spitfire_mode",
"fates_harvest_mode",
"fates_history_dimlevel",
"fates_inventory_ctrl_filename",
"fates_seeddisp_cadence",
"use_century_decomp",
"use_fates_cohort_age_tracking",
"use_fates_ed_st3",
"use_fates_ed_prescribed_phys",
"use_fates_fixed_biogeog",
"use_fates_inventory_init",
"use_fates_luh",
"use_fates_lupft",
"use_fates_nocomp",
"use_fates_parteh_mode",
"use_fates_planthydro",
"use_fates_potentialveg",
"use_fates_sp",
"use_fates_tree_damage",
"use_snicar_ad",
"use_vertsoilc",
"fluh_timeseries");
foreach my $var ( @list ) {
if ( defined($nl->get_value($var)) ) {
$nl_flags->{$var} = $nl->get_value($var);
Expand Down Expand Up @@ -841,17 +857,17 @@ sub setup_cmdl_fates_mode {
if ( defined($nl->get_value($var)) ) {
fatal_error("$var is being set, but can ONLY be set when -bgc fates option is used.\n");
}
$var = "use_fates_cohort_age_tracking";
$var = "fates_harvest_mode";
if ( defined($nl->get_value($var)) ) {
fatal_error("$var is being set, but can ONLY be set when -bgc fates option is used.\n");
}
$var = "use_fates_fixed_biogeog";
$var = "use_fates_cohort_age_tracking";
if ( defined($nl->get_value($var)) ) {
fatal_error("$var is being set, but can ONLY be set when -bgc fates option is used.\n");
}
$var = "use_fates_logging";
$var = "use_fates_fixed_biogeog";
if ( defined($nl->get_value($var)) ) {
fatal_error("$var is being set, but can ONLY be set when -bgc fates option is used.\n");
fatal_error("$var is being set, but can ONLY be set when -bgc fates option is used.\n");
}
$var = "fates_parteh_mode";
if ( defined($nl->get_value($var)) ) {
Expand All @@ -877,6 +893,10 @@ sub setup_cmdl_fates_mode {
if ( defined($nl->get_value($var)) ) {
fatal_error("$var is being set, but can ONLY be set when -bgc fates option is used.\n");
}
$var = "use_fates_lupft";
if ( defined($nl->get_value($var)) ) {
fatal_error("$var is being set, but can ONLY be set when -bgc fates option is used.\n");
}
$var = "fates_inventory_ctrl_filename";
if ( defined($nl->get_value($var)) ) {
fatal_error("$var is being set, but can ONLY be set when -bgc fates option is used.\n");
Expand Down Expand Up @@ -2812,8 +2832,8 @@ sub setup_logic_do_harvest {
if (string_is_undef_or_empty($nl->get_value('flanduse_timeseries'))) {
$cannot_be_true = "$var can only be set to true when running a transient case (flanduse_timeseries non-blank)";
}
elsif (!( value_is_true($nl->get_value('use_cn')) || value_is_true($nl->get_value('use_fates')) )) {
$cannot_be_true = "$var can only be set to true when running with CN (use_cn == true) or when using FATES (use_fates == true)";
elsif (!( value_is_true($nl->get_value('use_cn')))) {
$cannot_be_true = "$var can only be set to true when running with CN (use_cn == true)";
}

if ($cannot_be_true) {
Expand Down Expand Up @@ -3380,25 +3400,28 @@ sub setup_logic_fates {
my ($test_files, $nl_flags, $definition, $defaults, $nl, $physv) = @_;

if ( value_is_true( $nl_flags->{'use_fates'}) ) {
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'fates_spitfire_mode', 'use_fates'=>$nl_flags->{'use_fates'} );
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'use_fates_fixed_biogeog', 'use_fates'=>$nl_flags->{'use_fates'} );
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'use_fates_logging', 'use_fates'=>$nl_flags->{'use_fates'});
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'use_fates_planthydro', 'use_fates'=>$nl_flags->{'use_fates'});
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'fates_paramfile', 'phys'=>$nl_flags->{'phys'});
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'fluh_timeseries', 'phys'=>$nl_flags->{'phys'});
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'flandusepftdat', 'phys'=>$nl_flags->{'phys'});
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'fates_harvest_mode', 'use_fates'=>$nl_flags->{'use_fates'} );
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'fates_history_dimlevel', 'use_fates'=>$nl_flags->{'use_fates'});
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'fates_inventory_ctrl_filename','use_fates'=>$nl_flags->{'use_fates'});
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'fates_parteh_mode', 'use_fates'=>$nl_flags->{'use_fates'});
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'fates_seeddisp_cadence', 'use_fates'=>$nl_flags->{'use_fates'});
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'fates_spitfire_mode', 'use_fates'=>$nl_flags->{'use_fates'} );
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'use_fates_cohort_age_tracking','use_fates'=>$nl_flags->{'use_fates'});
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'use_fates_nocomp', 'use_fates'=>$nl_flags->{'use_fates'});
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'use_fates_ed_st3', 'use_fates'=>$nl_flags->{'use_fates'});
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'use_fates_ed_prescribed_phys', 'use_fates'=>$nl_flags->{'use_fates'});
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'use_fates_fixed_biogeog', 'use_fates'=>$nl_flags->{'use_fates'});
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'use_fates_inventory_init', 'use_fates'=>$nl_flags->{'use_fates'});
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'fates_inventory_ctrl_filename','use_fates'=>$nl_flags->{'use_fates'});
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'use_fates_cohort_age_tracking','use_fates'=>$nl_flags->{'use_fates'});
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'use_fates_planthydro', 'use_fates'=>$nl_flags->{'use_fates'});
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'use_fates_sp', 'use_fates'=>$nl_flags->{'use_fates'});
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'use_fates_nocomp', 'use_fates'=>$nl_flags->{'use_fates'});
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'use_fates_tree_damage', 'use_fates'=>$nl_flags->{'use_fates'});
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'fates_seeddisp_cadence', 'use_fates'=>$nl_flags->{'use_fates'});
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'use_fates_luh', 'use_fates'=>$nl_flags->{'use_fates'});
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'fates_paramfile', 'phys'=>$nl_flags->{'phys'});
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'fluh_timeseries', 'phys'=>$nl_flags->{'phys'});
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'fates_history_dimlevel','use_fates'=>$nl_flags->{'use_fates'});

add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'use_fates_lupft', 'use_fates'=>$nl_flags->{'use_fates'});
add_default($test_files, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'use_fates_potentialveg', 'use_fates'=>$nl_flags->{'use_fates'});

# For FATES SP mode make sure no-competion, 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";
Expand All @@ -3418,9 +3441,37 @@ sub setup_logic_fates {
if (&value_is_true( $nl->get_value('use_fates_planthydro') )) {
fatal_error('fates sp mode is currently not supported to work with fates hydro');
}
# FATES landuse can not be active with fates sp mode is active
if ( &value_is_true($nl->get_value('use_fates_luh')) ) {
fatal_error("use_fates_luh is can NOT be true when use_fates_sp is true" );
}
}
}
# 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($test_files, $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)) ) {
fatal_error("$var is required when use_fates_lupft is set" );
} elsif ( ! -f "$fname" ) {
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)) ) {
# 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 @@ -3436,6 +3487,29 @@ sub setup_logic_fates {
}
}
}
# check that fates landuse is on and harvest mode is off when potential veg switch is true
my $var = "use_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')) ) {
fatal_error("use_fates_luh must be true when $var is true" );
}
if ( $nl->get_value('fates_harvest_mode') ne "no_harvest") {
fatal_error("fates_harvest_mode must be off 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 raw luh2 harvest data
if ( $nl->get_value($var) eq "luhdata_area" || $nl->get_value($var) eq "luhdata_mass" ) {
# 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" );
}
}
}
}
}

Expand Down
20 changes: 11 additions & 9 deletions components/elm/bld/namelist_files/namelist_defaults.xml
Original file line number Diff line number Diff line change
Expand Up @@ -587,10 +587,12 @@ lnd/clm2/surfdata_map/surfdata_conusx4v1_simyr2000_c160503.nc</fsurdat>
<flanduse_timeseries hgrid="ne30np4" rcp="2.6" sim_year_range="1850-2100"
use_crop=".false." >lnd/clm2/surfdata_map/surfdata.pftdyn_ne30np4_rcp2.6_simyr1850-2100_c130524.nc</flanduse_timeseries>

<!-- Land Use Harmonization unified data sets for dynamic FATES land use change -->
<!-- Land Use Harmonization unified timeseries data sets for dynamic FATES land use change -->
<fluh_timeseries hgrid="4x5" sim_year_range="1850-2015" use_fates=".true."
>lnd/clm2/surfdata_map/fates-sci.1.68.3_api.31.0.0_tools.1.0.1/LUH2_states_transitions_management.timeseries_4x5_hist_simyr1850-2015_c231101.nc</fluh_timeseries>

<!-- Land Use Harmonization static landuse x pft mapping data sets for FATES land use change -->
<flandusepftdat hgrid="4x5" use_fates=".true." >lnd/clm2/surfdata_map/fates-sci.1.73.0_api.36.0.0/fates_landuse_pft_map_4x5_240206.nc</flandusepftdat>

<!-- GLC mask datasets (relative to {csmdata}) -->
<!-- Currently glc_grid is not being read from anywhere, so these rules are broken. -->
Expand Down Expand Up @@ -2177,25 +2179,25 @@ this mask will have smb calculated over the entire global land surface
<!-- Defaults for FATES interface -->
<!-- ========================================= -->
<fates_spitfire_mode use_fates=".true.">0</fates_spitfire_mode>
<use_fates_fixed_biogeog use_fates=".true.">.false.</use_fates_fixed_biogeog>
<use_fates_nocomp use_fates=".true.">.false.</use_fates_nocomp>
<fates_harvest_mode use_fates=".true.">no_harvest</fates_harvest_mode>
<fates_history_dimlevel use_fates=".true.">2,2</fates_history_dimlevel>
<fates_inventory_ctrl_filename use_fates=".true."> "/dev/null" </fates_inventory_ctrl_filename>
<fates_parteh_mode use_fates=".true.">1</fates_parteh_mode>
<fates_seeddisp_cadence use_fates=".true.">0</fates_seeddisp_cadence>
<use_fates_planthydro use_fates=".true.">.false.</use_fates_planthydro>
<use_fates_tree_damage use_fates=".true.">.false.</use_fates_tree_damage>
<use_fates_ed_st3 use_fates=".true.">.false.</use_fates_ed_st3>
<use_fates_ed_prescribed_phys use_fates=".true.">.false.</use_fates_ed_prescribed_phys>
<use_fates_logging use_fates=".true.">.false.</use_fates_logging>
<use_fates_cohort_age_tracking use_fates=".true.">.false.</use_fates_cohort_age_tracking>
<use_fates_sp use_fates=".true.">.false.</use_fates_sp>
<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_lupft use_fates=".true.">.false.</use_fates_lupft>
<use_fates_potentialveg use_fates=".true.">.false.</use_fates_potentialveg>
<use_fates_luh use_fates=".true." >.false.</use_fates_luh>
<use_fates_inventory_init use_fates=".true.">.false.</use_fates_inventory_init>
<fates_inventory_ctrl_filename use_fates=".true."> "/dev/null" </fates_inventory_ctrl_filename>
<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>
<fates_history_dimlevel use_fates=".true.">2,2</fates_history_dimlevel>
<use_vertsoilc bgc_mode="fates" >.true.</use_vertsoilc>
<use_century_decomp bgc_mode="fates" >.true.</use_century_decomp>
<use_lch4 bgc_mode="fates" >.false.</use_lch4>
Expand Down
Loading

0 comments on commit 8771e50

Please sign in to comment.