Skip to content

Commit

Permalink
Merge remote-tracking branch 'bbyefork/bbye/lnd/integrate_FAN_and_Fer…
Browse files Browse the repository at this point in the history
…tilizer_for_crops' (PR #5981)

Adds Flow of Agriculture Nitrogen (ammonia emissions) to crop model.
Adds gridded fertilizer for nitrogen and phosphorus.
Adds manure application.

All tests with CN biogeochemistry will have a namelist change.
[NML]
[non-BFB] for crop tests
  • Loading branch information
peterdschwartz committed Dec 8, 2023
2 parents cd22d14 + 123e652 commit fa40af6
Show file tree
Hide file tree
Showing 54 changed files with 4,516 additions and 157 deletions.
1 change: 1 addition & 0 deletions cime_config/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"ERS.f09_g16.I1850ELMCN.elm-bgcinterface",
"SMS.r05_r05.I1850ELMCN.elm-qian_1948",
"SMS_Ly2_P1x1.1x1_smallvilleIA.IELMCNCROP.elm-per_crop",
"SMS_Ly2_P1x1.1x1_smallvilleIA.IELMCNCROP.elm-fan",
"SMS.r05_r05.IELM.elm-topounit",
"ERS.ELM_USRDAT.I1850ELM.elm-usrdat",
"ERS.f09_f09.IELM.elm-lnd_rof_2way",
Expand Down
70 changes: 66 additions & 4 deletions components/elm/bld/ELMBuildNamelist.pm
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ sub process_commandline {
note => undef,
drydep => 0,
megan => 0,
fan => "default",
irrig => "default",
res => "default",
silent => 0,
Expand Down Expand Up @@ -361,6 +362,7 @@ sub process_commandline {
"nutrient_comp_pathway=s" => \$opts{'nutrient_comp_pathway'},
"soil_decomp=s" => \$opts{'soil_decomp'},
"solar_rad_scheme=s" => \$opts{'solar_rad_scheme'},
"fan=s" => \$opts{'fan'},
) or usage();

# Give usage message.
Expand Down Expand Up @@ -542,7 +544,8 @@ sub read_namelist_defaults {
my @nl_defaults_files = ( "$nl_flags->{'cfgdir'}/namelist_files/namelist_defaults_overall.xml",
"$nl_flags->{'cfgdir'}/namelist_files/namelist_defaults.xml",
"$drvblddir/namelist_files/namelist_defaults_drv.xml",
"$nl_flags->{'cfgdir'}/namelist_files/namelist_defaults_drydep.xml" );
"$nl_flags->{'cfgdir'}/namelist_files/namelist_defaults_drydep.xml",
"$nl_flags->{'cfgdir'}/namelist_files/namelist_defaults_fan.xml" );

# Add the location of the use case defaults files to the options hash
$opts->{'use_case_dir'} = "$nl_flags->{'cfgdir'}/namelist_files/use_cases";
Expand Down Expand Up @@ -1908,6 +1911,7 @@ sub process_namelist_inline_logic {
setup_logic_fates($opts->{'test'}, $nl_flags, $definition, $defaults, $nl, $physv);
setup_logic_bgc_spinup($opts->{'test'}, $nl_flags, $definition, $defaults, $nl, $physv);
setup_logic_supplemental_nitrogen($opts->{'test'}, $nl_flags, $definition, $defaults, $nl, $physv);
setup_logic_fan($opts, $nl_flags, $definition, $defaults, $nl, $physv);

#########################################
# namelist group: clm_humanindex_inparm #
Expand Down Expand Up @@ -2995,6 +2999,61 @@ sub setup_logic_phosphorus_deposition {

#-------------------------------------------------------------------------------

sub setup_logic_fan {
my ($opts, $nl_flags, $definition, $defaults, $nl, $physv) = @_;

# Flags to control FAN (Flow of Agricultural Nitrogen) nitrogen deposition (manure and fertilizer)
#
if ( $nl_flags->{'bgc_mode'} =~/cn|bgc/ ) {
if( $opts->{'fan'} ) {
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'use_fan',
'use_cn'=>$nl_flags->{'use_cn'} );
$nl_flags->{'use_fan'} = $nl->get_value('use_fan');
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'fan_nh3_to_atm',
'fan_mode'=>$opts->{'fan'});
$nl_flags->{'fan_nh3_to_atm'} = $nl->get_value('fan_nh3_to_atm');
}

if ( value_is_true( $nl_flags->{'use_fates'} ) && value_is_true( $nl_flags->{'use_fan'} ) ) {
fatal_error("Cannot turn use_fan on when use_fates is on\n" );
}
if (!value_is_true($nl_flags->{'use_crop'}) && value_is_true( $nl_flags->{'use_fan'} )) {
fatal_error('Cannot use_fan if use_crop is false');
} #

if( $opts->{'fan'} ) {
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, "fanmapalgo", 'phys'=>$nl_flags->{'phys'},
'use_cn'=>$nl_flags->{'use_cn'}, 'hgrid'=>$nl_flags->{'res'} );
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, "stream_year_first_fan", 'phys'=>$nl_flags->{'phys'},
'use_cn'=>$nl_flags->{'use_cn'}, 'sim_year'=>$nl_flags->{'sim_year'}, 'sim_year_range'=>$nl_flags->{'sim_year_range'});
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, "stream_year_last_fan", 'phys'=>$nl_flags->{'phys'},
'use_cn'=>$nl_flags->{'use_cn'}, 'sim_year'=>$nl_flags->{'sim_year'},'sim_year_range'=>$nl_flags->{'sim_year_range'});
# Set align year, if first and last years are different
if ( $nl->get_value("stream_year_first_fan") != $nl->get_value("stream_year_last_fan") ) {
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, "model_year_align_fan", 'sim_year'=>$nl_flags->{'sim_year'},
'sim_year_range'=>$nl_flags->{'sim_year_range'});
}
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, "stream_fldfilename_fan", 'phys'=>$nl_flags->{'phys'},
'use_cn'=>$nl_flags->{'use_cn'}, 'rcp'=>$nl_flags->{'rcp'}, 'hgrid'=>"1.9x2.5" );
} else {
# If bgc is NOT CN/CNDV then make sure none of the ndep settings are set!
if ( defined($nl->get_value('stream_year_first_fan')) ||
defined($nl->get_value('stream_year_last_fan')) ||
defined($nl->get_value('model_year_align_fan')) ||
defined($nl->get_value('stream_fldfilename_fan'))
) {
fatal_error("When bgc is NOT CN, FATES or CNDV none of: stream_year_first_ndep," .
"stream_year_last_ndep, model_year_align_ndep, nor stream_fldfilename_ndep" .
" can be set! $nl_flags->{'bgc_mode'} \n");
}
}

}
}


#-------------------------------------------------------------------------------

sub setup_logic_popd_streams {
# population density streams require elm and CN/BGC
my ($test_files, $nl_flags, $definition, $defaults, $nl, $physv) = @_;
Expand Down Expand Up @@ -3268,6 +3327,9 @@ sub write_output_files {
}
{
push @groups, "elm_humanindex_inparm";
if ( $nl_flags->{'use_fan'} eq ".true." ) {
push @groups, "fan_nml";
}
}
}

Expand All @@ -3279,6 +3341,9 @@ sub write_output_files {
# Drydep or MEGAN namelist
if ($opts->{'drydep'} || $opts->{'megan'} ) {
@groups = qw(drydep_inparm megan_emis_nl);
if ( $nl_flags->{'use_fan'} eq ".true." ) {
push @groups, "fan_inparm";
}
$outfile = "$opts->{'dir'}/drv_flds_in";
$nl->write($outfile, 'groups'=>\@groups, 'note'=>"$note" );
verbose_message("Writing @groups namelists to $outfile");
Expand Down Expand Up @@ -3392,9 +3457,6 @@ sub add_default {
} else {
if ($is_input_pathname eq 'abs') {
$val = set_abs_filepath($val, $inputdata_rootdir);
if ( $test_files and ($val !~ /null/) and (! -f "$val") ) {
fatal_error("file not found: $var = $val");
}
}
}
}
Expand Down
49 changes: 47 additions & 2 deletions components/elm/bld/namelist_files/namelist_defaults.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ attributes from the config_cache.xml file (with keys converted to upper-case).
for the CLM2 data in the CESM distribution -->
<!-- Plant function types (relative to {csmdata}) -->
<paramfile use_cn=".false." use_fates=".false." >lnd/clm2/paramdata/clm_params_c180301.nc</paramfile>
<paramfile use_crop=".true." >lnd/clm2/paramdata/clm_params_c220120.nc</paramfile>
<paramfile use_crop=".true." >lnd/clm2/paramdata/clm_params_c220224.nc</paramfile>
<paramfile nu_com="ECA" use_fates=".true." use_crop=".false." >lnd/clm2/paramdata/clm_params.cbgc.c07292018.nc</paramfile>
<paramfile nu_com="ECA" use_cn=".true." use_crop=".false." >lnd/clm2/paramdata/clm_params.cbgc.c07292018.nc</paramfile>
<paramfile use_crop=".false." use_cn=".true." >lnd/clm2/paramdata/clm_params_c211124.nc</paramfile>
Expand Down Expand Up @@ -357,7 +357,7 @@ lnd/clm2/surfdata_map/surfdata_10x15_mp24_simyr2000_c130927.nc</fsurdat>
<fsurdat hgrid="1x1_numaIA" sim_year="2000" use_crop=".true." >
lnd/clm2/surfdata_map/surfdata_1x1_numaIA_mp24_simyr2000_c130927.nc</fsurdat>
<fsurdat hgrid="1x1_smallvilleIA" sim_year="2000" use_crop=".true." >
lnd/clm2/surfdata_map/surfdata_1x1_smallvilleIA_mp50_simyr2000_c210930.nc</fsurdat>
lnd/clm2/surfdata_map/surfdata_1x1_smallvilleIA_mp50_simyr2000_c230905.nc</fsurdat>

<fsurdat hgrid="5x5_amazon" sim_year="2000" use_crop=".false." >
lnd/clm2/surfdata_map/surfdata_5x5_amazon_simyr2000_c130927.nc</fsurdat>
Expand Down Expand Up @@ -726,6 +726,45 @@ this mask will have smb calculated over the entire global land surface
<pdepmapalgo use_cn=".true." hgrid="1x1_tropicAtl" >nn</pdepmapalgo>
<pdepmapalgo use_cn=".true." hgrid="5x5_amazon" >nn</pdepmapalgo>

+<!-- FAN Nitrogen (manure) deposition streams namelist defaults -->
<stream_year_first_fan use_cn=".true." sim_year="2000" >2010</stream_year_first_fan>
<stream_year_last_fan use_cn=".true." sim_year="2000" >2010</stream_year_last_fan>

<stream_year_first_fan use_cn=".true." sim_year="1850" >2010</stream_year_first_fan>
<stream_year_last_fan use_cn=".true." sim_year="1850" >2010</stream_year_last_fan>

<stream_year_first_fan use_cn=".true." sim_year="1000" >2010</stream_year_first_fan>
<stream_year_last_fan use_cn=".true." sim_year="1000" >2010</stream_year_last_fan>

<stream_year_first_fan use_cn=".true." sim_year="constant" sim_year_range="1000-1002" >2010</stream_year_first_fan>
<stream_year_last_fan use_cn=".true." sim_year="constant" sim_year_range="1000-1002" >2010</stream_year_last_fan>

<stream_year_first_fan use_cn=".true." sim_year="constant" sim_year_range="1000-1004" >2010</stream_year_first_fan>
<stream_year_last_fan use_cn=".true." sim_year="constant" sim_year_range="1000-1004" >2010</stream_year_last_fan>

<stream_year_first_fan use_cn=".true." sim_year="constant" sim_year_range="1850-2000" >2010</stream_year_first_fan>
<stream_year_last_fan use_cn=".true." sim_year="constant" sim_year_range="1850-2000" >2010</stream_year_last_fan>

<stream_year_first_fan use_cn=".true." sim_year="constant" sim_year_range="1850-2100" >2010</stream_year_first_fan>
<stream_year_last_fan use_cn=".true." sim_year="constant" sim_year_range="1850-2100" >2010</stream_year_last_fan>

<stream_year_first_fan use_cn=".true." sim_year="constant" sim_year_range="2000-2100" >2010</stream_year_first_fan>
<stream_year_last_fan use_cn=".true." sim_year="constant" sim_year_range="2000-2100" >2010</stream_year_last_fan>

<stream_fldfilename_fan>lnd/clm2/ndepdata/fan_nitrogen_e3sm_f19_c20191010.nc</stream_fldfilename_fan>

<fanmapalgo use_cn=".true." >bilinear</fanmapalgo>

<fanmapalgo use_cn=".true." hgrid="1x1_brazil" >nn</fanmapalgo>
<fanmapalgo use_cn=".true." hgrid="1x1_mexicocityMEX" >nn</fanmapalgo>
<fanmapalgo use_cn=".true." hgrid="1x1_vancouverCAN" >nn</fanmapalgo>
<fanmapalgo use_cn=".true." hgrid="1x1_urbanc_alpha" >nn</fanmapalgo>
<fanmapalgo use_cn=".true." hgrid="1x1_camdenNJ" >nn</fanmapalgo>
<fanmapalgo use_cn=".true." hgrid="1x1_asphaltjungleNJ" >nn</fanmapalgo>
<fanmapalgo use_cn=".true." hgrid="1x1_tropicAtl" >nn</fanmapalgo>
<fanmapalgo use_cn=".true." hgrid="5x5_amazon" >nn</fanmapalgo>
<fanmapalgo use_cn=".true." hgrid="1x1_smallvilleIA" >nn</fanmapalgo>

<!-- LAI streams namelist defaults -->
<use_lai_streams >.false.</use_lai_streams>
<stream_year_first_lai >2001</stream_year_first_lai>
Expand Down Expand Up @@ -2103,4 +2142,10 @@ this mask will have smb calculated over the entire global land surface
<use_century_decomp bgc_mode="fates" >.true.</use_century_decomp>
<use_lch4 bgc_mode="fates" >.false.</use_lch4>

<!-- flow of agricultural nitrogen (fan) model -->
<use_fan use_cn=".true.">.false.</use_fan>
<use_fan use_cn=".false.">.false.</use_fan>
<use_fan use_fates=".true." >.false.</use_fan>
<use_fan fan_mode='disable'>.false.</use_fan>

</namelist_defaults>
19 changes: 19 additions & 0 deletions components/elm/bld/namelist_files/namelist_defaults_fan.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0"?>

<?xml-stylesheet type="text/xsl" href="namelist_defaults.xsl"?>

<namelist_defaults>

<!--
Values to use by default for creation of CLM model driver namelists.
The element names are the same as the corresponding namelist
variables. Values that depend on the model configuration use
attributes to express the dependency. The recognized attributes
are: RESOLUTION, defaults, mask, ic_ymd, ic_tod, sim_year and all configuration
attributes from the config_cache.xml file (with keys converted to upper-case).
-->

<fan_nh3_to_atm use_fan=".false.">.false.</fan_nh3_to_atm>
<fan_nh3_to_atm use_fan=".true." fan_mode="fan_atm">.true.</fan_nh3_to_atm>

</namelist_defaults>
74 changes: 74 additions & 0 deletions components/elm/bld/namelist_files/namelist_definition.xml
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,25 @@ Max number of plant functional types in naturally vegetated landunit.
Toggle to turn on the dynamic root model.
</entry>

<!-- ======================================================================================== -->
<!-- Namelist options for FAN model -->
<!-- ======================================================================================== -->

<entry id="use_fan" type="logical" category="physics"
group="elm_inparm" valid_values="" value=".false.">
Toggle to turn on the Flow of Agricultural Nitrogen (FAN) model.
Default configuration has no connection to soil or atmosphere.
</entry>

<entry id="fan_mode" type="char*32" category="physics"
group="elm_inparm" valid_values="fan_offline,fan_soil,fan_atm,fan_full">
Optional flag to turn on the fan mode coupling atm/soil.
fan_offline = use only fan for calculating emissions (no coupling)
fan_soil = fan coupled to soil bgc
fan_atm = fan coupled to atmosphere
fan_full = fan coupled to both soil bgc and atmosphere
</entry>

<!-- -->
<!-- mkmapdata namelist -->
<!-- -->
Expand Down Expand Up @@ -1138,6 +1157,61 @@ Mapping method from Phosphorus deposition input file to the model resolution
</entry>


<!-- ======================================================================================== -->
<!-- fan streams Namelist (only used when bgc=cn/cndv and use_fan=.true.) -->
<!-- ======================================================================================== -->

<entry id="stream_year_first_fan" type="integer" category="datasets"
group="fan_nml" valid_values="" >
First year to loop over for FAN Nitrogen (manure) Deposition data
</entry>

<entry id="stream_year_last_fan" type="integer" category="datasets"
group="fan_nml" valid_values="" >
Last year to loop over for FAN Nitrogen (manure) Deposition data
</entry>

<entry id="model_year_align_fan" type="integer" category="datasets"
group="fan_nml" valid_values="" >
Simulation year that aligns with stream_year_first_fan value
</entry>

<entry id="stream_fldfilename_fan" type="char*256" category="datasets"
input_pathname="abs" group="fan_nml" valid_values="" >
Filename of input stream data for FAN Nitrogen (manure) Deposition
</entry>

<entry id="fanmapalgo" type="char*256" category="datasets"
group="fan_nml" valid_values="bilinear,nn,nnoni,nnonj,spval,copy" >
Mapping method from FAN Nitrogen (manure) deposition input file to the model resolution
bilinear = bilinear interpolation
nn = nearest neighbor
nnoni = nearest neighbor on the "i" (longitude) axis
nnonj = nearest neighbor on the "j" (latitude) axis
spval = set to special value
copy = copy using the same indices
</entry>

<entry id="fan_to_bgc_crop" type="logical" category="physics"
group="fan_nml" valid_values="" >
Toggle to connect the FAN N pools to soil biogeochemistry for CROP VEGETATION columns
</entry>

<entry id="fan_to_bgc_veg" type="logical" category="physics"
group="fan_nml" valid_values="" >
Toggle to connect the FAN N pools to soil biogeochemistry for NATIVE VEGETATION columns
</entry>

<entry id="fract_spread_grass" type="real" category="physics"
group="fan_nml" valid_values="" >
Fraction of manure N produced in crop columns but spread on native vegetation columns (grasslands)
</entry>

<entry id="nh4_ads_coef" type="real" category="physics"
group="fan_nml" valid_values="">
Adsorption coefficient for ammonium in FAN. Must be >= 0, 0 means no adsorption.
</entry>

<!-- ======================================================================================== -->
<!-- lai_streams streams Namelist (when phys = CLM4_5) -->
<!-- ======================================================================================== -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,12 @@
Default: TRUE
</entry>

<!-- ======================================================================================== -->
<!-- FAN fields -->
<!-- ======================================================================================== -->
<entry id="fan_nh3_to_atm" type="logical" category="FAN"
group="fan_inparm" valid_values="" >
Switch on/off the coupling of NH3 emissions from FAN/CLM to CAM
</entry>

</namelist_definition>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use_fan = .true.
do_budgets = .false.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
flanduse_timeseries = '$DIN_LOC_ROOT/lnd/clm2/surfdata_map/landuse.timeseries_1x1_smallvilleIA_mp50_hist_simyr1850-1855_c210930.nc'
fsurdat = '$DIN_LOC_ROOT/lnd/clm2/surfdata_map/surfdata_1x1_smallvilleIA_mp50_simyr2000_c210930.nc'
fsurdat = '$DIN_LOC_ROOT/lnd/clm2/surfdata_map/surfdata_1x1_smallvilleIA_mp50_simyr2000_c230905.nc'

check_dynpft_consistency = .false.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
fsurdat = '$DIN_LOC_ROOT/lnd/clm2/surfdata_map/surfdata_1x1_smallvilleIA_mp50_simyr2000_miscanthus_c200606.nc'
fsurdat = '$DIN_LOC_ROOT/lnd/clm2/surfdata_map/surfdata_1x1_smallvilleIA_mp50_simyr2000_miscanthus_c230905.nc'
do_budgets = .false.
8 changes: 5 additions & 3 deletions components/elm/src/biogeochem/CNEcosystemDynBetrMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ subroutine CNEcosystemDynBetr(bounds, &
canopystate_vars, soilstate_vars, temperature_vars, crop_vars, &
photosyns_vars, soilhydrology_vars, energyflux_vars, &
PlantMicKinetics_vars, &
phosphorusflux_vars, phosphorusstate_vars)
phosphorusflux_vars, phosphorusstate_vars, frictionvel_vars)

! Description:
! Update vegetation related state variables and
Expand Down Expand Up @@ -140,6 +140,7 @@ subroutine CNEcosystemDynBetr(bounds, &
type(PlantMicKinetics_type) , intent(inout) :: PlantMicKinetics_vars
type(phosphorusflux_type) , intent(inout) :: phosphorusflux_vars
type(phosphorusstate_type) , intent(inout) :: phosphorusstate_vars
type(frictionvel_type) , intent(in) :: frictionvel_vars

real(r8) :: dt
integer :: c13= 0, c14=1
Expand Down Expand Up @@ -178,12 +179,13 @@ subroutine CNEcosystemDynBetr(bounds, &

call t_startf('CNDeposition')
call NitrogenDeposition(bounds, &
atm2lnd_vars, dt )
atm2lnd_vars, frictionvel_vars, &
soilstate_vars, filter_soilc, num_soilc,dt )
call t_stopf('CNDeposition')

call t_startf('MaintenanceResp')
if (crop_prog) then
call NitrogenFert(bounds, num_soilc,filter_soilc )
call NitrogenFert(bounds, num_soilc,filter_soilc, num_pcropp, filter_pcropp )

end if
call MaintenanceResp(bounds, num_soilc, filter_soilc, num_soilp, filter_soilp, &
Expand Down
Loading

0 comments on commit fa40af6

Please sign in to comment.