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

migrate FATES to use the normal BGC call sequence #1959

Merged
merged 55 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
ff2e756
Mocked up the updated cbalance checking with fates
rgknox Jan 27, 2023
55f0af2
Incremental progress towareds converting fates-clm carbon accounting …
rgknox Feb 3, 2023
789eb9c
another incremental step towards having the native cn balancing and c…
rgknox Feb 13, 2023
c506151
more incremental fates-clm mass balance checking and pathway coupling…
rgknox Feb 16, 2023
f38d9a3
Incremental progress towards getting fates to work with the C and N b…
rgknox Mar 1, 2023
2f1ec52
Pass through of getting fates in the full BGC call sequence. This inc…
rgknox Mar 2, 2023
cb4f510
Added suppln to fates cases
rgknox Mar 2, 2023
782b894
added vertical profile code to the fates bgc call sequence
rgknox Mar 6, 2023
4772204
minor changes ot clmbuildnamelist
rgknox Mar 6, 2023
12e6b11
Removed various if-clauses that prevented BGC calls and initializatio…
rgknox Mar 9, 2023
5539289
FATES bgc work. Add use_fates_bgc, cleaned out some use_fates filteri…
rgknox Mar 10, 2023
0248331
Merge branch 'master' into clmfates-cbalance
rgknox Mar 10, 2023
8e638d4
updated fates external and the default parameter file
rgknox Mar 13, 2023
4bdfea6
moved the use_fates broadcast earlier in the control process
rgknox Mar 14, 2023
f4092b3
Fixes to CN wood products restart w/ fates on
rgknox Mar 15, 2023
873883c
cleaning up clm-fates bgc pr
rgknox Mar 15, 2023
79a77d6
cleanup of fates-bgc coupling
rgknox Mar 16, 2023
ff923e1
FATES in the normal bgc call sequence, addressing reviewer comments
rgknox May 25, 2023
158b182
Part-way through re-name-spacing the soilc and soilp filters for BGC
rgknox May 25, 2023
82d9b57
Updates to the build-namelist
rgknox May 26, 2023
1d3e8d0
Reverting namelist defaults related to NDEP, we were getting ahead of…
rgknox Jun 7, 2023
c9b6ce9
merge resolution, mostly conflicts with Gross Unrepresented Landuse t…
rgknox Jun 7, 2023
7fa071d
Fixes to build
rgknox Jun 8, 2023
6959556
Reverted use_cn filter on ndep namelist settings
rgknox Jun 8, 2023
27e28ab
preserving b4b on nitrogen variables by referting a filter to allc
rgknox Jun 8, 2023
0f2d990
Updates to the fates-clm bgc call sequence, to preserve b4b behavior …
rgknox Jun 12, 2023
0676ac2
various fixes for fates bgc
rgknox Jun 14, 2023
868e8c2
reverted call order on readfirenml
rgknox Jun 30, 2023
080cd5b
Update default scope of cn_products_type procedures
rgknox Jun 30, 2023
a4e690b
update to the span of columns that carbon summary variables are calcu…
rgknox Jul 4, 2023
40e7600
Fixes to zeroing carbon and nitrogen summary variables
rgknox Jul 5, 2023
f452386
merge resolution on fates bgc call sequence and dev 130
rgknox Jul 12, 2023
3a8fb5c
forgot to remove conflict tags
rgknox Jul 12, 2023
27f336d
Return this to what it was before the FATES addition should come later
ekluzek Jul 19, 2023
132f4eb
Check that with FATES on neither LUNA nor FUN can be on
ekluzek Jul 19, 2023
d4261c8
Explicitly make sure you can not turn LUNA on with FATES, and add a u…
ekluzek Jul 19, 2023
d2306c5
Add a test that FATES with suplemental nitrogen on is NOT allowed, th…
ekluzek Jul 19, 2023
739cf7c
Add error check for suplnitro for FATES
ekluzek Jul 20, 2023
d4ed2f6
resolving reviewer requests for clmfate-cbalance
rgknox Jul 24, 2023
9dac206
removed fates columns from the nocrop filter
rgknox Jul 24, 2023
6f3a2f1
Added calls to set the litter source on restart for fates
rgknox Jul 26, 2023
dbac92c
Updates to nfixing during fates run
rgknox Jul 27, 2023
7c920c6
Moved a call to update a call to fates litter fluxes to be immediatel…
rgknox Aug 10, 2023
e305a29
conflict resolutions between dev133 and clmfates-bgc
rgknox Aug 11, 2023
907ca1a
Provisions to satisfy nag compiler, cnveg datastructures on now alloc…
Aug 12, 2023
eaea030
Update to clm-fates-bgc zero-allocating instead of not allocating cnv…
Aug 14, 2023
6925f8c
Update fates external pointer to the fates bgc call sequence tag
rgknox Aug 14, 2023
1ccf0d9
update changelog
rgknox Aug 14, 2023
8056ae6
Run through black, fix #2112
ekluzek Aug 16, 2023
c05ce88
Add black commit to git blame ignore file
ekluzek Aug 16, 2023
76f1310
Add list of source files and directories to the github action
ekluzek Aug 16, 2023
89ad049
Try it with a one line list with square brackets
ekluzek Aug 16, 2023
44c696e
Add actions for each source
ekluzek Aug 16, 2023
bab1735
Needs a dot in front of the directory, so doesn't do an absolute path
ekluzek Aug 16, 2023
5765f94
Update Change files
ekluzek Aug 16, 2023
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
4 changes: 2 additions & 2 deletions Externals_CLM.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[fates]
local_path = src/fates
protocol = git
repo_url = https://github.com/NGEET/fates
tag = sci.1.66.1_api.25.5.0
repo_url = https://github.com/rgknox/fates
branch = clm-cbalance
required = True

[externals_description]
Expand Down
71 changes: 39 additions & 32 deletions bld/CLMBuildNamelist.pm
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ OPTIONS
This toggles off the namelist variable: use_cn
bgc = Carbon Nitrogen with methane, nitrification, vertical soil C,
CENTURY or MIMICS decomposition
This toggles on the namelist variables:
This toggles on the namelist variables:
use_cn, use_lch4, use_nitrif_denitrif
fates = FATES/Ecosystem Demography with below ground BGC
This toggles on the namelist variables:
use_fates
fates = FATES/Ecosystem Demography with below ground BGC
CENTURY or MIMICS decomposition
This toggles on the namelist variables:
use_fates. use_lch4 and use_nitrif_denitrif are optional

(Only for CLM4.5/CLM5.0)
-[no-]chk_res Also check [do NOT check] to make sure the resolution and
land-mask is valid.
Expand Down Expand Up @@ -763,26 +765,12 @@ sub setup_cmdl_fates_mode {
}
}

# The following variables may be set by the user and are compatible with use_fates
ekluzek marked this conversation as resolved.
Show resolved Hide resolved
# no need to set defaults, covered in a different routine
my @list = ( "use_lch4" );
foreach my $var ( @list ) {
if ( defined($nl->get_value($var)) ) {
$nl_flags->{$var} = $nl->get_value($var);
$val = $nl_flags->{$var};
my $group = $definition->get_group_name($var);
$nl->set_variable_value($group, $var, $val);
if ( ! $definition->is_valid_value( $var, $val ) ) {
my @valid_values = $definition->get_valid_values( $var );
$log->fatal_error("$var has a value ($val) that is NOT valid. Valid values are: @valid_values");
}
}
}
} else {
# 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" );
"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" );
# dis-allow fates specific namelist items with non-fates runs
foreach my $var ( @list ) {
if ( defined($nl->get_value($var)) ) {
Expand Down Expand Up @@ -2979,24 +2967,30 @@ sub setup_logic_supplemental_nitrogen {
my ($opts, $nl_flags, $definition, $defaults, $nl) = @_;

if ( $nl_flags->{'bgc_mode'} ne "sp" && $nl_flags->{'bgc_mode'} ne "fates" && &value_is_true($nl_flags->{'use_crop'}) ) {
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl,
'suplnitro', 'use_cn'=>$nl_flags->{'use_cn'}, 'use_crop'=>$nl_flags->{'use_crop'});
}
# If this is non-fates, non-sp and crop is active
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl,
'suplnitro', 'use_cn'=>$nl_flags->{'use_cn'}, 'use_crop'=>$nl_flags->{'use_crop'});

} elsif ( $nl_flags->{'bgc_mode'} eq "fates" && not &value_is_true( $nl_flags->{'use_fates_sp'}) ) {
# Or... if its fates but not fates-sp
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl,
'suplnitro', 'use_fates'=>$nl_flags->{'use_fates'});
}

#
# Error checking for suplnitro
#
my $suplnitro = $nl->get_value('suplnitro');
if ( defined($suplnitro) ) {
if ( $nl_flags->{'bgc_mode'} eq "sp" ) {
$log->fatal_error("supplemental Nitrogen (suplnitro) is set, but neither CN nor CNDV is active!");
$log->fatal_error("supplemental Nitrogen (suplnitro) is set, but neither CN nor CNDV nor FATES is active!");
ekluzek marked this conversation as resolved.
Show resolved Hide resolved
ekluzek marked this conversation as resolved.
Show resolved Hide resolved
}
if ( ! &value_is_true($nl_flags->{'use_crop'}) && $suplnitro =~ /PROG_CROP_ONLY/i ) {
$log->fatal_error("supplemental Nitrogen is set to run over prognostic crops, but prognostic crop is NOT active!");
}

if ( $suplnitro =~ /ALL/i ) {
if ( $nl_flags->{'bgc_spinup'} eq "on" ) {
if ( $nl_flags->{'bgc_spinup'} eq "on" && $nl_flags->{'bgc_mode'} ne "fates" ) {
ekluzek marked this conversation as resolved.
Show resolved Hide resolved
$log->warning("There is no need to use a bgc_spinup mode when supplemental Nitrogen is on for all PFT's, as these modes spinup Nitrogen" );
}
}
Expand Down Expand Up @@ -3313,6 +3307,12 @@ sub setup_logic_luna {
'use_cn'=>$nl_flags->{'use_cn'} );
}
$nl_flags->{'use_luna'} = $nl->get_value('use_luna');

# LUNA can NOT be on with FATES
if ( &value_is_true( $nl_flags->{'use_luna'} ) && &value_is_true( $nl_flags->{'use_fates'} )) {
$log->fatal_error("Cannot turn use_luna to true when bgc=fates" );
}

my $vcmax_opt= $nl->get_value('vcmax_opt');
# lnc_opt only applies if luna is on or for vcmax_opt=3/4
if ( &value_is_true( $nl_flags->{'use_luna'} ) || $vcmax_opt == 3 || $vcmax_opt == 4 ) {
Expand Down Expand Up @@ -3479,18 +3479,18 @@ sub setup_logic_nitrogen_deposition {
my ($opts, $nl_flags, $definition, $defaults, $nl) = @_;

#
# Nitrogen deposition for bgc=CN
# Nitrogen deposition for bgc=CN or fates
ekluzek marked this conversation as resolved.
Show resolved Hide resolved
#
if ( $nl_flags->{'bgc_mode'} =~/bgc/ ) {
if ( ($nl_flags->{'bgc_mode'} =~/bgc/) ) { # or ($nl_flags->{'bgc_mode'} =~/fates/) ) {
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'ndepmapalgo', 'phys'=>$nl_flags->{'phys'},
'use_cn'=>$nl_flags->{'use_cn'}, 'hgrid'=>$nl_flags->{'res'},
'clm_accelerated_spinup'=>$nl_flags->{'clm_accelerated_spinup'} );
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'ndep_taxmode', 'phys'=>$nl_flags->{'phys'},
'use_cn'=>$nl_flags->{'use_cn'},
'lnd_tuning_mode'=>$nl_flags->{'lnd_tuning_mode'} );
'use_cn'=>$nl_flags->{'use_cn'},
'lnd_tuning_mode'=>$nl_flags->{'lnd_tuning_mode'} );
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'ndep_varlist', 'phys'=>$nl_flags->{'phys'},
'use_cn'=>$nl_flags->{'use_cn'},
'lnd_tuning_mode'=>$nl_flags->{'lnd_tuning_mode'} );
'use_cn'=>$nl_flags->{'use_cn'},
'lnd_tuning_mode'=>$nl_flags->{'lnd_tuning_mode'} );
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'stream_year_first_ndep', 'phys'=>$nl_flags->{'phys'},
'use_cn'=>$nl_flags->{'use_cn'}, 'sim_year'=>$nl_flags->{'sim_year'},
'sim_year_range'=>$nl_flags->{'sim_year_range'});
Expand Down Expand Up @@ -4220,6 +4220,13 @@ sub setup_logic_fates {
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'} );
}
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'}) ) {
$log->fatal_error("supplemental Nitrogen (suplnitro) is NOT set to ALL, FATES is on, " .
"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
Expand Down
3 changes: 2 additions & 1 deletion bld/namelist_files/namelist_defaults_ctsm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ attributes from the config_cache.xml file (with keys converted to upper-case).

<!-- Supplmental Nitrogen mode -->
<suplnitro use_cn=".true." >NONE</suplnitro>
<suplnitro use_fates=".true." >NONE</suplnitro>
<suplnitro use_fates=".true." >ALL</suplnitro>

<!-- Albedo for glaciers -->
<albice phys="clm5_1" >0.50,0.30</albice>
Expand Down Expand Up @@ -510,6 +510,7 @@ attributes from the config_cache.xml file (with keys converted to upper-case).
<use_luna phys="clm5_0" >.true.</use_luna>
<use_luna phys="clm5_0" use_fates=".true." >.false.</use_luna>
<use_luna phys="clm4_5" >.false.</use_luna>
<use_luna phys="clm4_5" use_fates=".true." >.false.</use_luna>

<!-- Flexible CN options -->
<MM_Nuptake_opt use_flexibleCN=".true." >.true.</MM_Nuptake_opt>
Expand Down
17 changes: 16 additions & 1 deletion bld/unit_testers/build-namelist_test.pl
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ sub cat_and_create_namelistinfile {
#
# Figure out number of tests that will run
#
my $ntests = 1975;
my $ntests = 1978;
if ( defined($opts{'compare'}) ) {
$ntests += 1344;
}
Expand Down Expand Up @@ -984,6 +984,21 @@ sub cat_and_create_namelistinfile {
GLC_TWO_WAY_COUPLING=>"FALSE",
phys=>"clm5_1",
},
"useFATESWluna" =>{ options=>"--bgc fates --envxml_dir . --no-megan",
namelst=>"use_luna=TRUE",
GLC_TWO_WAY_COUPLING=>"FALSE",
phys=>"clm5_1",
},
"useFATESWfun" =>{ options=>"--bgc fates --envxml_dir . --no-megan",
namelst=>"use_fun=TRUE",
GLC_TWO_WAY_COUPLING=>"FALSE",
phys=>"clm5_1",
},
"useFATESWOsuplnitro" =>{ options=>"--bgc fates --envxml_dir . --no-megan",
namelst=>"suplnitro='NONE'",
GLC_TWO_WAY_COUPLING=>"FALSE",
phys=>"clm5_1",
},
"FireNoneButBGCfireon" =>{ options=>"-bgc bgc -envxml_dir . -light_res none",
namelst=>"fire_method='li2021gswpfrc'",
GLC_TWO_WAY_COUPLING=>"FALSE",
Expand Down
66 changes: 36 additions & 30 deletions src/biogeochem/CNAnnualUpdateMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module CNAnnualUpdateMod
use CNvegStateType , only : cnveg_state_type
use PatchType , only : patch
use filterColMod , only : filter_col_type, col_filter_from_filter_and_logical_array
use ColumnType , only : col
!
implicit none
private
Expand All @@ -21,7 +22,7 @@ module CNAnnualUpdateMod
contains

!-----------------------------------------------------------------------
subroutine CNAnnualUpdate(bounds, num_soilc, filter_soilc, num_soilp, filter_soilp, &
subroutine CNAnnualUpdate(bounds, num_bgc_soilc, filter_bgc_soilc, num_bgc_vegp, filter_bgc_vegp, &
cnveg_state_inst, cnveg_carbonflux_inst)
!
! !DESCRIPTION:
Expand All @@ -34,10 +35,10 @@ subroutine CNAnnualUpdate(bounds, num_soilc, filter_soilc, num_soilp, filter_soi
!
! !ARGUMENTS:
type(bounds_type) , intent(in) :: bounds
integer , intent(in) :: num_soilc ! number of soil columns in filter
integer , intent(in) :: filter_soilc(:) ! filter for soil columns
integer , intent(in) :: num_soilp ! number of soil patches in filter
integer , intent(in) :: filter_soilp(:) ! filter for soil patches
integer , intent(in) :: num_bgc_soilc ! number of bgc soil columns in filter
integer , intent(in) :: filter_bgc_soilc(:) ! filter for bgc soil columns
integer , intent(in) :: num_bgc_vegp ! number of bgc veg patches in filter
integer , intent(in) :: filter_bgc_vegp(:) ! filter for bgc veg patches
type(cnveg_state_type) , intent(inout) :: cnveg_state_inst
type(cnveg_carbonflux_type) , intent(inout) :: cnveg_carbonflux_inst
!
Expand All @@ -53,22 +54,25 @@ subroutine CNAnnualUpdate(bounds, num_soilc, filter_soilc, num_soilp, filter_soi
dt = get_step_size_real()
secspyear = get_curr_days_per_year() * secspday

do fc = 1,num_soilc
c = filter_soilc(fc)
cnveg_state_inst%annsum_counter_col(c) = cnveg_state_inst%annsum_counter_col(c) + dt
if (cnveg_state_inst%annsum_counter_col(c) >= secspyear) then
end_of_year(c) = .true.
cnveg_state_inst%annsum_counter_col(c) = 0._r8
else
end_of_year(c) = .false.
do fc = 1,num_bgc_soilc
c = filter_bgc_soilc(fc)
if(.not.col%is_fates(c))then
ekluzek marked this conversation as resolved.
Show resolved Hide resolved
cnveg_state_inst%annsum_counter_col(c) = cnveg_state_inst%annsum_counter_col(c) + dt
if (cnveg_state_inst%annsum_counter_col(c) >= secspyear) then
end_of_year(c) = .true.
cnveg_state_inst%annsum_counter_col(c) = 0._r8
else
end_of_year(c) = .false.
end if
end if
end do


do fp = 1,num_soilp
p = filter_soilp(fp)
do fp = 1,num_bgc_vegp
p = filter_bgc_vegp(fp)
c = patch%column(p)

if (end_of_year(c)) then
if (end_of_year(c) .and. .not.col%is_fates(c)) then
ekluzek marked this conversation as resolved.
Show resolved Hide resolved

! update annual plant ndemand accumulator
cnveg_state_inst%annsum_potential_gpp_patch(p) = cnveg_state_inst%tempsum_potential_gpp_patch(p)
Expand All @@ -94,20 +98,22 @@ subroutine CNAnnualUpdate(bounds, num_soilc, filter_soilc, num_soilp, filter_soi
end do

! Get column-level averages, just for the columns that have reached their personal end-of-year
filter_endofyear_c = col_filter_from_filter_and_logical_array( &
bounds = bounds, &
num_orig = num_soilc, &
filter_orig = filter_soilc, &
logical_col = end_of_year(bounds%begc:bounds%endc))

call p2c(bounds, filter_endofyear_c%num, filter_endofyear_c%indices, &
cnveg_carbonflux_inst%annsum_npp_patch(bounds%begp:bounds%endp), &
cnveg_carbonflux_inst%annsum_npp_col(bounds%begc:bounds%endc))

call p2c(bounds, filter_endofyear_c%num, filter_endofyear_c%indices, &
cnveg_state_inst%annavg_t2m_patch(bounds%begp:bounds%endp), &
cnveg_state_inst%annavg_t2m_col(bounds%begc:bounds%endc))

if(num_bgc_vegp>0)then
filter_endofyear_c = col_filter_from_filter_and_logical_array( &
bounds = bounds, &
num_orig = num_bgc_soilc, &
filter_orig = filter_bgc_soilc, &
logical_col = end_of_year(bounds%begc:bounds%endc))

call p2c(bounds, filter_endofyear_c%num, filter_endofyear_c%indices, &
cnveg_carbonflux_inst%annsum_npp_patch(bounds%begp:bounds%endp), &
cnveg_carbonflux_inst%annsum_npp_col(bounds%begc:bounds%endc))

call p2c(bounds, filter_endofyear_c%num, filter_endofyear_c%indices, &
cnveg_state_inst%annavg_t2m_patch(bounds%begp:bounds%endp), &
cnveg_state_inst%annavg_t2m_col(bounds%begc:bounds%endc))
end if

end subroutine CNAnnualUpdate

end module CNAnnualUpdateMod
Loading