diff --git a/.gitmodules b/.gitmodules index e437f56d61..8127cac482 100644 --- a/.gitmodules +++ b/.gitmodules @@ -28,7 +28,7 @@ [submodule "fates"] path = src/fates url = https://github.com/NGEET/fates -fxtag = sci.1.73.0_api.35.0.0 +fxtag = sci.1.77.1_api.36.0.0 fxrequired = AlwaysRequired # Standard Fork to compare to with "git fleximod test" to ensure personal forks aren't committed fxDONOTUSEurl = https://github.com/NCAR/fates-release diff --git a/bld/CLMBuildNamelist.pm b/bld/CLMBuildNamelist.pm index 26ede70f32..142dd4aae4 100755 --- a/bld/CLMBuildNamelist.pm +++ b/bld/CLMBuildNamelist.pm @@ -787,9 +787,10 @@ sub setup_cmdl_fates_mode { # dis-allow fates specific namelist items with non-fates runs my @list = ( "fates_spitfire_mode", "use_fates_planthydro", "use_fates_ed_st3", "use_fates_ed_prescribed_phys", "use_fates_cohort_age_tracking","use_fates_inventory_init","use_fates_fixed_biogeog", - "use_fates_nocomp","use_fates_sp","fates_inventory_ctrl_filename","use_fates_logging", - "fates_parteh_mode","use_fates_tree_damage","fates_history_dimlevel","fates_seeddisp_cadence", - "use_fates_luh","fluh_timeseries" ); + "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_lupft","fates_history_dimlevel" ); + # dis-allow fates specific namelist items with non-fates runs foreach my $var ( @list ) { if ( defined($nl->get_value($var)) ) { @@ -3075,8 +3076,8 @@ sub setup_logic_do_harvest { $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 either CN or FATES"; + elsif (!&value_is_true($nl->get_value('use_cn'))) { + $cannot_be_true = "$var can only be set to true when running with CN. Please set use_cn to true."; } if ($cannot_be_true) { @@ -4550,13 +4551,27 @@ 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", - "use_fates_logging","fates_parteh_mode", "use_fates_cohort_age_tracking","use_fates_tree_damage", - "use_fates_luh","fates_history_dimlevel" ); + "use_fates_inventory_init","fates_seeddisp_cadence","fates_history_dimlevel", + "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, $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'=>remove_leading_and_trailing_quotes($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'}) ) { @@ -4564,7 +4579,7 @@ sub setup_logic_fates { "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 # @@ -4581,6 +4596,12 @@ 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'); + } + # 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'); @@ -4599,16 +4620,92 @@ sub setup_logic_fates { } } } + # make sure that fates landuse x pft mode has the necessary run mode configurations + my $var = "use_fates_lupft"; + if ( defined($nl->get_value($var)) ) { + if ( &value_is_true($nl->get_value($var)) ) { + 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. Do not add default if use_fates_potentialveg is true. + # If fixed biogeography is on, make sure that flandusepftdat is avilable. my $var = "use_fates_luh"; if ( defined($nl->get_value($var)) ) { if ( &value_is_true($nl->get_value($var)) ) { - $var = "fluh_timeseries"; - 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 ); + $var = "use_fates_potentialveg"; + if ( defined($nl->get_value($var)) ) { + if ( ! &value_is_true($nl->get_value($var)) ) { + $var = "fluh_timeseries"; + add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, $var, 'use_fates'=>$nl_flags->{'use_fates'}, + 'hgrid'=>$nl_flags->{'res'}, 'sim_year_range'=>$nl_flags->{'sim_year_range'}); + 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_luh is set and use_fates_potentialveg is false" ); + } elsif ( ! -f "$fname" ) { + $log->fatal_error("$var does NOT point to a valid filename" ); + } + } + } + $var = "use_fates_fixed_biogeog"; + 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, 'use_fates'=>$nl_flags->{'use_fates'}, + '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_luh and use_fates_fixed_biogeog is set" ); + } elsif ( ! -f "$fname" ) { + $log->fatal_error("$var does NOT point to a valid filename" ); + } + } + } + } + } + # 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" ); + } + my $var = remove_leading_and_trailing_quotes($nl->get_value('fates_harvest_mode')); + if ( $var ne 'no_harvest') { + $log->fatal_error("fates_harvest_mode set to $var. It must set to no_harvest when use_potential_veg is true." ); + } + my $var = "fluh_timeseries"; + if ( defined($nl->get_value($var)) ) { + $log->fatal_error("fluh_timeseries can not be defined when use_fates_potentialveg 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 + my $mode = remove_leading_and_trailing_quotes($nl->get_value($var)); + if ( $mode eq 'luhdata_area' || $mode 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')) ) { + $log->fatal_error("use_fates_luh is required to be true when $var is luhdata_mass or luhdata_area" ); + } + } elsif ( $mode eq 'landuse_timeseries' ) { + # Check to make sure that the user set the flanduse_timeseries file + # Since the flanduse_timeseries logic checking is upstream of the fates logic, + # don't add the default here. The onus is on the user to match the correct timeseries + # data to the correct surface dataset resolution + my $var = "flanduse_timeseries"; 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_luh is set" ); + $log->fatal_error("$var is required when fates_harvest_mode is landuse_timeseries" ); } elsif ( ! -f "$fname" ) { - $log->fatal_error("$fname does NOT point to a valid filename" ); + $log->fatal_error("$var does NOT point to a valid filename" ); } } } diff --git a/bld/namelist_files/namelist_defaults_ctsm.xml b/bld/namelist_files/namelist_defaults_ctsm.xml index e2ba2de74b..97620c770d 100644 --- a/bld/namelist_files/namelist_defaults_ctsm.xml +++ b/bld/namelist_files/namelist_defaults_ctsm.xml @@ -513,7 +513,7 @@ attributes from the config_cache.xml file (with keys converted to upper-case). -lnd/clm2/paramdata/fates_params_api.35.0.0_12pft_c240326.nc +lnd/clm2/paramdata/fates_params_api.36.0.0_12pft_c240517.nc @@ -2050,14 +2050,17 @@ lnd/clm2/surfdata_esmf/NEON/surfdata_1x1_NEON_TOOL_hist_78pfts_CMIP6_simyr2000_c - + 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 + +lnd/clm2/surfdata_map/fates-sci.1.77.0_api.36.0.0/fates_landuse_pft_map_4x5_240206.nc + 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 + >lnd/clm2/surfdata_map/fates-sci.1.68.3_api.31.0.0_tools.1.0.1/LUH2_states_transitions_management.timeseries_4x5_hist_simyr0850-2015_c240216.nc .false. @@ -2551,22 +2554,31 @@ lnd/clm2/surfdata_esmf/NEON/surfdata_1x1_NEON_TOOL_hist_78pfts_CMIP6_simyr2000_c 0 +no_harvest .false. .false. .false. .false. .false. -.false. .false. .false. -.false. +.false. +.false. +.true. +.true. +.true. +.true. +.false. 1 0 +.true. +.true. +.false. +.true. +.true. +.false. 2,2 -.true. -.false. -.true. -.false. + diff --git a/bld/namelist_files/namelist_definition_ctsm.xml b/bld/namelist_files/namelist_definition_ctsm.xml index bc92dafbf0..0912617872 100644 --- a/bld/namelist_files/namelist_definition_ctsm.xml +++ b/bld/namelist_files/namelist_definition_ctsm.xml @@ -734,10 +734,17 @@ Toggle to turn on no competition mode (only relevant if FATES is being used). Toggle to turn on FATES satellite phenology mode (only relevant if FATES is being used). - -Toggle to turn on the logging module -(Only relevant if FATES is on) + +Set FATES harvesting mode by setting fates_harvest_mode to a valid string option. +Allowed values are: + no_harvest: no fates harvesting of any kind + event_code: fates logging via fates logging event codes (see fates parameter file) only + landuse_timeseries: fates harvest driven by CLM flanduse_timeseries file (dynHarvestMod)** + luhdata_area: fates harvest driven by LUH2 raw harvest data, area-based (dynFATESLandUseChangeMod) + luhdata_mass: fates harvest driven by LUH2 raw harvest data, mass-based (dynFATESLandUseChangeMod) +**Note that the landuse_timeseries option is not the same as the FATES fluh_timeseries data file. +This option is older than the luhdata options and may be depricated at some point in the future. If TRUE, enable use of land use harmonization (LUH) state and transition data from luh_timeseries file. +This is enabled by default if fates_harvest_mode is set to use the raw LUH2 harvest data (Also, only valid for use_fates = true and is incompatible with transient runs currently.) + +If TRUE, enable use of FATES land use with no competition and fixed biogeography. This mode +requires the use of the land use x pft association static data map file. See the +flandusepftdat definition entry in this file for more information. +(Only valid for use_fates = true and is incompatible with transient runs currently.) + + + +If TRUE, ignore the land-use state vector and transitions, and assert that all lands +are primary, and that there is no harvest. This mode is only relevant for FATES +spin-up workflows that are intending to use the spin-up restart output to start a +FATES land use transient case using the use_fates_lupft namelist option. The option +should be set to true for the spin-up case and false for the transient case. + + @@ -806,6 +831,18 @@ types to vary over time. (Only relevant if FATES is on). + +Full pathname of fates landuse x pft association static data map. +The file associates land use types with pfts across a static global map. +This file is necessary for running FATES with use_fates_luh, +use_fates_nocomp, and use_fates_fixedbiogeo engaged (note that use_fates_lupft +is provided as a namelist option to engage all necessary options). The file is output +by the FATES land use data tool (https://github.com/NGEET/tools-fates-landusedata) +which processes the raw land use data from the THEMIS tool data sets +(https://doi.org/10.5065/29s7-7b41) + + Toggle to turn on the LUNA model, to effect Photosynthesis by leaf Nitrogen diff --git a/bld/unit_testers/build-namelist_test.pl b/bld/unit_testers/build-namelist_test.pl index 9b283af334..d02d68b06b 100755 --- a/bld/unit_testers/build-namelist_test.pl +++ b/bld/unit_testers/build-namelist_test.pl @@ -163,10 +163,10 @@ sub cat_and_create_namelistinfile { # # Figure out number of tests that will run # -my $ntests = 3306; +my $ntests = 3314; if ( defined($opts{'compare'}) ) { - $ntests += 2045; + $ntests += 2052; } plan( tests=>$ntests ); @@ -1083,7 +1083,7 @@ sub cat_and_create_namelistinfile { phys=>"clm5_0", }, "useloggingButNOTFATES" =>{ options=>"-envxml_dir . -no-megan", - namelst=>"use_fates_logging=.true.", + namelst=>"fates_harvest_mode='event_code'", GLC_TWO_WAY_COUPLING=>"FALSE", phys=>"clm4_5", }, @@ -1097,11 +1097,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", @@ -1127,6 +1132,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='event_code',use_fates_luh=T", + GLC_TWO_WAY_COUPLING=>"FALSE", + phys=>"clm5_0", + }, + "useFATESHARVEST3WOLUH" =>{ options=>"-bgc fates -envxml_dir . -no-megan", + namelst=>"use_fates_luh=F,fates_harvest_mode='luhdata_area'", + 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", diff --git a/cime_config/SystemTests/pvt.py b/cime_config/SystemTests/pvt.py new file mode 100644 index 0000000000..cf923dd334 --- /dev/null +++ b/cime_config/SystemTests/pvt.py @@ -0,0 +1,133 @@ +""" +FATES land use potential vegetation spin up + transient test + +This is a FATES specific test: + +1) conduct a spinup with use_fates_potentialveg on + - write restart file + - use CLM_ACCELERATED_SPINUP? +2) run a transient landuse case with use_fates_lupft + - start from the restart file generated in (1) +""" +from CIME.XML.standard_module_setup import * +from CIME.SystemTests.system_tests_common import SystemTestsCommon +from CIME.SystemTests.test_utils.user_nl_utils import append_to_user_nl_files +import shutil, glob, os + +logger = logging.getLogger(__name__) + + +class PVT(SystemTestsCommon): + def __init__(self, case): + SystemTestsCommon.__init__(self, case) + + # Do not allow PVT to be run with certain testmods + # Should this be targeted to a specific testmod for simplicity for now? + # Technically this could be run with the luh fates_harvest_modes + error_message = None + casebaseid = self._case.get_value("CASEBASEID") + casebaseid = casebaseid.split("-")[-1] + if casebaseid[0:10] != "FatesLUPFT": + error_message = f"Only call PVT with testmod FatesLUPFT. {casebaseid} selected." + + # Only allow to run if resolution is 4x5 for now + # Other grid resolutions will be pre-processed and included in the namelist defaults at a future date. + # Potentially we could generate these on the fly although doing so would result in increased build time + lnd_grid = self._case.get_value("LND_GRID") + if lnd_grid != "4x5": + error_message = ( + f"PVT can currently only be run with 4x5 resolution. {lnd_grid} selected." + ) + + if error_message is not None: + logger.error(error_message) + raise RuntimeError(error_message) + + def run_phase(self): + # ------------------------------------------------------------------- + # (1) Run FATES spin-up case in potential vegetation mode + # ------------------------------------------------------------------- + orig_case = self._case + orig_casevar = self._case.get_value("CASE") + caseroot = self._case.get_value("CASEROOT") + + # Set the run start date based on the desired starting reference case year + refcase_year = 1700 + stop_n_pveg = 5 + startyear_pveg = refcase_year - stop_n_pveg + + # clone the main case to create spinup case + logger.info("PVT log: cloning setup") + clone_path = "{}.potveg".format(caseroot) + if os.path.exists(clone_path): + shutil.rmtree(clone_path) + logger.info("PVT log: cloning") + clone = self._case.create_clone(clone_path, keepexe=True) + logger.info("PVT log: cloning complete") + + # setup the clone case + os.chdir(clone_path) + self._set_active_case(clone) + + # set the clone case values + with clone: + clone.set_value("CLM_ACCELERATED_SPINUP", "off") + clone.set_value("STOP_N", stop_n_pveg) + clone.set_value("STOP_OPTION", "nyears") + clone.set_value("RUN_STARTDATE", "{}-01-01".format(startyear_pveg)) + + # Modify the spin up case to use the potential vegetation mode. + # Checks for incompatible cases and necessary mapping files are + # handled in the build case. + # Turn off fates_harvest_mode for the spin up. + + logger.info("PVT log: modify user_nl_clm file for spin up run") + added_content = ["use_fates_potentialveg = .true.", "fates_harvest_mode = 'no_harvest'"] + append_to_user_nl_files(clone_path, "clm", added_content) + + # Run the spin up case + # As per SSP test: + # "No history files expected, set suffix=None to avoid compare error" + logger.info("PVT log: starting spin-up run") + dout_sr = clone.get_value("DOUT_S_ROOT") + self._skip_pnl = False + self.run_indv(suffix=None, st_archive=True) + + # ------------------------------------------------------------------- + # (2) Run FATES transient case using restart file from spin-up + # ------------------------------------------------------------------- + os.chdir(caseroot) + self._set_active_case(orig_case) + + # Copy restart files from spin up to the transient case run directory + # obtain rpointer files and necessary restart files from short term archiving directory + rundir = self._case.get_value("RUNDIR") + + refdate = str(refcase_year) + "-01-01-00000" + rest_path = os.path.join(dout_sr, "rest", "{}".format(refdate)) + + for item in glob.glob("{}/*{}*".format(rest_path, refdate)): + link_name = os.path.join(rundir, os.path.basename(item)) + if os.path.islink(link_name) and os.readlink(link_name) == item: + # Link is already set up correctly: do nothing + # (os.symlink raises an exception if you try to replace an + # existing file) + pass + else: + os.symlink(item, link_name) + + for item in glob.glob("{}/*rpointer*".format(rest_path)): + shutil.copy(item, rundir) + + # Update run case settings + self._case.set_value("CLM_ACCELERATED_SPINUP", "off") + self._case.set_value("RUN_TYPE", "hybrid") + self._case.set_value("GET_REFCASE", False) + self._case.set_value("RUN_REFCASE", "{}.potveg".format(orig_casevar)) + self._case.set_value("RUN_REFDATE", "{}-01-01".format(refcase_year)) + self._case.set_value("RUN_STARTDATE", "{}-01-01".format(refcase_year)) + self._case.set_value("DOUT_S", False) + self._case.flush() + + # do the restart run (short term archiving is off) + self.run_indv() diff --git a/cime_config/SystemTests/systemtest_utils.py b/cime_config/SystemTests/systemtest_utils.py index c5ac986abd..c252f73251 100644 --- a/cime_config/SystemTests/systemtest_utils.py +++ b/cime_config/SystemTests/systemtest_utils.py @@ -2,7 +2,8 @@ Reduce code duplication by putting reused functions here. """ -import os, subprocess +import os, subprocess, re, glob +from collections import OrderedDict def cmds_to_setup_conda(caseroot): @@ -84,3 +85,26 @@ def run_python_script(caseroot, this_conda_env, command_in, tool_path): except: print(f"ERROR trying to run {tool_name}.") raise + + +# Read a user_nl file and return the namelist option if found +def find_user_nl_option(caseroot, component, namelist_option): + + # This is a copy of the CIME _get_list_of_user_nl_files + # which could be used if this moved into the CIME project + file_pattern = "user_nl_" + component + "*" + file_list = glob.glob(os.path.join(caseroot, file_pattern)) + + # Check that there is at least one file + if len(file_list) == 0: + raise RuntimeError("No user_nl files found for component " + component) + + # Read through the file list and look for a match and return the whole entry + output = OrderedDict() + for one_file in file_list: + with open(one_file, "r") as user_nl_file: + user_nl_text = user_nl_file.read() + reg = rf"{namelist_option}.*?(?=,|\n)" + find_out = re.findall(reg, user_nl_text) + output[one_file] = find_out + return output diff --git a/cime_config/config_tests.xml b/cime_config/config_tests.xml index ea128dd5c8..12859b9131 100644 --- a/cime_config/config_tests.xml +++ b/cime_config/config_tests.xml @@ -123,6 +123,18 @@ This defines various CTSM-specific system tests $STOP_N + + FATES potential vegetarion spin-up + land use transient run test + 1 + ndays + startup + 4 + FALSE + FALSE + $STOP_OPTION + $STOP_N + + Generate prescribed maturity requirements, then test with them 1 diff --git a/cime_config/testdefs/ExpectedTestFails.xml b/cime_config/testdefs/ExpectedTestFails.xml index 7a07a056f7..d1e0a1a8b8 100644 --- a/cime_config/testdefs/ExpectedTestFails.xml +++ b/cime_config/testdefs/ExpectedTestFails.xml @@ -165,32 +165,32 @@ - + FAIL - #2321 + #2653 - - + + FAIL - #2373 + FATES#1216 - + + + + FAIL - FATES#701 + #2321 - - + + FAIL #2373 - - - FAIL FATES#701 diff --git a/cime_config/testdefs/testlist_clm.xml b/cime_config/testdefs/testlist_clm.xml index 239f0a3ffe..59044feb10 100644 --- a/cime_config/testdefs/testlist_clm.xml +++ b/cime_config/testdefs/testlist_clm.xml @@ -2991,12 +2991,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cime_config/testdefs/testmods_dirs/clm/Fates/user_nl_clm b/cime_config/testdefs/testmods_dirs/clm/Fates/user_nl_clm index 406fb598f6..91df3e2e61 100644 --- a/cime_config/testdefs/testmods_dirs/clm/Fates/user_nl_clm +++ b/cime_config/testdefs/testmods_dirs/clm/Fates/user_nl_clm @@ -16,7 +16,7 @@ hist_fincl1 = 'FATES_NCOHORTS', 'FATES_TRIMMING', 'FATES_AREA_PLANTS', 'FATES_SAPWOODC', 'FATES_LEAFC', 'FATES_FROOTC', 'FATES_REPROC', 'FATES_STRUCTC', 'FATES_NONSTRUCTC', 'FATES_VEGC_ABOVEGROUND', 'FATES_CANOPY_VEGC', 'FATES_USTORY_VEGC', 'FATES_PRIMARY_PATCHFUSION_ERR', -'FATES_HARVEST_CARBON_FLUX', 'FATES_DISTURBANCE_RATE_FIRE', +'FATES_HARVEST_WOODPROD_C_FLUX', 'FATES_DISTURBANCE_RATE_FIRE', 'FATES_DISTURBANCE_RATE_LOGGING', 'FATES_DISTURBANCE_RATE_TREEFALL', 'FATES_STOMATAL_COND', 'FATES_LBLAYER_COND', 'FATES_NPP', 'FATES_GPP', 'FATES_AUTORESP', 'FATES_GROWTH_RESP', 'FATES_MAINT_RESP', 'FATES_GPP_CANOPY', diff --git a/cime_config/testdefs/testmods_dirs/clm/FatesColdLUH2/README b/cime_config/testdefs/testmods_dirs/clm/FatesColdLUH2/README new file mode 100644 index 0000000000..9b782cb2a7 --- /dev/null +++ b/cime_config/testdefs/testmods_dirs/clm/FatesColdLUH2/README @@ -0,0 +1,4 @@ +Currently the FATES LUH2 category of test mods currently only supports +4x5 grid resolutions. This is because we only have one LUH2 time series +dataset for the 4x5 resolution. In the future we will provide more resolutions +which will be added to the namelist defaults. diff --git a/cime_config/testdefs/testmods_dirs/clm/FatesColdLUH2/user_nl_clm b/cime_config/testdefs/testmods_dirs/clm/FatesColdLUH2/user_nl_clm index 854c21407f..e25490ffbb 100644 --- a/cime_config/testdefs/testmods_dirs/clm/FatesColdLUH2/user_nl_clm +++ b/cime_config/testdefs/testmods_dirs/clm/FatesColdLUH2/user_nl_clm @@ -1 +1,9 @@ + +! Run a transient case, with vegetation starting from bare ground, but land use starting from LUH state vector on starting date, in a nocomp configuration. +! From Charlie's list of valid FATES configurations: +! https://docs.google.com/spreadsheets/d/1eE3sRMYxfocZKbT8uIQhXpjjtfM2feXPRSWXJNoo4jM/edit#gid=0 use_fates_luh = .true. +use_fates_nocomp = .true. +use_fates_fixed_biogeog = .true. +use_fates_sp = .false. +use_fates_potentialveg = .false. diff --git a/cime_config/testdefs/testmods_dirs/clm/FatesColdLUH2HarvestArea/include_user_mods b/cime_config/testdefs/testmods_dirs/clm/FatesColdLUH2HarvestArea/include_user_mods new file mode 100644 index 0000000000..7eb8bb1579 --- /dev/null +++ b/cime_config/testdefs/testmods_dirs/clm/FatesColdLUH2HarvestArea/include_user_mods @@ -0,0 +1 @@ +../FatesColdLUH2 diff --git a/cime_config/testdefs/testmods_dirs/clm/FatesColdLUH2HarvestArea/user_nl_clm b/cime_config/testdefs/testmods_dirs/clm/FatesColdLUH2HarvestArea/user_nl_clm new file mode 100644 index 0000000000..426b41b49e --- /dev/null +++ b/cime_config/testdefs/testmods_dirs/clm/FatesColdLUH2HarvestArea/user_nl_clm @@ -0,0 +1 @@ +fates_harvest_mode = 'luhdata_area' diff --git a/cime_config/testdefs/testmods_dirs/clm/FatesColdLUH2HarvestMass/include_user_mods b/cime_config/testdefs/testmods_dirs/clm/FatesColdLUH2HarvestMass/include_user_mods new file mode 100644 index 0000000000..7eb8bb1579 --- /dev/null +++ b/cime_config/testdefs/testmods_dirs/clm/FatesColdLUH2HarvestMass/include_user_mods @@ -0,0 +1 @@ +../FatesColdLUH2 diff --git a/cime_config/testdefs/testmods_dirs/clm/FatesColdLUH2HarvestMass/user_nl_clm b/cime_config/testdefs/testmods_dirs/clm/FatesColdLUH2HarvestMass/user_nl_clm new file mode 100644 index 0000000000..7b6bc24f5a --- /dev/null +++ b/cime_config/testdefs/testmods_dirs/clm/FatesColdLUH2HarvestMass/user_nl_clm @@ -0,0 +1 @@ +fates_harvest_mode = 'luhdata_mass' diff --git a/cime_config/testdefs/testmods_dirs/clm/FatesColdLandUse/user_nl_clm b/cime_config/testdefs/testmods_dirs/clm/FatesColdLandUse/user_nl_clm index 668f9c861d..b27a74031c 100644 --- a/cime_config/testdefs/testmods_dirs/clm/FatesColdLandUse/user_nl_clm +++ b/cime_config/testdefs/testmods_dirs/clm/FatesColdLandUse/user_nl_clm @@ -1,2 +1,2 @@ flanduse_timeseries = '$DIN_LOC_ROOT/lnd/clm2/surfdata_esmf/ctsm5.2.0/landuse.timeseries_4x5_hist_16_CMIP6_1850-2015_c230620.nc' -do_harvest = .true. +fates_harvest_mode = 'landuse_timeseries' diff --git a/cime_config/testdefs/testmods_dirs/clm/FatesColdLogging/user_nl_clm b/cime_config/testdefs/testmods_dirs/clm/FatesColdLogging/user_nl_clm index 3b74a4fd37..d2079d9e43 100644 --- a/cime_config/testdefs/testmods_dirs/clm/FatesColdLogging/user_nl_clm +++ b/cime_config/testdefs/testmods_dirs/clm/FatesColdLogging/user_nl_clm @@ -1 +1 @@ -use_fates_logging= .true. +fates_harvest_mode = 'event_code' diff --git a/cime_config/testdefs/testmods_dirs/clm/FatesLUPFT/README b/cime_config/testdefs/testmods_dirs/clm/FatesLUPFT/README new file mode 100644 index 0000000000..88f5c2c8fb --- /dev/null +++ b/cime_config/testdefs/testmods_dirs/clm/FatesLUPFT/README @@ -0,0 +1,9 @@ +This test mod does not use cold start and is intended to +be used in conjunction with a test workflow that provides +an initialization file. Currently this is accomplished +by using the test mod in conjunction with the PVT +system test. The PVT system test runs a FATES spin-up +case using the use_fates_potentialveg mode and then +references the restart output to run a use_fates_lupft +transient mode case. + diff --git a/cime_config/testdefs/testmods_dirs/clm/FatesLUPFT/include_user_mods b/cime_config/testdefs/testmods_dirs/clm/FatesLUPFT/include_user_mods new file mode 100644 index 0000000000..4c7aa0f2b4 --- /dev/null +++ b/cime_config/testdefs/testmods_dirs/clm/FatesLUPFT/include_user_mods @@ -0,0 +1 @@ +../Fates diff --git a/cime_config/testdefs/testmods_dirs/clm/FatesLUPFT/user_nl_clm b/cime_config/testdefs/testmods_dirs/clm/FatesLUPFT/user_nl_clm new file mode 100644 index 0000000000..10044848a0 --- /dev/null +++ b/cime_config/testdefs/testmods_dirs/clm/FatesLUPFT/user_nl_clm @@ -0,0 +1 @@ +use_fates_lupft = .true. diff --git a/cime_config/testdefs/testmods_dirs/clm/FatesLUPFTAreaHarvest/include_user_mods b/cime_config/testdefs/testmods_dirs/clm/FatesLUPFTAreaHarvest/include_user_mods new file mode 100644 index 0000000000..1ceba4c200 --- /dev/null +++ b/cime_config/testdefs/testmods_dirs/clm/FatesLUPFTAreaHarvest/include_user_mods @@ -0,0 +1 @@ +../FatesLUPFT diff --git a/cime_config/testdefs/testmods_dirs/clm/FatesLUPFTAreaHarvest/user_nl_clm b/cime_config/testdefs/testmods_dirs/clm/FatesLUPFTAreaHarvest/user_nl_clm new file mode 100644 index 0000000000..426b41b49e --- /dev/null +++ b/cime_config/testdefs/testmods_dirs/clm/FatesLUPFTAreaHarvest/user_nl_clm @@ -0,0 +1 @@ +fates_harvest_mode = 'luhdata_area' diff --git a/cime_config/usermods_dirs/fates_sp/user_nl_clm b/cime_config/usermods_dirs/fates_sp/user_nl_clm index 093ecd7eda..37da8d1c67 100644 --- a/cime_config/usermods_dirs/fates_sp/user_nl_clm +++ b/cime_config/usermods_dirs/fates_sp/user_nl_clm @@ -22,7 +22,7 @@ hist_fexcl1 = 'FATES_TRIMMING', 'FATES_COLD_STATUS', 'FATES_GDD', 'FATES_NCHILLD 'FATES_SAPWOODC', 'FATES_FROOTC', 'FATES_REPROC', 'FATES_STRUCTC', 'FATES_NONSTRUCTC', 'FATES_VEGC_ABOVEGROUND', 'FATES_CANOPY_VEGC', 'FATES_USTORY_VEGC', 'FATES_PRIMARY_PATCHFUSION_ERR', 'FATES_DISTURBANCE_RATE_FIRE', 'FATES_DISTURBANCE_RATE_LOGGING', 'FATES_DISTURBANCE_RATE_TREEFALL', - 'FATES_HARVEST_CARBON_FLUX', 'FATES_GPP_CANOPY', 'FATES_AUTORESP_CANOPY', + 'FATES_HARVEST_WOODPROD_C_FLUX', 'FATES_GPP_CANOPY', 'FATES_AUTORESP_CANOPY', 'FATES_GPP_USTORY', 'FATES_AUTORESP_USTORY', 'FATES_CROWNAREA_CL', 'FATES_DEMOTION_CARBONFLUX', 'FATES_PROMOTION_CARBONFLUX', 'FATES_MORTALITY_CFLUX_CANOPY', 'FATES_MORTALITY_CFLUX_USTORY', 'FATES_DDBH_CANOPY_SZ', 'FATES_DDBH_USTORY_SZ', 'FATES_BASALAREA_SZ', diff --git a/doc/ChangeLog b/doc/ChangeLog index 00c576d0d8..8cc3198fae 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,4 +1,129 @@ =============================================================== +Tag name: ctsm5.2.013 +Originator(s): samrabin (Sam Rabin, UCAR/TSS, samrabin@ucar.edu) + glemieux (Gregory Lemieux, LBNL, glemieux@lbl.gov) +Date: Thu Jul 18 10:51:11 MDT 2024 +One-line Summary: FATES Land Use V2 + +Purpose and description of changes +---------------------------------- +This tag enables FATES to utilize its land use mode with fixed +biogeography and no competition mode engaged. To facilitate +this update, the host land model reads in a new static map data +set that associates land use with FATES plant functional types. +This tag also updates the pre-existing FATES dynamic land use +module to provide access to the raw LUH2 harvest data from the +FATES LUH2 timeseries data set (added in ctsm5.1.dev160). + +Significant changes to scientifically-supported configurations +-------------------------------------------------------------- + +Does this tag change answers significantly for any of the following physics configurations? +(Details of any changes will be given in the "Answer changes" section below.) + + [Put an [X] in the box for any configuration with significant answer changes.] + +[ ] clm6_0 + +[ ] clm5_1 + +[ ] clm5_0 + +[ ] ctsm5_0-nwp + +[ ] clm4_5 + + +Notes of particular relevance for users +--------------------------------------- + +Caveats for users (e.g., need to interpolate initial conditions): + FATES satellite phenology mode and land use mode are currently incompatible + and trying to engage both will result in a graceful build failure message + +Changes to CTSM's user interface (e.g., new/renamed XML or namelist variables): + New FATES namelist option: fates_harvest_mode + - This new option provides five harvest modes + - The 'event_code' mode takes over the now defunct use_fates_logging option + - The 'landuse_timeseries' option supersedes the use of do_harvest option + with FATES. Using do_harvest is no longer compatible with FATES. + + New FATES namelist option: use_fates_lupft + - This option enables the necessary namelist options and data sets to run + FATES with land use, no competition, and fixed biogeography modes. + + New FATES namelist option: flandusepftdat + - This data set is necessary for running with use_fates_lupft. + + New FATES namelist option: use_potential_veg + - This option is only necessary for use with FATES spin-up to transient + workflows that will engage the use_fates_lupft mode for the transient case + +Changes made to namelist defaults (e.g., changed parameter values): + The default FATES parameter file has been updated to account for the new + parameters necessary for land use v2. + + A new default data set has been provided for flandusepftdat. Only a 4x5 grid + resolution is currently provided. + +Changes to the datasets (e.g., parameter, surface or initial files): + The FATES land use timeseries data set, fluh_timeseries, has been updated to + provide a wider timeseries range, from 0850-2015. + + +Notes of particular relevance for developers: +--------------------------------------------- +Changes to tests or testing: + + New FATES testmods have been added to account for the additional harvest mode + and use_fates_lupft namelist options. Additoinally a new system text prefix, + PVT, has been added to test the use_fates_potentialveg spin-up to use_fates_lupft + transient workflow. These have been added to the fates test suite. + +Bugs fixed +---------- +List of CTSM issues fixed (include CTSM Issue # and description) [one per line]: +Fixes #2444 Failing water isotope test on the ctsm5.2 branch + +Notes of particular relevance for users +--------------------------------------- +Changes to documentation: None + +Testing summary: +---------------- + + build-namelist tests (if CLMBuildNamelist.pm has changed): + + derecho - PASS + + regular tests (aux_clm: https://github.com/ESCOMP/CTSM/wiki/System-Testing-Guide#pre-merge-system-testing): + + derecho ----- TBD + izumi ------- TBD + + fates tests: (give name of baseline if different from CTSM tagname, normally fates baselines are fates--) + derecho ----- OK + +If the tag used for baseline comparisons was NOT the previous tag, note that here: + fates tested against fates-sci.1.76.4_api.35.1.0-ctsm5.2.008 + + +Answer changes +-------------- +Changes answers relative to baseline: Only for FATES test mods, otherwise B4B + +Other details +------------- +List any git submodules updated (cime, rtm, mosart, cism, fates, etc.): + FATES: sci.1.73.0_api.35.0.0 -> sci.1.77.0_api.36.0.0 + +Pull Requests that document the changes (include PR ids): +(https://github.com/ESCOMP/ctsm/pull) + #2507 -- FATES land use v2 API update (CTSM-side) + NGEET#1116 -- V2 Land Use Change + +=============================================================== +=============================================================== Tag name: ctsm5.2.012 Originator(s): sacks (Bill Sacks, UCAR/NCAR/CGD) Date: Tue 16 Jul 2024 08:57:42 AM MDT diff --git a/doc/ChangeSum b/doc/ChangeSum index 381b0db858..df8e6dcf6a 100644 --- a/doc/ChangeSum +++ b/doc/ChangeSum @@ -1,5 +1,6 @@ Tag Who Date Summary ============================================================================================================================ + ctsm5.2.013 glemieux 07/18/2024 FATES Land Use V2 ctsm5.2.012 sacks 07/16/2024 Relax tolerance for truncating small snocan values in CanopyFluxes ctsm5.2.011 slevis 07/12/2024 Merge b4b-dev ctsm5.2.010 multiple 07/11/2024 Explicit A/C adoption diff --git a/src/dyn_subgrid/dynFATESLandUseChangeMod.F90 b/src/dyn_subgrid/dynFATESLandUseChangeMod.F90 index 45f4340d6a..1bc6ab929e 100644 --- a/src/dyn_subgrid/dynFATESLandUseChangeMod.F90 +++ b/src/dyn_subgrid/dynFATESLandUseChangeMod.F90 @@ -26,13 +26,40 @@ module dynFATESLandUseChangeMod ! Landuse state at beginning of year (fraction of gridcell), landuse state name x gridcell real(r8), allocatable, public :: landuse_states(:,:) + ! TODO SSR: Ask Charlie for description to go here + real(r8), allocatable, public :: landuse_harvest(:,:) + ! Number of landuse transition and state names integer, public, parameter :: num_landuse_transition_vars = 108 integer, public, parameter :: num_landuse_state_vars = 12 + integer, public, parameter :: num_landuse_harvest_vars = 5 + + ! Define the fates landuse namelist mode switch values + character(len=18), public, parameter :: fates_harvest_no_logging = 'no_harvest' + character(len=18), public, parameter :: fates_harvest_logging_only = 'event_code' + character(len=18), public, parameter :: fates_harvest_clmlanduse = 'landuse_timeseries' + character(len=18), public, parameter :: fates_harvest_luh_area = 'luhdata_area' + character(len=18), public, parameter :: fates_harvest_luh_mass = 'luhdata_mass' + + ! Define landuse harvest unit integer representation + integer, public, parameter :: landuse_harvest_area_units = 1 + integer, public, parameter :: landuse_harvest_mass_units = 2 + integer, public :: landuse_harvest_units ! landuse filename type(dyn_file_type), target :: dynFatesLandUse_file + ! LUH2 raw wood harvest area fraction + ! LUH2 data set variable names can be found at https://luh.umd.edu/LUH2/LUH2_v2h_README.pdf + character(len=10), target :: landuse_harvest_area_varnames(num_landuse_harvest_vars) = & + [character(len=10) :: 'primf_harv', 'primn_harv', 'secmf_harv', 'secyf_harv', 'secnf_harv'] + + ! LUH2 raw wood harvest biomass carbon + character(len=10), target :: landuse_harvest_mass_varnames(num_landuse_harvest_vars) = & + [character(len=10) :: 'primf_bioh', 'primn_bioh', 'secmf_bioh', 'secyf_bioh', 'secnf_bioh'] + + character(len=10), public, pointer :: landuse_harvest_varnames(:) => null() + ! Land use name arrays character(len=5), public, parameter :: landuse_state_varnames(num_landuse_state_vars) = & [character(len=5) :: 'primf','primn','secdf','secdn','pastr','range', & @@ -64,8 +91,9 @@ module dynFATESLandUseChangeMod 'c3nfx_to_c3ann','c3nfx_to_c4ann','c3nfx_to_c3per','c3nfx_to_c4per', & 'c3nfx_to_secdf','c3nfx_to_secdn','c3nfx_to_pastr','c3nfx_to_range','c3nfx_to_urban'] - type(dyn_var_time_uninterp_type) :: landuse_transition_vars(num_landuse_transition_vars) ! value of each landuse variable - type(dyn_var_time_uninterp_type) :: landuse_state_vars(num_landuse_state_vars) ! value of each landuse variable + type(dyn_var_time_uninterp_type) :: landuse_transition_vars(num_landuse_transition_vars) ! value of each transitions variable + type(dyn_var_time_uninterp_type) :: landuse_state_vars(num_landuse_state_vars) ! value of each state variable + type(dyn_var_time_uninterp_type) :: landuse_harvest_vars(num_landuse_harvest_vars) ! value of each harvest variable public :: dynFatesLandUseInit public :: dynFatesLandUseInterp @@ -79,14 +107,15 @@ subroutine dynFatesLandUseInit(bounds, landuse_filename) ! Initialize data structures for land use information. ! !USES: - use clm_varctl , only : use_cn, use_fates_luh + use clm_varctl , only : use_cn, use_fates_luh, fates_harvest_mode + use clm_varctl , only : use_fates_potentialveg use dynVarTimeUninterpMod , only : dyn_var_time_uninterp_type use dynTimeInfoMod , only : YEAR_POSITION_START_OF_TIMESTEP use dynTimeInfoMod , only : YEAR_POSITION_END_OF_TIMESTEP ! !ARGUMENTS: type(bounds_type), intent(in) :: bounds ! proc-level bounds - character(len=*) , intent(in) :: landuse_filename ! name of file containing land use information + character(len=*) , intent(in) :: landuse_filename ! name of file containing landuse timeseries information (fates luh2) ! !LOCAL VARIABLES integer :: varnum, i ! counter for harvest variables @@ -111,37 +140,69 @@ subroutine dynFatesLandUseInit(bounds, landuse_filename) if (ier /= 0) then call endrun(msg=' allocation error for landuse_transitions'//errMsg(__FILE__, __LINE__)) end if + allocate(landuse_harvest(num_landuse_harvest_vars,bounds%begg:bounds%endg),stat=ier) + if (ier /= 0) then + call endrun(msg=' allocation error for landuse_harvest'//errMsg(__FILE__, __LINE__)) + end if + ! Initialize the states, transitions and harvest mapping percentages as zero by default landuse_states = 0._r8 landuse_transitions = 0._r8 - - if (use_fates_luh) then - - ! Generate the dyn_file_type object. Note that the land use data being read in is for the - ! transitions occuring within the current year - dynFatesLandUse_file = dyn_file_type(landuse_filename, YEAR_POSITION_END_OF_TIMESTEP) - - ! Get initial land use data - num_points = (bounds%endg - bounds%begg + 1) - landuse_shape(1) = num_points ! Does this need an explicit array shape to be passed to the constructor? - do varnum = 1, num_landuse_transition_vars - landuse_transition_vars(varnum) = dyn_var_time_uninterp_type( & - dyn_file=dynFatesLandUse_file, varname=landuse_transition_varnames(varnum), & - dim1name=grlnd, conversion_factor=1.0_r8, & - do_check_sums_equal_1=.false., data_shape=landuse_shape) - end do - do varnum = 1, num_landuse_state_vars - landuse_state_vars(varnum) = dyn_var_time_uninterp_type( & - dyn_file=dynFatesLandUse_file, varname=landuse_state_varnames(varnum), & - dim1name=grlnd, conversion_factor=1.0_r8, & - do_check_sums_equal_1=.false., data_shape=landuse_shape) - end do + landuse_harvest = 0._r8 + + ! Avoid initializing the landuse timeseries file if in fates potential vegetation mode + if (.not. use_fates_potentialveg) then + if (use_fates_luh) then + + ! Generate the dyn_file_type object. + ! Start calls get_prev_date, whereas end calls get_curr_date + dynFatesLandUse_file = dyn_file_type(landuse_filename, YEAR_POSITION_END_OF_TIMESTEP) + + ! Get initial land use data from the fates luh2 timeseries dataset + num_points = (bounds%endg - bounds%begg + 1) + landuse_shape(1) = num_points ! Does this need an explicit array shape to be passed to the constructor? + do varnum = 1, num_landuse_transition_vars + landuse_transition_vars(varnum) = dyn_var_time_uninterp_type( & + dyn_file=dynFatesLandUse_file, varname=landuse_transition_varnames(varnum), & + dim1name=grlnd, conversion_factor=1.0_r8, & + do_check_sums_equal_1=.false., data_shape=landuse_shape) + end do + do varnum = 1, num_landuse_state_vars + landuse_state_vars(varnum) = dyn_var_time_uninterp_type( & + dyn_file=dynFatesLandUse_file, varname=landuse_state_varnames(varnum), & + dim1name=grlnd, conversion_factor=1.0_r8, & + do_check_sums_equal_1=.false., data_shape=landuse_shape) + end do + + ! Get the harvest rate data from the fates luh2 timeseries dataset if enabled + if (trim(fates_harvest_mode) .eq. fates_harvest_luh_area .or. & + trim(fates_harvest_mode) .eq. fates_harvest_luh_mass) then + + ! change the harvest varnames being used depending on the mode selected + if (trim(fates_harvest_mode) .eq. fates_harvest_luh_area ) then + landuse_harvest_varnames => landuse_harvest_area_varnames + landuse_harvest_units = landuse_harvest_area_units + elseif (trim(fates_harvest_mode) .eq. fates_harvest_luh_mass ) then + landuse_harvest_varnames => landuse_harvest_mass_varnames + landuse_harvest_units = landuse_harvest_mass_units + else + call endrun(msg=' undefined fates harvest mode selected'//errMsg(__FILE__, __LINE__)) + end if + + do varnum = 1, num_landuse_harvest_vars + landuse_harvest_vars(varnum) = dyn_var_time_uninterp_type( & + dyn_file=dynFatesLandUse_file, varname=landuse_harvest_varnames(varnum), & + dim1name=grlnd, conversion_factor=1.0_r8, & + do_check_sums_equal_1=.false., data_shape=landuse_shape) + end do + end if + end if + + ! Since fates needs state data during initialization, make sure to call + ! the interpolation routine at the start + call dynFatesLandUseInterp(bounds,init_state=.true.) end if - ! Since fates needs state data during initialization, make sure to call - ! the interpolation routine at the start - call dynFatesLandUseInterp(bounds,init_state=.true.) - end subroutine dynFatesLandUseInit @@ -159,7 +220,7 @@ subroutine dynFatesLandUseInterp(bounds, init_state) ! !USES: use dynTimeInfoMod , only : time_info_type - use clm_varctl , only : use_cn + use clm_varctl , only : use_cn, fates_harvest_mode ! !ARGUMENTS: type(bounds_type), intent(in) :: bounds ! proc-level bounds @@ -181,13 +242,14 @@ subroutine dynFatesLandUseInterp(bounds, init_state) init_flag = init_state end if - ! Get the current year + ! Get the data for the current year call dynFatesLandUse_file%time_info%set_current_year() if (dynFatesLandUse_file%time_info%is_before_time_series() .and. .not.(init_flag)) then ! Reset the land use transitions to zero for safety landuse_transitions(1:num_landuse_transition_vars,bounds%begg:bounds%endg) = 0._r8 landuse_states(1:num_landuse_state_vars,bounds%begg:bounds%endg) = 0._r8 + landuse_harvest(1:num_landuse_harvest_vars,bounds%begg:bounds%endg) = 0._r8 else ! Loop through all variables on the data file and put data into the temporary array ! then update the global state and transitions array. @@ -200,6 +262,13 @@ subroutine dynFatesLandUseInterp(bounds, init_state) call landuse_state_vars(varnum)%get_current_data(this_data) landuse_states(varnum,bounds%begg:bounds%endg) = this_data(bounds%begg:bounds%endg) end do + if (trim(fates_harvest_mode) .eq. fates_harvest_luh_area .or. & + trim(fates_harvest_mode) .eq. fates_harvest_luh_mass) then + do varnum = 1, num_landuse_harvest_vars + call landuse_harvest_vars(varnum)%get_current_data(this_data) + landuse_harvest(varnum,bounds%begg:bounds%endg) = this_data(bounds%begg:bounds%endg) + end do + end if deallocate(this_data) end if diff --git a/src/dyn_subgrid/dynSubgridDriverMod.F90 b/src/dyn_subgrid/dynSubgridDriverMod.F90 index e5ca3f002e..ea1210521d 100644 --- a/src/dyn_subgrid/dynSubgridDriverMod.F90 +++ b/src/dyn_subgrid/dynSubgridDriverMod.F90 @@ -89,6 +89,11 @@ subroutine dynSubgrid_init(bounds_proc, glc_behavior, crop_inst) ! Note that dynpft_init needs to be called from outside any loops over clumps - so ! this routine needs to be called from outside any loops over clumps. ! + ! + ! !USES: + use clm_varctl , only : fates_harvest_mode + use dynFATESLandUseChangeMod , only : fates_harvest_clmlanduse + ! ! !ARGUMENTS: type(bounds_type) , intent(in) :: bounds_proc ! processor-level bounds type(glc_behavior_type) , intent(in) :: glc_behavior @@ -123,7 +128,7 @@ subroutine dynSubgrid_init(bounds_proc, glc_behavior, crop_inst) ! flanduse_timeseries file. However, this could theoretically be changed so that the ! harvest data were separated from the pftdyn data, allowing them to differ in the ! years over which they apply. - if (get_do_harvest()) then + if (get_do_harvest() .or. trim(fates_harvest_mode) == fates_harvest_clmlanduse) then call dynHarvest_init(bounds_proc, harvest_filename=get_flanduse_timeseries()) end if @@ -201,7 +206,7 @@ subroutine dynSubgrid_driver(bounds_proc, ! OUTSIDE any loops over clumps in the driver. ! ! !USES: - use clm_varctl , only : use_cn, use_fates, use_fates_luh + use clm_varctl , only : use_cn, use_fates, use_fates_luh, use_fates_potentialveg use dynInitColumnsMod , only : initialize_new_columns use dynConsBiogeophysMod , only : dyn_hwcontent_init, dyn_hwcontent_final use dynEDMod , only : dyn_ED @@ -290,7 +295,7 @@ subroutine dynSubgrid_driver(bounds_proc, call dynurban_interp(bounds_proc) end if - if (use_fates_luh) then + if (use_fates_luh .and. .not. use_fates_potentialveg) then call dynFatesLandUseInterp(bounds_proc) end if diff --git a/src/fates b/src/fates index adfa664806..1982b0032c 160000 --- a/src/fates +++ b/src/fates @@ -1 +1 @@ -Subproject commit adfa6648063408d443f5cae671bd37f713d3e3e8 +Subproject commit 1982b0032c3cab6278892eccb85f643114ffb1af diff --git a/src/main/clm_instMod.F90 b/src/main/clm_instMod.F90 index ab690a92a6..a134265e02 100644 --- a/src/main/clm_instMod.F90 +++ b/src/main/clm_instMod.F90 @@ -200,6 +200,7 @@ subroutine clm_instInit(bounds) use SoilWaterRetentionCurveFactoryMod , only : create_soil_water_retention_curve use decompMod , only : get_proc_bounds use BalanceCheckMod , only : GetBalanceCheckSkipSteps + use clm_varctl , only : flandusepftdat use clm_varctl , only : use_hillslope use HillslopeHydrologyMod , only : SetHillslopeSoilThickness use initVerticalMod , only : setSoilLayerClass @@ -448,7 +449,7 @@ subroutine clm_instInit(bounds) ! Initialize the Functionaly Assembled Terrestrial Ecosystem Simulator (FATES) ! if (use_fates) then - call clm_fates%Init(bounds) + call clm_fates%Init(bounds, flandusepftdat) end if deallocate (h2osno_col) diff --git a/src/main/clm_varctl.F90 b/src/main/clm_varctl.F90 index 06ae11d92d..f804a39207 100644 --- a/src/main/clm_varctl.F90 +++ b/src/main/clm_varctl.F90 @@ -334,7 +334,7 @@ module clm_varctl ! > 1 for external data (lightning and/or anthropogenic ignitions) ! see bld/namelist_files/namelist_definition_clm4_5.xml for details logical, public :: use_fates_tree_damage = .false. ! true => turn on tree damage module - logical, public :: use_fates_logging = .false. ! true => turn on logging module + character(len=256), public :: fates_harvest_mode = '' ! five different harvest modes; see namelist definition logical, public :: use_fates_planthydro = .false. ! true => turn on fates hydro logical, public :: use_fates_cohort_age_tracking = .false. ! true => turn on cohort age tracking logical, public :: use_fates_ed_st3 = .false. ! true => static stand structure @@ -357,7 +357,10 @@ module clm_varctl integer, dimension(2), public :: fates_history_dimlevel = (/2,2/) 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 character(len=256), public :: fates_inventory_ctrl_filename = '' ! filename for inventory control ! FATES SP AND FATES BGC are MUTUTALLY EXCLUSIVE, THEY CAN'T BOTH BE ON diff --git a/src/main/controlMod.F90 b/src/main/controlMod.F90 index 6d20701e26..f876e97176 100644 --- a/src/main/controlMod.F90 +++ b/src/main/controlMod.F90 @@ -234,7 +234,7 @@ subroutine control_init(dtime) ! FATES Flags namelist /clm_inparm/ fates_paramfile, use_fates, & - fates_spitfire_mode, use_fates_logging, & + fates_spitfire_mode, fates_harvest_mode, & use_fates_planthydro, use_fates_ed_st3, & use_fates_cohort_age_tracking, & use_fates_ed_prescribed_phys, & @@ -243,7 +243,10 @@ subroutine control_init(dtime) use_fates_nocomp, & use_fates_sp, & use_fates_luh, & + use_fates_lupft, & + use_fates_potentialveg, & fluh_timeseries, & + flandusepftdat, & fates_inventory_ctrl_filename, & fates_parteh_mode, & fates_seeddisp_cadence, & @@ -799,7 +802,7 @@ subroutine control_spmd() call mpi_bcast (for_testing_allow_interp_non_ciso_to_ciso, 1, MPI_LOGICAL, 0, mpicom, ier) call mpi_bcast (fates_spitfire_mode, 1, MPI_INTEGER, 0, mpicom, ier) - call mpi_bcast (use_fates_logging, 1, MPI_LOGICAL, 0, mpicom, ier) + call mpi_bcast (fates_harvest_mode, len(fates_harvest_mode) , MPI_CHARACTER, 0, mpicom, ier) call mpi_bcast (use_fates_planthydro, 1, MPI_LOGICAL, 0, mpicom, ier) call mpi_bcast (use_fates_tree_damage, 1, MPI_LOGICAL, 0, mpicom, ier) call mpi_bcast (use_fates_cohort_age_tracking, 1, MPI_LOGICAL, 0, mpicom, ier) @@ -810,10 +813,14 @@ 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) call mpi_bcast (fates_paramfile, len(fates_paramfile) , MPI_CHARACTER, 0, mpicom, ier) call mpi_bcast (fluh_timeseries, len(fluh_timeseries) , MPI_CHARACTER, 0, mpicom, ier) + call mpi_bcast (flandusepftdat, len(flandusepftdat) , MPI_CHARACTER, 0, mpicom, ier) + call mpi_bcast (fates_parteh_mode, 1, MPI_INTEGER, 0, mpicom, ier) call mpi_bcast (fates_seeddisp_cadence, 1, MPI_INTEGER, 0, mpicom, ier) call mpi_bcast (fates_history_dimlevel, 2, MPI_INTEGER, 0, mpicom, ier) @@ -1190,7 +1197,7 @@ subroutine control_print () write(iulog, *) ' use_fates = ', use_fates if (use_fates) then write(iulog, *) ' fates_spitfire_mode = ', fates_spitfire_mode - write(iulog, *) ' use_fates_logging = ', use_fates_logging + write(iulog, *) ' fates_harvest_mode = ', fates_harvest_mode write(iulog, *) ' fates_paramfile = ', fates_paramfile write(iulog, *) ' fates_parteh_mode = ', fates_parteh_mode write(iulog, *) ' use_fates_planthydro = ', use_fates_planthydro @@ -1203,7 +1210,10 @@ 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) write(iulog, *) ' fates_seeddisp_cadence = ', fates_seeddisp_cadence write(iulog, *) ' fates_seeddisp_cadence: 0, 1, 2, 3 => off, daily, monthly, or yearly dispersal' write(iulog, *) ' fates_inventory_ctrl_filename = ', trim(fates_inventory_ctrl_filename) diff --git a/src/utils/clmfates_interfaceMod.F90 b/src/utils/clmfates_interfaceMod.F90 index fcd5cb5230..e3e7644b90 100644 --- a/src/utils/clmfates_interfaceMod.F90 +++ b/src/utils/clmfates_interfaceMod.F90 @@ -54,12 +54,15 @@ module CLMFatesInterfaceMod use clm_varctl , only : use_fates_cohort_age_tracking use clm_varctl , only : use_fates_ed_st3 use clm_varctl , only : use_fates_ed_prescribed_phys - use clm_varctl , only : use_fates_logging + use clm_varctl , only : fates_harvest_mode use clm_varctl , only : use_fates_inventory_init use clm_varctl , only : use_fates_fixed_biogeog use clm_varctl , only : use_fates_nocomp use clm_varctl , only : use_fates_sp use clm_varctl , only : use_fates_luh + use clm_varctl , only : use_fates_lupft + use clm_varctl , only : use_fates_potentialveg + use clm_varctl , only : flandusepftdat use clm_varctl , only : fates_seeddisp_cadence use clm_varctl , only : fates_inventory_ctrl_filename use clm_varctl , only : use_nitrif_denitrif @@ -167,7 +170,6 @@ module CLMFatesInterfaceMod use FATESFireBase , only : fates_fire_base_type use FATESFireFactoryMod , only : no_fire, scalar_lightning, successful_ignitions,& anthro_ignitions, anthro_suppression - use dynSubgridControlMod , only : get_do_harvest use dynHarvestMod , only : num_harvest_inst, harvest_varnames use dynHarvestMod , only : harvest_units, mass_units, unitless_units use dynHarvestMod , only : dynHarvest_interp_resolve_harvesttypes @@ -180,7 +182,14 @@ module CLMFatesInterfaceMod use dynFATESLandUseChangeMod, only : num_landuse_transition_vars, num_landuse_state_vars use dynFATESLandUseChangeMod, only : landuse_transitions, landuse_states use dynFATESLandUseChangeMod, only : landuse_transition_varnames, landuse_state_varnames - use dynFATESLandUseChangeMod, only : dynFatesLandUseInterp + use dynFATESLandUseChangeMod, only : num_landuse_harvest_vars + use dynFATESLandUseChangeMod, only : fates_harvest_no_logging + use dynFATESLandUseChangeMod, only : fates_harvest_clmlanduse + use dynFATESLandUseChangeMod, only : fates_harvest_luh_area + use dynFATESLandUseChangeMod, only : fates_harvest_luh_mass + use dynFATESLandUseChangeMod, only : landuse_harvest + use dynFATESLandUseChangeMod, only : landuse_harvest_units + use dynFATESLandUseChangeMod, only : landuse_harvest_varnames implicit none @@ -273,6 +282,8 @@ module CLMFatesInterfaceMod character(len=*), parameter, private :: sourcefile = & __FILE__ + integer, parameter :: num_landuse_pft_vars = 4 + public :: CLMFatesGlobals1 public :: CLMFatesGlobals2 public :: CrossRefHistoryFields @@ -386,6 +397,7 @@ subroutine CLMFatesGlobals2() integer :: pass_cohort_age_tracking integer :: pass_tree_damage integer :: pass_use_luh + integer :: pass_use_potentialveg integer :: pass_num_luh_states integer :: pass_num_luh_transitions @@ -483,13 +495,6 @@ subroutine CLMFatesGlobals2() end if call set_fates_ctrlparms('use_ed_st3',ival=pass_ed_st3) - if(use_fates_logging) then - pass_logging = 1 - else - pass_logging = 0 - end if - call set_fates_ctrlparms('use_logging',ival=pass_logging) - if(use_fates_ed_prescribed_phys) then pass_ed_prescribed_phys = 1 else @@ -511,26 +516,30 @@ subroutine CLMFatesGlobals2() end if call set_fates_ctrlparms('use_cohort_age_tracking',ival=pass_cohort_age_tracking) - ! check fates logging namelist value first because hlm harvest overrides it - if(use_fates_logging) then - pass_logging = 1 - else - pass_logging = 0 - end if - - if(get_do_harvest()) then - pass_logging = 1 - pass_num_lu_harvest_cats = num_harvest_inst - pass_lu_harvest = 1 - else - pass_lu_harvest = 0 - pass_num_lu_harvest_cats = 0 + ! FATES logging and harvest modes + pass_logging = 0 + pass_lu_harvest = 0 + pass_num_lu_harvest_cats = 0 + if (trim(fates_harvest_mode) /= fates_harvest_no_logging) then + pass_logging = 1 ! Time driven logging, without landuse harvest + ! CLM landuse timeseries driven harvest rates + if (trim(fates_harvest_mode) == fates_harvest_clmlanduse) then + pass_num_lu_harvest_cats = num_harvest_inst + pass_lu_harvest = 1 + + ! LUH2 landuse timeseries driven harvest rates + else if (trim(fates_harvest_mode)== fates_harvest_luh_area .or. & + trim(fates_harvest_mode)== fates_harvest_luh_mass) then + pass_lu_harvest = 1 + pass_num_lu_harvest_cats = num_landuse_harvest_vars + end if end if call set_fates_ctrlparms('use_lu_harvest',ival=pass_lu_harvest) call set_fates_ctrlparms('num_lu_harvest_cats',ival=pass_num_lu_harvest_cats) call set_fates_ctrlparms('use_logging',ival=pass_logging) + ! FATES landuse modes if(use_fates_luh) then pass_use_luh = 1 pass_num_luh_states = num_landuse_state_vars @@ -540,10 +549,18 @@ subroutine CLMFatesGlobals2() pass_num_luh_states = 0 pass_num_luh_transitions = 0 end if + call set_fates_ctrlparms('use_luh2',ival=pass_use_luh) call set_fates_ctrlparms('num_luh2_states',ival=pass_num_luh_states) call set_fates_ctrlparms('num_luh2_transitions',ival=pass_num_luh_transitions) + if ( use_fates_potentialveg ) then + pass_use_potentialveg = 1 + else + pass_use_potentialveg = 0 + end if + call set_fates_ctrlparms('use_fates_potentialveg',ival=pass_use_potentialveg) + if(use_fates_inventory_init) then pass_inventory_init = 1 else @@ -675,7 +692,7 @@ end subroutine CLMFatesTimesteps ! ==================================================================================== - subroutine init(this, bounds_proc ) + subroutine init(this, bounds_proc, flandusepftdat) ! --------------------------------------------------------------------------------- ! This initializes the hlm_fates_interface_type @@ -704,6 +721,7 @@ subroutine init(this, bounds_proc ) ! Input Arguments class(hlm_fates_interface_type), intent(inout) :: this type(bounds_type),intent(in) :: bounds_proc + character(len=*), intent(in) :: flandusepftdat ! local variables integer :: nclumps ! Number of threads @@ -721,6 +739,9 @@ subroutine init(this, bounds_proc ) integer :: ndecomp integer :: numg + real(r8), allocatable :: landuse_pft_map(:,:,:) + real(r8), allocatable :: landuse_bareground(:) + ! Initialize the FATES communicators with the HLM ! This involves to stages ! 1) allocate the vectors @@ -753,6 +774,13 @@ subroutine init(this, bounds_proc ) write(iulog,*) 'clm_fates%init(): allocating for ',nclumps,' threads' end if + ! Retrieve the landuse x pft static data if the file is present + if (use_fates_fixed_biogeog .and. use_fates_luh) then + call GetLandusePFTData(bounds_proc, flandusepftdat, landuse_pft_map, landuse_bareground) + end if + + nclumps = get_proc_clumps() + allocate(copy_fates_var(bounds_proc%begc:bounds_proc%endc)) copy_fates_var(:) = .false. @@ -857,18 +885,26 @@ subroutine init(this, bounds_proc ) this%fates(nc)%sites(s)%lat = grc%latdeg(g) this%fates(nc)%sites(s)%lon = grc%londeg(g) - this%fates(nc)%bc_in(s)%pft_areafrac(:)=0._r8 - ! initialize static layers for reduced complexity FATES versions from HLM - ! maybe make this into a subroutine of it's own later. - do m = surfpft_lb,surfpft_ub - ft = m - surfpft_lb - this%fates(nc)%bc_in(s)%pft_areafrac(ft)=wt_nat_patch(g,m) - end do + ! Transfer the landuse x pft data to fates via bc_in if file is given + if (use_fates_fixed_biogeog) then + if (use_fates_luh) then + this%fates(nc)%bc_in(s)%pft_areafrac_lu(:,1:num_landuse_pft_vars) = landuse_pft_map(g,:,1:num_landuse_pft_vars) + this%fates(nc)%bc_in(s)%baregroundfrac = landuse_bareground(g) + else + ! initialize static layers for reduced complexity FATES versions from HLM + ! maybe make this into a subroutine of it's own later. + this%fates(nc)%bc_in(s)%pft_areafrac(:)=0._r8 + do m = surfpft_lb,surfpft_ub + ft = m - surfpft_lb + this%fates(nc)%bc_in(s)%pft_areafrac(ft)=wt_nat_patch(g,m) + end do - if (abs(sum(this%fates(nc)%bc_in(s)%pft_areafrac(surfpft_lb:surfpft_ub)) - 1.0_r8) > sum_to_1_tol) then - write(iulog,*) 'pft_area error in interfc ', s, sum(this%fates(nc)%bc_in(s)%pft_areafrac(:)) - 1.0_r8 - call endrun(msg=errMsg(sourcefile, __LINE__)) - end if + if (abs(sum(this%fates(nc)%bc_in(s)%pft_areafrac(surfpft_lb:surfpft_ub)) - 1.0_r8) > sum_to_1_tol) then + write(iulog,*) 'pft_area error in interfc ', s, sum(this%fates(nc)%bc_in(s) %pft_areafrac(:)) - 1.0_r8 + call endrun(msg=errMsg(sourcefile, __LINE__)) + end if + end if + end if end do !site ! Initialize site-level static quantities dictated by the HLM @@ -910,6 +946,12 @@ subroutine init(this, bounds_proc ) ! Fire data to send to FATES call create_fates_fire_data_method( this%fates_fire_data_method ) + ! deallocate the local landuse x pft array + if (use_fates_fixed_biogeog .and. use_fates_luh) then + deallocate(landuse_pft_map) + deallocate(landuse_bareground) + end if + call t_stopf('fates_init') end subroutine init @@ -1026,7 +1068,8 @@ subroutine dynamics_driv(this, nc, bounds_clump, & ! Set the FATES global time and date variables call GetAndSetTime - if (get_do_harvest()) then + ! Get harvest rates for CLM landuse timeseries driven rates + if (trim(fates_harvest_mode) == fates_harvest_clmlanduse) then call dynHarvest_interp_resolve_harvesttypes(bounds_clump, & harvest_rates=harvest_rates(begg:endg,1:num_harvest_inst), & after_start_of_harvest_ts=after_start_of_harvest_ts) @@ -1152,7 +1195,7 @@ subroutine dynamics_driv(this, nc, bounds_clump, & ! for now there is one veg column per gridcell, so store all harvest data in each site ! this will eventually change ! today's hlm harvest flag needs to be set no matter what - if (get_do_harvest()) then + if (trim(fates_harvest_mode) == fates_harvest_clmlanduse) then if (after_start_of_harvest_ts) then this%fates(nc)%bc_in(s)%hlm_harvest_rates(1:num_harvest_inst) = harvest_rates(g,1:num_harvest_inst) else @@ -1170,6 +1213,12 @@ subroutine dynamics_driv(this, nc, bounds_clump, & write(iulog,*) harvest_units call endrun(msg=errMsg(sourcefile, __LINE__)) end if + + else if (trim(fates_harvest_mode) == fates_harvest_luh_area .or. & + trim(fates_harvest_mode) == fates_harvest_luh_mass) then + this%fates(nc)%bc_in(s)%hlm_harvest_rates = landuse_harvest(:,g) + this%fates(nc)%bc_in(s)%hlm_harvest_catnames = landuse_harvest_varnames + this%fates(nc)%bc_in(s)%hlm_harvest_units = landuse_harvest_units endif if (use_fates_luh) then @@ -2132,6 +2181,13 @@ subroutine init_coldstart(this, waterstatebulk_inst, waterdiagnosticbulk_inst, & this%fates(nc)%bc_in(s)%hlm_luh_state_names = landuse_state_varnames this%fates(nc)%bc_in(s)%hlm_luh_transitions = landuse_transitions(:,g) this%fates(nc)%bc_in(s)%hlm_luh_transition_names = landuse_transition_varnames + + if (trim(fates_harvest_mode) == fates_harvest_luh_area .or. & + trim(fates_harvest_mode) == fates_harvest_luh_mass) then + this%fates(nc)%bc_in(s)%hlm_harvest_rates = landuse_harvest(:,g) + this%fates(nc)%bc_in(s)%hlm_harvest_catnames = landuse_harvest_varnames + this%fates(nc)%bc_in(s)%hlm_harvest_units = landuse_harvest_units + end if end if end do @@ -3755,6 +3811,112 @@ subroutine GetAndSetTime() end subroutine GetAndSetTime + ! ====================================================================================== + + subroutine GetLandusePFTData(bounds, landuse_pft_file, landuse_pft_map, landuse_bareground) + + ! !DESCRIPTION: + ! Read in static landuse x pft file + + ! !USES: + use fileutils , only : getfil + use ncdio_pio , only : file_desc_t, ncd_io, ncd_inqdlen + use ncdio_pio , only : ncd_pio_openfile, ncd_pio_closefile + use decompMod , only : BOUNDS_LEVEL_PROC + use clm_varcon, only : grlnd + use FatesConstantsMod, only : fates_unset_r8 + + + ! !ARGUMENTS: + type(bounds_type), intent(in) :: bounds ! proc-level bounds + character(len=*) , intent(in) :: landuse_pft_file ! name of file containing static landuse x pft information + real(r8), allocatable, intent(inout) :: landuse_pft_map(:,:,:) + real(r8), allocatable, intent(inout) :: landuse_bareground(:) + + ! !LOCAL VARIABLES + integer :: varnum ! variable number + integer :: dimid, dimlen ! dimension id number and length + integer :: ier ! error id + character(len=256) :: locfn ! local file name + type(file_desc_t) :: ncid ! netcdf id + real(r8), pointer :: arraylocal(:,:) ! local array for reading fraction data + real(r8), pointer :: arraylocal_bareground(:) ! local array for reading bareground data + logical :: readvar ! true => variable is on dataset + !character(len=16), parameter :: grlnd = 'lndgrid' ! name of lndgrid + + integer, parameter :: dim_landuse_pft = 14 + + ! Land use name arrays + character(len=10), parameter :: landuse_pft_map_varnames(num_landuse_pft_vars) = & + [character(len=10) :: 'frac_primr','frac_secnd','frac_pastr','frac_range'] !need to move 'frac_surf' to a different variable + + character(len=*), parameter :: subname = 'GetLandusePFTData' + + !----------------------------------------------------------------------- + + ! Check to see if the landuse file name has been provided + ! Note: getfile checks this as well + if (masterproc) then + write(iulog,*) 'Attempting to read landuse x pft data .....' + if (landuse_pft_file == ' ') then + write(iulog,*)'landuse_pft_file must be specified' + call endrun(msg=errMsg(__FILE__, __LINE__)) + endif + endif + + ! Initialize the landuse x pft arrays and initialize to unset + allocate(landuse_pft_map(bounds%begg:bounds%endg,dim_landuse_pft,num_landuse_pft_vars),stat=ier) + if (ier /= 0) then + call endrun(msg=' allocation error for landuse_pft_map'//errMsg(__FILE__, __LINE__)) + end if + landuse_pft_map = fates_unset_r8 + + allocate(landuse_bareground(bounds%begg:bounds%endg),stat=ier) + if (ier /= 0) then + call endrun(msg=' allocation error for landuse_bareground'//errMsg(__FILE__, __LINE__)) + end if + landuse_bareground = fates_unset_r8 + + + ! Get the local filename and open the file + call getfil(landuse_pft_file, locfn, 0) + call ncd_pio_openfile (ncid, trim(locfn), 0) + + ! Check that natpft dimension on the file matches the target array dimensions + call ncd_inqdlen(ncid, dimid, dimlen, 'natpft') + if (dimlen /= dim_landuse_pft) then + write(iulog,*) 'natpft dimensions on the landuse x pft file do not match target array size' + call endrun(msg=errMsg(__FILE__, __LINE__)) + end if + + ! Allocate a temporary array since ncdio expects a pointer + allocate(arraylocal(bounds%begg:bounds%endg,dim_landuse_pft)) + allocate(arraylocal_bareground(bounds%begg:bounds%endg)) + + ! Read the landuse x pft data from file + do varnum = 1, num_landuse_pft_vars + call ncd_io(ncid=ncid, varname=landuse_pft_map_varnames(varnum), flag='read', & + data=arraylocal, dim1name=grlnd, readvar=readvar) + if (.not. readvar) & + call endrun(msg='ERROR: '//trim(landuse_pft_map_varnames(varnum))// & + ' NOT on landuse x pft file'//errMsg(__FILE__, __LINE__)) + landuse_pft_map(bounds%begg:bounds%endg,:,varnum) = arraylocal(bounds%begg:bounds%endg,:) + end do + + ! Read the bareground data from file. This is per gridcell only. + call ncd_io(ncid=ncid, varname='frac_brgnd', flag='read', & + data=arraylocal_bareground, dim1name=grlnd, readvar=readvar) + if (.not. readvar) call endrun(msg='ERROR: frac_brgnd NOT on landuse x pft file'//errMsg(__FILE__, __LINE__)) + landuse_bareground(bounds%begg:bounds%endg) = arraylocal_bareground(bounds%begg:bounds%endg) + + ! Deallocate the temporary local array point and close the file + deallocate(arraylocal) + deallocate(arraylocal_bareground) + call ncd_pio_closefile(ncid) + + end subroutine GetLandusePFTData + + !----------------------------------------------------------------------- end module CLMFatesInterfaceMod