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

Remove fates dependency on do_harvest #2

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
85 changes: 44 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,51 +4445,66 @@ 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" );
}
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" );
}
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) {
# 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" );
}
# 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" );
}
}
}
}
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. fates_harvest_mode == fates_harvest_clmlanduse) then
call dynHarvest_init(bounds_proc, harvest_filename=get_flanduse_timeseries())
end if

Expand Down
70 changes: 26 additions & 44 deletions src/utils/clmfates_interfaceMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,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
Expand All @@ -185,6 +184,7 @@ module CLMFatesInterfaceMod
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 : landuse_harvest
use dynFATESLandUseChangeMod, only : landuse_harvest_units
Expand Down Expand Up @@ -489,13 +489,6 @@ subroutine CLMFatesGlobals2()
end if
call set_fates_ctrlparms('use_ed_st3',ival=pass_ed_st3)

if (fates_harvest_mode > fates_harvest_no_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
Expand All @@ -517,39 +510,29 @@ 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 can override it
! FATES logging and harvest modes
if (fates_harvest_mode > fates_harvest_no_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
pass_logging = 1 ! Time driven logging, without landuse harvest
! CLM landuse timeseries driven harvest rates
if (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 (fates_harvest_mode >= fates_harvest_luh_area) then
pass_lu_harvest = 1
pass_num_lu_harvest_cats = num_landuse_harvest_vars
else
pass_lu_harvest = 0
pass_num_lu_harvest_cats = 0
end if
end if

! FATES landuse modes
if(use_fates_luh) then
pass_use_luh = 1
pass_num_luh_states = num_landuse_state_vars
pass_num_luh_transitions = num_landuse_transition_vars

! Do not set harvest passing variables to zero not in luh harvest modes
! as the user may want to use the CLM landuse harvest with luh2 transitions
if(fates_harvest_mode >= fates_harvest_luh_area) then
! End the run if do_harvest is true with this run mode.
! This should be caught be the build namelist.
if(get_do_harvest()) then
call endrun(msg="do_harvest and fates_harvest_mode using luh2 harvest data are incompatible"//&
errmsg(sourcefile, __LINE__))
else
pass_lu_harvest = 1
end if
end if
else
pass_use_luh = 0
pass_num_luh_states = 0
Expand All @@ -567,8 +550,7 @@ subroutine CLMFatesGlobals2()
end if
call set_fates_ctrlparms('use_fates_potentialveg',ival=pass_use_potentialveg)

! Wait to set the harvest and logging variables after checking get_do_harvest
! and fates_harvest_modes
! Wait to set the harvest and logging variables after checking fates_harvest_modes
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)
Expand Down Expand Up @@ -996,7 +978,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 (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)
Expand Down Expand Up @@ -1122,7 +1105,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 (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
Expand All @@ -1140,19 +1123,18 @@ subroutine dynamics_driv(this, nc, bounds_clump, &
write(iulog,*) harvest_units
call endrun(msg=errMsg(sourcefile, __LINE__))
end if

else if (fates_harvest_mode >= fates_harvest_luh_area) 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
this%fates(nc)%bc_in(s)%hlm_luh_states = landuse_states(:,g)
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 (fates_harvest_mode >= fates_harvest_luh_area) 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
Expand Down