Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update fates_harvest_mode to use characters for namelist option select #3

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 58 additions & 41 deletions bld/CLMBuildNamelist.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2932,8 +2932,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) {
Expand Down Expand Up @@ -4433,21 +4433,9 @@ 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)) ) {
Expand All @@ -4457,50 +4445,79 @@ sub setup_logic_fates {
}
}
# check that fates landuse change mode has the necessary luh2 landuse timeseries data
# and add the default if not defined
# 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 );
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" );
} elsif ( ! -f "$fname" ) {
$log->fatal_error("$fname does NOT point to a valid filename" );
}
$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, 'phys'=>$nl_flags->{'phys'},
'hgrid'=>$nl_flags->{'res'}, 'sim_year_range'=>$nl_flags->{'sim_year_range'}, 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 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,
'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" );
}
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" );
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 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')) ) {
# $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) {
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 greater than 2" );
$log->fatal_error("use_fates_luh is required to be true when $var is luhdata_mass or luhdata_area" );
}
# 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')) ) {
$log->fatal_error("do_harvest can not be true when $var is greater than 2" );
} elsif ( $mode eq 'surfdata_file' ) {
# 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 fates_harvest_mode is surfdata_file" );
} elsif ( ! -f "$fname" ) {
$log->fatal_error("$var does NOT point to a valid filename" );
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions bld/namelist_files/namelist_defaults_ctsm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2759,7 +2759,7 @@ use_crop=".true.">lnd/clm2/surfdata_map/ctsm5.1.dev052/landuse.timeseries_mpasa1

<!-- ===== FATES DEFAULTS =========== -->
<fates_spitfire_mode use_fates=".true.">0</fates_spitfire_mode>
<fates_harvest_mode use_fates=".true.">0</fates_harvest_mode>
<fates_harvest_mode use_fates=".true.">no_harvest</fates_harvest_mode>
<use_fates_planthydro use_fates=".true.">.false.</use_fates_planthydro>
<use_fates_tree_damage use_fates=".true.">.false.</use_fates_tree_damage>
<use_fates_cohort_age_tracking use_fates=".true.">.false.</use_fates_cohort_age_tracking>
Expand All @@ -2769,8 +2769,8 @@ use_crop=".true.">lnd/clm2/surfdata_map/ctsm5.1.dev052/landuse.timeseries_mpasa1
<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." fates_harvest_mode="luhdata_area" >.true.</use_fates_luh>
<use_fates_luh use_fates=".true." fates_harvest_mode="luhdata_mass" >.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>
Expand Down
19 changes: 9 additions & 10 deletions bld/namelist_files/namelist_definition_ctsm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -734,15 +734,15 @@ 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).
</entry>

<entry id="fates_harvest_mode" type="integer" category="physics"
group="clm_inparm" valid_values="0,1,2,3,4", value="0" >
Set FATES harvesting mode by setting fates_harvest_mode > 0.
<entry id="fates_harvest_mode" type="char*13" category="physics"
group="clm_inparm" valid_values="no_harvest,event_code,surfdata_file,luhdata_area,luhdata_mass">
Set FATES harvesting mode by setting fates_harvest_mode to a valid string option.
Allowed values are:
0 : no fates harvesting of any kind
1 : fates logging via fates logging event codes (see fates parameter file) only
2 : fates harvest driven by CLM landuse timeseries data (dynHarvestMod)
3 : fates harvest driven by LUH2 raw harvest data, area-based (dynFATESLandUseChangeMod)
4 : fates harvest driven by LUH2 raw harvest data, mass-based (dynFATESLandUseChangeMod)
no_harvest: no fates harvesting of any kind
event_code: fates logging via fates logging event codes (see fates parameter file) only
surfdata_file: fates harvest driven by CLM landuse timeseries data (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)
</entry>

<entry id="use_fates_planthydro" type="logical" category="physics"
Expand Down Expand Up @@ -786,8 +786,7 @@ Full pathname to the inventory initialization control file.
<entry id="use_fates_luh" type="logical" category="physics"
group="clm_inparm" valid_values="" >
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 (fates_harvest_mode >= 3)
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.)
</entry>

Expand Down
6 changes: 3 additions & 3 deletions bld/unit_testers/build-namelist_test.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ sub cat_and_create_namelistinfile {
phys=>"clm4_5",
},
"useloggingButNOTFATES" =>{ options=>"-envxml_dir . -no-megan",
namelst=>"fates_harvest_mode=1",
namelst=>"fates_harvest_mode=event_code",
GLC_TWO_WAY_COUPLING=>"FALSE",
phys=>"clm4_5",
},
Expand Down Expand Up @@ -1102,12 +1102,12 @@ sub cat_and_create_namelistinfile {
phys=>"clm5_0",
},
"useFATESPOTVEGwithHARVEST" =>{ options=>"-bgc fates -envxml_dir . -no-megan",
namelst=>"use_fates_potentialveg=T,fates_harvest_mode=1",
namelst=>"use_fates_potentialveg=T,fates_harvest_mode=event_code",
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",
namelst=>"use_fates_luh=F,fates_harvest_mode=luhdata_area",
GLC_TWO_WAY_COUPLING=>"FALSE",
phys=>"clm5_0",
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fates_harvest_mode = 0
fates_harvest_mode = no_harvest
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fates_harvest_mode = 1
fates_harvest_mode = event_code
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fates_harvest_mode = 2
fates_harvest_mode = surfdata_file
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fates_harvest_mode = 3
fates_harvest_mode = luhdata_area
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fates_harvest_mode = 4
fates_harvest_mode = luhdata_mass
20 changes: 11 additions & 9 deletions src/dyn_subgrid/dynFATESLandUseChangeMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ module dynFATESLandUseChangeMod
integer, public, parameter :: num_landuse_harvest_vars = 5

! Define the fates landuse namelist mode switch values
integer, public, parameter :: fates_harvest_no_logging = 0
integer, public, parameter :: fates_harvest_logging_only = 1
integer, public, parameter :: fates_harvest_clmlanduse = 2
integer, public, parameter :: fates_harvest_luh_area = 3
integer, public, parameter :: fates_harvest_luh_mass = 4
character(len=13), public, parameter :: fates_harvest_no_logging = 'no_harvest'
character(len=13), public, parameter :: fates_harvest_logging_only = 'event_code'
character(len=13), public, parameter :: fates_harvest_clmlanduse = 'surfdata_file'
character(len=13), public, parameter :: fates_harvest_luh_area = 'luhdata_area'
character(len=13), public, parameter :: fates_harvest_luh_mass = 'luhdata_mass'

! Define landuse harvest unit integer representation
integer, public, parameter :: landuse_harvest_area_units = 1
Expand Down Expand Up @@ -171,13 +171,14 @@ subroutine dynFatesLandUseInit(bounds, landuse_filename)
end do

! Get the harvest rate data from the fates luh2 timeseries dataset if enabled
if (fates_harvest_mode .ge. fates_harvest_luh_area ) then
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 (fates_harvest_mode .eq. fates_harvest_luh_area ) then
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 (fates_harvest_mode .eq. fates_harvest_luh_mass ) then
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
Expand Down Expand Up @@ -256,7 +257,8 @@ 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 (fates_harvest_mode .ge. fates_harvest_luh_area ) then
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)
Expand Down
7 changes: 6 additions & 1 deletion src/dyn_subgrid/dynSubgridDriverMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/main/clm_varctl.F90
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,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
integer, public :: fates_harvest_mode = 0 ! 0 for no harvest/logging; 1-4 for harvest mode options
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
Expand Down
2 changes: 1 addition & 1 deletion src/main/controlMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,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 (fates_harvest_mode, 1, MPI_INTEGER, 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)
Expand Down
Loading